KVM: arm64: Fix hardware enable/disable flows for pKVM
PATCH v2 1/1 KVM: arm64: Fix hardware enable/disable flows for pKVM
When running in protected mode, the hyp stub is disabled after pKVM is initialized, meaning the host cannot enable/disable the hyp at runtime. As such, kvm_arm_hardware_enabled is always 1 after initialization, and kvm_arch_hardware_enable() never enables the vgic maintenance irq or timer irqs.
Unconditionally enable/disable the vgic + timer irqs in the respective calls, instead relying on the percpu bookkeeping in the generic code to keep track of which cpus have the interrupts unmasked.
--- arch/arm64/kvm/arm.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)
arch/arm64/kvm/arm.c +4 -10
@@ -1867,14 +1867,10 @@ static void _kvm_arch_hardware_enable(void *discard)int kvm_arch_hardware_enable (void ) { -int was_enabled =__this_cpu_read (kvm_arm_hardware_enabled); -_kvm_arch_hardware_enable (NULL ); -if (!was_enabled) { -kvm_vgic_cpu_up (); -kvm_timer_cpu_up (); - } +kvm_vgic_cpu_up (); +kvm_timer_cpu_up ();return 0 ; }
@@ -1889,10 +1885,8 @@ static void _kvm_arch_hardware_disable(void *discard)void kvm_arch_hardware_disable (void ) { -if (__this_cpu_read (kvm_arm_hardware_enabled)) { -kvm_timer_cpu_down (); -kvm_vgic_cpu_down (); - } +kvm_timer_cpu_down (); +kvm_vgic_cpu_down ();if (!is_protected_kvm_enabled ())_kvm_arch_hardware_disable (NULL );
Signature · 1 line
2.41.0.487.g6d72f3e995-goog
Quoted 43 lines · Raghavendra Rao Ananta
When running in protected mode, the hyp stub is disabled after pKVM is initialized, meaning the host cannot enable/disable the hyp at runtime. As such,
kvm_arm_hardware_enabledis always 1 after initialization, andkvm_arch_hardware_enable()never enables the vgic maintenance irq or timer irqs.Unconditionally enable/disable the vgic + timer irqs in the respective calls, instead relying on the percpu bookkeeping in the generic code to keep track of which cpus have the interrupts unmasked.
Fixes 466d27e48d7c ("KVM: arm64: Simplify the CPUHP logic")Reported-by Oliver Upton <[email protected]>Suggested-by Oliver Upton <[email protected]>Signed-off-by Raghavendra Rao Ananta <[email protected]>--- arch/arm64/kvm/arm.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)arch/arm64/kvm/arm.c +2
-6@@ -1867,14 +1867,10 @@ static void _kvm_arch_hardware_enable(void *discard)int kvm_arch_hardware_enable (void ) { -int was_enabled =__this_cpu_read (kvm_arm_hardware_enabled); -_kvm_arch_hardware_enable (NULL ); -if (!was_enabled) { -kvm_vgic_cpu_up (); -kvm_timer_cpu_up (); - } +kvm_vgic_cpu_up (); +kvm_timer_cpu_up ();return 0 ; }@@ -1889,10 +1885,8 @@ static void _kvm_arch_hardware_disable(void *discard)void kvm_arch_hardware_disable (void )
arch/arm64/kvm/arm.c static void _kvm_arch_hardware_disable(void *discard) · line 1892
Quoted 10 lines
arch/arm64/kvm/arm.c +2
-4{ -if (__this_cpu_read (kvm_arm_hardware_enabled)) { -kvm_timer_cpu_down (); -kvm_vgic_cpu_down (); - } +kvm_timer_cpu_down (); +kvm_vgic_cpu_down ();if (!is_protected_kvm_enabled ())_kvm_arch_hardware_disable (NULL );
Note that this will likely conflict with the preemption disabling patch that is on its way to upstream. Otherwise:
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
Oliver Upton
AppliedQuoted 11 lines · Raghavendra Rao Ananta
When running in protected mode, the hyp stub is disabled after pKVM is initialized, meaning the host cannot enable/disable the hyp at runtime. As such,
kvm_arm_hardware_enabledis always 1 after initialization, andkvm_arch_hardware_enable()never enables the vgic maintenance irq or timer irqs.Unconditionally enable/disable the vgic + timer irqs in the respective calls, instead relying on the percpu bookkeeping in the generic code to keep track of which cpus have the interrupts unmasked.
[...]
Applied to kvmarm/fixes, thanks!
[1/1] KVM: arm64: Fix hardware enable/disable flows for pKVM
https://git.kernel.org/kvmarm/kvmarm/c/c718ca0e9940
--
Best,
Oliver