Received: by 10.213.65.68 with SMTP id h4csp2122946imn; Sun, 8 Apr 2018 20:16:10 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+TO5j5wkse0KkezB+cCXPA0DxLv8Y/lYOtVuvxlja8b2xcfeX5u1YvVOlNzED9D/sLNm7b X-Received: by 10.98.149.78 with SMTP id p75mr28049380pfd.188.1523243770212; Sun, 08 Apr 2018 20:16:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523243770; cv=none; d=google.com; s=arc-20160816; b=H1z60Fmsjf7ViIFiAjFA6dW8XFYvbZ98zjQ58uD/j7K+XRp9jWKCHhoXURXG9FYqpG JW5FofnffLQDCajFE8um0ohK/mJ1bnPzhQicD2SSUHlKZEaCvN/A0iOPIxIFZPBeuJv3 qhAODTsbcg9WK3dBqlawKJvTjjEr7D9iTeXlrNrZNAdbO/IpLf/hMPKv5Zm5YVPErkMn JmVBsFB0sY5kfRrZ5UJxWMRZrYy0kjSwF+D3Mc9/DrIhQqPU/1aWoNh6GND131TP9mUW mC/7VB1myN9deC7QV2/1G+c9Xkk2ofnfMl3v1jpt84DFyVps74LKw+SmQhhFhtu+CVbw dXOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=BlXNlAgTp9S8jEG37OcL/gYITfmNCpxgjMHumNTaHXw=; b=QRpP8efdpnJkyTnjQBnOWn25Dij50mNGaTIUDYWpACFYlvagJVg9iGE4RfNb8dT+g/ 0GoA08iaanKVLjs741cd5wk3FvyaV9BMlzxA4NHe0GDldUqNssXRB0A6vTwpmP71U6uw RacvFhreQORW+7V3AVsbrkrIMl4x4fj6/naDTrZG2xRe9yGFPaah4JAiu4UiHq/7MaAt BaVc2Nyatu+2KIJX+BcPChw433TbymsH5cfqTy3UUjUpwOXGkhDz6LW0xBRSeToM8BQg A9kDqz6WUb8uR0dibTiRi7bdiP0AMzfELExHp90AoePGpwX+doqBTmMmZ/+729H1hT+x nnyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=AZcFYk96; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o13si4487753pgs.830.2018.04.08.20.15.33; Sun, 08 Apr 2018 20:16:10 -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=@microsoft.com header.s=selector1 header.b=AZcFYk96; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755551AbeDIC4g (ORCPT + 99 others); Sun, 8 Apr 2018 22:56:36 -0400 Received: from mail-bn3nam01on0139.outbound.protection.outlook.com ([104.47.33.139]:14848 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755238AbeDIAZp (ORCPT ); Sun, 8 Apr 2018 20:25:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=BlXNlAgTp9S8jEG37OcL/gYITfmNCpxgjMHumNTaHXw=; b=AZcFYk96uBqndpUK/zSudqRJ83k479fSQyRC4pJy15+vSAfjrqVa+5FpJnqEW2gp3/xO27YrWoUSou4ZZo2FtKSlQpRJQ6RDg61zSIaleuN69e2r2Ef0n8z4j1jQy+U+2jHDLvXDwkq90oLew9cExo5MGzblZtxTPUFc89Tinds= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB1013.namprd21.prod.outlook.com (52.132.133.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.0; Mon, 9 Apr 2018 00:25:38 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059%2]) with mapi id 15.20.0696.003; Mon, 9 Apr 2018 00:25:38 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Will Deacon , Catalin Marinas , Sasha Levin Subject: [PATCH AUTOSEL for 4.14 132/161] arm64: spinlock: Fix theoretical trylock() A-B-A with LSE atomics Thread-Topic: [PATCH AUTOSEL for 4.14 132/161] arm64: spinlock: Fix theoretical trylock() A-B-A with LSE atomics Thread-Index: AQHTz5i7h+yz/e0xr063sB6Ji34vSw== Date: Mon, 9 Apr 2018 00:21:41 +0000 Message-ID: <20180409001936.162706-132-alexander.levin@microsoft.com> References: <20180409001936.162706-1-alexander.levin@microsoft.com> In-Reply-To: <20180409001936.162706-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB1013;7:4GYVwL0ZKLBJynwCHcJop2D7HvY3mdAd66tQnKaOJ/OhRIo9JJl9Pu+jwq6fDHWlcroPBISSrRh3/nWb9icIGMi85tM1L0XYhR0l2uXF5oS+weRv8XbH74Qgaax4fCTrUWF58TvKNZcoRHpJ8VyffDVSA/1NOM8psHdZELRiDQU/h1rPSyJpZVT2VCZhL91TtB5xznOLK4cGFS6hyJTZ6lCOJ2Vit+p5zAxY8BdqRAJ7t8azKLH4yRyet1JZZdz5;20:thGQQ521mgPDf+dbzLfIHQRbwQWCgmO6K9fUZglt+IGCt/KZxVO3jR5buFJVNYyuOvi/eVja0NI/osInU+LWyhGYh9dqjUI+CAG/tn4grI1cJciKMCvqmsrHNQvSC3frA26NGNZtu5FaMz+4zgWm8sugH9BzKbkc21X09JNfmoo= X-MS-Office365-Filtering-Correlation-Id: a6ae9e19-711f-40f3-2739-08d59db06b76 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(3008032)(48565401081)(2017052603328)(7193020);SRVR:DM5PR2101MB1013; x-ms-traffictypediagnostic: DM5PR2101MB1013: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(180628864354917)(89211679590171); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(8121501046)(5005006)(3231221)(944501327)(52105095)(3002001)(93006095)(93001095)(10201501046)(6055026)(61426038)(61427038)(6041310)(20161123560045)(20161123564045)(20161123558120)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:DM5PR2101MB1013;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB1013; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(346002)(366004)(376002)(396003)(39860400002)(39380400002)(189003)(199004)(3280700002)(2616005)(8936002)(7736002)(476003)(446003)(11346002)(53936002)(3660700001)(86362001)(575784001)(86612001)(81156014)(2906002)(186003)(81166006)(105586002)(1076002)(8676002)(26005)(97736004)(25786009)(6512007)(3846002)(68736007)(72206003)(106356001)(5660300001)(6486002)(6666003)(6116002)(14454004)(4326008)(305945005)(6436002)(2501003)(5250100002)(10290500003)(478600001)(2900100001)(59450400001)(22452003)(110136005)(316002)(99286004)(66066001)(10090500001)(107886003)(76176011)(102836004)(54906003)(6506007)(36756003)(486006)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB1013;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: 4bWFjG/yn3GsJRIfTMXjONhrMCf8d7hfRpMmgNLSfSnj/H74q+hmeMw6xKpxw6Mn9saqvXNJeX2CkY5ZsnQ/SnrE3h4XwkwRt+dZJj8jG78/q/WlOE1YOawjuY+J4lhVc8sgGB/y5Tbhhd7p8VBH4k81ic0Eym9gZEE/AkxmFZFzpBPInXMm6l+nc/xv0AxTB+RPdKAepovqDLjLEYoHsII8zBaZp1lwUzDops/P2+cAB7oMhtvxsxDLQU11Ku/zs6JVvkc9sL7dL85rtnVeAMamFvSYr2m+bDTrylkVsngZNjQCHzNcFDVDKLKbV4TRDbr3wH8TnUe6+CLkLCTPVdjsyakCE/XOZQVHWpLkBAU6/hjJrLknNmTXNwrJDiozAignNNsZmP0f2mDYW5hKYLI3ztnskDwKSAdRfK/43Io= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: a6ae9e19-711f-40f3-2739-08d59db06b76 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:21:41.3624 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1013 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- arch/arm64/include/asm/spinlock.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/spinlock.h b/arch/arm64/include/asm/spi= nlock.h index 95ad7102b63c..82375b896be5 100644 --- 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_spinlock_t *lock= ) " 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:") : "=3D&r" (lockval), "=3D&r" (tmp), "+Q" (*lock) : "I" (1 << TICKET_SHIFT) --=20 2.15.1