* Re: [PATCH] libkvm-s390
2008-07-11 17:29 [PATCH] libkvm-s390 Carsten Otte
@ 2008-07-13 8:29 ` Avi Kivity
2008-07-14 11:33 ` Christian Borntraeger
2008-07-14 15:34 ` Anthony Liguori
2008-07-16 15:28 ` [PATCH v2/RFC] libkvm-s390 Christian Borntraeger
2 siblings, 1 reply; 12+ messages in thread
From: Avi Kivity @ 2008-07-13 8:29 UTC (permalink / raw)
To: Carsten Otte; +Cc: kvm, Olaf Schnapper, Christian Borntraeger, Hollis Blanchard
Carsten Otte wrote:
> This patch makes libkvm build and work on s390. It should be a noop for
> all other architectures.
>
> Signed-off-by: Carsten Otte <cotte@de.ibm.com>
> ---
> Index: kvm-userspace/libkvm/config-s390x.mak
> ===================================================================
> --- /dev/null
> +++ kvm-userspace/libkvm/config-s390x.mak
> @@ -0,0 +1,6 @@
> +
> +LIBDIR := /lib
> +CFLAGS +=
> +CFLAGS += -D__s390x__
> +
> +libkvm-$(ARCH)-objs := libkvm-s390x.o
> Index: kvm-userspace/libkvm/libkvm-s390x.c
> ===================================================================
> --- /dev/null
> +++ kvm-userspace/libkvm/libkvm-s390x.c
> @@ -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.
> + * derived from libkvm-powerpc.c
> + *
>
So it the comment above. So much for our review.
> + * Copyright 2008 IBM Corporation
> + * Authors:
> + * Carsten Otte <cotte@de.ibm.com>
> + *
> + * 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
> ===================================================================
> --- kvm-userspace.orig/Makefile
> +++ kvm-userspace/Makefile
> @@ -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
>
> Index: kvm-userspace/libkvm/kvm-common.h
> ===================================================================
> --- kvm-userspace.orig/libkvm/kvm-common.h
> +++ kvm-userspace/libkvm/kvm-common.h
> @@ -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
> +#else
> +#define KVM_MAX_NUM_MEM_REGIONS 1u
> #define MAX_VCPUS 16
>
64
> +#define LIBKVM_S390_ORIGIN (0UL)
>
Thought you got rid of that?
--
error compiling committee.c: too many arguments to function
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH] libkvm-s390
2008-07-13 8:29 ` Avi Kivity
@ 2008-07-14 11:33 ` Christian Borntraeger
2008-07-14 11:44 ` Avi Kivity
0 siblings, 1 reply; 12+ messages in thread
From: Christian Borntraeger @ 2008-07-14 11:33 UTC (permalink / raw)
To: Avi Kivity; +Cc: Carsten Otte, kvm, Olaf Schnapper, Hollis Blanchard
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.
> > +/*
> > + * 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
>
> > + * 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?
> > +#ifndef __s390x__
> > #define KVM_MAX_NUM_MEM_REGIONS 8u
> > +#define MAX_VCPUS 64
> >
>
> 16
>
> > +#else
> > +#define KVM_MAX_NUM_MEM_REGIONS 1u
> > #define MAX_VCPUS 16
> >
>
> 64
Yes, indeed.
> > +#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
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] libkvm-s390
2008-07-14 11:33 ` Christian Borntraeger
@ 2008-07-14 11:44 ` Avi Kivity
2008-07-14 12:25 ` Christian Borntraeger
0 siblings, 1 reply; 12+ messages in thread
From: Avi Kivity @ 2008-07-14 11:44 UTC (permalink / raw)
To: Christian Borntraeger; +Cc: Carsten Otte, kvm, Olaf Schnapper, Hollis Blanchard
Christian Borntraeger wrote:
>
>>> +#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).
--
error compiling committee.c: too many arguments to function
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] libkvm-s390
2008-07-14 11:44 ` Avi Kivity
@ 2008-07-14 12:25 ` Christian Borntraeger
0 siblings, 0 replies; 12+ messages in thread
From: Christian Borntraeger @ 2008-07-14 12:25 UTC (permalink / raw)
To: Avi Kivity; +Cc: Carsten Otte, kvm, Olaf Schnapper, Hollis Blanchard
Am Montag, 14. Juli 2008 schrieb Avi Kivity:
> 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).
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
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] libkvm-s390
2008-07-11 17:29 [PATCH] libkvm-s390 Carsten Otte
2008-07-13 8:29 ` Avi Kivity
@ 2008-07-14 15:34 ` Anthony Liguori
2008-07-14 17:00 ` Christian Borntraeger
2008-07-16 15:28 ` [PATCH v2/RFC] libkvm-s390 Christian Borntraeger
2 siblings, 1 reply; 12+ messages in thread
From: Anthony Liguori @ 2008-07-14 15:34 UTC (permalink / raw)
To: Carsten Otte
Cc: Avi Kivity, kvm, Olaf Schnapper, Christian Borntraeger,
Hollis Blanchard
Carsten Otte wrote:
> 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
> Signed-off-by: Carsten Otte <cotte@de.ibm.com>
> ---
> Index: kvm-userspace/libkvm/config-s390x.mak
> ===================================================================
> --- /dev/null
> +++ kvm-userspace/libkvm/config-s390x.mak
> @@ -0,0 +1,6 @@
> +
> +LIBDIR := /lib
> +CFLAGS +=
> +CFLAGS += -D__s390x__
> +
> +libkvm-$(ARCH)-objs := libkvm-s390x.o
> Index: kvm-userspace/libkvm/libkvm-s390x.c
> ===================================================================
> --- /dev/null
> +++ kvm-userspace/libkvm/libkvm-s390x.c
> @@ -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 <cotte@de.ibm.com>
> + *
> + * 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
> ===================================================================
> --- kvm-userspace.orig/Makefile
> +++ kvm-userspace/Makefile
> @@ -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
>
> Index: kvm-userspace/libkvm/kvm-common.h
> ===================================================================
> --- kvm-userspace.orig/libkvm/kvm-common.h
> +++ kvm-userspace/libkvm/kvm-common.h
> @@ -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
> ===================================================================
> --- /dev/null
> +++ kvm-userspace/libkvm/kvm-s390x.h
> @@ -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 <avi@qumranet.com>
> + * Yaniv Kamay <yaniv@qumranet.com>
> + *
> + * Copyright 2008 IBM Corporation.
> + * Authors:
> + * Carsten Otte <cotte@de.ibm.com>
> + *
> + * 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
> ===================================================================
> --- kvm-userspace.orig/libkvm/libkvm.c
> +++ kvm-userspace/libkvm/libkvm.c
> @@ -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, unsign
> return 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 majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH] libkvm-s390
2008-07-14 15:34 ` Anthony Liguori
@ 2008-07-14 17:00 ` Christian Borntraeger
2008-07-14 18:00 ` Anthony Liguori
0 siblings, 1 reply; 12+ messages in thread
From: Christian Borntraeger @ 2008-07-14 17:00 UTC (permalink / raw)
To: Anthony Liguori
Cc: Carsten Otte, Avi Kivity, kvm, Olaf Schnapper, Hollis Blanchard
Am Montag, 14. Juli 2008 schrieb Anthony Liguori:
> Carsten Otte wrote:
> > 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
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] libkvm-s390
2008-07-14 17:00 ` Christian Borntraeger
@ 2008-07-14 18:00 ` Anthony Liguori
0 siblings, 0 replies; 12+ messages in thread
From: Anthony Liguori @ 2008-07-14 18:00 UTC (permalink / raw)
To: Christian Borntraeger
Cc: Carsten Otte, Avi Kivity, kvm, Olaf Schnapper, Hollis Blanchard
Christian Borntraeger wrote:
> Am Montag, 14. Juli 2008 schrieb Anthony Liguori:
>
>> Carsten Otte wrote:
>>
>>> 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?
>
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
> Christian
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v2/RFC] libkvm-s390
2008-07-11 17:29 [PATCH] libkvm-s390 Carsten Otte
2008-07-13 8:29 ` Avi Kivity
2008-07-14 15:34 ` Anthony Liguori
@ 2008-07-16 15:28 ` Christian Borntraeger
2008-07-17 11:08 ` Christian Ehrhardt
2 siblings, 1 reply; 12+ messages in thread
From: Christian Borntraeger @ 2008-07-16 15:28 UTC (permalink / raw)
To: Avi Kivity; +Cc: Carsten Otte, kvm, Olaf Schnapper, Hollis Blanchard
This 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 <cotte@de.ibm.com>
From: Christian Borntraeger <borntraeger@de.ibm.com>
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
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(-)
Index: kvm-userspace/Makefile
===================================================================
--- kvm-userspace.orig/Makefile
+++ kvm-userspace/Makefile
@@ -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
Index: kvm-userspace/libkvm/config-s390.mak
===================================================================
--- /dev/null
+++ kvm-userspace/libkvm/config-s390.mak
@@ -0,0 +1,3 @@
+# s390 31bit mode
+LIBDIR := /lib
+libkvm-$(ARCH)-objs := libkvm-s390.o
Index: kvm-userspace/libkvm/config-s390x.mak
===================================================================
--- /dev/null
+++ kvm-userspace/libkvm/config-s390x.mak
@@ -0,0 +1,3 @@
+# s390 64 bit mode (arch=s390x)
+LIBDIR := /lib64
+libkvm-$(ARCH)-objs := libkvm-s390.o
Index: kvm-userspace/libkvm/kvm-common.h
===================================================================
--- kvm-userspace.orig/libkvm/kvm-common.h
+++ kvm-userspace/libkvm/kvm-common.h
@@ -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;
Index: kvm-userspace/libkvm/kvm-s390.h
===================================================================
--- /dev/null
+++ kvm-userspace/libkvm/kvm-s390.h
@@ -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 <avi@qumranet.com>
+ * Yaniv Kamay <yaniv@qumranet.com>
+ *
+ * Copyright 2008 IBM Corporation.
+ * Authors:
+ * Carsten Otte <cotte@de.ibm.com>
+ *
+ * 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
Index: kvm-userspace/libkvm/libkvm-s390.c
===================================================================
--- /dev/null
+++ kvm-userspace/libkvm/libkvm-s390.c
@@ -0,0 +1,137 @@
+/*
+ * 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 <cotte@de.ibm.com>
+ * Christian Borntraeger <borntraeger@de.ibm.com>
+ *
+ * This work is licensed under the GNU LGPL license, version 2.
+ */
+
+#include <sys/ioctl.h>
+#include <asm/ptrace.h>
+
+#include "libkvm.h"
+#include "kvm-common.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;
+ struct kvm_sregs sregs;
+ int i;
+
+ if (kvm_get_regs(kvm, vcpu, ®s))
+ return;
+
+ if (kvm_get_sregs(kvm, vcpu, &sregs))
+ return;
+
+ fprintf(stderr, "guest vcpu #%d\n", vcpu);
+ fprintf(stderr, "PSW:\t%16.16lx %16.16lx\n",
+ kvm->run[vcpu]->s390_sieic.mask,
+ kvm->run[vcpu]->s390_sieic.addr);
+ fprintf(stderr,"GPRS:");
+ for (i=0; i<15; i+=4)
+ fprintf(stderr, "\t%16.16lx %16.16lx %16.16lx %16.16lx\n",
+ regs.gprs[i],
+ regs.gprs[i+1],
+ regs.gprs[i+2],
+ regs.gprs[i+3]);
+ fprintf(stderr,"ACRS:");
+ for (i=0; i<15; i+=4)
+ fprintf(stderr, "\t%8.8x %8.8x %8.8x %8.8x\n",
+ sregs.acrs[i],
+ sregs.acrs[i+1],
+ sregs.acrs[i+2],
+ sregs.acrs[i+3]);
+
+ fprintf(stderr,"CRS:");
+ for (i=0; i<15; i+=4)
+ fprintf(stderr, "\t%16.16lx %16.16lx %16.16lx %16.16lx\n",
+ sregs.crs[i],
+ sregs.crs[i+1],
+ sregs.crs[i+2],
+ sregs.crs[i+3]);
+}
+
+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;
+}
+
+int kvm_s390_initial_reset(kvm_context_t kvm, int slot)
+{
+ return ioctl(kvm->vcpu_fd[slot], KVM_S390_INITIAL_RESET, NULL);
+}
+
+int kvm_s390_interrupt(kvm_context_t kvm, int slot,
+ struct kvm_s390_interrupt *kvmint)
+{
+ if (slot>=0)
+ return ioctl(kvm->vcpu_fd[slot], KVM_S390_INTERRUPT, kvmint);
+ else
+ return ioctl(kvm->vm_fd, KVM_S390_INTERRUPT, kvmint);
+}
+
+int kvm_s390_set_initial_psw(kvm_context_t kvm, int slot, psw_t psw)
+{
+ return ioctl(kvm->vcpu_fd[slot], KVM_S390_SET_INITIAL_PSW, &psw);
+}
+
+int kvm_s390_store_status(kvm_context_t kvm, int slot, unsigned long addr)
+{
+ return ioctl(kvm->vcpu_fd[slot], KVM_S390_STORE_STATUS, addr);
+}
Index: kvm-userspace/libkvm/libkvm.c
===================================================================
--- kvm-userspace.orig/libkvm/libkvm.c
+++ kvm-userspace/libkvm/libkvm.c
@@ -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",
Index: kvm-userspace/libkvm/libkvm.h
===================================================================
--- kvm-userspace.orig/libkvm/libkvm.h
+++ kvm-userspace/libkvm/libkvm.h
@@ -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
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH v2/RFC] libkvm-s390
2008-07-16 15:28 ` [PATCH v2/RFC] libkvm-s390 Christian Borntraeger
@ 2008-07-17 11:08 ` Christian Ehrhardt
2008-07-17 15:28 ` [PATCH v3] libkvm-s390 Christian Borntraeger
0 siblings, 1 reply; 12+ messages in thread
From: Christian Ehrhardt @ 2008-07-17 11:08 UTC (permalink / raw)
To: Christian Borntraeger
Cc: Avi Kivity, Carsten Otte, kvm, Olaf Schnapper, Hollis Blanchard
Christian Borntraeger wrote:
> This is an update patch for libkvm to build and work on s390
[...]
> Index: kvm-userspace/libkvm/libkvm-s390.c
> ===================================================================
> --- /dev/null
> +++ kvm-userspace/libkvm/libkvm-s390.c
> @@ -0,0 +1,137 @@
> +/*
> + * 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 <cotte@de.ibm.com>
> + * Christian Borntraeger <borntraeger@de.ibm.com>
>
whitespace error - well just in the comment, but if you resubmit it
anyway this space could be removed ;-)
[...]
> +
> +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.
[...]
> Index: kvm-userspace/libkvm/libkvm.c
> ===================================================================
> --- kvm-userspace.orig/libkvm/libkvm.c
> +++ kvm-userspace/libkvm/libkvm.c
> @@ -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
>
>
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.
[...]
--
Grüsse / regards,
Christian Ehrhardt
IBM Linux Technology Center, Open Virtualization
^ permalink raw reply [flat|nested] 12+ messages in thread* [PATCH v3] libkvm-s390
2008-07-17 11:08 ` Christian Ehrhardt
@ 2008-07-17 15:28 ` Christian Borntraeger
2008-07-19 7:56 ` Avi Kivity
0 siblings, 1 reply; 12+ messages in thread
From: Christian Borntraeger @ 2008-07-17 15:28 UTC (permalink / raw)
To: Avi Kivity
Cc: Christian Ehrhardt, Carsten Otte, kvm, Olaf Schnapper,
Hollis Blanchard
From: Carsten Otte <cotte@de.ibm.com>
From: Christian Borntraeger <borntraeger@de.ibm.com>
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.
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
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(-)
Index: kvm-userspace/Makefile
===================================================================
--- kvm-userspace.orig/Makefile
+++ kvm-userspace/Makefile
@@ -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
Index: kvm-userspace/libkvm/config-s390.mak
===================================================================
--- /dev/null
+++ kvm-userspace/libkvm/config-s390.mak
@@ -0,0 +1,3 @@
+# s390 31bit mode
+LIBDIR := /lib
+libkvm-$(ARCH)-objs := libkvm-s390.o
Index: kvm-userspace/libkvm/config-s390x.mak
===================================================================
--- /dev/null
+++ kvm-userspace/libkvm/config-s390x.mak
@@ -0,0 +1,3 @@
+# s390 64 bit mode (arch=s390x)
+LIBDIR := /lib64
+libkvm-$(ARCH)-objs := libkvm-s390.o
Index: kvm-userspace/libkvm/kvm-common.h
===================================================================
--- kvm-userspace.orig/libkvm/kvm-common.h
+++ kvm-userspace/libkvm/kvm-common.h
@@ -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;
Index: kvm-userspace/libkvm/kvm-s390.h
===================================================================
--- /dev/null
+++ kvm-userspace/libkvm/kvm-s390.h
@@ -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 <avi@qumranet.com>
+ * Yaniv Kamay <yaniv@qumranet.com>
+ *
+ * Copyright 2008 IBM Corporation.
+ * Authors:
+ * Carsten Otte <cotte@de.ibm.com>
+ *
+ * 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
Index: kvm-userspace/libkvm/libkvm-s390.c
===================================================================
--- /dev/null
+++ kvm-userspace/libkvm/libkvm-s390.c
@@ -0,0 +1,131 @@
+/*
+ * 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 <cotte@de.ibm.com>
+ * Christian Borntraeger <borntraeger@de.ibm.com>
+ *
+ * This work is licensed under the GNU LGPL license, version 2.
+ */
+
+#include <sys/ioctl.h>
+#include <asm/ptrace.h>
+
+#include "libkvm.h"
+#include "kvm-common.h"
+#include <errno.h>
+#include <stdio.h>
+#include <inttypes.h>
+
+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;
+ struct kvm_sregs sregs;
+ int i;
+
+ if (kvm_get_regs(kvm, vcpu, ®s))
+ return;
+
+ if (kvm_get_sregs(kvm, vcpu, &sregs))
+ return;
+
+ fprintf(stderr, "guest vcpu #%d\n", vcpu);
+ fprintf(stderr, "PSW:\t%16.16lx %16.16lx\n",
+ kvm->run[vcpu]->s390_sieic.mask,
+ kvm->run[vcpu]->s390_sieic.addr);
+ fprintf(stderr,"GPRS:");
+ for (i=0; i<15; i+=4)
+ fprintf(stderr, "\t%16.16lx %16.16lx %16.16lx %16.16lx\n",
+ regs.gprs[i],
+ regs.gprs[i+1],
+ regs.gprs[i+2],
+ regs.gprs[i+3]);
+ fprintf(stderr,"ACRS:");
+ for (i=0; i<15; i+=4)
+ fprintf(stderr, "\t%8.8x %8.8x %8.8x %8.8x\n",
+ sregs.acrs[i],
+ sregs.acrs[i+1],
+ sregs.acrs[i+2],
+ sregs.acrs[i+3]);
+
+ fprintf(stderr,"CRS:");
+ for (i=0; i<15; i+=4)
+ fprintf(stderr, "\t%16.16lx %16.16lx %16.16lx %16.16lx\n",
+ sregs.crs[i],
+ sregs.crs[i+1],
+ sregs.crs[i+2],
+ sregs.crs[i+3]);
+}
+
+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;
+}
+
+int kvm_s390_initial_reset(kvm_context_t kvm, int slot)
+{
+ return ioctl(kvm->vcpu_fd[slot], KVM_S390_INITIAL_RESET, NULL);
+}
+
+int kvm_s390_interrupt(kvm_context_t kvm, int slot,
+ struct kvm_s390_interrupt *kvmint)
+{
+ if (slot>=0)
+ return ioctl(kvm->vcpu_fd[slot], KVM_S390_INTERRUPT, kvmint);
+ else
+ return ioctl(kvm->vm_fd, KVM_S390_INTERRUPT, kvmint);
+}
+
+int kvm_s390_set_initial_psw(kvm_context_t kvm, int slot, psw_t psw)
+{
+ return ioctl(kvm->vcpu_fd[slot], KVM_S390_SET_INITIAL_PSW, &psw);
+}
+
+int kvm_s390_store_status(kvm_context_t kvm, int slot, unsigned long addr)
+{
+ return ioctl(kvm->vcpu_fd[slot], KVM_S390_STORE_STATUS, addr);
+}
Index: kvm-userspace/libkvm/libkvm.c
===================================================================
--- kvm-userspace.orig/libkvm/libkvm.c
+++ kvm-userspace/libkvm/libkvm.c
@@ -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",
Index: kvm-userspace/libkvm/libkvm.h
===================================================================
--- kvm-userspace.orig/libkvm/libkvm.h
+++ kvm-userspace/libkvm/libkvm.h
@@ -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
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH v3] libkvm-s390
2008-07-17 15:28 ` [PATCH v3] libkvm-s390 Christian Borntraeger
@ 2008-07-19 7:56 ` Avi Kivity
0 siblings, 0 replies; 12+ messages in thread
From: Avi Kivity @ 2008-07-19 7:56 UTC (permalink / raw)
To: Christian Borntraeger
Cc: Christian Ehrhardt, Carsten Otte, kvm, Olaf Schnapper,
Hollis Blanchard
Christian Borntraeger wrote:
> From: Carsten Otte <cotte@de.ibm.com>
> From: Christian Borntraeger <borntraeger@de.ibm.com>
>
> 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.
--
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
^ permalink raw reply [flat|nested] 12+ messages in thread