[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v8 55/65] x86/spec-ctrl: keep cpu-stack off while XPTI is enabled



XPTI gives each pCPU a root page-table of its own, which the pCPU runs
on while a 64-bit PV guest using XPTI is in context.  It maps the pCPU's
stack, cloned at its directmap address: the entry paths read the
stack's cpu_info block before they switch to the full page-tables, so
the stack must be mapped at the address the pCPU runs on in both.

Per-CPU stacks, as the cpu-stack option describes them, move every
pCPU onto a stack at an address of its own.  Giving XPTI's root
page-tables their own mapping of the stack there is left for a later
change.  Until then, keep cpu-stack off, for every domain kind, while
XPTI is enabled for the hardware domain or for other PV domains, by
default or explicitly, and say so in the boot log.

XPTI's own handling is unchanged: with cpu-stack off its root clones
the stack's directmap alias, as before.

Assisted-by: 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):
- New.
---
 docs/misc/xen-command-line.pandoc |  5 ++++-
 xen/arch/x86/spec_ctrl.c          | 17 +++++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/docs/misc/xen-command-line.pandoc 
b/docs/misc/xen-command-line.pandoc
index 4404d70661..1941d790dd 100644
--- a/docs/misc/xen-command-line.pandoc
+++ b/docs/misc/xen-command-line.pandoc
@@ -238,7 +238,9 @@ are meant to be used for debugging purposes only.**
   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.
+  latter disables the former, whichever comes last.  It is disabled, with
+  a boot-log warning, while XPTI is enabled for the hardware domain or for
+  PV domains (see `xpti`), by default or explicitly.
 
 * `directmap` (only available when Xen is built with
   `CONFIG_SPARSE_DIRECTMAP`) runs guest contexts on a sparse view of the
@@ -3166,6 +3168,7 @@ other for a PV domain.  Enabled explicitly, as a whole or 
with `dom0` or
 `domu`, XPTI keeps the PV domains it covers off the sparse view, and the boot
 log says so.  Left to its default, XPTI is disabled for the PV domains using
 the sparse view, with a boot-log warning where it would otherwise be enabled.
+While XPTI is enabled, for `dom0` or `domu`, `asi=cpu-stack` is disabled.
 
 ### xsave (x86)
 > `= <boolean>`
diff --git a/xen/arch/x86/spec_ctrl.c b/xen/arch/x86/spec_ctrl.c
index 474ce8b026..feb46b5826 100644
--- a/xen/arch/x86/spec_ctrl.c
+++ b/xen/arch/x86/spec_ctrl.c
@@ -2422,6 +2422,23 @@ void __init init_speculation_mitigations(void)
 
     xpti_init_default();
 
+    /*
+     * XPTI's per-CPU root page-table, on which a CPU runs while a PV guest
+     * using XPTI is in context, maps the CPU's stack at its directmap
+     * address.  Per-CPU stacks run each CPU on its stack at an address of
+     * its own; until XPTI's root page-table is given its own mapping of the
+     * stack there, they stay off while XPTI is enabled, for the hardware
+     * domain or for other PV domains, wherever they would be in use: for
+     * HVM domains, a PVH hardware domain included.
+     */
+    if ( IS_ENABLED(CONFIG_PV) && IS_ENABLED(CONFIG_HVM) &&
+         (opt_xpti_hwdom || opt_xpti_domu) &&
+         (opt_cpu_stack_hvm || (opt_dom0_pvh && opt_pvh_cpu_stack_hwdom)) )
+    {
+        printk(XENLOG_WARNING "XPTI enabled, disabling cpu-stack\n");
+        opt_cpu_stack_hvm = opt_pvh_cpu_stack_hwdom = false;
+    }
+
     l1tf_calculations();
 
     /*
-- 
2.56.0




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.