Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp296047iob; Wed, 11 May 2022 14:48:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQVahoStynGkAq/PNR5+HWq0xDk51fZAdnSjLAJMXanzpZ7yk6406RAVEAFlEvVQukabtg X-Received: by 2002:a05:6402:27d4:b0:428:2273:12cd with SMTP id c20-20020a05640227d400b00428227312cdmr31459454ede.149.1652305735847; Wed, 11 May 2022 14:48:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652305735; cv=none; d=google.com; s=arc-20160816; b=tW6nGzkXX40uzFOA16gmcDQ0OK7qpEPMa4MZLwG7T9FwQ/WWTQ27KBDz5eEir61Tvi dlfQGa7eO6vvweU9rIQ5/f0Bez2GC6Z2WX+4XLmUp3IcnHcvyn6RtpVJiJ9iIQjV5FGW 7yYLb1ZoFx9f1JSoHKLpS86l6maXdjUCE2BMClLcJETKbM0hw/iDynU31ehz6njeZcTT G7retVtjF4UCylvWoOkan0OD+M3IDDvwmScZCrJ+MuSH6ZTxSYsTJJlodxBWUAV/fi8w 5pP/OZK7e8FGb5QWSO1RDpNIkYu4D2oqqjgNXvgbSQW1o6uS2WtJTrYebrsBfUS3Cc94 /9rg== 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; bh=3s4gLt+yB8pywwqb68gAqLj79LtRlp7/znpW2L+rOBo=; b=DCTnglMkrRV6G7rgjItNaLoDgKYeukqLhLEVxDBTtcDeTlUYGzPGoHGydor9DuWFNz v+0vT4TbxCf9V1Uc1t8gnCK0NVTi2cnx954+YgBYlhL6xwCuoosY4/8zqqrlZk+scwLU 1RoU9ykN9n1AMEeJKuqZLaRVfNqTzHXlmQi66fI5jE52SgRXkgpgVilkufieGwImmhQ+ Eo7SiQYTg61g5cWVGZXOK0NB2DADqdK9TcRSEEqEzjxlLzGbyRodMXR898r37Fqc0VQ0 kcm4tgPR/SPRR2lU7Y6sgIajgCrMv83hfSK2b/o8FxFh9xIW5U2E1U438qEmiOmlab68 W4vw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e10-20020a056402088a00b0041d729425a6si3466244edy.589.2022.05.11.14.48.09; Wed, 11 May 2022 14:48: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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343982AbiEKPwB (ORCPT + 99 others); Wed, 11 May 2022 11:52:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232122AbiEKPv7 (ORCPT ); Wed, 11 May 2022 11:51:59 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B65B263BDC; Wed, 11 May 2022 08:51:57 -0700 (PDT) Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 5.0.0) id d8280e60ce8cbe7d; Wed, 11 May 2022 17:51:55 +0200 Received: from kreacher.localnet (unknown [213.134.181.161]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by v370.home.net.pl (Postfix) with ESMTPSA id E7F4066C3E6; Wed, 11 May 2022 17:51:54 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Viresh Kumar Subject: [PATCH v1 3/3] cpufreq: Rearrange locking in cpufreq_remove_dev() Date: Wed, 11 May 2022 17:51:39 +0200 Message-ID: <1836239.tdWV9SEqCh@kreacher> In-Reply-To: <5585781.DvuYhMxLoT@kreacher> References: <5585781.DvuYhMxLoT@kreacher> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="UTF-8" X-CLIENT-IP: 213.134.181.161 X-CLIENT-HOSTNAME: 213.134.181.161 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvfedrgeehgdeltdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepvddufedrudefgedrudekuddrudeiudenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpedvudefrddufeegrddukedurdduiedupdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeefpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepvhhirhgvshhhrdhkuhhmrghrsehlihhnrghrohdrohhrgh X-DCC--Metrics: v370.home.net.pl 1024; Body=3 Fuz1=3 Fuz2=3 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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 From: Rafael J. Wysocki Currently, cpufreq_remove_dev() invokes the ->exit() driver callback without holding the policy rwsem which is inconsistent with what happens if ->exit() is invoked directly from cpufreq_offline(). It also manipulates the real_cpus mask and removes the CPU device symlink without holding the policy rwsem, but cpufreq_offline() holds the rwsem around the modifications thereof. For consistency, modify cpufreq_remove_dev() to hold the policy rwsem until the ->exit() callback has been called (or it has been determined that it is not necessary to call it). Signed-off-by: Rafael J. Wysocki --- drivers/cpufreq/cpufreq.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) Index: linux-pm/drivers/cpufreq/cpufreq.c =================================================================== --- linux-pm.orig/drivers/cpufreq/cpufreq.c +++ linux-pm/drivers/cpufreq/cpufreq.c @@ -1659,19 +1659,26 @@ static void cpufreq_remove_dev(struct de if (!policy) return; + down_write(&policy->rwsem); + if (cpu_online(cpu)) - cpufreq_offline(cpu); + __cpufreq_offline(cpu, policy); cpumask_clear_cpu(cpu, policy->real_cpus); remove_cpu_dev_symlink(policy, dev); - if (cpumask_empty(policy->real_cpus)) { - /* We did light-weight exit earlier, do full tear down now */ - if (cpufreq_driver->offline) - cpufreq_driver->exit(policy); - - cpufreq_policy_free(policy); + if (!cpumask_empty(policy->real_cpus)) { + up_write(&policy->rwsem); + return; } + + /* We did light-weight exit earlier, do full tear down now */ + if (cpufreq_driver->offline) + cpufreq_driver->exit(policy); + + up_write(&policy->rwsem); + + cpufreq_policy_free(policy); } /**