From patchwork Mon Apr 9 00:29:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 132963 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp665317ljb; Sun, 8 Apr 2018 18:05:36 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+afLDq0jMitHCP7k8cC9caFOCryUnGTjULtsu7BHmt3vXpJyYBuZBx1jKzHsnLdggrIley X-Received: by 10.99.120.3 with SMTP id t3mr23273130pgc.56.1523235936783; Sun, 08 Apr 2018 18:05:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523235936; cv=none; d=google.com; s=arc-20160816; b=yRZfxDQthwAbc1XwhvjBhSk2GNGP9HVQhI5Hji0W3Hzahp8+J7f55U9YYJJ1wxvD2h 45wSMpnocgZOS0N4cCLkPz3khuN3rFRiiTZH6SxesJyg3yX6mXJTMLSdX4sYPCjNwTl2 PcPDFNshYfBHph1bAY8bZHjTcicCtwp5YBkni77LD5d/osi/ywTmogwTY+JJV6G8wgtU y+36yfj9gFPJz8lad24S2XzYdLaRGyf6lEGdgRyohZ3dE5A7H/4XHzSNWAUUNVqfERfn IjQNCYp8TWMg52c82SzAcmCaNFZoMDwM9FreMyqrJ1Lkl2a2ugIBfQdQeCCjav6X61FL 68pg== 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=SuHhaq51TqBEz+88A0d9BbfeOaOdTgWJBQhQOoFia9I=; b=Yb6Llr3Slr6D7AiPrRa0WGRIZ2IeOUgVelM4UsNtJxZLvsvomKMCcSRoiJvS78WlgI gYLloKjFG3NSWLqei22t2SuWhoglihoE+Y6FQ9SHJBPTJPeaC1anYys1ODKYoxX0gE1t eZo5D23E+8kqlru8dPu5nbQpOFYghB2Bv+Bu4lW4OIeb6btuCkeIr3eIXBio4lukB4jb ISwbO7KCW0jftphG2aC0CEfShwKEdWtlxUAMT3eQfdyF/Yv9CLgix86b+yRcN/SMg40M 4JjgHGUnT8cw7HdhIOFqVJvyBylzsNoNUHJQGo2xEhWU8FeEU9dCWh6KWKUpy1f7Xjhg kxnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=ZYfJ0XSh; 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 d5si10533138pgc.236.2018.04.08.18.05.36; Sun, 08 Apr 2018 18:05:36 -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=ZYfJ0XSh; 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 S933132AbeDIAjb (ORCPT + 29 others); Sun, 8 Apr 2018 20:39:31 -0400 Received: from mail-co1nam03on0103.outbound.protection.outlook.com ([104.47.40.103]:45124 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933110AbeDIAj0 (ORCPT ); Sun, 8 Apr 2018 20:39:26 -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=SuHhaq51TqBEz+88A0d9BbfeOaOdTgWJBQhQOoFia9I=; b=ZYfJ0XShR9gGdnWACp36PG4FZta6ciB+E+K0L+9UhnHNaABQdRTwSaT+dTrTHc3slNJCwAwdVXXXLADJ1RxG9jFoQb8GiB7hw1KAeaHWYmpdjeEKvBjKDzh3Xuzjo9yakdwo5ik1ZeOIaY8qMnAO5lEuP+A3rAJy062X1oyBhmQ= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB1047.namprd21.prod.outlook.com (52.132.128.16) 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:39:23 +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:39:23 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Will Deacon , Linus Torvalds , Thomas Gleixner , Ingo Molnar , Sasha Levin Subject: [PATCH AUTOSEL for 4.4 161/162] locking/qspinlock: Ensure node->count is updated before initialising node Thread-Topic: [PATCH AUTOSEL for 4.4 161/162] locking/qspinlock: Ensure node->count is updated before initialising node Thread-Index: AQHTz5nicqXB/srxrk62KE5Agd7zKg== Date: Mon, 9 Apr 2018 00:29:56 +0000 Message-ID: <20180409002738.163941-161-alexander.levin@microsoft.com> References: <20180409002738.163941-1-alexander.levin@microsoft.com> In-Reply-To: <20180409002738.163941-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; DM5PR2101MB1047; 7:uhup+F5q6U6FjtrCNZydskw9NxalxYvX+tSwRhptxkD/A8M43ba8vGZbNiO3UFP767OcDrRcCkdOoZ2OaK0gBLbhDBYj+ujkcvfqNN2E08ByUOO9AC8iAHbq5NLvcgayAOpKWWpc9IpYZHHjhM5/7sYzOK5G2+iIRC2wpJTrYUjTYyFSddnS7BN3IvwuKJPeWymTbpQqqzvO57n5hZvPeUgHIzVyfYT8tgja4SBxxjmr7S5k0CLXJEOyjj4ZRVXn; 20:6b/A41pcf/nfDeKsdWjHwH0huJ/csKbkvz08xYc4qIhnMgi93zNDw014chWFfFzTAz7uRfETS3teDrq65S9wpRu5anA5zOa13JcUYyVSCFJ0bVF4xnPrnnXxMJ9Ep1dCa6tIPz2yuPa8J4vmuyhc5TKgvExfEwo4H28/jOQPDC8= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: 17e2c5dd-39de-4871-fe22-08d59db25726 x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020); SRVR:DM5PR2101MB1047; x-ms-traffictypediagnostic: DM5PR2101MB1047: 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)(42068640409301); 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:DM5PR2101MB1047; BCL:0; PCL:0; RULEID:; SRVR:DM5PR2101MB1047; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(376002)(396003)(366004)(39860400002)(346002)(39380400002)(189003)(199004)(51234002)(97736004)(3660700001)(2900100001)(2906002)(8936002)(11346002)(3280700002)(106356001)(446003)(68736007)(72206003)(1076002)(966005)(86612001)(25786009)(3846002)(36756003)(107886003)(6116002)(81166006)(4326008)(486006)(81156014)(6306002)(6512007)(6436002)(53936002)(14454004)(8676002)(26005)(5250100002)(86362001)(105586002)(6666003)(305945005)(186003)(10290500003)(7736002)(10090500001)(102836004)(6486002)(2616005)(5660300001)(316002)(2501003)(66066001)(22452003)(54906003)(99286004)(110136005)(478600001)(59450400001)(476003)(76176011)(6506007)(22906009)(217873001); DIR:OUT; SFP:1102; SCL:1; SRVR:DM5PR2101MB1047; 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: iutPlE8DdaORd37gPk/wjAgcFPT5vYXpd2DttRGp0T+gcZT4jKveIOAalWIirrmo69Cw4i4ypqmoDPfe4j3hXBdTu0T+ttX8H3sk8FWxBC2AdH+ngZ+rjccr+J/C7bDNJy62gqO+J2koHZ2GJVBRGzWqcVztFmtZqheOTXJxwcQA1djlytkK2QZFWwC7Ek7Ex2Q+NYUuJO+nlXo3tItdlyuc9KozbRaoQQ9mZfhY8nR/6Zn6aMDteQl84bzE1oIGmiA3zmRI9vD5kM8rk5OktdWOJoyVYUGWiBsM5mL7D0Zce1/5huse+DfeLN/G1Di/zKSfe6SZgLDGu8wWNuaPi+AuydCdpPsteO04exHkEPSq7HageO9GdNP7C3xN3+dAEhRGiNjpHPVacmGCJF5av8+x/bOOzuXm+RkApg9V2Pg= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 17e2c5dd-39de-4871-fe22-08d59db25726 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:29:56.5684 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1047 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Will Deacon [ Upstream commit 11dc13224c975efcec96647a4768a6f1bb7a19a8 ] When queuing on the qspinlock, the count field for the current CPU's head node is incremented. This needn't be atomic because locking in e.g. IRQ context is balanced and so an IRQ will return with node->count as it found it. However, the compiler could in theory reorder the initialisation of node[idx] before the increment of the head node->count, causing an IRQ to overwrite the initialised node and potentially corrupt the lock state. Avoid the potential for this harmful compiler reordering by placing a barrier() between the increment of the head node->count and the subsequent node initialisation. Signed-off-by: Will Deacon Acked-by: Peter Zijlstra (Intel) Cc: Linus Torvalds Cc: Thomas Gleixner Link: http://lkml.kernel.org/r/1518528177-19169-3-git-send-email-will.deacon@arm.com Signed-off-by: Ingo Molnar Signed-off-by: Sasha Levin --- kernel/locking/qspinlock.c | 8 ++++++++ 1 file changed, 8 insertions(+) -- 2.15.1 diff --git a/kernel/locking/qspinlock.c b/kernel/locking/qspinlock.c index 8173bc7fec92..3b40c8809e52 100644 --- a/kernel/locking/qspinlock.c +++ b/kernel/locking/qspinlock.c @@ -423,6 +423,14 @@ queue: tail = encode_tail(smp_processor_id(), idx); node += idx; + + /* + * Ensure that we increment the head node->count before initialising + * the actual node. If the compiler is kind enough to reorder these + * stores, then an IRQ could overwrite our assignments. + */ + barrier(); + node->locked = 0; node->next = NULL; pv_init_node(node);