Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752789AbbBXOrr (ORCPT ); Tue, 24 Feb 2015 09:47:47 -0500 Received: from mail-we0-f177.google.com ([74.125.82.177]:44900 "EHLO mail-we0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752401AbbBXOro (ORCPT ); Tue, 24 Feb 2015 09:47:44 -0500 Date: Tue, 24 Feb 2015 15:47:37 +0100 From: Ingo Molnar To: Greg KH Cc: Raghavendra K T , tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, torvalds@linux-foundation.org, konrad.wilk@oracle.com, pbonzini@redhat.com, peterz@infradead.org, paulmck@linux.vnet.ibm.com, waiman.long@hp.com, davej@redhat.com, oleg@redhat.com, x86@kernel.org, jeremy@goop.org, paul.gortmaker@windriver.com, ak@linux.intel.com, jasowang@redhat.com, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, xen-devel@lists.xenproject.org, riel@redhat.com, borntraeger@de.ibm.com, akpm@linux-foundation.org, a.ryabinin@samsung.com, sasha.levin@oracle.com, dave@stgolabs.net, stable@vger.kernel.org Subject: Re: [PATCH for stable] x86/spinlocks/paravirt: Fix memory corruption on unlock Message-ID: <20150224144737.GA26074@gmail.com> References: <1424769899-14158-1-git-send-email-raghavendra.kt@linux.vnet.ibm.com> <20150224141731.GA16033@kroah.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150224141731.GA16033@kroah.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3553 Lines: 86 * Greg KH wrote: > On Tue, Feb 24, 2015 at 02:54:59PM +0530, Raghavendra K T wrote: > > Paravirt spinlock clears slowpath flag after doing unlock. > > As explained by Linus currently it does: > > prev = *lock; > > add_smp(&lock->tickets.head, TICKET_LOCK_INC); > > > > /* add_smp() is a full mb() */ > > > > if (unlikely(lock->tickets.tail & TICKET_SLOWPATH_FLAG)) > > __ticket_unlock_slowpath(lock, prev); > > > > which is *exactly* the kind of things you cannot do with spinlocks, > > because after you've done the "add_smp()" and released the spinlock > > for the fast-path, you can't access the spinlock any more. Exactly > > because a fast-path lock might come in, and release the whole data > > structure. > > > > Linus suggested that we should not do any writes to lock after unlock(), > > and we can move slowpath clearing to fastpath lock. > > > > So this patch implements the fix with: > > 1. Moving slowpath flag to head (Oleg): > > Unlocked locks don't care about the slowpath flag; therefore we can keep > > it set after the last unlock, and clear it again on the first (try)lock. > > -- this removes the write after unlock. note that keeping slowpath flag would > > result in unnecessary kicks. > > By moving the slowpath flag from the tail to the head ticket we also avoid > > the need to access both the head and tail tickets on unlock. > > > > 2. use xadd to avoid read/write after unlock that checks the need for > > unlock_kick (Linus): > > We further avoid the need for a read-after-release by using xadd; > > the prev head value will include the slowpath flag and indicate if we > > need to do PV kicking of suspended spinners -- on modern chips xadd > > isn't (much) more expensive than an add + load. > > > > Result: > > setup: 16core (32 cpu +ht sandy bridge 8GB 16vcpu guest) > > benchmark overcommit %improve > > kernbench 1x -0.13 > > kernbench 2x 0.02 > > dbench 1x -1.77 > > dbench 2x -0.63 > > > > [Jeremy: hinted missing TICKET_LOCK_INC for kick] > > [Oleg: Moving slowpath flag to head, ticket_equals idea] > > [PeterZ: Detailed changelog] > > > > Reported-by: Sasha Levin > > Suggested-by: Linus Torvalds > > Signed-off-by: Raghavendra K T > > Reviewed-by: Oleg Nesterov > > Acked-by: David Vrabel > > --- > > arch/x86/include/asm/spinlock.h | 94 ++++++++++++++++++++--------------------- > > arch/x86/kernel/kvm.c | 7 ++- > > arch/x86/xen/spinlock.c | 7 ++- > > 3 files changed, 58 insertions(+), 50 deletions(-) > > > > Changes for stable: > > - Don't replace the ACCESS_ONCE to READ_ONCE which would cause horraneous > > Compiler warnings (Linus, David Vbriel, PeterZ, Ingo) > > What is the git commit id of this in Linus's tree? What > stable tree(s) do you want this applied to? It's: d6abfdb20223 x86/spinlocks/paravirt: Fix memory corruption on unlock You'll also need this fix from Linus to avoid (harmless) build warnings: dd36929720f4 kernel: make READ_ONCE() valid on const arguments Thanks, Ingo -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/