Received: by 10.192.165.148 with SMTP id m20csp540334imm; Wed, 25 Apr 2018 03:58:28 -0700 (PDT) X-Google-Smtp-Source: AIpwx49XaDmauYoK8DJIoOIrqHOQ08X1a0DUGZWo7lJzVNKuwKE5sGaiod2uPOrqsx0wnIQfMCQR X-Received: by 10.98.64.91 with SMTP id n88mr27621872pfa.229.1524653908637; Wed, 25 Apr 2018 03:58:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524653908; cv=none; d=google.com; s=arc-20160816; b=OyFC0pkw4/sCAVrjS9hWjYDp3kTUUosjJBIN3fXvbMLDVHn4/KxsmybhE7IA/zh5/M XmY/1FeX5FmUgC0WJ32bu1F5h1xg8BuO4tzBvk9MbzJUr6iXi6Dyd4VohTn5OCaMf+WV T/vBQLj4xiOxIcHtR+gEqzWNLvkVJp1gz7gnAmxCf0ktg981oIU027JUywfcP3oObFUv YfvdmrPa/T/ckYS6hmKlwPGApKSov0AH6nDSJ0PI1Yqbvyx6x1LR1Z0Jy523pLCrCuUB QSqTZRF5EyQZroo4+ksluGONtYUsMNnXcFfb+fAnX90RYbvmAcIbCfjq8PFM+XIKnfOv +2Mg== 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 :arc-authentication-results; bh=Y21n68hYk7lAsvbOYeXgxri4g1Asy3LTwMgnlU/xwzo=; b=iUVDI5TjzfdXphHVU9ulqsAsNIbisFtyUOHI+5Q5WRnY8IylcV7MNdMhOjagqZkeW8 Yur6lYjqV28NFStZi+KycQWXe/I01apbbNISTPyHNYu459DeNYFdzQaYtHxH8KuhQmwa V1DUV51RnCDEdt/ubz00GtKXgVMcuKn5ZznM3YuyURW4bG7kBD1nAMv9wRtcPPqwD1G/ V80vdRj6vb6jgv2JGEyfFu93is3+Twz+5M7dsEWz/hckzFjoxZKgchm/pBNS6tC88uxj tIV0MWSmJgAq4YbO/45rzWpggIH7bYrh3rId9k9hLVi1IyUYfqOLta05uX6YFaJy8ZTW k/DA== ARC-Authentication-Results: i=1; mx.google.com; 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 x24-v6si16946122pll.25.2018.04.25.03.58.14; Wed, 25 Apr 2018 03:58:28 -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; 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 S1754272AbeDYK4l (ORCPT + 99 others); Wed, 25 Apr 2018 06:56:41 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:52882 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752444AbeDYKnL (ORCPT ); Wed, 25 Apr 2018 06:43:11 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id AF39E49F; Wed, 25 Apr 2018 10:43:10 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Catalin Marinas , Will Deacon , Sasha Levin Subject: [PATCH 4.14 143/183] arm64: spinlock: Fix theoretical trylock() A-B-A with LSE atomics Date: Wed, 25 Apr 2018 12:36:03 +0200 Message-Id: <20180425103248.294024456@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180425103242.532713678@linuxfoundation.org> References: <20180425103242.532713678@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 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Will Deacon [ Upstream commit 202fb4ef81e3ec765c23bd1e6746a5c25b797d0e ] If the spinlock "next" ticket wraps around between the initial LDR and the cmpxchg in the LSE version of spin_trylock, then we can erroneously think that we have successfuly acquired the lock because we only check whether the next ticket return by the cmpxchg is equal to the owner ticket in our updated lock word. This patch fixes the issue by performing a full 32-bit check of the lock word when trying to determine whether or not the CASA instruction updated memory. Reported-by: Catalin Marinas Signed-off-by: Will Deacon Signed-off-by: Catalin Marinas Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- arch/arm64/include/asm/spinlock.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/arch/arm64/include/asm/spinlock.h +++ b/arch/arm64/include/asm/spinlock.h @@ -89,8 +89,8 @@ static inline int arch_spin_trylock(arch " cbnz %w1, 1f\n" " add %w1, %w0, %3\n" " casa %w0, %w1, %2\n" - " and %w1, %w1, #0xffff\n" - " eor %w1, %w1, %w0, lsr #16\n" + " sub %w1, %w1, %3\n" + " eor %w1, %w1, %w0\n" "1:") : "=&r" (lockval), "=&r" (tmp), "+Q" (*lock) : "I" (1 << TICKET_SHIFT)