]> www.infradead.org Git - users/hch/misc.git/commitdiff
xen: Remove dependency between pciback and privcmd
authorJiqian Chen <Jiqian.Chen@amd.com>
Sat, 12 Oct 2024 08:45:37 +0000 (16:45 +0800)
committerJuergen Gross <jgross@suse.com>
Fri, 18 Oct 2024 09:59:04 +0000 (11:59 +0200)
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 isn't always 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")
Reported-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Signed-off-by: Jiqian Chen <Jiqian.Chen@amd.com>
Reviewed-by: Juergen Gross <jgross@suse.com>
Message-ID: <20241012084537.1543059-1-Jiqian.Chen@amd.com>
Signed-off-by: Juergen Gross <jgross@suse.com>
drivers/xen/Kconfig
drivers/xen/acpi.c
drivers/xen/privcmd.c
drivers/xen/xen-pciback/pci_stub.c
include/xen/acpi.h

index 72ddee4c1544df017a71815d31db9b03b37db0a5..f7d6f47971fdf8a27db45841f43af081e7030289 100644 (file)
@@ -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
index 9e2096524fbc5c8136d14df557b334983d940b98..d2ee605c5ca1c7898a4dc5cc324b51af84497f13 100644 (file)
@@ -125,3 +125,27 @@ int xen_acpi_get_gsi_info(struct pci_dev *dev,
        return 0;
 }
 EXPORT_SYMBOL_GPL(xen_acpi_get_gsi_info);
+
+static get_gsi_from_sbdf_t get_gsi_from_sbdf;
+static DEFINE_RWLOCK(get_gsi_from_sbdf_lock);
+
+void xen_acpi_register_get_gsi_func(get_gsi_from_sbdf_t func)
+{
+       write_lock(&get_gsi_from_sbdf_lock);
+       get_gsi_from_sbdf = func;
+       write_unlock(&get_gsi_from_sbdf_lock);
+}
+EXPORT_SYMBOL_GPL(xen_acpi_register_get_gsi_func);
+
+int xen_acpi_get_gsi_from_sbdf(u32 sbdf)
+{
+       int ret = -EOPNOTSUPP;
+
+       read_lock(&get_gsi_from_sbdf_lock);
+       if (get_gsi_from_sbdf)
+               ret = get_gsi_from_sbdf(sbdf);
+       read_unlock(&get_gsi_from_sbdf_lock);
+
+       return ret;
+}
+EXPORT_SYMBOL_GPL(xen_acpi_get_gsi_from_sbdf);
index 3273cb8c2a6627ce9652773a0c16057aa12f7a8f..4f75bc876454fc20afa0cf6fc39578e582f963ce 100644 (file)
@@ -850,15 +850,13 @@ out:
 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;
 
index 2f3da5ac62cd888b60b1b5423f121196aa953d5a..b616b7768c3b97598446d43feef7f4aa2e266440 100644 (file)
@@ -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,
@@ -1757,11 +1756,19 @@ static int __init xen_pcibk_init(void)
                bus_register_notifier(&pci_bus_type, &pci_stub_nb);
 #endif
 
+#ifdef CONFIG_XEN_ACPI
+       xen_acpi_register_get_gsi_func(pcistub_get_gsi_from_sbdf);
+#endif
+
        return err;
 }
 
 static void __exit xen_pcibk_cleanup(void)
 {
+#ifdef CONFIG_XEN_ACPI
+       xen_acpi_register_get_gsi_func(NULL);
+#endif
+
 #ifdef CONFIG_PCI_IOV
        bus_unregister_notifier(&pci_bus_type, &pci_stub_nb);
 #endif
index daa96a22d257e94a04d4322cf4c558a4274c16df..c66a8461612ea788a81adb554863d3b7db1202ed 100644 (file)
@@ -35,6 +35,8 @@
 
 #include <linux/types.h>
 
+typedef int (*get_gsi_from_sbdf_t)(u32 sbdf);
+
 #ifdef CONFIG_XEN_DOM0
 #include <asm/xen/hypervisor.h>
 #include <xen/xen.h>
@@ -72,6 +74,8 @@ int xen_acpi_get_gsi_info(struct pci_dev *dev,
                                                  int *gsi_out,
                                                  int *trigger_out,
                                                  int *polarity_out);
+void xen_acpi_register_get_gsi_func(get_gsi_from_sbdf_t func);
+int xen_acpi_get_gsi_from_sbdf(u32 sbdf);
 #else
 static inline void xen_acpi_sleep_register(void)
 {
@@ -89,12 +93,12 @@ static inline int xen_acpi_get_gsi_info(struct pci_dev *dev,
 {
        return -1;
 }
-#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)
+static inline void xen_acpi_register_get_gsi_func(get_gsi_from_sbdf_t func)
+{
+}
+
+static inline int xen_acpi_get_gsi_from_sbdf(u32 sbdf)
 {
        return -1;
 }