public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: ehrhardt@linux.vnet.ibm.com
To: kvm@vger.kernel.org, avi@redhat.com
Cc: ehrhardt@linux.vnet.ibm.com, borntraeger@de.ibm.com,
	cotte@de.ibm.com, heiko.carstens@de.ibm.com,
	schwidefsky@de.ibm.com, mtosatti@redhat.com
Subject: [PATCH 1/3] kvm-s390: infrastructure to kick vcpus out of guest state - rebased
Date: Tue,  2 Jun 2009 16:26:09 +0200	[thread overview]
Message-ID: <1243952771-32428-2-git-send-email-ehrhardt@linux.vnet.ibm.com> (raw)
In-Reply-To: <1243952771-32428-1-git-send-email-ehrhardt@linux.vnet.ibm.com>

From: Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com>

As requested this is a rebased patch on top of the already applied v3
of the patch series.

*updates to already applied version*
- ensure allocations (might_sleep) are out of atomic context
- centralize consumption of vcpu->request bits

To ensure vcpu's come out of guest context in certain cases this patch adds a
s390 specific way to kick them out of guest context. Currently it kicks them
out to rerun the vcpu_run path in the s390 code, but the mechanism itself is
expandable and with a new flag we could also add e.g. kicks to userspace etc.

Signed-off-by: Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com>
---

[diffstat]
 include/asm/kvm_host.h |    2 +-
 kvm/intercept.c        |   10 ++++++----
 kvm/kvm-s390.c         |    7 +++----
 kvm/kvm-s390.h         |   16 +++++++++++++++-
 kvm/sigp.c             |   31 +++++++++++++++++++++----------
 5 files changed, 46 insertions(+), 20 deletions(-)

Index: kvm/arch/s390/kvm/intercept.c
===================================================================
--- kvm.orig/arch/s390/kvm/intercept.c
+++ kvm/arch/s390/kvm/intercept.c
@@ -141,10 +141,12 @@ static int handle_stop(struct kvm_vcpu *
 			rc = -ENOTSUPP;
 	}
 
-	if (vcpu->arch.local_int.action_bits & ACTION_RELOADVCPU_ON_STOP) {
-		vcpu->arch.local_int.action_bits &= ~ACTION_RELOADVCPU_ON_STOP;
-		rc = SIE_INTERCEPT_RERUNVCPU;
-		vcpu->run->exit_reason = KVM_EXIT_INTR;
+	if (vcpu->arch.local_int.action_bits & ACTION_VCPUREQUEST_ON_STOP) {
+		vcpu->arch.local_int.action_bits &= ~ACTION_VCPUREQUEST_ON_STOP;
+		if (kvm_s390_handle_vcpu_requests(vcpu, VCPUREQUESTLVL_SIGP)) {
+			rc = SIE_INTERCEPT_CHECKREQUESTS;
+			vcpu->run->exit_reason = KVM_EXIT_INTR;
+		}
 	}
 
 	if (vcpu->arch.local_int.action_bits & ACTION_STOP_ON_STOP) {
Index: kvm/arch/s390/include/asm/kvm_host.h
===================================================================
--- kvm.orig/arch/s390/include/asm/kvm_host.h
+++ kvm/arch/s390/include/asm/kvm_host.h
@@ -182,7 +182,7 @@ struct kvm_s390_interrupt_info {
 /* for local_interrupt.action_flags */
 #define ACTION_STORE_ON_STOP		(1<<0)
 #define ACTION_STOP_ON_STOP		(1<<1)
-#define ACTION_RELOADVCPU_ON_STOP	(1<<2)
+#define ACTION_VCPUREQUEST_ON_STOP	(1<<2)
 
 struct kvm_s390_local_interrupt {
 	spinlock_t lock;
Index: kvm/arch/s390/kvm/kvm-s390.c
===================================================================
--- kvm.orig/arch/s390/kvm/kvm-s390.c
+++ kvm/arch/s390/kvm/kvm-s390.c
@@ -484,8 +484,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_v
 
 rerun_vcpu:
 	if (vcpu->requests)
-		if (test_and_clear_bit(KVM_REQ_MMU_RELOAD, &vcpu->requests))
-			kvm_s390_vcpu_set_mem(vcpu);
+		kvm_s390_handle_vcpu_requests(vcpu, VCPUREQUESTLVL_VCPURUN);
 
 	/* verify, that memory has been registered */
 	if (!vcpu->arch.sie_block->gmslm) {
@@ -521,7 +520,7 @@ rerun_vcpu:
 		rc = kvm_handle_sie_intercept(vcpu);
 	} while (!signal_pending(current) && !rc);
 
-	if (rc == SIE_INTERCEPT_RERUNVCPU)
+	if (rc == SIE_INTERCEPT_CHECKREQUESTS)
 		goto rerun_vcpu;
 
 	if (signal_pending(current) && !rc) {
@@ -710,7 +709,7 @@ int kvm_arch_set_memory_region(struct kv
 						&kvm->vcpus[i]->requests))
 				continue;
 			kvm_s390_inject_sigp_stop(kvm->vcpus[i],
-						  ACTION_RELOADVCPU_ON_STOP);
+						  ACTION_VCPUREQUEST_ON_STOP);
 		}
 	}
 
Index: kvm/arch/s390/kvm/kvm-s390.h
===================================================================
--- kvm.orig/arch/s390/kvm/kvm-s390.h
+++ kvm/arch/s390/kvm/kvm-s390.h
@@ -25,7 +25,7 @@
 typedef int (*intercept_handler_t)(struct kvm_vcpu *vcpu);
 
 /* negativ values are error codes, positive values for internal conditions */
-#define SIE_INTERCEPT_RERUNVCPU		(1<<0)
+#define SIE_INTERCEPT_CHECKREQUESTS		(1<<0)
 int kvm_handle_sie_intercept(struct kvm_vcpu *vcpu);
 
 #define VM_EVENT(d_kvm, d_loglevel, d_string, d_args...)\
@@ -81,6 +81,20 @@ static inline void kvm_s390_vcpu_set_mem
 	up_read(&vcpu->kvm->slots_lock);
 }
 
