On 09.06.23 17:38, Juergen Gross wrote:
On 07.06.23 15:12, Christoph Hellwig wrote:
On Mon, May 22, 2023 at 10:37:09AM +0200, Juergen Gross wrote:
In normal cases PCI passthrough in PV guests requires to start the guest
with e820_host=1. So it should be rather easy to limit allocating the
64MB in PV guests to the cases where the memory map has non-RAM regions
especially in the first 1MB of the memory.

This will cover even hotplug cases. The only case not covered would be a
guest started with e820_host=1 even if no PCI passthrough was planned.
But this should be rather rare (at least I hope so).

So is this an ACK for the patch and can we go ahead with it?

As long as above mentioned check of the E820 map is done, yes.

If you want I can send a diff to be folded into your patch on Monday.

Attached is a patch for adding a new flag xen_pv_pci_possible. You can
either add the patch to your series or merge it into your patch 2.

You need to modify your patch like this:

@@ -111,7 +90,10 @@ static inline void __init pci_xen_swiotlb_init(void)
 void __init pci_iommu_alloc(void)
 {
        if (xen_pv_domain()) {
-               if (xen_initial_domain() || x86_swiotlb_enable)
+               if (xen_initial_domain() ||
+                   (IS_ENABLED(CONFIG_XEN_PCIDEV_FRONTEND) &&
+                    xen_pv_pci_possible) ||
+                   x86_swiotlb_enable)
                        pci_xen_swiotlb_init();
                return;
        }


Juergen
From 7e84a88243b57bc90d1ef6bd42661f499886e659 Mon Sep 17 00:00:00 2001
From: Juergen Gross <jgr...@suse.com>
Date: Mon, 12 Jun 2023 09:57:18 +0200
Subject: [PATCH] xen/pci: add flag for PCI passthrough being possible

When running as a Xen PV guests passed through PCI devices only have a
chance to work if the Xen supplied memory map has some PCI space
reserved.

Add a flag xen_pv_pci_possible which will be set in early boot in case
the memory map has at least one area with the type E820_TYPE_RESERVED.

Signed-off-by: Juergen Gross <jgr...@suse.com>
---
 arch/x86/xen/setup.c | 6 ++++++
 include/xen/xen.h    | 6 ++++++
 2 files changed, 12 insertions(+)

diff --git a/arch/x86/xen/setup.c b/arch/x86/xen/setup.c
index c2be3efb2ba0..716f76c41416 100644
--- a/arch/x86/xen/setup.c
+++ b/arch/x86/xen/setup.c
@@ -43,6 +43,9 @@ struct xen_memory_region xen_extra_mem[XEN_EXTRA_MEM_MAX_REGIONS] __initdata;
 /* Number of pages released from the initial allocation. */
 unsigned long xen_released_pages;
 
+/* Memory map would allow PCI passthrough. */
+bool xen_pv_pci_possible;
+
 /* E820 map used during setting up memory. */
 static struct e820_table xen_e820_table __initdata;
 
@@ -804,6 +807,9 @@ char * __init xen_memory_setup(void)
 		chunk_size = size;
 		type = xen_e820_table.entries[i].type;
 
+		if (type == E820_TYPE_RESERVED)
+			xen_pv_pci_possible = true;
+
 		if (type == E820_TYPE_RAM) {
 			if (addr < mem_end) {
 				chunk_size = min(size, mem_end - addr);
diff --git a/include/xen/xen.h b/include/xen/xen.h
index 0efeb652f9b8..5eb0a974a11e 100644
--- a/include/xen/xen.h
+++ b/include/xen/xen.h
@@ -29,6 +29,12 @@ extern bool xen_pvh;
 
 extern uint32_t xen_start_flags;
 
+#ifdef CONFIG_XEN_PV
+extern bool xen_pv_pci_possible;
+#else
+#define xen_pv_pci_possible	0
+#endif
+
 #include <xen/interface/hvm/start_info.h>
 extern struct hvm_start_info pvh_start_info;
 
-- 
2.35.3

Attachment: OpenPGP_0xB0DE9DD628BF132F.asc
Description: OpenPGP public key

Attachment: OpenPGP_signature
Description: OpenPGP digital signature

Reply via email to