]> git.baikalelectronics.ru Git - kernel.git/commitdiff
KVM: arm64: Remove host_cpu_context member from vcpu structure
authorMarc Zyngier <maz@kernel.org>
Fri, 5 Jun 2020 13:08:13 +0000 (14:08 +0100)
committerMarc Zyngier <maz@kernel.org>
Tue, 9 Jun 2020 09:59:52 +0000 (10:59 +0100)
For very long, we have kept this pointer back to the per-cpu
host state, despite having working per-cpu accessors at EL2
for some time now.

Recent investigations have shown that this pointer is easy
to abuse in preemptible context, which is a sure sign that
it would better be gone. Not to mention that a per-cpu
pointer is faster to access at all times.

Reported-by: Andrew Scull <ascull@google.com>
Acked-by: Mark Rutland <mark.rutland@arm.com
Reviewed-by: Andrew Scull <ascull@google.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
arch/arm64/include/asm/kvm_host.h
arch/arm64/kvm/arm.c
arch/arm64/kvm/hyp/debug-sr.c
arch/arm64/kvm/hyp/switch.c
arch/arm64/kvm/hyp/sysreg-sr.c
arch/arm64/kvm/pmu.c

index 59029e90b557ebaf31d78e3de17a98670711d1f4..ada1faa92211ba18a1acced660e845065c27a016 100644 (file)
@@ -284,9 +284,6 @@ struct kvm_vcpu_arch {
        struct kvm_guest_debug_arch vcpu_debug_state;
        struct kvm_guest_debug_arch external_debug_state;
 
-       /* Pointer to host CPU context */
-       struct kvm_cpu_context *host_cpu_context;
-
        struct thread_info *host_thread_info;   /* hyp VA */
        struct user_fpsimd_state *host_fpsimd_state;    /* hyp VA */
 
index 14b7472666079e27077f4c399b80f6e88a3ee38f..6ddaa23ef346f19da9bea5171852575a9771c0f8 100644 (file)
@@ -340,10 +340,8 @@ void kvm_arch_vcpu_unblocking(struct kvm_vcpu *vcpu)
 void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
 {
        int *last_ran;
-       kvm_host_data_t *cpu_data;
 
        last_ran = this_cpu_ptr(vcpu->kvm->arch.last_vcpu_ran);
-       cpu_data = this_cpu_ptr(&kvm_host_data);
 
        /*
         * We might get preempted before the vCPU actually runs, but
@@ -355,7 +353,6 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
        }
 
        vcpu->cpu = cpu;
-       vcpu->arch.host_cpu_context = &cpu_data->host_ctxt;
 
        kvm_vgic_load(vcpu);
        kvm_timer_vcpu_load(vcpu);
index 0fc9872a1467107203dfca22867c6887f3eff551..e95af204fec7414df5e0f2d215c4d96912e3558c 100644 (file)
@@ -185,7 +185,7 @@ void __hyp_text __debug_switch_to_guest(struct kvm_vcpu *vcpu)
        if (!(vcpu->arch.flags & KVM_ARM64_DEBUG_DIRTY))
                return;
 
-       host_ctxt = kern_hyp_va(vcpu->arch.host_cpu_context);
+       host_ctxt = &__hyp_this_cpu_ptr(kvm_host_data)->host_ctxt;
        guest_ctxt = &vcpu->arch.ctxt;
        host_dbg = &vcpu->arch.host_debug_state.regs;
        guest_dbg = kern_hyp_va(vcpu->arch.debug_ptr);
@@ -207,7 +207,7 @@ void __hyp_text __debug_switch_to_host(struct kvm_vcpu *vcpu)
        if (!(vcpu->arch.flags & KVM_ARM64_DEBUG_DIRTY))
                return;
 
-       host_ctxt = kern_hyp_va(vcpu->arch.host_cpu_context);
+       host_ctxt = &__hyp_this_cpu_ptr(kvm_host_data)->host_ctxt;
        guest_ctxt = &vcpu->arch.ctxt;
        host_dbg = &vcpu->arch.host_debug_state.regs;
        guest_dbg = kern_hyp_va(vcpu->arch.debug_ptr);
index d60c2ef0fe8c03b745ac73ede2f0a5c717d96990..1853c1788e0c67c87c4db405d1a85a4dcab43427 100644 (file)
@@ -532,7 +532,7 @@ static bool __hyp_text __hyp_handle_ptrauth(struct kvm_vcpu *vcpu)
            !esr_is_ptrauth_trap(kvm_vcpu_get_hsr(vcpu)))
                return false;
 
-       ctxt = kern_hyp_va(vcpu->arch.host_cpu_context);
+       ctxt = &__hyp_this_cpu_ptr(kvm_host_data)->host_ctxt;
        __ptrauth_save_key(ctxt->sys_regs, APIA);
        __ptrauth_save_key(ctxt->sys_regs, APIB);
        __ptrauth_save_key(ctxt->sys_regs, APDA);
@@ -703,7 +703,7 @@ static int __kvm_vcpu_run_vhe(struct kvm_vcpu *vcpu)
        struct kvm_cpu_context *guest_ctxt;
        u64 exit_code;
 
-       host_ctxt = vcpu->arch.host_cpu_context;
+       host_ctxt = &__hyp_this_cpu_ptr(kvm_host_data)->host_ctxt;
        host_ctxt->__hyp_running_vcpu = vcpu;
        guest_ctxt = &vcpu->arch.ctxt;
 
@@ -808,7 +808,7 @@ int __hyp_text __kvm_vcpu_run_nvhe(struct kvm_vcpu *vcpu)
 
        vcpu = kern_hyp_va(vcpu);
 
-       host_ctxt = kern_hyp_va(vcpu->arch.host_cpu_context);
+       host_ctxt = &__hyp_this_cpu_ptr(kvm_host_data)->host_ctxt;
        host_ctxt->__hyp_running_vcpu = vcpu;
        guest_ctxt = &vcpu->arch.ctxt;
 
index 6d2df9fe0b5d2dcc2e1c9b98229079da666c0c50..143d7b7358f2c9d85d3657dd14d9c0c8d8cdaacd 100644 (file)
@@ -265,12 +265,13 @@ void __hyp_text __sysreg32_restore_state(struct kvm_vcpu *vcpu)
  */
 void kvm_vcpu_load_sysregs(struct kvm_vcpu *vcpu)
 {
-       struct kvm_cpu_context *host_ctxt = vcpu->arch.host_cpu_context;
        struct kvm_cpu_context *guest_ctxt = &vcpu->arch.ctxt;
+       struct kvm_cpu_context *host_ctxt;
 
        if (!has_vhe())
                return;
 
+       host_ctxt = &__hyp_this_cpu_ptr(kvm_host_data)->host_ctxt;
        __sysreg_save_user_state(host_ctxt);
 
        /*
@@ -301,12 +302,13 @@ void kvm_vcpu_load_sysregs(struct kvm_vcpu *vcpu)
  */
 void kvm_vcpu_put_sysregs(struct kvm_vcpu *vcpu)
 {
-       struct kvm_cpu_context *host_ctxt = vcpu->arch.host_cpu_context;
        struct kvm_cpu_context *guest_ctxt = &vcpu->arch.ctxt;
+       struct kvm_cpu_context *host_ctxt;
 
        if (!has_vhe())
                return;
 
+       host_ctxt = &__hyp_this_cpu_ptr(kvm_host_data)->host_ctxt;
        deactivate_traps_vhe_put();
 
        __sysreg_save_el1_state(guest_ctxt);
index e71d00bb5271bac281d8068ce10b5d8f36a5cce3..b5ae3a5d509e40f27a83d02093435e1ad93cdebd 100644 (file)
@@ -163,15 +163,13 @@ static void kvm_vcpu_pmu_disable_el0(unsigned long events)
  */
 void kvm_vcpu_pmu_restore_guest(struct kvm_vcpu *vcpu)
 {
-       struct kvm_cpu_context *host_ctxt;
        struct kvm_host_data *host;
        u32 events_guest, events_host;
 
        if (!has_vhe())
                return;
 
-       host_ctxt = vcpu->arch.host_cpu_context;
-       host = container_of(host_ctxt, struct kvm_host_data, host_ctxt);
+       host = this_cpu_ptr(&kvm_host_data);
        events_guest = host->pmu_events.events_guest;
        events_host = host->pmu_events.events_host;
 
@@ -184,15 +182,13 @@ void kvm_vcpu_pmu_restore_guest(struct kvm_vcpu *vcpu)
  */
 void kvm_vcpu_pmu_restore_host(struct kvm_vcpu *vcpu)
 {
-       struct kvm_cpu_context *host_ctxt;
        struct kvm_host_data *host;
        u32 events_guest, events_host;
 
        if (!has_vhe())
                return;
 
-       host_ctxt = vcpu->arch.host_cpu_context;
-       host = container_of(host_ctxt, struct kvm_host_data, host_ctxt);
+       host = this_cpu_ptr(&kvm_host_data);
        events_guest = host->pmu_events.events_guest;
        events_host = host->pmu_events.events_host;