Skip to content

Commit 700b886

Browse files
reijiw-kvmMarc Zyngier
authored andcommitted
KVM: arm64: selftests: Remove the hard-coded {b,w}pn#0 from debug-exceptions
Remove the hard-coded {break,watch}point #0 from the guest_code() in debug-exceptions to allow {break,watch}point number to be specified. Change reset_debug_state() to zeroing all dbg{b,w}{c,v}r_el0 registers so that guest_code() can use the function to reset those registers even when non-zero {break,watch}points are specified for guest_code(). Subsequent patches will add test cases for non-zero {break,watch}points. Signed-off-by: Reiji Watanabe <[email protected]> Reviewed-by: Ricardo Koller <[email protected]> Reviewed-by: Oliver Upton <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent f6d02aa commit 700b886

File tree

1 file changed

+32
-18
lines changed

1 file changed

+32
-18
lines changed

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

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,30 @@ GEN_DEBUG_WRITE_REG(dbgwvr)
9595

9696
static void reset_debug_state(void)
9797
{
98+
uint8_t brps, wrps, i;
99+
uint64_t dfr0;
100+
98101
asm volatile("msr daifset, #8");
99102

100103
write_sysreg(0, osdlr_el1);
101104
write_sysreg(0, oslar_el1);
102105
isb();
103106

104107
write_sysreg(0, mdscr_el1);
105-
/* This test only uses the first bp and wp slot. */
106-
write_sysreg(0, dbgbvr0_el1);
107-
write_sysreg(0, dbgbcr0_el1);
108-
write_sysreg(0, dbgwcr0_el1);
109-
write_sysreg(0, dbgwvr0_el1);
108+
109+
/* Reset all bcr/bvr/wcr/wvr registers */
110+
dfr0 = read_sysreg(id_aa64dfr0_el1);
111+
brps = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_BRPS), dfr0);
112+
for (i = 0; i <= brps; i++) {
113+
write_dbgbcr(i, 0);
114+
write_dbgbvr(i, 0);
115+
}
116+
wrps = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_WRPS), dfr0);
117+
for (i = 0; i <= wrps; i++) {
118+
write_dbgwcr(i, 0);
119+
write_dbgwvr(i, 0);
120+
}
121+
110122
isb();
111123
}
112124

@@ -118,14 +130,14 @@ static void enable_os_lock(void)
118130
GUEST_ASSERT(read_sysreg(oslsr_el1) & 2);
119131
}
120132

121-
static void install_wp(uint64_t addr)
133+
static void install_wp(uint8_t wpn, uint64_t addr)
122134
{
123135
uint32_t wcr;
124136
uint32_t mdscr;
125137

126138
wcr = DBGWCR_LEN8 | DBGWCR_RD | DBGWCR_WR | DBGWCR_EL1 | DBGWCR_E;
127-
write_dbgwcr(0, wcr);
128-
write_dbgwvr(0, addr);
139+
write_dbgwcr(wpn, wcr);
140+
write_dbgwvr(wpn, addr);
129141

130142
isb();
131143

@@ -136,14 +148,14 @@ static void install_wp(uint64_t addr)
136148
isb();
137149
}
138150

139-
static void install_hw_bp(uint64_t addr)
151+
static void install_hw_bp(uint8_t bpn, uint64_t addr)
140152
{
141153
uint32_t bcr;
142154
uint32_t mdscr;
143155

144156
bcr = DBGBCR_LEN8 | DBGBCR_EXEC | DBGBCR_EL1 | DBGBCR_E;
145-
write_dbgbcr(0, bcr);
146-
write_dbgbvr(0, addr);
157+
write_dbgbcr(bpn, bcr);
158+
write_dbgbvr(bpn, addr);
147159
isb();
148160

149161
asm volatile("msr daifclr, #8");
@@ -166,7 +178,7 @@ static void install_ss(void)
166178

167179
static volatile char write_data;
168180

169-
static void guest_code(void)
181+
static void guest_code(uint8_t bpn, uint8_t wpn)
170182
{
171183
GUEST_SYNC(0);
172184

@@ -179,15 +191,15 @@ static void guest_code(void)
179191

180192
/* Hardware-breakpoint */
181193
reset_debug_state();
182-
install_hw_bp(PC(hw_bp));
194+
install_hw_bp(bpn, PC(hw_bp));
183195
asm volatile("hw_bp: nop");
184196
GUEST_ASSERT_EQ(hw_bp_addr, PC(hw_bp));
185197

186198
GUEST_SYNC(2);
187199

188200
/* Hardware-breakpoint + svc */
189201
reset_debug_state();
190-
install_hw_bp(PC(bp_svc));
202+
install_hw_bp(bpn, PC(bp_svc));
191203
asm volatile("bp_svc: svc #0");
192204
GUEST_ASSERT_EQ(hw_bp_addr, PC(bp_svc));
193205
GUEST_ASSERT_EQ(svc_addr, PC(bp_svc) + 4);
@@ -196,7 +208,7 @@ static void guest_code(void)
196208

197209
/* Hardware-breakpoint + software-breakpoint */
198210
reset_debug_state();
199-
install_hw_bp(PC(bp_brk));
211+
install_hw_bp(bpn, PC(bp_brk));
200212
asm volatile("bp_brk: brk #0");
201213
GUEST_ASSERT_EQ(sw_bp_addr, PC(bp_brk));
202214
GUEST_ASSERT_EQ(hw_bp_addr, PC(bp_brk));
@@ -205,7 +217,7 @@ static void guest_code(void)
205217

206218
/* Watchpoint */
207219
reset_debug_state();
208-
install_wp(PC(write_data));
220+
install_wp(wpn, PC(write_data));
209221
write_data = 'x';
210222
GUEST_ASSERT_EQ(write_data, 'x');
211223
GUEST_ASSERT_EQ(wp_data_addr, PC(write_data));
@@ -239,7 +251,7 @@ static void guest_code(void)
239251
/* OS Lock blocking hardware-breakpoint */
240252
reset_debug_state();
241253
enable_os_lock();
242-
install_hw_bp(PC(hw_bp2));
254+
install_hw_bp(bpn, PC(hw_bp2));
243255
hw_bp_addr = 0;
244256
asm volatile("hw_bp2: nop");
245257
GUEST_ASSERT_EQ(hw_bp_addr, 0);
@@ -251,7 +263,7 @@ static void guest_code(void)
251263
enable_os_lock();
252264
write_data = '\0';
253265
wp_data_addr = 0;
254-
install_wp(PC(write_data));
266+
install_wp(wpn, PC(write_data));
255267
write_data = 'x';
256268
GUEST_ASSERT_EQ(write_data, 'x');
257269
GUEST_ASSERT_EQ(wp_data_addr, 0);
@@ -376,6 +388,8 @@ static void test_guest_debug_exceptions(void)
376388
vm_install_sync_handler(vm, VECTOR_SYNC_CURRENT,
377389
ESR_EC_SVC64, guest_svc_handler);
378390

391+
/* Run tests with breakpoint#0 and watchpoint#0. */
392+
vcpu_args_set(vcpu, 2, 0, 0);
379393
for (stage = 0; stage < 11; stage++) {
380394
vcpu_run(vcpu);
381395

0 commit comments

Comments
 (0)