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

[PATCH v8 00/65] ASI: HVM, functionally complete



This is a functionally complete series to implement address space
isolation.  It does not include any low-hanging optimizations.

The approach is the same since v3: Start by focusing on just getting
ASI and intra-domain isolation for HVM guests.  PV support is added
where it's simple to do.

The main difference in v8:

  Two patches from v7 have been checked in, and comments on 3/ have
  been addressed.

  Include PH2, allowing HVM domains with per-vCPU areas to map only
  the stack of the pCPU on which they're running.

Included in this version:

  Additional safety precautions for a previously posted patch (01).

- X1 (02-06): Add a vCPU state window to the per-domain area (both for
  PV and HVM).  Move SVM VMCB structures and VMX guest MSR areas into
  it.

- X2 (07-10): Move every vCPU's saved register frame (PV and HVM), and
  the HVM emulator's operand caches, into the vCPU state window.  10
  also clears the vCPU's copy of an emulated I/O request once it has
  been consumed.

- X3 (11-13): Introduce map_domain_pages(), which maps several pages
  in the calling vCPU's per-domain area, and use it in place of vmap()
  for the shadow code's cross-page emulated writes and the HVM
  emulator's multi-frame accesses.

- X4 (14-20): Move the guest XSAVE areas into the vCPU state window.

- VH (21-29): Give each vCPU of an HVM guest its own per-domain area
  and its own mapcache.

- DV (30-38): Maintain two "views" of the directmap: A full directmap,
  and a sparse directmap.  The full directmap is what we have now; the
  sparse directmap removes non-xenheap heap memory.

- PH1 (39-49): Preparation for per-pCPU stacks,
  modifying rendezvous and call-function IPIs to not use the stack.

- PH2 (50-65), new in this version: Moving pCPU stacks into the
  perdomain area, allocating them from the domheap

Implemented but not yet posted:

- O: A number of optimizations to improve performance

The functionality of 01-38 (X, VH, and DV) is the bare minimum that
XenServer needs to make it into 4.23.

v7 can be found here:

https://lore.kernel.org/xen-devel/20261119-asi-hvm-v7-0-6551b6d5c879@xxxxxxxxxxxxxx/

v8 is based on staging 091d3c200281.  v7's 01-02 are in staging
(9f9e2532c20d, ff9c79ec370c); v7's 03-50 are v8's 02-49.

Changes in v8:

- 01 is new, after Andrew's reply to v7's 01:
  populate_perdomain_mapping() asserts that _PAGE_AVAIL0 is clear in the
  flags it is given, and masks it out.

- Following Jan's review of v7's 03: 02 asserts v == current in
  svm_guest_x86_mode(), gives svm_set_tsc_offset() one exit path, and
  maps the VMCB through pointers-to-const where it only reads it; 04
  maps it through a pointer-to-const too.

- "No functional change" is gone from four messages: 07 and 33 drop it,
  18 says that the new error paths cannot be taken yet, and 44 says what
  does change (the smp_rmb() on Arm).

- PH2 (50-65) is new.

Some more details:

10 also limits exposure of ioreq state: Completely isolating each
vCPU's I/O requests from being read by other vCPUs of the same domain
is complicated; as a mitigation, this patch clears the emulated I/O
request once it has been consumed, reducing the window available to
read the payload.

14-17 are Alejandro's patches from "x86: Address Space Isolation FPU
preparations" (v3, January 2025), revived.

State is moved from the xenheap into the per-domain area for both ASI
and non-ASI domains: VMCB, MSR List, vCPU register frame, and
XSAVE/FPU areas.  Same is true for users of map_domain_pages.  This
protects non-ASI domains from ASI domains.

One key thing to get feedback on, still open from v6, is the question
below 20's "---": xstate_init() now panics on hardware whose XSAVE
area needs more than the three pages reserved for it in the vCPU state
window.  No current hardware does.  Should it do more, for instance
size the reservation from the size found at boot, or fall back to
xenheap areas on such hardware?

In PH1, the data that rendezvous and call-function IPIs hand to other
CPUs moves off the initiating CPU's stack.  44 adds by-value payloads
for call-function IPIs, which 46-48 use, and 49 asserts that a payload
passed by pointer is not on the stack.

