Skip to contentSkip to conversation

x86/PV32: fix physdev_op_compat handling

PATCH Superseded Jan Beulich 2 participants 3 messages Oct 8, 2021 – Oct 11, 2021

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/PV32: fix physdev_op_compat handling

The conversion of the original code failed to recognize that the 32-bit compat variant of this (sorry, two different meanings of "compat" here) needs to continue to invoke the compat handler, not the native one. Arrange for this and also remove the one #define that hasn't been necessary anymore as of that change.

Affected functions (having existed prior to the introduction of the new hypercall) are PHYSDEVOP_set_iobitmap and PHYSDEVOP_apic_{read,write}. For all others the operand struct layout doesn't differ.

Fixes 1252e2823117 ("x86/pv: Export pv_hypercall_table[] rather than working around it in several ways")

---
Additionally the XSA-344 fix causes guest register corruption afaict, when EVTCHNOP_reset gets called through the compat function and needs a continuation. While guests shouldn't invoke that function this way, I think we would better have forced all pre-3.2-unavailable functions into an error path, rather than forwarding them to the actual handler. I'm not sure though how relevant we consider it to fix this (one way or another).

xen/arch/x86/x86_64/compat.c +1 -1
@@ -10,8 +10,8 @@ EMIT_FILE;
 
 #define physdev_op                    compat_physdev_op
 #define physdev_op_t                  physdev_op_compat_t
-#define do_physdev_op                 compat_physdev_op
 #define do_physdev_op_compat(x)       compat_physdev_op_compat(_##x)
+#define native                        compat
 
 #define COMPAT
 #define _XEN_GUEST_HANDLE(t) XEN_GUEST_HANDLE(t)
#1 lore raw
Quoted 9 lines · Jan Beulich

The conversion of the original code failed to recognize that the 32-bit compat variant of this (sorry, two different meanings of "compat" here) needs to continue to invoke the compat handler, not the native one. Arrange for this and also remove the one #define that hasn't been necessary anymore as of that change.

Affected functions (having existed prior to the introduction of the new hypercall) are PHYSDEVOP_set_iobitmap and PHYSDEVOP_apic_{read,write}. For all others the operand struct layout doesn't differ.

:-/

Neither of those ABI breakages would be subtle.  But why didn't XTF notice?  Edit: It appears as if my PHYSDEVOP_set_iobitmap tests never got completed.

Quoted 11 lines
Fixes 1252e2823117 ("x86/pv: Export pv_hypercall_table[] rather than working around it in several ways")

---
Additionally the XSA-344 fix causes guest register corruption afaict, when EVTCHNOP_reset gets called through the compat function and needs a continuation. While guests shouldn't invoke that function this way, I think we would better have forced all pre-3.2-unavailable functions into an error path, rather than forwarding them to the actual handler. I'm not sure though how relevant we consider it to fix this (one way or another).

EVTCHNOP_reset{,_cont} are -ENOSYS'd in do_event_channel_op_compat() without being forwarded.  I can't see a problem.

But yes - we'd have problems if any pre-3.2-available functions needed to become continuable.

We ought to consider dropping compatibility for guests that obsolete...

xen/arch/x86/x86_64/compat.c EMIT_FILE; · line 13

Quoted 8 lines
xen/arch/x86/x86_64/compat.c +0 -1
@@ -10,8 +10,8 @@ EMIT_FILE;
 
 #define physdev_op                    compat_physdev_op
 #define physdev_op_t                  physdev_op_compat_t
-#define do_physdev_op                 compat_physdev_op

This is still needed, technically.  It impacts the typeof() expression:

typeof(do_physdev_op) *fn =
    (void *)pv_hypercall_table[__HYPERVISOR_physdev_op].native;

and the reason why everything compiles is because
{do,compat}_physdev_op() have identical types.

~Andrew

Quoted 6 lines
xen/arch/x86/x86_64/compat.c +1 -0
 #define do_physdev_op_compat(x)       compat_physdev_op_compat(_##x)
+#define native                        compat
 
 #define COMPAT
 #define _XEN_GUEST_HANDLE(t) XEN_GUEST_HANDLE(t)
#2 lore raw
Quoted 11 lines · Andrew Cooper
Quoted 9 lines · Jan Beulich

The conversion of the original code failed to recognize that the 32-bit compat variant of this (sorry, two different meanings of "compat" here) needs to continue to invoke the compat handler, not the native one. Arrange for this and also remove the one #define that hasn't been necessary anymore as of that change.

Affected functions (having existed prior to the introduction of the new hypercall) are PHYSDEVOP_set_iobitmap and PHYSDEVOP_apic_{read,write}. For all others the operand struct layout doesn't differ.

Quoted 5 lines

:-/

Neither of those ABI breakages would be subtle.  But why didn't XTF notice?  Edit: It appears as if my PHYSDEVOP_set_iobitmap tests never got completed.

But the XTF would have used the modern hypercall, wouldn't it? At least the pv-iopl test does.

Quoted 10 lines
Quoted 7 lines

Additionally the XSA-344 fix causes guest register corruption afaict, when EVTCHNOP_reset gets called through the compat function and needs a continuation. While guests shouldn't invoke that function this way, I think we would better have forced all pre-3.2-unavailable functions into an error path, rather than forwarding them to the actual handler. I'm not sure though how relevant we consider it to fix this (one way or another).

EVTCHNOP_reset{,_cont} are -ENOSYS'd in do_event_channel_op_compat() without being forwarded.  I can't see a problem.

You're right - I think I did look at do_physdev_op_compat() deriving evtchn-compat behavior from there as well.

Quoted 10 lines

xen/arch/x86/x86_64/compat.c EMIT_FILE; · line 13

Quoted 7 lines
xen/arch/x86/x86_64/compat.c +0 -1
@@ -10,8 +10,8 @@ EMIT_FILE;
 
 #define physdev_op                    compat_physdev_op
 #define physdev_op_t                  physdev_op_compat_t
-#define do_physdev_op                 compat_physdev_op

This is still needed, technically.  It impacts the typeof() expression:

Quoted 5 lines

typeof(do_physdev_op) *fn =
    (void *)pv_hypercall_table[__HYPERVISOR_physdev_op].native;

and the reason why everything compiles is because
{do,compat}_physdev_op() have identical types.

Oh, indeed - thanks for pointing out.

Jan