From: Sean Christopherson <seanjc@google.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: kvm@vger.kernel.org, Sean Christopherson <seanjc@google.com>
Subject: [kvm-unit-tests PATCH 1/4] x86/debug: Set all active-low DR6 bits when resetting DR6
Date: Fri, 25 Sep 2026 16:00:00 -0700 [thread overview]
Message-ID: <20260925230003.2362261-2-seanjc@google.com> (raw)
In-Reply-To: <20260925230003.2362261-1-seanjc@google.com>
Set all active-low DR6 bits when resetting DR6 between testcases, as
clearing active-low bits causes test failures when run on (virtual) CPUs
that support such bits, due to the checks all expecting the active-low
bits to be set. The bug has gone unnoticed because the default config uses
a virtual CPU model that doesn't support any active-low bits.
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
x86/debug.c | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/x86/debug.c b/x86/debug.c
index eef0dfd8..c677af99 100644
--- a/x86/debug.c
+++ b/x86/debug.c
@@ -100,7 +100,7 @@ static void __run_single_step_db_test(db_test_fn test, db_report_fn report_fn)
bool ign;
n = 0;
- write_dr6(0);
+ write_dr6(DR6_ACTIVE_LOW);
start = test();
report_fn(start, "");
@@ -114,7 +114,7 @@ static void __run_single_step_db_test(db_test_fn test, db_report_fn report_fn)
return;
n = 0;
- write_dr6(0);
+ write_dr6(DR6_ACTIVE_LOW);
/*
* Run the test in usermode. Use the expected start RIP from the first
@@ -336,7 +336,7 @@ static void report_singlestep_with_movss_blocking_and_dr7_gd(unsigned long start
static noinline unsigned long singlestep_with_movss_blocking_and_dr7_gd(void)
{
- unsigned long start_rip;
+ unsigned long scratch = DR6_ACTIVE_LOW;
write_dr7(DR7_GD);
@@ -348,7 +348,6 @@ static noinline unsigned long singlestep_with_movss_blocking_and_dr7_gd(void)
* General Detect #DB.
*/
asm volatile(
- "xor %0, %0\n\t"
"pushf\n\t"
"pop %%rax\n\t"
"or $(1<<8),%%rax\n\t"
@@ -361,9 +360,9 @@ static noinline unsigned long singlestep_with_movss_blocking_and_dr7_gd(void)
"push %%rax\n\t"
"popf\n\t"
"lea 1b(%%rip),%0\n\t"
- : "=r" (start_rip) : : "rax"
+ : "+r" (scratch) :: "rax"
);
- return start_rip;
+ return scratch;
}
static void report_singlestep_with_sti_hlt(unsigned long start,
@@ -480,7 +479,7 @@ int main(int ac, char **av)
write_cr4(cr4 | X86_CR4_DE);
read_dr4();
report(got_ud, "DR4 read got #UD with CR4.DE == 1");
- write_dr6(0);
+ write_dr6(DR6_ACTIVE_LOW);
extern unsigned char sw_bp;
asm volatile("int3; sw_bp:");
@@ -509,7 +508,7 @@ int main(int ac, char **av)
n = 0;
extern unsigned char hw_bp2;
write_dr2(&hw_bp2);
- write_dr6(DR6_BS | DR6_TRAP1);
+ write_dr6(DR6_ACTIVE_LOW | DR6_BS | DR6_TRAP1);
asm volatile("hw_bp2: nop");
report(n == 1 &&
db_addr[0] == ((unsigned long)&hw_bp2) &&
@@ -528,7 +527,7 @@ int main(int ac, char **av)
n = 0;
write_dr1((void *)&value);
- write_dr6(DR6_BS);
+ write_dr6(DR6_ACTIVE_LOW | DR6_BS);
write_dr7(0x00d0040a); // 4-byte write
extern unsigned char hw_wp1;
@@ -542,7 +541,7 @@ int main(int ac, char **av)
"hw watchpoint (test that dr6.BS is not cleared)");
n = 0;
- write_dr6(0);
+ write_dr6(DR6_ACTIVE_LOW);
extern unsigned char hw_wp2;
asm volatile(
@@ -555,7 +554,7 @@ int main(int ac, char **av)
"hw watchpoint (test that dr6.BS is not set)");
n = 0;
- write_dr6(0);
+ write_dr6(DR6_ACTIVE_LOW);
extern unsigned char sw_icebp;
asm volatile(".byte 0xf1; sw_icebp:");
report(n == 1 &&
--
2.56.0.rc1.315.gc6ed9934b7-goog
next prev parent reply other threads:[~2026-09-25 23:00 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-25 22:59 [kvm-unit-tests PATCH 0/4] x86/debug: Add Bus Lock Detect coverage Sean Christopherson
2026-09-25 23:00 ` Sean Christopherson [this message]
2026-09-25 23:00 ` [kvm-unit-tests PATCH 2/4] x86/debug: Run the "debug" test with the host CPU model Sean Christopherson
2026-09-25 23:00 ` [kvm-unit-tests PATCH 3/4] x86/debug: Verify that KVM correctly emulates DR6 active-low and fixed-1 semantics Sean Christopherson
2026-09-25 23:00 ` [kvm-unit-tests PATCH 4/4] x86/debug: Add actual test coverage for Bus Lock Detect #DBs Sean Christopherson
2026-10-02 21:07 ` [kvm-unit-tests PATCH 0/4] x86/debug: Add Bus Lock Detect coverage Sean Christopherson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260925230003.2362261-2-seanjc@google.com \
--to=seanjc@google.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox