[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20251025093428.1379218-1-zengheng4@huawei.com>
Date: Sat, 25 Oct 2025 17:34:28 +0800
From: Zeng Heng <zengheng4@...wei.com>
To: <ben.horgan@....com>, <james.morse@....com>
CC: <zengheng4@...wei.com>, <amitsinght@...vell.com>,
<baisheng.gao@...soc.com>, <baolin.wang@...ux.alibaba.com>,
<carl@...amperecomputing.com>, <catalin.marinas@....com>, <dakr@...nel.org>,
<dave.martin@....com>, <david@...hat.com>, <dfustini@...libre.com>,
<fenghuay@...dia.com>, <gregkh@...uxfoundation.org>, <gshan@...hat.com>,
<guohanjun@...wei.com>, <jeremy.linton@....com>,
<jonathan.cameron@...wei.com>, <kobak@...dia.com>, <lcherian@...vell.com>,
<lenb@...nel.org>, <linux-acpi@...r.kernel.org>,
<linux-arm-kernel@...ts.infradead.org>, <linux-kernel@...r.kernel.org>,
<lpieralisi@...nel.org>, <peternewman@...gle.com>, <quic_jiles@...cinc.com>,
<rafael@...nel.org>, <robh@...nel.org>, <rohit.mathew@....com>,
<scott@...amperecomputing.com>, <sdonthineni@...dia.com>,
<sudeep.holla@....com>, <sunnanyong@...wei.com>, <tan.shaopeng@...itsu.com>,
<wangkefeng.wang@...wei.com>, <will@...nel.org>, <xhao@...ux.alibaba.com>
Subject: [PATCH] arm64/mpam: Clean MBWU monitor overflow bit
The MSMON_MBWU register accumulates counts monotonically forward and
would not automatically cleared to zero on overflow. The overflow portion
is exactly what mpam_msmon_overflow_val() computes, there is no need to
additionally subtract mbwu_state->prev_val.
Before invoking write_msmon_ctl_flt_vals(), the overflow bit of the
MSMON_MBWU register must first be read to prevent it from being
inadvertently cleared by the write operation. Then, before updating the
monitor configuration, the overflow bit should be cleared to zero.
Finally, use the overflow bit instead of relying on counter wrap-around
to determine whether an overflow has occurred, that avoids the case where
a wrap-around (now > prev_val) is overlooked.
Signed-off-by: Zeng Heng <zengheng4@...wei.com>
---
drivers/resctrl/mpam_devices.c | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/mpam_devices.c
index 0dd048279e02..575980e3a366 100644
--- a/drivers/resctrl/mpam_devices.c
+++ b/drivers/resctrl/mpam_devices.c
@@ -1062,6 +1062,21 @@ static u64 mpam_msmon_overflow_val(enum mpam_device_features type)
}
}
+static bool read_msmon_mbwu_is_overflow(struct mpam_msc *msc)
+{
+ u32 ctl;
+ bool overflow;
+
+ ctl = mpam_read_monsel_reg(msc, CFG_MBWU_CTL);
+ overflow = ctl & MSMON_CFG_x_CTL_OFLOW_STATUS ? true : false;
+
+ if (overflow)
+ mpam_write_monsel_reg(msc, CFG_MBWU_CTL, ctl &
+ ~MSMON_CFG_x_CTL_OFLOW_STATUS);
+
+ return overflow;
+}
+
/* Call with MSC lock held */
static void __ris_msmon_read(void *arg)
{
@@ -1069,6 +1084,7 @@ static void __ris_msmon_read(void *arg)
bool config_mismatch;
struct mon_read *m = arg;
u64 now, overflow_val = 0;
+ bool mbwu_overflow = false;
struct mon_cfg *ctx = m->ctx;
bool reset_on_next_read = false;
struct mpam_msc_ris *ris = m->ris;
@@ -1091,6 +1107,7 @@ static void __ris_msmon_read(void *arg)
reset_on_next_read = mbwu_state->reset_on_next_read;
mbwu_state->reset_on_next_read = false;
}
+ mbwu_overflow = read_msmon_mbwu_is_overflow(msc);
}
/*
@@ -1138,8 +1155,8 @@ static void __ris_msmon_read(void *arg)
mbwu_state = &ris->mbwu_state[ctx->mon];
/* Add any pre-overflow value to the mbwu_state->val */
- if (mbwu_state->prev_val > now)
- overflow_val = mpam_msmon_overflow_val(m->type) - mbwu_state->prev_val;
+ if (mbwu_overflow)
+ overflow_val = mpam_msmon_overflow_val(m->type);
mbwu_state->prev_val = now;
mbwu_state->correction += overflow_val;
--
2.25.1
Powered by blists - more mailing lists