+/* interception levels from which handle vcpu requests can be called */
+#define VCPUREQUESTLVL_SIGP		1
+#define VCPUREQUESTLVL_VCPURUN		2
+static inline unsigned long kvm_s390_handle_vcpu_requests(struct kvm_vcpu *vcpu,
+						   int level)
+{
+	BUG_ON(!level);
+
+	if (!vcpu->requests)
+		return 0;
+
+	return vcpu->requests;
+}
+
 /* implemented in priv.c */
 int kvm_s390_handle_b2(struct kvm_vcpu *vcpu);
 
Index: kvm/arch/s390/kvm/sigp.c
===================================================================
--- kvm.orig/arch/s390/kvm/sigp.c
+++ kvm/arch/s390/kvm/sigp.c
@@ -108,15 +108,9 @@ unlock:
 	return rc;
 }
 
-static int __inject_sigp_stop(struct kvm_s390_local_interrupt *li, int action)
+static int __inject_sigp_stop(struct kvm_s390_local_interrupt *li, int action,
+			      struct kvm_s390_interrupt_info *inti)
 {
-	struct kvm_s390_interrupt_info *inti;
-
-	inti = kzalloc(sizeof(*inti), GFP_KERNEL);
-	if (!inti)
-		return -ENOMEM;
-	inti->type = KVM_S390_SIGP_STOP;
-
 	spin_lock_bh(&li->lock);
 	list_add_tail(&inti->list, &li->list);
 	atomic_set(&li->active, 1);
@@ -133,11 +127,17 @@ static int __sigp_stop(struct kvm_vcpu *
 {
 	struct kvm_s390_float_interrupt *fi = &vcpu->kvm->arch.float_int;
 	struct kvm_s390_local_interrupt *li;
+	struct kvm_s390_interrupt_info *inti;
 	int rc;
 
 	if (cpu_addr >= KVM_MAX_VCPUS)
 		return 3; /* not operational */
 
+	inti = kzalloc(sizeof(*inti), GFP_KERNEL);
+	if (!inti)
+		return -ENOMEM;
+	inti->type = KVM_S390_SIGP_STOP;
+
 	spin_lock(&fi->lock);
 	li = fi->local_int[cpu_addr];
 	if (li == NULL) {
@@ -145,7 +145,7 @@ static int __sigp_stop(struct kvm_vcpu *
 		goto unlock;
 	}
 
-	rc = __inject_sigp_stop(li, action);
+	rc = __inject_sigp_stop(li, action, inti);
 
 unlock:
 	spin_unlock(&fi->lock);
@@ -156,7 +156,18 @@ unlock:
 int kvm_s390_inject_sigp_stop(struct kvm_vcpu *vcpu, int action)
 {
 	struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
-	return __inject_sigp_stop(li, action);
+	struct kvm_s390_interrupt_info *inti;
+	int rc;
+
+	inti = kzalloc(sizeof(*inti), GFP_KERNEL);
+	if (!inti)
+		return -ENOMEM;
+	inti->type = KVM_S390_SIGP_STOP;
+
+	rc = __inject_sigp_stop(li, action, inti);
+	if (rc)
+		kfree(inti);
+	return rc;
 }
 
 static int __sigp_set_arch(struct kvm_vcpu *vcpu, u32 parameter)

  reply	other threads:[~2009-06-02 14:26 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-02 14:26 [PATCH 0/3] kvm-s390: revised version of kvm-s390 guest memory handling - rebased ehrhardt
2009-06-02 14:26 ` ehrhardt [this message]
2009-06-02 14:26 ` [PATCH 2/3] kvm-s390: update vcpu->cpu " ehrhardt
2009-06-02 14:26 ` [PATCH 3/3] kvm-s390: streamline memslot handling " ehrhardt
2009-06-05 20:53   ` Marcelo Tosatti
2009-06-08 10:51     ` Christian Ehrhardt
2009-06-08 11:10       ` Avi Kivity
2009-06-08 12:05         ` Christian Ehrhardt
2009-06-08 12:09           ` Avi Kivity
2009-06-09  0:56       ` Marcelo Tosatti
2009-06-14 12:04         ` Avi Kivity
2009-06-15 13:47           ` Christian Ehrhardt
  -- strict thread matches above, loose matches on Subject: below --
2009-06-15 13:47 [PATCH 0/3] kvm-s390: revised version of kvm-s390 guest memory handling - rebased v2 ehrhardt
2009-06-15 13:47 ` [PATCH 1/3] kvm-s390: infrastructure to kick vcpus out of guest state - rebased ehrhardt

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=1243952771-32428-2-git-send-email-ehrhardt@linux.vnet.ibm.com \
    --to=ehrhardt@linux.vnet.ibm.com \
    --cc=avi@redhat.com \
    --cc=borntraeger@de.ibm.com \
    --cc=cotte@de.ibm.com \
    --cc=heiko.carstens@de.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    --cc=schwidefsky@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