Skip to contentSkip to conversation

s390x: modularize virtio-gpu-ccw

PATCH In review Gerd Hoffmann 3 participants 7 messages Mar 17, 2021 – Mar 26, 2021 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

cover s390x: modularize virtio-gpu-ccw

Maybe not the most elegant but rather simple approach to the "parent object missing" problem: Use a symbol reference to make sure ccw modules load only in case ccw support is present.

Also split the cpu changes to a separate patch.

Gerd Hoffmann (3):
s390x: move S390_ADAPTER_SUPPRESSIBLE
s390x: add have_virtio_ccw
s390x: modularize virtio-gpu-ccw

 hw/s390x/virtio-ccw.h        | 5 +++++
 include/hw/s390x/css.h       | 7 -------
 include/hw/s390x/s390_flic.h | 3 +++
 target/s390x/cpu.h           | 9 ++++++---
 hw/s390x/virtio-ccw-gpu.c    | 4 +++-
 hw/s390x/virtio-ccw.c        | 2 ++
 util/module.c                | 1 +
 hw/s390x/meson.build         | 8 +++++++-
 8 files changed, 27 insertions(+), 12 deletions(-)
Signature · 1 line
2.30.2
#1 lore raw

PATCH 1/3 s390x: move S390_ADAPTER_SUPPRESSIBLE

The definition S390_ADAPTER_SUPPRESSIBLE was moved to "cpu.h", per suggestion of Thomas Huth. From interface design perspective, IMHO, not a good thing as it belongs to the public interface of css_register_io_adapters(). We did this because CONFIG_KVM requeires NEED_CPU_H and Thomas, and other commenters did not like the consequences of that.

Moving the interrupt related declarations to s390_flic.h was suggested by Cornelia Huck.

---
 include/hw/s390x/css.h       | 7 -------
 include/hw/s390x/s390_flic.h | 3 +++
 target/s390x/cpu.h           | 9 ++++++---
 3 files changed, 9 insertions(+), 10 deletions(-)
include/hw/s390x/css.h +0 -7
index 7901ab276ce9..bba7593d2eaa 100644
@@ -12,7 +12,6 @@
 #ifndef CSS_H
 #define CSS_H
 
-#include "cpu.h"
 #include "hw/s390x/adapter.h"
 #include "hw/s390x/s390_flic.h"
 #include "hw/s390x/ioinst.h"
@@ -233,12 +232,6 @@ uint32_t css_get_adapter_id(CssIoAdapterType type, uint8_t isc);
 void css_register_io_adapters(CssIoAdapterType type, bool swap, bool maskable,
                               uint8_t flags, Error **errp);
 
-#ifndef CONFIG_KVM
-#define S390_ADAPTER_SUPPRESSIBLE 0x01
-#else
-#define S390_ADAPTER_SUPPRESSIBLE KVM_S390_ADAPTER_SUPPRESSIBLE
-#endif
-
 #ifndef CONFIG_USER_ONLY
 SubchDev *css_find_subch(uint8_t m, uint8_t cssid, uint8_t ssid,
                          uint16_t schid);
include/hw/s390x/s390_flic.h +3 -0
index e91b15d2d6af..3907a13d0766 100644
@@ -134,6 +134,9 @@ void s390_flic_init(void);
 S390FLICState *s390_get_flic(void);
 QEMUS390FLICState *s390_get_qemu_flic(S390FLICState *fs);
 S390FLICStateClass *s390_get_flic_class(S390FLICState *fs);
+void s390_crw_mchk(void);
+void s390_io_interrupt(uint16_t subchannel_id, uint16_t subchannel_nr,
+                       uint32_t io_int_parm, uint32_t io_int_word);
 bool ais_needed(void *opaque);
 
 #endif /* HW_S390_FLIC_H */
target/s390x/cpu.h +6 -3
index 60d434d5edd5..b434b905c0ae 100644
@@ -40,6 +40,12 @@
 
 #define S390_MAX_CPUS 248
 
