Skip to contentSkip to conversation

s390-ccw.img: block size and DASD format support

PATCH Applied Jens Freimann 3 participants 10 messages Aug 29, 2014 – Sep 5, 2014

lore
Share & tools
lore
#0 lore raw

cover s390-ccw.img: block size and DASD format support

Patches 1-5 contain changes improving support of more disk formats and block sizes.

Patch 6 makes sure we print a newline to leave a clean slate before continuing with IPL.

Patch 7 updates the binary.

regards
Jens

Christian Borntraeger (1):
pc-bios/s390-ccw: Do proper console setup

Eugene (jno) Dvurechenski (6):
pc-bios/s390-ccw: support all virtio block size pc-bios/s390-ccw: handle more ECKD DASD block sizes pc-bios/s390-ccw Improve ECKD informational message pc-bios/s390-ccw Really big EAV ECKD DASD handling pc-bios/s390-ccw: IPL from DASD with format variations pc-bios/s390-ccw.img binary update

 pc-bios/s390-ccw.img       | Bin 17752 -> 17752 bytes
 pc-bios/s390-ccw/bootmap.c | 107 +++++++++++++++++++++++++++------------------
 pc-bios/s390-ccw/bootmap.h |   2 +-
 pc-bios/s390-ccw/virtio.c  |  48 +++++++++++++++-----
 pc-bios/s390-ccw/virtio.h  |   2 +-
 5 files changed, 103 insertions(+), 56 deletions(-)
Signature · 1 line
1.8.5.5
#3 lore raw

PATCH 3/7 pc-bios/s390-ccw Improve ECKD informational message

From: "Eugene (jno) Dvurechenski" <[email protected]>

Add block size display to ECKD scheme report.

---
 pc-bios/s390-ccw/bootmap.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)
pc-bios/s390-ccw/bootmap.c +20 -2
index f175679..e4352b1 100644
@@ -298,6 +298,25 @@ static void ipl_eckd(ECKD_IPL_mode_t mode)
     }
 }
 
+static void print_eckd_msg(void)
+{
+    char msg[] = "Using ECKD scheme (block size *****), ";
+    char *p = &msg[34], *q = &msg[30];
+    int n = virtio_get_block_size();
+
+    /* Fill in the block size and show up the message */
+    if (n > 0 && n <= 99999) {
+        while (n) {
+            *p-- = '0' + (n % 10);
+            n /= 10;
+        }
+        while (p >= q) {
+            *p-- = ' ';
+        }
+    }
+    sclp_print(msg);
+}
+
 /***********************************************************************
  * IPL a SCSI disk
  */
@@ -447,12 +466,11 @@ void zipl_load(void)
     }
 
     /* We have failed to follow the SCSI scheme, so */
-    sclp_print("Using ECKD scheme.\n");
     if (virtio_guessed_disk_nature()) {
         sclp_print("Using guessed DASD geometry.\n");
         virtio_assume_eckd();
     }
-
+    print_eckd_msg();
     if (magic_match(mbr->magic, IPL1_MAGIC)) {
         ipl_eckd(ECKD_CDL); /* no return */
     }
Signature · 1 line
1.8.5.5
#2 lore raw

PATCH 2/7 pc-bios/s390-ccw: handle more ECKD DASD block sizes

In reply to Jens Freimann

From: "Eugene (jno) Dvurechenski" <[email protected]>

Using dasdfmt(8) to format a DASD allows to choose a block size. There are four supported values: 512, 1024, 2048, and 4096 bytes per block. Each block size leads to selection of new count of sectors per track. The head count remains always the same: 15.

This empiric knowledge is used to detect ECKD DASD to IPL from.

---
 pc-bios/s390-ccw/virtio.c | 27 ++++++++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)
pc-bios/s390-ccw/virtio.c +24 -3
index 04977e4..6ed3dc9 100644
@@ -299,14 +299,35 @@ bool virtio_disk_is_scsi(void)
         && (virtio_get_block_size()  == 512);
 }
 
+/*
+ * Other supported value pairs, if any, would need to be added here.
+ * Note: head count is always 15.
+ */
+static inline u8 virtio_eckd_sectors_for_block_size(int size)
+{
+    switch (size) {
+    case 512:
+        return 49;
+    case 1024:
+        return 33;
+    case 2048:
+        return 21;
+    case 4096:
+        return 12;
+    }
+    return 0;
+}
+
 bool virtio_disk_is_eckd(void)
 {
+    const int block_size = virtio_get_block_size();
+
     if (guessed_disk_nature) {
-        return (virtio_get_block_size()  == 4096);
+        return (block_size  == 4096);
     }
     return (blk_cfg.geometry.heads == 15)
-        && (blk_cfg.geometry.sectors == 12)
-        && (virtio_get_block_size()  == 4096);
+        && (blk_cfg.geometry.sectors ==
+            virtio_eckd_sectors_for_block_size(block_size));
 }
 
 bool virtio_ipl_disk_is_valid(void)
Signature · 1 line
1.8.5.5
#4 lore raw

PATCH 4/7 pc-bios/s390-ccw Really big EAV ECKD DASD handling

In reply to Jens Freimann

From: "Eugene (jno) Dvurechenski" <[email protected]>

For EAV ECKD DASD, the cylinder count will have the magic value 0xfffeU. Therefore, use the block number to test for valid eckd addresses instead.

---
 pc-bios/s390-ccw/bootmap.c | 31 +++++++++++++++----------------
 pc-bios/s390-ccw/virtio.c  | 11 ++++++-----
 pc-bios/s390-ccw/virtio.h  |  2 +-
 3 files changed, 22 insertions(+), 22 deletions(-)
pc-bios/s390-ccw/bootmap.c +15 -16
index e4352b1..d4c579c 100644
@@ -93,11 +93,23 @@ static inline void verify_boot_info(BootInfo *bip)
                "Bad block size in zIPL section of the 1st record.");
 }
 
-static bool eckd_valid_address(BootMapPointer *p)
+static block_number_t eckd_block_num(BootMapPointer *p)
 {
+    const uint64_t sectors = virtio_get_sectors();
+    const uint64_t heads = virtio_get_heads();
     const uint64_t cylinder = p->eckd.cylinder
                             + ((p->eckd.head & 0xfff0) << 12);
     const uint64_t head = p->eckd.head & 0x000f;
+    const block_number_t block = sectors * heads * cylinder
+                               + sectors * head
+                               + p->eckd.sector
+                               - 1; /* block nr starts with zero */
+    return block;
+}
+
+static bool eckd_valid_address(BootMapPointer *p)
+{
+    const uint64_t head = p->eckd.head & 0x000f;
 
     if (head >= virtio_get_heads()
         ||  p->eckd.sector > virtio_get_sectors()
@@ -105,27 +117,14 @@ static bool eckd_valid_address(BootMapPointer *p)
         return false;
     }
 
-    if (!virtio_guessed_disk_nature() && cylinder >= virtio_get_cylinders()) {
+    if (!virtio_guessed_disk_nature() &&
+        eckd_block_num(p) >= virtio_get_blocks()) {
         return false;
     }
 
     return true;
 }
 
-static block_number_t eckd_block_num(BootMapPointer *p)
-{
-    const uint64_t sectors = virtio_get_sectors();
-    const uint64_t heads = virtio_get_heads();
-    const uint64_t cylinder = p->eckd.cylinder
-                            + ((p->eckd.head & 0xfff0) << 12);
-    const uint64_t head = p->eckd.head & 0x000f;
-    const block_number_t block = sectors * heads * cylinder
-                               + sectors * head
-                               + p->eckd.sector
-                               - 1; /* block nr starts with zero */
-    return block;
-}
-
 static block_number_t load_eckd_segments(block_number_t blk, uint64_t *address)
 {
     block_number_t block_nr;
pc-bios/s390-ccw/virtio.c +6 -5
index 6ed3dc9..c0540d1 100644
@@ -340,11 +340,6 @@ int virtio_get_block_size(void)
     return blk_cfg.blk_size << blk_cfg.physical_block_exp;
 }
 
-uint16_t virtio_get_cylinders(void)
-{
-    return blk_cfg.geometry.cylinders;
-}
-
 uint8_t virtio_get_heads(void)
 {
     return blk_cfg.geometry.heads;
@@ -355,6 +350,12 @@ uint8_t virtio_get_sectors(void)
     return blk_cfg.geometry.sectors;
 }
 
+uint64_t virtio_get_blocks(void)
+{
+    return blk_cfg.capacity /
+           (virtio_get_block_size() / VIRTIO_SECTOR_SIZE);
+}
+
 void virtio_setup_block(struct subchannel_id schid)
 {
     struct vq_info_block info;
pc-bios/s390-ccw/virtio.h +1 -1
index f1fb1b0..c23466b 100644
@@ -192,9 +192,9 @@ extern bool virtio_disk_is_scsi(void);
 extern bool virtio_disk_is_eckd(void);
 extern bool virtio_ipl_disk_is_valid(void);
 extern int virtio_get_block_size(void);
-extern uint16_t virtio_get_cylinders(void);
 extern uint8_t virtio_get_heads(void);
 extern uint8_t virtio_get_sectors(void);
+extern uint64_t virtio_get_blocks(void);
 extern int virtio_read_many(ulong sector, void *load_addr, int sec_num);
 
 #define VIRTIO_SECTOR_SIZE 512
Signature · 1 line
1.8.5.5
#5 lore raw

PATCH 5/7 pc-bios/s390-ccw: IPL from DASD with format variations

In reply to Jens Freimann

From: "Eugene (jno) Dvurechenski" <[email protected]>

There are two known cases of DASD format where signatures are incomplete or absent:

1. result of <dasdfmt -d ldl -L ...> (ECKD_LDL_UNLABELED)
2. CDL with zero keys in IPL1 and IPL2 records

Now the code attempts to
1. find zIPL and use SCSI layout
2. find IPL1 and use CDL layout
3. find CMS1 and use LDL layout
3. find LNX1 and use LDL layout
4. find zIPL and use unlabeled LDL layout
5. find zIPL and use CDL layout
6. die
in this sequence.

---
 pc-bios/s390-ccw/bootmap.c | 52 ++++++++++++++++++++++++++--------------------
 pc-bios/s390-ccw/bootmap.h |  2 +-
 2 files changed, 30 insertions(+), 24 deletions(-)
pc-bios/s390-ccw/bootmap.c +29 -23
index d4c579c..aa1cf80 100644
@@ -222,7 +222,6 @@ static void ipl_eckd_cdl(void)
 
     memset(sec, FREE_SPACE_FILLER, sizeof(sec));
     read_block(1, ipl2, "Cannot read IPL2 record at block 1");
-    IPL_assert(magic_match(ipl2, IPL2_MAGIC), "No IPL2 record");
 
     mbr = &ipl2->u.x.mbr;
     IPL_assert(magic_match(mbr, ZIPL_MAGIC), "No zIPL section in IPL2 record.");
@@ -246,12 +245,10 @@ static void ipl_eckd_cdl(void)
     /* no return */
 }
 
-static void ipl_eckd_ldl(ECKD_IPL_mode_t mode)
+static void print_eckd_ldl_msg(ECKD_IPL_mode_t mode)
 {
     LDL_VTOC *vlbl = (void *)sec; /* already read, 3rd block */
     char msg[4] = { '?', '.', '\n', '\0' };
-    block_number_t block_nr;
-    BootInfo *bip;
 
     sclp_print((mode == ECKD_CMS) ? "CMS" : "LDL");
     sclp_print(" version ");
@@ -271,12 +268,27 @@ static void ipl_eckd_ldl(ECKD_IPL_mode_t mode)
     }
     sclp_print(msg);
     print_volser(vlbl->volser);
+}
+
+static void ipl_eckd_ldl(ECKD_IPL_mode_t mode)
+{
+    block_number_t block_nr;
+    BootInfo *bip = (void *)(sec + 0x70); /* BootInfo is MBR for LDL */
+
+    if (mode != ECKD_LDL_UNLABELED) {
+        print_eckd_ldl_msg(mode);
+    }
 
     /* DO NOT read BootMap pointer (only one, xECKD) at block #2 */
 
     memset(sec, FREE_SPACE_FILLER, sizeof(sec));
-    read_block(0, sec, "Cannot read block 0");
-    bip = (void *)(sec + 0x70); /* "boot info" is "eckd mbr" for LDL */
+    read_block(0, sec, "Cannot read block 0 to grab boot info.");
+    if (mode == ECKD_LDL_UNLABELED) {
+        if (!magic_match(bip->magic, ZIPL_MAGIC)) {
+            return; /* not applicable layout */
+        }
+        sclp_print("unlabeled LDL.\n");
+    }
     verify_boot_info(bip);
 
     block_nr = eckd_block_num((void *)&(bip->bp.ipl.bm_ptr.eckd.bptr));
@@ -284,19 +296,6 @@ static void ipl_eckd_ldl(ECKD_IPL_mode_t mode)
     /* no return */
 }
 
