Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935158AbcKKRWE (ORCPT ); Fri, 11 Nov 2016 12:22:04 -0500 Received: from merlin.infradead.org ([205.233.59.134]:57552 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934330AbcKKRWB (ORCPT ); Fri, 11 Nov 2016 12:22:01 -0500 Date: Fri, 11 Nov 2016 18:22:03 +0100 From: Peter Zijlstra To: Martin Schwidefsky Cc: Thomas Gleixner , linux-kernel@vger.kernel.org Subject: Re: [PATCH] x86/preempt: do not clear PREEMPT_NEED_RESCHED on preempt count reset Message-ID: <20161111172203.GN3117@twins.programming.kicks-ass.net> References: <1478523660-733-1-git-send-email-schwidefsky@de.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1478523660-733-1-git-send-email-schwidefsky@de.ibm.com> User-Agent: Mutt/1.5.23.1 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1540 Lines: 44 On Mon, Nov 07, 2016 at 02:01:00PM +0100, Martin Schwidefsky wrote: > The per-cpu preempt count of x86 contains two values, the actual preempt > count and the inverted PREEMPT_NEED_RESCHED bit. If a corrupted preempt > count is detected the preempt_count_set function is used to reset the > preempt count. > > In case the inverted PREEMPT_NEED_RESCHED bit is zero at the time of the > reset, the preemption indication is lost. Use raw_cpu_cmpxchg_4 to reset > only the count part and leave the PREEMPT_NEED_RESCHED bit as it is. > > Signed-off-by: Martin Schwidefsky Thanks Martin! I don't suppose this really hurts too much; if we hit a warn where this restore is needed there are bigger problems, but given you've done the patch already and it does improve consistency, I've taken it. > --- > arch/x86/include/asm/preempt.h | 8 +++++++- > 1 file changed, 7 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h > index 17f2186..ec1f3c6 100644 > --- a/arch/x86/include/asm/preempt.h > +++ b/arch/x86/include/asm/preempt.h > @@ -24,7 +24,13 @@ static __always_inline int preempt_count(void) > > static __always_inline void preempt_count_set(int pc) > { > - raw_cpu_write_4(__preempt_count, pc); > + int old, new; > + > + do { > + old = raw_cpu_read_4(__preempt_count); > + new = (old & PREEMPT_NEED_RESCHED) | > + (pc & ~PREEMPT_NEED_RESCHED); > + } while (raw_cpu_cmpxchg_4(__preempt_count, old, new) != old); > } > > /* > -- > 1.9.1 >