public inbox for llvm@lists.linux.dev
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@nvidia.com>
To: "Tian, Kevin" <kevin.tian@intel.com>
Cc: "iommu@lists.linux.dev" <iommu@lists.linux.dev>,
	Joerg Roedel <joro@8bytes.org>,
	"llvm@lists.linux.dev" <llvm@lists.linux.dev>,
	Nathan Chancellor <nathan@kernel.org>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Miguel Ojeda <ojeda@kernel.org>,
	Robin Murphy <robin.murphy@arm.com>, "Rix, Tom" <trix@redhat.com>,
	Will Deacon <will@kernel.org>,
	Lu Baolu <baolu.lu@linux.intel.com>,
	Nicolin Chen <nicolinc@nvidia.com>
Subject: Re: [PATCH v4 15/17] iommu: Allow IOMMU_RESV_DIRECT to work on ARM
Date: Wed, 26 Apr 2023 10:36:19 -0300	[thread overview]
Message-ID: <ZEko0xQzArFvR82J@nvidia.com> (raw)
In-Reply-To: <BL1PR11MB527165BEE507FED5D3D57A928C639@BL1PR11MB5271.namprd11.prod.outlook.com>

On Thu, Apr 20, 2023 at 08:00:28AM +0000, Tian, Kevin wrote:
> > From: Jason Gunthorpe <jgg@nvidia.com>
> > Sent: Wednesday, April 12, 2023 9:52 PM
> >
> > @@ -2918,6 +2922,17 @@ static int iommu_setup_default_domain(struct
> > iommu_group *group,
> >  		}
> >  	}
> > 
> > +	/*
> > +	 * Drivers are supposed to allow mappings to be installed in a
> > domain
> > +	 * before device attachment, but some don't. Hack around this defect
> > by
> > +	 * trying again after attaching. If this happens it means the device
> > +	 * will not continuously have the IOMMU_RESV_DIRECT map.
> > +	 */
> > +	if (direct_failed) {
> > +		for_each_group_device(group, gdev)
> > +			iommu_create_device_direct_mappings(dom, gdev-
> > >dev);
> > +	}
> > +
> 
> Throw out a warning so user knows that the continuity might be broken
> here?

I suppose we should also fail the whole function if we hit failures
here?

