Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp991756ybg; Wed, 3 Jun 2020 20:37:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzqeXMbAddfgCBvQFr0LWoFB27uGSB5OC+PYvVccD8xYejqHU1SZZ6xpT7B06KxK+/ZlCrK X-Received: by 2002:a05:6402:642:: with SMTP id u2mr2406329edx.230.1591241847885; Wed, 03 Jun 2020 20:37:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591241847; cv=none; d=google.com; s=arc-20160816; b=Gvk1T9o01tbYoFZ4nK3G92sBPwIumJqC7v1KEG0bIkTkb+vT2A2Egg1uplOkkbuKJD Zdxii9NpyeaAUxHz+sRFSDVXba+V4N/fw2gu8y5CCpLdljLYwBxuEc5UCBq4laPmZs43 v+zBiDbnwUUDYuaYHZVqYL7daDbbjtXm36SWSOh19qiDWjG7CMwpLOvKquyeRkiVyb61 ML5Y9vPrzoQFEkleqzzfj2hwTntateqnyhjAcAXAVY1hdj1kk12H5nAglrp2ZyZ+cgzh l6feLmg3V9e4jZDScZxS0U35C6+qc4BTa0pfmT0AN+e6HHzh2+x3tYF4xjTUEkEDKUNb jsiQ== 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=cYni1uVqqfou0Wg6BQUYul0ljOulcNsm9hKc69fYIKY=; b=lp+AdJQuqanhwZlfx6L3m1WTR/QATmozah96sMlDzK2t0m46vkhupgoU39kqQjyhfg ktLe+t45v0j1AW349A/vSYjiqTj4eQLjAoKbx33gy+zAcWEEOIlCTdNc4CbCwjYUB6Vd Yyuw7I9kt9k2UZ7fXOTIvUiAx1DF/95+oOTutxr3LOBLwoaZXgJS6EANHT0kJsu6xxkT aHon1T4QSkznMUpI5A3Sn6BFRfaRWPxTsQmhS+8s7oAEOmGCVXdwr78g2HXRk9Sktmsz 0HfCzu7Gu9rzPc7XzSD361A6rn4rQsg2HC0vwYT3X168+rgGqExCxOmVmlIy4Ysp8MMj pn3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=F8kKGoeQ; 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 z2si912842ejo.329.2020.06.03.20.37.05; Wed, 03 Jun 2020 20:37:27 -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=F8kKGoeQ; 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 S1727113AbgFDDeL (ORCPT + 99 others); Wed, 3 Jun 2020 23:34:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:32812 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726186AbgFDDeK (ORCPT ); Wed, 3 Jun 2020 23:34:10 -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 CE42C206DC; Thu, 4 Jun 2020 03:34:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591241649; bh=gt4qqSNeMEPnaSAiYD6PO8BVbCUAl+iOh1hthwO2Yz4=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=F8kKGoeQMHCcStKwKTGmR7SlI1ffeGcY5BuLwHDRWXMq5aFmzGmAFFPD4I03Tt2in MOEnf8DRvgjP9aGZVWObC9bFo2kZbwy39dMUSWSkp1NN9er6fo5NAN4K4Lw8PkvISK Jd7+gVFYKPdQ3+kTL5V+OXsL/c45wDep2PyPFWCY= Received: by paulmck-ThinkPad-P72.home (Postfix, from userid 1000) id B2EDE3522946; Wed, 3 Jun 2020 20:34:09 -0700 (PDT) Date: Wed, 3 Jun 2020 20:34:09 -0700 From: "Paul E. McKenney" To: Peter Zijlstra Cc: tglx@linutronix.de, x86@kernel.org, elver@google.com, kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, will@kernel.org, dvyukov@google.com, glider@google.com, andreyknvl@google.com Subject: Re: [PATCH 2/9] rcu: Fixup noinstr warnings Message-ID: <20200604033409.GX29598@paulmck-ThinkPad-P72> Reply-To: paulmck@kernel.org References: <20200603114014.152292216@infradead.org> <20200603114051.896465666@infradead.org> <20200603164600.GQ29598@paulmck-ThinkPad-P72> <20200603171320.GE2570@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200603171320.GE2570@hirez.programming.kicks-ass.net> 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 Wed, Jun 03, 2020 at 07:13:20PM +0200, Peter Zijlstra wrote: > On Wed, Jun 03, 2020 at 09:46:00AM -0700, Paul E. McKenney wrote: > > > > --- a/kernel/rcu/tree.c > > > +++ b/kernel/rcu/tree.c > > > @@ -250,7 +250,7 @@ static noinstr void rcu_dynticks_eqs_ent > > > * next idle sojourn. > > > */ > > > rcu_dynticks_task_trace_enter(); // Before ->dynticks update! > > > - seq = atomic_add_return(RCU_DYNTICK_CTRL_CTR, &rdp->dynticks); > > > + seq = arch_atomic_add_return(RCU_DYNTICK_CTRL_CTR, &rdp->dynticks); > > > > To preserve KCSAN's ability to see this, there would be something like > > instrument_atomic_write(&rdp->dynticks, sizeof(rdp->dynticks)) prior > > to the instrumentation_end() invoked before rcu_dynticks_eqs_enter() > > in each of rcu_eqs_enter() and rcu_nmi_exit(), correct? > > Yes. > > > > // RCU is no longer watching. Better be in extended quiescent state! > > > WARN_ON_ONCE(IS_ENABLED(CONFIG_RCU_EQS_DEBUG) && > > > (seq & RCU_DYNTICK_CTRL_CTR)); > > > @@ -274,13 +274,13 @@ static noinstr void rcu_dynticks_eqs_exi > > > * and we also must force ordering with the next RCU read-side > > > * critical section. > > > */ > > > - seq = atomic_add_return(RCU_DYNTICK_CTRL_CTR, &rdp->dynticks); > > > + seq = arch_atomic_add_return(RCU_DYNTICK_CTRL_CTR, &rdp->dynticks); > > > > And same here, but after the instrumentation_begin() following > > rcu_dynticks_eqs_exit() in both rcu_eqs_exit() and rcu_nmi_enter(), > > correct? > > Yep. > > > > // RCU is now watching. Better not be in an extended quiescent state! > > > rcu_dynticks_task_trace_exit(); // After ->dynticks update! > > > WARN_ON_ONCE(IS_ENABLED(CONFIG_RCU_EQS_DEBUG) && > > > !(seq & RCU_DYNTICK_CTRL_CTR)); > > > if (seq & RCU_DYNTICK_CTRL_MASK) { > > > - atomic_andnot(RCU_DYNTICK_CTRL_MASK, &rdp->dynticks); > > > + arch_atomic_andnot(RCU_DYNTICK_CTRL_MASK, &rdp->dynticks); > > > > This one is gone in -rcu. > > Good, because that would make things 'complicated' with the external > instrumentation call. And is actually the reason I didn't even attempt > it this time around. > > > > smp_mb__after_atomic(); /* _exit after clearing mask. */ > > > } > > > } > > > @@ -313,7 +313,7 @@ static __always_inline bool rcu_dynticks > > > { > > > struct rcu_data *rdp = this_cpu_ptr(&rcu_data); > > > > > > - return !(atomic_read(&rdp->dynticks) & RCU_DYNTICK_CTRL_CTR); > > > + return !(arch_atomic_read(&rdp->dynticks) & RCU_DYNTICK_CTRL_CTR); > > The above is actually instrumented by KCSAN, due to arch_atomic_read() > being a READ_ONCE() and it now understanding volatile. > > > Also instrument_atomic_write(&rdp->dynticks, sizeof(rdp->dynticks)) as Right, this should instead be instrument_read(...). Though if KCSAN is unconditionally instrumenting volatile, how does this help? Or does KCSAN's instrumentation of volatile somehow avoid causing trouble? > > follows: > > > > o rcu_nmi_exit(): After each following instrumentation_begin(). > > Yes > > > o In theory in rcu_irq_exit_preempt(), but as this generates code > > only in lockdep builds, it might not be worth worrying about. > > > > o Ditto for rcu_irq_exit_check_preempt(). > > > > o Ditto for __rcu_irq_enter_check_tick(). > > Not these, afaict they're all the above arch_atomic_read(), which is > instrumented due to volatile in these cases. > > > o rcu_nmi_enter(): After each following instrumentation_begin(). > > Yes > > > o __rcu_is_watching() is itself noinstr: > > > > o idtentry_enter_cond_rcu(): After each following > > instrumentation_begin(). > > > > o rcu_is_watching(): Either before or after the call to > > rcu_dynticks_curr_cpu_in_eqs(). > > Something like that yes. > > > > } > > > > > > /* > > > @@ -692,6 +692,7 @@ noinstr void rcu_nmi_exit(void) > > > { > > > struct rcu_data *rdp = this_cpu_ptr(&rcu_data); > > > > > > + instrumentation_begin(); > > > /* > > > * Check for ->dynticks_nmi_nesting underflow and bad ->dynticks. > > > * (We are exiting an NMI handler, so RCU better be paying attention > > > @@ -705,7 +706,6 @@ noinstr void rcu_nmi_exit(void) > > > * leave it in non-RCU-idle state. > > > */ > > > if (rdp->dynticks_nmi_nesting != 1) { > > > - instrumentation_begin(); > > > trace_rcu_dyntick(TPS("--="), rdp->dynticks_nmi_nesting, rdp->dynticks_nmi_nesting - 2, > > > atomic_read(&rdp->dynticks)); > > > WRITE_ONCE(rdp->dynticks_nmi_nesting, /* No store tearing. */ > > > @@ -714,7 +714,6 @@ noinstr void rcu_nmi_exit(void) > > > return; > > > } > > > > > > - instrumentation_begin(); > > > /* This NMI interrupted an RCU-idle CPU, restore RCU-idleness. */ > > > trace_rcu_dyntick(TPS("Startirq"), rdp->dynticks_nmi_nesting, 0, atomic_read(&rdp->dynticks)); > > > WRITE_ONCE(rdp->dynticks_nmi_nesting, 0); /* Avoid store tearing. */ > > > > This one looks to be having no effect on instrumentation of atomics, but > > rather coalescing a pair of instrumentation_begin() into one. > > > > Do I understand correctly? > > Almost, it puts the WARN_ON_ONCE()s under instrumentation_begin() too, > and that makes a differnce, iirc it was the > rcu_dynticks_curr_cpu_in_eqs() call that stood out. But that could've > been before I switched it to arch_atomic_read(). In any case, I find > this form a lot clearer. Got it, thank you. Thanx, Paul