x86/pv-shim: configuring / building re-arrangements
cover x86/pv-shim: configuring / building re-arrangements
The first patch, while being the main piece here, and while fixing a bug kind of as a side effect, is partly RFC; see there. The other two changes are really minor adjustments for aspects noticed while putting together the main change.
1: common: reduce PV shim footprint
2: don't even allow enabling GRANT_TABLE
3: suppress core-parking logic
Jan
PATCH 1/3 common: reduce PV shim footprint
Having CONFIG_PV_SHIM conditionals in common code isn't really nice. Utilize that we're no longer invoking hypercall handlers via indirect calls through a table of function vectors. With the use of direct calls from the macros defined by hypercall-defs.h, we can simply define overriding macros for event channel and grant table ops handling. All this requires is arrangement for careful double inclusion of asm/hypercall.h out of xen/hypercall.h. Such double inclusion is required because hypercall-defs.h expects certain definitions to be in place, while the new handling (placed in pv/shim.h, which is now included from asm/hypercall.h despite the apparent cyclic dependency) requires prototypes from hypercall-defs.h to be available already.
Note that this makes it necessary to further constrain the stubbing of pv_shim from common/sched/core.c, and allows removing the inclusion of asm/guest.h there as well. Since this is actually part of the overall goal, leverage the mechanism to also get rid of the similar construct in xsm/flask/hooks.c, including xen/hypercall.h instead.
Note further that kind of as a side effect this fixes grant table handling for 32-bit shim guests when GRANT_TABLE=y, as the non-stub compat_grant_table_op() did not redirect to pv_shim_grant_table_op().
A downside of this is that now do_{event_channel,grant_table}_op() are built in full again when PV_SHIM_EXCLUSIVE=y, despite all the code actually being dead in that case.
---
RFC: Sadly I had to restore the two "#define pv_shim false", for Arm to
continue to build. Originally I was hoping to get rid of that #ifdef-ary altogether. Would it be acceptable to put a single, central #define in e.g. xen/sched.h or xen/hypercall.h?
xen/arch/x86/include/asm/hypercall.h +13 -8
@@ -6,14 +6,23 @@#error "asm/hypercall.h should not be included directly - include xen/hypercall.h instead"#endif -#ifndef __ASM_X86_HYPERCALL_H__ -#define __ASM_X86_HYPERCALL_H__ -#include <xen/types.h> +#include <public/xen.h> #include <public/physdev.h> -#include <public/event_channel.h> #include <public/arch-x86/xen-mca.h> /* for do_mca */ + +#ifdef CONFIG_COMPAT +#include <compat/arch-x86/xen.h> +#include <compat/physdev.h> +#include <compat/platform.h> +#endif + +#if !defined(__ASM_X86_HYPERCALL_H__) && \ + (!defined(CONFIG_PV_SHIM ) || defined(hypercall_args_pv64)) +#define __ASM_X86_HYPERCALL_H__ +#include <asm/paging.h> +#include <asm/pv/shim.h> #define __HYPERVISOR_paging_domctl_cont __HYPERVISOR_arch_1
@@ -33,10 +42,6 @@ void pv_ring3_init_hypercall_page(void *#ifdef CONFIG_COMPAT -#include <compat/arch-x86/xen.h> -#include <compat/physdev.h> -#include <compat/platform.h> -extern int compat_common_vcpu_op (int cmd,struct vcpu *v,XEN_GUEST_HANDLE_PARAM (void ) arg);
xen/arch/x86/include/asm/pv/shim.h +16 -0
@@ -49,6 +49,22 @@ const struct platform_bad_page *pv_shim_typeof (do_event_channel_op) pv_shim_event_channel_op;typeof (do_grant_table_op) pv_shim_grant_table_op; +#ifdef CONFIG_PV_SHIM_EXCLUSIVE +#define REVECTOR(pfx, op, args...) pv_shim_ ## op(args) +#else +#define REVECTOR(pfx, op, args...) ({ \ + likely(!pv_shim) \ + ? pfx ## _ ## op(args) \ + : pv_shim_ ## op(args); \ +}) +#endif + +#define do_event_channel_op(args...) REVECTOR(do, event_channel_op, args) +#define do_grant_table_op(args...) REVECTOR(do, grant_table_op, args) +#ifdef CONFIG_COMPAT +#define compat_grant_table_op(args...) REVECTOR(compat, grant_table_op, args) +#endif +#else static inline void pv_shim_setup_dom(struct domain *d, l4_pgentry_t *l4start,
xen/arch/x86/pv/shim.c +3 -3
@@ -822,9 +822,9 @@ long pv_shim_grant_table_op(unsigned intreturn rc; } -#ifndef CONFIG_GRANT_TABLE +#if !defined(CONFIG_GRANT_TABLE ) && !defined(CONFIG_PV_SHIM_EXCLUSIVE )/* Thin wrapper(s) needed. */ -long do_grant_table_op ( +long (do_grant_table_op)(unsigned int cmd,XEN_GUEST_HANDLE_PARAM (void ) uop,unsigned int count) {if ( !pv_shim )
@@ -834,7 +834,7 @@ long do_grant_table_op( }#ifdef CONFIG_PV32 -int compat_grant_table_op ( +int (compat_grant_table_op)(unsigned int cmd,XEN_GUEST_HANDLE_PARAM (void ) uop,unsigned int count) {if ( !pv_shim )
xen/common/compat/grant_table.c +1 -1
@@ -56,7 +56,7 @@ CHECK_gnttab_swap_grant_ref; CHECK_gnttab_cache_flush;#undef xen_gnttab_cache_flush -int compat_grant_table_op ( +int (compat_grant_table_op)(unsigned int cmd,XEN_GUEST_HANDLE_PARAM (void ) cmp_uop,unsigned int count) {int rc =0 ;
xen/common/event_channel.c +1 -10
@@ -32,10 +32,6 @@#include <public/event_channel.h> #include <xsm/xsm.h> -#ifdef CONFIG_PV_SHIM -#include <asm/guest.h> -#endif -#define ERROR_EXIT (_errno) \ do { \ gdprintk(XENLOG_WARNING, \
@@ -1222,15 +1218,10 @@ static int evtchn_set_priority(const strreturn ret; } -long do_event_channel_op (int cmd,XEN_GUEST_HANDLE_PARAM (void ) arg) +long (do_event_channel_op)(int cmd,XEN_GUEST_HANDLE_PARAM (void ) arg) {int rc; -#ifdef CONFIG_PV_SHIM -if (unlikely (pv_shim) ) -return pv_shim_event_channel_op (cmd, arg); -#endif -switch ( cmd ) {case EVTCHNOP_alloc_unbound: {
xen/common/grant_table.c +1 -10
@@ -45,10 +45,6 @@#include <asm/flushtlb.h> #include <asm/guest_atomics.h> -#ifdef CONFIG_PV_SHIM -#include <asm/guest.h> -#endif -/* Per-domain grant information. */ struct grant_table {/*
@@ -3563,17 +3559,12 @@ gnttab_cache_flush(XEN_GUEST_HANDLE_PARAreturn 0 ; } -long do_grant_table_op ( +long (do_grant_table_op)(unsigned int cmd,XEN_GUEST_HANDLE_PARAM (void ) uop,unsigned int count) {long rc;unsigned int opaque_in = cmd &GNTTABOP_ARG_MASK , opaque_out =0 ; -#ifdef CONFIG_PV_SHIM -if (unlikely (pv_shim) ) -return pv_shim_grant_table_op (cmd, uop, count); -#endif -if ( (int )count <0 )return -EINVAL ;
xen/common/sched/core.c +1 -3
@@ -40,9 +40,7 @@#include "private.h" -#ifdef CONFIG_XEN_GUEST -#include <asm/guest.h> -#else +#ifndef CONFIG_X86 #define pv_shim false#endif
xen/include/xen/hypercall.h +3 -0
@@ -24,6 +24,9 @@/* Needs to be after asm/hypercall.h. */ #include <xen/hypercall-defs.h> +/* Include a 2nd time, for x86'es PV shim. */ +#include <asm/hypercall.h> + extern long arch_do_domctl( struct xen_domctl *domctl, struct domain *d,
xen/xsm/flask/hooks.c +2 -3
@@ -19,6 +19,7 @@#include <xen/cpumask.h> #include <xen/errno.h> #include <xen/guest_access.h> +#include <xen/hypercall.h> #include <xen/xenoprof.h> #include <xen/iommu.h> #ifdef CONFIG_HAS_PCI_MSI
@@ -38,9 +39,7 @@#include <conditional.h> #include "private.h" -#ifdef CONFIG_X86 -#include <asm/pv/shim.h> -#else +#ifndef CONFIG_X86 #define pv_shim false#endif
PATCH 2/3 x86/pv-shim: don't even allow enabling GRANT_TABLE
In reply to Jan BeulichGrant table code is unused in shim mode, so there's no point in building it in the first place for shim-exclusive mode.
xen/arch/x86/configs/pvshim_defconfig +0 -1
@@ -9,7 +9,6 @@ CONFIG_EXPERT=y # Disable features not used by the PV shim # CONFIG_XEN_SHSTK is not set # CONFIG_XEN_IBT is not set -# CONFIG_GRANT_TABLE is not set # CONFIG_HYPFS is not set # CONFIG_BIGMEM is not set # CONFIG_KEXEC is not set
xen/common/Kconfig +1 -0
@@ -14,6 +14,7 @@ config CORE_PARKING config GRANT_TABLE bool "Grant table support" if EXPERT default y + depends on !PV_SHIM_EXCLUSIVE ---help--- Grant table provides a generic mechanism to memory sharing between domains. This shared memory interface underpins the
Andrew Cooper
NAKRe: [PATCH 2/3] x86/pv-shim: don't even allow enabling GRANT_TABLE
Quoted 4 lines · Jan Beulich
Grant table code is unused in shim mode, so there's no point in building it in the first place for shim-exclusive mode.
Signed-off-by Jan Beulich <[email protected]>
nack.
This is bogus, as is every other "depends on !PV_SHIM_EXCLUSIVE".
The only reason I haven't reverting the others so make allyesconfig doesn't disable CONFIG_HVM, is because I haven't had time. This change further breaks allyesconfig by disabling GRANT_TABLE too.
PV_SHIM_EXCLUSIVE is a simple option for a bit of dead code elimination. It is not valid to be used like this.
~Andrew
Re: [PATCH 2/3] x86/pv-shim: don't even allow enabling GRANT_TABLE
Quoted 9 lines · Andrew Cooper
Quoted 4 lines · Jan Beulich
Grant table code is unused in shim mode, so there's no point in building it in the first place for shim-exclusive mode.
Signed-off-by Jan Beulich <[email protected]>nack.
This is bogus, as is every other "depends on !PV_SHIM_EXCLUSIVE".
But why? Doing things like this in Kconfig is exactly ...
Quoted 6 lines
The only reason I haven't reverting the others so
make allyesconfigdoesn't disableCONFIG_HVM, is because I haven't had time. This change further breaks allyesconfig by disablingGRANT_TABLEtoo.
PV_SHIM_EXCLUSIVEis a simple option for a bit of dead code elimination. It is not valid to be used like this.
... for the purpose of dead code elimination. By nack-ing a change like this (and by having voiced opposition to earlier ones) you simply call for yet more entirely unhelpful #ifdef-ary. See the last paragraph of the description of patch 1, half of which this change rectifies. The solution on the evtchn side, unfortunately, looks to be #ifdef-ary, short of there being a suitable Kconfig option.
Furthermore Kconfig, in my view, is specifically intended to allow to prevent the user from selecting entirely bogus option combinations (and even more so suggest entirely bogus configurations by bogus default settings). If you disagree, then I'm afraid we have a 2nd Kconfig usage topic which we need to settle on in a project-wide manner. If only we ever made any progress on such ...
As to allyesconfig - I can see your point there, but then arrangements need to be invented to avoid this kind of unhelpful behavior.
Which raises two questions then: Would you view
config GRANT_TABLE
bool "Grant table support" if EXPERT
default y if !PV_SHIM_EXCLUSIVE
as acceptable? I could accept this as a (perhaps) temporary compromise, until the general aspect was settled. And what about the different kind of change in patch 3, where allyesconfig isn't affected (afaict)?
Also, as a wider scope remark: In general - and this particularly applies to cases where you feel like nack-ing things - comments on patches want to be constructive (and thus actionable, pointing out possible ways for the author to re-work things such they would become acceptable while achieving the same goal; see the first of the two questions above for a possible example). There's nothing constructive in your response here, nor was there ever (afair) in earlier nacks that I received from you.
Jan
Re: [PATCH 2/3] x86/pv-shim: don't even allow enabling GRANT_TABLE
Quoted 34 lines · Jan Beulich
Quoted 9 lines · Andrew Cooper
Quoted 4 lines · Jan Beulich
Grant table code is unused in shim mode, so there's no point in building it in the first place for shim-exclusive mode.
Signed-off-by Jan Beulich <[email protected]>nack.
This is bogus, as is every other "depends on !PV_SHIM_EXCLUSIVE".
But why? Doing things like this in
Kconfigis exactly ...Quoted 6 lines
The only reason I haven't reverting the others so
make allyesconfigdoesn't disableCONFIG_HVM, is because I haven't had time. This change further breaks allyesconfig by disablingGRANT_TABLEtoo.
PV_SHIM_EXCLUSIVEis a simple option for a bit of dead code elimination. It is not valid to be used like this.... for the purpose of dead code elimination. By nack-ing a change like this (and by having voiced opposition to earlier ones) you simply call for yet more entirely unhelpful #ifdef-ary. See the last paragraph of the description of patch 1, half of which this change rectifies. The solution on the evtchn side, unfortunately, looks to be #ifdef-ary, short of there being a suitable
Kconfigoption.Furthermore
Kconfig, in my view, is specifically intended to allow to prevent the user from selecting entirely bogus option combinations (and even more so suggest entirely bogus configurations by bogus default settings). If you disagree, then I'm afraid we have a 2ndKconfigusage topic which we need to settle on in a project-wide manner. If only we ever made any progress on such ...
Quoted 2 lines
As to allyesconfig - I can see your point there, but then arrangements need to be invented to avoid this kind of unhelpful behavior.
Thinking more about it, if allyesconfig is meant to be useful, then any "depends on !..." (other than for base architecture identifiers) would be wrong (see e.g. COVERAGE depending on !LIVEPATCH or ARM_SMMU_V3 depending on !ACPI). And this would extend to Linux as well - how do they deal with that?
Jan
Re: [PATCH 2/3] x86/pv-shim: don't even allow enabling GRANT_TABLE
Quoted 35 lines · Jan Beulich
Quoted 34 lines · Jan Beulich
Quoted 9 lines · Andrew Cooper
Quoted 4 lines · Jan Beulich
Grant table code is unused in shim mode, so there's no point in building it in the first place for shim-exclusive mode.
Signed-off-by Jan Beulich <[email protected]>nack.
This is bogus, as is every other "depends on !PV_SHIM_EXCLUSIVE".
But why? Doing things like this in
Kconfigis exactly ...Quoted 6 lines
The only reason I haven't reverting the others so
make allyesconfigdoesn't disableCONFIG_HVM, is because I haven't had time. This change further breaks allyesconfig by disablingGRANT_TABLEtoo.
PV_SHIM_EXCLUSIVEis a simple option for a bit of dead code elimination. It is not valid to be used like this.... for the purpose of dead code elimination. By nack-ing a change like this (and by having voiced opposition to earlier ones) you simply call for yet more entirely unhelpful #ifdef-ary. See the last paragraph of the description of patch 1, half of which this change rectifies. The solution on the evtchn side, unfortunately, looks to be #ifdef-ary, short of there being a suitable
Kconfigoption.Furthermore
Kconfig, in my view, is specifically intended to allow to prevent the user from selecting entirely bogus option combinations (and even more so suggest entirely bogus configurations by bogus default settings). If you disagree, then I'm afraid we have a 2ndKconfigusage topic which we need to settle on in a project-wide manner. If only we ever made any progress on such ...
Quoted 8 lines
Quoted 2 lines
As to allyesconfig - I can see your point there, but then arrangements need to be invented to avoid this kind of unhelpful behavior.
Thinking more about it, if allyesconfig is meant to be useful, then any "depends on !..." (other than for base architecture identifiers) would be wrong (see e.g. COVERAGE depending on !LIVEPATCH or
ARM_SMMU_V3depending on !ACPI). And this would extend to Linux as well - how do they deal with that?
Isn't allyesconfig for new options only? At least in Linux it is documented this way.
Otherwise options like CONFIG_X86_32 (which depends on !X86_64) would make no sense either.
So the way to go seems to have some default minimal configs (in our case e.g. shim and no-shim), which can then be expanded via allyesconfig or allnoconfig.
Juergen
Re: [PATCH 2/3] x86/pv-shim: don't even allow enabling GRANT_TABLE
Quoted 39 lines · Juergen Gross
Quoted 38 lines · Jan Beulich
Quoted 36 lines · Jan Beulich
Quoted 9 lines · Andrew Cooper
Quoted 4 lines · Jan Beulich
Grant table code is unused in shim mode, so there's no point in building it in the first place for shim-exclusive mode.
Signed-off-by Jan Beulich <[email protected]>nack.
This is bogus, as is every other "depends on !PV_SHIM_EXCLUSIVE".
But why? Doing things like this in
Kconfigis exactly ...Quoted 6 lines
The only reason I haven't reverting the others so
make allyesconfigdoesn't disableCONFIG_HVM, is because I haven't had time. This change further breaks allyesconfig by disablingGRANT_TABLEtoo.
PV_SHIM_EXCLUSIVEis a simple option for a bit of dead code elimination. It is not valid to be used like this.... for the purpose of dead code elimination. By nack-ing a change like this (and by having voiced opposition to earlier ones) you simply call for yet more entirely unhelpful #ifdef-ary. See the last paragraph of the description of patch 1, half of which this change rectifies. The solution on the evtchn side, unfortunately, looks to be #ifdef-ary, short of there being a suitable
Kconfigoption.Furthermore
Kconfig, in my view, is specifically intended to allow to prevent the user from selecting entirely bogus option combinations (and even more so suggest entirely bogus configurations by bogus default settings). If you disagree, then I'm afraid we have a 2ndKconfigusage topic which we need to settle on in a project-wide manner. If only we ever made any progress on such ...As to allyesconfig - I can see your point there, but then arrangements need to be invented to avoid this kind of unhelpful behavior.
Quoted 8 lines
Quoted 5 lines
Thinking more about it, if allyesconfig is meant to be useful, then any "depends on !..." (other than for base architecture identifiers) would be wrong (see e.g. COVERAGE depending on !LIVEPATCH or
ARM_SMMU_V3depending on !ACPI). And this would extend to Linux as well - how do they deal with that?Isn't allyesconfig for new options only? At least in Linux it is documented this way.
Is it? I only find
"make allyesconfig"
Create a ./.config file by setting symbol values to 'y' as much as possible.
and a couple of instances of "New config where all options are accepted with yes". What you refer to ...
Quoted 6 lines
Otherwise options like
CONFIG_X86_32(which depends on !X86_64) would make no sense either.So the way to go seems to have some default minimal configs (in our case e.g. shim and no-shim), which can then be expanded via allyesconfig or allnoconfig.
... looks to be optional behavior with KCONFIG_ALLCONFIG (which of course we could leverage for our CI in order to avoid introducing restrictions on what may be used in "depends on").
Jan
Re: [PATCH 2/3] x86/pv-shim: don't even allow enabling GRANT_TABLE
Quoted 46 lines · Jan Beulich
Quoted 45 lines · Juergen Gross
Quoted 43 lines · Jan Beulich
Quoted 34 lines · Jan Beulich
Quoted 9 lines · Andrew Cooper
Quoted 4 lines · Jan Beulich
Grant table code is unused in shim mode, so there's no point in building it in the first place for shim-exclusive mode.
Signed-off-by Jan Beulich <[email protected]>nack.
This is bogus, as is every other "depends on !PV_SHIM_EXCLUSIVE".
But why? Doing things like this in
Kconfigis exactly ...Quoted 6 lines
The only reason I haven't reverting the others so
make allyesconfigdoesn't disableCONFIG_HVM, is because I haven't had time. This change further breaks allyesconfig by disablingGRANT_TABLEtoo.
PV_SHIM_EXCLUSIVEis a simple option for a bit of dead code elimination. It is not valid to be used like this.... for the purpose of dead code elimination. By nack-ing a change like this (and by having voiced opposition to earlier ones) you simply call for yet more entirely unhelpful #ifdef-ary. See the last paragraph of the description of patch 1, half of which this change rectifies. The solution on the evtchn side, unfortunately, looks to be #ifdef-ary, short of there being a suitable
Kconfigoption.Furthermore
Kconfig, in my view, is specifically intended to allow to prevent the user from selecting entirely bogus option combinations (and even more so suggest entirely bogus configurations by bogus default settings). If you disagree, then I'm afraid we have a 2ndKconfigusage topic which we need to settle on in a project-wide manner. If only we ever made any progress on such ...Quoted 2 lines
As to allyesconfig - I can see your point there, but then arrangements need to be invented to avoid this kind of unhelpful behavior.
Thinking more about it, if allyesconfig is meant to be useful, then any "depends on !..." (other than for base architecture identifiers) would be wrong (see e.g. COVERAGE depending on !LIVEPATCH or
ARM_SMMU_V3depending on !ACPI). And this would extend to Linux as well - how do they deal with that?
Quoted 8 lines
Quoted 2 lines
Isn't allyesconfig for new options only? At least in Linux it is documented this way.
Is it? I only find
"make allyesconfig"
Create a ./.config file by setting symbol values to 'y' as much as possible.
Hmm, strange. I seem to have either looked at something else, or I haven't read it correctly.
Sorry for the noise.
And probably time for more coffee.
Juergen
PATCH 3/3 x86/pv-shim: suppress core-parking logic
In reply to Jan BeulichThis is all dead code in shim-exclusive mode, so there's no point in building it.
---
Contextually depends on "core-parking: fix build with gcc12 and NR_CPUS=1"
xen/arch/x86/Kconfig +1 -1
@@ -10,7 +10,7 @@ config X86 select ALTERNATIVE_CALL select ARCH_MAP_DOMAIN_PAGE select ARCH_SUPPORTS_INT128 - select CORE_PARKING if NR_CPUS > 1 + select CORE_PARKING if NR_CPUS > 1 && !PV_SHIM_EXCLUSIVE select HAS_ALTERNATIVE select HAS_COMPAT select HAS_CPUFREQ