Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp820061iob; Fri, 13 May 2022 13:33:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwi+A8FA1tRn2MSsyOUo5ZnP/VJezOMqTrQ3u8SLQNh2SDqiYExTM3Nsc2wARAO0ZFfMVAX X-Received: by 2002:a05:600c:34c8:b0:394:92b4:f63c with SMTP id d8-20020a05600c34c800b0039492b4f63cmr16776184wmq.58.1652473987635; Fri, 13 May 2022 13:33:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652473987; cv=none; d=google.com; s=arc-20160816; b=iXhhO1E+ruKGTyq9vOMM6NOavliEotdl0IgBZSZZKg1IV9nNgXg+fnBzLL9FedFOKW bzCLNBbgbnL7Pydz9x6lTJDzknt16Km2tdLXhc4uvThD190nOvQzDyziT4k+7bYtDC8i ba4cVSBpVP6A6S95x77jKmfj/YbxejtlkH4E/RSthOmO9ESYH1njT+ghDlO6FzA/Zl3/ u2HBe6uViz9PzekzLUR0/ynnJfSVU5a1WzmuaHh98A0HNl0au6BY20RXRZa3z1ThpFVJ raxaUmze6v6/4txRDumW2s7wzM0q/nCnZkdVjyVxiEHZQbnk6Kj93rSbdVZFuFybbgD1 FYuA== 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; bh=73Q4ig9VmqJ22FBOR2b+2j1Ani6FbrMKsnpdJgype9o=; b=bnMHs2UQ3jyCRNCP01Fx2ggsR9+rapnRv6oDWp4JWLOlzibXjm0L18BwBwD/pSbzfj 8uoOM2p14R9z1CocFo/xOJwUAQThrp19MAw7AZztOINEqk0XJoRvncYm46w76WXdYx2d bsrSUm2HR3dWKJaz+fn97dCpOwJOQUus/txqJ/jGf74yUt/iSX0QD0Fl2+z7J/7dcEgU ZaLuZ+JgVI8HmdxrABMI4SraFV8TwHursSsZu1Fh9Eq6jOFlouYGw1Jw22rxMCGvqb9v Qx5CbxlcjmA62NvguyKuXu+y7EGHPlFjBQIvCr9FLOXQL5dt/fLIRvSPSkU6qMyGkM0G 0Jng== 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v12-20020a05600c214c00b0038ebbdaa671si2962653wml.79.2022.05.13.13.32.37; Fri, 13 May 2022 13:33:07 -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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352820AbiELKtc (ORCPT + 99 others); Thu, 12 May 2022 06:49:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352827AbiELKtU (ORCPT ); Thu, 12 May 2022 06:49:20 -0400 Received: from mail-yb1-f178.google.com (mail-yb1-f178.google.com [209.85.219.178]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB67D22D620; Thu, 12 May 2022 03:49:18 -0700 (PDT) Received: by mail-yb1-f178.google.com with SMTP id i38so8911056ybj.13; Thu, 12 May 2022 03:49:18 -0700 (PDT) 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=73Q4ig9VmqJ22FBOR2b+2j1Ani6FbrMKsnpdJgype9o=; b=uUsdP36xRujd6SCekJNuBc+IPRtUT2W8mt0jReGHX4AIM6ELLr8SK80OJIYzn13oKu b9Nh+yP75fpPJEbruMrm+VCcm5x0sVWLjVNk8aKc5Z5zZwEhFb3hm+fxjkkW7YuvFJpo +Df/lYFyaHhdl+NI0ZIHTIpmZ4shBzMF97QvkaZ8SGYLZrS3I7rn6OuMXbMRHfHut5Q0 9mMs4chISGF8tsSR86AhYuIu4uO6isp3qhs7dgU2IrlCw+4/NlXzmEzrKsEqJxLv0UcL ct4a9kCXpHgSUF3VYGm9TvcDOT/YWI0/PySzrGxHCoXLX5dKiKDAjEGxIE/42IU3/lRA 4hog== X-Gm-Message-State: AOAM531KEfZMyvjoNnMI8uS+wccv1qLncG+OmDnjHpCcB1QRLZ3heaDU LTUSoYs4FCZ6c98z7IMaEsXLxIjKLZs45JiWy6gjHv/HMwU= X-Received: by 2002:a25:e792:0:b0:645:7ddb:b5eb with SMTP id e140-20020a25e792000000b006457ddbb5ebmr27902834ybh.482.1652352557949; Thu, 12 May 2022 03:49:17 -0700 (PDT) MIME-Version: 1.0 References: <20220510035259.5ep52sgahd2a6rie@vireshk-i7> <20220510154236.88753-1-schspa@gmail.com> <20220511043515.fn2gz6q3kcpdai5p@vireshk-i7> <20220511122114.wccgyur6g3qs6fps@vireshk-i7> <20220512065623.q4aa6y52pst3zpxu@vireshk-i7> In-Reply-To: <20220512065623.q4aa6y52pst3zpxu@vireshk-i7> From: "Rafael J. Wysocki" Date: Thu, 12 May 2022 12:49:07 +0200 Message-ID: Subject: Re: [PATCH v3] cpufreq: fix race on cpufreq online To: Viresh Kumar Cc: "Rafael J. Wysocki" , Schspa Shi , Linux Kernel Mailing List , Linux PM Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, 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 On Thu, May 12, 2022 at 8:56 AM Viresh Kumar wrote: > > On 11-05-22, 15:19, Rafael J. Wysocki wrote: > > On Wed, May 11, 2022 at 2:59 PM Rafael J. Wysocki wrote: > > > > Hmm, I don't think depending on the values of policy->cpus is a good idea to be > > > > honest. This design is inviting bugs to come in at another place. We need a > > > > clear flag for this, a new flag or something like policy_list. > > > > Why? > > Because it doesn't mean anything unless we have code elsewhere which checks this > specifically. It should be fine though after using policy_is_inactive() in > show/store as you suggested, which I too tried to do in a patch :) > > > > > Also I see the same bug happening while the policy is removed. The kobject is > > > > put after the rwsem is dropped. > > > > This shouldn't be a problem because of the wait_for_completion() in > > cpufreq_policy_put_kobj(). It is known that cpufreq_sysfs_release() > > has run when cpufreq_policy_put_kobj() returns, so it is safe to free > > the policy then. > > I agree to that, but the destruction of stuff happens right in > cpufreq_policy_free() where it starts removing the policy from the list and > clears cpufreq_cpu_data. I don't know if it will break anything or not, but we > should disallow any further sysfs operations once we have reached > cpufreq_policy_free(). Well, would there be a problem with moving the cpufreq_policy_put_kobj() call to the front of cpufreq_policy_free()? If we did that, we'd know that everything could be torn down safely, because nobody would be holding references to the policy any more. > > TBH, I'm not sure why show() doesn't check policy_is_inactive() under the rwsem. > > I agree, both show/store should have it. > > > Moreover, I'm not sure why the locking dance in store() is necessary. > > commit fdd320da84c6 ("cpufreq: Lock CPU online/offline in cpufreq_register_driver()") I get that, but I'm wondering if locking CPU hotplug from store() is needed at all. I mean, if we are in store(), we are holding an active reference to the policy kobject, so the policy cannot go away until we are done anyway. Thus it should be sufficient to use the policy rwsem for synchronization.