public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf/x86/intel/uncore: Add error handling for uncore_msr_box_ctl()
@ 2025-04-01 14:17 Wentao Liang
  2025-04-01 15:43 ` Liang, Kan
  2025-04-01 18:24 ` Ingo Molnar
  0 siblings, 2 replies; 3+ messages in thread
From: Wentao Liang @ 2025-04-01 14:17 UTC (permalink / raw)
  To: peterz, mingo, acme, namhyung, mark.rutland, alexander.shishkin,
	jolsa, irogers, adrian.hunter, kan.liang, tglx, bp, dave.hansen,
	x86, hpa
  Cc: linux-perf-users, linux-kernel, Wentao Liang, stable

In mtl_uncore_msr_init_box(), the return value of uncore_msr_box_ctl()
needs to be checked before being used as the parameter of wrmsrl().
A proper implementation can be found in ivbep_uncore_msr_init_box().

Add error handling for uncore_msr_box_ctl() to ensure the MSR write
operation is only performed when a valid MSR address is returned.

Fixes: c828441f21dd ("perf/x86/intel/uncore: Add Meteor Lake support")
Cc: stable@vger.kernel.org # v6.3+
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
 arch/x86/events/intel/uncore_snb.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/x86/events/intel/uncore_snb.c b/arch/x86/events/intel/uncore_snb.c
index 3934e1e4e3b1..84070388f495 100644
--- a/arch/x86/events/intel/uncore_snb.c
+++ b/arch/x86/events/intel/uncore_snb.c
@@ -691,7 +691,10 @@ static struct intel_uncore_type mtl_uncore_hac_cbox = {
 
 static void mtl_uncore_msr_init_box(struct intel_uncore_box *box)
 {
-	wrmsrl(uncore_msr_box_ctl(box), SNB_UNC_GLOBAL_CTL_EN);
+	unsigned int msr = uncore_msr_box_ctl(box);
+
+	if (msr)
+		wrmsrl(msr, SNB_UNC_GLOBAL_CTL_EN);
 }
 
 static struct intel_uncore_ops mtl_uncore_msr_ops = {
-- 
2.42.0.windows.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] perf/x86/intel/uncore: Add error handling for uncore_msr_box_ctl()
  2025-04-01 14:17 [PATCH] perf/x86/intel/uncore: Add error handling for uncore_msr_box_ctl() Wentao Liang
@ 2025-04-01 15:43 ` Liang, Kan
  2025-04-01 18:24 ` Ingo Molnar
  1 sibling, 0 replies; 3+ messages in thread
From: Liang, Kan @ 2025-04-01 15:43 UTC (permalink / raw)
  To: Wentao Liang, peterz, mingo, acme, namhyung, mark.rutland,
	alexander.shishkin, jolsa, irogers, adrian.hunter, tglx, bp,
	dave.hansen, x86, hpa
  Cc: linux-perf-users, linux-kernel, stable



On 2025-04-01 10:17 a.m., Wentao Liang wrote:
> In mtl_uncore_msr_init_box(), the return value of uncore_msr_box_ctl()
> needs to be checked before being used as the parameter of wrmsrl().
> A proper implementation can be found in ivbep_uncore_msr_init_box().
> 
> Add error handling for uncore_msr_box_ctl() to ensure the MSR write
> operation is only performed when a valid MSR address is returned.
> 
> Fixes: c828441f21dd ("perf/x86/intel/uncore: Add Meteor Lake support")
> Cc: stable@vger.kernel.org # v6.3+
> Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>

Reviewed-by: Kan Liang <kan.liang@linux.intel.com>

Thanks,
Kan> ---
>  arch/x86/events/intel/uncore_snb.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/x86/events/intel/uncore_snb.c b/arch/x86/events/intel/uncore_snb.c
> index 3934e1e4e3b1..84070388f495 100644
> --- a/arch/x86/events/intel/uncore_snb.c
> +++ b/arch/x86/events/intel/uncore_snb.c
> @@ -691,7 +691,10 @@ static struct intel_uncore_type mtl_uncore_hac_cbox = {
>  
>  static void mtl_uncore_msr_init_box(struct intel_uncore_box *box)
>  {
> -	wrmsrl(uncore_msr_box_ctl(box), SNB_UNC_GLOBAL_CTL_EN);
> +	unsigned int msr = uncore_msr_box_ctl(box);
> +
> +	if (msr)
> +		wrmsrl(msr, SNB_UNC_GLOBAL_CTL_EN);
>  }
>  
>  static struct intel_uncore_ops mtl_uncore_msr_ops = {


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] perf/x86/intel/uncore: Add error handling for uncore_msr_box_ctl()
  2025-04-01 14:17 [PATCH] perf/x86/intel/uncore: Add error handling for uncore_msr_box_ctl() Wentao Liang
  2025-04-01 15:43 ` Liang, Kan
@ 2025-04-01 18:24 ` Ingo Molnar
  1 sibling, 0 replies; 3+ messages in thread
From: Ingo Molnar @ 2025-04-01 18:24 UTC (permalink / raw)
  To: Wentao Liang
  Cc: peterz, mingo, acme, namhyung, mark.rutland, alexander.shishkin,
	jolsa, irogers, adrian.hunter, kan.liang, tglx, bp, dave.hansen,
	x86, hpa, linux-perf-users, linux-kernel, stable


* Wentao Liang <vulab@iscas.ac.cn> wrote:

> In mtl_uncore_msr_init_box(), the return value of uncore_msr_box_ctl()
> needs to be checked before being used as the parameter of wrmsrl().
> A proper implementation can be found in ivbep_uncore_msr_init_box().
> 
> Add error handling for uncore_msr_box_ctl() to ensure the MSR write
> operation is only performed when a valid MSR address is returned.
> 
> Fixes: c828441f21dd ("perf/x86/intel/uncore: Add Meteor Lake support")
> Cc: stable@vger.kernel.org # v6.3+
> Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
> ---
>  arch/x86/events/intel/uncore_snb.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/x86/events/intel/uncore_snb.c b/arch/x86/events/intel/uncore_snb.c
> index 3934e1e4e3b1..84070388f495 100644
> --- a/arch/x86/events/intel/uncore_snb.c
> +++ b/arch/x86/events/intel/uncore_snb.c
> @@ -691,7 +691,10 @@ static struct intel_uncore_type mtl_uncore_hac_cbox = {
>  
>  static void mtl_uncore_msr_init_box(struct intel_uncore_box *box)
>  {
> -	wrmsrl(uncore_msr_box_ctl(box), SNB_UNC_GLOBAL_CTL_EN);
> +	unsigned int msr = uncore_msr_box_ctl(box);
> +
> +	if (msr)
> +		wrmsrl(msr, SNB_UNC_GLOBAL_CTL_EN);

Exactly what happens without this patch, do we crash during boot due to 
the incorrect wrmsr()?

Thanks,

	Ingo

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-04-01 18:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-01 14:17 [PATCH] perf/x86/intel/uncore: Add error handling for uncore_msr_box_ctl() Wentao Liang
2025-04-01 15:43 ` Liang, Kan
2025-04-01 18:24 ` Ingo Molnar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox