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

[PATCH v7 00/50] ASI: HVM through PH1



This is the first part of a series to implement address space
isolation.

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.

Two key differences in v7:

- X1-4, which move vCPU state out of the xenheap and into a per-vCPU
  state area, are now at the front.  While these are necessary for
  ASI, they're also just general clean-up patches moving things out of
  the xenheap, and should be considered for commit even without the
  rest of the series.

- Include PH1 at the end, the first set of preparatory patches for
  having per-pCPU stack mappings.

The full series can be roughly divided as below:

Included in this version:

- X1 (01-07): 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 (08-11): Move every vCPU's saved register frame (PV and HVM), and
  the HVM emulator's operand caches, into the vCPU state window.  11
  also clears the vCPU's copy of an emulated I/O request once it has
  been consumed.

- X3 (12-14): 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 (15-21): Move the guest XSAVE areas into the vCPU state window.

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

- DV (31-39): 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 (40-50), new in this version: Preparation for per-pCPU stacks,
  modifying rendezvous and call-function IPIs to not use the stack.

Implemented but not yet posted:

- PH2: Moving pCPU stacks into the perdomain area, allocating them
  from the domheap

- O: A number of optimizations to improve performance

The functionality of 01-39 (v6's, through X4) is the bare minimum that
XenServer needs to make it into 4.23.

v6 can be found here:

https://lore.kernel.org/xen-devel/20261103-asi-hvm-v6-0-59dbc5ce9615@xxxxxxxxxxxxxx/

v7 is based on staging 5b28c0efc1d5.  v6's 01-04 are in staging
(61c1d7aafc47, af8ab775f391, d4f928aaa320, 6d59811c3eee), as are v6's
15, "xen/gunzip: process pending softirqs once per deflate block"
(aa0b5c26fe88), and 22, "xen/xmalloc: return an emptied region after
dropping the pool lock" (e33b6d11fe79).  With the new order, v6's
24-44 are v7's 01-21, v6's 05-13 are 22-30, and v6's 14, 16-21 and 23
are 31, 32-37 and 39.

Changes in v7:

- X1-X4 come first.  As they apply to staging without VH or DV, they
  no longer assume per-vCPU page-tables or the sparse directmap:
  create_perdomain_mapping() is given the domain until 22 converts its
  callers, the map_domain_pages() slot bitmap is a field of struct
  arch_vcpu, and messages and comments describe the domain-wide area.
  22, 25, 27 and 30 are ported over them.  Each patch's changelog has
  the details.

- Following Jan's review of v6's 25, the vCPU state window's AMD- and
  Intel-specific slots share the same pages, and the slots are in
  patch order (02, 09, 10 and 21).

- Following Jan's review of v6's 28, svm_vmcb_dump() is now passed the
  vCPU, so that it maps the VMCB itself and still prints its physical
  address: 05, "x86/svm: Pass struct vcpu to svm_vmcb_dump()".

- 07 is retitled "x86/vmx: move the guest MSR load/save list off the
  xenheap": on its own, the move takes the list off the xenheap; the
  directmap still maps the domain-heap page.

- The vmap-strict sub-option of asi= is split out of
  "x86/domain_page: introduce map_domain_pages()" (12) into a patch of
  its own, 38, after the sparse directmap view's sub-option (37).

- 35, "x86/domain_page: clear a mapcache slot at its last unmap": the
  two INVLPGs at a per-vCPU mapcache slot's last unmap are replaced by
  a mark on the CPU, and a CR3 reload when it is set, as the last step
  before the next VM entry and at a lazy switch to idle.  This reverses
  Roger's request for v4, and takes the first of the alternatives he
  named on v3 15/18.  On an Intel box the INVLPGs cost a PVH guest's
  yield ping-pong 1.81 us a round trip, the flush 0.24 us; a port read
  that QEMU answers, 4,537 ns and 339 ns.

- PH1 (40-50) is new.

Some more details:

11 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.

15-18 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 21'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.  45 adds by-value payloads
for call-function IPIs, which 47-49 use, and 50 asserts that a payload
passed by pointer is not on the stack.

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 v7, on the series as posted (staging 5b28c0efc1d5):

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

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

- QEMU (TCG) smoke boots at 21 and 50: PV and PVH dom0s (the PVH one
  on HAP and on shadow), and XTF's 32-bit PV and 32-bit HVM selftests
  as dom0; at 50 without asi= and with asi=1 (asi= arrives with 23).
  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 50 without asi= and 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; with asi=1, XTF's full suite, 32-bit PV included, passes twice
  (the usual four skips).

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

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

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

Extending the intra-domain isolation to PV guests would involve
implementing per-vCPU root pagetables for PV guests.  There are draft
implementations of this, but they are quite complicated.

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 (39):
  x86/mm: introduce a per-vCPU state window in the perdomain area
  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

Roger Pau Monné (7):
  x86/mm: introduce populate_perdomain_mapping()
  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           |  57 +++
 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               |  11 +-
 xen/arch/x86/cpu/microcode/core.c           |   7 +-
 xen/arch/x86/cpu/mtrr/main.c                |  11 +-
 xen/arch/x86/domain.c                       | 235 ++++++++--
 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                  | 153 +++++--
 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           |  45 +-
 xen/arch/x86/include/asm/domain.h           | 111 ++++-
 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               |  29 +-
 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/mm.c                           | 430 ++++++++++++++++--
 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                        |   4 +
 xen/arch/x86/shutdown.c                     |   4 +-
 xen/arch/x86/smp.c                          |  10 +-
 xen/arch/x86/sparse-directmap.c             | 455 +++++++++++++++++++
 xen/arch/x86/spec_ctrl.c                    | 183 +++++++-
 xen/arch/x86/sysctl.c                       |   3 +-
 xen/arch/x86/time.c                         |  11 +-
 xen/arch/x86/traps.c                        |  20 +-
 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/page_alloc.c                     |  51 ++-
 xen/common/smp.c                            |  95 +++-
 xen/common/stop_machine.c                   |   6 +
 xen/include/xen/domain_page.h               |  21 +
 xen/include/xen/mm.h                        |  40 ++
 xen/include/xen/smp.h                       |  82 +++-
 63 files changed, 3365 insertions(+), 617 deletions(-)
 create mode 100644 xen/arch/x86/include/asm/sparse-directmap.h
 create mode 100644 xen/arch/x86/sparse-directmap.c


base-commit: 5b28c0efc1d5d73ce651ca651e103c45b6932f9d
-- 
2.56.0




 


Rackspace

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