All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jarkko Sakkinen <jarkko@kernel.org>
To: "Li,Rongqing(ACG CCN)" <lirongqing@baidu.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>,
	Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
	Borislav Petkov <bp@alien8.de>, "x86@kernel.org" <x86@kernel.org>,
	"H . Peter Anvin" <hpa@zytor.com>,
	Kai Huang <kai.huang@intel.com>,
	"linux-sgx@vger.kernel.org" <linux-sgx@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: 答复: [PATCH][v2] x86/sgx: Use list_for_each_entry_srcu() for mm_list traversal
Date: Wed, 15 Apr 2026 05:49:36 +0300	[thread overview]
Message-ID: <ad78wMV3Au2yN4ko@kernel.org> (raw)
In-Reply-To: <484ff5a62fee43618b30bbafb1ab3723@baidu.com>

On Tue, Apr 14, 2026 at 07:47:54AM +0000, Li,Rongqing(ACG CCN) wrote:
> 
> 
> > From: Li RongQing <lirongqing@baidu.com>
> > 
> > In commit 1728ab54b4be ("x86/sgx: Add a page reclaimer") (v5.11),
> > list_for_each_entry_rcu() was used to traverse the enclave's mm_list.
> > However, this is incorrect because the list is protected by a Sleepable RCU (SRCU)
> > lock (encl->srcu).
> > 
> > Since commit 28875945ba98 ("rcu: Add support for consolidated-RCU reader
> > checking") (v5.4), RCU lockdep checking has become stricter. When
> > CONFIG_PROVE_RCU is enabled, using the standard list_for_each_entry_rcu()
> > while only holding an SRCU lock triggers "suspicious RCU usage" false positive
> > warnings, as it does not recognize SRCU read-side critical sections.
> > 
> > Fix this by switching to list_for_each_entry_srcu(), which was introduced
> > specifically for this purpose in commit ae2212a7216b
> > ("rculist: Introduce list/hlist_for_each_entry_srcu() macros") (v5.10).
> > This correctly associates the traversal with the SRCU lock and eliminates the
> > lockdep warnings.
> > 
> > Fixes: 1728ab54b4be ("x86/sgx: Add a page reclaimer")
> > Signed-off-by: Li RongQing <lirongqing@baidu.com>
> > Acked-by: Kai Huang <kai.huang@intel.com>
> > ---
> 
> Ping
> 
> thanks
> 
> [Li,Rongqing] 
> 
> 
> 
> > Diff with v1: rewrite changelog
> > 
> >  arch/x86/kernel/cpu/sgx/encl.c | 12 ++++++++----
> > arch/x86/kernel/cpu/sgx/main.c |  3 ++-
> >  2 files changed, 10 insertions(+), 5 deletions(-)
> > 
> > diff --git a/arch/x86/kernel/cpu/sgx/encl.c b/arch/x86/kernel/cpu/sgx/encl.c
> > index ac60ebd..91362d7 100644
> > --- a/arch/x86/kernel/cpu/sgx/encl.c
> > +++ b/arch/x86/kernel/cpu/sgx/encl.c
> > @@ -822,7 +822,8 @@ static struct sgx_encl_mm *sgx_encl_find_mm(struct
> > sgx_encl *encl,
> > 
> >  	idx = srcu_read_lock(&encl->srcu);
> > 
> > -	list_for_each_entry_rcu(tmp, &encl->mm_list, list) {
> > +	list_for_each_entry_srcu(tmp, &encl->mm_list, list,
> > +			srcu_read_lock_held(&encl->srcu)) {
> >  		if (tmp->mm == mm) {
> >  			encl_mm = tmp;
> >  			break;
> > @@ -933,7 +934,8 @@ const cpumask_t *sgx_encl_cpumask(struct sgx_encl
> > *encl)
> > 
> >  	idx = srcu_read_lock(&encl->srcu);
> > 
> > -	list_for_each_entry_rcu(encl_mm, &encl->mm_list, list) {
> > +	list_for_each_entry_srcu(encl_mm, &encl->mm_list, list,
> > +			srcu_read_lock_held(&encl->srcu)) {
> >  		if (!mmget_not_zero(encl_mm->mm))
> >  			continue;
> > 
> > @@ -1018,7 +1020,8 @@ static struct mem_cgroup
> > *sgx_encl_get_mem_cgroup(struct sgx_encl *encl)
> >  	 */
> >  	idx = srcu_read_lock(&encl->srcu);
> > 
> > -	list_for_each_entry_rcu(encl_mm, &encl->mm_list, list) {
> > +	list_for_each_entry_srcu(encl_mm, &encl->mm_list, list,
> > +			srcu_read_lock_held(&encl->srcu)) {
> >  		if (!mmget_not_zero(encl_mm->mm))
> >  			continue;
> > 
> > @@ -1212,7 +1215,8 @@ void sgx_zap_enclave_ptes(struct sgx_encl *encl,
> > unsigned long addr)
> > 
> >  		idx = srcu_read_lock(&encl->srcu);
> > 
> > -		list_for_each_entry_rcu(encl_mm, &encl->mm_list, list) {
> > +		list_for_each_entry_srcu(encl_mm, &encl->mm_list, list,
> > +				srcu_read_lock_held(&encl->srcu)) {
> >  			if (!mmget_not_zero(encl_mm->mm))
> >  				continue;
> > 
> > diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c
> > index 38b7fd2..581e0c4 100644
> > --- a/arch/x86/kernel/cpu/sgx/main.c
> > +++ b/arch/x86/kernel/cpu/sgx/main.c
> > @@ -120,7 +120,8 @@ static bool sgx_reclaimer_age(struct sgx_epc_page
> > *epc_page)
> > 
> >  	idx = srcu_read_lock(&encl->srcu);
> > 
> > -	list_for_each_entry_rcu(encl_mm, &encl->mm_list, list) {
> > +	list_for_each_entry_srcu(encl_mm, &encl->mm_list, list,
> > +			srcu_read_lock_held(&encl->srcu)) {
> >  		if (!mmget_not_zero(encl_mm->mm))
> >  			continue;
> > 
> > --
> > 2.9.4
> 


Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>

BR, Jarkko

  reply	other threads:[~2026-04-15  2:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-26  1:40 [PATCH][v2] x86/sgx: Use list_for_each_entry_srcu() for mm_list traversal lirongqing
2026-03-05  8:43 ` 答复: " Li,Rongqing(ACG CCN)
2026-04-14  7:47 ` Li,Rongqing(ACG CCN)
2026-04-15  2:49   ` Jarkko Sakkinen [this message]
2026-05-08  0:43     ` 答复: [????] Re: ??: " Li,Rongqing(ACG CCN)

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=ad78wMV3Au2yN4ko@kernel.org \
    --to=jarkko@kernel.org \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=kai.huang@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sgx@vger.kernel.org \
    --cc=lirongqing@baidu.com \
    --cc=mingo@redhat.com \
    --cc=tglx@kernel.org \
    --cc=x86@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.