From nobody Tue Jun 16 07:39:44 2026 Received: from canpmsgout07.his.huawei.com (canpmsgout07.his.huawei.com [113.46.200.222]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0B95B37EFEE for ; Fri, 17 Apr 2026 07:52:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.222 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776412328; cv=none; b=f0die5VI/EK8CrshfW1IQNmFbMyFqyMJF1/Olq2+1HggYkIn/REwzP50RkyT/FRDRxZ3i8hM9eu+ggV7Qd/HhQEeXnZhxx/9ZsF6vYahbW3U9XE+tudb6NbB/YRxTraBO+J5DgLMRiX71uTRl3+QZIhEGU+3iPlnr5ynxuD84aI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776412328; c=relaxed/simple; bh=ELnSW3yLpClXcHidxJHDtv6/y6MjsiuhJZAvlOFp8uM=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=OjGFie8cNS4PIg0fUqPLnpHsgDj11pFpP1QN3ocELVBpUF6fwREYvMPb+otDw9d8mxjG9+kqU7ff7LtjeNHB70KyKFg/WXHUpExC3t+rE9XL51qX4C/PtfiyTsDgZf3Yyo8CWng9+KPor22oFNgrlyBAP973heZrv7vv0oKMMZY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=K/cf9fy8; arc=none smtp.client-ip=113.46.200.222 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="K/cf9fy8" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=88nG6H4r1GizV2chlSnk0hz72ZIJRcXC44bA5b9iwUg=; b=K/cf9fy8RADpjXLfVXndq57EMKjddeFurf5ZMDMVD9T3mWIXf15Sw7Yu+Mn7PlWEUdi+jJfXC jU3v5NvQqrsfcoe/hRa66u8naVyLU1kZGSGlYrDN1AOaGuul3h+QmSnAxukcYu8TQORdbAnas7f kW3ol0846orDC8haKwROswQ= Received: from mail.maildlp.com (unknown [172.19.163.214]) by canpmsgout07.his.huawei.com (SkyGuard) with ESMTPS id 4fxn3w3lw3zLlSv; Fri, 17 Apr 2026 15:45:32 +0800 (CST) Received: from dggpemf500011.china.huawei.com (unknown [7.185.36.131]) by mail.maildlp.com (Postfix) with ESMTPS id 47B9C4056C; Fri, 17 Apr 2026 15:51:51 +0800 (CST) Received: from huawei.com (10.90.53.73) by dggpemf500011.china.huawei.com (7.185.36.131) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 17 Apr 2026 15:51:50 +0800 From: Jinjie Ruan To: , , , , , , , CC: Subject: [PATCH] cpu/hotplug: Fix NULL kobject warning in cpuhp_smt_enable() Date: Fri, 17 Apr 2026 15:55:34 +0800 Message-ID: <20260417075534.3745793-1-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems500002.china.huawei.com (7.221.188.17) To dggpemf500011.china.huawei.com (7.185.36.131) Content-Type: text/plain; charset="utf-8" When booting with `maxcpus` greater than the number of present CPUs (e.g., QEMU -smp cpus=3D4,maxcpus=3D8), some CPUs are marked as 'present' but have= not yet been registered via register_cpu(). Consequently, the per-cpu device objects for these CPUs are not yet initialized. In cpuhp_smt_enable(), the code iterates over all present CPUs. Calling _cpu_up() for these unregistered CPUs eventually leads to sysfs_create_group() being called with a NULL kobject (or a kobject without a directory), triggering the following warning in fs/sysfs/group.c: if (WARN_ON(!kobj || (!update && !kobj->sd))) return -EINVAL; Fix this by adding a check for get_cpu_device(cpu). This ensures that SMT is only enabled for CPUs that have successfully completed their base device registration in sysfs. How to reproduce: 1. echo off > /sys/devices/system/cpu/smt/control psci: CPU1 killed (polled 0 ms) psci: CPU3 killed (polled 0 ms) 2. echo 2 > /sys/devices/system/cpu/smt/control Detected PIPT I-cache on CPU1 GICv3: CPU1: found redistributor 1 region 0:0x00000000080c0000 CPU1: Booted secondary processor 0x0000000001 [0x410fd082] Detected PIPT I-cache on CPU3 GICv3: CPU3: found redistributor 3 region 0:0x0000000008100000 CPU3: Booted secondary processor 0x0000000003 [0x410fd082] ------------[ cut here ]------------ WARNING: fs/sysfs/group.c:137 at internal_create_group+0x41c/0x4bc, CPU#2:= sh/181 Modules linked in: CPU: 2 UID: 0 PID: 181 Comm: sh Not tainted 7.0.0-rc1-00010-g8d13386c7624 = #142 PREEMPT Hardware name: QEMU KVM Virtual Machine, BIOS 0.0.0 02/06/2015 pstate: 20000005 (nzCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=3D--) pc : internal_create_group+0x41c/0x4bc lr : sysfs_create_group+0x18/0x24 sp : ffff80008078ba40 x29: ffff80008078ba40 x28: ffff296c980ad000 x27: ffff00007fb94128 x26: 0000000000000054 x25: ffffd693e845f3f0 x24: 0000000000000001 x23: 0000000000000001 x22: 0000000000000004 x21: 0000000000000000 x20: ffffd693e845fc10 x19: 0000000000000004 x18: 00000000ffffffff x17: 0000000000000000 x16: 0000000000000000 x15: 0000000000000000 x14: 0000000000000358 x13: 0000000000000007 x12: 0000000000000350 x11: 0000000000000008 x10: 0000000000000407 x9 : 0000000000000400 x8 : ffff00007fbf3b60 x7 : 0000000000000000 x6 : ffffd693e845f3f0 x5 : ffff00007fb94128 x4 : 0000000000000000 x3 : ffff000000f4eac0 x2 : ffffd693e7095a08 x1 : 0000000000000000 x0 : 0000000000000000 Call trace: internal_create_group+0x41c/0x4bc (P) sysfs_create_group+0x18/0x24 topology_add_dev+0x1c/0x28 cpuhp_invoke_callback+0x104/0x20c __cpuhp_invoke_callback_range+0x94/0x11c _cpu_up+0x200/0x37c cpuhp_smt_enable+0xbc/0x114 control_store+0xe8/0x1d4 dev_attr_store+0x18/0x2c sysfs_kf_write+0x7c/0x94 kernfs_fop_write_iter+0x128/0x1b8 vfs_write+0x2b0/0x354 ksys_write+0x68/0xfc __arm64_sys_write+0x1c/0x28 invoke_syscall+0x48/0x10c el0_svc_common.constprop.0+0x40/0xe8 do_el0_svc+0x20/0x2c el0_svc+0x34/0x124 el0t_64_sync_handler+0xa0/0xe4 el0t_64_sync+0x198/0x19c ---[ end trace 0000000000000000 ]--- Cc: stable@vger.kernel.org Fixes: eed4583bcf9a6 ("arm64: Kconfig: Enable HOTPLUG_SMT") Signed-off-by: Jinjie Ruan suggested-by me. --- kernel/cpu.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/kernel/cpu.c b/kernel/cpu.c index bc4f7a9ba64e..df725d92ad4f 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -2706,6 +2706,13 @@ int cpuhp_smt_enable(void) cpu_maps_update_begin(); cpu_smt_control =3D CPU_SMT_ENABLED; for_each_present_cpu(cpu) { + /* + * Skip CPUs that have not been registered in sysfs yet. + * This avoids triggering NULL kobject warnings for maxcpus. + */ + if (!get_cpu_device(cpu)) + continue; + /* Skip online CPUs and CPUs on offline nodes */ if (cpu_online(cpu) || !node_online(cpu_to_node(cpu))) continue; --=20 2.34.1