Skip to content

Commit 5ced4e5

Browse files
reijiw-kvmMarc Zyngier
authored andcommitted
KVM: arm64: selftests: Add a test case for a linked watchpoint
Currently, the debug-exceptions test doesn't have a test case for a linked watchpoint. Add a test case for the linked watchpoint to the test. The new test case uses the highest numbered context-aware breakpoint (for Context ID match), and the watchpoint#0, which is linked to the context-aware breakpoint. Signed-off-by: Reiji Watanabe <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 1423659 commit 5ced4e5

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tools/testing/selftests/kvm/aarch64/debug-exceptions.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
#define DBGWCR_WR (0x2 << 3)
2323
#define DBGWCR_EL1 (0x1 << 1)
2424
#define DBGWCR_E (0x1 << 0)
25+
#define DBGWCR_LBN_SHIFT 16
26+
#define DBGWCR_WT_SHIFT 20
27+
#define DBGWCR_WT_LINK (0x1 << DBGWCR_WT_SHIFT)
2528

2629
#define SPSR_D (1 << 9)
2730
#define SPSR_SS (1 << 21)
@@ -171,6 +174,28 @@ static void install_hw_bp(uint8_t bpn, uint64_t addr)
171174
enable_monitor_debug_exceptions();
172175
}
173176

177+
static void install_wp_ctx(uint8_t addr_wp, uint8_t ctx_bp, uint64_t addr,
178+
uint64_t ctx)
179+
{
180+
uint32_t wcr;
181+
uint64_t ctx_bcr;
182+
183+
/* Setup a context-aware breakpoint for Linked Context ID Match */
184+
ctx_bcr = DBGBCR_LEN8 | DBGBCR_EXEC | DBGBCR_EL1 | DBGBCR_E |
185+
DBGBCR_BT_CTX_LINK;
186+
write_dbgbcr(ctx_bp, ctx_bcr);
187+
write_dbgbvr(ctx_bp, ctx);
188+
189+
/* Setup a linked watchpoint (linked to the context-aware breakpoint) */
190+
wcr = DBGWCR_LEN8 | DBGWCR_RD | DBGWCR_WR | DBGWCR_EL1 | DBGWCR_E |
191+
DBGWCR_WT_LINK | ((uint32_t)ctx_bp << DBGWCR_LBN_SHIFT);
192+
write_dbgwcr(addr_wp, wcr);
193+
write_dbgwvr(addr_wp, addr);
194+
isb();
195+
196+
enable_monitor_debug_exceptions();
197+
}
198+
174199
void install_hw_bp_ctx(uint8_t addr_bp, uint8_t ctx_bp, uint64_t addr,
175200
uint64_t ctx)
176201
{
@@ -306,6 +331,16 @@ static void guest_code(uint8_t bpn, uint8_t wpn, uint8_t ctx_bpn)
306331
write_sysreg(0, contextidr_el1);
307332
GUEST_ASSERT_EQ(hw_bp_addr, PC(hw_bp_ctx));
308333

334+
/* Linked watchpoint */
335+
reset_debug_state();
336+
install_wp_ctx(wpn, ctx_bpn, PC(write_data), ctx);
337+
/* Set context id */
338+
write_sysreg(ctx, contextidr_el1);
339+
isb();
340+
write_data = 'x';
341+
GUEST_ASSERT_EQ(write_data, 'x');
342+
GUEST_ASSERT_EQ(wp_data_addr, PC(write_data));
343+
309344
GUEST_DONE();
310345
}
311346

0 commit comments

Comments
 (0)