Skip to contentSkip to conversation

S390 April patch round

PATCH Applied Alexander Graf 5 participants 21 messages Apr 1, 2010 – Apr 12, 2010

lore
Share & tools
lore
#0 lore raw

cover S390 April patch round

While improving KVM on S390x I stumbled across some more issues. The most annoying ones were in the character layer, where -nographic would just fail on most users. This set fixes these issues.

The set also adds support for my new zipl bootloader. Using this firmware and a patches version of zipl you can finally boot from virtio disks without the need to pass -kernel and -initrd directly!

Alexander Graf (6):
S390: Add stub for cpu_get_phys_page_debug
S390: Tell user why VM creation failed
Make char muxer more robust wrt small FIFOs Always notify consumers of char devices if they're open [S390] Implement virtio reset
[S390] Add firmware code

 hw/s390-virtio-bus.c  |    3 +--
 hw/s390-virtio-bus.h  |    1 +
 hw/s390-virtio.c      |   29 +++++++++++++++++++++++++----
 kvm-all.c             |    7 ++++++-
 pc-bios/s390-zipl.rom |  Bin 0 -> 2448 bytes
 qemu-char.c           |   30 ++++++++++++++++++++++++++++++
 qemu-char.h           |    1 +
 target-s390x/helper.c |    5 +++++
 8 files changed, 69 insertions(+), 7 deletions(-)
 create mode 100755 pc-bios/s390-zipl.rom
#1 lore raw

PATCH 1/6 S390: Add stub for cpu_get_phys_page_debug

We don't implement any virtual memory in the S390 target so far, so let's add a stub for this now mandatory function.

Fixes building of S390 target.

---
 target-s390x/helper.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
target-s390x/helper.c +5 -0
index ba0c052..4a5297b 100644
@@ -58,6 +58,11 @@ void cpu_reset(CPUS390XState *env)
     tlb_flush(env, 1);
 }
 
+target_phys_addr_t cpu_get_phys_page_debug(CPUState *env, target_ulong addr)
+{
+    return 0;
+}
+
 #ifndef CONFIG_USER_ONLY
 
 int cpu_s390x_handle_mmu_fault (CPUState *env, target_ulong address, int rw,
Signature · 1 line
1.6.0.2
#2 lore raw

PATCH 2/6 S390: Tell user why VM creation failed

In reply to Alexander Graf

The KVM kernel module on S390 refuses to create a VM when the switch_amode kernel parameter is not used.

Since that is not exactly obvious, let's give the user a nice warning.

---
 kvm-all.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
kvm-all.c +6 -1
index 40b5a51..9de66c9 100644
@@ -607,8 +607,13 @@ int kvm_init(int smp_cpus)
     }
 
     s->vmfd = kvm_ioctl(s, KVM_CREATE_VM, 0);
-    if (s->vmfd < 0)
+    if (s->vmfd < 0) {
+#ifdef TARGET_S390X
+        fprintf(stderr, "Please add the 'switch_amode' kernel parameter to "
+                        "your host kernel command line\n");
+#endif
         goto err;
+    }
 
     /* initially, KVM allocated its own memory and we had to jump through
      * hooks to make phys_ram_base point to this.  Modern versions of KVM
Signature · 1 line
1.6.0.2
#3 lore raw

PATCH 3/6 Make char muxer more robust wrt small FIFOs

In reply to Alexander Graf

Virtio-Console can only process one character at a time. Using it on S390 gave me strage "lags" where I got the character I pressed before when pressing one. So I typed in "abc" and only received "a", then pressed "d" but the guest received "b" and so on.

While the stdio driver calls a poll function that just processes on its queue in case virtio-console can't take multiple characters at once, the muxer does not have such callbacks, so it can't empty its queue.

To work around that limitation, I introduced a new timer that only gets active when the guest can not receive any more characters. In that case it polls again after a while to check if the guest is now receiving input.

This patch fixes input when using -nographic on s390 for me.

---

Please consider for stable.

---
 qemu-char.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
qemu-char.c +10 -0
index 048da3f..6ad6609 100644
@@ -219,6 +219,7 @@ typedef struct {
     IOEventHandler *chr_event[MAX_MUX];
     void *ext_opaque[MAX_MUX];
     CharDriverState *drv;
+    QEMUTimer *accept_timer;
     int focus;
     int mux_cnt;
     int term_got_escape;
@@ -380,6 +381,13 @@ static void mux_chr_accept_input(CharDriverState *chr)
         d->chr_read[m](d->ext_opaque[m],
                        &d->buffer[m][d->cons[m]++ & MUX_BUFFER_MASK], 1);
     }
+
+    /* We're still not able to sync producer and consumer, so let's wait a bit
+       and try again by then. */
+    if (d->prod[m] != d->cons[m]) {
+        qemu_mod_timer(d->accept_timer, qemu_get_clock(vm_clock)
+                                        + (int64_t)100000);
+    }
 }
 
 static int mux_chr_can_read(void *opaque)
@@ -462,6 +470,8 @@ static CharDriverState *qemu_chr_open_mux(CharDriverState *drv)
     chr->opaque = d;
     d->drv = drv;
     d->focus = -1;
