linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: madhuparnabhowmik10@gmail.com, sean.j.christopherson@intel.com,
	vkuznets@redhat.com, wanpengli@tencent.com, jmattson@google.com,
	tglx@linutronix.de, bp@alien8.de
Cc: x86@kernel.org, kvm@vger.kernel.org,
	linux-kernel@vger.kernel.org, joel@joelfernandes.org,
	paulmck@kernel.org, frextrite@gmail.com,
	linux-kernel-mentees@lists.linuxfoundation.org,
	Paul McKenney <paulmck@linux.vnet.ibm.com>
Subject: Re: [PATCH v2] kvm: Fix false positive RCU usage warning
Date: Tue, 23 Jun 2020 09:39:53 +0200	[thread overview]
Message-ID: <9fff3c6b-1978-c647-16f7-563a1cdf62ff@redhat.com> (raw)
In-Reply-To: <20200516082227.22194-1-madhuparnabhowmik10@gmail.com>

On 16/05/20 10:22, madhuparnabhowmik10@gmail.com wrote:
> From: Madhuparna Bhowmik <madhuparnabhowmik10@gmail.com>
> 
> Fix the following false positive warnings:
> 
> [ 9403.765413][T61744] =============================
> [ 9403.786541][T61744] WARNING: suspicious RCU usage
> [ 9403.807865][T61744] 5.7.0-rc1-next-20200417 #4 Tainted: G             L
> [ 9403.838945][T61744] -----------------------------
> [ 9403.860099][T61744] arch/x86/kvm/mmu/page_track.c:257 RCU-list traversed in non-reader section!!
> 
> and
> 
> [ 9405.859252][T61751] =============================
> [ 9405.859258][T61751] WARNING: suspicious RCU usage
> [ 9405.880867][T61755] -----------------------------
> [ 9405.911936][T61751] 5.7.0-rc1-next-20200417 #4 Tainted: G             L
> [ 9405.911942][T61751] -----------------------------
> [ 9405.911950][T61751] arch/x86/kvm/mmu/page_track.c:232 RCU-list traversed in non-reader section!!
> 
> Since srcu read lock is held, these are false positive warnings.
> Therefore, pass condition srcu_read_lock_held() to
> list_for_each_entry_rcu().
> 
> Reported-by: kernel test robot <lkp@intel.com>
> Signed-off-by: Madhuparna Bhowmik <madhuparnabhowmik10@gmail.com>
> ---
> v2:
> -Rebase v5.7-rc5
> 
>  arch/x86/kvm/mmu/page_track.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/x86/kvm/mmu/page_track.c b/arch/x86/kvm/mmu/page_track.c
> index ddc1ec3bdacd..1ad79c7aa05b 100644
> --- a/arch/x86/kvm/mmu/page_track.c
> +++ b/arch/x86/kvm/mmu/page_track.c
> @@ -229,7 +229,8 @@ void kvm_page_track_write(struct kvm_vcpu *vcpu, gpa_t gpa, const u8 *new,
>  		return;
>  
>  	idx = srcu_read_lock(&head->track_srcu);
> -	hlist_for_each_entry_rcu(n, &head->track_notifier_list, node)
> +	hlist_for_each_entry_rcu(n, &head->track_notifier_list, node,
> +				srcu_read_lock_held(&head->track_srcu))
>  		if (n->track_write)
>  			n->track_write(vcpu, gpa, new, bytes, n);
>  	srcu_read_unlock(&head->track_srcu, idx);
> @@ -254,7 +255,8 @@ void kvm_page_track_flush_slot(struct kvm *kvm, struct kvm_memory_slot *slot)
>  		return;
>  
>  	idx = srcu_read_lock(&head->track_srcu);
> -	hlist_for_each_entry_rcu(n, &head->track_notifier_list, node)
> +	hlist_for_each_entry_rcu(n, &head->track_notifier_list, node,
> +				srcu_read_lock_held(&head->track_srcu))
>  		if (n->track_flush_slot)
>  			n->track_flush_slot(kvm, slot, n);
>  	srcu_read_unlock(&head->track_srcu, idx);
> 

Hi, sorry for the delay in reviewing this patch.  I would like to ask
Paul about it.

While you're correctly fixing a false positive, hlist_for_each_entry_rcu
would have a false _negative_ if you called it under
rcu_read_lock/unlock and the data structure was protected by SRCU.  This
is why for example srcu_dereference is used instead of
rcu_dereference_check, and why srcu_dereference uses
__rcu_dereference_check (with the two underscores) instead of
rcu_dereference_check.  Using rcu_dereference_check would add an "||
rcu_read_lock_held()" to the condition which is wrong.

I think instead you should add hlist_for_each_srcu and
hlist_for_each_entry_srcu macro to include/linux/rculist.h.

There is no need for equivalents of hlist_for_each_entry_continue_rcu
and hlist_for_each_entry_from_rcu, because they use rcu_dereference_raw.
 However, it's not documented why they do so.

Paul, do you have any objections to the idea?  Thanks,

Paolo


  reply	other threads:[~2020-06-23  7:40 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-16  8:22 [PATCH v2] kvm: Fix false positive RCU usage warning madhuparnabhowmik10
2020-06-23  7:39 ` Paolo Bonzini [this message]
2020-06-23 15:02   ` Joel Fernandes
2020-06-23 15:30     ` Madhuparna Bhowmik
2020-06-23 15:39       ` Paul E. McKenney
2020-06-23 15:43         ` Joel Fernandes
2020-06-23 17:49         ` Madhuparna Bhowmik
2020-06-23 19:34           ` Joel Fernandes
2020-06-23 15:29   ` Madhuparna Bhowmik

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=9fff3c6b-1978-c647-16f7-563a1cdf62ff@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=bp@alien8.de \
    --cc=frextrite@gmail.com \
    --cc=jmattson@google.com \
    --cc=joel@joelfernandes.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel-mentees@lists.linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=madhuparnabhowmik10@gmail.com \
    --cc=paulmck@kernel.org \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=sean.j.christopherson@intel.com \
    --cc=tglx@linutronix.de \
    --cc=vkuznets@redhat.com \
    --cc=wanpengli@tencent.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).