public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] kvm-s390: fix registering memory regions while vcpus do exist
@ 2009-02-05 16:01 Carsten Otte
  2009-02-05 16:03 ` [PATCH 2/3] kvm-s390: verify that memory slot is present for vm in kvm_run Carsten Otte
  2009-02-05 16:05 ` [PATCH 3/3] kvm common: verify that cpu slot is available when creating new vcpu Carsten Otte
  0 siblings, 2 replies; 8+ messages in thread
From: Carsten Otte @ 2009-02-05 16:01 UTC (permalink / raw)
  To: Avi Kivity; +Cc: KVM mailing list

This patch fixes an incorrectness in the kvm backend for s390.
In case virtual cpus are being created before the corresponding
memory slot is being registered, we need to update the sie
control blocks for the virtual cpus. In order to do that, we
use the vcpu->mutex to lock out kvm_run and friends. This way
we can ensure a consistent update of the memory for the entire
smp configuration.

Signed-off-by: Carsten Otte <cotte@de.ibm.com>
---
 arch/s390/kvm/kvm-s390.c |   25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

Index: kvm/arch/s390/kvm/kvm-s390.c
===================================================================
--- kvm.orig/arch/s390/kvm/kvm-s390.c
+++ kvm/arch/s390/kvm/kvm-s390.c
@@ -660,6 +660,8 @@ int kvm_arch_set_memory_region(struct kv
 				struct kvm_memory_slot old,
 				int user_alloc)
 {
+	int i;
+
 	/* A few sanity checks. We can have exactly one memory slot which has
 	   to start at guest virtual zero and which has to be located at a
 	   page boundary in userland and which has to end at a page boundary.
@@ -679,13 +681,28 @@ int kvm_arch_set_memory_region(struct kv
 	if (mem->memory_size & (PAGE_SIZE - 1))
 		return -EINVAL;
 
+	/* lock all vcpus */
+	for (i = 0; i < KVM_MAX_VCPUS; ++i) {
+		if (kvm->vcpus[i]) {
+			mutex_lock(&kvm->vcpus[i]->mutex);
+		}
+	}
+
 	kvm->arch.guest_origin = mem->userspace_addr;
 	kvm->arch.guest_memsize = mem->memory_size;
 
-	/* FIXME: we do want to interrupt running CPUs and update their memory
-	   configuration now to avoid race conditions. But hey, changing the
-	   memory layout while virtual CPUs are running is usually bad
-	   programming practice. */
+	/* update sie control blocks, and unlock all vcpus */
+	for (i = 0; i < KVM_MAX_VCPUS; ++i) {
+		if (kvm->vcpus[i]) {
+			kvm->vcpus[i]->arch.sie_block->gmsor =
+				kvm->arch.guest_origin;
+			kvm->vcpus[i]->arch.sie_block->gmslm =
+				kvm->arch.guest_memsize +
+				kvm->arch.guest_origin +
+				VIRTIODESCSPACE - 1ul;
+			mutex_unlock(&kvm->vcpus[i]->mutex);
+		}
+	}
 
 	return 0;
 }

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2009-02-09 10:26 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-05 16:01 [PATCH 1/3] kvm-s390: fix registering memory regions while vcpus do exist Carsten Otte
2009-02-05 16:03 ` [PATCH 2/3] kvm-s390: verify that memory slot is present for vm in kvm_run Carsten Otte
2009-02-05 16:05 ` [PATCH 3/3] kvm common: verify that cpu slot is available when creating new vcpu Carsten Otte
2009-02-05 16:32   ` Carsten Otte
2009-02-05 16:40   ` [PATCH 3/3 v2] " Carsten Otte
2009-02-08  6:26   ` [PATCH 3/3] " Marcelo Tosatti
2009-02-08  9:47     ` Avi Kivity
2009-02-09 10:26     ` Carsten Otte

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox