Kernel KVM virtualization development
 help / color / mirror / Atom feed
* [Patch v6 0/3] Host support for SMT and Enhanced SMT Protection
@ 2026-12-05 22:34 Pratik R. Sampat
  2026-12-05 22:34 ` [Patch v6 1/3] KVM: SVM: Re-queue events that were never injected Pratik R. Sampat
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Pratik R. Sampat @ 2026-12-05 22:34 UTC (permalink / raw)
  To: x86, kvm, linux-doc, linux-kernel
  Cc: tglx, mingo, bp, dave.hansen, haiyangz, wei.liu, seanjc, pbonzini,
	thomas.lendacky, kim.phillips, nikunj, michael.roth, ashish.kalra,
	prsampat

SMT Protection (SMTP) and Enhanced SMT Protection (ESMTP) let an
SEV-SNP VM control what may run on the SMT sibling of a thread that is
executing one of its vCPUs.  This mitigates the side-channel risk of
sharing core resources with untrusted host threads or with another
guest.

SMTP (Zen 4 and later) requires every sibling thread on the physical
core to be idle in host mode while the vCPU is in guest mode, which
gives up half of every core the VM runs on.

ESMTP (Zen 5 and later) relaxes that: a sibling may also run a vCPU
the guest has declared a legal sibling.  A legal sibling is another
ESMTP vCPU of the same guest (matching ASID) with the same
VCPU_SIBLING_MASK and the same VCPU_ID outside that mask.

Unlike core scheduling, where co-residency is a host kernel policy
expressed with cookies, both features are enforced by hardware.  For
ESMTP the policy lives in the VMSA.  The host is not trusted to keep
its own kernel, userspace, or interrupt-handling work off a sibling
thread while a protected vCPU is in guest mode.

Series
----------
Patch 1 is a prerequisite.  KVM has assumed that a #VMEXIT with
EVENTINJ still valid only happens on VMEXIT_INVALID, after which the
guest is torn down.  With SMTP and ESMTP, VMRUN can end with an
ordinary exit code without entering guest mode, so the staged event
was never delivered.  Detect that in svm_complete_interrupts() and
requeue the event instead of dropping it.

Patch 2 adds SMTP: the CPUID feature bit, IDLE_WAKEUP_ICR, retrying
VMRUN on VMEXIT_IDLE_REQUIRED, and advertising SVM_SEV_FEAT_SMTP
through KVM_X86_SEV_VMSA_FEATURES so userspace can request it with
KVM_SEV_INIT2.  IDLE_WAKEUP_ICR is programmed on each CPU when
virtualization is enabled on it.

Patch 3 adds ESMTP on top: the scattered CPUID bit, the VMCB timeout
field, retrying the three new exits, populating VCPU_ID and
VCPU_SIBLING_MASK in the launch VMSAs KVM builds, KVM fully sets
VCPU_SIBLING_MASK, as the guest does for its APs, so every vCPU of the
guest may be co-resident with any other.

Merging
-------
Following the discussion on v4, guest and host support are now split
into separate series to untangle x86 and KVM. Since the guest series
from v5 is now pushed to tip, this series adds the KVM host side.

  8509996df261 ("x86/sev: Add Enhanced SMT Protection fields to the VMSA")
  0d4aa2a4f846 ("x86/sev: Add guest support for Enhanced SMT Protection")

SMTP needs no guest changes.

Testing
-------
It is tested with the v5 guest patches and patched OVMF [1] and
QEMU [2] builds. Launch an SEV-SNP guest with ESMTP enabled on the
sev-snp-guest object:

For SMTP:
  -object sev-snp-guest,id=sev0,cbitpos=51,reduced-phys-bits=1,smtp=on

Or,

For ESMTP:
  -object sev-snp-guest,id=sev0,cbitpos=51,reduced-phys-bits=1,esmtp=on

SMTP and ESMTP are mutually exclusive.

The guest reports the feature in dmesg among the SNP feature names:

  # dmesg | grep -i SEV
  ... SEV-SNP ... SMTProt ...
Or,
  ... SEV-SNP ... ESMTProt ...

To check the sibling behaviour on an SMT=2 host:

* Identify a sibling pair X and Y on the host:
    cat /sys/devices/system/cpu/cpuX/topology/thread_siblings_list
* Pin two of the guest's vCPUs to X and Y.
* Load both vCPUs in the guest, e.g. stress-ng --cpu 2.
  * With SMTP: host CPUs should show 50% guest utilization each, since
    the two vCPUs cannot run together at once and one sibling thread
    must idle when the other runs.
  * With ESMTP: Both host CPUs should show 100% guest utilization, since
    the two vCPUs are legal siblings.
* Start a host task on one of the pair, e.g. taskset -c X stress-ng
  --cpu 1.  CPU X's time should now be split between host and guest.
  * With SMTP: guest utilization on CPU Y should remain relatively
    unchanged since it already must remain idle regardless of what runs
    on CPU X.
  * With ESMTP: guest utilization on CPU Y should drop, since the vCPU
    on Y cannot enter guest mode while the host task runs on X.

Based on tip/master.

v6:
* Host support only.  Guest support was split out in v5 and is in tip.
* New patch 2: host support for regular SMT Protection. SMTP is less
  flexible than ESMTP, since it keeps the sibling idle instead of
  allowing a legal sibling vCPU, but ESMTP needs Zen 5 or later while
  SMTP is available from Zen 4.
* Move IDLE_WAKEUP_ICR programming which is used by both SMTP and ESMTP
  to the former patch. Since functionally the patch remains the,
  retaining reviewed-by's.
* Patch 1: update the commit message and comment to cover SMTP as well
  as ESMTP.
* Patch 3: reject KVM_SEV_INIT2 requests that set both SMTP and ESMTP,
  now that KVM can advertise both.

v5: https://lore.kernel.org/kvm/cover.1794935627.git.prsampat@amd.com/
* Split guest and host support into separate series, per Sean and
  Boris [4]. This series carries guest support only.
* New patch 1: move the VCPU_ID/VCPU_SIBLING_MASK VMSA definitions out
  of the KVM host patch so that the guest side builds on its own.
  Retaining Tom's reviewed-by since it is functionally unchanged.
* Drop the sibling-mask comments from patches 2 and 3 - Boris
* Rebase onto tip/master.

v4: https://lore.kernel.org/all/cover.1794244450.git.prsampat@amd.com/
* Fix conflict of reserved bits introduced by PML support in
  vmcb_control_area

v3: https://lore.kernel.org/kvm/cover.1792184487.git.prsampat@amd.com
* Collected Reviewed-by tags - Tom
* Use sev_status to determine SNP support for guest as well - Tom
* Not syncing the tools/ copy of msr-index.h, since several bits apart
  from ESMTP differ and the perf tooling maintainers usually sync it.
  Happy to add a sync patch if needed.

v2: https://lore.kernel.org/kvm/cover.1791302373.git.prsampat@amd.com/
* Populate the ESMTP VMSA fields for Hyper-V AP bring-up - Sashiko
* Add ESMTP to SNP_FEATURES_IMPL and SNP_FEATURES_IMPL_REQ - local
  Sashiko instance

v1: https://lore.kernel.org/kvm/cover.1789399214.git.prsampat@amd.com

[1]: https://github.com/tianocore/edk2/pull/13128
[2]: https://lists.nongnu.org/archive/html/qemu-devel/2026-12/msg01488.html
[3]: https://lore.kernel.org/all/avc-5lkQhoR6US9o@google.com/

Pratik R. Sampat (3):
  KVM: SVM: Re-queue events that were never injected
  KVM: SVM: Add host support for SMT Protection
  KVM: SVM: Add host support for Enhanced SMT Protection

 .../admin-guide/kernel-parameters.txt         | 19 ++++++
 arch/x86/include/asm/cpufeatures.h            |  2 +
 arch/x86/include/asm/msr-index.h              |  1 +
 arch/x86/include/asm/svm.h                    |  5 +-
 arch/x86/include/uapi/asm/svm.h               | 11 +++-
 arch/x86/kernel/cpu/scattered.c               |  1 +
 arch/x86/kvm/svm/sev.c                        | 58 ++++++++++++++++++-
 arch/x86/kvm/svm/svm.c                        | 42 ++++++++++++--
 arch/x86/kvm/svm/svm.h                        |  2 +
 9 files changed, 134 insertions(+), 7 deletions(-)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-12-05 23:03 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05 22:34 [Patch v6 0/3] Host support for SMT and Enhanced SMT Protection Pratik R. Sampat
2026-12-05 22:34 ` [Patch v6 1/3] KVM: SVM: Re-queue events that were never injected Pratik R. Sampat
2026-12-05 22:59   ` sashiko-bot
2026-12-05 22:34 ` [Patch v6 2/3] KVM: SVM: Add host support for SMT Protection Pratik R. Sampat
2026-12-05 23:03   ` sashiko-bot
2026-12-05 22:35 ` [Patch v6 3/3] KVM: SVM: Add host support for Enhanced " Pratik R. Sampat
2026-12-05 23:00   ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox