Skip to contentSkip to conversation

[4.17] x86: (re-)wire two VCPUOP_* for 32-bit guests

PATCH In review Jan Beulich 3 participants 9 messages Sep 29, 2022

lore
Share & tools
lore
#0 lore raw

cover [4.17] x86: (re-)wire two VCPUOP_* for 32-bit guests

1: re-connect VCPUOP_send_nmi for 32-bit guests
2: wire up VCPUOP_register_vcpu_time_memory_area for 32-bit guests

As to 4.17: Patch 1 addresses a recently introduced regression, while the issue patch 2 addresses has been there effectively forever (so cannot really be viewed as a regression).

Jan

#1 lore raw

PATCH 1/2 [4.17] x86: re-connect VCPUOP_send_nmi for 32-bit guests

With the "inversion" of VCPUOP handling, processing arch-specific ones first, the forwarding of this sub-op from the (common) compat handler to (common) non-compat one did no longer have the intended effect. It now needs forwarding between the arch-specific handlers.

Fixes 8a96c0ea7999 ("xen: move do_vcpu_op() to arch specific code")
xen/arch/x86/x86_64/domain.c +1 -0
@@ -58,6 +58,7 @@ compat_vcpu_op(int cmd, unsigned int vcp
         break;
     }
 
+    case VCPUOP_send_nmi:
     case VCPUOP_get_physid:
         rc = do_vcpu_op(cmd, vcpuid, arg);
         break;
xen/common/compat/domain.c +0 -1
@@ -99,7 +99,6 @@ int compat_common_vcpu_op(int cmd, struc
     case VCPUOP_stop_periodic_timer:
     case VCPUOP_stop_singleshot_timer:
     case VCPUOP_register_vcpu_info:
-    case VCPUOP_send_nmi:
         rc = common_vcpu_op(cmd, v, arg);
         break;
 
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2][4.17] x86: re-connect VCPUOP_send_nmi for 32-bit guests

Quoted 7 lines · Jan Beulich

With the "inversion" of VCPUOP handling, processing arch-specific ones first, the forwarding of this sub-op from the (common) compat handler to (common) non-compat one did no longer have the intended effect. It now needs forwarding between the arch-specific handlers.

Fixes 8a96c0ea7999 ("xen: move do_vcpu_op() to arch specific code")

This seems prone to errors, I wonder if we should add a note to do_vcpu_op() to notice that hypercalls handled there need to be explicitly forwarded from compat_vcpu_op.

I've also noticed that compat_common_vcpu_op() forwards VCPUOP_set_singleshot_timer to do_vcpu_op(), but that seems to be an useless jump, shouldn't it forward directly to common_vcpu_op()?

Thanks, Roger.

#3 lore raw

Re: [PATCH 1/2][4.17] x86: re-connect VCPUOP_send_nmi for 32-bit guests

Quoted 10 lines · Roger Pau Monné
Quoted 7 lines · Jan Beulich

With the "inversion" of VCPUOP handling, processing arch-specific ones first, the forwarding of this sub-op from the (common) compat handler to (common) non-compat one did no longer have the intended effect. It now needs forwarding between the arch-specific handlers.

Fixes 8a96c0ea7999 ("xen: move do_vcpu_op() to arch specific code")

Thanks.

Quoted 3 lines

This seems prone to errors, I wonder if we should add a note to do_vcpu_op() to notice that hypercalls handled there need to be explicitly forwarded from compat_vcpu_op.

Perhaps. I guess if such a comment had been added by the original change, the mistake corrected here would have been noticed right away.

Quoted 3 lines

I've also noticed that compat_common_vcpu_op() forwards VCPUOP_set_singleshot_timer to do_vcpu_op(), but that seems to be an useless jump, shouldn't it forward directly to common_vcpu_op()?

Looks like another (less severe) oversight, yes. Do you want to make a patch or should I?

Jan

#4 lore raw

RE: [PATCH 1/2][4.17] x86: re-connect VCPUOP_send_nmi for 32-bit guests

In reply to Jan Beulich

Hi Jan,

Quoted 5 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Subject: [PATCH 1/2][4.17] x86: re-connect VCPUOP_send_nmi for 32-bit guests

Quoted 7 lines

With the "inversion" of VCPUOP handling, processing arch-specific ones first, the forwarding of this sub-op from the (common) compat handler to (common) non-compat one did no longer have the intended effect. It now needs forwarding between the arch-specific handlers.

