xen/arm: Add cmdline boot option "pci-passthrough = <boolean>"
authorRahul Singh <rahul.singh@arm.com>
Wed, 6 Oct 2021 17:40:29 +0000 (18:40 +0100)
committerStefano Stabellini <stefano.stabellini@xilinx.com>
Thu, 7 Oct 2021 19:47:25 +0000 (12:47 -0700)
Add cmdline boot option "pci-passthrough = = <boolean>" to enable or
disable the PCI passthrough support on ARM.

Signed-off-by: Rahul Singh <rahul.singh@arm.com>
[stefano: one bool_t/bool correction]
Signed-off-by: Stefano Stabellini <stefano.stabellini@xilinx.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
docs/misc/xen-command-line.pandoc
xen/arch/arm/pci/pci.c
xen/drivers/pci/physdev.c
xen/include/asm-arm/pci.h
xen/include/asm-x86/pci.h

index 5cae4adc584a2aa7702e7539d55b5187af3e1189..b1f7978aa44cf167cc90c0dfc92ca62e3f443b91 100644 (file)
@@ -1819,6 +1819,13 @@ All numbers specified must be hexadecimal ones.
 
 This option can be specified more than once (up to 8 times at present).
 
+### pci-passthrough (arm)
+> `= <boolean>`
+
+> Default: `false`
+
+Flag to enable or disable support for PCI passthrough
+
 ### pcid (x86)
 > `= <boolean> | xpti=<bool>`
 
index e359bab9ea241846f02b41188a0d807d3e7d4d6b..73540045d187ccc6105fe34521f49653102f31ef 100644 (file)
@@ -16,6 +16,7 @@
 #include <xen/device_tree.h>
 #include <xen/errno.h>
 #include <xen/init.h>
+#include <xen/param.h>
 #include <xen/pci.h>
 
 /*
@@ -62,8 +63,19 @@ static int __init acpi_pci_init(void)
 }
 #endif
 
+/* By default pci passthrough is disabled. */
+bool __read_mostly pci_passthrough_enabled;
+boolean_param("pci-passthrough", pci_passthrough_enabled);
+
 static int __init pci_init(void)
 {
+    /*
+     * Enable PCI passthrough when has been enabled explicitly
+     * (pci-passthrough=on).
+     */
+    if ( !pci_passthrough_enabled )
+        return 0;
+
     pci_segments_init();
 
     if ( acpi_disabled )
index 4f3e1a96c0fd214770d3a1261b65a2a1f3919191..42db3e6d133c6e5672ba74813f2802aabc335751 100644 (file)
@@ -18,6 +18,9 @@ ret_t pci_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         struct pci_dev_info pdev_info;
         nodeid_t node = NUMA_NO_NODE;
 
+        if ( !is_pci_passthrough_enabled() )
+            return -EOPNOTSUPP;
+
         ret = -EFAULT;
         if ( copy_from_guest(&add, arg, 1) != 0 )
             break;
@@ -53,6 +56,9 @@ ret_t pci_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
     case PHYSDEVOP_pci_device_remove: {
         struct physdev_pci_device dev;
 
+        if ( !is_pci_passthrough_enabled() )
+            return -EOPNOTSUPP;
+
         ret = -EFAULT;
         if ( copy_from_guest(&dev, arg, 1) != 0 )
             break;
index 7dd9eb3dba613340ff730128ddfc8680b560056c..fb68d63ffe3912673f7dcc1ab3381952d06c9e9c 100644 (file)
 
 #define pci_to_dev(pcidev) (&(pcidev)->arch.dev)
 
+extern bool pci_passthrough_enabled;
+
 /* Arch pci dev struct */
 struct arch_pci_dev {
     struct device dev;
 };
 
+static always_inline bool is_pci_passthrough_enabled(void)
+{
+    return pci_passthrough_enabled;
+}
 #else   /*!CONFIG_HAS_PCI*/
 
 struct arch_pci_dev { };
 
+static always_inline bool is_pci_passthrough_enabled(void)
+{
+    return false;
+}
+
 #endif  /*!CONFIG_HAS_PCI*/
 #endif /* __ARM_PCI_H__ */
index cc05045e9cbfbeb1a430ae1e263db1d6f331c59d..e07695103265056967544cd5d7e7d7b5d2fd7dc1 100644 (file)
@@ -32,4 +32,10 @@ bool_t pci_ro_mmcfg_decode(unsigned long mfn, unsigned int *seg,
 extern int pci_mmcfg_config_num;
 extern struct acpi_mcfg_allocation *pci_mmcfg_config;
 
+/* Unlike ARM, PCI passthrough is always enabled for x86. */
+static always_inline bool is_pci_passthrough_enabled(void)
+{
+    return true;
+}
+
 #endif /* __X86_PCI_H__ */