linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 0/3] MSR fixes and cleanups after last round of MSR cleanups
@ 2025-05-12  8:45 Xin Li (Intel)
  2025-05-12  8:45 ` [PATCH v1 1/3] x86/msr: Remove a superfluous inclusion of <asm/asm.h> Xin Li (Intel)
                   ` (2 more replies)
  0 siblings, 3 replies; 22+ messages in thread
From: Xin Li (Intel) @ 2025-05-12  8:45 UTC (permalink / raw)
  To: linux-kernel, xen-devel, linux-acpi
  Cc: tglx, mingo, bp, dave.hansen, x86, hpa, peterz, jgross,
	boris.ostrovsky, rafael, lenb

These patches:

1) remove a superfluous inclusion of <asm/asm.h> accidently added to
   drivers/acpi/processor_throttling.c in commit:

     efef7f184f2e ("x86/msr: Add explicit includes of <asm/msr.h>").

2) Fix uninitialized symbol 'err' introduced by:

     d815da84fdd0 ("x86/msr: Change the function type of native_read_msr_safe()").

3) Convert a native_wrmsr() use to native_wrmsrq() in
   arch/x86/coco/sev/core.c.


Xin Li (Intel) (3):
  x86/msr: Remove a superfluous inclusion of <asm/asm.h>
  x86/xen/msr: Fix uninitialized symbol 'err'
  x86/msr: Convert a native_wrmsr() use to native_wrmsrq()

 arch/x86/coco/sev/core.c            | 7 +------
 arch/x86/xen/enlighten_pv.c         | 5 ++++-
 drivers/acpi/processor_throttling.c | 1 -
 3 files changed, 5 insertions(+), 8 deletions(-)


base-commit: 9cf78722003178b09c409df9aafe9d79e5b9a74e
-- 
2.49.0


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

* [PATCH v1 1/3] x86/msr: Remove a superfluous inclusion of <asm/asm.h>
  2025-05-12  8:45 [PATCH v1 0/3] MSR fixes and cleanups after last round of MSR cleanups Xin Li (Intel)
@ 2025-05-12  8:45 ` Xin Li (Intel)
  2025-05-18  6:50   ` [tip: x86/core] " tip-bot2 for Xin Li (Intel)
  2025-05-12  8:45 ` [PATCH v1 2/3] x86/xen/msr: Fix uninitialized symbol 'err' Xin Li (Intel)
  2025-05-12  8:45 ` [PATCH v1 3/3] x86/msr: Convert a native_wrmsr() use to native_wrmsrq() Xin Li (Intel)
  2 siblings, 1 reply; 22+ messages in thread
From: Xin Li (Intel) @ 2025-05-12  8:45 UTC (permalink / raw)
  To: linux-kernel, xen-devel, linux-acpi
  Cc: tglx, mingo, bp, dave.hansen, x86, hpa, peterz, jgross,
	boris.ostrovsky, rafael, lenb

The following commit:

  efef7f184f2e ("x86/msr: Add explicit includes of <asm/msr.h>")

added a superfluous inclusion of <asm/asm.h> to

  drivers/acpi/processor_throttling.c.

Remove it.

Signed-off-by: Xin Li (Intel) <xin@zytor.com>
---
 drivers/acpi/processor_throttling.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/acpi/processor_throttling.c b/drivers/acpi/processor_throttling.c
index ecd7fe256153..d1541a386fbc 100644
--- a/drivers/acpi/processor_throttling.c
+++ b/drivers/acpi/processor_throttling.c
@@ -21,7 +21,6 @@
 #include <linux/uaccess.h>
 #include <acpi/processor.h>
 #include <asm/io.h>
-#include <asm/asm.h>
 #ifdef CONFIG_X86
 #include <asm/msr.h>
 #endif
-- 
2.49.0


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

* [PATCH v1 2/3] x86/xen/msr: Fix uninitialized symbol 'err'
  2025-05-12  8:45 [PATCH v1 0/3] MSR fixes and cleanups after last round of MSR cleanups Xin Li (Intel)
  2025-05-12  8:45 ` [PATCH v1 1/3] x86/msr: Remove a superfluous inclusion of <asm/asm.h> Xin Li (Intel)
@ 2025-05-12  8:45 ` Xin Li (Intel)
  2025-05-15 15:29   ` Ingo Molnar
  2025-05-12  8:45 ` [PATCH v1 3/3] x86/msr: Convert a native_wrmsr() use to native_wrmsrq() Xin Li (Intel)
  2 siblings, 1 reply; 22+ messages in thread
From: Xin Li (Intel) @ 2025-05-12  8:45 UTC (permalink / raw)
  To: linux-kernel, xen-devel, linux-acpi
  Cc: tglx, mingo, bp, dave.hansen, x86, hpa, peterz, jgross,
	boris.ostrovsky, rafael, lenb

xen_read_msr_safe() currently passes an uninitialized argument err to
xen_do_read_msr().  But as xen_do_read_msr() may not set the argument,
xen_read_msr_safe() could return err with an unpredictable value.

To ensure correctness, initialize err to 0 (representing success)
in xen_read_msr_safe().

Because xen_read_msr_safe() is essentially a wrapper of xen_do_read_msr(),
the latter should be responsible for initializing the value of *err to 0.
Thus initialize *err to 0 in xen_do_read_msr().

Fixes: 502ad6e5a619 ("x86/msr: Change the function type of native_read_msr_safe()")
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Closes: https://lore.kernel.org/xen-devel/aBxNI_Q0-MhtBSZG@stanley.mountain/
Signed-off-by: Xin Li (Intel) <xin@zytor.com>
---
 arch/x86/xen/enlighten_pv.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_pv.c