Fixes 8a96c0ea7999 ("xen: move do_vcpu_op() to arch specific code")

From the cover letter I found this is a bug fix for a recently introduced regression. So I believe this should be merged for 4.17, hence:

Kind regards,
Henry

#5 lore raw

PATCH 2/2 [4.17?] x86: wire up VCPUOP_register_vcpu_time_memory_area for 32-bit guests

In reply to Jan Beulich

Forever sinced its introduction VCPUOP_register_vcpu_time_memory_area was available only to native domains. Linux, for example, would attempt to use it irrespective of guest bitness (including in its so called PVHVM mode) as long as it finds XEN_PVCLOCK_TSC_STABLE_BIT set (which we set only for clocksource=tsc, which in turn needs engaging via command line option).

Fixes a5d39947cb89 ("Allow guests to register secondary vcpu_time_info")

---
Is it actually correct for us to do cross-vCPU updates of the area here (and also in the native counterpart as well as for runstate area updates)? The virtual address may be valid for the given vCPU only, but may be mapped to something else on the current vCPU (yet we only deal with it not being mapped at all). Note how HVM code already calls update_vcpu_system_time() only when v == current.

I'm surprised by Linux not using the secondary area in a broader fashion. But I'm also surprised that they would only ever register an area for vCPU 0.

xen/arch/x86/x86_64/domain.c +20 -0
@@ -58,6 +58,26 @@ compat_vcpu_op(int cmd, unsigned int vcp
         break;
     }
 
+    case VCPUOP_register_vcpu_time_memory_area:
+    {
+        struct compat_vcpu_register_time_memory_area area = { .addr.p = 0 };
+
+        rc = -EFAULT;
+        if ( copy_from_guest(&area.addr.h, arg, 1) )
+            break;
+
+        if ( area.addr.h.c != area.addr.p ||
+             !compat_handle_okay(area.addr.h, 1) )
+            break;
+
+        rc = 0;
+        guest_from_compat_handle(v->arch.time_info_guest, area.addr.h);
+
+        force_update_vcpu_system_time(v);
+
+        break;
+    }
+
     case VCPUOP_send_nmi:
     case VCPUOP_get_physid:
         rc = do_vcpu_op(cmd, vcpuid, arg);
#6 lore raw

RE: [PATCH 2/2][4.17?] x86: wire up VCPUOP_register_vcpu_time_memory_area for 32-bit guests

Hi Jan,

Quoted 23 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Subject: [PATCH 2/2][4.17?] x86: wire up VCPUOP_register_vcpu_time_memory_area for 32-bit guests

Forever sinced its introduction VCPUOP_register_vcpu_time_memory_area was available only to native domains. Linux, for example, would attempt to use it irrespective of guest bitness (including in its so called PVHVM mode) as long as it finds XEN_PVCLOCK_TSC_STABLE_BIT set (which we
set only for clocksource=tsc, which in turn needs engaging via command line option).

Fixes a5d39947cb89 ("Allow guests to register secondary vcpu_time_info")

---
Is it actually correct for us to do cross-vCPU updates of the area here (and also in the native counterpart as well as for runstate area updates)? The virtual address may be valid for the given vCPU only, but may be mapped to something else on the current vCPU (yet we only deal with it not being mapped at all). Note how HVM code already calls update_vcpu_system_time() only when v == current.

Quoted 3 lines

I'm surprised by Linux not using the secondary area in a broader fashion. But I'm also surprised that they would only ever register an area for vCPU 0.

I re-read the guide for release manager, and it tells me that "in feature freeze and early stage of code freeze, bug fixes are encouraged to be merged, while in the late stage of code freeze, complex bug fixes might be rejected if the risk of accepting is higher than the risk of rejecting it".

Hence I guess in current stage, I would not block this patch for release. If this patch is acked/reviewed by other x86 maintainers, feel free to add:

Kind regards,
Henry

Acked-by on v1 2/2
#7 lore raw

Re: [PATCH 2/2][4.17?] x86: wire up VCPUOP_register_vcpu_time_memory_area for 32-bit guests

In reply to Jan Beulich
Quoted 9 lines · Jan Beulich

