Skip to contentSkip to conversation

vfio/pci: make MSI handling optional

PATCH In review Arnd Bergmann 3 participants 5 messages Oct 9, 2014 – Feb 16, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vfio/pci: make MSI handling optional

A recent bug fix to the MSIx handling in vfio added references to functions that may not be defined if MSI is disabled in the kernel, resulting in this link error:

drivers/built-in.o: In function `vfio_msi_set_vector_signal':
:(.text+0x450808): undefined reference to get_cached_msi_msg' :(.text+0x45080c): undefined reference to write_msi_msg'

Quoted 1 line

From what I can tell, all the MSI specific ioctl handling can

be made optional in this case, which also reduces the code size for the vfo driver. This patches does so using a build-time IS_ENABLED() check, which leaves all the build coverage testing present but avoids the link error.

A side-effect of this is that the driver now returns -ENOTTY instead of -EINVAL if user space calls VFIO_PCI_MSI_IRQ_INDEX on a kernel without MSI support, which seems to be the best behavior, but the approach could easily be changed if we want to preserve the existing behavior for compatibility reasons.

Fixes b8f02af096b1 ("vfio/pci: Restore MSIx message prior to enabling")

---
Found using randconfig build testing on ARM.

drivers/vfio/pci/vfio_pci_intrs.c +3 -0
index 553212f037c3..1117f96b8556 100644
@@ -827,6 +827,9 @@ int vfio_pci_set_irqs_ioctl(struct vfio_pci_device *vdev, uint32_t flags,
 		break;
 	case VFIO_PCI_MSI_IRQ_INDEX:
 	case VFIO_PCI_MSIX_IRQ_INDEX:
+		if (!IS_ENABLED(CONFIG_PCI_MSI))
+			break;
+
 		switch (flags & VFIO_IRQ_SET_ACTION_TYPE_MASK) {
 		case VFIO_IRQ_SET_ACTION_MASK:
 		case VFIO_IRQ_SET_ACTION_UNMASK:
#1 lore raw
Quoted 20 lines · Arnd Bergmann

A recent bug fix to the MSIx handling in vfio added references to functions that may not be defined if MSI is disabled in the kernel, resulting in this link error:

drivers/built-in.o: In function `vfio_msi_set_vector_signal':
:(.text+0x450808): undefined reference to get_cached_msi_msg' :(.text+0x45080c): undefined reference to write_msi_msg'

From what I can tell, all the MSI specific ioctl handling can be made optional in this case, which also reduces the code size for the vfo driver. This patches does so using a build-time IS_ENABLED() check, which leaves all the build coverage testing present but avoids the link error.

A side-effect of this is that the driver now returns -ENOTTY instead of -EINVAL if user space calls VFIO_PCI_MSI_IRQ_INDEX on a kernel without MSI support, which seems to be the best behavior, but the approach could easily be changed if we want to preserve the existing behavior for compatibility reasons.

Quoted 3 lines
Fixes b8f02af096b1 ("vfio/pci: Restore MSIx message prior to enabling")

---

Why wouldn't we handle this with stubs for get_cached_msi_msg' and write_msi_msg'? We're really not talking about much code that might get removed by the compiler with this static branch and and it seems like a rather non-standard mechanism. The count of MSI/X IRQs advertised to the user should be zero without CONFIG_MSI and later range checks would prevent calls to
these functions for invalid indexes, so it's a bit of a random test in the code flow. Thanks,

Alex

Quoted 17 lines

Found using randconfig build testing on ARM.