In PH2, with the new cpu-stack sub-option of asi= (54), each pCPU's
stack is mapped at an address of its own in the per-domain area, and
the pCPU runs on it there (58-59); an HVM vCPU's page-tables then map
only the stack of the pCPU it runs on (60), and the stacks come from
the domain heap, which the sparse directmap does not map (61).  62
zeroes the stack on context switch.  54, 56-59 and 62 are Roger's, from
"x86: adventures in Address Space Isolation" (v2, January 2025),
reworked HVM-first; their changelogs say what changed since.  50 fixes
a bug in staging under FRED and applies on its own; 63-65 add checks
that could be dropped.

Note that at the end of this series, PV guests can be given the sparse
directmap; this isolates them from other domains, but doesn't isolate
vCPUs within a domain.  With this series, a PV domain's register
frames and XSAVE areas are also out of reach of domains on the sparse
directmap, whether or not the PV domain itself is on it.

Testing of v8, on the series as posted (staging 091d3c200281):

- Builds of xen/ at each of the 65 patches, in seven configurations:
  debug and release, !HVM, !PV, the PV shim, and shadow paging, debug
  and release; from 32, which adds CONFIG_SPARSE_DIRECTMAP, also with
  it, debug and release.  No warnings or errors beyond those staging
  itself gives.  arm64 builds of 65, debug and release.

- On an Intel NUC: whole-tree builds (xen, tools, stubdom, docs) at
  each of the 65, with tools/tests/vpci run.

- QEMU (TCG) boots at each of the 65: PV dom0s without asi=, with
  asi=1, with asi=1,dom0=0 and with xpti=1; PVH dom0s without asi=,
  with asi=1 and with asi=1,dom0=0, on HAP and on shadow; and XTF's
  32-bit PV and 32-bit HVM selftests as dom0 (asi= arrives with 22).
  Each boot gets to dom0's userspace (or the test's result) with no
  crash, assertion or WARN() in Xen's log.

- On the NUC: boots of 65 with asi=1.  In each, a 64-bit PV guest is
  live-migrated to the same host in shadow log-dirty mode under a
  verified workload, with an HVM guest beside it, and XTF's full suite,
  32-bit PV included, passes twice (the usual four skips).

- GitLab CI
  https://gitlab.com/xen-project/hardware/xen-staging/-/pipelines/3142304689

A dependency graph of the above functionality can be found here:

https://xenbits.xenproject.org/people/gdunlap/asi-series-deps.html

Alejandro Vallejo (4):
  x86/emulator: Refactor FXSAVE_AREA to use wrappers
  x86/mpx: Map/unmap xsave area in read_bndcfgu()
  x86/fpu: Pass explicit xsave areas to fpu_(f)xsave()
  x86/fpu: Pass explicit xsave areas to fpu_(f)xrstor()

George Dunlap (49):
  x86/mm: mask _PAGE_AVAIL0 out of populate_perdomain_mapping()'s flags
  x86/svm: introduce SVM_MAP_VMCB() and SVM_UNMAP_VMCB()
  x86/svm: restore guest debug registers in svm_do_resume()
  x86/svm: Pass struct vcpu to svm_vmcb_dump()
  x86/svm: allocate VMCBs from the domain heap behind the vCPU state
    window
  x86/vmx: move the guest MSR load/save list off the xenheap
  x86: access a vCPU's saved register frame through map/unmap helpers
  x86: move the saved register frame behind the vCPU state window
  x86/hvm: move the emulator's operand caches behind the vCPU state
    window
  x86/hvm: clear the vCPU's copy of an emulated I/O request once
    consumed
  x86/domain_page: introduce map_domain_pages()
  x86/shadow: use map_domain_pages() for cross-page emulated writes
  x86/hvm: use map_domain_pages() for multi-frame emulated accesses
  x86/xstate: classify xsave-area seam accesses by failure mode
  x86/domain: restore FPU state after switching to the new page tables
  x86/xstate: move guest XSAVE areas behind the vCPU state window
  x86/mm: have init_xen_l4_slots() take a vCPU in place of the domain
  x86/domain_page: drop redundant is_pv_vcpu() checks
  x86/domain_page: don't unmap a mapcache entry that is not present
  x86/mm: let Xen's page-table walker operate on a given root
  x86/mm: add hooks for a sparse view of the directmap
  x86/mm: build and maintain a sparse view of the directmap
  x86/domain_page: key the directmap fast paths on the loaded view
  x86/domain_page: clear a mapcache slot at its last unmap
  x86/mm: run guest contexts on the sparse directmap view
  x86/spec-ctrl: wire the sparse directmap view into the asi= option
  x86/spec-ctrl: add the vmap-strict sub-option of asi=
  x86/mm: split a sparse directmap superpage with a page being freed
  x86/mtrr: move the set_mtrr() rendezvous data off the stack
  x86/smp: move smp_send_stop()'s AP-stop flag off the stack
  x86/time: move the calibration rendezvous data off the stack
  x86/ucode: move the stop_machine payload off the stack
  x86/MCE: pass NULL to x86_mc_mceinject()
  xen/smp: introduce by-value payloads for call-function IPIs
  x86/cpufreq: move the CPU mask out of struct drv_cmd
  x86/acpi: pass stack-allocated callfunc payloads by value
  x86/mce: pass the error-injection callfunc payload by value
  x86: pass remaining stack-allocated callfunc payloads by value
  xen/smp: assert that by-pointer callfunc payloads are not on the stack
  x86/traps: refresh the BSP's rsp0 under FRED when its stack moves
  x86/traps: have show_stack_overflow() expect the stack the TSS names
  x86/smpboot: track per-CPU stack pages alongside stack_base
  x86: keep a per-CPU mirror of current for cross-CPU readers
  x86/spec-ctrl: keep cpu-stack off while XPTI is enabled
  x86/hvm: map only its own CPU's stack in a cpu-stack vCPU's
    page-tables
  x86/mm: allocate per-CPU stacks from the domain heap
  xen: assert that data handed to other CPUs is not on a CPU's stack
  x86/traps: name the CPU whose stack a fatal page fault hit
  xen/wait: crash the domain if the saved stack is not this CPU's

Roger Pau Monne (6):
  x86/spec-ctrl: add the cpu-stack sub-option of asi=
  x86/mm: write shadow stack tokens for the address the stack is used at
  x86/setup: allocate the BSP's stack after the speculation mitigations
  x86/mm: map each CPU's stack at a per-CPU address in the per-domain
    area
  x86/mm: run every CPU on a per-CPU stack address
  x86/mm: zero stack on context switch

Roger Pau Monné (6):
  x86/mm: prepare create_perdomain_mapping() for per-vCPU perdomain
    areas
  x86/spec-ctrl: introduce Address Space Isolation command line option
  x86/hvm: introduce per-vCPU L3 page-table
  x86/domain_page: prepare the mapcache for per-vCPU accounting
  x86/domain_page: move struct mapcache_vcpu to struct arch_vcpu
  x86/hvm: introduce per-vCPU mapcache for vCPU-PT domains

 docs/misc/xen-command-line.pandoc           |  80 +++
 tools/tests/vpci/emul.h                     |   2 +
 xen/arch/x86/Kconfig                        |   1 +
 xen/arch/x86/Makefile                       |   1 +
 xen/arch/x86/acpi/cpu_idle.c                |   3 +-
 xen/arch/x86/acpi/cpufreq/acpi.c            |  28 +-
 xen/arch/x86/acpi/cpufreq/cpufreq.c         |   4 +-
 xen/arch/x86/acpi/cpufreq/powernow.c        |   6 +-
 xen/arch/x86/acpi/lib.c                     |   3 +-
 xen/arch/x86/cpu/mcheck/mce.c               |  16 +-
 xen/arch/x86/cpu/microcode/core.c           |   7 +-
 xen/arch/x86/cpu/mtrr/main.c                |  11 +-
 xen/arch/x86/domain.c                       | 254 +++++--
 xen/arch/x86/domain_page.c                  | 475 ++++++++++---
 xen/arch/x86/domctl.c                       |  98 +--
 xen/arch/x86/flushtlb.c                     |   6 +
 xen/arch/x86/hvm/domain.c                   |   6 +-
 xen/arch/x86/hvm/emulate.c                  | 243 +++++--
 xen/arch/x86/hvm/hvm.c                      | 116 ++--
 xen/arch/x86/hvm/svm/nestedsvm.c            |  12 +-
 xen/arch/x86/hvm/svm/svm.c                  | 162 +++--
 xen/arch/x86/hvm/svm/vmcb.c                 |  81 ++-
 xen/arch/x86/hvm/svm/vmcb.h                 |  31 +-
 xen/arch/x86/hvm/vmx/vmcs.c                 | 151 ++++-
 xen/arch/x86/hvm/vmx/vmx.c                  |  10 +-
 xen/arch/x86/hypercall.c                    |   4 +-
 xen/arch/x86/i387.c                         |  60 +-
 xen/arch/x86/include/asm/config.h           |  40 +-
 xen/arch/x86/include/asm/current.h          |  77 ++-
 xen/arch/x86/include/asm/domain.h           | 129 +++-
 xen/arch/x86/include/asm/hvm/emulate.h      |   9 +-
 xen/arch/x86/include/asm/hvm/vcpu.h         |   7 +
 xen/arch/x86/include/asm/hvm/vmx/vmcs.h     |  63 +-
 xen/arch/x86/include/asm/i387.h             |   1 +
 xen/arch/x86/include/asm/mm.h               |  25 +-
 xen/arch/x86/include/asm/smp.h              |  51 +-
 xen/arch/x86/include/asm/sparse-directmap.h |  83 +++
 xen/arch/x86/include/asm/spec_ctrl.h        |   3 +
 xen/arch/x86/include/asm/xstate.h           |  73 +-
 xen/arch/x86/irq.c                          |   2 +
 xen/arch/x86/mm.c                           | 713 ++++++++++++++++++--
 xen/arch/x86/mm/hap/hap.c                   |   2 +-
 xen/arch/x86/mm/shadow/hvm.c                |   6 +-
 xen/arch/x86/mm/shadow/multi.c              |   5 +-
 xen/arch/x86/platform_hypercall.c           |   2 +-
 xen/arch/x86/psr.c                          |   2 +-
 xen/arch/x86/pv/dom0_build.c                |  11 +-
 xen/arch/x86/pv/domain.c                    |  20 +-
 xen/arch/x86/pv/shim.c                      |   4 +-
 xen/arch/x86/setup.c                        |  28 +-
 xen/arch/x86/shutdown.c                     |   4 +-
 xen/arch/x86/smp.c                          |  10 +-
 xen/arch/x86/smpboot.c                      | 104 ++-
 xen/arch/x86/sparse-directmap.c             | 455 +++++++++++++
 xen/arch/x86/spec_ctrl.c                    | 308 ++++++++-
 xen/arch/x86/sysctl.c                       |   3 +-
 xen/arch/x86/time.c                         |  11 +-
 xen/arch/x86/traps-setup.c                  |   3 +
 xen/arch/x86/traps.c                        |  78 ++-
 xen/arch/x86/x86_64/mm.c                    |  12 +-
 xen/arch/x86/x86_emulate/blk.c              |  36 +-
 xen/arch/x86/xstate.c                       | 212 +++++-
 xen/common/Kconfig                          |  18 +
 xen/common/notifier.c                       |   3 +
 xen/common/page_alloc.c                     |  51 +-
 xen/common/smp.c                            |  95 ++-
 xen/common/stop_machine.c                   |   6 +
 xen/common/tasklet.c                        |   3 +
 xen/common/timer.c                          |   4 +
 xen/common/wait.c                           |  25 +-
 xen/drivers/vpci/vpci.c                     |   2 +
 xen/include/xen/domain_page.h               |  21 +
 xen/include/xen/mm.h                        |  40 ++
 xen/include/xen/smp.h                       |  99 ++-
 74 files changed, 4144 insertions(+), 686 deletions(-)
 create mode 100644 xen/arch/x86/include/asm/sparse-directmap.h
 create mode 100644 xen/arch/x86/sparse-directmap.c


base-commit: 091d3c200281ea44846ccdf1e5d39985321c643e
-- 
2.56.0




 


Rackspace

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