Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3700629ybt; Tue, 23 Jun 2020 08:42:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzY7l/oCL/4xRACgnDPVteX+xWHQdC0NEOfB5kXHY3T2gD4+1H9ixDbJRumxmbqPCWnWs/f X-Received: by 2002:a17:906:5617:: with SMTP id f23mr19864860ejq.331.1592926976898; Tue, 23 Jun 2020 08:42:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592926976; cv=none; d=google.com; s=arc-20160816; b=OInZIVz92jfBOb11Z8Di3wuoz9cR9BdyNahlBpebVNJqhq3MVZSAHnajox6CT3M+Bi cmCvUKeZTRAWCdBpl5Dyn7jl+bUUboefVTNBHzq+8zX8/qc4z+nxhHjO+RV14RfG/l0E PbGjXqJ1rjYu0/6WI/VzxgcKc4WmlgBXyhyL9Sm2WAAX5c4q/8JOrAtl4bjcdelWK3Ba F6Xfy2AHkMEVjfTLvn4C8o/LR3XXk2tZ6f725Mm0cgsdBufz7Z5Zm9wU+Fnz/A9VeY2K IE0GJn6ghL+iuRNw6jwCuE04FwhH3oZZjt5T2wcIn5jFHUca22UVs9ukP8dDs1Vu+bjS Iu5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=yDHyunaNUffCIrfWoA6JStkb2E0XmAat1MijtVOdPZM=; b=lvRvu8Vtxr9d6JBt3ShQLlPYVwh5w4JHUbQ6CybKRfa678LrXzN2Whu55fcAHkek/N qOMO0rRdOGQXaZoBG71dtc320nzRXJ0ss+2gFCYQeRUWJ7pt0u5yF01A9/llreGV2xrf fFEBkrGedefQoRFktQXn9H5W42ncpJiGRgfxFJjkEY9x7uk1H6xnw/bahEDXCAoy9ntg GKqUsuer/7eiec11+7nqYLoZGmIqrr1V4fjSHt+IUexwuympcfPWaOqt+U9/S6OtlZkj FvORSP/e0FxG9GtiPwdjVgdAf0HAd0YXf2V3KEdCzC3I2xhuWsCqY4RYUgVy15a7wFlF XehQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1TBY+NtH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a1si9024635edn.58.2020.06.23.08.42.32; Tue, 23 Jun 2020 08:42:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1TBY+NtH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733095AbgFWPjE (ORCPT + 99 others); Tue, 23 Jun 2020 11:39:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:59410 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732521AbgFWPjC (ORCPT ); Tue, 23 Jun 2020 11:39:02 -0400 Received: from paulmck-ThinkPad-P72.home (50-39-105-78.bvtn.or.frontiernet.net [50.39.105.78]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 73A4E20723; Tue, 23 Jun 2020 15:39:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592926741; bh=+x1igQ+cwGJahoOJANLkVvcfFKTZ4z3VP4CCyxbX6vg=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=1TBY+NtHCatXMh0x3ApkXXBFe0f14Wt+7fwqLHvSh2/22tPRahTYUPd0jbTy++osU JSLNRJIaQnKZVNQMh6ggqiDcvvlq7D9makuUG4Yjlldmc3wbK9x6M8DH7UOExsZR4q s4OdTFfEb6fy23ojr1kND05pFsPLYxV26Fk8ia48= Received: by paulmck-ThinkPad-P72.home (Postfix, from userid 1000) id 5A3873522657; Tue, 23 Jun 2020 08:39:01 -0700 (PDT) Date: Tue, 23 Jun 2020 08:39:01 -0700 From: "Paul E. McKenney" To: Madhuparna Bhowmik Cc: Joel Fernandes , Paolo Bonzini , sean.j.christopherson@intel.com, vkuznets@redhat.com, wanpengli@tencent.com, jmattson@google.com, tglx@linutronix.de, bp@alien8.de, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, frextrite@gmail.com, linux-kernel-mentees@lists.linuxfoundation.org Subject: Re: [PATCH v2] kvm: Fix false positive RCU usage warning Message-ID: <20200623153901.GG9247@paulmck-ThinkPad-P72> Reply-To: paulmck@kernel.org References: <20200516082227.22194-1-madhuparnabhowmik10@gmail.com> <9fff3c6b-1978-c647-16f7-563a1cdf62ff@redhat.com> <20200623150236.GD9005@google.com> <20200623153036.GB9914@madhuparna-HP-Notebook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200623153036.GB9914@madhuparna-HP-Notebook> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 23, 2020 at 09:00:36PM +0530, Madhuparna Bhowmik wrote: > On Tue, Jun 23, 2020 at 11:02:36AM -0400, Joel Fernandes wrote: > > On Tue, Jun 23, 2020 at 09:39:53AM +0200, Paolo Bonzini wrote: > > > On 16/05/20 10:22, madhuparnabhowmik10@gmail.com wrote: > > > > From: Madhuparna Bhowmik > > > > > > > > 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 > > > > Signed-off-by: Madhuparna Bhowmik > > > > --- > > > > 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. > > > > You are right, this patch is wrong, we need a new SRCU list macro to do the > > right thing which would also get rid of the last list argument. > > > Can we really get rid of the last argument? We would need the > srcu_struct right for checking? Agreed! However, the API could be simplified by passing in a pointer to the srcu_struct instead of a lockdep expression. An optional lockdep expression might still be helpful for calls from the update side, of course. Thanx, Paul