Received: by 10.213.65.68 with SMTP id h4csp2116296imn; Sun, 8 Apr 2018 20:07:08 -0700 (PDT) X-Google-Smtp-Source: AIpwx48aErRoeCZxM4wHZhuXem0qlhnL5TjwEXu8SGtJPLuOq3kVUYj3OxgD37gF0OTse+1hoiYT X-Received: by 2002:a17:902:70c5:: with SMTP id l5-v6mr6929003plt.382.1523243228357; Sun, 08 Apr 2018 20:07:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523243228; cv=none; d=google.com; s=arc-20160816; b=osIvmQdtnokriwnzo6KfvfjbkAKttahG+Kbn4QIbD+bNE4b/TGDXY9A6MKtQ1KmzFR VtYa49omvwudToGEbZH+mdq8tzgImzJJ1uqoqKzWXFvufZT6tI4O6V5YPxSuNLlffPrF MKbHjUgvLue8FZ67Dl/yI1VLUooxsJEMQ++ZafykBrfxEj0INFMPdrFps5TdOmdnfYLt qT5YNDtv+hfN60w+ZGplZ5WvS/t6A+r7G6lgraE+zO8/ecAhdzoD8M/acRJ15snz9dPI Uvt/9Nats3TXULNw7EbNOo7IrMffMZ154zsy3BIBsXRjdIe2+RPMS/a0OyF51tRxGzT6 kT5A== 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=xv+MzhbRqk6xoDlsTW4eQIjUoBlwxhsDdVI7cKoOnXw=; b=S1Ycv8WAeVXSyjFnH/6E68kUvOJAqo1AhSj3Pz+FTYZStSkkStA6CXFbdylS8gFQ2V ut67frbp89UbJ64OZXSWxD3+ACCJ5rnfQwqbzoPdtmrFJ2t8WCjWQdwJsz4gwrUPk+Ux V5Jb509TcI1Xep2A2dU0Rg1c8daisT1TG6eY6hObdp0YqvXisCqIq+ItoOwRWHmTOulX Ts5TQg98du0Vh9JHsmGGtcsnaDfBJo6ed9sGdHTMhFNa7lijBpP6WqQykstLbZk/1tzH wy5kQgJ8Zj/AScgR7UJgu9bUdEZl5faQ5uuWIVgaBch3k55dEF6uCR+Y2VNQRkmrQkCo 5HjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=F83qCKav; 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 g1si10170913pgq.743.2018.04.08.20.06.31; Sun, 08 Apr 2018 20:07:08 -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=F83qCKav; 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 S932606AbeDIAfL (ORCPT + 99 others); Sun, 8 Apr 2018 20:35:11 -0400 Received: from mail-by2nam01on0115.outbound.protection.outlook.com ([104.47.34.115]:46358 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755215AbeDIAey (ORCPT ); Sun, 8 Apr 2018 20:34:54 -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=xv+MzhbRqk6xoDlsTW4eQIjUoBlwxhsDdVI7cKoOnXw=; b=F83qCKavyxGobMroE6msIaKQwWGIYRrbt767y76fe0MJPOtYpZv02HkUcgTPiWxmjmi7tlqYNsfxhRn3pJ4kWTyuLELQLC1B+Z7sP1J8BYlpzlM2M+ARMOuwTuA70T2VoWz8MB/NhRQSysIDsOJx7YHWJh+26f1i4lmTjO1B8uk= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0806.namprd21.prod.outlook.com (10.167.107.156) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.3; Mon, 9 Apr 2018 00:34:47 +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:47 +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.9 290/293] locking/qspinlock: Ensure node->count is updated before initialising node Thread-Topic: [PATCH AUTOSEL for 4.9 290/293] locking/qspinlock: Ensure node->count is updated before initialising node Thread-Index: AQHTz5lv3gsVWtfZGUasLrStRynHag== Date: Mon, 9 Apr 2018 00:26:43 +0000 Message-ID: <20180409002239.163177-290-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;DM5PR2101MB0806;7:1ndrlA44A433YTBiF9hzuo1/r+CnFonUkhwRowYMBaXrrgpknjXUF0M36g9Sy2yiiOPKS3X4hZEBOfDc2n4IqOan3rXL8/+eTdCRGd38SvidhJerCMNJvV8rCEeP9ECgdiGKcnmWOhwLaLvK6nudd9k8g1GXrz+ZG8FwmcCkZeCLwYFyuUvxJRtQ0gQGzRLE+Sr8X5IGtulQRgYITOaC3QKmvmzhFZeIeYHzIcH6xEarzpEnHoYYEORxy3i4uh1v;20:+DDIE07lPdCbTsnGxuV+pvwKvUCk+riDnzEDCvMcKScn4PT55WhQl+D0/s7jDj3OOpYiGE043QDHrF8jO2n1F8Axw36j6whfAcUFk7IqLykn7WihbI1gQ/jNT9u7pMuxAqisgIghwVQtOBCt2wTUGl1h/i5TRETacYVxkwTP15w= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: 9e1e4cc9-963b-4cea-aa9d-08d59db1b291 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB0806; x-ms-traffictypediagnostic: DM5PR2101MB0806: 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)(3231221)(944501327)(52105095)(93006095)(93001095)(10201501046)(3002001)(6055026)(61426038)(61427038)(6041310)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123560045)(20161123558120)(6072148)(201708071742011);SRVR:DM5PR2101MB0806;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0806; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(346002)(39860400002)(376002)(396003)(366004)(39380400002)(199004)(189003)(51234002)(2906002)(25786009)(2501003)(10290500003)(476003)(11346002)(446003)(97736004)(5250100002)(68736007)(2616005)(102836004)(6506007)(59450400001)(3846002)(3660700001)(486006)(3280700002)(305945005)(6666003)(99286004)(5660300001)(76176011)(1076002)(186003)(26005)(7736002)(6116002)(81156014)(81166006)(86612001)(4326008)(105586002)(10090500001)(2900100001)(54906003)(22452003)(316002)(36756003)(110136005)(107886003)(8676002)(6436002)(478600001)(53936002)(66066001)(6486002)(6512007)(6306002)(86362001)(966005)(14454004)(72206003)(8936002)(106356001)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0806;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: XxQAIEH+exP27PlsnBWaX1ypGExaaqEgVY0sT2yIKqpPiK5f2gHAHL921ak3XsJ+u9uEmPUsb3chzgM0K7O3YcNmkwSr07UiIEJ4Qt9mNw/kCASvb719FGfsaypzqtvDvgCVdRp6CXE2rk5ADp4uoOXWGqz0j+uDqnKPuUOy/5mak6oS+s+U+xmnMF1Afw1UXQc08JM67fdV4KrKexxyMSU2O2WA5VKK1VSUwrMYj3kBw85G6YWbJ6QrjZaf6pHzEaLJwFrTnPaYP5W+fU/yhJFN0+1Jm9j7X8FWBvah8gP5r48c+3RQaKXdXh5Lqe1rlsQu8AvqTJM+qv74fPFV+/XzZniWdG6kWv07xlQ8SzxcjMKCKzIN5TOgahGGlzsn0CJFgi0mI0NA9fTTUqyaFnqkkp13dAeOaFM7jhhML0Y= 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: 9e1e4cc9-963b-4cea-aa9d-08d59db1b291 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:26:43.2384 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0806 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.deaco= n@arm.com Signed-off-by: Ingo Molnar Signed-off-by: Sasha Levin --- kernel/locking/qspinlock.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/kernel/locking/qspinlock.c b/kernel/locking/qspinlock.c index b2caec7315af..a72f5df643f8 100644 --- a/kernel/locking/qspinlock.c +++ b/kernel/locking/qspinlock.c @@ -495,6 +495,14 @@ queue: tail =3D encode_tail(smp_processor_id(), idx); =20 node +=3D 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 =3D 0; node->next =3D NULL; pv_init_node(node); --=20 2.15.1