target/arm: Kick the other vCPUs on SEV under TCG round-robin
PATCH 1/1 target/arm: Kick the other vCPUs on SEV under TCG round-robin
In round-robin (single-thread) TCG, all vCPUs share one host thread, so qemu_cpu_is_self() is true for every vCPU.
The SEV helper used it to skip the kick of the issuing vCPU, and so skipped it for every other vCPU too: a vCPU sleeping in WFE is only woken when the RR kick timer fires.
Compare against the issuing vCPU instead.
--- target/arm/tcg/op_helper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
target/arm/tcg/op_helper.c +2 -2
@@ -470,11 +470,11 @@ void HELPER(wfit)(CPUARMState *env, uint32_t rd)void HELPER (sev )(CPUARMState *env) { -CPUState *cs =env_cpu (env); +CPUState *self =env_cpu (env), *cs;CPU_FOREACH (cs) {ARMCPU *target_cpu =ARM_CPU (cs); target_cpu->env.event_register = true; -if (!qemu_cpu_is_self (cs)) { +if (cs != self) {qemu_cpu_kick (cs); } }
Signature · 1 line
2.55.0
Quoted 20 lines · Philippe Mathieu-Daudé
In round-robin (single-thread) TCG, all vCPUs share one host thread, so
qemu_cpu_is_self()is true for every vCPU.The SEV helper used it to skip the kick of the issuing vCPU, and so skipped it for every other vCPU too: a vCPU sleeping in WFE is only woken when the RR kick timer fires.
Compare against the issuing vCPU instead.
Fixes d238858bff60 ("target/arm: Implement WFE, SEV and SEVONPEND")Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/arm/tcg/op_helper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)target/arm/tcg/op_helper.c +0
-0
target/arm/tcg/op_helper.c void HELPER(wfit)(CPUARMState *env, uint32_t rd) · line 473
Quoted 5 lines
target/arm/tcg/op_helper.c +1
-1@@ -470,11 +470,11 @@ void HELPER(wfit)(CPUARMState *env, uint32_t rd)void HELPER (sev )(CPUARMState *env) { -CPUState *cs =env_cpu (env); +CPUState *self =env_cpu (env), *cs;
While rebasing I noticed I did that 1 week before latest ARM PR and this conflicts with c5ec1bfad103 ("target/arm: don't pass env to the sev helper"), then I noticed the previous 8def1f30d5d4 ("target/arm: hold bql when SEV sets the event_register") which is a distinct fix. This patch is still needed but need this to be squashed now:
- CPUState *self = env_cpu(env), *cs;
+ CPUState *self = current_cpu, *cs;
Or even simpler, check @current_cpu in place (no @self local var).
Quoted 8 lines
target/arm/tcg/op_helper.c +1
-1CPU_FOREACH (cs) {ARMCPU *target_cpu =ARM_CPU (cs); target_cpu->env.event_register = true; -if (!qemu_cpu_is_self (cs)) { +if (cs != self) {qemu_cpu_kick (cs); } }
Quoted 35 lines · Philippe Mathieu-Daudé
Quoted 20 lines · Philippe Mathieu-Daudé
In round-robin (single-thread) TCG, all vCPUs share one host thread, so
qemu_cpu_is_self()is true for every vCPU.The SEV helper used it to skip the kick of the issuing vCPU, and so skipped it for every other vCPU too: a vCPU sleeping in WFE is only woken when the RR kick timer fires.
Compare against the issuing vCPU instead.
Fixes d238858bff60 ("target/arm: Implement WFE, SEV and SEVONPEND")Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/arm/tcg/op_helper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)target/arm/tcg/op_helper.c +0
-0target/arm/tcg/op_helper.c void HELPER(wfit)(CPUARMState *env, uint32_t rd) · line 473
Quoted 5 lines
target/arm/tcg/op_helper.c +1
-1@@ -470,11 +470,11 @@ void HELPER(wfit)(CPUARMState *env, uint32_t rd)void HELPER (sev )(CPUARMState *env) { -CPUState *cs =env_cpu (env); +CPUState *self =env_cpu (env), *cs;While rebasing I noticed I did that 1 week before latest ARM PR and this conflicts with
c5ec1bfad103("target/arm: don't pass env to the sev helper"), then I noticed the previous8def1f30d5d4("target/arm: hold bql when SEV sets theevent_register") which is a distinct fix. This patch is still needed but need this to be squashed now:
Quoted 4 lines
- CPUState *self =
env_cpu(env), *cs;
+ CPUState *self =current_cpu, *cs;Or even simpler, check @current_cpu in place (no @self local var).
Generally speaking, I think we should avoid use of current_cpu where we can -- it's an "action at a distance" global variable. If this function needs the CPU pointer for the current CPU then we should revert c5ec1bfad103 so that we pass the env pointer to the helper function again.
thanks
-- PMM
Quoted 40 lines · Peter Maydell
Quoted 38 lines · Philippe Mathieu-Daudé
Quoted 20 lines · Philippe Mathieu-Daudé
In round-robin (single-thread) TCG, all vCPUs share one host thread, so
qemu_cpu_is_self()is true for every vCPU.The SEV helper used it to skip the kick of the issuing vCPU, and so skipped it for every other vCPU too: a vCPU sleeping in WFE is only woken when the RR kick timer fires.
Compare against the issuing vCPU instead.
Fixes d238858bff60 ("target/arm: Implement WFE, SEV and SEVONPEND")Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/arm/tcg/op_helper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)target/arm/tcg/op_helper.c +0
-0target/arm/tcg/op_helper.c void HELPER(wfit)(CPUARMState *env, uint32_t rd) · line 473
Quoted 5 lines
target/arm/tcg/op_helper.c +1
-1@@ -470,11 +470,11 @@ void HELPER(wfit)(CPUARMState *env, uint32_t rd)void HELPER (sev )(CPUARMState *env) { -CPUState *cs =env_cpu (env); +CPUState *self =env_cpu (env), *cs;While rebasing I noticed I did that 1 week before latest ARM PR and this conflicts with
c5ec1bfad103("target/arm: don't pass env to the sev helper"), then I noticed the previous8def1f30d5d4("target/arm: hold bql when SEV sets theevent_register") which is a distinct fix. This patch is still needed but need this to be squashed now:- CPUState *self =
env_cpu(env), *cs;
+ CPUState *self =current_cpu, *cs;
Quoted 7 lines
Quoted 1 line
Or even simpler, check @current_cpu in place (no @self local var).
Generally speaking, I think we should avoid use of
current_cpuwhere we can -- it's an "action at a distance" global variable. If this function needs the CPU pointer for the current CPU then we should revertc5ec1bfad103so that we pass the env pointer to the helper function again.
Thanks for the head up, I concur.
Quoted 38 lines · Philippe Mathieu-Daudé
Quoted 37 lines · Peter Maydell
Quoted 35 lines · Philippe Mathieu-Daudé
Quoted 20 lines · Philippe Mathieu-Daudé
In round-robin (single-thread) TCG, all vCPUs share one host thread, so
qemu_cpu_is_self()is true for every vCPU.The SEV helper used it to skip the kick of the issuing vCPU, and so skipped it for every other vCPU too: a vCPU sleeping in WFE is only woken when the RR kick timer fires.
Compare against the issuing vCPU instead.
Fixes d238858bff60 ("target/arm: Implement WFE, SEV and SEVONPEND")Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
target/arm/tcg/op_helper.c| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)target/arm/tcg/op_helper.c +0
-0target/arm/tcg/op_helper.c void HELPER(wfit)(CPUARMState *env, uint32_t rd) · line 473
Quoted 5 lines
target/arm/tcg/op_helper.c +1
-1@@ -470,11 +470,11 @@ void HELPER(wfit)(CPUARMState *env, uint32_t rd) void HELPER(sev)(CPUARMState *env) { - CPUState *cs = env_cpu(env); + CPUState *self = env_cpu(env), *cs;While rebasing I noticed I did that 1 week before latest ARM PR and this conflicts with
c5ec1bfad103("target/arm: don't pass env to the sev helper"), then I noticed the previous8def1f30d5d4("target/arm: hold bql when SEV sets theevent_register") which is a distinct fix. This patch is still needed but need this to be squashed now:
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
- CPUState *self =
env_cpu(env), *cs;
+ CPUState *self =current_cpu, *cs;Or even simpler, check @current_cpu in place (no @self local var).
Generally speaking, I think we should avoid use of
current_cpuwhere we can -- it's an "action at a distance" global variable.
Besides, that would be the first use of @current_cpu in target/ !
Quoted 7 lines
Quoted 3 lines
If this function needs the CPU pointer for the current CPU then we should revert
c5ec1bfad103so that we pass the env pointer to the helper function again.Thanks for the head up, I concur.
Quoted 2 lines · Philippe Mathieu-Daudé
In round-robin (single-thread) TCG, all vCPUs share one host thread, so
qemu_cpu_is_self()is true for every vCPU.
This makes me think we should check other cases of qemu_cpu_is_self. For example:
void icount_handle_interrupt(CPUState *cpu, int mask)
{
int old_mask = cpu->interrupt_request; tcg_handle_interrupt(cpu, mask);
if (qemu_cpu_is_self(cpu) &&
!cpu->neg.can_do_io
&& (mask & ~old_mask) != 0) {
cpu_abort(cpu, "Raised interrupt while not in I/O function");
}}
Besides current_cpu does change even in rr so why I we testing against thread rather than CPUState?
Quoted 31 lines
The SEV helper used it to skip the kick of the issuing vCPU, and so skipped it for every other vCPU too: a vCPU sleeping in WFE is only woken when the RR kick timer fires.
Compare against the issuing vCPU instead.
Fixes d238858bff60 ("target/arm: Implement WFE, SEV and SEVONPEND")Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/arm/tcg/op_helper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)target/arm/tcg/op_helper.c +2
-2@@ -470,11 +470,11 @@ void HELPER(wfit)(CPUARMState *env, uint32_t rd)void HELPER (sev )(CPUARMState *env) { -CPUState *cs =env_cpu (env); +CPUState *self =env_cpu (env), *cs;CPU_FOREACH (cs) {ARMCPU *target_cpu =ARM_CPU (cs); target_cpu->env.event_register = true; -if (!qemu_cpu_is_self (cs)) { +if (cs != self) {qemu_cpu_kick (cs); } }
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro