0727d3
From f09f2f12133073d6ccab3b2bd95717d435adc442 Mon Sep 17 00:00:00 2001
0727d3
From: Thomas Huth <thuth@redhat.com>
0727d3
Date: Fri, 8 Jul 2022 12:29:50 +0200
0727d3
Subject: [PATCH 31/37] pc-bios/s390-ccw/virtio-blkdev: Simplify/fix
0727d3
 virtio_ipl_disk_is_valid()
0727d3
0727d3
RH-Author: Thomas Huth <thuth@redhat.com>
0727d3
RH-MergeRequest: 198: pc-bios/s390-ccw: Fix boot from disks with 4k sectors that do not have the typical DASD geometry
0727d3
RH-Commit: [3/9] ca0b836a417ce5bbd26e489551f573d6b2fc9e94
0727d3
RH-Bugzilla: 2098076
0727d3
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
0727d3
RH-Acked-by: David Hildenbrand <david@redhat.com>
0727d3
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
0727d3
0727d3
Bugzilla: http://bugzilla.redhat.com/2098076
0727d3
0727d3
commit bbf615f7b707f009ef8e757d170902ad33b90644
0727d3
Author: Thomas Huth <thuth@redhat.com>
0727d3
Date:   Mon Jul 4 13:18:55 2022 +0200
0727d3
0727d3
    pc-bios/s390-ccw/virtio-blkdev: Simplify/fix virtio_ipl_disk_is_valid()
0727d3
0727d3
    The s390-ccw bios fails to boot if the boot disk is a virtio-blk
0727d3
    disk with a sector size of 4096. For example:
0727d3
0727d3
     dasdfmt -b 4096 -d cdl -y -p -M quick /dev/dasdX
0727d3
     fdasd -a /dev/dasdX
0727d3
     install a guest onto /dev/dasdX1 using virtio-blk
0727d3
     qemu-system-s390x -nographic -hda /dev/dasdX1
0727d3
0727d3
    The bios then bails out with:
0727d3
0727d3
     ! Cannot read block 0 !
0727d3
0727d3
    Looking at virtio_ipl_disk_is_valid() and especially the function
0727d3
    virtio_disk_is_scsi(), it does not really make sense that we expect
0727d3
    only such a limited disk geometry (like a block size of 512) for
0727d3
    our boot disks. Let's relax the check and allow everything that
0727d3
    remotely looks like a sane disk.
0727d3
0727d3
    Message-Id: <20220704111903.62400-5-thuth@redhat.com>
0727d3
    Reviewed-by: Eric Farman <farman@linux.ibm.com>
0727d3
    Signed-off-by: Thomas Huth <thuth@redhat.com>
0727d3
0727d3
Signed-off-by: Thomas Huth <thuth@redhat.com>
0727d3
---
0727d3
 pc-bios/s390-ccw/virtio-blkdev.c | 41 ++++++--------------------------
0727d3
 pc-bios/s390-ccw/virtio.h        |  2 --
0727d3
 2 files changed, 7 insertions(+), 36 deletions(-)
0727d3
0727d3
diff --git a/pc-bios/s390-ccw/virtio-blkdev.c b/pc-bios/s390-ccw/virtio-blkdev.c
0727d3
index 6483307630..7e13155589 100644
0727d3
--- a/pc-bios/s390-ccw/virtio-blkdev.c
0727d3
+++ b/pc-bios/s390-ccw/virtio-blkdev.c
0727d3
@@ -166,46 +166,19 @@ void virtio_assume_eckd(void)
0727d3
         virtio_eckd_sectors_for_block_size(vdev->config.blk.blk_size);
0727d3
 }
0727d3
 
0727d3
-bool virtio_disk_is_scsi(void)
0727d3
-{
0727d3
-    VDev *vdev = virtio_get_device();
0727d3
-
0727d3
-    if (vdev->guessed_disk_nature == VIRTIO_GDN_SCSI) {
0727d3
-        return true;
0727d3
-    }
0727d3
-    switch (vdev->senseid.cu_model) {
0727d3
-    case VIRTIO_ID_BLOCK:
0727d3
-        return (vdev->config.blk.geometry.heads == 255)
0727d3
-            && (vdev->config.blk.geometry.sectors == 63)
0727d3
-            && (virtio_get_block_size()  == VIRTIO_SCSI_BLOCK_SIZE);
0727d3
-    case VIRTIO_ID_SCSI:
0727d3
-        return true;
0727d3
-    }
0727d3
-    return false;
0727d3
-}
0727d3
-
0727d3
-bool virtio_disk_is_eckd(void)
0727d3
+bool virtio_ipl_disk_is_valid(void)
0727d3
 {
0727d3
+    int blksize = virtio_get_block_size();
0727d3
     VDev *vdev = virtio_get_device();
0727d3
-    const int block_size = virtio_get_block_size();
0727d3
 
0727d3
-    if (vdev->guessed_disk_nature == VIRTIO_GDN_DASD) {
0727d3
+    if (vdev->guessed_disk_nature == VIRTIO_GDN_SCSI ||
0727d3
+        vdev->guessed_disk_nature == VIRTIO_GDN_DASD) {
0727d3
         return true;
0727d3
     }
0727d3
-    switch (vdev->senseid.cu_model) {
0727d3
-    case VIRTIO_ID_BLOCK:
0727d3
-        return (vdev->config.blk.geometry.heads == 15)
0727d3
-            && (vdev->config.blk.geometry.sectors ==
0727d3
-                virtio_eckd_sectors_for_block_size(block_size));
0727d3
-    case VIRTIO_ID_SCSI:
0727d3
-        return false;
0727d3
-    }
0727d3
-    return false;
0727d3
-}
0727d3
 
0727d3
-bool virtio_ipl_disk_is_valid(void)
0727d3
-{
0727d3
-    return virtio_disk_is_scsi() || virtio_disk_is_eckd();
0727d3
+    return (vdev->senseid.cu_model == VIRTIO_ID_BLOCK ||
0727d3
+            vdev->senseid.cu_model == VIRTIO_ID_SCSI) &&
0727d3
+           blksize >= 512 && blksize <= 4096;
0727d3
 }
0727d3
 
0727d3
 int virtio_get_block_size(void)
0727d3
diff --git a/pc-bios/s390-ccw/virtio.h b/pc-bios/s390-ccw/virtio.h
0727d3
index 9e410bde6f..241730effe 100644
0727d3
--- a/pc-bios/s390-ccw/virtio.h
0727d3
+++ b/pc-bios/s390-ccw/virtio.h
0727d3
@@ -186,8 +186,6 @@ void virtio_assume_scsi(void);
0727d3
 void virtio_assume_eckd(void);
0727d3
 void virtio_assume_iso9660(void);
0727d3
 
0727d3
-extern bool virtio_disk_is_scsi(void);
0727d3
-extern bool virtio_disk_is_eckd(void);
0727d3
 extern bool virtio_ipl_disk_is_valid(void);
0727d3
 extern int virtio_get_block_size(void);
0727d3
 extern uint8_t virtio_get_heads(void);
0727d3
-- 
0727d3
2.35.3
0727d3