Skip to content

Commit 7e8037b

Browse files
Saurabh Sengarliuw
authored andcommitted
x86/hyperv: Fix the detection of E820_TYPE_PRAM in a Gen2 VM
A Gen2 VM doesn't support legacy PCI/PCIe, so both raw_pci_ops and raw_pci_ext_ops are NULL, and pci_subsys_init() -> pcibios_init() doesn't call pcibios_resource_survey() -> e820__reserve_resources_late(); as a result, any emulated persistent memory of E820_TYPE_PRAM (12) via the kernel parameter memmap=nn[KMG]!ss is not added into iomem_resource and hence can't be detected by register_e820_pmem(). Fix this by directly calling e820__reserve_resources_late() in hv_pci_init(), which is called from arch_initcall(pci_arch_init). It's ok to move a Gen2 VM's e820__reserve_resources_late() from subsys_initcall(pci_subsys_init) to arch_initcall(pci_arch_init) because the code in-between doesn't depend on the E820 resources. e820__reserve_resources_late() depends on e820__reserve_resources(), which has been called earlier from setup_arch(). For a Gen-2 VM, the new hv_pci_init() also adds any memory of E820_TYPE_PMEM (7) into iomem_resource, and acpi_nfit_register_region() -> acpi_nfit_insert_resource() -> region_intersects() returns REGION_INTERSECTS, so the memory of E820_TYPE_PMEM won't get added twice. Changed the local variable "int gen2vm" to "bool gen2vm". Signed-off-by: Saurabh Sengar <[email protected]> Signed-off-by: Dexuan Cui <[email protected]> Signed-off-by: Wei Liu <[email protected]> Message-ID: <[email protected]>
1 parent c380320 commit 7e8037b

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

arch/x86/hyperv/hv_init.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/io.h>
1616
#include <asm/apic.h>
1717
#include <asm/desc.h>
18+
#include <asm/e820/api.h>
1819
#include <asm/sev.h>
1920
#include <asm/ibt.h>
2021
#include <asm/hypervisor.h>
@@ -286,15 +287,31 @@ static int hv_cpu_die(unsigned int cpu)
286287

287288
static int __init hv_pci_init(void)
288289
{
289-
int gen2vm = efi_enabled(EFI_BOOT);
290+
bool gen2vm = efi_enabled(EFI_BOOT);
290291

291292
/*
292-
* For Generation-2 VM, we exit from pci_arch_init() by returning 0.
293-
* The purpose is to suppress the harmless warning:
293+
* A Generation-2 VM doesn't support legacy PCI/PCIe, so both
294+
* raw_pci_ops and raw_pci_ext_ops are NULL, and pci_subsys_init() ->
295+
* pcibios_init() doesn't call pcibios_resource_survey() ->
296+
* e820__reserve_resources_late(); as a result, any emulated persistent
297+
* memory of E820_TYPE_PRAM (12) via the kernel parameter
298+
* memmap=nn[KMG]!ss is not added into iomem_resource and hence can't be
299+
* detected by register_e820_pmem(). Fix this by directly calling
300+
* e820__reserve_resources_late() here: e820__reserve_resources_late()
301+
* depends on e820__reserve_resources(), which has been called earlier
302+
* from setup_arch(). Note: e820__reserve_resources_late() also adds
303+
* any memory of E820_TYPE_PMEM (7) into iomem_resource, and
304+
* acpi_nfit_register_region() -> acpi_nfit_insert_resource() ->
305+
* region_intersects() returns REGION_INTERSECTS, so the memory of
306+
* E820_TYPE_PMEM won't get added twice.
307+
*
308+
* We return 0 here so that pci_arch_init() won't print the warning:
294309
* "PCI: Fatal: No config space access function found"
295310
*/
296-
if (gen2vm)
311+
if (gen2vm) {
312+
e820__reserve_resources_late();
297313
return 0;
314+
}
298315

299316
/* For Generation-1 VM, we'll proceed in pci_arch_init(). */
300317
return 1;

0 commit comments

Comments
 (0)