x86/spec-ctrl: Bug / (mis)feature fixes
cover x86/spec-ctrl: Bug / (mis)feature fixes
Andrew Cooper (3):
x86/spec-ctrl: Honour spec-ctrl=0 for unpriv-mmio sub-option xen/cmdline: Extend parse_boolean() to signal a name match x86/spec-ctrl: Add fine-grained cmdline suboptions for primitives
docs/misc/xen-command-line.pandoc | 12 +++++-- xen/arch/x86/spec_ctrl.c | 67 +++++++++++++++++++++++++++++++++------ xen/common/kernel.c | 20 +++++++++--- xen/include/xen/lib.h | 3 +- 4 files changed, 85 insertions(+), 17 deletions(-)
Signature · 1 line
2.11.0
PATCH 1/3 x86/spec-ctrl: Honour spec-ctrl=0 for unpriv-mmio sub-option
This was an oversight from when unpriv-mmio was introduced.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
--- xen/arch/x86/spec_ctrl.c | 1 + 1 file changed, 1 insertion(+)
xen/arch/x86/spec_ctrl.c +1 -0
@@ -122,6 +122,7 @@ static int __init cf_check parse_spec_ctrl(const char *s) opt_l1d_flush =0 ; opt_branch_harden = false; opt_srb_lock =0 ; + opt_unpriv_mmio = false; }else if ( val >0 ) rc = -EINVAL ;
Signature · 1 line
2.11.0
Re: [PATCH 1/3] x86/spec-ctrl: Honour spec-ctrl=0 for unpriv-mmio sub-option
Quoted 4 lines · Andrew Cooper
This was an oversight from when unpriv-mmio was introduced.
Fixes 8c24b70fedcb ("x86/spec-ctrl: Add spec-ctrl=unpriv-mmio")Signed-off-by Andrew Cooper <[email protected]>
I'm not entirely certain in how far it wouldn't be useful to mention that "spec-ctrl=no-xen" is similarly corrected by this change.
Jan
PATCH 2/3 xen/cmdline: Extend parse_boolean() to signal a name match
In reply to Andrew CooperThis will help parsing a sub-option which has boolean and non-boolean options available.
First, rework 'int val' into 'bool has_neg_prefix'. This inverts it's value, but the resulting logic is far easier to follow.
Second, reject anything of the form 'no-$FOO=' which excludes ambiguous constructs such as 'no-$foo=yes' which have never been valid.
This just leaves the case where everything is otherwise fine, but parse_bool() can't interpret the provided string.
---
CC: George Dunlap <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Wei Liu <[email protected]>
CC: Julien Grall <[email protected]>
CC: Juergen Gross <[email protected]>
--- xen/common/kernel.c | 20 ++++++++++++++++---- xen/include/xen/lib.h | 3 ++- 2 files changed, 18 insertions(+), 5 deletions(-)
xen/common/kernel.c +16 -4
@@ -272,9 +272,9 @@ int parse_bool(const char *s, const char *e)int parse_boolean (const char *name,const char *s,const char *e) {size_t slen, nlen; -int val = !!strncmp (s,"no-" ,3 ); +bool has_neg_prefix = !strncmp (s,"no-" ,3 ); -if ( !val ) +if ( has_neg_prefix ) s +=3 ; slen = e ? ({ASSERT (e >= s); e - s; }) :strlen (s);
@@ -286,11 +286,23 @@ int parse_boolean(const char *name, const char *s, const char *e)/* Exact, unadorned name? Result depends on the 'no-' prefix. */ if ( slen == nlen ) -return val; +return !has_neg_prefix; + +/* Inexact match with a 'no-' prefix? Not valid. */ +if ( has_neg_prefix ) +return -1 ;/* =$SOMETHING? Defer to the regular boolean parsing. */ if ( s[nlen] =='=' ) -return parse_bool (&s[nlen +1 ], e); + { +int b =parse_bool (&s[nlen +1 ], e); + +if ( b >=0 ) +return b; + +/* Not a boolean, but the name matched. Signal specially. */ +return -2 ; + }/* Unrecognised. Give up. */ return -1 ;
xen/include/xen/lib.h +2 -1
@@ -89,7 +89,8 @@ int parse_bool(const char *s, const char *e);/** * Given a specific name, parses a string of the form: * [no-]$NAME[=...] -* returning 0 or 1 for a recognised boolean, or -1 for an error. +* returning 0 or 1 for a recognised boolean. Returns -1 for general errors, +* and -2 for "not a boolean, but $NAME= matches". */ int parse_boolean (const char *name,const char *s,const char *e);
Signature · 1 line
2.11.0
Re: [PATCH 2/3] xen/cmdline: Extend parse_boolean() to signal a name match
Quoted 6 lines · Andrew Cooper
This will help parsing a sub-option which has boolean and non-boolean options available.
First, rework 'int val' into 'bool
has_neg_prefix'. This inverts it's value, but the resulting logic is far easier to follow.
Quoted 7 lines
Second, reject anything of the form 'no-$FOO=' which excludes ambiguous constructs such as 'no-$foo=yes' which have never been valid.
This just leaves the case where everything is otherwise fine, but
parse_bool()can't interpret the provided string.Signed-off-by Andrew Cooper <[email protected]>
Juergen
Re: [PATCH 2/3] xen/cmdline: Extend parse_boolean() to signal a name match
In reply to Andrew CooperQuoted 6 lines · Andrew Cooper
This will help parsing a sub-option which has boolean and non-boolean options available.
First, rework 'int val' into 'bool
has_neg_prefix'. This inverts it's value, but the resulting logic is far easier to follow.
Quoted 7 lines
Second, reject anything of the form 'no-$FOO=' which excludes ambiguous constructs such as 'no-$foo=yes' which have never been valid.
This just leaves the case where everything is otherwise fine, but
parse_bool()can't interpret the provided string.Signed-off-by Andrew Cooper <[email protected]>
PATCH 3/3 x86/spec-ctrl: Add fine-grained cmdline suboptions for primitives
In reply to Andrew CooperSupport controling the PV/HVM suboption of msr-sc/rsb/md-clear, which previously wasn't possible.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
--- docs/misc/xen-command-line.pandoc | 12 +++++-- xen/arch/x86/spec_ctrl.c | 66 +++++++++++++++++++++++++++++++++------ 2 files changed, 66 insertions(+), 12 deletions(-)
docs/misc/xen-command-line.pandoc +9 -3
@@ -2257,7 +2257,8 @@ not be able to control the state of the mitigation. By default SSBD will be mitigated at runtime (i.e `ssbd=runtime`). ### spec-ctrl (x86) -> `= List of [ <bool>, xen=<bool>, {pv,hvm,msr-sc,rsb,md-clear}=<bool>, +> `= List of [ <bool>, xen=<bool>, {pv,hvm}=<bool>, +> {msr-sc,rsb,md-clear}=<bool>|{pv,hvm}=<bool>, > bti-thunk=retpoline|lfence|jmp, {ibrs,ibpb,ssbd,psfd, > eager-fpu,l1d-flush,branch-harden,srb-lock, > unpriv-mmio}=<bool> ]`
@@ -2282,12 +2283,17 @@ in place for guests to use. Use of a positive boolean value for either of these options is invalid. -The booleans `pv=`, `hvm=`, `msr-sc=`, `rsb=` and `md-clear=` offer fine +The `pv=`, `hvm=`, `msr-sc=`, `rsb=` and `md-clear=` options offer fine grained control over the primitives by Xen. These impact Xen's ability to -protect itself, and Xen's ability to virtualise support for guests to use. +protect itself, and/or Xen's ability to virtualise support for guests to use. * `pv=` and `hvm=` offer control over all suboptions for PV and HVM guests respectively. +* Each other option can be used either as a plain boolean + (e.g. `spec-ctrl=rsb` to control both the PV and HVM sub-options), or with + `pv=` or `hvm=` subsuboptions (e.g. `spec-ctrl=rsb=no-hvm` to disable HVM + RSB only). + * `msr-sc=` offers control over Xen's support for manipulating `MSR_SPEC_CTRL` on entry and exit. These blocks are necessary to virtualise support for guests and if disabled, guests will be unable to use IBRS/STIBP/SSBD/etc.
xen/arch/x86/spec_ctrl.c +57 -9
77 lines not on this page · raw message
Signature · 1 line
2.11.0
Re: [PATCH 3/3] x86/spec-ctrl: Add fine-grained cmdline suboptions for primitives
Quoted 4 lines · Andrew Cooper
Support controling the PV/HVM suboption of msr-sc/rsb/md-clear, which previously wasn't possible.
Signed-off-by Andrew Cooper <[email protected]>