+#ifndef CONFIG_KVM
+#define S390_ADAPTER_SUPPRESSIBLE 0x01
+#else
+#define S390_ADAPTER_SUPPRESSIBLE KVM_S390_ADAPTER_SUPPRESSIBLE
+#endif
+
 typedef struct PSW {
     uint64_t mask;
     uint64_t addr;
@@ -806,9 +812,6 @@ int cpu_s390x_signal_handler(int host_signum, void *pinfo, void *puc);
 
 
 /* interrupt.c */
-void s390_crw_mchk(void);
-void s390_io_interrupt(uint16_t subchannel_id, uint16_t subchannel_nr,
-                       uint32_t io_int_parm, uint32_t io_int_word);
 #define RA_IGNORED                  0
 void s390_program_interrupt(CPUS390XState *env, uint32_t code, uintptr_t ra);
 /* service interrupts are floating therefore we must not pass an cpustate */
Signature · 1 line
2.30.2
#2 lore raw

Re: [PATCH 1/3] s390x: move S390_ADAPTER_SUPPRESSIBLE

Quoted 4 lines · Gerd Hoffmann

The definition S390_ADAPTER_SUPPRESSIBLE was moved to "cpu.h", per suggestion of Thomas Huth. From interface design perspective, IMHO, not a good thing as it belongs to the public interface of css_register_io_adapters(). We did this because CONFIG_KVM requeires

Typo "requeires" -> "requires"

Quoted 13 lines

NEED_CPU_H and Thomas, and other commenters did not like the consequences of that.

Moving the interrupt related declarations to s390_flic.h was suggested by Cornelia Huck.

---
 include/hw/s390x/css.h       | 7 -------
 include/hw/s390x/s390_flic.h | 3 +++
 target/s390x/cpu.h           | 9 ++++++---
 3 files changed, 9 insertions(+), 10 deletions(-)
#3 lore raw

PATCH 2/3 s390x: add have_virtio_ccw

In reply to Gerd Hoffmann

Introduce a symbol which can be used to prevent ccw modules being loaded into system emulators without ccw support.

---
 hw/s390x/virtio-ccw.h | 5 +++++
 hw/s390x/virtio-ccw.c | 2 ++
 2 files changed, 7 insertions(+)
hw/s390x/virtio-ccw.h +5 -0
index 49a2b8ca42df..0168232e3b8d 100644
@@ -63,6 +63,11 @@ typedef struct VirtioBusClass VirtioCcwBusClass;
 DECLARE_OBJ_CHECKERS(VirtioCcwBusState, VirtioCcwBusClass,
                      VIRTIO_CCW_BUS, TYPE_VIRTIO_CCW_BUS)
 
+/*
+ * modules can reference this symbol to avoid being loaded
+ * into system emulators without ccw support
+ */
+extern bool have_virtio_ccw;
 
 struct VirtIOCCWDeviceClass {
     CCWDeviceClass parent_class;
hw/s390x/virtio-ccw.c +2 -0
index 06c06056814b..314ed7b24566 100644
@@ -35,6 +35,8 @@
 
 #define NR_CLASSIC_INDICATOR_BITS 64
 
+bool have_virtio_ccw = true;
+
 static int virtio_ccw_dev_post_load(void *opaque, int version_id)
 {
     VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(opaque);
Signature · 1 line
2.30.2
#4 lore raw

PATCH 3/3 s390x: modularize virtio-gpu-ccw

In reply to Gerd Hoffmann

Since the virtio-gpu-ccw device depends on the hw-display-virtio-gpu module, which provides the type virtio-gpu-device, packaging the hw-display-virtio-gpu module as a separate package that may or may not be installed along with the qemu package leads to problems. Namely if the hw-display-virtio-gpu is absent, qemu continues to advertise virtio-gpu-ccw, but it aborts not only when one attempts using virtio-gpu-ccw, but also when libvirtd's capability probing tries to instantiate the type to introspect it.

Let us thus introduce a module named hw-s390x-virtio-gpu-ccw that is going to provide the virtio-gpu-ccw device. The hw-s390x prefix was chosen because it is not a portable device.

With virtio-gpu-ccw built as a module, the correct way to package a modularized qemu is to require that hw-display-virtio-gpu must be installed whenever the module hw-s390x-virtio-gpu-ccw.

---
 hw/s390x/virtio-ccw-gpu.c | 4 +++-
 util/module.c             | 1 +
 hw/s390x/meson.build      | 8 +++++++-
 3 files changed, 11 insertions(+), 2 deletions(-)
hw/s390x/virtio-ccw-gpu.c +3 -1
index c301e2586bde..75a9e4bb3908 100644
@@ -62,7 +62,9 @@ static const TypeInfo virtio_ccw_gpu = {
 
 static void virtio_ccw_gpu_register(void)
 {
-    type_register_static(&virtio_ccw_gpu);
+    if (have_virtio_ccw) {
+        type_register_static(&virtio_ccw_gpu);
+    }
 }
 
 type_init(virtio_ccw_gpu_register)
util/module.c +1 -0
index c65060c167df..cbe89fede628 100644
@@ -304,6 +304,7 @@ static struct {
     { "virtio-gpu-pci-base",   "hw-", "display-virtio-gpu-pci" },
     { "virtio-gpu-pci",        "hw-", "display-virtio-gpu-pci" },
     { "vhost-user-gpu-pci",    "hw-", "display-virtio-gpu-pci" },
+    { "virtio-gpu-ccw",        "hw-", "s390x-virtio-gpu-ccw"   },
     { "virtio-vga-base",       "hw-", "display-virtio-vga"    },
     { "virtio-vga",            "hw-", "display-virtio-vga"    },
     { "vhost-user-vga",        "hw-", "display-virtio-vga"    },
hw/s390x/meson.build +7 -1
index 91495b563146..327e9c93afa9 100644
@@ -34,7 +34,6 @@ virtio_ss.add(files('virtio-ccw.c'))
 virtio_ss.add(when: 'CONFIG_VIRTIO_BALLOON', if_true: files('virtio-ccw-balloon.c'))
 virtio_ss.add(when: 'CONFIG_VIRTIO_BLK', if_true: files('virtio-ccw-blk.c'))
 virtio_ss.add(when: 'CONFIG_VIRTIO_CRYPTO', if_true: files('virtio-ccw-crypto.c'))
-virtio_ss.add(when: 'CONFIG_VIRTIO_GPU', if_true: files('virtio-ccw-gpu.c'))
 virtio_ss.add(when: 'CONFIG_VIRTIO_INPUT', if_true: files('virtio-ccw-input.c'))
 virtio_ss.add(when: 'CONFIG_VIRTIO_NET', if_true: files('virtio-ccw-net.c'))
 virtio_ss.add(when: 'CONFIG_VIRTIO_RNG', if_true: files('virtio-ccw-rng.c'))
@@ -48,3 +47,10 @@ virtio_ss.add(when: 'CONFIG_VHOST_USER_FS', if_true: files('vhost-user-fs-ccw.c'
 s390x_ss.add_all(when: 'CONFIG_VIRTIO_CCW', if_true: virtio_ss)
 
 hw_arch += {'s390x': s390x_ss}
+
+hw_s390x_modules = {}
+virtio_gpu_ccw_ss = ss.source_set()
+virtio_gpu_ccw_ss.add(when: ['CONFIG_VIRTIO_GPU', 'CONFIG_VIRTIO_CCW'],
+                      if_true: [files('virtio-ccw-gpu.c'), pixman])
+hw_s390x_modules += {'virtio-gpu-ccw': virtio_gpu_ccw_ss}
+modules += {'hw-s390x': hw_s390x_modules}
Signature · 1 line
2.30.2
Reviewed-by Tested-by on the v1 series
#5 lore raw
In reply to Gerd Hoffmann
Quoted 3 lines · On Wed, 17 Mar 2021 10:56:19 +0100 Gerd Hoffmann <[email protected]> wrote:

Maybe not the most elegant but rather simple approach to the "parent object missing" problem: Use a symbol reference to make sure ccw modules load only in case ccw support is present.

[..]

Hi Gerd! I've tested this and I think mostly does what it should. The only thing that I'm inclined to consider a little quirky is the first message:

$ ./qemu-system-x86_64 -device virtio-gpu-ccw
Failed to open module: /home/pasic/build/qemu/hw-s390x-virtio-gpu-ccw.so: undefined symbol: have_virtio_ccw
qemu-system-x86_64: -device virtio-gpu-ccw: 'virtio-gpu-ccw' is not a valid device model name

But with something like --help we don't see it, and I assume neither do we when probing, because there the modules are loaded with mayfail. So for me this is acceptable, because it happens only if one tries to use a device that ain't advertised.

Compared to Daniels suggestion, I find that one conceptually clearer, and even more flexible. Implementation-wise I find this patch-set simpler. I don't know how would it scale to modules depending on modules (and it feels a little hackish), but we can address such problems as they emerge if they emerge, so I did not think too hard.

Let me also note, that you took authorship of all three patches, which I'm fine with. All I really care about at this stage is getting this fixed in a remotely sane way, and this is definitely one. I'm also willing to invest more work in that symlink based approach, if that is what the community wants, but I would prefer this fixed as soon as possible.

If you keep the authorship for all the patches, I would like to offer:

for all three patches. (If I'm going to be the author of some of the patches, those tags don't make sense for those).

Thanks for your work!

Regards,
Halil

#6 lore raw

Hi,

Quoted 3 lines

Compared to Daniels suggestion, I find that one conceptually clearer, and even more flexible. Implementation-wise I find this patch-set simpler.

Given we are in fixes-only mode I think we should go for the simple solution. Should be easy enough to revert in case we want replace this with something else after the 6.0 release.

Quoted 2 lines

Added & queued.
CI running, pull req later today when all goes well.

thanks,
Gerd