Received: by 10.223.185.116 with SMTP id b49csp5957823wrg; Wed, 7 Mar 2018 22:38:34 -0800 (PST) X-Google-Smtp-Source: AG47ELtUF35tFHdi4Ham5w9KDujmm3QDdaE7xKpsWwSvnDVtakeO4ptcpjBZx6k9LW1tBxCN1VgH X-Received: by 10.101.97.72 with SMTP id o8mr20603528pgv.119.1520491114625; Wed, 07 Mar 2018 22:38:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520491114; cv=none; d=google.com; s=arc-20160816; b=y2W9XB/aKAxuxfFSme35zehbY2aW+Yxyb+rIEVSSF7tcOnZjsk57nGYVpI8aPBGwX+ y4RUc/jeUUhwi0cfaRSMIiAtSpMEsNzLZ6hPpNz1FXFz+BjXRihTmfbwAfeio5P/+JTr O4bg8XAoB1H0PH5Bz/8Ct+qBymh5kzw0W7Uwl/j5qA13vWsNcFVqAz/RRb6Fhs1h+7OR 2U5hO7QAyPyGBSAqD6q4cHdfw7T8anAFJbRP8gYAif52v34oTXZPCYzKCFHkHTFDFckB 4ET4r/5pcVN6KR694plqHVrZFhiwkKOU1HBWdVWhh1e+nyJOX0xeDURIa1lBsg8H7prj faqw== 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=kwBEHjP7s+XqeMnASxU3eCW2OG65awzjm5qc9AhFjBQ=; b=l7473/GOma15UwDmk+sAVkQiuzIY1fVLoiZfG9jXQN06tn04Vm3yyqSGpb8fdN4ZZO eyuAZQygYno+1rz80A4UqogtcAqeWPsXgh5kD65fnUWvrnERyz2D9fkbSjt3OlciMZBB a/SY6mYaSgS0WSLDnt5kRyIAp4RO5McluHRxa5BWxW1n2SPKXKca+wFmC2t6Cpc2k6Uu qD3yF23qJMaJjsHIhe0taGfxb1WI//pPACxw8KePQADnuRWyRGRfQmRW8Hd07Uc1hPDR zB8jqRPJNO8PKDEc44QiG3bCx4sVRik5qli+UgMvkSwUSBHR03IS5fkzBUuMky84+SZp 6jZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=Mg4TzQsf; 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 5-v6si14097439plf.396.2018.03.07.22.38.20; Wed, 07 Mar 2018 22:38:34 -0800 (PST) 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=Mg4TzQsf; 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 S965494AbeCHE7y (ORCPT + 99 others); Wed, 7 Mar 2018 23:59:54 -0500 Received: from mail-bl2nam02on0092.outbound.protection.outlook.com ([104.47.38.92]:59552 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S965459AbeCHE7u (ORCPT ); Wed, 7 Mar 2018 23:59:50 -0500 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=kwBEHjP7s+XqeMnASxU3eCW2OG65awzjm5qc9AhFjBQ=; b=Mg4TzQsfMC0HwtIpD6ZJzr/LEzYlVjW4sNnoGNQ0MltwUbVHlFHWIjQ+fyfwQmYDiyHWS7OsHkECHO7ECLKJGjWf3/Mpdpnm22gxVi4v8QNCiqHiSCH1vwq/GzKcLC6iTM3WTQagLbLy3gvXlL5B9a2zs13riHd2YAiFnnJaXQo= 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.588.3; Thu, 8 Mar 2018 04:59:44 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8063:c68a:b210:7446]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8063:c68a:b210:7446%2]) with mapi id 15.20.0588.008; Thu, 8 Mar 2018 04:59:44 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Stephen Boyd , Michael Turquette , Shawn Guo , Sasha Levin Subject: [PATCH AUTOSEL for 4.14 63/67] clk: Don't touch hardware when reparenting during registration Thread-Topic: [PATCH AUTOSEL for 4.14 63/67] clk: Don't touch hardware when reparenting during registration Thread-Index: AQHTtpoI2kkQaF+lW0OH6REWd8SU3A== Date: Thu, 8 Mar 2018 04:58:00 +0000 Message-ID: <20180308045641.7814-63-alexander.levin@microsoft.com> References: <20180308045641.7814-1-alexander.levin@microsoft.com> In-Reply-To: <20180308045641.7814-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:b4srKdow6WH2RJ4bYmBs2u1BCqQkPfoYx9wIrF/LWQbTqDA4N75vBl9uUGIn3RTUfpBBdEBDYoSTmtysKJ/yw53flTjx3o/RAEfgJifEsFYvWsnSFMRBC2eE7J0+QQCW5RTdqa9CtzQjEcsA0ZgbYlrreIbBLWmzFYQecGKilhbh61eF3L3Mn1SqTM0/UwZMIZtQ0W8Xn7+FHWcKix413pnPXm53zxvVbbwd8hka7yhwInFGtkbBFKJPxFtsUlFI;20:J/oRuTNTOFW515YQkE56poPm+7Kfg0agMZCFk5T7E80WVTGKkBQmWnHANBVVk3Vf7s8SFC1C1eoitv9fuP1Ji8GcE8dwoLTrUt8Z2nIE2/Uk8G3YjNcRlG4Ych0Y+yQh3PubpRc2ibiSPCYHqgAwtib58X1bHLCkqsDoLugOYNM= x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 343df81a-867d-4254-c12d-08d584b168c0 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(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)(185117386973197); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040501)(2401047)(5005006)(8121501046)(3002001)(10201501046)(93006095)(93001095)(3231220)(944501244)(52105095)(6055026)(61426038)(61427038)(6041288)(20161123562045)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(6072148)(201708071742011);SRVR:DM5PR2101MB0920;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0920; x-forefront-prvs: 060503E79B x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39860400002)(396003)(39380400002)(346002)(366004)(376002)(189003)(199004)(81156014)(81166006)(5250100002)(8936002)(54906003)(2501003)(305945005)(8676002)(107886003)(110136005)(97736004)(99286004)(6436002)(36756003)(316002)(72206003)(76176011)(14454004)(6486002)(7736002)(478600001)(10290500003)(186003)(22452003)(59450400001)(68736007)(105586002)(2950100002)(106356001)(102836004)(575784001)(26005)(6506007)(86362001)(3660700001)(5660300001)(2906002)(10090500001)(1076002)(25786009)(2900100001)(53936002)(4326008)(66066001)(6512007)(6666003)(6116002)(3280700002)(3846002)(86612001)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0920;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: 5XPKuKNJ2dtr7hhb7iEzutvaEaWeZfvbi/tIFjIcHdvdOYhyCDvmCFIoqP/Mq8889azYgUtcNVchuxZOqHDoNQB7CSZTBLA7sREPEX7dGeNgSftMHSScWZkE6JcRdG/nHpOPBQcurUgDX6V0sSE6jANg/JdN4iCu6Tf89lpteJOdmm4ezO9fnPInalaaXbOvES/ZcoqarJZWSeosGZ7E/jGvPg8xYFDKEQZrASWuEusQe2komFTxqlmnVTNaDMHpo1kNAl4B8jJ4OfxeyEXlLph2xLVVGmRFCXjqaDUWbY8DxEh3rY71wPEzVK+MLLQ88iprLxtzcxdPdHMDQL7iPQ== 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: 343df81a-867d-4254-c12d-08d584b168c0 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Mar 2018 04:58:00.3739 (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: Stephen Boyd [ Upstream commit f8f8f1d04494d3a6546bee3f0618c4dba31d7b72 ] The orphan clocks reparent operation shouldn't touch the hardware if clocks are enabled, otherwise it may get a chance to disable a newly registered critical clock which triggers the warning below. Assuming we have two clocks: A and B, B is the parent of A. Clock A has flag: CLK_OPS_PARENT_ENABLE Clock B has flag: CLK_IS_CRITICAL Step 1: Clock A is registered, then it becomes orphan. Step 2: Clock B is registered. Before clock B reach the critical clock enable operation, orphan A will find the newly registered parent B and do reparent operation, then parent B will be finally disabled in __clk_set_parent_after() due to CLK_OPS_PARENT_ENABLE flag as there's still no users of B which will then trigger the following warning. WARNING: CPU: 0 PID: 0 at drivers/clk/clk.c:597 clk_core_disable+0xb4/0xe0 Modules linked in: CPU: 0 PID: 0 Comm: swapper/0 Not tainted 4.11.0-rc1-00056-gdff1f66-dirty #= 1373 Hardware name: Generic DT based system Backtrace: [] (dump_backtrace) from [] (show_stack+0x18/0x1c) r6:600000d3 r5:00000000 r4:c0e26358 r3:00000000 [] (show_stack) from [] (dump_stack+0xb4/0xe8) [] (dump_stack) from [] (__warn+0xd8/0x104) r10:c0c21cd0 r9:c048aa78 r8:00000255 r7:00000009 r6:c0c1cd90 r5:00000000 r4:00000000 r3:c0e01d34 [] (__warn) from [] (warn_slowpath_null+0x28/0x30) r9:00000000 r8:ef00bf80 r7:c165ac4c r6:ef00bf80 r5:ef00bf80 r4:ef00bf80 [] (warn_slowpath_null) from [] (clk_core_disable+0xb4/= 0xe0) [] (clk_core_disable) from [] (clk_core_disable_lock+0x= 20/0x2c) r4:000000d3 r3:c0e0af00 [] (clk_core_disable_lock) from [] (clk_core_disable_un= prepare+0x14/0x28) r5:00000000 r4:ef00bf80 [] (clk_core_disable_unprepare) from [] (__clk_set_pare= nt_after+0x38/0x54) r4:ef00bd80 r3:000010a0 [] (__clk_set_parent_after) from [] (clk_register+0x4d0= /0x648) r6:ef00d500 r5:ef00bf80 r4:ef00bd80 r3:ef00bfd4 [] (clk_register) from [] (clk_hw_register+0x10/0x1c) r9:00000000 r8:00000003 r7:00000000 r6:00000824 r5:00000001 r4:ef00d500 [] (clk_hw_register) from [] (_register_divider+0xcc/0x= 120) [] (_register_divider) from [] (clk_register_divider+0x= 44/0x54) r10:00000004 r9:00000003 r8:00000001 r7:00000000 r6:00000003 r5:00000001 r4:f0810030 [] (clk_register_divider) from [] (imx7ulp_clocks_init+= 0x558/0xe98) r7:c0e296f8 r6:c165c808 r5:00000000 r4:c165c808 [] (imx7ulp_clocks_init) from [] (of_clk_init+0x118/0x1= e0) r10:00000001 r9:c0e01f68 r8:00000000 r7:c0e01f60 r6:ef7f8974 r5:ef0035c0 r4:00000006 [] (of_clk_init) from [] (time_init+0x2c/0x38) r10:efffed40 r9:c0d61a48 r8:c0e78000 r7:c0e07900 r6:ffffffff r5:c0e78000 r4:00000000 [] (time_init) from [] (start_kernel+0x218/0x394) [] (start_kernel) from [<6000807c>] (0x6000807c) r10:00000000 r9:410fc075 r8:6000406a r7:c0e0c930 r6:c0d61a44 r5:c0e07918 r4:c0e78294 We know that the clk isn't enabled with any sort of prepare_count here so we don't need to enable anything to prevent a race. And we're holding the prepare mutex so set_rate/set_parent can't race here either. Based on an earlier patch by Dong Aisheng. Fixes: fc8726a2c021 ("clk: core: support clocks which requires parents enab= le (part 2)") Cc: Michael Turquette Cc: Shawn Guo Reported-by: Dong Aisheng Signed-off-by: Stephen Boyd Signed-off-by: Sasha Levin --- drivers/clk/clk.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index c8d83acda006..416d44cc772c 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -2476,14 +2476,17 @@ static int __clk_core_init(struct clk_core *core) */ hlist_for_each_entry_safe(orphan, tmp2, &clk_orphan_list, child_node) { struct clk_core *parent =3D __clk_init_parent(orphan); + unsigned long flags; =20 /* * we could call __clk_set_parent, but that would result in a * redundant call to the .set_rate op, if it exists */ if (parent) { - __clk_set_parent_before(orphan, parent); - __clk_set_parent_after(orphan, parent, NULL); + /* update the clk tree topology */ + flags =3D clk_enable_lock(); + clk_reparent(orphan, parent); + clk_enable_unlock(flags); __clk_recalc_accuracies(orphan); __clk_recalc_rates(orphan, 0); } --=20 2.14.1