All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@nvidia.com>
To: Jerry Snitselaar <jsnitsel@redhat.com>
Cc: iommu@lists.linux.dev, Joerg Roedel <joro@8bytes.org>,
	Robin Murphy <robin.murphy@arm.com>,
	Will Deacon <will@kernel.org>,
	Lu Baolu <baolu.lu@linux.intel.com>,
	Dan Carpenter <dan.carpenter@linaro.org>,
	Janne Grunau <j@jannau.net>, Joerg Roedel <jroedel@suse.de>,
	Sven Peter <sven@svenpeter.dev>
Subject: Re: [PATCH] iommu: Flow ERR_PTR out from __iommu_domain_alloc()
Date: Wed, 1 Nov 2023 20:17:27 -0300	[thread overview]
Message-ID: <20231101231727.GA5675@nvidia.com> (raw)
In-Reply-To: <65qhudcviofmcl2g64wca4yy2a772uqvoky6xp62ij2svj67vg@cr2pu6anogqh>

On Wed, Nov 01, 2023 at 11:52:08AM -0700, Jerry Snitselaar wrote:
> On Wed, Nov 01, 2023 at 02:51:02PM -0300, Jason Gunthorpe wrote:
> > Most of the calling code now has error handling that can carry an error
> > code further up the call chain. Keep the exported interface
> > iommu_domain_alloc() returning NULL and reflow the internal code to use
> > ERR_PTR not NULL for domain allocation failure.
> > 
> > Optionally allow drivers to return ERR_PTR from any of the alloc ops. Many
> > of the new ops (user, sva, etc) already return ERR_PTR, so having two
> > rules is confusing and hard on drivers. This fixes a bug in DART that was
> > returning ERR_PTR.
> > 
> > This also fixes a bug in iommu_group_alloc_default_domain() where it
> > returned both NULL and ERR_PTR, now it always returns ERR_PTR.
> > 
> > Fixes: 482feb5c6492 ("iommu/dart: Call apple_dart_finalize_domain() as part of alloc_paging()")
> > Fixes: 1c68cbc64fe6 ("iommu: Add IOMMU_DOMAIN_PLATFORM")
> > Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> > Link: https://lore.kernel.org/linux-iommu/b85e0715-3224-4f45-ad6b-ebb9f08c015d@moroto.mountain/
> > Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> > ---
> >  drivers/iommu/iommu.c | 53 +++++++++++++++++++++++++++++--------------
> >  1 file changed, 36 insertions(+), 17 deletions(-)
> > 
> > diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
> > index f17a1113f3d6a3..6bc044d2310487 100644
> > --- a/drivers/iommu/iommu.c
> > +++ b/drivers/iommu/iommu.c
> > @@ -1802,10 +1802,10 @@ iommu_group_alloc_default_domain(struct iommu_group *group, int req_type)
> >  
> >  	/* Otherwise IDENTITY and DMA_FQ defaults will try DMA */
> >  	if (iommu_def_domain_type == IOMMU_DOMAIN_DMA)
> > -		return NULL;
> > +		return ERR_PTR(-ENODEV);
> >  	dom = __iommu_group_alloc_default_domain(group, IOMMU_DOMAIN_DMA);
> >  	if (!dom)
> 
> Should this be if(IS_ERR(dom)) ?

Blah, I think I somehow missed this function:

@@ -1788,7 +1788,7 @@ iommu_group_alloc_default_domain(struct iommu_group *group, int req_type)
         */
        if (ops->default_domain) {
                if (req_type)
-                       return NULL;
+                       return ERR_PTR(-EINVAL);
                return ops->default_domain;
        }
 
@@ -1797,14 +1797,14 @@ iommu_group_alloc_default_domain(struct iommu_group *group, int req_type)
 
        /* The driver gave no guidance on what type to use, try the default */
        dom = __iommu_group_alloc_default_domain(group, iommu_def_domain_type);
-       if (dom)
+       if (!IS_ERR(dom))
                return dom;
 
        /* Otherwise IDENTITY and DMA_FQ defaults will try DMA */
        if (iommu_def_domain_type == IOMMU_DOMAIN_DMA)
-               return ERR_PTR(-ENODEV);
+               return ERR_PTR(-EINVAL);
        dom = __iommu_group_alloc_default_domain(group, IOMMU_DOMAIN_DMA);
-       if (!dom)
+       if (IS_ERR(dom))
                return dom;
 
        pr_warn("Failed to allocate default IOMMU domain of type %u for group %s - Falling back to IOMMU_DOMAIN_DMA",


Thanks! 
Jason

  reply	other threads:[~2023-11-01 23:17 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-01 17:51 [PATCH] iommu: Flow ERR_PTR out from __iommu_domain_alloc() Jason Gunthorpe
2023-11-01 18:52 ` Jerry Snitselaar
2023-11-01 23:17   ` Jason Gunthorpe [this message]
2023-11-02  4:10     ` Dan Carpenter
2023-11-02  5:09       ` Jerry Snitselaar
2023-11-02  5:22         ` Dan Carpenter
2023-11-02 12:12           ` Jason Gunthorpe
2023-11-02 13:09             ` Robin Murphy
2023-11-02 17:35               ` Jerry Snitselaar

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=20231101231727.GA5675@nvidia.com \
    --to=jgg@nvidia.com \
    --cc=baolu.lu@linux.intel.com \
    --cc=dan.carpenter@linaro.org \
    --cc=iommu@lists.linux.dev \
    --cc=j@jannau.net \
    --cc=joro@8bytes.org \
    --cc=jroedel@suse.de \
    --cc=jsnitsel@redhat.com \
    --cc=robin.murphy@arm.com \
    --cc=sven@svenpeter.dev \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.