Blame SOURCES/kvm-pc-bios-s390-ccw-bootmap-Improve-the-guessing-logic-.patch

4841a6
From 8433b2ba40d0618c7086da87685e1c51b6da3b11 Mon Sep 17 00:00:00 2001
4841a6
From: Thomas Huth <thuth@redhat.com>
4841a6
Date: Fri, 8 Jul 2022 12:29:50 +0200
4841a6
Subject: [PATCH 30/37] pc-bios/s390-ccw/bootmap: Improve the guessing logic in
4841a6
 zipl_load_vblk()
4841a6
4841a6
RH-Author: Thomas Huth <thuth@redhat.com>
4841a6
RH-MergeRequest: 198: pc-bios/s390-ccw: Fix boot from disks with 4k sectors that do not have the typical DASD geometry
4841a6
RH-Commit: [2/9] db1d2e7929352bec0e1a5d4cf3fb385bbe02304b
4841a6
RH-Bugzilla: 2098076
4841a6
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
4841a6
RH-Acked-by: David Hildenbrand <david@redhat.com>
4841a6
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
4841a6
4841a6
Bugzilla: http://bugzilla.redhat.com/2098076
4841a6
4841a6
commit 422865f6672ee1482b98d18321b55c1ecfb06c82
4841a6
Author: Thomas Huth <thuth@redhat.com>
4841a6
Date:   Mon Jul 4 13:18:54 2022 +0200
4841a6
4841a6
    pc-bios/s390-ccw/bootmap: Improve the guessing logic in zipl_load_vblk()
4841a6
4841a6
    The logic of trying an final ISO or ECKD boot on virtio-block devices is
4841a6
    very weird: Since the geometry hardly ever matches in virtio_disk_is_scsi(),
4841a6
    virtio_blk_setup_device() always sets a "guessed" disk geometry via
4841a6
    virtio_assume_scsi() (which is certainly also wrong in a lot of cases).
4841a6
4841a6
    zipl_load_vblk() then sees that there's been a "virtio_guessed_disk_nature"
4841a6
    and tries to fix up the geometry again via virtio_assume_iso9660() before
4841a6
    always trying to do ipl_iso_el_torito(). That's a very brain-twisting
4841a6
    way of attempting to boot from ISO images, which won't work anymore after
4841a6
    the following patches that will clean up the virtio_assume_scsi() mess
4841a6
    (and thus get rid of the "virtio_guessed_disk_nature" here).
4841a6
4841a6
    Let's try a better approach instead: ISO files always have a magic
4841a6
    string "CD001" at offset 0x8001 (see e.g. the ECMA-119 specification)
4841a6
    which we can use to decide whether we should try to boot in ISO 9660
4841a6
    mode (which we should also try if we see a sector size of 2048).
4841a6
4841a6
    And if we were not able to boot in ISO mode here, the final boot attempt
4841a6
    before panicking is to boot in ECKD mode. Since this is our last boot
4841a6
    attempt anyway, simply always assume the ECKD geometry here (if the sector
4841a6
    size was not 4096 yet), so that we also do not depend on the guessed disk
4841a6
    geometry from virtio_blk_setup_device() here anymore.
4841a6
4841a6
    Message-Id: <20220704111903.62400-4-thuth@redhat.com>
4841a6
    Signed-off-by: Thomas Huth <thuth@redhat.com>
4841a6
4841a6
Signed-off-by: Thomas Huth <thuth@redhat.com>
4841a6
---
4841a6
 pc-bios/s390-ccw/bootmap.c | 27 +++++++++++++++++++++++----
4841a6
 1 file changed, 23 insertions(+), 4 deletions(-)
4841a6
4841a6
diff --git a/pc-bios/s390-ccw/bootmap.c b/pc-bios/s390-ccw/bootmap.c
4841a6
index 56411ab3b6..994e59c0b0 100644
4841a6
--- a/pc-bios/s390-ccw/bootmap.c
4841a6
+++ b/pc-bios/s390-ccw/bootmap.c
4841a6
@@ -780,18 +780,37 @@ static void ipl_iso_el_torito(void)
4841a6
     }
4841a6
 }
4841a6
 
4841a6
+/**
4841a6
+ * Detect whether we're trying to boot from an .ISO image.
4841a6
+ * These always have a signature string "CD001" at offset 0x8001.
4841a6
+ */
4841a6
+static bool has_iso_signature(void)
4841a6
+{
4841a6
+    int blksize = virtio_get_block_size();
4841a6
+
4841a6
+    if (!blksize || virtio_read(0x8000 / blksize, sec)) {
4841a6
+        return false;
4841a6
+    }
4841a6
+
4841a6
+    return !memcmp("CD001", &sec[1], 5);
4841a6
+}
4841a6
+
4841a6
 /***********************************************************************
4841a6
  * Bus specific IPL sequences
4841a6
  */
4841a6
 
4841a6
 static void zipl_load_vblk(void)
4841a6
 {
4841a6
-    if (virtio_guessed_disk_nature()) {
4841a6
-        virtio_assume_iso9660();
4841a6
+    int blksize = virtio_get_block_size();
4841a6
+
4841a6
+    if (blksize == VIRTIO_ISO_BLOCK_SIZE || has_iso_signature()) {
4841a6
+        if (blksize != VIRTIO_ISO_BLOCK_SIZE) {
4841a6
+            virtio_assume_iso9660();
4841a6
+        }
4841a6
+        ipl_iso_el_torito();
4841a6
     }
4841a6
-    ipl_iso_el_torito();
4841a6
 
4841a6
-    if (virtio_guessed_disk_nature()) {
4841a6
+    if (blksize != VIRTIO_DASD_DEFAULT_BLOCK_SIZE) {
4841a6
         sclp_print("Using guessed DASD geometry.\n");
4841a6
         virtio_assume_eckd();
4841a6
     }
4841a6
-- 
4841a6
2.35.3
4841a6