From patchwork Wed Aug 16 09:49:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liao Chang X-Patchwork-Id: 136003 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b82d:0:b0:3f2:4152:657d with SMTP id z13csp1282354vqi; Fri, 18 Aug 2023 02:58:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGRYSsjPGCLoiXV/mUbZBLbFNOTZAI/ktQWjiqUVRMQPwqfAWe+MDs6XQ4tpvXXnU4JJndJ X-Received: by 2002:aa7:d9d3:0:b0:527:3a95:3fa4 with SMTP id v19-20020aa7d9d3000000b005273a953fa4mr2040346eds.20.1692352694382; Fri, 18 Aug 2023 02:58:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692352694; cv=none; d=google.com; s=arc-20160816; b=gvrEXT4Wb8pTbImSUCboCll78YZLYKQpVtizVFLd4QWw7/Pzq9ZxvEksjxiC1/H6uO i+zvQ3d5zTG4xBqJkI0f004Gw3cm6PYCuHA7O5cnl2stU5YERi96oyJ14vDPe+VP1iM3 b7Ll5lE9Br8FK2zvbTy0XqDAuRZebV8Ya1TVeoAw+LOkgDaplV61pQilclhpsulcREOe gbG8r0N768XFe67pEdCA9UmMzFZHzryvbjfCj5rnoBHoupe8PiAVk/cLGXKURrWRATlI vgSOzjNHKpAEiEsOouhRnVN3YBsKfAhiFghevgZVsERORqE6xML787eF/zW3PIglOnEa e5AA== 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 :message-id:date:subject:cc:to:from; bh=jI9dXjwDM8QSOaj31fiWE2TWD8CQ5jVlzZebZjfGqtA=; fh=MkjW1f1ixasRiKuzf2PaYxsdrg4RoFahP+0zEUjLGHA=; b=vqNlv86VDlhFLgWboTT5cZ4IshG3AYN51VULNokTQeWBmae+DHHJ0TKZOjh9r8dDHE RtmT0H0yyovu7xPFAAfo+2+icR67BC8A+ODi6tYsJNRBKYYLFUH1KJnnqrpbL8UqwhmO rpsjSjaETV5tp4+1TEfzQ648hym0LVJTxPddDekN24EmIQgCiUm2r8j8p/jmzsJ6c1l5 pE1PuDgwFURIJSslKxeu9UZpe3WLxgzko/HH38mj3BB/uUK0Bfm2eD4KlAjPZIPMYuHy VOAinijz2QeiIynvamCrmZhevX8GTdkKsPe1EGxOAtfnbOAFcc6tcbx5wY+kL9m6PpZ0 nO4w== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q13-20020aa7cc0d000000b005234e73d32dsi1065889edt.429.2023.08.18.02.57.50; Fri, 18 Aug 2023 02:58:14 -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 S243622AbjHPJwD (ORCPT + 99 others); Wed, 16 Aug 2023 05:52:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243665AbjHPJvy (ORCPT ); Wed, 16 Aug 2023 05:51:54 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A638273B; Wed, 16 Aug 2023 02:51:24 -0700 (PDT) Received: from kwepemi500012.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4RQjzZ0pwTz1GDHX; Wed, 16 Aug 2023 17:50:02 +0800 (CST) Received: from huawei.com (10.67.174.28) 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; Wed, 16 Aug 2023 17:51:21 +0800 From: Liao Chang To: , CC: , Subject: [PATCH v2] cpufreq: cppc: Set fie_disabled to FIE_DISABLED if fails to create kworker_fie Date: Wed, 16 Aug 2023 09:49:38 +0000 Message-ID: <20230816094938.862186-1-liaochang1@huawei.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Originating-IP: [10.67.174.28] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemi500012.china.huawei.com (7.221.188.12) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1774560418975004137 X-GMAIL-MSGID: 1774560418975004137 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(); + fie_disabled = FIE_DISABLED; } } -static void cppc_freq_invariance_exit(void) -{ - if (fie_disabled) - return; - - kthread_destroy_worker(kworker_fie); - kworker_fie = NULL; -} - #else static inline void cppc_cpufreq_cpu_fie_init(struct cpufreq_policy *policy) {