Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1019450iob; Fri, 13 May 2022 19:52:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwdKdL4W6zKrNMKzPkrP8A4gRYsYL8ySoUXID8ClDTLSemjf3HG5OFeBJZ7EWd8zaId9QFW X-Received: by 2002:a05:6000:c7:b0:20a:d8c1:d044 with SMTP id q7-20020a05600000c700b0020ad8c1d044mr6159823wrx.422.1652496757494; Fri, 13 May 2022 19:52:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652496757; cv=none; d=google.com; s=arc-20160816; b=qgYV0KGDtjah0AkTGiMf67EfTQl1xEH/pTTot0cTl795PiLQK+zk98zLxOmX5mP8zV /L03tvJIdKVdgjKlCRawcBKUWOPNKnk6dNkrr0ko787x98e2xCIBntxAepxtZInAph01 6ZnQXeoINxaOZh6NhgYOeTHWA+QQYGgbHrq7tmQKZKrGhZQsa5TypmwENUEkvoX3/7CU +onjm54VXM7yTbp2GMXGuDIy9GEj0nDzrC5idXS+4T8mFRegzDjx+t7Ad46WH6H77QxA cFoUzDHh1WhT5NLSdqwqFFsJMEv7gxRAmlcOaNWN0YXqg4WDR6/YShJ6jDBEU7aKLHpx 2NVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=BoY7g8nUQQ3BvW0xBl0eILMoOU8tGg7MZ9xjNiqrFPA=; b=ljPbmF+1+N+hVxKAPViEMZMmpKB+GlLJvr12ZQxjl6gMwN5IheA26TxuXP3/tndce7 9MK1qYKHyTv/EPxQ9izcYZEE38sOsRj2oTEncoE0b3c8d8tPw483EwIPV3YF7ywYwbzN PFWzwtu6X1ymYHzPrlX8de3MBx5TilX651ix+hl5PzctZilggOF1LSlJauHoBSE/uYy0 q75cG87BQEEPrei1tB+WOjqydl4Xko9eBA/p9XmWB5fhv/qdCB45RJhDqfAwSJOz1Jx6 oIms84icmbJHXjuk7x/eJ7uSZT79p7KNxtOjwp9PQWptslsO7JyyRosDcceoFEWzHfLf PFsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=TH7l9ias; 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 11-20020a05600c274b00b0038eba03f669si3369893wmw.49.2022.05.13.19.52.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 19:52:37 -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=TH7l9ias; 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 EE9DF37FFEE; Fri, 13 May 2022 16:39:07 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356136AbiELQBe (ORCPT + 99 others); Thu, 12 May 2022 12:01:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343533AbiELQBa (ORCPT ); Thu, 12 May 2022 12:01:30 -0400 Received: from mail-oa1-x31.google.com (mail-oa1-x31.google.com [IPv6:2001:4860:4864:20::31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0EC147558; Thu, 12 May 2022 09:01:28 -0700 (PDT) Received: by mail-oa1-x31.google.com with SMTP id 586e51a60fabf-ed9a75c453so7131423fac.11; Thu, 12 May 2022 09:01:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=BoY7g8nUQQ3BvW0xBl0eILMoOU8tGg7MZ9xjNiqrFPA=; b=TH7l9iasZncqnM5kUsqw7GwUDOgqZpjRQ9+dl4GQpL+/5cH5UVP+bjbrT+vsprLv4z pwVBaeaGBSBWxAGZoCgSSUQLvIlt1CRZ7/6Q7z1gts6rlcG7rHbH/oqfW51h86zVhfF2 3s+pzxr/jBtnRXomw2dHHx7nV5kHJLKKJILZVH0eZNm5/YVPapJK4G7R0wFVVGFqs977 UhSoI4uadPx+aSBHE9WgbJXilQ6BZl+oBec+wjMFL36cpvI/7PV/raWjk4iCKrmslGdn E768o01/UPTWFZ1EORuaBNU/7FugBRPrAzcdSKzQ5ETnXycI8Xtqgs0fYKzIkPJtdO+h ZWLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=BoY7g8nUQQ3BvW0xBl0eILMoOU8tGg7MZ9xjNiqrFPA=; b=3i9ndeOwYD+GYqFKeiGPOD/Pn6lT5pofZwquTJJQIduWL9nlROtdcvmmQD3pMCoSVQ 3C7GfSyNemPJpGRDQFWW8fm0hIUiXUEtBXzKpwp6AXnU4O/kFAMYRLTqzMVHz+WO+AqE /+oDHonsUOa/g7jyLZYqa5Qz9p7Vrtmg2CFAcOOu9VudcH136hr4UEAfA3sHzc8EZmAp LNiYfgT0A6iKsExfbEwz4rTMb1yMyFgBVKdlUEdQt4m+bqwEzKJAGPRhmbnpCkCXGbzr 6Q1N7Po8Rs3MwcUe/soqnIlGW4BfDunAhG6nY6fNvetgiJinl17WnqWIfSYFHCtK3CDC jBZw== X-Gm-Message-State: AOAM533IGYxVm1FkobfYcGQC8n1F+F4Di9Q9OZV+qYQaC0S4fb4WrQ3S S2tDkin8GfSTvwO09L6KhKJVRb89xHeuv92CMZmaoAH7IpYADKLD X-Received: by 2002:a05:6870:5b89:b0:e9:bb4c:a6f1 with SMTP id em9-20020a0568705b8900b000e9bb4ca6f1mr299361oab.52.1652371287934; Thu, 12 May 2022 09:01:27 -0700 (PDT) MIME-Version: 1.0 References: <20220512135231.10076-1-schspa@gmail.com> <20220512135231.10076-2-schspa@gmail.com> In-Reply-To: From: Schspa Shi Date: Fri, 13 May 2022 00:01:16 +0800 Message-ID: Subject: Re: [PATCH v4 2/2] cpufreq: make interface functions and lock holding state clear To: "Rafael J. Wysocki" Cc: Viresh Kumar , Linux PM , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" 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 "Rafael J. Wysocki" writes: > On Thu, May 12, 2022 at 3:52 PM Schspa Shi wrote: >> >> 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 > > IMV this still addresses 2 different issues and so it should be split > into 2 different patches. > >> --- >> 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 > > Patch 1: > >> @@ -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. > > which addresses the problem that cpufreq_online() updates the > policy->cpus and related_cpus masks without holding the policy rwsem > (since the policy kobject has been registered already at this point, > this is generally unsafe). > > A side-effect of it is that ->online() and ->init() will be called > under the policy rwsem now, but that should be fine and is more > consistent than the current code too. > > Patch 2: > >> @@ -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); >> -- > > which addressed the issue of calling ->offline() and ->exit() without > holding the policy rwsem that is at best inconsistent with > cpufreq_offline(). No, we can't split this into two different patches. which will cause a uninitialized unlock for policy rwsem. This will make the git bitsec unusable. Which Dan Carpenter reported, and cause the patch of the v1 version to be reverted. Link: https://lore.kernel.org/all/YnKZCGaig+EXSowf@kili/ --- BRs Schspa Shi