From nobody Fri Dec 19 05:03:49 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 82AE5CA0FF8 for ; Sat, 2 Sep 2023 07:50:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351810AbjIBHuF (ORCPT ); Sat, 2 Sep 2023 03:50:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233441AbjIBHuD (ORCPT ); Sat, 2 Sep 2023 03:50:03 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BB54B4 for ; Sat, 2 Sep 2023 00:49:57 -0700 (PDT) Received: from dggpemm100010.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4Rd6T908S3z1M94J; Sat, 2 Sep 2023 15:48:13 +0800 (CST) Received: from dggpemm500007.china.huawei.com (7.185.36.183) by dggpemm100010.china.huawei.com (7.185.36.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Sat, 2 Sep 2023 15:49:55 +0800 Received: from huawei.com (10.175.103.91) by dggpemm500007.china.huawei.com (7.185.36.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Sat, 2 Sep 2023 15:49:54 +0800 From: Yang Yingliang To: CC: , , , , , , , , , , , Subject: [PATCH] sched/smt: fix unbalance sched_smt_present dec/inc Date: Sat, 2 Sep 2023 15:46:09 +0800 Message-ID: <20230902074609.1757507-1-yangyingliang@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.103.91] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm500007.china.huawei.com (7.185.36.183) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" I got the following warn report while doing stress test: jump label: negative count! WARNING: CPU: 3 PID: 38 at kernel/jump_label.c:263 static_key_slow_try_dec+= 0x9d/0xb0 Call Trace: __static_key_slow_dec_cpuslocked+0x16/0x70 sched_cpu_deactivate+0x26e/0x2a0 cpuhp_invoke_callback+0x3ad/0x10d0 cpuhp_thread_fun+0x3f5/0x680 smpboot_thread_fn+0x56d/0x8d0 kthread+0x309/0x400 ret_from_fork+0x41/0x70 ret_from_fork_asm+0x1b/0x30 Becaus when cpuset_cpu_inactive() fails in sched_cpu_deactivate(), the cpu offline failed, but sched_smt_present is decreased before calling sched_cpu_deactivate, it leads unbalance dec/inc, so fix it by increasing sched_smt_present in the error path. Fixes: c5511d03ec09 ("sched/smt: Make sched_smt_present track topology") Signed-off-by: Yang Yingliang Reviewed-by: Chen Yu Reviewed-by: Tim Chen --- kernel/sched/core.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 2299a5cfbfb9..b7ef2df36b75 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -9745,6 +9745,10 @@ int sched_cpu_deactivate(unsigned int cpu) sched_update_numa(cpu, false); ret =3D cpuset_cpu_inactive(cpu); if (ret) { +#ifdef CONFIG_SCHED_SMT + if (cpumask_weight(cpu_smt_mask(cpu)) =3D=3D 2) + static_branch_inc_cpuslocked(&sched_smt_present); +#endif balance_push_set(cpu, false); set_cpu_active(cpu, true); sched_update_numa(cpu, true); --=20 2.25.1