Skip to contentSkip to conversation

arm_mpam: guard MBWU state before adding it to garbage

PATCH Applied Guangshuo Li 3 participants 3 messages Jul 8 – Jul 16 MPAM driver

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm_mpam: guard MBWU state before adding it to garbage

__destroy_component_cfg() adds each RIS mbwu_state object to the MPAM garbage list when destroying component configuration.

However, mbwu_state is allocated per RIS and only for RISes with MBWU monitors. A component can therefore have comp->cfg allocated while some RISes still have ris->mbwu_state set to NULL.

Passing a NULL mbwu_state to add_to_garbage() dereferences the NULL pointer inside the macro.

Skip RISes that do not have an mbwu_state object before adding them to the garbage list.

Fixes 41e8a14950e1 ("arm_mpam: Track bandwidth counter state for power management")
---
 drivers/resctrl/mpam_devices.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/resctrl/mpam_devices.c +4 -2
index b69f99488111..59225694255f 100644
@@ -2606,8 +2606,10 @@ static void __destroy_component_cfg(struct mpam_component *comp)
 		msc = vmsc->msc;
 
 		if (mpam_mon_sel_lock(msc)) {
-			list_for_each_entry(ris, &vmsc->ris, vmsc_list)
-				add_to_garbage(ris->mbwu_state);
+			list_for_each_entry(ris, &vmsc->ris, vmsc_list) {
+				if (ris->mbwu_state)
+					add_to_garbage(ris->mbwu_state);
+			}
 			mpam_mon_sel_unlock(msc);
 		}
 	}
Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 1/1
#1 lore raw

Hi Guangshuo,

Quoted 7 lines · Guangshuo Li

__destroy_component_cfg() adds each RIS mbwu_state object to the MPAM garbage list when destroying component configuration.

However, mbwu_state is allocated per RIS and only for RISes with MBWU monitors. A component can therefore have comp->cfg allocated while some RISes still have ris->mbwu_state set to NULL.

Quoted 8 lines

Passing a NULL mbwu_state to add_to_garbage() dereferences the NULL pointer inside the macro.

Skip RISes that do not have an mbwu_state object before adding them to the garbage list.

Fixes 41e8a14950e1 ("arm_mpam: Track bandwidth counter state for power management")

Good spot and thanks for the fix.

Quoted 21 lines
---
 drivers/resctrl/mpam_devices.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/resctrl/mpam_devices.c +4 -2
index b69f99488111..59225694255f 100644
@@ -2606,8 +2606,10 @@ static void __destroy_component_cfg(struct mpam_component *comp)
 		msc = vmsc->msc;
 
 		if (mpam_mon_sel_lock(msc)) {
-			list_for_each_entry(ris, &vmsc->ris, vmsc_list)
-				add_to_garbage(ris->mbwu_state);
+			list_for_each_entry(ris, &vmsc->ris, vmsc_list) {
+				if (ris->mbwu_state)
+					add_to_garbage(ris->mbwu_state);
+			}
 			mpam_mon_sel_unlock(msc);
 		}
 	}
Applied
#2 lore raw
In reply to Guangshuo Li
Quoted 8 lines · Guangshuo Li

__destroy_component_cfg() adds each RIS mbwu_state object to the MPAM garbage list when destroying component configuration.

However, mbwu_state is allocated per RIS and only for RISes with MBWU monitors. A component can therefore have comp->cfg allocated while some RISes still have ris->mbwu_state set to NULL.

[...]

Applied to arm64 (for-next/fixes), thanks!

[1/1] arm_mpam: guard MBWU state before adding it to garbage

      https://git.kernel.org/arm64/c/977f52909c62

Cheers,

Signature · 5 lines
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev