S390x KVM support
cover S390x KVM support
While S390x was one of the first targets that were supported by KVM it always lacked qemu system emulation support.
In order to change that sad fact, I figured I'd just take on the task myself, taking kuli (http://www.ibm.com/developerworks/linux/linux390/kuli.html),Documentation/s390/kvm.txt and lguest as starting points to write a clean, qemu'ish S390x Virtio machine emulation.
So now you can run Linux VMs on Linux on z/VM on LPAR on zSeries!
This is the resulting code. Please comment on things you like and also on the ones you don't :-).
The patchset is based on Uli's S390x userspace emulation patches. There's not really that much shared functionality, but I didn't want to reimplement the configure wheels. So make sure to have his patches applied first.
Please only run S390x system virtualization using io threads. S390x has very few intercepts and even less that actually reach userspace. So you'll end up with a non-responsive VM without a dedicated IO thread.
Use: $ ./configure --target-list=s390x-softmmu --enable-io-thread
Currently only -kernel, -initrd and friends work. Booting from a real dasd device is not supported.
Also to actually run this code you need a patch for an ugly bug in the kernel
module: http://alex.csgraf.de/psw.patch
I verified that the userspace actually works on a 2.6.27 (SLES11) kernel, so if it doesn't work on current git, please tell me! I'm too afraid that I might end up in a 3270 terminal to update the kernel on my z/VM instance :-).
Alexander Graf (9):
Export function for VA defined ram allocation
Add KVM support for S390x
Add support for S390x system emulation
Add S390x virtio machine bus
Add S390x virtio machine description
S390 GDB stub
Implement early printk in virtio-console
Set default console to virtio on S390x
Move mp_state to CPU_COMMON
Makefile.target | 2 + configure | 4 +- cpu-common.h | 1 + cpu-defs.h | 1 + exec.c | 15 ++- gdbstub.c | 52 ++++++ hw/s390-virtio-bus.c | 350 +++++++++++++++++++++++++++++++++++ hw/s390-virtio-bus.h | 64 +++++++ hw/s390-virtio.c | 244 ++++++++++++++++++++++++ hw/virtio-console.c | 7 + hw/virtio-console.h | 2 + target-i386/cpu.h | 1 - target-s390x/cpu.h | 86 +++++++++- target-s390x/exec.h | 5 + target-s390x/helper.c | 26 +++- target-s390x/kvm.c | 457 ++++++++++++++++++++++++++++++++++++++++++++++ target-s390x/machine.c | 30 +++ target-s390x/op_helper.c | 53 ++++++ vl.c | 26 +++ 19 files changed, 1418 insertions(+), 8 deletions(-) create mode 100644 hw/s390-virtio-bus.c create mode 100644 hw/s390-virtio-bus.h create mode 100644 hw/s390-virtio.c create mode 100644 target-s390x/kvm.c create mode 100644 target-s390x/machine.c
PATCH 1/9 Export function for VA defined ram allocation
S390 requires vmas for guests to be < 256 GB. So we need to directly export mmaps "try to use this vma as start address" feature to not accidently get over that limit.
--- cpu-common.h | 1 + exec.c | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-)
cpu-common.h +1 -0
@@ -30,6 +30,7 @@ static inline void cpu_register_physical_memory(target_phys_addr_t start_addr,ram_addr_t cpu_get_physical_page_desc (target_phys_addr_t addr);ram_addr_t qemu_ram_alloc (ram_addr_t ); +ram_addr_t _qemu_ram_alloc (ram_addr_t size,void *map_at);void qemu_ram_free (ram_addr_t addr);/* This should only be used for ram local to a device. */ void *qemu_get_ram_ptr (ram_addr_t addr);
exec.c +13 -2
@@ -2404,14 +2404,20 @@ void qemu_unregister_coalesced_mmio(target_phys_addr_t addr, ram_addr_t size)kvm_uncoalesce_mmio_region (addr, size); } -ram_addr_t qemu_ram_alloc (ram_addr_t size) +ram_addr_t _qemu_ram_alloc (ram_addr_t size,void *map_at) {RAMBlock *new_block; size =TARGET_PAGE_ALIGN (size); new_block =qemu_malloc (sizeof (*new_block)); - new_block->host =qemu_vmalloc (size); +if (map_at) { + new_block->host =mmap (map_at, size,PROT_EXEC |PROT_READ |PROT_WRITE , +MAP_SHARED |MAP_ANONYMOUS ,-1 ,0 ); + + }else { + new_block->host =qemu_vmalloc (size); + }#ifdef MADV_MERGEABLE madvise (new_block->host, size,MADV_MERGEABLE );#endif
@@ -2434,6 +2440,11 @@ ram_addr_t qemu_ram_alloc(ram_addr_t size)return new_block->offset; } +ram_addr_t qemu_ram_alloc (ram_addr_t size) +{ +return _qemu_ram_alloc (size,NULL ); +} +void qemu_ram_free (ram_addr_t addr) {/* TODO: implement this. */
Signature · 1 line
1.6.0.2
PATCH 2/9 Add KVM support for S390x
S390x was one of the first platforms that received support for KVM back in the day. Unfortunately until now there hasn't been a qemu implementation that would enable users to actually run guests.
So let's include support for KVM S390x in qemu!
--- configure | 4 +- target-s390x/kvm.c | 457 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 460 insertions(+), 1 deletions(-) create mode 100644 target-s390x/kvm.c
configure +3 -1
@@ -1342,6 +1342,8 @@ EOF kvm_cflags="$kvm_cflags -I$kerneldir/arch/x86/include" elif test "$cpu" = "ppc" -a -d "$kerneldir/arch/powerpc/include" ; then kvm_cflags="$kvm_cflags -I$kerneldir/arch/powerpc/include" + elif test "$cpu" = "s390x" -a -d "$kerneldir/arch/s390/include" ; then + kvm_cflags="$kvm_cflags -I$kerneldir/arch/s390/include" elif test -d "$kerneldir/arch/$cpu/include" ; then kvm_cflags="$kvm_cflags -I$kerneldir/arch/$cpu/include" fi
@@ -2286,7 +2288,7 @@ case "$target_arch2" in fi esac case "$target_arch2" in - i386|x86_64|ppcemb|ppc|ppc64) + i386|x86_64|ppcemb|ppc|ppc64|s390x) # Make sure the target and host cpus are compatible if test "$kvm" = "yes" -a "$target_softmmu" = "yes" -a \ \( "$target_arch2" = "$cpu" -o \
target-s390x/kvm.c new file +457 -0
457 lines not on this page · raw message
Signature · 1 line
1.6.0.2
PATCH 3/9 Add support for S390x system emulation
Right now only S390x Linux userspace emulation is supported. Let's enable the basics for system emulation so we can run virtual machines with KVM!
--- target-s390x/cpu.h | 86 ++++++++++++++++++++++++++++++++++++++++++++- target-s390x/exec.h | 5 +++ target-s390x/helper.c | 26 +++++++++++++- target-s390x/machine.c | 30 ++++++++++++++++ target-s390x/op_helper.c | 53 ++++++++++++++++++++++++++++ 5 files changed, 196 insertions(+), 4 deletions(-) create mode 100644 target-s390x/machine.c
target-s390x/cpu.h +84 -2
@@ -30,8 +30,7 @@#include "softfloat.h" -#define NB_MMU_MODES 2 // guess -#define MMU_USER_IDX 0 // guess +#define NB_MMU_MODES 2 typedef union FPReg { struct {
@@ -77,12 +76,28 @@ static inline void cpu_clone_regs(CPUState *env, target_ulong newsp) }#endif +#define MMU_MODE0_SUFFIX _kernel +#define MMU_MODE1_SUFFIX _user +#define MMU_USER_IDX 1 +static inline int cpu_mmu_index (CPUState *env) +{ +/* XXX: Currently we don't implement virtual memory */ +return 0 ; +} + +CPUS390XState *cpu_s390x_init (const char *cpu_model);void s390x_translate_init (void );int cpu_s390x_exec (CPUS390XState *s);void cpu_s390x_close (CPUS390XState *s);void do_interrupt (CPUState *env); +#ifndef CONFIG_USER_ONLY +extern int s390_virtio_hypercall (CPUState *env); +extern void kvm_s390_virtio_irq (CPUState *env,int config_change,uint64_t token); +extern CPUState *s390_cpu_addr2state (uint16_t cpu_addr); +#endif +/* you can call this signal handler from your SIGBUS and SIGSEGV signal handlers to inform the virtual CPU of exceptions. non zero is returned if the signal was handled by the virtual CPU. */
@@ -129,4 +144,71 @@ static inline void cpu_get_tb_cpu_state(CPUState* env, target_ulong *pc, *cs_base =0 ; *flags = env->psw.mask; // guess } + +/* Program Status Word. */ +#define S390_PSWM_REGNUM 0 +#define S390_PSWA_REGNUM 1 +/* General Purpose Registers. */ +#define S390_R0_REGNUM 2 +#define S390_R1_REGNUM 3 +#define S390_R2_REGNUM 4 +#define S390_R3_REGNUM 5 +#define S390_R4_REGNUM 6 +#define S390_R5_REGNUM 7 +#define S390_R6_REGNUM 8 +#define S390_R7_REGNUM 9 +#define S390_R8_REGNUM 10 +#define S390_R9_REGNUM 11 +#define S390_R10_REGNUM 12 +#define S390_R11_REGNUM 13 +#define S390_R12_REGNUM 14 +#define S390_R13_REGNUM 15 +#define S390_R14_REGNUM 16 +#define S390_R15_REGNUM 17 +/* Access Registers. */ +#define S390_A0_REGNUM 18 +#define S390_A1_REGNUM 19 +#define S390_A2_REGNUM 20 +#define S390_A3_REGNUM 21 +#define S390_A4_REGNUM 22 +#define S390_A5_REGNUM 23 +#define S390_A6_REGNUM 24 +#define S390_A7_REGNUM 25 +#define S390_A8_REGNUM 26 +#define S390_A9_REGNUM 27 +#define S390_A10_REGNUM 28 +#define S390_A11_REGNUM 29 +#define S390_A12_REGNUM 30 +#define S390_A13_REGNUM 31 +#define S390_A14_REGNUM 32 +#define S390_A15_REGNUM 33 +/* Floating Point Control Word. */ +#define S390_FPC_REGNUM 34 +/* Floating Point Registers. */ +#define S390_F0_REGNUM 35 +#define S390_F1_REGNUM 36 +#define S390_F2_REGNUM 37 +#define S390_F3_REGNUM 38 +#define S390_F4_REGNUM 39 +#define S390_F5_REGNUM 40 +#define S390_F6_REGNUM 41 +#define S390_F7_REGNUM 42 +#define S390_F8_REGNUM 43 +#define S390_F9_REGNUM 44 +#define S390_F10_REGNUM 45 +#define S390_F11_REGNUM 46 +#define S390_F12_REGNUM 47 +#define S390_F13_REGNUM 48 +#define S390_F14_REGNUM 49 +#define S390_F15_REGNUM 50 +/* Total. */ +#define S390_NUM_REGS 51 + +/* Pseudo registers -- PC and condition code. */ +#define S390_PC_REGNUM S390_NUM_REGS +#define S390_CC_REGNUM (S390_NUM_REGS+1) +#define S390_NUM_PSEUDO_REGS 2 +#define S390_NUM_TOTAL_REGS (S390_NUM_REGS+2) + +#endif
target-s390x/exec.h +5 -0
@@ -22,9 +22,14 @@ register struct CPUS390XState *env asm(AREG0); +#include "config.h" #include "cpu.h" #include "exec-all.h" +#if !defined(CONFIG_USER_ONLY ) +#include "softmmu_exec.h" +#endif /* !defined(CONFIG_USER_ONLY) */ +static inline int cpu_has_work (CPUState *env) {return env->interrupt_request &CPU_INTERRUPT_HARD ;// guess
target-s390x/helper.c +24 -2
@@ -27,6 +27,9 @@#include "gdbstub.h" #include "qemu-common.h" +#include <linux/kvm.h> +#include "kvm.h" +CPUS390XState *cpu_s390x_init (const char *cpu_model) {CPUS390XState *env;
@@ -61,13 +64,13 @@ int cpu_s390x_handle_mmu_fault (CPUState *env, target_ulong address, int rw, return 1; } +#endif /* CONFIG_USER_ONLY */ +target_phys_addr_t cpu_get_phys_page_debug (CPUState *env,target_ulong addr) {return addr; } -#endif /* CONFIG_USER_ONLY */ -void cpu_reset (CPUS390XState *env) {if (qemu_loglevel_mask (CPU_LOG_RESET )) {
@@ -79,3 +82,22 @@ void cpu_reset(CPUS390XState *env)/* FIXME: reset vector? */ tlb_flush (env,1 ); } + +#ifndef CONFIG_USER_ONLY + +int cpu_s390x_handle_mmu_fault (CPUState *env,target_ulong address,int rw, +int mmu_idx,int is_softmmu) +{ +target_ulong phys; +int prot; + +/* XXX: implement mmu */ + + phys = address; + prot =PAGE_READ |PAGE_WRITE ; + +return tlb_set_page (env, address &TARGET_PAGE_MASK , + phys &TARGET_PAGE_MASK , prot, + mmu_idx, is_softmmu); +} +#endif /* CONFIG_USER_ONLY */
target-s390x/machine.c new file +30 -0
@@ -0,0 +1,30 @@ +/* +* QEMU S390x machine definitions +* +* Copyright (c) 2009 Alexander Graf <[email protected]> +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include "hw/hw.h" +#include "hw/boards.h" + +void cpu_save (QEMUFile *f,void *opaque) +{ +} + +int cpu_load (QEMUFile *f,void *opaque,int version_id) +{ +return 0 ; +}
target-s390x/op_helper.c +53 -0
56 lines not on this page · raw message
Signature · 1 line
1.6.0.2
PATCH 4/9 Add S390x virtio machine bus
On S390x we don't want to go through the hassle of emulating real existing hardware, because we don't need to for running Linux.
So let's instead implement a machine that is 100% based on VirtIO which we fortunately implement already.
This patch implements the bus that is the groundwork for such an S390x virtio machine.
--- Makefile.target | 2 + hw/s390-virtio-bus.c | 350 ++++++++++++++++++++++++++++++++++++++++++++++++++ hw/s390-virtio-bus.h | 64 +++++++++ 3 files changed, 416 insertions(+), 0 deletions(-) create mode 100644 hw/s390-virtio-bus.c create mode 100644 hw/s390-virtio-bus.h
Makefile.target +2 -0
@@ -294,6 +294,8 @@ obj-sh4-y += ide/core.o ide/mmio.o obj-m68k-y = an5206.o mcf5206.o mcf_uart.o mcf_intc.o mcf5208.o mcf_fec.o obj-m68k-y += m68k-semi.o dummy_m68k.o +obj-s390x-y = s390-virtio-bus.o + main.o vl.o: QEMU_CFLAGS+=$(GPROF_CFLAGS) vl.o: QEMU_CFLAGS+=$(SDL_CFLAGS)
hw/s390-virtio-bus.c new file +350 -0
350 lines not on this page · raw message
hw/s390-virtio-bus.h new file +64 -0
64 lines not on this page · raw message
Signature · 1 line
1.6.0.2
PATCH 5/9 Add S390x virtio machine description
In order to use the new S390x virtio bus we just introduced, we also need a machine description that sets up the machine according to our PV specification.
Let's add that machine description and be happy!
--- Makefile.target | 2 +- hw/s390-virtio.c | 244 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 245 insertions(+), 1 deletions(-) create mode 100644 hw/s390-virtio.c
Makefile.target +1 -1
@@ -294,7 +294,7 @@ obj-sh4-y += ide/core.o ide/mmio.o obj-m68k-y = an5206.o mcf5206.o mcf_uart.o mcf_intc.o mcf5208.o mcf_fec.o obj-m68k-y += m68k-semi.o dummy_m68k.o -obj-s390x-y = s390-virtio-bus.o +obj-s390x-y = s390-virtio-bus.o s390-virtio.o main.o vl.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
hw/s390-virtio.c new file +244 -0
244 lines not on this page · raw message
Signature · 1 line
1.6.0.2
PATCH 6/9 S390 GDB stub
In order to debug funny kernel breakages it's always good to have a working gdb stub around.
While Uli's patches don't include one one, I needed one that's at least good enough for 'bt' and some variable examinations during early bootup.
So here it is - the absolute basics to get the qemu gdb stub running with s390x targets.
--- gdbstub.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 52 insertions(+), 0 deletions(-)
gdbstub.c +52 -0
@@ -1348,6 +1348,55 @@ static int cpu_gdb_write_register(CPUState *env, uint8_t *mem_buf, int n)return 8 ; } +#elif defined (TARGET_S390X ) + +#define NUM_CORE_REGS S390_NUM_TOTAL_REGS + +static int cpu_gdb_read_register (CPUState *env,uint8_t *mem_buf,int n) +{ +switch (n) { +case S390_PSWM_REGNUM :GET_REGL (env->psw.mask);break ; +case S390_PSWA_REGNUM :GET_REGL (env->psw.addr);break ; + case S390_R0_REGNUM ... S390_R15_REGNUM: +GET_REGL (env->regs[n-S390_R0_REGNUM ]);break ; + case S390_A0_REGNUM ... S390_A15_REGNUM: +GET_REG32 (env->aregs[n-S390_A0_REGNUM ]);break ; +case S390_FPC_REGNUM :GET_REG32 (env->fpc);break ; + case S390_F0_REGNUM ... S390_F15_REGNUM: +/* XXX */ +break ; +case S390_PC_REGNUM :GET_REGL (env->psw.addr);break ; +case S390_CC_REGNUM :GET_REG32 (env->cc);break ; + } + +return 0 ; +} + +static int cpu_gdb_write_register (CPUState *env,uint8_t *mem_buf,int n) +{ +target_ulong tmpl; +uint32_t tmp32; +int r =8 ; + tmpl =ldtul_p (mem_buf); + tmp32 =ldl_p (mem_buf); + +switch (n) { +case S390_PSWM_REGNUM : env->psw.mask = tmpl;break ; +case S390_PSWA_REGNUM : env->psw.addr = tmpl;break ; + case S390_R0_REGNUM ... S390_R15_REGNUM: + env->regs[n-S390_R0_REGNUM ] = tmpl;break ; + case S390_A0_REGNUM ... S390_A15_REGNUM: + env->aregs[n-S390_A0_REGNUM ] = tmp32; r=4 ;break ; +case S390_FPC_REGNUM : env->fpc = tmp32; r=4 ;break ; + case S390_F0_REGNUM ... S390_F15_REGNUM: +/* XXX */ +break ; +case S390_PC_REGNUM : env->psw.addr = tmpl;break ; +case S390_CC_REGNUM : env->cc = tmp32; r=4 ;break ; + } + +return r; +}#else #define NUM_CORE_REGS 0
@@ -1616,6 +1665,9 @@ static void gdb_set_cpu_pc(GDBState *s, target_ulong pc) s->c_cpu->pc = pc;#elif defined (TARGET_ALPHA ) s->c_cpu->pc = pc; +#elif defined (TARGET_S390X ) +cpu_synchronize_state (s->c_cpu); + s->c_cpu->psw.addr = pc;#endif }
Signature · 1 line
1.6.0.2
PATCH 7/9 Implement early printk in virtio-console
On our S390x Virtio machine we don't have anywhere to display early printks on, because we don't know about VGA or serial ports.
So instead we just forward everything to the virtio console that we created anyways.
--- hw/virtio-console.c | 7 +++++++ hw/virtio-console.h | 2 ++ 2 files changed, 9 insertions(+), 0 deletions(-)
hw/virtio-console.c +7 -0
@@ -105,6 +105,13 @@ static void vcon_event(void *opaque, int event)/* we will ignore any event for the time being */ } +void virtio_console_print_early (VirtIODevice *vdev,uint8_t *buf) +{ +VirtIOConsole *s =to_virtio_console (vdev); + +qemu_chr_write (s->chr, buf,strlen ((char *)buf)); +} +static void virtio_console_save (QEMUFile *f,void *opaque) {VirtIOConsole *s = opaque;
hw/virtio-console.h +2 -0
@@ -16,4 +16,6 @@/* The ID for virtio console */ #define VIRTIO_ID_CONSOLE 3 +void virtio_console_print_early (VirtIODevice *vdev,uint8_t *buf); +#endif
Signature · 1 line
1.6.0.2
PATCH 8/9 Set default console to virtio on S390x
All "normal" system emulation targets in qemu I'm aware of display output on either VGA or serial output.
Our S390x virtio machine doesn't have such kind of legacy hardware. So instead we need to default to a virtio console.
I'm not particularly proud of this patch. It would be a lot better to have something in the machine description that tells us about the default terminal.
--- vl.c | 26 ++++++++++++++++++++++++++ 1 files changed, 26 insertions(+), 0 deletions(-)
vl.c +26 -0
@@ -4818,6 +4818,20 @@ int main(int argc, char **argv, char **envp) cyls = heads = secs =0 ; translation =BIOS_ATA_TRANSLATION_AUTO ; +#ifdef TARGET_S390X +for (i =0 ; i <MAX_SERIAL_PORTS ; i++) + serial_devices[i] =NULL ; + serial_device_index =0 ; + +for (i =0 ; i <MAX_PARALLEL_PORTS ; i++) + parallel_devices[i] =NULL ; + parallel_device_index =0 ; + + virtio_consoles[0 ] ="mon:stdio" ; +for (i =1 ; i <MAX_VIRTIO_CONSOLES ; i++) + virtio_consoles[i] =NULL ; + virtio_console_index =0 ; +#else serial_devices[0 ] ="vc:80Cx24C" ;for (i =1 ; i <MAX_SERIAL_PORTS ; i++) serial_devices[i] =NULL ;
@@ -4831,6 +4845,7 @@ int main(int argc, char **argv, char **envp)for (i =0 ; i <MAX_VIRTIO_CONSOLES ; i++) virtio_consoles[i] =NULL ; virtio_console_index =0 ; +#endif monitor_devices[0 ] ="vc:80Cx24C" ;for (i =1 ; i <MAX_MONITOR_DEVICES ; i++) {
@@ -5709,6 +5724,17 @@ int main(int argc, char **argv, char **envp)break ; } } +for (i =0 ; i <MAX_VIRTIO_CONSOLES ; i++) { +const char *devname = virtio_consoles[i]; +if (devname && !strcmp (devname,"mon:stdio" )) { + monitor_devices[0 ] =NULL ; +break ; + }else if (devname && !strcmp (devname,"stdio" )) { + monitor_devices[0 ] =NULL ; + virtio_consoles[i] ="mon:stdio" ; +break ; + } + } }if (nb_numa_nodes >0 ) {
Signature · 1 line
1.6.0.2
PATCH 9/9 Move mp_state to CPU_COMMON
MP State is implemented in the generic code, so let's move the variable it accesses to generic code as well.
Still unbreaks PPC and now even S390x w/ KVM.
--- cpu-defs.h | 1 + target-i386/cpu.h | 1 - 2 files changed, 1 insertions(+), 1 deletions(-)
cpu-defs.h +1 -0
@@ -197,6 +197,7 @@ typedef struct CPUWatchpoint {const char *cpu_model_str; \struct KVMState *kvm_state; \struct kvm_run *kvm_run; \ +uint32_t mp_state; \int kvm_fd;#endif
target-i386/cpu.h +0 -1
@@ -692,7 +692,6 @@ typedef struct CPUX86State {/* For KVM */ uint64_t interrupt_bitmap[256 /64 ]; -uint32_t mp_state;/* in order to simplify APIC support, we leave this pointer to the user */
Signature · 1 line
1.6.0.2
Re: [Qemu-devel] [PATCH 8/9] Set default console to virtio on S390x
In reply to Alexander GrafQuoted 9 lines · Alexander Graf
All "normal" system emulation targets in qemu I'm aware of display output on either VGA or serial output.
Our S390x virtio machine doesn't have such kind of legacy hardware. So instead we need to default to a virtio console.
I'm not particularly proud of this patch. It would be a lot better to have something in the machine description that tells us about the default terminal.
One more reason to move the default devices qemu creates to a (machine specific) config file ...
cheers,
Gerd
Re: [Qemu-devel] [PATCH 4/9] Add S390x virtio machine bus
In reply to Alexander Grafhw/s390-virtio-bus.c line 65
Quoted 5 lines
hw/s390-virtio-bus.c new file +5
-0+VirtIOS390Bus *s390_virtio_bus_init (ram_addr_t *ram_size) +{ +VirtIOS390Bus *bus; + + bus = (VirtIOS390Bus *)qbus_create (&s390_virtio_bus_info,NULL ,"s390-virtio" );
While a cast works the political correct way to do this is using DO_UPCAST.
Also I'd suggest to add a sysbus -> s390-virtio bus bridge device, so your bus gets properly hooked up in the device tree. Have a look at the (quite simple) "isabus-bridge" device in isa-bus.c, which is used with 'qemu -M isapc'. You'll see the s390-virtio bus and all virtio devices attached to it in 'info qtree' then.
Quoted 1 line
+ bus = (VirtIOS390Bus *)dev->qdev.parent_bus;
DO_UPCAST().
hw/s390-virtio-bus.c line 243
Quoted 4 lines
hw/s390-virtio-bus.c new file +4
-0+VirtIOS390Device *s390_virtio_bus_console (VirtIOS390Bus *bus) +{ +return bus->console; +}
What this is needed for?
cheers,
Gerd
Re: [Qemu-devel] [PATCH 4/9] Add S390x virtio machine bus
Quoted 8 lines · Gerd Hoffmann
Quoted 6 lines
hw/s390-virtio-bus.c new file +5
-0+VirtIOS390Bus *s390_virtio_bus_init (ram_addr_t *ram_size) +{ +VirtIOS390Bus *bus; + + bus = (VirtIOS390Bus *)qbus_create(&s390_virtio_bus_info,NULL, "s390-virtio");
While a cast works the political correct way to do this is using
DO_UPCAST.
Oh - that one's new to me :-)
Quoted 1 line
Also I'd suggest to add a sysbus -> s390-virtio bus bridge device, so your bus gets properly hooked up in the device tree. Have a look at the (quite simple) "isabus-bridge" device in
isa-bus.c, which is used with 'qemu -M isapc'. You'll see the s390-virtio bus and all virtio devices attached to it in 'info qtree' then.
Uh, ok :o. Is that really important?
Quoted 10 lines
Quoted 1 line
+ bus = (VirtIOS390Bus *)dev->qdev.parent_bus;
DO_UPCAST().hw/s390-virtio-bus.c line 243
Quoted 4 lines
hw/s390-virtio-bus.c new file +4
-0+VirtIOS390Device *s390_virtio_bus_console (VirtIOS390Bus *bus) +{ +return bus->console; +}What this is needed for?
We need to know the console to do early printk. I figured it'd be better to have a function returning it, so we could possibly change semantics later.
Alex
Re: [Qemu-devel] [PATCH 4/9] Add S390x virtio machine bus
Hi,
Quoted 7 lines
Quoted 5 lines
Also I'd suggest to add a sysbus -> s390-virtio bus bridge device, so your bus gets properly hooked up in the device tree. Have a look at the (quite simple) "isabus-bridge" device in
isa-bus.c, which is used with 'qemu -M isapc'. You'll see the s390-virtio bus and all virtio devices attached to it in 'info qtree' then.Uh, ok :o. Is that really important?
Quite a few things depend on it. I think creating disks via '-device virtio-blk-s390' will not work without that ...
cheers,
Gerd
[Qemu-devel] Re: [PATCH 2/9] Add KVM support for S390x
In reply to Alexander GrafQuoted 1 line · Alexander Graf
++static int
s390_cpu_initial_reset(CPUState *env)
+{
+ /* XXX */ + fprintf(stderr, "XXX SIGP init\n"); + return -1;
+}
That one will really break SMP. Most of the initial reset is handled in-kernel for your convenience, therefore please think about using Kuli as inspiration on how to do this one ;-). Other then that, the s390 specifics in this patch look really nice.
[Qemu-devel] Re: [PATCH 2/9] Add KVM support for S390x
Quoted 8 lines · Carsten Otte
Quoted 1 line · Alexander Graf
++static int
s390_cpu_initial_reset(CPUState *env)target-s390x/kvm.c new file +5
-0+{ +/* XXX */ +fprintf (stderr,"XXX SIGP init\n" ); +return -1 ; +}That one will really break SMP. Most of the initial reset is handled in-kernel for your convenience, therefore please think about using Kuli as inspiration on how to do this one ;-).
Yes, SMP support is missing still. I ran into some problem implementing it.
Qemu by default doesn't allow -smp > 1 anyways, so I figured it's not too much of a problem for starters.
Quoted 1 line
Other then that, the s390 specifics in this patch look really nice.
Thanks :-)
Alex
[Qemu-devel] Re: [PATCH 1/9] Export function for VA defined ram allocation
In reply to Alexander GrafQuoted 3 lines · Alexander Graf
S390 requires vmas for guests to be < 256 GB. So we need to directly export mmaps "try to use this vma as start address" feature to not accidently get over that limit.
Hmmh, now that x86 has solved all the problems we should probably move away from using the same page table for userspace and guest too. That would make this "workaround" superfluous and memslots would work just the same on s390 as they do on x86. I've put it on my todo list. For now, this looks good to me.
Hi,
Quoted 1 line
So now you can run Linux VMs on Linux on z/VM on LPAR on zSeries!
Cool. Don't have a zSeries though ...
Quoted 3 lines
The patchset is based on Uli's S390x userspace emulation patches. There's not really that much shared functionality, but I didn't want to reimplement the configure wheels. So make sure to have his patches applied first.
Hmm. How hard would it be to wind up the cpu emulation bits so I can run s390x virtual machines on my x86 box?
cheers,
Gerd
Quoted 5 lines · Gerd Hoffmann
Hi,
Quoted 1 line
So now you can run Linux VMs on Linux on z/VM on LPAR on zSeries!
Cool. Don't have a zSeries though ...
I always thought that's commodity hardware .. oh well :-)
Quoted 5 lines
Quoted 3 lines
The patchset is based on Uli's S390x userspace emulation patches. There's not really that much shared functionality, but I didn't want to reimplement the configure wheels. So make sure to have his patches applied first.
Hmm. How hard would it be to wind up the cpu emulation bits so I can run s390x virtual machines on my x86 box?
It's feasible, but currently not implemented. I also don't know enough of the s390x internals to do it as is :-). On S390 the hardware and OS handle most of the virtualization parts themselves.
Uli, any comments on this?
Either way - let's focus on getting it working with KVM first!
Alex
Quoted 8 lines · Alexander Graf
While S390x was one of the first targets that were supported by KVM it always lacked qemu system emulation support.
In order to change that sad fact, I figured I'd just take on the task myself, taking kuli (http://www.ibm.com/developerworks/linux/linux390/kuli.html),
Documentation/s390/kvm.txtand lguest as starting points to write a clean, qemu'ish S390x Virtio machine emulation.
Quoted 5 lines
So now you can run Linux VMs on Linux on z/VM on LPAR on zSeries!
This is the resulting code. Please comment on things you like and also on the ones you don't :-).
Didn't find anything to dislike. It all looks good!
Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this signature is too narrow to contain.
Quoted 2 lines · Alexander Graf
This is the resulting code. Please comment on things you like and also on the ones you don't :-).
I've reviewed and tested it, great work Alex :-)
Quoted 2 lines
Also to actually run this code you need a patch for an ugly bug in the kernel
module: http://alex.csgraf.de/psw.patch
Well, it was not exactly a bug. Kuli does'nt need the psw to be updated in kvm_run at all times. Your hotfix updates the psw in a union, even if the exit reason indicates that s390_sieic is not valid. The patch at the end of this mail moves the PSW out of the union. I think it makes most sense if Avi picks this patch and you adopt your series to it. This way the user interface of the kvm module works for both kuli and qemu.
This patch moves s390 processor status word into the base kvm_run struct and keeps it up-to date on all userspace exits.
---arch/s390/kvm/kvm-s390.c | 14 ++++++++------include/linux/kvm.h | 8 ++++++--
2 files changed, 14 insertions(+), 8 deletions(-)
include/linux/kvm.h +1 -0
@@ -7,6 +7,7 @@* Note: you must update KVM_API_VERSION if you change this interface. */ +#include <linux/autoconf.h>
#include <linux/types.h>
#include <linux/compiler.h>
#include <linux/ioctl.h>
@@ -116,6 +117,11 @@
__u64 cr8; __u64 apic_base;
+#ifdef CONFIG_S390
+ /* the processor status word for s390 */
+ __u64 psw_mask; /* psw upper half */
+ __u64 psw_addr; /* psw lower half */
+#endif
union {
/* KVM_EXIT_UNKNOWN */
struct {
@@ -167,8 +173,6 @@
/* KVM_EXIT_S390_SIEIC */
struct {
__u8 icptcode;
- __u64 mask; /* psw upper half */
- __u64 addr; /* psw lower half */
__u16 ipa;
__u32 ipb;
} s390_sieic;arch/s390/kvm/kvm-s390.c +0 -0
@@ -421,7 +421,8 @@
if (atomic_read(&vcpu->arch.sie_block->cpuflags) & CPUSTAT_RUNNING) rc = -EBUSY; else - vcpu->arch.sie_block->gpsw = psw; + vcpu->run->psw_mask = psw.mask; + vcpu->run->psw_addr = psw.addr; vcpu_put(vcpu); return rc; }
@@ -509,9 +510,6 @@
switch (kvm_run->exit_reason) {
case KVM_EXIT_S390_SIEIC:
- vcpu->arch.sie_block->gpsw.mask = kvm_run->s390_sieic.mask;
- vcpu->arch.sie_block->gpsw.addr = kvm_run->s390_sieic.addr;
- break;
case KVM_EXIT_UNKNOWN:
case KVM_EXIT_INTR:
case KVM_EXIT_S390_RESET:
@@ -520,6 +518,9 @@
BUG();
}+ vcpu->arch.sie_block->gpsw.mask = kvm_run->psw_mask;
+ vcpu->arch.sie_block->gpsw.addr = kvm_run->psw_addr;
+
might_fault();
do {
@@ -539,8 +540,6 @@
/* intercept cannot be handled in-kernel, prepare kvm-run */
kvm_run->exit_reason = KVM_EXIT_S390_SIEIC;
kvm_run->s390_sieic.icptcode = vcpu->arch.sie_block->icptcode;
- kvm_run->s390_sieic.mask = vcpu->arch.sie_block->gpsw.mask;
- kvm_run->s390_sieic.addr = vcpu->arch.sie_block->gpsw.addr;
kvm_run->s390_sieic.ipa = vcpu->arch.sie_block->ipa;
kvm_run->s390_sieic.ipb = vcpu->arch.sie_block->ipb;
rc = 0;
@@ -552,6 +551,9 @@
rc = 0;
}+ kvm_run->psw_mask = vcpu->arch.sie_block->gpsw.mask;
+ kvm_run->psw_addr = vcpu->arch.sie_block->gpsw.addr;
+
if (vcpu->sigset_active) sigprocmask(SIG_SETMASK, &sigsaved, NULL);
Quoted 4 lines · Carsten Otte
Quoted 2 lines · Alexander Graf
This is the resulting code. Please comment on things you like and also on the ones you don't :-).
I've reviewed and tested it, great work Alex :-)
Thanks :-).
Quoted 3 lines
Quoted 2 lines
Also to actually run this code you need a patch for an ugly bug in the kernel
module: http://alex.csgraf.de/psw.patchWell, it was not exactly a bug. Kuli does'nt need the psw to be updated in
kvm_runat all times. Your hotfix updates the psw in a union, even if the exit reason indicates thats390_sieicis not valid. The patch at the end of this mail moves the PSW out of the union. I think it makes most sense if Avi picks this patch and you adopt your series to it. This way the user interface of the kvm module works for both kuli and qemu.
Alright, expect v2 today!
On a sidenode, please post the patch to kvm-devel too, so Marcelo has the chance to pick it up.
Quoted 65 lines
This patch moves s390 processor status word into the base
kvm_runstruct and keeps it up-to date on all userspace exits.Signed-off-by Carsten Otte <[email protected]>---
arch/s390/kvm/kvm-s390.c| 14 ++++++++------include/linux/kvm.h| 8 ++++++--2 files changed, 14 insertions(+), 8 deletions(-)Index:
kvm/include/linux/kvm.h
===================================================================include/linux/kvm.h +6
-2@@ -7,6 +7,7 @@* Note: you must update KVM_API_VERSION if you change this interface. */ +#include <linux/autoconf.h> #include <linux/types.h> #include <linux/compiler.h> #include <linux/ioctl.h> @@ -116,6 +117,11 @@__u64 cr8;__u64 apic_base; +#ifdef CONFIG_S390 +/* the processor status word for s390 */ +__u64 psw_mask;/* psw upper half */ +__u64 psw_addr;/* psw lower half */ +#endif union { /* KVM_EXIT_UNKNOWN */ struct {@@ -167,8 +173,6 @@/* KVM_EXIT_S390_SIEIC */ struct {__u8 icptcode; -__u64 mask;/* psw upper half */ -__u64 addr;/* psw lower half */ __u16 ipa;__u32 ipb; } s390_sieic;Index:
kvm/arch/s390/kvm/kvm-s390.c
===================================================================
---kvm.orig/arch/s390/kvm/kvm-s390.c2009-10-20 15:01:02.000000000
+0200
+++kvm/arch/s390/kvm/kvm-s390.c2009-10-20 18:13:45.000000000 +0200include/linux/kvm.h +2
-4@@ -421,7 +421,8 @@if (atomic_read (&vcpu->arch.sie_block->cpuflags) &CPUSTAT_RUNNING ) rc = -EBUSY ;else - vcpu->arch.sie_block->gpsw = psw; + vcpu->run->psw_mask = psw.mask; + vcpu->run->psw_addr = psw.addr;vcpu_put (vcpu);return rc; }@@ -509,9 +510,6 @@switch (kvm_run->exit_reason) {case KVM_EXIT_S390_SIEIC : - vcpu->arch.sie_block->gpsw.mask = kvm_run->s390_sieic.mask; - vcpu->arch.sie_block->gpsw.addr = kvm_run->s390_sieic.addr; -break ;case KVM_EXIT_UNKNOWN :case KVM_EXIT_INTR :case KVM_EXIT_S390_RESET :
include/linux/kvm.h line 519
Quoted 2 lines
include/linux/kvm.h +0
-0@@ -520,6 +518,9 @@BUG (); }
Why leave the switch? Do you want the BUG() that badly?
Most of the time that's just wasted cycles, right?
Quoted 15 lines
include/linux/kvm.h +3
-2+ vcpu->arch.sie_block->gpsw.mask = kvm_run->psw_mask; + vcpu->arch.sie_block->gpsw.addr = kvm_run->psw_addr; +might_fault (); do {@@ -539,8 +540,6 @@/* intercept cannot be handled in-kernel, prepare kvm-run */ kvm_run->exit_reason =KVM_EXIT_S390_SIEIC ; kvm_run->s390_sieic.icptcode = vcpu->arch.sie_block->icptcode; - kvm_run->s390_sieic.mask = vcpu->arch.sie_block->gpsw.mask; - kvm_run->s390_sieic.addr = vcpu->arch.sie_block->gpsw.addr; kvm_run->s390_sieic.ipa = vcpu->arch.sie_block->ipa; kvm_run->s390_sieic.ipb = vcpu->arch.sie_block->ipb; rc =0 ;
include/linux/kvm.h line 555
Quoted 5 lines
include/linux/kvm.h +3
-0@@ -552,6 +551,9 @@ rc =0 ; } + kvm_run->psw_mask = vcpu->arch.sie_block->gpsw.mask; + kvm_run->psw_addr = vcpu->arch.sie_block->gpsw.addr; +
I think you should not indent the equal signs here. They're not aligned to the ones above anymore anyways.
Apart from that, great patch!
I'll put all the pieces together today, so expect to be running Qemu backed virtualization on your mainframe :-).
Alex
Quoted 36 lines · Carsten Otte
Quoted 2 lines · Alexander Graf
This is the resulting code. Please comment on things you like and also on the ones you don't :-).
I've reviewed and tested it, great work Alex :-)
Quoted 2 lines
Also to actually run this code you need a patch for an ugly bug in the kernel
module: http://alex.csgraf.de/psw.patchWell, it was not exactly a bug. Kuli does'nt need the psw to be updated in
kvm_runat all times. Your hotfix updates the psw in a union, even if the exit reason indicates thats390_sieicis not valid. The patch at the end of this mail moves the PSW out of the union. I think it makes most sense if Avi picks this patch and you adopt your series to it. This way the user interface of the kvm module works for both kuli and qemu.This patch moves s390 processor status word into the base
kvm_runstruct and keeps it up-to date on all userspace exits.Signed-off-by Carsten Otte <[email protected]>---
arch/s390/kvm/kvm-s390.c| 14 ++++++++------include/linux/kvm.h| 8 ++++++--2 files changed, 14 insertions(+), 8 deletions(-)Index:
kvm/include/linux/kvm.h
===================================================================include/linux/kvm.h +1
-0@@ -7,6 +7,7 @@* Note: you must update KVM_API_VERSION if you change this interface. */ +#include <linux/autoconf.h> #include <linux/types.h> #include <linux/compiler.h> #include <linux/ioctl.h>
include/linux/kvm.h line 123
Quoted 7 lines
include/linux/kvm.h +5
-0@@ -116,6 +117,11 @@__u64 cr8;__u64 apic_base; +#ifdef CONFIG_S390 +/* the processor status word for s390 */ +__u64 psw_mask;/* psw upper half */ +__u64 psw_addr;/* psw lower half */ +#endif
While at it, I think we should either go all or nothing here.
Either we take the psw in on x86 too or we #ifdef out the x86 specific stuff on s390.
Alex
Quoted 1 line · Alexander Graf
Either we take the psw in on x86 too or we #ifdef out the x86 specific stuff on s390.
Good idea, I'll #ifndef CONFIG_S390 the x86 specifics while we're at it.
Quoted 3 lines · Carsten Otte
Quoted 1 line · Alexander Graf
Either we take the psw in on x86 too or we #ifdef out the x86 specific stuff on s390.
Good idea, I'll #ifndef
CONFIG_S390the x86 specifics while we're at it.
Maybe better #if defined(TARGET_X86) || defined(TARGET_IA64). We don't really need them for ppc either :-).
Alex
Quoted 61 lines · Carsten Otte
Quoted 2 lines · Alexander Graf
This is the resulting code. Please comment on things you like and also on the ones you don't :-).
I've reviewed and tested it, great work Alex :-)
Quoted 2 lines
Also to actually run this code you need a patch for an ugly bug in the kernel
module: http://alex.csgraf.de/psw.patchWell, it was not exactly a bug. Kuli does'nt need the psw to be updated in
kvm_runat all times. Your hotfix updates the psw in a union, even if the exit reason indicates thats390_sieicis not valid. The patch at the end of this mail moves the PSW out of the union. I think it makes most sense if Avi picks this patch and you adopt your series to it. This way the user interface of the kvm module works for both kuli and qemu.This patch moves s390 processor status word into the base
kvm_runstruct and keeps it up-to date on all userspace exits.Signed-off-by Carsten Otte <[email protected]>---
arch/s390/kvm/kvm-s390.c| 14 ++++++++------include/linux/kvm.h| 8 ++++++--2 files changed, 14 insertions(+), 8 deletions(-)Index:
kvm/include/linux/kvm.h
===================================================================include/linux/kvm.h +6
-2@@ -7,6 +7,7 @@* Note: you must update KVM_API_VERSION if you change this interface. */ +#include <linux/autoconf.h> #include <linux/types.h> #include <linux/compiler.h> #include <linux/ioctl.h> @@ -116,6 +117,11 @@__u64 cr8;__u64 apic_base; +#ifdef CONFIG_S390 +/* the processor status word for s390 */ +__u64 psw_mask;/* psw upper half */ +__u64 psw_addr;/* psw lower half */ +#endif union { /* KVM_EXIT_UNKNOWN */ struct {@@ -167,8 +173,6 @@/* KVM_EXIT_S390_SIEIC */ struct {__u8 icptcode; -__u64 mask;/* psw upper half */ -__u64 addr;/* psw lower half */ __u16 ipa;__u32 ipb; } s390_sieic;Index:
kvm/arch/s390/kvm/kvm-s390.c
===================================================================
---kvm.orig/arch/s390/kvm/kvm-s390.c2009-10-20 15:01:02.000000000
+0200
+++kvm/arch/s390/kvm/kvm-s390.c2009-10-20 18:13:45.000000000 +0200
include/linux/kvm.h line 425
Quoted 6 lines
include/linux/kvm.h +2
-1@@ -421,7 +421,8 @@if (atomic_read (&vcpu->arch.sie_block->cpuflags) &CPUSTAT_RUNNING ) rc = -EBUSY ;else - vcpu->arch.sie_block->gpsw = psw; + vcpu->run->psw_mask = psw.mask; + vcpu->run->psw_addr = psw.addr;
Missing braces.
Alex
Quoted 8 lines · Carsten Otte
This patch moves s390 processor status word into the base
kvm_runstruct and keeps it up-to date on all userspace exits.+#include <
linux/autoconf.h>
#include <linux/types.h>
#include <linux/compiler.h>
#include <linux/ioctl.h>
Not needed.
Review line 124
Quoted 9 lines
(quoted diff) +5
-0@@ -116,6 +117,11 @@ __u64 cr8; __u64 apic_base; +#ifdef CONFIG_S390 + /* the processor status word for s390 */ + __u64 psw_mask; /* psw upper half */ + __u64 psw_addr; /* psw lower half */ +#endif
Doesn't this break backward compatibility by changing the structure?
Best to put it after the union (and as a copy, so userspace that expects the previous location still works). If you're reading it from the kernel, also need a way to tell the kernel which copy to read from.
Also advertise with a KVM_CAP.
Additionally, CONFIG_ in public headers are frowned upon as non-portable. A workaround is to #define __KVM_S390 in <asm/kvm.h> and depend on that.
Review line 425
Quoted 10 lines
(quoted diff) +4
-2--- kvm.orig/arch/s390/kvm/kvm-s390.c 2009-10-20 15:01:02.000000000 +0200 +++ kvm/arch/s390/kvm/kvm-s390.c 2009-10-20 18:13:45.000000000 +0200@@ -421,7 +421,8 @@ if (atomic_read(&vcpu->arch.sie_block->cpuflags) & CPUSTAT_RUNNING) rc = -EBUSY; else - vcpu->arch.sie_block->gpsw = psw; + vcpu->run->psw_mask = psw.mask; + vcpu->run->psw_addr = psw.addr;
It's traditional to add braces around multi-line else blocks.
I'd also appreciate an explanation of what this is all about.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 24 lines · Avi Kivity
Quoted 8 lines · Carsten Otte
This patch moves s390 processor status word into the base
kvm_runstruct and keeps it up-to date on all userspace exits.+#include <
linux/autoconf.h>
#include <linux/types.h>
#include <linux/compiler.h>
#include <linux/ioctl.h>Not needed.
Review line 124
Quoted 9 lines
(quoted diff) +5
-0@@ -116,6 +117,11 @@ __u64 cr8; __u64 apic_base; +#ifdef CONFIG_S390 + /* the processor status word for s390 */ + __u64 psw_mask; /* psw upper half */ + __u64 psw_addr; /* psw lower half */ +#endifDoesn't this break backward compatibility by changing the structure?
Quoted 3 lines
Best to put it after the union (and as a copy, so userspace that expects the previous location still works). If you're reading it from the kernel, also need a way to tell the kernel which copy to read from.
Also advertise with a
KVM_CAP.
I don't think we need to go through the hassle here. There is effectively no user of that code for now and the ABI is considered unstable.
Quoted 17 lines
Additionally,
CONFIG_in public headers are frowned upon as non-portable. A workaround is to #define__KVM_S390in <asm/kvm.h> and depend on that.Review line 426
Quoted 12 lines
(quoted diff) +0
-1--- kvm.orig/arch/s390/kvm/kvm-s390.c 2009-10-2015:01:02.000000000 +0200
+++kvm/arch/s390/kvm/kvm-s390.c2009-10-20 18:13:45.000000000
+0200(quoted diff) +2
-1@@ -421,7 +421,8 @@ if (atomic_read(&vcpu->arch.sie_block->cpuflags) & CPUSTAT_RUNNING) rc = -EBUSY; else - vcpu->arch.sie_block->gpsw = psw; + vcpu->run->psw_mask = psw.mask; + vcpu->run->psw_addr = psw.addr;It's traditional to add braces around multi-line else blocks.
Quoted 1 line
I'd also appreciate an explanation of what this is all about.
Explanation in the code or explanation in an email reply?
Alex
Quoted 8 lines · Alexander Graf
Quoted 5 lines
Doesn't this break backward compatibility by changing the structure?
Best to put it after the union (and as a copy, so userspace that expects the previous location still works). If you're reading it from the kernel, also need a way to tell the kernel which copy to read from.
Also advertise with a
KVM_CAP.I don't think we need to go through the hassle here. There is effectively no user of that code for now and the ABI is considered unstable.
At the very least we need a KVM_CAP so qemu knows to fail on older kernels.
Quoted 4 lines
Quoted 2 lines
I'd also appreciate an explanation of what this is all about.
Explanation in the code or explanation in an email reply?
email. I assume s390 hackers would understand why the psw needs to be exposed to qemu on every exit. This is mostly for my personal interest.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 11 lines · Avi Kivity
Quoted 8 lines · Alexander Graf
Quoted 5 lines
Doesn't this break backward compatibility by changing the structure?
Best to put it after the union (and as a copy, so userspace that expects the previous location still works). If you're reading it from the kernel, also need a way to tell the kernel which copy to read from.
Also advertise with a
KVM_CAP.I don't think we need to go through the hassle here. There is effectively no user of that code for now and the ABI is considered unstable.
At the very least we need a
KVM_CAPso qemu knows to fail on older kernels.
Hm. Oh well :-). It can't hurt to have yet another CAP, right?
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
I'd also appreciate an explanation of what this is all about.
Explanation in the code or explanation in an email reply?
email. I assume s390 hackers would understand why the psw needs to be exposed to qemu on every exit. This is mostly for my personal interest.
PSW = (eflags << 32) | pc;
:-)
Before that patch it was only synced with the "vmcb" on special userspace handled intercepts, now it's synced on every exit to userspace.
Alex
Quoted 1 line · Alexander Graf
PSW = (eflags << 32) | pc;
Eh - 64 of course. The PSW is 128 bits.
Alex
Quoted 22 lines · Alexander Graf
Quoted 11 lines · Avi Kivity
Quoted 8 lines · Alexander Graf
Quoted 5 lines
Doesn't this break backward compatibility by changing the structure?
Best to put it after the union (and as a copy, so userspace that expects the previous location still works). If you're reading it from the kernel, also need a way to tell the kernel which copy to read from.
Also advertise with a
KVM_CAP.I don't think we need to go through the hassle here. There is effectively no user of that code for now and the ABI is considered unstable.
At the very least we need a
KVM_CAPso qemu knows to fail on older kernels.Hm. Oh well :-). It can't hurt to have yet another CAP, right?
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
I'd also appreciate an explanation of what this is all about.
Explanation in the code or explanation in an email reply?
Quoted 7 lines
Quoted 1 line
email. I assume s390 hackers would understand why the psw needs to be exposed to qemu on every exit. This is mostly for my personal interest.
PSW = (eflags << 32) | pc;
:-)
Before that patch it was only synced with the "vmcb" on special userspace handled intercepts, now it's synced on every exit to userspace.
Right, but why? x86 qemu doesn't care about either pc or eflags (with in-kernel irqchip, which s390 essentially is).
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 25 lines · Avi Kivity
Quoted 24 lines · Alexander Graf
Quoted 11 lines · Avi Kivity
Quoted 8 lines · Alexander Graf
Quoted 5 lines
Doesn't this break backward compatibility by changing the structure?
Best to put it after the union (and as a copy, so userspace that expects the previous location still works). If you're reading it from the kernel, also need a way to tell the kernel which copy to read from.
Also advertise with a
KVM_CAP.I don't think we need to go through the hassle here. There is effectively no user of that code for now and the ABI is considered unstable.
At the very least we need a
KVM_CAPso qemu knows to fail on older kernels.Hm. Oh well :-). It can't hurt to have yet another CAP, right?
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
I'd also appreciate an explanation of what this is all about.
Explanation in the code or explanation in an email reply?
email. I assume s390 hackers would understand why the psw needs to be exposed to qemu on every exit. This is mostly for my personal interest.
Quoted 7 lines
Quoted 5 lines
PSW = (eflags << 32) | pc;
:-)
Before that patch it was only synced with the "vmcb" on special userspace handled intercepts, now it's synced on every exit to userspace.
Right, but why? x86 qemu doesn't care about either pc or eflags (with in-kernel irqchip, which s390 essentially is).
The old code would only sync the psw for us on "intercepts that the kernel knows require userspace interaction". We'd "x /i $pc" somewhere along the way and would get an old psw, but GET_REGS would give us recent register states, not including the psw. That's a total nightmare.
To solve the psw nightmare there were basically 2 roads possible to take here:
1) Sync the PSW in the GET_REGS ioctl
2) Sync the PSW in kvm_run on all exits to userspace
Otherwise we can't debug guests.
The same goes for setting the PSW. Setting the PSW was only implemented when kvm_run->exit_reason == "the kernel thinks userspace needs to do something". So If you wanted to change the pc along the way, you couldn't.
Furthermore, there was a nasty bug in this whole optimization that lead me to think it's better to just get rid of the whole "kernel tries to be clever" implementation and just sync the psw at all times. Most exits to userspace are of the "userspace needs to do something" type anyways, so we're not really losing anything here. Implementing 2) was just really easy.
So I guess Carsten thought the same way and improved my original patch.
I hope that clarifies things.
Alex
Quoted 1 line · Avi Kivity
Right, but why? x86 qemu doesn't care about either pc or eflags (with in-kernel irqchip, which s390 essentially is).
For different reasons. Most prominent for setting the condition code, which is a sideband result of most instructions that indicates whether or not the instruction actually worked - similar to the exception model in high level programming languages.
Quoted 6 lines · Carsten Otte
Quoted 1 line · Avi Kivity
Right, but why? x86 qemu doesn't care about either pc or eflags (with in-kernel irqchip, which s390 essentially is).
For different reasons. Most prominent for setting the condition code, which is a sideband result of most instructions that indicates whether or not the instruction actually worked - similar to the exception model in high level programming languages.
Ok. Thanks for the explanation.
On x86 we avoid emulating instructions in userspace. Instead the kernel requests userspace to do something (triggered by the instruction), and the kernel does anything which might be implied by the instruction (like copying the result into a register, or updating pc).
An example is port I/O. instead of userspace reading %edx to query the port number and setting %eax to indicate the result, userspace reads a port number struct field and writes an I/O result struct field. Only the kernel accesses registers.
I don't know whether that model makes sense or not for s390, but please consider it.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 5 lines · Avi Kivity
On x86 we avoid emulating instructions in userspace. Instead the kernel requests userspace to do something (triggered by the instruction), and the kernel does anything which might be implied by the instruction (like copying the result into a register, or updating pc).
An example is port I/O. instead of userspace reading %edx to query the port number and setting %eax to indicate the result, userspace reads a port number struct field and writes an I/O result struct field. Only the kernel accesses registers.
I don't know whether that model makes sense or not for s390, but please consider it.
We do the same for many instructions (arch/s390/kvm/instruction.c). User exits
are only performed for isntructions that cannot be handled in kernel. Also, we do exit with requests to userspace, see the s390_reset exit reason. I think in this regard, our implementation is very similar to x86. Btw: this is something I did copycat from your implementation on integration into kvm. The original zlive code did handle all instructions in userland.
Quoted 8 lines · Carsten Otte
Quoted 5 lines · Avi Kivity
On x86 we avoid emulating instructions in userspace. Instead the kernel requests userspace to do something (triggered by the instruction), and the kernel does anything which might be implied by the instruction (like copying the result into a register, or updating pc).
An example is port I/O. instead of userspace reading %edx to query the port number and setting %eax to indicate the result, userspace reads a port number struct field and writes an I/O result struct field. Only the kernel accesses registers.
I don't know whether that model makes sense or not for s390, but please consider it.
We do the same for many instructions (
arch/s390/kvm/instruction.c). User exits
are only performed for isntructions that cannot be handled in kernel. Also, we do exit with requests to userspace, see thes390_resetexit reason. I think in this regard, our implementation is very similar to x86. Btw: this is something I did copycat from your implementation on integration into kvm. The original zlive code did handle all instructions in userland.
So why not do it for this instruction as well? Instead of updating the psw, return a success/error code and let the kernel update psw.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 1 line · Avi Kivity
So why not do it for this instruction as well? Instead of updating the psw, return a success/error code and let the kernel update psw.
It's not a single instruction, but a set of reasons we need the psw in userspace:
- for logging the instruction address on exits
- to check if a wait-type psw is active, and if so to switch between:
- enabled wait psws, where interrupts could wake the cpu (aka /halt, which needs to be handled in-kernel)
- disabled wait psws, where CPUs are suspended due to cpu hotremove, system dump on panic
- to handle cpus in stopped state, typically on regular reboots/shutdowns
- for setting the condition code during implementation of:
- all s/390 I/O instructions
- IPI for restarting remote CPUs (that are not in KVM_RUN)
- IPI for storing remote CPU status into the remote cpu's lowcore page
- IPI for resetting remote CPUs
- for all IPIs where the remote CPU is not known to the kernel, such as the detection loop for all 65535 cpu slots on startup of the guest kernel
- for interpretion of service calls (usually to the machine's service processor)
- virtio I/O
The sweet thing about having the psw in userspace is that for almost all above reasons, there's nothing more than the psw that we need to have in order to perform that operation. Giving the 128-bit psw to userspace does simply save us having special cases for above list, with an exit_reason and a struct for each of them.
Quoted 26 lines · Carsten Otte
Quoted 2 lines · Avi Kivity
So why not do it for this instruction as well? Instead of updating the psw, return a success/error code and let the kernel update psw.
It's not a single instruction, but a set of reasons we need the psw in userspace:
- for logging the instruction address on exits
- to check if a wait-type psw is active, and if so to switch between:
- enabled wait psws, where interrupts could wake the cpu (aka /halt, which needs to be handled in-kernel)
- disabled wait psws, where CPUs are suspended due to cpu hotremove, system dump on panic
- to handle cpus in stopped state, typically on regular reboots/shutdowns- for setting the condition code during implementation of:
- all s/390 I/O instructions
- IPI for restarting remote CPUs (that are not inKVM_RUN)
- IPI for storing remote CPU status into the remote cpu's lowcore page
- IPI for resetting remote CPUs
- for all IPIs where the remote CPU is not known to the kernel, such as the detection loop for all 65535 cpu slots on startup of the guest kernel
- for interpretion of service calls (usually to the machine's service processor)
- virtio I/O
Quoted 5 lines
The sweet thing about having the psw in userspace is that for almost all above reasons, there's nothing more than the psw that we need to have in order to perform that operation. Giving the 128-bit psw to userspace does simply save us having special cases for above list, with an
exit_reasonand a struct for each of them.
Any progress on the patch? This is really important to make KVM work properly on S390. I'd even go as far as suggesting it for linux-stable.
Alex
Quoted 4 lines · Alexander Graf
Any progress on the patch? This is really important to make KVM work properly on S390. I'd even go as far as suggesting it for linux-stable.
I forgot all about it, sorry. Marcelo, can you commit it?
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 11 lines · Avi Kivity
Review line 124
Quoted 9 lines
(quoted diff) +5
-0@@ -116,6 +117,11 @@ __u64 cr8; __u64 apic_base; +#ifdef CONFIG_S390 + /* the processor status word for s390 */ + __u64 psw_mask; /* psw upper half */ + __u64 psw_addr; /* psw lower half */ +#endifDoesn't this break backward compatibility by changing the structure?
Yes, but with a zero user base I think it's okay. I'd update our userspace. Once we pull CONFIG_EXPERIMENTAL we keep the API stable.
Quoted 1 line
Additionally,
CONFIG_in public headers are frowned upon as non-portable. A workaround is to #define__KVM_S390in <asm/kvm.h> and depend on that.
Yea, that's better.
Quoted 4 lines
Quoted 4 lines
(quoted diff) +2
-1--- kvm.orig/arch/s390/kvm/kvm-s390.c 2009-10-20 15:01:02.000000000 +0200 +++ kvm/arch/s390/kvm/kvm-s390.c 2009-10-20 18:13:45.000000000 +0200@@ -421,7 +421,8 @@
Quoted 8 lines
Review line 425
Quoted 6 lines
(quoted diff) +2
-1if (atomic_read(&vcpu->arch.sie_block->cpuflags) & CPUSTAT_RUNNING) rc = -EBUSY; else - vcpu->arch.sie_block->gpsw = psw; + vcpu->run->psw_mask = psw.mask; + vcpu->run->psw_addr = psw.addr;It's traditional to add braces around multi-line else blocks.
This is a plain bug, will fix.
Quoted 1 line
I'd also appreciate an explanation of what this is all about.
The processor status word does contain various bits about the CPU's state, such as interrupt mask bits, current address space, and the current instruction address. The status is kept in the in-kernel sie control block data structure and has so far only been mirrored into kvm_run during exit_reason == s390_sieic exits because user space needs to work on it. It was never part of get_regs/set_regs and friends as performance optimization: it's needed on almost every exit, having it in kvm_run saves doing syscalls. The gdb stub requires an up-to-date copy at every exit, and therefore the patch moves it out of the union and updates it at all userland exits.
Quoted 4 lines · Carsten Otte
Quoted 2 lines
I'd also appreciate an explanation of what this is all about.
The processor status word does contain various bits about the CPU's state, such as interrupt mask bits, current address space, and the current instruction address. The status is kept in the in-kernel sie control block data structure and has so far only been mirrored into
kvm_runduringexit_reason==s390_sieicexits because user space needs to work on it. It was never part of get_regs/set_regs and friends as performance optimization: it's needed on almost every exit, having it inkvm_runsaves doing syscalls. The gdb stub requires an up-to-date copy at every exit, and therefore the patch moves it out of the union and updates it at all userland exits.
gdb is hardly performance critical. Is that the only reason for the change?
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 1 line · Avi Kivity
gdb is hardly performance critical. Is that the only reason for the change?
Right, gdb is not performance critical. gdb is the reason for moving it out of the union, performance is the reason for having it in kvm_run at all.
There's only more reason to it: with a little tweaking in kuli, we'll be able to get rid of KVM_S390_SET_INITIAL_PSW ioctl with this change. That removes one oddity that makes us different from other platforms.
Quoted 4 lines · Carsten Otte
Quoted 1 line · Avi Kivity
gdb is hardly performance critical. Is that the only reason for the change?
Right, gdb is not performance critical. gdb is the reason for moving it out of the union, performance is the reason for having it in
kvm_runat all.
There's only more reason to it: with a little tweaking in kuli, we'll be able to get rid ofKVM_S390_SET_INITIAL_PSWioctl with this change. That removes one oddity that makes us different from other platforms.
In fact qemu/x86 does a KVM_SET_SREGS (which updates pc) on reset.
Signature · 1 line
error compiling committee.c: too many arguments to function