From: Babu Moger <bmoger@amd.com>
To: Sasha Levin <sashal@kernel.org>, stable@vger.kernel.org
Cc: Babu Moger <babu.moger@amd.com>,
"Borislav Petkov (AMD)" <bp@alien8.de>,
Reinette Chatre <reinette.chatre@intel.com>
Subject: Re: [PATCH 6.17.y 1/2] x86/resctrl: Refactor resctrl_arch_rmid_read()
Date: Mon, 20 Oct 2025 12:02:19 -0500 [thread overview]
Message-ID: <96bbf193-6cb5-4993-8033-a2a2faf2e494@amd.com> (raw)
In-Reply-To: <20251020165309.1843541-1-sashal@kernel.org>
Thank you for back-porting.
On 10/20/25 11:53, Sasha Levin wrote:
> From: Babu Moger <babu.moger@amd.com>
>
> [ Upstream commit 7c9ac605e202c4668e441fc8146a993577131ca1 ]
>
> resctrl_arch_rmid_read() adjusts the value obtained from MSR_IA32_QM_CTR to
> account for the overflow for MBM events and apply counter scaling for all the
> events. This logic is common to both reading an RMID and reading a hardware
> counter directly.
>
> Refactor the hardware value adjustment logic into get_corrected_val() to
> prepare for support of reading a hardware counter.
>
> Signed-off-by: Babu Moger <babu.moger@amd.com>
> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
> Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
> Link: https://lore.kernel.org/cover.1757108044.git.babu.moger@amd.com
> Stable-dep-of: 15292f1b4c55 ("x86/resctrl: Fix miscount of bandwidth event when reactivating previously unavailable RMID")
> Signed-off-by: Sasha Levin <sashal@kernel.org>
> ---
> arch/x86/kernel/cpu/resctrl/monitor.c | 38 ++++++++++++++++-----------
> 1 file changed, 23 insertions(+), 15 deletions(-)
>
> diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c
> index c261558276cdd..cff5bcaddf42f 100644
> --- a/arch/x86/kernel/cpu/resctrl/monitor.c
> +++ b/arch/x86/kernel/cpu/resctrl/monitor.c
> @@ -224,24 +224,13 @@ static u64 mbm_overflow_count(u64 prev_msr, u64 cur_msr, unsigned int width)
> return chunks >> shift;
> }
>
> -int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_mon_domain *d,
> - u32 unused, u32 rmid, enum resctrl_event_id eventid,
> - u64 *val, void *ignored)
> +static u64 get_corrected_val(struct rdt_resource *r, struct rdt_mon_domain *d,
> + u32 rmid, enum resctrl_event_id eventid, u64 msr_val)
> {
> struct rdt_hw_mon_domain *hw_dom = resctrl_to_arch_mon_dom(d);
> struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
> - int cpu = cpumask_any(&d->hdr.cpu_mask);
> struct arch_mbm_state *am;
> - u64 msr_val, chunks;
> - u32 prmid;
> - int ret;
> -
> - resctrl_arch_rmid_read_context_check();
> -
> - prmid = logical_rmid_to_physical_rmid(cpu, rmid);
> - ret = __rmid_read_phys(prmid, eventid, &msr_val);
> - if (ret)
> - return ret;
> + u64 chunks;
>
> am = get_arch_mbm_state(hw_dom, rmid, eventid);
> if (am) {
> @@ -253,7 +242,26 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_mon_domain *d,
> chunks = msr_val;
> }
>
> - *val = chunks * hw_res->mon_scale;
> + return chunks * hw_res->mon_scale;
> +}
> +
> +int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_mon_domain *d,
> + u32 unused, u32 rmid, enum resctrl_event_id eventid,
> + u64 *val, void *ignored)
> +{
> + int cpu = cpumask_any(&d->hdr.cpu_mask);
> + u64 msr_val;
> + u32 prmid;
> + int ret;
> +
> + resctrl_arch_rmid_read_context_check();
> +
> + prmid = logical_rmid_to_physical_rmid(cpu, rmid);
> + ret = __rmid_read_phys(prmid, eventid, &msr_val);
> + if (ret)
> + return ret;
> +
> + *val = get_corrected_val(r, d, rmid, eventid, msr_val);
>
> return 0;
> }
prev parent reply other threads:[~2025-10-20 17:02 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-20 7:59 FAILED: patch "[PATCH] x86/resctrl: Fix miscount of bandwidth event when" failed to apply to 6.17-stable tree gregkh
2025-10-20 15:04 ` [PATCH 6.17.y] x86/resctrl: Fix miscount of bandwidth event when reactivating previously unavailable RMID Babu Moger
2025-10-20 15:09 ` Greg KH
2025-10-20 15:42 ` Babu Moger
2025-10-20 16:21 ` Babu Moger
2025-10-20 16:58 ` Babu Moger
2025-10-20 16:53 ` [PATCH 6.17.y 1/2] x86/resctrl: Refactor resctrl_arch_rmid_read() Sasha Levin
2025-10-20 16:53 ` [PATCH 6.17.y 2/2] x86/resctrl: Fix miscount of bandwidth event when reactivating previously unavailable RMID Sasha Levin
2025-10-20 17:02 ` Babu Moger [this message]
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=96bbf193-6cb5-4993-8033-a2a2faf2e494@amd.com \
--to=bmoger@amd.com \
--cc=babu.moger@amd.com \
--cc=bp@alien8.de \
--cc=reinette.chatre@intel.com \
--cc=sashal@kernel.org \
--cc=stable@vger.kernel.org \
/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