Received: by 10.213.65.68 with SMTP id h4csp43521imn; Mon, 19 Mar 2018 18:59:28 -0700 (PDT) X-Google-Smtp-Source: AG47ELvHqMtoQtCNqBQ4m8WSBBNWhhQnFpIinsk70Y+u6GVjyWaMJA4mOhxTfG2B5W4UcWIiGi88 X-Received: by 10.99.7.138 with SMTP id 132mr7234970pgh.45.1521511168298; Mon, 19 Mar 2018 18:59:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521511168; cv=none; d=google.com; s=arc-20160816; b=LRmDC0oCPGpHMM6oB0GaQofBEN3tA68Ub53nhGnOs8QQU/fPquBL5KIYmTmDZITEEr jQqzI51D+l3v7VWlTQJM5YUIZUyLGX9grSVIukVTVq5pUEw+V/ia03dRFTv5hJ3zGz5F AJEmYc4wOlAMfNtmmk8ibmmAOCnTycmwftCabpkI6V25QvKhXHxMtq3BOXlxaNTDF1Me zn3rcGmdANg6Yj7F64vb2Orey04vjtqdLBl5Gi46/DF+wEXILYPlEzRti8QSBIAxye6c XwDU0UPflYtpjv5nbTwUDPY9A9h4FC50lbdck0TuL5oCn9RGady2Jr7fmXjy3jqNpZUX 3LiA== 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=iuckPAtG4mPbMTp5dXpRcO8Xjpvsfhrrpb/wLYhCMwI=; b=PkxijEPvN/16YnuA4/+XkVnZI5Lt5zYWX6+h2KdiiP69etoFBlRKVOns/Xxsafd61Y RkJ/OkXwZV31ef2XaSX2p/iTCSKPVcCi1WOmHnbs958SQa+JWDKtL3TZktaic1o98JJ2 JhhFETsreIlK/A3wxwbmY5DGQMCBapwXOtrteUhneO0E4Mhozp3UXJYpiIuK77KSGDzn gqgyz+jzI522BIdue/6DOOvuMY/gqJaIrjsFtsDzrzK9uiuCrd0fWkbF3gt/YTueC0ni S5ymAhauZSZ7EY4SLfCoOJfRsxcUV90wP14qF5UuokroX7LrHM1ZvaS7V15MsZzQRH8y sXNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=Vy+t4KUn; 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 n3si394089pgc.12.2018.03.19.18.59.14; Mon, 19 Mar 2018 18:59:28 -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=Vy+t4KUn; 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 S972329AbeCSWQj (ORCPT + 99 others); Mon, 19 Mar 2018 18:16:39 -0400 Received: from mail-bl2nam02on0123.outbound.protection.outlook.com ([104.47.38.123]:41056 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S934012AbeCSPtv (ORCPT ); Mon, 19 Mar 2018 11:49:51 -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=iuckPAtG4mPbMTp5dXpRcO8Xjpvsfhrrpb/wLYhCMwI=; b=Vy+t4KUntwfaNattLEulBNSfWxL97dkIpfHMr9fR+MKYRbI72fnbFD/bbNrp/f33RVt5RBMD1v6xJ4gs2n64eQtc4xBkHgVbKm/wMs4sddhQhnQWVbbOZsW0HtFyhstFTpXLLT+oIV4uGQFYvQr/n1O4XZy14PTKLt3ejRq1tDU= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB1109.namprd21.prod.outlook.com (52.132.130.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.631.0; Mon, 19 Mar 2018 15:49:44 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::3d9b:79e7:94eb:5d62]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::3d9b:79e7:94eb:5d62%5]) with mapi id 15.20.0631.004; Mon, 19 Mar 2018 15:49:44 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: David Lechner , Stephen Boyd , Sasha Levin Subject: [PATCH AUTOSEL for 4.15 104/124] clk: fix reentrancy of clk_enable() on UP systems Thread-Topic: [PATCH AUTOSEL for 4.15 104/124] clk: fix reentrancy of clk_enable() on UP systems Thread-Index: AQHTv5nJGUwlmQMprEeYWg0XJMUefw== Date: Mon, 19 Mar 2018 15:48:56 +0000 Message-ID: <20180319154645.11350-104-alexander.levin@microsoft.com> References: <20180319154645.11350-1-alexander.levin@microsoft.com> In-Reply-To: <20180319154645.11350-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;DM5PR2101MB1109;7:o0oNp7mTAll79hwjwc/jRdz03JseUw29rVRIpCFol0C1By0KowcyXHWs1SHM/xi8f69+bJdZT3NfDgWPvBAs+x8OcV7BgFA36aw7nSV+NxityhoBr4uvUc2z4wej/3kr1gKgv1FAMcbaMH+/DaM4JFSCyj4nzvcpoQ8Vb+QViwF0ZBBwzzP5MKR6fOU7zyUHJsNDHf8WOXiiHo7y70/2v+dgg09YmjnEjkV9zedIhdvBZ1SiyFrborcYTh7EGnTB;20:P8RFMW19FWQeOB1hTqzdyNDahymC/uW+tcPmsQx33lUOvD60Mq147r5BRPMkIuqWbhL6Wl6/M1SenHfmybuQqazaLTj3zqXdGreqtZZIBQhMg5EavAXiL6QZ8V4EQ0TpNd8h8ZfnCRLVTAuCjsxT/qEKVgB/OaUsy6FGIrCoLvg= x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 37c56910-e4c4-4f3e-a822-08d58db108e6 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB1109; x-ms-traffictypediagnostic: DM5PR2101MB1109: 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); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(5005006)(8121501046)(3231221)(944501300)(52105095)(3002001)(93006095)(93001095)(10201501046)(6055026)(61426038)(61427038)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123562045)(20161123564045)(20161123558120)(6072148)(201708071742011);SRVR:DM5PR2101MB1109;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB1109; x-forefront-prvs: 06167FAD59 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(366004)(396003)(39860400002)(39380400002)(376002)(346002)(199004)(189003)(81166006)(10290500003)(107886003)(81156014)(106356001)(6506007)(8676002)(3846002)(36756003)(8936002)(97736004)(6116002)(1076002)(102836004)(68736007)(6666003)(3280700002)(2950100002)(3660700001)(478600001)(72206003)(59450400001)(2906002)(14454004)(76176011)(66066001)(6512007)(5250100002)(10090500001)(2501003)(53936002)(6486002)(6436002)(26005)(316002)(22452003)(305945005)(7736002)(4326008)(25786009)(86362001)(575784001)(86612001)(5660300001)(2900100001)(99286004)(54906003)(186003)(105586002)(110136005)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB1109;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: IepFU700ldisaeb5engKyK1oSHK4sxIBaZj4nWbARf5sM02v2oJZSnfVf9aY+fujmscZkqFzMZvFCJuWP8jQ8M5wotYfph/CcrB3/Ws8c5SBhD0neRF4j1RiKhcahWs/pVoqrK+x0J+Vsjpm0Bn83KPFbBCxHjgNhrmAyTIHl70v3T+UkWPvi503fZ1fpqoE3zxDSEyrMGxcnVg4WdKfaSYGXZyp3wEY0RB4DJ+RFrI6o5pLdKt/6awZhXoOL3+LjJbKwi6jv0eJbyR1dxRro8aBgKnIC6krLyRIu68hbqM8pKnCXkUbzBzWY94hsK7fs0oHbTBPsMMFkFu9T6NFRA== 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: 37c56910-e4c4-4f3e-a822-08d58db108e6 X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Mar 2018 15:48:56.2991 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1109 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: David Lechner [ Upstream commit a12aa8a68dfef5de181f2e555aa950a0ab05411f ] Reentrant calls to clk_enable() are not working on UP systems. This is caused by the fact spin_trylock_irqsave() always returns true when CONFIG_SMP=3Dn (and CONFIG_DEBUG_SPINLOCK=3Dn) which causes the reference counting to not work correctly when clk_enable_lock() is called twice before clk_enable_unlock() is called (this happens when clk_enable() is called from within another clk_enable()). This fixes the problem by skipping the call to spin_trylock_irqsave() on UP systems and relying solely on reference counting. We also make sure to set flags in this case so that we are not returning an uninitialized value. Suggested-by: Stephen Boyd Signed-off-by: David Lechner Signed-off-by: Stephen Boyd Signed-off-by: Sasha Levin --- drivers/clk/clk.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index b56c11f51baf..a6575359de58 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -141,10 +141,18 @@ static unsigned long clk_enable_lock(void) { unsigned long flags; =20 - if (!spin_trylock_irqsave(&enable_lock, flags)) { + /* + * On UP systems, spin_trylock_irqsave() always returns true, even if + * we already hold the lock. So, in that case, we rely only on + * reference counting. + */ + if (!IS_ENABLED(CONFIG_SMP) || + !spin_trylock_irqsave(&enable_lock, flags)) { if (enable_owner =3D=3D current) { enable_refcnt++; __acquire(enable_lock); + if (!IS_ENABLED(CONFIG_SMP)) + local_save_flags(flags); return flags; } spin_lock_irqsave(&enable_lock, flags); --=20 2.14.1