Skip to contentSkip to conversation

arm_mpam: Release the mon_sel lock on mpam_save_mbwu_state() errors

PATCH Applied Ping Li 3 participants 3 messages Oct 20 – Oct 23 MPAM driver

lore
Share & tools
lore

Ping Li

author
#0 lore raw

PATCH 1/1 arm_mpam: Release the mon_sel lock on mpam_save_mbwu_state() errors

mpam_save_mbwu_state() takes the mon_sel lock at the top of each loop iteration, but the four error paths that return after failed MPAMF_MON_SEL register accesses do so without releasing it.

Take the lock with the conditional mon_sel_lock guard class instead, so all exit paths release it.

Fixes a3a94c13c442 ("arm_mpam: propagate MSC access errors for state saving function")
---
 drivers/resctrl/mpam_devices.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/resctrl/mpam_devices.c +5 -7
index 48adc49b833c..c067b6d57d71 100644
@@ -2037,8 +2037,10 @@ static int mpam_save_mbwu_state(void *arg)
 	struct mpam_class *class = ris->vmsc->comp->class;
 
 	for (i = 0; i < ris->props.num_mbwu_mon; i++) {
-		if (WARN_ON_ONCE(!mpam_mon_sel_lock(msc)))
-			return -EIO;
+		ACQUIRE(mon_sel_lock, guard)(msc);
+		ret = ACQUIRE_ERR(mon_sel_lock, &guard);
+		if (ret)
+			return ret;
 
 		mbwu_state = &ris->mbwu_state[i];
 		cfg = &mbwu_state->cfg;
@@ -2061,10 +2063,8 @@ static int mpam_save_mbwu_state(void *arg)
 		cfg->partid = FIELD_GET(MSMON_CFG_x_FLT_PARTID, cur_flt);
 		mbwu_state->enabled = FIELD_GET(MSMON_CFG_x_CTL_EN, cur_ctl);
 
-		if (!mbwu_state->enabled) {
-			mpam_mon_sel_unlock(msc);
+		if (!mbwu_state->enabled)
 			continue;
-		}
 
 		val = 0;
 		mbwu_arg = (struct mon_read) {
@@ -2088,8 +2088,6 @@ static int mpam_save_mbwu_state(void *arg)
 		ret = mpam_write_monsel_reg(msc, CFG_MBWU_CTL, 0);
 		if (ret)
 			return ret;
-
-		mpam_mon_sel_unlock(msc);
 	}
 
 	return 0;

base-commit: 8ea457f746d915d55f78b43d33b1cd618f3d93ad

Signature · 1 line
2.34.1
maintainer Reviewed-by on v1 1/1
#1 lore raw

Hi Ping,

Quoted 9 lines · Ping Li

mpam_save_mbwu_state() takes the mon_sel lock at the top of each loop iteration, but the four error paths that return after failed MPAMF_MON_SEL register accesses do so without releasing it.

Take the lock with the conditional mon_sel_lock guard class instead, so all exit paths release it.

Fixes a3a94c13c442 ("arm_mpam: propagate MSC access errors for state saving function")

Thanks for this. Looks like this was a result of the conflict between the MPAM-Fb series and my minor fixes series.

Cheers,

Ben

Quoted 44 lines
---
 drivers/resctrl/mpam_devices.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/resctrl/mpam_devices.c +5 -7
index 48adc49b833c..c067b6d57d71 100644
@@ -2037,8 +2037,10 @@ static int mpam_save_mbwu_state(void *arg)
 	struct mpam_class *class = ris->vmsc->comp->class;
 
 	for (i = 0; i < ris->props.num_mbwu_mon; i++) {
-		if (WARN_ON_ONCE(!mpam_mon_sel_lock(msc)))
-			return -EIO;
+		ACQUIRE(mon_sel_lock, guard)(msc);
+		ret = ACQUIRE_ERR(mon_sel_lock, &guard);
+		if (ret)
+			return ret;
 
 		mbwu_state = &ris->mbwu_state[i];
 		cfg = &mbwu_state->cfg;
@@ -2061,10 +2063,8 @@ static int mpam_save_mbwu_state(void *arg)
 		cfg->partid = FIELD_GET(MSMON_CFG_x_FLT_PARTID, cur_flt);
 		mbwu_state->enabled = FIELD_GET(MSMON_CFG_x_CTL_EN, cur_ctl);
 
-		if (!mbwu_state->enabled) {
-			mpam_mon_sel_unlock(msc);
+		if (!mbwu_state->enabled)
 			continue;
-		}
 
 		val = 0;
 		mbwu_arg = (struct mon_read) {
@@ -2088,8 +2088,6 @@ static int mpam_save_mbwu_state(void *arg)
 		ret = mpam_write_monsel_reg(msc, CFG_MBWU_CTL, 0);
 		if (ret)
 			return ret;
-
-		mpam_mon_sel_unlock(msc);
 	}
 
 	return 0;

base-commit: 8ea457f746d915d55f78b43d33b1cd618f3d93ad

#2 lore raw
In reply to Ping Li
Quoted 8 lines · Ping Li

mpam_save_mbwu_state() takes the mon_sel lock at the top of each loop iteration, but the four error paths that return after failed MPAMF_MON_SEL register accesses do so without releasing it.

Take the lock with the conditional mon_sel_lock guard class instead, so all exit paths release it.

[...]

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

[1/1] arm_mpam: Release the mon_sel lock on mpam_save_mbwu_state() errors

      https://git.kernel.org/arm64/c/643b64025650