evtchn: Introduce a per-guest knob to control FIFO ABI
v4 cover evtchn: Introduce a per-guest knob to control FIFO ABI
From: Paul Durrant <[email protected]>
This series is the next version of what was originally a single patch sent by Eslam Elnikety <[email protected]>. I have re-based and slightly expanded the modifications.
Paul Durrant (3):
domctl: introduce a new domain create flag,
XEN_DOMCTL_CDF_disable_fifo, ...
libxl: add a 'disable_fifo_evtchn' flag to libxl_domain_build_info ...
xl: add 'disable_evtchn_fifo' boolean option into xl.cfg(5) ...
docs/man/xl.cfg.5.pod.in | 8 ++++++++ tools/include/libxl.h | 8 ++++++++ tools/libs/light/libxl_create.c | 5 +++++ tools/libs/light/libxl_types.idl | 1 + tools/ocaml/libs/xc/xenctrl.ml | 1 + tools/ocaml/libs/xc/xenctrl.mli | 1 + tools/xl/xl_parse.c | 3 +++ xen/common/domain.c | 2 +- xen/common/event_channel.c | 17 +++++++++++++++++ xen/include/public/domctl.h | 4 +++- 10 files changed, 48 insertions(+), 2 deletions(-)
Signature · 1 line
2.20.1
PATCH v4 1/3 domctl: introduce a new domain create flag, XEN_DOMCTL_CDF_disable_fifo, ...
From: Paul Durrant <[email protected]>
...to control the visibility of the FIFO event channel operations (EVTCHNOP_init_control, EVTCHNOP_expand_array, and EVTCHNOP_set_priority) to the guest.
These operations were added to the public header in commit d2d50c2f308f ("evtchn: add FIFO-based event channel ABI") and the first implementation appeared in the two subsequent commits: edc8872aeb4a ("evtchn: implement EVTCHNOP_set_priority and add the set_priority hook") and 88910061ec61 ("evtchn: add FIFO-based event channel hypercalls and port ops"). Prior to that, a guest issuing those operations would receive a return value of -ENOSYS (not implemented) from Xen. Guests aware of the FIFO operations but running on an older (pre-4.4) Xen would fall back to using the 2-level event channel interface upon seeing this return value.
Unfortunately the uncontrolable appearance of these new operations in Xen 4.4 onwards has implications for hibernation of some Linux guests. During resume from hibernation, there are two kernels involved: the "boot" kernel and the "resume" kernel. The guest boot kernel may default to use FIFO operations and instruct Xen via EVTCHNOP_init_control to switch from 2-level to FIFO. On the other hand, the resume kernel keeps assuming 2-level, because it was hibernated on a version of Xen that did not support the FIFO operations.
To maintain compatibility it is necessary to make Xen behave as it did before the new operations were added and hence the code in this patch ensures that, if XEN_DOMCTL_CDF_disable_fifo is set, the FIFO event channel operations will again result in -ENOSYS being returned to the guest.
---
Cc: Christian Lindig <[email protected]>
Cc: David Scott <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Stefano Stabellini <[email protected]>
v4:
- New in v4
--- tools/ocaml/libs/xc/xenctrl.ml | 1 + tools/ocaml/libs/xc/xenctrl.mli | 1 + xen/common/domain.c | 2 +- xen/common/event_channel.c | 17 +++++++++++++++++ xen/include/public/domctl.h | 4 +++- 5 files changed, 23 insertions(+), 2 deletions(-)
tools/ocaml/libs/xc/xenctrl.ml +1 -0
@@ -65,6 +65,7 @@ type domain_create_flag = | CDF_XS_DOMAIN | CDF_IOMMU | CDF_NESTED_VIRT + | CDF_DISABLE_FIFO type domain_create_iommu_opts = | IOMMU_NO_SHAREPT
tools/ocaml/libs/xc/xenctrl.mli +1 -0
@@ -58,6 +58,7 @@ type domain_create_flag = | CDF_XS_DOMAIN | CDF_IOMMU | CDF_NESTED_VIRT + | CDF_DISABLE_FIFO type domain_create_iommu_opts = | IOMMU_NO_SHAREPT
xen/common/domain.c +1 -1
@@ -307,7 +307,7 @@ static int sanitise_domain_config(struct xen_domctl_createdomain *config) ~(XEN_DOMCTL_CDF_hvm | XEN_DOMCTL_CDF_hap | XEN_DOMCTL_CDF_s3_integrity | XEN_DOMCTL_CDF_oos_off | XEN_DOMCTL_CDF_xs_domain | XEN_DOMCTL_CDF_iommu | - XEN_DOMCTL_CDF_nested_virt) ) + XEN_DOMCTL_CDF_nested_virt | XEN_DOMCTL_CDF_disable_fifo) ) {dprintk (XENLOG_INFO ,"Unknown CDF flags %#x\n" , config->flags);return -EINVAL ;
xen/common/event_channel.c +17 -0
@@ -1193,10 +1193,27 @@ static long evtchn_set_priority(const struct evtchn_set_priority *set_priority)return ret; } +static bool is_fifo_op (int cmd) +{ +switch ( cmd ) + { +case EVTCHNOP_init_control: +case EVTCHNOP_expand_array: +case EVTCHNOP_set_priority: +return true; +default : +return false; + } +} +long do_event_channel_op (int cmd,XEN_GUEST_HANDLE_PARAM (void ) arg) {long rc; +if ( (current->domain->options & XEN_DOMCTL_CDF_disable_fifo) && +is_fifo_op (cmd) ) +return -ENOSYS ; +switch ( cmd ) {case EVTCHNOP_alloc_unbound: {
xen/include/public/domctl.h +3 -1
@@ -70,9 +70,11 @@ struct xen_domctl_createdomain {#define XEN_DOMCTL_CDF_iommu (1U<<_XEN_DOMCTL_CDF_iommu)#define _XEN_DOMCTL_CDF_nested_virt 6#define XEN_DOMCTL_CDF_nested_virt (1U << _XEN_DOMCTL_CDF_nested_virt) +#define _XEN_DOMCTL_CDF_disable_fifo 7 +#define XEN_DOMCTL_CDF_disable_fifo (1U << _XEN_DOMCTL_CDF_disable_fifo)/* Max XEN_DOMCTL_CDF_* constant. Used for ABI checking. */ -#define XEN_DOMCTL_CDF_MAX XEN_DOMCTL_CDF_nested_virt +#define XEN_DOMCTL_CDF_MAX XEN_DOMCTL_CDF_disable_fifouint32_t flags;
Signature · 1 line
2.20.1
Re: [PATCH v4 1/3] domctl: introduce a new domain create flag, XEN_DOMCTL_CDF_disable_fifo, ...
Quoted 16 lines · Paul Durrant
From: Paul Durrant <[email protected]>
...to control the visibility of the FIFO event channel operations (
EVTCHNOP_init_control,EVTCHNOP_expand_array, andEVTCHNOP_set_priority) to the guest.These operations were added to the public header in commit
d2d50c2f308f("evtchn: add FIFO-based event channel ABI") and the first implementation appeared in the two subsequent commits:edc8872aeb4a("evtchn: implementEVTCHNOP_set_priorityand add theset_priorityhook") and88910061ec61("evtchn: add FIFO-based event channel hypercalls and port ops"). Prior to that, a guest issuing those operations would receive a return value of-ENOSYS(not implemented) from Xen. Guests aware of the FIFO operations but running on an older (pre-4.4) Xen would fall back to using the 2-level event channel interface upon seeing this return value.
Quoted 7 lines
Unfortunately the uncontrolable appearance of these new operations in Xen 4.4 onwards has implications for hibernation of some Linux guests. During resume from hibernation, there are two kernels involved: the "boot" kernel and the "resume" kernel. The guest boot kernel may default to use FIFO operations and instruct Xen via
EVTCHNOP_init_controlto switch from 2-level to FIFO. On the other hand, the resume kernel keeps assuming 2-level, because it was hibernated on a version of Xen that did not support the FIFO operations.
And the alternative of the boot kernel issuing EVTCHNOP_reset has other unwanted consequences. Maybe worth mentioning here, as otherwise this would look like the obvious way to return to 2-level mode?
Also, why can't the boot kernel be instructed to avoid engaging FIFO mode?
Quoted 4 lines
To maintain compatibility it is necessary to make Xen behave as it did before the new operations were added and hence the code in this patch ensures that, if
XEN_DOMCTL_CDF_disable_fifois set, the FIFO event channel operations will again result in-ENOSYSbeing returned to the guest.
Are there indeed dependencies on the precise return value anywhere? If so, the generally inappropriate use (do_event_channel_op()'s default case really would also need switching) would want a brief comment, so it'll be understood by readers that this isn't code to derive other code from. If not, -EPERM or -EACCES perhaps?
Also, now that we gain a runtime control, do we perhaps also want a build time one?
Quoted 2 lines
Signed-off-by Paul Durrant <[email protected]>Signed-off-by Eslam Elnikety <[email protected]>
Are this order as well as the From: tag above correct? Or alternatively, are there actually any pieces left at all from Eslam's earlier patch?
Quoted 2 lines
v4:
- New in v4
(Just as an aside: That's quite interesting for a previously standalone patch. I guess that patch was really split, considering you've retained Eslam's S-o-b? But perhaps there are different ways to look at things ...)
xen/include/public/domctl.h struct xen_domctl_createdomain { · line 74
Quoted 8 lines
xen/include/public/domctl.h +2
-0@@ -70,9 +70,11 @@ struct xen_domctl_createdomain {#define XEN_DOMCTL_CDF_iommu (1U<<_XEN_DOMCTL_CDF_iommu)#define _XEN_DOMCTL_CDF_nested_virt 6#define XEN_DOMCTL_CDF_nested_virt (1U << _XEN_DOMCTL_CDF_nested_virt) +#define _XEN_DOMCTL_CDF_disable_fifo 7 +#define XEN_DOMCTL_CDF_disable_fifo (1U << _XEN_DOMCTL_CDF_disable_fifo)
Despite getting longish, I think this needs "evtchn" somewhere in the name. To keep size bounded, maybe XEN_DOMCTL_CDF_no_fifo_evtchn?
xen/include/public/domctl.h struct xen_domctl_createdomain { · line 77
Quoted 3 lines
xen/include/public/domctl.h +1
-1/* Max XEN_DOMCTL_CDF_* constant. Used for ABI checking. */ -#define XEN_DOMCTL_CDF_MAX XEN_DOMCTL_CDF_nested_virt +#define XEN_DOMCTL_CDF_MAX XEN_DOMCTL_CDF_disable_fifo
While not directly related to this patch, I'm puzzled by the presence of this constant: I've not been able to find any use of it. In particular you did have a need to modify sanitise_domain_config().
Jan
Re: [PATCH v4 1/3] domctl: introduce a new domain create flag, XEN_DOMCTL_CDF_disable_fifo, ...
Quoted 13 lines · Jan Beulich
xen/include/public/domctl.h struct xen_domctl_createdomain { · line 74
Quoted 8 lines · Paul Durrant
xen/include/public/domctl.h +2
-0@@ -70,9 +70,11 @@ struct xen_domctl_createdomain {#define XEN_DOMCTL_CDF_iommu (1U<<_XEN_DOMCTL_CDF_iommu)#define _XEN_DOMCTL_CDF_nested_virt 6#define XEN_DOMCTL_CDF_nested_virt (1U << _XEN_DOMCTL_CDF_nested_virt) +#define _XEN_DOMCTL_CDF_disable_fifo 7 +#define XEN_DOMCTL_CDF_disable_fifo (1U << _XEN_DOMCTL_CDF_disable_fifo)Despite getting longish, I think this needs "evtchn" somewhere in the name. To keep size bounded, maybe
XEN_DOMCTL_CDF_no_fifo_evtchn?
Quoted 8 lines
xen/include/public/domctl.h struct xen_domctl_createdomain { · line 77
Quoted 3 lines
xen/include/public/domctl.h +1
-1/* Max XEN_DOMCTL_CDF_* constant. Used for ABI checking. */ -#define XEN_DOMCTL_CDF_MAX XEN_DOMCTL_CDF_nested_virt +#define XEN_DOMCTL_CDF_MAX XEN_DOMCTL_CDF_disable_fifoWhile not directly related to this patch, I'm puzzled by the presence of this constant: I've not been able to find any use of it. In particular you did have a need to modify
sanitise_domain_config().
So it was you to introduce this, right away without any user, in 7fb0e134f8c6 ("tools/ocaml: abi: Use formal conversion and check in more places"). The only reference is from what I regard as a comment (I don't speak any ocaml, so I may be wrong). Could you clarify why we need to maintain this constant?
Thanks, Jan
RE: [PATCH v4 1/3] domctl: introduce a new domain create flag, XEN_DOMCTL_CDF_disable_fifo, ...
Quoted 11 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 25 November 2020 09:36
To: Andrew Cooper <[email protected]>
Cc: Durrant, Paul <[email protected]>; Elnikety, Eslam <[email protected]>; Christian Lindig <[email protected]>; David Scott <[email protected]>; Ian Jackson <[email protected]>; Wei Liu <[email protected]>; George Dunlap <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; [email protected]; Paul Durrant <[email protected]>
Subject: RE: [EXTERNAL] [PATCH v4 1/3] domctl: introduce a new domain create flag,XEN_DOMCTL_CDF_disable_fifo, ...
Quoted 19 lines
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.
Quoted 13 lines · Jan Beulich
xen/include/public/domctl.h struct xen_domctl_createdomain { · line 74
Quoted 8 lines · Paul Durrant
xen/include/public/domctl.h +2
-0@@ -70,9 +70,11 @@ struct xen_domctl_createdomain {#define XEN_DOMCTL_CDF_iommu (1U<<_XEN_DOMCTL_CDF_iommu)#define _XEN_DOMCTL_CDF_nested_virt 6#define XEN_DOMCTL_CDF_nested_virt (1U << _XEN_DOMCTL_CDF_nested_virt) +#define _XEN_DOMCTL_CDF_disable_fifo 7 +#define XEN_DOMCTL_CDF_disable_fifo (1U << _XEN_DOMCTL_CDF_disable_fifo)Despite getting longish, I think this needs "evtchn" somewhere in the name. To keep size bounded, maybe
XEN_DOMCTL_CDF_no_fifo_evtchn?
I'm ok with that name; I'll send a v5.
Quoted 9 lines
Quoted 8 lines
xen/include/public/domctl.h struct xen_domctl_createdomain { · line 77
Quoted 3 lines
xen/include/public/domctl.h +1
-1/* Max XEN_DOMCTL_CDF_* constant. Used for ABI checking. */ -#define XEN_DOMCTL_CDF_MAX XEN_DOMCTL_CDF_nested_virt +#define XEN_DOMCTL_CDF_MAX XEN_DOMCTL_CDF_disable_fifoWhile not directly related to this patch, I'm puzzled by the presence of this constant: I've not been able to find any use of it. In particular you did have a need to modify
sanitise_domain_config().
Quoted 6 lines
So it was you to introduce this, right away without any user, in
7fb0e134f8c6("tools/ocaml: abi: Use formal conversion and check in more places"). The only reference is from what I regard as a comment (I don't speak any ocaml, so I may be wrong). Could you clarify why we need to maintain this constant?
I can't remember the exact sequence of events but it became apparent at some point that the ocaml bindings were out of sync and they rely on a list of domain create flags where the number has to match the bit-shift value in domctl.h (among other things). Thus there is an auto-generated header called "xenctrl_abi_check.h" which is included by xenctrl_stubs.c. This header is generated from xenctrl.ml by the perl script "abi-check" and it relies the XEN_DOMCTL_CDF_MAX constant to form part of the checks it generates.
As an example, here is the generated header with this patch applied:
// found ocaml type x86_arch_emulation_flags at xenctrl.ml:38
BUILD_BUG_ON( XEN_X86_EMU_LAPIC != (1u << 0) ); BUILD_BUG_ON( XEN_X86_EMU_HPET != (1u << 1) ); BUILD_BUG_ON( XEN_X86_EMU_PM != (1u << 2) ); BUILD_BUG_ON( XEN_X86_EMU_RTC != (1u << 3) ); BUILD_BUG_ON( XEN_X86_EMU_IOAPIC != (1u << 4) ); BUILD_BUG_ON( XEN_X86_EMU_PIC != (1u << 5) ); BUILD_BUG_ON( XEN_X86_EMU_VGA != (1u << 6) ); BUILD_BUG_ON( XEN_X86_EMU_IOMMU != (1u << 7) ); BUILD_BUG_ON( XEN_X86_EMU_PIT != (1u << 8) ); BUILD_BUG_ON( XEN_X86_EMU_USE_PIRQ != (1u << 9) ); BUILD_BUG_ON( XEN_X86_EMU_VPCI != (1u << 10) ); BUILD_BUG_ON( XEN_X86_EMU_ALL != (1u << 11)-1u ); // found ocaml type domain_create_flag at xenctrl.ml:60 BUILD_BUG_ON( XEN_DOMCTL_CDF_hvm != (1u << 0) ); BUILD_BUG_ON( XEN_DOMCTL_CDF_hap != (1u << 1) ); BUILD_BUG_ON( XEN_DOMCTL_CDF_s3_integrity != (1u << 2) ); BUILD_BUG_ON( XEN_DOMCTL_CDF_oos_off != (1u << 3) ); BUILD_BUG_ON( XEN_DOMCTL_CDF_xs_domain != (1u << 4) ); BUILD_BUG_ON( XEN_DOMCTL_CDF_iommu != (1u << 5) ); BUILD_BUG_ON( XEN_DOMCTL_CDF_nested_virt != (1u << 6) ); BUILD_BUG_ON( XEN_DOMCTL_CDF_disable_fifo != (1u << 7) ); BUILD_BUG_ON( XEN_DOMCTL_CDF_MAX != (1u << 7) ); // found ocaml type domain_create_iommu_opts at xenctrl.ml:70 BUILD_BUG_ON( XEN_DOMCTL_IOMMU_no_sharept != (1u << 0) ); BUILD_BUG_ON( XEN_DOMCTL_IOMMU_MAX != (1u << 0) ); // found ocaml type physinfo_cap_flag at xenctrl.ml:113 BUILD_BUG_ON( XEN_SYSCTL_PHYSCAP_hvm != (1u << 0) ); BUILD_BUG_ON( XEN_SYSCTL_PHYSCAP_pv != (1u << 1) ); BUILD_BUG_ON( XEN_SYSCTL_PHYSCAP_directio != (1u << 2) ); BUILD_BUG_ON( XEN_SYSCTL_PHYSCAP_hap != (1u << 3) ); BUILD_BUG_ON( XEN_SYSCTL_PHYSCAP_shadow != (1u << 4) );
BUILD_BUG_ON( XEN_SYSCTL_PHYSCAP_iommu_hap_pt_share != (1u << 5) );BUILD_BUG_ON( XEN_SYSCTL_PHYSCAP_MAX != (1u << 5) );
Paul
RE: [PATCH v4 1/3] domctl: introduce a new domain create flag, XEN_DOMCTL_CDF_disable_fifo, ...
In reply to Jan BeulichQuoted 37 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 25 November 2020 09:20
To: Paul Durrant <[email protected]>
Cc: Paul Durrant <[email protected]>; Eslam Elnikety <[email protected]>; Christian Lindig <[email protected]>; David Scott <[email protected]>; Ian Jackson <[email protected]>; Wei Liu <[email protected]>; Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v4 1/3] domctl: introduce a new domain create flag,XEN_DOMCTL_CDF_disable_fifo,
...Quoted 16 lines · Paul Durrant
From: Paul Durrant <[email protected]>
...to control the visibility of the FIFO event channel operations (
EVTCHNOP_init_control,EVTCHNOP_expand_array, andEVTCHNOP_set_priority) to the guest.These operations were added to the public header in commit
d2d50c2f308f("evtchn: add FIFO-based event channel ABI") and the first implementation appeared in the two subsequent commits:edc8872aeb4a("evtchn: implementEVTCHNOP_set_priorityand add theset_priorityhook") and88910061ec61("evtchn: add FIFO-based event channel hypercalls and port ops"). Prior to that, a guest issuing those operations would receive a return value of-ENOSYS(not implemented) from Xen. Guests aware of the FIFO operations but running on an older (pre-4.4) Xen would fall back to using the 2-level event channel interface upon seeing this return value.Quoted 7 lines
Unfortunately the uncontrolable appearance of these new operations in Xen 4.4 onwards has implications for hibernation of some Linux guests. During resume from hibernation, there are two kernels involved: the "boot" kernel and the "resume" kernel. The guest boot kernel may default to use FIFO operations and instruct Xen via
EVTCHNOP_init_controlto switch from 2-level to FIFO. On the other hand, the resume kernel keeps assuming 2-level, because it was hibernated on a version of Xen that did not support the FIFO operations.
Quoted 8 lines
And the alternative of the boot kernel issuing
EVTCHNOP_resethas other unwanted consequences. Maybe worth mentioning here, as otherwise this would look like the obvious way to return to 2-level mode?Also, why can't the boot kernel be instructed to avoid engaging FIFO mode?
Both of those are, of course, viable alternatives if the guest can be modified. The problem we need to work around is guest that are already out there and cannot be updated.
Quoted 11 lines
Quoted 4 lines
To maintain compatibility it is necessary to make Xen behave as it did before the new operations were added and hence the code in this patch ensures that, if
XEN_DOMCTL_CDF_disable_fifois set, the FIFO event channel operations will again result in-ENOSYSbeing returned to the guest.Are there indeed dependencies on the precise return value anywhere? If so, the generally inappropriate use (do_event_channel_op()'s default case really would also need switching) would want a brief comment, so it'll be understood by readers that this isn't code to derive other code from. If not,
-EPERMor-EACCESperhaps?
The patch, as stated, is reverting behaviour and so the -ENOSYS really needs to stay since it is essentially ABI now. I am not aware of guest code that will, in fact, die if it sees -EPERM or -EACCES instead but there may be such code. The only safe thing to do is to make things look like the used to.
Quoted 2 lines
Also, now that we gain a runtime control, do we perhaps also want a build time one?
Yes, a Kconfig flag to compile out the code seems like a worthy addition. I'll spin up a follow-up patch as soon as I get time.
Paul
Quoted 38 lines
Quoted 3 lines
Signed-off-by Paul Durrant <[email protected]>Signed-off-by Eslam Elnikety <[email protected]>Are this order as well as the From: tag above correct? Or alternatively, are there actually any pieces left at all from Eslam's earlier patch?
Quoted 2 lines
v4:
- New in v4(Just as an aside: That's quite interesting for a previously standalone patch. I guess that patch was really split, considering you've retained Eslam's S-o-b? But perhaps there are different ways to look at things ...)
xen/include/public/domctl.h struct xen_domctl_createdomain { · line 74
Quoted 8 lines
xen/include/public/domctl.h +2
-0@@ -70,9 +70,11 @@ struct xen_domctl_createdomain {#define XEN_DOMCTL_CDF_iommu (1U<<_XEN_DOMCTL_CDF_iommu)#define _XEN_DOMCTL_CDF_nested_virt 6#define XEN_DOMCTL_CDF_nested_virt (1U << _XEN_DOMCTL_CDF_nested_virt) +#define _XEN_DOMCTL_CDF_disable_fifo 7 +#define XEN_DOMCTL_CDF_disable_fifo (1U << _XEN_DOMCTL_CDF_disable_fifo)Despite getting longish, I think this needs "evtchn" somewhere in the name. To keep size bounded, maybe
XEN_DOMCTL_CDF_no_fifo_evtchn?xen/include/public/domctl.h struct xen_domctl_createdomain { · line 77
Quoted 3 lines
xen/include/public/domctl.h +1
-1/* Max XEN_DOMCTL_CDF_* constant. Used for ABI checking. */ -#define XEN_DOMCTL_CDF_MAX XEN_DOMCTL_CDF_nested_virt +#define XEN_DOMCTL_CDF_MAX XEN_DOMCTL_CDF_disable_fifoWhile not directly related to this patch, I'm puzzled by the presence of this constant: I've not been able to find any use of it. In particular you did have a need to modify
sanitise_domain_config().Jan
Re: [PATCH v4 1/3] domctl: introduce a new domain create flag, XEN_DOMCTL_CDF_disable_fifo, ...
Quoted 33 lines · Paul Durrant
Quoted 33 lines
From: Jan Beulich <[email protected]>
Sent: 25 November 2020 09:20Quoted 16 lines · Paul Durrant
From: Paul Durrant <[email protected]>
...to control the visibility of the FIFO event channel operations (
EVTCHNOP_init_control,EVTCHNOP_expand_array, andEVTCHNOP_set_priority) to the guest.These operations were added to the public header in commit
d2d50c2f308f("evtchn: add FIFO-based event channel ABI") and the first implementation appeared in the two subsequent commits:edc8872aeb4a("evtchn: implementEVTCHNOP_set_priorityand add theset_priorityhook") and88910061ec61("evtchn: add FIFO-based event channel hypercalls and port ops"). Prior to that, a guest issuing those operations would receive a return value of-ENOSYS(not implemented) from Xen. Guests aware of the FIFO operations but running on an older (pre-4.4) Xen would fall back to using the 2-level event channel interface upon seeing this return value.Quoted 7 lines
Unfortunately the uncontrolable appearance of these new operations in Xen 4.4 onwards has implications for hibernation of some Linux guests. During resume from hibernation, there are two kernels involved: the "boot" kernel and the "resume" kernel. The guest boot kernel may default to use FIFO operations and instruct Xen via
EVTCHNOP_init_controlto switch from 2-level to FIFO. On the other hand, the resume kernel keeps assuming 2-level, because it was hibernated on a version of Xen that did not support the FIFO operations.And the alternative of the boot kernel issuing
EVTCHNOP_resethas other unwanted consequences. Maybe worth mentioning here, as otherwise this would look like the obvious way to return to 2-level mode?
Quoted 7 lines
Quoted 3 lines
Also, why can't the boot kernel be instructed to avoid engaging FIFO mode?
Both of those are, of course, viable alternatives if the guest can be modified. The problem we need to work around is guest that are already out there and cannot be updated.
Making use of EVTCHNOP_reset indeed would require a change to the kernel. But Linux has a command line option to suppress use of FIFO event channels, so I can't see why the boot kernel couldn't be passed this flag without any modification to the binary.
Quoted 12 lines
Quoted 11 lines
Quoted 4 lines
To maintain compatibility it is necessary to make Xen behave as it did before the new operations were added and hence the code in this patch ensures that, if
XEN_DOMCTL_CDF_disable_fifois set, the FIFO event channel operations will again result in-ENOSYSbeing returned to the guest.Are there indeed dependencies on the precise return value anywhere? If so, the generally inappropriate use (do_event_channel_op()'s default case really would also need switching) would want a brief comment, so it'll be understood by readers that this isn't code to derive other code from. If not,
-EPERMor-EACCESperhaps?
Quoted 5 lines
The patch, as stated, is reverting behaviour and so the
-ENOSYSreally needs to stay since it is essentially ABI now. I am not aware of guest code that will, in fact, die if it sees-EPERMor-EACCESinstead but there may be such code. The only safe thing to do is to make things look like the used to.
I don't think specific error codes can be considered "ABI". Not the least because, if there are multiple causes for an error, it ought to be undefined which error gets returned. A guest not falling back to 2-level on _any_ error here is basically setting itself up for eventual failure because of e.g. getting back -ENOMEM. Or someone deciding to add an XSM check to the function.
As said, I'm of the opinion that the other -ENOSYS ought to be replaced as well, which of course would be precluded if this was considered "ABI".
Jan
RE: [PATCH v4 1/3] domctl: introduce a new domain create flag, XEN_DOMCTL_CDF_disable_fifo, ...
Quoted 55 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 25 November 2020 11:51
To: [email protected]
Cc: Durrant, Paul <[email protected]>; Elnikety, Eslam <[email protected]>; 'Christian Lindig' <[email protected]>; 'David Scott' <[email protected]>; 'Ian Jackson' <[email protected]>; 'Wei Liu' <[email protected]>; 'Andrew Cooper' <[email protected]>; 'George Dunlap' <[email protected]>; 'Julien Grall' <[email protected]>; 'Stefano Stabellini' <[email protected]>; [email protected]
Subject: RE: [EXTERNAL] [PATCH v4 1/3] domctl: introduce a new domain create flag,XEN_DOMCTL_CDF_disable_fifo, ...CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.
Quoted 37 lines · Paul Durrant
Quoted 36 lines
From: Jan Beulich <[email protected]>
Sent: 25 November 2020 09:20Quoted 16 lines · Paul Durrant
From: Paul Durrant <[email protected]>
...to control the visibility of the FIFO event channel operations (
EVTCHNOP_init_control,EVTCHNOP_expand_array, andEVTCHNOP_set_priority) to the guest.These operations were added to the public header in commit
d2d50c2f308f("evtchn: add FIFO-based event channel ABI") and the first implementation appeared in the two subsequent commits:edc8872aeb4a("evtchn: implementEVTCHNOP_set_priorityand add theset_priorityhook") and88910061ec61("evtchn: add FIFO-based event channel hypercalls and port ops"). Prior to that, a guest issuing those operations would receive a return value of-ENOSYS(not implemented) from Xen. Guests aware of the FIFO operations but running on an older (pre-4.4) Xen would fall back to using the 2-level event channel interface upon seeing this return value.Quoted 7 lines
Unfortunately the uncontrolable appearance of these new operations in Xen 4.4 onwards has implications for hibernation of some Linux guests. During resume from hibernation, there are two kernels involved: the "boot" kernel and the "resume" kernel. The guest boot kernel may default to use FIFO operations and instruct Xen via
EVTCHNOP_init_controlto switch from 2-level to FIFO. On the other hand, the resume kernel keeps assuming 2-level, because it was hibernated on a version of Xen that did not support the FIFO operations.And the alternative of the boot kernel issuing
EVTCHNOP_resethas other unwanted consequences. Maybe worth mentioning here, as otherwise this would look like the obvious way to return to 2-level mode?Also, why can't the boot kernel be instructed to avoid engaging FIFO mode?
Quoted 9 lines
Quoted 3 lines
Both of those are, of course, viable alternatives if the guest can be modified. The problem we need to work around is guest that are already out there and cannot be updated.
Making use of
EVTCHNOP_resetindeed would require a change to the kernel. But Linux has a command line option to suppress use of FIFO event channels, so I can't see why the boot kernel couldn't be passed this flag without any modification to the binary.
I'm sure that was considered and found not to be feasible in our use-case. (Likely the command line is as much baked into the guest image as the kernel itself).
Quoted 18 lines
Quoted 12 lines
Quoted 11 lines
Quoted 4 lines
To maintain compatibility it is necessary to make Xen behave as it did before the new operations were added and hence the code in this patch ensures that, if
XEN_DOMCTL_CDF_disable_fifois set, the FIFO event channel operations will again result in-ENOSYSbeing returned to the guest.Are there indeed dependencies on the precise return value anywhere? If so, the generally inappropriate use (do_event_channel_op()'s default case really would also need switching) would want a brief comment, so it'll be understood by readers that this isn't code to derive other code from. If not,
-EPERMor-EACCESperhaps?Quoted 5 lines
The patch, as stated, is reverting behaviour and so the
-ENOSYSreally needs to stay since it is essentially ABI now. I am not aware of guest code that will, in fact, die if it sees-EPERMor-EACCESinstead but there may be such code. The only safe thing to do is to make things look like the used to.
Quoted 7 lines
I don't think specific error codes can be considered "ABI". Not the least because, if there are multiple causes for an error, it ought to be undefined which error gets returned. A guest not falling back to 2-level on _any_ error here is basically setting itself up for eventual failure because of e.g. getting back
-ENOMEM. Or someone deciding to add an XSM check to the function.
I'm not disagreeing that depending on -ENOSYS is a bad idea but, before FIFO came along, that's what the guest would see and that is what it ought to see again if we want to truly obscure the interface (which is the stated aim here).
Quoted 4 lines
As said, I'm of the opinion that the other
-ENOSYSought to be replaced as well, which of course would be precluded if this was considered "ABI".
Indeed.
Paul
Quoted 1 line
Jan
Re: [PATCH v4 1/3] domctl: introduce a new domain create flag, XEN_DOMCTL_CDF_disable_fifo, ...
In reply to Paul Durrantxen/include/public/domctl.h struct xen_domctl_createdomain { · line 74
Quoted 10 lines · Paul Durrant
xen/include/public/domctl.h +2
-0@@ -70,9 +70,11 @@ struct xen_domctl_createdomain {#define XEN_DOMCTL_CDF_iommu (1U<<_XEN_DOMCTL_CDF_iommu)#define _XEN_DOMCTL_CDF_nested_virt 6#define XEN_DOMCTL_CDF_nested_virt (1U << _XEN_DOMCTL_CDF_nested_virt) +#define _XEN_DOMCTL_CDF_disable_fifo 7 +#define XEN_DOMCTL_CDF_disable_fifo (1U << _XEN_DOMCTL_CDF_disable_fifo)
The sense is backwards. It should be a "permit the use of FIFO" control. If the code had been written this way to begin with, the bug you found wouldn't have existed.
Given that there is not currently a way to disable FIFO, you can probably do without an enumeration of whether the hypervisor supports it or not.
~Andrew
RE: [PATCH v4 1/3] domctl: introduce a new domain create flag, XEN_DOMCTL_CDF_disable_fifo, ...
Quoted 32 lines
-----Original Message-----
From: Andrew Cooper <[email protected]>
Sent: 25 November 2020 11:31
To: Paul Durrant <[email protected]>; [email protected]
Cc: Durrant, Paul <[email protected]>; Elnikety, Eslam <[email protected]>; Christian Lindig <[email protected]>; David Scott <[email protected]>; Ian Jackson <[email protected]>; Wei Liu <[email protected]>; George Dunlap <[email protected]>; Jan Beulich <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>
Subject: RE: [EXTERNAL] [PATCH v4 1/3] domctl: introduce a new domain create flag,XEN_DOMCTL_CDF_disable_fifo, ...CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.
xen/include/public/domctl.h struct xen_domctl_createdomain { · line 74
Quoted 10 lines · Paul Durrant
xen/include/public/domctl.h +2
-0@@ -70,9 +70,11 @@ struct xen_domctl_createdomain {#define XEN_DOMCTL_CDF_iommu (1U<<_XEN_DOMCTL_CDF_iommu)#define _XEN_DOMCTL_CDF_nested_virt 6#define XEN_DOMCTL_CDF_nested_virt (1U << _XEN_DOMCTL_CDF_nested_virt) +#define _XEN_DOMCTL_CDF_disable_fifo 7 +#define XEN_DOMCTL_CDF_disable_fifo (1U << _XEN_DOMCTL_CDF_disable_fifo)The sense is backwards. It should be a "permit the use of FIFO" control. If the code had been written this way to begin with, the bug you found wouldn't have existed.
Quoted 4 lines
Given that there is not currently a way to disable FIFO, you can probably do without an enumeration of whether the hypervisor supports it or not.
Ok, I can reverse the sense.
I found another one that we ought to control in a similar way... the per-cpu evtchn upcalls. AFAIK only the Windows PV drivers make use of it (and I can arrange to squash that with a registry flag) but it really falls into the same category as FIFO... so maybe we need a separate bit-field for these sorts of thing?
Paul
Quoted 1 line
~Andrew
PATCH v4 2/3 libxl: add a 'disable_fifo_evtchn' flag to libxl_domain_build_info ...
In reply to Paul DurrantFrom: Paul Durrant <[email protected]>
...to control setting the domain create flag XEN_DOMCTL_CDF_disable_fifo.
---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Anthony PERARD <[email protected]>
v4:
- New in v4
--- tools/include/libxl.h | 8 ++++++++ tools/libs/light/libxl_create.c | 5 +++++ tools/libs/light/libxl_types.idl | 1 + 3 files changed, 14 insertions(+)
tools/include/libxl.h +8 -0
@@ -444,6 +444,14 @@*/ #define LIBXL_HAVE_DISK_SAFE_REMOVE 1 +/* +* LIBXL_HAVE_BUILDINFO_DISABLE_EVTCHN_FIFO indicates that +* libxl_domain_build_info has a disable_evtchn_fifo (boolean) field +* to determine whether the EVTCHNOPs to initialize and manipulate FIFO +* event channels are exposed to the guest. +*/ +#define LIBXL_HAVE_BUILDINFO_DISABLE_EVTCHN_FIFO 1 +/* * libxl ABI compatibility *
tools/libs/light/libxl_create.c +5 -0
@@ -263,6 +263,8 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc,if (!b_info->event_channels) b_info->event_channels =1023 ; +libxl_defbool_setdefault (&b_info->disable_evtchn_fifo, false); +libxl__arch_domain_build_info_setdefault (gc, b_info);libxl_defbool_setdefault (&b_info->dm_restrict, false);
@@ -609,6 +611,9 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_config *d_config, .max_maptrack_frames = b_info->max_maptrack_frames, }; +if (libxl_defbool_val (b_info->disable_evtchn_fifo)) + create.flags |= XEN_DOMCTL_CDF_disable_fifo; +if (info->type !=LIBXL_DOMAIN_TYPE_PV ) { create.flags |= XEN_DOMCTL_CDF_hvm;
tools/libs/light/libxl_types.idl +1 -0
@@ -541,6 +541,7 @@ libxl_domain_build_info = Struct("domain_build_info",[ ("iomem", Array(libxl_iomem_range, "num_iomem")), ("claim_mode", libxl_defbool), ("event_channels", uint32), + ("disable_evtchn_fifo",libxl_defbool), ("kernel", string), ("cmdline", string), ("ramdisk", string),
Signature · 1 line
2.20.1
PATCH v4 3/3 xl: add 'disable_evtchn_fifo' boolean option into xl.cfg(5) ...
In reply to Paul DurrantFrom: Paul Durrant <[email protected]>
...to set the value of the 'disable_evtchn_fifo' flag in libxl_domain_build_info.
---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Anthony PERARD <[email protected]>
v4:
- New in v4
--- docs/man/xl.cfg.5.pod.in | 8 ++++++++ tools/xl/xl_parse.c | 3 +++ 2 files changed, 11 insertions(+)
docs/man/xl.cfg.5.pod.in +8 -0
@@ -1338,6 +1338,14 @@ FIFO-based event channel ABI support up to 131,071 event channels. Other guests are limited to 4095 (64-bit x86 and ARM) or 1023 (32-bit x86). +=item B<disable_evtchn_fifo=BOOLEAN> + +Indicates if support for FIFO event channel operations (EVTCHNOP_init_control, +EVTCHNOP_expand_array and EVTCHNOP_set_priority) are disabled. This can be +used to work around issues with guests hibernated on a version of Xen +prior to 4.4 and resumed on a version of Xen from 4.4. onwards. The default +value is false. + =item B<vdispl=[ "VDISPL_SPEC_STRING", "VDISPL_SPEC_STRING", ...]> Specifies the virtual display devices to be provided to the guest.
tools/xl/xl_parse.c +3 -0
@@ -1569,6 +1569,9 @@ void parse_config_data(const char *config_source,if (!xlu_cfg_get_long (config,"max_event_channels" , &l,0 )) b_info->event_channels = l; +xlu_cfg_get_defbool (config,"disable_evtchn_fifo" , + &b_info->disable_evtchn_fifo,0 ); +xlu_cfg_replace_string (config,"kernel" , &b_info->kernel,0 );xlu_cfg_replace_string (config,"ramdisk" , &b_info->ramdisk,0 );xlu_cfg_replace_string (config,"device_tree" , &b_info->device_tree,0 );
Signature · 1 line
2.20.1