drivers/vfio/pci/vfio_pci_intrs.c +3 -0
index 553212f037c3..1117f96b8556 100644
@@ -827,6 +827,9 @@ int vfio_pci_set_irqs_ioctl(struct vfio_pci_device *vdev, uint32_t flags,
 		break;
 	case VFIO_PCI_MSI_IRQ_INDEX:
 	case VFIO_PCI_MSIX_IRQ_INDEX:
+		if (!IS_ENABLED(CONFIG_PCI_MSI))
+			break;
+
 		switch (flags & VFIO_IRQ_SET_ACTION_TYPE_MASK) {
 		case VFIO_IRQ_SET_ACTION_MASK:
 		case VFIO_IRQ_SET_ACTION_UNMASK:
#2 lore raw
Quoted 10 lines · On Monday 13 October 2014 02:50:08 Alex Williamson wrote:

Why wouldn't we handle this with stubs for get_cached_msi_msg' and write_msi_msg'? We're really not talking about much code that might get removed by the compiler with this static branch and and it seems like a rather non-standard mechanism. The count of MSI/X IRQs advertised to the user should be zero without CONFIG_MSI and later range checks would prevent calls to
these functions for invalid indexes, so it's a bit of a random test in the code flow. Thanks,

That's fine with me too.

Arnd

#3 lore raw

PATCH 1/1 genirq/msi: add stubs for get_cached_msi_msg/pci_write_msi_msg

A bug fix to the MSIx handling in vfio added references to functions that may not be defined if MSI is disabled in the kernel, resulting in this link error:

drivers/built-in.o: In function `vfio_msi_set_vector_signal':
:(.text+0x450808): undefined reference to get_cached_msi_msg' :(.text+0x45080c): undefined reference to write_msi_msg'

As suggested by Alex Williamson, this adds stub implementations for get_cached_msi_msg() and pci_write_msi_msg().

In case this bugfix gets backported, please note that the #ifdef has changed over time, originally both functions were implemented in drivers/pci/msi.c and controlled by CONFIG_PCI_MSI, while nowadays get_cached_msi_msg() is part of the generic MSI support and can be used without PCI.

Fixes b8f02af096b1 ("vfio/pci: Restore MSIx message prior to enabling")

---
I had a workaround for this hidden in my randconfig tree but have now stumbled over it again, sorry for not following up a couple of years earlier.

---
 include/linux/msi.h | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
include/linux/msi.h +10 -1
index 0db320b7bb15..a83b84ff70e5 100644
@@ -17,7 +17,13 @@ struct msi_desc;
 struct pci_dev;
 struct platform_msi_priv_data;
 void __get_cached_msi_msg(struct msi_desc *entry, struct msi_msg *msg);
+#ifdef CONFIG_GENERIC_MSI_IRQ
 void get_cached_msi_msg(unsigned int irq, struct msi_msg *msg);
+#else
+static inline void get_cached_msi_msg(unsigned int irq, struct msi_msg *msg)
+{
+}
+#endif
 
 typedef void (*irq_write_msi_msg_t)(struct msi_desc *desc,
 				    struct msi_msg *msg);
@@ -116,11 +122,15 @@ struct msi_desc {
 
 struct pci_dev *msi_desc_to_pci_dev(struct msi_desc *desc);
 void *msi_desc_to_pci_sysdata(struct msi_desc *desc);
+void pci_write_msi_msg(unsigned int irq, struct msi_msg *msg);
 #else /* CONFIG_PCI_MSI */
 static inline void *msi_desc_to_pci_sysdata(struct msi_desc *desc)
 {
 	return NULL;
 }
+static inline void pci_write_msi_msg(unsigned int irq, struct msi_msg *msg)
+{
+}
 #endif /* CONFIG_PCI_MSI */
 
 struct msi_desc *alloc_msi_entry(struct device *dev, int nvec,
@@ -128,7 +138,6 @@ struct msi_desc *alloc_msi_entry(struct device *dev, int nvec,
 void free_msi_entry(struct msi_desc *entry);
 void __pci_read_msi_msg(struct msi_desc *entry, struct msi_msg *msg);
 void __pci_write_msi_msg(struct msi_desc *entry, struct msi_msg *msg);
-void pci_write_msi_msg(unsigned int irq, struct msi_msg *msg);
 
 u32 __pci_msix_desc_mask_irq(struct msi_desc *desc, u32 flag);
 u32 __pci_msi_desc_mask_irq(struct msi_desc *desc, u32 mask, u32 flag);
Signature · 1 line
2.9.0
#4 lore raw

[tip:irq/core] genirq/msi: Add stubs for get_cached_msi_msg/pci_write_msi_msg

genirq/msi: Add stubs for get_cached_msi_msg/pci_write_msi_msg
Commit-ID:  2f44e29cef006a4b0a4ecf7d4c5aac7d0fbb505c
Gitweb:     http://git.kernel.org/tip/2f44e29cef006a4b0a4ecf7d4c5aac7d0fbb505c
Author:     Arnd Bergmann <[email protected]>
AuthorDate: Tue, 14 Feb 2017 22:53:12 +0100
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Thu, 16 Feb 2017 15:32:19 +0100

genirq/msi: Add stubs for get_cached_msi_msg/pci_write_msi_msg

A bug fix to the MSIx handling in vfio added references to functions that may not be defined if MSI is disabled in the kernel, resulting in this link error:

drivers/built-in.o: In function `vfio_msi_set_vector_signal':
:(.text+0x450808): undefined reference to get_cached_msi_msg' :(.text+0x45080c): undefined reference to write_msi_msg'

As suggested by Alex Williamson, add stub implementations for get_cached_msi_msg() and pci_write_msi_msg().

In case this bugfix gets backported, please note that the #ifdef has changed over time, originally both functions were implemented in drivers/pci/msi.c and controlled by CONFIG_PCI_MSI, while nowadays get_cached_msi_msg() is part of the generic MSI support and can be used without PCI.

Fixes b8f02af096b1 ("vfio/pci: Restore MSIx message prior to enabling")
Cc Marc Zyngier <[email protected]>
Cc Alex Williamson <[email protected]>
Cc Bjorn Helgaas <[email protected]>
Cc Bart Van Assche <[email protected]>
---
 include/linux/msi.h | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
include/linux/msi.h +10 -1
index 0db320b..a83b84f 100644
@@ -17,7 +17,13 @@ struct msi_desc;
 struct pci_dev;
 struct platform_msi_priv_data;
 void __get_cached_msi_msg(struct msi_desc *entry, struct msi_msg *msg);
+#ifdef CONFIG_GENERIC_MSI_IRQ
 void get_cached_msi_msg(unsigned int irq, struct msi_msg *msg);
+#else
+static inline void get_cached_msi_msg(unsigned int irq, struct msi_msg *msg)
+{
+}
+#endif
 
 typedef void (*irq_write_msi_msg_t)(struct msi_desc *desc,
 				    struct msi_msg *msg);
@@ -116,11 +122,15 @@ struct msi_desc {
 
 struct pci_dev *msi_desc_to_pci_dev(struct msi_desc *desc);
 void *msi_desc_to_pci_sysdata(struct msi_desc *desc);
+void pci_write_msi_msg(unsigned int irq, struct msi_msg *msg);
 #else /* CONFIG_PCI_MSI */
 static inline void *msi_desc_to_pci_sysdata(struct msi_desc *desc)
 {
 	return NULL;
 }
+static inline void pci_write_msi_msg(unsigned int irq, struct msi_msg *msg)
+{
+}
 #endif /* CONFIG_PCI_MSI */
 
 struct msi_desc *alloc_msi_entry(struct device *dev, int nvec,
@@ -128,7 +138,6 @@ struct msi_desc *alloc_msi_entry(struct device *dev, int nvec,
 void free_msi_entry(struct msi_desc *entry);
 void __pci_read_msi_msg(struct msi_desc *entry, struct msi_msg *msg);
 void __pci_write_msi_msg(struct msi_desc *entry, struct msi_msg *msg);
-void pci_write_msi_msg(unsigned int irq, struct msi_msg *msg);
 
 u32 __pci_msix_desc_mask_irq(struct msi_desc *desc, u32 flag);
 u32 __pci_msi_desc_mask_irq(struct msi_desc *desc, u32 mask, u32 flag);