Received: by 2002:a05:7412:bb8d:b0:d7:7d3a:4fe2 with SMTP id js13csp1850964rdb; Thu, 17 Aug 2023 04:11:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHbi0NOxJuixcjxznW8bgZuJFdI5XyF71ez0DpBST1aH7aWuja3egJFt8GCpvFn2VvT4deP X-Received: by 2002:a54:448b:0:b0:3a4:1f0f:d108 with SMTP id v11-20020a54448b000000b003a41f0fd108mr5037958oiv.46.1692270669214; Thu, 17 Aug 2023 04:11:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692270669; cv=none; d=google.com; s=arc-20160816; b=nMqzp97/JMF6HSWd8LmhBC+4ZeaGyN2YKwynnyypCAFv/Zg+PGvDP0QRHMx3nBwnUf m3+h11jjcaA1KZ63GaiJSkINbcvSY9DCO3fqI4xDtKGL121mDsbW2BuDUEm3WFWc5NjB FKED6jkrUCyqTJjlkmKPc7znlDwaqPplS7abOFRWB8+k9OA5m9wlt/lFWRdWsv4D2gsq DNu6rHYaGupQg2fArUgz7pA0FcG6saxlRKWN53juej7qdJrJjSQzaQDzP9ROHYWP8guI VNSQFJQGtYRL33yeDj0hT1FeAxyg1L8uh1SBaSFC5DTFdnIYFWLxEovvwClsYM2Y6D4+ yiIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:user-agent:mime-version:date:message-id; bh=PHPyg8p3DbCJIRE2TGol6Q9hgjmbI+Ad/6HfbdzLn9o=; fh=zL0RJJbWGhtGViFoY08GZ7xRTleYWZrAT7mNooLCENE=; b=QJbxBjrx2c13KO9Rja1ZYsN1LOL2GMS5KlHZYPQT/RzaKT4U8UGWG/+fsHn95jmf5z up3XErll64C7BL7Pk8gAgyxemvVX2E0/Cyk8rX4sDqj3JFaSoFNJHSqOZVn/M8a+DynV mPnR3bMGKvQFq5Qmd52/cm5tY8Nhu2MpVjp0j8PLeJWqTmlxx1NW0VSJKsJ2wSJM4yYt 3u9jdX38ioTW7Lq5ln3yz66FMo+tOHJgbXm5zTibtEpXUL9NplvIoPF2sD1b+6JsNC5+ kepHJdNvqTId9z4DPnYxVhdY+Yx+ui18QQha3DD60MuJPorAabSRo8SnBvjKOZtqTNhU fpIA== 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s14-20020a63450e000000b0054fe07d2f49si13337327pga.657.2023.08.17.04.10.52; Thu, 17 Aug 2023 04:11:09 -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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233755AbjHQCdn (ORCPT + 99 others); Wed, 16 Aug 2023 22:33:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235022AbjHQCdS (ORCPT ); Wed, 16 Aug 2023 22:33:18 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97900270C; Wed, 16 Aug 2023 19:33:16 -0700 (PDT) Received: from kwepemi500012.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4RR89259nMzNmyn; Thu, 17 Aug 2023 10:29:42 +0800 (CST) Received: from [10.67.110.108] (10.67.110.108) by kwepemi500012.china.huawei.com (7.221.188.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Thu, 17 Aug 2023 10:33:14 +0800 Message-ID: Date: Thu, 17 Aug 2023 10:33:13 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.11.2 Subject: Re: [PATCH v2] cpufreq: cppc: Set fie_disabled to FIE_DISABLED if fails to create kworker_fie To: Viresh Kumar CC: , , References: <20230816094938.862186-1-liaochang1@huawei.com> <20230816103731.qwx3j3rmwyszq45j@vireshk-i7> From: "Liao, Chang" In-Reply-To: <20230816103731.qwx3j3rmwyszq45j@vireshk-i7> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.67.110.108] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemi500012.china.huawei.com (7.221.188.12) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS 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 在 2023/8/16 18:37, Viresh Kumar 写道: > On 16-08-23, 09:49, Liao Chang wrote: >> The function cppc_freq_invariance_init() may failed to create >> kworker_fie, make it more robust by setting fie_disabled to FIE_DISBALED >> to prevent an invalid pointer dereference in kthread_destroy_worker(), >> which called from cppc_freq_invariance_exit(). >> >> Link: https://lore.kernel.org/all/20230816034630.a4hvsj373q6aslk3@vireshk-i7/ >> >> Signed-off-by: Liao Chang >> --- >> drivers/cpufreq/cppc_cpufreq.c | 28 ++++++++++++++++------------ >> 1 file changed, 16 insertions(+), 12 deletions(-) >> >> diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c >> index 022e3555407c..bff4cde06083 100644 >> --- a/drivers/cpufreq/cppc_cpufreq.c >> +++ b/drivers/cpufreq/cppc_cpufreq.c >> @@ -220,6 +220,15 @@ static void cppc_cpufreq_cpu_fie_exit(struct cpufreq_policy *policy) >> } >> } >> >> +static void cppc_freq_invariance_exit(void) >> +{ >> + if (fie_disabled) >> + return; >> + >> + kthread_destroy_worker(kworker_fie); >> + kworker_fie = NULL; >> +} >> + >> static void __init cppc_freq_invariance_init(void) >> { >> struct sched_attr attr = { >> @@ -249,27 +258,22 @@ static void __init cppc_freq_invariance_init(void) >> return; >> >> kworker_fie = kthread_create_worker(0, "cppc_fie"); >> - if (IS_ERR(kworker_fie)) >> + if (IS_ERR(kworker_fie)) { >> + pr_warn("%s: failed to create kworker_fie: %ld\n", __func__, >> + PTR_ERR(kworker_fie)); >> + fie_disabled = FIE_DISABLED; >> return; >> + } >> >> ret = sched_setattr_nocheck(kworker_fie->task, &attr); >> if (ret) { >> pr_warn("%s: failed to set SCHED_DEADLINE: %d\n", __func__, >> ret); >> - kthread_destroy_worker(kworker_fie); >> - return; >> + cppc_freq_invariance_exit(); > > I don't really like this change, there aren't a lot of things that we > need to do here on cleanup, but just kthread_destroy_worker(). Calling > it directly makes more sense I guess. OK,I will simplify code in next revisoin. > >> + fie_disabled = FIE_DISABLED; >> } >> } >> >> -static void cppc_freq_invariance_exit(void) >> -{ >> - if (fie_disabled) >> - return; >> - >> - kthread_destroy_worker(kworker_fie); > >> - kworker_fie = NULL; > > I don't see the point of this line. Probably it can be dropped. I agree with you, when fie_disbaled is set to FIE_DISABLED and kthred_destroy_worker() is called, the driver has no chance to access the invalid kworker_fie pointer. Thanks. > >> -} >> - >> #else >> static inline void cppc_cpufreq_cpu_fie_init(struct cpufreq_policy *policy) >> { >> -- >> 2.34.1 > -- BR Liao, Chang