|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH v8 54/65] x86/spec-ctrl: add the cpu-stack sub-option of asi=
From: Roger Pau Monne <roger.pau@xxxxxxxxxx>
A pCPU's hypervisor stack holds the register frame, and working copies
of data, of the vCPU running there. Every context maps every stack
today: stacks are xenheap pages, reached at their directmap address.
Under Address Space Isolation, a vCPU of a vCPU-PT domain is to have
page-tables which map the stack of the pCPU it runs on, and no other.
Introduce the option for that, cpu-stack, ahead of the mechanism, as
the asi= option itself was introduced ahead of vCPU-PT. It is set by
the whole-feature forms, and by hvm= and dom0=, wherever they set
vcpu-pt, and on its own by cpu-stack=<bool> and cpu-stack=hvm=<bool>.
Like vcpu-pt it applies to HVM domains, a PVH hardware domain included,
and never to PV ones: a PV domain's per-domain area is shared by all
its vCPUs, which run on several pCPUs at once, so it cannot map the
stack of one pCPU only.
The stack mapping is to live in the vCPU's own per-domain area, so
cpu-stack relies on vcpu-pt. Enabling cpu-stack enables vcpu-pt as
well, and disabling vcpu-pt disables cpu-stack, the later setting
winning, so that the existing forms keep their meaning: asi=1,vcpu-pt=0
still leaves HVM domains without vCPU-PT. The boot log lists CPU-STACK
beside vCPU-PT.
The existing forms keep their effect, and nothing but the boot log reads
the new knobs yet.
Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
Assisted-by: Claude Code:claude-fable-5, Claude Code:claude-opus-4-8, Claude
Code:claude-opus-5-5
Signed-off-by: George Dunlap <gwd@xxxxxxxxxxxxxx>
---
Changes in v8:
- New in this version.
Changes since previously posted version ("x86: adventures in Address Space
Isolation", v2):
- Split out of "x86/mm: switch to a per-CPU mapped stack when using
ASI": the option on its own, ahead of the mechanism.
- HVM only: knobs for HVM guests and the hardware domain (used for a
PVH one); no pv= effect, no PV knob, no XPTI interaction here.
- Plain static booleans, without the late -1 resolution.
- vcpu-pt and cpu-stack imply each other as each is parsed, rather
than cpu-stack re-enabling vcpu-pt after the whole command line, so
that a later vcpu-pt=0 is not overridden.
- Docs, and the knobs' comment: the selected vCPUs' page-tables map no
other CPU's stack at the per-CPU addresses. v2's bullet said there
were no such mappings at all, which is untrue wherever the full
directmap is loaded.
---
docs/misc/xen-command-line.pandoc | 21 +++++++----
xen/arch/x86/spec_ctrl.c | 59 ++++++++++++++++++++++++++++---
2 files changed, 69 insertions(+), 11 deletions(-)
diff --git a/docs/misc/xen-command-line.pandoc
b/docs/misc/xen-command-line.pandoc
index 52e10eb393..4404d70661 100644
--- a/docs/misc/xen-command-line.pandoc
+++ b/docs/misc/xen-command-line.pandoc
@@ -204,7 +204,7 @@ to appropriate auditing by Xen. Argo is disabled by
default.
### asi (x86)
> `= List of [ <bool>, {pv,hvm,dom0}=<bool>, {directmap,vmap-strict}=<bool>,
-> vcpu-pt=<bool> | vcpu-pt=hvm=<bool> ]`
+> {vcpu-pt,cpu-stack}=<bool> | {vcpu-pt,cpu-stack}=hvm=<bool> ]`
> Default: `false`
@@ -215,16 +215,16 @@ mitigations for certain speculative related attacks, at
the cost of mapping
sensitive information on-demand. It might also offer some protection against
unmitigated speculation-related attacks.
-The mechanisms currently implemented are `vcpu-pt`, for HVM domains including
-a PVH hardware domain, and `directmap`, for all domains including the hardware
-domain, PV or PVH. The plain boolean enables or disables both, wherever they
-apply.
+The mechanisms currently implemented are `vcpu-pt` and `cpu-stack`, for HVM
+domains including a PVH hardware domain, and `directmap`, for all domains
+including the hardware domain, PV or PVH. The plain boolean enables or
+disables all three, wherever they apply.
* `pv=`, `hvm=` and `dom0=` enable the features for PV domains or HVM domains
other than the hardware domain, or for the hardware domain, PV or PVH. The
plain boolean does all three: `asi=1,dom0=0` leaves the hardware domain
- out. The forms naming no domain type (an un-suffixed `vcpu-pt=<bool>`, and
- `directmap=<bool>`) cover the hardware domain too.
+ out. The forms naming no domain type (un-suffixed `vcpu-pt=<bool>` and
+ `cpu-stack=<bool>`, and `directmap=<bool>`) cover the hardware domain too.
**WARNING: manual de-selection of enabled options will invalidate any
protection offered by the feature. The fine grained options provided below
@@ -233,6 +233,13 @@ are meant to be used for debugging purposes only.**
* `vcpu-pt` gives each vCPU its own per-domain area: the per-domain slot of
each vCPU's monitor table maps a region private to that vCPU.
+* `cpu-stack` runs every CPU on a stack at an address of its own, and
+ gives each vCPU of the selected domains page-tables which map, at those
+ addresses, the stack of the CPU it runs on and no other; the page-tables
+ of all other contexts map every CPU's stack there. `cpu-stack` relies
+ on `vcpu-pt`: enabling the former enables the latter, and disabling the
+ latter disables the former, whichever comes last.
+
* `directmap` (only available when Xen is built with
`CONFIG_SPARSE_DIRECTMAP`) runs guest contexts on a sparse view of the
directmap, which maps the memory Xen needs to reach at all times (the Xen
diff --git a/xen/arch/x86/spec_ctrl.c b/xen/arch/x86/spec_ctrl.c
index 3a1755aba4..474ce8b026 100644
--- a/xen/arch/x86/spec_ctrl.c
+++ b/xen/arch/x86/spec_ctrl.c
@@ -93,6 +93,15 @@ bool __ro_after_init opt_vmap_strict;
bool __ro_after_init opt_vcpu_pt_hvm;
bool __ro_after_init opt_vcpu_pt_hwdom;
+/*
+ * Run every CPU on a stack at an address of its own, and give the vCPUs of a
+ * vCPU-PT domain page-tables which map, at those addresses, only the stack of
+ * the CPU they run on (cpu-stack), for HVM domains and a PVH hardware domain.
+ * Implies vCPU-PT.
+ */
+static bool __ro_after_init opt_cpu_stack_hvm;
+static bool __ro_after_init opt_pvh_cpu_stack_hwdom;
+
static int __init cf_check parse_spec_ctrl(const char *s)
{
const char *ss;
@@ -553,6 +562,7 @@ static int __init cf_check parse_asi(const char *s)
if ( *s == '\0' )
{
opt_vcpu_pt_hwdom = opt_vcpu_pt_hvm = true;
+ opt_pvh_cpu_stack_hwdom = opt_cpu_stack_hvm = true;
set_sparse_dmap(true, true, true, true);
}
@@ -567,6 +577,7 @@ static int __init cf_check parse_asi(const char *s)
case 0:
case 1:
opt_vcpu_pt_hwdom = opt_vcpu_pt_hvm = val;
+ opt_pvh_cpu_stack_hwdom = opt_cpu_stack_hvm = val;
set_sparse_dmap(true, true, true, val);
break;
@@ -575,12 +586,12 @@ static int __init cf_check parse_asi(const char *s)
set_sparse_dmap(true, false, false, val);
else if ( (val = parse_boolean("hvm", s, ss)) >= 0 )
{
- opt_vcpu_pt_hvm = val;
+ opt_vcpu_pt_hvm = opt_cpu_stack_hvm = val;
set_sparse_dmap(false, true, false, val);
}
else if ( (val = parse_boolean("dom0", s, ss)) >= 0 )
{
- opt_vcpu_pt_hwdom = val;
+ opt_vcpu_pt_hwdom = opt_pvh_cpu_stack_hwdom = val;
set_sparse_dmap(false, false, true, val);
}
else if ( (val = parse_boolean("directmap", s, ss)) >= 0 )
@@ -603,6 +614,9 @@ static int __init cf_check parse_asi(const char *s)
case 1:
case 0:
opt_vcpu_pt_hwdom = opt_vcpu_pt_hvm = val;
+ /* No per-CPU stacks without vCPU-PT. */
+ if ( !val )
+ opt_pvh_cpu_stack_hwdom = opt_cpu_stack_hvm = false;
break;
case -2:
@@ -610,6 +624,39 @@ static int __init cf_check parse_asi(const char *s)
if ( (val = parse_boolean("hvm", s, ss)) >= 0 )
{
opt_vcpu_pt_hvm = val;
+ if ( !val )
+ opt_cpu_stack_hvm = false;
+ break;
+ }
+ fallthrough;
+ default:
+ rc = -EINVAL;
+ break;
+ }
+ }
+ else if ( (val = parse_boolean("cpu-stack", s, ss)) != -1 )
+ {
+ /*
+ * Per-CPU stacks rely on per-vCPU page-tables: enabling
+ * cpu-stack enables vcpu-pt as well, as disabling vcpu-pt
+ * (above) disables cpu-stack. The later setting wins.
+ */
+ switch ( val )
+ {
+ case 1:
+ opt_vcpu_pt_hwdom = opt_vcpu_pt_hvm = true;
+ fallthrough;
+ case 0:
+ opt_pvh_cpu_stack_hwdom = opt_cpu_stack_hvm = val;
+ break;
+
+ case -2:
+ s += strlen("cpu-stack=");
+ if ( (val = parse_boolean("hvm", s, ss)) >= 0 )
+ {
+ opt_cpu_stack_hvm = val;
+ if ( val )
+ opt_vcpu_pt_hvm = true;
break;
}
fallthrough;
@@ -832,14 +879,18 @@ static void __init print_details(enum ind_thunk thunk)
printk(" ASI directmap mode: %s\n",
sparse_dmap_configured() ? "sparse" : "full");
- printk(" ASI features for Dom0:%s%s%s\n",
+ printk(" ASI features for Dom0:%s%s%s%s\n",
hwdom_pt || hwdom_sd ? "" : " None",
hwdom_pt ? " vCPU-PT" : "",
+ hwdom_pt && opt_pvh_cpu_stack_hwdom
+ ? " CPU-STACK" : "",
hwdom_sd ? " sparse-directmap" : "");
if ( IS_ENABLED(CONFIG_HVM) )
- printk(" ASI features for HVM VMs:%s%s%s\n",
+ printk(" ASI features for HVM VMs:%s%s%s%s\n",
opt_vcpu_pt_hvm ? "" : " None",
opt_vcpu_pt_hvm ? " vCPU-PT" : "",
+ opt_vcpu_pt_hvm && opt_cpu_stack_hvm
+ ? " CPU-STACK" : "",
opt_vcpu_pt_hvm && sparse_dmap_hvm()
? " sparse-directmap" : "");
if ( IS_ENABLED(CONFIG_PV) )
--
2.56.0
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |