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" <iommu@lists.linux.dev>
Subject: Re: [PATCH v2 2/2] iommu/arm-smmu-v3: Adopt arm_smmu_event in handlers
Date: Fri, 30 Aug 2024 00:06:51 +0000 [thread overview]
Message-ID: <ZtENG42cpYrvSugF@google.com> (raw)
In-Reply-To: <ZtAFAs86+iTmEHKo@Asurada-Nvidia>
On Wed, Aug 28, 2024 at 10:20:02PM -0700, Nicolin Chen wrote:
> Hi Pranjal,
>
> On Tue, Aug 27, 2024 at 12:30:26PM -0700, Pranjal Shrivastava wrote:
>
> > /* Stage-2 is always pinned at the moment */
> > - if (evt[1] & EVTQ_1_S2)
> > + if (event->stage)
> > return -EFAULT;
>
> Should it be named to "s2" v.s stage?
Sure, will rename it with the next version.
>
> > - mutex_lock(&smmu->streams_mutex);
> > - master = arm_smmu_find_master(smmu, sid);
> > - if (!master) {
> > - ret = -EINVAL;
> > - goto out_unlock;
> > - }
> > + if (!event->master)
> > + return -EINVAL;
> >
> > - ret = iommu_report_device_fault(master->dev, &fault_evt);
> > -out_unlock:
> > - mutex_unlock(&smmu->streams_mutex);
> > + ret = iommu_report_device_fault(event->master->dev, &fault_evt);
>
> The iommu_report_device_fault(master->dev) call lost its mutex
> lock. I wonder if it could be unsafe to continue with that dev
> pointer.
Ack, I agree, responded with [Patch 1/2] in detail.
In summary, we need to avoid the following situation:
1. The evtq_thread gets scheduled
2. arm_smmu_release_device removes the `master` & its streams
3. In the `handle_evt` we dereference `master` which has been `kfree`ed
(also, we don't return -EINVAL in that case as we ideally should)
I'll add back the `arm_smmu_find_master` in the the `arm_smmu_handle_evt`
along with the locks. Nice catch! :)
>
> Nicolin
Thanks,
Pranjal
prev parent reply other threads:[~2024-08-30 0:06 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-27 19:30 [PATCH v2 0/2] iommu/arm-smmu-v3: Parse out event records Pranjal Shrivastava
2024-08-27 19:30 ` [PATCH v2 1/2] iommu/arm-smmu-v3: Print better events records Pranjal Shrivastava
2024-08-29 6:36 ` Nicolin Chen
2024-08-29 23:54 ` Pranjal Shrivastava
2024-08-30 1:45 ` Nicolin Chen
2024-09-02 8:23 ` Pranjal Shrivastava
2024-09-02 23:02 ` Nicolin Chen
2024-09-05 16:06 ` Pranjal Shrivastava
2024-09-06 1:55 ` Nicolin Chen
2024-09-06 12:55 ` Will Deacon
2024-09-06 16:39 ` Robin Murphy
2024-09-06 18:42 ` Nicolin Chen
2024-09-09 14:45 ` Will Deacon
2024-09-09 17:30 ` Pranjal Shrivastava
2024-09-10 4:43 ` Nicolin Chen
2024-11-04 16:40 ` Daniel Mentz
2024-08-27 19:30 ` [PATCH v2 2/2] iommu/arm-smmu-v3: Adopt arm_smmu_event in handlers Pranjal Shrivastava
2024-08-29 5:20 ` Nicolin Chen
2024-08-30 0:06 ` Pranjal Shrivastava [this message]
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=ZtENG42cpYrvSugF@google.com \
--to=praan@google.com \
--cc=iommu@lists.linux.dev \
--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