index 3be38350f044..01f1d441347e 100644
--- a/arch/x86/xen/enlighten_pv.c
+++ b/arch/x86/xen/enlighten_pv.c
@@ -1091,6 +1091,9 @@ static u64 xen_do_read_msr(u32 msr, int *err)
 {
 	u64 val = 0;	/* Avoid uninitialized value for safe variant. */
 
+	if (err)
+		*err = 0;
+
 	if (pmu_msr_chk_emulated(msr, &val, true))
 		return val;
 
@@ -1162,7 +1165,7 @@ static void xen_do_write_msr(u32 msr, u64 val, int *err)
 
 static int xen_read_msr_safe(u32 msr, u64 *val)
 {
-	int err;
+	int err = 0;
 
 	*val = xen_do_read_msr(msr, &err);
 	return err;
-- 
2.49.0


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

* [PATCH v1 3/3] x86/msr: Convert a native_wrmsr() use to native_wrmsrq()
  2025-05-12  8:45 [PATCH v1 0/3] MSR fixes and cleanups after last round of MSR cleanups Xin Li (Intel)
  2025-05-12  8:45 ` [PATCH v1 1/3] x86/msr: Remove a superfluous inclusion of <asm/asm.h> Xin Li (Intel)
  2025-05-12  8:45 ` [PATCH v1 2/3] x86/xen/msr: Fix uninitialized symbol 'err' Xin Li (Intel)
@ 2025-05-12  8:45 ` Xin Li (Intel)
  2025-05-15 15:27   ` Ingo Molnar
  2025-05-19 17:05   ` Xin Li
  2 siblings, 2 replies; 22+ messages in thread
From: Xin Li (Intel) @ 2025-05-12  8:45 UTC (permalink / raw)
  To: linux-kernel, xen-devel, linux-acpi
  Cc: tglx, mingo, bp, dave.hansen, x86, hpa, peterz, jgross,
	boris.ostrovsky, rafael, lenb

Convert a native_wrmsr() use to native_wrmsrq() to zap meaningless type
conversions when a u64 MSR value is splitted into two u32.

Signed-off-by: Xin Li (Intel) <xin@zytor.com>
---
 arch/x86/coco/sev/core.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c
index ff82151f7718..b3ce6fc8b62d 100644
--- a/arch/x86/coco/sev/core.c
+++ b/arch/x86/coco/sev/core.c
@@ -282,12 +282,7 @@ static inline u64 sev_es_rd_ghcb_msr(void)
 
 static __always_inline void sev_es_wr_ghcb_msr(u64 val)
 {
-	u32 low, high;
-
-	low  = (u32)(val);
-	high = (u32)(val >> 32);
-
-	native_wrmsr(MSR_AMD64_SEV_ES_GHCB, low, high);
+	native_wrmsrq(MSR_AMD64_SEV_ES_GHCB, val);
 }
 
 static int vc_fetch_insn_kernel(struct es_em_ctxt *ctxt,
-- 
2.49.0


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

* Re: [PATCH v1 3/3] x86/msr: Convert a native_wrmsr() use to native_wrmsrq()
  2025-05-12  8:45 ` [PATCH v1 3/3] x86/msr: Convert a native_wrmsr() use to native_wrmsrq() Xin Li (Intel)
@ 2025-05-15 15:27   ` Ingo Molnar
  2025-05-15 17:54     ` Xin Li
  2025-05-19 17:05   ` Xin Li
  1 sibling, 1 reply; 22+ messages in thread
From: Ingo Molnar @ 2025-05-15 15:27 UTC (permalink / raw)
  To: Xin Li (Intel)
  Cc: linux-kernel, xen-devel, linux-acpi, tglx, bp, dave.hansen, x86,
	hpa, peterz, jgross, boris.ostrovsky, rafael, lenb


* Xin Li (Intel) <xin@zytor.com> wrote:

> Convert a native_wrmsr() use to native_wrmsrq() to zap meaningless type
> conversions when a u64 MSR value is splitted into two u32.
> 
> Signed-off-by: Xin Li (Intel) <xin@zytor.com>
> ---
>  arch/x86/coco/sev/core.c | 7 +------
>  1 file changed, 1 insertion(+), 6 deletions(-)
> 
> diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c
> index ff82151f7718..b3ce6fc8b62d 100644
> --- a/arch/x86/coco/sev/core.c
> +++ b/arch/x86/coco/sev/core.c
> @@ -282,12 +282,7 @@ static inline u64 sev_es_rd_ghcb_msr(void)
>  
>  static __always_inline void sev_es_wr_ghcb_msr(u64 val)
>  {
> -	u32 low, high;
> -
> -	low  = (u32)(val);
> -	high = (u32)(val >> 32);
> -
> -	native_wrmsr(MSR_AMD64_SEV_ES_GHCB, low, high);
> +	native_wrmsrq(MSR_AMD64_SEV_ES_GHCB, val);

BTW., at this point we should probably just replace 
sev_es_wr_ghcb_msr() calls with direct calls to:

	native_wrmsrq(MSR_AMD64_SEV_ES_GHCB, ...);

as sev_es_wr_ghcb_msr() is now basically an open-coded native_wrmsrq().

Thanks,

	Ingo

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

* Re: [PATCH v1 2/3] x86/xen/msr: Fix uninitialized symbol 'err'
  2025-05-12  8:45 ` [PATCH v1 2/3] x86/xen/msr: Fix uninitialized symbol 'err' Xin Li (Intel)
@ 2025-05-15 15:29   ` Ingo Molnar
  2025-05-15 18:11     ` Xin Li
  0 siblings, 1 reply; 22+ messages in thread
From: Ingo Molnar @ 2025-05-15 15:29 UTC (permalink / raw)
  To: Xin Li (Intel)
  Cc: linux-kernel, xen-devel, linux-acpi, tglx, bp, dave.hansen, x86,
	hpa, peterz, jgross, boris.ostrovsky, rafael, lenb


* Xin Li (Intel) <xin@zytor.com> wrote:

> xen_read_msr_safe() currently passes an uninitialized argument err to
> xen_do_read_msr().  But as xen_do_read_msr() may not set the argument,
> xen_read_msr_safe() could return err with an unpredictable value.
> 
> To ensure correctness, initialize err to 0 (representing success)
> in xen_read_msr_safe().
> 
> Because xen_read_msr_safe() is essentially a wrapper of xen_do_read_msr(),
> the latter should be responsible for initializing the value of *err to 0.
> Thus initialize *err to 0 in xen_do_read_msr().
> 
> Fixes: 502ad6e5a619 ("x86/msr: Change the function type of native_read_msr_safe()")
> Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> Closes: https://lore.kernel.org/xen-devel/aBxNI_Q0-MhtBSZG@stanley.mountain/
> Signed-off-by: Xin Li (Intel) <xin@zytor.com>
> ---
>  arch/x86/xen/enlighten_pv.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_pv.c
> index 3be38350f044..01f1d441347e 100644
> --- a/arch/x86/xen/enlighten_pv.c
> +++ b/arch/x86/xen/enlighten_pv.c
> @@ -1091,6 +1091,9 @@ static u64 xen_do_read_msr(u32 msr, int *err)
>  {
>  	u64 val = 0;	/* Avoid uninitialized value for safe variant. */
>  
> +	if (err)
> +		*err = 0;
> +
>  	if (pmu_msr_chk_emulated(msr, &val, true))
>  		return val;
>  
> @@ -1162,7 +1165,7 @@ static void xen_do_write_msr(u32 msr, u64 val, int *err)
>  
>  static int xen_read_msr_safe(u32 msr, u64 *val)
>  {
> -	int err;
> +	int err = 0;
>  
>  	*val = xen_do_read_msr(msr, &err);
>  	return err;

So why not initialize 'err' with 0 in both callers, xen_read_msr_safe() 
and xen_read_msr(), and avoid all the initialization trouble in 
xen_do_read_msr()?

Thanks,

	Ingo

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

* Re: [PATCH v1 3/3] x86/msr: Convert a native_wrmsr() use to native_wrmsrq()
  2025-05-15 15:27   ` Ingo Molnar
@ 2025-05-15 17:54     ` Xin Li
  2025-05-17  4:42       ` Xin Li
  0 siblings, 1 reply; 22+ messages in thread
From: Xin Li @ 2025-05-15 17:54 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, xen-devel, linux-acpi, tglx, bp, dave.hansen, x86,
	hpa, peterz, jgross, boris.ostrovsky, rafael, lenb

On 5/15/2025 8:27 AM, Ingo Molnar wrote:
> 
> * Xin Li (Intel) <xin@zytor.com> wrote:
> 
>> Convert a native_wrmsr() use to native_wrmsrq() to zap meaningless type
>> conversions when a u64 MSR value is splitted into two u32.
>>
> 
> BTW., at this point we should probably just replace
> sev_es_wr_ghcb_msr() calls with direct calls to:
> 
> 	native_wrmsrq(MSR_AMD64_SEV_ES_GHCB, ...);
> 
> as sev_es_wr_ghcb_msr() is now basically an open-coded native_wrmsrq().
> 

I thought about it, however it looks to me that current code prefers not
to spread MSR_AMD64_SEV_ES_GHCB in 17 callsites.  And anyway it's a 
__always_inline function.

But as you have asked, I will make the change unless someone objects.

Thanks!
     Xin

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

* Re: [PATCH v1 2/3] x86/xen/msr: Fix uninitialized symbol 'err'
  2025-05-15 15:29   ` Ingo Molnar
@ 2025-05-15 18:11     ` Xin Li
  2025-05-16 13:19       ` Ingo Molnar
  2025-05-16 13:42       ` Jürgen Groß
  0 siblings, 2 replies; 22+ messages in thread
From: Xin Li @ 2025-05-15 18:11 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, xen-devel, linux-acpi, tglx, bp, dave.hansen, x86,
	hpa, peterz, jgross, boris.ostrovsky, rafael, lenb

On 5/15/2025 8:29 AM, Ingo Molnar wrote:
> 
> * Xin Li (Intel) <xin@zytor.com> wrote:
> 
>> xen_read_msr_safe() currently passes an uninitialized argument err to
>> xen_do_read_msr().  But as xen_do_read_msr() may not set the argument,
>> xen_read_msr_safe() could return err with an unpredictable value.
>>
>> To ensure correctness, initialize err to 0 (representing success)
>> in xen_read_msr_safe().
>>
>> Because xen_read_msr_safe() is essentially a wrapper of xen_do_read_msr(),
>> the latter should be responsible for initializing the value of *err to 0.
>> Thus initialize *err to 0 in xen_do_read_msr().
>>
>> Fixes: 502ad6e5a619 ("x86/msr: Change the function type of native_read_msr_safe()")
>> Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
>> Closes: https://lore.kernel.org/xen-devel/aBxNI_Q0-MhtBSZG@stanley.mountain/
>> Signed-off-by: Xin Li (Intel) <xin@zytor.com>
>> ---
>>   arch/x86/xen/enlighten_pv.c | 5 ++++-
>>   1 file changed, 4 insertions(+), 1 deletion(-)
>>
>> diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_pv.c
>> index 3be38350f044..01f1d441347e 100644
>> --- a/arch/x86/xen/enlighten_pv.c
>> +++ b/arch/x86/xen/enlighten_pv.c
>> @@ -1091,6 +1091,9 @@ static u64 xen_do_read_msr(u32 msr, int *err)
>>   {
>>   	u64 val = 0;	/* Avoid uninitialized value for safe variant. */
>>   
>> +	if (err)
>> +		*err = 0;
>> +
>>   	if (pmu_msr_chk_emulated(msr, &val, true))
>>   		return val;
>>   
>> @@ -1162,7 +1165,7 @@ static void xen_do_write_msr(u32 msr, u64 val, int *err)
>>   
>>   static int xen_read_msr_safe(u32 msr, u64 *val)
>>   {
>> -	int err;
>> +	int err = 0;
>>   
>>   	*val = xen_do_read_msr(msr, &err);
>>   	return err;
> 
> So why not initialize 'err' with 0 in both callers, xen_read_msr_safe()
> and xen_read_msr(), and avoid all the initialization trouble in
> xen_do_read_msr()?

Yeah, I should make the change in xen_read_msr() too.

However xen_do_read_msr() should be implemented in a defensive way to
set *err properly as it's part of its return value.  Actually it was so,
but one of my previous cleanup patch removed it because err is no longer
passed to pmu_msr_chk_emulated().

Thanks!
     Xin

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

* Re: [PATCH v1 2/3] x86/xen/msr: Fix uninitialized symbol 'err'
  2025-05-15 18:11     ` Xin Li
@ 2025-05-16 13:19       ` Ingo Molnar
  2025-05-16 13:42       ` Jürgen Groß
  1 sibling, 0 replies; 22+ messages in thread
From: Ingo Molnar @ 2025-05-16 13:19 UTC (permalink / raw)
  To: Xin Li
  Cc: linux-kernel, xen-devel, linux-acpi, tglx, bp, dave.hansen, x86,
	hpa, peterz, jgross, boris.ostrovsky, rafael, lenb


* Xin Li <xin@zytor.com> wrote:

> On 5/15/2025 8:29 AM, Ingo Molnar wrote:
> > 
> > * Xin Li (Intel) <xin@zytor.com> wrote:
> > 
> > > xen_read_msr_safe() currently passes an uninitialized argument err to
> > > xen_do_read_msr().  But as xen_do_read_msr() may not set the argument,
> > > xen_read_msr_safe() could return err with an unpredictable value.
> > > 
> > > To ensure correctness, initialize err to 0 (representing success)
> > > in xen_read_msr_safe().
> > > 
> > > Because xen_read_msr_safe() is essentially a wrapper of xen_do_read_msr(),
> > > the latter should be responsible for initializing the value of *err to 0.
> > > Thus initialize *err to 0 in xen_do_read_msr().
> > > 
> > > Fixes: 502ad6e5a619 ("x86/msr: Change the function type of native_read_msr_safe()")
> > > Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> > > Closes: https://lore.kernel.org/xen-devel/aBxNI_Q0-MhtBSZG@stanley.mountain/
> > > Signed-off-by: Xin Li (Intel) <xin@zytor.com>
> > > ---
> > >   arch/x86/xen/enlighten_pv.c | 5 ++++-
> > >   1 file changed, 4 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_pv.c
> > > index 3be38350f044..01f1d441347e 100644
> > > --- a/arch/x86/xen/enlighten_pv.c
> > > +++ b/arch/x86/xen/enlighten_pv.c
> > > @@ -1091,6 +1091,9 @@ static u64 xen_do_read_msr(u32 msr, int *err)
> > >   {
> > >   	u64 val = 0;	/* Avoid uninitialized value for safe variant. */
> > > +	if (err)
> > > +		*err = 0;
> > > +
> > >   	if (pmu_msr_chk_emulated(msr, &val, true))
> > >   		return val;
> > > @@ -1162,7 +1165,7 @@ static void xen_do_write_msr(u32 msr, u64 val, int *err)
> > >   static int xen_read_msr_safe(u32 msr, u64 *val)
> > >   {
> > > -	int err;
> > > +	int err = 0;
> > >   	*val = xen_do_read_msr(msr, &err);
> > >   	return err;
> > 
> > So why not initialize 'err' with 0 in both callers, xen_read_msr_safe()
> > and xen_read_msr(), and avoid all the initialization trouble in
> > xen_do_read_msr()?
> 
> Yeah, I should make the change in xen_read_msr() too.
> 
> However xen_do_read_msr() should be implemented in a defensive way to
> set *err properly as it's part of its return value.  Actually it was so,
> but one of my previous cleanup patch removed it because err is no longer
> passed to pmu_msr_chk_emulated().

Maybe. It's up to Juergen though.

Thanks,

	Ingo

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

* Re: [PATCH v1 2/3] x86/xen/msr: Fix uninitialized symbol 'err'
  2025-05-15 18:11     ` Xin Li
  2025-05-16 13:19       ` Ingo Molnar
@ 2025-05-16 13:42       ` Jürgen Groß
  2025-05-17 16:23         ` Xin Li
  2025-05-17 16:57         ` [PATCH v1A " Xin Li (Intel)
  1 sibling, 2 replies; 22+ messages in thread
From: Jürgen Groß @ 2025-05-16 13:42 UTC (permalink / raw)
  To: Xin Li, Ingo Molnar
  Cc: linux-kernel, xen-devel, linux-acpi, tglx, bp, dave.hansen, x86,
	hpa, peterz, boris.ostrovsky, rafael, lenb


[-- Attachment #1.1.1: Type: text/plain, Size: 2574 bytes --]

On 15.05.25 20:11, Xin Li wrote:
> On 5/15/2025 8:29 AM, Ingo Molnar wrote:
>>
>> * Xin Li (Intel) <xin@zytor.com> wrote:
>>
>>> xen_read_msr_safe() currently passes an uninitialized argument err to
>>> xen_do_read_msr().  But as xen_do_read_msr() may not set the argument,
>>> xen_read_msr_safe() could return err with an unpredictable value.
>>>
>>> To ensure correctness, initialize err to 0 (representing success)
>>> in xen_read_msr_safe().
>>>
>>> Because xen_read_msr_safe() is essentially a wrapper of xen_do_read_msr(),
>>> the latter should be responsible for initializing the value of *err to 0.
>>> Thus initialize *err to 0 in xen_do_read_msr().
>>>
>>> Fixes: 502ad6e5a619 ("x86/msr: Change the function type of 
>>> native_read_msr_safe()")
>>> Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
>>> Closes: https://lore.kernel.org/xen-devel/aBxNI_Q0-MhtBSZG@stanley.mountain/
>>> Signed-off-by: Xin Li (Intel) <xin@zytor.com>
>>> ---
>>>   arch/x86/xen/enlighten_pv.c | 5 ++++-
>>>   1 file changed, 4 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_pv.c
>>> index 3be38350f044..01f1d441347e 100644
>>> --- a/arch/x86/xen/enlighten_pv.c
>>> +++ b/arch/x86/xen/enlighten_pv.c
>>> @@ -1091,6 +1091,9 @@ static u64 xen_do_read_msr(u32 msr, int *err)
>>>   {
>>>       u64 val = 0;    /* Avoid uninitialized value for safe variant. */
>>> +    if (err)
>>> +        *err = 0;
>>> +
>>>       if (pmu_msr_chk_emulated(msr, &val, true))
>>>           return val;
>>> @@ -1162,7 +1165,7 @@ static void xen_do_write_msr(u32 msr, u64 val, int *err)
>>>   static int xen_read_msr_safe(u32 msr, u64 *val)
>>>   {
>>> -    int err;
>>> +    int err = 0;
>>>       *val = xen_do_read_msr(msr, &err);
>>>       return err;
>>
>> So why not initialize 'err' with 0 in both callers, xen_read_msr_safe()
>> and xen_read_msr(), and avoid all the initialization trouble in
>> xen_do_read_msr()?
> 
> Yeah, I should make the change in xen_read_msr() too.
> 
> However xen_do_read_msr() should be implemented in a defensive way to
> set *err properly as it's part of its return value.  Actually it was so,
> but one of my previous cleanup patch removed it because err is no longer
> passed to pmu_msr_chk_emulated().

xen_do_read_msr() is usable only in enlighten_pv.c as it is static.

So I'd prefer to drop setting err to 0 in xen_do_read_msr() initially
and to set err to 0 in all callers.


Juergen

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3743 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]

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

* Re: [PATCH v1 3/3] x86/msr: Convert a native_wrmsr() use to native_wrmsrq()
  2025-05-15 17:54     ` Xin Li
@ 2025-05-17  4:42       ` Xin Li
  2025-05-17  7:12         ` Ingo Molnar
  0 siblings, 1 reply; 22+ messages in thread
From: Xin Li @ 2025-05-17  4:42 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, xen-devel, linux-acpi, tglx, bp, dave.hansen, x86,
	hpa, peterz, jgross, boris.ostrovsky, rafael, lenb

On 5/15/2025 10:54 AM, Xin Li wrote:
> On 5/15/2025 8:27 AM, Ingo Molnar wrote:
>>
>> * Xin Li (Intel) <xin@zytor.com> wrote:
>>
>>> Convert a native_wrmsr() use to native_wrmsrq() to zap meaningless type
>>> conversions when a u64 MSR value is splitted into two u32.
>>>
>>
>> BTW., at this point we should probably just replace
>> sev_es_wr_ghcb_msr() calls with direct calls to:
>>
>>     native_wrmsrq(MSR_AMD64_SEV_ES_GHCB, ...);
>>
>> as sev_es_wr_ghcb_msr() is now basically an open-coded native_wrmsrq().
>>
> 
> I thought about it, however it looks to me that current code prefers not
> to spread MSR_AMD64_SEV_ES_GHCB in 17 callsites.  And anyway it's a 
> __always_inline function.
> 
> But as you have asked, I will make the change unless someone objects.

Hi Ingo,

I took a further look and found that we can't simply replace
sev_es_wr_ghcb_msr() with native_wrmsrq(MSR_AMD64_SEV_ES_GHCB, ...).

There are two sev_es_wr_ghcb_msr() definitions.  One is defined in
arch/x86/boot/compressed/sev.h and it references boot_wrmsr() defined in
arch/x86/boot/msr.h to do MSR write.

The other one is defined in arch/x86/include/asm/sev-internal.h, which
uses native_wrmsrq() from arch/x86/include/asm/msr.h to write MSR.

Because:
1) arch/x86/boot/startup/sev-shared.c is included in both
         arch/x86/boot/compressed/sev.c
    and
         arch/x86/boot/startup/sev-startup.c

2) arch/x86/boot/startup/sev-shared.c has several references to
    sev_es_wr_ghcb_msr(),

sev_es_wr_ghcb_msr() is converted to boot_wrmsr() when included in
arch/x86/boot/compressed/sev.c or native_wrmsrq() when included in
arch/x86/boot/startup/sev-startup.c.

It would change the compressed code to use native_wrmsrq() if we remove
sev_es_wr_ghcb_msr() from arch/x86/include/asm/sev-internal.h and use 
native_wrmsrq() directly in the startup code.

We probably should get rid of boot_wrmsr() and use native_wrmsrq() in
the compressed code because they are indeed the same thing.  But as we
are so close to the v6.16 merge window, I don't think it's a good idea
to make the change right now.

So maybe I should just drop this patch and we can do the job after the 
coming merge window.

But if you think it's not a bad idea to replace native_wrmsr() with
native_wrmsrq() right now, I can keep this original patch.

Thanks!
     Xin






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

* Re: [PATCH v1 3/3] x86/msr: Convert a native_wrmsr() use to native_wrmsrq()
  2025-05-17  4:42       ` Xin Li
@ 2025-05-17  7:12         ` Ingo Molnar
  2025-05-17  7:26           ` Xin Li
  0 siblings, 1 reply; 22+ messages in thread
From: Ingo Molnar @ 2025-05-17  7:12 UTC (permalink / raw)
  To: Xin Li
  Cc: linux-kernel, xen-devel, linux-acpi, tglx, bp, dave.hansen, x86,
	hpa, peterz, jgross, boris.ostrovsky, rafael, lenb


* Xin Li <xin@zytor.com> wrote:

> On 5/15/2025 10:54 AM, Xin Li wrote:
> > On 5/15/2025 8:27 AM, Ingo Molnar wrote:
> > > 
> > > * Xin Li (Intel) <xin@zytor.com> wrote:
> > > 
> > > > Convert a native_wrmsr() use to native_wrmsrq() to zap meaningless type
> > > > conversions when a u64 MSR value is splitted into two u32.
> > > > 
> > > 
> > > BTW., at this point we should probably just replace
> > > sev_es_wr_ghcb_msr() calls with direct calls to:
> > > 
> > >     native_wrmsrq(MSR_AMD64_SEV_ES_GHCB, ...);
> > > 
> > > as sev_es_wr_ghcb_msr() is now basically an open-coded native_wrmsrq().
> > > 
> > 
> > I thought about it, however it looks to me that current code prefers not
> > to spread MSR_AMD64_SEV_ES_GHCB in 17 callsites.  And anyway it's a
> > __always_inline function.
> > 
> > But as you have asked, I will make the change unless someone objects.
> 
> Hi Ingo,
> 
> I took a further look and found that we can't simply replace
> sev_es_wr_ghcb_msr() with native_wrmsrq(MSR_AMD64_SEV_ES_GHCB, ...).
> 
> There are two sev_es_wr_ghcb_msr() definitions.  One is defined in
> arch/x86/boot/compressed/sev.h and it references boot_wrmsr() defined in
> arch/x86/boot/msr.h to do MSR write.

Ah, indeed, it's also a startup code wrapper, which wrmsrq() doesn't 
have at the moment. Fair enough.

Thanks,

	Ingo

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

* Re: [PATCH v1 3/3] x86/msr: Convert a native_wrmsr() use to native_wrmsrq()
  2025-05-17  7:12         ` Ingo Molnar
@ 2025-05-17  7:26           ` Xin Li
  2025-05-17 13:21             ` Ingo Molnar
  0 siblings, 1 reply; 22+ messages in thread
From: Xin Li @ 2025-05-17  7:26 UTC (permalink / raw)
  To: Molnar Ingo
  Cc: linux-kernel, xen-devel, linux-acpi, tglx, bp, dave.hansen, x86,
	hpa, peterz, jgross, boris.ostrovsky, rafael, lenb


>>> On 5/15/2025 10:54 AM, Xin Li wrote:
>>> On 5/15/2025 8:27 AM, Ingo Molnar wrote:
>>>> 
>>>> * Xin Li (Intel) <xin@zytor.com> wrote:
>>>> 
>>>>> Convert a native_wrmsr() use to native_wrmsrq() to zap meaningless type
>>>>> conversions when a u64 MSR value is splitted into two u32.
>>>>> 
>>>> 
>>>> BTW., at this point we should probably just replace
>>>> sev_es_wr_ghcb_msr() calls with direct calls to:
>>>> 
>>>>     native_wrmsrq(MSR_AMD64_SEV_ES_GHCB, ...);
>>>> 
>>>> as sev_es_wr_ghcb_msr() is now basically an open-coded native_wrmsrq().
>>>> 
>>> 
>>> I thought about it, however it looks to me that current code prefers not
>>> to spread MSR_AMD64_SEV_ES_GHCB in 17 callsites.  And anyway it's a
>>> __always_inline function.
>>> 
>>> But as you have asked, I will make the change unless someone objects.
>> 
>> Hi Ingo,
>> 
>> I took a further look and found that we can't simply replace
>> sev_es_wr_ghcb_msr() with native_wrmsrq(MSR_AMD64_SEV_ES_GHCB, ...).
>> 
>> There are two sev_es_wr_ghcb_msr() definitions.  One is defined in
>> arch/x86/boot/compressed/sev.h and it references boot_wrmsr() defined in
>> arch/x86/boot/msr.h to do MSR write.
> 
> Ah, indeed, it's also a startup code wrapper, which wrmsrq() doesn't
> have at the moment. Fair enough.

So you want me to drop this patch then?

Thanks!
    Xin

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

* Re: [PATCH v1 3/3] x86/msr: Convert a native_wrmsr() use to native_wrmsrq()
  2025-05-17  7:26           ` Xin Li
@ 2025-05-17 13:21             ` Ingo Molnar
  2025-05-17 16:25               ` Xin Li
  0 siblings, 1 reply; 22+ messages in thread
From: Ingo Molnar @ 2025-05-17 13:21 UTC (permalink / raw)
  To: Xin Li
  Cc: linux-kernel, xen-devel, linux-acpi, tglx, bp, dave.hansen, x86,
	hpa, peterz, jgross, boris.ostrovsky, rafael, lenb


* Xin Li <xin@zytor.com> wrote:

> 
> >>> On 5/15/2025 10:54 AM, Xin Li wrote:
> >>> On 5/15/2025 8:27 AM, Ingo Molnar wrote:
> >>>> 
> >>>> * Xin Li (Intel) <xin@zytor.com> wrote:
> >>>> 
> >>>>> Convert a native_wrmsr() use to native_wrmsrq() to zap meaningless type
> >>>>> conversions when a u64 MSR value is splitted into two u32.
> >>>>> 
> >>>> 
> >>>> BTW., at this point we should probably just replace
> >>>> sev_es_wr_ghcb_msr() calls with direct calls to:
> >>>> 
> >>>>     native_wrmsrq(MSR_AMD64_SEV_ES_GHCB, ...);
> >>>> 
> >>>> as sev_es_wr_ghcb_msr() is now basically an open-coded native_wrmsrq().
> >>>> 
> >>> 
> >>> I thought about it, however it looks to me that current code prefers not
> >>> to spread MSR_AMD64_SEV_ES_GHCB in 17 callsites.  And anyway it's a
> >>> __always_inline function.
> >>> 
> >>> But as you have asked, I will make the change unless someone objects.
> >> 
> >> Hi Ingo,
> >> 
> >> I took a further look and found that we can't simply replace
> >> sev_es_wr_ghcb_msr() with native_wrmsrq(MSR_AMD64_SEV_ES_GHCB, ...).
> >> 
> >> There are two sev_es_wr_ghcb_msr() definitions.  One is defined in
> >> arch/x86/boot/compressed/sev.h and it references boot_wrmsr() defined in
> >> arch/x86/boot/msr.h to do MSR write.
> > 
> > Ah, indeed, it's also a startup code wrapper, which wrmsrq() doesn't
> > have at the moment. Fair enough.
> 
> So you want me to drop this patch then?

No, patch #3 is fine as-is in its -v1 form, I was wrong.

Thanks,

	Ingo

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

* Re: [PATCH v1 2/3] x86/xen/msr: Fix uninitialized symbol 'err'
  2025-05-16 13:42       ` Jürgen Groß
@ 2025-05-17 16:23         ` Xin Li
  2025-05-17 16:57         ` [PATCH v1A " Xin Li (Intel)
  1 sibling, 0 replies; 22+ messages in thread
From: Xin Li @ 2025-05-17 16:23 UTC (permalink / raw)
  To: Jürgen Groß, Ingo Molnar
  Cc: linux-kernel, xen-devel, linux-acpi, tglx, bp, dave.hansen, x86,
	hpa, peterz, boris.ostrovsky, rafael, lenb

On 5/16/2025 6:42 AM, Jürgen Groß wrote:
> On 15.05.25 20:11, Xin Li wrote:
>> On 5/15/2025 8:29 AM, Ingo Molnar wrote:
>>>
>>> * Xin Li (Intel) <xin@zytor.com> wrote:
>>>
>>>> xen_read_msr_safe() currently passes an uninitialized argument err to
>>>> xen_do_read_msr().  But as xen_do_read_msr() may not set the argument,
>>>> xen_read_msr_safe() could return err with an unpredictable value.
>>>>
>>>> To ensure correctness, initialize err to 0 (representing success)
>>>> in xen_read_msr_safe().
>>>>
>>>> Because xen_read_msr_safe() is essentially a wrapper of 
>>>> xen_do_read_msr(),
>>>> the latter should be responsible for initializing the value of *err 
>>>> to 0.
>>>> Thus initialize *err to 0 in xen_do_read_msr().
>>>>
>>>> Fixes: 502ad6e5a619 ("x86/msr: Change the function type of 
>>>> native_read_msr_safe()")
>>>> Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
>>>> Closes: https://lore.kernel.org/xen-devel/aBxNI_Q0- 
>>>> MhtBSZG@stanley.mountain/
>>>> Signed-off-by: Xin Li (Intel) <xin@zytor.com>
>>>> ---
>>>>   arch/x86/xen/enlighten_pv.c | 5 ++++-
>>>>   1 file changed, 4 insertions(+), 1 deletion(-)
>>>>
>>>> diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_pv.c
>>>> index 3be38350f044..01f1d441347e 100644
>>>> --- a/arch/x86/xen/enlighten_pv.c
>>>> +++ b/arch/x86/xen/enlighten_pv.c
>>>> @@ -1091,6 +1091,9 @@ static u64 xen_do_read_msr(u32 msr, int *err)
>>>>   {
>>>>       u64 val = 0;    /* Avoid uninitialized value for safe variant. */
>>>> +    if (err)
>>>> +        *err = 0;
>>>> +
>>>>       if (pmu_msr_chk_emulated(msr, &val, true))
>>>>           return val;
>>>> @@ -1162,7 +1165,7 @@ static void xen_do_write_msr(u32 msr, u64 val, 
>>>> int *err)
>>>>   static int xen_read_msr_safe(u32 msr, u64 *val)
>>>>   {
>>>> -    int err;
>>>> +    int err = 0;
>>>>       *val = xen_do_read_msr(msr, &err);
>>>>       return err;
>>>
>>> So why not initialize 'err' with 0 in both callers, xen_read_msr_safe()
>>> and xen_read_msr(), and avoid all the initialization trouble in
>>> xen_do_read_msr()?
>>
>> Yeah, I should make the change in xen_read_msr() too.
>>
>> However xen_do_read_msr() should be implemented in a defensive way to
>> set *err properly as it's part of its return value.  Actually it was so,
>> but one of my previous cleanup patch removed it because err is no longer
>> passed to pmu_msr_chk_emulated().
> 
> xen_do_read_msr() is usable only in enlighten_pv.c as it is static.
> 
> So I'd prefer to drop setting err to 0 in xen_do_read_msr() initially
> and to set err to 0 in all callers.

Okay, I will send v1A to address this comment then.

Thanks!
     Xin

> Juergen


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

* Re: [PATCH v1 3/3] x86/msr: Convert a native_wrmsr() use to native_wrmsrq()
  2025-05-17 13:21             ` Ingo Molnar
@ 2025-05-17 16:25               ` Xin Li
  0 siblings, 0 replies; 22+ messages in thread
From: Xin Li @ 2025-05-17 16:25 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, xen-devel, linux-acpi, tglx, bp, dave.hansen, x86,
	hpa, peterz, jgross, boris.ostrovsky, rafael, lenb

On 5/17/2025 6:21 AM, Ingo Molnar wrote:
>>> Ah, indeed, it's also a startup code wrapper, which wrmsrq() doesn't
>>> have at the moment. Fair enough.
>> So you want me to drop this patch then?
> No, patch #3 is fine as-is in its -v1 form

Thanks for confirming.

I'll just update patch #2 as version v1A then.

     Xin

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

* [PATCH v1A 2/3] x86/xen/msr: Fix uninitialized symbol 'err'
  2025-05-16 13:42       ` Jürgen Groß
  2025-05-17 16:23         ` Xin Li
@ 2025-05-17 16:57         ` Xin Li (Intel)
  2025-05-17 18:51           ` Jürgen Groß
                             ` (2 more replies)
  1 sibling, 3 replies; 22+ messages in thread
From: Xin Li (Intel) @ 2025-05-17 16:57 UTC (permalink / raw)
  To: linux-kernel, xen-devel, linux-acpi
  Cc: tglx, mingo, bp, dave.hansen, x86, hpa, peterz, jgross,
	boris.ostrovsky, dan.carpenter, rafael, lenb

xen_read_msr_safe() currently passes an uninitialized argument err to
xen_do_read_msr().  But as xen_do_read_msr() may not set the argument,
xen_read_msr_safe() could return err with an unpredictable value.

To ensure correctness, initialize err to 0 (representing success)
in xen_read_msr_safe().

Do the same in xen_read_msr(), even err is not used after being passed
to xen_do_read_msr().

Fixes: d815da84fdd0 ("x86/msr: Change the function type of native_read_msr_safe()"
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Closes: https://lore.kernel.org/xen-devel/aBxNI_Q0-MhtBSZG@stanley.mountain/
Signed-off-by: Xin Li (Intel) <xin@zytor.com>
---

Change in v1A:
*) Drop setting err to 0 in xen_do_read_msr() initially and set err to
   0 in all callers (Jürgen Groß).
---
 arch/x86/xen/enlighten_pv.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_pv.c
index 7f9ded1bc707..26bbaf4b7330 100644
--- a/arch/x86/xen/enlighten_pv.c
+++ b/arch/x86/xen/enlighten_pv.c
@@ -1162,7 +1162,7 @@ static void xen_do_write_msr(u32 msr, u64 val, int *err)
 
 static int xen_read_msr_safe(u32 msr, u64 *val)
 {
-	int err;
+	int err = 0;
 
 	*val = xen_do_read_msr(msr, &err);
 	return err;
@@ -1179,7 +1179,7 @@ static int xen_write_msr_safe(u32 msr, u64 val)
 
 static u64 xen_read_msr(u32 msr)
 {
-	int err;
+	int err = 0;
 
 	return xen_do_read_msr(msr, xen_msr_safe ? &err : NULL);
 }
-- 
2.49.0


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

* Re: [PATCH v1A 2/3] x86/xen/msr: Fix uninitialized symbol 'err'
  2025-05-17 16:57         ` [PATCH v1A " Xin Li (Intel)
@ 2025-05-17 18:51           ` Jürgen Groß
  2025-05-18  6:50           ` [tip: x86/core] x86/xen/msr: Fix uninitialized variable 'err' tip-bot2 for Xin Li (Intel)
  2025-05-21  6:56           ` tip-bot2 for Xin Li (Intel)
  2 siblings, 0 replies; 22+ messages in thread
From: Jürgen Groß @ 2025-05-17 18:51 UTC (permalink / raw)
  To: Xin Li (Intel), linux-kernel, xen-devel, linux-acpi
  Cc: tglx, mingo, bp, dave.hansen, x86, hpa, peterz, boris.ostrovsky,
	dan.carpenter, rafael, lenb


[-- Attachment #1.1.1: Type: text/plain, Size: 798 bytes --]

On 17.05.25 18:57, Xin Li (Intel) wrote:
> xen_read_msr_safe() currently passes an uninitialized argument err to
> xen_do_read_msr().  But as xen_do_read_msr() may not set the argument,
> xen_read_msr_safe() could return err with an unpredictable value.
> 
> To ensure correctness, initialize err to 0 (representing success)
> in xen_read_msr_safe().
> 
> Do the same in xen_read_msr(), even err is not used after being passed
> to xen_do_read_msr().
> 
> Fixes: d815da84fdd0 ("x86/msr: Change the function type of native_read_msr_safe()"
> Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> Closes: https://lore.kernel.org/xen-devel/aBxNI_Q0-MhtBSZG@stanley.mountain/
> Signed-off-by: Xin Li (Intel) <xin@zytor.com>

Reviewed-by: Juergen Gross <jgross@suse.com>


Juergen

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3743 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]

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

* [tip: x86/core] x86/xen/msr: Fix uninitialized variable 'err'
  2025-05-17 16:57         ` [PATCH v1A " Xin Li (Intel)
  2025-05-17 18:51           ` Jürgen Groß
@ 2025-05-18  6:50           ` tip-bot2 for Xin Li (Intel)
  2025-05-21  6:56           ` tip-bot2 for Xin Li (Intel)
  2 siblings, 0 replies; 22+ messages in thread
From: tip-bot2 for Xin Li (Intel) @ 2025-05-18  6:50 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Dan Carpenter, Xin Li (Intel), Ingo Molnar, Juergen Gross,
	H. Peter Anvin, x86, linux-kernel

The following commit has been merged into the x86/core branch of tip:

Commit-ID:     54c2c688cd9305bdbab4883b9da6ff63f4deca5d
Gitweb:        https://git.kernel.org/tip/54c2c688cd9305bdbab4883b9da6ff63f4deca5d
Author:        Xin Li (Intel) <xin@zytor.com>
AuthorDate:    Sat, 17 May 2025 09:57:12 -07:00
Committer:     Ingo Molnar <mingo@kernel.org>
CommitterDate: Sun, 18 May 2025 08:39:16 +02:00

x86/xen/msr: Fix uninitialized variable 'err'

xen_read_msr_safe() currently passes an uninitialized argument 'err' to
xen_do_read_msr(). But as xen_do_read_msr() may not set the argument,
xen_read_msr_safe() could return err with an unpredictable value.

To ensure correctness, initialize err to 0 (representing success)
in xen_read_msr_safe().

Do the same in xen_read_msr(), even err is not used after being passed
to xen_do_read_msr().

Closes: https://lore.kernel.org/xen-devel/aBxNI_Q0-MhtBSZG@stanley.mountain/
Fixes: d815da84fdd0 ("x86/msr: Change the function type of native_read_msr_safe()"
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Xin Li (Intel) <xin@zytor.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Juergen Gross <jgross@suse.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Link: https://lore.kernel.org/r/20250517165713.935384-1-xin@zytor.com
---
 arch/x86/xen/enlighten_pv.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_pv.c
index 7f9ded1..26bbaf4 100644
--- a/arch/x86/xen/enlighten_pv.c
+++ b/arch/x86/xen/enlighten_pv.c
@@ -1162,7 +1162,7 @@ static void xen_do_write_msr(u32 msr, u64 val, int *err)
 
 static int xen_read_msr_safe(u32 msr, u64 *val)
 {
-	int err;
+	int err = 0;
 
 	*val = xen_do_read_msr(msr, &err);
 	return err;
@@ -1179,7 +1179,7 @@ static int xen_write_msr_safe(u32 msr, u64 val)
 
 static u64 xen_read_msr(u32 msr)
 {
-	int err;
+	int err = 0;
 
 	return xen_do_read_msr(msr, xen_msr_safe ? &err : NULL);
 }

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

* [tip: x86/core] x86/msr: Remove a superfluous inclusion of <asm/asm.h>
  2025-05-12  8:45 ` [PATCH v1 1/3] x86/msr: Remove a superfluous inclusion of <asm/asm.h> Xin Li (Intel)
@ 2025-05-18  6:50   ` tip-bot2 for Xin Li (Intel)
  0 siblings, 0 replies; 22+ messages in thread
From: tip-bot2 for Xin Li (Intel) @ 2025-05-18  6:50 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Xin Li (Intel), Ingo Molnar, H. Peter Anvin, x86, linux-kernel

The following commit has been merged into the x86/core branch of tip:

Commit-ID:     9220aa8a6779b586ef11bcd5473d103f7cf60756
Gitweb:        https://git.kernel.org/tip/9220aa8a6779b586ef11bcd5473d103f7cf60756
Author:        Xin Li (Intel) <xin@zytor.com>
AuthorDate:    Mon, 12 May 2025 01:45:50 -07:00
Committer:     Ingo Molnar <mingo@kernel.org>
CommitterDate: Sun, 18 May 2025 08:39:09 +02:00

x86/msr: Remove a superfluous inclusion of <asm/asm.h>

The following commit:

  efef7f184f2e ("x86/msr: Add explicit includes of <asm/msr.h>")

added a superfluous inclusion of <asm/asm.h> to

  drivers/acpi/processor_throttling.c.

Remove it.

Fixes: efef7f184f2e ("x86/msr: Add explicit includes of <asm/msr.h>")
Signed-off-by: Xin Li (Intel) <xin@zytor.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: H. Peter Anvin <hpa@zytor.com>
Link: https://lore.kernel.org/r/20250512084552.1586883-2-xin@zytor.com
---
 drivers/acpi/processor_throttling.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/acpi/processor_throttling.c b/drivers/acpi/processor_throttling.c
index ecd7fe2..d1541a3 100644
--- a/drivers/acpi/processor_throttling.c
+++ b/drivers/acpi/processor_throttling.c
@@ -21,7 +21,6 @@
 #include <linux/uaccess.h>
 #include <acpi/processor.h>
 #include <asm/io.h>
-#include <asm/asm.h>
 #ifdef CONFIG_X86
 #include <asm/msr.h>
 #endif

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

* Re: [PATCH v1 3/3] x86/msr: Convert a native_wrmsr() use to native_wrmsrq()
  2025-05-12  8:45 ` [PATCH v1 3/3] x86/msr: Convert a native_wrmsr() use to native_wrmsrq() Xin Li (Intel)
  2025-05-15 15:27   ` Ingo Molnar
@ 2025-05-19 17:05   ` Xin Li
  1 sibling, 0 replies; 22+ messages in thread
From: Xin Li @ 2025-05-19 17:05 UTC (permalink / raw)
  To: linux-kernel, xen-devel, linux-acpi
  Cc: tglx, mingo, bp, dave.hansen, x86, hpa, peterz, jgross,
	boris.ostrovsky, rafael, lenb

On 5/12/2025 1:45 AM, Xin Li (Intel) wrote:
> Convert a native_wrmsr() use to native_wrmsrq() to zap meaningless type
> conversions when a u64 MSR value is splitted into two u32.
> 
> Signed-off-by: Xin Li (Intel) <xin@zytor.com>
> ---
>   arch/x86/coco/sev/core.c | 7 +------
>   1 file changed, 1 insertion(+), 6 deletions(-)
> 
> diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c
> index ff82151f7718..b3ce6fc8b62d 100644
> --- a/arch/x86/coco/sev/core.c
> +++ b/arch/x86/coco/sev/core.c
> @@ -282,12 +282,7 @@ static inline u64 sev_es_rd_ghcb_msr(void)
>   
>   static __always_inline void sev_es_wr_ghcb_msr(u64 val)
>   {
> -	u32 low, high;
> -
> -	low  = (u32)(val);
> -	high = (u32)(val >> 32);
> -
> -	native_wrmsr(MSR_AMD64_SEV_ES_GHCB, low, high);
> +	native_wrmsrq(MSR_AMD64_SEV_ES_GHCB, val);
>   }
>   
>   static int vc_fetch_insn_kernel(struct es_em_ctxt *ctxt,

Just noticed that this patch doesn't apply to tip/x86/core, I will send
it as a separate one.

Thanks!
     Xin

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

* [tip: x86/core] x86/xen/msr: Fix uninitialized variable 'err'
  2025-05-17 16:57         ` [PATCH v1A " Xin Li (Intel)
  2025-05-17 18:51           ` Jürgen Groß
  2025-05-18  6:50           ` [tip: x86/core] x86/xen/msr: Fix uninitialized variable 'err' tip-bot2 for Xin Li (Intel)
@ 2025-05-21  6:56           ` tip-bot2 for Xin Li (Intel)
  2 siblings, 0 replies; 22+ messages in thread
From: tip-bot2 for Xin Li (Intel) @ 2025-05-21  6:56 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Dan Carpenter, Xin Li (Intel), Ingo Molnar, Juergen Gross,
	H. Peter Anvin, x86, linux-kernel

The following commit has been merged into the x86/core branch of tip:

Commit-ID:     e95534e107d2e9e136aa4d7cbededb3827e80074
Gitweb:        https://git.kernel.org/tip/e95534e107d2e9e136aa4d7cbededb3827e80074
Author:        Xin Li (Intel) <xin@zytor.com>
AuthorDate:    Sat, 17 May 2025 09:57:12 -07:00
Committer:     Ingo Molnar <mingo@kernel.org>
CommitterDate: Wed, 21 May 2025 08:44:31 +02:00

x86/xen/msr: Fix uninitialized variable 'err'

xen_read_msr_safe() currently passes an uninitialized argument 'err' to
xen_do_read_msr(). But as xen_do_read_msr() may not set the argument,
xen_read_msr_safe() could return err with an unpredictable value.

To ensure correctness, initialize err to 0 (representing success)
in xen_read_msr_safe().

Do the same in xen_read_msr(), even err is not used after being passed
to xen_do_read_msr().

Closes: https://lore.kernel.org/xen-devel/aBxNI_Q0-MhtBSZG@stanley.mountain/
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Xin Li (Intel) <xin@zytor.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Juergen Gross <jgross@suse.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Link: https://lore.kernel.org/r/20250517165713.935384-1-xin@zytor.com
---
 arch/x86/xen/enlighten_pv.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_pv.c
index 7f9ded1..26bbaf4 100644
--- a/arch/x86/xen/enlighten_pv.c
+++ b/arch/x86/xen/enlighten_pv.c
@@ -1162,7 +1162,7 @@ static void xen_do_write_msr(u32 msr, u64 val, int *err)
 
 static int xen_read_msr_safe(u32 msr, u64 *val)
 {
-	int err;
+	int err = 0;
 
 	*val = xen_do_read_msr(msr, &err);
 	return err;
@@ -1179,7 +1179,7 @@ static int xen_write_msr_safe(u32 msr, u64 val)
 
 static u64 xen_read_msr(u32 msr)
 {
-	int err;
+	int err = 0;
 
 	return xen_do_read_msr(msr, xen_msr_safe ? &err : NULL);
 }

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

end of thread, other threads:[~2025-05-21  6:56 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-12  8:45 [PATCH v1 0/3] MSR fixes and cleanups after last round of MSR cleanups Xin Li (Intel)
2025-05-12  8:45 ` [PATCH v1 1/3] x86/msr: Remove a superfluous inclusion of <asm/asm.h> Xin Li (Intel)
2025-05-18  6:50   ` [tip: x86/core] " tip-bot2 for Xin Li (Intel)
2025-05-12  8:45 ` [PATCH v1 2/3] x86/xen/msr: Fix uninitialized symbol 'err' Xin Li (Intel)
2025-05-15 15:29   ` Ingo Molnar
2025-05-15 18:11     ` Xin Li
2025-05-16 13:19       ` Ingo Molnar
2025-05-16 13:42       ` Jürgen Groß
2025-05-17 16:23         ` Xin Li
2025-05-17 16:57         ` [PATCH v1A " Xin Li (Intel)
2025-05-17 18:51           ` Jürgen Groß
2025-05-18  6:50           ` [tip: x86/core] x86/xen/msr: Fix uninitialized variable 'err' tip-bot2 for Xin Li (Intel)
2025-05-21  6:56           ` tip-bot2 for Xin Li (Intel)
2025-05-12  8:45 ` [PATCH v1 3/3] x86/msr: Convert a native_wrmsr() use to native_wrmsrq() Xin Li (Intel)
2025-05-15 15:27   ` Ingo Molnar
2025-05-15 17:54     ` Xin Li
2025-05-17  4:42       ` Xin Li
2025-05-17  7:12         ` Ingo Molnar
2025-05-17  7:26           ` Xin Li
2025-05-17 13:21             ` Ingo Molnar
2025-05-17 16:25               ` Xin Li
2025-05-19 17:05   ` Xin Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).