Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp1007148ioo; Thu, 26 May 2022 22:18:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyXpZy6rNMdDFBargr4vjH9NudMmKTouqlYDL0lL6Uax8pD9jVs9bJMq1rqQYwTRRaLIyPb X-Received: by 2002:a17:90a:1b84:b0:1e0:493a:425c with SMTP id w4-20020a17090a1b8400b001e0493a425cmr6389287pjc.200.1653628735621; Thu, 26 May 2022 22:18:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653628735; cv=none; d=google.com; s=arc-20160816; b=i1J5FKPcvEWL4zPkgcCODiTjqJQ8jdUm5YrAUGc76VJ1B9jy0+2Ynsa8o8coKzoiwj BnyKeZsrQHxXIV7dwo4qSI/3txicz9NtKcNbQ0/qg+8wnE8RBWzxGTh1xb13N090ZGjv ZuBL7kNOzSmR+EQ/SHpf7NdLPhXUelHjH4656VxjjBv6rnbW+Cx2A8aflcCcE4nzNafI LQdBUs3y+yp6/Vh72kceQ3WtZql7DUFIRExbS0UJ0WhnwvgKyJMJg32wFde0cUsQup0B tj9hQDfFQQOsG+4Yp1kurV2VnW989N+ey517YNy14rzwyKOmFzjYbWRSKbQp+Bf/SeUo Ku2w== 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=Ufg1eOhDqrWLS5IemSf2tmmF5r8nZpWc+mO2s4T3ZiU=; b=DIlw22mWFfjaFZPrdKPAtOdEVIUhkRg8sPaQeMhdaKf66l3Fw63DfVNqp1dZIlk58E POobXPmQXY9jTNuAv/ccfmID8KDF7qppcFDOBAMMD9h06QokNOxqiAMtb4fjhkovt50K Xodz3b4aiEfNb+FNHw7eFy85K+PSY+kujuNRHoZvemd5errDvNy+ZfGHpuc/g2NIKCTf mSCeurB43dDNTzPm1TBj8ER4OVKXoLygRS7OucEknlOSy2ZmuLA6xgQ1iw4qX/j72ip8 /TllrsJwf0380wVv7nmXMgjClGHQDfp1UsesLIeWChROAUEG3CEmgf0NUSpPqIXodx+z fX/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=i+XHgWM4; 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=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l2-20020a056a00140200b0050d434ae30csi4704361pfu.217.2022.05.26.22.18.44; Thu, 26 May 2022 22:18:55 -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=@linaro.org header.s=google header.b=i+XHgWM4; 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=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239609AbiE0Dxr (ORCPT + 99 others); Thu, 26 May 2022 23:53:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236458AbiE0Dxo (ORCPT ); Thu, 26 May 2022 23:53:44 -0400 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C71A7E27B0 for ; Thu, 26 May 2022 20:53:43 -0700 (PDT) Received: by mail-pj1-x1029.google.com with SMTP id l7-20020a17090aaa8700b001dd1a5b9965so3316529pjq.2 for ; Thu, 26 May 2022 20:53:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ufg1eOhDqrWLS5IemSf2tmmF5r8nZpWc+mO2s4T3ZiU=; b=i+XHgWM4eeyGv4W88AgzSozzfSs6Qg6ZOmwwhXCEY/eEo8uT1ENLZBS6JE5xrZJgd6 M0bWeqCcWnZBoYw0VVp4ofmvyf8QSEDY5GooUN0pkWTmaGbhltS+RZhSl9W10TZtNdEb pcHDxXDkgZxQIMrsVpXIcBUNfGJ7KEM7XMz//owDzyDeod2UPqdHWmV8uugIp71ubW0u 3UgQsDFzBAmC2bkxuKoryk75D4L0pSHriTAF5px9Km86V6U2aLgv6nBZPg8SG5BlOwp6 FGdKjbrxRvCSpuBbx3/3lrYxFY93C8U4NZn/zMDgCtsubeOHzTeqv24Qo46GBpnjhmmg pmrQ== 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=Ufg1eOhDqrWLS5IemSf2tmmF5r8nZpWc+mO2s4T3ZiU=; b=tEUs2ufroeAYnOu//RlugfAB9FTiEmF8C50qv08H2brQYw1LCevgPz3vYxi3PGOdYS ArfckLgqghMrBaQpuqV+BhQ4QiLTOjK5cGq+9xSrg+jNniOHvIEMVGk8/L1MrQ6L0pgN 6kQNbWWJGCC812QfpZW17QUYPKzTLcIr5al7/qc1iGHnsGBMQ79b4QvErdxEERZ0DKPx rYErbf4Wa82PpduyfZ1MjYnab8OSVfWdmTL0JB/yTPqeRQOUp8lEkMDn+DalgjDKxEdT gHdTcbAs0gcDKqH22av5uxa+/JEgChjICw5cUiKdgPHZKxkgb86xdoTU7wGl/9krA8Dz A60A== X-Gm-Message-State: AOAM5330G/hX+1pc6jQmbzg/uKRuY+UnZrzF99Lnkn6Kw9p+OKIv7pZc oeQpK79YqXMcgnx8Rsed9hAq/w== X-Received: by 2002:a17:903:1c1:b0:161:aa16:f279 with SMTP id e1-20020a17090301c100b00161aa16f279mr41441831plh.88.1653623623300; Thu, 26 May 2022 20:53:43 -0700 (PDT) Received: from localhost ([122.162.234.2]) by smtp.gmail.com with ESMTPSA id m14-20020a17090a3f8e00b001d2edf4b513sm423635pjc.56.2022.05.26.20.53.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 May 2022 20:53:42 -0700 (PDT) From: Viresh Kumar To: "Rafael J. Wysocki" , Viresh Kumar Cc: linux-pm@vger.kernel.org, Vincent Guittot , kernel test robot , linux-kernel@vger.kernel.org Subject: [PATCH V2 2/3] cpufreq: Panic if policy is active in cpufreq_policy_free() Date: Fri, 27 May 2022 09:23:34 +0530 Message-Id: <426bf6edc80b2e944d459fa7b8dffbe8b73bb3d9.1653623526.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: <8c3d50faf8811e86136fb3f9c459e43fc3c50bc0.1653565641.git.viresh.kumar@linaro.org> References: <8c3d50faf8811e86136fb3f9c459e43fc3c50bc0.1653565641.git.viresh.kumar@linaro.org> 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,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 With the new design in place, to avoid potential races show() and store() callbacks check if the policy is active or not before proceeding any further. And in order to guarantee that cpufreq_policy_free() must be called after clearing the policy->cpus mask, i.e. by marking it inactive. Lets make sure we don't get a bug around this later and catch this early by putting a BUG_ON() within cpufreq_policy_free(). Also update cpufreq_online() a bit to make sure we clear the cpus mask for each error case before calling cpufreq_policy_free(). Signed-off-by: Viresh Kumar --- V2: Update cpufreq_online() and changelog. drivers/cpufreq/cpufreq.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index e24aa5d4bca5..0f8245731783 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1284,6 +1284,12 @@ static void cpufreq_policy_free(struct cpufreq_policy *policy) unsigned long flags; int cpu; + /* + * The callers must ensure the policy is inactive by now, to avoid any + * races with show()/store() callbacks. + */ + BUG_ON(!policy_is_inactive(policy)); + /* Remove policy from list */ write_lock_irqsave(&cpufreq_driver_lock, flags); list_del(&policy->policy_list); @@ -1538,8 +1544,6 @@ static int cpufreq_online(unsigned int cpu) for_each_cpu(j, policy->real_cpus) remove_cpu_dev_symlink(policy, j, get_cpu_device(j)); - cpumask_clear(policy->cpus); - out_offline_policy: if (cpufreq_driver->offline) cpufreq_driver->offline(policy); @@ -1549,6 +1553,7 @@ static int cpufreq_online(unsigned int cpu) cpufreq_driver->exit(policy); out_free_policy: + cpumask_clear(policy->cpus); up_write(&policy->rwsem); cpufreq_policy_free(policy); -- 2.31.1.272.g89b43f80a514