Skip to contentSkip to conversation

Xen 4.18.5 PV dbregs fail

PATCH In review Manuel Bouyer 3 participants 14 messages May 26, 2025 – May 27, 2025

lore
Share & tools
lore
#0 lore raw

Hello,
since I updated to Xen 4.18.5 (from 4.18.4), NetBSD's dbregs-related tests are failing. Only for PV; PVH and HVM guests are fine. They are failing for both 32bits and 64bits guests.

I tracked it down to dr6 being 0xffff0ff0 after the trace trap, when at last one of the lower bits should be 1 (I think it's bit 0, from the code).

I looked at the commit log between 4.18.4 and 4.18.5 but didn't see anything obvious.

Any idea ?

Signature · 3 lines
Manuel Bouyer <[email protected]>
     NetBSD: 26 ans d'experience feront toujours la difference
--
#1 lore raw
Quoted 5 lines · Manuel Bouyer

Hello,
since I updated to Xen 4.18.5 (from 4.18.4), NetBSD's dbregs-related tests are failing. Only for PV; PVH and HVM guests are fine. They are failing for both 32bits and 64bits guests.

Quoted 8 lines

I tracked it down to dr6 being 0xffff0ff0 after the trace trap, when at last one of the lower bits should be 1 (I think it's bit 0, from the code).

I looked at the commit log between 4.18.4 and 4.18.5 but didn't see anything obvious.

Any idea ?

Have you got a link to the test in question?

We've had a couple of bugfixes in this area, although debug handling isn't helped by the fact that both the SDM and APM are factually incorrect on how to write a #DB handler (and the vendors are moving at a glacial pace to correct them).

~Andrew

#2 lore raw
Quoted 12 lines · Andrew Cooper
Quoted 11 lines · Manuel Bouyer

Hello,
since I updated to Xen 4.18.5 (from 4.18.4), NetBSD's dbregs-related tests are failing. Only for PV; PVH and HVM guests are fine. They are failing for both 32bits and 64bits guests.

I tracked it down to dr6 being 0xffff0ff0 after the trace trap, when at last one of the lower bits should be 1 (I think it's bit 0, from the code).

I looked at the commit log between 4.18.4 and 4.18.5 but didn't see anything obvious.

Quoted 8 lines
Quoted 2 lines

Any idea ?

Have you got a link to the test in question?

We've had a couple of bugfixes in this area, although debug handling isn't helped by the fact that both the SDM and APM are factually incorrect on how to write a #DB handler (and the vendors are moving at a glacial pace to correct them).

But yes, having looked between 4.18.4 and 4.18.5, I can't see anything relevant to debug handling either.

Judging from your description, it looks like a breakpoint is going missing.

The relevant recent change for that is
https://xenbits.xen.org/gitweb/?p=xen.git;a=commitdiff;h=54ef601a66e8d812a6a6a308f02524e81201825e
although it's a bit older than 4.18.4.

I suppose it's possible that we call x86_merge_dr6() more than once when forwarding #DB to the guest, which might lose the breakpoint bits?

~Andrew

#3 lore raw
Quoted 22 lines · Andrew Cooper
Quoted 12 lines · Andrew Cooper
Quoted 11 lines · Manuel Bouyer

Hello,
since I updated to Xen 4.18.5 (from 4.18.4), NetBSD's dbregs-related tests are failing. Only for PV; PVH and HVM guests are fine. They are failing for both 32bits and 64bits guests.

I tracked it down to dr6 being 0xffff0ff0 after the trace trap, when at last one of the lower bits should be 1 (I think it's bit 0, from the code).

I looked at the commit log between 4.18.4 and 4.18.5 but didn't see anything obvious.

Quoted 8 lines
Quoted 2 lines

Any idea ?

Have you got a link to the test in question?

We've had a couple of bugfixes in this area, although debug handling isn't helped by the fact that both the SDM and APM are factually incorrect on how to write a #DB handler (and the vendors are moving at a glacial pace to correct them).

Quoted 8 lines

But yes, having looked between 4.18.4 and 4.18.5, I can't see anything relevant to debug handling either.

Judging from your description, it looks like a breakpoint is going missing.

The relevant recent change for that is
https://xenbits.xen.org/gitweb/?p=xen.git;a=commitdiff;h=54ef601a66e8d812a6a6a308f02524e81201825e
although it's a bit older than 4.18.4.

Well, my previous xen-debug.gz kernel is from Oct, 3 so it can't be 4.18.4, it's 4.18.3_20240909 which points to commit bd51e573a730efc569646379cd59ccba967cde97

looks like I forgot to update this server. So I need to looks deeper in the commit logs

Signature · 3 lines
Manuel Bouyer <[email protected]>
     NetBSD: 26 ans d'experience feront toujours la difference
--
#4 lore raw
Quoted 30 lines · Manuel Bouyer
Quoted 21 lines · Andrew Cooper
Quoted 12 lines · Andrew Cooper
Quoted 11 lines · Manuel Bouyer

Hello,
since I updated to Xen 4.18.5 (from 4.18.4), NetBSD's dbregs-related tests are failing. Only for PV; PVH and HVM guests are fine. They are failing for both 32bits and 64bits guests.

I tracked it down to dr6 being 0xffff0ff0 after the trace trap, when at last one of the lower bits should be 1 (I think it's bit 0, from the code).

I looked at the commit log between 4.18.4 and 4.18.5 but didn't see anything obvious.

Quoted 8 lines
Quoted 2 lines

Any idea ?

Have you got a link to the test in question?

We've had a couple of bugfixes in this area, although debug handling isn't helped by the fact that both the SDM and APM are factually incorrect on how to write a #DB handler (and the vendors are moving at a glacial pace to correct them).

Quoted 8 lines

But yes, having looked between 4.18.4 and 4.18.5, I can't see anything relevant to debug handling either.

Judging from your description, it looks like a breakpoint is going missing.

The relevant recent change for that is
https://xenbits.xen.org/gitweb/?p=xen.git;a=commitdiff;h=54ef601a66e8d812a6a6a308f02524e81201825e
although it's a bit older than 4.18.4.

Quoted 6 lines

Well, my previous xen-debug.gz kernel is from Oct, 3 so it can't be 4.18.4, it's 4.18.3_20240909 which points to commit bd51e573a730efc569646379cd59ccba967cde97

looks like I forgot to update this server. So I need to looks deeper in the commit logs

Well, that range does include the aforementioned commit.

Can you bisect around d32c77f471fb8400b6512c171a14cdd58f04f0a3 which is the backport of ^ in 4.18 ?

~Andrew

#5 lore raw
Quoted 5 lines · Andrew Cooper

[...]
Well, that range does include the aforementioned commit.

Can you bisect around d32c77f471fb8400b6512c171a14cdd58f04f0a3 which is the backport of ^ in 4.18 ?

Sure,
with 0d5f15e and d32c77f the test pass, with cecee35 it fails.

Signature · 3 lines
Manuel Bouyer <[email protected]>
     NetBSD: 26 ans d'experience feront toujours la difference
--
#6 lore raw
Quoted 9 lines · Manuel Bouyer
Quoted 5 lines · Andrew Cooper

[...]
Well, that range does include the aforementioned commit.

Can you bisect around d32c77f471fb8400b6512c171a14cdd58f04f0a3 which is the backport of ^ in 4.18 ?

Sure,
with 0d5f15e and d32c77f the test pass, with cecee35 it fails.

Oh interesting, so the basic forwarding of #DB back into a guest (d32c77f) works fine, but the changes to emulated debug exceptions (cecee35) break.

Anyway, I think I've spotted a logical error.  We do indeed end up calling x86_merge_dr6() twice, because of the TODO just out of context. Does this help?

~Andrew

xen/arch/x86/traps.c +0 -0
index 6d75b59b1e97..01b8be02b055 100644
@@ -1798,7 +1798,7 @@ void asmlinkage do_debug(struct cpu_user_regs *regs)

         return;
     }

-    pv_inject_DB(0 /* N/A, already merged */); +    pv_inject_DB(dr6 ^ X86_DR6_DEFAULT);
 }

 void asmlinkage do_entry_CP(struct cpu_user_regs *regs)

#7 lore raw
Quoted 11 lines · Andrew Cooper
Quoted 9 lines · Manuel Bouyer
Quoted 5 lines · Andrew Cooper

[...]
Well, that range does include the aforementioned commit.

Can you bisect around d32c77f471fb8400b6512c171a14cdd58f04f0a3 which is the backport of ^ in 4.18 ?

Sure,
with 0d5f15e and d32c77f the test pass, with cecee35 it fails.

Quoted 7 lines

Oh interesting, so the basic forwarding of #DB back into a guest (d32c77f) works fine, but the changes to emulated debug exceptions (cecee35) break.

Anyway, I think I've spotted a logical error.  We do indeed end up calling x86_merge_dr6() twice, because of the TODO just out of context. Does this help?

Yes, it works for cecee35; now testing with 4.18.5

Signature · 3 lines
Manuel Bouyer <[email protected]>
     NetBSD: 26 ans d'experience feront toujours la difference
--
#8 lore raw
Quoted 16 lines · Manuel Bouyer
Quoted 15 lines · Andrew Cooper
Quoted 9 lines · Manuel Bouyer
Quoted 5 lines · Andrew Cooper

[...]
Well, that range does include the aforementioned commit.

Can you bisect around d32c77f471fb8400b6512c171a14cdd58f04f0a3 which is the backport of ^ in 4.18 ?

Sure,
with 0d5f15e and d32c77f the test pass, with cecee35 it fails.

Oh interesting, so the basic forwarding of #DB back into a guest (d32c77f) works fine, but the changes to emulated debug exceptions (cecee35) break.

Quoted 5 lines
Quoted 3 lines

Anyway, I think I've spotted a logical error.  We do indeed end up calling x86_merge_dr6() twice, because of the TODO just out of context. Does this help?

Yes, it works for cecee35; now testing with 4.18.5

yes, it works with 4.18.5 too. All dbreg-related tests now pass again thanks !

Signature · 3 lines
Manuel Bouyer <[email protected]>
     NetBSD: 26 ans d'experience feront toujours la difference
--
#9 lore raw
Quoted 16 lines · Manuel Bouyer
Quoted 15 lines · Manuel Bouyer
Quoted 14 lines · Andrew Cooper
Quoted 9 lines · Manuel Bouyer
Quoted 5 lines · Andrew Cooper

[...]
Well, that range does include the aforementioned commit.

Can you bisect around d32c77f471fb8400b6512c171a14cdd58f04f0a3 which is the backport of ^ in 4.18 ?

Sure,
with 0d5f15e and d32c77f the test pass, with cecee35 it fails.

Oh interesting, so the basic forwarding of #DB back into a guest (d32c77f) works fine, but the changes to emulated debug exceptions (cecee35) break.

Quoted 7 lines
Quoted 4 lines
Quoted 3 lines

Anyway, I think I've spotted a logical error.  We do indeed end up calling x86_merge_dr6() twice, because of the TODO just out of context. Does this help?

Yes, it works for cecee35; now testing with 4.18.5

yes, it works with 4.18.5 too. All dbreg-related tests now pass again thanks !

Sorry I screwed it up so badly, and apparently also my own testing...

May I take that as a Tested-by tag on the patch then?

I'll get the fix merged once it's been reviewed, but 4.18 is in security-only support right now and is unlikely to get this as a backport.

Are you able to take the patch logically for NetBSD?

~Andrew

#10 lore raw
Quoted 20 lines · Andrew Cooper
Quoted 19 lines · Manuel Bouyer
Quoted 18 lines · Manuel Bouyer
Quoted 17 lines · Andrew Cooper
Quoted 9 lines · Manuel Bouyer
Quoted 5 lines · Andrew Cooper

[...]
Well, that range does include the aforementioned commit.

Can you bisect around d32c77f471fb8400b6512c171a14cdd58f04f0a3 which is the backport of ^ in 4.18 ?

Sure,
with 0d5f15e and d32c77f the test pass, with cecee35 it fails.

Oh interesting, so the basic forwarding of #DB back into a guest (d32c77f) works fine, but the changes to emulated debug exceptions (cecee35) break.

Anyway, I think I've spotted a logical error.  We do indeed end up calling x86_merge_dr6() twice, because of the TODO just out of context. Does this help?

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Yes, it works for cecee35; now testing with 4.18.5

yes, it works with 4.18.5 too. All dbreg-related tests now pass again thanks !

Sorry I screwed it up so badly, and apparently also my own testing...

May I take that as a Tested-by tag on the patch then?

Sure

Quoted 5 lines

I'll get the fix merged once it's been reviewed, but 4.18 is in security-only support right now and is unlikely to get this as a backport.

Are you able to take the patch logically for NetBSD?

Yes, I can add it to pkgsrc, no problem.

I need to package 4.20 too ...

Signature · 3 lines
Manuel Bouyer <[email protected]>
     NetBSD: 26 ans d'experience feront toujours la difference
--
#11 lore raw
In reply to Andrew Cooper
Quoted 9 lines · Andrew Cooper
Quoted 8 lines · Manuel Bouyer

Hello,
since I updated to Xen 4.18.5 (from 4.18.4), NetBSD's dbregs-related tests are failing. Only for PV; PVH and HVM guests are fine. They are failing for both 32bits and 64bits guests.

I tracked it down to dr6 being 0xffff0ff0 after the trace trap, when at last one of the lower bits should be 1 (I think it's bit 0, from the code).

Quoted 7 lines
Quoted 5 lines

I looked at the commit log between 4.18.4 and 4.18.5 but didn't see anything obvious.

Any idea ?

Have you got a link to the test in question?

For example, dbregs_dr0_trap_code in
https://cvsweb.netbsd.org/bsdweb.cgi/src/tests/lib/libc/sys/t_ptrace_x86_wait.h?rev=1.33;content-type=text%2Fplain

What's failing is

	ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_DBREG);

I added printfs in the kernel to show the debug registers when the process traps, this is where the 0xffff0ff0 value comes from.

Signature · 3 lines
Manuel Bouyer <[email protected]>
     NetBSD: 26 ans d'experience feront toujours la difference
--
#12 lore raw

PATCH 1/1 x86/pv: Fix breakpoint reporting

In reply to Manuel Bouyer

x86_merge_dr6() is not a no-op when 0 is passed in; it will discard the previously latched breakpoint bits.

The combination of do_debug()'s manual call to x86_merge_dr6() for external debuggers, and pv_inject_DB() calling pv_inject_event(), results in two x86_merge_dr6() calls.

Feed the same pending_dbg in the second time. This makes pv_inject_event()'s update of dr6 effectively a no-op, retaining the correct breakpoint bits.

Fixes db39fa4b27ea ("x86/pv: Fix merging of new status bits into %dr6")

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Manuel Bouyer <[email protected]>

Now to figure out why my testing didn't spot this...

---
 xen/arch/x86/traps.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/x86/traps.c +1 -1
index 22f20629327d..e7b4693415cd 100644
@@ -1823,7 +1823,7 @@ void asmlinkage do_debug(struct cpu_user_regs *regs)
         return;
     }
 
-    pv_inject_DB(0 /* N/A, already merged */);
+    pv_inject_DB(dr6 ^ X86_DR6_DEFAULT);
 }
 
 void asmlinkage do_entry_CP(struct cpu_user_regs *regs)

base-commit: 6cfe3ae346fc84fbd4380fc45c70780935da590a

Signature · 1 line
2.39.5
Acked-by on v1 1/1
#13 lore raw

Re: [PATCH] x86/pv: Fix breakpoint reporting

Quoted 7 lines · Andrew Cooper

x86_merge_dr6() is not a no-op when 0 is passed in; it will discard the previously latched breakpoint bits.

The combination of do_debug()'s manual call to x86_merge_dr6() for external debuggers, and pv_inject_DB() calling pv_inject_event(), results in two x86_merge_dr6() calls.

Quoted 6 lines

Feed the same pending_dbg in the second time. This makes pv_inject_event()'s update of dr6 effectively a no-op, retaining the correct breakpoint bits.

Fixes db39fa4b27ea ("x86/pv: Fix merging of new status bits into %dr6")

Thanks, Roger.