mbox series

[v7,00/10] x86: Expose consistent topology to guests

Message ID 20241021154600.11745-1-alejandro.vallejo@cloud.com (mailing list archive)
Headers show
Series x86: Expose consistent topology to guests | expand

Message

Alejandro Vallejo Oct. 21, 2024, 3:45 p.m. UTC
Current topology handling is close to non-existent. As things stand, APIC IDs
are allocated through the apic_id=vcpu_id*2 relation without giving any hints
to the OS on how to parse the x2APIC ID of a given CPU and assuming the guest
will assume 2 threads per core.

This series involves bringing x2APIC IDs into the migration stream, so older
guests keep operating as they used to and enhancing Xen+toolstack so new guests
get topology information consistent with their x2APIC IDs. As a side effect of
this, x2APIC IDs are now packed and don't have (unless under a pathological
case) gaps.

Further work ought to allow combining this topology configurations with
gang-scheduling of guest hyperthreads into affine physical hyperthreads. For
the time being it purposefully keeps the configuration of "1 socket" + "1
thread per core" + "1 core per vCPU".

===

Other minor changes highlighted in each individual patch.

Hypervisor prerequisites:

  patch  1: lib/x86: Bump max basic leaf in {pv,hvm}_max_policy
    * Conceptually similar to v6/patch1 ("Relax checks about policy
      compatibility"), but operates on the max policies instead.
  patch  2: xen/x86: Add initial x2APIC ID to the per-vLAPIC save area
  patch  3: xen/x86: Add supporting code for uploading LAPIC contexts during
           domain create

hvmloader prerequisites

  patch  4: tools/hvmloader: Retrieve (x2)APIC IDs from the APs themselves

Toolstack prerequisites:

  patch  5: tools/libacpi: Use LUT of APIC IDs rather than function pointer
  patch  6: tools/libguest: Always set vCPU context in vcpu_hvm()

No functional changes:

  patch  7: xen/lib: Add topology generator for x86
    * Tweaked the behaviour of the cache leaves on overflow and added stronger
      checks.
  patch  8: xen/x86: Derive topologically correct x2APIC IDs from the policy

Final toolstack/xen stitching:

  patch  9: tools/libguest: Set distinct x2APIC IDs for each vCPU
  patch 10: xen/x86: Synthesise domain topologies

v6: https://lore.kernel.org/xen-devel/20241001123807.605-1-alejandro.vallejo@cloud.com
v5: https://lore.kernel.org/xen-devel/20240808134251.29995-1-alejandro.vallejo@cloud.com/
v4: https://lore.kernel.org/xen-devel/cover.1719416329.git.alejandro.vallejo@cloud.com/
v3: https://lore.kernel.org/xen-devel/cover.1716976271.git.alejandro.vallejo@cloud.com/
v2: https://lore.kernel.org/xen-devel/cover.1715102098.git.alejandro.vallejo@cloud.com/
v1: https://lore.kernel.org/xen-devel/20240109153834.4192-1-alejandro.vallejo@cloud.com/


Alejandro Vallejo (10):
  lib/x86: Bump max basic leaf in {pv,hvm}_max_policy
  xen/x86: Add initial x2APIC ID to the per-vLAPIC save area
  xen/x86: Add supporting code for uploading LAPIC contexts during
    domain create
  tools/hvmloader: Retrieve (x2)APIC IDs from the APs themselves
  tools/libacpi: Use LUT of APIC IDs rather than function pointer
  tools/libguest: Always set vCPU context in vcpu_hvm()
  xen/lib: Add topology generator for x86
  xen/x86: Derive topologically correct x2APIC IDs from the policy
  tools/libguest: Set distinct x2APIC IDs for each vCPU
  tools/x86: Synthesise domain topologies

 tools/firmware/hvmloader/config.h        |   5 +-
 tools/firmware/hvmloader/hvmloader.c     |   6 +-
 tools/firmware/hvmloader/mp_tables.c     |   4 +-
 tools/firmware/hvmloader/smp.c           |  57 +++++--
 tools/firmware/hvmloader/util.c          |   7 +-
 tools/include/xen-tools/common-macros.h  |   5 +
 tools/include/xenguest.h                 |   8 +
 tools/libacpi/build.c                    |   6 +-
 tools/libacpi/libacpi.h                  |   2 +-
 tools/libs/guest/xg_cpuid_x86.c          |  29 +++-
 tools/libs/guest/xg_dom_x86.c            |  93 +++++++----
 tools/libs/light/libxl_dom.c             |  25 +++
 tools/libs/light/libxl_x86_acpi.c        |   7 +-
 tools/tests/cpu-policy/test-cpu-policy.c | 201 +++++++++++++++++++++++
 xen/arch/x86/cpu-policy.c                |  15 +-
 xen/arch/x86/cpuid.c                     |  18 +-
 xen/arch/x86/hvm/vlapic.c                |  42 ++++-
 xen/arch/x86/include/asm/hvm/vlapic.h    |   1 +
 xen/include/public/arch-x86/hvm/save.h   |   2 +
 xen/include/xen/lib/x86/cpu-policy.h     |  27 +++
 xen/lib/x86/policy.c                     | 169 +++++++++++++++++++
 xen/lib/x86/private.h                    |   4 +
 22 files changed, 649 insertions(+), 84 deletions(-)


base-commit: 081683ea578da56dd20b9dc22a64d03c893b47ba