From nobody Sun Jun 14 08:33:03 2026 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7FE5925D527 for ; Wed, 1 Apr 2026 18:56:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775069762; cv=none; b=s5lOoj7ddca1SOR2Pf3gUaMzZWyvoSEmvl2SQm285xvljNZ6WHN1Z/ymFVdYy0SmFwIxlDNhJ6M8Lu/z/mijXSteY0MPtW5d5+Rdj+Kd7OCf7iWfL+IerhSpdx27mr0Nz/WbQMoAHaMHVHEmokF6jktqnAAHcHa0HAXM69E25sI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775069762; c=relaxed/simple; bh=GLENySPtBP6upKUJeQqq4QK7gsBZYQu2lmtpDoSy+Mc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=rjagAXl99bLFtGuw/LYNFDgGNWq4GIGh0MxbLFeBfajeRWJExJNoV4DmB8VFIlZJMjh8r0QkE7j3K30S07BnPhqsVM0oTH7jGl6y/qweEQDxkdTA1ZNAw6iMeTXikp5cAMu3NWAz+m1Ff3VRAbh2qfYxfiFoEEMwoM3C/WQCe80= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=fgYwa39o; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fgYwa39o" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-486fc4725f0so356965e9.1 for ; Wed, 01 Apr 2026 11:56:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775069759; x=1775674559; darn=vger.kernel.org; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=9td9cq9L5YvCrBxhtAhJpc0r0mukXvHu5vwTqHO44BU=; b=fgYwa39omCyiZlp/ouiQTMb0y6tAAGd1+jwcooYRONZ0/oKm++jlgUNpKqnQ4nxNO8 58QyTejh+At92ZmsbzJZTcq36btqvBQ8glR74bp2vliWnbC7Jag/gvyISxhTFJssWsVA 9df5sVmlTv8xjJxGYFADujAAKbTZiU6DmOXLDjCCk5xZZsOz2kF7dCpKaJsrhu4uQMP8 NAi1YXbQ19lvLLCe7TZ4yJOphYE3aPl8xNnlg0eUQnns++qXSwrX5xsRLxQbS94wOoZe c3FT7/bsg8pp0bUX4DTrcl4/abr03zab8n/DsiPmmRFa7kmop3u8xG25Idt5nJne3Z0+ IAUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775069759; x=1775674559; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=9td9cq9L5YvCrBxhtAhJpc0r0mukXvHu5vwTqHO44BU=; b=SiOmAM7Kr05F5hfRw2ijEsO4h714Niw6jLqLjRxcytHUZ4PkipAoWQItwsGLwu72gk FVSksUoba0xwzw0NoQX/xqktA70qlyI7VC5nT+wvVxOo76twD9eQq0vifkSoeS4rRjuZ 3Y/pBvAcVAZt8e7jq8ikYG+2muqDWDNacf9F58Wg0NF4JV1rWeRdoK1Fkpzr3HEcdvUP c36FJDCHUABh1TjXAlX2+RPWE2JqyNUg3+IUk8EwWqZpBKznvGfdfEfN2z2RlZs0FM6N 5zGLiUxNHEWsE5D61pNez8XVoO+mRHmWy/2xZhU4pYCTINBO1fLwgiB6xJdvrzslPz/p lIQQ== X-Gm-Message-State: AOJu0YxFShDN4pL6dH0Ak1l9qGBFBgVGhSw2zMb5kPi0nmtA+Ci4UfM+ 0mkPXj8AQh3WbxERawlxGZMKydHEefF7rien4NbUG12I5niGcicDZJYb X-Gm-Gg: ATEYQzxCH7RjX6oTzqelaUTrIuxtbQQWwAsefoiK4Aewke8Sgv5Nzr0Jvsp7KEshLWt gZhv0/USMSLqBdx6tSX/0WYGrjEwmQXQsa04fWcR4Vt0cBnKFkaHmHD3CrJCRajZorjBYL3D++f I9i1Yo0LJ9aCoAqpqMA54trwCfrkuwmBCqO3V2yKzSEi/zgaOTGiBpKvlpc5y3TlwoUOJf0y085 DE0hKWTCfcUs9Rb5jT5rQ/0mI/J7cxzxXZpDXhG8l3Q5o5fx4hDkUrX9rPcKfdU+k0aq5nJyVWz qdGUZClCmNkZMdO82/njT8fJqHdknlMwVCTzI/Ha+mzwLZ/GyBV45FESOU0DlOLnwAn9aJb5jLy i9t74tYsrARe4BJuxU4lqN+RsH/W64q+ChE+To8bXEv0E+WPBZ+znWaxBIOOMe8MU4KXALmIwrf 69i8mN5Sbfk8ddKk0nC6+4vqUqWb1bP+jZTNPSLDYCuFukwywdcrdou0y2 X-Received: by 2002:a05:600c:8509:b0:483:6fe3:bb49 with SMTP id 5b1f17b1804b1-4887810ff5dmr191687805e9.0.1775069758596; Wed, 01 Apr 2026 11:55:58 -0700 (PDT) Received: from [127.0.1.1] (89-65-152-218.dynamic.play.pl. [89.65.152.218]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43d1e2a720dsm1906195f8f.4.2026.04.01.11.55.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Apr 2026 11:55:58 -0700 (PDT) From: Roman 'Hedin' Storozhenko Date: Wed, 01 Apr 2026 20:55:43 +0200 Subject: [PATCH] x86/msr: Use num_possible_cpus() for chrdev minor count Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260401-msr_cpu-v1-1-d8016f61d455@gmail.com> X-B4-Tracking: v=1; b=H4sIAC5qzWkC/6tWKk4tykwtVrJSqFYqSi3LLM7MzwNyDHUUlJIzE vPSU3UzU4B8JSMDIzMDEwND3dziovjkglLdFAuLxJRUQzOj5EQDJaDqgqLUtMwKsEnRsbW1AOB ewh5ZAAAA To: "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org Cc: linux-kernel@vger.kernel.org, Roman 'Hedin' Storozhenko X-Mailer: b4 0.13.0 The MSR driver currently register their character device regions using NR_CPUS as the minor count: __register_chrdev(..., 0, NR_CPUS, ...) This dates back to commit 0b962d473af3 ("x86, msr/cpuid: Register enough minors for the MSR and CPUID drivers"), which intentionally used NR_CPUS as a static upper bound on the maximum CPU index. However, NR_CPUS is a compile-time upper bound and may significantly exceed the actual number of CPUs supported by the running system (i.e. cpu_possible_mask). As a result, the drivers may reserve a much larger minor range than can ever be used at runtime. Replace NR_CPUS with num_possible_cpus() so that the registered minor range reflects the actual system topology instead of a static maximum. The driver already creates and destroy devices dynamically based on CPU hotplug state, so this change only affects the size of the internally reserved minor range and does not alter runtime behavior or userspace-visible interfaces. Signed-off-by: Roman 'Hedin' Storozhenko --- This series replaces NR_CPUS with num_possible_cpus() when registering character device regions for the MSR and CPUID drivers. Historically, commit 0b962d473af3 ("x86, msr/cpuid: Register enough minors for the MSR and CPUID drivers") switched to using NR_CPUS as a static upper bound on the maximum CPU index. While correct, this may result in reserving a significantly larger minor range than is actually usable on a given syste= m. This series updates the drivers to use num_possible_cpus(), aligning the registered minor range with the system=E2=80=99s CPU topology. The change does not affect runtime behavior: devices are still created and destroyed dynamically based on CPU hotplug state. Validation ---------- The change was validated in a virtme-ng environment with: CONFIG_NR_CPUS=3D64 possible CPUs: 0-7 (8 CPUs) 1) Internal state (eBPF) Using bpftrace on __register_chrdev_region(): Before: count =3D 64 After: count =3D 8 This confirms that the registered minor range now reflects num_possible_cpus() instead of NR_CPUS. 2) Userspace-visible behavior No change observed: /dev/cpu/*/msr count: unchanged (8) /sys/class/msr entries: unchanged (8) 3) Functional correctness rdmsr access continues to work as expected. 4) CPU hotplug Tracing msr_device_create shows identical behavior before and after, confirming that device lifecycle remains driven by CPU hotplug events. ---------- Overall, this change reduces over-allocation of minor numbers while preserving existing behavior and interfaces. --- arch/x86/kernel/msr.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c index 4469c784eaa0..7f93f59d3cd9 100644 --- a/arch/x86/kernel/msr.c +++ b/arch/x86/kernel/msr.c @@ -263,7 +263,7 @@ static int __init msr_init(void) { int err; =20 - if (__register_chrdev(MSR_MAJOR, 0, NR_CPUS, "cpu/msr", &msr_fops)) { + if (__register_chrdev(MSR_MAJOR, 0, num_possible_cpus(), "cpu/msr", &msr_= fops)) { pr_err("unable to get major %d for msr\n", MSR_MAJOR); return -EBUSY; } @@ -281,7 +281,7 @@ static int __init msr_init(void) out_class: class_unregister(&msr_class); out_chrdev: - __unregister_chrdev(MSR_MAJOR, 0, NR_CPUS, "cpu/msr"); + __unregister_chrdev(MSR_MAJOR, 0, num_possible_cpus(), "cpu/msr"); return err; } module_init(msr_init); @@ -290,7 +290,7 @@ static void __exit msr_exit(void) { cpuhp_remove_state(cpuhp_msr_state); class_unregister(&msr_class); - __unregister_chrdev(MSR_MAJOR, 0, NR_CPUS, "cpu/msr"); + __unregister_chrdev(MSR_MAJOR, 0, num_possible_cpus(), "cpu/msr"); } module_exit(msr_exit) =20 --- base-commit: 25f9333c7244d9c5a0243bcf045903ba19635d35 change-id: 20260401-msr_cpu-d88ade162ca0 Best regards, --=20 Roman 'Hedin' Storozhenko