Skip to contentSkip to conversation

pc-bios/s390 fixes for reboot-to-vfio-ccw

PATCH Superseded Eric Farman 4 participants 12 messages Nov 19, 2020 – Nov 20, 2020

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#1 lore raw

PATCH 1/2 pc-bios: s390x: Ensure Read IPL memory is clean

In reply to Eric Farman

If, for example, we boot off a virtio device and chreipl to a vfio-ccw device, the space at lowcore will be non-zero. We build a Read IPL CCW at address zero, but it will have leftover PSW data that will conflict with the Format-0 CCW being generated:

0x0: 00080000 80010000
------ Ccw0.cda
-- Ccw0.chainData
-- Reserved bits

The data address will be overwritten with the correct value (0x0), but the apparent data chain bit will cause subsequent memory to be used as the target of the data store, which may not be where we expect (0x0).

Clear out this space when we boot from DASD, so that we know it exists exactly as we expect.

---
 pc-bios/s390-ccw/dasd-ipl.c | 3 +++
 1 file changed, 3 insertions(+)
pc-bios/s390-ccw/dasd-ipl.c +3 -0
index 0fc879bb8e..71cbae2f16 100644
@@ -100,6 +100,9 @@ static void make_readipl(void)
 {
     Ccw0 *ccwIplRead = (Ccw0 *)0x00;
 
+    /* Clear out any existing data */
+    memset(ccwIplRead, 0, sizeof(Ccw0));
+
     /* Create Read IPL ccw at address 0 */
     ccwIplRead->cmd_code = CCW_CMD_READ_IPL;
     ccwIplRead->cda = 0x00; /* Read into address 0x00 in main memory */
Signature · 1 line
2.17.1
#6 lore raw

PATCH 2/2 pc-bios: s390x: Give precedence to reset PSW

In reply to Eric Farman

Let's look at the Reset PSW first instead of the contents of memory. It might be leftover from an earlier system boot when processing a chreipl.

---
 pc-bios/s390-ccw/jump2ipl.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
pc-bios/s390-ccw/jump2ipl.c +10 -10
index fbae45b03c..67b4afb6a0 100644
@@ -72,16 +72,6 @@ void jump_to_IPL_code(uint64_t address)
 
 void jump_to_low_kernel(void)
 {
-    /*
-     * If it looks like a Linux binary, i.e. there is the "S390EP" magic from
-     * arch/s390/kernel/head.S here, then let's jump to the well-known Linux
-     * kernel start address (when jumping to the PSW-at-zero address instead,
-     * the kernel startup code fails when we booted from a network device).
-     */
-    if (!memcmp((char *)0x10008, "S390EP", 6)) {
-        jump_to_IPL_code(KERN_IMAGE_START);
-    }
-
     /* Trying to get PSW at zero address */
     if (*((uint64_t *)0) & RESET_PSW_MASK) {
         /*
@@ -92,6 +82,16 @@ void jump_to_low_kernel(void)
         jump_to_IPL_code(0);
     }
 
+    /*
+     * If it looks like a Linux binary, i.e. there is the "S390EP" magic from
+     * arch/s390/kernel/head.S here, then let's jump to the well-known Linux
+     * kernel start address (when jumping to the PSW-at-zero address instead,
+     * the kernel startup code fails when we booted from a network device).
+     */
+    if (!memcmp((char *)0x10008, "S390EP", 6)) {
+        jump_to_IPL_code(KERN_IMAGE_START);
+    }
+
     /* No other option left, so use the Linux kernel start address */
     jump_to_IPL_code(KERN_IMAGE_START);
 }
Signature · 1 line
2.17.1
#0 lore raw

cover pc-bios/s390 fixes for reboot-to-vfio-ccw

Hi Conny, Thomas,

I've come across a couple problems when installing a guest onto a vfio-ccw disk. They were noticed when booting off an ISO via virtio, and writing the new guest OS to a vfio-ccw connected disk. The installation works correctly, in that the disk can be booted and used perfectly fine. But the end of the install process reboots to the new disk, and we end up with an error that looks like this:

Rebooting.
LOADPARM=[ ]
cio device error
ssid : 0x0000000000000000
cssid : 0x0000000000000000
sch_no: 0x0000000000000002
ctrl-unit type: 0x0000000000003990

Interrupt Response Block Data:
: 0x0000000000003990
Function Ctrl : [Start]
Activity Ctrl : [Start-Pending]
Status Ctrl : [Alert] [Primary] [Secondary] [Status-Pending] Device Status :
Channel Status : [Program-Check]
cpa=: 0x0000000000000008
prev_ccw=: 0x0008000080002018
this_ccw=: 0x0600001860000080
Eckd Dasd Sense Data (fmt 32-bytes):

    Channel Status : [Program-Check]
    Sense Condition Flags :
    Residual Count     =: 0x0000000000000000
    Phys Drive ID      =: 0x0000000000000000
    low cyl address    =: 0x0000000000000000
    head addr & hi cyl =: 0x0000000000000000
    format/message     =: 0x0000000000000000
    fmt-dependent[0-7] =: 0x0000000000000000
    fmt-dependent[8-15]=: 0x000000004a200f00
    prog action code   =: 0x0000000000000000
    Configuration info =: 0x00000000000040e0
    mcode / hi-cyl     =: 0x0000000000000000
    cyl & head addr [0]=: 0x0000000000000000
    cyl & head addr [1]=: 0x0000000000000000
    cyl & head addr [2]=: 0x0000000000000000

dasd-ipl: Failed to run Read IPL channel program

The problem can be easily (and quickly) reproduced by defining XML with two different guest disks, such as:

    <disk type='block' device='disk'>
      <driver name='qemu' type='raw'/>
      <source dev='/dev/disk/by-path/ccw-0.0.1234'/>
      <target dev='vda' bus='virtio'/>
      <address type='ccw' cssid='0xfe' ssid='0x0' devno='0x0000'/>
    </disk>
    <hostdev mode='subsystem' type='mdev' managed='no' model='vfio-ccw'>
      <source>
        <address uuid='12345678-1234-1234-1234-123456789abc'/>
      </source>
      <address type='ccw' cssid='0xfe' ssid='0x0' devno='0x1235'/>
    </hostdev>

Boot the guest off disk 1234, issue chreipl 0.0.1235, and reboot. Interestingly, going the other direction (1235->1234) works fine.

Two things occur here. First, the DASD IPL code builds a Read IPL Format-0 CCW at address zero, but assumes that the memory is already zero. If data is already present (which on reboot it does, and is probably a PSW), it might be included in that CCW. Patch 1 is a pretty straightforward fix for this. (Might this one be appropriate for 5.2?)

Secondly, the jump code looks at a couple memory locations to determine what jump to perform. But in this virtio-to-vfio jump, we should give precedence to the data at address zero, rather than the not-yet-cleared memory. Patch 2 swaps the order of these checks to enable this, and doesn't appear to affect normal disk boots. But there are a hundred other boot combinations that I haven't tried here, so could use some feedback on this one. I do recognize that this leaves no difference between the "if (!memcmp())" case and not, but left it this way to help better visualize the change I'm making.

Coda:
I didn't include rebuilt bios patch(es) here, but certainly can. Also, I'm on holiday all next week; so apologies in advance for sending a couple patches and then hiding shortly thereafter. :)

Eric Farman (2):
pc-bios: s390x: Ensure Read IPL memory is clean
pc-bios: s390x: Give precedence to reset PSW

 pc-bios/s390-ccw/dasd-ipl.c |  3 +++
 pc-bios/s390-ccw/jump2ipl.c | 20 ++++++++++----------
 2 files changed, 13 insertions(+), 10 deletions(-)
Signature · 1 line
2.17.1
#11 lore raw
Quoted 64 lines · On Thu, 19 Nov 2020 17:57:27 +0100 Eric Farman <[email protected]> wrote:

Hi Conny, Thomas,

I've come across a couple problems when installing a guest onto a vfio-ccw disk. They were noticed when booting off an ISO via virtio, and writing the new guest OS to a vfio-ccw connected disk. The installation works correctly, in that the disk can be booted and used perfectly fine. But the end of the install process reboots to the new disk, and we end up with an error that looks like this:

Rebooting.
LOADPARM=[ ]
cio device error
ssid : 0x0000000000000000
cssid : 0x0000000000000000
sch_no: 0x0000000000000002
ctrl-unit type: 0x0000000000003990

Interrupt Response Block Data:
: 0x0000000000003990
Function Ctrl : [Start]
Activity Ctrl : [Start-Pending]
Status Ctrl : [Alert] [Primary] [Secondary] [Status-Pending] Device Status :
Channel Status : [Program-Check]
cpa=: 0x0000000000000008
prev_ccw=: 0x0008000080002018
this_ccw=: 0x0600001860000080
Eckd Dasd Sense Data (fmt 32-bytes):

    Channel Status : [Program-Check]
    Sense Condition Flags :
    Residual Count     =: 0x0000000000000000
    Phys Drive ID      =: 0x0000000000000000
    low cyl address    =: 0x0000000000000000
    head addr & hi cyl =: 0x0000000000000000
    format/message     =: 0x0000000000000000
    fmt-dependent[0-7] =: 0x0000000000000000
    fmt-dependent[8-15]=: 0x000000004a200f00
    prog action code   =: 0x0000000000000000
    Configuration info =: 0x00000000000040e0
    mcode / hi-cyl     =: 0x0000000000000000
    cyl & head addr [0]=: 0x0000000000000000
    cyl & head addr [1]=: 0x0000000000000000
    cyl & head addr [2]=: 0x0000000000000000

dasd-ipl: Failed to run Read IPL channel program

The problem can be easily (and quickly) reproduced by defining XML with two different guest disks, such as:

    <disk type='block' device='disk'>
      <driver name='qemu' type='raw'/>
      <source dev='/dev/disk/by-path/ccw-0.0.1234'/>
      <target dev='vda' bus='virtio'/>
      <address type='ccw' cssid='0xfe' ssid='0x0' devno='0x0000'/>
    </disk>
    <hostdev mode='subsystem' type='mdev' managed='no' model='vfio-ccw'>
      <source>
        <address uuid='12345678-1234-1234-1234-123456789abc'/>
      </source>
      <address type='ccw' cssid='0xfe' ssid='0x0' devno='0x1235'/>
    </hostdev>

Boot the guest off disk 1234, issue chreipl 0.0.1235, and reboot. Interestingly, going the other direction (1235->1234) works fine.

Quoted 6 lines

Two things occur here. First, the DASD IPL code builds a Read IPL Format-0 CCW at address zero, but assumes that the memory is already zero. If data is already present (which on reboot it does, and is probably a PSW), it might be included in that CCW. Patch 1 is a pretty straightforward fix for this. (Might this one be appropriate for 5.2?)

That one is straightforward enough for 5.2, I guess.

Quoted 10 lines

Secondly, the jump code looks at a couple memory locations to determine what jump to perform. But in this virtio-to-vfio jump, we should give precedence to the data at address zero, rather than the not-yet-cleared memory. Patch 2 swaps the order of these checks to enable this, and doesn't appear to affect normal disk boots. But there are a hundred other boot combinations that I haven't tried here, so could use some feedback on this one. I do recognize that this leaves no difference between the "if (!memcmp())" case and not, but left it this way to help better visualize the change I'm making.

This is in code that usually gives me a headache :(

Quoted 3 lines

Coda:
I didn't include rebuilt bios patch(es) here, but certainly can.

I think it should not be too hard to have the person picking the patches generate them :) Especially if we end up going with patch 1 only for now.

Quoted 2 lines

Also, I'm on holiday all next week; so apologies in advance for sending a couple patches and then hiding shortly thereafter. :)

That's a time-proven strategy :)

Quoted 9 lines

Eric Farman (2):
pc-bios: s390x: Ensure Read IPL memory is clean
pc-bios: s390x: Give precedence to reset PSW

 pc-bios/s390-ccw/dasd-ipl.c |  3 +++
 pc-bios/s390-ccw/jump2ipl.c | 20 ++++++++++----------
 2 files changed, 13 insertions(+), 10 deletions(-)
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] pc-bios: s390x: Ensure Read IPL memory is clean

