kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC v2 00/17] AMD: Add Secure AVIC Guest Support
@ 2025-02-26  9:05 Neeraj Upadhyay
  2025-02-26  9:05 ` [RFC v2 01/17] x86/apic: Add new driver for Secure AVIC Neeraj Upadhyay
                   ` (16 more replies)
  0 siblings, 17 replies; 59+ messages in thread
From: Neeraj Upadhyay @ 2025-02-26  9:05 UTC (permalink / raw)
  To: linux-kernel
  Cc: bp, tglx, mingo, dave.hansen, Thomas.Lendacky, nikunj,
	Santosh.Shukla, Vasant.Hegde, Suravee.Suthikulpanit, David.Kaplan,
	x86, hpa, peterz, seanjc, pbonzini, kvm, kirill.shutemov,
	huibo.wang, naveen.rao

Introduction
------------

Secure AVIC is a new hardware feature in the AMD64 architecture to
allow SEV-SNP guests to prevent hypervisor from generating unexpected
interrupts to a vCPU or otherwise violate architectural assumptions
around APIC behavior.

One of the significant differences from AVIC or emulated x2APIC is that
Secure AVIC uses a guest-owned and managed APIC backing page. It also
introduces additional fields in both the VMCB and the Secure AVIC backing
page to aid the guest in limiting which interrupt vectors can be injected
into the guest.

Guest APIC Backing Page
-----------------------
Each vCPU has a guest-allocated APIC backing page of size 4K, which
maintains APIC state for that vCPU. The x2APIC MSRs are mapped at
their corresposing x2APIC MMIO offset within the guest APIC backing
page. All x2APIC accesses by guest or Secure AVIC hardware operate
on this backing page. The backing page should be pinned and NPT entry
for it should be always mapped while the corresponding vCPU is running.


MSR Accesses
------------
Secure AVIC only supports x2APIC MSR accesses. xAPIC MMIO offset based
accesses are not supported.

Some of the MSR accesses such as ICR writes (with shorthand equal to
self), SELF_IPI, EOI, TPR writes are accelerated by Secure AVIC
hardware. Other MSR accesses generate a #VC exception. The #VC
exception handler reads/writes to the guest APIC backing page.
As guest APIC backing page is accessible to the guest, the Secure
AVIC driver code optimizes APIC register access by directly
reading/writing to the guest APIC backing page (instead of taking
the #VC exception route).

In addition to the architected MSRs, following new fields are added to
the guest APIC backing page which can be modified directly by the
guest:

a. ALLOWED_IRR

ALLOWED_IRR vector indicates the interrupt vectors which the guest
allows the hypervisor to send. The combination of host-controlled
REQUESTED_IRR vectors (part of VMCB) and ALLOWED_IRR is used by
hardware to update the IRR vectors of the Guest APIC backing page.

#Offset        #bits        Description
204h           31:0         Guest allowed vectors 0-31
214h           31:0         Guest allowed vectors 32-63
...
274h           31:0         Guest allowed vectors 224-255

ALLOWED_IRR is meant to be used specifically for vectors that the
hypervisor is allowed to inject, such as device interrupts.  Interrupt
vectors used exclusively by the guest itself (like IPI vectors) should
not be allowed to be injected into the guest for security reasons.

b. NMI Request
 
#Offset        #bits        Description
278h           0            Set by Guest to request Virtual NMI


LAPIC Timer Support
-------------------
LAPIC timer is emulated by hypervisor. So, APIC_LVTT, APIC_TMICT and
APIC_TDCR, APIC_TMCCT APIC registers are not read/written to the guest
APIC backing page and are communicated to the hypervisor using SVM_EXIT_MSR
VMGEXIT. 

IPI Support
-----------
Only SELF_IPI is accelerated by Secure AVIC hardware. Other IPIs require
writing (from the Secure AVIC driver) to the IRR vector of the target CPU
backing page and then issuing VMGEXIT for the hypervisor to notify the
target vCPU.

KEXEC Support
-------------
Secure AVIC enabled guest can kexec to another kernel which has Secure
AVIC enabled, as the Hypervisor has Secure AVIC feature bit set in the
sev_status.

Driver Implementation Open Points
---------------------------------

The Secure AVIC driver only supports physical destination mode. If
logical destination mode need to be supported, then a separate x2apic
driver would be required for supporting logical destination mode.

Setting of ALLOWED_IRR vectors is done from vector.c for IOAPIC and MSI
interrupts. ALLOWED_IRR vector is not cleared when an interrupt vector
migrates to different CPU. Using a cleaner approach to manage and
configure allowed vectors needs more work.


Testing
-------

This series is based on top of commit 0f966b199269 "Merge branch into tip/master:
'x86/platform'" of tip/tip master branch.

Host Secure AVIC support patch series is at [1].

Qemu support patch is at [2].

QEMU commandline for testing Secure AVIC enabled guest:

qemu-system-x86_64 <...> -object sev-snp-guest,id=sev0,policy=0xb0000,cbitpos=51,reduced-phys-bits=1,allowed-sev-features=true,secure-avic=true

Following tests are done:

1) Boot to Prompt using initramfs and ubuntu fs.
2) Verified timer and IPI as part of the guest bootup.
3) Verified long run SCF TORTURE IPI test.

