Skip to content

Commit 19de711

Browse files
babumogerbp3tk0v
authored andcommitted
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: 1339086 ("x86,fs/resctrl: Detect Assignable Bandwidth Monitoring feature details") Co-developed-by: Reinette Chatre <[email protected]> Signed-off-by: Reinette Chatre <[email protected]> Signed-off-by: Babu Moger <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Reviewed-by: Reinette Chatre <[email protected]> Link: https://patch.msgid.link/a62e6ac063d0693475615edd213d5be5e55443e6.1760560934.git.babu.moger@amd.com
1 parent 211ddde commit 19de711

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

arch/x86/kernel/cpu/resctrl/monitor.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,16 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r)
458458
r->mon.mbm_cfg_mask = ecx & MAX_EVT_CONFIG_BITS;
459459
}
460460

461-
if (rdt_cpu_has(X86_FEATURE_ABMC)) {
461+
/*
462+
* resctrl assumes a system that supports assignable counters can
463+
* switch to "default" mode. Ensure that there is a "default" mode
464+
* to switch to. This enforces a dependency between the independent
465+
* X86_FEATURE_ABMC and X86_FEATURE_CQM_MBM_TOTAL/X86_FEATURE_CQM_MBM_LOCAL
466+
* hardware features.
467+
*/
468+
if (rdt_cpu_has(X86_FEATURE_ABMC) &&
469+
(rdt_cpu_has(X86_FEATURE_CQM_MBM_TOTAL) ||
470+
rdt_cpu_has(X86_FEATURE_CQM_MBM_LOCAL))) {
462471
r->mon.mbm_cntr_assignable = true;
463472
cpuid_count(0x80000020, 5, &eax, &ebx, &ecx, &edx);
464473
r->mon.num_mbm_cntrs = (ebx & GENMASK(15, 0)) + 1;

fs/resctrl/monitor.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1782,15 +1782,13 @@ int resctrl_mon_resource_init(void)
17821782
mba_mbps_default_event = QOS_L3_MBM_TOTAL_EVENT_ID;
17831783

17841784
if (r->mon.mbm_cntr_assignable) {
1785-
if (!resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID))
1786-
resctrl_enable_mon_event(QOS_L3_MBM_TOTAL_EVENT_ID);
1787-
if (!resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID))
1788-
resctrl_enable_mon_event(QOS_L3_MBM_LOCAL_EVENT_ID);
1789-
mon_event_all[QOS_L3_MBM_TOTAL_EVENT_ID].evt_cfg = r->mon.mbm_cfg_mask;
1790-
mon_event_all[QOS_L3_MBM_LOCAL_EVENT_ID].evt_cfg = r->mon.mbm_cfg_mask &
1791-
(READS_TO_LOCAL_MEM |
1792-
READS_TO_LOCAL_S_MEM |
1793-
NON_TEMP_WRITE_TO_LOCAL_MEM);
1785+
if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID))
1786+
mon_event_all[QOS_L3_MBM_TOTAL_EVENT_ID].evt_cfg = r->mon.mbm_cfg_mask;
1787+
if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID))
1788+
mon_event_all[QOS_L3_MBM_LOCAL_EVENT_ID].evt_cfg = r->mon.mbm_cfg_mask &
1789+
(READS_TO_LOCAL_MEM |
1790+
READS_TO_LOCAL_S_MEM |
1791+
NON_TEMP_WRITE_TO_LOCAL_MEM);
17941792
r->mon.mbm_assign_on_mkdir = true;
17951793
resctrl_file_fflags_init("num_mbm_cntrs",
17961794
RFTYPE_MON_INFO | RFTYPE_RES_CACHE);

0 commit comments

Comments
 (0)