Received: by 10.213.65.68 with SMTP id h4csp2117074imn; Sun, 8 Apr 2018 20:08:04 -0700 (PDT) X-Google-Smtp-Source: AIpwx49B3IlCEFvozW8Kmo8JxFqtJR1Kz2U+na3PHEINo0D+oEYs2bnRkj/i+E/uixrGyWfXH2yI X-Received: by 10.101.66.139 with SMTP id j11mr17460611pgp.370.1523243284372; Sun, 08 Apr 2018 20:08:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523243284; cv=none; d=google.com; s=arc-20160816; b=qZNcrCB8upTFYzob4RN2R+UJBKbTGjP3562EXUDgkT4dGQA1hJcviHOQbkfhvnIEGD izgbsm398ARBO1+OZFff63mvWt/VQP/kyJOgy8EAW0f0nwc7pYmS5b/x0Pzf3B8JlBok gbJ8KoG1Fjahv5uatWeEFRPCJkKy9cn/dNWgpX7bShJUdHBZbW1J3ELUhz5hU666ajFP 1dmtJAaCXOwczL17O2ZIttVfPHB8hLrVZqXdQQqJRN0cCipIILe9XPtRDAJkQNu6z8k6 CBbMES/K2UCkwFgOB46aOr5RGX/w8csI5F6q306LEOPsa+1J9yKobgt9R1OZ6nda8I4D Daxg== 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=riR9+2EfNDX+3EEEA5aHSc1bIT1AsXhBrF9Tc09yC2o=; b=YlZRwijqsz2BJKQLO2LEs06y5LtCf4jITpeKAY0EoLRQtaD0LcXBoEWIWATi7OAGHm 286zqblXpAAsnRrDSKine3Tw1w3sEmx5V6BgwaOPbvd9l8IU7tx8HvdHGxSPYmqgYib1 1+pBfDsep/y8M1zDxiZjDVpdEsIgRodAs7YlWszvT1vWbIzkeN437l7NRQ0X41ObIARZ naQBruQ761AMI+aqhdOfAAQICxf6VA70Uky/0TRnhQHsVOm7mDq2sW8AF5USMFsPj1Pb PKNIAaCMVISkKguutEgB7/MQ7eQ4yvfRv0HIxeFrrM949/2fHLGg0VDc01USvSrIQDjb q5RQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=JeFqNDS6; 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 ba2-v6si1837664plb.110.2018.04.08.20.07.27; Sun, 08 Apr 2018 20:08:04 -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=JeFqNDS6; 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 S933115AbeDIBnj (ORCPT + 99 others); Sun, 8 Apr 2018 21:43:39 -0400 Received: from mail-bl2nam02on0118.outbound.protection.outlook.com ([104.47.38.118]:14317 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932507AbeDIAeo (ORCPT ); Sun, 8 Apr 2018 20:34:44 -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=riR9+2EfNDX+3EEEA5aHSc1bIT1AsXhBrF9Tc09yC2o=; b=JeFqNDS6XAvCu6nttZvCVhu7mccXAtfetBzwhVQL9Jzlx2HmMIG+rlt3ExcT1+VKIiEg2H5WJOicMmTusQcEoqz+fNOsRGgK1N7WKfgFCZtJ+Gh6/xASPF1tsjoJLD524hcz8cc0Q96vxSyu6+JVtOZwNJAgjbOIvHfBYvsPTjQ= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0984.namprd21.prod.outlook.com (52.132.133.30) 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:34:39 +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:34:39 +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.9 278/293] arm64: spinlock: Fix theoretical trylock() A-B-A with LSE atomics Thread-Topic: [PATCH AUTOSEL for 4.9 278/293] arm64: spinlock: Fix theoretical trylock() A-B-A with LSE atomics Thread-Index: AQHTz5lpxhT3G2BR4E+4+YbtX90x+Q== Date: Mon, 9 Apr 2018 00:26:33 +0000 Message-ID: <20180409002239.163177-278-alexander.levin@microsoft.com> References: <20180409002239.163177-1-alexander.levin@microsoft.com> In-Reply-To: <20180409002239.163177-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;DM5PR2101MB0984;7:OeMpJNifVrRG/4u2lSxZWiw0nMwwJ95VQO+qKkI0xsn+3ea5rKx6MeR7wgw2HWW9S7muE1mHl7T/ox02tdOe2v/qDuqEj6+lIfHaUxxmHuZxtNs/yFV5jR2TLZENGpd1j5m1FEHHhPhz2QRYNyRdGEIA1Za4kX0KZqp9+hsTYOhXsiblFFdxUnnVud97f1VURq/0eywEI0+e3XopGWVnAvsLHi5TYKRpKe63dGwzV72eyLkOupPadEbL0+YbBZGc;20:PaaPPMK7PEoYROjjbRrHuWywT/tPt4wJ+AdYIEQvS2ZU0Sia1xf3a5EEeBH8pfuZqAB+qdkW7zHRPGBP3oybo/xqVIDeNpMZhHzvIphnRXCAaT7jt0ApgqqAbeXBAQRRT454kdjsx/0ekU0I4JZoZLeQfwtw9qNelysEcXgPY+Q= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: 49ffd854-535a-4edf-72ec-08d59db1adf7 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB0984; x-ms-traffictypediagnostic: DM5PR2101MB0984: 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)(93006095)(93001095)(3231221)(944501327)(52105095)(3002001)(10201501046)(6055026)(61426038)(61427038)(6041310)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123564045)(20161123560045)(6072148)(201708071742011);SRVR:DM5PR2101MB0984;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0984; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(396003)(39860400002)(366004)(39380400002)(346002)(376002)(199004)(189003)(26005)(99286004)(2906002)(14454004)(97736004)(59450400001)(8676002)(81156014)(81166006)(8936002)(6512007)(106356001)(76176011)(186003)(3280700002)(10090500001)(36756003)(6506007)(66066001)(3660700001)(72206003)(478600001)(6666003)(53936002)(2900100001)(105586002)(102836004)(2501003)(110136005)(54906003)(5250100002)(486006)(1076002)(25786009)(6116002)(6436002)(11346002)(6486002)(22452003)(4326008)(446003)(7736002)(575784001)(86362001)(305945005)(2616005)(476003)(68736007)(3846002)(86612001)(5660300001)(10290500003)(107886003)(316002)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0984;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: XBWUnvs7v9zjHHSgihf5OmWbUYH+zzQPwUYL/WwxyS1x1faw2gwre3VCVt1NmKbZEZAEtz7s7pkURjxV0ia6Tem/DZENX9DZjIQqHpg4hBOdy1gql8ZdI4qscGII1TFxWnUmznME+7ELh4yQlCQ8P9xpomUyW4FmsQD9d3gqs4lx2Bd8zYew+lZ7+2lPuKmRWRQkur+rlp6yOtmvlK+PwGDEabQzef+5z9o4wCOBM3WscS1qNDcd95gW+64epEjsLayIYdzCTiFEpOyi25EJa3qss73WetB17oMmMMN0YCaLwdo7AbJO0wGMvXe9wKO355RMr2b491jXdIL45lgVpAZwLf8+d9y2eR+30KVpQS9dsV6i35RLSLNARTjzBHA5qQd3LeZz4oc066GR5lb1GqnaeBt7CDysWwUCnICRfx0= 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: 49ffd854-535a-4edf-72ec-08d59db1adf7 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:26:33.1289 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0984 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 cae331d553f8..a9d2dd03c977 100644 --- a/arch/arm64/include/asm/spinlock.h +++ b/arch/arm64/include/asm/spinlock.h @@ -141,8 +141,8 @@ static inline int arch_spin_trylock(arch_spinlock_t *lo= ck) " 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