Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1001474iob; Fri, 13 May 2022 19:12:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxSQap5/OHw6UZOJ2gfCRxJUOdtjhdCue7A9OjSH0HZQ/1plc3TiGnZH3QWesYRU2rth0iW X-Received: by 2002:a5d:60c5:0:b0:20a:ed1a:9f9 with SMTP id x5-20020a5d60c5000000b0020aed1a09f9mr5917816wrt.623.1652494360271; Fri, 13 May 2022 19:12:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652494360; cv=none; d=google.com; s=arc-20160816; b=MmHabutwRx8MY0dMLbeDhXSgvMc9QP61dU8gVi/nIX2+07c25wrPop1NIuOe972gVy pKiYFmg2NqDQ2Z26dG8vTJWeyPFT4OowZLnDGdgU3k/UL//y+OUcyquyapcDbk+3fgDm L3kLucpLj8k7D0Ai3dzqSVzAMsLTaM0rJ4ydqdWJCMMDFy9UERfM/UpC7//eCDsnlPDE Hj2Yzs+FB5wZVmqP+fzLn0/bc8UsyGNnV0WQlsMDEJJvjDTu3A6+qIm1bliEnHYF5JiR pPYVhLEjfRj61nIqrTp72ilusn16U2mLQoowZO0D5r7+i7LJ6ZPCjALMZuVlr1uxyr8H q26Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=7D8erwxOxrNwpL4kTMFZcWrJ5A/nWK5FWS+W1RtdNck=; b=IqDs/TLZruTbh1aiOPNDdMRZNJBn/KTCe6zvUCOLCJh1EuOurfM80S9WCdwq5GfgYm PhRj6dsi1Mt1t8MroLRAWOk14bpdpU0CeoH52VCrciXVT+ew/hivtisVF2aBEq3RQ6S6 oswrgIa9z46zLSZcU6ygQOLLEhCzoIptFFuNhehIv3h9QH8T14fmvfHNY5XCfAig2trW K+f6ecvr8caBkoD2cq6uxK/Ewwr+/TSbDnZ/9lZZtvMhIWIQS89LgSPHJvn38YRj+fBn XHYfwn6LxnvTfsob6a2f7QjxJeUzLTA0T9kHOBdKHcHTylip9oPJDSajZaUR7DmMLbdp Pdig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=PrYGICVh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id p5-20020a05600c1d8500b0039432dc5495si3935480wms.207.2022.05.13.19.12.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 19:12:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=PrYGICVh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2DFF149E029; Fri, 13 May 2022 17:30:59 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379779AbiEMLJM (ORCPT + 99 others); Fri, 13 May 2022 07:09:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379766AbiEMLJI (ORCPT ); Fri, 13 May 2022 07:09:08 -0400 Received: from mail-qt1-x836.google.com (mail-qt1-x836.google.com [IPv6:2607:f8b0:4864:20::836]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7544F26C4DE; Fri, 13 May 2022 04:09:07 -0700 (PDT) Received: by mail-qt1-x836.google.com with SMTP id h3so6547255qtn.4; Fri, 13 May 2022 04:09:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7D8erwxOxrNwpL4kTMFZcWrJ5A/nWK5FWS+W1RtdNck=; b=PrYGICVhGTuengtryu36R642ZDAMVMtPk+eeETtYf2Cmfiw7mG7AGNsDQziNNnoIjo kh0QePFTODZMi99cysCpYNZIPSYqjFjyeNSwfgMtlVQZlXs3kVYlyF64y+jhDP5uO/XU XN95A7caOX4ZFmvvQasyvYYnVuvprWRvdPhVyBSWb5h/Kx6N+MJc4MKeGrt5QJbnRbK5 gHrKUl9rvVPpqkxUDK3PmpXXz7Vxd5rd/4HBlT/2rmGYRxGMx+18ohxiFLx/ptQ5eLK9 Y3c3QOgxsLZ7+GvAHHVPAfQFyjK5f/MrdTOxcDTQDs5fs0rCq1mmRReqDQ8F06orNO+9 V/3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7D8erwxOxrNwpL4kTMFZcWrJ5A/nWK5FWS+W1RtdNck=; b=nxxV0+E3PETpsc2VbU5Yxfse/hObaEGumQFdp5rpa5F7qr8wQAd8gUeWlbYwNEDBDX TjshREhw6QyMt/9XxSpY35PVEpJapAxbBhufb/SyaGC1AjH0B+J0LqEPzfL2+Nmm9YET t0VnmRn/p5XXIT+nuE5uD7fFEon7l8gRAV3Fo8FOT9fiIiWVstmef5Kjck0wFwlV6UHs KGMWu1GlEiqygcevnJ7ONJUBDFN072CkP1g7AzUVUh6Mjc5zzi7UI/bHoK4seYWxrac1 XBVrD1cxhCIr6FxhMz3tM78VBTW72LWgnrToDh1/N8CSvyDj6XTzT3MIbo83q0Wp8jPf aaiw== X-Gm-Message-State: AOAM532Lbxzv2m4sOSwMTEk+w7fIqkGzbpbyhEtSVTedE9b7I0Xgcoob eYOPnBykOHPm89ZUxKaFBlqM4LmGcdv6p/BK X-Received: by 2002:a05:622a:14c7:b0:2f3:d2ee:a676 with SMTP id u7-20020a05622a14c700b002f3d2eea676mr3926585qtx.604.1652440146548; Fri, 13 May 2022 04:09:06 -0700 (PDT) Received: from MBP.hobot.cc (ec2-13-59-0-164.us-east-2.compute.amazonaws.com. [13.59.0.164]) by smtp.gmail.com with ESMTPSA id b16-20020a05620a04f000b0069fd57d435fsm1127548qkh.101.2022.05.13.04.09.03 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 May 2022 04:09:06 -0700 (PDT) From: Schspa Shi To: rafael@kernel.org, viresh.kumar@linaro.org Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, schspa@gmail.com Subject: [PATCH v5 2/2] cpufreq: make interface functions and lock holding state clear Date: Fri, 13 May 2022 19:08:48 +0800 Message-Id: <20220513110848.20204-2-schspa@gmail.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20220513110848.20204-1-schspa@gmail.com> References: <20220513110848.20204-1-schspa@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org cpufreq_offline() calls offline() and exit() under the policy rwsem But they are called outside the rwsem in cpufreq_online(). This patch move the offline(), exit(), online(), init() to be inside of policy rwsem to achieve a clear lock relationship. All the init() online() implement only initialize policy object without holding this lock and won't call cpufreq APIs need to hold this lock. Signed-off-by: Schspa Shi --- drivers/cpufreq/cpufreq.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index ba73be6f0490..0f0f202f9a05 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1339,12 +1339,12 @@ static int cpufreq_online(unsigned int cpu) down_write(&policy->rwsem); policy->cpu = cpu; policy->governor = NULL; - up_write(&policy->rwsem); } else { new_policy = true; policy = cpufreq_policy_alloc(cpu); if (!policy) return -ENOMEM; + down_write(&policy->rwsem); } if (!new_policy && cpufreq_driver->online) { @@ -1384,7 +1384,6 @@ static int cpufreq_online(unsigned int cpu) cpumask_copy(policy->related_cpus, policy->cpus); } - down_write(&policy->rwsem); /* * affected cpus must always be the one, which are online. We aren't * managing offline cpus here. @@ -1536,7 +1535,6 @@ static int cpufreq_online(unsigned int cpu) remove_cpu_dev_symlink(policy, get_cpu_device(j)); cpumask_clear(policy->cpus); - up_write(&policy->rwsem); out_offline_policy: if (cpufreq_driver->offline) @@ -1545,6 +1543,7 @@ static int cpufreq_online(unsigned int cpu) out_exit_policy: if (cpufreq_driver->exit) cpufreq_driver->exit(policy); + up_write(&policy->rwsem); out_free_policy: cpufreq_policy_free(policy); -- 2.29.0