+    d->accept_timer = qemu_new_timer(vm_clock,
+                                     (QEMUTimerCB*)mux_chr_accept_input, chr);
     chr->chr_write = mux_chr_write;
     chr->chr_update_read_handler = mux_chr_update_read_handler;
     chr->chr_accept_input = mux_chr_accept_input;
Signature · 1 line
1.6.0.2
#4 lore raw

Re: [Qemu-devel] [PATCH 3/6] Make char muxer more robust wrt small FIFOs

Quoted 1 line · Alexander Graf

Virtio-Console can only process one character at a time.

The host can process as many as you give it, depending on the buffer size exposed by the guest.

On older guests (guest kernels w/o multiport support), the guest reads input from host, processes it and only then opens up another buffer for the host to write into.

On newer guests (guest kernels that support multiport), the guest fills the entire vq so that host can send as many buffers as possible without getting throttled. I guess you're getting hit by this.

Quoted 4 lines

Using it on S390
gave me strage "lags" where I got the character I pressed before when pressing one. So I typed in "abc" and only received "a", then pressed "d" but the guest received "b" and so on.

This might be because qemu-char would not be able to send out 'b' while the guest still processes 'a' and has no free buffers to write out to. On seeing 'd', it flushes its queue.

Can you try using a 2.6.34-rc3 kernel without this patch to see if things work fine?

Amit

#5 lore raw

Re: [Qemu-devel] [PATCH 3/6] Make char muxer more robust wrt small FIFOs

Quoted 8 lines · Amit Shah
Quoted 2 lines · Alexander Graf

Virtio-Console can only process one character at a time.

The host can process as many as you give it, depending on the buffer size exposed by the guest.

Quoted 8 lines

On older guests (guest kernels w/o multiport support), the guest reads input from host, processes it and only then opens up another buffer for the host to write into.

On newer guests (guest kernels that support multiport), the guest fills the entire vq so that host can send as many buffers as possible without getting throttled. I guess you're getting hit by this.

Probably, yes.

Quoted 6 lines
Quoted 5 lines

Using it on S390
gave me strage "lags" where I got the character I pressed before when pressing one. So I typed in "abc" and only received "a", then pressed "d" but the guest received "b" and so on.

Quoted 7 lines

This might be because qemu-char would not be able to send out 'b' while the guest still processes 'a' and has no free buffers to write out to. On seeing 'd', it flushes its queue.

Can you try using a 2.6.34-rc3 kernel without this patch to see if things work fine?

Hrm - would it actually matter? We need to have older guest kernels working anyways. And my S390 LPAR doesn't exactly have a lot of disk space, so compiling a kernel is anything but fun :-).

Alex

#6 lore raw

Re: [Qemu-devel] [PATCH 3/6] Make char muxer more robust wrt small FIFOs

Quoted 30 lines · Alexander Graf
Quoted 8 lines · Amit Shah
Quoted 2 lines · Alexander Graf

Virtio-Console can only process one character at a time.

The host can process as many as you give it, depending on the buffer size exposed by the guest.

Quoted 8 lines

On older guests (guest kernels w/o multiport support), the guest reads input from host, processes it and only then opens up another buffer for the host to write into.

On newer guests (guest kernels that support multiport), the guest fills the entire vq so that host can send as many buffers as possible without getting throttled. I guess you're getting hit by this.

Probably, yes.

Quoted 10 lines
Quoted 5 lines

Using it on S390
gave me strage "lags" where I got the character I pressed before when pressing one. So I typed in "abc" and only received "a", then pressed "d" but the guest received "b" and so on.

This might be because qemu-char would not be able to send out 'b' while the guest still processes 'a' and has no free buffers to write out to. On seeing 'd', it flushes its queue.

Quoted 7 lines
Quoted 3 lines

Can you try using a 2.6.34-rc3 kernel without this patch to see if things work fine?

Hrm - would it actually matter? We need to have older guest kernels working anyways. And my S390 LPAR doesn't exactly have a lot of disk space, so compiling a kernel is anything but fun :-).

Oh I just want to find out if it works for you -- you shouldn't get hit by the 1-char limit anymore.

Amit

Signature · 1 line
http://log.amitshah.net/
#7 lore raw

PATCH 4/6 Always notify consumers of char devices if they're open

In reply to Alexander Graf

When using virtio-console on s390, the input doesn't work.

The root of the problem is rather simple. What happens is the following:

1) create character device for stdio
2) char device is done creating, sends OPENED event
3) virtio-console adds handlers
4) no event comes because the char device is open already
5) virtio-console doesn't accept input because it didn't receive an OPENED event

To make that sure virtio-console gets notified that the character device is open even when it's been open from the beginning, this patch introduces a variable that keeps track of the opened state. If the device is open when the event handlers get installed, we just notify the handler.

This fixes input with virtio-console on s390.

---
 qemu-char.c |   20 ++++++++++++++++++++
 qemu-char.h |    1 +
 2 files changed, 21 insertions(+), 0 deletions(-)
qemu-char.c +20 -0
index 6ad6609..a9d9442 100644
@@ -109,6 +109,16 @@ static QTAILQ_HEAD(CharDriverStateHead, CharDriverState) chardevs =
 
 static void qemu_chr_event(CharDriverState *s, int event)
 {
+    /* Keep track if the char device is open */
+    switch (event) {
+        case CHR_EVENT_OPENED:
+            s->opened = 1;
+            break;
+        case CHR_EVENT_CLOSED:
+            s->opened = 0;
+            break;
+    }
+
     if (!s->chr_event)
         return;
     s->chr_event(s->handler_opaque, event);
@@ -193,6 +203,12 @@ void qemu_chr_add_handlers(CharDriverState *s,
     s->handler_opaque = opaque;
     if (s->chr_update_read_handler)
         s->chr_update_read_handler(s);
+
+    /* We're connecting to an already opened device, so let's make sure we
+       also get the open event */
+    if (s->opened) {
+        qemu_chr_generic_open(s);
+    }
 }
 
 static int null_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
@@ -475,6 +491,10 @@ static CharDriverState *qemu_chr_open_mux(CharDriverState *drv)
     chr->chr_write = mux_chr_write;
     chr->chr_update_read_handler = mux_chr_update_read_handler;
     chr->chr_accept_input = mux_chr_accept_input;
+
+    /* Muxes are always open on creation */
+    qemu_chr_generic_open(chr);
+
     return chr;
 }
 
qemu-char.h +1 -0
index 3a9427b..e3a0783 100644
@@ -67,6 +67,7 @@ struct CharDriverState {
     QEMUBH *bh;
     char *label;
     char *filename;
+    int opened;
     QTAILQ_ENTRY(CharDriverState) next;
 };
 
Signature · 1 line
1.6.0.2
Acked-by on v1 4/6
#8 lore raw

Re: [Qemu-devel] [PATCH 4/6] Always notify consumers of char devices if they're open

Quoted 11 lines · Alexander Graf

When using virtio-console on s390, the input doesn't work.

The root of the problem is rather simple. What happens is the following:

1) create character device for stdio
2) char device is done creating, sends OPENED event
3) virtio-console adds handlers
4) no event comes because the char device is open already
5) virtio-console doesn't accept input because it didn't receive an OPENED event

Quoted 8 lines

To make that sure virtio-console gets notified that the character device is open even when it's been open from the beginning, this patch introduces a variable that keeps track of the opened state. If the device is open when the event handlers get installed, we just notify the handler.

This fixes input with virtio-console on s390.

Amit

#9 lore raw

Re: [Qemu-devel] [PATCH 4/6] Always notify consumers of char devices if they're open

In reply to Alexander Graf
Quoted 11 lines · Alexander Graf

When using virtio-console on s390, the input doesn't work.

The root of the problem is rather simple. What happens is the following:

1) create character device for stdio
2) char device is done creating, sends OPENED event
3) virtio-console adds handlers
4) no event comes because the char device is open already
5) virtio-console doesn't accept input because it didn't receive an OPENED event

Quoted 6 lines

To make that sure virtio-console gets notified that the character device is open even when it's been open from the beginning, this patch introduces a variable that keeps track of the opened state. If the device is open when the event handlers get installed, we just notify the handler.

This fixes input with virtio-console on s390.

Thanks, applied.

Quoted 69 lines
---
 qemu-char.c |   20 ++++++++++++++++++++
 qemu-char.h |    1 +
 2 files changed, 21 insertions(+), 0 deletions(-)
qemu-char.c +20 -0
index 6ad6609..a9d9442 100644
@@ -109,6 +109,16 @@ static QTAILQ_HEAD(CharDriverStateHead, CharDriverState) chardevs =
 
 static void qemu_chr_event(CharDriverState *s, int event)
 {
+    /* Keep track if the char device is open */
+    switch (event) {
+        case CHR_EVENT_OPENED:
+            s->opened = 1;
+            break;
+        case CHR_EVENT_CLOSED:
+            s->opened = 0;
+            break;
+    }
+
     if (!s->chr_event)
         return;
     s->chr_event(s->handler_opaque, event);
@@ -193,6 +203,12 @@ void qemu_chr_add_handlers(CharDriverState *s,
     s->handler_opaque = opaque;
     if (s->chr_update_read_handler)
         s->chr_update_read_handler(s);
+
+    /* We're connecting to an already opened device, so let's make sure we
+       also get the open event */
+    if (s->opened) {
+        qemu_chr_generic_open(s);
+    }
 }
 
 static int null_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
@@ -475,6 +491,10 @@ static CharDriverState *qemu_chr_open_mux(CharDriverState *drv)
     chr->chr_write = mux_chr_write;
     chr->chr_update_read_handler = mux_chr_update_read_handler;
     chr->chr_accept_input = mux_chr_accept_input;
+
+    /* Muxes are always open on creation */
+    qemu_chr_generic_open(chr);
+
     return chr;
 }
 
qemu-char.h +1 -0
index 3a9427b..e3a0783 100644
@@ -67,6 +67,7 @@ struct CharDriverState {
     QEMUBH *bh;
     char *label;
     char *filename;
+    int opened;
     QTAILQ_ENTRY(CharDriverState) next;
 };
 
Signature · 1 line
1.6.0.2
Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
#10 lore raw

PATCH 5/6 Implement virtio reset

In reply to Alexander Graf

The guest may issue a RESET command for virtio. So far we didn't bother to implement it, but with my new bootloader we actually need it for Linux to get back to a safe state.

---
 hw/s390-virtio-bus.c |    3 +--
 hw/s390-virtio-bus.h |    1 +
 hw/s390-virtio.c     |    9 +++++----
 3 files changed, 7 insertions(+), 6 deletions(-)
hw/s390-virtio-bus.c +1 -2
index 9fc01e9..b52d08d 100644
@@ -56,7 +56,6 @@ typedef struct {
 static const VirtIOBindings virtio_s390_bindings;
 
 static ram_addr_t s390_virtio_device_num_vq(VirtIOS390Device *dev);
-static void s390_virtio_device_sync(VirtIOS390Device *dev);
 
 VirtIOS390Bus *s390_virtio_bus_init(ram_addr_t *ram_size)
 {
@@ -185,7 +184,7 @@ static ram_addr_t s390_virtio_next_ring(VirtIOS390Bus *bus)
     return r;
 }
 
-static void s390_virtio_device_sync(VirtIOS390Device *dev)
+void s390_virtio_device_sync(VirtIOS390Device *dev)
 {
     VirtIOS390Bus *bus = DO_UPCAST(VirtIOS390Bus, bus, dev->qdev.parent_bus);
     ram_addr_t cur_offs;
hw/s390-virtio-bus.h +1 -0
index 0ea8f54..333fea8 100644
@@ -65,3 +65,4 @@ extern VirtIOS390Device *s390_virtio_bus_find_vring(VirtIOS390Bus *bus,
                                                     int *vq_num);
 extern VirtIOS390Device *s390_virtio_bus_find_mem(VirtIOS390Bus *bus,
                                                   ram_addr_t mem);
+extern void s390_virtio_device_sync(VirtIOS390Device *dev);
hw/s390-virtio.c +5 -4
index ad3386f..c36a8b2 100644
@@ -99,10 +99,11 @@ int s390_virtio_hypercall(CPUState *env)
         break;
     case KVM_S390_VIRTIO_RESET:
     {
-        /* Virtio_reset resets the internal addresses, so we'd have to sync
-           them up again. We don't want to reallocate a vring though, so let's
-           just not reset. */
-        /* virtio_reset(dev->vdev); */
+        VirtIOS390Device *dev;
+
+        dev = s390_virtio_bus_find_mem(s390_bus, mem);
+        virtio_reset(dev->vdev);
+        s390_virtio_device_sync(dev);
         break;
     }
     case KVM_S390_VIRTIO_SET_STATUS:
Signature · 1 line
1.6.0.2
#11 lore raw

Re: [Qemu-devel] [PATCH 5/6] [S390] Implement virtio reset

Quoted 3 lines · Alexander Graf

The guest may issue a RESET command for virtio. So far we didn't bother to implement it, but with my new bootloader we actually need it for Linux to get back to a safe state.

Thanks, applied.

Quoted 63 lines
---
 hw/s390-virtio-bus.c |    3 +--
 hw/s390-virtio-bus.h |    1 +
 hw/s390-virtio.c     |    9 +++++----
 3 files changed, 7 insertions(+), 6 deletions(-)
hw/s390-virtio-bus.c +1 -2
index 9fc01e9..b52d08d 100644
@@ -56,7 +56,6 @@ typedef struct {
 static const VirtIOBindings virtio_s390_bindings;
 
 static ram_addr_t s390_virtio_device_num_vq(VirtIOS390Device *dev);
-static void s390_virtio_device_sync(VirtIOS390Device *dev);
 
 VirtIOS390Bus *s390_virtio_bus_init(ram_addr_t *ram_size)
 {
@@ -185,7 +184,7 @@ static ram_addr_t s390_virtio_next_ring(VirtIOS390Bus *bus)
     return r;
 }
 
-static void s390_virtio_device_sync(VirtIOS390Device *dev)
+void s390_virtio_device_sync(VirtIOS390Device *dev)
 {
     VirtIOS390Bus *bus = DO_UPCAST(VirtIOS390Bus, bus, dev->qdev.parent_bus);
     ram_addr_t cur_offs;
hw/s390-virtio-bus.h +1 -0
index 0ea8f54..333fea8 100644
@@ -65,3 +65,4 @@ extern VirtIOS390Device *s390_virtio_bus_find_vring(VirtIOS390Bus *bus,
                                                     int *vq_num);
 extern VirtIOS390Device *s390_virtio_bus_find_mem(VirtIOS390Bus *bus,
                                                   ram_addr_t mem);
+extern void s390_virtio_device_sync(VirtIOS390Device *dev);
hw/s390-virtio.c +5 -4
index ad3386f..c36a8b2 100644
@@ -99,10 +99,11 @@ int s390_virtio_hypercall(CPUState *env)
         break;
     case KVM_S390_VIRTIO_RESET:
     {
-        /* Virtio_reset resets the internal addresses, so we'd have to sync
-           them up again. We don't want to reallocate a vring though, so let's
-           just not reset. */
-        /* virtio_reset(dev->vdev); */
+        VirtIOS390Device *dev;
+
+        dev = s390_virtio_bus_find_mem(s390_bus, mem);
+        virtio_reset(dev->vdev);
+        s390_virtio_device_sync(dev);
         break;
     }
     case KVM_S390_VIRTIO_SET_STATUS:
Signature · 1 line
1.6.0.2
Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
#12 lore raw

PATCH 6/6 Add firmware code

In reply to Alexander Graf

This patch adds a firmware blob to the S390 target. The blob is a simple implementation of a virtio client that tries to read the second stage bootloader from sectors described as of offset 0x20 in the MBR.

In combination with an updated zipl this allows for booting from virtio block devices. This firmware is built from the same sources as the second stage bootloader. You can find the zipl patch to build both here:

http://alex.csgraf.de/qemu/0001-Zipl-VirtIO-bootloader-code.patch

---
 hw/s390-virtio.c      |   20 ++++++++++++++++++++
 pc-bios/s390-zipl.rom |  Bin 0 -> 2448 bytes
 2 files changed, 20 insertions(+), 0 deletions(-)
 create mode 100755 pc-bios/s390-zipl.rom
hw/s390-virtio.c +20 -0
index c36a8b2..91a3065 100644
@@ -52,6 +52,10 @@
 #define INITRD_PARM_SIZE                0x010410UL
 #define PARMFILE_START                  0x001000UL
 
+#define ZIPL_START			0x001000UL
+#define ZIPL_LOAD_ADDR			0x001000UL
+#define ZIPL_FILENAME			"s390-zipl.rom"
+
 #define MAX_BLK_DEVS                    10
 
 static VirtIOS390Bus *s390_bus;
@@ -140,6 +144,8 @@ static void s390_init(ram_addr_t ram_size,
     ram_addr_t kernel_size = 0;
     ram_addr_t initrd_offset;
     ram_addr_t initrd_size = 0;
+    ram_addr_t bios_size = 0;
+    char *bios_filename;
     int i;
 
     /* XXX we only work on KVM for now */
@@ -178,6 +184,20 @@ static void s390_init(ram_addr_t ram_size,
     env->halted = 0;
     env->exception_index = 0;
 
+    /* Load zipl bootloader */
+    if (bios_name == NULL)
+        bios_name = ZIPL_FILENAME;
+
+    bios_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
+    bios_size = load_image(bios_filename, qemu_get_ram_ptr(ZIPL_LOAD_ADDR));
+
+    if ((long)bios_size < 0) {
+        hw_error("could not load bootloader '%s'\n", bios_name);
+    }
+
+    env->psw.addr = ZIPL_START;
+    env->psw.mask = 0x0000000180000000ULL;
+
     if (kernel_filename) {
         kernel_size = load_image(kernel_filename, qemu_get_ram_ptr(0));
 
pc-bios/s390-zipl.rom new file binary +0 -0
new file mode 100755
index 0000000000000000000000000000000000000000..0f1b26afd5ad530035cdc6fbe285bae278ad5983
GIT binary patch
Signature · 1 line
1.6.0.2
#13 lore raw

[Qemu-devel] Re: [PATCH 6/6] [S390] Add firmware code

Quoted 3 lines · Alexander Graf

This patch adds a firmware blob to the S390 target. The blob is a simple implementation of a virtio client that tries to read the second stage bootloader from sectors described as of offset 0x20 in the MBR.

How do you intend to fullfill the source requirement for this firmware? I see no explicit license, so I assume GPL.

Bastian

Signature · 2 lines
Intuition, however illogical, is recognized as a command prerogative.
		-- Kirk, "Obsession", stardate 3620.7
#14 lore raw

[Qemu-devel] Re: [PATCH 6/6] [S390] Add firmware code

Am 01.04.2010 um 23:18 schrieb Bastian Blank <[email protected]>:

Quoted 7 lines · Alexander Graf
Quoted 3 lines

This patch adds a firmware blob to the S390 target. The blob is a simple implementation of a virtio client that tries to read the second stage bootloader from sectors described as of offset 0x20 in the MBR.

How do you intend to fullfill the source requirement for this firmware? I see no explicit license, so I assume GPL.

The firmware gets built as part of the s390-tools package which is GPLed FWIW. But all source required for it is in the patch I linked to. So you would be able to build it without s390-tools and all new virtio specific files are basically PD.

Alex

#15 lore raw

Re: [Qemu-devel] [PATCH 6/6] [S390] Add firmware code

In reply to Alexander Graf
Quoted 9 lines · Alexander Graf

This patch adds a firmware blob to the S390 target. The blob is a simple implementation of a virtio client that tries to read the second stage bootloader from sectors described as of offset 0x20 in the MBR.

In combination with an updated zipl this allows for booting from virtio block devices. This firmware is built from the same sources as the second stage bootloader. You can find the zipl patch to build both here:

http://alex.csgraf.de/qemu/0001-Zipl-VirtIO-bootloader-code.patch

I am not fully comfortable introducing a binary firmware based on a patch posted on a website. I see two options:
- Get your patch merged into ZIPL, so that we can build the firmware directly from the ZIPL sources
- Add the patch to the pc-bios/ directory

Also it would be nice to update pc-bios/README to provide details about the ZIPL version used to build pc-bios/s390-zipl.rom.

Quoted 32 lines
---
 hw/s390-virtio.c      |   20 ++++++++++++++++++++
 pc-bios/s390-zipl.rom |  Bin 0 -> 2448 bytes
 2 files changed, 20 insertions(+), 0 deletions(-)
 create mode 100755 pc-bios/s390-zipl.rom
hw/s390-virtio.c +6 -0
index c36a8b2..91a3065 100644
@@ -52,6 +52,10 @@
 #define INITRD_PARM_SIZE                0x010410UL
 #define PARMFILE_START                  0x001000UL
 
+#define ZIPL_START			0x001000UL
+#define ZIPL_LOAD_ADDR			0x001000UL
+#define ZIPL_FILENAME			"s390-zipl.rom"
+
 #define MAX_BLK_DEVS                    10
 
 static VirtIOS390Bus *s390_bus;
@@ -140,6 +144,8 @@ static void s390_init(ram_addr_t ram_size,
     ram_addr_t kernel_size = 0;
     ram_addr_t initrd_offset;
     ram_addr_t initrd_size = 0;
+    ram_addr_t bios_size = 0;
+    char *bios_filename;
     int i;
 
     /* XXX we only work on KVM for now */

hw/s390-virtio.c static void s390_init(ram_addr_t ram_size, · line 189

Quoted 6 lines
hw/s390-virtio.c +3 -0
@@ -178,6 +184,20 @@ static void s390_init(ram_addr_t ram_size,
     env->halted = 0;
     env->exception_index = 0;
 
+    /* Load zipl bootloader */
+    if (bios_name == NULL)
+        bios_name = ZIPL_FILENAME;

You are missing curly braces here.

hw/s390-virtio.c static void s390_init(ram_addr_t ram_size, · line 200

Quoted 10 lines
hw/s390-virtio.c +10 -0
+    bios_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
+    bios_size = load_image(bios_filename, qemu_get_ram_ptr(ZIPL_LOAD_ADDR));
+
+    if ((long)bios_size < 0) {
+        hw_error("could not load bootloader '%s'\n", bios_name);
+    }
+
+    env->psw.addr = ZIPL_START;
+    env->psw.mask = 0x0000000180000000ULL;
+

This probably has to be put in a reset handler so that this address is reloaded upon reboot.

Also do you really want to make the firmware mandatory? What about a warning and falling back to the direct kernel boot instead (if provided), as it is already now. Some other machines are doing that.

Quoted 51 lines
hw/s390-virtio.c +0 -0
     if (kernel_filename) {
         kernel_size = load_image(kernel_filename, qemu_get_ram_ptr(0));
 
pc-bios/s390-zipl.rom new file binary +0 -0
new file mode 100755
index 0000000000000000000000000000000000000000..0f1b26afd5ad530035cdc6fbe285bae278ad5983
GIT binary patch
Signature · 2 lines
-- 
1.6.0.2
Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
#16 lore raw

Re: [Qemu-devel] [PATCH 6/6] [S390] Add firmware code

Quoted 9 lines · Aurelien Jarno
Quoted 8 lines · Alexander Graf

This patch adds a firmware blob to the S390 target. The blob is a simple implementation of a virtio client that tries to read the second stage bootloader from sectors described as of offset 0x20 in the MBR.

In combination with an updated zipl this allows for booting from virtio block devices. This firmware is built from the same sources as the second stage bootloader. You can find the zipl patch to build both here:

Quoted 6 lines
Quoted 1 line

http://alex.csgraf.de/qemu/0001-Zipl-VirtIO-bootloader-code.patch

I am not fully comfortable introducing a binary firmware based on a patch posted on a website. I see two options:
- Get your patch merged into ZIPL, so that we can build the firmware directly from the ZIPL sources

IBM wants to keep the copyright on the zipl sources, so this one's out.

Quoted 1 line

- Add the patch to the pc-bios/ directory

Sounds good.

Quoted 2 lines

Also it would be nice to update pc-bios/README to provide details about the ZIPL version used to build pc-bios/s390-zipl.rom.

Hrm. I wonder where the s390-tools package comes from. I'll see what I can do there.

Quoted 42 lines
Quoted 33 lines

---
hw/s390-virtio.c | 20 ++++++++++++++++++++
pc-bios/s390-zipl.rom | Bin 0 -> 2448 bytes

2 files changed, 20 insertions(+), 0 deletions(-)

create mode 100755 pc-bios/s390-zipl.rom

hw/s390-virtio.c +6 -0
index c36a8b2..91a3065 100644
@@ -52,6 +52,10 @@
 #define INITRD_PARM_SIZE                0x010410UL
 #define PARMFILE_START                  0x001000UL
 
+#define ZIPL_START			0x001000UL
+#define ZIPL_LOAD_ADDR			0x001000UL
+#define ZIPL_FILENAME			"s390-zipl.rom"
+
 #define MAX_BLK_DEVS                    10
 
 static VirtIOS390Bus *s390_bus;
@@ -140,6 +144,8 @@ static void s390_init(ram_addr_t ram_size,
    ram_addr_t kernel_size = 0;
    ram_addr_t initrd_offset;
    ram_addr_t initrd_size = 0;
+    ram_addr_t bios_size = 0;
+    char *bios_filename;
    int i;
 
    /* XXX we only work on KVM for now */

hw/s390-virtio.c static void s390_init(ram_addr_t ram_size, · line 189

Quoted 6 lines
hw/s390-virtio.c +3 -0
@@ -178,6 +184,20 @@ static void s390_init(ram_addr_t ram_size,
    env->halted = 0;
    env->exception_index = 0;
 
+    /* Load zipl bootloader */
+    if (bios_name == NULL)
+        bios_name = ZIPL_FILENAME;

You are missing curly braces here.

Quoted 13 lines

hw/s390-virtio.c static void s390_init(ram_addr_t ram_size, · line 200

Quoted 10 lines
hw/s390-virtio.c +10 -0
+    bios_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
+    bios_size = load_image(bios_filename, qemu_get_ram_ptr(ZIPL_LOAD_ADDR));
+
+    if ((long)bios_size < 0) {
+        hw_error("could not load bootloader '%s'\n", bios_name);
+    }
+
+    env->psw.addr = ZIPL_START;
+    env->psw.mask = 0x0000000180000000ULL;
+

This probably has to be put in a reset handler so that this address is reloaded upon reboot.

A lot needs to go into a reset handler. In fact, we don't implement reset at all so far. I'd rather move it over to a reset handler when we actually introduce reset functionality.

Quoted 4 lines

Also do you really want to make the firmware mandatory? What about a warning and falling back to the direct kernel boot instead (if provided), as it is already now. Some other machines are doing that.

Yes, I do. It doesn't hurt to have it loaded and on -kernel we can just set the PSW differently, thus making the guest jump directly into the kernel. So the firmware is loaded and completely ignored. That's btw what happens with this patch already. -kernel overrides the firmware.

Alex

#17 lore raw

Re: [Qemu-devel] [PATCH 6/6] [S390] Add firmware code

Quoted 12 lines · Alexander Graf
Quoted 9 lines · Aurelien Jarno
Quoted 8 lines · Alexander Graf

This patch adds a firmware blob to the S390 target. The blob is a simple implementation of a virtio client that tries to read the second stage bootloader from sectors described as of offset 0x20 in the MBR.

In combination with an updated zipl this allows for booting from virtio block devices. This firmware is built from the same sources as the second stage bootloader. You can find the zipl patch to build both here:

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

http://alex.csgraf.de/qemu/0001-Zipl-VirtIO-bootloader-code.patch

I am not fully comfortable introducing a binary firmware based on a patch posted on a website. I see two options:
- Get your patch merged into ZIPL, so that we can build the firmware directly from the ZIPL sources

IBM wants to keep the copyright on the zipl sources, so this one's out.

You can't transfer the copyright, as it is done for example for GNU projects?

Quoted 65 lines
Quoted 1 line

- Add the patch to the pc-bios/ directory

Sounds good.

Quoted 2 lines

Also it would be nice to update pc-bios/README to provide details about the ZIPL version used to build pc-bios/s390-zipl.rom.

Hrm. I wonder where the s390-tools package comes from. I'll see what I can do there.

Quoted 42 lines
Quoted 33 lines

---
hw/s390-virtio.c | 20 ++++++++++++++++++++
pc-bios/s390-zipl.rom | Bin 0 -> 2448 bytes

2 files changed, 20 insertions(+), 0 deletions(-)

create mode 100755 pc-bios/s390-zipl.rom

hw/s390-virtio.c +6 -0
index c36a8b2..91a3065 100644
@@ -52,6 +52,10 @@
 #define INITRD_PARM_SIZE                0x010410UL
 #define PARMFILE_START                  0x001000UL
 
+#define ZIPL_START			0x001000UL
+#define ZIPL_LOAD_ADDR			0x001000UL
+#define ZIPL_FILENAME			"s390-zipl.rom"
+
 #define MAX_BLK_DEVS                    10
 
 static VirtIOS390Bus *s390_bus;
@@ -140,6 +144,8 @@ static void s390_init(ram_addr_t ram_size,
    ram_addr_t kernel_size = 0;
    ram_addr_t initrd_offset;
    ram_addr_t initrd_size = 0;
+    ram_addr_t bios_size = 0;
+    char *bios_filename;
    int i;
 
    /* XXX we only work on KVM for now */

hw/s390-virtio.c static void s390_init(ram_addr_t ram_size, · line 189

Quoted 6 lines
hw/s390-virtio.c +3 -0
@@ -178,6 +184,20 @@ static void s390_init(ram_addr_t ram_size,
    env->halted = 0;
    env->exception_index = 0;
 
+    /* Load zipl bootloader */
+    if (bios_name == NULL)
+        bios_name = ZIPL_FILENAME;

You are missing curly braces here.

Quoted 13 lines

hw/s390-virtio.c static void s390_init(ram_addr_t ram_size, · line 200

Quoted 10 lines
hw/s390-virtio.c +10 -0
+    bios_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
+    bios_size = load_image(bios_filename, qemu_get_ram_ptr(ZIPL_LOAD_ADDR));
+
+    if ((long)bios_size < 0) {
+        hw_error("could not load bootloader '%s'\n", bios_name);
+    }
+
+    env->psw.addr = ZIPL_START;
+    env->psw.mask = 0x0000000180000000ULL;
+

This probably has to be put in a reset handler so that this address is reloaded upon reboot.

Quoted 1 line

A lot needs to go into a reset handler. In fact, we don't implement reset at all so far. I'd rather move it over to a reset handler when we actually introduce reset functionality.

ok.

Quoted 7 lines
Quoted 4 lines

Also do you really want to make the firmware mandatory? What about a warning and falling back to the direct kernel boot instead (if provided), as it is already now. Some other machines are doing that.

Yes, I do. It doesn't hurt to have it loaded and on -kernel we can just set the PSW differently, thus making the guest jump directly into the kernel. So the firmware is loaded and completely ignored. That's btw what happens with this patch already. -kernel overrides the firmware.

That means people needs to have the firmware installed even if they don't need it.

Signature · 2 lines
Aurelien Jarno	                        GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
#18 lore raw

Re: [Qemu-devel] [PATCH 6/6] [S390] Add firmware code

Quoted 20 lines · Aurelien Jarno
Quoted 19 lines · Alexander Graf
Quoted 15 lines · Aurelien Jarno
Quoted 9 lines · Alexander Graf

This patch adds a firmware blob to the S390 target. The blob is a simple implementation of a virtio client that tries to read the second stage bootloader from sectors described as of offset 0x20 in the MBR.

In combination with an updated zipl this allows for booting from virtio block devices. This firmware is built from the same sources as the second stage bootloader. You can find the zipl patch to build both here:

http://alex.csgraf.de/qemu/0001-Zipl-VirtIO-bootloader-code.patch

I am not fully comfortable introducing a binary firmware based on a patch posted on a website. I see two options:
- Get your patch merged into ZIPL, so that we can build the firmware directly from the ZIPL sources

Quoted 4 lines
Quoted 1 line

IBM wants to keep the copyright on the zipl sources, so this one's out.

You can't transfer the copyright, as it is done for example for GNU projects?

I don't think so. Apart from it being illegal in Germany (you can't transfer full copyrights) I'm not sure that'd really help.

Another idea:

How about I set up a git tree on repo.or.cz and put it there? That git tree would contain all my changes, be a single public source and I'd try to pull all 'upstream' changes back in?

Quoted 10 lines
Quoted 7 lines
Quoted 4 lines

Also do you really want to make the firmware mandatory? What about a warning and falling back to the direct kernel boot instead (if provided), as it is already now. Some other machines are doing that.

Yes, I do. It doesn't hurt to have it loaded and on -kernel we can just set the PSW differently, thus making the guest jump directly into the kernel. So the firmware is loaded and completely ignored. That's btw what happens with this patch already. -kernel overrides the firmware.

That means people needs to have the firmware installed even if they don't need it.

I don't see a problem there. It's less than 4k. Plus it's mandatory for x86 and ppc too, so why make it different?

Alex

#19 lore raw

Re: [Qemu-devel] [PATCH 6/6] [S390] Add firmware code

Quoted 25 lines · Alexander Graf
Quoted 22 lines · Aurelien Jarno
Quoted 20 lines · Alexander Graf
Quoted 9 lines · Aurelien Jarno
Quoted 8 lines · Alexander Graf

This patch adds a firmware blob to the S390 target. The blob is a simple implementation of a virtio client that tries to read the second stage bootloader from sectors described as of offset 0x20 in the MBR.

In combination with an updated zipl this allows for booting from virtio block devices. This firmware is built from the same sources as the second stage bootloader. You can find the zipl patch to build both here:

Quoted 6 lines
Quoted 1 line

http://alex.csgraf.de/qemu/0001-Zipl-VirtIO-bootloader-code.patch

I am not fully comfortable introducing a binary firmware based on a patch posted on a website. I see two options:
- Get your patch merged into ZIPL, so that we can build the firmware directly from the ZIPL sources

IBM wants to keep the copyright on the zipl sources, so this one's out.

Quoted 8 lines
Quoted 2 lines

You can't transfer the copyright, as it is done for example for GNU projects?

I don't think so. Apart from it being illegal in Germany (you can't transfer full copyrights) I'm not sure that'd really help.

Another idea:

How about I set up a git tree on repo.or.cz and put it there? That git tree would contain all my changes, be a single public source and I'd try to pull all 'upstream' changes back in?

Also looks a good idea.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

Also do you really want to make the firmware mandatory? What about a warning and falling back to the direct kernel boot instead (if provided), as it is already now. Some other machines are doing that.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Yes, I do. It doesn't hurt to have it loaded and on -kernel we can just set the PSW differently, thus making the guest jump directly into the kernel. So the firmware is loaded and completely ignored. That's btw what happens with this patch already. -kernel overrides the firmware.

That means people needs to have the firmware installed even if they don't need it.

I don't see a problem there. It's less than 4k. Plus it's mandatory for x86 and ppc too, so why make it different?

It's mandatory for x86 and ppc as the bootloader is actually doing the jump to the kernel (for ppc it even provide some services to the kernel).

The main problem I see is for distributions that want to rebuild the firmwares from sources. Also making it optional is just a few lines more.

Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
#20 lore raw

Re: [Qemu-devel] [PATCH 6/6] [S390] Add firmware code

In reply to Aurelien Jarno
Quoted 5 lines · Aurelien Jarno

I am not fully comfortable introducing a binary firmware based on a patch posted on a website. I see two options:
- Get your patch merged into ZIPL, so that we can build the firmware directly from the ZIPL sources
- Add the patch to the pc-bios/ directory

Looks like we'll have to sort out how to work with patches against s390-tools from the legal side. So far s390-tools is IBM-Code only and released as GPL, maybe it needs to go to sourceforge or alike in order be able to receive contributions. While we're at it, I think it would be good to have it as a blob in QEMU so that users can actually boot :-).