[PATCH] KVM: arm64: Add missing index for trapping debug registers

Ricardo Koller ricarkol at google.com
Thu May 13 18:49:06 PDT 2021


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 at 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




More information about the linux-arm-kernel mailing list