[PATCH 1/7] iommu/vt-d: Add domain_alloc_paging support

Lu Baolu posted 7 patches 1 month, 2 weeks ago
There is a newer version of this series
[PATCH 1/7] iommu/vt-d: Add domain_alloc_paging support
Posted by Lu Baolu 1 month, 2 weeks ago
Add the domain_alloc_paging callback for domain allocation using the
iommu_paging_domain_alloc() interface.

Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
 drivers/iommu/intel/iommu.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index 9f6b0780f2ef..4803e0cb8279 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -4590,6 +4590,19 @@ static struct iommu_domain identity_domain = {
 	},
 };
 
+static struct iommu_domain *intel_iommu_domain_alloc_paging(struct device *dev)
+{
+	struct dmar_domain *dmar_domain;
+	bool first_stage;
+
+	first_stage = first_level_by_default(0);
+	dmar_domain = paging_domain_alloc(dev, first_stage);
+	if (IS_ERR(dmar_domain))
+		return ERR_CAST(dmar_domain);
+
+	return &dmar_domain->domain;
+}
+
 const struct iommu_ops intel_iommu_ops = {
 	.blocked_domain		= &blocking_domain,
 	.release_domain		= &blocking_domain,
@@ -4599,6 +4612,7 @@ const struct iommu_ops intel_iommu_ops = {
 	.domain_alloc		= intel_iommu_domain_alloc,
 	.domain_alloc_user	= intel_iommu_domain_alloc_user,
 	.domain_alloc_sva	= intel_svm_domain_alloc,
+	.domain_alloc_paging	= intel_iommu_domain_alloc_paging,
 	.probe_device		= intel_iommu_probe_device,
 	.release_device		= intel_iommu_release_device,
 	.get_resv_regions	= intel_iommu_get_resv_regions,
-- 
2.43.0
Re: [PATCH 1/7] iommu/vt-d: Add domain_alloc_paging support
Posted by Jason Gunthorpe 1 month, 2 weeks ago
On Fri, Oct 11, 2024 at 12:27:16PM +0800, Lu Baolu wrote:

> +static struct iommu_domain *intel_iommu_domain_alloc_paging(struct device *dev)
> +{
> +	struct dmar_domain *dmar_domain;
> +	bool first_stage;
> +
> +	first_stage = first_level_by_default(0);
> +	dmar_domain = paging_domain_alloc(dev, first_stage);
> +	if (IS_ERR(dmar_domain))
> +		return ERR_CAST(dmar_domain);
> +
> +	return &dmar_domain->domain;
> +}

With the direction that Vasant's series is going in, I think this
should be skipped and instead your other patch to make
domain_alloc_user (which we will rename) a full functional replacement
is the right thing.

Jason
Re: [PATCH 1/7] iommu/vt-d: Add domain_alloc_paging support
Posted by Baolu Lu 1 month, 2 weeks ago
On 2024/10/11 21:22, Jason Gunthorpe wrote:
> On Fri, Oct 11, 2024 at 12:27:16PM +0800, Lu Baolu wrote:
> 
>> +static struct iommu_domain *intel_iommu_domain_alloc_paging(struct device *dev)
>> +{
>> +	struct dmar_domain *dmar_domain;
>> +	bool first_stage;
>> +
>> +	first_stage = first_level_by_default(0);
>> +	dmar_domain = paging_domain_alloc(dev, first_stage);
>> +	if (IS_ERR(dmar_domain))
>> +		return ERR_CAST(dmar_domain);
>> +
>> +	return &dmar_domain->domain;
>> +}
> With the direction that Vasant's series is going in, I think this
> should be skipped and instead your other patch to make
> domain_alloc_user (which we will rename) a full functional replacement
> is the right thing.

I think it's too early to remove domain_alloc_paging from the iommu
driver. Vasant's series makes most of the paging domain allocation go
through domain_alloc_user ops, but for those that are non-PASID related,
it still goes through domain_alloc_paging. So perhaps we can clean up
after both series are merged.

Thanks,
baolu
Re: [PATCH 1/7] iommu/vt-d: Add domain_alloc_paging support
Posted by Jason Gunthorpe 1 month, 1 week ago
On Mon, Oct 14, 2024 at 08:53:36AM +0800, Baolu Lu wrote:
> On 2024/10/11 21:22, Jason Gunthorpe wrote:
> > On Fri, Oct 11, 2024 at 12:27:16PM +0800, Lu Baolu wrote:
> > 
> > > +static struct iommu_domain *intel_iommu_domain_alloc_paging(struct device *dev)
> > > +{
> > > +	struct dmar_domain *dmar_domain;
> > > +	bool first_stage;
> > > +
> > > +	first_stage = first_level_by_default(0);
> > > +	dmar_domain = paging_domain_alloc(dev, first_stage);
> > > +	if (IS_ERR(dmar_domain))
> > > +		return ERR_CAST(dmar_domain);
> > > +
> > > +	return &dmar_domain->domain;
> > > +}
> > With the direction that Vasant's series is going in, I think this
> > should be skipped and instead your other patch to make
> > domain_alloc_user (which we will rename) a full functional replacement
> > is the right thing.
> 
> I think it's too early to remove domain_alloc_paging from the iommu
> driver. Vasant's series makes most of the paging domain allocation go
> through domain_alloc_user ops, but for those that are non-PASID related,
> it still goes through domain_alloc_paging. So perhaps we can clean up
> after both series are merged.

I gave him a few more patches to finish the job, but yes let's not
make them interdependent. Just make sure this series sets things up so
we can delete this and the _user version can do everything

Jason
Re: [PATCH 1/7] iommu/vt-d: Add domain_alloc_paging support
Posted by Jason Gunthorpe 1 month, 2 weeks ago
On Fri, Oct 11, 2024 at 10:22:52AM -0300, Jason Gunthorpe wrote:
> On Fri, Oct 11, 2024 at 12:27:16PM +0800, Lu Baolu wrote:
> 
> > +static struct iommu_domain *intel_iommu_domain_alloc_paging(struct device *dev)
> > +{
> > +	struct dmar_domain *dmar_domain;
> > +	bool first_stage;
> > +
> > +	first_stage = first_level_by_default(0);
> > +	dmar_domain = paging_domain_alloc(dev, first_stage);
> > +	if (IS_ERR(dmar_domain))
> > +		return ERR_CAST(dmar_domain);
> > +
> > +	return &dmar_domain->domain;
> > +}
> 
> With the direction that Vasant's series is going in, I think this
> should be skipped and instead your other patch to make
> domain_alloc_user (which we will rename) a full functional replacement
> is the right thing.

Though I guess for patch ordering purposes it makes sense to just
leave this and remove it the next cycle

Jason