Skip to contentSkip to conversation

virtio: kconfig: memory devices are PCI only

PATCH In review Paolo Bonzini 3 participants 5 messages Sep 6, 2024 – Sep 26, 2024

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 virtio: kconfig: memory devices are PCI only

Virtio memory devices rely on PCI BARs to expose the contents of memory. Because of this they cannot be used (yet) with virtio-mmio or virtio-ccw. In fact the code that is common to virtio-mem and virtio-pmem, which is in hw/virtio/virtio-md-pci.c, is only included if CONFIG_VIRTIO_PCI is set. Reproduce the same condition in the Kconfig file, only allowing VIRTIO_MEM and VIRTIO_PMEM to be defined if the transport supports it.

Without this patch it is possible to create a configuration with CONFIG_VIRTIO_PCI=n and CONFIG_VIRTIO_MEM=y, but that causes a linking failure.

---
 hw/virtio/Kconfig | 11 +++++++++++
 1 file changed, 11 insertions(+)
hw/virtio/Kconfig +11 -0
index aa63ff7fd41..0afec2ae929 100644
@@ -16,6 +16,7 @@ config VIRTIO_PCI
     default y if PCI_DEVICES
     depends on PCI
     select VIRTIO
+    select VIRTIO_MD_SUPPORTED
 
 config VIRTIO_MMIO
     bool
@@ -35,10 +36,17 @@ config VIRTIO_CRYPTO
     default y
     depends on VIRTIO
 
+# not all virtio transports support memory devices; if none does,
+# no need to include the code
+config VIRTIO_MD_SUPPORTED
+    bool
+
 config VIRTIO_MD
     bool
+    depends on VIRTIO_MD_SUPPORTED
     select MEM_DEVICE
 
+# selected by the board if it has the required support code
 config VIRTIO_PMEM_SUPPORTED
     bool
 
@@ -46,9 +54,11 @@ config VIRTIO_PMEM
     bool
     default y
     depends on VIRTIO
+    depends on VIRTIO_MD_SUPPORTED
     depends on VIRTIO_PMEM_SUPPORTED
     select VIRTIO_MD
 
+# selected by the board if it has the required support code
 config VIRTIO_MEM_SUPPORTED
     bool
 
@@ -57,6 +67,7 @@ config VIRTIO_MEM
     default y
     depends on VIRTIO
     depends on LINUX
+    depends on VIRTIO_MD_SUPPORTED
     depends on VIRTIO_MEM_SUPPORTED
     select VIRTIO_MD
 
Signature · 1 line
2.46.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 7 lines · Paolo Bonzini

Virtio memory devices rely on PCI BARs to expose the contents of memory. Because of this they cannot be used (yet) with virtio-mmio or virtio-ccw. In fact the code that is common to virtio-mem and virtio-pmem, which is in hw/virtio/virtio-md-pci.c, is only included if CONFIG_VIRTIO_PCI is set. Reproduce the same condition in the Kconfig file, only allowing VIRTIO_MEM and VIRTIO_PMEM to be defined if the transport supports it.

Quoted 8 lines

Without this patch it is possible to create a configuration with CONFIG_VIRTIO_PCI=n and CONFIG_VIRTIO_MEM=y, but that causes a linking failure.

---

Thanks!

Signature · 3 lines
Cheers,

David / dhildenb
#2 lore raw
In reply to Paolo Bonzini
Quoted 10 lines · Paolo Bonzini

Virtio memory devices rely on PCI BARs to expose the contents of memory. Because of this they cannot be used (yet) with virtio-mmio or virtio-ccw. In fact the code that is common to virtio-mem and virtio-pmem, which is in hw/virtio/virtio-md-pci.c, is only included if CONFIG_VIRTIO_PCI is set. Reproduce the same condition in the Kconfig file, only allowing VIRTIO_MEM and VIRTIO_PMEM to be defined if the transport supports it.

Without this patch it is possible to create a configuration with CONFIG_VIRTIO_PCI=n and CONFIG_VIRTIO_MEM=y, but that causes a linking failure.

I'll queue this to

https://github.com/davidhildenbrand/qemu.git mem-next

and drop it if someone beats me to up-streaming it :)

Signature · 3 lines
Cheers,

David / dhildenb
Reviewed-by on v2 1/1
#3 lore raw
In reply to Paolo Bonzini
Quoted 10 lines

Virtio memory devices rely on PCI BARs to expose the contents of memory. Because of this they cannot be used (yet) with virtio-mmio or virtio-ccw. In fact the code that is common to virtio-mem and virtio-pmem, which is in hw/virtio/virtio-md-pci.c, is only included if CONFIG_VIRTIO_PCI is set. Reproduce the same condition in the Kconfig file, only allowing VIRTIO_MEM and VIRTIO_PMEM to be defined if the transport supports it.

Without this patch it is possible to create a configuration with CONFIG_VIRTIO_PCI=n and CONFIG_VIRTIO_MEM=y, but that causes a linking failure.

Just curious what is required to make virtio-mem & virtio-pmem compatible with virtio-mmio?

Maybe late but still:

Thanks,
Pankaj

Quoted 62 lines
---
 hw/virtio/Kconfig | 11 +++++++++++
 1 file changed, 11 insertions(+)
hw/virtio/Kconfig +11 -1
index aa63ff7fd41..0afec2ae929 100644
@@ -16,6 +16,7 @@ config VIRTIO_PCI
     default y if PCI_DEVICES
     depends on PCI
     select VIRTIO
+    select VIRTIO_MD_SUPPORTED
 
 config VIRTIO_MMIO
     bool
@@ -35,10 +36,17 @@ config VIRTIO_CRYPTO
     default y
     depends on VIRTIO
 
+# not all virtio transports support memory devices; if none does,
+# no need to include the code
+config VIRTIO_MD_SUPPORTED
+    bool
+
 config VIRTIO_MD
     bool
+    depends on VIRTIO_MD_SUPPORTED
     select MEM_DEVICE
 
+# selected by the board if it has the required support code
 config VIRTIO_PMEM_SUPPORTED
     bool
 
@@ -46,9 +54,11 @@ config VIRTIO_PMEM
     bool
     default y
     depends on VIRTIO
+    depends on VIRTIO_MD_SUPPORTED
     depends on VIRTIO_PMEM_SUPPORTED
     select VIRTIO_MD
 
+# selected by the board if it has the required support code
 config VIRTIO_MEM_SUPPORTED
     bool
 
@@ -57,6 +67,7 @@ config VIRTIO_MEM
     default y
     depends on VIRTIO
     depends on LINUX
+    depends on VIRTIO_MD_SUPPORTED
     depends on VIRTIO_MEM_SUPPORTED
     select VIRTIO_MD
 
--

2.46.0

#4 lore raw
Quoted 7 lines · Pankaj Gupta
Quoted 7 lines

Virtio memory devices rely on PCI BARs to expose the contents of memory. Because of this they cannot be used (yet) with virtio-mmio or virtio-ccw. In fact the code that is common to virtio-mem and virtio-pmem, which is in hw/virtio/virtio-md-pci.c, is only included if CONFIG_VIRTIO_PCI is set. Reproduce the same condition in the Kconfig file, only allowing VIRTIO_MEM and VIRTIO_PMEM to be defined if the transport supports it.

Quoted 6 lines
Quoted 3 lines

Without this patch it is possible to create a configuration with CONFIG_VIRTIO_PCI=n and CONFIG_VIRTIO_MEM=y, but that causes a linking failure.

Just curious what is required to make virtio-mem & virtio-pmem compatible with virtio-mmio?

I assume not that much: primarily implementing the virtio-md-mmio abstraction, and the virtio-mem-mmio/virtio-pmem-mmio proxy devices. Then, it needs to be wired up in the machine hotplug code.

I posted the virtio-ccw variant a couple of days ago [1].

Quoted 3 lines

Maybe late but still:

I already sent a merge request that includes this change. If I have to resend it, I'll include that. Thanks!

[1] https://lkml.kernel.org/r/[email protected]

Signature · 3 lines
Cheers,

David / dhildenb