thebeanogamer / rpms / qemu-kvm

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