pc-bios/s390-ccw: Verify virtio support when booting from virtio PCI device on s390x
The virtio specification requires that each PCI device has a vendor ID of 0x1af4. Verify this value before continuing with boot process. Signed-off-by: Jared Rossi <jrossi@linux.ibm.com> Reviewed-by: Eric Farman <farman@linux.ibm.com> Tested-by: Matthew Rosato <mjrosato@linux.ibm.com> Message-ID: <20260630141917.673995-5-jrossi@linux.ibm.com> Signed-off-by: Cornelia Huck <cohuck@redhat.com>
Jared Rossi committed
Jun 30, 2026 at 10:19 UTC
e26dafb207bc6218582fe18a1386026adb4620d3
5 files changed
+26
pc-bios/s390-ccw/main.c
+1
@@ -163,6 +163,7 @@ static bool find_fid(uint32_t fid)
163
}
164
165
vdev->pci_fh = entry.fh;
166
+ vdev->vendor_id = entry.vendor_id;
167
virtio_pci_id2type(vdev, entry.device_id);
168
169
return vdev->dev_type != 0;
pc-bios/s390-ccw/virtio-pci.c
+19
@@ -325,6 +325,20 @@ static int enable_pci_bus_master(void)
325
return 0;
326
}
327
328
+bool virtio_pci_is_supported(VDev *vdev)
329
+{
330
+ if (vdev->vendor_id == PCI_VENDOR_VIRTIO) {
331
+ switch (vdev->dev_type) {
332
+ case VIRTIO_ID_BLOCK:
333
+ return true;
334
+ default:
335
+ return false;
336
+ }
337
+ }
338
+
339
+ return false;
340
+}
341
+
342
int virtio_pci_setup(VDev *vdev)
343
{
344
VRing *vr;
@@ -335,6 +349,11 @@ int virtio_pci_setup(VDev *vdev)
349
vdev->guessed_disk_nature = VIRTIO_GDN_NONE;
350
vdev->cmd_vr_idx = 0;
351
352
+ if (!virtio_pci_is_supported(vdev)) {
353
+ puts("Virtio PCI unsupported for this device ID");
354
+ return -ENODEV;
355
+ }
356
+
357
if (virtio_pci_read_pci_cap_config()) {
358
puts("Invalid virtio PCI capabilities");
359
return -EIO;
pc-bios/s390-ccw/virtio-pci.h
+3
@@ -56,6 +56,8 @@
56
57
#define VIRTIO_F_VERSION_1 1 /* Feature bit 32 */
58
59
+#define PCI_VENDOR_VIRTIO 0x1af4
60
+
61
struct VirtioPciCap {
62
uint8_t bar; /* Which PCIAS it's in */
63
uint32_t off; /* Offset within bar */
@@ -65,6 +67,7 @@ typedef struct VirtioPciCap VirtioPciCap;
67
void virtio_pci_id2type(VDev *vdev, uint16_t device_id);
68
int virtio_pci_reset(VDev *vdev);
69
long virtio_pci_notify(VRing *vr);
70
+bool virtio_pci_is_supported(VDev *vdev);
71
int virtio_pci_setup(VDev *vdev);
72
int virtio_pci_setup_device(void);
73
pc-bios/s390-ccw/virtio.c
+2
@@ -247,6 +247,8 @@ bool virtio_is_supported(VDev *vdev)
247
case S390_IPL_TYPE_QEMU_SCSI:
248
case S390_IPL_TYPE_CCW:
249
return virtio_ccw_is_supported(vdev);
250
+ case S390_IPL_TYPE_PCI:
251
+ return virtio_pci_is_supported(vdev);
252
default:
253
return false;
254
}
pc-bios/s390-ccw/virtio.h
+1
@@ -259,6 +259,7 @@ struct VDev {
259
bool scsi_device_selected;
260
ScsiDevice selected_scsi_device;
261
uint32_t pci_fh;
262
+ uint16_t vendor_id;
263
uint32_t max_transfer;
264
uint32_t guest_features[2];
265
};