-static void ipl_eckd(ECKD_IPL_mode_t mode)
-{
-    switch (mode) {
-    case ECKD_CDL:
-        ipl_eckd_cdl(); /* no return */
-    case ECKD_CMS:
-    case ECKD_LDL:
-        ipl_eckd_ldl(mode); /* no return */
-    default:
-        virtio_panic("\n! Unknown ECKD IPL mode !\n");
-    }
-}
-
 static void print_eckd_msg(void)
 {
     char msg[] = "Using ECKD scheme (block size *****), ";
@@ -471,7 +470,7 @@ void zipl_load(void)
     }
     print_eckd_msg();
     if (magic_match(mbr->magic, IPL1_MAGIC)) {
-        ipl_eckd(ECKD_CDL); /* no return */
+        ipl_eckd_cdl(); /* no return */
     }
 
     /* LDL/CMS? */
@@ -479,11 +478,18 @@ void zipl_load(void)
     read_block(2, vlbl, "Cannot read block 2");
 
     if (magic_match(vlbl->magic, CMS1_MAGIC)) {
-        ipl_eckd(ECKD_CMS); /* no return */
+        ipl_eckd_ldl(ECKD_CMS); /* no return */
     }
     if (magic_match(vlbl->magic, LNX1_MAGIC)) {
-        ipl_eckd(ECKD_LDL); /* no return */
+        ipl_eckd_ldl(ECKD_LDL); /* no return */
     }
 
-    virtio_panic("\n* invalid MBR magic *\n");
+    ipl_eckd_ldl(ECKD_LDL_UNLABELED); /* it still may return */
+    /*
+     * Ok, it is not a LDL by any means.
+     * It still might be a CDL with zero record keys for IPL1 and IPL2
+     */
+    ipl_eckd_cdl();
+
+    virtio_panic("\n* this can never happen *\n");
 }
pc-bios/s390-ccw/bootmap.h +1 -1
index 30ef22f..6a4823d 100644
@@ -257,9 +257,9 @@ typedef struct IplVolumeLabel {
 
 typedef enum {
     ECKD_NO_IPL,
-    ECKD_CDL,
     ECKD_CMS,
     ECKD_LDL,
+    ECKD_LDL_UNLABELED,
 } ECKD_IPL_mode_t;
 
 /* utility code below */
Signature · 1 line
1.8.5.5
#1 lore raw

PATCH 1/7 pc-bios/s390-ccw: support all virtio block size

In reply to Jens Freimann

From: "Eugene (jno) Dvurechenski" <[email protected]>

The block size value may be given "as is" OR as a base value and a shift count (exponent). So, we have to use calculation to get the proper number in the code.

The main expression reads as
(blk_cfg.blk_size << blk_cfg.physical_block_exp)

E.g., various combinations between blk_size=1/physical_block_exp=12 and blk_size=4096/physical_block_exp=0 are valid for 4K blocks.

---
 pc-bios/s390-ccw/virtio.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
pc-bios/s390-ccw/virtio.c +8 -6
index 31b23b0..04977e4 100644
@@ -275,12 +275,14 @@ void virtio_assume_scsi(void)
 {
     guessed_disk_nature = true;
     blk_cfg.blk_size = 512;
+    blk_cfg.physical_block_exp = 0;
 }
 
 void virtio_assume_eckd(void)
 {
     guessed_disk_nature = true;
     blk_cfg.blk_size = 4096;
+    blk_cfg.physical_block_exp = 0;
 
     /* this must be here to calculate code segment position */
     blk_cfg.geometry.heads = 15;
@@ -290,31 +292,31 @@ void virtio_assume_eckd(void)
 bool virtio_disk_is_scsi(void)
 {
     if (guessed_disk_nature) {
-        return (blk_cfg.blk_size  == 512);
+        return (virtio_get_block_size()  == 512);
     }
     return (blk_cfg.geometry.heads == 255)
         && (blk_cfg.geometry.sectors == 63)
-        && (blk_cfg.blk_size  == 512);
+        && (virtio_get_block_size()  == 512);
 }
 
 bool virtio_disk_is_eckd(void)
 {
     if (guessed_disk_nature) {
-        return (blk_cfg.blk_size  == 4096);
+        return (virtio_get_block_size()  == 4096);
     }
     return (blk_cfg.geometry.heads == 15)
         && (blk_cfg.geometry.sectors == 12)
-        && (blk_cfg.blk_size  == 4096);
+        && (virtio_get_block_size()  == 4096);
 }
 
 bool virtio_ipl_disk_is_valid(void)
 {
-    return blk_cfg.blk_size && (virtio_disk_is_scsi() || virtio_disk_is_eckd());
+    return virtio_disk_is_scsi() || virtio_disk_is_eckd();
 }
 
 int virtio_get_block_size(void)
 {
-    return blk_cfg.blk_size;
+    return blk_cfg.blk_size << blk_cfg.physical_block_exp;
 }
 
 uint16_t virtio_get_cylinders(void)
Signature · 1 line
1.8.5.5
#6 lore raw

PATCH 6/7 pc-bios/s390-ccw: Do proper console setup

In reply to Jens Freimann

From: Christian Borntraeger <[email protected]>

The final newline/return must happen before we reset the sclp via diag 308.

---
 pc-bios/s390-ccw/bootmap.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
pc-bios/s390-ccw/bootmap.c +5 -5
index aa1cf80..115d8bb 100644
@@ -40,11 +40,6 @@ static void jump_to_IPL_2(void)
     ResetInfo *current = 0;
 
     void (*ipl)(void) = (void *) (uint64_t) current->ipl_continue;
-    debug_print_addr("set IPL addr to", ipl);
-
-    /* Ensure the guest output starts fresh */
-    sclp_print("\n");
-
     *current = save;
     ipl(); /* should not return */
 }
@@ -64,6 +59,11 @@ static void jump_to_IPL_code(uint64_t address)
     current->ipl_addr = (uint32_t) (uint64_t) &jump_to_IPL_2;
     current->ipl_continue = address & 0x7fffffff;
 
+    debug_print_int("set IPL addr to", current->ipl_continue);
+
+    /* Ensure the guest output starts fresh */
+    sclp_print("\n");
+
     /*
      * HACK ALERT.
      * We use the load normal reset to keep r15 unchanged. jump_to_IPL_2
Signature · 1 line
1.8.5.5
#7 lore raw

PATCH 7/7 pc-bios/s390-ccw.img binary update

In reply to Jens Freimann

From: "Eugene (jno) Dvurechenski" <[email protected]>

Rebuild of s390-ccw.img containing these patches:

pc-bios/s390-ccw: Do proper console setup pc-bios/s390-ccw: support all virtio block size pc-bios/s390-ccw: handle more ECKD DASD block sizes pc-bios/s390-ccw Improve ECKD informational message pc-bios/s390-ccw Really big EAV ECKD DASD handling pc-bios/s390-ccw: IPL from DASD with format variations

---
 pc-bios/s390-ccw.img | Bin 17752 -> 17752 bytes
 1 file changed, 0 insertions(+), 0 deletions(-)
pc-bios/s390-ccw.img binary +0 -0
index e3ea0d5664f01ff472d3531980941fb5f163ff02..44873ad1817f44a5610ea556f86394b2c4a4c1ff 100644
GIT binary patch
Signature · 1 line
1.8.5.5
#8 lore raw
In reply to Jens Freimann
Quoted 22 lines · Jens Freimann

Patches 1-5 contain changes improving support of more disk formats and block sizes.

Patch 6 makes sure we print a newline to leave a clean slate before continuing with IPL.

Patch 7 updates the binary.

regards
Jens

Christian Borntraeger (1):
pc-bios/s390-ccw: Do proper console setup

Eugene (jno) Dvurechenski (6):
pc-bios/s390-ccw: support all virtio block size pc-bios/s390-ccw: handle more ECKD DASD block sizes pc-bios/s390-ccw Improve ECKD informational message pc-bios/s390-ccw Really big EAV ECKD DASD handling pc-bios/s390-ccw: IPL from DASD with format variations pc-bios/s390-ccw.img binary update

Quoted 7 lines
 pc-bios/s390-ccw.img       | Bin 17752 -> 17752 bytes
 pc-bios/s390-ccw/bootmap.c | 107 +++++++++++++++++++++++++++------------------
 pc-bios/s390-ccw/bootmap.h |   2 +-
 pc-bios/s390-ccw/virtio.c  |  48 +++++++++++++++-----
 pc-bios/s390-ccw/virtio.h  |   2 +-
 5 files changed, 103 insertions(+), 56 deletions(-)

Thanks

Applied to github.com/borntraeger/qemu.git s390-next.

I will wait till next week before sending the pull request to give others a chance for feedback.

Christian

Reviewed-by
#9 lore raw
Quoted 31 lines · Christian Borntraeger
Quoted 22 lines · Jens Freimann

Patches 1-5 contain changes improving support of more disk formats and block sizes.

Patch 6 makes sure we print a newline to leave a clean slate before continuing with IPL.

Patch 7 updates the binary.

regards
Jens

Christian Borntraeger (1):
pc-bios/s390-ccw: Do proper console setup

Eugene (jno) Dvurechenski (6):
pc-bios/s390-ccw: support all virtio block size pc-bios/s390-ccw: handle more ECKD DASD block sizes pc-bios/s390-ccw Improve ECKD informational message pc-bios/s390-ccw Really big EAV ECKD DASD handling pc-bios/s390-ccw: IPL from DASD with format variations pc-bios/s390-ccw.img binary update

Quoted 7 lines
 pc-bios/s390-ccw.img       | Bin 17752 -> 17752 bytes
 pc-bios/s390-ccw/bootmap.c | 107 +++++++++++++++++++++++++++------------------
 pc-bios/s390-ccw/bootmap.h |   2 +-
 pc-bios/s390-ccw/virtio.c  |  48 +++++++++++++++-----
 pc-bios/s390-ccw/virtio.h  |   2 +-
 5 files changed, 103 insertions(+), 56 deletions(-)
Quoted 4 lines

Thanks

Applied to github.com/borntraeger/qemu.git s390-next.

Alex