Linux IOMMU Development
 help / color / mirror / Atom feed
* [RFC PATCH v1 0/6] Support nested SNP KVM guests on Hyper-V
@ 2023-01-23 16:51 Jeremi Piotrowski
  2023-01-23 16:51 ` [RFC PATCH v1 5/6] iommu/amd: Don't fail snp_enable when running virtualized Jeremi Piotrowski
  0 siblings, 1 reply; 2+ messages in thread
From: Jeremi Piotrowski @ 2023-01-23 16:51 UTC (permalink / raw)
  To: linux-kernel
  Cc: Jeremi Piotrowski, Wei Liu, Dexuan Cui, Tianyu Lan,
	Michael Kelley, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, linux-hyperv, Brijesh Singh, Michael Roth,
	Ashish Kalra, Tom Lendacky, linux-crypto, Joerg Roedel,
	Suravee Suthikulpanit, iommu

This patch series enables SNP-host support when running on Hyper-V, which
allows launching nested SNP guests. No guest or qemu changes are necessary
for this to work.

Patch 1 deals with allocating an RMP table which is not provided by
firmware/hypervisor. Patch 2 implements MSR-based rmpupdate/psmash instructions
which are meant for virtualized environments. Patch 3 maintains the rmptable
for internal kernel page tracking. Patch 4 makes sure that the kernel does not
disable SNP support during early CPU init. Patch 5 allows SNP initialization to
proceed when no iommus are available. Patch 6 adds a quirk in psp command
buffer handling, because of differences in SNP firmware spec interpretation.

This series depends on

- "Add AMD Secure Nested Paging (SEV-SNP) Hypervisor Support" (applies on top of RFC v7)
  https://lore.kernel.org/lkml/20221214194056.161492-1-michael.roth@amd.com/
- "Support ACPI PSP on Hyper-V"
  https://lore.kernel.org/lkml/20230123152250.26413-1-jpiotrowski@linux.microsoft.com/

Jeremi Piotrowski (6):
  x86/hyperv: Allocate RMP table during boot
  x86/sev: Add support for NestedVirtSnpMsr
  x86/sev: Maintain shadow rmptable on Hyper-V
  x86/amd: Configure necessary MSRs for SNP during CPU init when running
    as a guest
  iommu/amd: Don't fail snp_enable when running virtualized
  crypto: ccp - Introduce quirk to always reclaim pages after SEV-legacy
    commands

 arch/x86/hyperv/hv_init.c          |   5 ++
 arch/x86/include/asm/cpufeatures.h |   1 +
 arch/x86/include/asm/hyperv-tlfs.h |   3 +
 arch/x86/include/asm/mshyperv.h    |   3 +
 arch/x86/include/asm/msr-index.h   |   2 +
 arch/x86/include/asm/sev.h         |   2 +
 arch/x86/kernel/cpu/amd.c          |   8 +-
 arch/x86/kernel/cpu/mshyperv.c     |  41 ++++++++++
 arch/x86/kernel/sev.c              | 122 ++++++++++++++++++++++++++---
 drivers/crypto/ccp/sev-dev.c       |   6 +-
 drivers/crypto/ccp/sp-dev.h        |   4 +
 drivers/crypto/ccp/sp-platform.c   |   1 +
 drivers/iommu/amd/init.c           |   6 ++
 13 files changed, 191 insertions(+), 13 deletions(-)

-- 
2.25.1


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

* [RFC PATCH v1 5/6] iommu/amd: Don't fail snp_enable when running virtualized
  2023-01-23 16:51 [RFC PATCH v1 0/6] Support nested SNP KVM guests on Hyper-V Jeremi Piotrowski
@ 2023-01-23 16:51 ` Jeremi Piotrowski
  0 siblings, 0 replies; 2+ messages in thread
From: Jeremi Piotrowski @ 2023-01-23 16:51 UTC (permalink / raw)
  To: linux-kernel
  Cc: Jeremi Piotrowski, Wei Liu, Dexuan Cui, Tianyu Lan,
	Michael Kelley, linux-hyperv, Brijesh Singh, Michael Roth,
	Ashish Kalra, Tom Lendacky, Joerg Roedel, Suravee Suthikulpanit,
	iommu, Jeremi Piotrowski

From: Jeremi Piotrowski <jpiotrowski@microsoft.com>

Hyper-V VMs do not have access to an IOMMU but can support hosting SNP
VMs. amd_iommu_snp_enable() is on the SNP init path and should not fail
in that case.

Signed-off-by: Jeremi Piotrowski <jpiotrowski@linux.microsoft.com>
---
 drivers/iommu/amd/init.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c
index d1270e3c5baf..8049dbe78a27 100644
--- a/drivers/iommu/amd/init.c
+++ b/drivers/iommu/amd/init.c
@@ -3619,6 +3619,12 @@ int amd_iommu_pc_set_reg(struct amd_iommu *iommu, u8 bank, u8 cntr, u8 fxn, u64
 #ifdef CONFIG_AMD_MEM_ENCRYPT
 int amd_iommu_snp_enable(void)
 {
+	/*
+	 * If we're running virtualized there doesn't have to be an IOMMU for SNP to work.
+	 */
+	if (init_state == IOMMU_NOT_FOUND && boot_cpu_has(X86_FEATURE_HYPERVISOR))
+		return 0;
+
 	/*
 	 * The SNP support requires that IOMMU must be enabled, and is
 	 * not configured in the passthrough mode.
-- 
2.25.1


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

end of thread, other threads:[~2023-01-23 16:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-23 16:51 [RFC PATCH v1 0/6] Support nested SNP KVM guests on Hyper-V Jeremi Piotrowski
2023-01-23 16:51 ` [RFC PATCH v1 5/6] iommu/amd: Don't fail snp_enable when running virtualized Jeremi Piotrowski

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