xen/arm: SSBD (aka Spectre-v4) mitigation (XSA-263)
cover xen/arm: SSBD (aka Spectre-v4) mitigation (XSA-263)
Hi all,
This patch series implement the Xen hypervisor side of the "Spectre-v4" (CVE-2018-3639) mitigation known as "Speculative Store Bypass Disable" (SSBD).
More information can be found at:
https://bugs.chromium.org/p/project-zero/issues/detail?id=1528
https://developer.arm.com/support/arm-security-updates/speculative-processor-vulnerability
For all released Arm Cortex-A that are affected by this issue, then the preferred mitigation is simply to set a chicken bit in the firmware during CPU initialization and therefore no change to Xen is required. Other CPUs may require the chicken bit to be toggled dynamically (for example, when switching between kernel-mode and hypervisor-mode) and this is achieve by calling into EL3 via an SMC which has been published as part of the latest SMCCC specification:
https://developer.arm.com/cache-speculation-vulnerability-firmware-specification
as well as an ATF update for the released ARM cores affected by SSBD:
https://github.com/ARM-software/arm-trusted-firmware/pull/1392
These patches provide the following:
1. Safe probing of firmware to establish which CPUs in the system require calling into EL3 as part of the mitigation
2. A command-line option to force SSBD mitigation to be always on, always off, or dynamically toggled (default) for CPUs that require the EL3 call.
3. An initial implementation of the call via Xen, which exposes the mitigation to the guest via an HVC interface.
This patch also provides bug fix and new infrastructure require to implement the mitigation:
1. Zeroed each vCPU stack
2. Provide generic assembly macros
3. Provide alternative callback (RFC)
A branch can be found with all the patches at:
https://xenbits.xen.org/git-http/people/julieng/xen-unstable.git
branch ssbd/v1
Cheers,
Julien Grall (13):
xen/arm: domain: Zeroed the vCPU stack
xen/arm64: entry: Use named label in guest_sync
xen/arm: setup: Check errata for boot CPU later on xen/arm: Add ARCH_WORKAROUND_2 probing
xen/arm: Add command line option to control SSBD mitigation xen/arm: Add ARCH_WORKAROUND_2 support for guests
xen/arm: Simplify alternative patching
xen/arm: alternatives: Add dynamic patching feature xen/arm64: Add generic assembly macros
xen/arm64: Implement a fast path for handling SMCCC_ARCH_WORKAROUND_2 xen/arm: Kconfig: Move HARDEN_BRANCH_PREDICTOR under "Architecture
features"
xen/arm: smccc: Fix indentation in ARM_SMCCC_ARCH_WORKAROUND_1_FID xen/arm: Avoid to use current everywhere in enter_hypervisor_head
docs/misc/xen-command-line.markdown | 18 +++++ xen/arch/arm/Kconfig | 44 +++++++---- xen/arch/arm/alternative.c | 79 +++++++++++-------- xen/arch/arm/arm64/asm-offsets.c | 2 + xen/arch/arm/arm64/entry.S | 49 +++++++++++- xen/arch/arm/cpuerrata.c | 150 ++++++++++++++++++++++++++++++++++++ xen/arch/arm/domain.c | 12 +++ xen/arch/arm/setup.c | 8 +- xen/arch/arm/traps.c | 32 ++++++-- xen/arch/arm/vsmc.c | 37 +++++++++ xen/include/asm-arm/alternative.h | 44 +++++++++-- xen/include/asm-arm/arm64/macros.h | 25 ++++++ xen/include/asm-arm/cpuerrata.h | 42 ++++++++++ xen/include/asm-arm/cpufeature.h | 3 +- xen/include/asm-arm/current.h | 6 +- xen/include/asm-arm/macros.h | 2 +- xen/include/asm-arm/smccc.h | 13 +++- 17 files changed, 495 insertions(+), 71 deletions(-) create mode 100644 xen/include/asm-arm/arm64/macros.h
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 1/13 xen/arm: domain: Zeroed the vCPU stack
A stack is allocated per vCPU to be used by Xen. The allocation is done with alloc_xenheap_pages that does not zero the memory returned. However the top of the stack is containing information that will be used to store the initial state of the vCPU (see struct cpu_info). Some of the fields may not be initialized and will lead to use/leak bits of previous memory in some cases on the first run of vCPU (AFAICT this only happen on vCPU0 for Dom0).
While this is not strictly necessary, this patch zero the full stack to avoid more leakage.
This is part of XSA-263.
--- xen/arch/arm/domain.c | 4 ++++ 1 file changed, 4 insertions(+)
xen/arch/arm/domain.c +4 -0
@@ -540,6 +540,7 @@ void free_vcpu_struct(struct vcpu *v)int vcpu_initialise (struct vcpu *v) {int rc =0 ; +unsigned int i;BUILD_BUG_ON (sizeof (struct cpu_info ) >STACK_SIZE );
@@ -547,6 +548,9 @@ int vcpu_initialise(struct vcpu *v)if ( v->arch.stack ==NULL )return -ENOMEM ; +for ( i =0 ; i < (1U <<STACK_ORDER ); i++ ) +clear_page (v->arch.stack + (PAGE_SIZE * i)); + v->arch.cpu_info = (struct cpu_info *)(v->arch.stack +STACK_SIZE -sizeof (struct cpu_info ));
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 01/13] xen/arm: domain: Zeroed the vCPU stack
Quoted 10 lines · Julien Grall
A stack is allocated per vCPU to be used by Xen. The allocation is done with
alloc_xenheap_pagesthat does not zero the memory returned. However the top of the stack is containing information that will be used to store the initial state of the vCPU (see structcpu_info). Some of the fields may not be initialized and will lead to use/leak bits of previous memory in some cases on the first run of vCPU (AFAICT this only happen on vCPU0 for Dom0).While this is not strictly necessary, this patch zero the full stack to avoid more leakage.
Well spotted! struct cpu_info is the only instance of these cases, I suggest to zero only sizeof(struct cpu_info) to avoid having any impact on the boot time.
After all, with this series we have the mitigation enabled all the time in Xen for XSA-263. Or do you think there are other reasons to be concerned?
Quoted 32 lines
This is part of XSA-263.
Signed-off-by Julien Grall <[email protected]>--- xen/arch/arm/domain.c | 4 ++++ 1 file changed, 4 insertions(+)xen/arch/arm/domain.c +4
-0@@ -540,6 +540,7 @@ void free_vcpu_struct(struct vcpu *v)int vcpu_initialise (struct vcpu *v) {int rc =0 ; +unsigned int i;BUILD_BUG_ON (sizeof (struct cpu_info ) >STACK_SIZE );@@ -547,6 +548,9 @@ int vcpu_initialise(struct vcpu *v)if ( v->arch.stack ==NULL )return -ENOMEM ; +for ( i =0 ; i < (1U <<STACK_ORDER ); i++ ) +clear_page (v->arch.stack + (PAGE_SIZE * i)); + v->arch.cpu_info = (struct cpu_info *)(v->arch.stack +STACK_SIZE -sizeof (struct cpu_info ));Signature · 1 line
2.11.0
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 01/13] xen/arm: domain: Zeroed the vCPU stack
Hi Stefano,
Quoted 9 lines · Stefano Stabellini
Quoted 8 lines · Julien Grall
A stack is allocated per vCPU to be used by Xen. The allocation is done with
alloc_xenheap_pagesthat does not zero the memory returned. However the top of the stack is containing information that will be used to store the initial state of the vCPU (see structcpu_info). Some of the fields may not be initialized and will lead to use/leak bits of previous memory in some cases on the first run of vCPU (AFAICT this only happen on vCPU0 for Dom0).
Quoted 6 lines
Quoted 2 lines
While this is not strictly necessary, this patch zero the full stack to avoid more leakage.
Well spotted! struct
cpu_infois the only instance of these cases, I suggest to zero onlysizeof(struct cpu_info)to avoid having any impact on the boot time.
I really don't believe the impact is noticeable when you look at the rest of the domain creation.
Quoted 4 lines
After all, with this series we have the mitigation enabled all the time in Xen for XSA-263. Or do you think there are other reasons to be concerned?
This has nothing to do with XSA-263. This is more that it would be a good practice to zero anything by default rather than relying on the code to do the proper initialization. In the case of the stack it would be un-initialized value over code called by a domain or even assembly.
We already do that for all Domain specific structure but the stack.
I don't really particularly care to fully zeroed the stack if you don't want to see it.
Cheers,
Quoted 32 lines
Quoted 32 lines
This is part of XSA-263.
Signed-off-by Julien Grall <[email protected]>--- xen/arch/arm/domain.c | 4 ++++ 1 file changed, 4 insertions(+)xen/arch/arm/domain.c +4
-0@@ -540,6 +540,7 @@ void free_vcpu_struct(struct vcpu *v)int vcpu_initialise (struct vcpu *v) {int rc =0 ; +unsigned int i;BUILD_BUG_ON (sizeof (struct cpu_info ) >STACK_SIZE );@@ -547,6 +548,9 @@ int vcpu_initialise(struct vcpu *v)if ( v->arch.stack ==NULL )return -ENOMEM ; +for ( i =0 ; i < (1U <<STACK_ORDER ); i++ ) +clear_page (v->arch.stack + (PAGE_SIZE * i)); + v->arch.cpu_info = (struct cpu_info *)(v->arch.stack +STACK_SIZE -sizeof (struct cpu_info ));Signature · 1 line
2.11.0
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 01/13] xen/arm: domain: Zeroed the vCPU stack
Quoted 32 lines · Julien Grall
Hi Stefano,
Quoted 9 lines · Stefano Stabellini
Quoted 8 lines · Julien Grall
A stack is allocated per vCPU to be used by Xen. The allocation is done with
alloc_xenheap_pagesthat does not zero the memory returned. However the top of the stack is containing information that will be used to store the initial state of the vCPU (see structcpu_info). Some of the fields may not be initialized and will lead to use/leak bits of previous memory in some cases on the first run of vCPU (AFAICT this only happen on vCPU0 for Dom0).Quoted 6 lines
Quoted 2 lines
While this is not strictly necessary, this patch zero the full stack to avoid more leakage.
Well spotted! struct
cpu_infois the only instance of these cases, I suggest to zero onlysizeof(struct cpu_info)to avoid having any impact on the boot time.I really don't believe the impact is noticeable when you look at the rest of the domain creation.
Quoted 4 lines
After all, with this series we have the mitigation enabled all the time in Xen for XSA-263. Or do you think there are other reasons to be concerned?
This has nothing to do with XSA-263. This is more that it would be a good practice to zero anything by default rather than relying on the code to do the proper initialization. In the case of the stack it would be un-initialized value over code called by a domain or even assembly.
Quoted 4 lines
We already do that for all Domain specific structure but the stack.
I don't really particularly care to fully zeroed the stack if you don't want to see it.
I'd choose to only zero what we need.
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
This is part of XSA-263.
Signed-off-by Julien Grall <[email protected]>--- xen/arch/arm/domain.c | 4 ++++ 1 file changed, 4 insertions(+)xen/arch/arm/domain.c +1
-0@@ -540,6 +540,7 @@ void free_vcpu_struct(struct vcpu *v)int vcpu_initialise (struct vcpu *v) {int rc =0 ; +unsigned int i;BUILD_BUG_ON (sizeof (struct cpu_info ) >STACK_SIZE ); @@ -547,6 +548,9 @@ int vcpu_initialise(struct vcpu *v) if ( v->arch.stack == NULL )return -ENOMEM;+ for ( i = 0; i < (1U <<
STACK_ORDER); i++ )
Quoted 12 lines
Quoted 8 lines
Quoted 8 lines
xen/arch/arm/domain.c +2
-0+clear_page (v->arch.stack + (PAGE_SIZE * i)); + v->arch.cpu_info = (struct cpu_info *)(v->arch.stack +STACK_SIZE -sizeof (struct cpu_info ));Signature · 1 line
2.11.0Signature · 1 line
Julien Grall
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 2/13 xen/arm64: entry: Use named label in guest_sync
In reply to Julien GrallThis will improve readability for future changes.
This is part of XSA-263.
--- xen/arch/arm/arm64/entry.S | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
xen/arch/arm/arm64/entry.S +4 -4
@@ -226,11 +226,11 @@ guest_sync: mrs x1, esr_el2 lsr x1, x1, #HSR_EC_SHIFT /* x1 = ESR_EL2.EC */ cmp x1, #HSR_EC_HVC64 - b.ne 1f /* Not a HVC skip fastpath. */ + b.ne guest_sync_slowpath /* Not a HVC skip fastpath. */ mrs x1, esr_el2 and x1, x1, #0xffff /* Check the immediate [0:16] */ - cbnz x1, 1f /* should be 0 for HVC #0 */ + cbnz x1, guest_sync_slowpath /* should be 0 for HVC #0 */ /* * Fastest path possible for ARM_SMCCC_ARCH_WORKAROUND_1.
@@ -241,7 +241,7 @@ guest_sync: * be encoded as an immediate for cmp. */ eor w0, w0, #ARM_SMCCC_ARCH_WORKAROUND_1_FID - cbnz w0, 1f + cbnz w0, guest_sync_slowpath /* * Clobber both x0 and x1 to prevent leakage. Note that thanks
@@ -250,7 +250,7 @@ guest_sync: mov x1, xzr eret -1: +guest_sync_slowpath: /* * x0/x1 may have been scratch by the fast path above, so avoid * to save them.
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 02/13] xen/arm64: entry: Use named label in guest_sync
Quoted 5 lines · Julien Grall
This will improve readability for future changes.
This is part of XSA-263.
Signed-off-by Julien Grall <[email protected]>
Quoted 43 lines
--- xen/arch/arm/arm64/entry.S | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)xen/arch/arm/arm64/entry.S +4
-4@@ -226,11 +226,11 @@ guest_sync: mrs x1, esr_el2 lsr x1, x1, #HSR_EC_SHIFT /* x1 = ESR_EL2.EC */ cmp x1, #HSR_EC_HVC64 - b.ne 1f /* Not a HVC skip fastpath. */ + b.ne guest_sync_slowpath /* Not a HVC skip fastpath. */ mrs x1, esr_el2 and x1, x1, #0xffff /* Check the immediate [0:16] */ - cbnz x1, 1f /* should be 0 for HVC #0 */ + cbnz x1, guest_sync_slowpath /* should be 0 for HVC #0 */ /* * Fastest path possible for ARM_SMCCC_ARCH_WORKAROUND_1.@@ -241,7 +241,7 @@ guest_sync: * be encoded as an immediate for cmp. */ eor w0, w0, #ARM_SMCCC_ARCH_WORKAROUND_1_FID - cbnz w0, 1f + cbnz w0, guest_sync_slowpath /* * Clobber both x0 and x1 to prevent leakage. Note that thanks@@ -250,7 +250,7 @@ guest_sync: mov x1, xzr eret -1: +guest_sync_slowpath: /* * x0/x1 may have been scratch by the fast path above, so avoid * to save them.Signature · 1 line
2.11.0
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 3/13 xen/arm: setup: Check errata for boot CPU later on
In reply to Julien GrallSome errata will rely on the SMCCC version which is detected by psci_init().
This is part of XSA-263.
--- xen/arch/arm/setup.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
xen/arch/arm/setup.c +6 -2
@@ -171,8 +171,6 @@ static void __init processor_id(void) }processor_setup (); - -check_local_cpu_errata (); } void dt_unreserved_regions(paddr_t s, paddr_t e,
@@ -779,6 +777,12 @@ void __init start_xen(unsigned long boot_phys_offset,printk (XENLOG_INFO "SMP: Allowing %u CPUs\n" , cpus); nr_cpu_ids = cpus; +/* +* Some errata relies on SMCCC version which is detected by psci_init() +* (called from smp_init_cpus()). +*/ +check_local_cpu_errata (); +init_xen_time ();gic_init ();
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 03/13] xen/arm: setup: Check errata for boot CPU later on
Quoted 6 lines · Julien Grall
Some errata will rely on the SMCCC version which is detected by
psci_init().This is part of XSA-263.
Signed-off-by Julien Grall <[email protected]>
Quoted 33 lines
--- xen/arch/arm/setup.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)xen/arch/arm/setup.c +6
-2@@ -171,8 +171,6 @@ static void __init processor_id(void) }processor_setup (); - -check_local_cpu_errata (); } void dt_unreserved_regions(paddr_t s, paddr_t e,@@ -779,6 +777,12 @@ void __init start_xen(unsigned long boot_phys_offset,printk (XENLOG_INFO "SMP: Allowing %u CPUs\n" , cpus); nr_cpu_ids = cpus; +/* +* Some errata relies on SMCCC version which is detected by psci_init() +* (called from smp_init_cpus()). +*/ +check_local_cpu_errata (); +init_xen_time ();gic_init ();Signature · 1 line
2.11.0
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 03/13] xen/arm: setup: Check errata for boot CPU later on
Hi Stefano,
Quoted 9 lines · Stefano Stabellini
Quoted 6 lines · Julien Grall
Some errata will rely on the SMCCC version which is detected by
psci_init().This is part of XSA-263.
Signed-off-by Julien Grall <[email protected]>Reviewed-by Stefano Stabellini <[email protected]>
Thank you for the review. On an internal review Andre's suggested to move psci_init() outside smp_init_cpus(). Something like:
processor_id();
/* Need PSCI version for firmware based errata workarounds */
psci_init();
check_local_cpu_errata();
smp_init_cpus();I am wondering whether it would be clearer to have. What do you think?
Cheers,
Quoted 34 lines
Quoted 34 lines
--- xen/arch/arm/setup.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)xen/arch/arm/setup.c +6
-2@@ -171,8 +171,6 @@ static void __init processor_id(void) }processor_setup (); - -check_local_cpu_errata (); } void dt_unreserved_regions(paddr_t s, paddr_t e,@@ -779,6 +777,12 @@ void __init start_xen(unsigned long boot_phys_offset,printk (XENLOG_INFO "SMP: Allowing %u CPUs\n" , cpus); nr_cpu_ids = cpus; +/* +* Some errata relies on SMCCC version which is detected by psci_init() +* (called from smp_init_cpus()). +*/ +check_local_cpu_errata (); +init_xen_time ();gic_init ();Signature · 1 line
2.11.0
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 03/13] xen/arm: setup: Check errata for boot CPU later on
Quoted 18 lines · Julien Grall
Hi Stefano,
Quoted 9 lines · Stefano Stabellini
Quoted 6 lines · Julien Grall
Some errata will rely on the SMCCC version which is detected by
psci_init().This is part of XSA-263.
Signed-off-by Julien Grall <[email protected]>Reviewed-by Stefano Stabellini <[email protected]>Thank you for the review. On an internal review Andre's suggested to move
psci_init()outsidesmp_init_cpus(). Something like:processor_id();
Quoted 8 lines
/* Need PSCI version for firmware based errata workarounds */ psci_init(); check_local_cpu_errata(); smp_init_cpus();I am wondering whether it would be clearer to have. What do you think?
That also works. I am fine either way, they both look OK to me.
Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
--- xen/arch/arm/setup.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)xen/arch/arm/setup.c +2
-2@@ -171,8 +171,6 @@ static void __init processor_id(void) }processor_setup (); - -check_local_cpu_errata (); } void dt_unreserved_regions(paddr_t s, paddr_t e,@@ -779,6 +777,12 @@ void __init start_xen(unsigned long boot_phys_offset,printk (XENLOG_INFO "SMP: Allowing %u CPUs\n" , cpus); nr_cpu_ids = cpus; + /* +* Some errata relies on SMCCC version which is detected by psci_init() +* (called from smp_init_cpus()).
Quoted 12 lines
Quoted 8 lines
Quoted 8 lines
xen/arch/arm/setup.c +3
-0+*/ +check_local_cpu_errata (); +init_xen_time ();gic_init ();Signature · 1 line
2.11.0Signature · 1 line
Julien Grall
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 03/13] xen/arm: setup: Check errata for boot CPU later on
Hi Stefano,
Quoted 22 lines · Stefano Stabellini
Quoted 21 lines · Julien Grall
Hi Stefano,
Quoted 9 lines · Stefano Stabellini
Quoted 6 lines · Julien Grall
Some errata will rely on the SMCCC version which is detected by
psci_init().This is part of XSA-263.
Signed-off-by Julien Grall <[email protected]>Reviewed-by Stefano Stabellini <[email protected]>Thank you for the review. On an internal review Andre's suggested to move
psci_init()outsidesmp_init_cpus(). Something like:processor_id(); /* Need PSCI version for firmware based errata workarounds */ psci_init();
Quoted 7 lines
Quoted 5 lines
check_local_cpu_errata(); smp_init_cpus();I am wondering whether it would be clearer to have. What do you think?
That also works. I am fine either way, they both look OK to me.
I will keep the current version then.
Cheers,
Quoted 38 lines
Quoted 38 lines
Quoted 34 lines
Quoted 34 lines
--- xen/arch/arm/setup.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)xen/arch/arm/setup.c +5
-2@@ -171,8 +171,6 @@ static void __init processor_id(void) }processor_setup (); - -check_local_cpu_errata (); } void dt_unreserved_regions(paddr_t s, paddr_t e,@@ -779,6 +777,12 @@ void __init start_xen(unsigned long boot_phys_offset,printk (XENLOG_INFO "SMP: Allowing %u CPUs\n" , cpus); nr_cpu_ids = cpus; +/* +* Some errata relies on SMCCC version which is detected by psci_init() +* (called from smp_init_cpus()). +*/ +check_local_cpu_errata (); +init_xen_time ();gic_init ();Signature · 1 line
2.11.0Signature · 1 line
Julien Grall
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 4/13 xen/arm: Add ARCH_WORKAROUND_2 probing
In reply to Julien GrallAs for Spectre variant-2, we rely on SMCCC 1.1 to provide the discovery mechanism for detecting the SSBD mitigation.
A new capability is also allocated for that purpose, and a config option.
This is part of XSA-263.
--- xen/arch/arm/Kconfig | 10 ++++++++++ xen/arch/arm/cpuerrata.c | 39 +++++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/cpuerrata.h | 21 +++++++++++++++++++++ xen/include/asm-arm/cpufeature.h | 3 ++- xen/include/asm-arm/smccc.h | 6 ++++++ 5 files changed, 78 insertions(+), 1 deletion(-)
xen/arch/arm/Kconfig +10 -0
@@ -73,6 +73,16 @@ config SBSA_VUART_CONSOLE Allows a guest to use SBSA Generic UART as a console. The SBSA Generic UART implements a subset of ARM PL011 UART. +config ARM_SSBD + bool "Speculative Store Bypass Disable" if EXPERT = "y" + depends on HAS_ALTERNATIVE + default y + help + This enables mitigation of bypassing of previous stores by speculative + loads. + + If unsure, say Y. + endmenu menu "ARM errata workaround via the alternative framework"
xen/arch/arm/cpuerrata.c +39 -0
@@ -235,6 +235,39 @@ static int enable_ic_inv_hardening(void *data)#endif +#ifdef CONFIG_ARM_SSBD + +/* +* Assembly code may use the variable directly, so we need to make sure +* it fits in a register. +*/ +DEFINE_PER_CPU_READ_MOSTLY (register_t, ssbd_callback_required); + +static bool has_ssbd_mitigation (const struct arm_cpu_capabilities *entry) +{ +struct arm_smccc_res res; +bool supported = true; + +if ( smccc_ver <SMCCC_VERSION (1 ,1 ) ) +return false; + +/* +* The probe function return value is either negative (unsupported +* or mitigated), positive (unaffected), or zero (requires +* mitigation). We only need to do anything in the last case. +*/ +arm_smccc_1_1_smc (ARM_SMCCC_ARCH_FEATURES_FID , +ARM_SMCCC_ARCH_WORKAROUND_2_FID , &res); +if ( (int )res.a0 !=0 ) + supported = false; + +if ( supported ) +this_cpu (ssbd_callback_required) =1 ; + +return supported; +} +#endif +#define MIDR_RANGE (model, min, max) \ .matches = is_affected_midr_range, \ .midr_model = model, \
@@ -336,6 +369,12 @@ static const struct arm_cpu_capabilities arm_errata[] = { .enable = enable_ic_inv_hardening, },#endif +#ifdef CONFIG_ARM_SSBD + { + .capability = ARM_SSBD, + .matches = has_ssbd_mitigation, + }, +#endif {}, };
xen/include/asm-arm/cpuerrata.h +21 -0
@@ -27,9 +27,30 @@ static inline bool check_workaround_##erratum(void) \ CHECK_WORKAROUND_HELPER(766422, ARM32_WORKAROUND_766422, CONFIG_ARM_32) CHECK_WORKAROUND_HELPER(834220, ARM64_WORKAROUND_834220, CONFIG_ARM_64) +CHECK_WORKAROUND_HELPER(ssbd, ARM_SSBD, CONFIG_ARM_SSBD)#undef CHECK_WORKAROUND_HELPER +#ifdef CONFIG_ARM_SSBD + +#include <asm/current.h> + +DECLARE_PER_CPU (register_t, ssbd_callback_required); + +static inline bool cpu_require_ssbd_mitigation (void ) +{ +return this_cpu (ssbd_callback_required); +} + +#else + +static inline bool cpu_require_ssbd_mitigation (void ) +{ +return false; +} + +#endif +#endif /* __ARM_CPUERRATA_H__ */ /* * Local variables:
xen/include/asm-arm/cpufeature.h +2 -1
@@ -43,8 +43,9 @@#define SKIP_SYNCHRONIZE_SERROR_ENTRY_EXIT 5#define SKIP_CTXT_SWITCH_SERROR_SYNC 6#define ARM_HARDEN_BRANCH_PREDICTOR 7 +#define ARM_SSBD 8 -#define ARM_NCAPS 8 +#define ARM_NCAPS 9#ifndef __ASSEMBLY__
xen/include/asm-arm/smccc.h +6 -0
@@ -258,6 +258,12 @@ struct arm_smccc_res { ARM_SMCCC_OWNER_ARCH, \ 0x8000) +#define ARM_SMCCC_ARCH_WORKAROUND_2_FID \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + ARM_SMCCC_CONV_32, \ + ARM_SMCCC_OWNER_ARCH, \ + 0x7FFF) +/* SMCCC error codes */ #define ARM_SMCCC_ERR_UNKNOWN_FUNCTION (-1)#define ARM_SMCCC_NOT_SUPPORTED (-1)
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 04/13] xen/arm: Add ARCH_WORKAROUND_2 probing
Quoted 22 lines · Julien Grall
As for Spectre variant-2, we rely on SMCCC 1.1 to provide the discovery mechanism for detecting the SSBD mitigation.
A new capability is also allocated for that purpose, and a config option.
This is part of XSA-263.
Signed-off-by Julien Grall <[email protected]>--- xen/arch/arm/Kconfig | 10 ++++++++++ xen/arch/arm/cpuerrata.c | 39 +++++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/cpuerrata.h | 21 +++++++++++++++++++++ xen/include/asm-arm/cpufeature.h | 3 ++- xen/include/asm-arm/smccc.h | 6 ++++++ 5 files changed, 78 insertions(+), 1 deletion(-)xen/arch/arm/Kconfig +0
-0
xen/arch/arm/Kconfig config SBSA_VUART_CONSOLE · line 82
Quoted 10 lines
xen/arch/arm/Kconfig +7
-0@@ -73,6 +73,16 @@ config SBSA_VUART_CONSOLE Allows a guest to use SBSA Generic UART as a console. The SBSA Generic UART implements a subset of ARM PL011 UART. +config ARM_SSBD + bool "Speculative Store Bypass Disable" if EXPERT = "y" + depends on HAS_ALTERNATIVE + default y + help + This enables mitigation of bypassing of previous stores by speculative + loads.
I would add a reference to spectre v4. What do you think of:
This enables the mitigation of Spectre v4 attacks based on bypassing of previous memory stores by speculative loads.
Quoted 69 lines
xen/arch/arm/Kconfig +2
-0+ If unsure, say Y. + endmenu menu "ARM errata workaround via the alternative framework"xen/arch/arm/cpuerrata.c +39
-0@@ -235,6 +235,39 @@ static int enable_ic_inv_hardening(void *data)#endif +#ifdef CONFIG_ARM_SSBD + +/* +* Assembly code may use the variable directly, so we need to make sure +* it fits in a register. +*/ +DEFINE_PER_CPU_READ_MOSTLY (register_t, ssbd_callback_required); + +static bool has_ssbd_mitigation (const struct arm_cpu_capabilities *entry) +{ +struct arm_smccc_res res; +bool supported = true; + +if ( smccc_ver <SMCCC_VERSION (1 ,1 ) ) +return false; + +/* +* The probe function return value is either negative (unsupported +* or mitigated), positive (unaffected), or zero (requires +* mitigation). We only need to do anything in the last case. +*/ +arm_smccc_1_1_smc (ARM_SMCCC_ARCH_FEATURES_FID , +ARM_SMCCC_ARCH_WORKAROUND_2_FID , &res); +if ( (int )res.a0 !=0 ) + supported = false; + +if ( supported ) +this_cpu (ssbd_callback_required) =1 ; + +return supported; +} +#endif +#define MIDR_RANGE (model, min, max) \ .matches = is_affected_midr_range, \ .midr_model = model, \@@ -336,6 +369,12 @@ static const struct arm_cpu_capabilities arm_errata[] = { .enable = enable_ic_inv_hardening, },#endif +#ifdef CONFIG_ARM_SSBD + { + .capability = ARM_SSBD, + .matches = has_ssbd_mitigation, + }, +#endif {}, };xen/include/asm-arm/cpuerrata.h +0
-0@@ -27,9 +27,30 @@ static inline bool check_workaround_##erratum(void) \CHECK_WORKAROUND_HELPER (766422 ,ARM32_WORKAROUND_766422 ,CONFIG_ARM_32 )
xen/include/asm-arm/cpuerrata.h static inline bool check_workaround_##erratum(void) \ · line 38
Quoted 10 lines
xen/include/asm-arm/cpuerrata.h +6
-0CHECK_WORKAROUND_HELPER(834220, ARM64_WORKAROUND_834220, CONFIG_ARM_64) +CHECK_WORKAROUND_HELPER(ssbd, ARM_SSBD, CONFIG_ARM_SSBD)#undef CHECK_WORKAROUND_HELPER +#ifdef CONFIG_ARM_SSBD + +#include <asm/current.h> + +DECLARE_PER_CPU (register_t, ssbd_callback_required);
It is becoming more common to have per-cpu capabilities and workarounds (or at least per MPIDR). Instead of adding this add-hoc variable, should we make cpu_hwcaps per-cpu, then implement this check with cpus_have_cap (that would become per-cpu as well)?
It looks like the code would be simpler.
Quoted 52 lines
xen/include/asm-arm/cpuerrata.h +13
-0+static inline bool cpu_require_ssbd_mitigation (void ) +{ +return this_cpu (ssbd_callback_required); +} + +#else + +static inline bool cpu_require_ssbd_mitigation (void ) +{ +return false; +} +#endif +#endif /* __ARM_CPUERRATA_H__ */ /* * Local variables: xen/include/asm-arm/cpufeature.h +2
-1@@ -43,8 +43,9 @@#define SKIP_SYNCHRONIZE_SERROR_ENTRY_EXIT 5#define SKIP_CTXT_SWITCH_SERROR_SYNC 6#define ARM_HARDEN_BRANCH_PREDICTOR 7 +#define ARM_SSBD 8 -#define ARM_NCAPS 8 +#define ARM_NCAPS 9#ifndef __ASSEMBLY__xen/include/asm-arm/smccc.h +6
-0@@ -258,6 +258,12 @@ struct arm_smccc_res { ARM_SMCCC_OWNER_ARCH, \ 0x8000) +#define ARM_SMCCC_ARCH_WORKAROUND_2_FID \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + ARM_SMCCC_CONV_32, \ + ARM_SMCCC_OWNER_ARCH, \ + 0x7FFF) +/* SMCCC error codes */ #define ARM_SMCCC_ERR_UNKNOWN_FUNCTION (-1)#define ARM_SMCCC_NOT_SUPPORTED (-1)Signature · 1 line
2.11.0
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 04/13] xen/arm: Add ARCH_WORKAROUND_2 probing
Hi,
Quoted 36 lines · Stefano Stabellini
Quoted 22 lines · Julien Grall
As for Spectre variant-2, we rely on SMCCC 1.1 to provide the discovery mechanism for detecting the SSBD mitigation.
A new capability is also allocated for that purpose, and a config option.
This is part of XSA-263.
Signed-off-by Julien Grall <[email protected]>--- xen/arch/arm/Kconfig | 10 ++++++++++ xen/arch/arm/cpuerrata.c | 39 +++++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/cpuerrata.h | 21 +++++++++++++++++++++ xen/include/asm-arm/cpufeature.h | 3 ++- xen/include/asm-arm/smccc.h | 6 ++++++ 5 files changed, 78 insertions(+), 1 deletion(-)xen/arch/arm/Kconfig +0
-0xen/arch/arm/Kconfig config SBSA_VUART_CONSOLE · line 82
Quoted 10 lines
xen/arch/arm/Kconfig +7
-0@@ -73,6 +73,16 @@ config SBSA_VUART_CONSOLE Allows a guest to use SBSA Generic UART as a console. The SBSA Generic UART implements a subset of ARM PL011 UART. +config ARM_SSBD + bool "Speculative Store Bypass Disable" if EXPERT = "y" + depends on HAS_ALTERNATIVE + default y + help + This enables mitigation of bypassing of previous stores by speculative + loads.I would add a reference to spectre v4. What do you think of:
Quoted 2 lines
This enables the mitigation of Spectre v4 attacks based on bypassing of previous memory stores by speculative loads.
Well, the real name is SSBD (Speculative Store Bypass Disable). AFAIK, Spectre only refers to variant 1 and 2 so far. This one has no fancy name and the specifications is using SSBD.
Quoted 74 lines
Quoted 74 lines
xen/arch/arm/Kconfig +2
-0+ If unsure, say Y. + endmenu menu "ARM errata workaround via the alternative framework"xen/arch/arm/cpuerrata.c +39
-0@@ -235,6 +235,39 @@ static int enable_ic_inv_hardening(void *data)#endif +#ifdef CONFIG_ARM_SSBD + +/* +* Assembly code may use the variable directly, so we need to make sure +* it fits in a register. +*/ +DEFINE_PER_CPU_READ_MOSTLY (register_t, ssbd_callback_required); + +static bool has_ssbd_mitigation (const struct arm_cpu_capabilities *entry) +{ +struct arm_smccc_res res; +bool supported = true; + +if ( smccc_ver <SMCCC_VERSION (1 ,1 ) ) +return false; + +/* +* The probe function return value is either negative (unsupported +* or mitigated), positive (unaffected), or zero (requires +* mitigation). We only need to do anything in the last case. +*/ +arm_smccc_1_1_smc (ARM_SMCCC_ARCH_FEATURES_FID , +ARM_SMCCC_ARCH_WORKAROUND_2_FID , &res); +if ( (int )res.a0 !=0 ) + supported = false; + +if ( supported ) +this_cpu (ssbd_callback_required) =1 ; + +return supported; +} +#endif +#define MIDR_RANGE (model, min, max) \ .matches = is_affected_midr_range, \ .midr_model = model, \@@ -336,6 +369,12 @@ static const struct arm_cpu_capabilities arm_errata[] = { .enable = enable_ic_inv_hardening, },#endif +#ifdef CONFIG_ARM_SSBD + { + .capability = ARM_SSBD, + .matches = has_ssbd_mitigation, + }, +#endif {}, };xen/include/asm-arm/cpuerrata.h +1
-0@@ -27,9 +27,30 @@ static inline bool check_workaround_##erratum(void) \ CHECK_WORKAROUND_HELPER(766422, ARM32_WORKAROUND_766422, CONFIG_ARM_32) CHECK_WORKAROUND_HELPER(834220, ARM64_WORKAROUND_834220, CONFIG_ARM_64) +CHECK_WORKAROUND_HELPER(ssbd, ARM_SSBD, CONFIG_ARM_SSBD)#undef CHECK_WORKAROUND_HELPER
Quoted 8 lines
xen/include/asm-arm/cpuerrata.h static inline bool check_workaround_##erratum(void) \ · line 38
Quoted 5 lines
xen/include/asm-arm/cpuerrata.h +5
-0+#ifdef CONFIG_ARM_SSBD + +#include <asm/current.h> + +DECLARE_PER_CPU (register_t, ssbd_callback_required);It is becoming more common to have per-cpu capabilities and workarounds (or at least per MPIDR).
Really? This is the first place where we need an ad-hoc boolean per-CPU. For the hardening branch predictor, we have to store the vector pointer.
Quoted 5 lines
Instead of adding this add-hoc variable, should we make
cpu_hwcapsper-cpu, then implement this check withcpus_have_cap(that would become per-cpu as well)?It looks like the code would be simpler.
I don't see any benefits for that. Most of the workaround/features are platform wide because they either use alternative or set/clear a bit in the system registers.
Furthermore, as I wrote above the declaration, this is going to be used in assembly code and we need something that can be tested in the less possible number of instructions because The smccc function ARM_ARCH_WORKAROUND_2 is going to be called very often.
Lastly, after the next patch, ssbd_callback_required and ARM_SSBD have different meaning. The former indicates that runtime mitigation is required, while the latter just indicate that the mitigation is present (either runtime or forced enable).
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 04/13] xen/arm: Add ARCH_WORKAROUND_2 probing
Quoted 40 lines · Julien Grall
Hi,
Quoted 37 lines · Stefano Stabellini
Quoted 32 lines · Julien Grall
As for Spectre variant-2, we rely on SMCCC 1.1 to provide the discovery mechanism for detecting the SSBD mitigation.
A new capability is also allocated for that purpose, and a config option.
This is part of XSA-263.
Signed-off-by Julien Grall <[email protected]>--- xen/arch/arm/Kconfig | 10 ++++++++++ xen/arch/arm/cpuerrata.c | 39 +++++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/cpuerrata.h | 21 +++++++++++++++++++++ xen/include/asm-arm/cpufeature.h | 3 ++- xen/include/asm-arm/smccc.h | 6 ++++++ 5 files changed, 78 insertions(+), 1 deletion(-)xen/arch/arm/Kconfig +5
-0@@ -73,6 +73,16 @@ config SBSA_VUART_CONSOLE Allows a guest to use SBSA Generic UART as a console. The SBSA Generic UART implements a subset of ARM PL011 UART. +config ARM_SSBD + bool "Speculative Store Bypass Disable" if EXPERT = "y" + depends on HAS_ALTERNATIVE + default y + help + This enables mitigation of bypassing of previous stores byspeculative
xen/arch/arm/Kconfig config SBSA_VUART_CONSOLE · line 82
Quoted 1 line
xen/arch/arm/Kconfig +1
-0+ loads.I would add a reference to spectre v4. What do you think of:
Quoted 6 lines
Quoted 2 lines
This enables the mitigation of Spectre v4 attacks based on bypassing of previous memory stores by speculative loads.
Well, the real name is SSBD (Speculative Store Bypass Disable). AFAIK, Spectre only refers to variant 1 and 2 so far. This one has no fancy name and the specifications is using SSBD.
Googling for Spectre Variant 4 returns twice as many results as Googling for Speculative Store Bypass Disable. It doesn't matter what is the official name for the security issue, I think we need to include a reference to the most common name for it.
Quoted 98 lines
Quoted 71 lines
Quoted 71 lines
xen/arch/arm/Kconfig +2
-0+ If unsure, say Y. + endmenu menu "ARM errata workaround via the alternative framework"xen/arch/arm/cpuerrata.c +38
-0@@ -235,6 +235,39 @@ static int enable_ic_inv_hardening(void *data)#endif +#ifdef CONFIG_ARM_SSBD + +/* +* Assembly code may use the variable directly, so we need to make sure +* it fits in a register. +*/ +DEFINE_PER_CPU_READ_MOSTLY (register_t, ssbd_callback_required); + +static bool has_ssbd_mitigation (const struct arm_cpu_capabilities *entry) +{ +struct arm_smccc_res res; +bool supported = true; + +if ( smccc_ver <SMCCC_VERSION (1 ,1 ) ) +return false; + +/* +* The probe function return value is either negative (unsupported +* or mitigated), positive (unaffected), or zero (requires +* mitigation). We only need to do anything in the last case. +*/ +arm_smccc_1_1_smc (ARM_SMCCC_ARCH_FEATURES_FID , +ARM_SMCCC_ARCH_WORKAROUND_2_FID , &res); +if ( (int )res.a0 !=0 ) + supported = false; + +if ( supported ) +this_cpu (ssbd_callback_required) =1 ; + +return supported; +} +#endif +#define MIDR_RANGE (model, min, max) \ .matches = is_affected_midr_range, \ .midr_model = model, \@@ -336,6 +369,12 @@ static const struct arm_cpu_capabilities arm_errata[] = { .enable = enable_ic_inv_hardening, },#endif +#ifdef CONFIG_ARM_SSBD + { + .capability = ARM_SSBD, + .matches = has_ssbd_mitigation, + }, +#endif {}, };diff --git
a/xen/include/asm-arm/cpuerrata.hb/xen/include/asm-arm/cpuerrata.h
index4e45b237c8..e628d3ff56100644xen/include/asm-arm/cpuerrata.h +1
-0@@ -27,9 +27,30 @@ static inline bool check_workaround_##erratum(void) \CHECK_WORKAROUND_HELPER (766422 ,ARM32_WORKAROUND_766422 , CONFIG_ARM_32) CHECK_WORKAROUND_HELPER(834220, ARM64_WORKAROUND_834220, CONFIG_ARM_64) +CHECK_WORKAROUND_HELPER(ssbd, ARM_SSBD, CONFIG_ARM_SSBD)#undef CHECK_WORKAROUND_HELPERQuoted 8 lines
xen/include/asm-arm/cpuerrata.h static inline bool check_workaround_##erratum(void) \ · line 38
Quoted 5 lines
xen/include/asm-arm/cpuerrata.h +4
-0+#ifdef CONFIG_ARM_SSBD + +#include <asm/current.h> + +DECLARE_PER_CPU (register_t, ssbd_callback_required);It is becoming more common to have per-cpu capabilities and workarounds (or at least per MPIDR).
Really? This is the first place where we need an ad-hoc boolean per-CPU. For the hardening branch predictor, we have to store the vector pointer.
Quoted 5 lines
Instead of adding this add-hoc variable, should we make
cpu_hwcapsper-cpu, then implement this check withcpus_have_cap(that would become per-cpu as well)?It looks like the code would be simpler.
I don't see any benefits for that. Most of the workaround/features are platform wide because they either use alternative or set/clear a bit in the system registers.
Furthermore, as I wrote above the declaration, this is going to be used in assembly code and we need something that can be tested in the less possible number of instructions because The smccc function
ARM_ARCH_WORKAROUND_2is going to be called very often.
Quoted 4 lines
Lastly, after the next patch,
ssbd_callback_requiredandARM_SSBDhave different meaning. The former indicates that runtime mitigation is required, while the latter just indicate that the mitigation is present (either runtime or forced enable).
You are right. I was following up from the big.LITTLE series where not all CPUs need the same workaround. On the call you pointed out that the cpufeature framework is mostly to enable specific code workarounds in Xen for some erratas. These dynamic code fixes have to be enabled on all cores regardless on whether they are affected because they rely on dynamic code patching. I see your point, and I agree we should keep cpufeature as-is for now. I think I have a better suggestion in my reply to patch #5.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 04/13] xen/arm: Add ARCH_WORKAROUND_2 probing
Quoted 42 lines · Stefano Stabellini
Quoted 41 lines · Julien Grall
Hi,
Quoted 38 lines · Stefano Stabellini
Quoted 32 lines · Julien Grall
As for Spectre variant-2, we rely on SMCCC 1.1 to provide the discovery mechanism for detecting the SSBD mitigation.
A new capability is also allocated for that purpose, and a config option.
This is part of XSA-263.
Signed-off-by Julien Grall <[email protected]>--- xen/arch/arm/Kconfig | 10 ++++++++++ xen/arch/arm/cpuerrata.c | 39 +++++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/cpuerrata.h | 21 +++++++++++++++++++++ xen/include/asm-arm/cpufeature.h | 3 ++- xen/include/asm-arm/smccc.h | 6 ++++++ 5 files changed, 78 insertions(+), 1 deletion(-)xen/arch/arm/Kconfig +5
-0@@ -73,6 +73,16 @@ config SBSA_VUART_CONSOLE Allows a guest to use SBSA Generic UART as a console. The SBSA Generic UART implements a subset of ARM PL011 UART. +config ARM_SSBD + bool "Speculative Store Bypass Disable" if EXPERT = "y" + depends on HAS_ALTERNATIVE + default y + help + This enables mitigation of bypassing of previous stores byspeculative
xen/arch/arm/Kconfig config SBSA_VUART_CONSOLE · line 82
Quoted 1 line
xen/arch/arm/Kconfig +1
-0+ loads.I would add a reference to spectre v4. What do you think of:
This enables the mitigation of Spectre v4 attacks based on bypassing of previous memory stores by speculative loads.
Quoted 7 lines
Quoted 3 lines
Well, the real name is SSBD (Speculative Store Bypass Disable). AFAIK, Spectre only refers to variant 1 and 2 so far. This one has no fancy name and the specifications is using SSBD.
Googling for Spectre Variant 4 returns twice as many results as Googling for Speculative Store Bypass Disable. It doesn't matter what is the official name for the security issue, I think we need to include a reference to the most common name for it.
"Speculative Store Bypass" is the agreed vendor-neutral name for the issue. This is why all the mitigation is SSBD, where the D on the end is Disable.
Google SP4 is a common name (but only covers one reporter of the issue), whereas Spectre has nothing to do with this issue, and is definitely wrong to use.
If in doubt, use SSB(D).
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 04/13] xen/arm: Add ARCH_WORKAROUND_2 probing
Quoted 55 lines · Andrew Cooper
Quoted 42 lines · Stefano Stabellini
Quoted 41 lines · Julien Grall
Hi,
Quoted 38 lines · Stefano Stabellini
Quoted 32 lines · Julien Grall
As for Spectre variant-2, we rely on SMCCC 1.1 to provide the discovery mechanism for detecting the SSBD mitigation.
A new capability is also allocated for that purpose, and a config option.
This is part of XSA-263.
Signed-off-by Julien Grall <[email protected]>--- xen/arch/arm/Kconfig | 10 ++++++++++ xen/arch/arm/cpuerrata.c | 39 +++++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/cpuerrata.h | 21 +++++++++++++++++++++ xen/include/asm-arm/cpufeature.h | 3 ++- xen/include/asm-arm/smccc.h | 6 ++++++ 5 files changed, 78 insertions(+), 1 deletion(-)xen/arch/arm/Kconfig +5
-0@@ -73,6 +73,16 @@ config SBSA_VUART_CONSOLE Allows a guest to use SBSA Generic UART as a console. The SBSA Generic UART implements a subset of ARM PL011 UART. +config ARM_SSBD + bool "Speculative Store Bypass Disable" if EXPERT = "y" + depends on HAS_ALTERNATIVE + default y + help + This enables mitigation of bypassing of previous stores byspeculative
xen/arch/arm/Kconfig config SBSA_VUART_CONSOLE · line 82
Quoted 1 line
xen/arch/arm/Kconfig +1
-0+ loads.I would add a reference to spectre v4. What do you think of:
This enables the mitigation of Spectre v4 attacks based on bypassing of previous memory stores by speculative loads.
Quoted 7 lines
Quoted 3 lines
Well, the real name is SSBD (Speculative Store Bypass Disable). AFAIK, Spectre only refers to variant 1 and 2 so far. This one has no fancy name and the specifications is using SSBD.
Googling for Spectre Variant 4 returns twice as many results as Googling for Speculative Store Bypass Disable. It doesn't matter what is the official name for the security issue, I think we need to include a reference to the most common name for it.
"Speculative Store Bypass" is the agreed vendor-neutral name for the issue. This is why all the mitigation is SSBD, where the D on the end is Disable.
Quoted 5 lines
Google SP4 is a common name (but only covers one reporter of the issue), whereas Spectre has nothing to do with this issue, and is definitely wrong to use.
If in doubt, use SSB(D).
I think we should definitely call it SSBD, I was just saying that it might be helpful to include also "Variant 4" in the description, such as:
This is also known as Variant 4.
to help users find the right results on Google. Anyway, given that you are certainly better informed than me about it, I won't insist on this point, I am OK without mentioning "Variant 4".
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 04/13] xen/arm: Add ARCH_WORKAROUND_2 probing
Hi,
Quoted 62 lines · Stefano Stabellini
Quoted 55 lines · Andrew Cooper
Quoted 42 lines · Stefano Stabellini
Quoted 41 lines · Julien Grall
Hi,
Quoted 38 lines · Stefano Stabellini
Quoted 32 lines · Julien Grall
As for Spectre variant-2, we rely on SMCCC 1.1 to provide the discovery mechanism for detecting the SSBD mitigation.
A new capability is also allocated for that purpose, and a config option.
This is part of XSA-263.
Signed-off-by Julien Grall <[email protected]>--- xen/arch/arm/Kconfig | 10 ++++++++++ xen/arch/arm/cpuerrata.c | 39 +++++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/cpuerrata.h | 21 +++++++++++++++++++++ xen/include/asm-arm/cpufeature.h | 3 ++- xen/include/asm-arm/smccc.h | 6 ++++++ 5 files changed, 78 insertions(+), 1 deletion(-)xen/arch/arm/Kconfig +5
-0@@ -73,6 +73,16 @@ config SBSA_VUART_CONSOLE Allows a guest to use SBSA Generic UART as a console. The SBSA Generic UART implements a subset of ARM PL011 UART. +config ARM_SSBD + bool "Speculative Store Bypass Disable" if EXPERT = "y" + depends on HAS_ALTERNATIVE + default y + help + This enables mitigation of bypassing of previous stores byspeculative
xen/arch/arm/Kconfig config SBSA_VUART_CONSOLE · line 82
Quoted 1 line
xen/arch/arm/Kconfig +1
-0+ loads.I would add a reference to spectre v4. What do you think of:
This enables the mitigation of Spectre v4 attacks based on bypassing of previous memory stores by speculative loads.
Quoted 7 lines
Quoted 3 lines
Well, the real name is SSBD (Speculative Store Bypass Disable). AFAIK, Spectre only refers to variant 1 and 2 so far. This one has no fancy name and the specifications is using SSBD.
Googling for Spectre Variant 4 returns twice as many results as Googling for Speculative Store Bypass Disable. It doesn't matter what is the official name for the security issue, I think we need to include a reference to the most common name for it.
"Speculative Store Bypass" is the agreed vendor-neutral name for the issue. This is why all the mitigation is SSBD, where the D on the end is Disable.
Quoted 5 lines
Google SP4 is a common name (but only covers one reporter of the issue), whereas Spectre has nothing to do with this issue, and is definitely wrong to use.
If in doubt, use SSB(D).
Quoted 7 lines
I think we should definitely call it SSBD, I was just saying that it might be helpful to include also "Variant 4" in the description, such as:
This is also known as Variant 4.
to help users find the right results on Google.
There are enough hit with "Speculative Store Bypass Disable" for a user to find what's going on.
Quoted 3 lines
Anyway, given that you
are certainly better informed than me about it, I won't insist on this point, I am OK without mentioning "Variant 4".
I would prefer to not mention it in the Kconfig.
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 5/13 xen/arm: Add command line option to control SSBD mitigation
In reply to Julien GrallOn a system where the firmware implements ARCH_WORKAROUND_2, it may be useful to either permanently enable or disable the workaround for cases where the user decides that they'd rather not get a trap overhead, and keep the mitigation permanently on or off instead of switching it on exception entry/exit.
In any case, default to mitigation being enabled.
At the same time provide a accessor to know the state of the mitigation.
--- docs/misc/xen-command-line.markdown | 18 ++++++ xen/arch/arm/cpuerrata.c | 115 ++++++++++++++++++++++++++++++++---- xen/include/asm-arm/cpuerrata.h | 21 +++++++ xen/include/asm-arm/smccc.h | 1 + 4 files changed, 144 insertions(+), 11 deletions(-)
docs/misc/xen-command-line.markdown +18 -0
@@ -1756,6 +1756,24 @@ enforces the maximum theoretically necessary timeout of 670ms. Any number is being interpreted as a custom timeout in milliseconds. Zero or boolean false disable the quirk workaround, which is also the default. +### spec-ctrl (Arm) +> `= List of [ ssbd=force-disable|runtime|force-enable ]` + +Controls for speculative execution sidechannel mitigations. + +The option `ssbd=` is used to control the state of Speculative Store +Bypass Disable (SSBD) mitigation. + +* `ssbd=force-disable` will keep the mitigation permanently off. The guest +will not be able to control the state of the mitigation. +* `ssbd=runtime` will always turn on the mitigation when running in the +hypervisor context. The guest will be to turn on/off the mitigation for +itself by using the firmware interface ARCH\_WORKAROUND\_2. +* `ssbd=force-enable` will keep the mitigation permanently on. The guest will +not be able to control the state of the mitigation. + +By default SSBD will be mitigated at runtime (i.e `ssbd=runtime`). + ### spec-ctrl (x86) > `= List of [ <bool>, xen=<bool>, {pv,hvm,msr-sc,rsb}=<bool>, > bti-thunk=retpoline|lfence|jmp, {ibrs,ibpb,ssbd}=<bool> ]`
xen/arch/arm/cpuerrata.c +104 -11
141 lines not on this page · raw message
xen/include/asm-arm/cpuerrata.h +21 -0
@@ -31,10 +31,26 @@ CHECK_WORKAROUND_HELPER(ssbd, ARM_SSBD, CONFIG_ARM_SSBD)#undef CHECK_WORKAROUND_HELPER +enum ssbd_state +{ +ARM_SSBD_UNKNOWN , +ARM_SSBD_FORCE_DISABLE , +ARM_SSBD_RUNTIME , +ARM_SSBD_FORCE_ENABLE , +ARM_SSBD_MITIGATED , +}; +#ifdef CONFIG_ARM_SSBD #include <asm/current.h> +extern enum ssbd_state ssbd_state; + +static inline enum ssbd_state get_ssbd_state (void ) +{ +return ssbd_state; +} +DECLARE_PER_CPU (register_t, ssbd_callback_required);static inline bool cpu_require_ssbd_mitigation (void )
@@ -49,6 +65,11 @@ static inline bool cpu_require_ssbd_mitigation(void)return false; } +static inline enum ssbd_state get_sbdd_state (void ) +{ +return ARM_SSBD_UNKNOWN ; +} +#endif #endif /* __ARM_CPUERRATA_H__ */
xen/include/asm-arm/smccc.h +1 -0
@@ -265,6 +265,7 @@ struct arm_smccc_res { 0x7FFF)/* SMCCC error codes */ +#define ARM_SMCCC_NOT_REQUIRED (-2)#define ARM_SMCCC_ERR_UNKNOWN_FUNCTION (-1)#define ARM_SMCCC_NOT_SUPPORTED (-1)#define ARM_SMCCC_SUCCESS (0)
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 05/13] xen/arm: Add command line option to control SSBD mitigation
Quoted 23 lines · Julien Grall
On a system where the firmware implements
ARCH_WORKAROUND_2, it may be useful to either permanently enable or disable the workaround for cases where the user decides that they'd rather not get a trap overhead, and keep the mitigation permanently on or off instead of switching it on exception entry/exit.In any case, default to mitigation being enabled.
At the same time provide a accessor to know the state of the mitigation.
Signed-off-by Julien Grall <[email protected]>--- docs/misc/xen-command-line.markdown | 18 ++++++ xen/arch/arm/cpuerrata.c | 115 ++++++++++++++++++++++++++++++++---- xen/include/asm-arm/cpuerrata.h | 21 +++++++ xen/include/asm-arm/smccc.h | 1 + 4 files changed, 144 insertions(+), 11 deletions(-)docs/misc/xen-command-line.markdown +0
-0
docs/misc/xen-command-line.markdown enforces the maximum theoretically necessary timeout of 670ms. Any number · line 1760
Quoted 5 lines
docs/misc/xen-command-line.markdown +2
-0@@ -1756,6 +1756,24 @@ enforces the maximum theoretically necessary timeout of 670ms. Any number is being interpreted as a custom timeout in milliseconds. Zero or boolean false disable the quirk workaround, which is also the default. +### spec-ctrl (Arm) +> `= List of [ ssbd=force-disable|runtime|force-enable ]`
Why a list? Shouldn't it be one or the other?
Quoted 27 lines
docs/misc/xen-command-line.markdown +15
-0+Controls for speculative execution sidechannel mitigations. + +The option `ssbd=` is used to control the state of Speculative Store +Bypass Disable (SSBD) mitigation. + +* `ssbd=force-disable` will keep the mitigation permanently off. The guest +will not be able to control the state of the mitigation. +* `ssbd=runtime` will always turn on the mitigation when running in the +hypervisor context. The guest will be to turn on/off the mitigation for +itself by using the firmware interface ARCH\_WORKAROUND\_2. +* `ssbd=force-enable` will keep the mitigation permanently on. The guest will +not be able to control the state of the mitigation. + +By default SSBD will be mitigated at runtime (i.e `ssbd=runtime`). + ### spec-ctrl (x86) > `= List of [ <bool>, xen=<bool>, {pv,hvm,msr-sc,rsb}=<bool>, > bti-thunk=retpoline|lfence|jmp, {ibrs,ibpb,ssbd}=<bool> ]`xen/arch/arm/cpuerrata.c +1
-0@@ -237,6 +237,41 @@ static int enable_ic_inv_hardening(void *data)#ifdef CONFIG_ARM_SSBD +enum ssbd_state ssbd_state =ARM_SSBD_RUNTIME ;
xen/arch/arm/cpuerrata.c static int enable_ic_inv_hardening(void *data) · line 250
Quoted 10 lines
xen/arch/arm/cpuerrata.c +10
-0+ +static int __init parse_spec_ctrl (const char *s) +{ +const char *ss; +int rc =0 ; + + do { + ss = strchr(s, ','); + if ( !ss ) + ss = strchr(s, '\0');
It doesn't look like it is necessary to parse ',' at all. I would remove the while loop too.
Quoted 27 lines
xen/arch/arm/cpuerrata.c +23
-0+if ( !strncmp (s,"ssbd=" ,5 ) ) + { + s +=5 ; + +if ( !strncmp (s,"force-disable" , ss - s) ) + ssbd_state =ARM_SSBD_FORCE_DISABLE ; +else if ( !strncmp (s,"runtime" , ss - s) ) + ssbd_state =ARM_SSBD_RUNTIME ; +else if ( !strncmp (s,"force-enable" , ss - s) ) + ssbd_state =ARM_SSBD_FORCE_ENABLE ; +else + rc = -EINVAL ; + } +else + rc = -EINVAL ; + + s = ss +1 ; + }while ( *ss ); + +return rc; +} +custom_param ("spec-ctrl" , parse_spec_ctrl); +/* * Assembly code may use the variable directly, so we need to make sure * it fits in a register.
xen/arch/arm/cpuerrata.c DEFINE_PER_CPU_READ_MOSTLY(register_t, ssbd_callback_required); · line 284
Quoted 5 lines
xen/arch/arm/cpuerrata.c +1
-1@@ -246,25 +281,82 @@ DEFINE_PER_CPU_READ_MOSTLY(register_t, ssbd_callback_required);static bool has_ssbd_mitigation (const struct arm_cpu_capabilities *entry) {struct arm_smccc_res res; -bool supported = true; +bool required = true;
Please avoid this renaming. Choose one name or the other from the start.
xen/arch/arm/cpuerrata.c DEFINE_PER_CPU_READ_MOSTLY(register_t, ssbd_callback_required); · line 258
Quoted 8 lines
xen/arch/arm/cpuerrata.c +0
-5if ( smccc_ver <SMCCC_VERSION (1 ,1 ) )return false; -/* -* The probe function return value is either negative (unsupported -* or mitigated), positive (unaffected), or zero (requires -* mitigation). We only need to do anything in the last case. -*/
I would keep the comment
xen/arch/arm/cpuerrata.c DEFINE_PER_CPU_READ_MOSTLY(register_t, ssbd_callback_required); · line 292
Quoted 8 lines
xen/arch/arm/cpuerrata.c +1
-4arm_smccc_1_1_smc (ARM_SMCCC_ARCH_FEATURES_FID ,ARM_SMCCC_ARCH_WORKAROUND_2_FID , &res); -if ( (int )res.a0 !=0 ) - supported = false; -if ( supported ) -this_cpu (ssbd_callback_required) =1 ; + switch ( (int)res.a0 )
Please introduce this switch in the previous patch. But it makes sense to add the ssbd_state variable in this patch.
Quoted 6 lines
xen/arch/arm/cpuerrata.c +6
-0+ { +case ARM_SMCCC_NOT_SUPPORTED : + ssbd_state =ARM_SSBD_UNKNOWN ; +return false; + +case ARM_SMCCC_NOT_REQUIRED :
xen/arch/arm/cpuerrata.c DEFINE_PER_CPU_READ_MOSTLY(register_t, ssbd_callback_required); · line 308
Quoted 10 lines
xen/arch/arm/cpuerrata.c +10
-0+ ssbd_state =ARM_SSBD_MITIGATED ; +return false; + +case ARM_SMCCC_SUCCESS : + required = true; +break ; + +case 1 :/* Mitigation not required on this CPU. */ + required = false; +break ;
This should "return false". Also, it might make sense to set ssbd_state to ARM_SSBD_MITIGATED?
Quoted 16 lines
xen/arch/arm/cpuerrata.c +16
-0+ +default : +ASSERT_UNREACHABLE (); +return false; + } + +switch ( ssbd_state ) + { +case ARM_SSBD_FORCE_DISABLE : + { +static bool once = true; + +if ( once ) +printk ("%s disabled from command-line\n" , entry->desc); + once = false; +
xen/arch/arm/cpuerrata.c DEFINE_PER_CPU_READ_MOSTLY(register_t, ssbd_callback_required); · line 334
Quoted 10 lines
xen/arch/arm/cpuerrata.c +10
-0+arm_smccc_1_1_smc (ARM_SMCCC_ARCH_WORKAROUND_2_FID ,0 ,NULL ); + required = false; + +break ; + } + +case ARM_SSBD_RUNTIME : +if ( required ) + { +this_cpu (ssbd_callback_required) =1 ;
We have the ARM_SSBD bit, the ssbd_state variable and ssbd_callback_required. Both ARM_SSBD and ssbd_state are shared across cores while ssbd_callback_required is per-cpu. Does ssbd_callback_required really need to be per-cpu? Do we need both variables? For instance, we could just return ssbd_state == ARM_SSBD_RUNTIME instead of this_cpu(ssbd_callback_required)?
Quoted 5 lines
xen/arch/arm/cpuerrata.c +5
-0+arm_smccc_1_1_smc (ARM_SMCCC_ARCH_WORKAROUND_2_FID ,1 ,NULL ); + } + +break ; +
xen/arch/arm/cpuerrata.c DEFINE_PER_CPU_READ_MOSTLY(register_t, ssbd_callback_required); · line 349
Quoted 10 lines
xen/arch/arm/cpuerrata.c +10
-0+case ARM_SSBD_FORCE_ENABLE : + { +static bool once = true; + +if ( once ) +printk ("%s forced from command-line\n" , entry->desc); + once = false; + +arm_smccc_1_1_smc (ARM_SMCCC_ARCH_WORKAROUND_2_FID ,1 ,NULL ); + required = true;
This function is supposed to detect whether a workaround is needed, not enable it, right? Should this switch and relative code be moved to the .enable function for this capability?
Quoted 79 lines
xen/arch/arm/cpuerrata.c +9
-1+ break; + } + +default : +ASSERT_UNREACHABLE (); +return false; + } - return supported; +return required; }#endif @@ -371,6 +463,7 @@ static const struct arm_cpu_capabilities arm_errata[] = {#endif #ifdef CONFIG_ARM_SSBD { + .desc = "Speculative Store Bypass Disabled", .capability = ARM_SSBD, .matches = has_ssbd_mitigation, },xen/include/asm-arm/cpuerrata.h +21
-0@@ -31,10 +31,26 @@ CHECK_WORKAROUND_HELPER(ssbd, ARM_SSBD, CONFIG_ARM_SSBD)#undef CHECK_WORKAROUND_HELPER +enum ssbd_state +{ +ARM_SSBD_UNKNOWN , +ARM_SSBD_FORCE_DISABLE , +ARM_SSBD_RUNTIME , +ARM_SSBD_FORCE_ENABLE , +ARM_SSBD_MITIGATED , +}; +#ifdef CONFIG_ARM_SSBD #include <asm/current.h> +extern enum ssbd_state ssbd_state; + +static inline enum ssbd_state get_ssbd_state (void ) +{ +return ssbd_state; +} +DECLARE_PER_CPU (register_t, ssbd_callback_required);static inline bool cpu_require_ssbd_mitigation (void )@@ -49,6 +65,11 @@ static inline bool cpu_require_ssbd_mitigation(void)return false; } +static inline enum ssbd_state get_sbdd_state (void ) +{ +return ARM_SSBD_UNKNOWN ; +} +#endif #endif /* __ARM_CPUERRATA_H__ */ xen/include/asm-arm/smccc.h +1
-0@@ -265,6 +265,7 @@ struct arm_smccc_res { 0x7FFF)/* SMCCC error codes */ +#define ARM_SMCCC_NOT_REQUIRED (-2)#define ARM_SMCCC_ERR_UNKNOWN_FUNCTION (-1)#define ARM_SMCCC_NOT_SUPPORTED (-1)#define ARM_SMCCC_SUCCESS (0)Signature · 1 line
2.11.0
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 05/13] xen/arm: Add command line option to control SSBD mitigation
Quoted 181 lines · Stefano Stabellini
Quoted 23 lines · Julien Grall
On a system where the firmware implements
ARCH_WORKAROUND_2, it may be useful to either permanently enable or disable the workaround for cases where the user decides that they'd rather not get a trap overhead, and keep the mitigation permanently on or off instead of switching it on exception entry/exit.In any case, default to mitigation being enabled.
At the same time provide a accessor to know the state of the mitigation.
Signed-off-by Julien Grall <[email protected]>--- docs/misc/xen-command-line.markdown | 18 ++++++ xen/arch/arm/cpuerrata.c | 115 ++++++++++++++++++++++++++++++++---- xen/include/asm-arm/cpuerrata.h | 21 +++++++ xen/include/asm-arm/smccc.h | 1 + 4 files changed, 144 insertions(+), 11 deletions(-)docs/misc/xen-command-line.markdown +0
-0docs/misc/xen-command-line.markdown enforces the maximum theoretically necessary timeout of 670ms. Any number · line 1760
Quoted 5 lines
docs/misc/xen-command-line.markdown +2
-0@@ -1756,6 +1756,24 @@ enforces the maximum theoretically necessary timeout of 670ms. Any number is being interpreted as a custom timeout in milliseconds. Zero or boolean false disable the quirk workaround, which is also the default. +### spec-ctrl (Arm) +> `= List of [ ssbd=force-disable|runtime|force-enable ]`Why a list? Shouldn't it be one or the other?
Quoted 27 lines
docs/misc/xen-command-line.markdown +15
-0+Controls for speculative execution sidechannel mitigations. + +The option `ssbd=` is used to control the state of Speculative Store +Bypass Disable (SSBD) mitigation. + +* `ssbd=force-disable` will keep the mitigation permanently off. The guest +will not be able to control the state of the mitigation. +* `ssbd=runtime` will always turn on the mitigation when running in the +hypervisor context. The guest will be to turn on/off the mitigation for +itself by using the firmware interface ARCH\_WORKAROUND\_2. +* `ssbd=force-enable` will keep the mitigation permanently on. The guest will +not be able to control the state of the mitigation. + +By default SSBD will be mitigated at runtime (i.e `ssbd=runtime`). + ### spec-ctrl (x86) > `= List of [ <bool>, xen=<bool>, {pv,hvm,msr-sc,rsb}=<bool>, > bti-thunk=retpoline|lfence|jmp, {ibrs,ibpb,ssbd}=<bool> ]`xen/arch/arm/cpuerrata.c +1
-0@@ -237,6 +237,41 @@ static int enable_ic_inv_hardening(void *data)#ifdef CONFIG_ARM_SSBD +enum ssbd_state ssbd_state =ARM_SSBD_RUNTIME ;xen/arch/arm/cpuerrata.c static int enable_ic_inv_hardening(void *data) · line 250
Quoted 10 lines
xen/arch/arm/cpuerrata.c +10
-0+ +static int __init parse_spec_ctrl (const char *s) +{ +const char *ss; +int rc =0 ; + + do { + ss = strchr(s, ','); + if ( !ss ) + ss = strchr(s, '\0');It doesn't look like it is necessary to parse ',' at all. I would remove the while loop too.
Quoted 27 lines
xen/arch/arm/cpuerrata.c +23
-0+if ( !strncmp (s,"ssbd=" ,5 ) ) + { + s +=5 ; + +if ( !strncmp (s,"force-disable" , ss - s) ) + ssbd_state =ARM_SSBD_FORCE_DISABLE ; +else if ( !strncmp (s,"runtime" , ss - s) ) + ssbd_state =ARM_SSBD_RUNTIME ; +else if ( !strncmp (s,"force-enable" , ss - s) ) + ssbd_state =ARM_SSBD_FORCE_ENABLE ; +else + rc = -EINVAL ; + } +else + rc = -EINVAL ; + + s = ss +1 ; + }while ( *ss ); + +return rc; +} +custom_param ("spec-ctrl" , parse_spec_ctrl); +/* * Assembly code may use the variable directly, so we need to make sure * it fits in a register. xen/arch/arm/cpuerrata.c DEFINE_PER_CPU_READ_MOSTLY(register_t, ssbd_callback_required); · line 284
Quoted 5 lines
xen/arch/arm/cpuerrata.c +1
-1@@ -246,25 +281,82 @@ DEFINE_PER_CPU_READ_MOSTLY(register_t, ssbd_callback_required);static bool has_ssbd_mitigation (const struct arm_cpu_capabilities *entry) {struct arm_smccc_res res; -bool supported = true; +bool required = true;Please avoid this renaming. Choose one name or the other from the start.
xen/arch/arm/cpuerrata.c DEFINE_PER_CPU_READ_MOSTLY(register_t, ssbd_callback_required); · line 258
Quoted 8 lines
xen/arch/arm/cpuerrata.c +0
-5if ( smccc_ver <SMCCC_VERSION (1 ,1 ) )return false; -/* -* The probe function return value is either negative (unsupported -* or mitigated), positive (unaffected), or zero (requires -* mitigation). We only need to do anything in the last case. -*/ I would keep the comment
xen/arch/arm/cpuerrata.c DEFINE_PER_CPU_READ_MOSTLY(register_t, ssbd_callback_required); · line 292
Quoted 8 lines
xen/arch/arm/cpuerrata.c +1
-4arm_smccc_1_1_smc (ARM_SMCCC_ARCH_FEATURES_FID ,ARM_SMCCC_ARCH_WORKAROUND_2_FID , &res); -if ( (int )res.a0 !=0 ) - supported = false; -if ( supported ) -this_cpu (ssbd_callback_required) =1 ; + switch ( (int)res.a0 )Please introduce this switch in the previous patch. But it makes sense to add the
ssbd_statevariable in this patch.Quoted 6 lines
xen/arch/arm/cpuerrata.c +6
-0+ { +case ARM_SMCCC_NOT_SUPPORTED : + ssbd_state =ARM_SSBD_UNKNOWN ; +return false; + +case ARM_SMCCC_NOT_REQUIRED :xen/arch/arm/cpuerrata.c DEFINE_PER_CPU_READ_MOSTLY(register_t, ssbd_callback_required); · line 308
Quoted 10 lines
xen/arch/arm/cpuerrata.c +10
-0+ ssbd_state =ARM_SSBD_MITIGATED ; +return false; + +case ARM_SMCCC_SUCCESS : + required = true; +break ; + +case 1 :/* Mitigation not required on this CPU. */ + required = false; +break ;This should "return false". Also, it might make sense to set
ssbd_statetoARM_SSBD_MITIGATED?Quoted 25 lines
xen/arch/arm/cpuerrata.c +25
-0+ +default : +ASSERT_UNREACHABLE (); +return false; + } + +switch ( ssbd_state ) + { +case ARM_SSBD_FORCE_DISABLE : + { +static bool once = true; + +if ( once ) +printk ("%s disabled from command-line\n" , entry->desc); + once = false; + +arm_smccc_1_1_smc (ARM_SMCCC_ARCH_WORKAROUND_2_FID ,0 ,NULL ); + required = false; + +break ; + } + +case ARM_SSBD_RUNTIME : +if ( required ) + {
Quoted 8 lines
xen/arch/arm/cpuerrata.c DEFINE_PER_CPU_READ_MOSTLY(register_t, ssbd_callback_required); · line 334
Quoted 1 line
xen/arch/arm/cpuerrata.c +1
-0+this_cpu (ssbd_callback_required) =1 ;We have the
ARM_SSBDbit, thessbd_statevariable andssbd_callback_required. BothARM_SSBDandssbd_stateare shared across cores whilessbd_callback_requiredis per-cpu. Doesssbd_callback_requiredreally need to be per-cpu? Do we need both variables? For instance, we could just returnssbd_state==ARM_SSBD_RUNTIMEinstead ofthis_cpu(ssbd_callback_required)?
After reading the whole series, I think ssbd_state should be a per_cpu variable. parse_spec_ctrl initializes ssbd_state to the same value on all cpus. has_ssbd_mitigation modifies ssbd_state only on the CPUs it is running on. We get rid of ssbd_callback_required. The assembly fast past reads ssbd_state instead of ssbd_callback_required.
What do you think?
Quoted 92 lines
Quoted 5 lines
xen/arch/arm/cpuerrata.c +5
-0+arm_smccc_1_1_smc (ARM_SMCCC_ARCH_WORKAROUND_2_FID ,1 ,NULL ); + } + +break ; +xen/arch/arm/cpuerrata.c DEFINE_PER_CPU_READ_MOSTLY(register_t, ssbd_callback_required); · line 349
Quoted 10 lines
xen/arch/arm/cpuerrata.c +10
-0+case ARM_SSBD_FORCE_ENABLE : + { +static bool once = true; + +if ( once ) +printk ("%s forced from command-line\n" , entry->desc); + once = false; + +arm_smccc_1_1_smc (ARM_SMCCC_ARCH_WORKAROUND_2_FID ,1 ,NULL ); + required = true;This function is supposed to detect whether a workaround is needed, not enable it, right? Should this switch and relative code be moved to the .enable function for this capability?
Quoted 71 lines
xen/arch/arm/cpuerrata.c +9
-1+ break; + } + +default : +ASSERT_UNREACHABLE (); +return false; + } - return supported; +return required; }#endif @@ -371,6 +463,7 @@ static const struct arm_cpu_capabilities arm_errata[] = {#endif #ifdef CONFIG_ARM_SSBD { + .desc = "Speculative Store Bypass Disabled", .capability = ARM_SSBD, .matches = has_ssbd_mitigation, },xen/include/asm-arm/cpuerrata.h +21
-0@@ -31,10 +31,26 @@ CHECK_WORKAROUND_HELPER(ssbd, ARM_SSBD, CONFIG_ARM_SSBD)#undef CHECK_WORKAROUND_HELPER +enum ssbd_state +{ +ARM_SSBD_UNKNOWN , +ARM_SSBD_FORCE_DISABLE , +ARM_SSBD_RUNTIME , +ARM_SSBD_FORCE_ENABLE , +ARM_SSBD_MITIGATED , +}; +#ifdef CONFIG_ARM_SSBD #include <asm/current.h> +extern enum ssbd_state ssbd_state; + +static inline enum ssbd_state get_ssbd_state (void ) +{ +return ssbd_state; +} +DECLARE_PER_CPU (register_t, ssbd_callback_required);static inline bool cpu_require_ssbd_mitigation (void )@@ -49,6 +65,11 @@ static inline bool cpu_require_ssbd_mitigation(void)return false; } +static inline enum ssbd_state get_sbdd_state (void ) +{ +return ARM_SSBD_UNKNOWN ; +} +#endif #endif /* __ARM_CPUERRATA_H__ */ xen/include/asm-arm/smccc.h +0
-0@@ -265,6 +265,7 @@ struct arm_smccc_res { 0x7FFF)
Quoted 9 lines
Quoted 8 lines
xen/include/asm-arm/smccc.h +1
-0/* SMCCC error codes */ +#define ARM_SMCCC_NOT_REQUIRED (-2)#define ARM_SMCCC_ERR_UNKNOWN_FUNCTION (-1)#define ARM_SMCCC_NOT_SUPPORTED (-1)#define ARM_SMCCC_SUCCESS (0)Signature · 1 line
2.11.0
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 05/13] xen/arm: Add command line option to control SSBD mitigation
Hi Stefano,
Quoted 36 lines · Stefano Stabellini
Quoted 26 lines · Stefano Stabellini
Quoted 25 lines · Julien Grall
xen/arch/arm/cpuerrata.c +25
-0+ +default : +ASSERT_UNREACHABLE (); +return false; + } + +switch ( ssbd_state ) + { +case ARM_SSBD_FORCE_DISABLE : + { +static bool once = true; + +if ( once ) +printk ("%s disabled from command-line\n" , entry->desc); + once = false; + +arm_smccc_1_1_smc (ARM_SMCCC_ARCH_WORKAROUND_2_FID ,0 ,NULL ); + required = false; + +break ; + } + +case ARM_SSBD_RUNTIME : +if ( required ) + {Quoted 8 lines
Quoted 1 line
+
this_cpu(ssbd_callback_required)= 1;We have the
ARM_SSBDbit, thessbd_statevariable andssbd_callback_required. BothARM_SSBDandssbd_stateare shared across cores whilessbd_callback_requiredis per-cpu. Doesssbd_callback_requiredreally need to be per-cpu? Do we need both variables? For instance, we could just returnssbd_state==ARM_SSBD_RUNTIMEinstead ofthis_cpu(ssbd_callback_required)?
Quoted 7 lines
After reading the whole series, I think
ssbd_stateshould be aper_cpuvariable.parse_spec_ctrlinitializesssbd_stateto the same value on all cpus.has_ssbd_mitigationmodifiesssbd_stateonly on the CPUs it is running on. We get rid ofssbd_callback_required. The assembly fast past readsssbd_stateinstead ofssbd_callback_required.What do you think?
We need to keep the global ssbd_state around for the vsmc code as we need to tell the guest what is the system-wide decision.
This is because a vCPU may move from a affected CPU to a non-affected one. So we need to inform the same on every vCPU (i.e mitigated, dynamic...).
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 05/13] xen/arm: Add command line option to control SSBD mitigation
In reply to Stefano StabelliniHi Stefano,
Quoted 27 lines · Stefano Stabellini
Quoted 26 lines · Julien Grall
On a system where the firmware implements
ARCH_WORKAROUND_2, it may be useful to either permanently enable or disable the workaround for cases where the user decides that they'd rather not get a trap overhead, and keep the mitigation permanently on or off instead of switching it on exception entry/exit.In any case, default to mitigation being enabled.
At the same time provide a accessor to know the state of the mitigation.
Signed-off-by Julien Grall <[email protected]>--- docs/misc/xen-command-line.markdown | 18 ++++++ xen/arch/arm/cpuerrata.c | 115 ++++++++++++++++++++++++++++++++---- xen/include/asm-arm/cpuerrata.h | 21 +++++++ xen/include/asm-arm/smccc.h | 1 + 4 files changed, 144 insertions(+), 11 deletions(-)docs/misc/xen-command-line.markdown +0
-0@@ -1756,6 +1756,24 @@ enforces the maximum theoretically necessary timeout of 670ms. Any number is being interpreted as a custom timeout in milliseconds. Zero or boolean false disable the quirk workaround, which is also the default.
Quoted 4 lines
docs/misc/xen-command-line.markdown enforces the maximum theoretically necessary timeout of 670ms. Any number · line 1760
Quoted 2 lines
docs/misc/xen-command-line.markdown +2
-0+### spec-ctrl (Arm) +> `= List of [ ssbd=force-disable|runtime|force-enable ]`Why a list? Shouldn't it be one or the other?
Because I am thinking to extend it and add the possibility to disable branch predictor hardening. So I decided to get the code and documentation ready right now.
Quoted 27 lines
Quoted 27 lines
docs/misc/xen-command-line.markdown +15
-0+Controls for speculative execution sidechannel mitigations. + +The option `ssbd=` is used to control the state of Speculative Store +Bypass Disable (SSBD) mitigation. + +* `ssbd=force-disable` will keep the mitigation permanently off. The guest +will not be able to control the state of the mitigation. +* `ssbd=runtime` will always turn on the mitigation when running in the +hypervisor context. The guest will be to turn on/off the mitigation for +itself by using the firmware interface ARCH\_WORKAROUND\_2. +* `ssbd=force-enable` will keep the mitigation permanently on. The guest will +not be able to control the state of the mitigation. + +By default SSBD will be mitigated at runtime (i.e `ssbd=runtime`). + ### spec-ctrl (x86) > `= List of [ <bool>, xen=<bool>, {pv,hvm,msr-sc,rsb}=<bool>, > bti-thunk=retpoline|lfence|jmp, {ibrs,ibpb,ssbd}=<bool> ]`xen/arch/arm/cpuerrata.c +0
-0@@ -237,6 +237,41 @@ static int enable_ic_inv_hardening(void *data)#ifdef CONFIG_ARM_SSBD
Quoted 14 lines
xen/arch/arm/cpuerrata.c static int enable_ic_inv_hardening(void *data) · line 250
Quoted 11 lines
xen/arch/arm/cpuerrata.c +11
-0+enum ssbd_state ssbd_state =ARM_SSBD_RUNTIME ; + +static int __init parse_spec_ctrl (const char *s) +{ +const char *ss; +int rc =0 ; + + do { + ss = strchr(s, ','); + if ( !ss ) + ss = strchr(s, '\0');It doesn't look like it is necessary to parse ',' at all. I would remove the while loop too.
It matters, you want to catch and warn user that the command line is not valid. Imagine someone decide to add ",..." after. It also make easier to integrate new option without reworking it.
Quoted 28 lines
Quoted 28 lines
xen/arch/arm/cpuerrata.c +23
-0+if ( !strncmp (s,"ssbd=" ,5 ) ) + { + s +=5 ; + +if ( !strncmp (s,"force-disable" , ss - s) ) + ssbd_state =ARM_SSBD_FORCE_DISABLE ; +else if ( !strncmp (s,"runtime" , ss - s) ) + ssbd_state =ARM_SSBD_RUNTIME ; +else if ( !strncmp (s,"force-enable" , ss - s) ) + ssbd_state =ARM_SSBD_FORCE_ENABLE ; +else + rc = -EINVAL ; + } +else + rc = -EINVAL ; + + s = ss +1 ; + }while ( *ss ); + +return rc; +} +custom_param ("spec-ctrl" , parse_spec_ctrl); +/* * Assembly code may use the variable directly, so we need to make sure * it fits in a register.
Quoted 8 lines
xen/arch/arm/cpuerrata.c DEFINE_PER_CPU_READ_MOSTLY(register_t, ssbd_callback_required); · line 284
Quoted 6 lines
xen/arch/arm/cpuerrata.c +1
-1@@ -246,25 +281,82 @@ DEFINE_PER_CPU_READ_MOSTLY(register_t, ssbd_callback_required);static bool has_ssbd_mitigation (const struct arm_cpu_capabilities *entry) {struct arm_smccc_res res; -bool supported = true; +bool required = true;Please avoid this renaming. Choose one name or the other from the start.
This is what happen when you want to split a series in a logical way. The name "required" does not make sense with the previous patch. So the renaming make sense here.
Quoted 5 lines
Quoted 5 lines
xen/arch/arm/cpuerrata.c +0
-0if ( smccc_ver <SMCCC_VERSION (1 ,1 ) )return false;
Quoted 7 lines
xen/arch/arm/cpuerrata.c DEFINE_PER_CPU_READ_MOSTLY(register_t, ssbd_callback_required); · line 258
Quoted 5 lines
xen/arch/arm/cpuerrata.c +0
-5-/* -* The probe function return value is either negative (unsupported -* or mitigated), positive (unaffected), or zero (requires -* mitigation). We only need to do anything in the last case. -*/ I would keep the comment
The comment is not correct after this patch. The may need to act differently depending on the comment line. Regarding the values, the switch is more explanatory than those 3 lines.
Quoted 7 lines
Quoted 7 lines
xen/arch/arm/cpuerrata.c +0
-2arm_smccc_1_1_smc (ARM_SMCCC_ARCH_FEATURES_FID ,ARM_SMCCC_ARCH_WORKAROUND_2_FID , &res); -if ( (int )res.a0 !=0 ) - supported = false;
Quoted 6 lines
xen/arch/arm/cpuerrata.c DEFINE_PER_CPU_READ_MOSTLY(register_t, ssbd_callback_required); · line 292
Quoted 3 lines
xen/arch/arm/cpuerrata.c +1
-2-if ( supported ) -this_cpu (ssbd_callback_required) =1 ; + switch ( (int)res.a0 )Please introduce this switch in the previous patch. But it makes sense to add the
ssbd_statevariable in this patch.
Well, that's not going to make the diff simpler here as the switch will be different. So I would keep the patch like that.
Quoted 12 lines
Quoted 12 lines
xen/arch/arm/cpuerrata.c +10
-0+ { +case ARM_SMCCC_NOT_SUPPORTED : + ssbd_state =ARM_SSBD_UNKNOWN ; +return false; + +case ARM_SMCCC_NOT_REQUIRED : + ssbd_state =ARM_SSBD_MITIGATED ; +return false; + +case ARM_SMCCC_SUCCESS :
Quoted 8 lines
xen/arch/arm/cpuerrata.c DEFINE_PER_CPU_READ_MOSTLY(register_t, ssbd_callback_required); · line 308
Quoted 6 lines
xen/arch/arm/cpuerrata.c +6
-0+ required = true; +break ; + +case 1 :/* Mitigation not required on this CPU. */ + required = false; +break ;This should "return false".
It is perfectly fine to continue as it is safe to execute ARCH_WORKAROUND_2 on that CPU.
Also, it might make sense to set ssbd_state
Quoted 1 line
to
ARM_SSBD_MITIGATED?
No, the mitigation is not required on *that* CPU. It does not mean it will not be required for all CPUs. So it makes sense to not update ssbd_state.
Quoted 27 lines
Quoted 27 lines
xen/arch/arm/cpuerrata.c +25
-0+ +default : +ASSERT_UNREACHABLE (); +return false; + } + +switch ( ssbd_state ) + { +case ARM_SSBD_FORCE_DISABLE : + { +static bool once = true; + +if ( once ) +printk ("%s disabled from command-line\n" , entry->desc); + once = false; + +arm_smccc_1_1_smc (ARM_SMCCC_ARCH_WORKAROUND_2_FID ,0 ,NULL ); + required = false; + +break ; + } + +case ARM_SSBD_RUNTIME : +if ( required ) + {
Quoted 8 lines
xen/arch/arm/cpuerrata.c DEFINE_PER_CPU_READ_MOSTLY(register_t, ssbd_callback_required); · line 334
Quoted 1 line
xen/arch/arm/cpuerrata.c +1
-0+this_cpu (ssbd_callback_required) =1 ;We have the
ARM_SSBDbit, thessbd_statevariable andssbd_callback_required. BothARM_SSBDandssbd_stateare shared across cores whilessbd_callback_requiredis per-cpu. Doesssbd_callback_requiredreally need to be per-cpu? > Do we need both variables? For instance, we could just returnssbd_state==ARM_SSBD_RUNTIMEinstead ofthis_cpu(ssbd_callback_required)?
Let me start with because a guest vCPU may run on any pCPU, you always have to tell the guest the mitigation is required for all vCPUs.
By default, Linux is calling the workaround at entry from EL0 to enable it and at exit to EL0 to disable it. The workaround will first trap in EL2 and then get forwarded to EL3.
You can imagine that the trap to EL2 and then EL3 has a cost. If the workaround is not necessary, then you can reduce that cost by avoiding to trap at EL3. As you can have a platform with heterogenous CPUs, you need that workaround per-CPU.
The ARM_SSBD feature bit is useful in order to put shortcut in place using alternative (see check_workaround_ssbd). So on platform where the mitigation is not required, all the new code is nearly a NOP.
The ssbd_state is used in various place to know what is the global state of the mitigation:
- To initialize the vCPU state for the mitigation
- To report the guest what is the state of the mitigation using SMCCC
So all those variables have a specific purposes and cannot really be replaced by another way.
Quoted 13 lines
Quoted 13 lines
xen/arch/arm/cpuerrata.c +11
-0+arm_smccc_1_1_smc (ARM_SMCCC_ARCH_WORKAROUND_2_FID ,1 ,NULL ); + } + +break ; + +case ARM_SSBD_FORCE_ENABLE : + { +static bool once = true; + +if ( once ) +printk ("%s forced from command-line\n" , entry->desc);
Quoted 8 lines
xen/arch/arm/cpuerrata.c DEFINE_PER_CPU_READ_MOSTLY(register_t, ssbd_callback_required); · line 349
Quoted 4 lines
xen/arch/arm/cpuerrata.c +4
-0+ once = false; + +arm_smccc_1_1_smc (ARM_SMCCC_ARCH_WORKAROUND_2_FID ,1 ,NULL ); + required = true;This function is supposed to detect whether a workaround is needed, not enable it, right? Should this switch and relative code be moved to the .enable function for this capability?
I had the split before but it is difficult to get a nice split between .enable and .matches. So I decided to follow what Linux/KVM did and put everything in has_.
Quoted 73 lines
Quoted 73 lines
xen/arch/arm/cpuerrata.c +9
-1+ break; + } + +default : +ASSERT_UNREACHABLE (); +return false; + } - return supported; +return required; }#endif @@ -371,6 +463,7 @@ static const struct arm_cpu_capabilities arm_errata[] = {#endif #ifdef CONFIG_ARM_SSBD { + .desc = "Speculative Store Bypass Disabled", .capability = ARM_SSBD, .matches = has_ssbd_mitigation, },xen/include/asm-arm/cpuerrata.h +21
-0@@ -31,10 +31,26 @@ CHECK_WORKAROUND_HELPER(ssbd, ARM_SSBD, CONFIG_ARM_SSBD)#undef CHECK_WORKAROUND_HELPER +enum ssbd_state +{ +ARM_SSBD_UNKNOWN , +ARM_SSBD_FORCE_DISABLE , +ARM_SSBD_RUNTIME , +ARM_SSBD_FORCE_ENABLE , +ARM_SSBD_MITIGATED , +}; +#ifdef CONFIG_ARM_SSBD #include <asm/current.h> +extern enum ssbd_state ssbd_state; + +static inline enum ssbd_state get_ssbd_state (void ) +{ +return ssbd_state; +} +DECLARE_PER_CPU (register_t, ssbd_callback_required);static inline bool cpu_require_ssbd_mitigation (void )@@ -49,6 +65,11 @@ static inline bool cpu_require_ssbd_mitigation(void)return false; } +static inline enum ssbd_state get_sbdd_state (void ) +{ +return ARM_SSBD_UNKNOWN ; +} +#endif #endif /* __ARM_CPUERRATA_H__ */ xen/include/asm-arm/smccc.h +0
-0@@ -265,6 +265,7 @@ struct arm_smccc_res { 0x7FFF)
Quoted 8 lines
Quoted 8 lines
xen/include/asm-arm/smccc.h +1
-0/* SMCCC error codes */ +#define ARM_SMCCC_NOT_REQUIRED (-2)#define ARM_SMCCC_ERR_UNKNOWN_FUNCTION (-1)#define ARM_SMCCC_NOT_SUPPORTED (-1)#define ARM_SMCCC_SUCCESS (0)Signature · 1 line
2.11.0
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 05/13] xen/arm: Add command line option to control SSBD mitigation
Quoted 38 lines · Julien Grall
Hi Stefano,
Quoted 20 lines · Stefano Stabellini
Quoted 19 lines · Julien Grall
On a system where the firmware implements
ARCH_WORKAROUND_2, it may be useful to either permanently enable or disable the workaround for cases where the user decides that they'd rather not get a trap overhead, and keep the mitigation permanently on or off instead of switching it on exception entry/exit.In any case, default to mitigation being enabled.
At the same time provide a accessor to know the state of the mitigation.
Signed-off-by Julien Grall <[email protected]>--- docs/misc/xen-command-line.markdown | 18 ++++++ xen/arch/arm/cpuerrata.c | 115 ++++++++++++++++++++++++++++++++---- xen/include/asm-arm/cpuerrata.h | 21 +++++++ xen/include/asm-arm/smccc.h | 1 + 4 files changed, 144 insertions(+), 11 deletions(-)Quoted 14 lines
Quoted 6 lines
docs/misc/xen-command-line.markdown +0
-0@@ -1756,6 +1756,24 @@ enforces the maximum theoretically necessaryQuoted 6 lines
timeout of 670ms. Any number
is being interpreted as a custom timeout in milliseconds. Zero or
boolean
false disable the quirk workaround, which is also the default. +### spec-ctrl (Arm)
+>= List of [ ssbd=force-disable|runtime|force-enable ]Why a list? Shouldn't it be one or the other?
Quoted 3 lines
Because I am thinking to extend it and add the possibility to disable branch predictor hardening. So I decided to get the code and documentation ready right now.
OK, maybe it would be good to explain this in the commit message but it is not necessary.
Quoted 42 lines
Quoted 33 lines
Quoted 33 lines
docs/misc/xen-command-line.markdown +6
-0+Controls for speculative execution sidechannel mitigations. + +The option `ssbd=` is used to control the state of Speculative Store +Bypass Disable (SSBD) mitigation. + +* `ssbd=force-disable` will keep the mitigation permanently off. Theguest
docs/misc/xen-command-line.markdown +5
-0+will not be able to control the state of the mitigation. +* `ssbd=runtime` will always turn on the mitigation when running in the +hypervisor context. The guest will be to turn on/off the mitigation for +itself by using the firmware interface ARCH\_WORKAROUND\_2. +* `ssbd=force-enable` will keep the mitigation permanently on. The guestwill
docs/misc/xen-command-line.markdown +4
-0+not be able to control the state of the mitigation. + +By default SSBD will be mitigated at runtime (i.e `ssbd=runtime`). + ### spec-ctrl (x86) > `= List of [ <bool>, xen=<bool>, {pv,hvm,msr-sc,rsb}=<bool>, > bti-thunk=retpoline|lfence|jmp, {ibrs,ibpb,ssbd}=<bool>]`
xen/arch/arm/cpuerrata.c +5
-0@@ -237,6 +237,41 @@ static int enable_ic_inv_hardening(void *data)#ifdef CONFIG_ARM_SSBD +enum ssbd_state ssbd_state = ARM_SSBD_RUNTIME; + +static int __init parse_spec_ctrl (const char *s) +{ +const char *ss; +int rc =0 ;Quoted 8 lines
xen/arch/arm/cpuerrata.c static int enable_ic_inv_hardening(void *data) · line 250
Quoted 5 lines
xen/arch/arm/cpuerrata.c +5
-0+ + do { + ss = strchr(s, ','); + if ( !ss ) + ss = strchr(s, '\0');It doesn't look like it is necessary to parse ',' at all. I would remove the while loop too.
Quoted 3 lines
It matters, you want to catch and warn user that the command line is not valid. Imagine someone decide to add ",..." after. It also make easier to integrate new option without reworking it.
All right, I re-read the whole loop and looks fine to me.
Quoted 39 lines
Quoted 30 lines
Quoted 30 lines
xen/arch/arm/cpuerrata.c +23
-0+if ( !strncmp (s,"ssbd=" ,5 ) ) + { + s +=5 ; + +if ( !strncmp (s,"force-disable" , ss - s) ) + ssbd_state =ARM_SSBD_FORCE_DISABLE ; +else if ( !strncmp (s,"runtime" , ss - s) ) + ssbd_state =ARM_SSBD_RUNTIME ; +else if ( !strncmp (s,"force-enable" , ss - s) ) + ssbd_state =ARM_SSBD_FORCE_ENABLE ; +else + rc = -EINVAL ; + } +else + rc = -EINVAL ; + + s = ss +1 ; + }while ( *ss ); + +return rc; +} +custom_param ("spec-ctrl" , parse_spec_ctrl); +/* * Assembly code may use the variable directly, so we need to make sure * it fits in a register. @@ -246,25 +281,82 @@ DEFINE_PER_CPU_READ_MOSTLY(register_t, ssbd_callback_required);Quoted 8 lines
xen/arch/arm/cpuerrata.c DEFINE_PER_CPU_READ_MOSTLY(register_t, ssbd_callback_required); · line 284
Quoted 6 lines
xen/arch/arm/cpuerrata.c +1
-1static bool has_ssbd_mitigation (const struct arm_cpu_capabilities *entry) {struct arm_smccc_res res; -bool supported = true; +bool required = true;Please avoid this renaming. Choose one name or the other from the start.
Quoted 3 lines
This is what happen when you want to split a series in a logical way. The name "required" does not make sense with the previous patch. So the renaming make sense here.
Why does "required" not make sense in the previous patch? I think it would be fine.
In any case, I prefer that both of us spend time on useful stuff rather than choosing which patch should set the variable name :-) So I am going to drop this regardless.
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
xen/arch/arm/cpuerrata.c +0
-4if ( smccc_ver <SMCCC_VERSION (1 ,1 ) )return false; - /* -* The probe function return value is either negative (unsupported -* or mitigated), positive (unaffected), or zero (requires -* mitigation). We only need to do anything in the last case. -*/
Quoted 5 lines
Quoted 1 line
I would keep the comment
The comment is not correct after this patch. The may need to act differently depending on the comment line. Regarding the values, the switch is more explanatory than those 3 lines.
I see. You could keep the comment, removing "We only need to do anything in the last case." Either way is OK.
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
xen/arch/arm/cpuerrata.c +1
-3arm_smccc_1_1_smc (ARM_SMCCC_ARCH_FEATURES_FID ,ARM_SMCCC_ARCH_WORKAROUND_2_FID , &res); -if ( (int )res.a0 !=0 ) - supported = false; - if ( supported ) -this_cpu (ssbd_callback_required) =1 ; + switch ( (int)res.a0 )
Quoted 5 lines
Quoted 2 lines
Please introduce this switch in the previous patch. But it makes sense to add the
ssbd_statevariable in this patch.Well, that's not going to make the diff simpler here as the switch will be different. So I would keep the patch like that.
The split is a bit iffy to me, but if you don't want to change it, I can live with it anyway.
Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
xen/arch/arm/cpuerrata.c +10
-0+ { +case ARM_SMCCC_NOT_SUPPORTED : + ssbd_state =ARM_SSBD_UNKNOWN ; +return false; + +case ARM_SMCCC_NOT_REQUIRED : + ssbd_state =ARM_SSBD_MITIGATED ; +return false; + +case ARM_SMCCC_SUCCESS :Quoted 8 lines
xen/arch/arm/cpuerrata.c DEFINE_PER_CPU_READ_MOSTLY(register_t, ssbd_callback_required); · line 308
Quoted 6 lines
xen/arch/arm/cpuerrata.c +6
-0+ required = true; +break ; + +case 1 :/* Mitigation not required on this CPU. */ + required = false; +break ;This should "return false".
Quoted 2 lines
It is perfectly fine to continue as it is safe to execute
ARCH_WORKAROUND_2on that CPU.
This is the case where mitigation is not required but issuing the SMCCC is safe. Instead of returning immediately, we go through the next switch:
1) if ARM_SSBD_FORCE_DISABLE, we make the SMCCC
2) if ARM_SSBD_RUNTIME, we do nothing
3) if ARM_SSBD_FORCE_ENABLE, we make the SMCCC
What is the desired outcome for this situation? Obviously, continuing for case 2) is pointless, we might as well return immediately. For 1) and 3) is the intention that the SMCCC will actually have an effect even if the mitigation is not required?
Quoted 5 lines
Also, it might make sense to set
ssbd_stateQuoted 1 line
to
ARM_SSBD_MITIGATED?No, the mitigation is not required on *that* CPU. It does not mean it will not be required for all CPUs. So it makes sense to not update
ssbd_state.
I understand now, and thanks for the clarification on the call as well.
Quoted 52 lines
Quoted 27 lines
Quoted 27 lines
xen/arch/arm/cpuerrata.c +25
-0+ +default : +ASSERT_UNREACHABLE (); +return false; + } + +switch ( ssbd_state ) + { +case ARM_SSBD_FORCE_DISABLE : + { +static bool once = true; + +if ( once ) +printk ("%s disabled from command-line\n" , entry->desc); + once = false; + +arm_smccc_1_1_smc (ARM_SMCCC_ARCH_WORKAROUND_2_FID ,0 ,NULL ); + required = false; + +break ; + } + +case ARM_SSBD_RUNTIME : +if ( required ) + {Quoted 8 lines
xen/arch/arm/cpuerrata.c DEFINE_PER_CPU_READ_MOSTLY(register_t, ssbd_callback_required); · line 334
Quoted 1 line
xen/arch/arm/cpuerrata.c +1
-0+this_cpu (ssbd_callback_required) =1 ;We have the
ARM_SSBDbit, thessbd_statevariable andssbd_callback_required. BothARM_SSBDandssbd_stateare shared across cores whilessbd_callback_requiredis per-cpu. Doesssbd_callback_requiredreally need to be per-cpu? > Do we need both variables? For instance, we could just returnssbd_state==ARM_SSBD_RUNTIMEinstead ofthis_cpu(ssbd_callback_required)?Let me start with because a guest vCPU may run on any pCPU, you always have to tell the guest the mitigation is required for all vCPUs.
By default, Linux is calling the workaround at entry from EL0 to enable it and at exit to EL0 to disable it. The workaround will first trap in EL2 and then get forwarded to EL3.
You can imagine that the trap to EL2 and then EL3 has a cost. If the workaround is not necessary, then you can reduce that cost by avoiding to trap at EL3. As you can have a platform with heterogenous CPUs, you need that workaround per-CPU.
The
ARM_SSBDfeature bit is useful in order to put shortcut in place using alternative (seecheck_workaround_ssbd). So on platform where the mitigation is not required, all the new code is nearly a NOP.
Quoted 7 lines
The
ssbd_stateis used in various place to know what is the global state of the mitigation:
- To initialize the vCPU state for the mitigation
- To report the guest what is the state of the mitigation using SMCCCSo all those variables have a specific purposes and cannot really be replaced by another way.
Good explanation. Please add something like this to one of the commit messages. Please also consider the following suggestion.
Wouldn't it make sense to remove ssbd_callback_required and make ssbd_state a per-cpu variable? The Xen command line option would remain the same, global, but it would initialize the value of ssbd_state on all cpus. Then, has_ssbd_mitigation would further modify ssbd_state on a specific cpu to ARM_SSBD_UNKNOWN (if ARM_SMCCC_NOT_SUPPORTED), ARM_SSBD_MITIGATED (if ARM_SMCCC_NOT_REQUIRED"), etc. In the common case, the CPUs that need the workaround will have ssbd_state set to ARM_SSBD_RUNTIME, and the others will have ARM_SSBD_UNKNOWN or ARM_SSBD_MITIGATED, or maybe a new value ARM_SSBD_UNNECESSARY. It looks like it would still be simple to check on ssbd_state from assembly as well, it can still be done with one instruction, we just need to make sure to assign integer values to the enum, such as:
ARM_SSBD_UNKNOWN = 0,
ARM_SSBD_FORCE_DISABLE = 1,
etc.
Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
xen/arch/arm/cpuerrata.c +11
-0+arm_smccc_1_1_smc (ARM_SMCCC_ARCH_WORKAROUND_2_FID ,1 ,NULL ); + } + +break ; + +case ARM_SSBD_FORCE_ENABLE : + { +static bool once = true; + +if ( once ) +printk ("%s forced from command-line\n" , entry->desc);Quoted 8 lines
xen/arch/arm/cpuerrata.c DEFINE_PER_CPU_READ_MOSTLY(register_t, ssbd_callback_required); · line 349
Quoted 4 lines
xen/arch/arm/cpuerrata.c +4
-0+ once = false; + +arm_smccc_1_1_smc (ARM_SMCCC_ARCH_WORKAROUND_2_FID ,1 ,NULL ); + required = true;This function is supposed to detect whether a workaround is needed, not enable it, right? Should this switch and relative code be moved to the .enable function for this capability?
Quoted 3 lines
I had the split before but it is difficult to get a nice split between .enable and .matches. So I decided to follow what Linux/KVM did and put everything in
has_.
All right. Please add a note about this in the commit message or the code.
Quoted 67 lines
Quoted 67 lines
Quoted 67 lines
xen/arch/arm/cpuerrata.c +8
-0+ break; + } + +default : +ASSERT_UNREACHABLE (); +return false; + } - return supported; +return required; }#endif @@ -371,6 +463,7 @@ static const struct arm_cpu_capabilitiesarm_errata[] = {
#endif#ifdef CONFIG_ARM_SSBD {xen/arch/arm/cpuerrata.c +1
-0+ .desc = "Speculative Store Bypass Disabled", .capability = ARM_SSBD, .matches = has_ssbd_mitigation, },xen/include/asm-arm/cpuerrata.h +18
-0@@ -31,10 +31,26 @@ CHECK_WORKAROUND_HELPER(ssbd, ARM_SSBD, CONFIG_ARM_SSBD)#undef CHECK_WORKAROUND_HELPER +enum ssbd_state +{ +ARM_SSBD_UNKNOWN , +ARM_SSBD_FORCE_DISABLE , +ARM_SSBD_RUNTIME , +ARM_SSBD_FORCE_ENABLE , + ARM_SSBD_MITIGATED, +}; +#ifdef CONFIG_ARM_SSBD #include <asm/current.h> +extern enum ssbd_state ssbd_state; + +static inline enum ssbd_state get_ssbd_state (void ) +{ +return ssbd_state; +} +DECLARE_PER_CPU (register_t, ssbd_callback_required);static inline bool cpu_require_ssbd_mitigation (void )@@ -49,6 +65,11 @@ static inline bool cpu_require_ssbd_mitigation(void)return false; } +static inline enum ssbd_state get_sbdd_state(void) +{ +return ARM_SSBD_UNKNOWN ; +} +#endif #endif /* __ARM_CPUERRATA_H__ */ xen/include/asm-arm/smccc.h +1
-0@@ -265,6 +265,7 @@ struct arm_smccc_res { 0x7FFF)/* SMCCC error codes */ +#define ARM_SMCCC_NOT_REQUIRED (-2)
Quoted 12 lines
Quoted 6 lines
Quoted 6 lines
xen/include/asm-arm/smccc.h +0
-0#define ARM_SMCCC_ERR_UNKNOWN_FUNCTION (-1)#define ARM_SMCCC_NOT_SUPPORTED (-1)#define ARM_SMCCC_SUCCESS (0)Signature · 1 line
2.11.0Cheers,
Signature · 1 line
Julien Grall
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 05/13] xen/arm: Add command line option to control SSBD mitigation
Quoted 10 lines · Stefano Stabellini
Quoted 9 lines · Julien Grall
Quoted 8 lines · Stefano Stabellini
On Tue, 22 May 2018, Julien Grall >>>> arm_smccc_1_1_smc(ARM_SMCCC_ARCH_FEATURES_FID,
Quoted 6 lines
ARM_SMCCC_ARCH_WORKAROUND_2_FID, &res);xen/arch/arm/cpuerrata.c +1
-3-if ( (int )res.a0 !=0 ) - supported = false; - if ( supported ) -this_cpu (ssbd_callback_required) =1 ; + switch ( (int)res.a0 )
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Please introduce this switch in the previous patch. But it makes sense to add the
ssbd_statevariable in this patch.Well, that's not going to make the diff simpler here as the switch will be different. So I would keep the patch like that.
The split is a bit iffy to me, but if you don't want to change it, I can live with it anyway.
I don't think the other way will help. But I will do it.
Quoted 27 lines
Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
xen/arch/arm/cpuerrata.c +10
-0+ { +case ARM_SMCCC_NOT_SUPPORTED : + ssbd_state =ARM_SSBD_UNKNOWN ; +return false; + +case ARM_SMCCC_NOT_REQUIRED : + ssbd_state =ARM_SSBD_MITIGATED ; +return false; + +case ARM_SMCCC_SUCCESS :Quoted 8 lines
xen/arch/arm/cpuerrata.c DEFINE_PER_CPU_READ_MOSTLY(register_t, ssbd_callback_required); · line 308
Quoted 6 lines
xen/arch/arm/cpuerrata.c +6
-0+ required = true; +break ; + +case 1 :/* Mitigation not required on this CPU. */ + required = false; +break ;This should "return false".
Quoted 2 lines
It is perfectly fine to continue as it is safe to execute
ARCH_WORKAROUND_2on that CPU.This is the case where mitigation is not required but issuing the SMCCC is safe. Instead of returning immediately, we go through the next switch:
Quoted 8 lines
1) if
ARM_SSBD_FORCE_DISABLE, we make the SMCCC
2) ifARM_SSBD_RUNTIME, we do nothing
3) ifARM_SSBD_FORCE_ENABLE, we make the SMCCCWhat is the desired outcome for this situation? Obviously, continuing for case 2) is pointless, we might as well return immediately. For 1) and 3) is the intention that the SMCCC will actually have an effect even if the mitigation is not required?
While the SMCCC call in 1) and 3) will do nothing for those CPUs, you will still print a warning message if the user choose to force enable/disable the mitigation.
Quoted 76 lines
Quoted 52 lines
Quoted 27 lines
Quoted 27 lines
xen/arch/arm/cpuerrata.c +25
-0+ +default : +ASSERT_UNREACHABLE (); +return false; + } + +switch ( ssbd_state ) + { +case ARM_SSBD_FORCE_DISABLE : + { +static bool once = true; + +if ( once ) +printk ("%s disabled from command-line\n" , entry->desc); + once = false; + +arm_smccc_1_1_smc (ARM_SMCCC_ARCH_WORKAROUND_2_FID ,0 ,NULL ); + required = false; + +break ; + } + +case ARM_SSBD_RUNTIME : +if ( required ) + {Quoted 8 lines
Quoted 1 line
+
this_cpu(ssbd_callback_required)= 1;We have the
ARM_SSBDbit, thessbd_statevariable andssbd_callback_required. BothARM_SSBDandssbd_stateare shared across cores whilessbd_callback_requiredis per-cpu. Doesssbd_callback_requiredreally need to be per-cpu? > Do we need both variables? For instance, we could just returnssbd_state==ARM_SSBD_RUNTIMEinstead ofthis_cpu(ssbd_callback_required)?Let me start with because a guest vCPU may run on any pCPU, you always have to tell the guest the mitigation is required for all vCPUs.
By default, Linux is calling the workaround at entry from EL0 to enable it and at exit to EL0 to disable it. The workaround will first trap in EL2 and then get forwarded to EL3.
You can imagine that the trap to EL2 and then EL3 has a cost. If the workaround is not necessary, then you can reduce that cost by avoiding to trap at EL3. As you can have a platform with heterogenous CPUs, you need that workaround per-CPU.
The
ARM_SSBDfeature bit is useful in order to put shortcut in place using alternative (seecheck_workaround_ssbd). So on platform where the mitigation is not required, all the new code is nearly a NOP.Quoted 7 lines
The
ssbd_stateis used in various place to know what is the global state of the mitigation:
- To initialize the vCPU state for the mitigation
- To report the guest what is the state of the mitigation using SMCCCSo all those variables have a specific purposes and cannot really be replaced by another way.
Good explanation. Please add something like this to one of the commit messages. Please also consider the following suggestion.
Wouldn't it make sense to remove
ssbd_callback_requiredand makessbd_statea per-cpu variable? The Xen command line option would remain the same, global, but it would initialize the value ofssbd_stateon all cpus. Then,has_ssbd_mitigationwould further modifyssbd_stateon a specific cpu toARM_SSBD_UNKNOWN(ifARM_SMCCC_NOT_SUPPORTED),ARM_SSBD_MITIGATED(ifARM_SMCCC_NOT_REQUIRED"), etc. In the common case, the CPUs that need the workaround will havessbd_stateset toARM_SSBD_RUNTIME, and the others will haveARM_SSBD_UNKNOWNorARM_SSBD_MITIGATED, or maybe a new valueARM_SSBD_UNNECESSARY. It looks like it would still be simple to check onssbd_statefrom assembly as well, it can still be done with one instruction, we just need to make sure to assign integer values to the enum, such as:
Quoted 4 lines
ARM_SSBD_UNKNOWN= 0,
ARM_SSBD_FORCE_DISABLE= 1,etc.
As I said in my previous e-mail, we need to know the global state of the mitigation. This is because a vCPU may move from a affected CPU to a non-affected one. Therefore we need to inform the same on every vCPU (i.e mitigated, dynamic...).
Your suggestion will just save 4 bytes but add more code to find out what is the system-wide decision for the mitigation.
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 05/13] xen/arm: Add command line option to control SSBD mitigation
Quoted 15 lines · Julien Grall
Quoted 14 lines · Stefano Stabellini
Quoted 13 lines · Julien Grall
Quoted 11 lines · Stefano Stabellini
On Tue, 22 May 2018, Julien Grall >>>>
arm_smccc_1_1_smc(ARM_SMCCC_ARCH_FEATURES_FID,xen/arch/arm/cpuerrata.c DEFINE_PER_CPU_READ_MOSTLY(register_t, ssbd_callback_required); · line 292
Quoted 6 lines
ARM_SMCCC_ARCH_WORKAROUND_2_FID, &res);xen/arch/arm/cpuerrata.c +1
-3-if ( (int )res.a0 !=0 ) - supported = false; - if ( supported ) -this_cpu (ssbd_callback_required) =1 ; + switch ( (int)res.a0 )Please introduce this switch in the previous patch. But it makes sense to add the
ssbd_statevariable in this patch.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Well, that's not going to make the diff simpler here as the switch will be different. So I would keep the patch like that.
The split is a bit iffy to me, but if you don't want to change it, I can live with it anyway.
I don't think the other way will help. But I will do it.
Thank you
Quoted 32 lines
Quoted 32 lines
Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
xen/arch/arm/cpuerrata.c +10
-0+ { +case ARM_SMCCC_NOT_SUPPORTED : + ssbd_state =ARM_SSBD_UNKNOWN ; +return false; + +case ARM_SMCCC_NOT_REQUIRED : + ssbd_state =ARM_SSBD_MITIGATED ; +return false; + +case ARM_SMCCC_SUCCESS :Quoted 8 lines
xen/arch/arm/cpuerrata.c DEFINE_PER_CPU_READ_MOSTLY(register_t, ssbd_callback_required); · line 308
Quoted 6 lines
xen/arch/arm/cpuerrata.c +6
-0+ required = true; +break ; + +case 1 :/* Mitigation not required on this CPU. */ + required = false; +break ;This should "return false".
Quoted 3 lines
It is perfectly fine to continue as it is safe to execute
ARCH_WORKAROUND_2on
that CPU.This is the case where mitigation is not required but issuing the SMCCC is safe. Instead of returning immediately, we go through the next switch:
1) if
ARM_SSBD_FORCE_DISABLE, we make the SMCCC
2) ifARM_SSBD_RUNTIME, we do nothing
3) ifARM_SSBD_FORCE_ENABLE, we make the SMCCC
Quoted 8 lines
Quoted 4 lines
What is the desired outcome for this situation? Obviously, continuing for case 2) is pointless, we might as well return immediately. For 1) and 3) is the intention that the SMCCC will actually have an effect even if the mitigation is not required?
While the SMCCC call in 1) and 3) will do nothing for those CPUs, you will still print a warning message if the user choose to force enable/disable the mitigation.
Printing warnings could be a good idea. However, I think we should do the same thing for "1" and for "ARM_SMCCC_NOT_REQUIRED", and maybe even for "ARM_SMCCC_NOT_SUPPORTED": printing warnings for all or for none.
I also noticed that if the first SMCCC returns "1" and we continue, in case ssbd_state == ARM_SSBD_FORCE_ENABLE, "required" gets changed to "true". Do we want to let the user force-enable the mitigation even when it will do nothing? I am not really sure, probably not? In any case I would prefer if we kept the same behavior across "1" and "ARM_SMCCC_NOT_REQUIRED".
Quoted 85 lines
Quoted 85 lines
Quoted 63 lines
Quoted 27 lines
Quoted 27 lines
xen/arch/arm/cpuerrata.c +25
-0+ +default : +ASSERT_UNREACHABLE (); +return false; + } + +switch ( ssbd_state ) + { +case ARM_SSBD_FORCE_DISABLE : + { +static bool once = true; + +if ( once ) +printk ("%s disabled from command-line\n" , entry->desc); + once = false; + +arm_smccc_1_1_smc (ARM_SMCCC_ARCH_WORKAROUND_2_FID ,0 ,NULL ); + required = false; + +break ; + } + +case ARM_SSBD_RUNTIME : +if ( required ) + {Quoted 8 lines
Quoted 1 line
+
this_cpu(ssbd_callback_required)= 1;We have the
ARM_SSBDbit, thessbd_statevariable andssbd_callback_required. BothARM_SSBDandssbd_stateare shared across cores whilessbd_callback_requiredis per-cpu. Doesssbd_callback_requiredreally need to be per-cpu? > Do we need both variables? For instance, we could just returnssbd_state==ARM_SSBD_RUNTIMEinstead ofthis_cpu(ssbd_callback_required)?Let me start with because a guest vCPU may run on any pCPU, you always have to
tell the guest the mitigation is required for all vCPUs.By default, Linux is calling the workaround at entry from EL0 to enable it and
at exit to EL0 to disable it. The workaround will first trap in EL2 and then
get forwarded to EL3.You can imagine that the trap to EL2 and then EL3 has a cost. If the workaround is not necessary, then you can reduce that cost by avoiding to trap
at EL3. As you can have a platform with heterogenous CPUs, you need that workaround per-CPU.The
ARM_SSBDfeature bit is useful in order to put shortcut in place using alternative (seecheck_workaround_ssbd). So on platform where the mitigation
is not required, all the new code is nearly a NOP.The
ssbd_stateis used in various place to know what is the global state of
the mitigation:
- To initialize the vCPU state for the mitigation
- To report the guest what is the state of the mitigation using SMCCCQuoted 3 lines
So all those variables have a specific purposes and cannot really be replaced
by another way.Good explanation. Please add something like this to one of the commit messages. Please also consider the following suggestion.
Wouldn't it make sense to remove
ssbd_callback_requiredand makessbd_statea per-cpu variable? The Xen command line option would remain the same, global, but it would initialize the value ofssbd_stateon all cpus. Then,has_ssbd_mitigationwould further modifyssbd_stateon a specific cpu toARM_SSBD_UNKNOWN(ifARM_SMCCC_NOT_SUPPORTED),ARM_SSBD_MITIGATED(ifARM_SMCCC_NOT_REQUIRED"), etc. In the common case, the CPUs that need the workaround will havessbd_stateset toARM_SSBD_RUNTIME, and the others will haveARM_SSBD_UNKNOWNorARM_SSBD_MITIGATED, or maybe a new valueARM_SSBD_UNNECESSARY. It looks like it would still be simple to check onssbd_statefrom assembly as well, it can still be done with one instruction, we just need to make sure to assign integer values to the enum, such as:
ARM_SSBD_UNKNOWN= 0,
ARM_SSBD_FORCE_DISABLE= 1,
Quoted 6 lines
Quoted 1 line
etc.
As I said in my previous e-mail, we need to know the global state of the mitigation. This is because a vCPU may move from a affected CPU to a non-affected one. Therefore we need to inform the same on every vCPU (i.e mitigated, dynamic...).
All right, but if the SMCCC(ARM_SMCCC_ARCH_FEATURES_FID, ARM_SMCCC_ARCH_WORKAROUND_2_FID) returns ARM_SMCCC_SUCCESS on cpu0 and ARM_SMCCC_NOT_REQUIRED on cpu1, the result will be that ssbd_state is set to ARM_SSBD_MITIGATED for all cpus. Which is not what we want? It doesn't look like the vsmc would return the right value anymore.
One solution would be that has_ssbd_mitigation is not allowed to set ssbd_state to ARM_SSBD_UNKNOWN or ARM_SSBD_MITIGATED if previously, or afterwards, the SMCCC returns ARM_SMCCC_SUCCESS. In other words, ARM_SMCCC_SUCCESS trumps any other return values.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 05/13] xen/arm: Add command line option to control SSBD mitigation
Hi Stefano,
Quoted 72 lines · Stefano Stabellini
Quoted 15 lines · Julien Grall
Quoted 14 lines · Stefano Stabellini
Quoted 13 lines · Julien Grall
Quoted 11 lines · Stefano Stabellini
On Tue, 22 May 2018, Julien Grall >>>>
arm_smccc_1_1_smc(ARM_SMCCC_ARCH_FEATURES_FID,xen/arch/arm/cpuerrata.c DEFINE_PER_CPU_READ_MOSTLY(register_t, ssbd_callback_required); · line 292
Quoted 6 lines
ARM_SMCCC_ARCH_WORKAROUND_2_FID, &res);xen/arch/arm/cpuerrata.c +1
-3-if ( (int )res.a0 !=0 ) - supported = false; - if ( supported ) -this_cpu (ssbd_callback_required) =1 ; + switch ( (int)res.a0 )Please introduce this switch in the previous patch. But it makes sense to add the
ssbd_statevariable in this patch.Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Well, that's not going to make the diff simpler here as the switch will be different. So I would keep the patch like that.
The split is a bit iffy to me, but if you don't want to change it, I can live with it anyway.
I don't think the other way will help. But I will do it.
Thank you
Quoted 32 lines
Quoted 32 lines
Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
xen/arch/arm/cpuerrata.c +10
-0+ { +case ARM_SMCCC_NOT_SUPPORTED : + ssbd_state =ARM_SSBD_UNKNOWN ; +return false; + +case ARM_SMCCC_NOT_REQUIRED : + ssbd_state =ARM_SSBD_MITIGATED ; +return false; + +case ARM_SMCCC_SUCCESS :Quoted 8 lines
xen/arch/arm/cpuerrata.c DEFINE_PER_CPU_READ_MOSTLY(register_t, ssbd_callback_required); · line 308
Quoted 6 lines
xen/arch/arm/cpuerrata.c +6
-0+ required = true; +break ; + +case 1 :/* Mitigation not required on this CPU. */ + required = false; +break ;This should "return false".
Quoted 3 lines
It is perfectly fine to continue as it is safe to execute
ARCH_WORKAROUND_2on
that CPU.This is the case where mitigation is not required but issuing the SMCCC is safe. Instead of returning immediately, we go through the next switch:
1) if
ARM_SSBD_FORCE_DISABLE, we make the SMCCC
2) ifARM_SSBD_RUNTIME, we do nothing
3) ifARM_SSBD_FORCE_ENABLE, we make the SMCCCQuoted 8 lines
Quoted 4 lines
What is the desired outcome for this situation? Obviously, continuing for case 2) is pointless, we might as well return immediately. For 1) and 3) is the intention that the SMCCC will actually have an effect even if the mitigation is not required?
While the SMCCC call in 1) and 3) will do nothing for those CPUs, you will still print a warning message if the user choose to force enable/disable the mitigation.
Printing warnings could be a good idea. However, I think we should do the same thing for "1" and for "
ARM_SMCCC_NOT_REQUIRED", and maybe even for "ARM_SMCCC_NOT_SUPPORTED": printing warnings for all or for none.
Quoted 5 lines
I also noticed that if the first SMCCC returns "1" and we continue, in case
ssbd_state==ARM_SSBD_FORCE_ENABLE, "required" gets changed to "true". Do we want to let the user force-enable the mitigation even
when it will do nothing? I am not really sure, probably not? In any case
I would prefer if we kept the same behavior across "1" and
"ARM_SMCCC_NOT_REQUIRED".
I don't think it is right ot expect the same behavior for "1"and "ARM_SMCCC_NOT_REQUIRED". There are majors difference between those 2 and ARM_SMCCC_NOT_SUPPORTED.
From the spec ARM DEN 0070A section 2.2.5:
- If your firmware does not support the call, ARM_SMCCC_NOT_SUPPORTED
will be returned for *all* CPUs. This will happen on current firmwares.
- If your firmware has mitigation permanently disabled/enabled for
*all* CPUs, ARM_SMCCC_NOT_REQUIRED will be returned.
- If one of the CPUs in the platform require dynamic mitigation, the
call will return 0 for them. The others CPUs will return 1.
Printing a warning for the first two will likely scare the user because it is going to be printed on most of the current platforms.
Printing a warning for the last one makes sense because you know that one of the CPU may be affected. That CPU may be bring up later on. So you offer a print in similar place in the logs whatever the platform is.
Quoted 99 lines
Quoted 87 lines
Quoted 87 lines
Quoted 65 lines
Quoted 29 lines
Quoted 29 lines
xen/arch/arm/cpuerrata.c +25
-0+ +default : +ASSERT_UNREACHABLE (); +return false; + } + +switch ( ssbd_state ) + { +case ARM_SSBD_FORCE_DISABLE : + { +static bool once = true; + +if ( once ) +printk ("%s disabled from command-line\n" , entry->desc); + once = false; + +arm_smccc_1_1_smc (ARM_SMCCC_ARCH_WORKAROUND_2_FID ,0 ,NULL ); + required = false; + +break ; + } + +case ARM_SSBD_RUNTIME : +if ( required ) + {Quoted 8 lines
Quoted 1 line
+
this_cpu(ssbd_callback_required)= 1;We have the
ARM_SSBDbit, thessbd_statevariable andssbd_callback_required. BothARM_SSBDandssbd_stateare shared across cores whilessbd_callback_requiredis per-cpu. Doesssbd_callback_requiredreally need to be per-cpu? > Do we need both variables? For instance, we could just returnssbd_state==ARM_SSBD_RUNTIMEinstead ofthis_cpu(ssbd_callback_required)?Let me start with because a guest vCPU may run on any pCPU, you always have to
tell the guest the mitigation is required for all vCPUs.By default, Linux is calling the workaround at entry from EL0 to enable it and
at exit to EL0 to disable it. The workaround will first trap in EL2 and then
get forwarded to EL3.You can imagine that the trap to EL2 and then EL3 has a cost. If the workaround is not necessary, then you can reduce that cost by avoiding to trap
at EL3. As you can have a platform with heterogenous CPUs, you need that workaround per-CPU.The
ARM_SSBDfeature bit is useful in order to put shortcut in place using alternative (seecheck_workaround_ssbd). So on platform where the mitigation
is not required, all the new code is nearly a NOP.The
ssbd_stateis used in various place to know what is the global state of
the mitigation:
- To initialize the vCPU state for the mitigation
- To report the guest what is the state of the mitigation using SMCCCQuoted 3 lines
So all those variables have a specific purposes and cannot really be replaced
by another way.Good explanation. Please add something like this to one of the commit messages. Please also consider the following suggestion.
Wouldn't it make sense to remove
ssbd_callback_requiredand makessbd_statea per-cpu variable? The Xen command line option would remain the same, global, but it would initialize the value ofssbd_stateon all cpus. Then,has_ssbd_mitigationwould further modifyssbd_stateon a specific cpu toARM_SSBD_UNKNOWN(ifARM_SMCCC_NOT_SUPPORTED),ARM_SSBD_MITIGATED(ifARM_SMCCC_NOT_REQUIRED"), etc. In the common case, the CPUs that need the workaround will havessbd_stateset toARM_SSBD_RUNTIME, and the others will haveARM_SSBD_UNKNOWNorARM_SSBD_MITIGATED, or maybe a new valueARM_SSBD_UNNECESSARY. It looks like it would still be simple to check onssbd_statefrom assembly as well, it can still be done with one instruction, we just need to make sure to assign integer values to the enum, such as:
ARM_SSBD_UNKNOWN= 0,
ARM_SSBD_FORCE_DISABLE= 1,Quoted 6 lines
Quoted 1 line
etc.
As I said in my previous e-mail, we need to know the global state of the mitigation. This is because a vCPU may move from a affected CPU to a non-affected one. Therefore we need to inform the same on every vCPU (i.e mitigated, dynamic...).
All right, but if the
SMCCC(ARM_SMCCC_ARCH_FEATURES_FID, ARM_SMCCC_ARCH_WORKAROUND_2_FID)returnsARM_SMCCC_SUCCESSon cpu0 andARM_SMCCC_NOT_REQUIREDon cpu1, the result will be thatssbd_stateis set toARM_SSBD_MITIGATEDfor all cpus. Which is not what we want?
Quoted 6 lines
It doesn't look like the vsmc would return the right value anymore.
One solution would be that
has_ssbd_mitigationis not allowed to setssbd_statetoARM_SSBD_UNKNOWNorARM_SSBD_MITIGATEDif previously, or afterwards, the SMCCC returnsARM_SMCCC_SUCCESS. In other words,ARM_SMCCC_SUCCESStrumps any other return values.
There seem to be a misunderstanding of the spec. If ARM_SMCCC_NOT_REQUIRED is returned on one CPU, it will also be returned for all the others. It means that *all* CPUs have the mitigations permanently enabled/disabled.
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 05/13] xen/arm: Add command line option to control SSBD mitigation
Quoted 96 lines · Julien Grall
Quoted 76 lines · Stefano Stabellini
Quoted 16 lines · Julien Grall
Quoted 15 lines · Stefano Stabellini
Quoted 14 lines · Julien Grall
Quoted 12 lines · Stefano Stabellini
On Tue, 22 May 2018, Julien Grall >>>>
arm_smccc_1_1_smc(ARM_SMCCC_ARCH_FEATURES_FID,Review
Quoted 6 lines
ARM_SMCCC_ARCH_WORKAROUND_2_FID, &res);(quoted diff) +1
-3- if ( (int)res.a0 != 0 ) - supported = false; - if ( supported ) - this_cpu(ssbd_callback_required) = 1; + switch ( (int)res.a0 )Please introduce this switch in the previous patch. But it makes sense
to add thessbd_statevariable in this patch.Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Well, that's not going to make the diff simpler here as the switch will be
different. So I would keep the patch like that.The split is a bit iffy to me, but if you don't want to change it, I can live with it anyway.
I don't think the other way will help. But I will do it.
Thank you
Quoted 38 lines
Quoted 32 lines
Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
(quoted diff) +10
-0+ { + case ARM_SMCCC_NOT_SUPPORTED: + ssbd_state = ARM_SSBD_UNKNOWN; + return false; + + case ARM_SMCCC_NOT_REQUIRED: + ssbd_state = ARM_SSBD_MITIGATED; + return false; + + case ARM_SMCCC_SUCCESS:Quoted 8 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+ required = true; + break; + + case 1: /* Mitigation not required on this CPU. */ + required = false; + break;This should "return false".
Quoted 3 lines
It is perfectly fine to continue as it is safe to execute
ARCH_WORKAROUND_2on
that CPU.This is the case where mitigation is not required but issuing the SMCCC is safe. Instead of returning immediately, we go through the next switch:
1) if
ARM_SSBD_FORCE_DISABLE, we make the SMCCC
2) ifARM_SSBD_RUNTIME, we do nothing
3) ifARM_SSBD_FORCE_ENABLE, we make the SMCCCQuoted 5 lines
What is the desired outcome for this situation? Obviously, continuing for
case 2) is pointless, we might as well return immediately. For 1) and 3) is the intention that the SMCCC will actually have an effect even if the mitigation is not required?Quoted 4 lines
While the SMCCC call in 1) and 3) will do nothing for those CPUs, you will still print a warning message if the user choose to force enable/disable the
mitigation.Printing warnings could be a good idea. However, I think we should do the same thing for "1" and for "
ARM_SMCCC_NOT_REQUIRED", and maybe even for "ARM_SMCCC_NOT_SUPPORTED": printing warnings for all or for none.Quoted 6 lines
I also noticed that if the first SMCCC returns "1" and we continue, in case
ssbd_state==ARM_SSBD_FORCE_ENABLE, "required" gets changed to "true". Do we want to let the user force-enable the mitigation even when it will do nothing? I am not really sure, probably not? In any case I would prefer if we kept the same behavior across "1" and "ARM_SMCCC_NOT_REQUIRED".I don't think it is right ot expect the same behavior for "1"and "
ARM_SMCCC_NOT_REQUIRED". There are majors difference between those 2 andARM_SMCCC_NOT_SUPPORTED.From the spec ARM DEN 0070A section 2.2.5:
- If your firmware does not support the call,ARM_SMCCC_NOT_SUPPORTED
will be returned for *all* CPUs. This will happen on current firmwares.
- If your firmware has mitigation permanently disabled/enabled for
*all* CPUs,ARM_SMCCC_NOT_REQUIREDwill be returned.
- If one of the CPUs in the platform require dynamic mitigation, the
call will return 0 for them. The others CPUs will return 1.
Quoted 6 lines
Printing a warning for the first two will likely scare the user because it is going to be printed on most of the current platforms.
Printing a warning for the last one makes sense because you know that one of the CPU may be affected. That CPU may be bring up later on. So you offer a print in similar place in the logs whatever the platform is.
I should have read the spec more carefully, thanks for the pointer. Sorry about that. Finally, these patches are starting to make sense :-)
All right. I can see why ssbd_state and ssbd_callback_required are separate and their purpose. Aside from adding more info to the commit message, I'll make a couple of different suggestions:
1) Let's check if ssbd_state == ARM_SSBD_UNKNOWN || ssbd_state == ARM_SSBD_MITIGATED at the beginning of has_ssbd_mitigation and return early in that case. This will help clarify the intended behavior and mitigate broken firmware returning ARM_SMCCC_NOT_SUPPORTED only on some cpus. This is just optional, I am fine either way.
2) Can we turn ssbd_callback_required from a this_cpu variable to a single cpu bitmask? It is not great to introduce a new per-cpu varible for just one bit. It would save space and make it easier to access from assembly as a bitmask as it would remove the need for the ldr_this_cpu macro. If I am wrong and the bitmask makes things more complicated rather than simpler, then keep the code as is and just mention it in the next version of the patch.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 05/13] xen/arm: Add command line option to control SSBD mitigation
Hi,
Quoted 14 lines · Stefano Stabellini
Quoted 6 lines · Julien Grall
Quoted 5 lines · Stefano Stabellini
Quoted 4 lines · Julien Grall
Quoted 3 lines · Stefano Stabellini
Quoted 2 lines · Julien Grall
Quoted 1 line · Stefano Stabellini
On Tue, 22 May 2018, Julien Grall >>>>
I should have read the spec more carefully, thanks for the pointer. Sorry about that. Finally, these patches are starting to make sense :-)
All right. I can see why
ssbd_stateandssbd_callback_requiredare separate and their purpose. Aside from adding more info to the commit message, I'll make a couple of different suggestions:
Quoted 5 lines
1) Let's check if
ssbd_state==ARM_SSBD_UNKNOWN||ssbd_state==ARM_SSBD_MITIGATEDat the beginning ofhas_ssbd_mitigationand return early in that case. This will help clarify the intended behavior and mitigate broken firmware returningARM_SMCCC_NOT_SUPPORTEDonly on some cpus. This is just optional, I am fine either way.
A vendor not able to do a simple return "ARM_SMCCC_NOT_SUPPORTED" in their firmware are not worth to support it in Xen. Most likely, more important bits of that firmware would be broken.
Quoted 8 lines
2) Can we turn
ssbd_callback_requiredfrom athis_cpuvariable to a single cpu bitmask? It is not great to introduce a new per-cpu varible for just one bit. It would save space and make it easier to access from assembly as a bitmask as it would remove the need for theldr_this_cpumacro. If I am wrong and the bitmask makes things more complicated rather than simpler, then keep the code as is and just mention it in the next version of the patch.
I hope you are aware that this will only save 8 byte per-CPU. On most of embedded platform you will have less than 16 CPUs. So you would save at most 128 bytes (woah!). If you are that tight in memory, then there are better place to reduce the footprint.
I am also not sure to understand the problem of having ldr_this_cpu around. The macro is simple and in any case, you would still require at least a load for the bitmask.
Feel free to suggest an assembly version for the bitmask.
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 05/13] xen/arm: Add command line option to control SSBD mitigation
Quoted 40 lines · Julien Grall
Hi,
Quoted 14 lines · Stefano Stabellini
Quoted 6 lines · Julien Grall
Quoted 5 lines · Stefano Stabellini
Quoted 4 lines · Julien Grall
Quoted 3 lines · Stefano Stabellini
Quoted 2 lines · Julien Grall
Quoted 1 line · Stefano Stabellini
On Tue, 22 May 2018, Julien Grall >>>>
I should have read the spec more carefully, thanks for the pointer. Sorry about that. Finally, these patches are starting to make sense :-)
All right. I can see why
ssbd_stateandssbd_callback_requiredare separate and their purpose. Aside from adding more info to the commit message, I'll make a couple of different suggestions:Quoted 5 lines
1) Let's check if
ssbd_state==ARM_SSBD_UNKNOWN||ssbd_state==ARM_SSBD_MITIGATEDat the beginning ofhas_ssbd_mitigationand return early in that case. This will help clarify the intended behavior and mitigate broken firmware returningARM_SMCCC_NOT_SUPPORTEDonly on some cpus. This is just optional, I am fine either way.A vendor not able to do a simple return "
ARM_SMCCC_NOT_SUPPORTED" in their firmware are not worth to support it in Xen. Most likely, more important bits of that firmware would be broken.Quoted 8 lines
2) Can we turn
ssbd_callback_requiredfrom athis_cpuvariable to a single cpu bitmask? It is not great to introduce a new per-cpu varible for just one bit. It would save space and make it easier to access from assembly as a bitmask as it would remove the need for theldr_this_cpumacro. If I am wrong and the bitmask makes things more complicated rather than simpler, then keep the code as is and just mention it in the next version of the patch.I hope you are aware that this will only save 8 byte per-CPU. On most of embedded platform you will have less than 16 CPUs. So you would save at most 128 bytes (woah!). If you are that tight in memory, then there are better place to reduce the footprint.
Quoted 5 lines
I am also not sure to understand the problem of having
ldr_this_cpuaround. The macro is simple and in any case, you would still require at least a load for the bitmask.Feel free to suggest an assembly version for the bitmask.
OK, this is very simple, the first that came to mind, I am sure you can improve it:
// 65 is the cpu number, in this example
MOV X1, #65
// X1 tells us which doubleword to consider
// X2 has the bit shift for right doubleword
// X3 is the shifted X2, we'll use it to check the bitmask
AND X2, X1, #(64-1)
LSR X1, X1, #3
MOV X3, #0x1
LSL X3, X3, X2
// we load the pointer to the bitmask in X4
LDR X4, =cpumask
// increase the pointer to point to the right doubleword
ADD X4, X4, X1
// load the doubleword
LDR X4, [X4]
// mask with X3, the result is in X1
AND X1, X4, X3_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 05/13] xen/arm: Add command line option to control SSBD mitigation
(sorry for the formatting)
Quoted 68 lines · On Thu, 31 May 2018, 22:00 Stefano Stabellini, <[email protected]> wrote:
Quoted 17 lines · Julien Grall
Hi,
Quoted 14 lines · Stefano Stabellini
Quoted 6 lines · Julien Grall
Quoted 5 lines · Stefano Stabellini
Quoted 4 lines · Julien Grall
Quoted 3 lines · Stefano Stabellini
Quoted 2 lines · Julien Grall
Quoted 1 line · Stefano Stabellini
On Tue, 22 May 2018, Julien Grall >>>>
I should have read the spec more carefully, thanks for the pointer. Sorry about that. Finally, these patches are starting to make sense :-)
All right. I can see why
ssbd_stateandssbd_callback_requiredare separate and their purpose. Aside from adding more info to the commit message, I'll make a couple of different suggestions:Quoted 7 lines
Quoted 6 lines
1) Let's check if
ssbd_state==ARM_SSBD_UNKNOWN||ssbd_state==ARM_SSBD_MITIGATEDat the beginning ofhas_ssbd_mitigationand returnearly in that case. This will help clarify the intended behavior and mitigate broken firmware returning
ARM_SMCCC_NOT_SUPPORTEDonly on some cpus. This is just optional, I am fine either way.A vendor not able to do a simple return "
ARM_SMCCC_NOT_SUPPORTED" intheir
Quoted 1 line
firmware are not worth to support it in Xen. Most likely, more important
bits
Quoted 9 lines
of that firmware would be broken.
Quoted 7 lines
2) Can we turn
ssbd_callback_requiredfrom athis_cpuvariable to a single cpu bitmask? It is not great to introduce a new per-cpu varible for just one bit. It would save space and make it easier to access from assembly as a bitmask as it would remove the need for theldr_this_cpumacro. If I am wrong and the bitmask makes things more complicated rather than simpler, then keep the code as is and just mention it inthe
Quoted 4 lines
Quoted 1 line
next version of the patch.
I hope you are aware that this will only save 8 byte per-CPU. On most of embedded platform you will have less than 16 CPUs. So you would save at
most
Quoted 4 lines
128 bytes (woah!). If you are that tight in memory, then there are better place to reduce the footprint.
I am also not sure to understand the problem of having
ldr_this_cpuaround.
Quoted 1 line
The macro is simple and in any case, you would still require at least a
load
Quoted 3 lines
for the bitmask.
Feel free to suggest an assembly version for the bitmask.
OK, this is very simple, the first that came to mind, I am sure you can improve it:
// 65 is the cpu number, in this example MOV X1, #65 // X1 tells us which doubleword to consider // X2 has the bit shift for right doubleword // X3 is the shifted X2, we'll use it to check the bitmask AND X2, X1, #(64-1) LSR X1, X1, #3 MOV X3, #0x1 LSL X3, X3, X2
Quoted 9 lines
// we load the pointer to the bitmask in X4
LDR X4, =cpumask
// increase the pointer to point to the right doubleword
ADD X4, X4, X1
// load the doubleword
LDR X4, [X4]
// mask with X3, the result is in X1
AND X1, X4, X3Well, because of the SMCC v1.1 convention, you can only use x0-x3. So x4 is a no go.
You also cannot use x1 because it contains the enable/disable boolean.
Furthermore ldr_this_cpu is only 3 instructions. With your current solution, you have 9 instructions.
Even optimized, I honestly doubt you will manage 3 instructions. This is 30% more instructions!
So you are maybe going to save few bytes in memory, but everytime you execute the SMC you will lose some time. As this is happening at every entry/exit from EL0, this will have a significant impact on your workload.
At this stage, I will keep with the percpu variable. That's the best trade-off between performance and footprint.
Cheers,
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 05/13] xen/arm: Add command line option to control SSBD mitigation
In reply to Julien GrallQuoted 11 lines · Julien Grall
xen/include/asm-arm/cpuerrata.h +7
-0+extern enum ssbd_state ssbd_state; + +static inline enum ssbd_state get_ssbd_state (void ) +{ +return ssbd_state; +} +DECLARE_PER_CPU (register_t, ssbd_callback_required);static inline bool cpu_require_ssbd_mitigation (void )
xen/include/asm-arm/cpuerrata.h static inline bool cpu_require_ssbd_mitigation(void) · line 68
Quoted 4 lines
xen/include/asm-arm/cpuerrata.h +1
-0@@ -49,6 +65,11 @@ static inline bool cpu_require_ssbd_mitigation(void)return false; } +static inline enum ssbd_state get_sbdd_state (void )
The function name is mispelled
xen/include/asm-arm/cpuerrata.h static inline bool cpu_require_ssbd_mitigation(void) · line 73
Quoted 5 lines
xen/include/asm-arm/cpuerrata.h +4
-0+{ +return ARM_SSBD_UNKNOWN ; +} +#endif
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 05/13] xen/arm: Add command line option to control SSBD mitigation
Hi Stefano,
Quoted 10 lines · Stefano Stabellini
Quoted 9 lines · Julien Grall
xen/include/asm-arm/cpuerrata.h +7
-0+extern enum ssbd_state ssbd_state; + +static inline enum ssbd_state get_ssbd_state (void ) +{ +return ssbd_state; +} +DECLARE_PER_CPU (register_t, ssbd_callback_required);
Quoted 8 lines
xen/include/asm-arm/cpuerrata.h static inline bool cpu_require_ssbd_mitigation(void) · line 68
Quoted 6 lines
static inline bool
cpu_require_ssbd_mitigation(void)xen/include/asm-arm/cpuerrata.h +1
-0@@ -49,6 +65,11 @@ static inline bool cpu_require_ssbd_mitigation(void)return false; } +static inline enum ssbd_state get_sbdd_state (void )The function name is mispelled
Good catch. I will update it.
Cheers,
Quoted 8 lines
Quoted 7 lines
xen/include/asm-arm/cpuerrata.h +4
-0+{ +return ARM_SSBD_UNKNOWN ; +} +#endif
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 6/13 xen/arm: Add ARCH_WORKAROUND_2 support for guests
In reply to Julien GrallIn order to offer ARCH_WORKAROUND_2 support to guests, we need to track the state of the workaround per-vCPU. The field 'pad' in cpu_info is now repurposed to store flags easily accessible in assembly.
As the hypervisor will always run with the workaround enabled, we may need to enable (on guest exit) or disable (on guest entry) the workaround.
A follow-up patch will add fastpath for the workaround for arm64 guests.
This is part of XSA-263.
--- xen/arch/arm/domain.c | 8 ++++++++ xen/arch/arm/traps.c | 20 ++++++++++++++++++++ xen/arch/arm/vsmc.c | 37 +++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/current.h | 6 +++++- 4 files changed, 70 insertions(+), 1 deletion(-)
xen/arch/arm/domain.c +8 -0
@@ -21,6 +21,7 @@#include <xen/wait.h> #include <asm/alternative.h> +#include <asm/cpuerrata.h> #include <asm/cpufeature.h> #include <asm/current.h> #include <asm/event.h>
@@ -575,6 +576,13 @@ int vcpu_initialise(struct vcpu *v)if ( (rc =vcpu_vtimer_init (v)) !=0 ) goto fail; +/* +* The workaround 2 (i.e SSBD mitigation) is enabled by default if +* supported. +*/ +if (get_ssbd_state () ==ARM_SSBD_RUNTIME ) + v->arch.cpu_info->flags |=CPUINFO_WORKAROUND_2_FLAG ; +return rc; fail:
xen/arch/arm/traps.c +20 -0
@@ -2011,10 +2011,23 @@ inject_abt:inject_iabt_exception (regs, gva, hsr.len); } +static inline bool needs_ssbd_flip (struct vcpu *v) +{ +if ( !check_workaround_ssbd () ) +return false; + +return !((v->arch.cpu_info->flags &CPUINFO_WORKAROUND_2_FLAG ) && +cpu_require_ssbd_mitigation ()); +} +static void enter_hypervisor_head (struct cpu_user_regs *regs) {if (guest_mode (regs) ) { +/* If the guest has disabled the workaround, bring it back on. */ +if (needs_ssbd_flip (current) ) +arm_smccc_1_1_smc (ARM_SMCCC_ARCH_WORKAROUND_2_FID ,1 ,NULL ); +/* * If we pended a virtual abort, preserve it until it gets cleared. * See ARM ARM DDI 0487A.j D1.14.3 (Virtual Interrupts) for details,
@@ -2260,6 +2273,13 @@ void leave_hypervisor_tail(void)*/ SYNCHRONIZE_SERROR (SKIP_SYNCHRONIZE_SERROR_ENTRY_EXIT ); +/* +* The hypervisor runs with the workaround always present. +* If the guest wants it disabled, so be it... +*/ +if (needs_ssbd_flip (current) ) +arm_smccc_1_1_smc (ARM_SMCCC_ARCH_WORKAROUND_2_FID ,0 ,NULL ); +return ; }local_irq_enable ();
xen/arch/arm/vsmc.c +37 -0
@@ -18,6 +18,7 @@#include <xen/lib.h> #include <xen/types.h> #include <public/arch-arm/smccc.h> +#include <asm/cpuerrata.h> #include <asm/cpufeature.h> #include <asm/monitor.h> #include <asm/regs.h>
@@ -104,6 +105,23 @@ static bool handle_arch(struct cpu_user_regs *regs)if (cpus_have_cap (ARM_HARDEN_BRANCH_PREDICTOR ) ) ret =0 ;break ; +case ARM_SMCCC_ARCH_WORKAROUND_2_FID : +switch (get_ssbd_state () ) + { +case ARM_SSBD_UNKNOWN : +case ARM_SSBD_FORCE_DISABLE : +break ; + +case ARM_SSBD_RUNTIME : + ret =ARM_SMCCC_SUCCESS ; +break ; + +case ARM_SSBD_FORCE_ENABLE : +case ARM_SSBD_MITIGATED : + ret =ARM_SMCCC_NOT_REQUIRED ; +break ; + } +break ; }set_user_reg (regs,0 , ret);
@@ -114,6 +132,25 @@ static bool handle_arch(struct cpu_user_regs *regs)case ARM_SMCCC_ARCH_WORKAROUND_1_FID :/* No return value */ return true; + +case ARM_SMCCC_ARCH_WORKAROUND_2_FID : + { +bool enable = (uint32_t )get_user_reg (regs,1 ); + +/* +* ARM_WORKAROUND_2_FID should only be called when mitigation +* state can be changed at runtime. +*/ +if (unlikely (get_ssbd_state () !=ARM_SSBD_RUNTIME ) ) +return true; + +if ( enable ) +get_cpu_info ()->flags |=CPUINFO_WORKAROUND_2_FLAG ; +else +get_cpu_info ()->flags &= ~CPUINFO_WORKAROUND_2_FLAG ; + +return true; + } }return false;
xen/include/asm-arm/current.h +5 -1
@@ -7,6 +7,10 @@#include <asm/percpu.h> #include <asm/processor.h> +/* Tell whether the guest vCPU enabled Workaround 2 (i.e variant 4) */ +#define CPUINFO_WORKAROUND_2_FLAG_SHIFT 0 +#define CPUINFO_WORKAROUND_2_FLAG (_AC(1, U) << CPUINFO_WORKAROUND_2_FLAG_SHIFT) +#ifndef __ASSEMBLY__struct vcpu ;
@@ -21,7 +25,7 @@ DECLARE_PER_CPU(struct vcpu *, curr_vcpu);struct cpu_info {struct cpu_user_regs guest_cpu_user_regs;unsigned long elr; -unsigned int pad; +uint32_t flags; };static inline struct cpu_info *get_cpu_info (void )
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 06/13] xen/arm: Add ARCH_WORKAROUND_2 support for guests
Quoted 51 lines · Julien Grall
In order to offer
ARCH_WORKAROUND_2support to guests, we need to track the state of the workaround per-vCPU. The field 'pad' incpu_infois now repurposed to store flags easily accessible in assembly.As the hypervisor will always run with the workaround enabled, we may need to enable (on guest exit) or disable (on guest entry) the workaround.
A follow-up patch will add fastpath for the workaround for arm64 guests.
This is part of XSA-263.
Signed-off-by Julien Grall <[email protected]>--- xen/arch/arm/domain.c | 8 ++++++++ xen/arch/arm/traps.c | 20 ++++++++++++++++++++ xen/arch/arm/vsmc.c | 37 +++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/current.h | 6 +++++- 4 files changed, 70 insertions(+), 1 deletion(-)xen/arch/arm/domain.c +8
-0@@ -21,6 +21,7 @@#include <xen/wait.h> #include <asm/alternative.h> +#include <asm/cpuerrata.h> #include <asm/cpufeature.h> #include <asm/current.h> #include <asm/event.h> @@ -575,6 +576,13 @@ int vcpu_initialise(struct vcpu *v)if ( (rc =vcpu_vtimer_init (v)) !=0 ) goto fail; +/* +* The workaround 2 (i.e SSBD mitigation) is enabled by default if +* supported. +*/ +if (get_ssbd_state () ==ARM_SSBD_RUNTIME ) + v->arch.cpu_info->flags |=CPUINFO_WORKAROUND_2_FLAG ; +return rc; fail:xen/arch/arm/traps.c +0
-0
xen/arch/arm/traps.c inject_abt: · line 2017
Quoted 7 lines
xen/arch/arm/traps.c +4
-0@@ -2011,10 +2011,23 @@ inject_abt:inject_iabt_exception (regs, gva, hsr.len); } +static inline bool needs_ssbd_flip (struct vcpu *v) +{ +if ( !check_workaround_ssbd () ) +return false;
Why not check on get_ssbd_state() == ARM_SSBD_RUNTIME? I am confused on when is the right time to use the cpu capability check (check_workaround_ssbd), when is the right time to call get_ssbd_state() and when is the right time to call cpu_require_ssbd_mitigation().
xen/arch/arm/traps.c inject_abt: · line 2020
Quoted 2 lines
xen/arch/arm/traps.c +2
-0+return !((v->arch.cpu_info->flags &CPUINFO_WORKAROUND_2_FLAG ) && +cpu_require_ssbd_mitigation ());
It looks like this won't do as intended when v->arch.cpu_info->flags = 0 and cpu_require_ssbd_mitigation() returns false, am I right?
Maybe needs_ssbd_flip() should be implemented as follows:
return get_ssbd_state() == ARM_SSBD_RUNTIME &&
!(v->arch.cpu_info->flags & CPUINFO_WORKAROUND_2_FLAG)
Quoted 116 lines
xen/arch/arm/traps.c +13
-0+} +static void enter_hypervisor_head (struct cpu_user_regs *regs) {if (guest_mode (regs) ) { +/* If the guest has disabled the workaround, bring it back on. */ +if (needs_ssbd_flip (current) ) +arm_smccc_1_1_smc (ARM_SMCCC_ARCH_WORKAROUND_2_FID ,1 ,NULL ); +/* * If we pended a virtual abort, preserve it until it gets cleared. * See ARM ARM DDI 0487A.j D1.14.3 (Virtual Interrupts) for details, @@ -2260,6 +2273,13 @@ void leave_hypervisor_tail(void)*/ SYNCHRONIZE_SERROR (SKIP_SYNCHRONIZE_SERROR_ENTRY_EXIT ); +/* +* The hypervisor runs with the workaround always present. +* If the guest wants it disabled, so be it... +*/ +if (needs_ssbd_flip (current) ) +arm_smccc_1_1_smc (ARM_SMCCC_ARCH_WORKAROUND_2_FID ,0 ,NULL ); +return ; }local_irq_enable ();xen/arch/arm/vsmc.c +37
-0@@ -18,6 +18,7 @@#include <xen/lib.h> #include <xen/types.h> #include <public/arch-arm/smccc.h> +#include <asm/cpuerrata.h> #include <asm/cpufeature.h> #include <asm/monitor.h> #include <asm/regs.h> @@ -104,6 +105,23 @@ static bool handle_arch(struct cpu_user_regs *regs)if (cpus_have_cap (ARM_HARDEN_BRANCH_PREDICTOR ) ) ret =0 ;break ; +case ARM_SMCCC_ARCH_WORKAROUND_2_FID : +switch (get_ssbd_state () ) + { +case ARM_SSBD_UNKNOWN : +case ARM_SSBD_FORCE_DISABLE : +break ; + +case ARM_SSBD_RUNTIME : + ret =ARM_SMCCC_SUCCESS ; +break ; + +case ARM_SSBD_FORCE_ENABLE : +case ARM_SSBD_MITIGATED : + ret =ARM_SMCCC_NOT_REQUIRED ; +break ; + } +break ; }set_user_reg (regs,0 , ret);@@ -114,6 +132,25 @@ static bool handle_arch(struct cpu_user_regs *regs)case ARM_SMCCC_ARCH_WORKAROUND_1_FID :/* No return value */ return true; + +case ARM_SMCCC_ARCH_WORKAROUND_2_FID : + { +bool enable = (uint32_t )get_user_reg (regs,1 ); + +/* +* ARM_WORKAROUND_2_FID should only be called when mitigation +* state can be changed at runtime. +*/ +if (unlikely (get_ssbd_state () !=ARM_SSBD_RUNTIME ) ) +return true; + +if ( enable ) +get_cpu_info ()->flags |=CPUINFO_WORKAROUND_2_FLAG ; +else +get_cpu_info ()->flags &= ~CPUINFO_WORKAROUND_2_FLAG ; + +return true; + } }return false;xen/include/asm-arm/current.h +5
-1@@ -7,6 +7,10 @@#include <asm/percpu.h> #include <asm/processor.h> +/* Tell whether the guest vCPU enabled Workaround 2 (i.e variant 4) */ +#define CPUINFO_WORKAROUND_2_FLAG_SHIFT 0 +#define CPUINFO_WORKAROUND_2_FLAG (_AC(1, U) << CPUINFO_WORKAROUND_2_FLAG_SHIFT) +#ifndef __ASSEMBLY__struct vcpu ;@@ -21,7 +25,7 @@ DECLARE_PER_CPU(struct vcpu *, curr_vcpu);struct cpu_info {struct cpu_user_regs guest_cpu_user_regs;unsigned long elr; -unsigned int pad; +uint32_t flags; };static inline struct cpu_info *get_cpu_info (void )Signature · 1 line
2.11.0
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 06/13] xen/arm: Add ARCH_WORKAROUND_2 support for guests
Quoted 69 lines · Stefano Stabellini
Quoted 51 lines · Julien Grall
In order to offer
ARCH_WORKAROUND_2support to guests, we need to track the state of the workaround per-vCPU. The field 'pad' incpu_infois now repurposed to store flags easily accessible in assembly.As the hypervisor will always run with the workaround enabled, we may need to enable (on guest exit) or disable (on guest entry) the workaround.
A follow-up patch will add fastpath for the workaround for arm64 guests.
This is part of XSA-263.
Signed-off-by Julien Grall <[email protected]>--- xen/arch/arm/domain.c | 8 ++++++++ xen/arch/arm/traps.c | 20 ++++++++++++++++++++ xen/arch/arm/vsmc.c | 37 +++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/current.h | 6 +++++- 4 files changed, 70 insertions(+), 1 deletion(-)xen/arch/arm/domain.c +8
-0@@ -21,6 +21,7 @@#include <xen/wait.h> #include <asm/alternative.h> +#include <asm/cpuerrata.h> #include <asm/cpufeature.h> #include <asm/current.h> #include <asm/event.h> @@ -575,6 +576,13 @@ int vcpu_initialise(struct vcpu *v)if ( (rc =vcpu_vtimer_init (v)) !=0 ) goto fail; +/* +* The workaround 2 (i.e SSBD mitigation) is enabled by default if +* supported. +*/ +if (get_ssbd_state () ==ARM_SSBD_RUNTIME ) + v->arch.cpu_info->flags |=CPUINFO_WORKAROUND_2_FLAG ; +return rc; fail:xen/arch/arm/traps.c +0
-0xen/arch/arm/traps.c inject_abt: · line 2017
Quoted 7 lines
xen/arch/arm/traps.c +4
-0@@ -2011,10 +2011,23 @@ inject_abt:inject_iabt_exception (regs, gva, hsr.len); } +static inline bool needs_ssbd_flip (struct vcpu *v) +{ +if ( !check_workaround_ssbd () ) +return false;Why not check on
get_ssbd_state()==ARM_SSBD_RUNTIME? I am confused on when is the right time to use the cpu capability check (check_workaround_ssbd), when is the right time to callget_ssbd_state()and when is the right time to callcpu_require_ssbd_mitigation().xen/arch/arm/traps.c inject_abt: · line 2020
Quoted 2 lines
xen/arch/arm/traps.c +2
-0+return !((v->arch.cpu_info->flags &CPUINFO_WORKAROUND_2_FLAG ) && +cpu_require_ssbd_mitigation ());
Quoted 7 lines
It looks like this won't do as intended when
v->arch.cpu_info->flags= 0 andcpu_require_ssbd_mitigation()returns false, am I right?Maybe
needs_ssbd_flip()should be implemented as follows:return
get_ssbd_state()==ARM_SSBD_RUNTIME&&!(v->arch.cpu_info->flags & CPUINFO_WORKAROUND_2_FLAG)
With the intention of supporting systems where not all CPUs need/have the workaround, then it should be:
return cpu_require_ssbd_mitigation() &&
!(v->arch.cpu_info->flags & CPUINFO_WORKAROUND_2_FLAG)
Quoted 112 lines
Quoted 112 lines
xen/arch/arm/traps.c +13
-0+} +static void enter_hypervisor_head (struct cpu_user_regs *regs) {if (guest_mode (regs) ) { +/* If the guest has disabled the workaround, bring it back on. */ +if (needs_ssbd_flip (current) ) +arm_smccc_1_1_smc (ARM_SMCCC_ARCH_WORKAROUND_2_FID ,1 ,NULL ); +/* * If we pended a virtual abort, preserve it until it gets cleared. * See ARM ARM DDI 0487A.j D1.14.3 (Virtual Interrupts) for details, @@ -2260,6 +2273,13 @@ void leave_hypervisor_tail(void)*/ SYNCHRONIZE_SERROR (SKIP_SYNCHRONIZE_SERROR_ENTRY_EXIT ); +/* +* The hypervisor runs with the workaround always present. +* If the guest wants it disabled, so be it... +*/ +if (needs_ssbd_flip (current) ) +arm_smccc_1_1_smc (ARM_SMCCC_ARCH_WORKAROUND_2_FID ,0 ,NULL ); +return ; }local_irq_enable ();xen/arch/arm/vsmc.c +37
-0@@ -18,6 +18,7 @@#include <xen/lib.h> #include <xen/types.h> #include <public/arch-arm/smccc.h> +#include <asm/cpuerrata.h> #include <asm/cpufeature.h> #include <asm/monitor.h> #include <asm/regs.h> @@ -104,6 +105,23 @@ static bool handle_arch(struct cpu_user_regs *regs)if (cpus_have_cap (ARM_HARDEN_BRANCH_PREDICTOR ) ) ret =0 ;break ; +case ARM_SMCCC_ARCH_WORKAROUND_2_FID : +switch (get_ssbd_state () ) + { +case ARM_SSBD_UNKNOWN : +case ARM_SSBD_FORCE_DISABLE : +break ; + +case ARM_SSBD_RUNTIME : + ret =ARM_SMCCC_SUCCESS ; +break ; + +case ARM_SSBD_FORCE_ENABLE : +case ARM_SSBD_MITIGATED : + ret =ARM_SMCCC_NOT_REQUIRED ; +break ; + } +break ; }set_user_reg (regs,0 , ret);@@ -114,6 +132,25 @@ static bool handle_arch(struct cpu_user_regs *regs)case ARM_SMCCC_ARCH_WORKAROUND_1_FID :/* No return value */ return true; + +case ARM_SMCCC_ARCH_WORKAROUND_2_FID : + { +bool enable = (uint32_t )get_user_reg (regs,1 ); + +/* +* ARM_WORKAROUND_2_FID should only be called when mitigation +* state can be changed at runtime. +*/ +if (unlikely (get_ssbd_state () !=ARM_SSBD_RUNTIME ) ) +return true; + +if ( enable ) +get_cpu_info ()->flags |=CPUINFO_WORKAROUND_2_FLAG ; +else +get_cpu_info ()->flags &= ~CPUINFO_WORKAROUND_2_FLAG ; + +return true; + } }return false;xen/include/asm-arm/current.h +5
-1@@ -7,6 +7,10 @@#include <asm/percpu.h> #include <asm/processor.h> +/* Tell whether the guest vCPU enabled Workaround 2 (i.e variant 4) */ +#define CPUINFO_WORKAROUND_2_FLAG_SHIFT 0 +#define CPUINFO_WORKAROUND_2_FLAG (_AC(1, U) << CPUINFO_WORKAROUND_2_FLAG_SHIFT) +#ifndef __ASSEMBLY__struct vcpu ;@@ -21,7 +25,7 @@ DECLARE_PER_CPU(struct vcpu *, curr_vcpu);struct cpu_info {struct cpu_user_regs guest_cpu_user_regs;unsigned long elr; -unsigned int pad; +uint32_t flags; };
Quoted 5 lines
Quoted 4 lines
xen/include/asm-arm/current.h +0
-0static inline struct cpu_info *get_cpu_info (void )Signature · 1 line
2.11.0
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 06/13] xen/arm: Add ARCH_WORKAROUND_2 support for guests
Hi Stefano,
Quoted 56 lines · Stefano Stabellini
Quoted 55 lines · Stefano Stabellini
Quoted 54 lines · Julien Grall
In order to offer
ARCH_WORKAROUND_2support to guests, we need to track the state of the workaround per-vCPU. The field 'pad' incpu_infois now repurposed to store flags easily accessible in assembly.As the hypervisor will always run with the workaround enabled, we may need to enable (on guest exit) or disable (on guest entry) the workaround.
A follow-up patch will add fastpath for the workaround for arm64 guests.
This is part of XSA-263.
Signed-off-by Julien Grall <[email protected]>--- xen/arch/arm/domain.c | 8 ++++++++ xen/arch/arm/traps.c | 20 ++++++++++++++++++++ xen/arch/arm/vsmc.c | 37 +++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/current.h | 6 +++++- 4 files changed, 70 insertions(+), 1 deletion(-)xen/arch/arm/domain.c +8
-0@@ -21,6 +21,7 @@#include <xen/wait.h> #include <asm/alternative.h> +#include <asm/cpuerrata.h> #include <asm/cpufeature.h> #include <asm/current.h> #include <asm/event.h> @@ -575,6 +576,13 @@ int vcpu_initialise(struct vcpu *v)if ( (rc =vcpu_vtimer_init (v)) !=0 ) goto fail; +/* +* The workaround 2 (i.e SSBD mitigation) is enabled by default if +* supported. +*/ +if (get_ssbd_state () ==ARM_SSBD_RUNTIME ) + v->arch.cpu_info->flags |=CPUINFO_WORKAROUND_2_FLAG ; +return rc; fail:xen/arch/arm/traps.c +0
-0@@ -2011,10 +2011,23 @@ inject_abt:inject_iabt_exception (regs, gva, hsr.len); }
Quoted 6 lines
Quoted 6 lines
xen/arch/arm/traps.c inject_abt: · line 2017
Quoted 4 lines
xen/arch/arm/traps.c +4
-0+static inline bool needs_ssbd_flip (struct vcpu *v) +{ +if ( !check_workaround_ssbd () ) +return false;Why not check on
get_ssbd_state()==ARM_SSBD_RUNTIME?
get_ssbd_state() would introduce an overhead for each entry/exit even on platform not affected. check_workaround_ssbd() remove this overhead by using an alternative.
Quoted 4 lines
I am confused on
Quoted 3 lines
when is the right time to use the cpu capability check (
check_workaround_ssbd), when is the right time to callget_ssbd_state()and when is the right time to callcpu_require_ssbd_mitigation().
See my answer in the previous patches.
Quoted 10 lines
Quoted 10 lines
xen/arch/arm/traps.c inject_abt: · line 2020
Quoted 4 lines
xen/arch/arm/traps.c +2
-0+return !((v->arch.cpu_info->flags &CPUINFO_WORKAROUND_2_FLAG ) && +cpu_require_ssbd_mitigation ());It looks like this won't do as intended when
v->arch.cpu_info->flags= 0 andcpu_require_ssbd_mitigation()returns false, am I right?Maybe
needs_ssbd_flip()should be implemented as follows:
Quoted 8 lines
Quoted 2 lines
return get_ssbd_state() == ARM_SSBD_RUNTIME && !(v->arch.cpu_info->flags & CPUINFO_WORKAROUND_2_FLAG)With the intention of supporting systems where not all CPUs need/have the workaround, then it should be:
return cpu_require_ssbd_mitigation() && !(v->arch.cpu_info->flags & CPUINFO_WORKAROUND_2_FLAG)
Yes, I did the exact same error I reported to Marc on the KVM side :/. I will update the patch.
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 06/13] xen/arm: Add ARCH_WORKAROUND_2 support for guests
Quoted 64 lines · Julien Grall
Hi Stefano,
Quoted 52 lines · Stefano Stabellini
Quoted 51 lines · Stefano Stabellini
Quoted 50 lines · Julien Grall
In order to offer
ARCH_WORKAROUND_2support to guests, we need to track the
state of the workaround per-vCPU. The field 'pad' incpu_infois now repurposed to store flags easily accessible in assembly.As the hypervisor will always run with the workaround enabled, we may need to enable (on guest exit) or disable (on guest entry) the workaround.
A follow-up patch will add fastpath for the workaround for arm64 guests.
This is part of XSA-263.
Signed-off-by Julien Grall <[email protected]>--- xen/arch/arm/domain.c | 8 ++++++++ xen/arch/arm/traps.c | 20 ++++++++++++++++++++ xen/arch/arm/vsmc.c | 37 +++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/current.h | 6 +++++- 4 files changed, 70 insertions(+), 1 deletion(-)xen/arch/arm/domain.c +7
-0@@ -21,6 +21,7 @@#include <xen/wait.h> #include <asm/alternative.h> +#include <asm/cpuerrata.h> #include <asm/cpufeature.h> #include <asm/current.h> #include <asm/event.h> @@ -575,6 +576,13 @@ int vcpu_initialise(struct vcpu *v)if ( (rc =vcpu_vtimer_init (v)) !=0 ) goto fail; +/* +* The workaround 2 (i.e SSBD mitigation) is enabled by default if +* supported. +*/ + if ( get_ssbd_state() == ARM_SSBD_RUNTIME ) + v->arch.cpu_info->flags |= CPUINFO_WORKAROUND_2_FLAG; +return rc; fail:xen/arch/arm/traps.c +0
-0@@ -2011,10 +2011,23 @@ inject_abt:Quoted 8 lines
Quoted 8 lines
xen/arch/arm/traps.c inject_abt: · line 2017
Quoted 6 lines
xen/arch/arm/traps.c +3
-0inject_iabt_exception (regs, gva, hsr.len); } +static inline bool needs_ssbd_flip(struct vcpu *v) +{ +if ( !check_workaround_ssbd () ) +return false;Why not check on
get_ssbd_state()==ARM_SSBD_RUNTIME?
Quoted 3 lines
get_ssbd_state()would introduce an overhead for each entry/exit even on platform not affected.check_workaround_ssbd()remove this overhead by using an alternative.
Ah yes, great idea.
Quoted 6 lines
Quoted 4 lines
I am confused on
Quoted 3 lines
when is the right time to use the cpu capability check (
check_workaround_ssbd), when is the right time to callget_ssbd_state()and when is the right time to callcpu_require_ssbd_mitigation().See my answer in the previous patches.
I understand now, I didn't realize we wanted to go into the details of improving big.LITTLE scenarios with different erratas on the differnt CPUs.
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
xen/arch/arm/traps.c inject_abt: · line 2020
Quoted 4 lines
xen/arch/arm/traps.c +2
-0+return !((v->arch.cpu_info->flags &CPUINFO_WORKAROUND_2_FLAG ) && +cpu_require_ssbd_mitigation ());It looks like this won't do as intended when
v->arch.cpu_info->flags= 0 andcpu_require_ssbd_mitigation()returns false, am I right?Maybe
needs_ssbd_flip()should be implemented as follows:return get_ssbd_state() == ARM_SSBD_RUNTIME && !(v->arch.cpu_info->flags & CPUINFO_WORKAROUND_2_FLAG)
Quoted 8 lines
Quoted 5 lines
With the intention of supporting systems where not all CPUs need/have the workaround, then it should be:
return cpu_require_ssbd_mitigation() && !(v->arch.cpu_info->flags & CPUINFO_WORKAROUND_2_FLAG)Yes, I did the exact same error I reported to Marc on the KVM side :/. I will update the patch.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 7/13 xen/arm: Simplify alternative patching
In reply to Julien GrallThis is part of XSA-263.
---
I am aware of the missing commit message here. I wanted to send the series on the ML to get some feedback first.
--- xen/arch/arm/alternative.c | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-)
xen/arch/arm/alternative.c +13 -22
@@ -97,12 +97,16 @@ static u32 get_alt_insn(const struct alt_instr *alt,/* * The region patched should be read-write to allow __apply_alternatives * to replacing the instructions when necessary. +* +* @update_offset: Offset between the region patched and the writable +* region for the update. 0 if the patched region is writable. */ -static int __apply_alternatives (const struct alt_region *region) +static int __apply_alternatives (const struct alt_region *region, +paddr_t update_offset) {const struct alt_instr *alt; -const u32 *replptr; -u32 *origptr; +const u32 *replptr, *origptr; +u32 *updptr;printk (XENLOG_INFO "alternatives: Patching with alt table %p -> %p\n" , region->begin, region->end);
@@ -118,6 +122,7 @@ static int __apply_alternatives(const struct alt_region *region)BUG_ON (alt->alt_len != alt->orig_len); origptr =ALT_ORIG_PTR (alt); + updptr = (void *)origptr + update_offset; replptr =ALT_REPL_PTR (alt); nr_inst = alt->alt_len /sizeof (insn);
@@ -125,7 +130,7 @@ static int __apply_alternatives(const struct alt_region *region)for ( i =0 ; i < nr_inst; i++ ) { insn =get_alt_insn (alt, origptr + i, replptr + i); - *(origptr + i) =cpu_to_le32 (insn); + *(updptr + i) =cpu_to_le32 (insn); }/* Ensure the new instructions reached the memory and nuke */
@@ -162,9 +167,6 @@ static int __apply_alternatives_multi_stop(void *unused)paddr_t xen_size = _end - _start;unsigned int xen_order =get_order_from_bytes (xen_size);void *xenmap; -struct virtual_region patch_region = { - .list =LIST_HEAD_INIT (patch_region.list), - };BUG_ON (patched);
@@ -178,30 +180,19 @@ static int __apply_alternatives_multi_stop(void *unused)BUG_ON (!xenmap);/* -* If we generate a new branch instruction, the target will be -* calculated in this re-mapped Xen region. So we have to register -* this re-mapped Xen region as a virtual region temporarily. -*/ - patch_region.start = xenmap; - patch_region.end = xenmap + xen_size; -register_virtual_region (&patch_region); - -/* * Find the virtual address of the alternative region in the new * mapping. * alt_instr contains relative offset, so the function * __apply_alternatives will patch in the re-mapped version of * Xen. */ - region.begin = (void *)__alt_instructions - (void *)_start + xenmap; - region.end = (void *)__alt_instructions_end - (void *)_start + xenmap; + region.begin = __alt_instructions; + region.end = __alt_instructions_end; - ret =__apply_alternatives (®ion); + ret =__apply_alternatives (®ion, xenmap - (void *)_start);/* The patching is not expected to fail during boot. */ BUG_ON (ret !=0 ); -unregister_virtual_region (&patch_region); -vunmap (xenmap);/* Barriers provided by the cache flushing */
@@ -235,7 +226,7 @@ int apply_alternatives(const struct alt_instr *start, const struct alt_instr *en .end = end, }; -return __apply_alternatives (®ion); +return __apply_alternatives (®ion,0 ); }/*
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 07/13] xen/arm: Simplify alternative patching
You might want to CC Konrad next time on this patch
Quoted 108 lines · Julien Grall
This is part of XSA-263.
Signed-off-by Julien Grall <[email protected]>---
I am aware of the missing commit message here. I wanted to send the series on the ML to get some feedback first.--- xen/arch/arm/alternative.c | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-)xen/arch/arm/alternative.c +13
-22@@ -97,12 +97,16 @@ static u32 get_alt_insn(const struct alt_instr *alt,/* * The region patched should be read-write to allow __apply_alternatives * to replacing the instructions when necessary. +* +* @update_offset: Offset between the region patched and the writable +* region for the update. 0 if the patched region is writable. */ -static int __apply_alternatives (const struct alt_region *region) +static int __apply_alternatives (const struct alt_region *region, +paddr_t update_offset) {const struct alt_instr *alt; -const u32 *replptr; -u32 *origptr; +const u32 *replptr, *origptr; +u32 *updptr;printk (XENLOG_INFO "alternatives: Patching with alt table %p -> %p\n" , region->begin, region->end);@@ -118,6 +122,7 @@ static int __apply_alternatives(const struct alt_region *region)BUG_ON (alt->alt_len != alt->orig_len); origptr =ALT_ORIG_PTR (alt); + updptr = (void *)origptr + update_offset; replptr =ALT_REPL_PTR (alt); nr_inst = alt->alt_len /sizeof (insn);@@ -125,7 +130,7 @@ static int __apply_alternatives(const struct alt_region *region)for ( i =0 ; i < nr_inst; i++ ) { insn =get_alt_insn (alt, origptr + i, replptr + i); - *(origptr + i) =cpu_to_le32 (insn); + *(updptr + i) =cpu_to_le32 (insn); }/* Ensure the new instructions reached the memory and nuke */ @@ -162,9 +167,6 @@ static int __apply_alternatives_multi_stop(void *unused)paddr_t xen_size = _end - _start;unsigned int xen_order =get_order_from_bytes (xen_size);void *xenmap; -struct virtual_region patch_region = { - .list =LIST_HEAD_INIT (patch_region.list), - };BUG_ON (patched);@@ -178,30 +180,19 @@ static int __apply_alternatives_multi_stop(void *unused)BUG_ON (!xenmap);/* -* If we generate a new branch instruction, the target will be -* calculated in this re-mapped Xen region. So we have to register -* this re-mapped Xen region as a virtual region temporarily. -*/ - patch_region.start = xenmap; - patch_region.end = xenmap + xen_size; -register_virtual_region (&patch_region); - -/* * Find the virtual address of the alternative region in the new * mapping. * alt_instr contains relative offset, so the function * __apply_alternatives will patch in the re-mapped version of * Xen. */ - region.begin = (void *)__alt_instructions - (void *)_start + xenmap; - region.end = (void *)__alt_instructions_end - (void *)_start + xenmap; + region.begin = __alt_instructions; + region.end = __alt_instructions_end; - ret =__apply_alternatives (®ion); + ret =__apply_alternatives (®ion, xenmap - (void *)_start);/* The patching is not expected to fail during boot. */ BUG_ON (ret !=0 ); -unregister_virtual_region (&patch_region); -vunmap (xenmap);/* Barriers provided by the cache flushing */ @@ -235,7 +226,7 @@ int apply_alternatives(const struct alt_instr *start, const struct alt_instr *en .end = end, }; -return __apply_alternatives (®ion); +return __apply_alternatives (®ion,0 ); }/* Signature · 1 line
2.11.0
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 07/13] xen/arm: Simplify alternative patching
Quoted 2 lines · On Fri, 25 May 2018, 22:54 Stefano Stabellini, <[email protected]> wrote:
You might want to CC Konrad next time on this patch
May I ask why? This code falls under Arm maintainership.
Cheers,
Quoted 119 lines · Julien Grall
Quoted 24 lines
This is part of XSA-263.
Signed-off-by Julien Grall <[email protected]>---
I am aware of the missing commit message here. I wanted to send the series on the ML to get some feedback first.--- xen/arch/arm/alternative.c | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-)xen/arch/arm/alternative.c +3
-1@@ -97,12 +97,16 @@ static u32 get_alt_insn(const struct alt_instr *alt,/* * The region patched should be read-write to allow __apply_alternatives * to replacing the instructions when necessary. +* +* @update_offset: Offset between the region patched and the writable +* region for the update. 0 if the patched region is writable. */ -static int __apply_alternatives (const struct alt_region *region)xen/arch/arm/alternative.c static u32 get_alt_insn(const struct alt_instr *alt, · line 111
Quoted 10 lines
xen/arch/arm/alternative.c +4
-2+static int __apply_alternatives(const struct alt_region *region, + paddr_t update_offset) { const struct alt_instr *alt; - const u32 *replptr; - u32 *origptr; + const u32 *replptr, *origptr; + u32 *updptr; printk(XENLOG_INFO "alternatives: Patching with alt table %p ->%p\n",
xen/arch/arm/alternative.c static int __apply_alternatives(const struct
Quoted 2 lines
xen/arch/arm/alternative.c +0
-0region->begin, region->end);@@ -118,6 +122,7 @@ static int __apply_alternatives(const struct
alt_region*region)xen/arch/arm/alternative.c static int __apply_alternatives(const struct
Quoted 8 lines
xen/arch/arm/alternative.c +1
-0BUG_ON (alt->alt_len != alt->orig_len); origptr =ALT_ORIG_PTR (alt); + updptr = (void *)origptr + update_offset; replptr =ALT_REPL_PTR (alt); nr_inst = alt->alt_len /sizeof (insn);@@ -125,7 +130,7 @@ static int __apply_alternatives(const struct
alt_region*region)xen/arch/arm/alternative.c static int __apply_alternatives_multi_stop(void
Quoted 9 lines
xen/arch/arm/alternative.c +1
-1for ( i =0 ; i < nr_inst; i++ ) { insn =get_alt_insn (alt, origptr + i, replptr + i); - *(origptr + i) =cpu_to_le32 (insn); + *(updptr + i) =cpu_to_le32 (insn); }/* Ensure the new instructions reached the memory and nuke */ @@ -162,9 +167,6 @@ static int __apply_alternatives_multi_stop(void*unused)
xen/arch/arm/alternative.c static int __apply_alternatives_multi_stop(void
Quoted 10 lines
xen/arch/arm/alternative.c +0
-3paddr_t xen_size = _end - _start;unsigned int xen_order =get_order_from_bytes (xen_size);void *xenmap; -struct virtual_region patch_region = { - .list =LIST_HEAD_INIT (patch_region.list), - };BUG_ON (patched);@@ -178,30 +180,19 @@ static int __apply_alternatives_multi_stop(void*unused)
xen/arch/arm/alternative.c static int __apply_alternatives_multi_stop(void *unused)
Quoted 5 lines
xen/arch/arm/alternative.c +0
-2BUG_ON (!xenmap);/* -* If we generate a new branch instruction, the target will be -* calculated in this re-mapped Xen region. So we have to register
Quoted 4 lines
xen/arch/arm/alternative.c +0
-4-* this re-mapped Xen region as a virtual region temporarily. -*/ - patch_region.start = xenmap; - patch_region.end = xenmap + xen_size;xen/arch/arm/alternative.c static int __apply_alternatives_multi_stop(void *unused)
Quoted 10 lines
xen/arch/arm/alternative.c +0
-4-register_virtual_region (&patch_region); - -/* * Find the virtual address of the alternative region in the new * mapping. * alt_instr contains relative offset, so the function * __apply_alternatives will patch in the re-mapped version of * Xen. */ - region.begin = (void *)__alt_instructions - (void *)_start +xenmap;
xen/arch/arm/alternative.c static int __apply_alternatives_multi_stop(void · line 197
Quoted 1 line
xen/arch/arm/alternative.c +0
-1- region.end = (void *)__alt_instructions_end - (void *)_start +xenmap;
xen/arch/arm/alternative.c int apply_alternatives(const struct alt_instr
Quoted 14 lines
xen/arch/arm/alternative.c +3
-3+ region.begin = __alt_instructions; + region.end = __alt_instructions_end; - ret =__apply_alternatives (®ion); + ret =__apply_alternatives (®ion, xenmap - (void *)_start);/* The patching is not expected to fail during boot. */ BUG_ON (ret !=0 ); -unregister_virtual_region (&patch_region); -vunmap (xenmap);/* Barriers provided by the cache flushing */ @@ -235,7 +226,7 @@ int apply_alternatives(const struct alt_instr*start, const struct
alt_instr*enQuoted 11 lines
xen/arch/arm/alternative.c +1
-2.end = end, }; -return __apply_alternatives (®ion); +return __apply_alternatives (®ion,0 ); }/* -- 2.11.0
Quoted 4 lines
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 07/13] xen/arm: Simplify alternative patching
Quoted 5 lines · Julien Grall
On Fri, 25 May 2018, 22:54 Stefano Stabellini, <[email protected]> wrote:
You might want to CC Konrad next time on this patchMay I ask why? This code falls under Arm maintainership.
I know, but I appreciate his input if he has time for it
Quoted 108 lines · Julien Grall
> This is part of XSA-263.
>
> Signed-off-by: Julien Grall <[email protected]>
>
> ---
> I am aware of the missing commit message here. I wanted to send the
> series on the ML to get some feedback first.
> ---
> xen/arch/arm/alternative.c | 35 +++++++++++++----------------------
> 1 file changed, 13 insertions(+), 22 deletions(-)
>
> diff --git a/xen/arch/arm/alternative.c b/xen/arch/arm/alternative.c
> index 9ffdc475d6..bd62183def 100644
> --- a/xen/arch/arm/alternative.c
> +++ b/xen/arch/arm/alternative.c
> @@ -97,12 +97,16 @@ static u32 get_alt_insn(const struct alt_instr *alt,
> /*
> * The region patched should be read-write to allow __apply_alternatives
> * to replacing the instructions when necessary.
> + *
> + * @update_offset: Offset between the region patched and the writable
> + * region for the update. 0 if the patched region is writable.
> */
> -static int __apply_alternatives(const struct alt_region *region)
> +static int __apply_alternatives(const struct alt_region *region,
> + paddr_t update_offset)
> {
> const struct alt_instr *alt;
> - const u32 *replptr;
> - u32 *origptr;
> + const u32 *replptr, *origptr;
> + u32 *updptr;
>
> printk(XENLOG_INFO "alternatives: Patching with alt table %p -> %p\n",
> region->begin, region->end);
> @@ -118,6 +122,7 @@ static int __apply_alternatives(const struct alt_region *region)
> BUG_ON(alt->alt_len != alt->orig_len);
>
> origptr = ALT_ORIG_PTR(alt);
> + updptr = (void *)origptr + update_offset;
> replptr = ALT_REPL_PTR(alt);
>
> nr_inst = alt->alt_len / sizeof(insn);
> @@ -125,7 +130,7 @@ static int __apply_alternatives(const struct alt_region *region)
> for ( i = 0; i < nr_inst; i++ )
> {
> insn = get_alt_insn(alt, origptr + i, replptr + i);
> - *(origptr + i) = cpu_to_le32(insn);
> + *(updptr + i) = cpu_to_le32(insn);
> }
>
> /* Ensure the new instructions reached the memory and nuke */
> @@ -162,9 +167,6 @@ static int __apply_alternatives_multi_stop(void *unused)
> paddr_t xen_size = _end - _start;
> unsigned int xen_order = get_order_from_bytes(xen_size);
> void *xenmap;
> - struct virtual_region patch_region = {
> - .list = LIST_HEAD_INIT(patch_region.list),
> - };
>
> BUG_ON(patched);
>
> @@ -178,30 +180,19 @@ static int __apply_alternatives_multi_stop(void *unused)
> BUG_ON(!xenmap);
>
> /*
> - * If we generate a new branch instruction, the target will be
> - * calculated in this re-mapped Xen region. So we have to register
> - * this re-mapped Xen region as a virtual region temporarily.
> - */
> - patch_region.start = xenmap;
> - patch_region.end = xenmap + xen_size;
> - register_virtual_region(&patch_region);
> -
> - /*
> * Find the virtual address of the alternative region in the new
> * mapping.
> * alt_instr contains relative offset, so the function
> * __apply_alternatives will patch in the re-mapped version of
> * Xen.
> */
> - region.begin = (void *)__alt_instructions - (void *)_start + xenmap;
> - region.end = (void *)__alt_instructions_end - (void *)_start + xenmap;
> + region.begin = __alt_instructions;
> + region.end = __alt_instructions_end;
>
> - ret = __apply_alternatives(®ion);
> + ret = __apply_alternatives(®ion, xenmap - (void *)_start);
> /* The patching is not expected to fail during boot. */
> BUG_ON(ret != 0);
>
> - unregister_virtual_region(&patch_region);
> -
> vunmap(xenmap);
>
> /* Barriers provided by the cache flushing */
> @@ -235,7 +226,7 @@ int apply_alternatives(const struct alt_instr *start, const struct alt_instr *en
> .end = end,
> };
>
> - return __apply_alternatives(®ion);
> + return __apply_alternatives(®ion, 0);
> }
>
> /*Quoted 11 lines
> --
> 2.11.0
>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 07/13] xen/arm: Simplify alternative patching
Quoted 8 lines · Stefano Stabellini
Quoted 5 lines · Julien Grall
On Fri, 25 May 2018, 22:54 Stefano Stabellini, <[email protected]> wrote:
You might want to CC Konrad next time on this patchMay I ask why? This code falls under Arm maintainership.
I know, but I appreciate his input if he has time for it
I will, but you could also have CCed him from your first e-mail to give him more time.
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 8/13 xen/arm: alternatives: Add dynamic patching feature
In reply to Julien GrallThis is based on the Linux commit dea5e2a4c5bc "arm64: alternatives: Add dynamic patching feature" written by Marc Zyngier:
We've so far relied on a patching infrastructure that only gave us a single alternative, without any way to provide a range of potential replacement instructions. For a single feature, this is an all or nothing thing.
It would be interesting to have a more flexible grained way of patching the kernel though, where we could dynamically tune the code that gets injected.
In order to achive this, let's introduce a new form of dynamic patching, assiciating a callback to a patching site. This callback gets source and target locations of the patching request, as well as the number of instructions to be patched.
Dynamic patching is declared with the new ALTERNATIVE_CB and alternative_cb directives:
asm volatile(ALTERNATIVE_CB("mov %0, #0\n", callback)
: "r" (v));
or
alternative_cb callback
mov x0, #0
alternative_cb_end
where callback is the C function computing the alternative.
This is patch of XSA-263.
--- xen/arch/arm/alternative.c | 48 +++++++++++++++++++++++++++++---------- xen/include/asm-arm/alternative.h | 44 +++++++++++++++++++++++++++++++---- 2 files changed, 75 insertions(+), 17 deletions(-)
xen/arch/arm/alternative.c +36 -12
@@ -30,6 +30,8 @@#include <asm/byteorder.h> #include <asm/cpufeature.h> #include <asm/insn.h> +/* XXX: Move ARCH_PATCH_INSN_SIZE out of livepatch.h */ +#include <asm/livepatch.h> #include <asm/page.h> /* Override macros from asm/page.h to make them work with mfn_t */
@@ -94,6 +96,23 @@ static u32 get_alt_insn(const struct alt_instr *alt,return insn; } +static void patch_alternative (const struct alt_instr *alt, +const uint32_t *origptr, +uint32_t *updptr,int nr_inst) +{ +const uint32_t *replptr; +unsigned int i; + + replptr =ALT_REPL_PTR (alt); +for ( i =0 ; i < nr_inst; i++ ) + { +uint32_t insn; + + insn =get_alt_insn (alt, origptr + i, replptr + i); + updptr[i] =cpu_to_le32 (insn); + } +} +/* * The region patched should be read-write to allow __apply_alternatives * to replacing the instructions when necessary.
@@ -105,33 +124,38 @@ static int __apply_alternatives(const struct alt_region *region, paddr_t update_offset) {const struct alt_instr *alt; -const u32 *replptr, *origptr; +const u32 *origptr;u32 *updptr; +alternative_cb_t alt_cb;printk (XENLOG_INFO "alternatives: Patching with alt table %p -> %p\n" , region->begin, region->end);for ( alt = region->begin; alt < region->end; alt++ ) { -u32 insn; -int i, nr_inst; +int nr_inst; -if ( !cpus_have_cap (alt->cpufeature) ) +/* Use ARM_CB_PATCH as an unconditional patch */ +if ( alt->cpufeature <ARM_CB_PATCH && + !cpus_have_cap (alt->cpufeature) )continue ; -BUG_ON (alt->alt_len != alt->orig_len); +if ( alt->cpufeature ==ARM_CB_PATCH ) +BUG_ON (alt->alt_len !=0 ); +else +BUG_ON (alt->alt_len != alt->orig_len); origptr =ALT_ORIG_PTR (alt); updptr = (void *)origptr + update_offset; - replptr =ALT_REPL_PTR (alt); - nr_inst = alt->alt_len /sizeof (insn); + nr_inst = alt->orig_len /ARCH_PATCH_INSN_SIZE ; -for ( i =0 ; i < nr_inst; i++ ) - { - insn =get_alt_insn (alt, origptr + i, replptr + i); - *(updptr + i) =cpu_to_le32 (insn); - } +if ( alt->cpufeature <ARM_CB_PATCH ) + alt_cb = patch_alternative; +else + alt_cb =ALT_REPL_PTR (alt); + +alt_cb (alt, origptr, updptr, nr_inst);/* Ensure the new instructions reached the memory and nuke */ clean_and_invalidate_dcache_va_range(origptr,
xen/include/asm-arm/alternative.h +39 -5
99 lines not on this page · raw message
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 08/13] xen/arm: alternatives: Add dynamic patching feature
Quoted 26 lines · Julien Grall
This is based on the Linux commit
dea5e2a4c5bc"arm64: alternatives: Add dynamic patching feature" written by Marc Zyngier:We've so far relied on a patching infrastructure that only gave us a single alternative, without any way to provide a range of potential replacement instructions. For a single feature, this is an all or nothing thing.
It would be interesting to have a more flexible grained way of patching the kernel though, where we could dynamically tune the code that gets injected.
In order to achive this, let's introduce a new form of dynamic patching, assiciating a callback to a patching site. This callback gets source and target locations of the patching request, as well as the number of instructions to be patched.
Dynamic patching is declared with the new
ALTERNATIVE_CBandalternative_cbdirectives:
asm volatile(ALTERNATIVE_CB("mov %0, #0\n", callback)
: "r" (v));
or
alternative_cbcallback
mov x0, #0
alternative_cb_end
Quoted 7 lines
where callback is the C function computing the alternative.
Reviewed-by Christoffer Dall <[email protected]>Reviewed-by Catalin Marinas <[email protected]>Signed-off-by Marc Zyngier <[email protected]>This is patch of XSA-263.
This patch is part of XSA-263.
Quoted 1 line
Signed-off-by Julien Grall <[email protected]>
Quoted 205 lines
--- xen/arch/arm/alternative.c | 48 +++++++++++++++++++++++++++++---------- xen/include/asm-arm/alternative.h | 44 +++++++++++++++++++++++++++++++---- 2 files changed, 75 insertions(+), 17 deletions(-)xen/arch/arm/alternative.c +36
-12@@ -30,6 +30,8 @@#include <asm/byteorder.h> #include <asm/cpufeature.h> #include <asm/insn.h> +/* XXX: Move ARCH_PATCH_INSN_SIZE out of livepatch.h */ +#include <asm/livepatch.h> #include <asm/page.h> /* Override macros from asm/page.h to make them work with mfn_t */ @@ -94,6 +96,23 @@ static u32 get_alt_insn(const struct alt_instr *alt,return insn; } +static void patch_alternative (const struct alt_instr *alt, +const uint32_t *origptr, +uint32_t *updptr,int nr_inst) +{ +const uint32_t *replptr; +unsigned int i; + + replptr =ALT_REPL_PTR (alt); +for ( i =0 ; i < nr_inst; i++ ) + { +uint32_t insn; + + insn =get_alt_insn (alt, origptr + i, replptr + i); + updptr[i] =cpu_to_le32 (insn); + } +} +/* * The region patched should be read-write to allow __apply_alternatives * to replacing the instructions when necessary. @@ -105,33 +124,38 @@ static int __apply_alternatives(const struct alt_region *region, paddr_t update_offset) {const struct alt_instr *alt; -const u32 *replptr, *origptr; +const u32 *origptr;u32 *updptr; +alternative_cb_t alt_cb;printk (XENLOG_INFO "alternatives: Patching with alt table %p -> %p\n" , region->begin, region->end);for ( alt = region->begin; alt < region->end; alt++ ) { -u32 insn; -int i, nr_inst; +int nr_inst; -if ( !cpus_have_cap (alt->cpufeature) ) +/* Use ARM_CB_PATCH as an unconditional patch */ +if ( alt->cpufeature <ARM_CB_PATCH && + !cpus_have_cap (alt->cpufeature) )continue ; -BUG_ON (alt->alt_len != alt->orig_len); +if ( alt->cpufeature ==ARM_CB_PATCH ) +BUG_ON (alt->alt_len !=0 ); +else +BUG_ON (alt->alt_len != alt->orig_len); origptr =ALT_ORIG_PTR (alt); updptr = (void *)origptr + update_offset; - replptr =ALT_REPL_PTR (alt); - nr_inst = alt->alt_len /sizeof (insn); + nr_inst = alt->orig_len /ARCH_PATCH_INSN_SIZE ; -for ( i =0 ; i < nr_inst; i++ ) - { - insn =get_alt_insn (alt, origptr + i, replptr + i); - *(updptr + i) =cpu_to_le32 (insn); - } +if ( alt->cpufeature <ARM_CB_PATCH ) + alt_cb = patch_alternative; +else + alt_cb =ALT_REPL_PTR (alt); + +alt_cb (alt, origptr, updptr, nr_inst);/* Ensure the new instructions reached the memory and nuke */ clean_and_invalidate_dcache_va_range(origptr,xen/include/asm-arm/alternative.h +39
-5@@ -3,6 +3,8 @@#include <asm/cpufeature.h> +#define ARM_CB_PATCH ARM_NCAPS +#ifndef __ASSEMBLY__#include <xen/init.h> @@ -18,16 +20,24 @@ struct alt_instr { };/* Xen: helpers used by common code. */ -#define __ALT_PTR (a,f) ((u32 *)((void *)&(a)->f + (a)->f)) +#define __ALT_PTR (a,f) ((void *)&(a)->f + (a)->f)#define ALT_ORIG_PTR (a) __ALT_PTR(a, orig_offset)#define ALT_REPL_PTR (a) __ALT_PTR(a, alt_offset) +typedef void (*alternative_cb_t )(const struct alt_instr *alt, +const uint32_t *origptr,uint32_t *updptr, +int nr_inst); +void __init apply_alternatives_all (void );int apply_alternatives (const struct alt_instr *start,const struct alt_instr *end); -#define ALTINSTR_ENTRY (feature) \ +#define ALTINSTR_ENTRY (feature, cb) \ " .word 661b - .\n"/* label */ \ + " .if " __stringify(cb) " == 0\n" \" .word 663f - .\n" /* new instruction */ \ +" .else\n" \ + " .word " __stringify(cb) "- .\n" /* callback */ \ +" .endif\n" \ " .hword " __stringify(feature) "\n" /* feature bit */ \" .byte 662b-661b\n" /* source len */ \" .byte 664f-663f\n" /* replacement len */ @@ -45,15 +55,18 @@ int apply_alternatives(const struct alt_instr *start, const struct alt_instr *en* but most assemblers die if insn1 or insn2 have a .inst. This should * be fixed in a binutils release posterior to 2.25.51.0.2 (anything * containing commit 4e4d08cf7399b606 or c1baaddf8861). +* +* Alternatives with callbacks do not generate replacement instructions. */ -#define __ALTERNATIVE_CFG (oldinstr, newinstr, feature, cfg_enabled) \ +#define __ALTERNATIVE_CFG (oldinstr, newinstr, feature, cfg_enabled, cb) \ ".if "__stringify(cfg_enabled)" == 1\n" \ "661:\n\t" \ oldinstr "\n" \ "662:\n" \ ".pushsection .altinstructions,\"a\"\n" \ - ALTINSTR_ENTRY(feature) \ + ALTINSTR_ENTRY(feature,cb) \ ".popsection\n" \ + " .if " __stringify(cb) " == 0\n" \ ".pushsection .altinstr_replacement, \"a\"\n" \ "663:\n\t" \ newinstr "\n" \@@ -61,11 +74,17 @@ int apply_alternatives(const struct alt_instr *start, const struct alt_instr *en".popsection\n\t" \".org . - (664b-663b) + (662b-661b)\n\t" \".org . - (662b-661b) + (664b-663b)\n" \ +".else\n\t" \ +"663:\n\t" \ +"664:\n\t" \ +".endif\n" \ ".endif\n"#define _ALTERNATIVE_CFG (oldinstr, newinstr, feature, cfg, ...) \ - __ALTERNATIVE_CFG(oldinstr, newinstr, feature, IS_ENABLED(cfg)) + __ALTERNATIVE_CFG(oldinstr, newinstr, feature, IS_ENABLED(cfg), 0) +#define ALTERNATIVE_CB (oldinstr, cb) \ + __ALTERNATIVE_CFG(oldinstr, "NOT_AN_INSTRUCTION", ARM_CB_PATCH, 1, cb)#else #include <asm/asm_defns.h> @@ -126,6 +145,14 @@ int apply_alternatives(const struct alt_instr *start, const struct alt_instr *en 663: .endm +.macro alternative_cb cb + .set .Lasm_alt_mode,0 + .pushsection .altinstructions,"a" + altinstruction_entry 661f, \cb, ARM_CB_PATCH, 662f-661f, 0 + .popsection +661: +.endm +/* * Complete an alternative code sequence. */ @@ -135,6 +162,13 @@ int apply_alternatives(const struct alt_instr *start, const struct alt_instr *en .org . - (662b-661b) + (664b-663b) .endm +/* +* Callback-based alternative epilogue +*/ +.macro alternative_cb_end +662: +.endm +#define _ALTERNATIVE_CFG (insn1, insn2, cap, cfg, ...) \ alternative_insn insn1, insn2, cap, IS_ENABLED(cfg)Signature · 1 line
2.11.0
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 9/13 xen/arm64: Add generic assembly macros
In reply to Julien GrallAdd assembly macros to simplify assembly code:
- adr_cpu_info: Get the address to the current cpu_info structure
- ldr_this_cpu: Load a per-cpu value
This is part of XSA-263.
--- xen/include/asm-arm/arm64/macros.h | 25 +++++++++++++++++++++++++ xen/include/asm-arm/macros.h | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 xen/include/asm-arm/arm64/macros.h
xen/include/asm-arm/arm64/macros.h new file +25 -0
@@ -0,0 +1,25 @@ +#ifndef __ASM_ARM_ARM64_MACROS_H +#define __ASM_ARM_ARM64_MACROS_H + +/* +* @dst: Result of get_cpu_info() +*/ + .macro adr_cpu_info, dst + add \dst, sp, #STACK_SIZE + and \dst, \dst, #~(STACK_SIZE - 1) + sub \dst, \dst, #CPUINFO_sizeof + .endm + + /* + * @dst: Result of READ_ONCE(per_cpu(sym, smp_processor_id())) + * @sym: The name of the per-cpu variable + * @tmp: scratch register + */ + .macro ldr_this_cpu, dst, sym, tmp + ldr \dst, =per_cpu__\sym + mrs \tmp, tpidr_el2 + ldr \dst, [\dst, \tmp] + .endm + +#endif /* __ASM_ARM_ARM64_MACROS_H */ +
xen/include/asm-arm/macros.h +1 -1
@@ -8,7 +8,7 @@#if defined (CONFIG_ARM_32 )# include <asm/arm32/macros.h> #elif defined(CONFIG_ARM_64 ) -/* No specific ARM64 macros for now */ +# include <asm/arm64/macros.h> #else # error "unknown ARM variant"#endif
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 09/13] xen/arm64: Add generic assembly macros
Quoted 7 lines · Julien Grall
Add assembly macros to simplify assembly code:
-adr_cpu_info: Get the address to the currentcpu_infostructure
-ldr_this_cpu: Load a per-cpu valueThis is part of XSA-263.
Signed-off-by Julien Grall <[email protected]>
Quoted 53 lines
--- xen/include/asm-arm/arm64/macros.h | 25 +++++++++++++++++++++++++ xen/include/asm-arm/macros.h | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 xen/include/asm-arm/arm64/macros.hxen/include/asm-arm/arm64/macros.h new file +25
-0@@ -0,0 +1,25 @@ +#ifndef __ASM_ARM_ARM64_MACROS_H +#define __ASM_ARM_ARM64_MACROS_H + +/* +* @dst: Result of get_cpu_info() +*/ + .macro adr_cpu_info, dst + add \dst, sp, #STACK_SIZE + and \dst, \dst, #~(STACK_SIZE - 1) + sub \dst, \dst, #CPUINFO_sizeof + .endm + + /* + * @dst: Result of READ_ONCE(per_cpu(sym, smp_processor_id())) + * @sym: The name of the per-cpu variable + * @tmp: scratch register + */ + .macro ldr_this_cpu, dst, sym, tmp + ldr \dst, =per_cpu__\sym + mrs \tmp, tpidr_el2 + ldr \dst, [\dst, \tmp] + .endm + +#endif /* __ASM_ARM_ARM64_MACROS_H */ +xen/include/asm-arm/macros.h +1
-1@@ -8,7 +8,7 @@#if defined (CONFIG_ARM_32 )# include <asm/arm32/macros.h> #elif defined(CONFIG_ARM_64 ) -/* No specific ARM64 macros for now */ +# include <asm/arm64/macros.h> #else # error "unknown ARM variant"#endif Signature · 1 line
2.11.0
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 10/13 xen/arm64: Implement a fast path for handling SMCCC_ARCH_WORKAROUND_2
In reply to Julien GrallThe function ARM_SMCCC_ARCH_WORKAROUND_2 will be called by the guest for enabling/disabling the ssbd mitigation. So we want the handling to be as fast as possible.
The new sequence will forward guest's ARCH_WORKAROUND_2 call to EL3 and also track the state of the workaround per-vCPU.
Note that since we need to execute branches, this always executes after the spectre-v2 mitigation.
This code is based on KVM counterpart "arm64: KVM: Handle guest's ARCH_WORKAROUND_2 requests" written by Marc Zyngier.
This is part of XSA-263.
--- xen/arch/arm/arm64/asm-offsets.c | 2 ++ xen/arch/arm/arm64/entry.S | 43 +++++++++++++++++++++++++++++++++++++++- xen/arch/arm/cpuerrata.c | 18 +++++++++++++++++ 3 files changed, 62 insertions(+), 1 deletion(-)
xen/arch/arm/arm64/asm-offsets.c +2 -0
@@ -22,6 +22,7 @@void __dummy__ (void ) { OFFSET(UREGS_X0, struct cpu_user_regs, x0); + OFFSET(UREGS_X1, struct cpu_user_regs, x1); OFFSET(UREGS_LR, struct cpu_user_regs, lr); OFFSET(UREGS_SP, struct cpu_user_regs, sp);
@@ -45,6 +46,7 @@ void __dummy__(void)BLANK ();DEFINE (CPUINFO_sizeof,sizeof (struct cpu_info )); + OFFSET(CPUINFO_flags, struct cpu_info, flags); OFFSET(VCPU_arch_saved_context, struct vcpu, arch.saved_context);
xen/arch/arm/arm64/entry.S +42 -1
59 lines not on this page · raw message
xen/arch/arm/cpuerrata.c +18 -0
@@ -7,6 +7,7 @@#include <xen/warning.h> #include <asm/cpufeature.h> #include <asm/cpuerrata.h> +#include <asm/insn.h> #include <asm/psci.h> /* Override macros from asm/page.h to make them work with mfn_t */
@@ -272,6 +273,23 @@ static int __init parse_spec_ctrl(const char *s) }custom_param ("spec-ctrl" , parse_spec_ctrl); +/* Arm64 only for now as for Arm32 the workaround is currently handled in C. */ +#ifdef CONFIG_ARM_64 +void __init arm_enable_wa2_handling (const struct alt_instr *alt, +const uint32_t *origptr, +uint32_t *updptr,int nr_inst) +{ +BUG_ON (nr_inst !=1 ); + +/* +* Only allow mitigation on guest ARCH_WORKAROUND_2 if the SSBD +* state allow it to be flipped. +*/ +if (get_ssbd_state () ==ARM_SSBD_RUNTIME ) + *updptr =aarch64_insn_gen_nop (); +} +#endif +/* * Assembly code may use the variable directly, so we need to make sure * it fits in a register.
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 10/13] xen/arm64: Implement a fast path for handling SMCCC_ARCH_WORKAROUND_2
Quoted 10 lines · Julien Grall
The function
ARM_SMCCC_ARCH_WORKAROUND_2will be called by the guest for enabling/disabling the ssbd mitigation. So we want the handling to be as fast as possible.The new sequence will forward guest's
ARCH_WORKAROUND_2call to EL3 and also track the state of the workaround per-vCPU.Note that since we need to execute branches, this always executes after the spectre-v2 mitigation.
Quoted 6 lines
This code is based on KVM counterpart "arm64: KVM: Handle guest's
ARCH_WORKAROUND_2requests" written by Marc Zyngier.This is part of XSA-263.
Signed-off-by Julien Grall <[email protected]>
I think the patch works as intended.
Quoted 47 lines
--- xen/arch/arm/arm64/asm-offsets.c | 2 ++ xen/arch/arm/arm64/entry.S | 43 +++++++++++++++++++++++++++++++++++++++- xen/arch/arm/cpuerrata.c | 18 +++++++++++++++++ 3 files changed, 62 insertions(+), 1 deletion(-)xen/arch/arm/arm64/asm-offsets.c +2
-0@@ -22,6 +22,7 @@void __dummy__ (void ) { OFFSET(UREGS_X0, struct cpu_user_regs, x0); + OFFSET(UREGS_X1, struct cpu_user_regs, x1); OFFSET(UREGS_LR, struct cpu_user_regs, lr); OFFSET(UREGS_SP, struct cpu_user_regs, sp);@@ -45,6 +46,7 @@ void __dummy__(void)BLANK ();DEFINE (CPUINFO_sizeof,sizeof (struct cpu_info )); + OFFSET(CPUINFO_flags, struct cpu_info, flags); OFFSET(VCPU_arch_saved_context, struct vcpu, arch.saved_context);xen/arch/arm/arm64/entry.S +3
-1@@ -1,4 +1,6 @@ #include <asm/asm_defns.h> +#include <asm/current.h> +#include <asm/macros.h> #include <asm/regs.h> #include <asm/alternative.h> #include <asm/smccc.h>@@ -241,7 +243,7 @@ guest_sync: * be encoded as an immediate for cmp. */ eor w0, w0, #ARM_SMCCC_ARCH_WORKAROUND_1_FID - cbnz w0, guest_sync_slowpath + cbnz w0, check_wa2 /* * Clobber both x0 and x1 to prevent leakage. Note that thanks
xen/arch/arm/arm64/entry.S guest_sync: · line 257
Quoted 6 lines
xen/arch/arm/arm64/entry.S +3
-0@@ -250,6 +252,45 @@ guest_sync: mov x1, xzr eret +check_wa2: + /* ARM_SMCCC_ARCH_WORKAROUND_2 handling */ + eor w0, w0, #ARM_SMCCC_ARCH_WORKAROUND_1_FID
We come to check_wa2 after checking on #ARM_SMCCC_ARCH_WORKAROUND_1_FID, so maybe we can skip this?
Quoted 16 lines
xen/arch/arm/arm64/entry.S +16
-0+ eor w0, w0, #ARM_SMCCC_ARCH_WORKAROUND_2_FID + cbnz w0, guest_sync_slowpath +#ifdef CONFIG_ARM_SSBD +alternative_cb arm_enable_wa2_handling + b wa2_end +alternative_cb_end + /* Sanitize the argument */ + mov x0, #-(UREGS_kernel_sizeof - UREGS_X1) /* x0 := offset of guest's x1 on the stack */ + ldr x1, [sp, x0] /* Load guest's x1 */ + cmp w1, wzr + cset x1, ne + + /* + * Update the guest flag. At this stage sp point after the field + * guest_cpu_user_regs in cpu_info. + */
xen/arch/arm/arm64/entry.S guest_sync: · line 284
Quoted 10 lines
xen/arch/arm/arm64/entry.S +10
-0+ adr_cpu_info x2 + ldr x0, [x2, #CPUINFO_flags] + bfi x0, x1, #CPUINFO_WORKAROUND_2_FLAG_SHIFT, #1 + str x0, [x2, #CPUINFO_flags] + + /* Check that we actually need to perform the call */ + ldr_this_cpu x0, ssbd_callback_required, x2 + cbz x0, wa2_end + mov w0, #ARM_SMCCC_ARCH_WORKAROUND_2_FID + smc #0
Shouldn't we make the call only if get_cpu_info()->flags changed?
Quoted 50 lines
xen/arch/arm/arm64/entry.S +8
-0+wa2_end: + /* Don't leak data from the SMC call */ + mov x1, xzr + mov x2, xzr + mov x3, xzr +#endif /* !CONFIG_ARM_SSBD */ + mov x0, xzr + eret guest_sync_slowpath: /* * x0/x1 may have been scratch by the fast path above, so avoidxen/arch/arm/cpuerrata.c +18
-0@@ -7,6 +7,7 @@#include <xen/warning.h> #include <asm/cpufeature.h> #include <asm/cpuerrata.h> +#include <asm/insn.h> #include <asm/psci.h> /* Override macros from asm/page.h to make them work with mfn_t */ @@ -272,6 +273,23 @@ static int __init parse_spec_ctrl(const char *s) }custom_param ("spec-ctrl" , parse_spec_ctrl); +/* Arm64 only for now as for Arm32 the workaround is currently handled in C. */ +#ifdef CONFIG_ARM_64 +void __init arm_enable_wa2_handling (const struct alt_instr *alt, +const uint32_t *origptr, +uint32_t *updptr,int nr_inst) +{ +BUG_ON (nr_inst !=1 ); + +/* +* Only allow mitigation on guest ARCH_WORKAROUND_2 if the SSBD +* state allow it to be flipped. +*/ +if (get_ssbd_state () ==ARM_SSBD_RUNTIME ) + *updptr =aarch64_insn_gen_nop (); +} +#endif +/* * Assembly code may use the variable directly, so we need to make sure * it fits in a register. Signature · 1 line
2.11.0
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 10/13] xen/arm64: Implement a fast path for handling SMCCC_ARCH_WORKAROUND_2
Hi Stefano,
Quoted 71 lines · Stefano Stabellini
Quoted 10 lines · Julien Grall
The function
ARM_SMCCC_ARCH_WORKAROUND_2will be called by the guest for enabling/disabling the ssbd mitigation. So we want the handling to be as fast as possible.The new sequence will forward guest's
ARCH_WORKAROUND_2call to EL3 and also track the state of the workaround per-vCPU.Note that since we need to execute branches, this always executes after the spectre-v2 mitigation.
Quoted 6 lines
This code is based on KVM counterpart "arm64: KVM: Handle guest's
ARCH_WORKAROUND_2requests" written by Marc Zyngier.This is part of XSA-263.
Signed-off-by Julien Grall <[email protected]>I think the patch works as intended.
Quoted 50 lines
--- xen/arch/arm/arm64/asm-offsets.c | 2 ++ xen/arch/arm/arm64/entry.S | 43 +++++++++++++++++++++++++++++++++++++++- xen/arch/arm/cpuerrata.c | 18 +++++++++++++++++ 3 files changed, 62 insertions(+), 1 deletion(-)xen/arch/arm/arm64/asm-offsets.c +2
-0@@ -22,6 +22,7 @@void __dummy__ (void ) { OFFSET(UREGS_X0, struct cpu_user_regs, x0); + OFFSET(UREGS_X1, struct cpu_user_regs, x1); OFFSET(UREGS_LR, struct cpu_user_regs, lr); OFFSET(UREGS_SP, struct cpu_user_regs, sp);@@ -45,6 +46,7 @@ void __dummy__(void)BLANK ();DEFINE (CPUINFO_sizeof,sizeof (struct cpu_info )); + OFFSET(CPUINFO_flags, struct cpu_info, flags); OFFSET(VCPU_arch_saved_context, struct vcpu, arch.saved_context);xen/arch/arm/arm64/entry.S +3
-1@@ -1,4 +1,6 @@ #include <asm/asm_defns.h> +#include <asm/current.h> +#include <asm/macros.h> #include <asm/regs.h> #include <asm/alternative.h> #include <asm/smccc.h>@@ -241,7 +243,7 @@ guest_sync: * be encoded as an immediate for cmp. */ eor w0, w0, #ARM_SMCCC_ARCH_WORKAROUND_1_FID - cbnz w0, guest_sync_slowpath + cbnz w0, check_wa2 /* * Clobber both x0 and x1 to prevent leakage. Note that thanks@@ -250,6 +252,45 @@ guest_sync: mov x1, xzr eret
Quoted 6 lines
xen/arch/arm/arm64/entry.S guest_sync: · line 257
Quoted 3 lines
xen/arch/arm/arm64/entry.S +3
-0+check_wa2: + /* ARM_SMCCC_ARCH_WORKAROUND_2 handling */ + eor w0, w0, #ARM_SMCCC_ARCH_WORKAROUND_1_FIDWe come to
check_wa2after checking on #ARM_SMCCC_ARCH_WORKAROUND_1_FID, so maybe we can skip this?
This is necessary. w0 contains "guest x0" xor "ARM_SMCCC_ARCH_WORKAROUND_1_FID". So we first need to revert back the xor to get "guest x0".
Note, it would be possible to combine the 2 xor. Something like:
eor w0, w0, #(ARM_SMCCC_ARCH_WORKAROUND_1_FID ^ ARM_SMCCC_ARCH_WORKAROUND_2_FID).
Which version do you prefer?
Quoted 22 lines
Quoted 22 lines
xen/arch/arm/arm64/entry.S +20
-0+ eor w0, w0, #ARM_SMCCC_ARCH_WORKAROUND_2_FID + cbnz w0, guest_sync_slowpath +#ifdef CONFIG_ARM_SSBD +alternative_cb arm_enable_wa2_handling + b wa2_end +alternative_cb_end + /* Sanitize the argument */ + mov x0, #-(UREGS_kernel_sizeof - UREGS_X1) /* x0 := offset of guest's x1 on the stack */ + ldr x1, [sp, x0] /* Load guest's x1 */ + cmp w1, wzr + cset x1, ne + + /* + * Update the guest flag. At this stage sp point after the field + * guest_cpu_user_regs in cpu_info. + */ + adr_cpu_info x2 + ldr x0, [x2, #CPUINFO_flags] + bfi x0, x1, #CPUINFO_WORKAROUND_2_FLAG_SHIFT, #1 + str x0, [x2, #CPUINFO_flags]
Quoted 8 lines
xen/arch/arm/arm64/entry.S guest_sync: · line 284
Quoted 6 lines
xen/arch/arm/arm64/entry.S +6
-0+ + /* Check that we actually need to perform the call */ + ldr_this_cpu x0, ssbd_callback_required, x2 + cbz x0, wa2_end + mov w0, #ARM_SMCCC_ARCH_WORKAROUND_2_FID + smc #0Shouldn't we make the call only if get_cpu_info()->flags changed?
There are no harm to call ARCH_WORKAROUND_2 if the flag didn't changed. However the guest should already avoid to do the call when it is not necessary. So that's not a common case that we should care.
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 10/13] xen/arm64: Implement a fast path for handling SMCCC_ARCH_WORKAROUND_2
Quoted 81 lines · Julien Grall
Hi Stefano,
Quoted 65 lines · Stefano Stabellini
Quoted 10 lines · Julien Grall
The function
ARM_SMCCC_ARCH_WORKAROUND_2will be called by the guest for enabling/disabling the ssbd mitigation. So we want the handling to be as fast as possible.The new sequence will forward guest's
ARCH_WORKAROUND_2call to EL3 and also track the state of the workaround per-vCPU.Note that since we need to execute branches, this always executes after the spectre-v2 mitigation.
Quoted 6 lines
This code is based on KVM counterpart "arm64: KVM: Handle guest's
ARCH_WORKAROUND_2requests" written by Marc Zyngier.This is part of XSA-263.
Signed-off-by Julien Grall <[email protected]>I think the patch works as intended.
Quoted 44 lines
--- xen/arch/arm/arm64/asm-offsets.c | 2 ++ xen/arch/arm/arm64/entry.S | 43 +++++++++++++++++++++++++++++++++++++++- xen/arch/arm/cpuerrata.c | 18 +++++++++++++++++ 3 files changed, 62 insertions(+), 1 deletion(-)xen/arch/arm/arm64/asm-offsets.c +2
-0@@ -22,6 +22,7 @@void __dummy__ (void ) { OFFSET(UREGS_X0, struct cpu_user_regs, x0); + OFFSET(UREGS_X1, struct cpu_user_regs, x1); OFFSET(UREGS_LR, struct cpu_user_regs, lr); OFFSET(UREGS_SP, struct cpu_user_regs, sp);@@ -45,6 +46,7 @@ void __dummy__(void)BLANK ();DEFINE (CPUINFO_sizeof,sizeof (struct cpu_info )); + OFFSET(CPUINFO_flags, struct cpu_info, flags); OFFSET(VCPU_arch_saved_context, struct vcpu, arch.saved_context); diff --git a/xen/arch/arm/arm64/entry.S b/xen/arch/arm/arm64/entry.Sindex
e2344e565f..8e25ff3997100644xen/arch/arm/arm64/entry.S +3
-1@@ -1,4 +1,6 @@ #include <asm/asm_defns.h> +#include <asm/current.h> +#include <asm/macros.h> #include <asm/regs.h> #include <asm/alternative.h> #include <asm/smccc.h>@@ -241,7 +243,7 @@ guest_sync: * be encoded as an immediate for cmp. */ eor w0, w0, #ARM_SMCCC_ARCH_WORKAROUND_1_FID - cbnz w0, guest_sync_slowpath + cbnz w0, check_wa2 /* * Clobber both x0 and x1 to prevent leakage. Note that thanks@@ -250,6 +252,45 @@ guest_sync:Quoted 8 lines
xen/arch/arm/arm64/entry.S guest_sync: · line 257
Quoted 5 lines
xen/arch/arm/arm64/entry.S +2
-0mov x1, xzr eret +check_wa2: + /* ARM_SMCCC_ARCH_WORKAROUND_2 handling */ + eor w0, w0, #ARM_SMCCC_ARCH_WORKAROUND_1_FIDWe come to
check_wa2after checking on #ARM_SMCCC_ARCH_WORKAROUND_1_FID, so maybe we can skip this?This is necessary. w0 contains "guest x0" xor "
ARM_SMCCC_ARCH_WORKAROUND_1_FID". So we first need to revert back the xor to get "guest x0".
Quoted 6 lines
Note, it would be possible to combine the 2 xor. Something like:
eor w0, w0, #(ARM_SMCCC_ARCH_WORKAROUND_1_FID ^
ARM_SMCCC_ARCH_WORKAROUND_2_FID).Which version do you prefer?
I understand now. Let's combine the two xor.
Quoted 31 lines
Quoted 22 lines
Quoted 22 lines
xen/arch/arm/arm64/entry.S +8
-0+ eor w0, w0, #ARM_SMCCC_ARCH_WORKAROUND_2_FID + cbnz w0, guest_sync_slowpath +#ifdef CONFIG_ARM_SSBD +alternative_cb arm_enable_wa2_handling + b wa2_end +alternative_cb_end + /* Sanitize the argument */ + mov x0, #-(UREGS_kernel_sizeof - UREGS_X1) /* x0 := offsetof guest's x1 on the stack */
+ ldr x1, [sp, x0] /* Load guest's
x1 */xen/arch/arm/arm64/entry.S +11
-0+ cmp w1, wzr + cset x1, ne + + /* + * Update the guest flag. At this stage sp point after the field + * guest_cpu_user_regs in cpu_info. + */ + adr_cpu_info x2 + ldr x0, [x2, #CPUINFO_flags] + bfi x0, x1, #CPUINFO_WORKAROUND_2_FLAG_SHIFT, #1 + str x0, [x2, #CPUINFO_flags]Quoted 8 lines
xen/arch/arm/arm64/entry.S guest_sync: · line 284
Quoted 6 lines
xen/arch/arm/arm64/entry.S +6
-0+ + /* Check that we actually need to perform the call */ + ldr_this_cpu x0, ssbd_callback_required, x2 + cbz x0, wa2_end + mov w0, #ARM_SMCCC_ARCH_WORKAROUND_2_FID + smc #0Shouldn't we make the call only if get_cpu_info()->flags changed?
Quoted 3 lines
There are no harm to call
ARCH_WORKAROUND_2if the flag didn't changed. However the guest should already avoid to do the call when it is not necessary. So that's not a common case that we should care.
All right
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 11/13 xen/arm: Kconfig: Move HARDEN_BRANCH_PREDICTOR under "Architecture features"
In reply to Julien GrallAt the moment, HARDEN_BRANCH_PREDICTOR is not in any section making impossible for the user to unselect it.
Also, it looks like we require to use 'expert = "y"' for showing the option in expert mode.
--- xen/arch/arm/Kconfig | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-)
xen/arch/arm/Kconfig +17 -17
@@ -83,6 +83,23 @@ config ARM_SSBD If unsure, say Y. +config HARDEN_BRANCH_PREDICTOR + bool "Harden the branch predictor against aliasing attacks" if EXPERT = "y" + default y + help + Speculation attacks against some high-performance processors rely on + being able to manipulate the branch predictor for a victim context by + executing aliasing branches in the attacker context. Such attacks + can be partially mitigated against by clearing internal branch + predictor state and limiting the prediction logic in some situations. + + This config option will take CPU-specific actions to harden the + branch predictor against aliasing attacks and may rely on specific + instruction sequences or control bits being set by the system + firmware. + + If unsure, say Y. + endmenu menu "ARM errata workaround via the alternative framework"
@@ -197,23 +214,6 @@ config ARM64_ERRATUM_834220 endmenu -config HARDEN_BRANCH_PREDICTOR - bool "Harden the branch predictor against aliasing attacks" if EXPERT - default y - help - Speculation attacks against some high-performance processors rely on - being able to manipulate the branch predictor for a victim context by - executing aliasing branches in the attacker context. Such attacks - can be partially mitigated against by clearing internal branch - predictor state and limiting the prediction logic in some situations. - - This config option will take CPU-specific actions to harden the - branch predictor against aliasing attacks and may rely on specific - instruction sequences or control bits being set by the system - firmware. - - If unsure, say Y. - config ARM64_HARDEN_BRANCH_PREDICTOR def_bool y if ARM_64 && HARDEN_BRANCH_PREDICTOR
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 11/13] xen/arm: Kconfig: Move HARDEN_BRANCH_PREDICTOR under "Architecture features"
Quoted 7 lines · Julien Grall
At the moment,
HARDEN_BRANCH_PREDICTORis not in any section making impossible for the user to unselect it.Also, it looks like we require to use 'expert = "y"' for showing the option in expert mode.
Signed-off-by Julien Grall <[email protected]>
Very useful, thank you!
Quoted 59 lines
--- xen/arch/arm/Kconfig | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-)xen/arch/arm/Kconfig +17
-17@@ -83,6 +83,23 @@ config ARM_SSBD If unsure, say Y. +config HARDEN_BRANCH_PREDICTOR + bool "Harden the branch predictor against aliasing attacks" if EXPERT = "y" + default y + help + Speculation attacks against some high-performance processors rely on + being able to manipulate the branch predictor for a victim context by + executing aliasing branches in the attacker context. Such attacks + can be partially mitigated against by clearing internal branch + predictor state and limiting the prediction logic in some situations. + + This config option will take CPU-specific actions to harden the + branch predictor against aliasing attacks and may rely on specific + instruction sequences or control bits being set by the system + firmware. + + If unsure, say Y. + endmenu menu "ARM errata workaround via the alternative framework"@@ -197,23 +214,6 @@ config ARM64_ERRATUM_834220 endmenu -config HARDEN_BRANCH_PREDICTOR - bool "Harden the branch predictor against aliasing attacks" if EXPERT - default y - help - Speculation attacks against some high-performance processors rely on - being able to manipulate the branch predictor for a victim context by - executing aliasing branches in the attacker context. Such attacks - can be partially mitigated against by clearing internal branch - predictor state and limiting the prediction logic in some situations. - - This config option will take CPU-specific actions to harden the - branch predictor against aliasing attacks and may rely on specific - instruction sequences or control bits being set by the system - firmware. - - If unsure, say Y. - config ARM64_HARDEN_BRANCH_PREDICTOR def_bool y if ARM_64 && HARDEN_BRANCH_PREDICTORSignature · 1 line
2.11.0
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 12/13 xen/arm: smccc: Fix indentation in ARM_SMCCC_ARCH_WORKAROUND_1_FID
In reply to Julien Grall--- xen/include/asm-arm/smccc.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
xen/include/asm-arm/smccc.h +3 -3
@@ -254,9 +254,9 @@ struct arm_smccc_res {#define ARM_SMCCC_ARCH_WORKAROUND_1_FID \ ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ - ARM_SMCCC_CONV_32, \ - ARM_SMCCC_OWNER_ARCH, \ - 0x8000) + ARM_SMCCC_CONV_32, \ + ARM_SMCCC_OWNER_ARCH, \ + 0x8000)#define ARM_SMCCC_ARCH_WORKAROUND_2_FID \ ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 12/13] xen/arm: smccc: Fix indentation in ARM_SMCCC_ARCH_WORKAROUND_1_FID
Quoted 1 line · Julien Grall
Signed-off-by Julien Grall <[email protected]>
Quoted 24 lines
--- xen/include/asm-arm/smccc.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)xen/include/asm-arm/smccc.h +3
-3@@ -254,9 +254,9 @@ struct arm_smccc_res {#define ARM_SMCCC_ARCH_WORKAROUND_1_FID \ ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ - ARM_SMCCC_CONV_32, \ - ARM_SMCCC_OWNER_ARCH, \ - 0x8000) + ARM_SMCCC_CONV_32, \ + ARM_SMCCC_OWNER_ARCH, \ + 0x8000)#define ARM_SMCCC_ARCH_WORKAROUND_2_FID \ ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \Signature · 1 line
2.11.0
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 13/13 xen/arm: Avoid to use current everywhere in enter_hypervisor_head
In reply to Julien GrallUsing current is fairly expensive, so save up into a variable.
--- xen/arch/arm/traps.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
xen/arch/arm/traps.c +8 -6
@@ -2024,8 +2024,10 @@ static void enter_hypervisor_head(struct cpu_user_regs *regs) {if (guest_mode (regs) ) { +struct vcpu *v = current; +/* If the guest has disabled the workaround, bring it back on. */ -if (needs_ssbd_flip (current) ) +if (needs_ssbd_flip (v) )arm_smccc_1_1_smc (ARM_SMCCC_ARCH_WORKAROUND_2_FID ,1 ,NULL );/*
@@ -2034,8 +2036,8 @@ static void enter_hypervisor_head(struct cpu_user_regs *regs)* but the crucial bit is "On taking a vSError interrupt, HCR_EL2.VSE * (alias of HCR.VA) is cleared to 0." */ -if ( current->arch.hcr_el2 &HCR_VA ) - current->arch.hcr_el2 =READ_SYSREG (HCR_EL2 ); +if ( v->arch.hcr_el2 &HCR_VA ) + v->arch.hcr_el2 =READ_SYSREG (HCR_EL2 );#ifdef CONFIG_NEW_VGIC /*
@@ -2045,11 +2047,11 @@ static void enter_hypervisor_head(struct cpu_user_regs *regs)* TODO: Investigate whether this is necessary to do on every * trap and how it can be optimised. */ -vtimer_update_irqs (current); -vcpu_update_evtchn_irq (current); +vtimer_update_irqs (v); +vcpu_update_evtchn_irq (v);#endif -vgic_sync_from_lrs (current); +vgic_sync_from_lrs (v); } }
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 13/13] xen/arm: Avoid to use current everywhere in enter_hypervisor_head
Quoted 3 lines · Julien Grall
Using current is fairly expensive, so save up into a variable.
Signed-off-by Julien Grall <[email protected]>
Good idea. I am curious to know actually how much this patch would save but I am not going to ask you run the tests.
Quoted 49 lines
--- xen/arch/arm/traps.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)xen/arch/arm/traps.c +8
-6@@ -2024,8 +2024,10 @@ static void enter_hypervisor_head(struct cpu_user_regs *regs) {if (guest_mode (regs) ) { +struct vcpu *v = current; +/* If the guest has disabled the workaround, bring it back on. */ -if (needs_ssbd_flip (current) ) +if (needs_ssbd_flip (v) )arm_smccc_1_1_smc (ARM_SMCCC_ARCH_WORKAROUND_2_FID ,1 ,NULL );/* @@ -2034,8 +2036,8 @@ static void enter_hypervisor_head(struct cpu_user_regs *regs)* but the crucial bit is "On taking a vSError interrupt, HCR_EL2.VSE * (alias of HCR.VA) is cleared to 0." */ -if ( current->arch.hcr_el2 &HCR_VA ) - current->arch.hcr_el2 =READ_SYSREG (HCR_EL2 ); +if ( v->arch.hcr_el2 &HCR_VA ) + v->arch.hcr_el2 =READ_SYSREG (HCR_EL2 );#ifdef CONFIG_NEW_VGIC /* @@ -2045,11 +2047,11 @@ static void enter_hypervisor_head(struct cpu_user_regs *regs)* TODO: Investigate whether this is necessary to do on every * trap and how it can be optimised. */ -vtimer_update_irqs (current); -vcpu_update_evtchn_irq (current); +vtimer_update_irqs (v); +vcpu_update_evtchn_irq (v);#endif -vgic_sync_from_lrs (current); +vgic_sync_from_lrs (v); } }Signature · 1 line
2.11.0
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 13/13] xen/arm: Avoid to use current everywhere in enter_hypervisor_head
Hi Stefano,
Quoted 7 lines · Stefano Stabellini
Quoted 3 lines · Julien Grall
Using current is fairly expensive, so save up into a variable.
Signed-off-by Julien Grall <[email protected]>Good idea. I am curious to know actually how much this patch would save but I am not going to ask you run the tests.
I haven't benchmark it but looked at the resulting assembly code. This reduces by about ~20% the number of instructions in the function.
AFAIU, this is because of the way per-cpu access have been implemented. The per-cpu offset is stored in a system register (TPIDR_EL2), all the read to it cannot be optimized (access using volatile).
So every direct use of "current" will require at least a system register access and then a load from memory.
Cheers,
Quoted 52 lines
Reviewed-by Stefano Stabellini <[email protected]>Quoted 49 lines
--- xen/arch/arm/traps.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)xen/arch/arm/traps.c +8
-6@@ -2024,8 +2024,10 @@ static void enter_hypervisor_head(struct cpu_user_regs *regs) {if (guest_mode (regs) ) { +struct vcpu *v = current; +/* If the guest has disabled the workaround, bring it back on. */ -if (needs_ssbd_flip (current) ) +if (needs_ssbd_flip (v) )arm_smccc_1_1_smc (ARM_SMCCC_ARCH_WORKAROUND_2_FID ,1 ,NULL );/* @@ -2034,8 +2036,8 @@ static void enter_hypervisor_head(struct cpu_user_regs *regs)* but the crucial bit is "On taking a vSError interrupt, HCR_EL2.VSE * (alias of HCR.VA) is cleared to 0." */ -if ( current->arch.hcr_el2 &HCR_VA ) - current->arch.hcr_el2 =READ_SYSREG (HCR_EL2 ); +if ( v->arch.hcr_el2 &HCR_VA ) + v->arch.hcr_el2 =READ_SYSREG (HCR_EL2 );#ifdef CONFIG_NEW_VGIC /* @@ -2045,11 +2047,11 @@ static void enter_hypervisor_head(struct cpu_user_regs *regs)* TODO: Investigate whether this is necessary to do on every * trap and how it can be optimised. */ -vtimer_update_irqs (current); -vcpu_update_evtchn_irq (current); +vtimer_update_irqs (v); +vcpu_update_evtchn_irq (v);#endif -vgic_sync_from_lrs (current); +vgic_sync_from_lrs (v); } }Signature · 1 line
2.11.0
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 13/13] xen/arm: Avoid to use current everywhere in enter_hypervisor_head
Quoted 14 lines · Julien Grall
Hi Stefano,
Quoted 7 lines · Stefano Stabellini
Quoted 3 lines · Julien Grall
Using current is fairly expensive, so save up into a variable.
Signed-off-by Julien Grall <[email protected]>Good idea. I am curious to know actually how much this patch would save but I am not going to ask you run the tests.
I haven't benchmark it but looked at the resulting assembly code. This reduces by about ~20% the number of instructions in the function.
Quoted 6 lines
AFAIU, this is because of the way per-cpu access have been implemented. The per-cpu offset is stored in a system register (
TPIDR_EL2), all the read to it cannot be optimized (access using volatile).So every direct use of "current" will require at least a system register access and then a load from memory.
Very nice, thank you!
Quoted 52 lines
Quoted 52 lines
Reviewed-by Stefano Stabellini <[email protected]>Quoted 48 lines
--- xen/arch/arm/traps.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)xen/arch/arm/traps.c +3
-1@@ -2024,8 +2024,10 @@ static void enter_hypervisor_head(struct cpu_user_regs *regs) {if (guest_mode (regs) ) { +struct vcpu *v = current; +/* If the guest has disabled the workaround, bring it back on. */ -if (needs_ssbd_flip (current) ) +if (needs_ssbd_flip (v) )arm_smccc_1_1_smc (ARM_SMCCC_ARCH_WORKAROUND_2_FID ,1 ,NULL );/*xen/arch/arm/traps.c +0
-0@@ -2034,8 +2036,8 @@ static void enter_hypervisor_head(struct cpu_user_regs *regs) * but the crucial bit is "On taking a vSError interrupt,HCR_EL2.VSE
* (alias of HCR.VA) is cleared to 0."
*/xen/arch/arm/traps.c +5
-4-if ( current->arch.hcr_el2 &HCR_VA ) - current->arch.hcr_el2 =READ_SYSREG (HCR_EL2 ); +if ( v->arch.hcr_el2 &HCR_VA ) + v->arch.hcr_el2 =READ_SYSREG (HCR_EL2 );#ifdef CONFIG_NEW_VGIC /* @@ -2045,11 +2047,11 @@ static void enter_hypervisor_head(structcpu_user_regs *regs) * TODO: Investigate whether this is necessary to do on every * trap and how it can be optimised. */ -vtimer_update_irqs (current); -vcpu_update_evtchn_irq (current); +vtimer_update_irqs (v); +vcpu_update_evtchn_irq (v);#endif -vgic_sync_from_lrs (current); +vgic_sync_from_lrs (v); } }
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
Signature · 1 line
2.11.0Signature · 1 line
Julien Grall
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
I forgot to CC Juergen as RM. This series is candidate for Xen 4.11 as part of XSA-263.
Cheers,
Quoted 79 lines · Julien Grall
Hi all,
This patch series implement the Xen hypervisor side of the "Spectre-v4" (CVE-2018-3639) mitigation known as "Speculative Store Bypass Disable" (SSBD).
More information can be found at:
https://bugs.chromium.org/p/project-zero/issues/detail?id=1528 https://developer.arm.com/support/arm-security-updates/speculative-processor-vulnerabilityFor all released Arm Cortex-A that are affected by this issue, then the preferred mitigation is simply to set a chicken bit in the firmware during CPU initialization and therefore no change to Xen is required. Other CPUs may require the chicken bit to be toggled dynamically (for example, when switching between kernel-mode and hypervisor-mode) and this is achieve by calling into EL3 via an SMC which has been published as part of the latest SMCCC specification:
https://developer.arm.com/cache-speculation-vulnerability-firmware-specificationas well as an ATF update for the released ARM cores affected by SSBD:
https://github.com/ARM-software/arm-trusted-firmware/pull/1392These patches provide the following:
1. Safe probing of firmware to establish which CPUs in the system require calling into EL3 as part of the mitigation
2. A command-line option to force SSBD mitigation to be always on, always off, or dynamically toggled (default) for CPUs that require the EL3 call.
3. An initial implementation of the call via Xen, which exposes the mitigation to the guest via an HVC interface.This patch also provides bug fix and new infrastructure require to implement the mitigation:
1. Zeroed each vCPU stack
2. Provide generic assembly macros
3. Provide alternative callback (RFC)A branch can be found with all the patches at:
https://xenbits.xen.org/git-http/people/julieng/xen-unstable.git
branch ssbd/v1Cheers,
Julien Grall (13):
xen/arm: domain: Zeroed the vCPU stack
xen/arm64: entry: Use named label inguest_sync
xen/arm: setup: Check errata for boot CPU later on xen/arm: AddARCH_WORKAROUND_2probing
xen/arm: Add command line option to control SSBD mitigation xen/arm: AddARCH_WORKAROUND_2support for guests xen/arm: Simplify alternative patching
xen/arm: alternatives: Add dynamic patching feature xen/arm64: Add generic assembly macros
xen/arm64: Implement a fast path for handlingSMCCC_ARCH_WORKAROUND_2xen/arm:Kconfig: MoveHARDEN_BRANCH_PREDICTORunder "Architecture
features"
xen/arm: smccc: Fix indentation inARM_SMCCC_ARCH_WORKAROUND_1_FIDxen/arm: Avoid to use current everywhere inenter_hypervisor_headdocs/misc/xen-command-line.markdown | 18 +++++ xen/arch/arm/Kconfig | 44 +++++++---- xen/arch/arm/alternative.c | 79 +++++++++++-------- xen/arch/arm/arm64/asm-offsets.c | 2 + xen/arch/arm/arm64/entry.S | 49 +++++++++++- xen/arch/arm/cpuerrata.c | 150 ++++++++++++++++++++++++++++++++++++ xen/arch/arm/domain.c | 12 +++ xen/arch/arm/setup.c | 8 +- xen/arch/arm/traps.c | 32 ++++++-- xen/arch/arm/vsmc.c | 37 +++++++++ xen/include/asm-arm/alternative.h | 44 +++++++++-- xen/include/asm-arm/arm64/macros.h | 25 ++++++ xen/include/asm-arm/cpuerrata.h | 42 ++++++++++ xen/include/asm-arm/cpufeature.h | 3 +- xen/include/asm-arm/current.h | 6 +- xen/include/asm-arm/macros.h | 2 +- xen/include/asm-arm/smccc.h | 13 +++- 17 files changed, 495 insertions(+), 71 deletions(-)create mode 100644
xen/include/asm-arm/arm64/macros.h
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 2 lines · Julien Grall
I forgot to CC Juergen as RM. This series is candidate for Xen 4.11 as part of XSA-263.
For XSA patches I don't think you need it, but you can have my
for the series, of course.
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel