Skip to contentSkip to conversation

s390x: Fix intermittent errors with IPL from PCI devices on s390x

PATCH Superseded [email protected] 2 participants 15 messages Jun 23 – Jun 28

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover s390x: Fix intermittent errors with IPL from PCI devices on s390x

From: Jared Rossi <[email protected]>

When booting from a PCI device on s390x there may be intermittent failures caused by mismatched byte swaps. Refactor the byte swapping to ensure that it is properly synchronized.

Correct how the queue notification offset is calculated so that it meets the specification and may be used for multi-queue configurations in the future.

Handle some switch cases that were not caught for PCI devices.

Jared Rossi (1):
pc-bios/s390-ccw: Verify virtio support when booting from PCI device

    on s390x

Joshua Daley (1):
pc-bios/s390-ccw: write IPLB location for virtio-blk-pci IPL

Zhuoying Cai (3):
pc-bios/s390-ccw: Refactor byte swapping pc-bios/s390-ccw: Add per-queue notification offset for multi-queue
virtio configurations
s390x: Enable boot menu for virtio pci device

 hw/s390x/ipl.c                |  1 +
 pc-bios/s390-ccw/main.c       |  5 ++-
 pc-bios/s390-ccw/virtio-pci.c | 57 ++++++++++++++++++++++++++---------
 pc-bios/s390-ccw/virtio-pci.h |  2 +-
 pc-bios/s390-ccw/virtio.c     | 27 +++++++++--------
 pc-bios/s390-ccw/virtio.h     |  2 ++
 6 files changed, 64 insertions(+), 30 deletions(-)
Signature · 1 line
2.54.0
#1 lore raw

PATCH 1/5 pc-bios/s390-ccw: Refactor byte swapping

From: Zhuoying Cai <[email protected]>

Introduce local variables to cache the byte-swapped values eliminating some redundant byte swap operations. Additionally, do byte swap when polling to avoid a special case where endianness is preserved.

---
 pc-bios/s390-ccw/virtio.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
