Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2515048imm; Mon, 28 May 2018 09:32:06 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoW3arasiv6GDv0Oa7nIwS3KVmsMgW0BilarRnL6ZMR6D2IYNcP+q21K1mlv6ISMSINBs5s X-Received: by 2002:a62:91b:: with SMTP id e27-v6mr14153498pfd.93.1527525126569; Mon, 28 May 2018 09:32:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527525126; cv=none; d=google.com; s=arc-20160816; b=RA4nkjF7kXsIgFJ58JSyzG7MzhS/C/C1BJH/WjVfL4PUUSi512eCkHczlWoujjLPPh xbpXDJ4VsqOS3gUOIyUD5qIXrf5fKyNmpW6l2sjHjgkmuB8PNyjgu+y1ZLpGTKFGuGZo FmKfB8FUZdjuHkpHHuF5hegC8oTI4KtrAjS+8WdouhTmyxMVqHpUGbmBZk0f8WVeFBKW 1VhzAUaFKgBKqrZjcu3jNpleMN1O59DdcthGytb9id6Vi+gcBwZFrT3HfcO+PuHt4W5c Jpc3cMdAyYG+yDiVL9HqZYK9x7OyoGJDfpuZYLgfcQ97yF1hWnpiOgVj41Ke0MpVw6lj j6Pw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=8N2Dt2i/qZD9ahKHNqY0Mvx79cJWTtxIESABpkfYHGA=; b=q3SNnpsxgNsMfQXssQBZUcQbyLBp+TXxjpfHIQCEQ0CKLSXGaANQJ9MpSTUMWJ6ITT 2R4XSTIPk5y2P1k1q4L023RKAxfjNo16fViY5+4HNiuqrpowktqRAzGOV1JT35VM7cgA roGDmoCyfjRoule4NMltXXM8DPHjpBkO2F4c5TNonCgxzAZUZB2WRUbVwiao5adYa5Y+ jiY6QQgZUDjkUXTuxBoJUHr4hguAWtYBAUZP6IHr5UdNhKbF44g6xeFlkXbcWf4llH5z L4PLv2cKcQbG7f1joF2GF6wkTBo3RFgmG6MB+Ho3AchZYmxW0c9WzSFvHdmP5oYqDgra AW6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=N58GWFKC; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v6-v6si31390511plp.60.2018.05.28.09.31.51; Mon, 28 May 2018 09:32:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=N58GWFKC; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S940119AbeE1QbX (ORCPT + 99 others); Mon, 28 May 2018 12:31:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:57598 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935402AbeE1KJ3 (ORCPT ); Mon, 28 May 2018 06:09:29 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (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 AA066208A6; Mon, 28 May 2018 10:09:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527502169; bh=hnH48IUuR2AzGd8+wnOU7yX6Oajritn76MLkioWlc6I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N58GWFKCuTA76rdSyCCAMh/SCMtMLmBFj150zXpOb+GdVfcPizkaV0PdCnPPVSzUZ xhJYHblemH56luwn3wZ8p8xvD9zqyCmH5PBylxks2lZWXdXlGgoeNwEkLP60qywbgT YASKhjIvRQzka0EadZfHU4v66gAJKJU2lzaPg1jQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Will Deacon , Andrea Parri , "Paul E. McKenney" , Alan Stern , Andrew Morton , Ivan Kokshaysky , Linus Torvalds , Matt Turner , Peter Zijlstra , Richard Henderson , Thomas Gleixner , linux-alpha@vger.kernel.org, Ingo Molnar , Sasha Levin Subject: [PATCH 3.18 070/185] locking/xchg/alpha: Fix xchg() and cmpxchg() memory ordering bugs Date: Mon, 28 May 2018 12:01:51 +0200 Message-Id: <20180528100056.780995508@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100050.700971285@linuxfoundation.org> References: <20180528100050.700971285@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Andrea Parri [ Upstream commit 472e8c55cf6622d1c112dc2bc777f68bbd4189db ] Successful RMW operations are supposed to be fully ordered, but Alpha's xchg() and cmpxchg() do not meet this requirement. Will Deacon noticed the bug: > So MP using xchg: > > WRITE_ONCE(x, 1) > xchg(y, 1) > > smp_load_acquire(y) == 1 > READ_ONCE(x) == 0 > > would be allowed. ... which thus violates the above requirement. Fix it by adding a leading smp_mb() to the xchg() and cmpxchg() implementations. Reported-by: Will Deacon Signed-off-by: Andrea Parri Acked-by: Paul E. McKenney Cc: Alan Stern Cc: Andrew Morton Cc: Ivan Kokshaysky Cc: Linus Torvalds Cc: Matt Turner Cc: Peter Zijlstra Cc: Richard Henderson Cc: Thomas Gleixner Cc: linux-alpha@vger.kernel.org Link: http://lkml.kernel.org/r/1519291488-5752-1-git-send-email-parri.andrea@gmail.com Signed-off-by: Ingo Molnar Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- arch/alpha/include/asm/xchg.h | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) --- a/arch/alpha/include/asm/xchg.h +++ b/arch/alpha/include/asm/xchg.h @@ -11,6 +11,10 @@ * Atomic exchange. * Since it can be used to implement critical sections * it must clobber "memory" (also for interrupts in UP). + * + * The leading and the trailing memory barriers guarantee that these + * operations are fully ordered. + * */ static inline unsigned long @@ -18,6 +22,7 @@ ____xchg(_u8, volatile char *m, unsigned { unsigned long ret, tmp, addr64; + smp_mb(); __asm__ __volatile__( " andnot %4,7,%3\n" " insbl %1,%4,%1\n" @@ -42,6 +47,7 @@ ____xchg(_u16, volatile short *m, unsign { unsigned long ret, tmp, addr64; + smp_mb(); __asm__ __volatile__( " andnot %4,7,%3\n" " inswl %1,%4,%1\n" @@ -66,6 +72,7 @@ ____xchg(_u32, volatile int *m, unsigned { unsigned long dummy; + smp_mb(); __asm__ __volatile__( "1: ldl_l %0,%4\n" " bis $31,%3,%1\n" @@ -86,6 +93,7 @@ ____xchg(_u64, volatile long *m, unsigne { unsigned long dummy; + smp_mb(); __asm__ __volatile__( "1: ldq_l %0,%4\n" " bis $31,%3,%1\n" @@ -127,9 +135,12 @@ ____xchg(, volatile void *ptr, unsigned * store NEW in MEM. Return the initial value in MEM. Success is * indicated by comparing RETURN with OLD. * - * The memory barrier is placed in SMP unconditionally, in order to - * guarantee that dependency ordering is preserved when a dependency - * is headed by an unsuccessful operation. + * The leading and the trailing memory barriers guarantee that these + * operations are fully ordered. + * + * The trailing memory barrier is placed in SMP unconditionally, in + * order to guarantee that dependency ordering is preserved when a + * dependency is headed by an unsuccessful operation. */ static inline unsigned long @@ -137,6 +148,7 @@ ____cmpxchg(_u8, volatile char *m, unsig { unsigned long prev, tmp, cmp, addr64; + smp_mb(); __asm__ __volatile__( " andnot %5,7,%4\n" " insbl %1,%5,%1\n" @@ -164,6 +176,7 @@ ____cmpxchg(_u16, volatile short *m, uns { unsigned long prev, tmp, cmp, addr64; + smp_mb(); __asm__ __volatile__( " andnot %5,7,%4\n" " inswl %1,%5,%1\n" @@ -191,6 +204,7 @@ ____cmpxchg(_u32, volatile int *m, int o { unsigned long prev, cmp; + smp_mb(); __asm__ __volatile__( "1: ldl_l %0,%5\n" " cmpeq %0,%3,%1\n" @@ -214,6 +228,7 @@ ____cmpxchg(_u64, volatile long *m, unsi { unsigned long prev, cmp; + smp_mb(); __asm__ __volatile__( "1: ldq_l %0,%5\n" " cmpeq %0,%3,%1\n"