Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1039831iob; Fri, 13 May 2022 20:41:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzb2WbAEwAQ5HGC7luGtRHJJkM1uhSdSm+dwYj08+k2b1TFTM/yvOZNO0UjHUQmsKTwGYzj X-Received: by 2002:a05:6000:1689:b0:20c:4fa1:ffb7 with SMTP id y9-20020a056000168900b0020c4fa1ffb7mr6416743wrd.48.1652499667154; Fri, 13 May 2022 20:41:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652499667; cv=none; d=google.com; s=arc-20160816; b=mJxrV0WhQs4Mi/p5Q8mknIRxYFQ5x+hZiJ6WJ4+K5drL35lqZn4FYU98Osd+bLYGmI JXNSxWh1bdJE6+c/Q9IYzyMfh1uwtjkBMjafqEmNkLNEVYhcqvtnWhBhXIdn9Jgk4lY0 /AUF2rVCLmdUggolhiZb1k9FCBtibURTsLBjq6yNgvJc9DxaqifZ8SPCcNYYBfIuuITP 6lNqJVGDaxDT1dxwI085WvXkzv8bi1GFWi1/AfQMEvmbN2QsOg7dV/dmzByhbay/n3xH rd8aIN8+p2JdNXhc8KabI6BlM5t2LH0pmd5v7LBLDsMVbQd5y+N+YTY5Gh6pu+JA79o/ oXVw== 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=EntzcyMJqmyoVwB2wFomh4Orbg1WQwtLfJblu/8zhGs=; b=aX9j3xEN+LN/cyHEVnk4zpPfqTirfaYpENcs4YWiz356iU6+lf1RwF0kuunMgEumhl q03lXx72KXPbYugf3W+p8MlbCsjrWgo6zvibHU4VKfMNWNhUvjo+sfjyZlBtGRQoA782 rxX4IBIUU1r0nHVphV0sOFDcP/nLkSPACy4s3wJpQAMAeBtO95diebGP8/1P10o+CuSw bawdamYPl06VK4CEqj58MVCx6EYlBHdexqTusV7YuSZ4dn0ykM2UjOVylVTGw21IPBJv hu9A1CiPGXeS5JSGare6sAGyI/cJOUcUIwPi7omAeHdM+w7ZMk7ZdZL9Rq/kUeHqElik Pocg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=SUc7k2sP; 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 o3-20020adfeac3000000b00207ab3993dfsi3408809wrn.993.2022.05.13.20.41.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 20:41:07 -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=SUc7k2sP; 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 B5B37451C88; Fri, 13 May 2022 17:16:05 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354717AbiELNw6 (ORCPT + 99 others); Thu, 12 May 2022 09:52:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354722AbiELNws (ORCPT ); Thu, 12 May 2022 09:52:48 -0400 Received: from mail-qk1-x72b.google.com (mail-qk1-x72b.google.com [IPv6:2607:f8b0:4864:20::72b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD4E66541F; Thu, 12 May 2022 06:52:47 -0700 (PDT) Received: by mail-qk1-x72b.google.com with SMTP id 185so4627717qke.7; Thu, 12 May 2022 06:52:47 -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=EntzcyMJqmyoVwB2wFomh4Orbg1WQwtLfJblu/8zhGs=; b=SUc7k2sPrY6R3kV27omjPGQxBeNTkELcBzbTdTAtrEDCXV3NlJvvfIKu/5Hic7Xd4E rwv62gGkHlV4LUeq0pD16Wgi3qqe2nO3WLcmEnVRg680ZEL64VwRTzM5jYd4t7w+ruFF zbPQysckaTyoENbAf2HJp9/eHw0UPwWQvX2IflxfXtmNVqfSVZ3COKfO/wi2+7OMxuva bF5kiFUwhysPKcEHgphPmCf+Ok0p5RF6180iGE3+bOsx9vB27EjIcGFPfNaTeViAA3OF IjSWkUpSoJmLWheYkCA8GVGeYlNAQB8H8oERZA6lwtPRr9IO5WkdBPZNyz38Gd8kEMWA rrfQ== 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=EntzcyMJqmyoVwB2wFomh4Orbg1WQwtLfJblu/8zhGs=; b=Gdz4GXA9soUWZlaiESJv5g1AFkr+Bu4s/7VwGqIeDA83PimUe8w4sT2SW5pwI8sapq WkF91VqiecV+qAnI409U/3luH+QY/OQZ3rOABQCVd7p1iJ0wN5bALK8O28Uj5lcYahA1 jAwdDu3F5nyppAyu7cmpDErcdg0aFtPT8cLn27v00pMXdyAyMVjq2b3Ck3SHex6avMBp 1xe1vb7vj7Ot6vVUJ1muzDPLRJFEG+Ogdf5nlH/Wjb26u/zzl4rKilZ2RCttgFzI13Wz O7/bQFwwuyyWU2EV9jvkLr8r6H1GRMGuwwUU5nmEtytIFjyY26dyRw5nF3JKjjFOxYYg jmcQ== X-Gm-Message-State: AOAM531bTC05PciEceJ2pgE3RG3XFxnC6fA8qNTFWUBr1dUuyFhqnwST UDpqkKW1wVOjXKLU3JU2LIkE1SrcaX/kmWkF X-Received: by 2002:a37:63cc:0:b0:6a0:c68b:b06d with SMTP id x195-20020a3763cc000000b006a0c68bb06dmr8741580qkb.90.1652363567040; Thu, 12 May 2022 06:52:47 -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 r204-20020a37a8d5000000b0069fc13ce1e8sm2885591qke.25.2022.05.12.06.52.44 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 May 2022 06:52:46 -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 v4 2/2] cpufreq: make interface functions and lock holding state clear Date: Thu, 12 May 2022 21:52:31 +0800 Message-Id: <20220512135231.10076-2-schspa@gmail.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20220512135231.10076-1-schspa@gmail.com> References: <20220512135231.10076-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 35dffd738580..f242d5488364 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1343,12 +1343,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) { @@ -1388,7 +1388,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. @@ -1540,7 +1539,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) @@ -1549,6 +1547,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