Forever sinced its introduction VCPUOP_register_vcpu_time_memory_area was available only to native domains. Linux, for example, would attempt to use it irrespective of guest bitness (including in its so called PVHVM mode) as long as it finds XEN_PVCLOCK_TSC_STABLE_BIT set (which we set only for clocksource=tsc, which in turn needs engaging via command line option).

Fixes a5d39947cb89 ("Allow guests to register secondary vcpu_time_info")

Albeit I have concerns with the notes you raise below, not sure we also want to introduce a (broken') compat version of the same hypercall wrt v != current.

Quoted 11 lines

---
Is it actually correct for us to do cross-vCPU updates of the area here (and also in the native counterpart as well as for runstate area updates)? The virtual address may be valid for the given vCPU only, but may be mapped to something else on the current vCPU (yet we only deal with it not being mapped at all). Note how HVM code already calls update_vcpu_system_time() only when v == current.

I'm surprised by Linux not using the secondary area in a broader fashion. But I'm also surprised that they would only ever register an area for vCPU 0.

Would be better to update locally just when v == current, otherwise issue an IPI to the remote vCPU dirty mask and force an update on resume to guest path?

xen/arch/x86/x86_64/domain.c compat_vcpu_op(int cmd, unsigned int vcp · line 63

Quoted 10 lines
xen/arch/x86/x86_64/domain.c +3 -0
@@ -58,6 +58,26 @@ compat_vcpu_op(int cmd, unsigned int vcp
         break;
     }
 
+    case VCPUOP_register_vcpu_time_memory_area:
+    {
+        struct compat_vcpu_register_time_memory_area area = { .addr.p = 0 };

Why not just use { } to initialize?

Thanks, Roger.

#8 lore raw

Re: [PATCH 2/2][4.17?] x86: wire up VCPUOP_register_vcpu_time_memory_area for 32-bit guests

Quoted 8 lines · Roger Pau Monné
Quoted 7 lines · Jan Beulich

Forever sinced its introduction VCPUOP_register_vcpu_time_memory_area was available only to native domains. Linux, for example, would attempt to use it irrespective of guest bitness (including in its so called PVHVM mode) as long as it finds XEN_PVCLOCK_TSC_STABLE_BIT set (which we set only for clocksource=tsc, which in turn needs engaging via command line option).

Quoted 4 lines
Quoted 2 lines
Fixes a5d39947cb89 ("Allow guests to register secondary vcpu_time_info")

Thanks.

Quoted 3 lines

Albeit I have concerns with the notes you raise below, not sure we also want to introduce a (broken') compat version of the same hypercall wrt v != current.

Since "compat" is ambiguous in this context - I guess you don't mean just the variant for compat guests? Independent of that I'm afraid I don't see how a separate variant would help: If the cross-vCPU copying is not okay, then existing users as affected already, and would rather have the single variant work correctly. And if the newly added variant would be the one with the broken behavior, why would anyone switch to using it?

Quoted 8 lines
Quoted 8 lines

---
Is it actually correct for us to do cross-vCPU updates of the area here (and also in the native counterpart as well as for runstate area updates)? The virtual address may be valid for the given vCPU only, but may be mapped to something else on the current vCPU (yet we only deal with it not being mapped at all). Note how HVM code already calls update_vcpu_system_time() only when v == current.

Quoted 7 lines
Quoted 3 lines

I'm surprised by Linux not using the secondary area in a broader fashion. But I'm also surprised that they would only ever register an area for vCPU 0.

Would be better to update locally just when v == current, otherwise issue an IPI to the remote vCPU dirty mask and force an update on resume to guest path?

Yes, that's the outline of how to deal with this _if_ we determine the present behavior is flawed. Determination is difficult since, like with so many things, this is something that's not spelled out anywhere.

Quoted 11 lines

xen/arch/x86/x86_64/domain.c compat_vcpu_op(int cmd, unsigned int vcp · line 63

Quoted 9 lines
xen/arch/x86/x86_64/domain.c +3 -0
@@ -58,6 +58,26 @@ compat_vcpu_op(int cmd, unsigned int vcp
         break;
     }
 
+    case VCPUOP_register_vcpu_time_memory_area:
+    {
+        struct compat_vcpu_register_time_memory_area area = { .addr.p = 0 };

Why not just use { } to initialize?

I wanted to match (a) the VCPUOP_register_runstate_memory_area handling further up, just without using a separate assignment and (b) this line

        if ( area.addr.h.c != area.addr.p ||

And yes, initially I did consider using just { }.

Jan