pc-bios/s390-ccw/virtio.c +12 -12
index 390b55c7b9..a448dc96e2 100644
@@ -153,14 +153,14 @@ static void vr_bswap_descriptor(VRingDesc *desc)
 
 void vring_send_buf(VRing *vr, void *p, int len, int flags)
 {
-    if (!be_ipl()) {
-        vr->avail->idx = bswap16(vr->avail->idx);
-    }
+    uint16_t avail_idx;
+
+    avail_idx = be_ipl() ? vr->avail->idx : bswap16(vr->avail->idx);
 
     /* For follow-up chains we need to keep the first entry point */
     if (!(flags & VRING_HIDDEN_IS_CHAIN)) {
-        vr->avail->ring[vr->avail->idx % vr->num] = be_ipl() ? vr->next_idx :
-                                                               bswap16(vr->next_idx);
+        vr->avail->ring[avail_idx % vr->num] = be_ipl() ? vr->next_idx :
+                                                          bswap16(vr->next_idx);
     }
 
     vr->desc[vr->next_idx].addr = (unsigned long)p;
@@ -177,23 +177,23 @@ void vring_send_buf(VRing *vr, void *p, int len, int flags)
 
     /* Chains only have a single ID */
     if (!(flags & VRING_DESC_F_NEXT)) {
-        vr->avail->idx++;
-    }
-
-    if (!be_ipl()) {
-        vr->avail->idx = bswap16(vr->avail->idx);
+        avail_idx++;
+        vr->avail->idx = be_ipl() ? avail_idx : bswap16(avail_idx);
     }
 }
 
 int vr_poll(VRing *vr)
 {
-    if (vr->used->idx == vr->used_idx) {
+    uint16_t used_idx;
+
+    used_idx = be_ipl() ? vr->used->idx : bswap16(vr->used->idx);
+    if (used_idx == vr->used_idx) {
         vring_notify(vr);
         yield();
         return 0;
     }
 
-    vr->used_idx = vr->used->idx; /* Endianness is preserved */
+    vr->used_idx = used_idx;
     vr->next_idx = 0;
     vr->desc[0].len = 0;
     vr->desc[0].flags = 0;
Signature · 1 line
2.54.0
Reviewed-by on v1 1/5
#2 lore raw

Re: [PATCH 1/5] pc-bios/s390-ccw: Refactor byte swapping

Quoted 11 lines · On Mon, 2026-06-22 at 20:25 -0400, [email protected] wrote:

From: Zhuoying Cai <[email protected]>

Introduce local variables to cache the byte-swapped values eliminating some redundant byte swap operations. Additionally, do byte swap when polling to avoid a special case where endianness is preserved.

---
 pc-bios/s390-ccw/virtio.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
#3 lore raw

PATCH 2/5 pc-bios/s390-ccw: Add per-queue notification offset for multi-queue virtio configurations

In reply to [email protected]

From: Zhuoying Cai <[email protected]>

The initial support for virtio-blk-pci IPL devices used a single virt-queue, but other device types require multiple queues, and for PCI device types this also requires a per-queue notification offset.

Add a PCI notify field to the VRing struct so that each queue has a unique notify offset as defined in the virtio spec.

---
 pc-bios/s390-ccw/virtio-pci.c | 38 +++++++++++++++++++++--------------
 pc-bios/s390-ccw/virtio-pci.h |  2 +-
 pc-bios/s390-ccw/virtio.c     |  3 ++-
 pc-bios/s390-ccw/virtio.h     |  1 +
 4 files changed, 27 insertions(+), 17 deletions(-)
pc-bios/s390-ccw/virtio-pci.c +23 -15
index 53bdb52e76..2c83ec4f13 100644
@@ -21,7 +21,6 @@ VirtioPciCap c_cap; /* Common capabilities  */
 VirtioPciCap d_cap; /* Device capabilities  */
 VirtioPciCap n_cap; /* Notify capabilities  */
 uint32_t notify_mult;
-uint16_t q_notify_offset;
 
 static int virtio_pci_set_status(uint8_t status)
 {
@@ -74,10 +73,10 @@ int virtio_pci_reset(VDev *vdev)
     return 0;
 }
 
-long virtio_pci_notify(int vq_id)
+long virtio_pci_notify(VRing *vr)
 {
-    uint32_t offset = n_cap.off + notify_mult * q_notify_offset;
-    return vpci_bswap16_write(offset, n_cap.bar, (uint16_t) vq_id);
+    uint32_t offset = n_cap.off + notify_mult * vr->pci_notify;
+    return vpci_bswap16_write(offset, n_cap.bar, (uint16_t) vr->id);
 }
 
 /*
@@ -301,8 +300,7 @@ static int virtio_pci_read_pci_cap_config(void)
     }
 
     rc = vpci_read_bswap32(pos + VPCI_N_CAP_MULT, PCI_CFGBAR, &notify_mult);
-    if (rc || vpci_read_bswap16(c_cap.off + VPCI_C_OFFSET_Q_NOFF, c_cap.bar,
-                                &q_notify_offset)) {
+    if (rc) {
         puts("Failed to read notification queue configuration");
         return -EIO;
     }
@@ -332,7 +330,6 @@ int virtio_pci_setup(VDev *vdev)
     VRing *vr;
     int rc;
     uint8_t status;
-    uint16_t vq_size;
     int i = 0;
 
     vdev->guessed_disk_nature = VIRTIO_GDN_NONE;
@@ -380,28 +377,39 @@ int virtio_pci_setup(VDev *vdev)
         return -EIO;
     }
 
-    if (vpci_read_bswap16(VPCI_C_OFFSET_Q_SIZE, c_cap.bar, &vq_size)) {
-        puts("Failed to read virt-queue configuration");
-        return -EIO;
-    }
-
     /* Configure virt-queues for pci */
     for (i = 0; i < vdev->nr_vqs; i++) {
+        uint16_t vq_size;
+        uint16_t vq_notify;
         VqInfo info = {
             .queue = (unsigned long long) virtio_get_ring_area(i),
             .align = KVM_S390_VIRTIO_RING_ALIGN,
             .index = i,
-            .num = vq_size,
+            .num = 0,
         };
 
         vr = &vdev->vrings[i];
-        vring_init(vr, &info);
 
-        if (vpci_set_selected_vq(vr->id)) {
+        if (vpci_set_selected_vq(i)) {
             puts("Failed to set selected virt-queue");
             return -EIO;
         }
 
+        if (vpci_read_bswap16(c_cap.off + VPCI_C_OFFSET_Q_SIZE, c_cap.bar, &vq_size)) {
+            printf("Failed to read virt-queue %d size\n", i);
+            return -EIO;
+        }
+
+        info.num = vq_size;
+
+        if (vpci_read_bswap16(c_cap.off + VPCI_C_OFFSET_Q_NOFF, c_cap.bar, &vq_notify)) {
+            printf("Failed to read virt-queue %d notify offset\n", i);
+            return -EIO;
+        }
+
+        vr->pci_notify = vq_notify;
+        vring_init(vr, &info);
+
         rc = set_pci_vq_addr(VPCI_C_OFFSET_Q_DESCLO, vr->desc);
         rc |= set_pci_vq_addr(VPCI_C_OFFSET_Q_AVAILLO, vr->avail);
         rc |= set_pci_vq_addr(VPCI_C_OFFSET_Q_USEDLO, vr->used);
pc-bios/s390-ccw/virtio-pci.h +1 -1
index 90d07cb9a7..2494df1619 100644
@@ -64,7 +64,7 @@ typedef struct VirtioPciCap  VirtioPciCap;
 
 void virtio_pci_id2type(VDev *vdev, uint16_t device_id);
 int virtio_pci_reset(VDev *vdev);
-long virtio_pci_notify(int vq_id);
+long virtio_pci_notify(VRing *vr);
 int virtio_pci_setup(VDev *vdev);
 int virtio_pci_setup_device(void);
 
pc-bios/s390-ccw/virtio.c +2 -1
index a448dc96e2..df04479aa6 100644
@@ -114,7 +114,8 @@ bool vring_notify(VRing *vr)
         vr->cookie = virtio_ccw_notify(vdev.schid, vr->id, vr->cookie);
         break;
     case S390_IPL_TYPE_PCI:
-        vr->cookie = virtio_pci_notify(vr->id);
+        vr->cookie = virtio_pci_notify(vr);
+        break;
     default:
         return 1;
     }
pc-bios/s390-ccw/virtio.h +1 -0
index d32a4830ca..75ae5bdbc2 100644
@@ -107,6 +107,7 @@ struct VRing {
     VRingUsed *used;
     long cookie;
     int id;
+    uint16_t pci_notify;
 };
 typedef struct VRing VRing;
 
Signature · 1 line
2.54.0
#4 lore raw

Re: [PATCH 2/5] pc-bios/s390-ccw: Add per-queue notification offset for multi-queue virtio configurations

Quoted 17 lines · On Mon, 2026-06-22 at 20:25 -0400, [email protected] wrote:

From: Zhuoying Cai <[email protected]>

The initial support for virtio-blk-pci IPL devices used a single virt-queue, but other device types require multiple queues, and for PCI device types this also requires a per-queue notification offset.

Add a PCI notify field to the VRing struct so that each queue has a unique notify offset as defined in the virtio spec.

---
 pc-bios/s390-ccw/virtio-pci.c | 38 +++++++++++++++++++++--------------
 pc-bios/s390-ccw/virtio-pci.h |  2 +-
 pc-bios/s390-ccw/virtio.c     |  3 ++-
 pc-bios/s390-ccw/virtio.h     |  1 +
 4 files changed, 27 insertions(+), 17 deletions(-)

...snip...

pc-bios/s390-ccw/virtio.c bool vring_notify(VRing *vr) · line 118

Quoted 11 lines
pc-bios/s390-ccw/virtio.c +2 -1
index a448dc96e2..df04479aa6 100644
@@ -114,7 +114,8 @@ bool vring_notify(VRing *vr)
         vr->cookie = virtio_ccw_notify(vdev.schid, vr->id, vr->cookie);
         break;
     case S390_IPL_TYPE_PCI:
-        vr->cookie = virtio_pci_notify(vr->id);
+        vr->cookie = virtio_pci_notify(vr);
+        break;

The addition of this break is an important (and correct) fix, but shouldn't be tucked into this change. Please make it its own (preceding) patch, with a Fixes tag against d72fb5e6b2e.

Besides that, this looks fine.

Quoted 15 lines
pc-bios/s390-ccw/virtio.c +0 -0
     default:
         return 1;
     }
pc-bios/s390-ccw/virtio.h +1 -0
index d32a4830ca..75ae5bdbc2 100644
@@ -107,6 +107,7 @@ struct VRing {
     VRingUsed *used;
     long cookie;
     int id;
+    uint16_t pci_notify;
 };
 typedef struct VRing VRing;
 
#5 lore raw

PATCH 3/5 pc-bios/s390-ccw: write IPLB location for virtio-blk-pci IPL

In reply to [email protected]

From: Joshua Daley <[email protected]>

When IPL type is PCI, cutype is unknown, so the IPLB location does not get written to lowcore. Update the condition to check IPL type as well.

---
 pc-bios/s390-ccw/main.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
pc-bios/s390-ccw/main.c +2 -1
index 26287cfd81..1059fda03c 100644
@@ -52,7 +52,8 @@ void write_subsystem_identification(void)
 
 void write_iplb_location(void)
 {
-    if (cutype == CU_TYPE_VIRTIO && virtio_get_device_type() != VIRTIO_ID_NET) {
+    if ((cutype == CU_TYPE_VIRTIO || iplb.pbt == S390_IPL_TYPE_PCI) &&
+        virtio_get_device_type() != VIRTIO_ID_NET) {
         lowcore->ptr_iplb = ptr2u32(&iplb);
     }
 }
Signature · 1 line
2.54.0
#6 lore raw

Re: [PATCH 3/5] pc-bios/s390-ccw: write IPLB location for virtio-blk-pci IPL

Sorry all, I had a mental lapse when adding my sign-off to a couple patches in this series.

Disregard <[email protected]>
It should be:

Quoted 25 lines · On 6/22/26 8:25 PM, [email protected] wrote:

From: Joshua Daley <[email protected]>

When IPL type is PCI, cutype is unknown, so the IPLB location does not get written to lowcore. Update the condition to check IPL type as well.

---
  pc-bios/s390-ccw/main.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
pc-bios/s390-ccw/main.c +2 -1
index 26287cfd81..1059fda03c 100644
@@ -52,7 +52,8 @@ void write_subsystem_identification(void)
 
  void write_iplb_location(void)
  {
-    if (cutype == CU_TYPE_VIRTIO && virtio_get_device_type() != VIRTIO_ID_NET) {
+    if ((cutype == CU_TYPE_VIRTIO || iplb.pbt == S390_IPL_TYPE_PCI) &&
+        virtio_get_device_type() != VIRTIO_ID_NET) {
          lowcore->ptr_iplb = ptr2u32(&iplb);
      }
  }
#7 lore raw

Re: [PATCH 3/5] pc-bios/s390-ccw: write IPLB location for virtio-blk-pci IPL

In reply to [email protected]
Quoted 7 lines · On Mon, 2026-06-22 at 20:25 -0400, [email protected] wrote:

From: Joshua Daley <[email protected]>

When IPL type is PCI, cutype is unknown, so the IPLB location does not get written to lowcore. Update the condition to check IPL type as well.

I suppose "signed" is to be capitalized, but you mentioned this line is to be fixed anyway.

Quoted 9 lines
---
 pc-bios/s390-ccw/main.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
pc-bios/s390-ccw/main.c +0 -0
index 26287cfd81..1059fda03c 100644

pc-bios/s390-ccw/main.c void write_subsystem_identification(void) · line 55

Quoted 5 lines
pc-bios/s390-ccw/main.c +1 -1
@@ -52,7 +52,8 @@ void write_subsystem_identification(void)
 
 void write_iplb_location(void)
 {
-    if (cutype == CU_TYPE_VIRTIO && virtio_get_device_type() != VIRTIO_ID_NET) {
+    if ((cutype == CU_TYPE_VIRTIO || iplb.pbt == S390_IPL_TYPE_PCI) &&

Why iplb.pbt and not virtio_get_device()->ipl_type?

Quoted 4 lines
pc-bios/s390-ccw/main.c +1 -0
+        virtio_get_device_type() != VIRTIO_ID_NET) {
         lowcore->ptr_iplb = ptr2u32(&iplb);
     }
 }
#8 lore raw

Re: [PATCH 3/5] pc-bios/s390-ccw: write IPLB location for virtio-blk-pci IPL

Quoted 20 lines · Eric Farman
Quoted 7 lines · On Mon, 2026-06-22 at 20:25 -0400, [email protected] wrote:

From: Joshua Daley <[email protected]>

When IPL type is PCI, cutype is unknown, so the IPLB location does not get written to lowcore. Update the condition to check IPL type as well.

I suppose "signed" is to be capitalized, but you mentioned this line is to be fixed anyway.

Quoted 10 lines
---
  pc-bios/s390-ccw/main.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
pc-bios/s390-ccw/main.c +0 -0
index 26287cfd81..1059fda03c 100644
@@ -52,7 +52,8 @@ void write_subsystem_identification(void)
 
Quoted 5 lines

pc-bios/s390-ccw/main.c void write_subsystem_identification(void) · line 55

Quoted 4 lines
pc-bios/s390-ccw/main.c +1 -1
  void write_iplb_location(void)
  {
-    if (cutype == CU_TYPE_VIRTIO && virtio_get_device_type() != VIRTIO_ID_NET) {
+    if ((cutype == CU_TYPE_VIRTIO || iplb.pbt == S390_IPL_TYPE_PCI) &&

Why iplb.pbt and not virtio_get_device()->ipl_type?

It should have been, but I think an even better solution would be to use virtio_is_supported(). I’ll reorder the patches so that the is_virtio_supported() fix discussed in the comments on Patch 4 come before this, then use the generic call covering both CCW and PCI here.

Quoted 4 lines

pc-bios/s390-ccw/main.c void write_subsystem_identification(void) · line 59

Quoted 4 lines
pc-bios/s390-ccw/main.c +1 -0
+        virtio_get_device_type() != VIRTIO_ID_NET) {
          lowcore->ptr_iplb = ptr2u32(&iplb);
      }
  }

Thanks again,
Jared Rossi

#9 lore raw

PATCH 4/5 pc-bios/s390-ccw: Verify virtio support when booting from PCI device on s390x

In reply to [email protected]

From: Jared Rossi <[email protected]>

The virtio specification requires that each PCI device has a vendor ID of 0x1AF4. Verify this value before continuing with boot process.

---
 pc-bios/s390-ccw/main.c       |  1 +
 pc-bios/s390-ccw/virtio-pci.c | 19 +++++++++++++++++++
 pc-bios/s390-ccw/virtio.h     |  1 +
 3 files changed, 21 insertions(+)
pc-bios/s390-ccw/main.c +1 -0
index 1059fda03c..567e97bf32 100644
@@ -164,6 +164,7 @@ static bool find_fid(uint32_t fid)
     }
 
     vdev->pci_fh = entry.fh;
+    vdev->vendor_id = entry.vendor_id;
     virtio_pci_id2type(vdev, entry.device_id);
 
     return vdev->dev_type != 0;
pc-bios/s390-ccw/virtio-pci.c +19 -0
index 2c83ec4f13..07b53b894f 100644
@@ -325,6 +325,20 @@ static int enable_pci_bus_master(void)
     return 0;
 }
 
+bool virtio_pci_is_supported(VDev *vdev)
+{
+    if (vdev->vendor_id == 0x1AF4) {
+        switch (vdev->dev_type) {
+        case VIRTIO_ID_BLOCK:
+            return true;
+        default:
+            return false;
+        }
+    }
+
+    return false;
+}
+
 int virtio_pci_setup(VDev *vdev)
 {
     VRing *vr;
@@ -335,6 +349,11 @@ int virtio_pci_setup(VDev *vdev)
     vdev->guessed_disk_nature = VIRTIO_GDN_NONE;
     vdev->cmd_vr_idx = 0;
 
+    if (!virtio_pci_is_supported(vdev)) {
+        puts("Virtio PCI unsupported for this device ID");
+        return -ENODEV;
+    }
+
     if (virtio_pci_read_pci_cap_config()) {
         puts("Invalid virtio PCI capabilities");
         return -EIO;
pc-bios/s390-ccw/virtio.h +1 -0
index 75ae5bdbc2..aa307025e0 100644
@@ -259,6 +259,7 @@ struct VDev {
     bool scsi_device_selected;
     ScsiDevice selected_scsi_device;
     uint32_t pci_fh;
+    uint16_t vendor_id;
     uint32_t max_transfer;
     uint32_t guest_features[2];
 };
Signature · 1 line
2.54.0
#10 lore raw

Re: [PATCH 4/5] pc-bios/s390-ccw: Verify virtio support when booting from PCI device on s390x

Quoted 29 lines · On Mon, 2026-06-22 at 20:25 -0400, [email protected] wrote:

From: Jared Rossi <[email protected]>

The virtio specification requires that each PCI device has a vendor ID of 0x1AF4. Verify this value before continuing with boot process.

---
 pc-bios/s390-ccw/main.c       |  1 +
 pc-bios/s390-ccw/virtio-pci.c | 19 +++++++++++++++++++
 pc-bios/s390-ccw/virtio.h     |  1 +
 3 files changed, 21 insertions(+)
pc-bios/s390-ccw/main.c +1 -0
index 1059fda03c..567e97bf32 100644
@@ -164,6 +164,7 @@ static bool find_fid(uint32_t fid)
     }
 
     vdev->pci_fh = entry.fh;
+    vdev->vendor_id = entry.vendor_id;
     virtio_pci_id2type(vdev, entry.device_id);
 
     return vdev->dev_type != 0;
pc-bios/s390-ccw/virtio-pci.c +0 -0
index 2c83ec4f13..07b53b894f 100644

pc-bios/s390-ccw/virtio-pci.c static int enable_pci_bus_master(void) · line 330

Quoted 6 lines
pc-bios/s390-ccw/virtio-pci.c +3 -0
@@ -325,6 +325,20 @@ static int enable_pci_bus_master(void)
     return 0;
 }
 
+bool virtio_pci_is_supported(VDev *vdev)
+{
+    if (vdev->vendor_id == 0x1AF4) {

I'd prefer this hex value be lowercase, as they usually are in code.

Not sure where a good place would be, but defining a constant for the PCI Vendor ID 0x1af4 (similar
to #define CU_TYPE_VIRTIO 0x3832) would provide some good context of what's happening
here.

Quoted 15 lines
pc-bios/s390-ccw/virtio-pci.c +11 -0
+        switch (vdev->dev_type) {
+        case VIRTIO_ID_BLOCK:
+            return true;
+        default:
+            return false;
+        }
+    }
+
+    return false;
+}
+
 int virtio_pci_setup(VDev *vdev)
 {
     VRing *vr;

pc-bios/s390-ccw/virtio-pci.c int virtio_pci_setup(VDev *vdev) · line 352

Quoted 4 lines
pc-bios/s390-ccw/virtio-pci.c +1 -0
@@ -335,6 +349,11 @@ int virtio_pci_setup(VDev *vdev)
     vdev->guessed_disk_nature = VIRTIO_GDN_NONE;
     vdev->cmd_vr_idx = 0;
 
+    if (!virtio_pci_is_supported(vdev)) {

Why is this done here, versus called from virtio_is_supported() such that it covers both -ccw and - pci paths?

I'm guessing it's because the CLP data that contains the vendor_id isn't read until find_fid(), which runs against the possible call in probe_boot_device()->is_dev_possibly_bootable(). If there's a way to straighten out that chicken/egg I think that'd be useful.

Quoted 19 lines
pc-bios/s390-ccw/virtio-pci.c +4 -0
+        puts("Virtio PCI unsupported for this device ID");
+        return -ENODEV;
+    }
+
     if (virtio_pci_read_pci_cap_config()) {
         puts("Invalid virtio PCI capabilities");
         return -EIO;
pc-bios/s390-ccw/virtio.h +1 -0
index 75ae5bdbc2..aa307025e0 100644
@@ -259,6 +259,7 @@ struct VDev {
     bool scsi_device_selected;
     ScsiDevice selected_scsi_device;
     uint32_t pci_fh;
+    uint16_t vendor_id;
     uint32_t max_transfer;
     uint32_t guest_features[2];
 };
#11 lore raw

Re: [PATCH 4/5] pc-bios/s390-ccw: Verify virtio support when booting from PCI device on s390x

Quoted 33 lines · Eric Farman
Quoted 32 lines · On Mon, 2026-06-22 at 20:25 -0400, [email protected] wrote:

From: Jared Rossi <[email protected]>

The virtio specification requires that each PCI device has a vendor ID of 0x1AF4. Verify this value before continuing with boot process.

---
  pc-bios/s390-ccw/main.c       |  1 +
  pc-bios/s390-ccw/virtio-pci.c | 19 +++++++++++++++++++
  pc-bios/s390-ccw/virtio.h     |  1 +
  3 files changed, 21 insertions(+)
pc-bios/s390-ccw/main.c +1 -0
index 1059fda03c..567e97bf32 100644
@@ -164,6 +164,7 @@ static bool find_fid(uint32_t fid)
      }
 
      vdev->pci_fh = entry.fh;
+    vdev->vendor_id = entry.vendor_id;
      virtio_pci_id2type(vdev, entry.device_id);
 
      return vdev->dev_type != 0;
pc-bios/s390-ccw/virtio-pci.c +0 -0
index 2c83ec4f13..07b53b894f 100644
@@ -325,6 +325,20 @@ static int enable_pci_bus_master(void)
      return 0;
  }
 
Quoted 8 lines

pc-bios/s390-ccw/virtio-pci.c static int enable_pci_bus_master(void) · line 330

Quoted 3 lines
pc-bios/s390-ccw/virtio-pci.c +3 -0
+bool virtio_pci_is_supported(VDev *vdev)
+{
+    if (vdev->vendor_id == 0x1AF4) {

I'd prefer this hex value be lowercase, as they usually are in code.

Not sure where a good place would be, but defining a constant for the PCI Vendor ID 0x1af4 (similar
to #define CU_TYPE_VIRTIO 0x3832) would provide some good context of what's happening
here.

Good ideas, will do.

Quoted 19 lines
Quoted 19 lines
pc-bios/s390-ccw/virtio-pci.c +11 -0
+        switch (vdev->dev_type) {
+        case VIRTIO_ID_BLOCK:
+            return true;
+        default:
+            return false;
+        }
+    }
+
+    return false;
+}
+
  int virtio_pci_setup(VDev *vdev)
  {
      VRing *vr;
@@ -335,6 +349,11 @@ int virtio_pci_setup(VDev *vdev)
      vdev->guessed_disk_nature = VIRTIO_GDN_NONE;
      vdev->cmd_vr_idx = 0;
 
Quoted 7 lines

pc-bios/s390-ccw/virtio-pci.c int virtio_pci_setup(VDev *vdev) · line 352

Quoted 1 line
pc-bios/s390-ccw/virtio-pci.c +1 -0
+    if (!virtio_pci_is_supported(vdev)) {

Why is this done here, versus called from virtio_is_supported() such that it covers both -ccw and - pci paths?

I'm guessing it's because the CLP data that contains the vendor_id isn't read until find_fid(), which runs against the possible call in probe_boot_device()->is_dev_possibly_bootable(). If there's a way to straighten out that chicken/egg I think that'd be useful.

The short answer is that this is an analogous call to the one in the virtio CCW setup that also calls the bus specific check directly (which seems reasonable given that we are doing the bus specific setup). The call from is_device_possibly_bootable() serves a different purpose from the ones in the virtio setup functions; both are needed and there isn’t any chicken/egg problem with that.

Although you are correct that the virtio_is_supported() generic wrapper should contain the case for PCI, so I will fix that now.

Quoted 12 lines
Quoted 12 lines
pc-bios/s390-ccw/virtio-pci.c +4 -0
+        puts("Virtio PCI unsupported for this device ID");
+        return -ENODEV;
+    }
+
      if (virtio_pci_read_pci_cap_config()) {
          puts("Invalid virtio PCI capabilities");
          return -EIO;
pc-bios/s390-ccw/virtio.h +0 -0
index 75ae5bdbc2..aa307025e0 100644
Quoted 8 lines

pc-bios/s390-ccw/virtio.h struct VDev { · line 265

Quoted 8 lines
pc-bios/s390-ccw/virtio.h +1 -0
@@ -259,6 +259,7 @@ struct VDev {
      bool scsi_device_selected;
      ScsiDevice selected_scsi_device;
      uint32_t pci_fh;
+    uint16_t vendor_id;
      uint32_t max_transfer;
      uint32_t guest_features[2];
  };

Thanks for the feedback,

Regards,
Jared Rossi

#12 lore raw

PATCH 5/5 s390x: Enable boot menu for virtio pci device

In reply to [email protected]

From: Zhuoying Cai <[email protected]>

Add S390_IPL_TYPE_PCI to the boot menu handling logic to enable interactive boot menu support for virtio PCI devices on s390x.

---
 hw/s390x/ipl.c          | 1 +
 pc-bios/s390-ccw/main.c | 1 +
 2 files changed, 2 insertions(+)
hw/s390x/ipl.c +1 -0
index 4cca21c621..d5fdc3ea0f 100644
@@ -315,6 +315,7 @@ static void s390_ipl_set_boot_menu(S390IPLState *ipl)
             return;
         }
         break;
+    case S390_IPL_TYPE_PCI:
     case S390_IPL_TYPE_QEMU_SCSI:
         break;
     default:
pc-bios/s390-ccw/main.c +1 -0
index 567e97bf32..be83d598e2 100644
@@ -185,6 +185,7 @@ static void menu_setup(VDev *vdev)
 
     switch (vdev->ipl_type) {
     case S390_IPL_TYPE_CCW:
+    case S390_IPL_TYPE_PCI:
     case S390_IPL_TYPE_QEMU_SCSI:
         menu_set_parms(qipl.qipl_flags & BOOT_MENU_FLAG_MASK,
                        qipl.boot_menu_timeout);
Signature · 1 line
2.54.0
#13 lore raw

Re: [PATCH 5/5] s390x: Enable boot menu for virtio pci device

Please disregard <[email protected]>
It should be:

Quoted 36 lines · On 6/22/26 8:25 PM, [email protected] wrote:

From: Zhuoying Cai <[email protected]>

Add S390_IPL_TYPE_PCI to the boot menu handling logic to enable interactive boot menu support for virtio PCI devices on s390x.

---
  hw/s390x/ipl.c          | 1 +
  pc-bios/s390-ccw/main.c | 1 +
  2 files changed, 2 insertions(+)
hw/s390x/ipl.c +1 -0
index 4cca21c621..d5fdc3ea0f 100644
@@ -315,6 +315,7 @@ static void s390_ipl_set_boot_menu(S390IPLState *ipl)
              return;
          }
          break;
+    case S390_IPL_TYPE_PCI:
      case S390_IPL_TYPE_QEMU_SCSI:
          break;
      default:
pc-bios/s390-ccw/main.c +1 -0
index 567e97bf32..be83d598e2 100644
@@ -185,6 +185,7 @@ static void menu_setup(VDev *vdev)
 
      switch (vdev->ipl_type) {
      case S390_IPL_TYPE_CCW:
+    case S390_IPL_TYPE_PCI:
      case S390_IPL_TYPE_QEMU_SCSI:
          menu_set_parms(qipl.qipl_flags & BOOT_MENU_FLAG_MASK,
                         qipl.boot_menu_timeout);
Reviewed-by on v1 5/5
#14 lore raw

Re: [PATCH 5/5] s390x: Enable boot menu for virtio pci device

In reply to [email protected]
Quoted 11 lines · On Mon, 2026-06-22 at 20:25 -0400, [email protected] wrote:

From: Zhuoying Cai <[email protected]>

Add S390_IPL_TYPE_PCI to the boot menu handling logic to enable interactive boot menu support for virtio PCI devices on s390x.

---
 hw/s390x/ipl.c          | 1 +
 pc-bios/s390-ccw/main.c | 1 +
 2 files changed, 2 insertions(+)