mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ping Li <leeonion.muyu@gmail.com>
To: james.morse@arm.com, ben.horgan@arm.com,
	reinette.chatre@intel.com, fenghuay@nvidia.com
Cc: linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, Ping Li <leeonion.muyu@gmail.com>
Subject: [PATCH] arm_mpam: Account for a MBWU overflow before reading the counter value
Date: Wed, 11 Nov 2026 15:17:09 +0800	[thread overview]
Message-ID: <20261111071709.3115172-1-leeonion.muyu@gmail.com> (raw)

While checking the driver's overflow handling and NRDY behaviour with
the design engineering team, the following problem was found in
__ris_msmon_read_locked():

__ris_msmon_read_locked() reads the MSMON_CFG_MBWU_CTL overflow status
bit, clears it, then reads the counter value. The counter value read is
where the overflow is accounted for, by adding the counter size to the
per-monitor correction value.

If the monitor reports NRDY when the counter value is read,
__ris_msmon_read_locked() returns -EBUSY, and mpam_msmon_read() retries
after waiting. The overflow status bit was already cleared, so the
retry reads it as 0, and the overflow is never accounted for. Each
occurrence silently loses a counter-size increment from the accumulated
bandwidth count.

The overflow status bit was read before it was cleared, so the overflow
has already happened. Account for it before attempting to read the
counter value, as the cleared status bit cannot be re-read.

Signed-off-by: Ping Li <leeonion.muyu@gmail.com>
---
 drivers/resctrl/mpam_devices.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/mpam_devices.c
index 27abf60f4d67..5384c9a4a1ad 100644
--- a/drivers/resctrl/mpam_devices.c
+++ b/drivers/resctrl/mpam_devices.c
@@ -1528,6 +1528,16 @@ static void __ris_msmon_read_locked(struct mon_read *m)
 			return;
 	}
 
+	/*
+	 * The overflow status bit was read above, before being cleared by
+	 * software. The overflow has already happened, so account for it
+	 * even if reading the counter value below fails, as the cleared
+	 * status bit cannot be re-read.
+	 */
+	if (overflow)
+		ris->mbwu_state[ctx->mon].correction +=
+			mpam_msmon_overflow_val(m->type, msc);
+
 	switch (m->type) {
 	case mpam_feat_msmon_csu:
 		m->err = mpam_read_monsel_reg(msc, CSU, &now32);
@@ -1569,9 +1579,6 @@ static void __ris_msmon_read_locked(struct mon_read *m)
 
 		mbwu_state = &ris->mbwu_state[ctx->mon];
 
-		if (overflow)
-			mbwu_state->correction += mpam_msmon_overflow_val(m->type, msc);
-
 		/*
 		 * Include bandwidth consumed before the last hardware reset and
 		 * a counter size increment for each overflow.
-- 
2.34.1


                 reply	other threads:[~2026-11-11  7:17 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261111071709.3115172-1-leeonion.muyu@gmail.com \
    --to=leeonion.muyu@gmail.com \
    --cc=ben.horgan@arm.com \
    --cc=fenghuay@nvidia.com \
    --cc=james.morse@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=reinette.chatre@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®