public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Christian Borntraeger <borntraeger@de.ibm.com>
To: Avi Kivity <avi@qumranet.com>
Cc: Carsten Otte <cotte@de.ibm.com>, kvm <kvm@vger.kernel.org>,
	Olaf Schnapper <os@de.ibm.com>,
	Hollis Blanchard <hollisb@us.ibm.com>
Subject: [PATCH v2/RFC] libkvm-s390
Date: Wed, 16 Jul 2008 17:28:58 +0200	[thread overview]
Message-ID: <200807161728.58658.borntraeger@de.ibm.com> (raw)
In-Reply-To: <1215797386.6014.4.camel@cotte.boeblingen.de.ibm.com>

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, &regs))
+		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

  parent reply	other threads:[~2008-07-16 15:29 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 11:44     ` Avi Kivity
2008-07-14 12:25       ` Christian Borntraeger
2008-07-14 15:34 ` Anthony Liguori
2008-07-14 17:00   ` Christian Borntraeger
2008-07-14 18:00     ` Anthony Liguori
2008-07-16 15:28 ` Christian Borntraeger [this message]
2008-07-17 11:08   ` [PATCH v2/RFC] libkvm-s390 Christian Ehrhardt
2008-07-17 15:28     ` [PATCH v3] libkvm-s390 Christian Borntraeger
2008-07-19  7:56       ` Avi Kivity

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200807161728.58658.borntraeger@de.ibm.com \
    --to=borntraeger@de.ibm.com \
    --cc=avi@qumranet.com \
    --cc=cotte@de.ibm.com \
    --cc=hollisb@us.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=os@de.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox