From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mx.groups.io with SMTP id smtpd.web11.903.1647050145463002246 for ; Fri, 11 Mar 2022 17:56:22 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=NyZ7LIyB; spf=pass (domain: intel.com, ip: 192.55.52.115, mailfrom: min.m.xu@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1647050182; x=1678586182; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hUd1UXi39AfwxYc6EPB9ZHwyv1gu4jDCsgDEfKyfPyI=; b=NyZ7LIyBhBt1DL3mxaEx6tHy3r6pSR3S1a+vdfUUrkMbyYjm958qVOzj hUl3VVkcxYloIxZJolyou8TdWuLQToe1OB3M1Fke+0S0OkiSRTGpfKiPR fTJw/+eAIOo8kd9K5yGSvPyq/GcgXJhvlo5CKZKEW7kLT80mFn+PM7a+e 9MDyCjj+uVYDk+DFmGHf9BnghF+vEQMty2mZtOZlhz8guOOYrHB+k7M50 ZpFOASqUIDvJlaeB859g382vKc5PW3vjnvQBZYSMJubOrWPgJUUY5JYoC CATLO1L7jcsBBx5qDrhcEFuCUtIhu+whkWAik1Zliz+mntgEIRnT4Vuba Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10283"; a="255895202" X-IronPort-AV: E=Sophos;i="5.90,175,1643702400"; d="scan'208";a="255895202" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Mar 2022 17:56:22 -0800 X-IronPort-AV: E=Sophos;i="5.90,175,1643702400"; d="scan'208";a="555565282" Received: from mxu9-mobl1.ccr.corp.intel.com ([10.255.29.254]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Mar 2022 17:56:19 -0800 From: "Min Xu" To: devel@edk2.groups.io Cc: Min Xu , Ard Biesheuvel , Jordan Justen , Brijesh Singh , Erdem Aktas , James Bottomley , Jiewen Yao , Tom Lendacky , Gerd Hoffmann Subject: [PATCH V8 38/47] OvmfPkg: Update PlatformInitLib for Tdx guest Date: Sat, 12 Mar 2022 09:54:03 +0800 Message-Id: X-Mailer: git-send-email 2.29.2.windows.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 There are below changes in PlatformInitLib for Tdx guest: 1. Publish ram regions In Tdx guest, the system memory is passed in TdHob by host VMM. So the major task of PlatformTdxPublishRamRegions is to walk thru the TdHob list and transfer the ResourceDescriptorHob and MemoryAllocationHob to the hobs in DXE phase. 2. Build MemoryAllocationHob for Tdx Mailbox and Ovmf work area. 3. Update of PlatformAddressWidthInitialization. The physical address width that Tdx guest supports is either 48 or 52. 4. Update of PlatformMemMapInitialization. 0xA0000 - 0xFFFFF is VGA bios region. Platform initialization marks the region as MMIO region. Dxe code maps MMIO region as IO region. As TDX guest, MMIO region is maps as shared. However VGA BIOS doesn't need to be shared. Guest TDX Linux maps VGA BIOS as private and accesses for BIOS and stuck on repeating EPT violation. VGA BIOS (more generally ROM region) should be private. Skip marking VGA BIOA region [0xa000, 0xfffff] as MMIO in HOB. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Brijesh Singh Cc: Erdem Aktas Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Cc: Gerd Hoffmann Acked-by: Gerd Hoffmann Signed-off-by: Min Xu --- OvmfPkg/Include/Library/PlatformInitLib.h | 14 ++++++ OvmfPkg/Library/PlatformInitLib/IntelTdx.c | 49 +++++++++++++++++++ .../Library/PlatformInitLib/IntelTdxNull.c | 16 ++++++ OvmfPkg/Library/PlatformInitLib/MemDetect.c | 14 ++++++ OvmfPkg/Library/PlatformInitLib/Platform.c | 4 +- 5 files changed, 96 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/Include/Library/PlatformInitLib.h b/OvmfPkg/Include/Library/PlatformInitLib.h index f41b4f16d9fa..452a7be7af08 100644 --- a/OvmfPkg/Include/Library/PlatformInitLib.h +++ b/OvmfPkg/Include/Library/PlatformInitLib.h @@ -220,4 +220,18 @@ ProcessTdxHobList ( VOID ); +/** + In Tdx guest, the system memory is passed in TdHob by host VMM. So + the major task of PlatformTdxPublishRamRegions is to walk thru the + TdHob list and transfer the ResourceDescriptorHob and MemoryAllocationHob + to the hobs in DXE phase. + + MemoryAllocationHob should also be created for Mailbox and Ovmf work area. +**/ +VOID +EFIAPI +PlatformTdxPublishRamRegions ( + VOID + ); + #endif // PLATFORM_INIT_LIB_H_ diff --git a/OvmfPkg/Library/PlatformInitLib/IntelTdx.c b/OvmfPkg/Library/PlatformInitLib/IntelTdx.c index c74c8ee20dae..338cd256af94 100644 --- a/OvmfPkg/Library/PlatformInitLib/IntelTdx.c +++ b/OvmfPkg/Library/PlatformInitLib/IntelTdx.c @@ -512,3 +512,52 @@ TransferTdxHobList ( Hob.Raw = GET_NEXT_HOB (Hob); } } + +/** + In Tdx guest, the system memory is passed in TdHob by host VMM. So + the major task of PlatformTdxPublishRamRegions is to walk thru the + TdHob list and transfer the ResourceDescriptorHob and MemoryAllocationHob + to the hobs in DXE phase. + + MemoryAllocationHob should also be created for Mailbox and Ovmf work area. +**/ +VOID +EFIAPI +PlatformTdxPublishRamRegions ( + VOID + ) +{ + if (!TdIsEnabled ()) { + return; + } + + TransferTdxHobList (); + + // + // The memory region defined by PcdOvmfSecGhcbBackupBase is pre-allocated by + // host VMM and used as the td mailbox at the beginning of system boot. + // + BuildMemoryAllocationHob ( + FixedPcdGet32 (PcdOvmfSecGhcbBackupBase), + FixedPcdGet32 (PcdOvmfSecGhcbBackupSize), + EfiACPIMemoryNVS + ); + + if (FixedPcdGet32 (PcdOvmfWorkAreaSize) != 0) { + // + // Reserve the work area. + // + // Since this memory range will be used by the Reset Vector on S3 + // resume, it must be reserved as ACPI NVS. + // + // If S3 is unsupported, then various drivers might still write to the + // work area. We ought to prevent DXE from serving allocation requests + // such that they would overlap the work area. + // + BuildMemoryAllocationHob ( + (EFI_PHYSICAL_ADDRESS)(UINTN)FixedPcdGet32 (PcdOvmfWorkAreaBase), + (UINT64)(UINTN)FixedPcdGet32 (PcdOvmfWorkAreaSize), + EfiBootServicesData + ); + } +} diff --git a/OvmfPkg/Library/PlatformInitLib/IntelTdxNull.c b/OvmfPkg/Library/PlatformInitLib/IntelTdxNull.c index af90e0866e89..3ebe582af8de 100644 --- a/OvmfPkg/Library/PlatformInitLib/IntelTdxNull.c +++ b/OvmfPkg/Library/PlatformInitLib/IntelTdxNull.c @@ -28,3 +28,19 @@ ProcessTdxHobList ( { return EFI_UNSUPPORTED; } + +/** + In Tdx guest, the system memory is passed in TdHob by host VMM. So + the major task of PlatformTdxPublishRamRegions is to walk thru the + TdHob list and transfer the ResourceDescriptorHob and MemoryAllocationHob + to the hobs in DXE phase. + + MemoryAllocationHob should also be created for Mailbox and Ovmf work area. +**/ +VOID +EFIAPI +PlatformTdxPublishRamRegions ( + VOID + ) +{ +} diff --git a/OvmfPkg/Library/PlatformInitLib/MemDetect.c b/OvmfPkg/Library/PlatformInitLib/MemDetect.c index fbd3073bd3d1..7c9b2627623b 100644 --- a/OvmfPkg/Library/PlatformInitLib/MemDetect.c +++ b/OvmfPkg/Library/PlatformInitLib/MemDetect.c @@ -37,6 +37,8 @@ Module Name: #include #include #include +#include + #include VOID @@ -528,7 +530,19 @@ PlatformAddressWidthInitialization ( PhysMemAddressWidth = 36; } + #if defined (MDE_CPU_X64) + if (TdIsEnabled ()) { + if (TdSharedPageMask () == (1ULL << 47)) { + PhysMemAddressWidth = 48; + } else { + PhysMemAddressWidth = 52; + } + } + + ASSERT (PhysMemAddressWidth <= 52); + #else ASSERT (PhysMemAddressWidth <= 48); + #endif PlatformInfoHob->FirstNonAddress = FirstNonAddress; PlatformInfoHob->PhysMemAddressWidth = PhysMemAddressWidth; diff --git a/OvmfPkg/Library/PlatformInitLib/Platform.c b/OvmfPkg/Library/PlatformInitLib/Platform.c index 96bc41b1098c..0f63efbd3ac6 100644 --- a/OvmfPkg/Library/PlatformInitLib/Platform.c +++ b/OvmfPkg/Library/PlatformInitLib/Platform.c @@ -136,7 +136,9 @@ PlatformMemMapInitialization ( // // Video memory + Legacy BIOS region // - PlatformAddIoMemoryRangeHob (0x0A0000, BASE_1MB); + if (!TdIsEnabled ()) { + PlatformAddIoMemoryRangeHob (0x0A0000, BASE_1MB); + } if (PlatformInfoHob->HostBridgeDevId == 0xffff /* microvm */) { PlatformAddIoMemoryBaseSizeHob (MICROVM_GED_MMIO_BASE, SIZE_4KB); -- 2.29.2.windows.2