]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
KVM: arm64: Handle RAS SErrors from EL1 on guest exit
authorJames Morse <james.morse@arm.com>
Mon, 15 Jan 2018 19:39:04 +0000 (19:39 +0000)
committerSeth Forshee <seth.forshee@canonical.com>
Fri, 16 Mar 2018 15:45:32 +0000 (10:45 -0500)
BugLink: http://bugs.launchpad.net/bugs/1756096
We expect to have firmware-first handling of RAS SErrors, with errors
notified via an APEI method. For systems without firmware-first, add
some minimal handling to KVM.

There are two ways KVM can take an SError due to a guest, either may be a
RAS error: we exit the guest due to an SError routed to EL2 by HCR_EL2.AMO,
or we take an SError from EL2 when we unmask PSTATE.A from __guest_exit.

For SError that interrupt a guest and are routed to EL2 the existing
behaviour is to inject an impdef SError into the guest.

Add code to handle RAS SError based on the ESR. For uncontained and
uncategorized errors arm64_is_fatal_ras_serror() will panic(), these
errors compromise the host too. All other error types are contained:
For the fatal errors the vCPU can't make progress, so we inject a virtual
SError. We ignore contained errors where we can make progress as if
we're lucky, we may not hit them again.

If only some of the CPUs support RAS the guest will see the cpufeature
sanitised version of the id registers, but we may still take RAS SError
on this CPU. Move the SError handling out of handle_exit() into a new
handler that runs before we can be preempted. This allows us to use
this_cpu_has_cap(), via arm64_is_ras_serror().

Acked-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
(cherry picked from commit 3368bd809764d3ef0810e16c1e1531fec32e8d8e)
Signed-off-by: Manoj Iyer <manoj.iyer@canonical.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
arch/arm/include/asm/kvm_host.h
arch/arm64/include/asm/kvm_host.h
arch/arm64/kvm/handle_exit.c
virt/kvm/arm/arm.c

index 9d43d9d27884b87ee27990ccbec1a8b189450ff0..ef54013b5b9f1ee3f9656e41d0451cbc160cd56e 100644 (file)
@@ -238,6 +238,9 @@ int kvm_arm_coproc_set_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *);
 int handle_exit(struct kvm_vcpu *vcpu, struct kvm_run *run,
                int exception_index);
 
+static inline void handle_exit_early(struct kvm_vcpu *vcpu, struct kvm_run *run,
+                                    int exception_index) {}
+
 static inline void __cpu_init_hyp_mode(phys_addr_t pgd_ptr,
                                       unsigned long hyp_stack_ptr,
                                       unsigned long vector_ptr)
index 9b45196c0ce2f571aed3f677ab00017ba4072116..a9880cbe06dcbbe359d03507f4625b959fa46ef6 100644 (file)
@@ -347,6 +347,8 @@ void kvm_mmu_wp_memory_region(struct kvm *kvm, int slot);
 
 int handle_exit(struct kvm_vcpu *vcpu, struct kvm_run *run,
                int exception_index);
+void handle_exit_early(struct kvm_vcpu *vcpu, struct kvm_run *run,
+                      int exception_index);
 
 int kvm_perf_init(void);
 int kvm_perf_teardown(void);
index c6c59356aa88d267ee8608919fdf3aea561a5df2..6aa0b2bf7280a6d5a82dc36ee34b67fe100de4e2 100644 (file)
 #include <asm/kvm_emulate.h>
 #include <asm/kvm_mmu.h>
 #include <asm/debug-monitors.h>
+#include <asm/traps.h>
 
 #define CREATE_TRACE_POINTS
 #include "trace.h"
 
 typedef int (*exit_handle_fn)(struct kvm_vcpu *, struct kvm_run *);
 
+static void kvm_handle_guest_serror(struct kvm_vcpu *vcpu, u32 esr)
+{
+       if (!arm64_is_ras_serror(esr) || arm64_is_fatal_ras_serror(NULL, esr))
+               kvm_inject_vabt(vcpu);
+}
+
 static int handle_hvc(struct kvm_vcpu *vcpu, struct kvm_run *run)
 {
        int ret;
@@ -262,7 +269,6 @@ int handle_exit(struct kvm_vcpu *vcpu, struct kvm_run *run,
        case ARM_EXCEPTION_IRQ:
                return 1;
        case ARM_EXCEPTION_EL1_SERROR:
-               kvm_inject_vabt(vcpu);
                /* We may still need to return for single-step */
                if (!(*vcpu_cpsr(vcpu) & DBG_SPSR_SS)
                        && kvm_arm_handle_step_debug(vcpu, run))
@@ -285,3 +291,13 @@ int handle_exit(struct kvm_vcpu *vcpu, struct kvm_run *run,
                return 0;
        }
 }
+
+/* For exit types that need handling before we can be preempted */
+void handle_exit_early(struct kvm_vcpu *vcpu, struct kvm_run *run,
+                      int exception_index)
+{
+       exception_index = ARM_EXCEPTION_CODE(exception_index);
+
+       if (exception_index == ARM_EXCEPTION_EL1_SERROR)
+               kvm_handle_guest_serror(vcpu, kvm_vcpu_get_hsr(vcpu));
+}
index f065cfe1c1db821f0dc792cc043fc6000cbecd41..d72589d47a91a44ac3b833173577d00aa9effe2d 100644 (file)
@@ -763,6 +763,9 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
                guest_exit();
                trace_kvm_exit(ret, kvm_vcpu_trap_get_class(vcpu), *vcpu_pc(vcpu));
 
+               /* Exit types that need handling before we can be preempted */
+               handle_exit_early(vcpu, run, ret);
+
                preempt_enable();
 
                ret = handle_exit(vcpu, run, ret);