libkvm-s390
PATCH 1/1 libkvm-s390
This patch makes libkvm build and work on s390. It should be a noop for all other architectures.
---
libkvm/config-s390x.mak new file +6 -0
@@ -0,0 +1,6 @@ + +LIBDIR := /lib +CFLAGS += +CFLAGS += -D__s390x__ + +libkvm-$(ARCH)-objs := libkvm-s390x.o
libkvm/libkvm-s390x.c new file +98 -0
98 lines not on this page · raw message
Makefile +1 -1
@@ -5,7 +5,7 @@ DESTDIR= rpmrelease = devel -sane-arch = $(subst i386,x86,$(subst x86_64,x86,$(ARCH))) +sane-arch = $(subst i386,x86,$(subst x86_64,x86,$(subst s390x,s390,$(ARCH)))) .PHONY: kernel user libkvm qemu bios vgabios extboot clean libfdt
libkvm/kvm-common.h +7 -0
@@ -18,8 +18,15 @@/* FIXME: share this number with kvm */ /* FIXME: or dynamically alloc/realloc regions */ +#ifndef __s390x__#define KVM_MAX_NUM_MEM_REGIONS 8u +#define MAX_VCPUS 64 +#else +#define KVM_MAX_NUM_MEM_REGIONS 1u#define MAX_VCPUS 16 +#define LIBKVM_S390_ORIGIN (0UL) +#endif +/* kvm abi verison variable */ extern int kvm_abi;
libkvm/kvm-s390x.h new file +30 -0
@@ -0,0 +1,30 @@ +/* +* This header is for functions & variables that will ONLY be +* used inside libkvm for s390. +* THESE ARE NOT EXPOSED TO THE USER AND ARE ONLY FOR USE +* WITHIN LIBKVM. +* +* Copyright (C) 2006 Qumranet, Inc. +* +* Authors: +* Avi Kivity <[email protected]> +* Yaniv Kamay <[email protected]> +* +* Copyright 2008 IBM Corporation. +* Authors: +* Carsten Otte <[email protected]> +* +* This work is licensed under the GNU LGPL license, version 2. +*/ + +#ifndef KVM_S390X_H +#define KVM_S390X_H + +#include "kvm-common.h" + +#define PAGE_SIZE 4096ul +#define PAGE_MASK (~(PAGE_SIZE - 1)) + +#define smp_wmb () asm volatile("" ::: "memory") + +#endif
libkvm/libkvm.c +13 -1
@@ -48,6 +48,10 @@#include "kvm-powerpc.h" #endif +#if defined(__s390x__) +#include "kvm-s390x.h" +#endif +int kvm_abi =EXPECTED_KVM_API_VERSION ;int kvm_page_size;
@@ -88,7 +92,11 @@ int get_free_slot(kvm_context_t kvm)if (tss_ext >0 ) i =0 ; else +#if !defined(__s390x__) i =1 ; +#else + i =0 ; +#endif for (; i <KVM_MAX_NUM_MEM_REGIONS ; ++i)if (!slots[i].len)
@@ -392,7 +400,6 @@ int kvm_create(kvm_context_t kvm, unsignreturn 0 ; } -#ifdef KVM_CAP_USER_MEMORY void *kvm_create_userspace_phys_mem(kvm_context_t kvm, unsigned long phys_start,
@@ -410,7 +417,12 @@ void *kvm_create_userspace_phys_mem(kvm_if (writable) prot |=PROT_WRITE ; +#if !defined(__s390x__) ptr =mmap (NULL , len, prot,MAP_ANONYMOUS |MAP_SHARED ,-1 ,0 ); +#else + ptr =mmap (LIBKVM_S390_ORIGIN , len, prot |PROT_EXEC , +MAP_FIXED |MAP_SHARED |MAP_ANONYMOUS ,-1 ,0 ); +#endif if (ptr ==MAP_FAILED ) {fprintf (stderr,"create_userspace_phys_mem: %s" ,strerror (errno));return 0 ;
Quoted 22 lines · Carsten Otte
This patch makes libkvm build and work on s390. It should be a noop for all other architectures.
Signed-off-by Carsten Otte <[email protected]>---
Index: kvm-userspace/libkvm/config-s390x.mak
===================================================================libkvm/config-s390x.mak new file +6
-0@@ -0,0 +1,6 @@ + +LIBDIR := /lib +CFLAGS += +CFLAGS += -D__s390x__ + +libkvm-$(ARCH)-objs := libkvm-s390x.oIndex:
kvm-userspace/libkvm/libkvm-s390x.c
===================================================================
libkvm/libkvm-s390x.c line 6
Quoted 6 lines
libkvm/libkvm-s390x.c new file +6
-0@@ -0,0 +1,98 @@ +/* +* This header is for functions & variables that will ONLY be +* used inside libkvm for s390x. +* THESE ARE NOT EXPOSED TO THE USER AND ARE ONLY FOR USE +* WITHIN LIBKVM. +*
It isn't a header.
libkvm/libkvm-s390x.c line 8
Quoted 3 lines
libkvm/libkvm-s390x.c new file +2
-0+* derived from libkvm-powerpc.c +*
So it the comment above. So much for our review.
Quoted 108 lines
libkvm/libkvm-s390x.c new file +90
-0+* Copyright 2008 IBM Corporation +* Authors: +* Carsten Otte <[email protected]> +* +* This work is licensed under the GNU LGPL license, version 2. +*/ + +#include "libkvm.h" +#include <errno.h> +#include <stdio.h> +#include <inttypes.h> + +int handle_dcr (struct kvm_run *run,kvm_context_t kvm,int vcpu) +{ +fprintf (stderr,"%s: Operation not supported\n" , __FUNCTION__); +return -1 ; +} + +int kvm_alloc_kernel_memory (kvm_context_t kvm,unsigned long memory, +void **vm_mem) +{ +fprintf (stderr,"%s: Operation not supported\n" , __FUNCTION__); +return -1 ; +} + +void *kvm_create_kernel_phys_mem (kvm_context_t kvm,unsigned long phys_start, +unsigned long len,int log,int writable) +{ +fprintf (stderr,"%s: Operation not supported\n" , __FUNCTION__); +return NULL ; +} + +void kvm_show_code (kvm_context_t kvm,int vcpu) +{ +fprintf (stderr,"%s: Operation not supported\n" , __FUNCTION__); +} + +void kvm_show_regs (kvm_context_t kvm,int vcpu) +{ +struct kvm_regs regs; +int i; + +if (kvm_get_regs (kvm, vcpu, ®s)) +return ; +/* +fprintf(stderr,"guest vcpu #%d\n", vcpu); +fprintf(stderr,"pc: %016"PRIx64" msr: %016"PRIx64"\n", +regs.pc, regs.msr); +fprintf(stderr,"lr: %016"PRIx64" ctr: %016"PRIx64"\n", +regs.lr, regs.ctr); +fprintf(stderr,"srr0: %016"PRIx64" srr1: %016"PRIx64"\n", +regs.srr0, regs.srr1); +for (i=0; i<32; i+=4) +{ +fprintf(stderr, "gpr%02d: %016"PRIx64" %016"PRIx64" %016"PRIx64 +" %016"PRIx64"\n", i, +regs.gpr[i], +regs.gpr[i+1], +regs.gpr[i+2], +regs.gpr[i+3]); +} + +fflush(stdout); +*/ +} + +int kvm_arch_create (kvm_context_t kvm,unsigned long phys_mem_bytes, +void **vm_mem) +{ +return 0 ; +} + +int kvm_arch_create_default_phys_mem (kvm_context_t kvm, +unsigned long phys_mem_bytes, +void **vm_mem) +{ +return 0 ; +} + +int kvm_arch_run (struct kvm_run *run,kvm_context_t kvm,int vcpu) +{ +int ret =0 ; + +switch (run->exit_reason){ +default : + ret =1 ; +break ; + } +return ret; +}Index: kvm-userspace/Makefile
===================================================================Makefile +1
-1@@ -5,7 +5,7 @@ DESTDIR= rpmrelease = devel -sane-arch = $(subst i386,x86,$(subst x86_64,x86,$(ARCH))) +sane-arch = $(subst i386,x86,$(subst x86_64,x86,$(subst s390x,s390,$(ARCH)))) .PHONY: kernel user libkvm qemu bios vgabios extboot clean libfdtIndex:
kvm-userspace/libkvm/kvm-common.h
===================================================================
libkvm/kvm-common.h line 24
Quoted 7 lines
libkvm/kvm-common.h +2
-0@@ -18,8 +18,15 @@/* FIXME: share this number with kvm */ /* FIXME: or dynamically alloc/realloc regions */ +#ifndef __s390x__#define KVM_MAX_NUM_MEM_REGIONS 8u +#define MAX_VCPUS 64
16
libkvm/kvm-common.h line 30
Quoted 4 lines
libkvm/kvm-common.h +2
-0+#else +#define KVM_MAX_NUM_MEM_REGIONS 1u#define MAX_VCPUS 16
64
libkvm/kvm-common.h line 30
Quoted 2 lines
libkvm/kvm-common.h +1
-0+#define LIBKVM_S390_ORIGIN (0UL)
Thought you got rid of that?
Signature · 1 line
error compiling committee.c: too many arguments to function
That patch was Carstens last job before he left into vacation. I promised to look after it, so I will sent an updated patch soon.
Quoted 9 lines
Quoted 7 lines
+/*
+ * This header is for functions & variables that will ONLY be
+ * used inside libkvm for s390x.
+ * THESE ARE NOT EXPOSED TO THE USER AND ARE ONLY FOR USE
+ * WITHIN LIBKVM.
+ *It isn't a header.
Will fix
Quoted 6 lines
Quoted 4 lines
+ * derived from
libkvm-powerpc.c
+ *So it the comment above. So much for our review.
I guess libkvm-powerpc.c will be fixed by the powerpc guys?
Quoted 7 lines
libkvm/kvm-common.h line 23
Quoted 4 lines
libkvm/kvm-common.h +2
-0+#ifndef __s390x__#define KVM_MAX_NUM_MEM_REGIONS 8u +#define MAX_VCPUS 6416
Quoted 6 lines
libkvm/kvm-common.h line 26
Quoted 4 lines
libkvm/kvm-common.h +2
-0+#else +#define KVM_MAX_NUM_MEM_REGIONS 1u#define MAX_VCPUS 1664
Yes, indeed.
Quoted 3 lines
Quoted 1 line
+#define
LIBKVM_S390_ORIGIN(0UL)Thought you got rid of that?
Sort of. We have the kernel code ready to move away the guest from address 0. To achieve that goal we use the offset and limit field in the control block. Thing is, on older models the offset and limit must be < 128GB. that means we still cannot use randomly allocated memory. LIBKVM_S390_ORIGIN=1M,2M or 16M would be perfectly fine, 2TB (typical malloc space) is not. Furthermore, this change is still in kvm.git, but not in Linus git. Therefore, we would like to keep the guest at 0 and fix that at a later time, ok?
Christian
Quoted 10 lines · Christian Borntraeger
Quoted 5 lines
Quoted 3 lines
+#define
LIBKVM_S390_ORIGIN(0UL)Thought you got rid of that?
Sort of. We have the kernel code ready to move away the guest from address 0. To achieve that goal we use the offset and limit field in the control block.
Thing is, on older models the offset and limit must be < 128GB. that means we still cannot use randomly allocated memory. LIBKVM_S390_ORIGIN=1M,2M or 16M would be perfectly fine, 2TB (typical malloc space) is not. Furthermore, this change is still in kvm.git, but not in Linus git. Therefore, we would like to keep the guest at 0 and fix that at a later time, ok?
Certainly. I suggest exposing this via a KVM_CAP_blah and adapting at runtime.
Placing the guest at offset zero is dangerous, since all a guest has to do is place a function at guest physical address zero and wait for a kernel bug that calls a null function pointer (at least, it would behave like that on x86, provided no-execute was disabled; it may well be that s390 has additional protection).
Signature · 1 line
error compiling committee.c: too many arguments to function
Am Montag, 14. Juli 2008 schrieb Avi Kivity:
Quoted 8 lines
Certainly. I suggest exposing this via a
KVM_CAP_blahand adapting at runtime.Placing the guest at offset zero is dangerous, since all a guest has to do is place a function at guest physical address zero and wait for a kernel bug that calls a null function pointer (at least, it would behave like that on x86, provided no-execute was disabled; it may well be that s390 has additional protection).
Since we have separate address space for kernel and userspace this should be fine for s390. But I totally agree that offset != 0 is better for quality and testing. During KVM Forum time frame I found some null pointer accesses in our userspace code when I changed offset to 1MB. In the long term we definitely want to move our guest.
Christian
Quoted 3 lines · Carsten Otte
This patch makes libkvm build and work on s390. It should be a noop for all other architectures.
I'm thinking of spending some time eliminate libkvm altogether in the next month or so. Noone seems to be using it for alternative userspaces and the code that interacts with it in QEMU badly needs refactoring.
Dropping the abstraction will probably result in a big drop in lines of code and would probably make it more clear anyway.
Regards,
Anthony Liguori
Quoted 239 lines
Signed-off-by Carsten Otte <[email protected]>---
Index: kvm-userspace/libkvm/config-s390x.mak
===================================================================libkvm/config-s390x.mak new file +6
-0@@ -0,0 +1,6 @@ + +LIBDIR := /lib +CFLAGS += +CFLAGS += -D__s390x__ + +libkvm-$(ARCH)-objs := libkvm-s390x.oIndex:
kvm-userspace/libkvm/libkvm-s390x.c
===================================================================libkvm/libkvm-s390x.c new file +98
-0@@ -0,0 +1,98 @@ +/* +* This header is for functions & variables that will ONLY be +* used inside libkvm for s390x. +* THESE ARE NOT EXPOSED TO THE USER AND ARE ONLY FOR USE +* WITHIN LIBKVM. +* +* derived from libkvm-powerpc.c +* +* Copyright 2008 IBM Corporation +* Authors: +* Carsten Otte <[email protected]> +* +* This work is licensed under the GNU LGPL license, version 2. +*/ + +#include "libkvm.h" +#include <errno.h> +#include <stdio.h> +#include <inttypes.h> + +int handle_dcr (struct kvm_run *run,kvm_context_t kvm,int vcpu) +{ +fprintf (stderr,"%s: Operation not supported\n" , __FUNCTION__); +return -1 ; +} + +int kvm_alloc_kernel_memory (kvm_context_t kvm,unsigned long memory, +void **vm_mem) +{ +fprintf (stderr,"%s: Operation not supported\n" , __FUNCTION__); +return -1 ; +} + +void *kvm_create_kernel_phys_mem (kvm_context_t kvm,unsigned long phys_start, +unsigned long len,int log,int writable) +{ +fprintf (stderr,"%s: Operation not supported\n" , __FUNCTION__); +return NULL ; +} + +void kvm_show_code (kvm_context_t kvm,int vcpu) +{ +fprintf (stderr,"%s: Operation not supported\n" , __FUNCTION__); +} + +void kvm_show_regs (kvm_context_t kvm,int vcpu) +{ +struct kvm_regs regs; +int i; + +if (kvm_get_regs (kvm, vcpu, ®s)) +return ; +/* +fprintf(stderr,"guest vcpu #%d\n", vcpu); +fprintf(stderr,"pc: %016"PRIx64" msr: %016"PRIx64"\n", +regs.pc, regs.msr); +fprintf(stderr,"lr: %016"PRIx64" ctr: %016"PRIx64"\n", +regs.lr, regs.ctr); +fprintf(stderr,"srr0: %016"PRIx64" srr1: %016"PRIx64"\n", +regs.srr0, regs.srr1); +for (i=0; i<32; i+=4) +{ +fprintf(stderr, "gpr%02d: %016"PRIx64" %016"PRIx64" %016"PRIx64 +" %016"PRIx64"\n", i, +regs.gpr[i], +regs.gpr[i+1], +regs.gpr[i+2], +regs.gpr[i+3]); +} + +fflush(stdout); +*/ +} + +int kvm_arch_create (kvm_context_t kvm,unsigned long phys_mem_bytes, +void **vm_mem) +{ +return 0 ; +} + +int kvm_arch_create_default_phys_mem (kvm_context_t kvm, +unsigned long phys_mem_bytes, +void **vm_mem) +{ +return 0 ; +} + +int kvm_arch_run (struct kvm_run *run,kvm_context_t kvm,int vcpu) +{ +int ret =0 ; + +switch (run->exit_reason){ +default : + ret =1 ; +break ; + } +return ret; +}Index: kvm-userspace/Makefile
===================================================================Makefile +1
-1@@ -5,7 +5,7 @@ DESTDIR= rpmrelease = devel -sane-arch = $(subst i386,x86,$(subst x86_64,x86,$(ARCH))) +sane-arch = $(subst i386,x86,$(subst x86_64,x86,$(subst s390x,s390,$(ARCH)))) .PHONY: kernel user libkvm qemu bios vgabios extboot clean libfdtIndex:
kvm-userspace/libkvm/kvm-common.h
===================================================================libkvm/kvm-common.h +7
-0@@ -18,8 +18,15 @@/* FIXME: share this number with kvm */ /* FIXME: or dynamically alloc/realloc regions */ +#ifndef __s390x__#define KVM_MAX_NUM_MEM_REGIONS 8u +#define MAX_VCPUS 64 +#else +#define KVM_MAX_NUM_MEM_REGIONS 1u#define MAX_VCPUS 16 +#define LIBKVM_S390_ORIGIN (0UL) +#endif +/* kvm abi verison variable */ extern int kvm_abi;Index:
kvm-userspace/libkvm/kvm-s390x.h
===================================================================libkvm/kvm-s390x.h new file +30
-0@@ -0,0 +1,30 @@ +/* +* This header is for functions & variables that will ONLY be +* used inside libkvm for s390. +* THESE ARE NOT EXPOSED TO THE USER AND ARE ONLY FOR USE +* WITHIN LIBKVM. +* +* Copyright (C) 2006 Qumranet, Inc. +* +* Authors: +* Avi Kivity <[email protected]> +* Yaniv Kamay <[email protected]> +* +* Copyright 2008 IBM Corporation. +* Authors: +* Carsten Otte <[email protected]> +* +* This work is licensed under the GNU LGPL license, version 2. +*/ + +#ifndef KVM_S390X_H +#define KVM_S390X_H + +#include "kvm-common.h" + +#define PAGE_SIZE 4096ul +#define PAGE_MASK (~(PAGE_SIZE - 1)) + +#define smp_wmb () asm volatile("" ::: "memory") + +#endif Index:
kvm-userspace/libkvm/libkvm.c
===================================================================libkvm/libkvm.c +13
-2@@ -48,6 +48,10 @@#include "kvm-powerpc.h" #endif +#if defined(__s390x__) +#include "kvm-s390x.h" +#endif +int kvm_abi =EXPECTED_KVM_API_VERSION ;int kvm_page_size;@@ -88,7 +92,11 @@ int get_free_slot(kvm_context_t kvm)if (tss_ext >0 ) i =0 ; else +#if !defined(__s390x__) i =1 ; +#else + i =0 ; +#endif for (; i <KVM_MAX_NUM_MEM_REGIONS ; ++i)if (!slots[i].len)@@ -392,7 +400,6 @@ int kvm_create(kvm_context_t kvm, unsignreturn 0 ; } -#ifdef KVM_CAP_USER_MEMORY void *kvm_create_userspace_phys_mem(kvm_context_t kvm, unsigned long phys_start,@@ -410,7 +417,12 @@ void *kvm_create_userspace_phys_mem(kvm_if (writable) prot |=PROT_WRITE ; +#if !defined(__s390x__) ptr =mmap (NULL , len, prot,MAP_ANONYMOUS |MAP_SHARED ,-1 ,0 ); +#else + ptr =mmap (LIBKVM_S390_ORIGIN , len, prot |PROT_EXEC , +MAP_FIXED |MAP_SHARED |MAP_ANONYMOUS ,-1 ,0 ); +#endif if (ptr ==MAP_FAILED ) {fprintf (stderr,"create_userspace_phys_mem: %s" ,strerror (errno));return 0 ; --To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Am Montag, 14. Juli 2008 schrieb Anthony Liguori:
Quoted 11 lines
Quoted 3 lines · Carsten Otte
This patch makes libkvm build and work on s390. It should be a noop for all other architectures.
I'm thinking of spending some time eliminate libkvm altogether in the next month or so. Noone seems to be using it for alternative userspaces and the code that interacts with it in QEMU badly needs refactoring.
Dropping the abstraction will probably result in a big drop in lines of code and would probably make it more clear anyway.
Does that mean, that I can stop finishing Carstens patch?
Christian
Quoted 8 lines · Christian Borntraeger
Am Montag, 14. Juli 2008 schrieb Anthony Liguori:
Quoted 6 lines
Quoted 4 lines · Carsten Otte
This patch makes libkvm build and work on s390. It should be a noop for all other architectures.
Quoted 7 lines
Quoted 4 lines
I'm thinking of spending some time eliminate libkvm altogether in the next month or so. Noone seems to be using it for alternative userspaces and the code that interacts with it in QEMU badly needs refactoring.
Dropping the abstraction will probably result in a big drop in lines of code and would probably make it more clear anyway.
Does that mean, that I can stop finishing Carstens patch?
Depends. I'd say there's not a lot of utility making kuli use libkvm in it's current form. If you're trying to get QEMU working, then getting libkvm working is probably a good start.
It's still not clear whether libkvm is a useful abstraction. It may be that we want to refactor libkvm to be more useful so it's not 100% clear atm that it's going away.
Regards,
Anthony Liguori
Quoted 2 lines
Christian
PATCH 1/1 libkvm-s390
In reply to Carsten OtteThis is an update patch for libkvm to build and work on s390.
It should address all comments from Avi as well as some aspects I have found:
o implement kvm_show_regs
o use s390 instead of s390x in file names. It is commonly used for 31 and 64bit systems
o dont define __s390__ and __s390x__ in config.mak. Its predefined in gcc.
o add some callbacks (done by Carsten, but not yet posted)
From: Carsten Otte <[email protected]>
From: Christian Borntraeger <[email protected]>
--- Makefile | 2 libkvm/config-s390.mak | 3 + libkvm/config-s390x.mak | 3 + libkvm/kvm-common.h | 7 ++ libkvm/kvm-s390.h | 31 ++++++++++ libkvm/libkvm-s390.c | 137 ++++++++++++++++++++++++++++++++++++++++++++++++ libkvm/libkvm.c | 25 ++++++++ libkvm/libkvm.h | 17 +++++ 8 files changed, 224 insertions(+), 1 deletion(-)
Makefile +1 -1
@@ -5,7 +5,7 @@ DESTDIR= rpmrelease = devel -sane-arch = $(subst i386,x86,$(subst x86_64,x86,$(ARCH))) +sane-arch = $(subst i386,x86,$(subst x86_64,x86,$(subst s390x,s390,$(ARCH)))) .PHONY: kernel user libkvm qemu bios vgabios extboot clean libfdt
libkvm/config-s390.mak new file +3 -0
@@ -0,0 +1,3 @@ +# s390 31bit mode +LIBDIR := /lib +libkvm-$(ARCH)-objs := libkvm-s390.o
libkvm/config-s390x.mak new file +3 -0
@@ -0,0 +1,3 @@ +# s390 64 bit mode (arch=s390x) +LIBDIR := /lib64 +libkvm-$(ARCH)-objs := libkvm-s390.o
libkvm/kvm-common.h +7 -0
@@ -18,8 +18,15 @@/* FIXME: share this number with kvm */ /* FIXME: or dynamically alloc/realloc regions */ +#ifndef __s390__#define KVM_MAX_NUM_MEM_REGIONS 8u#define MAX_VCPUS 16 +#else +#define KVM_MAX_NUM_MEM_REGIONS 1u +#define MAX_VCPUS 64 +#define LIBKVM_S390_ORIGIN (0UL) +#endif +/* kvm abi verison variable */ extern int kvm_abi;
libkvm/kvm-s390.h new file +31 -0
@@ -0,0 +1,31 @@ +/* +* This header is for functions & variables that will ONLY be +* used inside libkvm for s390. +* THESE ARE NOT EXPOSED TO THE USER AND ARE ONLY FOR USE +* WITHIN LIBKVM. +* +* Copyright (C) 2006 Qumranet, Inc. +* +* Authors: +* Avi Kivity <[email protected]> +* Yaniv Kamay <[email protected]> +* +* Copyright 2008 IBM Corporation. +* Authors: +* Carsten Otte <[email protected]> +* +* This work is licensed under the GNU LGPL license, version 2. +*/ + +#ifndef KVM_S390_H +#define KVM_S390_H + +#include <asm/ptrace.h> +#include "kvm-common.h" + +#define PAGE_SIZE 4096ul +#define PAGE_MASK (~(PAGE_SIZE - 1)) + +#define smp_wmb () asm volatile("" ::: "memory") + +#endif
libkvm/libkvm-s390.c new file +137 -0
137 lines not on this page · raw message
libkvm/libkvm.c +25 -0
@@ -48,6 +48,10 @@#include "kvm-powerpc.h" #endif +#if defined(__s390__) +#include "kvm-s390.h" +#endif +int kvm_abi =EXPECTED_KVM_API_VERSION ;int kvm_page_size;
@@ -88,7 +92,11 @@ int get_free_slot(kvm_context_t kvm)if (tss_ext >0 ) i =0 ; else +#if !defined(__s390__) i =1 ; +#else + i =0 ; +#endif for (; i <KVM_MAX_NUM_MEM_REGIONS ; ++i)if (!slots[i].len)
@@ -410,7 +418,12 @@ void *kvm_create_userspace_phys_mem(kvm_if (writable) prot |=PROT_WRITE ; +#if !defined(__s390__) ptr =mmap (NULL , len, prot,MAP_ANONYMOUS |MAP_SHARED ,-1 ,0 ); +#else + ptr =mmap (LIBKVM_S390_ORIGIN , len, prot |PROT_EXEC , +MAP_FIXED |MAP_SHARED |MAP_ANONYMOUS ,-1 ,0 ); +#endif if (ptr ==MAP_FAILED ) {fprintf (stderr,"create_userspace_phys_mem: %s" ,strerror (errno));return 0 ;
@@ -895,8 +908,10 @@ int kvm_run(kvm_context_t kvm, int vcpu)struct kvm_run *run = kvm->run[vcpu]; again: +#if !defined(__s390__)if (!kvm->irqchip_in_kernel) run->request_interrupt_window =try_push_interrupts (kvm); +#endif r =pre_kvm_run (kvm, vcpu);if (r)return r;
@@ -927,10 +942,12 @@ again: }#endif +#if !defined(__s390__)if (r ==-1 ) { r =handle_io_window (kvm); goto more; } +#endif if (1 ) {switch (run->exit_reason) {case KVM_EXIT_UNKNOWN :
@@ -969,6 +986,14 @@ again:case KVM_EXIT_SHUTDOWN : r =handle_shutdown (kvm, vcpu);break ; +#if defined(__s390__) +case KVM_EXIT_S390_SIEIC : + r = kvm->callbacks->s390_handle_intercept (kvm, vcpu, + run); +break ; +case KVM_EXIT_S390_RESET : + r = kvm->callbacks->s390_handle_reset (kvm, vcpu, run); +#endif default :if (kvm_arch_run (run, kvm, vcpu)) { fprintf(stderr, "unhandled vm exit: 0x%x\n",
libkvm/libkvm.h +17 -0
@@ -5,6 +5,10 @@#ifndef LIBKVM_H #define LIBKVM_H +#if defined(__s390__) +#include <asm/ptrace.h> +#endif +#include <stdint.h> #ifndef __user
@@ -69,6 +73,12 @@ struct kvm_callbacks {int (*powerpc_dcr_read)(int vcpu,uint32_t dcrn,uint32_t *data);int (*powerpc_dcr_write)(int vcpu,uint32_t dcrn,uint32_t data);#endif +#if defined(__s390__) +int (*s390_handle_intercept)(kvm_context_t context,int vcpu, +struct kvm_run *run); +int (*s390_handle_reset)(kvm_context_t context,int vcpu, +struct kvm_run *run); +#endif };/*!
@@ -639,4 +649,11 @@ int kvm_enable_vapic(kvm_context_t kvm,#endif +#if defined(__s390__) +int kvm_s390_initial_reset (kvm_context_t kvm,int slot); +int kvm_s390_interrupt (kvm_context_t kvm,int slot, +struct kvm_s390_interrupt *kvmint); +int kvm_s390_set_initial_psw (kvm_context_t kvm,int slot,psw_t psw); +int kvm_s390_store_status (kvm_context_t kvm,int slot,unsigned long addr); +#endif #endif
Quoted 1 line · Christian Borntraeger
This is an update patch for libkvm to build and work on s390
[...]
Quoted 7 lines
Index:
kvm-userspace/libkvm/libkvm-s390.c
===================================================================libkvm/libkvm-s390.c new file +1
-0@@ -0,0 +1,137 @@ +/*
libkvm/libkvm-s390.c line 11
Quoted 10 lines
libkvm/libkvm-s390.c new file +10
-0+* This file contains the s390 specific implementation for the +* architecture dependent functions defined in kvm-common.h and +* libkvm.h +* +* Copyright (C) 2006 Qumranet +* Copyright IBM Corp. 2008 +* +* Authors: +* Carsten Otte <[email protected]> +* Christian Borntraeger <[email protected]>
whitespace error - well just in the comment, but if you resubmit it anyway this space could be removed ;-)
[...]
libkvm/libkvm-s390.c line 30
Quoted 8 lines
libkvm/libkvm-s390.c new file +7
-0+ +int handle_dcr (struct kvm_run *run,kvm_context_t kvm,int vcpu) +{ +fprintf (stderr,"%s: Operation not supported\n" , __FUNCTION__); +return -1 ; +} +
I think Carsten started with the powerpc file here.
This function is powerpc only and even in our code only called later on in this libkvm-$arch.c file. Maybe we should patch our file and make it static to clarify that.
Since you don't have that call its superfluous, you should be able to drop it without consequence.
[...]
Quoted 16 lines
Index:
kvm-userspace/libkvm/libkvm.c
===================================================================libkvm/libkvm.c +4
-0@@ -48,6 +48,10 @@#include "kvm-powerpc.h" #endif +#if defined(__s390__) +#include "kvm-s390.h" +#endif +int kvm_abi =EXPECTED_KVM_API_VERSION ;int kvm_page_size;
libkvm/libkvm.c int get_free_slot(kvm_context_t kvm) · line 101
Quoted 10 lines
libkvm/libkvm.c +4
-0@@ -88,7 +92,11 @@ int get_free_slot(kvm_context_t kvm)if (tss_ext >0 ) i =0 ; else +#if !defined(__s390__) i =1 ; +#else + i =0 ; +#endif
This looks a bit complicated, but when thinking of the result this just means that i is always 0 on s390. Therefore I think it would look less confusing when the ifdef would not be in the else part of that tss_ext if.
Since i will always be zero in s390 case you could do things like
- initialize i with 0 and let the whole block until the for loop run in "if !defined(__s390__)"
That way you would additionally stop modifying the tss_ext variable which is not used in the s390 case anyway.
[...]
Signature · 2 lines
Grüsse / regards, Christian Ehrhardt IBM Linux Technology Center, Open Virtualization
PATCH v3 1/1 libkvm-s390
From: Carsten Otte <[email protected]>
From: Christian Borntraeger <[email protected]>
This is an update patch for libkvm to build and work on s390. It should address Avis and Christians comments. Tested on s390. Compile tested on i386.
Avi please consider to apply.
--- Makefile | 2 libkvm/config-s390.mak | 3 + libkvm/config-s390x.mak | 3 + libkvm/kvm-common.h | 7 ++ libkvm/kvm-s390.h | 31 +++++++++++ libkvm/libkvm-s390.c | 131 ++++++++++++++++++++++++++++++++++++++++++++++++ libkvm/libkvm.c | 23 ++++++++ libkvm/libkvm.h | 17 ++++++ 8 files changed, 215 insertions(+), 2 deletions(-)
Makefile +1 -1
@@ -5,7 +5,7 @@ DESTDIR= rpmrelease = devel -sane-arch = $(subst i386,x86,$(subst x86_64,x86,$(ARCH))) +sane-arch = $(subst i386,x86,$(subst x86_64,x86,$(subst s390x,s390,$(ARCH)))) .PHONY: kernel user libkvm qemu bios vgabios extboot clean libfdt
libkvm/config-s390.mak new file +3 -0
@@ -0,0 +1,3 @@ +# s390 31bit mode +LIBDIR := /lib +libkvm-$(ARCH)-objs := libkvm-s390.o
libkvm/config-s390x.mak new file +3 -0
@@ -0,0 +1,3 @@ +# s390 64 bit mode (arch=s390x) +LIBDIR := /lib64 +libkvm-$(ARCH)-objs := libkvm-s390.o
libkvm/kvm-common.h +7 -0
@@ -18,8 +18,15 @@/* FIXME: share this number with kvm */ /* FIXME: or dynamically alloc/realloc regions */ +#ifndef __s390__#define KVM_MAX_NUM_MEM_REGIONS 8u#define MAX_VCPUS 16 +#else +#define KVM_MAX_NUM_MEM_REGIONS 1u +#define MAX_VCPUS 64 +#define LIBKVM_S390_ORIGIN (0UL) +#endif +/* kvm abi verison variable */ extern int kvm_abi;
libkvm/kvm-s390.h new file +31 -0
@@ -0,0 +1,31 @@ +/* +* This header is for functions & variables that will ONLY be +* used inside libkvm for s390. +* THESE ARE NOT EXPOSED TO THE USER AND ARE ONLY FOR USE +* WITHIN LIBKVM. +* +* Copyright (C) 2006 Qumranet, Inc. +* +* Authors: +* Avi Kivity <[email protected]> +* Yaniv Kamay <[email protected]> +* +* Copyright 2008 IBM Corporation. +* Authors: +* Carsten Otte <[email protected]> +* +* This work is licensed under the GNU LGPL license, version 2. +*/ + +#ifndef KVM_S390_H +#define KVM_S390_H + +#include <asm/ptrace.h> +#include "kvm-common.h" + +#define PAGE_SIZE 4096ul +#define PAGE_MASK (~(PAGE_SIZE - 1)) + +#define smp_wmb () asm volatile("" ::: "memory") + +#endif
libkvm/libkvm-s390.c new file +131 -0
131 lines not on this page · raw message
libkvm/libkvm.c +22 -1
@@ -48,6 +48,10 @@#include "kvm-powerpc.h" #endif +#if defined(__s390__) +#include "kvm-s390.h" +#endif +int kvm_abi =EXPECTED_KVM_API_VERSION ;int kvm_page_size;
@@ -74,7 +78,7 @@ int get_free_slot(kvm_context_t kvm)int i;int tss_ext; -#ifdef KVM_CAP_SET_TSS_ADDR +#if defined(KVM_CAP_SET_TSS_ADDR ) && !defined(__s390__) tss_ext =ioctl (kvm->fd,KVM_CHECK_EXTENSION ,KVM_CAP_SET_TSS_ADDR );#else tss_ext =0 ;
@@ -410,7 +414,12 @@ void *kvm_create_userspace_phys_mem(kvm_if (writable) prot |=PROT_WRITE ; +#if !defined(__s390__) ptr =mmap (NULL , len, prot,MAP_ANONYMOUS |MAP_SHARED ,-1 ,0 ); +#else + ptr =mmap (LIBKVM_S390_ORIGIN , len, prot |PROT_EXEC , +MAP_FIXED |MAP_SHARED |MAP_ANONYMOUS ,-1 ,0 ); +#endif if (ptr ==MAP_FAILED ) {fprintf (stderr,"create_userspace_phys_mem: %s" ,strerror (errno));return 0 ;
@@ -895,8 +904,10 @@ int kvm_run(kvm_context_t kvm, int vcpu)struct kvm_run *run = kvm->run[vcpu]; again: +#if !defined(__s390__)if (!kvm->irqchip_in_kernel) run->request_interrupt_window =try_push_interrupts (kvm); +#endif r =pre_kvm_run (kvm, vcpu);if (r)return r;
@@ -927,10 +938,12 @@ again: }#endif +#if !defined(__s390__)if (r ==-1 ) { r =handle_io_window (kvm); goto more; } +#endif if (1 ) {switch (run->exit_reason) {case KVM_EXIT_UNKNOWN :
@@ -969,6 +982,14 @@ again:case KVM_EXIT_SHUTDOWN : r =handle_shutdown (kvm, vcpu);break ; +#if defined(__s390__) +case KVM_EXIT_S390_SIEIC : + r = kvm->callbacks->s390_handle_intercept (kvm, vcpu, + run); +break ; +case KVM_EXIT_S390_RESET : + r = kvm->callbacks->s390_handle_reset (kvm, vcpu, run); +#endif default :if (kvm_arch_run (run, kvm, vcpu)) { fprintf(stderr, "unhandled vm exit: 0x%x\n",
libkvm/libkvm.h +17 -0
@@ -5,6 +5,10 @@#ifndef LIBKVM_H #define LIBKVM_H +#if defined(__s390__) +#include <asm/ptrace.h> +#endif +#include <stdint.h> #ifndef __user
@@ -69,6 +73,12 @@ struct kvm_callbacks {int (*powerpc_dcr_read)(int vcpu,uint32_t dcrn,uint32_t *data);int (*powerpc_dcr_write)(int vcpu,uint32_t dcrn,uint32_t data);#endif +#if defined(__s390__) +int (*s390_handle_intercept)(kvm_context_t context,int vcpu, +struct kvm_run *run); +int (*s390_handle_reset)(kvm_context_t context,int vcpu, +struct kvm_run *run); +#endif };/*!
@@ -639,4 +649,11 @@ int kvm_enable_vapic(kvm_context_t kvm,#endif +#if defined(__s390__) +int kvm_s390_initial_reset (kvm_context_t kvm,int slot); +int kvm_s390_interrupt (kvm_context_t kvm,int slot, +struct kvm_s390_interrupt *kvmint); +int kvm_s390_set_initial_psw (kvm_context_t kvm,int slot,psw_t psw); +int kvm_s390_store_status (kvm_context_t kvm,int slot,unsigned long addr); +#endif #endif
Avi Kivity
AppliedQuoted 8 lines · Christian Borntraeger
From: Carsten Otte <[email protected]>
From: Christian Borntraeger <[email protected]>This is an update patch for libkvm to build and work on s390. It should address Avis and Christians comments. Tested on s390. Compile tested on i386.
Applied, thanks.
Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this signature is too narrow to contain.