Re: [PATCH 2/2] iommu/sva: Remove mm parameter from SVA bind API

From: Lu Baolu
Date: Wed Apr 14 2021 - 02:33:24 EST


Hi Jacob,

On 4/14/21 8:09 AM, Jacob Pan wrote:
Hi Jean,

On Fri, 9 Apr 2021 11:03:05 -0700, Jacob Pan
<jacob.jun.pan@xxxxxxxxxxxxxxx> wrote:

problems:

* We don't have a use-case for binding the mm of a remote process (and
it's supposedly difficult for device drivers to do it securely). So
OK, we remove the mm argument from iommu_sva_bind_device() and use the
current mm. But the IOMMU driver isn't going to do
get_task_mm(current) every time it needs the mm being bound, it will
take it from iommu_sva_bind_device(). Likewise iommu_sva_alloc_pasid()
shouldn't need to bother with get_task_mm().

* cgroup accounting for IOASIDs needs to be on the current task.
Removing the mm parameter from iommu_sva_alloc_pasid() doesn't help
with that. Sure it indicates that iommu_sva_alloc_pasid() needs a
specific task context but that's only for cgroup purpose, and I'd
rather pass the cgroup down from iommu_sva_bind_device() anyway (but am
fine with keeping it within ioasid_alloc() for now). Plus it's an
internal helper, easy for us to check that the callers are doing the
right thing.
With the above split, we really just have one allocation function:
ioasid_alloc(), so it can manage current cgroup accounting within. Would
this work?
After a few attempts, I don't think the split can work better. I will
restore the mm parameter and add a warning if mm != current->mm.

I still worry about supervisor pasid allocation.

If we use iommu_sva_alloc_pasid() to allocate a supervisor pasid, which
mm should the pasid be set? I've ever thought about passing &init_mm to
iommu_sva_alloc_pasid(). But if you add "mm != current->mm", this seems
not to work. Or do you prefer a separated interface for supervisor pasid
allocation/free?

Best regards,
baolu


Thanks,

Jacob