From: Tianyu Lan <tiala@xxxxxxxxxxxxx> Hyper-V provides two modes for running SEV-SNP VMs: 1) In vTOM mode with a paravisor (see Section 15.36.8 of [1]) 2) In "fully enlightened" mode with normal "C" bit control over page encryption, and no paravisor For #1, the paravisor runs in VMPL 0, while Linux runs in VMPL 2 (see Section 15.36.7 of [1]). The paravisor is typically provided by Hyper-V and handles most of the SNP-related functionality. As such, most of the SNP functionality in the Linux guest is bypassed. The guest operates in vTOM mode, where encryption is enabled by default. The guest must still request page transitions between private and shared, but there is relatively less SNP machinery required in the guest. Support for this mode of operation first went upstream in the 5.15 kernel. For #2, this patch set provides the initial support. The existing SEV-SNP machinery in the kernel is fully used, but Hyper-V specific updates are required to properly share Hyper-V communication pages between the guest and host and to start APs at boot time. In either mode, Hyper-V requires that the guest implement the SEV-SNP Restricted Interrupt Injection feature (see Section 15.36.16 of [1], and Section 5 of [2]). Without this feature, the guest is subject to attack by a compromised hypervisor that can inject any exception at any time, such as injecting an interrupt while the guest has interrupts disabled. In vTOM mode, Restricted Interrupt Injection is implemented by the paravisor, so no Linux guest changes are required. But in fully enlightened mode, the Linux guest must provide the implementation. This patch set is derived from an earlier patch set that includes both the Hyper-V specific changes and Restricted Interrupt Injection support.[3] But it is now limited to only the Hyper-V specific changes. The Restricted Interrupt Injection support will come later in a separate patch set. [1] https://www.amd.com/system/files/TechDocs/24593.pdf [2] https://www.amd.com/system/files/TechDocs/56421-guest-hypervisor-communication-block-standardization.pdf [3] https://lore.kernel.org/lkml/20230515165917.1306922-1-ltykernel@xxxxxxxxx/ Change since v1: * vTOM case uses paravisor_present flag and HV_ISOLATION_TYPE_SNP type. * Rework some patches' change log * Fix some comments in the patches Tianyu Lan (9): x86/hyperv: Add sev-snp enlightened guest static key x86/hyperv: Set Virtual Trust Level in VMBus init message x86/hyperv: Mark Hyper-V vp assist page unencrypted in SEV-SNP enlightened guest drivers: hv: Mark percpu hvcall input arg page unencrypted in SEV-SNP enlightened guest x86/hyperv: Use vmmcall to implement Hyper-V hypercall in sev-snp enlightened guest clocksource: hyper-v: Mark hyperv tsc page unencrypted in sev-snp enlightened guest x86/hyperv: Initialize cpu and memory for SEV-SNP enlightened guest x86/hyperv: Add smp support for SEV-SNP guest x86/hyperv: Add hyperv-specific handling for VMMCALL under SEV-ES arch/x86/hyperv/hv_init.c | 52 +++++++- arch/x86/hyperv/ivm.c | 199 +++++++++++++++++++++++++++++ arch/x86/include/asm/hyperv-tlfs.h | 7 + arch/x86/include/asm/mshyperv.h | 73 +++++++++-- arch/x86/kernel/cpu/mshyperv.c | 42 +++++- drivers/clocksource/hyperv_timer.c | 2 +- drivers/hv/connection.c | 1 + drivers/hv/hv.c | 57 ++++++++- drivers/hv/hv_common.c | 19 +++ include/asm-generic/hyperv-tlfs.h | 1 + include/asm-generic/mshyperv.h | 13 +- include/linux/hyperv.h | 4 +- 12 files changed, 445 insertions(+), 25 deletions(-) -- 2.25.1