[1] https://github.com/AMDESE/linux-kvm/tree/savic-host-latest
[2] https://github.com/AMDESE/qemu/tree/secure-avic

Change since v1

  - Added Kexec support.
  - Instead of doing a 2M aligned allocation for backing pages,
    allocate individual PAGE_SIZE pages for vCPUs.
  - Instead of reading Extended Topology Enumeration CPUID, APIC_ID
    value is read from Hv and updated in APIC backing page. Hv returned
    ID is checked for any duplicates.
  - Propagate all LVT* register reads and writes to Hv.
  - Check that Secure AVIC control MSR is not intercepted by Hv.
  - Fix EOI handling for level-triggered interrupts.
  - Misc cleanups and commit log updates.

Kishon Vijay Abraham I (5):
  x86/apic: Support LAPIC timer for Secure AVIC
  x86/sev: Initialize VGIF for secondary VCPUs for Secure AVIC
  x86/apic: Add support to send NMI IPI for Secure AVIC
  x86/sev: Enable NMI support for Secure AVIC
  x86/sev: Indicate SEV-SNP guest supports Secure AVIC

Neeraj Upadhyay (12):
  x86/apic: Add new driver for Secure AVIC
  x86/apic: Initialize Secure AVIC APIC backing page
  x86/apic: Populate .read()/.write() callbacks of Secure AVIC driver
  x86/apic: Initialize APIC ID for Secure AVIC
  x86/apic: Add update_vector callback for Secure AVIC
  x86/apic: Add support to send IPI for Secure AVIC
  x86/apic: Allow NMI to be injected from hypervisor for Secure AVIC
  x86/apic: Read and write LVT* APIC registers from HV for SAVIC guests
  x86/apic: Handle EOI writes for SAVIC guests
  x86/apic: Add kexec support for Secure AVIC
  x86/apic: Enable Secure AVIC in Control MSR
  x86/sev: Prevent SECURE_AVIC_CONTROL MSR interception for Secure AVIC
    guests

 arch/x86/Kconfig                    |  14 +
 arch/x86/boot/compressed/sev.c      |   4 +-
 arch/x86/coco/core.c                |   3 +
 arch/x86/coco/sev/core.c            | 145 +++++++-
 arch/x86/include/asm/apic.h         |   4 +
 arch/x86/include/asm/apicdef.h      |   2 +
 arch/x86/include/asm/msr-index.h    |   9 +-
 arch/x86/include/asm/sev.h          |  10 +
 arch/x86/include/uapi/asm/svm.h     |   3 +
 arch/x86/kernel/apic/Makefile       |   1 +
 arch/x86/kernel/apic/apic.c         |   9 +
 arch/x86/kernel/apic/vector.c       |   8 +
 arch/x86/kernel/apic/x2apic_savic.c | 530 ++++++++++++++++++++++++++++
 include/linux/cc_platform.h         |   8 +
 14 files changed, 743 insertions(+), 7 deletions(-)
 create mode 100644 arch/x86/kernel/apic/x2apic_savic.c


base-commit: 0f966b1992694763de4dae6bdf817c5c1c6fc66d
-- 
2.34.1


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

end of thread, other threads:[~2025-04-07 16:17 UTC | newest]

