linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] KVM: arm64: Add missing index for trapping debug registers
@ 2021-05-14  1:49 Ricardo Koller
  2021-05-14  8:19 ` Marc Zyngier
  0 siblings, 1 reply; 3+ messages in thread
From: Ricardo Koller @ 2021-05-14  1:49 UTC (permalink / raw)
  To: kvmarm
  Cc: maz, james.morse, alexandru.elisei, drjones, suzuki.poulose,
	linux-arm-kernel, Ricardo Koller

Trapping an access to debug register <n> (like bvr<n>, bcr<n>, wvr<n>,
wcr<n>) results in storing and loading values from the vcpu copy at
index 0 (irrespective of <n>). So, this guest test fails:

  /* traps and wrongly stores 0x123 into vcpu->bvr[0] */
  write_sysreg(dbgbvr1_el1, 0x123);
  /* reads 0 from the real bvr[1] without trapping */
  GUEST_ASSERT(read_sysreg(dbgbvr1_el1) == 0x123); /* check fails */

Fix this by setting the register index in macro DBG_BCR_BVR_WCR_WVR_EL1
to <n>.

Signed-off-by: Ricardo Koller <ricarkol@google.com>
---
 arch/arm64/kvm/sys_regs.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
index 76ea2800c33e..e4ec9edd49fa 100644
--- a/arch/arm64/kvm/sys_regs.c
+++ b/arch/arm64/kvm/sys_regs.c
@@ -935,13 +935,13 @@ static bool access_pmuserenr(struct kvm_vcpu *vcpu, struct sys_reg_params *p,
 /* Silly macro to expand the DBG{BCR,BVR,WVR,WCR}n_EL1 registers in one go */
 #define DBG_BCR_BVR_WCR_WVR_EL1(n)					\
 	{ SYS_DESC(SYS_DBGBVRn_EL1(n)),					\
-	  trap_bvr, reset_bvr, 0, 0, get_bvr, set_bvr },		\
+	  trap_bvr, reset_bvr, n, 0, get_bvr, set_bvr },		\
 	{ SYS_DESC(SYS_DBGBCRn_EL1(n)),					\
-	  trap_bcr, reset_bcr, 0, 0, get_bcr, set_bcr },		\
+	  trap_bcr, reset_bcr, n, 0, get_bcr, set_bcr },		\
 	{ SYS_DESC(SYS_DBGWVRn_EL1(n)),					\
-	  trap_wvr, reset_wvr, 0, 0,  get_wvr, set_wvr },		\
+	  trap_wvr, reset_wvr, n, 0,  get_wvr, set_wvr },		\
 	{ SYS_DESC(SYS_DBGWCRn_EL1(n)),					\
-	  trap_wcr, reset_wcr, 0, 0,  get_wcr, set_wcr }
+	  trap_wcr, reset_wcr, n, 0,  get_wcr, set_wcr }
 
 #define PMU_SYS_REG(r)						\
 	SYS_DESC(r), .reset = reset_unknown, .visibility = pmu_visibility
-- 
2.31.1.751.gd2f1c929bd-goog


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-05-14 17:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-14  1:49 [PATCH] KVM: arm64: Add missing index for trapping debug registers Ricardo Koller
2021-05-14  8:19 ` Marc Zyngier
2021-05-14 17:53   ` Ricardo Koller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).