Skip to contentSkip to conversation

x86/domctl: restore all registers in arch_{get,set}_info_guest()

PATCH In review Marek Marczykowski-Górecki 6 participants 10 messages Jul 20

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/domctl: restore all registers in arch_{get,set}_info_guest()

Commit 9f892f84c279 ("x86/domctl: Stop using XLAT_cpu_user_regs()") converted memcpy() of the cpu_user_regs structure to explicit copy of its fields. In the compat case, it intentionally missed few of them, named in the commit message. But the 64bit case missed also r8-r15 registers, which was not intentional. This, at least, caused Linux 6.18.x crash when resuming PVH domU.

Fix it by adding missing assignments.

Fixes 9f892f84c279 ("x86/domctl: Stop using XLAT_cpu_user_regs()")
---
 xen/arch/x86/domain.c | 8 ++++++++
 xen/arch/x86/domctl.c | 8 ++++++++
 2 files changed, 16 insertions(+)
xen/arch/x86/domain.c +8 -0
index 1d458f1372e5..ba7244ccc513 100644
@@ -1255,6 +1255,14 @@ int arch_set_info_guest(
 
     if ( !compat )
     {
+        v->arch.user_regs.r15               = c.nat->user_regs.r15;
+        v->arch.user_regs.r14               = c.nat->user_regs.r14;
+        v->arch.user_regs.r13               = c.nat->user_regs.r13;
+        v->arch.user_regs.r12               = c.nat->user_regs.r12;
+        v->arch.user_regs.r11               = c.nat->user_regs.r11;
+        v->arch.user_regs.r10               = c.nat->user_regs.r10;
+        v->arch.user_regs.r9                = c.nat->user_regs.r9;
+        v->arch.user_regs.r8                = c.nat->user_regs.r8;
         v->arch.user_regs.rbx               = c.nat->user_regs.rbx;
         v->arch.user_regs.rcx               = c.nat->user_regs.rcx;
         v->arch.user_regs.rdx               = c.nat->user_regs.rdx;
xen/arch/x86/domctl.c +8 -0
index 07f712a0a40d..3ea4c650eee0 100644
@@ -1481,6 +1481,14 @@ void arch_get_info_guest(struct vcpu *v, vcpu_guest_context_u c)
     if ( !compat )
     {
         /* Backing memory is pre-zeroed. */
+        c.nat->user_regs.r15               = v->arch.user_regs.r15;
+        c.nat->user_regs.r14               = v->arch.user_regs.r14;
+        c.nat->user_regs.r13               = v->arch.user_regs.r13;
+        c.nat->user_regs.r12               = v->arch.user_regs.r12;
+        c.nat->user_regs.r11               = v->arch.user_regs.r11;
+        c.nat->user_regs.r10               = v->arch.user_regs.r10;
+        c.nat->user_regs.r9                = v->arch.user_regs.r9;
+        c.nat->user_regs.r8                = v->arch.user_regs.r8;
         c.nat->user_regs.rbx               = v->arch.user_regs.rbx;
         c.nat->user_regs.rcx               = v->arch.user_regs.rcx;
         c.nat->user_regs.rdx               = v->arch.user_regs.rdx;
Signature · 1 line
2.54.0
Reviewed-by on v1 1/1
#1 lore raw

[4.22] Re: [PATCH] x86/domctl: restore all registers in arch_{get,set}_info_guest()

Quoted 6 lines · Marek Marczykowski-Górecki

Commit 9f892f84c279 ("x86/domctl: Stop using XLAT_cpu_user_regs()") converted memcpy() of the cpu_user_regs structure to explicit copy of its fields. In the compat case, it intentionally missed few of them, named in the commit message. But the 64bit case missed also r8-r15 registers, which was not intentional. This, at least, caused Linux 6.18.x crash when resuming PVH domU.

Oh, wow, what a bad mistake (including by me as the reviewer).

Quoted 4 lines

Fix it by adding missing assignments.

Fixes 9f892f84c279 ("x86/domctl: Stop using XLAT_cpu_user_regs()")

One remark though (equally applying to the original change):

Quoted 7 lines
xen/arch/x86/domain.c +1 -0
@@ -1255,6 +1255,14 @@ int arch_set_info_guest(
 
     if ( !compat )
     {
+        v->arch.user_regs.r15               = c.nat->user_regs.r15;

xen/arch/x86/domain.c int arch_set_info_guest( · line 1268

Quoted 10 lines
xen/arch/x86/domain.c +7 -0
+        v->arch.user_regs.r14               = c.nat->user_regs.r14;
+        v->arch.user_regs.r13               = c.nat->user_regs.r13;
+        v->arch.user_regs.r12               = c.nat->user_regs.r12;
+        v->arch.user_regs.r11               = c.nat->user_regs.r11;
+        v->arch.user_regs.r10               = c.nat->user_regs.r10;
+        v->arch.user_regs.r9                = c.nat->user_regs.r9;
+        v->arch.user_regs.r8                = c.nat->user_regs.r8;
         v->arch.user_regs.rbx               = c.nat->user_regs.rbx;
         v->arch.user_regs.rcx               = c.nat->user_regs.rcx;
         v->arch.user_regs.rdx               = c.nat->user_regs.rdx;

Neither here nor ...

Quoted 7 lines
xen/arch/x86/domctl.c +1 -0
@@ -1481,6 +1481,14 @@ void arch_get_info_guest(struct vcpu *v, vcpu_guest_context_u c)
     if ( !compat )
     {
         /* Backing memory is pre-zeroed. */
+        c.nat->user_regs.r15               = v->arch.user_regs.r15;

xen/arch/x86/domctl.c void arch_get_info_guest(struct vcpu *v, vcpu_guest_context_u c) · line 1494

Quoted 10 lines
xen/arch/x86/domctl.c +7 -0
+        c.nat->user_regs.r14               = v->arch.user_regs.r14;
+        c.nat->user_regs.r13               = v->arch.user_regs.r13;
+        c.nat->user_regs.r12               = v->arch.user_regs.r12;
+        c.nat->user_regs.r11               = v->arch.user_regs.r11;
+        c.nat->user_regs.r10               = v->arch.user_regs.r10;
+        c.nat->user_regs.r9                = v->arch.user_regs.r9;
+        c.nat->user_regs.r8                = v->arch.user_regs.r8;
         c.nat->user_regs.rbx               = v->arch.user_regs.rbx;
         c.nat->user_regs.rcx               = v->arch.user_regs.rcx;
         c.nat->user_regs.rdx               = v->arch.user_regs.rdx;

... here it becomes clear what has determined the order in which fields are copied. It's neither by register number nor by field order nor alphabetically. We might do ourselves a (however minor) favor if we used a clear criteria; likely field order would be best. The more that the new internal struct cpu_user_regs mirrors field order from the original external one. Andrew (in particular)?

Also, despite this being an issue in 4.21 already, I think this definitely wants considering for 4.22.

Jan

Reviewed-by
#2 lore raw

Re: [4.22] Re: [PATCH] x86/domctl: restore all registers in arch_{get,set}_info_guest()

Quoted 64 lines · Jan Beulich
Quoted 6 lines · Marek Marczykowski-Górecki

Commit 9f892f84c279 ("x86/domctl: Stop using XLAT_cpu_user_regs()") converted memcpy() of the cpu_user_regs structure to explicit copy of its fields. In the compat case, it intentionally missed few of them, named in the commit message. But the 64bit case missed also r8-r15 registers, which was not intentional. This, at least, caused Linux 6.18.x crash when resuming PVH domU.

Oh, wow, what a bad mistake (including by me as the reviewer).

Quoted 4 lines

Fix it by adding missing assignments.

Fixes 9f892f84c279 ("x86/domctl: Stop using XLAT_cpu_user_regs()")

One remark though (equally applying to the original change):

Quoted 7 lines
xen/arch/x86/domain.c +1 -0
@@ -1255,6 +1255,14 @@ int arch_set_info_guest(
 
      if ( !compat )
      {
+        v->arch.user_regs.r15               = c.nat->user_regs.r15;

xen/arch/x86/domain.c int arch_set_info_guest( · line 1268

Quoted 10 lines
xen/arch/x86/domain.c +7 -0
+        v->arch.user_regs.r14               = c.nat->user_regs.r14;
+        v->arch.user_regs.r13               = c.nat->user_regs.r13;
+        v->arch.user_regs.r12               = c.nat->user_regs.r12;
+        v->arch.user_regs.r11               = c.nat->user_regs.r11;
+        v->arch.user_regs.r10               = c.nat->user_regs.r10;
+        v->arch.user_regs.r9                = c.nat->user_regs.r9;
+        v->arch.user_regs.r8                = c.nat->user_regs.r8;
          v->arch.user_regs.rbx               = c.nat->user_regs.rbx;
          v->arch.user_regs.rcx               = c.nat->user_regs.rcx;
          v->arch.user_regs.rdx               = c.nat->user_regs.rdx;

Neither here nor ...

Quoted 7 lines
xen/arch/x86/domctl.c +1 -0
@@ -1481,6 +1481,14 @@ void arch_get_info_guest(struct vcpu *v, vcpu_guest_context_u c)
      if ( !compat )
      {
          /* Backing memory is pre-zeroed. */
+        c.nat->user_regs.r15               = v->arch.user_regs.r15;

xen/arch/x86/domctl.c void arch_get_info_guest(struct vcpu *v, vcpu_guest_context_u c) · line 1494

Quoted 10 lines
xen/arch/x86/domctl.c +7 -0
+        c.nat->user_regs.r14               = v->arch.user_regs.r14;
+        c.nat->user_regs.r13               = v->arch.user_regs.r13;
+        c.nat->user_regs.r12               = v->arch.user_regs.r12;
+        c.nat->user_regs.r11               = v->arch.user_regs.r11;
+        c.nat->user_regs.r10               = v->arch.user_regs.r10;
+        c.nat->user_regs.r9                = v->arch.user_regs.r9;
+        c.nat->user_regs.r8                = v->arch.user_regs.r8;
          c.nat->user_regs.rbx               = v->arch.user_regs.rbx;
          c.nat->user_regs.rcx               = v->arch.user_regs.rcx;
          c.nat->user_regs.rdx               = v->arch.user_regs.rdx;

... here it becomes clear what has determined the order in which fields are copied. It's neither by register number nor by field order nor alphabetically. We might do ourselves a (however minor) favor if we used a clear criteria; likely field order would be best. The more that the new internal struct cpu_user_regs mirrors field order from the original external one. Andrew (in particular)?

Quoted 2 lines

Also, despite this being an issue in 4.21 already, I think this definitely wants considering for 4.22.

Considering that it leads to crash of Linux I agree that we want to have this in 4.22:

Thanks.

~ Oleksii

#3 lore raw

Re: [4.22] Re: [PATCH] x86/domctl: restore all registers in arch_{get,set}_info_guest()

Quoted 3 lines · Oleksii Kurochko

Considering that it leads to crash of Linux I agree that we want to have this in 4.22:

Btw, I'm transcribing this to Release-acked-by: while preparing to commit.

Jan

#4 lore raw

Re: [4.22] Re: [PATCH] x86/domctl: restore all registers in arch_{get,set}_info_guest()

Quoted 6 lines · Jan Beulich
Quoted 3 lines · Oleksii Kurochko

Considering that it leads to crash of Linux I agree that we want to have this in 4.22:

Btw, I'm transcribing this to Release-acked-by: while preparing to commit.

Thanks. I missed to add Release-acked-by:

~ Oleksii

Reviewed-by
#5 lore raw

Re: [4.22] Re: [PATCH] x86/domctl: restore all registers in arch_{get,set}_info_guest()

In reply to Jan Beulich
Quoted 8 lines · Jan Beulich
Quoted 6 lines · Marek Marczykowski-Górecki

Commit 9f892f84c279 ("x86/domctl: Stop using XLAT_cpu_user_regs()") converted memcpy() of the cpu_user_regs structure to explicit copy of its fields. In the compat case, it intentionally missed few of them, named in the commit message. But the 64bit case missed also r8-r15 registers, which was not intentional. This, at least, caused Linux 6.18.x crash when resuming PVH domU.

Oh, wow, what a bad mistake (including by me as the reviewer).

Yes, I'm very embarrassed by this mistake.  It also highlights a serious gap in testing which we need to address.  We've managed a release and a half with PV migration plain broken before figuring out why.

Quoted 6 lines
Quoted 5 lines

Fix it by adding missing assignments.

Fixes 9f892f84c279 ("x86/domctl: Stop using XLAT_cpu_user_regs()")
Quoted 37 lines

One remark though (equally applying to the original change):

Quoted 7 lines
xen/arch/x86/domain.c +1 -0
@@ -1255,6 +1255,14 @@ int arch_set_info_guest(
 
     if ( !compat )
     {
+        v->arch.user_regs.r15               = c.nat->user_regs.r15;

xen/arch/x86/domain.c int arch_set_info_guest( · line 1268

Quoted 10 lines
xen/arch/x86/domain.c +7 -0
+        v->arch.user_regs.r14               = c.nat->user_regs.r14;
+        v->arch.user_regs.r13               = c.nat->user_regs.r13;
+        v->arch.user_regs.r12               = c.nat->user_regs.r12;
+        v->arch.user_regs.r11               = c.nat->user_regs.r11;
+        v->arch.user_regs.r10               = c.nat->user_regs.r10;
+        v->arch.user_regs.r9                = c.nat->user_regs.r9;
+        v->arch.user_regs.r8                = c.nat->user_regs.r8;
         v->arch.user_regs.rbx               = c.nat->user_regs.rbx;
         v->arch.user_regs.rcx               = c.nat->user_regs.rcx;
         v->arch.user_regs.rdx               = c.nat->user_regs.rdx;

Neither here nor ...

Quoted 15 lines
xen/arch/x86/domctl.c +8 -0
@@ -1481,6 +1481,14 @@ void arch_get_info_guest(struct vcpu *v, vcpu_guest_context_u c)
     if ( !compat )
     {
         /* Backing memory is pre-zeroed. */
+        c.nat->user_regs.r15               = v->arch.user_regs.r15;
+        c.nat->user_regs.r14               = v->arch.user_regs.r14;
+        c.nat->user_regs.r13               = v->arch.user_regs.r13;
+        c.nat->user_regs.r12               = v->arch.user_regs.r12;
+        c.nat->user_regs.r11               = v->arch.user_regs.r11;
+        c.nat->user_regs.r10               = v->arch.user_regs.r10;
+        c.nat->user_regs.r9                = v->arch.user_regs.r9;
+        c.nat->user_regs.r8                = v->arch.user_regs.r8;
         c.nat->user_regs.rbx               = v->arch.user_regs.rbx;
Quoted 8 lines

xen/arch/x86/domctl.c void arch_get_info_guest(struct vcpu *v, vcpu_guest_context_u c) · line 1494

Quoted 2 lines
xen/arch/x86/domctl.c +0 -0
         c.nat->user_regs.rcx               = v->arch.user_regs.rcx;
         c.nat->user_regs.rdx               = v->arch.user_regs.rdx;

... here it becomes clear what has determined the order in which fields are copied. It's neither by register number nor by field order nor alphabetically. We might do ourselves a (however minor) favor if we used a clear criteria; likely field order would be best. The more that the new internal struct cpu_user_regs mirrors field order from the original external one. Andrew (in particular)?

They are the order that XLAT_cpu_user_regs() expanded in; that is - x86_32's cpu_user_regs field order.

... which now I think about it is correct for one of the two uses of XLAT_cpu_user_regs() but suboptimal for the other.

They all want to be field-order of the loading side, because that way we're working with the prefetcher rather than against it.

I'm making a follow-up, because I think it's more complicated than just interleaving these lines, and I suggest we take Marek's patch as-is.

~Andrew

#6 lore raw

Re: [4.22] Re: [PATCH] x86/domctl: restore all registers in arch_{get,set}_info_guest()

Quoted 9 lines · Andrew Cooper
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Marek Marczykowski-Górecki

Commit 9f892f84c279 ("x86/domctl: Stop using XLAT_cpu_user_regs()") converted memcpy() of the cpu_user_regs structure to explicit copy of its fields. In the compat case, it intentionally missed few of them, named in the commit message. But the 64bit case missed also r8-r15 registers, which was not intentional. This, at least, caused Linux 6.18.x crash when resuming PVH domU.

Quoted 6 lines
Quoted 1 line

Oh, wow, what a bad mistake (including by me as the reviewer).

Yes, I'm very embarrassed by this mistake. It also highlights a serious gap in testing which we need to address. We've managed a release and a half with PV migration plain broken before figuring out why.

...

Is migration tested by CI or just for some reason this was not captured?

Frediano

#7 lore raw

Re: [4.22] Re: [PATCH] x86/domctl: restore all registers in arch_{get,set}_info_guest()

Quoted 12 lines · Frediano Ziglio
Quoted 11 lines · Andrew Cooper
Quoted 8 lines · Jan Beulich
Quoted 6 lines · Marek Marczykowski-Górecki

Commit 9f892f84c279 ("x86/domctl: Stop using XLAT_cpu_user_regs()") converted memcpy() of the cpu_user_regs structure to explicit copy of its fields. In the compat case, it intentionally missed few of them, named in the commit message. But the 64bit case missed also r8-r15 registers, which was not intentional. This, at least, caused Linux 6.18.x crash when resuming PVH domU.

Oh, wow, what a bad mistake (including by me as the reviewer).

Quoted 7 lines
Quoted 4 lines

Yes, I'm very embarrassed by this mistake. It also highlights a serious gap in testing which we need to address. We've managed a release and a half with PV migration plain broken before figuring out why.

...

Is migration tested by CI or just for some reason this was not captured?

It was in osstest, but it isn't in gitlab. I'll cleanup my current test and submit it, but I'd really appreciate committing the (reviewed/acked) test-artifacts series[1], as some of the pending tests depend on it (although the suspend one doesn't).

[1] https://lore.kernel.org/xen-devel/ah24pfWb_orPRaJG@mail-itl/

Signature · 3 lines
Best Regards,
Marek Marczykowski-Górecki
Invisible Things Lab
Reviewed-by on v1 1/1
#8 lore raw
In reply to Marek Marczykowski-Górecki

Le 20/07/2026 à 02:16, Marek Marczykowski-Górecki a écrit :

Quoted 11 lines

Commit 9f892f84c279 ("x86/domctl: Stop using XLAT_cpu_user_regs()") converted memcpy() of the cpu_user_regs structure to explicit copy of its fields. In the compat case, it intentionally missed few of them, named in the commit message. But the 64bit case missed also r8-r15 registers, which was not intentional. This, at least, caused Linux 6.18.x crash when resuming PVH domU.

Fix it by adding missing assignments.

Fixes 9f892f84c279 ("x86/domctl: Stop using XLAT_cpu_user_regs()")
Reviewed-by on v1 1/1
#9 lore raw
In reply to Marek Marczykowski-Górecki
Quoted 45 lines · Marek Marczykowski-Górecki

Commit 9f892f84c279 ("x86/domctl: Stop using XLAT_cpu_user_regs()") converted memcpy() of the cpu_user_regs structure to explicit copy of its fields. In the compat case, it intentionally missed few of them, named in the commit message. But the 64bit case missed also r8-r15 registers, which was not intentional. This, at least, caused Linux 6.18.x crash when resuming PVH domU.

Fix it by adding missing assignments.

Fixes 9f892f84c279 ("x86/domctl: Stop using XLAT_cpu_user_regs()")
---
 xen/arch/x86/domain.c | 8 ++++++++
 xen/arch/x86/domctl.c | 8 ++++++++
 2 files changed, 16 insertions(+)
xen/arch/x86/domain.c +8 -0
index 1d458f1372e5..ba7244ccc513 100644
@@ -1255,6 +1255,14 @@ int arch_set_info_guest(
 
     if ( !compat )
     {
+        v->arch.user_regs.r15               = c.nat->user_regs.r15;
+        v->arch.user_regs.r14               = c.nat->user_regs.r14;
+        v->arch.user_regs.r13               = c.nat->user_regs.r13;
+        v->arch.user_regs.r12               = c.nat->user_regs.r12;
+        v->arch.user_regs.r11               = c.nat->user_regs.r11;
+        v->arch.user_regs.r10               = c.nat->user_regs.r10;
+        v->arch.user_regs.r9                = c.nat->user_regs.r9;
+        v->arch.user_regs.r8                = c.nat->user_regs.r8;
         v->arch.user_regs.rbx               = c.nat->user_regs.rbx;
         v->arch.user_regs.rcx               = c.nat->user_regs.rcx;
         v->arch.user_regs.rdx               = c.nat->user_regs.rdx;
xen/arch/x86/domctl.c +1 -0
index 07f712a0a40d..3ea4c650eee0 100644
@@ -1481,6 +1481,14 @@ void arch_get_info_guest(struct vcpu *v, vcpu_guest_context_u c)
     if ( !compat )
     {
         /* Backing memory is pre-zeroed. */
+        c.nat->user_regs.r15               = v->arch.user_regs.r15;

xen/arch/x86/domctl.c void arch_get_info_guest(struct vcpu *v, vcpu_guest_context_u c) · line 1494

Quoted 10 lines
xen/arch/x86/domctl.c +7 -0
+        c.nat->user_regs.r14               = v->arch.user_regs.r14;
+        c.nat->user_regs.r13               = v->arch.user_regs.r13;
+        c.nat->user_regs.r12               = v->arch.user_regs.r12;
+        c.nat->user_regs.r11               = v->arch.user_regs.r11;
+        c.nat->user_regs.r10               = v->arch.user_regs.r10;
+        c.nat->user_regs.r9                = v->arch.user_regs.r9;
+        c.nat->user_regs.r8                = v->arch.user_regs.r8;
         c.nat->user_regs.rbx               = v->arch.user_regs.rbx;
         c.nat->user_regs.rcx               = v->arch.user_regs.rcx;
         c.nat->user_regs.rdx               = v->arch.user_regs.rdx;

Frediano