x86/boot: Disable IBRS in intr/nmi exit path at bootup stage
PATCH v2 1/1 x86/boot: Disable IBRS in intr/nmi exit path at bootup stage
After reset, IBRS is disabled by processor, but a coming intr/nmi leave IBRS enabled after their exit. It's not necessory for bootup code to run in low performance with IBRS enabled.
On ORACLE X6-2(500GB/88 cpus, dom0 11GB/20 vcpus), we observed an 200s+ delay in construct_dom0.
By initializing use_shadow_spec_ctrl with the result of (system_state < SYS_STATE_active), IBRS is disabled in intr/nmi exit path at bootup stage. Then delay in construct_dom0 is ~50s.
When hot-onlining a CPU, we initialize IBRS early and set use_shadow_spec_ctrl to false to avoid Branch Target Injection from sibling threads.
v2: Use (system_state < SYS_STATE_active) to initialize use_shadow_spec_ctrl instead of literal 1 per Jan.
--- xen/include/asm-x86/spec_ctrl.h | 16 +++++++++++++++- 1 files changed, 15 insertions(+), 1 deletions(-)
xen/include/asm-x86/spec_ctrl.h +15 -1
@@ -32,8 +32,22 @@ extern uint8_t default_bti_ist_info;static inline void init_shadow_spec_ctrl_state (void ) {struct cpu_info *info =get_cpu_info (); +uint32_t val =SPEC_CTRL_IBRS ; + +/* Initialize IA32_SPEC_CTRL MSR for hotplugging cpu early */ +if ( system_state >= SYS_STATE_active ) + asm volatile (ALTERNATIVE(ASM_NOP3, "wrmsr", X86_FEATURE_XEN_IBRS_SET) + :: "a" (val), "c" (MSR_SPEC_CTRL), "d" (0) : "memory"); - info->shadow_spec_ctrl = info->use_shadow_spec_ctrl =0 ; + info->shadow_spec_ctrl =0 ; +/* +* We want to make sure we clear IBRS in interrupt exit path +* (DO_SPEC_CTRL_EXIT_TO_XEN) while dom0 is still booting to +* avoid unnecessary performance impact. As soon as dom0 has +* booted use_shadow_spec_ctrl will be cleared, for example, +* in idle routine. +*/ + info->use_shadow_spec_ctrl = system_state < SYS_STATE_active; info->bti_ist_info = default_bti_ist_info; }
Signature · 6 lines
1.7.3 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 27.03.18 at 06:52, <[email protected]> wrote:
After reset, IBRS is disabled by processor, but a coming intr/nmi leave IBRS enabled after their exit. It's not necessory for bootup code to run in low performance with IBRS enabled.
On ORACLE X6-2(500GB/88 cpus, dom0 11GB/20 vcpus), we observed an 200s+ delay in
construct_dom0.By initializing
use_shadow_spec_ctrlwith the result of (system_state<SYS_STATE_active), IBRS is disabled in intr/nmi exit path at bootup stage. Then delay inconstruct_dom0is ~50s.
Quoted 5 lines
When hot-onlining a CPU, we initialize IBRS early and set
use_shadow_spec_ctrlto false to avoid Branch Target Injection from sibling threads.v2: Use (
system_state<SYS_STATE_active) to initializeuse_shadow_spec_ctrlinstead of literal 1 per Jan.
Please place revision information below the first --- marker.
xen/include/asm-x86/spec_ctrl.h extern uint8_t default_bti_ist_info; · line 35
Quoted 7 lines
xen/include/asm-x86/spec_ctrl.h +1
-0@@ -32,8 +32,22 @@ extern uint8_t default_bti_ist_info;static inline void init_shadow_spec_ctrl_state (void ) {struct cpu_info *info =get_cpu_info (); +uint32_t val =SPEC_CTRL_IBRS ;
Why do you need this variable?
xen/include/asm-x86/spec_ctrl.h extern uint8_t default_bti_ist_info; · line 40
Quoted 4 lines
xen/include/asm-x86/spec_ctrl.h +4
-0+/* Initialize IA32_SPEC_CTRL MSR for hotplugging cpu early */ +if ( system_state >= SYS_STATE_active ) + asm volatile (ALTERNATIVE(ASM_NOP3, "wrmsr", X86_FEATURE_XEN_IBRS_SET) + :: "a" (val), "c" (MSR_SPEC_CTRL), "d" (0) : "memory");
I can see the point of doing this, but the title of the patch doesn't cover it (I think this has been missing independent of your interrupt/ NMI paths consideration).
Further INIT# (unlike RESET#) doesn't clear the register, so you may want/need to also clear the register in the X86_FEATURE_XEN_IBRS_CLEAR case.
Also you don't need ASM_NOP3 here after 4008c71d7a ("x86/alt:
Support for automatic padding calculations").
Additionally I think it would be better to keep low and high parts of the value next to each other in the constraints, rather than putting the MSR index in the middle.
xen/include/asm-x86/spec_ctrl.h extern uint8_t default_bti_ist_info; · line 50
Quoted 10 lines
xen/include/asm-x86/spec_ctrl.h +9
-1- info->shadow_spec_ctrl = info->use_shadow_spec_ctrl =0 ; + info->shadow_spec_ctrl =0 ; +/* +* We want to make sure we clear IBRS in interrupt exit path +* (DO_SPEC_CTRL_EXIT_TO_XEN) while dom0 is still booting to +* avoid unnecessary performance impact. As soon as dom0 has +* booted use_shadow_spec_ctrl will be cleared, for example, +* in idle routine. +*/ + info->use_shadow_spec_ctrl = system_state < SYS_STATE_active;
I think the code overall would be more readable if you had just a single condition (in if/else form).
And then there is the question of whether to use < / >= or != / == : In the resume case, not guest vCPU-s are active (yet), so perhaps the latter would be better.
In any event please give Andrew a chance to reply before you send another version, as he may have a different opinion and/or other valuable input.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 12 lines · Jan Beulich
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 27.03.18 at 06:52, <[email protected]> wrote:
After reset, IBRS is disabled by processor, but a coming intr/nmi leave IBRS enabled after their exit. It's not necessory for bootup code to run in low performance with IBRS enabled.
On ORACLE X6-2(500GB/88 cpus, dom0 11GB/20 vcpus), we observed an 200s+ delay in
construct_dom0.By initializing
use_shadow_spec_ctrlwith the result of (system_state<SYS_STATE_active), IBRS is disabled in intr/nmi exit path at bootup stage. Then delay inconstruct_dom0is ~50s.
Quoted 7 lines
Quoted 5 lines
When hot-onlining a CPU, we initialize IBRS early and set
use_shadow_spec_ctrlto false to avoid Branch Target Injection from sibling threads.v2: Use (
system_state<SYS_STATE_active) to initializeuse_shadow_spec_ctrlinstead of literal 1 per Jan.Please place revision information below the first --- marker.
Ok
Quoted 10 lines
xen/include/asm-x86/spec_ctrl.h extern uint8_t default_bti_ist_info; · line 35
Quoted 8 lines
xen/include/asm-x86/spec_ctrl.h +1
-0@@ -32,8 +32,22 @@ extern uint8_t default_bti_ist_info;static inline void init_shadow_spec_ctrl_state (void ) {struct cpu_info *info =get_cpu_info (); +uint32_t val =SPEC_CTRL_IBRS ;Why do you need this variable?
This is a copy of the same code in spec_ctrl_enter_idle() and spec_ctrl_exit_idle().
Quoted 9 lines
xen/include/asm-x86/spec_ctrl.h extern uint8_t default_bti_ist_info; · line 40
Quoted 5 lines
xen/include/asm-x86/spec_ctrl.h +4
-0+/* Initialize IA32_SPEC_CTRL MSR for hotplugging cpu early */ +if ( system_state >= SYS_STATE_active ) + asm volatile (ALTERNATIVE(ASM_NOP3, "wrmsr", X86_FEATURE_XEN_IBRS_SET) + :: "a" (val), "c" (MSR_SPEC_CTRL), "d" (0) : "memory");I can see the point of doing this, but the title of the patch doesn't cover it (I think this has been missing independent of your interrupt/ NMI paths consideration).
Could I make a seperate patch for above four lines? Looks hard to describe all these in one title.
Quoted 4 lines
Further INIT# (unlike RESET#) doesn't clear the register, so you may want/need to also clear the register in the
X86_FEATURE_XEN_IBRS_CLEARcase.
I did consider using ALTERNATIVE_2 here, so dumped the IA32_SPEC_CTRL msr's value just after the entry of init_shadow_spec_ctrl_state() for a hot-onlining CPU and it's zero, this is the X86_FEATURE_XEN_IBRS_SET case. In X86_FEATURE_XEN_IBRS_CLEAR case, will IBRS ever be set?
Quoted 3 lines
Also you don't need
ASM_NOP3here after4008c71d7a("x86/alt:
Support for automatic padding calculations").
Yes
Quoted 4 lines
Additionally I think it would be better to keep low and high parts of the value next to each other in the constraints, rather than putting the MSR index in the middle.
Same copy from spec_ctrl_enter_idle() and spec_ctrl_exit_idle(), maybe it's better to have a seperate patch to fix all of them, including the variable val.
Quoted 12 lines
xen/include/asm-x86/spec_ctrl.h extern uint8_t default_bti_ist_info; · line 50
Quoted 11 lines
xen/include/asm-x86/spec_ctrl.h +9
-1- info->shadow_spec_ctrl = info->use_shadow_spec_ctrl =0 ; + info->shadow_spec_ctrl =0 ; +/* +* We want to make sure we clear IBRS in interrupt exit path +* (DO_SPEC_CTRL_EXIT_TO_XEN) while dom0 is still booting to +* avoid unnecessary performance impact. As soon as dom0 has +* booted use_shadow_spec_ctrl will be cleared, for example, +* in idle routine. +*/ + info->use_shadow_spec_ctrl = system_state < SYS_STATE_active;
Quoted 2 lines
I think the code overall would be more readable if you had just a single condition (in if/else form).
Ok
Quoted 4 lines
And then there is the question of whether to use < / >= or != / == : In the resume case, not guest vCPU-s are active (yet), so perhaps the latter would be better.
Ok
Quoted 4 lines
In any event please give Andrew a chance to reply before you send another version, as he may have a different opinion and/or other valuable input.
Ok, I'll wait Andrew's reply before go ahead.
Thanks
Zhenzhong
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 27.03.18 at 13:03, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich
xen/include/asm-x86/spec_ctrl.h extern uint8_t default_bti_ist_info; · line 35
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 27.03.18 at 06:52, <[email protected]> wrote:
xen/include/asm-x86/spec_ctrl.h +1
-0@@ -32,8 +32,22 @@ extern uint8_t default_bti_ist_info;static inline void init_shadow_spec_ctrl_state (void ) {struct cpu_info *info =get_cpu_info (); +uint32_t val =SPEC_CTRL_IBRS ;Why do you need this variable?
Quoted 2 lines
This is a copy of the same code in
spec_ctrl_enter_idle()andspec_ctrl_exit_idle().
In the latter the variable looks pretty pointless too, but I assume Andrew has put it there to be as symmetric as possible with the former, where the variable is used twice.
Quoted 10 lines
Quoted 8 lines
xen/include/asm-x86/spec_ctrl.h extern uint8_t default_bti_ist_info; · line 40
Quoted 4 lines
xen/include/asm-x86/spec_ctrl.h +4
-0+/* Initialize IA32_SPEC_CTRL MSR for hotplugging cpu early */ +if ( system_state >= SYS_STATE_active ) + asm volatile (ALTERNATIVE(ASM_NOP3, "wrmsr", X86_FEATURE_XEN_IBRS_SET) + :: "a" (val), "c" (MSR_SPEC_CTRL), "d" (0) : "memory");I can see the point of doing this, but the title of the patch doesn't cover it (I think this has been missing independent of your interrupt/ NMI paths consideration).
Could I make a seperate patch for above four lines? Looks hard to describe all these in one title.
Well, addressing separate issues in separate patches would be better anyway.
Quoted 7 lines
Quoted 3 lines
Further INIT# (unlike RESET#) doesn't clear the register, so you may want/need to also clear the register in the
X86_FEATURE_XEN_IBRS_CLEARcase.I did consider using
ALTERNATIVE_2here, so dumped theIA32_SPEC_CTRLmsr's value just after the entry ofinit_shadow_spec_ctrl_state()for a hot-onlining CPU and it's zero, this is theX86_FEATURE_XEN_IBRS_SETcase. InX86_FEATURE_XEN_IBRS_CLEARcase, will IBRS ever be set?
Remember - we're possibly dealing with post-INIT# state here. What has run on the CPU before the INIT# is simply unknown.
Quoted 6 lines
Quoted 3 lines
Additionally I think it would be better to keep low and high parts of the value next to each other in the constraints, rather than putting the MSR index in the middle.
Same copy from
spec_ctrl_enter_idle()andspec_ctrl_exit_idle(), maybe it's better to have a seperate patch to fix all of them, including the variable val.
Perhaps, yes. I didn't notice this ordering aspect when reviewing the earlier patches.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 64 lines · Jan Beulich
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 27.03.18 at 06:52, <[email protected]> wrote:
After reset, IBRS is disabled by processor, but a coming intr/nmi leave IBRS enabled after their exit. It's not necessory for bootup code to run in low performance with IBRS enabled.
On ORACLE X6-2(500GB/88 cpus, dom0 11GB/20 vcpus), we observed an 200s+ delay in
construct_dom0.By initializing
use_shadow_spec_ctrlwith the result of (system_state<SYS_STATE_active), IBRS is disabled in intr/nmi exit path at bootup stage. Then delay inconstruct_dom0is ~50s.Quoted 5 lines
When hot-onlining a CPU, we initialize IBRS early and set
use_shadow_spec_ctrlto false to avoid Branch Target Injection from sibling threads.v2: Use (
system_state<SYS_STATE_active) to initializeuse_shadow_spec_ctrlinstead of literal 1 per Jan.Please place revision information below the first --- marker.
xen/include/asm-x86/spec_ctrl.h extern uint8_t default_bti_ist_info; · line 35
Quoted 7 lines
xen/include/asm-x86/spec_ctrl.h +1
-0@@ -32,8 +32,22 @@ extern uint8_t default_bti_ist_info;static inline void init_shadow_spec_ctrl_state (void ) {struct cpu_info *info =get_cpu_info (); +uint32_t val =SPEC_CTRL_IBRS ;Why do you need this variable?
xen/include/asm-x86/spec_ctrl.h extern uint8_t default_bti_ist_info; · line 40
Quoted 4 lines
xen/include/asm-x86/spec_ctrl.h +4
-0+/* Initialize IA32_SPEC_CTRL MSR for hotplugging cpu early */ +if ( system_state >= SYS_STATE_active ) + asm volatile (ALTERNATIVE(ASM_NOP3, "wrmsr", X86_FEATURE_XEN_IBRS_SET) + :: "a" (val), "c" (MSR_SPEC_CTRL), "d" (0) : "memory");I can see the point of doing this, but the title of the patch doesn't cover it (I think this has been missing independent of your interrupt/ NMI paths consideration).
Further INIT# (unlike RESET#) doesn't clear the register, so you may want/need to also clear the register in the
X86_FEATURE_XEN_IBRS_CLEARcase.Also you don't need
ASM_NOP3here after4008c71d7a("x86/alt:
Support for automatic padding calculations").Additionally I think it would be better to keep low and high parts of the value next to each other in the constraints, rather than putting the MSR index in the middle.
xen/include/asm-x86/spec_ctrl.h extern uint8_t default_bti_ist_info; · line 50
Quoted 10 lines
xen/include/asm-x86/spec_ctrl.h +9
-1- info->shadow_spec_ctrl = info->use_shadow_spec_ctrl =0 ; + info->shadow_spec_ctrl =0 ; +/* +* We want to make sure we clear IBRS in interrupt exit path +* (DO_SPEC_CTRL_EXIT_TO_XEN) while dom0 is still booting to +* avoid unnecessary performance impact. As soon as dom0 has +* booted use_shadow_spec_ctrl will be cleared, for example, +* in idle routine. +*/ + info->use_shadow_spec_ctrl = system_state < SYS_STATE_active;I think the code overall would be more readable if you had just a single condition (in if/else form).
Quoted 7 lines
And then there is the question of whether to use < / >= or != / == : In the resume case, not guest vCPU-s are active (yet), so perhaps the latter would be better.
In any event please give Andrew a chance to reply before you send another version, as he may have a different opinion and/or other valuable input.
Hi Andrew,
May I have your comments? If there is no further suggestions from you, I'll prepare to make the new version.
Thanks
Zhenzhong
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel