Skip to content

Commit bf4b96b

Browse files
mrutland-armMarc Zyngier
authored andcommitted
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 <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 72a610f commit bf4b96b

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

arch/arm64/kvm/sys_regs.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2094,9 +2094,9 @@ static void unhandled_cp_access(struct kvm_vcpu *vcpu,
20942094
WARN_ON(1);
20952095
}
20962096

2097-
kvm_err("Unsupported guest CP%d access at: %08lx [%08lx]\n",
2098-
cp, *vcpu_pc(vcpu), *vcpu_cpsr(vcpu));
2099-
print_sys_reg_instr(params);
2097+
print_sys_reg_msg(params,
2098+
"Unsupported guest CP%d access at: %08lx [%08lx]\n",
2099+
cp, *vcpu_pc(vcpu), *vcpu_cpsr(vcpu));
21002100
kvm_inject_undefined(vcpu);
21012101
}
21022102

@@ -2245,9 +2245,9 @@ static int emulate_sys_reg(struct kvm_vcpu *vcpu,
22452245
if (likely(r)) {
22462246
perform_access(vcpu, params, r);
22472247
} else {
2248-
kvm_err("Unsupported guest sys_reg access at: %lx [%08lx]\n",
2249-
*vcpu_pc(vcpu), *vcpu_cpsr(vcpu));
2250-
print_sys_reg_instr(params);
2248+
print_sys_reg_msg(params,
2249+
"Unsupported guest sys_reg access at: %lx [%08lx]\n",
2250+
*vcpu_pc(vcpu), *vcpu_cpsr(vcpu));
22512251
kvm_inject_undefined(vcpu);
22522252
}
22532253
return 1;

arch/arm64/kvm/sys_regs.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,24 @@ struct sys_reg_desc {
6262
#define REG_HIDDEN_USER (1 << 0) /* hidden from userspace ioctls */
6363
#define REG_HIDDEN_GUEST (1 << 1) /* hidden from guest */
6464

65-
static inline void print_sys_reg_instr(const struct sys_reg_params *p)
65+
static __printf(2, 3)
66+
inline void print_sys_reg_msg(const struct sys_reg_params *p,
67+
char *fmt, ...)
6668
{
69+
va_list va;
70+
71+
va_start(va, fmt);
6772
/* Look, we even formatted it for you to paste into the table! */
68-
kvm_pr_unimpl(" { Op0(%2u), Op1(%2u), CRn(%2u), CRm(%2u), Op2(%2u), func_%s },\n",
73+
kvm_pr_unimpl("%pV { Op0(%2u), Op1(%2u), CRn(%2u), CRm(%2u), Op2(%2u), func_%s },\n",
74+
&(struct va_format){ fmt, &va },
6975
p->Op0, p->Op1, p->CRn, p->CRm, p->Op2, p->is_write ? "write" : "read");
76+
va_end(va);
77+
}
78+
79+
static inline void print_sys_reg_instr(const struct sys_reg_params *p)
80+
{
81+
/* GCC warns on an empty format string */
82+
print_sys_reg_msg(p, "%s", "");
7083
}
7184

7285
static inline bool ignore_write(struct kvm_vcpu *vcpu,

0 commit comments

Comments
 (0)