In reply to Eric Farman
Quoted 29 lines · Eric Farman

If, for example, we boot off a virtio device and chreipl to a vfio-ccw device, the space at lowcore will be non-zero. We build a Read IPL CCW at address zero, but it will have leftover PSW data that will conflict with the Format-0 CCW being generated:

0x0: 00080000 80010000
------ Ccw0.cda
-- Ccw0.chainData
-- Reserved bits

The data address will be overwritten with the correct value (0x0), but the apparent data chain bit will cause subsequent memory to be used as the target of the data store, which may not be where we expect (0x0).

Clear out this space when we boot from DASD, so that we know it exists exactly as we expect.

---
 pc-bios/s390-ccw/dasd-ipl.c | 3 +++
 1 file changed, 3 insertions(+)
pc-bios/s390-ccw/dasd-ipl.c +0 -0
index 0fc879bb8e..71cbae2f16 100644

pc-bios/s390-ccw/dasd-ipl.c static void make_readipl(void) · line 108

Quoted 9 lines
pc-bios/s390-ccw/dasd-ipl.c +3 -0
@@ -100,6 +100,9 @@ static void make_readipl(void)
 {
     Ccw0 *ccwIplRead = (Ccw0 *)0x00;
 
+    /* Clear out any existing data */
+    memset(ccwIplRead, 0, sizeof(Ccw0));
+
     /* Create Read IPL ccw at address 0 */
     ccwIplRead->cmd_code = CCW_CMD_READ_IPL;
     ccwIplRead->cda = 0x00; /* Read into address 0x00 in main memory */

Sounds reasonable.

#7 lore raw

Re: [PATCH 2/2] pc-bios: s390x: Give precedence to reset PSW

In reply to Eric Farman
Quoted 33 lines · Eric Farman

Let's look at the Reset PSW first instead of the contents of memory. It might be leftover from an earlier system boot when processing a chreipl.

---
 pc-bios/s390-ccw/jump2ipl.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
pc-bios/s390-ccw/jump2ipl.c +0 -10
index fbae45b03c..67b4afb6a0 100644
@@ -72,16 +72,6 @@ void jump_to_IPL_code(uint64_t address)
 
 void jump_to_low_kernel(void)
 {
-    /*
-     * If it looks like a Linux binary, i.e. there is the "S390EP" magic from
-     * arch/s390/kernel/head.S here, then let's jump to the well-known Linux
-     * kernel start address (when jumping to the PSW-at-zero address instead,
-     * the kernel startup code fails when we booted from a network device).
-     */
-    if (!memcmp((char *)0x10008, "S390EP", 6)) {
-        jump_to_IPL_code(KERN_IMAGE_START);
-    }
-
     /* Trying to get PSW at zero address */
     if (*((uint64_t *)0) & RESET_PSW_MASK) {
         /*
@@ -92,6 +82,16 @@ void jump_to_low_kernel(void)
         jump_to_IPL_code(0);
     }

pc-bios/s390-ccw/jump2ipl.c void jump_to_low_kernel(void) · line 93

Quoted 10 lines
pc-bios/s390-ccw/jump2ipl.c +9 -0
 
+    /*
+     * If it looks like a Linux binary, i.e. there is the "S390EP" magic from
+     * arch/s390/kernel/head.S here, then let's jump to the well-known Linux
+     * kernel start address (when jumping to the PSW-at-zero address instead,
+     * the kernel startup code fails when we booted from a network device).
+     */
+    if (!memcmp((char *)0x10008, "S390EP", 6)) {
+        jump_to_IPL_code(KERN_IMAGE_START);
+    }

That feels a little bit dangerous ... I assume the order has been that way for a reason, e.g. I think we had to jump to KERN_IMAGE_START for some older versions of the Linux kernel since the startup code that was referenced by the PSW at address zero was not working in KVM...

What do you think about this alternate idea instead: Clear the memory at location 0x10008 at the very beginning of the main() function (or maybe in boot_setup())? Then we can be sure that there is no stale S390EP magic dangling around anymore once we've loaded the new kernel...

Thomas

#8 lore raw

Re: [PATCH 2/2] pc-bios: s390x: Give precedence to reset PSW

Quoted 35 lines · Thomas Huth
Quoted 34 lines · Eric Farman

Let's look at the Reset PSW first instead of the contents of memory. It might be leftover from an earlier system boot when processing a chreipl.

---
  pc-bios/s390-ccw/jump2ipl.c | 20 ++++++++++----------
  1 file changed, 10 insertions(+), 10 deletions(-)
pc-bios/s390-ccw/jump2ipl.c +0 -10
index fbae45b03c..67b4afb6a0 100644
@@ -72,16 +72,6 @@ void jump_to_IPL_code(uint64_t address)
 
  void jump_to_low_kernel(void)
  {
-    /*
-     * If it looks like a Linux binary, i.e. there is the "S390EP" magic from
-     * arch/s390/kernel/head.S here, then let's jump to the well-known Linux
-     * kernel start address (when jumping to the PSW-at-zero address instead,
-     * the kernel startup code fails when we booted from a network device).
-     */
-    if (!memcmp((char *)0x10008, "S390EP", 6)) {
-        jump_to_IPL_code(KERN_IMAGE_START);
-    }
-
      /* Trying to get PSW at zero address */
      if (*((uint64_t *)0) & RESET_PSW_MASK) {
          /*
@@ -92,6 +82,16 @@ void jump_to_low_kernel(void)
          jump_to_IPL_code(0);
      }
 
Quoted 14 lines

pc-bios/s390-ccw/jump2ipl.c void jump_to_low_kernel(void) · line 93

Quoted 9 lines
pc-bios/s390-ccw/jump2ipl.c +9 -0
+    /*
+     * If it looks like a Linux binary, i.e. there is the "S390EP" magic from
+     * arch/s390/kernel/head.S here, then let's jump to the well-known Linux
+     * kernel start address (when jumping to the PSW-at-zero address instead,
+     * the kernel startup code fails when we booted from a network device).
+     */
+    if (!memcmp((char *)0x10008, "S390EP", 6)) {
+        jump_to_IPL_code(KERN_IMAGE_START);
+    }

That feels a little bit dangerous ... I assume the order has been that way for a reason, e.g. I think we had to jump to KERN_IMAGE_START for some older versions of the Linux kernel since the startup code that was referenced by the PSW at address zero was not working in KVM...

Makes sense. It does seem like a precarious piece of code.

Quoted 4 lines

What do you think about this alternate idea instead: Clear the memory at location 0x10008 at the very beginning of the main() function (or maybe in boot_setup())?

This seems to work too (I put it in boot_setup(), prior to call to store_iplb()).

Then we can be sure that there is no stale S390EP magic

Quoted 4 lines

dangling around anymore once we've loaded the new kernel...

Thomas

#9 lore raw

Re: [PATCH 2/2] pc-bios: s390x: Give precedence to reset PSW

Quoted 60 lines · Eric Farman
Quoted 45 lines · Thomas Huth
Quoted 44 lines · Eric Farman

Let's look at the Reset PSW first instead of the contents of memory. It might be leftover from an earlier system boot when processing a chreipl.

---
  pc-bios/s390-ccw/jump2ipl.c | 20 ++++++++++----------

  1 file changed, 10 insertions(+), 10 deletions(-)
pc-bios/s390-ccw/jump2ipl.c +0 -2
index fbae45b03c..67b4afb6a0 100644
@@ -72,16 +72,6 @@ void jump_to_IPL_code(uint64_t address)
     void jump_to_low_kernel(void)
   {
-    /*
-     * If it looks like a Linux binary, i.e. there is the "S390EP" magic

from
-     * arch/s390/kernel/head.S here, then let's jump to the well-known Linux
-     * kernel start address (when jumping to the PSW-at-zero address instead,
-     * the kernel startup code fails when we booted from a network device). -     */
-    if (!memcmp((char *)0x10008, "S390EP", 6)) {
-        jump_to_IPL_code(KERN_IMAGE_START);
-    }
-
      /* Trying to get PSW at zero address */
      if (*((uint64_t *)0) & RESET_PSW_MASK) {
          /*

pc-bios/s390-ccw/jump2ipl.c +0 -0
@@ -92,6 +82,16 @@ void jump_to_low_kernel(void)
           jump_to_IPL_code(0);
       }

  +    /*
+     * If it looks like a Linux binary, i.e. there is the "S390EP" magic from
+     * arch/s390/kernel/head.S here, then let's jump to the well-known Linux
+     * kernel start address (when jumping to the PSW-at-zero address instead,
+     * the kernel startup code fails when we booted from a network device). +     */

Quoted 8 lines
Quoted 3 lines

+    if (!memcmp((char *)0x10008, "S390EP", 6)) {
+        jump_to_IPL_code(KERN_IMAGE_START);
+    }

That feels a little bit dangerous ... I assume the order has been that way for a reason, e.g. I think we had to jump to KERN_IMAGE_START for some older versions of the Linux kernel since the startup code that was referenced by the PSW at address zero was not working in KVM...

Makes sense.  It does seem like a precarious piece of code.

Quoted 1 line
Quoted 6 lines
Quoted 3 lines

What do you think about this alternate idea instead: Clear the memory at location 0x10008 at the very beginning of the main() function (or maybe in boot_setup())?

This seems to work too (I put it in boot_setup(), prior to call to store_iplb()).

Great, can you send the patch before your holidays next week? (If you don't have enough time, that's ok, too, it's trivial enough, so I think I could write such a patch, too)

Thomas

Reviewed-by on v1 1/2
#3 lore raw

Re: [PATCH 1/2] pc-bios: s390x: Ensure Read IPL memory is clean

In reply to Eric Farman
Quoted 14 lines · Eric Farman

If, for example, we boot off a virtio device and chreipl to a vfio-ccw device, the space at lowcore will be non-zero. We build a Read IPL CCW at address zero, but it will have leftover PSW data that will conflict with the Format-0 CCW being generated:

0x0: 00080000 80010000
------ Ccw0.cda
-- Ccw0.chainData
-- Reserved bits

The data address will be overwritten with the correct value (0x0), but the apparent data chain bit will cause subsequent memory to be used as the target of the data store, which may not be where we expect (0x0).

Quoted 6 lines

Clear out this space when we boot from DASD, so that we know it exists exactly as we expect.

Seems like I should have been more specific with my LGTM:

Quoted 19 lines
---
 pc-bios/s390-ccw/dasd-ipl.c | 3 +++
 1 file changed, 3 insertions(+)
pc-bios/s390-ccw/dasd-ipl.c +3 -0
index 0fc879bb8e..71cbae2f16 100644
@@ -100,6 +100,9 @@ static void make_readipl(void)
 {
     Ccw0 *ccwIplRead = (Ccw0 *)0x00;
 
+    /* Clear out any existing data */
+    memset(ccwIplRead, 0, sizeof(Ccw0));
+
     /* Create Read IPL ccw at address 0 */
     ccwIplRead->cmd_code = CCW_CMD_READ_IPL;
     ccwIplRead->cda = 0x00; /* Read into address 0x00 in main memory */
Acked-by on v1 1/2
#5 lore raw

Re: [PATCH 1/2] pc-bios: s390x: Ensure Read IPL memory is clean

In reply to Eric Farman
Quoted 17 lines · On Thu, 19 Nov 2020 17:57:28 +0100 Eric Farman <[email protected]> wrote:

If, for example, we boot off a virtio device and chreipl to a vfio-ccw device, the space at lowcore will be non-zero. We build a Read IPL CCW at address zero, but it will have leftover PSW data that will conflict with the Format-0 CCW being generated:

0x0: 00080000 80010000
------ Ccw0.cda
-- Ccw0.chainData
-- Reserved bits

The data address will be overwritten with the correct value (0x0), but the apparent data chain bit will cause subsequent memory to be used as the target of the data store, which may not be where we expect (0x0).

Clear out this space when we boot from DASD, so that we know it exists exactly as we expect.

Quoted 6 lines
---
 pc-bios/s390-ccw/dasd-ipl.c | 3 +++
 1 file changed, 3 insertions(+)
#10 lore raw

Re: [PATCH 2/2] pc-bios: s390x: Give precedence to reset PSW

In reply to Thomas Huth
Quoted 65 lines · Thomas Huth
Quoted 64 lines · Eric Farman
Quoted 45 lines · Thomas Huth
Quoted 44 lines · Eric Farman

Let's look at the Reset PSW first instead of the contents of memory. It might be leftover from an earlier system boot when processing a chreipl.

---
   pc-bios/s390-ccw/jump2ipl.c | 20 ++++++++++----------
   1 file changed, 10 insertions(+), 10 deletions(-)
pc-bios/s390-ccw/jump2ipl.c +0 -2
index fbae45b03c..67b4afb6a0 100644
@@ -72,16 +72,6 @@ void jump_to_IPL_code(uint64_t address)
     void jump_to_low_kernel(void)
   {
-    /*
-     * If it looks like a Linux binary, i.e. there is the "S390EP" magic

from
-     * arch/s390/kernel/head.S here, then let's jump to the well-known Linux
-     * kernel start address (when jumping to the PSW-at-zero address instead,
-     * the kernel startup code fails when we booted from a network device). -     */
-    if (!memcmp((char *)0x10008, "S390EP", 6)) {
-        jump_to_IPL_code(KERN_IMAGE_START);
-    }

pc-bios/s390-ccw/jump2ipl.c +1 -1
-
       /* Trying to get PSW at zero address */
       if (*((uint64_t *)0) & RESET_PSW_MASK) {
           /*
@@ -92,6 +82,16 @@ void jump_to_low_kernel(void)
           jump_to_IPL_code(0);
       }
   +    /*
+     * If it looks like a Linux binary, i.e. there is the "S390EP" magic

from
+     * arch/s390/kernel/head.S here, then let's jump to the well-known Linux
+     * kernel start address (when jumping to the PSW-at-zero address instead,
+     * the kernel startup code fails when we booted from a network device). +     */

Quoted 8 lines
Quoted 3 lines

+    if (!memcmp((char *)0x10008, "S390EP", 6)) {
+        jump_to_IPL_code(KERN_IMAGE_START);
+    }

That feels a little bit dangerous ... I assume the order has been that way for a reason, e.g. I think we had to jump to KERN_IMAGE_START for some older versions of the Linux kernel since the startup code that was referenced by the PSW at address zero was not working in KVM...

Makes sense.  It does seem like a precarious piece of code.

Quoted 4 lines

What do you think about this alternate idea instead: Clear the memory at location 0x10008 at the very beginning of the main() function (or maybe in boot_setup())?

Quoted 6 lines
Quoted 2 lines

This seems to work too (I put it in boot_setup(), prior to call to store_iplb()).

Great, can you send the patch before your holidays next week? (If you don't have enough time, that's ok, too, it's trivial enough, so I think I could write such a patch, too)

Will do. I have it written up, just didn't want to send it last night and have surprises when I came in this morning. :)

Quoted 3 lines

Thomas

#4 lore raw

Re: [PATCH 1/2] pc-bios: s390x: Ensure Read IPL memory is clean

In reply to Janosch Frank
Quoted 18 lines · Janosch Frank
Quoted 17 lines · Eric Farman

If, for example, we boot off a virtio device and chreipl to a vfio-ccw device, the space at lowcore will be non-zero. We build a Read IPL CCW at address zero, but it will have leftover PSW data that will conflict with the Format-0 CCW being generated:

0x0: 00080000 80010000
------ Ccw0.cda
-- Ccw0.chainData
-- Reserved bits

The data address will be overwritten with the correct value (0x0), but the apparent data chain bit will cause subsequent memory to be used as the target of the data store, which may not be where we expect (0x0).

Clear out this space when we boot from DASD, so that we know it exists exactly as we expect.

Quoted 6 lines
Quoted 3 lines

Seems like I should have been more specific with my LGTM:

Thanks, Janosch. I didn't want to put words in your acronym. :)

Quoted 21 lines
Quoted 20 lines
---
  pc-bios/s390-ccw/dasd-ipl.c | 3 +++
  1 file changed, 3 insertions(+)
pc-bios/s390-ccw/dasd-ipl.c +3 -0
index 0fc879bb8e..71cbae2f16 100644
@@ -100,6 +100,9 @@ static void make_readipl(void)
  {
      Ccw0 *ccwIplRead = (Ccw0 *)0x00;
 
+    /* Clear out any existing data */
+    memset(ccwIplRead, 0, sizeof(Ccw0));
+
      /* Create Read IPL ccw at address 0 */
      ccwIplRead->cmd_code = CCW_CMD_READ_IPL;
      ccwIplRead->cda = 0x00; /* Read into address 0x00 in main memory */