All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH AUTOSEL 6.6 01/40] x86/hyperv: Fix the detection of E820_TYPE_PRAM in a Gen2 VM
@ 2023-11-28 21:05 Sasha Levin
  2023-11-28 21:05 ` [PATCH AUTOSEL 6.6 02/40] usb: aqc111: check packet for fixup for true limit Sasha Levin
                   ` (38 more replies)
  0 siblings, 39 replies; 42+ messages in thread
From: Sasha Levin @ 2023-11-28 21:05 UTC (permalink / raw)
  To: linux-kernel, stable
  Cc: Saurabh Sengar, Dexuan Cui, Wei Liu, Sasha Levin, kys, haiyangz,
	tglx, mingo, bp, dave.hansen, x86, linux-hyperv

From: Saurabh Sengar <ssengar@linux.microsoft.com>

[ Upstream commit 7e8037b099c0bbe8f2109dc452dbcab8d400fc53 ]

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 <ssengar@linux.microsoft.com>
Signed-off-by: Dexuan Cui <decui@microsoft.com>
Signed-off-by: Wei Liu <wei.liu@kernel.org>
Message-ID: <1699691867-9827-1-git-send-email-ssengar@linux.microsoft.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 arch/x86/hyperv/hv_init.c | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c
index 21556ad87f4ba..8f3a4d16bb791 100644
--- a/arch/x86/hyperv/hv_init.c
+++ b/arch/x86/hyperv/hv_init.c
@@ -15,6 +15,7 @@
 #include <linux/io.h>
 #include <asm/apic.h>
 #include <asm/desc.h>
+#include <asm/e820/api.h>
 #include <asm/sev.h>
 #include <asm/ibt.h>
 #include <asm/hypervisor.h>
