* [PATCH 6.18.y 0/4] KVM: x86: Fix DR6.BLD regression in guests
@ 2026-11-23 12:14 Baoli Zhang
2026-11-23 12:14 ` [PATCH 6.18.y 1/4] KVM: x86: Rename kvm_dr6_fixed() => kvm_get_dr6_fixed_1() Baoli Zhang
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Baoli Zhang @ 2026-11-23 12:14 UTC (permalink / raw)
To: stable; +Cc: kvm, Sean Christopherson, Paolo Bonzini, Yanx L Liu, Baoli Zhang
Hi,
a58917a271cb ("KVM: x86: Preserve DR6.BLD (Bus Lock Detect) when
delivering #DB payload"), upstream 719a1d58bf43, went into 6.18.61
without the rest of its upstream series. Since then kvm-unit-tests
x86/debug fails on hosts with Bus Lock Detect when the guest CPU model
doesn't have it, e.g. the default qemu64:
FAIL: Wanted #DB on 0x400da7 w/ DR6 = 0xffff0ff4, got 1 #DBs, addr[0] = 0x400da7, DR6 = 0xffff07f4
...
SUMMARY: 25 tests, 17 unexpected failures
Once KVM stops intercepting DR accesses, the guest's write of 0 to DR6
goes to hardware and clears BLD. sync_dirty_debug_regs() copies that into
vcpu->arch.dr6, and since a58917a271cb the #DB payload path no longer
sets BLD back, so the guest sees it cleared.
Later patches in the same series fix this upstream (v7.4-rc1). This
backports those two fixes and the two cleanups they depend on. Patch 3
needed a small change: 6.18 has no arch/x86/kvm/regs.h, so the new
declaration goes in asm/kvm_host.h.
Tested on an Intel host with bus_lock_detect with a 6.18.64-based kernel
whose DR6 handling matches v6.18.64: x86/debug goes from 17 failures to
all 25 passing.
7.3.y, 6.12.y, 6.6.y and 6.1.y picked up the same commit (in 7.3.2,
6.12.117, 6.6.163 and 6.1.193) and probably need these too. I haven't
tested those, but can send backports if wanted.
Thanks,
Baoli
Sean Christopherson (4):
KVM: x86: Rename kvm_dr6_fixed() => kvm_get_dr6_fixed_1()
KVM: Return an "unsigned long", not "u64" for the fixed-1 DR6 bits
KVM: x86: Force fixed-1 bits in DR6 after synchronizing with hardware
KVM: x86: Set guest's fixed-1 DR6 bits when delivering #DB payload
arch/x86/include/asm/kvm_host.h | 1 +
arch/x86/kvm/regs.c | 7 ++++---
arch/x86/kvm/x86.c | 3 ++-
3 files changed, 7 insertions(+), 4 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 6.18.y 1/4] KVM: x86: Rename kvm_dr6_fixed() => kvm_get_dr6_fixed_1()
2026-11-23 12:14 [PATCH 6.18.y 0/4] KVM: x86: Fix DR6.BLD regression in guests Baoli Zhang
@ 2026-11-23 12:14 ` Baoli Zhang
2026-11-23 12:14 ` [PATCH 6.18.y 2/4] KVM: Return an "unsigned long", not "u64" for the fixed-1 DR6 bits Baoli Zhang
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Baoli Zhang @ 2026-11-23 12:14 UTC (permalink / raw)
To: stable; +Cc: kvm, Sean Christopherson, Paolo Bonzini, Yanx L Liu, Baoli Zhang
From: Sean Christopherson <seanjc@google.com>
commit cc551e8d4f77c278fd0bb0ed45d1103cb5a90889 upstream.
Rename kvm_dr6_fixed() to kvm_get_dr6_fixed_1() to make it more clear that
the helper retrieves the fixed-1 DR6 bits for a given vCPU.
No functional change intended.
Link: https://patch.msgid.link/20260930193634.3415089-3-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
Tested-by: Yanx L Liu <yanx.l.liu@intel.com>
Signed-off-by: Baoli Zhang <baoli.zhang@linux.intel.com>
---
arch/x86/kvm/regs.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kvm/regs.c b/arch/x86/kvm/regs.c
index d19a9e7e41f37..3cd1fb8fb09ad 100644
--- a/arch/x86/kvm/regs.c
+++ b/arch/x86/kvm/regs.c
@@ -679,7 +679,7 @@ void kvm_update_dr7(struct kvm_vcpu *vcpu)
}
EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_update_dr7);
-static u64 kvm_dr6_fixed(struct kvm_vcpu *vcpu)
+static u64 kvm_get_dr6_fixed_1(struct kvm_vcpu *vcpu)
{
u64 fixed = DR6_FIXED_1;
@@ -705,7 +705,7 @@ int kvm_set_dr(struct kvm_vcpu *vcpu, int dr, unsigned long val)
case 6:
if (!kvm_dr6_valid(val))
return 1; /* #GP */
- vcpu->arch.dr6 = (val & DR6_VOLATILE) | kvm_dr6_fixed(vcpu);
+ vcpu->arch.dr6 = (val & DR6_VOLATILE) | kvm_get_dr6_fixed_1(vcpu);
break;
case 5:
default: /* 7 */
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 6.18.y 2/4] KVM: Return an "unsigned long", not "u64" for the fixed-1 DR6 bits
2026-11-23 12:14 [PATCH 6.18.y 0/4] KVM: x86: Fix DR6.BLD regression in guests Baoli Zhang
2026-11-23 12:14 ` [PATCH 6.18.y 1/4] KVM: x86: Rename kvm_dr6_fixed() => kvm_get_dr6_fixed_1() Baoli Zhang
@ 2026-11-23 12:14 ` Baoli Zhang
2026-11-23 12:29 ` sashiko-bot
2026-11-23 12:14 ` [PATCH 6.18.y 3/4] KVM: x86: Force fixed-1 bits in DR6 after synchronizing with hardware Baoli Zhang
2026-11-23 12:14 ` [PATCH 6.18.y 4/4] KVM: x86: Set guest's fixed-1 DR6 bits when delivering #DB payload Baoli Zhang
3 siblings, 1 reply; 6+ messages in thread
From: Baoli Zhang @ 2026-11-23 12:14 UTC (permalink / raw)
To: stable; +Cc: kvm, Sean Christopherson, Paolo Bonzini, Yanx L Liu, Baoli Zhang
From: Sean Christopherson <seanjc@google.com>
commit 28bb033664eef3c18c6acb2c075fc01d7ada9296 upstream.
Return an "unsigned long" instead of a "u64" from the helper to get the
fixed-1 DR6 bits, as debug registers are natural width registers, not
64-bit registers.
No functional change intended (the fixed-1 bits only set bits in 31:0, and
the sole caller truncates the value to an "unsigned long").
Link: https://patch.msgid.link/20260930193634.3415089-4-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
Tested-by: Yanx L Liu <yanx.l.liu@intel.com>
Signed-off-by: Baoli Zhang <baoli.zhang@linux.intel.com>
---
arch/x86/kvm/regs.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kvm/regs.c b/arch/x86/kvm/regs.c
index 3cd1fb8fb09ad..7556eee700029 100644
--- a/arch/x86/kvm/regs.c
+++ b/arch/x86/kvm/regs.c
@@ -679,15 +679,16 @@ void kvm_update_dr7(struct kvm_vcpu *vcpu)
}
EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_update_dr7);
-static u64 kvm_get_dr6_fixed_1(struct kvm_vcpu *vcpu)
+static unsigned long kvm_get_dr6_fixed_1(struct kvm_vcpu *vcpu)
{
- u64 fixed = DR6_FIXED_1;
+ unsigned long fixed = DR6_FIXED_1;
if (!guest_cpu_cap_has(vcpu, X86_FEATURE_RTM))
fixed |= DR6_RTM;
if (!guest_cpu_cap_has(vcpu, X86_FEATURE_BUS_LOCK_DETECT))
fixed |= DR6_BUS_LOCK;
+
return fixed;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 6.18.y 3/4] KVM: x86: Force fixed-1 bits in DR6 after synchronizing with hardware
2026-11-23 12:14 [PATCH 6.18.y 0/4] KVM: x86: Fix DR6.BLD regression in guests Baoli Zhang
2026-11-23 12:14 ` [PATCH 6.18.y 1/4] KVM: x86: Rename kvm_dr6_fixed() => kvm_get_dr6_fixed_1() Baoli Zhang
2026-11-23 12:14 ` [PATCH 6.18.y 2/4] KVM: Return an "unsigned long", not "u64" for the fixed-1 DR6 bits Baoli Zhang
@ 2026-11-23 12:14 ` Baoli Zhang
2026-11-23 12:14 ` [PATCH 6.18.y 4/4] KVM: x86: Set guest's fixed-1 DR6 bits when delivering #DB payload Baoli Zhang
3 siblings, 0 replies; 6+ messages in thread
From: Baoli Zhang @ 2026-11-23 12:14 UTC (permalink / raw)
To: stable; +Cc: kvm, Sean Christopherson, Paolo Bonzini, Yanx L Liu, Baoli Zhang
From: Sean Christopherson <seanjc@google.com>
commit 7b88577a0983af221a78fc66c56532eb97d8fd2f upstream.
Set all fixed-1 bits in KVM's version of DR6 after synchronizing with
hardware to paper over as much of the virtualization hole as possible.
Because KVM dynamically disables DR interception, a guest can write any
DR6 bit that isn't fixed in bare metal, even if the bit is supposed to be
fixed from the guest's perspective.
In addition to providing some amount of consistency in KVM, this will allow
adding sanity checks that KVM never ends up with fixed-1 bits clear in its
version of DR6.
Link: https://patch.msgid.link/20260930193634.3415089-5-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
[ Baoli: 6.18 has no arch/x86/kvm/regs.h, declare kvm_get_dr6_fixed_1()
in arch/x86/include/asm/kvm_host.h next to kvm_get_dr() instead. ]
Tested-by: Yanx L Liu <yanx.l.liu@intel.com>
Signed-off-by: Baoli Zhang <baoli.zhang@linux.intel.com>
---
arch/x86/include/asm/kvm_host.h | 1 +
arch/x86/kvm/regs.c | 2 +-
arch/x86/kvm/x86.c | 1 +
3 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 319aeac052f14..413d1a1cd0919 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -2249,6 +2249,7 @@ int kvm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4);
int kvm_set_cr8(struct kvm_vcpu *vcpu, unsigned long cr8);
int kvm_set_dr(struct kvm_vcpu *vcpu, int dr, unsigned long val);
unsigned long kvm_get_dr(struct kvm_vcpu *vcpu, int dr);
+unsigned long kvm_get_dr6_fixed_1(struct kvm_vcpu *vcpu);
unsigned long kvm_get_cr8(struct kvm_vcpu *vcpu);
void kvm_lmsw(struct kvm_vcpu *vcpu, unsigned long msw);
int __kvm_set_xcr(struct kvm_vcpu *vcpu, u32 index, u64 xcr);
diff --git a/arch/x86/kvm/regs.c b/arch/x86/kvm/regs.c
index 7556eee700029..6c7fda91b670d 100644
--- a/arch/x86/kvm/regs.c
+++ b/arch/x86/kvm/regs.c
@@ -679,7 +679,7 @@ void kvm_update_dr7(struct kvm_vcpu *vcpu)
}
EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_update_dr7);
-static unsigned long kvm_get_dr6_fixed_1(struct kvm_vcpu *vcpu)
+unsigned long kvm_get_dr6_fixed_1(struct kvm_vcpu *vcpu)
{
unsigned long fixed = DR6_FIXED_1;
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 3ca396316d3cf..a620f14410595 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -11042,6 +11042,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
WARN_ON(vcpu->arch.switch_db_regs & KVM_DEBUGREG_AUTO_SWITCH);
kvm_x86_call(sync_dirty_debug_regs)(vcpu);
kvm_update_dr0123(vcpu);
+ vcpu->arch.dr6 |= kvm_get_dr6_fixed_1(vcpu);
kvm_update_dr7(vcpu);
}
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 6.18.y 4/4] KVM: x86: Set guest's fixed-1 DR6 bits when delivering #DB payload
2026-11-23 12:14 [PATCH 6.18.y 0/4] KVM: x86: Fix DR6.BLD regression in guests Baoli Zhang
` (2 preceding siblings ...)
2026-11-23 12:14 ` [PATCH 6.18.y 3/4] KVM: x86: Force fixed-1 bits in DR6 after synchronizing with hardware Baoli Zhang
@ 2026-11-23 12:14 ` Baoli Zhang
3 siblings, 0 replies; 6+ messages in thread
From: Baoli Zhang @ 2026-11-23 12:14 UTC (permalink / raw)
To: stable; +Cc: kvm, Sean Christopherson, Paolo Bonzini, Yanx L Liu, Baoli Zhang
From: Sean Christopherson <seanjc@google.com>
commit c62ffee78db8837a6251af83798907af37b53ed4 upstream.
When delivering a #DB payload, set all DR6 bits that are fixed-1 from the
guest's perspective, not just the host's perspective. Don't WARN on a
"bad" payload (or existing DR6) even though KVM itself shouldn't set DR6
or synthesize a payload without the fixed-1 bits set, as userspace can
provide a completely arbitrary payload via KVM_SET_VCPU_EVENTS (and
"hardening" that flow is not worth the effort as there's no benefit in
practice).
Link: https://patch.msgid.link/20260930193634.3415089-6-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
Tested-by: Yanx L Liu <yanx.l.liu@intel.com>
Signed-off-by: Baoli Zhang <baoli.zhang@linux.intel.com>
---
arch/x86/kvm/x86.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index a620f14410595..c06a793bf8c97 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -809,7 +809,7 @@ void kvm_deliver_exception_payload(struct kvm_vcpu *vcpu,
* breakpoint), it is reserved and must be zero in DR6.
*/
vcpu->arch.dr6 &= ~BIT(12);
- vcpu->arch.dr6 |= DR6_FIXED_1;
+ vcpu->arch.dr6 |= kvm_get_dr6_fixed_1(vcpu);
break;
case PF_VECTOR:
vcpu->arch.cr2 = ex->payload;
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 6.18.y 2/4] KVM: Return an "unsigned long", not "u64" for the fixed-1 DR6 bits
2026-11-23 12:14 ` [PATCH 6.18.y 2/4] KVM: Return an "unsigned long", not "u64" for the fixed-1 DR6 bits Baoli Zhang
@ 2026-11-23 12:29 ` sashiko-bot
0 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-11-23 12:29 UTC (permalink / raw)
To: Baoli Zhang; +Cc: kvm
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] KVM: x86: missing DR6 fixed-1 bit enforcement in
KVM_SET_DEBUGREGS [1]
--
commit 6ea58ce45be6bc8f3686d6726ca7358f4937978d
Author: Sean Christopherson <seanjc@google.com>
KVM: Return an "unsigned long", not "u64" for the fixed-1 DR6 bits
This commit changes the return type and local variable of
kvm_get_dr6_fixed_1() from u64 to unsigned long to match the natural
width of debug registers.
Link: https://patch.msgid.link/20260930193634.3415089-4-seanjc@google.com
> diff --git a/arch/x86/kvm/regs.c b/arch/x86/kvm/regs.c
> index 3cd1fb8fb09ad..7556eee700029 100644
> --- a/arch/x86/kvm/regs.c
> +++ b/arch/x86/kvm/regs.c
> @@ -679,15 +679,16 @@ void kvm_update_dr7(struct kvm_vcpu *vcpu)
> }
> EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_update_dr7);
>
> -static u64 kvm_get_dr6_fixed_1(struct kvm_vcpu *vcpu)
> +static unsigned long kvm_get_dr6_fixed_1(struct kvm_vcpu *vcpu)
> {
> - u64 fixed = DR6_FIXED_1;
> + unsigned long fixed = DR6_FIXED_1;
>
> if (!guest_cpu_cap_has(vcpu, X86_FEATURE_RTM))
> fixed |= DR6_RTM;
>
> if (!guest_cpu_cap_has(vcpu, X86_FEATURE_BUS_LOCK_DETECT))
> fixed |= DR6_BUS_LOCK;
> +
> return fixed;
> }
[Severity: Critical]
This problem wasn't introduced by this patch, but can
kvm_vcpu_ioctl_x86_set_debugregs() and kvm_deliver_exception_payload()
leave dynamically fixed-1 bits cleared in vcpu->arch.dr6 [1]?
kvm_vcpu_ioctl_x86_set_debugregs() assigns dbgregs->dr6 directly to
vcpu->arch.dr6 without ORing in kvm_get_dr6_fixed_1(vcpu), and
kvm_deliver_exception_payload() applies static DR6 masks when delivering
a DB_VECTOR payload rather than enforcing the dynamic fixed-1 bits
(DR6_RTM and DR6_BUS_LOCK when the guest lacks those CPUID features):
arch/x86/kvm/regs.c:kvm_vcpu_ioctl_x86_set_debugregs() {
...
kvm_update_dr0123(vcpu);
vcpu->arch.dr6 = dbgregs->dr6;
vcpu->arch.dr7 = dbgregs->dr7;
...
}
If userspace clears these bits via KVM_SET_DEBUGREGS or injects a #DB
payload that clears them, vcpu->arch.dr6 violates the fixed-1 invariant
and can trigger a host kernel crash or denial of service when subsequent
sanity checks evaluate DR6.
[1] https://sashiko.dev/#/bug/linux-aad38d43-73ef-489e-897a-07392877a8fb
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261123121427.2803358-1-baoli.zhang@linux.intel.com?part=2
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-23 12:29 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 12:14 [PATCH 6.18.y 0/4] KVM: x86: Fix DR6.BLD regression in guests Baoli Zhang
2026-11-23 12:14 ` [PATCH 6.18.y 1/4] KVM: x86: Rename kvm_dr6_fixed() => kvm_get_dr6_fixed_1() Baoli Zhang
2026-11-23 12:14 ` [PATCH 6.18.y 2/4] KVM: Return an "unsigned long", not "u64" for the fixed-1 DR6 bits Baoli Zhang
2026-11-23 12:29 ` sashiko-bot
2026-11-23 12:14 ` [PATCH 6.18.y 3/4] KVM: x86: Force fixed-1 bits in DR6 after synchronizing with hardware Baoli Zhang
2026-11-23 12:14 ` [PATCH 6.18.y 4/4] KVM: x86: Set guest's fixed-1 DR6 bits when delivering #DB payload Baoli Zhang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox