From: Avi Kivity <avi@qumranet.com>
To: kvm-devel@lists.sourceforge.net
Cc: linux-kernel@vger.kernel.org, Carsten Otte <cotte@de.ibm.com>
Subject: [PATCH 07/45] KVM: s390: sie intercept handling
Date: Thu, 17 Apr 2008 12:10:12 +0300 [thread overview]
Message-ID: <1208423450-29415-8-git-send-email-avi@qumranet.com> (raw)
In-Reply-To: <1208423450-29415-1-git-send-email-avi@qumranet.com>
From: Carsten Otte <cotte@de.ibm.com>
From: Christian Borntraeger <borntraeger@de.ibm.com>
This path introduces handling of sie intercepts in three flavors: Intercepts
are either handled completely in-kernel by kvm_handle_sie_intercept(),
or passed to userspace with corresponding data in struct kvm_run in case
kvm_handle_sie_intercept() returns -ENOTSUPP.
In case of partial execution in kernel with the need of userspace support,
kvm_handle_sie_intercept() may choose to set up struct kvm_run and return
-EREMOTE.
The trivial intercept reasons are handled in this patch:
handle_noop() just does nothing for intercepts that don't require our support
at all
handle_stop() is called when a cpu enters stopped state, and it drops out to
userland after updating our vcpu state
handle_validity() faults in the cpu lowcore if needed, or passes the request
to userland
Acked-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
Signed-off-by: Carsten Otte <cotte@de.ibm.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
---
arch/s390/kvm/Makefile | 2 +-
arch/s390/kvm/intercept.c | 80 +++++++++++++++++++++++++++++++++++++++++++
arch/s390/kvm/kvm-s390.c | 46 ++++++++++++++++++++++++-
arch/s390/kvm/kvm-s390.h | 7 ++++
include/asm-s390/kvm_host.h | 4 ++
include/linux/kvm.h | 9 +++++
6 files changed, 146 insertions(+), 2 deletions(-)
create mode 100644 arch/s390/kvm/intercept.c
diff --git a/arch/s390/kvm/Makefile b/arch/s390/kvm/Makefile
index 0d8d113..27882b3 100644
--- a/arch/s390/kvm/Makefile
+++ b/arch/s390/kvm/Makefile
@@ -10,5 +10,5 @@ common-objs = $(addprefix ../../../virt/kvm/, kvm_main.o)
EXTRA_CFLAGS += -Ivirt/kvm -Iarch/s390/kvm
-kvm-objs := $(common-objs) kvm-s390.o sie64a.o
+kvm-objs := $(common-objs) kvm-s390.o sie64a.o intercept.o
obj-$(CONFIG_KVM) += kvm.o
diff --git a/arch/s390/kvm/intercept.c b/arch/s390/kvm/intercept.c
new file mode 100644
index 0000000..e757230
--- /dev/null
+++ b/arch/s390/kvm/intercept.c
@@ -0,0 +1,80 @@
+/*
+ * intercept.c - in-kernel handling for sie intercepts
+ *
+ * Copyright IBM Corp. 2008
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License (version 2 only)
+ * as published by the Free Software Foundation.
+ *
+ * Author(s): Carsten Otte <cotte@de.ibm.com>
+ * Christian Borntraeger <borntraeger@de.ibm.com>
+ */
+
+#include <linux/kvm_host.h>
+#include <linux/errno.h>
+#include <linux/pagemap.h>
+
+#include <asm/kvm_host.h>
+
+#include "kvm-s390.h"
+
+static int handle_noop(struct kvm_vcpu *vcpu)
+{
+ switch (vcpu->arch.sie_block->icptcode) {
+ case 0x10:
+ vcpu->stat.exit_external_request++;
+ break;
+ case 0x14:
+ vcpu->stat.exit_external_interrupt++;
+ break;
+ default:
+ break; /* nothing */
+ }
+ return 0;
+}
+
+static int handle_stop(struct kvm_vcpu *vcpu)
+{
+ vcpu->stat.exit_stop_request++;
+ VCPU_EVENT(vcpu, 3, "%s", "cpu stopped");
+ atomic_clear_mask(CPUSTAT_RUNNING, &vcpu->arch.sie_block->cpuflags);
+ return -ENOTSUPP;
+}
+
+static int handle_validity(struct kvm_vcpu *vcpu)
+{
+ int viwhy = vcpu->arch.sie_block->ipb >> 16;
+ vcpu->stat.exit_validity++;
+ if (viwhy == 0x37) {
+ fault_in_pages_writeable((char __user *)
+ vcpu->kvm->arch.guest_origin +
+ vcpu->arch.sie_block->prefix,
+ PAGE_SIZE);
+ return 0;
+ }
+ VCPU_EVENT(vcpu, 2, "unhandled validity intercept code %d",
+ viwhy);
+ return -ENOTSUPP;
+}
+
+static const intercept_handler_t intercept_funcs[0x48 >> 2] = {
+ [0x00 >> 2] = handle_noop,
+ [0x10 >> 2] = handle_noop,
+ [0x14 >> 2] = handle_noop,
+ [0x20 >> 2] = handle_validity,
+ [0x28 >> 2] = handle_stop,
+};
+
+int kvm_handle_sie_intercept(struct kvm_vcpu *vcpu)
+{
+ intercept_handler_t func;
+ u8 code = vcpu->arch.sie_block->icptcode;
+
+ if (code & 3 || code > 0x48)
+ return -ENOTSUPP;
+ func = intercept_funcs[code >> 2];
+ if (func)
+ return func(vcpu);
+ return -ENOTSUPP;
+}
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index 6e1e1d3..a906499 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -23,12 +23,17 @@
#include <asm/lowcore.h>
#include <asm/pgtable.h>
+#include "kvm-s390.h"
#include "gaccess.h"
#define VCPU_STAT(x) offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU
struct kvm_stats_debugfs_item debugfs_entries[] = {
{ "userspace_handled", VCPU_STAT(exit_userspace) },
+ { "exit_validity", VCPU_STAT(exit_validity) },
+ { "exit_stop_request", VCPU_STAT(exit_stop_request) },
+ { "exit_external_request", VCPU_STAT(exit_external_request) },
+ { "exit_external_interrupt", VCPU_STAT(exit_external_interrupt) },
{ NULL }
};
@@ -380,6 +385,7 @@ static void __vcpu_run(struct kvm_vcpu *vcpu)
int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
{
+ int rc;
sigset_t sigsaved;
vcpu_load(vcpu);
@@ -389,7 +395,45 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
atomic_set_mask(CPUSTAT_RUNNING, &vcpu->arch.sie_block->cpuflags);
- __vcpu_run(vcpu);
+ 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_S390_RESET:
+ break;
+ default:
+ BUG();
+ }
+
+ might_sleep();
+
+ do {
+ __vcpu_run(vcpu);
+
+ rc = kvm_handle_sie_intercept(vcpu);
+ } while (!signal_pending(current) && !rc);
+
+ if (signal_pending(current) && !rc)
+ rc = -EINTR;
+
+ if (rc == -ENOTSUPP) {
+ /* 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;
+ }
+
+ if (rc == -EREMOTE) {
+ /* intercept was handled, but userspace support is needed
+ * kvm_run has been prepared by the handler */
+ rc = 0;
+ }
if (vcpu->sigset_active)
sigprocmask(SIG_SETMASK, &sigsaved, NULL);
diff --git a/arch/s390/kvm/kvm-s390.h b/arch/s390/kvm/kvm-s390.h
index ed64a22..5b82527 100644
--- a/arch/s390/kvm/kvm-s390.h
+++ b/arch/s390/kvm/kvm-s390.h
@@ -13,6 +13,13 @@
#ifndef ARCH_S390_KVM_S390_H
#define ARCH_S390_KVM_S390_H
+
+#include <linux/kvm_host.h>
+
+typedef int (*intercept_handler_t)(struct kvm_vcpu *vcpu);
+
+int kvm_handle_sie_intercept(struct kvm_vcpu *vcpu);
+
#define VM_EVENT(d_kvm, d_loglevel, d_string, d_args...)\
do { \
debug_sprintf_event(d_kvm->arch.dbf, d_loglevel, d_string "\n", \
diff --git a/include/asm-s390/kvm_host.h b/include/asm-s390/kvm_host.h
index c9d6533..8965b38 100644
--- a/include/asm-s390/kvm_host.h
+++ b/include/asm-s390/kvm_host.h
@@ -101,6 +101,10 @@ struct sie_block {
struct kvm_vcpu_stat {
u32 exit_userspace;
+ u32 exit_external_request;
+ u32 exit_external_interrupt;
+ u32 exit_stop_request;
+ u32 exit_validity;
};
struct kvm_vcpu_arch {
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index 2367ff0..f2acd6b 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -74,6 +74,7 @@ struct kvm_irqchip {
#define KVM_EXIT_INTR 10
#define KVM_EXIT_SET_TPR 11
#define KVM_EXIT_TPR_ACCESS 12
+#define KVM_EXIT_S390_SIEIC 13
/* for KVM_RUN, returned by mmap(vcpu_fd, offset=0) */
struct kvm_run {
@@ -138,6 +139,14 @@ struct kvm_run {
__u32 is_write;
__u32 pad;
} tpr_access;
+ /* KVM_EXIT_S390_SIEIC */
+ struct {
+ __u8 icptcode;
+ __u64 mask; /* psw upper half */
+ __u64 addr; /* psw lower half */
+ __u16 ipa;
+ __u32 ipb;
+ } s390_sieic;
/* Fix the size of the union. */
char padding[256];
};
--
1.5.5
next prev parent reply other threads:[~2008-04-17 9:13 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-04-17 9:10 [PATCH 00/45] KVM updates for the 2.6.26 merge window (part III) Avi Kivity
2008-04-17 9:10 ` [PATCH 01/45] s390: fixup for kvm Avi Kivity
2008-04-17 9:10 ` [PATCH 02/45] s390: KVM preparation: provide hook to enable pgstes in user pagetable Avi Kivity
2008-04-17 9:10 ` [PATCH 03/45] s390: KVM preparation: host memory management changes for s390 kvm Avi Kivity
2008-04-17 9:10 ` [PATCH 04/45] s390: KVM preparation: address of the 64bit extint parm in lowcore Avi Kivity
2008-04-17 9:10 ` [PATCH 05/45] s390: KVM preparation: split sysinfo defintions for kvm use Avi Kivity
2008-04-17 9:10 ` [PATCH 06/45] KVM: s390: arch backend for the kvm kernel module Avi Kivity
2008-04-17 9:10 ` Avi Kivity [this message]
2008-04-17 9:10 ` [PATCH 08/45] KVM: s390: interrupt subsystem, cpu timer, waitpsw Avi Kivity
2008-04-17 9:10 ` [PATCH 09/45] KVM: s390: intercepts for privileged instructions Avi Kivity
2008-04-17 9:10 ` [PATCH 10/45] KVM: s390: interprocessor communication via sigp Avi Kivity
2008-04-17 9:10 ` [PATCH 11/45] KVM: s390: intercepts for diagnose instructions Avi Kivity
2008-04-17 9:10 ` [PATCH 12/45] KVM: s390: add kvm to kconfig on s390 Avi Kivity
2008-04-17 9:10 ` [PATCH 13/45] KVM: s390: API documentation Avi Kivity
2008-04-17 15:11 ` Randy Dunlap
2008-04-17 15:42 ` Carsten Otte
2008-04-17 9:10 ` [PATCH 14/45] KVM: s390: update maintainers Avi Kivity
2008-04-17 9:10 ` [PATCH 15/45] s390: KVM guest: detect when running on kvm Avi Kivity
2008-04-17 9:10 ` [PATCH 16/45] s390: KVM guest: virtio device support, and kvm hypercalls Avi Kivity
2008-04-17 9:10 ` [PATCH 17/45] KVM: VMX: Enable MSR Bitmap feature Avi Kivity
2008-04-17 9:10 ` [PATCH 18/45] KVM: MMU: unify slots_lock usage Avi Kivity
2008-04-17 9:10 ` [PATCH 19/45] KVM: MMU: allow the vm to shrink the kvm mmu shadow caches Avi Kivity
2008-04-17 9:10 ` [PATCH 20/45] KVM: Free apic access page on vm destruction Avi Kivity
2008-04-17 9:10 ` [PATCH 21/45] KVM: function declaration parameter name cleanup Avi Kivity
2008-04-17 9:10 ` [PATCH 22/45] KVM: add vm refcounting Avi Kivity
2008-04-17 9:10 ` [PATCH 23/45] KVM: MMU: Only mark_page_accessed() if the page was accessed by the guest Avi Kivity
2008-04-17 9:10 ` [PATCH 24/45] KVM: MMU: prepopulate guest pages after write-protecting Avi Kivity
2008-04-17 9:10 ` [PATCH 25/45] KVM: s390: Fix incorrect return value Avi Kivity
2008-04-17 9:10 ` [PATCH 26/45] KVM: s390: rename stfl to kvm_stfl Avi Kivity
2008-04-17 9:10 ` [PATCH 27/45] KVM: s390: Improve pgste accesses Avi Kivity
2008-04-17 9:10 ` [PATCH 28/45] ia64: Add API for allocating Dynamic TR resource Avi Kivity
2008-04-17 9:10 ` [PATCH 29/45] ia64: Implement smp_call_function_mask for ia64 Avi Kivity
2008-04-17 9:10 ` [PATCH 30/45] KVM: ia64: Prepare some structure and routines for kvm use Avi Kivity
2008-04-17 9:10 ` [PATCH 31/45] KVM: ia64: Add header files for kvm/ia64 Avi Kivity
2008-04-17 9:10 ` [PATCH 32/45] KVM: ia64: Add kvm arch-specific core code " Avi Kivity
2008-04-17 9:10 ` [PATCH 33/45] KVM: ia64: Add header files " Avi Kivity
2008-04-17 9:10 ` [PATCH 34/45] KVM: ia64: VMM module interfaces Avi Kivity
2008-04-17 9:10 ` [PATCH 35/45] KVM: ia64: Add TLB virtulization support Avi Kivity
2008-04-17 9:10 ` [PATCH 36/45] KVM: ia64: Add interruption vector table for vmm Avi Kivity
2008-04-17 9:10 ` [PATCH 37/45] KVM: ia64: Add mmio decoder for kvm/ia64 Avi Kivity
2008-04-17 9:10 ` [PATCH 38/45] KVM: ia64: Add trampoline for guest/host mode switch Avi Kivity
2008-04-17 9:10 ` [PATCH 39/45] KVM: ia64: Add processor virtulization support Avi Kivity
2008-04-17 9:10 ` [PATCH 40/45] KVM: ia64: Add optimization for some virtulization faults Avi Kivity
2008-04-17 9:10 ` [PATCH 41/45] KVM: ia64: Generate offset values for assembly code use Avi Kivity
2008-04-17 9:10 ` [PATCH 42/45] KVM: ia64: Add guest interruption injection support Avi Kivity
2008-04-17 9:10 ` [PATCH 43/45] KVM: ia64: Add kvm sal/pal virtulization support Avi Kivity
2008-04-17 9:10 ` [PATCH 44/45] KVM: ia64: Enable kvm build for ia64 Avi Kivity
2008-04-17 9:10 ` [PATCH 45/45] KVM: ia64: Add a guide about how to create kvm guests on ia64 Avi Kivity
2008-04-17 15:15 ` Randy Dunlap
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=1208423450-29415-8-git-send-email-avi@qumranet.com \
--to=avi@qumranet.com \
--cc=cotte@de.ibm.com \
--cc=kvm-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
/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
all inboxes | Powered by JetHome®