All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Li,Rongqing" <lirongqing@baidu.com>
To: Joerg Roedel <joro@8bytes.org>,
	Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>,
	Vasant Hegde <vasant.hegde@amd.com>,
	"Will Deacon" <will@kernel.org>,
	Robin Murphy <robin.murphy@arm.com>,
	"iommu@lists.linux.dev" <iommu@lists.linux.dev>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: 答复: [PATCH] iommu/amd: RCU-protect iommu_ga_log_notifier
Date: Wed, 14 Oct 2026 06:14:12 +0000	[thread overview]
Message-ID: <204090a962c24642ab3d94aadaadc851@baidu.com> (raw)
In-Reply-To: <20260924064709.2194-1-lirongqing@baidu.com>

> 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.
> 

Ping

thanks

[Li,Rongqing] 


> 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) {
> +				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;
>  		}
> --
> 2.9.4


  reply	other threads:[~2026-10-14  6:16 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 [this message]
2026-11-16 14:48 ` Vasant Hegde
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=204090a962c24642ab3d94aadaadc851@baidu.com \
    --to=lirongqing@baidu.com \
    --cc=iommu@lists.linux.dev \
    --cc=joro@8bytes.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=suravee.suthikulpanit@amd.com \
    --cc=vasant.hegde@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.