Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp2659905iob; Mon, 16 May 2022 03:24:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwvsFvD7KEbWc1RJBPWN7OzcxU3oSJHxoJRSvW/21QEjZRkXp3QW35RR84/030UgsdramCY X-Received: by 2002:a05:6402:1941:b0:413:2822:9c8 with SMTP id f1-20020a056402194100b00413282209c8mr12473227edz.13.1652696656948; Mon, 16 May 2022 03:24:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652696656; cv=none; d=google.com; s=arc-20160816; b=zzGIx57u3LycUk/LvTfcea9suAmjleYokB8oH3Iq6flr2uhK13rWTyP9EAl5AHKoHE KO615o0HSPLBqJGSNlNA4/0Srhv6XTla0sSl3GTq2xKlE+SdPeobaFn62CMROF9db1Uy 8+vQweYizjgWK4AEjVeFjwDcmUY81w+wga13ndA8svXSv3hicoOc1RJapr4uqauxIULY Mw2oIFxnh8VDuaaeu2ztUp/w60XVRAjMyvSjYYlsCXenjPCq81yOAxKJjxjZ50rf4xSC Cp1dxVDK+N7SufGyLXJCDkI5WSzCbmShErTYO7cDEiZqexeYfYolr7vLXpajVUAgSnAb ZkVg== 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=Iknl9FGNjcSKriVQ8ROc164iV8qluWzwBBYuxxLunGQ=; b=CcJ8Cw10Fta29dJkc+ypgJq0mPxuobbgt3kWDfS9QoISvdvDXJOaZLv1DX5XFeL0Xv 7rxVlFtaHoMrfYmrNb9PJ8xetc9LXmwOpiVjNsdBoGpfPQWEImRQ+ifKZ228nCiEvcAC lr3Sd7iYgkcm1nK14whvr0XcVl2SATFLSHOlRRN5122+huyEZL5nVqfBT8eSXojZOVfu ZblFvx9k1taXBD5Hmv74nIZRZAoIhJAEW70zt3WkEnS0YEcDFOcaNbNwhIA25NIHrEe5 W1OYQ01S/MJ+lPZIN/XNOlLkuZmswAS3TeGzTqKsgYLgBnezm0An8tpsqE7narZePsgc B30g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Bsbk8Y0y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g6-20020aa7d1c6000000b0042aa7b4db4csi3922242edp.127.2022.05.16.03.23.51; Mon, 16 May 2022 03:24:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Bsbk8Y0y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239578AbiEPDMP (ORCPT + 99 others); Sun, 15 May 2022 23:12:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231238AbiEPDMO (ORCPT ); Sun, 15 May 2022 23:12:14 -0400 Received: from mail-qk1-x72d.google.com (mail-qk1-x72d.google.com [IPv6:2607:f8b0:4864:20::72d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7AD4611C01; Sun, 15 May 2022 20:12:13 -0700 (PDT) Received: by mail-qk1-x72d.google.com with SMTP id k8so11414572qki.8; Sun, 15 May 2022 20:12:13 -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=Iknl9FGNjcSKriVQ8ROc164iV8qluWzwBBYuxxLunGQ=; b=Bsbk8Y0yg5VxbQEpNpD579fQ1Jdbh8Tc00NPMDYN65Kd6bwr6CayognJQIG7jL7Z/o MHH5OkbN57AW6FSdXW9EOCyJbg/uQ+hT8uT7ZkSRM3xwsOKsJnjSJQ9MkUKgsU15criK NUgjyzxFUT+23G+ri+8Yotz8JKrE9073pl2GUL28wBvelugkksLGfCMPwU5tWLL2le8G 9fHFnVZOgBInIPTAXJ/fl4YjYGNOHgUStQM5ImS+mOEKCH4PDnaiaZDmDcoo0zYJjTs4 DaVia075alP46+fk/Cs+S6cmqPxyu2+l+GDl47nPqZagp1tKlMIKGGTBkn26ggmiYh+3 qC2w== 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=Iknl9FGNjcSKriVQ8ROc164iV8qluWzwBBYuxxLunGQ=; b=WadKUsooTwzoqZZTKFaRQD+oTH9U53W4s4dndlqGf0bZBNCu6aWapPcgCT/5NwtGuB 4pea9cNopzZAB8BzW1rLCzEVVwJdSAlQfPezrtNn/scXcQGeRb/ccwjAZa6oJ6pQ8nDp xVTq4w1Gf5FR9xS31APwMD5ML+r3oaZiS0kW9QpbcS8xIoX1CGi7KeIubdb4qbZdt8U+ Vt7Lac0oSkEv8zFpDIgQOADylooUdDcnv6fwKfZmxB2jHJfTq6dxb//a3OHIhkbRdhJD CedVyCqYXES/dKYWWYlFn583ct0gB2S8UetMyDB7iEcWAOh3zg146Qk3f+tlJYtgWSrN eC9A== X-Gm-Message-State: AOAM530CPyqe8AVi/PgM4B1gipf+5+aZ8L5xIsqUj/Goe17qdJNrrDeB i5j51SB5b9EVuFHP1aT45/QB3IDeE1/0GYAZ X-Received: by 2002:ae9:df46:0:b0:69f:b616:762b with SMTP id t67-20020ae9df46000000b0069fb616762bmr11030804qkf.600.1652670732521; Sun, 15 May 2022 20:12:12 -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 186-20020a370bc3000000b0069fcabfdaebsm4993072qkl.70.2022.05.15.20.12.10 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 15 May 2022 20:12:12 -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 v6 2/2] cpufreq: make interface functions and lock holding state clear Date: Mon, 16 May 2022 11:02:51 +0800 Message-Id: <20220516030251.42323-2-schspa@gmail.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20220516030251.42323-1-schspa@gmail.com> References: <20220516030251.42323-1-schspa@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index ba73be6f0490..ccb774e02934 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) @@ -1547,6 +1545,8 @@ static int cpufreq_online(unsigned int cpu) cpufreq_driver->exit(policy); out_free_policy: + up_write(&policy->rwsem); + cpufreq_policy_free(policy); return ret; } -- 2.29.0