From: Pranjal Shrivastava <praan@google.com>
To: Nicolin Chen <nicolinc@nvidia.com>
Cc: Joerg Roedel <joro@8bytes.org>, Will Deacon <will@kernel.org>,
Robin Murphy <robin.murphy@arm.com>,
Mostafa Saleh <smostafa@google.com>,
iommu@lists.linux.dev, Jason Gunthorpe <jgg@nvidia.com>,
Daniel Mentz <danielmentz@google.com>
Subject: Re: [PATCH v5 3/3] iommu/arm-smmu-v3: Avoid redundant master lookup in events
Date: Fri, 15 Nov 2024 13:26:22 +0000 [thread overview]
Message-ID: <ZzdL_mC7ZiWVjtoQ@google.com> (raw)
In-Reply-To: <ZzPqRH57RjNS+lJ8@Asurada-Nvidia>
On Tue, Nov 12, 2024 at 03:52:36PM -0800, Nicolin Chen wrote:
> On Tue, Nov 12, 2024 at 08:30:18AM +0000, Pranjal Shrivastava wrote:
> > Remove the call to `arm_smmu_find_master` in `arm_smmu_handle_evt`.
> >
> > The call was primarily to retrieve `master->dev` ptr for reporting iommu
> > device faults. Since this info is already available in the `event->dev`
> > field, we no longer need to lookup the master to fetch the dev pointer.
>
> We only protected the "dev" for dev_name() while the streams_mutex
> is still required against arm_smmu_remove_master?
>
Umm.. as per the code upstream, we were just finding master because we
wanted to pass the master->dev in "iommu_report_device_fault", thus even
if the master is free'd by arm_smmu_remove_master, the struct dev
wouldn't be free'd as we still hold a reference to it here due to the
call to get_device in arm_smmu_decode_event.
> > @@ -1857,17 +1855,14 @@ static int arm_smmu_handle_evt(struct arm_smmu_device *smmu,
> > flt->prm.pasid = event->ssid;
> > }
> >
> > - mutex_lock(&smmu->streams_mutex);
> > - master = arm_smmu_find_master(smmu, event->sid);
> > - if (!master) {
> > - ret = -EINVAL;
> > - goto out_unlock;
> > - }
> > + /*
> > + * If the master wasn't found while reading the event or
> > + * get_device() returned NULL, we shouldn't report a fault.
> > + */
> > + if (!event->dev)
> > + return -EINVAL;
> >
> > - ret = iommu_report_device_fault(master->dev, &fault_evt);
> > -out_unlock:
> > - mutex_unlock(&smmu->streams_mutex);
> > - return ret;
> > + return iommu_report_device_fault(event->dev, &fault_evt);
>
> Apart from the question that I asked above, it'd be convenient for
> my vIRQ series to add on top if we can keep the master here:
> https://github.com/nicolinc/iommufd/blob/66b3f9cdb39920880fb052b53f11ceb16af007fe/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c#L1782
>
> Given that your flow is:
> arm_smmu_decode_event(...); // get event->dev
> if (arm_smmu_handle_evt(...)) // validate event->dev
> arm_smmu_dump_event(...); // use event->dev
>
> Could we just keep the driver as it is, so your flow will be:
> arm_smmu_decode_event(...); // no event->dev
> if (arm_smmu_handle_evt(...)) // get event->dev
> arm_smmu_dump_event(...); // use event->dev
> ?
Hmm.. looking at the vIRQ series it seems like we'd anyways need to call
arm_smmu_find_master here as you're adding more fields to that struct
and plan to use them here.
In that case, I don't think we need this patch [Patch 3/3] ?
We can keep the code as is and simply populate the event->dev ptr in
arm_smmu_handle_evt when we lock the streams_mutex as you suggested.
>
> > static void arm_smmu_dump_raw_event(struct arm_smmu_device *smmu, u64 *raw,
> > @@ -1927,6 +1922,7 @@ static void arm_smmu_dump_event(struct arm_smmu_device *smmu, u64 *raw,
> > }
> > }
> >
> > +
> > static irqreturn_t arm_smmu_evtq_thread(int irq, void *dev)
>
> Should drop this.
Ahh, my bad, will remove that.
Interesting to note that checkpatch didn't crib about it!
>
> Thanks
> Nicolin
Thanks,
Praan
next prev parent reply other threads:[~2024-11-15 13:26 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-12 8:30 [PATCH v5 0/3] iommu/arm-smmu-v3: Parse out event records Pranjal Shrivastava
2024-11-12 8:30 ` [PATCH v5 1/3] iommu/arm-smmu-v3: Introduce struct arm_smmu_event Pranjal Shrivastava
2024-11-12 23:30 ` Nicolin Chen
2024-11-15 13:13 ` Pranjal Shrivastava
2024-11-15 21:34 ` Nicolin Chen
2024-11-18 16:24 ` Jason Gunthorpe
2024-11-19 9:03 ` Will Deacon
2024-11-19 9:27 ` Pranjal Shrivastava
2024-11-20 9:56 ` Will Deacon
2024-11-20 11:46 ` Pranjal Shrivastava
2024-11-27 3:25 ` Daniel Mentz
2024-11-27 9:25 ` Pranjal Shrivastava
2024-11-27 19:42 ` Daniel Mentz
2024-11-27 20:53 ` Pranjal Shrivastava
2024-11-28 23:40 ` Daniel Mentz
2024-11-29 12:56 ` Pranjal Shrivastava
2024-11-12 8:30 ` [PATCH v5 2/3] iommu/arm-smmu-v3: Log better event records Pranjal Shrivastava
2024-11-12 8:30 ` [PATCH v5 3/3] iommu/arm-smmu-v3: Avoid redundant master lookup in events Pranjal Shrivastava
2024-11-12 23:52 ` Nicolin Chen
2024-11-15 13:26 ` Pranjal Shrivastava [this message]
2024-11-15 21:46 ` Nicolin Chen
2024-11-20 4:45 ` [PATCH v5 0/3] iommu/arm-smmu-v3: Parse out event records Daniel Mentz
2024-11-20 6:54 ` Pranjal Shrivastava
2024-11-20 7:12 ` Pranjal Shrivastava
2024-11-20 11:43 ` Pranjal Shrivastava
2024-11-22 23:33 ` Daniel Mentz
2024-11-26 9:30 ` Pranjal Shrivastava
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=ZzdL_mC7ZiWVjtoQ@google.com \
--to=praan@google.com \
--cc=danielmentz@google.com \
--cc=iommu@lists.linux.dev \
--cc=jgg@nvidia.com \
--cc=joro@8bytes.org \
--cc=nicolinc@nvidia.com \
--cc=robin.murphy@arm.com \
--cc=smostafa@google.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