KVM: arm64: Introduce a bad_trap() primitive for unexpected trap handling
authorMarc Zyngier <maz@kernel.org>
Mon, 6 Nov 2023 16:42:13 +0000 (16:42 +0000)
committerMarc Zyngier <maz@kernel.org>
Tue, 19 Dec 2023 09:51:24 +0000 (09:51 +0000)
In order to ease the debugging of NV, it is helpful to have the kernel
shout at you when an unexpected trap is handled. We already have this
in a couple of cases. Make this a more generic infrastructure that we
will make use of very shortly.

Reviewed-by: Oliver Upton <oliver.upton@linux.dev>
Signed-off-by: Marc Zyngier <maz@kernel.org>
arch/arm64/kvm/sys_regs.c

index cdfc79ccc7a18698026ebd4e7d1988bef4abae8e..3709c35666a267c61c22d53b2e8bac80707db09a 100644 (file)
@@ -45,24 +45,31 @@ static u64 sys_reg_to_index(const struct sys_reg_desc *reg);
 static int set_id_reg(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd,
                      u64 val);
 
-static bool read_from_write_only(struct kvm_vcpu *vcpu,
-                                struct sys_reg_params *params,
-                                const struct sys_reg_desc *r)
+static bool bad_trap(struct kvm_vcpu *vcpu,
+                    struct sys_reg_params *params,
+                    const struct sys_reg_desc *r,
+                    const char *msg)
 {
-       WARN_ONCE(1, "Unexpected sys_reg read to write-only register\n");
+       WARN_ONCE(1, "Unexpected %s\n", msg);
        print_sys_reg_instr(params);
        kvm_inject_undefined(vcpu);
        return false;
 }
 
+static bool read_from_write_only(struct kvm_vcpu *vcpu,
+                                struct sys_reg_params *params,
+                                const struct sys_reg_desc *r)
+{
+       return bad_trap(vcpu, params, r,
+                       "sys_reg read to write-only register");
+}
+
 static bool write_to_read_only(struct kvm_vcpu *vcpu,
                               struct sys_reg_params *params,
                               const struct sys_reg_desc *r)
 {
-       WARN_ONCE(1, "Unexpected sys_reg write to read-only register\n");
-       print_sys_reg_instr(params);
-       kvm_inject_undefined(vcpu);
-       return false;
+       return bad_trap(vcpu, params, r,
+                       "sys_reg write to read-only register");
 }
 
 u64 vcpu_read_sys_reg(const struct kvm_vcpu *vcpu, int reg)