XSM: cleanups
cover XSM: cleanups
Various XSM cleanups from observations based on Daniel's previous cleanup series.
Andrew Cooper (4):
xen/xsm: Complete altcall conversion of xsm interface xen/xsm: Drop xsm_hvm_control() hook xen/xsm: Improve fallback handling in xsm_fixup_ops() xen/xsm: Address hypercall ABI problems
Jan Beulich (1):
x86/altcall: allow compound types to be passed
xen/include/Makefile | 2 +- xen/include/asm-x86/alternative.h | 4 +- xen/include/xsm/dummy.h | 19 --- xen/include/xsm/xsm.h | 39 ++---- xen/xsm/Makefile | 1 + xen/xsm/dummy.c | 254 ++++++++++++++++++++------------------ xen/xsm/flask/flask_op.c | 60 ++++----- xen/xsm/flask/hooks.c | 9 -- xen/xsm/private.h | 16 +++ xen/xsm/xsm_core.c | 12 -- xen/xsm/xsm_op.c | 51 ++++++++ 11 files changed, 245 insertions(+), 222 deletions(-) create mode 100644 xen/xsm/private.h create mode 100644 xen/xsm/xsm_op.c
Signature · 1 line
2.11.0
PATCH 1/5 x86/altcall: allow compound types to be passed
From: Jan Beulich <[email protected]>
Replace the conditional operator in ALT_CALL_ARG(), which was intended to limit usable types to scalar ones, by a size check. Some restriction here is necessary to make sure we don't violate the ABI's calling conventions, but limiting to scalar types was both too restrictive (disallowing e.g. guest handles) and too permissive (allowing e.g. __int128_t).
Note that there was some anomaly with that conditional operator anyway:
Something - I don't recall what - made it impossible to omit the middle operand.
Code-generation-wise this has the effect of removing certain zero- or sign-extending in some altcall invocations. This ought to be fine as the ABI doesn't require sub-sizeof(int) values to be extended, except when passed through an ellipsis. No functions subject to altcall patching has a variable number of arguments, though.
Unfortunately this triggers [-Werror=sizeof-array-argument] on some versions of GCC, so alter xsm_{alloc,free}_security_evtchns() to use a pointer rather than array parameter.
---
CC: Daniel De Graaf <[email protected]>
CC: Daniel Smith <[email protected]>
CC: Jan Beulich <[email protected]>
--- xen/include/asm-x86/alternative.h | 4 ++-- xen/include/xsm/xsm.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
xen/include/asm-x86/alternative.h +2 -2
@@ -168,8 +168,8 @@ extern void alternative_branches(void);#define ALT_CALL_arg6 "r9"#define ALT_CALL_ARG (arg, n) \ - register typeof((arg) ? (arg) : 0) a ## n ## _ \ - asm ( ALT_CALL_arg ## n ) = (arg) + register typeof(arg) a ## n ## _ asm ( ALT_CALL_arg ## n ) = \ + ({ BUILD_BUG_ON(sizeof(arg) > sizeof(void *)); (arg); })#define ALT_CALL_NO_ARG (n) \ register unsigned long a ## n ## _ asm ( ALT_CALL_arg ## n )
xen/include/xsm/xsm.h +2 -2
@@ -332,13 +332,13 @@ static inline void xsm_free_security_domain(struct domain *d) }static inline int xsm_alloc_security_evtchns ( -struct evtchn chn[],unsigned int nr) +struct evtchn *chn,unsigned int nr) {return alternative_call (xsm_ops.alloc_security_evtchns, chn, nr); }static inline void xsm_free_security_evtchns ( -struct evtchn chn[],unsigned int nr) +struct evtchn *chn,unsigned int nr) {alternative_vcall (xsm_ops.free_security_evtchns, chn, nr); }
Signature · 1 line
2.11.0
Re: [PATCH 1/5] x86/altcall: allow compound types to be passed
Quoted 19 lines · Andrew Cooper
From: Jan Beulich <[email protected]>
Replace the conditional operator in
ALT_CALL_ARG(), which was intended to limit usable types to scalar ones, by a size check. Some restriction here is necessary to make sure we don't violate the ABI's calling conventions, but limiting to scalar types was both too restrictive (disallowing e.g. guest handles) and too permissive (allowing e.g.__int128_t).Note that there was some anomaly with that conditional operator anyway:
Something - I don't recall what - made it impossible to omit the middle operand.Code-generation-wise this has the effect of removing certain zero- or sign-extending in some altcall invocations. This ought to be fine as the ABI doesn't require sub-sizeof(int) values to be extended, except when passed through an ellipsis. No functions subject to altcall patching has a variable number of arguments, though.
Quoted 4 lines
Requested-by Andrew Cooper <[email protected]>Signed-off-by Jan Beulich <[email protected]>Acked-by Andrew Cooper <[email protected]>
PATCH 2/5 xen/xsm: Complete altcall conversion of xsm interface
In reply to Andrew CooperWith alternative_call() capable of handling compound types, the three remaining hooks can be optimised at boot time too.
---
CC: Daniel De Graaf <[email protected]>
CC: Daniel Smith <[email protected]>
I'm on the fence as to whether to declare this as fixing "xsm: convert xsm_ops hook calls to alternative call"
--- xen/include/xsm/xsm.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
xen/include/xsm/xsm.h +3 -3
@@ -579,13 +579,13 @@ static inline int xsm_hypfs_op(xsm_default_t def)static inline long xsm_do_xsm_op (XEN_GUEST_HANDLE_PARAM (void ) op) { -return xsm_ops.do_xsm_op (op); +return alternative_call (xsm_ops.do_xsm_op, op); }#ifdef CONFIG_COMPAT static inline int xsm_do_compat_op (XEN_GUEST_HANDLE_PARAM (void ) op) { -return xsm_ops.do_compat_op (op); +return alternative_call (xsm_ops.do_compat_op, op); }#endif
@@ -698,7 +698,7 @@ static inline int xsm_mmuext_op(static inline int xsm_update_va_mapping (xsm_default_t def,struct domain *d,struct domain *f,l1_pgentry_t pte) { -return xsm_ops.update_va_mapping (d, f, pte); +return alternative_call (xsm_ops.update_va_mapping, d, f, pte); } static inline int xsm_priv_mapping(
Signature · 1 line
2.11.0
Re: [PATCH 2/5] xen/xsm: Complete altcall conversion of xsm interface
Quoted 4 lines · Andrew Cooper
With
alternative_call()capable of handling compound types, the three remaining hooks can be optimised at boot time too.Signed-off-by Andrew Cooper <[email protected]>
Re: [PATCH 2/5] xen/xsm: Complete altcall conversion of xsm interface
In reply to Andrew CooperQuoted 10 lines · Andrew Cooper
With
alternative_call()capable of handling compound types, the three remaining hooks can be optimised at boot time too.Signed-off-by Andrew Cooper <[email protected]>---
CC: Daniel De Graaf <[email protected]>
CC: Daniel Smith <[email protected]>I'm on the fence as to whether to declare this as fixing "xsm: convert
xsm_opshook calls to alternative call"
I don't know about fixing but completing was accurate. I am fairly certain in one of the incarnations of the patch set there was a comment identifying that these were left remaining since compound types were not supported by altcall.
Regardless,
v/r,
dps
Re: [PATCH 2/5] xen/xsm: Complete altcall conversion of xsm interface
In reply to Andrew CooperQuoted 10 lines · Andrew Cooper
With
alternative_call()capable of handling compound types, the three remaining hooks can be optimised at boot time too.Signed-off-by Andrew Cooper <[email protected]>---
CC: Daniel De Graaf <[email protected]>
CC: Daniel Smith <[email protected]>I'm on the fence as to whether to declare this as fixing "xsm: convert
xsm_opshook calls to alternative call"
Forgot to say a word on this: I'd consider Fixes: appropriate, as the commit's description says nothing about these having been left out, nor why.
Jan
Re: [PATCH 2/5] xen/xsm: Complete altcall conversion of xsm interface
Quoted 9 lines · Jan Beulich
Quoted 8 lines · Andrew Cooper
With
alternative_call()capable of handling compound types, the three remaining hooks can be optimised at boot time too.Signed-off-by Andrew Cooper <[email protected]>---
CC: Daniel De Graaf <[email protected]>
CC: Daniel Smith <[email protected]>
Quoted 5 lines
Quoted 2 lines
I'm on the fence as to whether to declare this as fixing "xsm: convert
xsm_opshook calls to alternative call"Forgot to say a word on this: I'd consider Fixes: appropriate, as the commit's description says nothing about these having been left out, nor why.
Ok. I'll insert one.
~Andrew
PATCH 3/5 xen/xsm: Drop xsm_hvm_control() hook
In reply to Andrew CooperThe final caller was dropped by c/s 58cbc034dc62 "dm_op: convert HVMOP_inject_trap and HVMOP_inject_msi"
---
CC: Daniel De Graaf <[email protected]>
CC: Daniel Smith <[email protected]>
--- xen/include/xsm/dummy.h | 7 ------- xen/include/xsm/xsm.h | 7 ------- xen/xsm/dummy.c | 1 - xen/xsm/flask/hooks.c | 1 - 4 files changed, 16 deletions(-)
xen/include/xsm/dummy.h +0 -7
@@ -580,13 +580,6 @@ static XSM_INLINE int xsm_hvm_param(return xsm_default_action (action, current->domain, d); } -static XSM_INLINE int xsm_hvm_control( - XSM_DEFAULT_ARG struct domain *d, unsigned long op) -{ -XSM_ASSERT_ACTION (XSM_DM_PRIV ); -return xsm_default_action (action, current->domain, d); -} - static XSM_INLINE int xsm_hvm_param_altp2mhvm(XSM_DEFAULT_ARG struct domain *d) {XSM_ASSERT_ACTION (XSM_PRIV );
xen/include/xsm/xsm.h +0 -7
@@ -138,7 +138,6 @@ struct xsm_ops {#endif int (*hvm_param)(struct domain *d,unsigned long op); -int (*hvm_control)(struct domain *d,unsigned long op);int (*hvm_param_altp2mhvm)(struct domain *d);int (*hvm_altp2mhvm_op)(struct domain *d,uint64_t mode,uint32_t op);int (*get_vnumainfo)(struct domain *d);
@@ -595,12 +594,6 @@ static inline int xsm_hvm_param(return alternative_call (xsm_ops.hvm_param, d, op); } -static inline int xsm_hvm_control ( -xsm_default_t def,struct domain *d,unsigned long op) -{ -return alternative_call (xsm_ops.hvm_control, d, op); -} -static inline int xsm_hvm_param_altp2mhvm (xsm_default_t def,struct domain *d) {return alternative_call (xsm_ops.hvm_param_altp2mhvm, d);
xen/xsm/dummy.c +0 -1
@@ -103,7 +103,6 @@ void __init xsm_fixup_ops (struct xsm_ops *ops)set_to_dummy_if_null (ops, page_offline);set_to_dummy_if_null (ops, hypfs_op);set_to_dummy_if_null (ops, hvm_param); -set_to_dummy_if_null (ops, hvm_control);set_to_dummy_if_null (ops, hvm_param_altp2mhvm);set_to_dummy_if_null (ops, hvm_altp2mhvm_op);
xen/xsm/flask/hooks.c +0 -1
@@ -1816,7 +1816,6 @@ static const struct xsm_ops __initconstrel flask_ops = { .page_offline = flask_page_offline, .hypfs_op = flask_hypfs_op, .hvm_param = flask_hvm_param, - .hvm_control = flask_hvm_param, .hvm_param_altp2mhvm = flask_hvm_param_altp2mhvm, .hvm_altp2mhvm_op = flask_hvm_altp2mhvm_op,
Signature · 1 line
2.11.0
Re: [PATCH 3/5] xen/xsm: Drop xsm_hvm_control() hook
Quoted 7 lines · Andrew Cooper
The final caller was dropped by c/s
58cbc034dc62"dm_op: convertHVMOP_inject_trapandHVMOP_inject_msi"Signed-off-by Andrew Cooper <[email protected]>---
CC: Daniel De Graaf <[email protected]>
CC: Daniel Smith <[email protected]>
PATCH 4/5 xen/xsm: Improve fallback handling in xsm_fixup_ops()
In reply to Andrew CooperThe current xsm_fixup_ops() is just shy of a full page when compiled, and very fragile to NULL function pointer errors.
Address both of these issues with a minor piece of structure (ab)use. Introduce dummy_ops, and fixup the provided xsm_ops pointer by treating both as an array of unsigned longs.
The compiled size improvement speaks for itself:
$ ../scripts/bloat-o-meter xen-syms-before xen-syms-after add/remove: 1/0 grow/shrink: 0/1 up/down: 712/-3897 (-3185) Function old new delta dummy_ops - 712 +712 xsm_fixup_ops 3987 90 -3897
and there is an additional safety check that will make it obvious during development if there is an issue with the fallback handling.
---
CC: Daniel De Graaf <[email protected]>
CC: Daniel Smith <[email protected]>
--- xen/include/xsm/xsm.h | 9 ++ xen/xsm/dummy.c | 254 +++++++++++++++++++++++++++----------------------- 2 files changed, 147 insertions(+), 116 deletions(-)
xen/include/xsm/xsm.h +9 -0
@@ -42,6 +42,15 @@ enum xsm_default { };typedef enum xsm_default xsm_default_t ; +/* +* !!! WARNING !!! +* +* For simplicity, xsm_fixup_ops() expects that this structure is made +* exclusively of function pointers to non-init functions. Think carefully +* before deviating from the pattern. +* +* !!! WARNING !!! +*/ struct xsm_ops {void (*security_domaininfo)(struct domain *d,struct xen_domctl_getdomaininfo *info);
xen/xsm/dummy.c +138 -116
283 lines not on this page · raw message
Signature · 1 line
2.11.0
Re: [PATCH 4/5] xen/xsm: Improve fallback handling in xsm_fixup_ops()
Quoted 15 lines · Andrew Cooper
The current
xsm_fixup_ops()is just shy of a full page when compiled, and very fragile to NULL function pointer errors.Address both of these issues with a minor piece of structure (ab)use. Introduce
dummy_ops, and fixup the providedxsm_opspointer by treating both as an array of unsigned longs.The compiled size improvement speaks for itself:
$ ../scripts/bloat-o-meter xen-syms-before xen-syms-after add/remove: 1/0 grow/shrink: 0/1 up/down: 712/-3897 (-3185) Function old new delta dummy_ops - 712 +712 xsm_fixup_ops 3987 90 -3897
Quoted 7 lines
and there is an additional safety check that will make it obvious during development if there is an issue with the fallback handling.
Signed-off-by Andrew Cooper <[email protected]>---
CC: Daniel De Graaf <[email protected]>
CC: Daniel Smith <[email protected]>
Re: [PATCH 4/5] xen/xsm: Improve fallback handling in xsm_fixup_ops()
In reply to Andrew Cooperxen/xsm/dummy.c line 162
Quoted 11 lines · Andrew Cooper
xen/xsm/dummy.c +11
-0+void __init xsm_fixup_ops (struct xsm_ops *ops) +{ +/* +* We make some simplifying assumptions about struct xsm_ops; that it is +* made exclusively of function pointers to non-init text. +* +* This allows us to walk over struct xsm_ops as if it were an array of +* unsigned longs. +*/ +unsigned long *dst =_p (ops); +unsigned long *src =_p (&dummy_ops);
I'm afraid I consider this an abuse of _p(): It hides casting when that would better not be hidden (and there's then also a pointless step through "unsigned long" in the casting). I suppose this is also why "src" didn't end up "const unsigned long *" - with spelled out casts the casting away of const might have been more noticable.
xen/xsm/dummy.c line 174
Quoted 11 lines
xen/xsm/dummy.c +11
-0+for ( ; dst < (unsigned long *)(ops +1 ); src++, dst++ ) + { +/* +* If you encounter this BUG(), then you've most likely added a new +* XSM hook but failed to provide the default implementation in +* dummy_ops. +* +* If not, then perhaps a function pointer to an init function, or +* something which isn't a function pointer at all. +*/ +BUG_ON (!is_kernel_text (*src));
Just as a remark, not a request to change anything: A cause of this triggering may also be is_kernel_text() not covering all text sections. Some of what recently we've been talking about informally may lead to new text section variants appearing, and whether those would sensibly end up inside [_stext,_etext) is uncertain.
Jan
Re: [PATCH 4/5] xen/xsm: Improve fallback handling in xsm_fixup_ops()
Quoted 17 lines · Jan Beulich
xen/xsm/dummy.c line 162
Quoted 11 lines · Andrew Cooper
xen/xsm/dummy.c +11
-0+void __init xsm_fixup_ops (struct xsm_ops *ops) +{ +/* +* We make some simplifying assumptions about struct xsm_ops; that it is +* made exclusively of function pointers to non-init text. +* +* This allows us to walk over struct xsm_ops as if it were an array of +* unsigned longs. +*/ +unsigned long *dst =_p (ops); +unsigned long *src =_p (&dummy_ops);I'm afraid I consider this an abuse of
_p(): It hides casting when that would better not be hidden (and there's then also a pointless step through "unsigned long" in the casting). I suppose this is also why "src" didn't end up "const unsigned long *" - with spelled out casts the casting away of const might have been more noticable.
I've changed to a const pointer, but opencoding _p() wouldn't make it any more likely for me to have spotted that it ought to have been const to begin with.
But ultimately it comes down to neatness/clarity. This:
unsigned long *dst = _p(ops);
const unsigned long *src = _p(&dummy_ops);
is easier to read than this:
unsigned long *dst = (unsigned long *)ops;
const unsigned long *src = (const unsigned long *)&dummy_ops;
Fundamentally, I can do either, but I have a preference for the one which is easier to follow.
Quoted 11 lines
xen/xsm/dummy.c line 174
Quoted 11 lines
xen/xsm/dummy.c +11
-0+for ( ; dst < (unsigned long *)(ops +1 ); src++, dst++ ) + { +/* +* If you encounter this BUG(), then you've most likely added a new +* XSM hook but failed to provide the default implementation in +* dummy_ops. +* +* If not, then perhaps a function pointer to an init function, or +* something which isn't a function pointer at all. +*/ +BUG_ON (!is_kernel_text (*src));
Quoted 5 lines
Just as a remark, not a request to change anything: A cause of this triggering may also be
is_kernel_text()not covering all text sections. Some of what recently we've been talking about informally may lead to new text section variants appearing, and whether those would sensibly end up inside [_stext,_etext) is uncertain.
I'm afraid that I'm not aware of what you're referring to here. But I don't think any good will come from having is_kernel_text() not covering suitable things.
~Andrew
Re: [PATCH 4/5] xen/xsm: Improve fallback handling in xsm_fixup_ops()
Quoted 28 lines · Andrew Cooper
Quoted 17 lines · Jan Beulich
xen/xsm/dummy.c line 162
Quoted 11 lines · Andrew Cooper
xen/xsm/dummy.c +11
-0+void __init xsm_fixup_ops (struct xsm_ops *ops) +{ +/* +* We make some simplifying assumptions about struct xsm_ops; that it is +* made exclusively of function pointers to non-init text. +* +* This allows us to walk over struct xsm_ops as if it were an array of +* unsigned longs. +*/ +unsigned long *dst =_p (ops); +unsigned long *src =_p (&dummy_ops);I'm afraid I consider this an abuse of
_p(): It hides casting when that would better not be hidden (and there's then also a pointless step through "unsigned long" in the casting). I suppose this is also why "src" didn't end up "const unsigned long *" - with spelled out casts the casting away of const might have been more noticable.I've changed to a const pointer, but opencoding
_p()wouldn't make it any more likely for me to have spotted that it ought to have been const to begin with.But ultimately it comes down to neatness/clarity. This:
unsigned long *dst =
_p(ops);
const unsigned long *src =_p(&dummy_ops);
Quoted 7 lines
is easier to read than this:
unsigned long *dst = (unsigned long *)ops;
const unsigned long *src = (const unsigned long *)&dummy_ops;Fundamentally, I can do either, but I have a preference for the one which is easier to follow.
One option would be to at least make _p() cast to const void *.
Jan
PATCH 5/5 xen/xsm: Address hypercall ABI problems
In reply to Andrew CooperCurrently, __HYPERVISOR_xsm_op enters xsm_ops.do_{xsm,compat}_op() which means that if any other XSM module registers a handler, we'll break the hypercall ABI totally by having the behaviour depend on the selected XSM module.
There are 2 options:
1) Rename __HYPERVISOR_xsm_op to __HYPERVISOR_flask_op. If another XSM module wants hypercalls, they'll have to introduce a new top-level hypercall.
2) Make the current flask_op() be common, and require new hypercalls to fit compatibly with xen_flask_op_t. This can be done fairly easily by subdividing the .cmd space.
In this patch, we implement option 2.
Move the stub {do,compat}_xsm_op() implementation into a new xsm_op.c so we can more easily do multi-inclusion compat magic. Also add a new private.h, because flask/hook.c's local declaration of {do,compat}_flask_op() wasn't remotely safe.
The top level now dispatches into {do,compat}_flask_op() based on op.cmd, and handles the primary copy in/out.
---
CC: Daniel De Graaf <[email protected]>
CC: Daniel Smith <[email protected]>
Only lightly tested. Slightly RFC. There are several things which aren't great, but probably want addressing in due course.
1) The public headers probably want to lose the flask name (in a compatible way), now that the hypercall is common. This probably wants to be combined with no longer taking a void handle.
2) {do,compat}_xsm_op() are currently identical other than the dispatched-to functions because the size of xsm_flask_op_t is invariant with COMPAT-ness. We could simplfy things by only having one, and dispatching to {do,compat}_*_op() directly, but I'm not sure whether the complexity is worth it.
3) Bloat-o-meter says these changes add 16 extra bytes to dm_op() and I can't figure out what could possibly be causing this.
--- xen/include/Makefile | 2 +- xen/include/xsm/dummy.h | 12 ---------- xen/include/xsm/xsm.h | 17 -------------- xen/xsm/Makefile | 1 + xen/xsm/dummy.c | 5 ---- xen/xsm/flask/flask_op.c | 60 ++++++++++++++++++++++-------------------------- xen/xsm/flask/hooks.c | 8 ------- xen/xsm/private.h | 16 +++++++++++++ xen/xsm/xsm_core.c | 12 ---------- xen/xsm/xsm_op.c | 51 ++++++++++++++++++++++++++++++++++++++++ 10 files changed, 96 insertions(+), 88 deletions(-) create mode 100644 xen/xsm/private.h create mode 100644 xen/xsm/xsm_op.c
xen/include/Makefile +1 -1
@@ -32,7 +32,7 @@ headers-$(CONFIG_HYPFS) += compat/hypfs.h headers-$(CONFIG_KEXEC) += compat/kexec.h headers-$(CONFIG_TRACEBUFFER) += compat/trace.h headers-$(CONFIG_XENOPROF) += compat/xenoprof.h -headers-$(CONFIG_XSM_FLASK) += compat/xsm/flask_op.h +headers-$(CONFIG_XSM) += compat/xsm/flask_op.h cppflags-y := -include public/xen-compat.h -DXEN_GENERATING_COMPAT_HEADERS cppflags-$(CONFIG_X86) += -m32
xen/include/xsm/dummy.h +0 -12
@@ -466,18 +466,6 @@ static XSM_INLINE int xsm_hypfs_op(XSM_DEFAULT_VOID)return xsm_default_action (action, current->domain,NULL ); } -static XSM_INLINE long xsm_do_xsm_op (XEN_GUEST_HANDLE_PARAM (void ) op) -{ -return -ENOSYS ; -} - -#ifdef CONFIG_COMPAT -static XSM_INLINE int xsm_do_compat_op(XEN_GUEST_HANDLE_PARAM(void) op) -{ -return -ENOSYS ; -} -#endif - static XSM_INLINE char *xsm_show_irq_sid(int irq) {return NULL ;
xen/include/xsm/xsm.h +0 -17
@@ -141,11 +141,6 @@ struct xsm_ops {int (*page_offline)(uint32_t cmd);int (*hypfs_op)(void ); -long (*do_xsm_op)(XEN_GUEST_HANDLE_PARAM (void ) op); -#ifdef CONFIG_COMPAT -int (*do_compat_op)(XEN_GUEST_HANDLE_PARAM (void ) op); -#endif -int (*hvm_param)(struct domain *d,unsigned long op);int (*hvm_param_altp2mhvm)(struct domain *d);int (*hvm_altp2mhvm_op)(struct domain *d,uint64_t mode,uint32_t op);
@@ -585,18 +580,6 @@ static inline int xsm_hypfs_op(xsm_default_t def)return alternative_call (xsm_ops.hypfs_op); } -static inline long xsm_do_xsm_op (XEN_GUEST_HANDLE_PARAM (void ) op) -{ -return alternative_call (xsm_ops.do_xsm_op, op); -} - -#ifdef CONFIG_COMPAT -static inline int xsm_do_compat_op (XEN_GUEST_HANDLE_PARAM (void ) op) -{ -return alternative_call (xsm_ops.do_compat_op, op); -} -#endif -static inline int xsm_hvm_param (xsm_default_t def,struct domain *d,unsigned long op) {
xen/xsm/Makefile +1 -0
@@ -1,4 +1,5 @@ obj-y += xsm_core.o +obj-y += xsm_op.o obj-$(CONFIG_XSM) += xsm_policy.o obj-$(CONFIG_XSM) += dummy.o obj-$(CONFIG_XSM_SILO) += silo.o
xen/xsm/dummy.c +0 -5
@@ -99,11 +99,6 @@ static const struct xsm_ops __initconstrel dummy_ops = { .hvm_param_altp2mhvm = xsm_hvm_param_altp2mhvm, .hvm_altp2mhvm_op = xsm_hvm_altp2mhvm_op, - .do_xsm_op = xsm_do_xsm_op, -#ifdef CONFIG_COMPAT - .do_compat_op = xsm_do_compat_op, -#endif - .add_to_physmap = xsm_add_to_physmap, .remove_from_physmap = xsm_remove_from_physmap, .map_gmfn_foreign = xsm_map_gmfn_foreign,
xen/xsm/flask/flask_op.c +27 -33
149 lines not on this page · raw message
xen/xsm/flask/hooks.c +0 -8
@@ -1742,9 +1742,6 @@ static int flask_argo_send(const struct domain *d, const struct domain *t)#endif -long do_flask_op (XEN_GUEST_HANDLE_PARAM (void ) u_flask_op); -int compat_flask_op (XEN_GUEST_HANDLE_PARAM (void ) u_flask_op); - static const struct xsm_ops __initconstrel flask_ops = { .security_domaininfo = flask_security_domaininfo, .domain_create = flask_domain_create,
@@ -1819,7 +1816,6 @@ static const struct xsm_ops __initconstrel flask_ops = { .hvm_param_altp2mhvm = flask_hvm_param_altp2mhvm, .hvm_altp2mhvm_op = flask_hvm_altp2mhvm_op, - .do_xsm_op = do_flask_op, .get_vnumainfo = flask_get_vnumainfo, .vm_event_control = flask_vm_event_control,
@@ -1836,10 +1832,6 @@ static const struct xsm_ops __initconstrel flask_ops = { .mem_sharing = flask_mem_sharing, #endif -#ifdef CONFIG_COMPAT - .do_compat_op = compat_flask_op, -#endif - .add_to_physmap = flask_add_to_physmap, .remove_from_physmap = flask_remove_from_physmap, .map_gmfn_foreign = flask_map_gmfn_foreign,
xen/xsm/private.h new file +16 -0
@@ -0,0 +1,16 @@ +#ifndef XSM_PRIVATE_H +#define XSM_PRIVATE_H + +#include <public/xsm/flask_op.h> + +long do_flask_op (xen_flask_op_t *op,bool *copyback); + +#ifdef CONFIG_COMPAT + +#include <compat/xsm/flask_op.h> + +int compat_flask_op (compat_flask_op_t *op,bool *copyback); + +#endif /* CONFIG_COMPAT */ + +#endif /* XSM_PRIVATE_H */
xen/xsm/xsm_core.c +0 -12
@@ -218,15 +218,3 @@ bool __init has_xsm_magic(paddr_t start)#endif #endif - -long do_xsm_op (XEN_GUEST_HANDLE_PARAM (void ) op) -{ -return xsm_do_xsm_op (op); -} - -#ifdef CONFIG_COMPAT -int compat_xsm_op (XEN_GUEST_HANDLE_PARAM (void ) op) -{ -return xsm_do_compat_op (op); -} -#endif
xen/xsm/xsm_op.c new file +51 -0
51 lines not on this page · raw message
Signature · 1 line
2.11.0
Re: [PATCH 5/5] xen/xsm: Address hypercall ABI problems
Quoted 14 lines · Andrew Cooper
Currently,
__HYPERVISOR_xsm_openters xsm_ops.do_{xsm,compat}_op() which means that if any other XSM module registers a handler, we'll break the hypercall ABI totally by having the behaviour depend on the selected XSM module.There are 2 options:
1) Rename__HYPERVISOR_xsm_opto__HYPERVISOR_flask_op. If another XSM module wants hypercalls, they'll have to introduce a new top-level hypercall.
2) Make the currentflask_op()be common, and require new hypercalls to fit compatibly withxen_flask_op_t. This can be done fairly easily by subdividing the .cmd space.In this patch, we implement option 2.
Quoted 7 lines
Move the stub {do,compat}_xsm_op() implementation into a new
xsm_op.cso we can more easily do multi-inclusion compat magic. Also add a newprivate.h, because flask/hook.c's local declaration of {do,compat}_flask_op() wasn't remotely safe.The top level now dispatches into {do,compat}_flask_op() based on op.cmd, and handles the primary copy in/out.
I'm not convinced this is the only reasonable way of implementing 2). I could also see number space to be separated in different ways, ...
Quoted 11 lines
Signed-off-by Andrew Cooper <[email protected]>---
CC: Daniel De Graaf <[email protected]>
CC: Daniel Smith <[email protected]>Only lightly tested. Slightly RFC. There are several things which aren't great, but probably want addressing in due course.
1) The public headers probably want to lose the flask name (in a compatible way), now that the hypercall is common. This probably wants to be combined with no longer taking a void handle.
... leaving per-module public headers and perhaps merely adding an abstracting
struct xen_xsm_op_t {
uint32_t op;
... /* placeholder */
};or (making explicit one possible variant of number space splitting)
union xen_xsm_op_t {
uint32_t op;
struct {
uint16_t cmd;
uint16_t mod;
} u;
... /* placeholder */
};in, say, a new public/xsm.h.
As a result I consider this change either going too far (because of not knowing future needs) or not far enough (by e.g. leaving do_xsm_op() to use xen_flask_op_t.
Quoted 5 lines
2) {do,compat}_xsm_op() are currently identical other than the dispatched-to functions because the size of
xsm_flask_op_tis invariant with COMPAT-ness. We could simplfy things by only having one, and dispatching to {do,compat}_*_op() directly, but I'm not sure whether the complexity is worth it.
Perhaps not, I would say, not the least because (as said above) I think we shouldn't put in place restrictions which may get in the way of adding some future module.
Extending struct xen_flask_op to become a generic XSM interface structure (or even just for Flask's own purposes) also is not as straightforward as it might seem: There's currently no provision for sub-structs which would grow the overall size of the structure:
The copy_{to,from}_guest() invocations for existing sub-ops may not copy more that the present worth of sizeof(struct xen_flask_op). Yet your implementation of do_xsm_op() moves this deficiency from Flask to XSM.
Quoted 2 lines
3) Bloat-o-meter says these changes add 16 extra bytes to
dm_op()and I can't figure out what could possibly be causing this.
Without comparing the object files in closer detail it's guesswork, but might this be register scheduling differences resulting from the changed sizeof(struct xsm_ops)? I've been observing similar seemingly unmotivated changes to generated code ...
xen/xsm/flask/flask_op.c line 25
Quoted 7 lines
xen/xsm/flask/flask_op.c +1
-0@@ -22,6 +22,8 @@#include <objsec.h> #include <conditional.h> +#include "../private.h"
Kind of odd: I'd expect a file named such to not get included across directory levels, unless a single component was split in such a way (to me Flask and XSM core are separate, yet still related components).
Jan
Re: [PATCH 5/5] xen/xsm: Address hypercall ABI problems
Quoted 55 lines · Jan Beulich
Quoted 14 lines · Andrew Cooper
Currently,
__HYPERVISOR_xsm_openters xsm_ops.do_{xsm,compat}_op() which means that if any other XSM module registers a handler, we'll break the hypercall ABI totally by having the behaviour depend on the selected XSM module.There are 2 options:
1) Rename__HYPERVISOR_xsm_opto__HYPERVISOR_flask_op. If another XSM module wants hypercalls, they'll have to introduce a new top-level hypercall.
2) Make the currentflask_op()be common, and require new hypercalls to fit compatibly withxen_flask_op_t. This can be done fairly easily by subdividing the .cmd space.In this patch, we implement option 2.
Quoted 7 lines
Move the stub {do,compat}_xsm_op() implementation into a new
xsm_op.cso we can more easily do multi-inclusion compat magic. Also add a newprivate.h, because flask/hook.c's local declaration of {do,compat}_flask_op() wasn't remotely safe.The top level now dispatches into {do,compat}_flask_op() based on op.cmd, and handles the primary copy in/out.
I'm not convinced this is the only reasonable way of implementing 2). I could also see number space to be separated in different ways, ...
Quoted 11 lines
Signed-off-by Andrew Cooper <[email protected]>---
CC: Daniel De Graaf <[email protected]>
CC: Daniel Smith <[email protected]>Only lightly tested. Slightly RFC. There are several things which aren't great, but probably want addressing in due course.
1) The public headers probably want to lose the flask name (in a compatible way), now that the hypercall is common. This probably wants to be combined with no longer taking a void handle.
... leaving per-module public headers and perhaps merely adding an abstracting
struct xen_xsm_op_t { uint32_t op; ... /* placeholder */ };or (making explicit one possible variant of number space splitting)
union xen_xsm_op_t { uint32_t op; struct { uint16_t cmd; uint16_t mod; } u; ... /* placeholder */ };
Quoted 1 line
in, say, a new
public/xsm.h.
That doesn't work. The ABI is fixed at sizeof(xen_flask_op_t) for all other modules, because a caller which doesn't know which module is in use must not have Xen over-read/write the object passed while it's trying to figure things out.
Quoted 3 lines
As a result I consider this change either going too far (because of not knowing future needs) or not far enough (by e.g. leaving
do_xsm_op()to usexen_flask_op_t.
Well - what it does is prevent someone from breaking the ABI with literally this patch
xen/xsm/silo.c +0 -0
@@ -100,6 +100,11 @@ static int silo_argo_send(const struct domain *d1, const struct domain *d2)
#endif
+static long silo_do_xsm_op(XEN_GUEST_HANDLE_PARAM(void) op)
+{
+ /* ... */
+}
+
static const struct xsm_ops __initconstrel silo_xsm_ops = { .evtchn_unbound = silo_evtchn_unbound,
.evtchn_interdomain = silo_evtchn_interdomain,
@@ -110,6 +115,7 @@ static const struct xsm_ops __initconstrel silo_xsm_ops = { .argo_register_single_source = silo_argo_register_single_source, .argo_send = silo_argo_send,
#endif
+ .do_xsm_op = silo_do_xsm_op,
};
const struct xsm_ops *__init silo_init(void)
This is a damage limitation patch, but without knowing how the next module is going to want to do hypercalls differently, it is rather hard to judge what is appropriate. I certainly didn't waste much time thinking about it.
Quoted 10 lines
Quoted 6 lines
2) {do,compat}_xsm_op() are currently identical other than the dispatched-to functions because the size of
xsm_flask_op_tis invariant with COMPAT-ness. We could simplfy things by only having one, and dispatching to {do,compat}_*_op() directly, but I'm not sure whether the complexity is worth it.Perhaps not, I would say, not the least because (as said above) I think we shouldn't put in place restrictions which may get in the way of adding some future module.
Quoted 8 lines
Extending struct
xen_flask_opto become a generic XSM interface structure (or even just for Flask's own purposes) also is not as straightforward as it might seem: There's currently no provision for sub-structs which would grow the overall size of the structure:
The copy_{to,from}_guest() invocations for existing sub-ops may not copy more that the present worth ofsizeof(struct xen_flask_op). Yet your implementation ofdo_xsm_op()moves this deficiency from Flask to XSM.
Deficiency yes, but necessary to avoid breaking the ABI for caller which doesn't know which module is in use. This cannot be fixed without swapping to approach 1.
Quoted 6 lines
Quoted 2 lines
3) Bloat-o-meter says these changes add 16 extra bytes to
dm_op()and I can't figure out what could possibly be causing this.Without comparing the object files in closer detail it's guesswork, but might this be register scheduling differences resulting from the changed
sizeof(struct xsm_ops)? I've been observing similar seemingly unmotivated changes to generated code ...
The only thing it can plausibly be is a knock-on effect from the structure of xsm_ops changing.
Normally, I wouldn't be to surprised to see some displacement fields dropping from 4 to 1 byte as xsm_ops is getting smaller, but everything is alt_call()'d up so should be a 7-byte call *disp32(%rip).
Quoted 11 lines
xen/xsm/flask/flask_op.c line 25
Quoted 7 lines
xen/xsm/flask/flask_op.c +1
-0@@ -22,6 +22,8 @@#include <objsec.h> #include <conditional.h> +#include "../private.h" Kind of odd: I'd expect a file named such to not get included across directory levels, unless a single component was split in such a way (to me Flask and XSM core are separate, yet still related components).
Its all a tangled mess because logically separating XSM and Flask was a task done when SILO was introduced.
There is not an appropriately located file (under xen/xsm/ ) where the prototypes could reasonably live, and this felt like the lesser of the available evils.
~Andrew
Re: [PATCH 5/5] xen/xsm: Address hypercall ABI problems
Quoted 139 lines · Andrew Cooper
Quoted 55 lines · Jan Beulich
Quoted 14 lines · Andrew Cooper
Currently,
__HYPERVISOR_xsm_openters xsm_ops.do_{xsm,compat}_op() which means that if any other XSM module registers a handler, we'll break the hypercall ABI totally by having the behaviour depend on the selected XSM module.There are 2 options:
1) Rename__HYPERVISOR_xsm_opto __HYPERVISOR_flask_op. If another XSM module wants hypercalls, they'll have to introduce a new top-level hypercall.
2) Make the currentflask_op()be common, and require new hypercalls to fit compatibly with xen_flask_op_t. This can be done fairly easily by subdividing the .cmd space.In this patch, we implement option 2.
Quoted 7 lines
Move the stub {do,compat}_xsm_op() implementation into a new
xsm_op.cso we can more easily do multi-inclusion compat magic. Also add a newprivate.h, because flask/hook.c's local declaration of {do,compat}_flask_op() wasn't remotely safe.The top level now dispatches into {do,compat}_flask_op() based on op.cmd, and handles the primary copy in/out.
I'm not convinced this is the only reasonable way of implementing 2). I could also see number space to be separated in different ways, ...
Quoted 11 lines
Signed-off-by Andrew Cooper <[email protected]>---
CC: Daniel De Graaf <[email protected]>
CC: Daniel Smith <[email protected]>Only lightly tested. Slightly RFC. There are several things which aren't great, but probably want addressing in due course.
1) The public headers probably want to lose the flask name (in a compatible way), now that the hypercall is common. This probably wants to be combined with no longer taking a void handle.
... leaving per-module public headers and perhaps merely adding an abstracting
struct
xen_xsm_op_t{
uint32_top;
... /* placeholder */
};or (making explicit one possible variant of number space splitting)
union
xen_xsm_op_t{
uint32_top;
struct {
uint16_tcmd;
uint16_tmod;
} u;
... /* placeholder */
};Quoted 1 line
in, say, a new
public/xsm.h.That doesn't work. The ABI is fixed at
sizeof(xen_flask_op_t)for all other modules, because a caller which doesn't know which module is in use must not have Xen over-read/write the object passed while it's trying to figure things out.Quoted 3 lines
As a result I consider this change either going too far (because of not knowing future needs) or not far enough (by e.g. leaving
do_xsm_op()to usexen_flask_op_t.Well - what it does is prevent someone from breaking the ABI with literally this patch
xen/xsm/silo.c +5
-0@@ -100,6 +100,11 @@ static int silo_argo_send(const struct domain *d1, const struct domain *d2) #endif +static long silo_do_xsm_op (XEN_GUEST_HANDLE_PARAM (void ) op) +{ + /* ... */ +} + static const struct xsm_ops __initconstrel silo_xsm_ops = { .evtchn_unbound = silo_evtchn_unbound,.evtchn_interdomain =
silo_evtchn_interdomain,xen/xsm/silo.c +1
-0@@ -110,6 +115,7 @@ static const struct xsm_ops __initconstrel silo_xsm_ops = { .argo_register_single_source = silo_argo_register_single_source, .argo_send = silo_argo_send, #endif + .do_xsm_op = silo_do_xsm_op, };const struct
xsm_ops*__initsilo_init(void)This is a damage limitation patch, but without knowing how the next module is going to want to do hypercalls differently, it is rather hard to judge what is appropriate. I certainly didn't waste much time thinking about it.
Quoted 10 lines
Quoted 6 lines
2) {do,compat}_xsm_op() are currently identical other than the dispatched-to functions because the size of
xsm_flask_op_tis invariant with COMPAT-ness. We could simplfy things by only having one, and dispatching to {do,compat}_*_op() directly, but I'm not sure whether the complexity is worth it.Perhaps not, I would say, not the least because (as said above) I think we shouldn't put in place restrictions which may get in the way of adding some future module.
Quoted 8 lines
Extending struct
xen_flask_opto become a generic XSM interface structure (or even just for Flask's own purposes) also is not as straightforward as it might seem: There's currently no provision for sub-structs which would grow the overall size of the structure:
The copy_{to,from}_guest() invocations for existing sub-ops may not copy more that the present worth ofsizeof(struct xen_flask_op). Yet your implementation ofdo_xsm_op()moves this deficiency from Flask to XSM.Deficiency yes, but necessary to avoid breaking the ABI for caller which doesn't know which module is in use. This cannot be fixed without swapping to approach 1.
Quoted 6 lines
Quoted 2 lines
3) Bloat-o-meter says these changes add 16 extra bytes to
dm_op()and I can't figure out what could possibly be causing this.Without comparing the object files in closer detail it's guesswork, but might this be register scheduling differences resulting from the changed
sizeof(struct xsm_ops)? I've been observing similar seemingly unmotivated changes to generated code ...The only thing it can plausibly be is a knock-on effect from the structure of
xsm_opschanging.Normally, I wouldn't be to surprised to see some displacement fields dropping from 4 to 1 byte as
xsm_opsis getting smaller, but everything is alt_call()'d up so should be a 7-bytecall *disp32(%rip).Quoted 10 lines
Quoted 6 lines
xen/xsm/flask/flask_op.c +0
-0@@ -22,6 +22,8 @@ #include <objsec.h> #include <conditional.h>+#include "
../private.h"Kind of odd: I'd expect a file named such to not get included across directory levels, unless a single component was split in such a way (to me Flask and XSM core are separate, yet still related components).
Quoted 3 lines
Its all a tangled mess because logically separating XSM and Flask was a task done when SILO was introduced.
There is not an appropriately located file (under xen/xsm/ ) where the prototypes could reasonably live, and this felt like the lesser of the available evils.
I guess it is worth adding, so we're all on the same page.
The thing I actually need to do is fix the fact that the prototypes for {do,compat}_flask_op() are local in xen/xsm/flask/hooks.c and not in a header shared with xen/xsm/flask/flask_op.c.
The thing I wanted to do is stop it being so trivially easy to break the ABI with a 5-line patch.
Any bikeshedding beyond that can happen in due course.
~Andrew
Re: [PATCH 5/5] xen/xsm: Address hypercall ABI problems
Quoted 21 lines · Andrew Cooper
Quoted 13 lines · Andrew Cooper
Quoted 11 lines · Jan Beulich
Quoted 6 lines · Andrew Cooper
xen/xsm/flask/flask_op.c +0
-0@@ -22,6 +22,8 @@ #include <objsec.h> #include <conditional.h>+#include "
../private.h"Kind of odd: I'd expect a file named such to not get included across directory levels, unless a single component was split in such a way (to me Flask and XSM core are separate, yet still related components).
Quoted 6 lines
Its all a tangled mess because logically separating XSM and Flask was a task done when SILO was introduced.
There is not an appropriately located file (under xen/xsm/ ) where the prototypes could reasonably live, and this felt like the lesser of the available evils.
Quoted 5 lines
I guess it is worth adding, so we're all on the same page.
The thing I actually need to do is fix the fact that the prototypes for {do,compat}_flask_op() are local in
xen/xsm/flask/hooks.cand not in a header shared withxen/xsm/flask/flask_op.c.
And I fully agree we need to do so. Me saying "kind of odd" also wasn't meant as an objection, just to express my surprise to see something like this.
Jan
Re: [PATCH 5/5] xen/xsm: Address hypercall ABI problems
In reply to Andrew CooperQuoted 56 lines · Andrew Cooper
Quoted 55 lines · Jan Beulich
Quoted 14 lines · Andrew Cooper
Currently,
__HYPERVISOR_xsm_openters xsm_ops.do_{xsm,compat}_op() which means that if any other XSM module registers a handler, we'll break the hypercall ABI totally by having the behaviour depend on the selected XSM module.There are 2 options:
1) Rename__HYPERVISOR_xsm_opto__HYPERVISOR_flask_op. If another XSM module wants hypercalls, they'll have to introduce a new top-level hypercall.
2) Make the currentflask_op()be common, and require new hypercalls to fit compatibly withxen_flask_op_t. This can be done fairly easily by subdividing the .cmd space.In this patch, we implement option 2.
Quoted 7 lines
Move the stub {do,compat}_xsm_op() implementation into a new
xsm_op.cso we can more easily do multi-inclusion compat magic. Also add a newprivate.h, because flask/hook.c's local declaration of {do,compat}_flask_op() wasn't remotely safe.The top level now dispatches into {do,compat}_flask_op() based on op.cmd, and handles the primary copy in/out.
I'm not convinced this is the only reasonable way of implementing 2). I could also see number space to be separated in different ways, ...
Quoted 11 lines
Signed-off-by Andrew Cooper <[email protected]>---
CC: Daniel De Graaf <[email protected]>
CC: Daniel Smith <[email protected]>Only lightly tested. Slightly RFC. There are several things which aren't great, but probably want addressing in due course.
1) The public headers probably want to lose the flask name (in a compatible way), now that the hypercall is common. This probably wants to be combined with no longer taking a void handle.
... leaving per-module public headers and perhaps merely adding an abstracting
struct xen_xsm_op_t { uint32_t op; ... /* placeholder */ };or (making explicit one possible variant of number space splitting)
union xen_xsm_op_t { uint32_t op; struct { uint16_t cmd; uint16_t mod; } u; ... /* placeholder */ };
Quoted 6 lines
Quoted 1 line
in, say, a new
public/xsm.h.That doesn't work. The ABI is fixed at
sizeof(xen_flask_op_t)for all other modules, because a caller which doesn't know which module is in use must not have Xen over-read/write the object passed while it's trying to figure things out.
Well, imo figuring out which module is in use should be via a sysctl. Then there would be no restrictions by one module's interface definitions on other modules.
Quoted 32 lines
Quoted 3 lines
As a result I consider this change either going too far (because of not knowing future needs) or not far enough (by e.g. leaving
do_xsm_op()to usexen_flask_op_t.Well - what it does is prevent someone from breaking the ABI with literally this patch
xen/xsm/silo.c +5
-0@@ -100,6 +100,11 @@ static int silo_argo_send(const struct domain *d1, const struct domain *d2) #endif +static long silo_do_xsm_op (XEN_GUEST_HANDLE_PARAM (void ) op) +{ + /* ... */ +} + static const struct xsm_ops __initconstrel silo_xsm_ops = { .evtchn_unbound = silo_evtchn_unbound,.evtchn_interdomain =
silo_evtchn_interdomain,xen/xsm/silo.c +1
-0@@ -110,6 +115,7 @@ static const struct xsm_ops __initconstrel silo_xsm_ops = { .argo_register_single_source = silo_argo_register_single_source, .argo_send = silo_argo_send, #endif + .do_xsm_op = silo_do_xsm_op, };
Quoted 1 line
const struct
xsm_ops*__initsilo_init(void)
So I'm afraid I don't see any ABI breakage here. Provided of course silo_do_xsm_op() avoids the FLASK_* number space and uses a struct layout compatible with the head of struct xen_flask_op.
Jan