[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <d46a3f73-4e0f-c86a-f8f8-ff207bedf4e5@linux.intel.com>
Date: Wed, 30 Mar 2022 12:35:40 +0800
From: Lu Baolu <baolu.lu@...ux.intel.com>
To: Jacob Pan <jacob.jun.pan@...el.com>
Cc: baolu.lu@...ux.intel.com, Joerg Roedel <joro@...tes.org>,
Jason Gunthorpe <jgg@...dia.com>,
Christoph Hellwig <hch@...radead.org>,
Kevin Tian <kevin.tian@...el.com>,
Ashok Raj <ashok.raj@...el.com>, Will Deacon <will@...nel.org>,
Robin Murphy <robin.murphy@....com>,
Jean-Philippe Brucker <jean-philippe@...aro.com>,
linux-kernel@...r.kernel.org, iommu@...ts.linux-foundation.org
Subject: Re: [PATCH RFC v2 03/11] iommu/sva: Add iommu_domain type for SVA
On 2022/3/30 5:38, Jacob Pan wrote:
>> +static struct iommu_domain *
>> +iommu_sva_alloc_domain(struct device *dev, struct mm_struct *mm)
>> +{
>> + struct bus_type *bus = dev->bus;
>> + struct iommu_sva_cookie *cookie;
>> + struct iommu_domain *domain;
>> + void *curr;
>> +
>> + if (!bus || !bus->iommu_ops)
>> + return NULL;
>> +
>> + cookie = kzalloc(sizeof(*cookie), GFP_KERNEL);
>> + if (!cookie)
>> + return NULL;
>> +
>> + domain = bus->iommu_ops->domain_alloc(IOMMU_DOMAIN_SVA);
>> + if (!domain)
>> + goto err_domain_alloc;
>> +
>> + cookie->mm = mm;
>> + cookie->pasid = mm->pasid;
> How do you manage the mm life cycle? do you require caller take mm reference?
> Or this should be limited to the current mm?
>
The existing sva_bind() interface requires the caller to take the mm
reference before calling it. So mm is safe during sva bind() and
unbind().
drivers/iommu/iommu.c:
/**
* iommu_sva_bind_device() - Bind a process address space to a device
* @dev: the device
* @mm: the mm to bind, caller must hold a reference to it
* @drvdata: opaque data pointer to pass to bind callback
*
* Create a bond between device and address space, allowing the device
to access
* the mm using the returned PASID. If a bond already exists between
@device and
* @mm, it is returned and an additional reference is taken. Caller
must call
* iommu_sva_unbind_device() to release each reference.
*
* iommu_dev_enable_feature(dev, IOMMU_DEV_FEAT_SVA) must be called
first, to
* initialize the required SVA features.
*
* On error, returns an ERR_PTR value.
*/
struct iommu_sva *
iommu_sva_bind_device(struct device *dev, struct mm_struct *mm, void
*drvdata)
Best regards,
baolu
Powered by blists - more mailing lists