OSDN Git Service

KVM: arm64: Sanely ratelimit sysreg messages
authorMark Rutland <mark.rutland@arm.com>
Thu, 5 Dec 2019 18:06:51 +0000 (18:06 +0000)
committerMarc Zyngier <maz@kernel.org>
Fri, 6 Dec 2019 11:41:45 +0000 (11:41 +0000)
Currently kvm_pr_unimpl() is ratelimited, so print_sys_reg_instr() won't
spam the console. However, someof its callers try to print some
contextual information with kvm_err(), which is not ratelimited. This
means that in some cases the context may be printed without the sysreg
encoding, which isn't all that useful.

Let's ensure that both are consistently printed together and
ratelimited, by refactoring print_sys_reg_instr() so that some callers
can provide it with an arbitrary format string.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20191205180652.18671-2-mark.rutland@arm.com
arch/arm64/kvm/sys_regs.c
arch/arm64/kvm/sys_regs.h

index 2071260..e8bf08e 100644 (file)
@@ -2094,9 +2094,9 @@ static void unhandled_cp_access(struct kvm_vcpu *vcpu,
                WARN_ON(1);
        }
 
-       kvm_err("Unsupported guest CP%d access at: %08lx [%08lx]\n",
-               cp, *vcpu_pc(vcpu), *vcpu_cpsr(vcpu));
-       print_sys_reg_instr(params);
+       print_sys_reg_msg(params,
+                         "Unsupported guest CP%d access at: %08lx [%08lx]\n",
+                         cp, *vcpu_pc(vcpu), *vcpu_cpsr(vcpu));
        kvm_inject_undefined(vcpu);
 }
 
@@ -2245,9 +2245,9 @@ static int emulate_sys_reg(struct kvm_vcpu *vcpu,
        if (likely(r)) {
                perform_access(vcpu, params, r);
        } else {
-               kvm_err("Unsupported guest sys_reg access at: %lx [%08lx]\n",
-                       *vcpu_pc(vcpu), *vcpu_cpsr(vcpu));
-               print_sys_reg_instr(params);
+               print_sys_reg_msg(params,
+                                 "Unsupported guest sys_reg access at: %lx [%08lx]\n",
+                                 *vcpu_pc(vcpu), *vcpu_cpsr(vcpu));
                kvm_inject_undefined(vcpu);
        }
        return 1;
index 9bca031..5a6fc30 100644 (file)
@@ -62,11 +62,24 @@ struct sys_reg_desc {
 #define REG_HIDDEN_USER                (1 << 0) /* hidden from userspace ioctls */
 #define REG_HIDDEN_GUEST       (1 << 1) /* hidden from guest */
 
-static inline void print_sys_reg_instr(const struct sys_reg_params *p)
+static __printf(2, 3)
+inline void print_sys_reg_msg(const struct sys_reg_params *p,
+                                      char *fmt, ...)
 {
+       va_list va;
+
+       va_start(va, fmt);
        /* Look, we even formatted it for you to paste into the table! */
-       kvm_pr_unimpl(" { Op0(%2u), Op1(%2u), CRn(%2u), CRm(%2u), Op2(%2u), func_%s },\n",
+       kvm_pr_unimpl("%pV { Op0(%2u), Op1(%2u), CRn(%2u), CRm(%2u), Op2(%2u), func_%s },\n",
+                     &(struct va_format){ fmt, &va },
                      p->Op0, p->Op1, p->CRn, p->CRm, p->Op2, p->is_write ? "write" : "read");
+       va_end(va);
+}
+
+static inline void print_sys_reg_instr(const struct sys_reg_params *p)
+{
+       /* GCC warns on an empty format string */
+       print_sys_reg_msg(p, "%s", "");
 }
 
 static inline bool ignore_write(struct kvm_vcpu *vcpu,