]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
KVM: arm64: nv: Accelerate EL0 counter accesses from hypervisor context
authorMarc Zyngier <maz@kernel.org>
Tue, 17 Dec 2024 14:23:14 +0000 (14:23 +0000)
committerMarc Zyngier <maz@kernel.org>
Thu, 2 Jan 2025 19:19:10 +0000 (19:19 +0000)
Similarly to handling the physical timer accesses early when FEAT_ECV
causes a trap, we try to handle the physical counter without returning
to the general sysreg handling.

More surprisingly, we introduce something similar for the virtual
counter. Although this isn't necessary yet, it will prove useful on
systems that have a broken CNTVOFF_EL2 implementation. Yes, they exist.

Acked-by: Oliver Upton <oliver.upton@linux.dev>
Link: https://lore.kernel.org/r/20241217142321.763801-7-maz@kernel.org
Signed-off-by: Marc Zyngier <maz@kernel.org>
arch/arm64/kvm/hyp/vhe/switch.c

index 51119d58ecff86ba183c8099991615e56140ed21..ef344bcff09a1bfde7516afce20877fec4e97659 100644 (file)
@@ -324,6 +324,10 @@ static bool kvm_hyp_handle_timer(struct kvm_vcpu *vcpu, u64 *exit_code)
                        val = __vcpu_sys_reg(vcpu, CNTP_CVAL_EL0);
                }
                break;
+       case SYS_CNTPCT_EL0:
+       case SYS_CNTPCTSS_EL0:
+               val = compute_counter_value(vcpu_hptimer(vcpu));
+               break;
        case SYS_CNTV_CTL_EL02:
                val = compute_emulated_cntx_ctl_el0(vcpu, CNTV_CTL_EL0);
                break;
@@ -342,6 +346,10 @@ static bool kvm_hyp_handle_timer(struct kvm_vcpu *vcpu, u64 *exit_code)
                else
                        val = __vcpu_sys_reg(vcpu, CNTV_CVAL_EL0);
                break;
+       case SYS_CNTVCT_EL0:
+       case SYS_CNTVCTSS_EL0:
+               val = compute_counter_value(vcpu_hvtimer(vcpu));
+               break;
        default:
                return false;
        }