KVM: arm64: Sanely ratelimit sysreg messages

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
This commit is contained in:
Mark Rutland 2019-12-05 18:06:51 +00:00 committed by Marc Zyngier
parent 72a610f32e
commit bf4b96bb54
2 changed files with 22 additions and 9 deletions

View File

@ -2094,9 +2094,9 @@ static void unhandled_cp_access(struct kvm_vcpu *vcpu,
WARN_ON(1); WARN_ON(1);
} }
kvm_err("Unsupported guest CP%d access at: %08lx [%08lx]\n", print_sys_reg_msg(params,
cp, *vcpu_pc(vcpu), *vcpu_cpsr(vcpu)); "Unsupported guest CP%d access at: %08lx [%08lx]\n",
print_sys_reg_instr(params); cp, *vcpu_pc(vcpu), *vcpu_cpsr(vcpu));
kvm_inject_undefined(vcpu); kvm_inject_undefined(vcpu);
} }
@ -2245,9 +2245,9 @@ static int emulate_sys_reg(struct kvm_vcpu *vcpu,
if (likely(r)) { if (likely(r)) {
perform_access(vcpu, params, r); perform_access(vcpu, params, r);
} else { } else {
kvm_err("Unsupported guest sys_reg access at: %lx [%08lx]\n", print_sys_reg_msg(params,
*vcpu_pc(vcpu), *vcpu_cpsr(vcpu)); "Unsupported guest sys_reg access at: %lx [%08lx]\n",
print_sys_reg_instr(params); *vcpu_pc(vcpu), *vcpu_cpsr(vcpu));
kvm_inject_undefined(vcpu); kvm_inject_undefined(vcpu);
} }
return 1; return 1;

View File

@ -62,11 +62,24 @@ struct sys_reg_desc {
#define REG_HIDDEN_USER (1 << 0) /* hidden from userspace ioctls */ #define REG_HIDDEN_USER (1 << 0) /* hidden from userspace ioctls */
#define REG_HIDDEN_GUEST (1 << 1) /* hidden from guest */ #define REG_HIDDEN_GUEST (1 << 1) /* hidden from guest */
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("%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) static inline void print_sys_reg_instr(const struct sys_reg_params *p)
{ {
/* Look, we even formatted it for you to paste into the table! */ /* GCC warns on an empty format string */
kvm_pr_unimpl(" { Op0(%2u), Op1(%2u), CRn(%2u), CRm(%2u), Op2(%2u), func_%s },\n", print_sys_reg_msg(p, "%s", "");
p->Op0, p->Op1, p->CRn, p->CRm, p->Op2, p->is_write ? "write" : "read");
} }
static inline bool ignore_write(struct kvm_vcpu *vcpu, static inline bool ignore_write(struct kvm_vcpu *vcpu,