Thread overview: 59+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-26  9:05 [RFC v2 00/17] AMD: Add Secure AVIC Guest Support Neeraj Upadhyay
2025-02-26  9:05 ` [RFC v2 01/17] x86/apic: Add new driver for Secure AVIC Neeraj Upadhyay
2025-03-20 15:51   ` Borislav Petkov
2025-03-21  3:44     ` Neeraj Upadhyay
2025-03-21 13:55       ` Borislav Petkov
2025-03-21 16:09         ` Neeraj Upadhyay
2025-03-21 17:11           ` Borislav Petkov
2025-04-01  5:12             ` Neeraj Upadhyay
2025-04-02  9:47               ` Borislav Petkov
2025-04-02 10:34                 ` Neeraj Upadhyay
2025-04-07 13:17                   ` Borislav Petkov
2025-04-07 16:17                     ` Neeraj Upadhyay
2025-03-21 12:44     ` Thomas Gleixner
2025-03-21 13:52       ` Borislav Petkov
2025-03-21 12:53   ` Thomas Gleixner
2025-03-21 13:25     ` Neeraj Upadhyay
2025-02-26  9:05 ` [RFC v2 02/17] x86/apic: Initialize Secure AVIC APIC backing page Neeraj Upadhyay
2025-03-21 13:08   ` Thomas Gleixner
2025-03-21 13:49     ` Neeraj Upadhyay
2025-03-21 16:32   ` Francesco Lavra
2025-03-21 17:00     ` Neeraj Upadhyay
2025-02-26  9:05 ` [RFC v2 03/17] x86/apic: Populate .read()/.write() callbacks of Secure AVIC driver Neeraj Upadhyay
2025-03-21 13:38   ` Thomas Gleixner
2025-03-21 14:00     ` Neeraj Upadhyay
2025-02-26  9:05 ` [RFC v2 04/17] x86/apic: Initialize APIC ID for Secure AVIC Neeraj Upadhyay
2025-03-21 13:52   ` Thomas Gleixner
2025-03-21 15:11     ` Neeraj Upadhyay
2025-02-26  9:05 ` [RFC v2 05/17] x86/apic: Add update_vector callback " Neeraj Upadhyay
2025-03-21 14:27   ` Thomas Gleixner
2025-03-21 15:35     ` Neeraj Upadhyay
2025-03-25 12:10       ` Neeraj Upadhyay
2025-03-27 10:27         ` Thomas Gleixner
2025-03-27 11:17           ` Neeraj Upadhyay
2025-03-27 12:18             ` Thomas Gleixner
2025-03-27 12:30               ` Neeraj Upadhyay
2025-02-26  9:05 ` [RFC v2 06/17] x86/apic: Add support to send IPI " Neeraj Upadhyay
2025-03-21 15:06   ` Thomas Gleixner
2025-04-01 10:25     ` Neeraj Upadhyay
2025-02-26  9:05 ` [RFC v2 07/17] x86/apic: Support LAPIC timer " Neeraj Upadhyay
2025-02-26  9:05 ` [RFC v2 08/17] x86/sev: Initialize VGIF for secondary VCPUs " Neeraj Upadhyay
2025-02-26  9:05 ` [RFC v2 09/17] x86/apic: Add support to send NMI IPI " Neeraj Upadhyay
2025-02-26  9:05 ` [RFC v2 10/17] x86/apic: Allow NMI to be injected from hypervisor " Neeraj Upadhyay
2025-02-26  9:05 ` [RFC v2 11/17] x86/sev: Enable NMI support " Neeraj Upadhyay
2025-02-26  9:05 ` [RFC v2 12/17] x86/apic: Read and write LVT* APIC registers from HV for SAVIC guests Neeraj Upadhyay
2025-02-26  9:05 ` [RFC v2 13/17] x86/apic: Handle EOI writes " Neeraj Upadhyay
2025-03-21 15:41   ` Thomas Gleixner
2025-03-21 17:11     ` Sean Christopherson
2025-03-27 10:48       ` Thomas Gleixner
2025-03-27 12:20         ` Thomas Gleixner
2025-03-27 14:19           ` Sean Christopherson
2025-03-27 16:54             ` Thomas Gleixner
2025-02-26  9:05 ` [RFC v2 14/17] x86/apic: Add kexec support for Secure AVIC Neeraj Upadhyay
2025-03-21 15:48   ` Thomas Gleixner
2025-04-01 10:35     ` Neeraj Upadhyay
2025-04-01 18:31       ` Thomas Gleixner
2025-04-02  2:40         ` Neeraj Upadhyay
2025-02-26  9:05 ` [RFC v2 15/17] x86/apic: Enable Secure AVIC in Control MSR Neeraj Upadhyay
2025-02-26  9:05 ` [RFC v2 16/17] x86/sev: Prevent SECURE_AVIC_CONTROL MSR interception for Secure AVIC guests Neeraj Upadhyay
2025-02-26  9:05 ` [RFC v2 17/17] x86/sev: Indicate SEV-SNP guest supports Secure AVIC Neeraj Upadhyay

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).