So like this:

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index f44e2c21e9d05e..7a3b249601ea49 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -2873,8 +2873,12 @@ static int iommu_setup_default_domain(struct iommu_group *group,
 	 */
 	direct_failed = false;
 	for_each_group_device(group, gdev) {
-		if (iommu_create_device_direct_mappings(dom, gdev->dev))
+		if (iommu_create_device_direct_mappings(dom, gdev->dev)) {
 			direct_failed = true;
+			dev_warn_once(
+				gdev->dev->iommu->iommu_dev->dev,
+				"IOMMU driver was not able to establish FW requested direct mapping.");
+		}
 	}
 
 	/* We must set default_domain early for __iommu_device_set_domain */
@@ -2906,10 +2910,20 @@ static int iommu_setup_default_domain(struct iommu_group *group,
 	 * will not continuously have the IOMMU_RESV_DIRECT map.
 	 */
 	if (direct_failed) {
-		for_each_group_device(group, gdev)
-			iommu_create_device_direct_mappings(dom, gdev->dev);
+		for_each_group_device(group, gdev) {
+			ret = iommu_create_device_direct_mappings(dom, gdev->dev);
+			if (ret)
+				goto err_restore;
+		}
 	}
 
+err_restore:
+	if (old_dom) {
+		__iommu_group_set_domain_internal(
+			group, old_dom, IOMMU_SET_DOMAIN_MUST_SUCCEED);
+		iommu_domain_free(dom);
+		old_dom = NULL;
+	}
 out_free:
 	if (old_dom)
 		iommu_domain_free(old_dom);

Thanks,
Jason

  reply	other threads:[~2023-04-26 13:36 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-12 13:51 [PATCH v4 00/17] Consolidate the error handling around device attachment Jason Gunthorpe
2023-04-12 13:51 ` [PATCH v4 01/17] iommu: Replace iommu_group_device_count() with list_count_nodes() Jason Gunthorpe
2023-04-12 13:51 ` [PATCH v4 02/17] iommu: Add for_each_group_device() Jason Gunthorpe
2023-04-12 13:51 ` [PATCH v4 03/17] iommu: Make __iommu_group_set_domain() handle error unwind Jason Gunthorpe
2023-04-12 13:51 ` [PATCH v4 04/17] iommu: Use __iommu_group_set_domain() for __iommu_attach_group() Jason Gunthorpe
2023-04-12 13:51 ` [PATCH v4 05/17] iommu: Use __iommu_group_set_domain() in iommu_change_dev_def_domain() Jason Gunthorpe
2023-04-12 13:51 ` [PATCH v4 06/17] iommu: Replace __iommu_group_dma_first_attach() with set_domain Jason Gunthorpe
2023-04-13  2:35   ` Baolu Lu
2023-04-20  7:25   ` Tian, Kevin
2023-04-20 12:59     ` Jason Gunthorpe
2023-04-12 13:51 ` [PATCH v4 07/17] iommu: Remove iommu_group_do_dma_first_attach() from iommu_group_add_device() Jason Gunthorpe
2023-04-20  7:26   ` Tian, Kevin
2023-04-12 13:51 ` [PATCH v4 08/17] iommu: Replace iommu_group_do_dma_first_attach with __iommu_device_set_domain Jason Gunthorpe
2023-04-12 13:51 ` [PATCH v4 09/17] iommu: Fix iommu_probe_device() to attach the right domain Jason Gunthorpe
2023-04-12 13:51 ` [PATCH v4 10/17] iommu: Do iommu_group_create_direct_mappings() before attach Jason Gunthorpe
2023-04-20  7:29   ` Tian, Kevin
2023-04-12 13:51 ` [PATCH v4 11/17] iommu: Remove the assignment of group->domain during default domain alloc Jason Gunthorpe
2023-04-12 13:51 ` [PATCH v4 12/17] iommu: Consolidate the code to calculate the target default domain type Jason Gunthorpe
2023-04-20  7:30   ` Tian, Kevin
2023-04-12 13:51 ` [PATCH v4 13/17] iommu: Revise iommu_group_alloc_default_domain() Jason Gunthorpe
2023-04-13  2:47   ` Baolu Lu
2023-04-20  7:54   ` Tian, Kevin
2023-04-12 13:51 ` [PATCH v4 14/17] iommu: Consolidate the default_domain setup to one function Jason Gunthorpe
2023-04-20  7:57   ` Tian, Kevin
2023-04-12 13:51 ` [PATCH v4 15/17] iommu: Allow IOMMU_RESV_DIRECT to work on ARM Jason Gunthorpe
2023-04-20  8:00   ` Tian, Kevin
2023-04-26 13:36     ` Jason Gunthorpe [this message]
2023-04-26 23:48       ` Tian, Kevin
2023-04-12 13:51 ` [PATCH v4 16/17] iommu: Remove __iommu_group_for_each_dev() Jason Gunthorpe
2023-04-20  8:06   ` Tian, Kevin
2023-04-20 13:01     ` Jason Gunthorpe
2023-04-21  3:05       ` Tian, Kevin
2023-04-12 13:51 ` [PATCH v4 17/17] iommu: Tidy the control flow in iommu_group_store_type() Jason Gunthorpe
2023-04-20  8:07   ` Tian, Kevin
2023-05-01 22:01 ` [PATCH v4 00/17] Consolidate the error handling around device attachment Heiko Stübner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZEko0xQzArFvR82J@nvidia.com \
    --to=jgg@nvidia.com \
    --cc=baolu.lu@linux.intel.com \
    --cc=iommu@lists.linux.dev \
    --cc=joro@8bytes.org \
    --cc=kevin.tian@intel.com \
    --cc=llvm@lists.linux.dev \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=nicolinc@nvidia.com \
    --cc=ojeda@kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=trix@redhat.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox