Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp3638703ioo; Wed, 25 May 2022 05:10:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzCe20D/X+H3f3GjEN2OqdmU7Gv8lnyglmL1hjfqeP1I37kpSgWQIFIcEErpUUPV9lZrF62 X-Received: by 2002:a17:907:6286:b0:6da:6e24:5e43 with SMTP id nd6-20020a170907628600b006da6e245e43mr28862603ejc.449.1653480629648; Wed, 25 May 2022 05:10:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653480629; cv=none; d=google.com; s=arc-20160816; b=k2Rvh5aRG+tWpYlxSHYKFuYQJhQ/K/6Cdykd7wpyzgCXaQTueVAzMXEy1XVIuUdtQJ WyWP2Ts/yuWrVCBwc1aY1efAgBJQ2K979YC1tnNdb8jF0THzMP49Noyk0Dgt4fbNbWXf MPp3oLSuJI+6u7XNDa1yAMO40gFvsq+m1Iw21Lv7xulM5GQFm+hDJ7zjYJBch0eWg1nR Q5PpsIAGqQqnq0j3f/Cpv/5Nc0QGbACTUM067PY3SFNZ7OGBagZBsi1+NLKNezb9nS0H plf8bWv4Z5cZg8aVGknNgoEG42W1jPVoVhK+Zitg0mPzkMMEmMux05k49kzlK9aOp49n fnzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=J7vss77naDm9fOC8P6NM8lmEpi8zZTDw8bIiy70a/Yk=; b=MSJs9QPMQjH/efMPmYDPfKShUDRXkfi+HyIlUkoSS1VPLi6gYFMRkzQh5y4CLpYsMe 7AGqPemml/a85v9EF4qDtGpsnxQvIrxgBklPOELTXpgHtgbgYswpxSUm/8V6higNaWOF SicZVleyZPd4B13nF0cqZjD9W6FhpF5NH03OOTmMmoO7JSWZjqrYBAAj7QaNIvbz9xw/ hA+JmSc4us3NBJ7UHLMiwXLVunwI4fwV/QOFJD4yZNHbnDNCVTBt6uY5Cm3S62BAnfEr IlcmfvEgOTvDl/PnR4omIeMSqMPYzU42VIi62bnLmjMeKbT23BWlxdcG/tmUL9x+XuKB 08AQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QzZRuZ+O; 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 z66-20020a509e48000000b0042bc5df1476si2111151ede.77.2022.05.25.05.10.02; Wed, 25 May 2022 05:10:29 -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=QzZRuZ+O; 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 S242772AbiEYFcY (ORCPT + 99 others); Wed, 25 May 2022 01:32:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235569AbiEYFcV (ORCPT ); Wed, 25 May 2022 01:32:21 -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 967CC5DD26 for ; Tue, 24 May 2022 22:32:19 -0700 (PDT) Received: by mail-pj1-x1029.google.com with SMTP id x2-20020a17090a1f8200b001e07a64c461so720644pja.4 for ; Tue, 24 May 2022 22:32:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=J7vss77naDm9fOC8P6NM8lmEpi8zZTDw8bIiy70a/Yk=; b=QzZRuZ+O8qEKTbpPmIUUUbXrrBLOVqJhJZOAMhXHuAPtGk2bgfVMmEjvEAwLAmjVhi 8uH26rfPd1GE+7T15JAXzaWMH/s8XfjxJv/t+2OFGQN2sWyU6PgKOg/md3mlW2mDmX3w rGC0TL9GTHSfr/ULBPy0BmZvwlRcRI7jRTJe66ZwRDuReOri3+8fOSDTUfVNm3uVOowL XLcaotd3oOeFnMSRDJZ33qXRHpgel1z5H+XISQXEuB1qf4hna5jf/JOtm6R0i+69h6Ai 1L051SkoMPRF3LxzXcuEZfquPlZgzPn387N1MX3P37Oc5t+gbIWQYYfPvGxOUVs+sOYj jeqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=J7vss77naDm9fOC8P6NM8lmEpi8zZTDw8bIiy70a/Yk=; b=hIK+QHB5IM5nVydUfBP0Ka8xmYfOsO8LXiK6BW1V4/OemDEkb+CKJY3OzHavZwGIyr EHvPTguIrNJYQl4/jBbZtF+Ae6fwjmV/Ramj6h6sb8Q+bq2IHBScUpf8LKMxbcVcfhyi 2yi8skV2oQ4CDQwfIArLVNv8OFYaPms3iTx6sw5m+L/mmsthAZ+PlfRcc/zaamLz+T2D bITUmdLKVoMlyylXjzohCnqrKOEAVpQA1J5E7aXv68Qm87e65UfNNyC0MMawWNdcwZZY zcmzwRbVlSudilaxBN5K69Zkeizp8Rjyo0A3T14jqUDqY2aoSglAcOraYZTOBLtMcumI 2Ldg== X-Gm-Message-State: AOAM532JhtQHnx3QD8JgAzEoS7J/5/iW30jakSmC5IwlXkzjGaWppWxb hxyblumUzH+LXX724X/npO4vGw== X-Received: by 2002:a17:902:6b42:b0:15d:3603:6873 with SMTP id g2-20020a1709026b4200b0015d36036873mr31237100plt.30.1653456739137; Tue, 24 May 2022 22:32:19 -0700 (PDT) Received: from localhost ([122.162.234.2]) by smtp.gmail.com with ESMTPSA id n9-20020a170902f60900b0015e8d4eb2adsm8165528plg.247.2022.05.24.22.32.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 May 2022 22:32:18 -0700 (PDT) Date: Wed, 25 May 2022 11:02:16 +0530 From: Viresh Kumar To: "Rafael J. Wysocki" Cc: Schspa Shi , Linux Kernel Mailing List , Linux PM Subject: Re: [PATCH v3] cpufreq: fix race on cpufreq online Message-ID: <20220525053216.yw4asdj3ynf7fzwo@vireshk-i7> References: <20220512065623.q4aa6y52pst3zpxu@vireshk-i7> <20220513042705.nbnd6vccuiu6lb7a@vireshk-i7> <20220524111456.hw4qugsvt4bm7reh@vireshk-i7> <20220524112917.apcvvvblksg7jdu4@vireshk-i7> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 On 24-05-22, 13:53, Rafael J. Wysocki wrote: > On Tue, May 24, 2022 at 1:48 PM Rafael J. Wysocki wrote: > > So this was done before the entire CPU hotplug rework and it was > > useful at that time. > > > > The current code always runs cpufreq_set_policy() under policy->rwsem > > and governors are stopped under policy->rwsem, so this particular race > > cannot happen AFAICS. > > > > Locking CPU hotplug prevents CPUs from going away while store() is > > running, but in order to run store(), the caller must hold an active > > reference to the policy kobject. That prevents the policy from being > > freed and so policy->rwsem can be acquired. After policy->rwsem has > > been acquired, policy->cpus can be checked to determine whether or not > > there are any online CPUs for the given policy (there may be none), > > because policy->cpus is only manipulated under policy->rwsem. > > > > If a CPU that belongs to the given policy is going away, > > cpufreq_offline() has to remove it from policy->cpus under > > policy->rwsem, so either it has to wait for store() to release > > policy->rwsem, or store() will acquire policy->rwsem after it and will > > find that policy->cpus is empty. > > Moreover, locking CPU hotplug doesn't actually prevent > cpufreq_remove_dev() from running which can happen when the cpufreq > driver is unregistered, for example. Right, we can get rid of this now I believe. -- viresh