* [PATCH v2] x86,fs/resctrl: Fix NULL pointer dereference when events force disabled while in mbm_event mode
@ 2025-10-16 13:34 Babu Moger
2025-10-16 18:17 ` Reinette Chatre
2025-10-20 16:16 ` [tip: x86/urgent] x86,fs/resctrl: Fix NULL pointer dereference with events force-disabled " tip-bot2 for Babu Moger
0 siblings, 2 replies; 3+ messages in thread
From: Babu Moger @ 2025-10-16 13:34 UTC (permalink / raw)
To: babu.moger, tony.luck, reinette.chatre, Dave.Martin, james.morse,
tglx, mingo, bp, dave.hansen
Cc: x86, hpa, linux-kernel, peternewman, eranian, gautham.shenoy
The following NULL pointer dereference is encountered on mount of resctrl
fs after booting a system that support assignable counters with the
"rdt=!mbmtotal,!mbmlocal" kernel parameters:
BUG: kernel NULL pointer dereference, address: 0000000000000008
RIP: 0010:mbm_cntr_get
Call Trace:
rdtgroup_assign_cntr_event
rdtgroup_assign_cntrs
rdt_get_tree
Specifying the kernel parameter "rdt=!mbmtotal,!mbmlocal" effectively
disables the legacy X86_FEATURE_CQM_MBM_TOTAL and X86_FEATURE_CQM_MBM_LOCAL
features and thus the MBM events they represent. This results in the
per-domain MBM event related data structures to not be allocated during
resctrl early initialization.
resctrl fs initialization follows by implicitly enabling both MBM total and
local events on a system that supports assignable counters (mbm_event
mode), but this enabling occurs after the per-domain data structures have
been created.
During runtime resctrl fs assumes that an enabled event can access all its
state. This results in NULL pointer dereference when resctrl attempts to
access the un-allocated structures of an enabled event.
Remove the late MBM event enabling from resctrl fs.
This leaves a problem where the X86_FEATURE_CQM_MBM_TOTAL and
X86_FEATURE_CQM_MBM_LOCAL features may be disabled while assignable
counter (mbm_event) mode is enabled without any events to support.
Switching between the "default" and "mbm_event" mode without any events
is not practical.
Create a dependency between the
X86_FEATURE_CQM_MBM_TOTAL/X86_FEATURE_CQM_MBM_LOCAL and X86_FEATURE_ABMC
(assignable counter) hardware features. An x86 system that supports
assignable counters now requires support of X86_FEATURE_CQM_MBM_TOTAL or
X86_FEATURE_CQM_MBM_LOCAL. This ensures all needed MBM related data
structures are created before use and that it is only possible to switch
between "default" and "mbm_event" mode when the same events are available
in both modes. This dependency does not exist in the hardware but this
usage of these feature settings work for known systems.
Fixes: 13390861b426e ("x86,fs/resctrl: Detect Assignable Bandwidth Monitoring feature details")
Co-developed-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Babu Moger <babu.moger@amd.com>
---
v2: Added dependancy of X86_FEATURE_CQM_MBM_TOTAL/X86_FEATURE_CQM_MBM_LOCAL for
X86_FEATURE_ABMC.
Rephrased changelog from Reinette. Thanks
Added Fixes, Co-developed-by, Signed-off-by tags.
v1: https://lore.kernel.org/lkml/6082147693739c4514e4a650a62f805956331d51.1759263540.git.babu.moger@amd.com/
---
arch/x86/kernel/cpu/resctrl/monitor.c | 11 ++++++++++-
fs/resctrl/monitor.c | 16 +++++++---------
2 files changed, 17 insertions(+), 10 deletions(-)
diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c
index 8da3069936be..dffcc8307500 100644
--- a/arch/x86/kernel/cpu/resctrl/monitor.c
+++ b/arch/x86/kernel/cpu/resctrl/monitor.c
@@ -459,7 +459,16 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r)
r->mon.mbm_cfg_mask = ecx & MAX_EVT_CONFIG_BITS;
}
- if (rdt_cpu_has(X86_FEATURE_ABMC)) {
+ /*
+ * resctrl assumes a system that supports assignable counters can
+ * switch to "default" mode. Ensure that there is a "default" mode
+ * to switch to. This enforces a dependency between the independent
+ * X86_FEATURE_ABMC and X86_FEATURE_CQM_MBM_TOTAL/X86_FEATURE_CQM_MBM_LOCAL
+ * hardware features.
+ */
+ if (rdt_cpu_has(X86_FEATURE_ABMC) &&
+ (rdt_cpu_has(X86_FEATURE_CQM_MBM_TOTAL) ||
+ rdt_cpu_has(X86_FEATURE_CQM_MBM_LOCAL))) {
r->mon.mbm_cntr_assignable = true;
cpuid_count(0x80000020, 5, &eax, &ebx, &ecx, &edx);
r->mon.num_mbm_cntrs = (ebx & GENMASK(15, 0)) + 1;
diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c
index 4076336fbba6..572a9925bd6c 100644
--- a/fs/resctrl/monitor.c
+++ b/fs/resctrl/monitor.c
@@ -1782,15 +1782,13 @@ int resctrl_mon_resource_init(void)
mba_mbps_default_event = QOS_L3_MBM_TOTAL_EVENT_ID;
if (r->mon.mbm_cntr_assignable) {
- if (!resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID))
- resctrl_enable_mon_event(QOS_L3_MBM_TOTAL_EVENT_ID);
- if (!resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID))
- resctrl_enable_mon_event(QOS_L3_MBM_LOCAL_EVENT_ID);
- mon_event_all[QOS_L3_MBM_TOTAL_EVENT_ID].evt_cfg = r->mon.mbm_cfg_mask;
- mon_event_all[QOS_L3_MBM_LOCAL_EVENT_ID].evt_cfg = r->mon.mbm_cfg_mask &
- (READS_TO_LOCAL_MEM |
- READS_TO_LOCAL_S_MEM |
- NON_TEMP_WRITE_TO_LOCAL_MEM);
+ if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID))
+ mon_event_all[QOS_L3_MBM_TOTAL_EVENT_ID].evt_cfg = r->mon.mbm_cfg_mask;
+ if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID))
+ mon_event_all[QOS_L3_MBM_LOCAL_EVENT_ID].evt_cfg = r->mon.mbm_cfg_mask &
+ (READS_TO_LOCAL_MEM |
+ READS_TO_LOCAL_S_MEM |
+ NON_TEMP_WRITE_TO_LOCAL_MEM);
r->mon.mbm_assign_on_mkdir = true;
resctrl_file_fflags_init("num_mbm_cntrs",
RFTYPE_MON_INFO | RFTYPE_RES_CACHE);
--
2.34.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] x86,fs/resctrl: Fix NULL pointer dereference when events force disabled while in mbm_event mode
2025-10-16 13:34 [PATCH v2] x86,fs/resctrl: Fix NULL pointer dereference when events force disabled while in mbm_event mode Babu Moger
@ 2025-10-16 18:17 ` Reinette Chatre
2025-10-20 16:16 ` [tip: x86/urgent] x86,fs/resctrl: Fix NULL pointer dereference with events force-disabled " tip-bot2 for Babu Moger
1 sibling, 0 replies; 3+ messages in thread
From: Reinette Chatre @ 2025-10-16 18:17 UTC (permalink / raw)
To: Babu Moger, tony.luck, Dave.Martin, james.morse, tglx, mingo, bp,
dave.hansen
Cc: x86, hpa, linux-kernel, peternewman, eranian, gautham.shenoy
Hi Babu,
On 10/16/25 6:34 AM, Babu Moger wrote:
> The following NULL pointer dereference is encountered on mount of resctrl
> fs after booting a system that support assignable counters with the
> "rdt=!mbmtotal,!mbmlocal" kernel parameters:
>
> BUG: kernel NULL pointer dereference, address: 0000000000000008
> RIP: 0010:mbm_cntr_get
> Call Trace:
> rdtgroup_assign_cntr_event
> rdtgroup_assign_cntrs
> rdt_get_tree
>
> Specifying the kernel parameter "rdt=!mbmtotal,!mbmlocal" effectively
> disables the legacy X86_FEATURE_CQM_MBM_TOTAL and X86_FEATURE_CQM_MBM_LOCAL
> features and thus the MBM events they represent. This results in the
> per-domain MBM event related data structures to not be allocated during
> resctrl early initialization.
>
> resctrl fs initialization follows by implicitly enabling both MBM total and
> local events on a system that supports assignable counters (mbm_event
> mode), but this enabling occurs after the per-domain data structures have
> been created.
>
> During runtime resctrl fs assumes that an enabled event can access all its
> state. This results in NULL pointer dereference when resctrl attempts to
> access the un-allocated structures of an enabled event.
>
> Remove the late MBM event enabling from resctrl fs.
>
> This leaves a problem where the X86_FEATURE_CQM_MBM_TOTAL and
> X86_FEATURE_CQM_MBM_LOCAL features may be disabled while assignable
> counter (mbm_event) mode is enabled without any events to support.
> Switching between the "default" and "mbm_event" mode without any events
> is not practical.
>
> Create a dependency between the
> X86_FEATURE_CQM_MBM_TOTAL/X86_FEATURE_CQM_MBM_LOCAL and X86_FEATURE_ABMC
> (assignable counter) hardware features. An x86 system that supports
> assignable counters now requires support of X86_FEATURE_CQM_MBM_TOTAL or
> X86_FEATURE_CQM_MBM_LOCAL. This ensures all needed MBM related data
> structures are created before use and that it is only possible to switch
> between "default" and "mbm_event" mode when the same events are available
> in both modes. This dependency does not exist in the hardware but this
> usage of these feature settings work for known systems.
>
> Fixes: 13390861b426e ("x86,fs/resctrl: Detect Assignable Bandwidth Monitoring feature details")
> Co-developed-by: Reinette Chatre <reinette.chatre@intel.com>
> Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
> Signed-off-by: Babu Moger <babu.moger@amd.com>
> ---
Thank you very much.
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reinette
^ permalink raw reply [flat|nested] 3+ messages in thread
* [tip: x86/urgent] x86,fs/resctrl: Fix NULL pointer dereference with events force-disabled in mbm_event mode
2025-10-16 13:34 [PATCH v2] x86,fs/resctrl: Fix NULL pointer dereference when events force disabled while in mbm_event mode Babu Moger
2025-10-16 18:17 ` Reinette Chatre
@ 2025-10-20 16:16 ` tip-bot2 for Babu Moger
1 sibling, 0 replies; 3+ messages in thread
From: tip-bot2 for Babu Moger @ 2025-10-20 16:16 UTC (permalink / raw)
To: linux-tip-commits
Cc: Reinette Chatre, Babu Moger, Borislav Petkov (AMD), x86, linux-kernel
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: 19de7113bfac33ba92c004a9b510612bb745cfa0
Gitweb: https://git.kernel.org/tip/19de7113bfac33ba92c004a9b510612bb745cfa0
Author: Babu Moger <babu.moger@amd.com>
AuthorDate: Thu, 16 Oct 2025 08:34:19 -05:00
Committer: Borislav Petkov (AMD) <bp@alien8.de>
CommitterDate: Mon, 20 Oct 2025 18:06:31 +02:00
x86,fs/resctrl: Fix NULL pointer dereference with events force-disabled in mbm_event mode
The following NULL pointer dereference is encountered on mount of resctrl fs
after booting a system that supports assignable counters with the
"rdt=!mbmtotal,!mbmlocal" kernel parameters:
BUG: kernel NULL pointer dereference, address: 0000000000000008
RIP: 0010:mbm_cntr_get
Call Trace:
rdtgroup_assign_cntr_event
rdtgroup_assign_cntrs
rdt_get_tree
Specifying the kernel parameter "rdt=!mbmtotal,!mbmlocal" effectively disables
the legacy X86_FEATURE_CQM_MBM_TOTAL and X86_FEATURE_CQM_MBM_LOCAL features
and the MBM events they represent. This results in the per-domain MBM event
related data structures to not be allocated during early initialization.
resctrl fs initialization follows by implicitly enabling both MBM total and
local events on a system that supports assignable counters (mbm_event mode),
but this enabling occurs after the per-domain data structures have been
created.
After booting, resctrl fs assumes that an enabled event can access all its
state. This results in NULL pointer dereference when resctrl attempts to
access the un-allocated structures of an enabled event.
Remove the late MBM event enabling from resctrl fs.
This leaves a problem where the X86_FEATURE_CQM_MBM_TOTAL and
X86_FEATURE_CQM_MBM_LOCAL features may be disabled while assignable counter
(mbm_event) mode is enabled without any events to support. Switching between
the "default" and "mbm_event" mode without any events is not practical.
Create a dependency between the X86_FEATURE_{CQM_MBM_TOTAL,CQM_MBM_LOCAL} and
X86_FEATURE_ABMC (assignable counter) hardware features. An x86 system that
supports assignable counters now requires support of X86_FEATURE_CQM_MBM_TOTAL
or X86_FEATURE_CQM_MBM_LOCAL.
This ensures all needed MBM related data structures are created before use and
that it is only possible to switch between "default" and "mbm_event" mode when
the same events are available in both modes. This dependency does not exist in
the hardware but this usage of these feature settings work for known systems.
[ bp: Massage commit message. ]
Fixes: 13390861b426e ("x86,fs/resctrl: Detect Assignable Bandwidth Monitoring feature details")
Co-developed-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Babu Moger <babu.moger@amd.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Link: https://patch.msgid.link/a62e6ac063d0693475615edd213d5be5e55443e6.1760560934.git.babu.moger@amd.com
---
arch/x86/kernel/cpu/resctrl/monitor.c | 11 ++++++++++-
fs/resctrl/monitor.c | 16 +++++++---------
2 files changed, 17 insertions(+), 10 deletions(-)
diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c
index 2cd25a0..fe1a2aa 100644
--- a/arch/x86/kernel/cpu/resctrl/monitor.c
+++ b/arch/x86/kernel/cpu/resctrl/monitor.c
@@ -458,7 +458,16 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r)
r->mon.mbm_cfg_mask = ecx & MAX_EVT_CONFIG_BITS;
}
- if (rdt_cpu_has(X86_FEATURE_ABMC)) {
+ /*
+ * resctrl assumes a system that supports assignable counters can
+ * switch to "default" mode. Ensure that there is a "default" mode
+ * to switch to. This enforces a dependency between the independent
+ * X86_FEATURE_ABMC and X86_FEATURE_CQM_MBM_TOTAL/X86_FEATURE_CQM_MBM_LOCAL
+ * hardware features.
+ */
+ if (rdt_cpu_has(X86_FEATURE_ABMC) &&
+ (rdt_cpu_has(X86_FEATURE_CQM_MBM_TOTAL) ||
+ rdt_cpu_has(X86_FEATURE_CQM_MBM_LOCAL))) {
r->mon.mbm_cntr_assignable = true;
cpuid_count(0x80000020, 5, &eax, &ebx, &ecx, &edx);
r->mon.num_mbm_cntrs = (ebx & GENMASK(15, 0)) + 1;
diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c
index 4076336..572a992 100644
--- a/fs/resctrl/monitor.c
+++ b/fs/resctrl/monitor.c
@@ -1782,15 +1782,13 @@ int resctrl_mon_resource_init(void)
mba_mbps_default_event = QOS_L3_MBM_TOTAL_EVENT_ID;
if (r->mon.mbm_cntr_assignable) {
- if (!resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID))
- resctrl_enable_mon_event(QOS_L3_MBM_TOTAL_EVENT_ID);
- if (!resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID))
- resctrl_enable_mon_event(QOS_L3_MBM_LOCAL_EVENT_ID);
- mon_event_all[QOS_L3_MBM_TOTAL_EVENT_ID].evt_cfg = r->mon.mbm_cfg_mask;
- mon_event_all[QOS_L3_MBM_LOCAL_EVENT_ID].evt_cfg = r->mon.mbm_cfg_mask &
- (READS_TO_LOCAL_MEM |
- READS_TO_LOCAL_S_MEM |
- NON_TEMP_WRITE_TO_LOCAL_MEM);
+ if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID))
+ mon_event_all[QOS_L3_MBM_TOTAL_EVENT_ID].evt_cfg = r->mon.mbm_cfg_mask;
+ if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID))
+ mon_event_all[QOS_L3_MBM_LOCAL_EVENT_ID].evt_cfg = r->mon.mbm_cfg_mask &
+ (READS_TO_LOCAL_MEM |
+ READS_TO_LOCAL_S_MEM |
+ NON_TEMP_WRITE_TO_LOCAL_MEM);
r->mon.mbm_assign_on_mkdir = true;
resctrl_file_fflags_init("num_mbm_cntrs",
RFTYPE_MON_INFO | RFTYPE_RES_CACHE);
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-10-20 16:16 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-10-16 13:34 [PATCH v2] x86,fs/resctrl: Fix NULL pointer dereference when events force disabled while in mbm_event mode Babu Moger
2025-10-16 18:17 ` Reinette Chatre
2025-10-20 16:16 ` [tip: x86/urgent] x86,fs/resctrl: Fix NULL pointer dereference with events force-disabled " tip-bot2 for Babu Moger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®