x86/SVM: correct boot time cpu_data[] handling
PATCH v2 1/1 x86/SVM: correct boot time cpu_data[] handling
start_svm() already runs after cpu_data[] was set up, so it shouldn't modify it anymore (at least not directly). Constify the involved pointers.
Furthermore LMSLE feature detection was broken by 566ddbe833 ("x86:
Fail CPU bringup cleanly if it cannot initialise HVM"), as Andrew Cooper has pointed out: c couldn't possibly equal &boot_cpu_data anymore.
---
v2: Suppress setting cpu_has_lmsl for now.
xen/arch/x86/hvm/svm/asid.c +1 -1
@@ -22,7 +22,7 @@#include <asm/amd.h> #include <asm/hvm/nestedhvm.h> -void svm_asid_init (struct cpuinfo_x86 *c) +void svm_asid_init (const struct cpuinfo_x86 *c) {int nasids =0 ;
xen/arch/x86/hvm/svm/svm.c +12 -6
@@ -1330,7 +1330,7 @@ static int svm_cpu_up_prepare(unsigned ireturn 0 ; } -static void svm_init_erratum_383 (struct cpuinfo_x86 *c) +static void svm_init_erratum_383 (const struct cpuinfo_x86 *c) {uint64_t msr_content;
@@ -1365,11 +1365,12 @@ static int svm_handle_osvw(struct vcpu *return 0 ; } -static int svm_cpu_up (void ) +static int _svm_cpu_up (bool bsp) {uint64_t msr_content; -int rc, cpu =smp_processor_id (); -struct cpuinfo_x86 *c = &cpu_data[cpu]; +int rc; +unsigned int cpu =smp_processor_id (); +const struct cpuinfo_x86 *c = &cpu_data[cpu];/* Check whether SVM feature is disabled in BIOS */ rdmsrl (MSR_K8_VM_CR , msr_content);
@@ -1402,7 +1403,7 @@ static int svm_cpu_up(void)rdmsrl (MSR_EFER , msr_content);if ( msr_content &EFER_LMSLE ) { -if ( c == &boot_cpu_data ) +if (0 &&/* FIXME: Migration! */ bsp ) cpu_has_lmsl =1 ;wrmsrl (MSR_EFER , msr_content ^EFER_LMSLE ); }
@@ -1419,13 +1420,18 @@ static int svm_cpu_up(void)return 0 ; } +static int svm_cpu_up (void ) +{ +return _svm_cpu_up (false); +} +const struct hvm_function_table *__init start_svm (void ) {bool_t printed =0 ;svm_host_osvw_reset (); -if (svm_cpu_up () ) +if (_svm_cpu_up (true) ) {printk ("SVM: failed to initialise.\n" );return NULL ;
xen/include/asm-x86/hvm/svm/asid.h +1 -1
@@ -22,7 +22,7 @@#include <asm/hvm/asid.h> #include <asm/processor.h> -void svm_asid_init (struct cpuinfo_x86 *c); +void svm_asid_init (const struct cpuinfo_x86 *c);static inline void svm_asid_g_invlpg (struct vcpu *v,unsigned long g_vaddr) {
x86/SVM: correct boot time cpu_data[] handling
start_svm() already runs after cpu_data[] was set up, so it shouldn't modify it anymore (at least not directly). Constify the involved pointers.
Furthermore LMSLE feature detection was broken by 566ddbe833 ("x86:
Fail CPU bringup cleanly if it cannot initialise HVM"), as Andrew Cooper has pointed out: c couldn't possibly equal &boot_cpu_data anymore.
---
v2: Suppress setting cpu_has_lmsl for now.
xen/arch/x86/hvm/svm/asid.c +1 -1
@@ -22,7 +22,7 @@#include <asm/amd.h> #include <asm/hvm/nestedhvm.h> -void svm_asid_init (struct cpuinfo_x86 *c) +void svm_asid_init (const struct cpuinfo_x86 *c) {int nasids =0 ;
xen/arch/x86/hvm/svm/svm.c +12 -6
@@ -1330,7 +1330,7 @@ static int svm_cpu_up_prepare(unsigned ireturn 0 ; } -static void svm_init_erratum_383 (struct cpuinfo_x86 *c) +static void svm_init_erratum_383 (const struct cpuinfo_x86 *c) {uint64_t msr_content;
@@ -1365,11 +1365,12 @@ static int svm_handle_osvw(struct vcpu *return 0 ; } -static int svm_cpu_up (void ) +static int _svm_cpu_up (bool bsp) {uint64_t msr_content; -int rc, cpu =smp_processor_id (); -struct cpuinfo_x86 *c = &cpu_data[cpu]; +int rc; +unsigned int cpu =smp_processor_id (); +const struct cpuinfo_x86 *c = &cpu_data[cpu];/* Check whether SVM feature is disabled in BIOS */ rdmsrl (MSR_K8_VM_CR , msr_content);
@@ -1402,7 +1403,7 @@ static int svm_cpu_up(void)rdmsrl (MSR_EFER , msr_content);if ( msr_content &EFER_LMSLE ) { -if ( c == &boot_cpu_data ) +if (0 &&/* FIXME: Migration! */ bsp ) cpu_has_lmsl =1 ;wrmsrl (MSR_EFER , msr_content ^EFER_LMSLE ); }
@@ -1419,13 +1420,18 @@ static int svm_cpu_up(void)return 0 ; } +static int svm_cpu_up (void ) +{ +return _svm_cpu_up (false); +} +const struct hvm_function_table *__init start_svm (void ) {bool_t printed =0 ;svm_host_osvw_reset (); -if (svm_cpu_up () ) +if (_svm_cpu_up (true) ) {printk ("SVM: failed to initialise.\n" );return NULL ;
xen/include/asm-x86/hvm/svm/asid.h +1 -1
@@ -22,7 +22,7 @@#include <asm/hvm/asid.h> #include <asm/processor.h> -void svm_asid_init (struct cpuinfo_x86 *c); +void svm_asid_init (const struct cpuinfo_x86 *c);static inline void svm_asid_g_invlpg (struct vcpu *v,unsigned long g_vaddr) {
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 10 lines · Jan Beulich
start_svm()already runs after cpu_data[] was set up, so it shouldn't modify it anymore (at least not directly). Constify the involved pointers.Furthermore LMSLE feature detection was broken by
566ddbe833("x86:
Fail CPU bringup cleanly if it cannot initialise HVM"), as Andrew Cooper has pointed out: c couldn't possibly equal&boot_cpu_dataanymore.Signed-off-by Jan Beulich <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 10 lines · Jan Beulich
start_svm()already runs after cpu_data[] was set up, so it shouldn't modify it anymore (at least not directly). Constify the involved pointers.Furthermore LMSLE feature detection was broken by
566ddbe833("x86:
Fail CPU bringup cleanly if it cannot initialise HVM"), as Andrew Cooper has pointed out: c couldn't possibly equal&boot_cpu_dataanymore.Signed-off-by Jan Beulich <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel