From patchwork Mon Apr 9 00:18:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 132944 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp638753ljb; Sun, 8 Apr 2018 17:21:18 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+UW621i1VTKbWTGfwM6QDX2gHkzXsdINR/NHkBVaQM0q7B1xfVHMsFSHbynS8+5Zp5ziiW X-Received: by 2002:a17:902:784c:: with SMTP id e12-v6mr6545030pln.60.1523233278335; Sun, 08 Apr 2018 17:21:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523233278; cv=none; d=google.com; s=arc-20160816; b=OjYociMVRWRCF3is8Q+Tvta06cV83r2MepzTYSpnbq8seQcLAp+1+ZCB/hBablAGrL PC+7l/cq7v+9tczQ9l3rzCxlqDo9WhYLHgVryanigt6X088VqKlr8RHpFqQNsuMrS5Y/ GKKVa6L2Am6z3WElJ5e8XQdq+uReYMNltkgeEOo1i0U6DbYChRgUDtxYVfvwLRurET6y s3pX+sHSBtjTe4gvRamyaoKyv8a95MYMh9e3Pr+9+YFSj8cxHNsgTbIbAU5ha2jjwpn8 uDUJnU6XWTvIu3MHuZ2tn/I+DPGwlHK0lO1+hgSfYVK2Myh+OL/wUPcZkJwP/bMqxIv7 2PUA== 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=stxwsgx9ioubXT+0D3lj3L37pu/Ovc9bsbxI7EacnIg=; b=DZrNevsRmDZapzY6/aD50GZZLo7MilQCQsKLqCVjzJUq1lF6A8fk3eEsN0ohufKWHM xOmoggKAH3AX6zrB6PVqY+j5Xt57OE3OXYhyx90a1t5ggdDLRjmEcdRn9cPqWV6Gik3r nHCMJzAZ/5yz0kAyjKVjUN4Sfrrtm+gP144MkYnEt0rYqg3sXcGU3xAxera2eX/jv1TB zlZP6kJ2/4hIkfGx9LAnGXBlPOV1dianZ3S5IF9d6Yszfqcj5Hr6LZKZtkUdryx3eE7f mx2VND5cSC1okgTMLy1XXSIjLyco8qN3SJIWm7uf+5gQrpCucRz3oRY7W718icNDlOR8 3a8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=WaBHQccR; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 h10si10501424pgf.715.2018.04.08.17.21.18; Sun, 08 Apr 2018 17:21:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-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=WaBHQccR; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 S1754416AbeDIAVQ (ORCPT + 11 others); Sun, 8 Apr 2018 20:21:16 -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 S1754368AbeDIAVI (ORCPT ); Sun, 8 Apr 2018 20:21:08 -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=stxwsgx9ioubXT+0D3lj3L37pu/Ovc9bsbxI7EacnIg=; b=WaBHQccRAmOFov5WXrky5ngZofVCUgeHB3TCQ/R2tbLWNwidgQMi4oiLGq/XnN/kd3bx28rWJNxakjRt/ZL6QPqICZSkECwOlFB1y0SVjq+GdoDAHT6Yy518Q2iDSXh97Wz0hLCuN4I1M5pMVbND2NDduer+DV7uzn40mXvleJs= 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:01 +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:01 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Ulf Hansson , "Rafael J . Wysocki" , Sasha Levin Subject: [PATCH AUTOSEL for 4.15 158/189] PM / domains: Fix up domain-idle-states OF parsing Thread-Topic: [PATCH AUTOSEL for 4.15 158/189] PM / domains: Fix up domain-idle-states OF parsing Thread-Index: AQHTz5hYc68iXFq2Q0+F2Jj40Togrg== Date: Mon, 9 Apr 2018 00:18:55 +0000 Message-ID: <20180409001637.162453-158-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:TXIEWWtv8OiaDgTAfv4zxKJQ/teafIvgCo1XIOX3Js9iBejZtCKSlLxT1taIWEO/fCKmSR5y4cpGpW2jbn9IFkLd2ohH3JaIfVVkRHDfupA8bRyc/gG2vWGBL3Yk97VIKEnx+yJ7OffMGffGe1FKCR2vLA4/UwKym8aND94PU+GKts0l7CwoyIfU9ZUiC+AZsieTcH9GOpTXnzdrrjNeIBeIKtkFO618nztt4vM3ckt4u8ABhYpFZh5kMCJc1hj+; 20:j9c2R+YZOCqaKNN6IC9eQsi5W9Ss05+cUso0oURvFVTgSpVKl/uyHsiPvUH+yMLdiw/dAsXU1PtgsGd3RraseQZoT/t3uQGKkIeoHCTY60R22M1FNqbIfU8Q6lAQU5ZQkSz5WsrpD9P082avM2srYS4Kt8QHU28zj0gA0z9mfS0= X-MS-Office365-Filtering-Correlation-Id: 923574c2-2480-40cb-32e6-08d59dafc686 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)(89211679590171)(131327999870524)(228905959029699); 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)(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: 3FupOKxTxwJrs5JFnU1YJWR3V+lT1bjslPuEVHXAkZn6m0dc8SL9md5ne7Wk7oaJ8EvTAF7fVkVpHyAmIzUeP5duHkPc0nizxvvdWisWZYc9JK6nnVVC04TvuHG+z1Z9PxWxn5PiTNBVRvOkZG/tFUBBKWXWFSFEyYBZG9jPptIoK684TWKI+7oXrhhf0V3//UTwOqhcFIuQA6DD0L5D97ThN8tEi2FsDsvd3IgBnzYoO9QNSHCtUnBv4fz8tJAem7xXGvXBkQqMxMXP4bI9BCMJAOMjTou+l1Lj1uAGpSXNS94ZgvnSHv0d1zJ0zXMsg7DDihQ83hEhj+flLjIflquGKDK0J65BYBXKf/zabRYY9hTHxMzN7Pr2yAGSPj05HLpPoAoL6zwePKBqN/5Frpkc9dPuxAKv6W6lmuM5dSI= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 923574c2-2480-40cb-32e6-08d59dafc686 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:18:55.2526 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0920 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Ulf Hansson [ Upstream commit a3381e3a65cbaf612c8f584906c4dba27e84267c ] Commit b539cc82d493 (PM / Domains: Ignore domain-idle-states that are not compatible), made it possible to ignore non-compatible domain-idle-states OF nodes. However, in case that happens while doing the OF parsing, the number of elements in the allocated array would exceed the numbers actually needed, thus wasting memory. Fix this by pre-iterating the genpd OF node and counting the number of compatible domain-idle-states nodes, before doing the allocation. While doing this, it makes sense to rework the code a bit to avoid open coding, of parts responsible for the OF node iteration. Let's also take the opportunity to clarify the function header for of_genpd_parse_idle_states(), about what is being returned in case of errors. Fixes: b539cc82d493 (PM / Domains: Ignore domain-idle-states that are not compatible) Signed-off-by: Ulf Hansson Reviewed-by: Lina Iyer Signed-off-by: Rafael J. Wysocki Signed-off-by: Sasha Levin --- drivers/base/power/domain.c | 76 +++++++++++++++++++++++++++------------------ 1 file changed, 45 insertions(+), 31 deletions(-) -- 2.15.1 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 0c80bea05bcb..69520ad6f169 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -2293,6 +2293,38 @@ static int genpd_parse_state(struct genpd_power_state *genpd_state, return 0; } +static int genpd_iterate_idle_states(struct device_node *dn, + struct genpd_power_state *states) +{ + int ret; + struct of_phandle_iterator it; + struct device_node *np; + int i = 0; + + ret = of_count_phandle_with_args(dn, "domain-idle-states", NULL); + if (ret <= 0) + return ret; + + /* Loop over the phandles until all the requested entry is found */ + of_for_each_phandle(&it, ret, dn, "domain-idle-states", NULL, 0) { + np = it.node; + if (!of_match_node(idle_state_match, np)) + continue; + if (states) { + ret = genpd_parse_state(&states[i], np); + if (ret) { + pr_err("Parsing idle state node %pOF failed with err %d\n", + np, ret); + of_node_put(np); + return ret; + } + } + i++; + } + + return i; +} + /** * of_genpd_parse_idle_states: Return array of idle states for the genpd. * @@ -2302,49 +2334,31 @@ static int genpd_parse_state(struct genpd_power_state *genpd_state, * * Returns the device states parsed from the OF node. The memory for the states * is allocated by this function and is the responsibility of the caller to - * free the memory after use. + * free the memory after use. If no domain idle states is found it returns + * -EINVAL and in case of errors, a negative error code. */ int of_genpd_parse_idle_states(struct device_node *dn, struct genpd_power_state **states, int *n) { struct genpd_power_state *st; - struct device_node *np; - int i = 0; - int err, ret; - int count; - struct of_phandle_iterator it; - const struct of_device_id *match_id; + int ret; - count = of_count_phandle_with_args(dn, "domain-idle-states", NULL); - if (count <= 0) - return -EINVAL; + ret = genpd_iterate_idle_states(dn, NULL); + if (ret <= 0) + return ret < 0 ? ret : -EINVAL; - st = kcalloc(count, sizeof(*st), GFP_KERNEL); + st = kcalloc(ret, sizeof(*st), GFP_KERNEL); if (!st) return -ENOMEM; - /* Loop over the phandles until all the requested entry is found */ - of_for_each_phandle(&it, err, dn, "domain-idle-states", NULL, 0) { - np = it.node; - match_id = of_match_node(idle_state_match, np); - if (!match_id) - continue; - ret = genpd_parse_state(&st[i++], np); - if (ret) { - pr_err - ("Parsing idle state node %pOF failed with err %d\n", - np, ret); - of_node_put(np); - kfree(st); - return ret; - } + ret = genpd_iterate_idle_states(dn, st); + if (ret <= 0) { + kfree(st); + return ret < 0 ? ret : -EINVAL; } - *n = i; - if (!i) - kfree(st); - else - *states = st; + *states = st; + *n = ret; return 0; } From patchwork Mon Apr 9 00:19:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 132945 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp639154ljb; Sun, 8 Apr 2018 17:21:58 -0700 (PDT) X-Google-Smtp-Source: AIpwx48x3qk3p1ZID9dtYYqJCe6MD3U3Ghv4JcgJpGddwCGooOJn0tVnxhtSsflDa+gG0rrplkSW X-Received: by 2002:a17:902:60cf:: with SMTP id k15-v6mr36169975pln.44.1523233318327; Sun, 08 Apr 2018 17:21:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523233318; cv=none; d=google.com; s=arc-20160816; b=LnwWTvN9UuWWCu7fZr2Q4ytSVvP2xNDfHNPRVKcOAUEAigYr/9mDoJHVo9wBKkHAo9 zrnee89sbc69CTOljojuZWg+mcs2Eld5CBtQpZpbikAomdg9teHfnlE5Yn/s2GSwNFCh xKjxJFfV8O6nLDtHDEZB7dxpJZ8ilcMYq3tbmPAFkEJ6dVusj/f+cl5aulDK71d5b3Mw MLKGeBDDW8YPEx+lihr9jJhq07kL11Kxb0QAlOA7nh9j7CgQte3x/JAChRsVIBSmWqYL ZiE1xkZVOs1EiLDXhY5fgx6OFIw9Qw+L8+HP89sdwF1b6/VQETyNdaNBwHWEkTh/4Akk BJGw== 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=eupEr1OImIC1dqrHon02FUZNbis2rWHcIzoICgpkI+s=; b=T6CnSE5JoeiL1J80bvb84IxawfnL9wR8tTk9DVd5xiDTY2LjzOW4+yuwORcLxEIwat SL2puQu6IVDE0WIH2oCxgURDZ64tysJBxARMTjoqm8X72X2zjv/TSlcx8tJ3pGVY2lIH qh4SzhMY4sgL8zMyqpligX65jA0P9h4573P1SKw5+4XXcnn+XW7n4UEdSBR415JOdNxW NcFlHo2b13JeNRaEY0kL+wpGHK+rQXiLLGflyD6EW+ySBYOC6WELZvj9B5IXRsMMFW5+ BJ1VRPZ4qVMGAVKDC16zwy8ocWnz3Hl+9EpbmAHW6j3xbRlcXtb9uAk+v6oH5xPeHmEv T8QA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=m/8/xtTB; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 q1-v6si13062667plb.349.2018.04.08.17.21.58; Sun, 08 Apr 2018 17:21:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-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=m/8/xtTB; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 S1754524AbeDIAVy (ORCPT + 11 others); Sun, 8 Apr 2018 20:21:54 -0400 Received: from mail-bl2nam02on0124.outbound.protection.outlook.com ([104.47.38.124]:27520 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754514AbeDIAVw (ORCPT ); Sun, 8 Apr 2018 20:21:52 -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=eupEr1OImIC1dqrHon02FUZNbis2rWHcIzoICgpkI+s=; b=m/8/xtTBKFcSEnKZLOe7dZUYOYSIIZsib93mcpWZZijqMRez8xS6T4pH1zDp3qTEzFtinLUO9Vn0TH83QAnSTAgEY4o8bc7cJnFOI++I0HKJNJ7c2v6TxHWCwO/ggC9LA0jQFDH96xikmi9ABNxJSvcl3VvIBqYvkk31hlkKveQ= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB1125.namprd21.prod.outlook.com (52.132.130.150) 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:50 +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:50 +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.15 184/189] locking/qspinlock: Ensure node->count is updated before initialising node Thread-Topic: [PATCH AUTOSEL for 4.15 184/189] locking/qspinlock: Ensure node->count is updated before initialising node Thread-Index: AQHTz5hjB8f5t6qcs0yvvTsHcbKj2g== Date: Mon, 9 Apr 2018 00:19:14 +0000 Message-ID: <20180409001637.162453-184-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; DM5PR2101MB1125; 7:8khjXMp6EbU5LHbjQS84+CW+TCZM/FTdOYCTkIgKW4QVAGil5MUHtmETiQZREqrR5SoPQbcre6CzDS30CxPdBdf+6v9kpemmcpoUk1LCPrsWsIQ7gFJVGRVJZ1r0Zurg9e82uDKb7t011QYR9+Cj6GJqsWMjAheLgwwbJD0+u9R/hxqt4DFCCsxIwEX7K5KwnAsl+S+xef8m/UsNJMRKrbZC5+idaUjnaNNYXZCpPE3mAJmzPq0C0PcmXATAmYBb; 20:ujbLrDDs0+6jcl4SV/W+YfoPPLm3CalB9lsjPNeZ3Gswv/ZTOIPkvnT2czJ2MJEusK9Jn0lMReitfANVSav2ah9Jq10i8G2yfQ27csThYfOsOWBcPE+PJdMZGzUDJeFgzP3Co5BgrK7CjxEtrL/kLb+cTEFhN039Px7/OHq39mc= X-MS-Office365-Filtering-Correlation-Id: 7fc6e134-e863-476c-f5d9-08d59dafe39b 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:DM5PR2101MB1125; x-ms-traffictypediagnostic: DM5PR2101MB1125: 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)(3002001)(93006095)(93001095)(10201501046)(6055026)(61426038)(61427038)(6041310)(20161123560045)(20161123564045)(20161123558120)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011); SRVR:DM5PR2101MB1125; BCL:0; PCL:0; RULEID:; SRVR:DM5PR2101MB1125; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(366004)(376002)(396003)(39380400002)(39860400002)(346002)(199004)(189003)(51234002)(105586002)(7736002)(8676002)(97736004)(81166006)(59450400001)(106356001)(966005)(81156014)(305945005)(14454004)(66066001)(1076002)(102836004)(5250100002)(478600001)(2501003)(2900100001)(22452003)(72206003)(68736007)(26005)(86362001)(8936002)(76176011)(6506007)(6116002)(6486002)(186003)(5660300001)(6306002)(3660700001)(316002)(54906003)(110136005)(25786009)(2906002)(10090500001)(6512007)(3280700002)(6666003)(10290500003)(53936002)(99286004)(86612001)(3846002)(6436002)(486006)(4326008)(2616005)(11346002)(107886003)(36756003)(476003)(446003)(22906009)(217873001); DIR:OUT; SFP:1102; SCL:1; SRVR:DM5PR2101MB1125; 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: C7xk4qsiqvQq7PUpbTRyY5B11EvboGxceJfdfynR9KuXgiYso+HtUpD89XNXQBkXfpDTGBPlx86Yb/D4G2nnQNqIbeJnde+PESv/BHt0+41nY+sHaT/AXK845wFNs4i1B+blPximBMpwU19JTVa7w3/nta6PyjMMsvw56i9/fJP4JiIDmqLBDNHGLjk59eFOM1G2+ammDjLRXe4XVN4Fq+dNwj5ElADHxmjzaxLNdWKlZJwjwUsgpmo7hzhpPc0miUUlrAjGw9Jf6sTlK/PejjPtwdv7ZrHaU7f3rFtmAVqDaARjAaKTw/LI8ZqQiYsC8doBJvSFp8x1cY5uL65ZSFrEuuSBUQNLRTF0dX/OLjI4PSwMtaxxo8e8veHUW40kHwmJorl+31m7O9BKeijSa4XDdNNG39aKd2nF+IEIiZQ= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7fc6e134-e863-476c-f5d9-08d59dafe39b X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:19:14.1737 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1125 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@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 294294c71ba4..50dc42aeaa56 100644 --- a/kernel/locking/qspinlock.c +++ b/kernel/locking/qspinlock.c @@ -379,6 +379,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);