Received: by 10.213.65.68 with SMTP id h4csp2141409imn; Sun, 8 Apr 2018 20:46:22 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/2p4OgI4c1sJF9tbJGM4d2AlPxgpqpX0ti9UNUczL0TT7jDExnifBCFRsbatuOtnQbuYLa X-Received: by 10.99.172.86 with SMTP id z22mr855989pgn.35.1523245582440; Sun, 08 Apr 2018 20:46:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523245582; cv=none; d=google.com; s=arc-20160816; b=ZcgvWSOxDV4Y43ugJhcKFzTFe37Fnt8QIFCUvLVhWa4by+WgLOTXA6i/UBP1zwqJd/ 3P6kz6uTDLgJF6Aqqh+uYDpdXXrBDYSHydVcPhTZn1CqjnaAqKaacSi3Vbll13IhSsIe SwKlwmzcFiX1LLck5WSSe4Gi0peZhJRJ23GR9aKSstx8QDcNipmQdm8wic4LCuFRRrio GsDVuMHfdjs+y3ZX2HR8CcNWzI5FgiTAP51OgyB3KUMaK+7c2QjS/6JhidxliYhBSzBR DOTNJXMwvjU1dq3CSv9V20IJkqw5JUGPx4gus6zfE92lz5svKKhArSkgA+SmehYg4sLa Y5Ww== 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=EI7gpy5sJQCccRlKHxeKKWWWMnOip8HrDdweQE4PcNc=; b=R/lLbEIdOL0IlA4lFivMZfK2Q0Jjypg9ISbHaZWOxMspjsSlUQV6LgS+PROPVOgIi3 FE3Mf5On+wbiTvR3lx/x4ay17kcDH6zxRVSbWMo5p55pr8VUCBPb2Ad4YSvLL5i7SGJs aK0nueKRIn0mZiFLURriV9zKvlMFrAJF7KBP2c0WuMyHCYwnxXjhrHi6JUrIOhXtHqbf YX2AsOYDozyvDyusH1emXp9EB0/3XvNtgDNeH21zialKp/eJBqOpKnh3ANMft2vgw4cE eiUhE2XiHSBO0io8yNLrCtZOcF2CEGajHhv81pcj705KXiG9yYQxK8UEMoCEgeBBRyXh DrOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=XmwsSsUN; 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 a31-v6si13661901pla.322.2018.04.08.20.45.45; Sun, 08 Apr 2018 20:46:22 -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=XmwsSsUN; 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 S1754361AbeDIDky (ORCPT + 99 others); Sun, 8 Apr 2018 23:40:54 -0400 Received: from mail-sn1nam01on0130.outbound.protection.outlook.com ([104.47.32.130]:47481 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753095AbeDIAVG (ORCPT ); Sun, 8 Apr 2018 20:21:06 -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=EI7gpy5sJQCccRlKHxeKKWWWMnOip8HrDdweQE4PcNc=; b=XmwsSsUN1EZ3yEdj6RrP5eUxwd/mKpP54pyIkZlQHzj3pgdt1dNDYqM0NhV1vihyTwMkJ/0+3otYqwxl85RAJWLNHhpSOtuhHLBWzbZwiJCAAYQ2K5Kt3hLPa23hJ73xiOzldGsid4gCYrib18n7Ziv2j+c+4laIHQDJNHeip/Q= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0920.namprd21.prod.outlook.com (52.132.132.165) 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:21:00 +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:21:00 +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.15 156/189] arm64: spinlock: Fix theoretical trylock() A-B-A with LSE atomics Thread-Topic: [PATCH AUTOSEL for 4.15 156/189] arm64: spinlock: Fix theoretical trylock() A-B-A with LSE atomics Thread-Index: AQHTz5hXrnHqT7NipEi+j2IpHQkKWQ== Date: Mon, 9 Apr 2018 00:18:53 +0000 Message-ID: <20180409001637.162453-156-alexander.levin@microsoft.com> References: <20180409001637.162453-1-alexander.levin@microsoft.com> In-Reply-To: <20180409001637.162453-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;DM5PR2101MB0920;7:KSL+az0CvQISkJdcK3UohJ1kYS+DJNXPsk+F8s2ijjZYt/VngH1vRUDjcqpSV4JlD7E6fzBMmQ1Nx0hG0ckfX2U8IRaEpbHuz6FlJGUou2mpR1Af7uv/6I/JCgY7qZOewYrEjDK/Qm83LJGCcmfKWNcCnn5NvXvGU7zFrEiLEQJRARclwuQyozL87aRcZ4f0u6EqBXLgIQQOhjn9RFBtKkvHRcAKSFeoKg2+8EJVWpvfIP/AEb9seXaCfdi7kJ4w;20:HlFQHDpy76vi/y81noRsdiR/MGHg1CswWc68oYq6JxKKFchHlOfkxUnNzI+ERMq2Bwjst7RJro9vC5tvGbZsA5QJ/0iv5OWWUDAv9ullZ+XEiCjxHHwfnUap/iaaA4ESKwdm+EMjMw2CvmnqdXwGZMYVqRJZN/J3f4YDdIlR/A8= X-MS-Office365-Filtering-Correlation-Id: f48875b7-4507-4501-b416-08d59dafc5a3 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:DM5PR2101MB0920; x-ms-traffictypediagnostic: DM5PR2101MB0920: 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:DM5PR2101MB0920;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0920; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39860400002)(39380400002)(396003)(366004)(346002)(376002)(199004)(189003)(66066001)(86362001)(59450400001)(3660700001)(3280700002)(25786009)(76176011)(2900100001)(36756003)(6506007)(2906002)(99286004)(86612001)(6486002)(102836004)(305945005)(1076002)(7736002)(575784001)(97736004)(2616005)(446003)(11346002)(476003)(486006)(26005)(6666003)(6512007)(4326008)(107886003)(5660300001)(478600001)(6436002)(105586002)(10290500003)(5250100002)(22452003)(316002)(186003)(8676002)(110136005)(81166006)(54906003)(6116002)(8936002)(72206003)(53936002)(2501003)(3846002)(68736007)(14454004)(81156014)(10090500001)(106356001)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0920;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: WyjfvOSQtdTAI7yQScZF0qo/5LXZ/4+l3RxFaop5EXBuOBMqoToaCgzUPZm3REhM/QdGf/ksBc8ItkU2Lbyrr6v8f6mNQ3tusTfI23L91FZmv9he92axoWQrFn1FJf4lyZQeAX2rAQRf4hxUWQsKPG/1ZyHCKxHKBsAMboBFmEmed9bvB6nhGZsZkLivkiq084SbYvqFteEzdDXzCMRqTui9ZN1Fm2yc0oCWuJuO6VornsmcP5ZxNVQP6hNVwUKbMzxR5nEQbDkcCSDtuHfi4yru+FoPDlys48M+gUUIT3oRTDRf0f4cCuHPiRTy6GD8Ln6fD9/iNbsN2u6HECpBoJCPD3qZo0MLmC3m/1LWRmgNo7R4oi+PoXbkVuG2pevQWDTAMzdGct4cM64nBCZIYlw+pOXUDesLa+r9e1Kd1SM= 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: f48875b7-4507-4501-b416-08d59dafc5a3 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:18:53.7214 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0920 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 fdb827c7832f..ebdae15d665d 100644 --- a/arch/arm64/include/asm/spinlock.h +++ b/arch/arm64/include/asm/spinlock.h @@ -87,8 +87,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