summaryrefslogtreecommitdiff
path: root/OvmfPkg/Library/PlatformInitLib
AgeCommit message (Collapse)AuthorFilesLines
2026-08-23OvmfPkg/PlatformInitLib: Set dynamic MMIO window size to 1/4ramkumar.s1-1/+1
Large multi-GPU passthrough configurations can exhaust the current MMIO window sizing rule (1/8 of guest physical address space), especially with newer GPUs that have very large BAR requirements and alignment overhead. With 46-bit guest physical addressing, the 1/8 rule provides an 8TB MMIO window. Newer GPUs with 512GB VRAM can exhaust an 8TB window when passing through up to 8 devices. Increase the MMIO window size to 1/4 of guest physical address space. This provides a 16TB MMIO window on a 46-bit setup. Tested with 8-GPU passthrough (512GB VRAM per GPU). With this change, all GPUs are visible and functional in the VM; without it, one GPU was unusable. Signed-off-by: ramkumar.s <ramkumar.s@nutanix.com>
2026-07-07OvmfPkg/PlatformInitLib: restore below-4G low memory detection for TDVFStanislaw Grams1-3/+7
Commit 0a0919607c ("OvmfPkg/PlatformInitLib: redefine low memory") narrowed PlatformGetLowMemoryCB() to consider only the first below-4G memory block whose base address is zero. The change was intended to fix SVSM guests, where SVSM caves a chunk out of below-4G RAM and OVMF must not stray into that hole. TDVF, however, reports its below-4G RAM through the TdHob as two adjacent resource descriptors: [0, 0x800000) EFI_RESOURCE_SYSTEM_MEMORY (pre-accepted) [0x800000, ~4G) EFI_RESOURCE_MEMORY_UNACCEPTED PlatformScanE820Tdx() surfaces both as EfiAcpiAddressRangeMemory E820 entries. After 0a0919607c only the first, tiny 8 MiB block is picked up, so PlatformInfoHob->LowMemory becomes 0x800000. In OvmfPkg/PlatformPei/MemDetect.c PublishPeiMemory() this drives: LowerMemorySize = 0x00800000 // LowMemory PeiMemoryCap = 0x04F82000 // ~81 MiB MemoryBase = LowerMemorySize - PeiMemoryCap // UINT32 underflow = 0xFB87E000 Permanent PEI memory is then published at 0xFB87E000, which is not backed by RAM. TemporaryRamMigration()'s first CopyMem into that phantom range (observed as 0xFB898000 in the failing log) faults, tearing down the TD. Fold adjacent below-4G memory blocks into the low-memory span: accept an entry whose base equals the current LowMemory and advance LowMemory by its length. LowMemory starts at zero, so the first accepted block at address 0 still starts the sequence; non-adjacent above-4G or SVSM-carved blocks continue to be skipped (their base does not match LowMemory); and the TDVF accepted+unaccepted pair, which is contiguous, is now grouped correctly. Co-authored-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Stanislaw Grams <stanislaw.grams@intel.com>
2026-04-01OvmfPkg/PlatformInitLib: redefine low memoryGerd Hoffmann1-11/+13
Traditionally "low memory" is all memory below 4G. The code logic dates back to the days where OVMF has used the CMOS to figure how much memory is installed instead of the e820 table provided by qemu. That approach to memory detection implicitly assumes there is a single block of memory below 4G. Should that not be the case things fall apart. This happens in case OVMF runs under SVSM and SVSM caves out a chunk of memory below 4G for itself, passing the remaining two blocks of memory below 4G on to OVMF (via igvm memory map). Fix that by redefining what OVMF considers "low memory". It is the first block of memory (with base address zero) now. This fixes the SVSM use case outlined above. For other use cases nothing will change. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2026-03-11OvmfPkg/PlatformInitLib: Add SoftReserved memory type supportfanhuang1-0/+16
Add support for E820 Soft Reserved Memory regions in OVMF firmware. This memory type is used by QEMU to expose Specific Purpose Memory (SPM). Changes: - Add EfiAcpiAddressRangeSoftReserved to EFI_ACPI_MEMORY_TYPE enum - Handle SoftReserved in PlatformAddHobCB() by creating Resource HOBs with standard memory attributes plus EFI_RESOURCE_ATTRIBUTE_SPECIAL_PURPOSE Background: - E820_TYPE_SOFT_RESERVED (0xEFFFFFFF) is defined in Linux kernel: include/uapi/linux/e820.h - SPM (Specific Purpose Memory) is defined in ACPI 6.4+ specification - Use cases include High Bandwidth Memory (HBM) attached to accelerators/GPUs The 0xEFFFFFFF value follows the E820 extension convention where values above 0x7FFFFFFF are reserved for OEM/firmware-specific use. Linux kernel adopted this value for "soft reserved" memory that should not be used by the OS for general allocation but can be managed by device drivers. Signed-off-by: FangSheng Huang <FangSheng.Huang@amd.com>
2025-12-10OvmfPkg/PlatformInitLib: reserve igvm parameter areaGerd Hoffmann3-0/+30
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2025-10-10OvmfPkg/PlatformInitLib: add sanity checks to igvm codeGerd Hoffmann1-0/+24
With SEV or SEV-ES being active uninitialized memory is random cipher text instead of being zero-initialized. So checking against zero to figure whenever igvm parameters are present or not is not sufficient. Apply more strict sanity checks. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2025-09-29OvmfPkg/igvm: add PlatformIgvmVpCountGerd Hoffmann2-0/+35
Add support for getting the cpu count via IGVM parameter. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2025-09-29OvmfPkg/igvm: handle igvm data hobsGerd Hoffmann3-1/+78
In case HOBs are present in the IGVM data hob area register the memory regions as bootservice data to avoid them being overwritten. Also copy over the HOBs so they can easily be found later using standard HobLib functions. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2025-09-29OvmfPkg/igvm: add igvm memory map support.Gerd Hoffmann3-5/+117
In case a IGVM memory map is present in the parameter area use that when detecting guest memory. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2025-06-20OvmfPkg: Add the ResetVector in TDX MailBoxCeping Sun1-1/+4
Base on ACPI 6.6 Multiprocessor Wakeup Structure, TDVF needs to provide a physical address of the ResetVector to OS. And it should allow the Multiprocessor Wakeup Mailbox to be reset in order to be used once again with a given AP. Signed-off-by: Ceping Sun <cepingx.sun@intel.com> Reviewed-by: Min Xu <min.m.xu@intel.com> Tested-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
2025-06-14OvmfPkg: Add OVMF Mem Debug Log buffer to PEI mem cap/reserve early bufferAaron Young2-0/+17
Add the memory debug log buffer size (pages) to TotalPages in PlatformPei:GetPeiMemoryCap() help ensure we don't run out of memory. Also Reserve the "early" memory debug log buffer. Cc: Gerd Hoffmann <kraxel@redhat.com> Cc: Ard Biesheuvel <ardb+tianocore@kernel.org> Cc: Jiewen Yao <jiewen.yao@intel.com> Signed-off-by: Aaron Young <aaron.young@oracle.com>
2025-03-14OvmfPkg: Use user-specified opt/ovmf/X-PciMmio64Mb value unconditionallyMitchell Augustin1-3/+6
Prior to this change, OVMF considers opt/ovmf/X-PciMmio64Mb the minimum aperture size, allowing us to force the window to be larger but not smaller than what PlatformDynamicMmioWindow calculates. Adjust OVMF so that a smaller value for the aperture is honored. Context: Due to an inefficiency in the way older host kernels manage pfnmaps for guest VM memory ranges [0], guests with large-BAR GPUs passed-through have a very long (multiple minutes) initialization time when the MMIO window advertised by OVMF is sufficiently sized for the passed-through BARs (i.e., the correct OVMF behavior). However, on older distro series such as Ubuntu Jammy, users have benefited from fast guest boot times when OVMF advertised an MMIO window that was too small to accommodate the full BAR, since this resulted in the long PCI initialization process being skipped (and retried later, if pci=realloc pci=nocrs were set). While the root cause is being fully addressed in the upstream kernel [1], the solution relies on huge pfnmap support, which is a substantial series with many ABI changes that is unlikely to land in many LTS and legacy distro kernels, including those of Ubuntu Noble. As a result, the only kernel improvement supported on those kernels is this patch [2], which reduces the extra boot time by about half. Unfortunately, that boot time is still an average of 1-3 minutes longer per-VM-boot than what can be achieved when the host is running a version of OVMF without PlatformDynamicMmioWindow (PDMW) support (introduced in [3]) Since there is no way to force the use of the classic MMIO window size[4] in any version of OVMF after [3], and since we have a use case for such functionality on legacy distro kernels that would yield significant, recurring compute time savings across all impacted VMs, this change to this knob's behavior seems appropriate. [0]: https://lore.kernel.org/all/CAHTA-uYp07FgM6T1OZQKqAdSA5JrZo0ReNEyZgQZub4mDRrV5w@mail.gmail.com/ [1]: https://lore.kernel.org/all/20250205231728.2527186-1-alex.williamson@redhat.com/ [2]: https://lore.kernel.org/all/20250111210652.402845-1-alex.williamson@redhat.com/ [3]: ecb778d [4]: https://edk2.groups.io/g/devel/topic/109651206?p=Created,,,20,1,0,0 Signed-off-by: Mitchell Augustin <mitchell.augustin@canonical.com>
2025-03-07OvmfPkg/PlatformInitLib: fix typoGerd Hoffmann1-1/+1
There is a typo in the FwCfg file name, it's spelled 'tianocore' not 'tianocode'. Fix it. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2024-11-25OvmfPkg/PlatformInitLib: enable x2apic mode if neededGerd Hoffmann2-0/+7
Enable x2apic mode in case the number of possible CPUs (including hotplug-able CPus which are not (yet) online) is larger than 255. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2024-11-23OvmfPkg/PlatformInitLib: Retry NV vars FV check as sharedTom Lendacky2-2/+31
When OVMF is built with SECURE_BOOT_ENABLE, the variable store will be populated and validated in PlatformValidateNvVarStore(). When an SEV or an SEV-ES guest is running, this may be encrypted or unencrypted depending on how the guest was started. If the guest was started with the combined code and variable contents (OVMF.fd), then the variable store will be encrypted. If the guest was started with the separate code and variables contents (OVMF_CODE.fd and OVMF_VARS.fd), then the variable store will be unencrypted. When PlatformValidateNvVarStore() is first invoked, the variable store area is initially mapped encrypted, which may or may not pass the variable validation step depending how the guest was launched. To accomodate this, retry the validation step on failure after remapping the variable store area as unencrypted. Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
2024-09-13OvmfPkg: Use TdInfo instead of fw_cfg to get cpu count in TDVFCeping Sun2-2/+15
Currently TDVF gets cpu count information via fw_cfg, but this information can also be retrieved by calling of TdCall.TdInfo. And TdCall is responded by tdx-module which is trust. So, from the security perspective we shall use TdCall.Tdinfo instead of fw_cfg. Cc: Erdem Aktas <erdemaktas@google.com> Cc: Jiewen Yao <jiewen.yao@intel.com> Cc: Min Xu <min.m.xu@intel.com> Cc: Gerd Hoffmann <kraxel@redhat.com> Cc: Elena Reshetova <elena.reshetova@intel.com> Signed-off-by: Ceping Sun <cepingx.sun@intel.com>
2024-09-03OvmfPkg: Use TdHob instead of e820tables to get memory info in TDVFCeping Sun1-0/+34
Currently, TDVF gets LowMemory and FistNonAddress from the e820tables via fw_cfg, while TD-Hob can also provide the memory info of LowMemory and FistNonAddress. In current stage e820tables are not measured but TD-Hob is measured in early phase by TDVF. So, from the security perspective we'd better use the information from TD-Hob instead of e820tables. Cc: Erdem Aktas <erdemaktas@google.com> Cc: Jiewen Yao <jiewen.yao@intel.com> Cc: Min Xu <min.m.xu@intel.com> Cc: Gerd Hoffmann <kraxel@redhat.com> Cc: Elena Reshetova <elena.reshetova@intel.com> Signed-off-by: Ceping Sun <cepingx.sun@intel.com>
2024-08-31OvmfPkg/PlatformInitLib: allow switching to 4-level pagingGerd Hoffmann3-0/+185
There are a number of mostly older guests such as RHEL-7 which do not support 5-level paging. This patch adds support for switching from 5-level paging mode back to 4-level paging mode. This is done in PEI, after inspecting the address space needed (installed memory and reservations configured via fw_cfg). By default small guests (which need less than 1 TB) will use 4-level paging mode. There is a fw_cfg override though, so it is possible to force the one or the other this way: qemu-system-x86_64 -fw_cfg name=opt/org.tianocode/PagingLevel,string=5 Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2024-08-30OvmfPkg: Refactor PcdSetNxForStack usage in TDVFCeping Sun1-0/+5
In the current code, TDVF reads the PcdSetNxForStack value via fw_cfg , but overwrites it with a fixed value after the read is complete. In this patch, TDVF removes the redundant logic code. Cc: Erdem Aktas <erdemaktas@google.com> Cc: Jiewen Yao <jiewen.yao@intel.com> Cc: Min Xu <min.m.xu@intel.com> Cc: Gerd Hoffmann <kraxel@redhat.com> Cc: Elena Reshetova <elena.reshetova@intel.com> Signed-off-by: Ceping Sun <cepingx.sun@intel.com>
2024-08-29OvmfPkg/PlatformInitLib: Reserve Sec Page Tables in TDVFCeping Sun1-0/+12
In the system boot phase, if OS postpone onlining some CPU until later, the sec page tables could be overwritten. So, TDVF needs to reserve the initial page tables that would be used by APs on Mailbox wakeup. Cc: Erdem Aktas <erdemaktas@google.com> Cc: Jiewen Yao <jiewen.yao@intel.com> Cc: Min Xu <min.m.xu@intel.com> Cc: Gerd Hoffmann <kraxel@redhat.com> Cc: Elena Reshetova <elena.reshetova@intel.com> Cc: Kirill A Shutemov <kirill.shutemov@linux.intel.com> Signed-off-by: Ceping Sun <cepingx.sun@intel.com>
2024-06-26OvmfPkg/Sec: Setup MTRR early in the boot process.Gerd Hoffmann1-5/+5
Specifically before running lzma uncompress of the main firmware volume. This is needed to make sure caching is enabled, otherwise the uncompress can be extremely slow. Adapt the ASSERTs and MTRR setup in PlatformInitLib to the changes. Background: Depending on virtual machine configuration kvm may uses EPT memory types to apply guest MTRR settings. In case MTRRs are disabled kvm will use the uncachable memory type for all mappings. The vmx_get_mt_mask() function in the linux kernel handles this and can be found here: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/arch/x86/kvm/vmx/vmx.c?h=v6.7.1#n7580 In most VM configurations kvm uses MTRR_TYPE_WRBACK unconditionally. In case the VM has a mdev device assigned that is not the case though. Before commit e8aa4c6546ad ("UefiCpuPkg/ResetVector: Cache Disable should not be set by default in CR0") kvm also ended up using MTRR_TYPE_WRBACK due to KVM_X86_QUIRK_CD_NW_CLEARED. After that commit kvm evaluates guest mtrr settings, which why setting up MTRRs early is important now. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2024-06-06OvmfPkg/PlatformInitLib: allow PhysBits larger than 48Gerd Hoffmann1-5/+5
If GuestPhysBits reports more than 48 phys-bits can be used allow to go beyond that limit. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2024-06-06OvmfPkg/PlatformInitLib: add support for GuestPhysBitsGerd Hoffmann1-3/+14
Add support for GuestPhysBits (cpuid 0x80000008, eax, bits 23:16). GuestPhysBits is a field which can be set by the hypervisor to inform the guest about the /usable/ physical address space bits. This can be smaller than the PhysBits of the CPU, for example because of nested paging limitations. OVMF will read GuestPhysBits, log the value, in case it is set use it as upper limit. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2024-05-08OvmfPkg: Use newly defined Unaccepted Memory TypeSachin Ganesh1-4/+4
EFI_RESOURCE_MEMORY_UNACCEPTED has been officially defined in the PI 1.8 specification. So all temporary solutions have been replaced with the actual definition. Cc: Felix Polyudov <felixp@ami.com> Cc: Dhanaraj V <vdhanaraj@ami.com> Cc: Jiewen Yao <jiewen.yao@intel.com> Cc: Liming Gao <gaoliming@byosoft.com.cn> Signed-off-by: Sachin Ganesh <sachinganesh@ami.com> Reviewed-by: Jiewen Yao <jiewen.yao@intel.com> Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com>
2024-05-08OvmfPkg: Refine SmmAccess implementationJiaxin Wu2-0/+11
This patch refines the SmmAccess implementation: 1. SmramMap will be retrieved from the gEfiSmmSmramMemoryGuid instead of original from the TSEG Memory Base register. 2. Remove the gEfiAcpiVariableGuid creation, thus the DESCRIPTOR_INDEX definition can be also cleaned. 3. The gEfiAcpiVariableGuid HOB is moved to the OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf. Cc: Ard Biesheuvel <ardb+tianocore@kernel.org> Cc: Jiewen Yao <jiewen.yao@intel.com> Cc: Gerd Hoffmann <kraxel@redhat.com> Cc: Ray Ni <ray.ni@intel.com> Signed-off-by: Jiaxin Wu <jiaxin.wu@intel.com> Tested-by: Gerd Hoffmann <kraxel@redhat.com> Acked-by: Gerd Hoffmann <kraxel@redhat.com> Acked-by: Jiewen Yao <Jiewen.yao@intel.com>
2024-05-08OvmfPkg/PlatformInitLib: Create gEfiSmmSmramMemoryGuidJiaxin Wu2-40/+90
In the PiSmmCpuDxeSmm driver, SMRAM allocation for SMI handlers and processor Save State areas was traditionally performed using the Smst->AllocatePages() function during the DXE phase. The introduction of SmmRelocationLib changes this process by moving the allocation to the PEI phase, where Smst->AllocatePages() is not accessible. Instead, the allocation is now handled by partitioning the SMRAM based on the information provided by a GUID HOB (identified by gEfiSmmSMramMemoryGuid). This patch is to ensure that OVMF produces the gEfiSmmSMramMemoryGuid HOB, allowing SmmRelocationLib to reserve the necessary memory for SMBASE relocation. More info for the change: 1. The EFI_SMM_SMRAM_MEMORY_GUID HOB, as defined in the PI specification, vol.3, section 5, which is used to describe the SMRAM memory regions supported by the platform. This HOB should be produced during the memory detection phase to align with the PI spec. 2. In addition to the memory reserved for ACPI S3 resume, an increasing number of features require reserving SMRAM for specific purposes, such as SmmRelocation. Other advanced features in Intel platforms also necessitate this. The implementation of these features varies and is entirely dependent on the platform. This is why an increasing number of platforms are adopting the EFI_SMM_SMRAM_MEMORY_GUID HOB for SMRAM description. 3. It is crucial that the SMRAM information remains consistent when retrieved from the platform, whether through the SMM ACCESS PPI/Protocol or the EFI_SMM_SMRAM_MEMORY_GUID HOB. Inconsistencies can lead to unexpected issues, most commonly memory region conflicts. 4. The SMM ACCESS PPI/Protocol can be naturally implemented for general use. The common approach is to utilize the EFI_SMM_SMRAM_MEMORY_GUID HOB. For reference, see the existing implementation in the EDK2 repository at edk2/UefiPayloadPkg/SmmAccessDxe/SmmAccessDxe.inf and edk2-platforms/Silicon/Intel/IntelSiliconPkg/Feature/ SmmAccess/Library/PeiSmmAccessLib/PeiSmmAccessLib.inf. Next patch will refine the OVMF SMM Access to consume the EFI_SMM_SMRAM_MEMORY_GUID HOB. Cc: Ard Biesheuvel <ardb+tianocore@kernel.org> Cc: Jiewen Yao <jiewen.yao@intel.com> Cc: Gerd Hoffmann <kraxel@redhat.com> Cc: Ray Ni <ray.ni@intel.com> Signed-off-by: Jiaxin Wu <jiaxin.wu@intel.com> Tested-by: Gerd Hoffmann <kraxel@redhat.com> Acked-by: Gerd Hoffmann <kraxel@redhat.com> Acked-by: Jiewen Yao <Jiewen.yao@intel.com>
2024-02-29OvmfPkg/PlatformInitLib: add 5-level paging supportGerd Hoffmann1-19/+44
Adjust physical address space logic for la57 mode (5-level paging). With a larger logical address space we can identity-map a larger physical address space. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com> Acked-by: Ard Biesheuvel <ardb@kernel.org> Message-Id: <20240222105407.75735-4-kraxel@redhat.com> Cc: Michael Roth <michael.roth@amd.com> Cc: Jiewen Yao <jiewen.yao@intel.com> Cc: Liming Gao <gaoliming@byosoft.com.cn> Cc: Laszlo Ersek <lersek@redhat.com> Cc: Tom Lendacky <thomas.lendacky@amd.com> Cc: Paolo Bonzini <pbonzini@redhat.com> Cc: Ard Biesheuvel <ardb+tianocore@kernel.org> Cc: Gerd Hoffmann <kraxel@redhat.com> Cc: Min Xu <min.m.xu@intel.com> Cc: Erdem Aktas <erdemaktas@google.com> Cc: Oliver Steffen <osteffen@redhat.com> Cc: Ard Biesheuvel <ardb@kernel.org> [lersek@redhat.com: turn the "Cc:" message headers from Gerd's on-list posting into "Cc:" tags in the commit message, in order to pacify "PatchCheck.py"]
2024-01-15OvmfPkg: Update PlatformAddressWidthInitialization for CloudHvThomas Barrett1-0/+12
In addition to initializing the PhysMemAddressWidth and FirstNonAddress fields in PlatformInfoHob, the PlatformAddressWidthInitialization function is responsible for initializing the PcdPciMmio64Base and PcdPciMmio64Size fields. Currently, for CloudHv guests, the PcdPciMmio64Base is placed immediately after either the 4G boundary or the last RAM region, whichever is greater. We do not change this behavior. Previously, when booting CloudHv guests with greater than 1TiB of high memory, the PlatformAddressWidthInitialization function incorrect calculates the amount of RAM using the overflowed 24-bit CMOS register. Now, we update the PlatformAddressWidthInitialization behavior on CloudHv to scan the E820 entries to detect the amount of RAM. This allows CloudHv guests to boot with greater than 1TiB of RAM Signed-off-by: Thomas Barrett <tbarrett@crusoeenergy.com> Acked-by: Gerd Hoffmann <kraxel@redhat.com>
2024-01-15OvmfPkg: Add CloudHv support to PlatformScanE820 utility function.Thomas Barrett1-30/+65
The PlatformScanE820 utility function is not currently compatible with CloudHv since it relies on the prescence of the "etc/e820" QemuFwCfg file. Update the PlatformScanE820 to iterate through the PVH e820 entries when running on a CloudHv guest. Signed-off-by: Thomas Barrett <tbarrett@crusoeenergy.com> Acked-by: Gerd Hoffmann <kraxel@redhat.com>
2023-06-01OvmfPkg/PlatformInitLib: limit phys-bits to 46.Gerd Hoffmann1-3/+6
Older linux kernels have problems with phys-bits larger than 46, ubuntu 18.04 (kernel 4.15) has been reported to be affected. Reduce phys-bits limit from 47 to 46. Reported-by: Fiona Ebner <f.ebner@proxmox.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2023-05-29OvmfPkg/PlatformInitLib: check PcdUse1GPageTableGerd Hoffmann2-0/+6
If PcdUse1GPageTable is not enabled restrict the physical address space used to 1TB, to limit the amount of memory needed for identity mapping page tables. The same already happens in case the processor has no support for gigabyte pages. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Acked-by: Ard Biesheuvel <ardb@kernel.org>
2023-04-10OvmfPkg: Update code to be more C11 compliant by using __func__Rebecca Cran2-24/+24
__FUNCTION__ is a pre-standard extension that gcc and Visual C++ among others support, while __func__ was standardized in C99. Since it's more standard, replace __FUNCTION__ with __func__ throughout OvmfPkg. Signed-off-by: Rebecca Cran <rebecca@bsdio.com> Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com> Reviewed-by: Ard Biesheuvel <ardb@kernel.org> Reviewed-by: Sunil V L <sunilvl@ventanamicro.com>
2023-03-29OvmfPkg: Replace static struct initialization with ZeroMem callRebecca Cran1-1/+3
Replace the static struct initialization with a call to ZeroMem to avoid generating a call to memset in certain build configurations. Signed-off-by: Rebecca Cran <rebecca@bsdio.com> Reviewed-by: Gerd Hoffmann <kraxel@redhat.com> Reviewed-by: Oliver Smith-Denny <osd@smith-denny.com> Reviewed-by: Jiewen Yao <jiewen.yao@intel.com> Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
2023-03-28OvmfPkg/PlatformInitLib: simplify mtrr setupGerd Hoffmann1-21/+15
With the new mmconfig location at 0xe0000000 above the 32-bit PCI MMIO window we don't have to special-case the mmconfig xbar any more. We'll just add a mtrr uncachable entry starting at MMIO window base and ending at 4GB. Update comments to match reality. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Reviewed-by: Anthony PERARD <anthony.perard@citrix.com>
2023-03-28OvmfPkg/PlatformInitLib: move mmconfig to 0xe0000000Gerd Hoffmann1-5/+5
Also swap the ordering of 32bit PCI MMIO window on q35, i.e. use the room between end of low memory and the start of the mmconfig bar. With a typical configuration on modern qemu with gigabyte-aligned memory the MMIO window start at 0x8000000, sized 1532 MB. In case there is memory present above 0x80000000 the window will start at 0xc0000000 instead, with 512 MB size. This depends on qemu commit 4a4418369d6d ("q35: fix mmconfig and PCI0._CRS"), so it raises the bar for the lowest supported version to qemu 4.1 (released Aug 2019). Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Reviewed-by: Anthony PERARD <anthony.perard@citrix.com>
2023-03-28OvmfPkg/PlatformInitLib: update address space layout commentGerd Hoffmann1-13/+15
Move the commment up so it is placed just before the address space calculations start. Also add q35 memory layout. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Reviewed-by: Anthony PERARD <anthony.perard@citrix.com>
2023-02-04OvmfPkg: Refactor ProcessHobListMin M Xu3-789/+0
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4243 ProcessHobList once was implemented in PlatformInitLib and it walks thru TdHob list and accept un-accepted memories. This patch moves the codes to SecTdxHelperLib and rename ProcessHobList as TdxHelperProcessTdHob After TdxHelperProcessTdHob is introduced, below changes are applied: - Call TdxHelperProcessTdHob instead of ProcessHobList in SecMain.c (in both OvmfPkgX64/Sec and IntelTdx/Sec). - Delete the duplicated codes in PlatformInitLib Cc: Erdem Aktas <erdemaktas@google.com> Cc: James Bottomley <jejb@linux.ibm.com> Cc: Jiewen Yao <jiewen.yao@intel.com> Cc: Gerd Hoffmann <kraxel@redhat.com> Cc: Tom Lendacky <thomas.lendacky@amd.com> Cc: Michael Roth <michael.roth@amd.com> Acked-by: Gerd Hoffmann <kraxel@redhat.com> Reviewed-by: Jiewen Yao <jiewen.yao@intel.com> Signed-off-by: Min Xu <min.m.xu@intel.com>
2023-01-26OvmfPkg: fix BuildResourceDescriptorHob call in PlatformAddHobCB()Gerd Hoffmann1-1/+1
BuildResourceDescriptorHob() expects the third parameter be the Length, not the End address. Fixes: 328076cfdf45 ("OvmfPkg/PlatformInitLib: Add PlatformAddHobCB") Reported-by: Tom Lendacky <thomas.lendacky@amd.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Tested-by: Tom Lendacky <thomas.lendacky@amd.com> Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
2023-01-20OvmfPkg/PlatformInitLib: catch QEMU's CPU hotplug reg block regressionLaszlo Ersek1-0/+87
In QEMU v5.1.0, the CPU hotplug register block misbehaves: the negotiation protocol is (effectively) broken such that it suggests that switching from the legacy interface to the modern interface works, but in reality the switch never happens. The symptom has been witnessed when using TCG acceleration; KVM seems to mask the issue. The issue persists with the following (latest) stable QEMU releases: v5.2.0, v6.2.0, v7.2.0. Currently there is no stable release that addresses the problem. The QEMU bug confuses the Present and Possible counting in function PlatformMaxCpuCountInitialization(), in "OvmfPkg/Library/PlatformInitLib/Platform.c". OVMF ends up with Present=0 Possible=1. This in turn further confuses MpInitLib in UefiCpuPkg (hence firmware-time multiprocessing will be broken). Worse, CPU hot(un)plug with SMI will be summarily broken in OvmfPkg/CpuHotplugSmm, which (considering the privilege level of SMM) is not that great. Detect the issue in PlatformCpuCountBugCheck(), and print an error message and *hang* if the issue is present. Users willing to take risks can override the hang with the experimental QEMU command line option -fw_cfg name=opt/org.tianocore/X-Cpuhp-Bugcheck-Override,string=yes (The "-fw_cfg" QEMU option itself is not experimental; its above argument, as far it concerns the firmware, is experimental.) The problem was originally reported by Ard [0]. We analyzed it at [1] and [2]. A QEMU patch was sent at [3]; now merged as commit dab30fbef389 ("acpi: cpuhp: fix guest-visible maximum access size to the legacy reg block", 2023-01-08), to be included in QEMU v8.0.0. [0] https://bugzilla.tianocore.org/show_bug.cgi?id=4234#c2 [1] https://bugzilla.tianocore.org/show_bug.cgi?id=4234#c3 [2] IO port write width clamping differs between TCG and KVM http://mid.mail-archive.com/aaedee84-d3ed-a4f9-21e7-d221a28d1683@redhat.com https://lists.gnu.org/archive/html/qemu-devel/2023-01/msg00199.html [3] acpi: cpuhp: fix guest-visible maximum access size to the legacy reg block http://mid.mail-archive.com/20230104090138.214862-1-lersek@redhat.com https://lists.gnu.org/archive/html/qemu-devel/2023-01/msg00278.html NOTE: PlatformInitLib is used in the following platform DSCs: OvmfPkg/AmdSev/AmdSevX64.dsc OvmfPkg/CloudHv/CloudHvX64.dsc OvmfPkg/IntelTdx/IntelTdxX64.dsc OvmfPkg/Microvm/MicrovmX64.dsc OvmfPkg/OvmfPkgIa32.dsc OvmfPkg/OvmfPkgIa32X64.dsc OvmfPkg/OvmfPkgX64.dsc but I can only test this change with the last three platforms, running on QEMU. Test results: TCG QEMU OVMF override result patched patched --- ------- ------- -------- -------------------------------------- 0 0 0 0 CPU counts OK (KVM masks the QEMU bug) 0 0 1 0 CPU counts OK (KVM masks the QEMU bug) 0 1 0 0 CPU counts OK (QEMU fix, but KVM masks the QEMU bug anyway) 0 1 1 0 CPU counts OK (QEMU fix, but KVM masks the QEMU bug anyway) 1 0 0 0 boot with broken CPU counts (original QEMU bug) 1 0 1 0 broken CPU count caught (boot hangs) 1 0 1 1 broken CPU count caught, bug check overridden, boot continues 1 1 0 0 CPU counts OK (QEMU fix) 1 1 1 0 CPU counts OK (QEMU fix) Cc: Ard Biesheuvel <ardb+tianocore@kernel.org> Cc: Brijesh Singh <brijesh.singh@amd.com> Cc: Erdem Aktas <erdemaktas@google.com> Cc: Gerd Hoffmann <kraxel@redhat.com> Cc: James Bottomley <jejb@linux.ibm.com> Cc: Jiewen Yao <jiewen.yao@intel.com> Cc: Jordan Justen <jordan.l.justen@intel.com> Cc: Michael Brown <mcb30@ipxe.org> Cc: Min Xu <min.m.xu@intel.com> Cc: Oliver Steffen <osteffen@redhat.com> Cc: Sebastien Boeuf <sebastien.boeuf@intel.com> Cc: Tom Lendacky <thomas.lendacky@amd.com> Bugzilla: https://bugzilla.tianocore.org/show_bug.cgi?id=4250 Signed-off-by: Laszlo Ersek <lersek@redhat.com> Message-Id: <20230119110131.91923-3-lersek@redhat.com> Reviewed-by: Ard Biesheuvel <ardb@kernel.org> Hugely-appreciated-by: Michael Brown <mcb30@ipxe.org> Acked-by: Gerd Hoffmann <kraxel@redhat.com>
2023-01-20OvmfPkg/PlatformInitLib: factor out PlatformCpuCountBugCheck()Laszlo Ersek1-23/+58
Move the QEMU v2.7 reset bug check/workaround to a separate function, as we'll need to detect further issues. Cc: Ard Biesheuvel <ardb+tianocore@kernel.org> Cc: Brijesh Singh <brijesh.singh@amd.com> Cc: Erdem Aktas <erdemaktas@google.com> Cc: Gerd Hoffmann <kraxel@redhat.com> Cc: James Bottomley <jejb@linux.ibm.com> Cc: Jiewen Yao <jiewen.yao@intel.com> Cc: Jordan Justen <jordan.l.justen@intel.com> Cc: Michael Brown <mcb30@ipxe.org> Cc: Min Xu <min.m.xu@intel.com> Cc: Oliver Steffen <osteffen@redhat.com> Cc: Sebastien Boeuf <sebastien.boeuf@intel.com> Cc: Tom Lendacky <thomas.lendacky@amd.com> Bugzilla: https://bugzilla.tianocore.org/show_bug.cgi?id=4250 Signed-off-by: Laszlo Ersek <lersek@redhat.com> Message-Id: <20230119110131.91923-2-lersek@redhat.com> Reviewed-by: Ard Biesheuvel <ardb@kernel.org> Hugely-appreciated-by: Michael Brown <mcb30@ipxe.org> Acked-by: Gerd Hoffmann <kraxel@redhat.com>
2023-01-17OvmfPkg/PlatformInitLib: reorder PlatformQemuUc32BaseInitializationGerd Hoffmann1-8/+8
First handle the cases which do not need know the value of PlatformInfoHob->LowMemory (microvm and cloudhv). Then call PlatformGetSystemMemorySizeBelow4gb() to get LowMemory. Finally handle the cases (q35 and pc) which need to look at LowMemory, Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
2023-01-17OvmfPkg/PlatformInitLib: Add PlatformReservationConflictCBGerd Hoffmann1-0/+46
Add PlatformReservationConflictCB() callback function for use with PlatformScanE820(). It checks whenever the 64bit PCI MMIO window overlaps with a reservation from qemu. If so move down the MMIO window to resolve the conflict. Write any actions done (moving mmio window) to the firmware log with INFO loglevel. This happens on (virtual) AMD machines with 1TB address space, because the AMD IOMMU uses an address window just below 1TB. Bugzilla: https://bugzilla.tianocore.org/show_bug.cgi?id=4251 Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
2023-01-17OvmfPkg/PlatformInitLib: Add PlatformAddHobCBGerd Hoffmann1-138/+48
Add PlatformAddHobCB() callback function for use with PlatformScanE820(). It adds HOBs for high memory and reservations (low memory is handled elsewhere because there are some special cases to consider). This replaces calls to PlatformScanOrAdd64BitE820Ram() with AddHighHobs = TRUE. Write any actions done (adding HOBs, skip unknown types) to the firmware log with INFO loglevel. Also remove PlatformScanOrAdd64BitE820Ram() which is not used any more. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
2023-01-17OvmfPkg/PlatformInitLib: Add PlatformGetLowMemoryCBGerd Hoffmann2-26/+51
Add PlatformGetLowMemoryCB() callback function for use with PlatformScanE820(). It stores the low memory size in PlatformInfoHob->LowMemory. This replaces calls to PlatformScanOrAdd64BitE820Ram() with non-NULL LowMemory. Write any actions done (setting LowMemory) to the firmware log with INFO loglevel. Also change PlatformGetSystemMemorySizeBelow4gb() to likewise set PlatformInfoHob->LowMemory instead of returning the value. Update all Callers to the new convention. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
2023-01-17OvmfPkg/PlatformInitLib: Add PlatformScanE820 and GetFirstNonAddressCBGerd Hoffmann1-23/+93
First step replacing the PlatformScanOrAdd64BitE820Ram() function. Add a PlatformScanE820() function which loops over the e280 entries from FwCfg and calls a callback for each of them. Add a GetFirstNonAddressCB() function which will store the first free address (right after the last RAM block) in PlatformInfoHob->FirstNonAddress. This replaces calls to PlatformScanOrAdd64BitE820Ram() with non-NULL MaxAddress. Write any actions done (setting FirstNonAddress) to the firmware log with INFO loglevel. Also drop local FirstNonAddress variables and use PlatformInfoHob->FirstNonAddress instead everywhere. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
2023-01-12OvmfPkg/PlatformInitLib: fix comment about uncacheable MTRRsLaszlo Ersek1-1/+1
In commit 49edde15230a ("OvmfPkg/PlatformPei: set 32-bit UC area at PciBase / PciExBarBase (pc/q35)", 2019-06-03), I forgot to update the comment. Do it now. Fixes: 49edde15230a5bfd6746225eb95535eaa2ec1ba4 Signed-off-by: Laszlo Ersek <lersek@redhat.com> Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
2022-12-23OvmfPkg/PlatformInitLib: pass through reservations from qemuGerd Hoffmann1-0/+16
qemu uses the etc/e820 fw_cfg file not only for memory, but also for reservations. Handle reservations by adding resource descriptor hobs for them. A typical qemu configuration has a small reservation between lapic and flash: # sudo cat /proc/iomem [ ... ] fee00000-fee00fff : Local APIC feffc000-feffffff : Reserved <= HERE ffc00000-ffffffff : Reserved [ ... ] Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2022-12-21OvmfPkg/PlatformInitLib: Implement multi-core accept memory for TDVFMin M Xu2-49/+363
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4172 TDVF once accepts memory only by BSP. To improve the boot performance this patch introduce the multi-core accpet memory. Multi-core means BSP and APs work together to accept memory. TDVF leverages mailbox to wake up APs. It is not enabled in MpInitLib (Which requires SIPI). So multi-core accept memory cannot leverages MpInitLib to coordinate BSP and APs to work together. So TDVF split the accept memory into 2 phases. - AcceptMemoryForAPsStack: BSP accepts a small piece of memory which is then used by APs to setup stack. We assign a 16KB stack for each AP. So a td-guest with 256 vCPU requires 255*16KB = 4080KB. - AcceptMemory: After above small piece of memory is accepted, BSP commands APs to accept memory by sending AcceptPages command in td-mailbox. Together with the command and accpet-function, the APsStack address is send as well. APs then set the stack and jump to accept-function to accept memory. AcceptMemoryForAPsStack accepts as small memory as possible and then jump to AcceptMemory. It fully takes advantage of BSP/APs to work together. After accept memory is done, the memory region for APsStack is not used anymore. It can be used as other private memory. Because accept-memory is in the very beginning of boot process and it will not impact other phases. Cc: Erdem Aktas <erdemaktas@google.com> Cc: Gerd Hoffmann <kraxel@redhat.com> Cc: James Bottomley <jejb@linux.ibm.com> Cc: Jiewen Yao <jiewen.yao@intel.com> Cc: Tom Lendacky <thomas.lendacky@amd.com> Signed-off-by: Min Xu <min.m.xu@intel.com> Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
2022-12-20OvmfPkg/PlatformInitLib: Fix integrity checking failed of NvVarStoreChun-Yi Lee1-4/+5
In the commit 4f173db8b4 "OvmfPkg/PlatformInitLib: Add functions for EmuVariableNvStore", it introduced a PlatformValidateNvVarStore() function for checking the integrity of NvVarStore. In some cases when the VariableHeader->StartId is VARIABLE_DATA, the VariableHeader->State is not just one of the four primary states: VAR_IN_DELETED_TRANSITION, VAR_DELETED, VAR_HEADER_VALID_ONLY, VAR_ADDED. The state may combined two or three states, e.g. 0x3C = (VAR_IN_DELETED_TRANSITION & VAR_ADDED) & VAR_DELETED or 0x3D = VAR_ADDED & VAR_DELETED When the variable store has those variables, system booting/rebooting will hangs in a ASSERT: NvVarStore Variable header State was invalid. ASSERT /mnt/working/source_code-git/edk2/OvmfPkg/Library/PlatformInitLib/Platform.c(819): ((BOOLEAN)(0==1)) Adding more log to UpdateVariable() and PlatformValidateNvVarStore(), we saw some variables which have 0x3C or 0x3D state in store. e.g. UpdateVariable(), VariableName=BootOrder L1871, State=0000003F <-- VAR_ADDED State &= VAR_DELETED=0000003D FlushHobVariableToFlash(), VariableName=BootOrder ... UpdateVariable(), VariableName=InitialAttemptOrder L1977, State=0000003F State &= VAR_IN_DELETED_TRANSITION=0000003E L2376, State=0000003E State &= VAR_DELETED=0000003C FlushHobVariableToFlash(), VariableName=InitialAttemptOrder ... UpdateVariable(), VariableName=ConIn L1977, State=0000003F State &= VAR_IN_DELETED_TRANSITION=0000003E L2376, State=0000003E State &= VAR_DELETED=0000003C FlushHobVariableToFlash(), VariableName=ConIn ... So, only allowing the four primary states is not enough. This patch changes the falid states list (Follow Jiewen Yao's suggestion): 1. VAR_HEADER_VALID_ONLY (0x7F) - Header added (*) 2. VAR_ADDED (0x3F) - Header + data added 3. VAR_ADDED & VAR_IN_DELETED_TRANSITION (0x3E) - marked as deleted, but still valid, before new data is added. (*) 4. VAR_ADDED & VAR_IN_DELETED_TRANSITION & VAR_DELETED (0x3C) - deleted, after new data is added. 5. VAR_ADDED & VAR_DELETED (0x3D) - deleted directly, without new data. (*) means to support surprise shutdown. And removed (VAR_IN_DELETED_TRANSITION) and (VAR_DELETED) because they are invalid states. v2: Follow Jiewen Yao's suggestion to add the following valid states: VAR_ADDED & VAR_DELETED (0x3D) VAR_ADDED & VAR_IN_DELETED_TRANSITION (0x3E) VAR_ADDED & VAR_IN_DELETED_TRANSITION & VAR_DELETED (0x3C) and removed the following invalid states: VAR_IN_DELETED_TRANSITION VAR_DELETED Signed-off-by: Chun-Yi Lee <jlee@suse.com> Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
2022-12-16OvmfPkg/PlatformInitLib: Transfer GUID Extension HOBSebastien Boeuf1-0/+5
This is required for passing the ACPI tables from the VMM up to the guest OS. They are transferred through this GUID extension. Signed-off-by: Jiaqi Gao <jiaqi.gao@intel.com> Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com> Reviewed-by: Min Xu <min.m.xu@intel.com> Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>