thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 7 months ago
Clone

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

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