From: Vasant Hegde <vasant.hegde@amd.com>
To: lirongqing <lirongqing@baidu.com>, Joerg Roedel <joro@8bytes.org>,
Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>,
Will Deacon <will@kernel.org>,
Robin Murphy <robin.murphy@arm.com>,
iommu@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iommu/amd: RCU-protect iommu_ga_log_notifier
Date: Mon, 16 Nov 2026 20:18:56 +0530 [thread overview]
Message-ID: <301430f5-c96a-42e2-bd81-de564650f9a9@amd.com> (raw)
In-Reply-To: <20260924064709.2194-1-lirongqing@baidu.com>
Hi Li,
On 9/24/2026 12:17 PM, lirongqing wrote:
> From: Li RongQing <lirongqing@baidu.com>
>
> iommu_poll_ga_log() accesses iommu_ga_log_notifier without an RCU
> read-side critical section, so synchronize_rcu() in the unregister
> path does not wait for an in-flight notifier callback.
>
> Use rcu_assign_pointer() when updating the notifier and
> rcu_dereference() under scoped_guard(rcu) when invoking it. Load the
> pointer once to close the race with unregister.
>
> Keep the RCU read-side critical section minimal: only the pointer load
> and the indirect notifier call stay inside scoped_guard(rcu). Move
> pr_debug and pr_err outside the section so that logging does not extend
> the window that synchronize_rcu() must wait for.
I didn't see your patch earlier and posted somewhat similar fix. But since you
posted earlier I will pick this. Can you please address below comments.
[1]
https://lore.kernel.org/linux-iommu/20261105041603.399016-4-vasant.hegde@amd.com/
>
> Signed-off-by: Li RongQing <lirongqing@baidu.com>
> ---
> drivers/iommu/amd/iommu.c | 30 +++++++++++++++++++-----------
> 1 file changed, 19 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
> index a06cd61..a31464a 100644
> --- a/drivers/iommu/amd/iommu.c
> +++ b/drivers/iommu/amd/iommu.c
> @@ -1054,11 +1054,11 @@ static void iommu_poll_events(struct amd_iommu *iommu)
> }
>
> #ifdef CONFIG_IRQ_REMAP
> -static int (*iommu_ga_log_notifier)(u32);
> +static int (__rcu *iommu_ga_log_notifier)(u32 ga_tag);
>
> int amd_iommu_register_ga_log_notifier(int (*notifier)(u32))
> {
> - iommu_ga_log_notifier = notifier;
> + rcu_assign_pointer(iommu_ga_log_notifier, notifier);
>
> /*
> * Ensure all in-flight IRQ handlers run to completion before returning
> @@ -1094,17 +1094,25 @@ static void iommu_poll_ga_log(struct amd_iommu *iommu)
>
> /* Handle GA entry */
> switch (GA_REQ_TYPE(log_entry)) {
> - case GA_GUEST_NR:
> - if (!iommu_ga_log_notifier)
> - break;
> -
> - pr_debug("%s: devid=%#x, ga_tag=%#x\n",
> - __func__, GA_DEVID(log_entry),
> - GA_TAG(log_entry));
> + case GA_GUEST_NR: {
> + int (*notifier)(u32 ga_tag);
> + int ret = 0;
> +
> + scoped_guard(rcu) {
Why we need scoped_guard()? we don't have multiple error condition to handle. I
think simple rcu_read_lock() -> call notifier stuff -> rcu_read_unlock() is
good enough. That way we can avoid multiple if(notifier) check as well.
-Vasant
> + notifier = rcu_dereference(iommu_ga_log_notifier);
> + if (notifier)
> + ret = notifier(GA_TAG(log_entry));
> + }
>
> - if (iommu_ga_log_notifier(GA_TAG(log_entry)) != 0)
> - pr_err("GA log notifier failed.\n");
> + if (notifier) {
> + pr_debug("%s: devid=%#x, ga_tag=%#x\n",
> + __func__, GA_DEVID(log_entry),
> + GA_TAG(log_entry));
> + if (ret)
> + pr_err("GA log notifier failed.\n");
> + }
> break;
> + }
> default:
> break;
> }
next prev parent reply other threads:[~2026-11-16 14:49 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-24 6:47 [PATCH] iommu/amd: RCU-protect iommu_ga_log_notifier lirongqing
2026-10-14 6:14 ` 答复: " Li,Rongqing
2026-11-16 14:48 ` Vasant Hegde [this message]
2026-11-17 2:18 ` 答复: [外部邮件] " Li,Rongqing
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=301430f5-c96a-42e2-bd81-de564650f9a9@amd.com \
--to=vasant.hegde@amd.com \
--cc=iommu@lists.linux.dev \
--cc=joro@8bytes.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lirongqing@baidu.com \
--cc=robin.murphy@arm.com \
--cc=suravee.suthikulpanit@amd.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 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.