On Mon, Sep 20, 2021, at 12:23 PM, Fenghua Yu wrote: > PASIDs are fundamentally hardware resources in a shared address space. > There is a limited number of them to use ENQCMD on shared workqueue. > They must be shared and managed. They can not, for instance, be > statically allocated to processes. > > Free PASID eagerly by sending IPIs in unbind was disabled due to locking > and other issues in commit 9bfecd058339 ("x86/cpufeatures: Force disable > X86_FEATURE_ENQCMD and remove update_pasid()"). > > Lazy PASID free is implemented in order to re-enable the ENQCMD feature. > PASIDs are currently reference counted and are centered around device > usage. To support lazy PASID free, reference counts are tracked in the > following scenarios: > > 1. The PASID's reference count is initialized as 1 when the PASID is first > allocated in bind. This is already implemented. > 2. A reference is taken when a device is bound to the mm and dropped > when the device is unbound from the mm. This reference tracks device > usage of the PASID. This is already implemented. > 3. A reference is taken when a task's IA32_PASID MSR is initialized in > #GP fix up and dropped when the task exits. This reference tracks > the task usage of the PASID. It is implemented here.
I think this is unnecessarily complicated because it's buying in to the existing ISA misconception that PASID has anything to do with a task. A PASID belongs to an mm, full stop. Now the ISA is nasty and we have tasks that have *noticed* that their mm has a PASID and tasks that have not noticed this fact, but that should be irrelevant to essentially everything except the fault handler. So just refcount the thing the obvious way: take a reference when you stick the PASID in the mm_struct and drop the reference in __mmdrop(). Problem solved. You could probably drop it more aggressively in __mmput(), and the comment explaining why is left as an exercise to the reader -- if a kernel thread starts doing ENQCMD, we have worse things to worry about :) --Andy _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu