Skip to contentSkip to conversation

xen: Remove dependency between pciback and privcmd

PATCH Superseded Jiqian Chen 4 participants 7 messages Oct 10, 2024 Xen hypervisor interface

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 xen: Remove dependency between pciback and privcmd

Commit 2fae6bb7be32 ("xen/privcmd: Add new syscall to get gsi from dev") adds a weak reverse dependency to the config XEN_PRIVCMD definition, that dependency causes xen-privcmd can't be loaded on domU, because dependent xen-pciback is always not be loaded successfully on domU.

To solve above problem, remove that dependency, and do not call pcistub_get_gsi_from_sbdf() directly, instead add a hook in drivers/xen/apci.c, xen-pciback register the real call function, then in privcmd_ioctl_pcidev_get_gsi call that hook.

Fixes 2fae6bb7be32 ("xen/privcmd: Add new syscall to get gsi from dev")

---
v1->v2 changes:
Added hook xen_acpi_get_gsi_from_sbdf.
Changed pcistub_get_gsi_from_sbdf to static and pciback register it as the real hook function.

---
 drivers/xen/Kconfig                |  1 -
 drivers/xen/acpi.c                 | 17 +++++++++++++++++
 drivers/xen/privcmd.c              |  6 ++----
 drivers/xen/xen-pciback/pci_stub.c |  4 ++--
 include/xen/acpi.h                 | 12 ++++--------
 5 files changed, 25 insertions(+), 15 deletions(-)
drivers/xen/Kconfig +0 -1
index 72ddee4c1544..f7d6f47971fd 100644
@@ -261,7 +261,6 @@ config XEN_SCSI_BACKEND
 config XEN_PRIVCMD
 	tristate "Xen hypercall passthrough driver"
 	depends on XEN
-	imply XEN_PCIDEV_BACKEND
 	default m
 	help
 	  The hypercall passthrough driver allows privileged user programs to
drivers/xen/acpi.c +17 -0
index 9e2096524fbc..0bff2f3a87d2 100644
@@ -125,3 +125,20 @@ int xen_acpi_get_gsi_info(struct pci_dev *dev,
 	return 0;
 }
 EXPORT_SYMBOL_GPL(xen_acpi_get_gsi_info);
+
+get_gsi_from_sbdf_t get_gsi_from_sbdf = NULL;
+
+void xen_acpi_register_get_gsi_func(get_gsi_from_sbdf_t func)
+{
+	get_gsi_from_sbdf = func;
+}
+EXPORT_SYMBOL_GPL(xen_acpi_register_get_gsi_func);
+
+int xen_acpi_get_gsi_from_sbdf(u32 sbdf)
+{
+	if (get_gsi_from_sbdf)
+		return get_gsi_from_sbdf(sbdf);
+
+	return -EINVAL;
+}
+EXPORT_SYMBOL_GPL(xen_acpi_get_gsi_from_sbdf);
\ No newline at end of file
drivers/xen/privcmd.c +2 -4
index 3273cb8c2a66..4f75bc876454 100644
@@ -850,15 +850,13 @@ static long privcmd_ioctl_mmap_resource(struct file *file,
 static long privcmd_ioctl_pcidev_get_gsi(struct file *file, void __user *udata)
 {
 #if defined(CONFIG_XEN_ACPI)
-	int rc = -EINVAL;
+	int rc;
 	struct privcmd_pcidev_get_gsi kdata;
 
 	if (copy_from_user(&kdata, udata, sizeof(kdata)))
 		return -EFAULT;
 
-	if (IS_REACHABLE(CONFIG_XEN_PCIDEV_BACKEND))
-		rc = pcistub_get_gsi_from_sbdf(kdata.sbdf);
-
+	rc = xen_acpi_get_gsi_from_sbdf(kdata.sbdf);
 	if (rc < 0)
 		return rc;
 
drivers/xen/xen-pciback/pci_stub.c +2 -2
index 2f3da5ac62cd..900e6199eec7 100644
@@ -227,7 +227,7 @@ static struct pci_dev *pcistub_device_get_pci_dev(struct xen_pcibk_device *pdev,
 }
 
 #ifdef CONFIG_XEN_ACPI
-int pcistub_get_gsi_from_sbdf(unsigned int sbdf)
+static int pcistub_get_gsi_from_sbdf(unsigned int sbdf)
 {
 	struct pcistub_device *psdev;
 	int domain = (sbdf >> 16) & 0xffff;
@@ -242,7 +242,6 @@ int pcistub_get_gsi_from_sbdf(unsigned int sbdf)
 
 	return psdev->gsi;
 }
-EXPORT_SYMBOL_GPL(pcistub_get_gsi_from_sbdf);
 #endif
 
 struct pci_dev *pcistub_get_pci_dev_by_slot(struct xen_pcibk_device *pdev,
@@ -484,6 +483,7 @@ static int pcistub_init_device(struct pcistub_device *psdev)
 		if (err)
 			goto config_release;
 		psdev->gsi = gsi;
+		xen_acpi_register_get_gsi_func(pcistub_get_gsi_from_sbdf);
 	}
 #endif
 
include/xen/acpi.h +4 -8
index daa96a22d257..ef4f70e4a557 100644
@@ -91,13 +91,9 @@ static inline int xen_acpi_get_gsi_info(struct pci_dev *dev,
 }
 #endif
 
-#ifdef CONFIG_XEN_PCI_STUB
-int pcistub_get_gsi_from_sbdf(unsigned int sbdf);
-#else
-static inline int pcistub_get_gsi_from_sbdf(unsigned int sbdf)
-{
-	return -1;
-}
-#endif
+typedef int (*get_gsi_from_sbdf_t)(u32 sbdf);
+
+void xen_acpi_register_get_gsi_func(get_gsi_from_sbdf_t func);
+int xen_acpi_get_gsi_from_sbdf(unsigned int sbdf);
 
 #endif	/* _XEN_ACPI_H */
Signature · 1 line
2.34.1
#1 lore raw
Quoted 11 lines · Jiqian Chen
drivers/xen/acpi.c +5 -0
@@ -125,3 +125,20 @@ int xen_acpi_get_gsi_info(struct pci_dev *dev,
 	return 0;
 }
 EXPORT_SYMBOL_GPL(xen_acpi_get_gsi_info);
+
+get_gsi_from_sbdf_t get_gsi_from_sbdf = NULL;
+
+void xen_acpi_register_get_gsi_func(get_gsi_from_sbdf_t func)
+{

drivers/xen/acpi.c int xen_acpi_get_gsi_info(struct pci_dev *dev, · line 142

Quoted 10 lines
drivers/xen/acpi.c +10 -0
+	get_gsi_from_sbdf = func;
+}
+EXPORT_SYMBOL_GPL(xen_acpi_register_get_gsi_func);
+
+int xen_acpi_get_gsi_from_sbdf(u32 sbdf)
+{
+	if (get_gsi_from_sbdf)
+		return get_gsi_from_sbdf(sbdf);
+
+	return -EINVAL;

Perhaps better -EOPNOTSUPP?

drivers/xen/acpi.c int xen_acpi_get_gsi_info(struct pci_dev *dev, · line 144

Quoted 3 lines
drivers/xen/acpi.c +2 -0
+}
+EXPORT_SYMBOL_GPL(xen_acpi_get_gsi_from_sbdf);
\ No newline at end of file

Can you please take care of this as well while touching the file? Or maybe you are doing so, but the diff doesn't show it properly?

drivers/xen/acpi.c static int pcistub_init_device(struct pcistub_device *psdev) · line 488

Quoted 7 lines
drivers/xen/acpi.c +1 -0
@@ -484,6 +483,7 @@ static int pcistub_init_device(struct pcistub_device *psdev)
 		if (err)
 			goto config_release;
 		psdev->gsi = gsi;
+		xen_acpi_register_get_gsi_func(pcistub_get_gsi_from_sbdf);
 	}
 #endif

Why here rather than directly in xen_pcibk_init()? And why no change to xen_pcibk_cleanup() to remove the hook again on unload? Which will then raise the question of possible race conditions.

Jan

#2 lore raw
Quoted 16 lines · Jan Beulich
Quoted 15 lines · Jiqian Chen
drivers/xen/acpi.c +9 -0
@@ -125,3 +125,20 @@ int xen_acpi_get_gsi_info(struct pci_dev *dev,
 	return 0;
 }
 EXPORT_SYMBOL_GPL(xen_acpi_get_gsi_info);
+
+get_gsi_from_sbdf_t get_gsi_from_sbdf = NULL;
+
+void xen_acpi_register_get_gsi_func(get_gsi_from_sbdf_t func)
+{
+	get_gsi_from_sbdf = func;
+}
+EXPORT_SYMBOL_GPL(xen_acpi_register_get_gsi_func);
+
Quoted 8 lines

drivers/xen/acpi.c int xen_acpi_get_gsi_info(struct pci_dev *dev, · line 142

Quoted 6 lines
drivers/xen/acpi.c +6 -0
+int xen_acpi_get_gsi_from_sbdf(u32 sbdf)
+{
+	if (get_gsi_from_sbdf)
+		return get_gsi_from_sbdf(sbdf);
+
+	return -EINVAL;

Perhaps better -EOPNOTSUPP?

OK, will change.

Quoted 7 lines

drivers/xen/acpi.c int xen_acpi_get_gsi_info(struct pci_dev *dev, · line 144

Quoted 4 lines
drivers/xen/acpi.c +2 -0
+}
+EXPORT_SYMBOL_GPL(xen_acpi_get_gsi_from_sbdf);
\ No newline at end of file

Can you please take care of this as well while touching the file? Or maybe you are doing so, but the diff doesn't show it properly?

Yes, will change.

Quoted 12 lines

drivers/xen/acpi.c static int pcistub_init_device(struct pcistub_device *psdev) · line 488

Quoted 8 lines
drivers/xen/acpi.c +1 -0
@@ -484,6 +483,7 @@ static int pcistub_init_device(struct pcistub_device *psdev)
 		if (err)
 			goto config_release;
 		psdev->gsi = gsi;
+		xen_acpi_register_get_gsi_func(pcistub_get_gsi_from_sbdf);
 	}
 #endif

Why here rather than directly in xen_pcibk_init()? And why no change to xen_pcibk_cleanup() to remove the hook again on unload? Which will then raise the question of possible race conditions.

You are right, will change in next version.

Quoted 2 lines

Jan

Signature · 2 lines
Best regards,
Jiqian Chen.
maintainer
#3 lore raw
In reply to Jiqian Chen
Quoted 107 lines · Jiqian Chen

Commit 2fae6bb7be32 ("xen/privcmd: Add new syscall to get gsi from dev") adds a weak reverse dependency to the config XEN_PRIVCMD definition, that dependency causes xen-privcmd can't be loaded on domU, because dependent xen-pciback is always not be loaded successfully on domU.

To solve above problem, remove that dependency, and do not call pcistub_get_gsi_from_sbdf() directly, instead add a hook in drivers/xen/apci.c, xen-pciback register the real call function, then in privcmd_ioctl_pcidev_get_gsi call that hook.

Fixes 2fae6bb7be32 ("xen/privcmd: Add new syscall to get gsi from dev")

---
v1->v2 changes:
Added hook xen_acpi_get_gsi_from_sbdf.
Changed pcistub_get_gsi_from_sbdf to static and pciback register it as the real hook function.

---
  drivers/xen/Kconfig                |  1 -
  drivers/xen/acpi.c                 | 17 +++++++++++++++++
  drivers/xen/privcmd.c              |  6 ++----
  drivers/xen/xen-pciback/pci_stub.c |  4 ++--
  include/xen/acpi.h                 | 12 ++++--------
  5 files changed, 25 insertions(+), 15 deletions(-)
drivers/xen/Kconfig +0 -1
index 72ddee4c1544..f7d6f47971fd 100644
@@ -261,7 +261,6 @@ config XEN_SCSI_BACKEND
  config XEN_PRIVCMD
  	tristate "Xen hypercall passthrough driver"
  	depends on XEN
-	imply XEN_PCIDEV_BACKEND
  	default m
  	help
  	  The hypercall passthrough driver allows privileged user programs to
drivers/xen/acpi.c +17 -0
index 9e2096524fbc..0bff2f3a87d2 100644
@@ -125,3 +125,20 @@ int xen_acpi_get_gsi_info(struct pci_dev *dev,
  	return 0;
  }
  EXPORT_SYMBOL_GPL(xen_acpi_get_gsi_info);
+
+get_gsi_from_sbdf_t get_gsi_from_sbdf = NULL;
+
+void xen_acpi_register_get_gsi_func(get_gsi_from_sbdf_t func)
+{
+	get_gsi_from_sbdf = func;
+}
+EXPORT_SYMBOL_GPL(xen_acpi_register_get_gsi_func);
+
+int xen_acpi_get_gsi_from_sbdf(u32 sbdf)
+{
+	if (get_gsi_from_sbdf)
+		return get_gsi_from_sbdf(sbdf);
+
+	return -EINVAL;
+}
+EXPORT_SYMBOL_GPL(xen_acpi_get_gsi_from_sbdf);
\ No newline at end of file
drivers/xen/privcmd.c +2 -4
index 3273cb8c2a66..4f75bc876454 100644
@@ -850,15 +850,13 @@ static long privcmd_ioctl_mmap_resource(struct file *file,
  static long privcmd_ioctl_pcidev_get_gsi(struct file *file, void __user *udata)
  {
  #if defined(CONFIG_XEN_ACPI)
-	int rc = -EINVAL;
+	int rc;
  	struct privcmd_pcidev_get_gsi kdata;
 
  	if (copy_from_user(&kdata, udata, sizeof(kdata)))
  		return -EFAULT;
 
-	if (IS_REACHABLE(CONFIG_XEN_PCIDEV_BACKEND))
-		rc = pcistub_get_gsi_from_sbdf(kdata.sbdf);
-
+	rc = xen_acpi_get_gsi_from_sbdf(kdata.sbdf);
  	if (rc < 0)
  		return rc;
 
drivers/xen/xen-pciback/pci_stub.c +1 -2
index 2f3da5ac62cd..900e6199eec7 100644
@@ -227,7 +227,7 @@ static struct pci_dev *pcistub_device_get_pci_dev(struct xen_pcibk_device *pdev,
  }
 
  #ifdef CONFIG_XEN_ACPI
-int pcistub_get_gsi_from_sbdf(unsigned int sbdf)
+static int pcistub_get_gsi_from_sbdf(unsigned int sbdf)
  {
  	struct pcistub_device *psdev;
  	int domain = (sbdf >> 16) & 0xffff;
@@ -242,7 +242,6 @@ int pcistub_get_gsi_from_sbdf(unsigned int sbdf)
 
  	return psdev->gsi;
  }
-EXPORT_SYMBOL_GPL(pcistub_get_gsi_from_sbdf);
  #endif
 
  struct pci_dev *pcistub_get_pci_dev_by_slot(struct xen_pcibk_device *pdev,

drivers/xen/xen-pciback/pci_stub.c static int pcistub_init_device(struct pcistub_device *psdev) · line 486

Quoted 4 lines
drivers/xen/xen-pciback/pci_stub.c +1 -0
@@ -484,6 +483,7 @@ static int pcistub_init_device(struct pcistub_device *psdev)
  		if (err)
  			goto config_release;
  		psdev->gsi = gsi;
+		xen_acpi_register_get_gsi_func(pcistub_get_gsi_from_sbdf);

I don't think this is the right place for registering the function.

It should be done at the end of xen_pcibk_init() (guarded with CONFIG_XEN_ACPI).

Additionally you should reset the function pointer NULL in xen_pcibk_cleanup().

Juergen

#4 lore raw
Quoted 109 lines · Jürgen Groß
Quoted 101 lines · Jiqian Chen

Commit 2fae6bb7be32 ("xen/privcmd: Add new syscall to get gsi from dev") adds a weak reverse dependency to the config XEN_PRIVCMD definition, that dependency causes xen-privcmd can't be loaded on domU, because dependent xen-pciback is always not be loaded successfully on domU.

To solve above problem, remove that dependency, and do not call pcistub_get_gsi_from_sbdf() directly, instead add a hook in drivers/xen/apci.c, xen-pciback register the real call function, then in privcmd_ioctl_pcidev_get_gsi call that hook.

Fixes 2fae6bb7be32 ("xen/privcmd: Add new syscall to get gsi from dev")

---
v1->v2 changes:
Added hook xen_acpi_get_gsi_from_sbdf.
Changed pcistub_get_gsi_from_sbdf to static and pciback register it as the real hook function.
---
  drivers/xen/Kconfig                |  1 -
  drivers/xen/acpi.c                 | 17 +++++++++++++++++ drivers/xen/privcmd.c              |  6 ++---- drivers/xen/xen-pciback/pci_stub.c |  4 ++--
  include/xen/acpi.h                 | 12 ++++--------

  5 files changed, 25 insertions(+), 15 deletions(-)
drivers/xen/Kconfig +0 -0
index 72ddee4c1544..f7d6f47971fd 100644
@@ -261,7 +261,6 @@ config XEN_SCSI_BACKEND

  config XEN_PRIVCMD
      tristate "Xen hypercall passthrough driver"
      depends on XEN
-    imply XEN_PCIDEV_BACKEND
      default m
      help
        The hypercall passthrough driver allows privileged user programs to

drivers/xen/acpi.c +17 -0
index 9e2096524fbc..0bff2f3a87d2 100644
@@ -125,3 +125,20 @@ int xen_acpi_get_gsi_info(struct pci_dev *dev,
       return 0;
   }
   EXPORT_SYMBOL_GPL(xen_acpi_get_gsi_info);
+
+get_gsi_from_sbdf_t get_gsi_from_sbdf = NULL;
+
+void xen_acpi_register_get_gsi_func(get_gsi_from_sbdf_t func)
+{
+    get_gsi_from_sbdf = func;
+}
+EXPORT_SYMBOL_GPL(xen_acpi_register_get_gsi_func);
+
+int xen_acpi_get_gsi_from_sbdf(u32 sbdf)
+{
+    if (get_gsi_from_sbdf)
+        return get_gsi_from_sbdf(sbdf);
+
+    return -EINVAL;
+}
+EXPORT_SYMBOL_GPL(xen_acpi_get_gsi_from_sbdf);
\ No newline at end of file
drivers/xen/privcmd.c +2 -3
index 3273cb8c2a66..4f75bc876454 100644
@@ -850,15 +850,13 @@ static long privcmd_ioctl_mmap_resource(struct file *file,
   static long privcmd_ioctl_pcidev_get_gsi(struct file *file, void __user *udata)
   {
   #if defined(CONFIG_XEN_ACPI)
-    int rc = -EINVAL;
+    int rc;
       struct privcmd_pcidev_get_gsi kdata;
         if (copy_from_user(&kdata, udata, sizeof(kdata)))
           return -EFAULT;
   -    if (IS_REACHABLE(CONFIG_XEN_PCIDEV_BACKEND))
-        rc = pcistub_get_gsi_from_sbdf(kdata.sbdf);
-
+    rc = xen_acpi_get_gsi_from_sbdf(kdata.sbdf);
       if (rc < 0)
           return rc;

  diff --git a/drivers/xen/xen-pciback/pci_stub.c b/drivers/xen/xen-pciback/pci_stub.c index 2f3da5ac62cd..900e6199eec7 100644

drivers/xen/xen-pciback/pci_stub.c +1 -2
@@ -227,7 +227,7 @@ static struct pci_dev *pcistub_device_get_pci_dev(struct xen_pcibk_device *pdev,
   }
     #ifdef CONFIG_XEN_ACPI
-int pcistub_get_gsi_from_sbdf(unsigned int sbdf)
+static int pcistub_get_gsi_from_sbdf(unsigned int sbdf)
   {
       struct pcistub_device *psdev;
       int domain = (sbdf >> 16) & 0xffff;
@@ -242,7 +242,6 @@ int pcistub_get_gsi_from_sbdf(unsigned int sbdf)
         return psdev->gsi;
   }
-EXPORT_SYMBOL_GPL(pcistub_get_gsi_from_sbdf);
   #endif
     struct pci_dev *pcistub_get_pci_dev_by_slot(struct xen_pcibk_device *pdev,

drivers/xen/xen-pciback/pci_stub.c static int pcistub_init_device(struct pcistub_device *psdev) · line 486

Quoted 4 lines
drivers/xen/xen-pciback/pci_stub.c +1 -0
@@ -484,6 +483,7 @@ static int pcistub_init_device(struct pcistub_device *psdev)
           if (err)
               goto config_release;
           psdev->gsi = gsi;
+        xen_acpi_register_get_gsi_func(pcistub_get_gsi_from_sbdf);

I don't think this is the right place for registering the function.

Quoted 3 lines

It should be done at the end of xen_pcibk_init() (guarded with CONFIG_XEN_ACPI).

Additionally you should reset the function pointer NULL in xen_pcibk_cleanup().

Should I need to add a new unregister function to reset, or just pass NULL to xen_acpi_register_get_gsi_func ?

Quoted 3 lines

Juergen

Signature · 2 lines
Best regards,
Jiqian Chen.
maintainer
#5 lore raw
Quoted 110 lines · Jiqian
Quoted 109 lines · Jürgen Groß
Quoted 101 lines · Jiqian Chen

Commit 2fae6bb7be32 ("xen/privcmd: Add new syscall to get gsi from dev") adds a weak reverse dependency to the config XEN_PRIVCMD definition, that dependency causes xen-privcmd can't be loaded on domU, because dependent xen-pciback is always not be loaded successfully on domU.

To solve above problem, remove that dependency, and do not call pcistub_get_gsi_from_sbdf() directly, instead add a hook in drivers/xen/apci.c, xen-pciback register the real call function, then in privcmd_ioctl_pcidev_get_gsi call that hook.

Fixes 2fae6bb7be32 ("xen/privcmd: Add new syscall to get gsi from dev")

---
v1->v2 changes:
Added hook xen_acpi_get_gsi_from_sbdf.
Changed pcistub_get_gsi_from_sbdf to static and pciback register it as the real hook function.

---
   drivers/xen/Kconfig                |  1 -
   drivers/xen/acpi.c                 | 17 +++++++++++++++++
   drivers/xen/privcmd.c              |  6 ++----
   drivers/xen/xen-pciback/pci_stub.c |  4 ++--
   include/xen/acpi.h                 | 12 ++++--------
   5 files changed, 25 insertions(+), 15 deletions(-)
drivers/xen/Kconfig +0 -1
index 72ddee4c1544..f7d6f47971fd 100644
@@ -261,7 +261,6 @@ config XEN_SCSI_BACKEND
   config XEN_PRIVCMD
       tristate "Xen hypercall passthrough driver"
       depends on XEN
-    imply XEN_PCIDEV_BACKEND
       default m
       help
         The hypercall passthrough driver allows privileged user programs to
drivers/xen/acpi.c +17 -0
index 9e2096524fbc..0bff2f3a87d2 100644
@@ -125,3 +125,20 @@ int xen_acpi_get_gsi_info(struct pci_dev *dev,
       return 0;
   }
   EXPORT_SYMBOL_GPL(xen_acpi_get_gsi_info);
+
+get_gsi_from_sbdf_t get_gsi_from_sbdf = NULL;
+
+void xen_acpi_register_get_gsi_func(get_gsi_from_sbdf_t func)
+{
+    get_gsi_from_sbdf = func;
+}
+EXPORT_SYMBOL_GPL(xen_acpi_register_get_gsi_func);
+
+int xen_acpi_get_gsi_from_sbdf(u32 sbdf)
+{
+    if (get_gsi_from_sbdf)
+        return get_gsi_from_sbdf(sbdf);
+
+    return -EINVAL;
+}
+EXPORT_SYMBOL_GPL(xen_acpi_get_gsi_from_sbdf);
\ No newline at end of file
drivers/xen/privcmd.c +2 -3
index 3273cb8c2a66..4f75bc876454 100644
@@ -850,15 +850,13 @@ static long privcmd_ioctl_mmap_resource(struct file *file,
   static long privcmd_ioctl_pcidev_get_gsi(struct file *file, void __user *udata)
   {
   #if defined(CONFIG_XEN_ACPI)
-    int rc = -EINVAL;
+    int rc;
       struct privcmd_pcidev_get_gsi kdata;
         if (copy_from_user(&kdata, udata, sizeof(kdata)))
           return -EFAULT;
   -    if (IS_REACHABLE(CONFIG_XEN_PCIDEV_BACKEND))
-        rc = pcistub_get_gsi_from_sbdf(kdata.sbdf);
-
+    rc = xen_acpi_get_gsi_from_sbdf(kdata.sbdf);
       if (rc < 0)
           return rc;
   diff --git a/drivers/xen/xen-pciback/pci_stub.c b/drivers/xen/xen-pciback/pci_stub.c

index 2f3da5ac62cd..900e6199eec7 100644

drivers/xen/xen-pciback/pci_stub.c +1 -2
@@ -227,7 +227,7 @@ static struct pci_dev *pcistub_device_get_pci_dev(struct xen_pcibk_device *pdev,
   }
     #ifdef CONFIG_XEN_ACPI
-int pcistub_get_gsi_from_sbdf(unsigned int sbdf)
+static int pcistub_get_gsi_from_sbdf(unsigned int sbdf)
   {
       struct pcistub_device *psdev;
       int domain = (sbdf >> 16) & 0xffff;
@@ -242,7 +242,6 @@ int pcistub_get_gsi_from_sbdf(unsigned int sbdf)
         return psdev->gsi;
   }
-EXPORT_SYMBOL_GPL(pcistub_get_gsi_from_sbdf);
   #endif
     struct pci_dev *pcistub_get_pci_dev_by_slot(struct xen_pcibk_device *pdev,

drivers/xen/xen-pciback/pci_stub.c static int pcistub_init_device(struct pcistub_device *psdev) · line 486

Quoted 4 lines
drivers/xen/xen-pciback/pci_stub.c +1 -0
@@ -484,6 +483,7 @@ static int pcistub_init_device(struct pcistub_device *psdev)
           if (err)
               goto config_release;
           psdev->gsi = gsi;
+        xen_acpi_register_get_gsi_func(pcistub_get_gsi_from_sbdf);

I don't think this is the right place for registering the function.

Quoted 4 lines
Quoted 3 lines

It should be done at the end of xen_pcibk_init() (guarded with CONFIG_XEN_ACPI).

Additionally you should reset the function pointer NULL in xen_pcibk_cleanup().

Should I need to add a new unregister function to reset, or just pass NULL to xen_acpi_register_get_gsi_func ?

I think passing NULL is fine.

But you'll need some kind of locking to avoid a race between a call of the hook and parallel unloading the pciback module.

Juergen

#6 lore raw
In reply to Jiqian Chen
Quoted 42 lines · Jiqian Chen

Commit 2fae6bb7be32 ("xen/privcmd: Add new syscall to get gsi from dev") adds a weak reverse dependency to the config XEN_PRIVCMD definition, that dependency causes xen-privcmd can't be loaded on domU, because dependent xen-pciback is always not be loaded successfully on domU.

To solve above problem, remove that dependency, and do not call pcistub_get_gsi_from_sbdf() directly, instead add a hook in drivers/xen/apci.c, xen-pciback register the real call function, then in privcmd_ioctl_pcidev_get_gsi call that hook.

Fixes 2fae6bb7be32 ("xen/privcmd: Add new syscall to get gsi from dev")

---
v1->v2 changes:
Added hook xen_acpi_get_gsi_from_sbdf.
Changed pcistub_get_gsi_from_sbdf to static and pciback register it as the real hook function.

---
 drivers/xen/Kconfig                |  1 -
 drivers/xen/acpi.c                 | 17 +++++++++++++++++
 drivers/xen/privcmd.c              |  6 ++----
 drivers/xen/xen-pciback/pci_stub.c |  4 ++--
 include/xen/acpi.h                 | 12 ++++--------
 5 files changed, 25 insertions(+), 15 deletions(-)
drivers/xen/Kconfig +0 -1
index 72ddee4c1544..f7d6f47971fd 100644
@@ -261,7 +261,6 @@ config XEN_SCSI_BACKEND
 config XEN_PRIVCMD
 	tristate "Xen hypercall passthrough driver"
 	depends on XEN
-	imply XEN_PCIDEV_BACKEND
 	default m
 	help
 	  The hypercall passthrough driver allows privileged user programs to
drivers/xen/acpi.c +0 -0
index 9e2096524fbc..0bff2f3a87d2 100644

drivers/xen/acpi.c int xen_acpi_get_gsi_info(struct pci_dev *dev, · line 129

Quoted 5 lines
drivers/xen/acpi.c +2 -0
@@ -125,3 +125,20 @@ int xen_acpi_get_gsi_info(struct pci_dev *dev,
 	return 0;
 }
 EXPORT_SYMBOL_GPL(xen_acpi_get_gsi_info);
+
+get_gsi_from_sbdf_t get_gsi_from_sbdf = NULL;

This can be static

Quoted 91 lines
drivers/xen/acpi.c +14 -0
+void xen_acpi_register_get_gsi_func(get_gsi_from_sbdf_t func)
+{
+	get_gsi_from_sbdf = func;
+}
+EXPORT_SYMBOL_GPL(xen_acpi_register_get_gsi_func);
+
+int xen_acpi_get_gsi_from_sbdf(u32 sbdf)
+{
+	if (get_gsi_from_sbdf)
+		return get_gsi_from_sbdf(sbdf);
+
+	return -EINVAL;
+}
+EXPORT_SYMBOL_GPL(xen_acpi_get_gsi_from_sbdf);
\ No newline at end of file
drivers/xen/privcmd.c +2 -4
index 3273cb8c2a66..4f75bc876454 100644
@@ -850,15 +850,13 @@ static long privcmd_ioctl_mmap_resource(struct file *file,
 static long privcmd_ioctl_pcidev_get_gsi(struct file *file, void __user *udata)
 {
 #if defined(CONFIG_XEN_ACPI)
-	int rc = -EINVAL;
+	int rc;
 	struct privcmd_pcidev_get_gsi kdata;
 
 	if (copy_from_user(&kdata, udata, sizeof(kdata)))
 		return -EFAULT;
 
-	if (IS_REACHABLE(CONFIG_XEN_PCIDEV_BACKEND))
-		rc = pcistub_get_gsi_from_sbdf(kdata.sbdf);
-
+	rc = xen_acpi_get_gsi_from_sbdf(kdata.sbdf);
 	if (rc < 0)
 		return rc;
 
drivers/xen/xen-pciback/pci_stub.c +2 -2
index 2f3da5ac62cd..900e6199eec7 100644
@@ -227,7 +227,7 @@ static struct pci_dev *pcistub_device_get_pci_dev(struct xen_pcibk_device *pdev,
 }
 
 #ifdef CONFIG_XEN_ACPI
-int pcistub_get_gsi_from_sbdf(unsigned int sbdf)
+static int pcistub_get_gsi_from_sbdf(unsigned int sbdf)
 {
 	struct pcistub_device *psdev;
 	int domain = (sbdf >> 16) & 0xffff;
@@ -242,7 +242,6 @@ int pcistub_get_gsi_from_sbdf(unsigned int sbdf)
 
 	return psdev->gsi;
 }
-EXPORT_SYMBOL_GPL(pcistub_get_gsi_from_sbdf);
 #endif
 
 struct pci_dev *pcistub_get_pci_dev_by_slot(struct xen_pcibk_device *pdev,
@@ -484,6 +483,7 @@ static int pcistub_init_device(struct pcistub_device *psdev)
 		if (err)
 			goto config_release;
 		psdev->gsi = gsi;
+		xen_acpi_register_get_gsi_func(pcistub_get_gsi_from_sbdf);
 	}
 #endif
 
include/xen/acpi.h +4 -8
index daa96a22d257..ef4f70e4a557 100644
@@ -91,13 +91,9 @@ static inline int xen_acpi_get_gsi_info(struct pci_dev *dev,
 }
 #endif
 
-#ifdef CONFIG_XEN_PCI_STUB
-int pcistub_get_gsi_from_sbdf(unsigned int sbdf);
-#else
-static inline int pcistub_get_gsi_from_sbdf(unsigned int sbdf)
-{
-	return -1;
-}
-#endif
+typedef int (*get_gsi_from_sbdf_t)(u32 sbdf);
+
+void xen_acpi_register_get_gsi_func(get_gsi_from_sbdf_t func);
+int xen_acpi_get_gsi_from_sbdf(unsigned int sbdf);
 
 #endif	/* _XEN_ACPI_H */
Signature · 1 line
2.34.1