From: Shameerali Kolothum Thodi <shameerali.kolothum.thodi@huawei.com>
To: Robin Murphy <robin.murphy@arm.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"iommu@lists.linux-foundation.org"
<iommu@lists.linux-foundation.org>
Cc: "joro@8bytes.org" <joro@8bytes.org>,
"jean-philippe@linaro.org" <jean-philippe@linaro.org>,
"will@kernel.org" <will@kernel.org>,
"Zengtao (B)" <prime.zeng@hisilicon.com>,
"linuxarm@openeuler.org" <linuxarm@openeuler.org>
Subject: RE: [PATCH v2] iommu: Check dev->iommu in iommu_dev_xxx functions
Date: Fri, 12 Feb 2021 17:28:34 +0000 [thread overview]
Message-ID: <33cf95925cfb47dda3ee472e00b9846c@huawei.com> (raw)
In-Reply-To: <d541ebeb-5b89-7a9d-50a2-3867f9cf78b3@arm.com>
> -----Original Message-----
> From: Shameerali Kolothum Thodi
> Sent: 12 February 2021 16:45
> To: 'Robin Murphy' <robin.murphy@arm.com>; linux-kernel@vger.kernel.org;
> iommu@lists.linux-foundation.org
> Cc: joro@8bytes.org; jean-philippe@linaro.org; will@kernel.org; Zengtao (B)
> <prime.zeng@hisilicon.com>; linuxarm@openeuler.org
> Subject: RE: [PATCH v2] iommu: Check dev->iommu in iommu_dev_xxx functions
>
>
>
> > -----Original Message-----
> > From: Robin Murphy [mailto:robin.murphy@arm.com]
> > Sent: 12 February 2021 16:39
> > To: Shameerali Kolothum Thodi <shameerali.kolothum.thodi@huawei.com>;
> > linux-kernel@vger.kernel.org; iommu@lists.linux-foundation.org
> > Cc: joro@8bytes.org; jean-philippe@linaro.org; will@kernel.org; Zengtao (B)
> > <prime.zeng@hisilicon.com>; linuxarm@openeuler.org
> > Subject: Re: [PATCH v2] iommu: Check dev->iommu in iommu_dev_xxx
> functions
> >
> > On 2021-02-12 14:54, Shameerali Kolothum Thodi wrote:
> > > Hi Robin/Joerg,
> > >
> > >> -----Original Message-----
> > >> From: Shameer Kolothum
> [mailto:shameerali.kolothum.thodi@huawei.com]
> > >> Sent: 01 February 2021 12:41
> > >> To: linux-kernel@vger.kernel.org; iommu@lists.linux-foundation.org
> > >> Cc: joro@8bytes.org; robin.murphy@arm.com; jean-philippe@linaro.org;
> > >> will@kernel.org; Zengtao (B) <prime.zeng@hisilicon.com>;
> > >> linuxarm@openeuler.org
> > >> Subject: [Linuxarm] [PATCH v2] iommu: Check dev->iommu in
> > iommu_dev_xxx
> > >> functions
> > >>
> > >> The device iommu probe/attach might have failed leaving dev->iommu
> > >> to NULL and device drivers may still invoke these functions resulting
> > >> in a crash in iommu vendor driver code. Hence make sure we check that.
> > >>
> > >> Also added iommu_ops to the "struct dev_iommu" and set it if the dev
> > >> is successfully associated with an iommu.
> > >>
> > >> Fixes: a3a195929d40 ("iommu: Add APIs for multiple domains per
> device")
> > >> Signed-off-by: Shameer Kolothum
> > <shameerali.kolothum.thodi@huawei.com>
> > >> ---
> > >> v1 --> v2:
> > >> -Added iommu_ops to struct dev_iommu based on the discussion with
> > Robin.
> > >> -Rebased against iommu-tree core branch.
> > >
> > > A gentle ping on this...
> >
> > Is there a convincing justification for maintaining yet another copy of
> > the ops pointer rather than simply dereferencing iommu_dev->ops at point
> > of use?
> >
>
> TBH, nothing I can think of now. That was mainly the way I interpreted your
> suggestion
> from the v1. Now it looks like you didn’t mean it :). I am Ok to rework it to
> dereference
> it from iommu_dev. Please let me know.
So we can do something like this,
index fd76e2f579fe..5fd31a3cec18 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -2865,10 +2865,12 @@ EXPORT_SYMBOL_GPL(iommu_fwspec_add_ids);
*/
int iommu_dev_enable_feature(struct device *dev, enum iommu_dev_features feat)
{
- const struct iommu_ops *ops = dev->bus->iommu_ops;
+ if (dev->iommu && dev->iommu->iommu_dev && dev->iommu->iommu_dev->ops)
+ struct iommu_ops *ops = dev->iommu->iommu_dev->ops;
- if (ops && ops->dev_enable_feat)
- return ops->dev_enable_feat(dev, feat);
+ if (ops->dev_enable_feat)
+ return ops->dev_enable_feat(dev, feat);
+ }
return -ENODEV;
}
Again, not sure we need to do the checking for iommu->dev and ops here. If the
dev->iommu is set, is it safe to assume that we have a valid iommu->iommu_dev
and ops always? (May be it is safer to do the checking in case something
else breaks this assumption in future). Please let me know your thoughts.
Thanks,
Shameer
next prev parent reply other threads:[~2021-02-12 17:30 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-12 14:54 Shameerali Kolothum Thodi
2021-02-12 16:38 ` Robin Murphy
2021-02-12 16:44 ` Shameerali Kolothum Thodi
2021-02-12 17:28 ` Shameerali Kolothum Thodi [this message]
2021-02-16 13:45 ` Robin Murphy
-- strict thread matches above, loose matches on Subject: below --
2021-02-01 12:40 Shameer Kolothum
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=33cf95925cfb47dda3ee472e00b9846c@huawei.com \
--to=shameerali.kolothum.thodi@huawei.com \
--cc=iommu@lists.linux-foundation.org \
--cc=jean-philippe@linaro.org \
--cc=joro@8bytes.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxarm@openeuler.org \
--cc=prime.zeng@hisilicon.com \
--cc=robin.murphy@arm.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
Powered by JetHome