MSR fixes and cleanups after last round of MSR cleanups
Subsystems (3)
cover MSR fixes and cleanups after last round of MSR cleanups
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
Signature · 1 line
2.49.0
PATCH 1/3 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.
--- drivers/acpi/processor_throttling.c | 1 - 1 file changed, 1 deletion(-)
drivers/acpi/processor_throttling.c +0 -1
@@ -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
Signature · 1 line
2.49.0
[tip: x86/core] x86/msr: Remove a superfluous inclusion of <asm/asm.h>
The following commit has been merged into the x86/core branch of tip:
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) <[email protected]> AuthorDate: Mon, 12 May 2025 01:45:50 -07:00 Committer: Ingo Molnar <[email protected]> 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.
--- drivers/acpi/processor_throttling.c | 1 - 1 file changed, 1 deletion(-)
drivers/acpi/processor_throttling.c +0 -1
@@ -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
PATCH 2/3 x86/xen/msr: Fix uninitialized symbol 'err'
In reply to Xin Li (Intel)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().
--- arch/x86/xen/enlighten_pv.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
arch/x86/xen/enlighten_pv.c +4 -1
@@ -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;
Signature · 1 line
2.49.0
Re: [PATCH v1 2/3] x86/xen/msr: Fix uninitialized symbol 'err'
Quoted 34 lines · Xin Li (Intel)
xen_read_msr_safe()currently passes an uninitialized argument err toxen_do_read_msr(). But asxen_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 ofxen_do_read_msr(), the latter should be responsible for initializing the value of *err to 0. Thus initialize *err to 0 inxen_do_read_msr().Fixes 502ad6e5a619 ("x86/msr: Change the function type of native_read_msr_safe()")Reported-by Dan Carpenter <[email protected]>Signed-off-by Xin Li (Intel) <[email protected]>--- arch/x86/xen/enlighten_pv.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)arch/x86/xen/enlighten_pv.c +3
-0@@ -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;
arch/x86/xen/enlighten_pv.c static void xen_do_write_msr(u32 msr, u64 val, int *err) · line 1171
Quoted 8 lines
arch/x86/xen/enlighten_pv.c +1
-1@@ -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
Re: [PATCH v1 2/3] x86/xen/msr: Fix uninitialized symbol 'err'
Quoted 43 lines · Ingo Molnar
Quoted 40 lines · Xin Li (Intel)
xen_read_msr_safe()currently passes an uninitialized argument err toxen_do_read_msr(). But asxen_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 ofxen_do_read_msr(), the latter should be responsible for initializing the value of *err to 0. Thus initialize *err to 0 inxen_do_read_msr().Fixes 502ad6e5a619 ("x86/msr: Change the function type of native_read_msr_safe()")Reported-by Dan Carpenter <[email protected]>Signed-off-by Xin Li (Intel) <[email protected]>--- arch/x86/xen/enlighten_pv.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)arch/x86/xen/enlighten_pv.c +4
-1@@ -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 ;
Quoted 6 lines
arch/x86/xen/enlighten_pv.c static void xen_do_write_msr(u32 msr, u64 val, int *err) · line 1171
Quoted 2 lines
arch/x86/xen/enlighten_pv.c +0
-0*val =xen_do_read_msr (msr, &err);return err;So why not initialize 'err' with 0 in both callers,
xen_read_msr_safe()andxen_read_msr(), and avoid all the initialization trouble inxen_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
Re: [PATCH v1 2/3] x86/xen/msr: Fix uninitialized symbol 'err'
Quoted 47 lines · Xin Li
Quoted 37 lines · Ingo Molnar
Quoted 34 lines · Xin Li (Intel)
xen_read_msr_safe()currently passes an uninitialized argument err toxen_do_read_msr(). But asxen_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 ofxen_do_read_msr(), the latter should be responsible for initializing the value of *err to 0. Thus initialize *err to 0 inxen_do_read_msr().Fixes 502ad6e5a619 ("x86/msr: Change the function type of native_read_msr_safe()")Reported-by Dan Carpenter <[email protected]>Signed-off-by Xin Li (Intel) <[email protected]>--- arch/x86/xen/enlighten_pv.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)arch/x86/xen/enlighten_pv.c +3
-0@@ -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) {Quoted 8 lines
arch/x86/xen/enlighten_pv.c static void xen_do_write_msr(u32 msr, u64 val, int *err) · line 1171
Quoted 4 lines
arch/x86/xen/enlighten_pv.c +1
-1-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()andxen_read_msr(), and avoid all the initialization trouble inxen_do_read_msr()?
Quoted 6 lines
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 topmu_msr_chk_emulated().
Maybe. It's up to Juergen though.
Thanks,
Ingo
Jürgen Groß
maintainerRe: [PATCH v1 2/3] x86/xen/msr: Fix uninitialized symbol 'err'
In reply to Xin LiQuoted 47 lines · Xin Li
Quoted 37 lines · Ingo Molnar
Quoted 34 lines · Xin Li (Intel)
xen_read_msr_safe()currently passes an uninitialized argument err to xen_do_read_msr(). But asxen_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 ofxen_do_read_msr(), the latter should be responsible for initializing the value of *err to 0. Thus initialize *err to 0 inxen_do_read_msr().Fixes 502ad6e5a619 ("x86/msr: Change the function type of native_read_msr_safe()")Reported-by Dan Carpenter <[email protected]>Signed-off-by Xin Li (Intel) <[email protected]>---
arch/x86/xen/enlighten_pv.c| 5 ++++-1 file changed, 4 insertions(+), 1 deletion(-)arch/x86/xen/enlighten_pv.c +0
-0@@ -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;arch/x86/xen/enlighten_pv.c +0
-0@@ -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) {Quoted 8 lines
arch/x86/xen/enlighten_pv.c static void xen_do_write_msr(u32 msr, u64 val, int *err) · line 1171
Quoted 4 lines
arch/x86/xen/enlighten_pv.c +1
-1- 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()andxen_read_msr(), and avoid all the initialization trouble inxen_do_read_msr()?
Quoted 6 lines
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 topmu_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
Re: [PATCH v1 2/3] x86/xen/msr: Fix uninitialized symbol 'err'
Quoted 56 lines · Jürgen Groß
Quoted 48 lines · Xin Li
Quoted 38 lines · Ingo Molnar
Quoted 35 lines · Xin Li (Intel)
xen_read_msr_safe()currently passes an uninitialized argument err to xen_do_read_msr(). But asxen_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 ofxen_do_read_msr(), the latter should be responsible for initializing the value of *err to 0. Thus initialize *err to 0 inxen_do_read_msr().Fixes 502ad6e5a619 ("x86/msr: Change the function type of native_read_msr_safe()")Reported-by Dan Carpenter <[email protected]>Signed-off-by Xin Li (Intel) <[email protected]>---
arch/x86/xen/enlighten_pv.c| 5 ++++-1 file changed, 4 insertions(+), 1 deletion(-)arch/x86/xen/enlighten_pv.c +0
-0@@ -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;arch/x86/xen/enlighten_pv.c +0
-0@@ -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) {Quoted 8 lines
arch/x86/xen/enlighten_pv.c static void xen_do_write_msr(u32 msr, u64 val, int *err) · line 1171
Quoted 4 lines
arch/x86/xen/enlighten_pv.c +1
-1- 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()andxen_read_msr(), and avoid all the initialization trouble inxen_do_read_msr()?Quoted 6 lines
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 topmu_msr_chk_emulated().
Quoted 4 lines
xen_do_read_msr()is usable only inenlighten_pv.cas 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
Quoted 1 line
Juergen
PATCH 2/3 x86/xen/msr: Fix uninitialized symbol 'err'
In reply to Jürgen Groß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().
---
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(-)
arch/x86/xen/enlighten_pv.c +2 -2
@@ -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 ); }
Signature · 1 line
2.49.0
Re: [PATCH v1A 2/3] x86/xen/msr: Fix uninitialized symbol 'err'
Quoted 7 lines · Xin Li (Intel)
xen_read_msr_safe()currently passes an uninitialized argument err toxen_do_read_msr(). But asxen_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().
Quoted 7 lines
Do the same in
xen_read_msr(), even err is not used after being passed toxen_do_read_msr().Fixes d815da84fdd0 ("x86/msr: Change the function type of native_read_msr_safe()"Reported-by Dan Carpenter <[email protected]>Signed-off-by Xin Li (Intel) <[email protected]>
Juergen
[tip: x86/core] x86/xen/msr: Fix uninitialized variable 'err'
In reply to Xin Li (Intel)The following commit has been merged into the x86/core branch of tip:
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) <[email protected]> AuthorDate: Sat, 17 May 2025 09:57:12 -07:00 Committer: Ingo Molnar <[email protected]> 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().
--- arch/x86/xen/enlighten_pv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/xen/enlighten_pv.c +2 -2
@@ -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 ); }
[tip: x86/core] x86/xen/msr: Fix uninitialized variable 'err'
In reply to Xin Li (Intel)The following commit has been merged into the x86/core branch of tip:
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) <[email protected]> AuthorDate: Sat, 17 May 2025 09:57:12 -07:00 Committer: Ingo Molnar <[email protected]> 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().
--- arch/x86/xen/enlighten_pv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/xen/enlighten_pv.c +2 -2
@@ -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 ); }
PATCH 3/3 x86/msr: Convert a native_wrmsr() use to native_wrmsrq()
In reply to Xin Li (Intel)Convert a native_wrmsr() use to native_wrmsrq() to zap meaningless type conversions when a u64 MSR value is splitted into two u32.
--- arch/x86/coco/sev/core.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
arch/x86/coco/sev/core.c +1 -6
@@ -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,
Signature · 1 line
2.49.0
Re: [PATCH v1 3/3] x86/msr: Convert a native_wrmsr() use to native_wrmsrq()
Quoted 13 lines · Xin Li (Intel)
Convert a
native_wrmsr()use tonative_wrmsrq()to zap meaningless type conversions when a u64 MSR value is splitted into two u32.Signed-off-by Xin Li (Intel) <[email protected]>--- arch/x86/coco/sev/core.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)arch/x86/coco/sev/core.c +0
-0
arch/x86/coco/sev/core.c static inline u64 sev_es_rd_ghcb_msr(void) · line 285
Quoted 10 lines
arch/x86/coco/sev/core.c +1
-6@@ -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
Re: [PATCH v1 3/3] x86/msr: Convert a native_wrmsr() use to native_wrmsrq()
Quoted 7 lines · Ingo Molnar
Quoted 3 lines · Xin Li (Intel)
Convert a
native_wrmsr()use tonative_wrmsrq()to zap meaningless type conversions when a u64 MSR value is splitted into two u32.
Quoted 7 lines
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-codednative_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
Re: [PATCH v1 3/3] x86/msr: Convert a native_wrmsr() use to native_wrmsrq()
Quoted 13 lines · Xin Li
Quoted 12 lines · Ingo Molnar
Quoted 3 lines · Xin Li (Intel)
Convert a
native_wrmsr()use tonative_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, ...);
Quoted 7 lines
Quoted 2 lines
as
sev_es_wr_ghcb_msr()is now basically an open-codednative_wrmsrq().I thought about it, however it looks to me that current code prefers not
to spreadMSR_AMD64_SEV_ES_GHCBin 17 callsites. And anyway it's a__always_inlinefunction.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 removesev_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
Re: [PATCH v1 3/3] x86/msr: Convert a native_wrmsr() use to native_wrmsrq()
Quoted 23 lines · Xin Li
Quoted 13 lines · Xin Li
Quoted 12 lines · Ingo Molnar
Quoted 3 lines · Xin Li (Intel)
Convert a
native_wrmsr()use tonative_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, ...);
Quoted 8 lines
Quoted 2 lines
as
sev_es_wr_ghcb_msr()is now basically an open-codednative_wrmsrq().I thought about it, however it looks to me that current code prefers not to spread
MSR_AMD64_SEV_ES_GHCBin 17 callsites. And anyway it's a__always_inlinefunction.But as you have asked, I will make the change unless someone objects.
Quoted 8 lines
Hi Ingo,
I took a further look and found that we can't simply replace
sev_es_wr_ghcb_msr()withnative_wrmsrq(MSR_AMD64_SEV_ES_GHCB, ...).There are two
sev_es_wr_ghcb_msr()definitions. One is defined inarch/x86/boot/compressed/sev.hand it referencesboot_wrmsr()defined inarch/x86/boot/msr.hto do MSR write.
Ah, indeed, it's also a startup code wrapper, which wrmsrq() doesn't have at the moment. Fair enough.
Thanks,
Ingo
Re: [PATCH v1 3/3] x86/msr: Convert a native_wrmsr() use to native_wrmsrq()
Quoted 29 lines
Quoted 29 lines
Quoted 15 lines · Xin Li
Quoted 12 lines · Ingo Molnar
Quoted 3 lines · Xin Li (Intel)
Convert a
native_wrmsr()use tonative_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, ...);Quoted 8 lines
Quoted 2 lines
as
sev_es_wr_ghcb_msr()is now basically an open-codednative_wrmsrq().I thought about it, however it looks to me that current code prefers not to spread
MSR_AMD64_SEV_ES_GHCBin 17 callsites. And anyway it's a__always_inlinefunction.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()withnative_wrmsrq(MSR_AMD64_SEV_ES_GHCB, ...).
Quoted 6 lines
Quoted 3 lines
There are two
sev_es_wr_ghcb_msr()definitions. One is defined inarch/x86/boot/compressed/sev.hand it referencesboot_wrmsr()defined inarch/x86/boot/msr.hto 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
Re: [PATCH v1 3/3] x86/msr: Convert a native_wrmsr() use to native_wrmsrq()
Quoted 29 lines · Xin Li
Quoted 29 lines
Quoted 29 lines
Quoted 15 lines · Xin Li
Quoted 12 lines · Ingo Molnar
Quoted 3 lines · Xin Li (Intel)
Convert a
native_wrmsr()use tonative_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, ...);Quoted 8 lines
Quoted 2 lines
as
sev_es_wr_ghcb_msr()is now basically an open-codednative_wrmsrq().I thought about it, however it looks to me that current code prefers not to spread
MSR_AMD64_SEV_ES_GHCBin 17 callsites. And anyway it's a__always_inlinefunction.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()withnative_wrmsrq(MSR_AMD64_SEV_ES_GHCB, ...).
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
There are two
sev_es_wr_ghcb_msr()definitions. One is defined inarch/x86/boot/compressed/sev.hand it referencesboot_wrmsr()defined inarch/x86/boot/msr.hto 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
Re: [PATCH v1 3/3] x86/msr: Convert a native_wrmsr() use to native_wrmsrq()
Quoted 4 lines · Ingo Molnar
Quoted 3 lines
Quoted 2 lines
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
Re: [PATCH v1 3/3] x86/msr: Convert a native_wrmsr() use to native_wrmsrq()
In reply to Xin Li (Intel)Quoted 16 lines · Xin Li (Intel)
Convert a
native_wrmsr()use tonative_wrmsrq()to zap meaningless type conversions when a u64 MSR value is splitted into two u32.Signed-off-by Xin Li (Intel) <[email protected]>--- arch/x86/coco/sev/core.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)arch/x86/coco/sev/core.c +0
-0@@ -282,12 +282,7 @@ static inline u64 sev_es_rd_ghcb_msr(void) static __always_inline void sev_es_wr_ghcb_msr(u64 val) {
arch/x86/coco/sev/core.c static inline u64 sev_es_rd_ghcb_msr(void) · line 288
Quoted 10 lines
arch/x86/coco/sev/core.c +1
-6-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