@@ -286,15 +287,31 @@ static int hv_cpu_die(unsigned int cpu)
 
 static int __init hv_pci_init(void)
 {
-	int gen2vm = efi_enabled(EFI_BOOT);
+	bool gen2vm = efi_enabled(EFI_BOOT);
 
 	/*
-	 * For Generation-2 VM, we exit from pci_arch_init() by returning 0.
-	 * The purpose is to suppress the harmless warning:
+	 * A Generation-2 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() here: e820__reserve_resources_late()
+	 * depends on e820__reserve_resources(), which has been called earlier
+	 * from setup_arch(). Note: e820__reserve_resources_late() 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.
+	 *
+	 * We return 0 here so that pci_arch_init() won't print the warning:
 	 * "PCI: Fatal: No config space access function found"
 	 */
-	if (gen2vm)
+	if (gen2vm) {
+		e820__reserve_resources_late();
 		return 0;
+	}
 
 	/* For Generation-1 VM, we'll proceed in pci_arch_init().  */
 	return 1;
-- 
2.42.0


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

end of thread, other threads:[~2023-11-28 21:27 UTC | newest]

Thread overview: 42+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-28 21:05 [PATCH AUTOSEL 6.6 01/40] x86/hyperv: Fix the detection of E820_TYPE_PRAM in a Gen2 VM Sasha Levin
2023-11-28 21:05 ` [PATCH AUTOSEL 6.6 02/40] usb: aqc111: check packet for fixup for true limit Sasha Levin
2023-11-28 21:05 ` [PATCH AUTOSEL 6.6 03/40] stmmac: dwmac-loongson: Add architecture dependency Sasha Levin
2023-11-28 21:05   ` Sasha Levin
2023-11-28 21:05 ` [PATCH AUTOSEL 6.6 04/40] rxrpc: Fix some minor issues with bundle tracing Sasha Levin
2023-11-28 21:05 ` [PATCH AUTOSEL 6.6 05/40] blk-throttle: fix lockdep warning of "cgroup_mutex or RCU read lock required!" Sasha Levin
2023-11-28 21:05 ` [PATCH AUTOSEL 6.6 06/40] blk-cgroup: bypass blkcg_deactivate_policy after destroying Sasha Levin
2023-11-28 21:05 ` [PATCH AUTOSEL 6.6 07/40] bcache: avoid oversize memory allocation by small stripe_size Sasha Levin
2023-11-28 21:05 ` [PATCH AUTOSEL 6.6 08/40] bcache: remove redundant assignment to variable cur_idx Sasha Levin
2023-11-28 21:05 ` [PATCH AUTOSEL 6.6 09/40] bcache: add code comments for bch_btree_node_get() and __bch_btree_node_alloc() Sasha Levin
2023-11-28 21:05 ` [PATCH AUTOSEL 6.6 10/40] bcache: avoid NULL checking to c->root in run_cache_set() Sasha Levin
2023-11-28 21:05 ` [PATCH AUTOSEL 6.6 11/40] nbd: fold nbd config initialization into nbd_alloc_config() Sasha Levin
2023-11-28 21:05 ` [PATCH AUTOSEL 6.6 12/40] nbd: factor out a helper to get nbd_config without holding 'config_lock' Sasha Levin
2023-11-28 21:05 ` [PATCH AUTOSEL 6.6 13/40] nbd: fix null-ptr-dereference while accessing 'nbd->config' Sasha Levin
2023-11-28 21:05 ` [PATCH AUTOSEL 6.6 14/40] nvme-auth: unlock mutex in one place only Sasha Levin
2023-11-28 21:05 ` [PATCH AUTOSEL 6.6 15/40] nvme-auth: set explanation code for failure2 msgs Sasha Levin
2023-11-28 21:05 ` [PATCH AUTOSEL 6.6 16/40] nvme: catch errors from nvme_configure_metadata() Sasha Levin
2023-11-28 21:05 ` [PATCH AUTOSEL 6.6 17/40] selftests/bpf: fix bpf_loop_bench for new callback verification scheme Sasha Levin
2023-11-28 21:05 ` [PATCH AUTOSEL 6.6 18/40] LoongArch: Add dependency between vmlinuz.efi and vmlinux.efi Sasha Levin
2023-11-28 21:05 ` [PATCH AUTOSEL 6.6 19/40] LoongArch: Record pc instead of offset in la_abs relocation Sasha Levin
2023-11-28 21:05 ` [PATCH AUTOSEL 6.6 20/40] LoongArch: Silence the boot warning about 'nokaslr' Sasha Levin
2023-11-28 21:05 ` [PATCH AUTOSEL 6.6 21/40] LoongArch: Mark {dmw,tlb}_virt_to_page() exports as non-GPL Sasha Levin
2023-11-28 21:05 ` [PATCH AUTOSEL 6.6 22/40] LoongArch: Implement constant timer shutdown interface Sasha Levin
2023-11-28 21:05 ` [PATCH AUTOSEL 6.6 23/40] platform/x86: intel_telemetry: Fix kernel doc descriptions Sasha Levin
2023-11-28 21:05 ` [PATCH AUTOSEL 6.6 24/40] HID: mcp2221: Set driver data before I2C adapter add Sasha Levin
2023-11-28 21:05 ` [PATCH AUTOSEL 6.6 25/40] HID: mcp2221: Allow IO to start during probe Sasha Levin
2023-11-28 21:05 ` [PATCH AUTOSEL 6.6 26/40] HID: apple: add Jamesdonkey and A3R to non-apple keyboards list Sasha Levin
2023-11-28 21:05 ` [PATCH AUTOSEL 6.6 27/40] HID: glorious: fix Glorious Model I HID report Sasha Levin
2023-11-28 21:05 ` [PATCH AUTOSEL 6.6 28/40] HID: add ALWAYS_POLL quirk for Apple kb Sasha Levin
2023-11-28 21:05 ` [PATCH AUTOSEL 6.6 29/40] nbd: pass nbd_sock to nbd_read_reply() instead of index Sasha Levin
2023-11-28 21:05 ` [PATCH AUTOSEL 6.6 30/40] HID: hid-asus: reset the backlight brightness level on resume Sasha Levin
2023-11-28 21:05 ` [PATCH AUTOSEL 6.6 31/40] HID: multitouch: Add quirk for HONOR GLO-GXXX touchpad Sasha Levin
2023-11-28 21:05 ` [PATCH AUTOSEL 6.6 32/40] nfc: virtual_ncidev: Add variable to check if ndev is running Sasha Levin
2023-11-28 21:05 ` [PATCH AUTOSEL 6.6 33/40] scripts/checkstack.pl: match all stack sizes for s390 Sasha Levin
2023-11-28 21:05 ` [PATCH AUTOSEL 6.6 34/40] asm-generic: qspinlock: fix queued_spin_value_unlocked() implementation Sasha Levin
2023-11-28 21:05 ` [PATCH AUTOSEL 6.6 35/40] eventfs: Do not allow NULL parent to eventfs_start_creating() Sasha Levin
2023-11-28 21:05 ` [PATCH AUTOSEL 6.6 36/40] net: usb: qmi_wwan: claim interface 4 for ZTE MF290 Sasha Levin
2023-11-28 21:05 ` [PATCH AUTOSEL 6.6 37/40] smb: client: implement ->query_reparse_point() for SMB1 Sasha Levin
2023-11-28 21:05 ` [PATCH AUTOSEL 6.6 38/40] smb: client: introduce ->parse_reparse_point() Sasha Levin
2023-11-28 21:05 ` [PATCH AUTOSEL 6.6 39/40] smb: client: set correct file type from NFS reparse points Sasha Levin
2023-11-28 21:05 ` [PATCH AUTOSEL 6.6 40/40] arm64: add dependency between vmlinuz.efi and Image Sasha Levin
2023-11-28 21:05   ` Sasha Levin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.