From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Paul E. McKenney" Subject: Re: [PATCH RFC tip/core/rcu 1/2] srcu: Allow use of Tiny/Tree SRCU from both process and interrupt context Date: Tue, 6 Jun 2017 10:50:48 -0700 Message-ID: <20170606175048.GH3721@linux.vnet.ibm.com> References: <20170605220919.GA27820@linux.vnet.ibm.com> <1496700591-30177-1-git-send-email-paulmck@linux.vnet.ibm.com> <20170606172342.r4zicqm4jb3nbwsz@hirez.programming.kicks-ass.net> Reply-To: paulmck@linux.vnet.ibm.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: linux-kernel@vger.kernel.org, mingo@kernel.org, jiangshanlai@gmail.com, dipankar@in.ibm.com, akpm@linux-foundation.org, mathieu.desnoyers@efficios.com, josh@joshtriplett.org, tglx@linutronix.de, rostedt@goodmis.org, dhowells@redhat.com, edumazet@google.com, fweisbec@gmail.com, oleg@redhat.com, Paolo Bonzini , kvm@vger.kernel.org, Linus Torvalds To: Peter Zijlstra Return-path: Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:55996 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751638AbdFFRuy (ORCPT ); Tue, 6 Jun 2017 13:50:54 -0400 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v56HmtZb090262 for ; Tue, 6 Jun 2017 13:50:54 -0400 Received: from e12.ny.us.ibm.com (e12.ny.us.ibm.com [129.33.205.202]) by mx0a-001b2d01.pphosted.com with ESMTP id 2ax03734h8-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 06 Jun 2017 13:50:53 -0400 Received: from localhost by e12.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 6 Jun 2017 13:50:53 -0400 Content-Disposition: inline In-Reply-To: <20170606172342.r4zicqm4jb3nbwsz@hirez.programming.kicks-ass.net> Sender: kvm-owner@vger.kernel.org List-ID: On Tue, Jun 06, 2017 at 07:23:42PM +0200, Peter Zijlstra wrote: > On Mon, Jun 05, 2017 at 03:09:50PM -0700, Paul E. McKenney wrote: > > diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c > > index 3ae8474557df..157654fa436a 100644 > > --- a/kernel/rcu/srcutree.c > > +++ b/kernel/rcu/srcutree.c > > @@ -357,7 +357,7 @@ EXPORT_SYMBOL_GPL(cleanup_srcu_struct); > > > > /* > > * Counts the new reader in the appropriate per-CPU element of the > > - * srcu_struct. Must be called from process context. > > + * srcu_struct. > > * Returns an index that must be passed to the matching srcu_read_unlock(). > > */ > > int __srcu_read_lock(struct srcu_struct *sp) > > @@ -365,7 +365,7 @@ int __srcu_read_lock(struct srcu_struct *sp) > > int idx; > > > > idx = READ_ONCE(sp->srcu_idx) & 0x1; > > - __this_cpu_inc(sp->sda->srcu_lock_count[idx]); > > + this_cpu_inc(sp->sda->srcu_lock_count[idx]); > > smp_mb(); /* B */ /* Avoid leaking the critical section. */ > > return idx; > > } > > So again, the change is to make this an IRQ safe operation, however if > we have this balance requirement, the IRQ will not visibly change the > value and load-store should be good again, no? > > Or am I missing some other detail with this implementation? Unlike Tiny SRCU, Classic and Tree SRCU increment one counter (->srcu_lock_count[]) and decrement another (->srcu_unlock_count[]). So balanced srcu_read_lock() and srcu_read_unlock() within an irq handler would increment both counters, with no decrements. Therefore, __srcu_read_lock()'s counter manipulation needs to be irq-safe. Thanx, Paul