diff mbox series

[v6,8/9] xen/arm: enable dom0 to use PCI devices with pci-passthrough=no

Message ID 20231109182716.367119-9-stewart.hildebrand@amd.com (mailing list archive)
State New, archived
Headers show
Series SMMU handling for PCIe Passthrough on ARM | expand

Commit Message

Stewart Hildebrand Nov. 9, 2023, 6:27 p.m. UTC
Enable the use of IOMMU + PCI in dom0 without having to specify
"pci-passthrough=yes". We rely on dom0 to initialize the PCI controller
and perform a PHYSDEVOP_pci_device_add call to add each device to SMMU.

Enable pci_init() for initializing Xen's internal PCI subsystem, and
allow PHYSDEVOP_pci_device_add when pci-passthrough is disabled.

Signed-off-by: Stewart Hildebrand <stewart.hildebrand@amd.com>
---
v5->v6:
* new patch - this effectively replaces
  ("Revert "xen/arm: Add cmdline boot option "pci-passthrough = <boolean>""")
---
 xen/arch/arm/pci/pci.c    | 3 ++-
 xen/drivers/pci/physdev.c | 6 ------
 2 files changed, 2 insertions(+), 7 deletions(-)

Comments

Jan Beulich Nov. 10, 2023, 8:53 a.m. UTC | #1
On 09.11.2023 19:27, Stewart Hildebrand wrote:
> --- a/xen/drivers/pci/physdev.c
> +++ b/xen/drivers/pci/physdev.c
> @@ -18,9 +18,6 @@ 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;
> @@ -56,9 +53,6 @@ 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;

This renders is_pci_passthrough_enabled() and Arm-only construct. IOW the
x86 definition of the function should then also be removed, for ending up
dead otherwise.

Jan
Julien Grall Dec. 19, 2023, 7:36 p.m. UTC | #2
Hi Stewart,

On 09/11/2023 18:27, Stewart Hildebrand wrote:
> Enable the use of IOMMU + PCI in dom0 without having to specify
> "pci-passthrough=yes". We rely on dom0 to initialize the PCI controller
> and perform a PHYSDEVOP_pci_device_add call to add each device to SMMU.
> 
> Enable pci_init() for initializing Xen's internal PCI subsystem, and
> allow PHYSDEVOP_pci_device_add when pci-passthrough is disabled.
> 
> Signed-off-by: Stewart Hildebrand <stewart.hildebrand@amd.com>
> ---
> v5->v6:
> * new patch - this effectively replaces
>    ("Revert "xen/arm: Add cmdline boot option "pci-passthrough = <boolean>""")
> ---
>   xen/arch/arm/pci/pci.c    | 3 ++-
>   xen/drivers/pci/physdev.c | 6 ------
>   2 files changed, 2 insertions(+), 7 deletions(-)
> 
> diff --git a/xen/arch/arm/pci/pci.c b/xen/arch/arm/pci/pci.c
> index 78b97beaef12..ba72fbaf1dfc 100644
> --- a/xen/arch/arm/pci/pci.c
> +++ b/xen/arch/arm/pci/pci.c
> @@ -16,6 +16,7 @@
>   #include <xen/device_tree.h>
>   #include <xen/errno.h>
>   #include <xen/init.h>
> +#include <xen/iommu.h>
>   #include <xen/param.h>
>   #include <xen/pci.h>
>   
> @@ -85,7 +86,7 @@ static int __init pci_init(void)
>        * Enable PCI passthrough when has been enabled explicitly
>        * (pci-passthrough=on).
>        */

The comment needs to be updated after ...
> -    if ( !pci_passthrough_enabled )
> +    if ( !is_pci_passthrough_enabled() && !iommu_enabled )

... this change.

>           return 0;
>   
>       pci_segments_init();
> diff --git a/xen/drivers/pci/physdev.c b/xen/drivers/pci/physdev.c
> index 42db3e6d133c..4f3e1a96c0fd 100644
> --- a/xen/drivers/pci/physdev.c
> +++ b/xen/drivers/pci/physdev.c
> @@ -18,9 +18,6 @@ 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;
> -

AFAIU, this means that pci_add_device() can now be reached even if 
pci_segments_init() is not called (this can happen when iommu=false). 
What error will now be returned and how dom0 will behave?

Cheers,
diff mbox series

Patch

diff --git a/xen/arch/arm/pci/pci.c b/xen/arch/arm/pci/pci.c
index 78b97beaef12..ba72fbaf1dfc 100644
--- a/xen/arch/arm/pci/pci.c
+++ b/xen/arch/arm/pci/pci.c
@@ -16,6 +16,7 @@ 
 #include <xen/device_tree.h>
 #include <xen/errno.h>
 #include <xen/init.h>
+#include <xen/iommu.h>
 #include <xen/param.h>
 #include <xen/pci.h>
 
@@ -85,7 +86,7 @@  static int __init pci_init(void)
      * Enable PCI passthrough when has been enabled explicitly
      * (pci-passthrough=on).
      */
-    if ( !pci_passthrough_enabled )
+    if ( !is_pci_passthrough_enabled() && !iommu_enabled )
         return 0;
 
     pci_segments_init();
diff --git a/xen/drivers/pci/physdev.c b/xen/drivers/pci/physdev.c
index 42db3e6d133c..4f3e1a96c0fd 100644
--- a/xen/drivers/pci/physdev.c
+++ b/xen/drivers/pci/physdev.c
@@ -18,9 +18,6 @@  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;
@@ -56,9 +53,6 @@  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;