All of lore.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: kvm@vger.kernel.org
Subject: [PATCH 30/45] KVM: s390: Fix memory slot versus run - v3
Date: Sun, 24 May 2009 18:50:15 +0300	[thread overview]
Message-ID: <1243180230-2480-31-git-send-email-avi@redhat.com> (raw)
In-Reply-To: <1243180230-2480-1-git-send-email-avi@redhat.com>

From: Carsten Otte <cotte@de.ibm.com>

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.

*updates in v3*
In consideration of the s390 memslot constraints locking was changed
to trylock. These locks should never be held, as vcpu's can't run without
the single memslot we just assign when running this code. To ensure this
never deadlocks in case other code changes the code uses trylocks and bail
out if it can't get all locks.

Additionally most of the discussed special conditions for s390 like
only one memslot and no user_alloc are now checked for validity in
kvm_arch_set_memory_region.

Reported-by: Mijo Safradin <mijo@linux.vnet.ibm.com>
Signed-off-by: Carsten Otte <cotte@de.ibm.com>
Signed-off-by: Christian Ehrhardt <ehrhardt@de.ibm.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
---
 arch/s390/kvm/kvm-s390.c |   36 +++++++++++++++++++++++++++++++-----
 1 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index f4d56e9..86567e1 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -657,6 +657,8 @@ int kvm_arch_set_memory_region(struct kvm *kvm,
 				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.
@@ -664,7 +666,7 @@ int kvm_arch_set_memory_region(struct kvm *kvm,
 	   vmas. It is okay to mmap() and munmap() stuff in this slot after
 	   doing this call at any time */
 
-	if (mem->slot)
+	if (mem->slot || kvm->arch.guest_memsize)
 		return -EINVAL;
 
 	if (mem->guest_phys_addr)
@@ -676,15 +678,39 @@ int kvm_arch_set_memory_region(struct kvm *kvm,
 	if (mem->memory_size & (PAGE_SIZE - 1))
 		return -EINVAL;
 
+	if (!user_alloc)
+		return -EINVAL;
+
+	/* lock all vcpus */
+	for (i = 0; i < KVM_MAX_VCPUS; ++i) {
+		if (!kvm->vcpus[i])
+			continue;
+		if (!mutex_trylock(&kvm->vcpus[i]->mutex))
+			goto fail_out;
+	}
+
 	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;
+
+fail_out:
+	for (; i >= 0; i--)
+		mutex_unlock(&kvm->vcpus[i]->mutex);
+	return -EINVAL;
 }
 
 void kvm_arch_flush_shadow(struct kvm *kvm)
-- 
1.6.0.6


  parent reply	other threads:[~2009-05-24 15:56 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-24 15:49 [PATCH 00/45] KVM updates for the 2.6.31 merge window (batch 3/3) Avi Kivity
2009-05-24 15:49 ` [PATCH 01/45] KVM: Remove inject_pending_vectors() callback Avi Kivity
2009-05-24 15:49 ` [PATCH 02/45] KVM: Remove kvm_push_irq() Avi Kivity
2009-05-24 15:49 ` [PATCH 03/45] KVM: sync_lapic_to_cr8() should always sync cr8 to V_TPR Avi Kivity
2009-05-24 15:49 ` [PATCH 04/45] KVM: Do not report TPR write to userspace if new value bigger or equal to a previous one Avi Kivity
2009-05-24 15:49 ` [PATCH 05/45] KVM: Get rid of arch.interrupt_window_open & arch.nmi_window_open Avi Kivity
2009-05-24 15:49 ` [PATCH 06/45] KVM: SVM: Add NMI injection support Avi Kivity
2009-05-24 15:49 ` [PATCH 07/45] KVM: Fix userspace IRQ chip migration Avi Kivity
2009-05-24 15:49 ` [PATCH 08/45] KVM: Get rid of get_irq() callback Avi Kivity
2009-05-24 15:49 ` [PATCH 09/45] KVM: Wake up waitqueue before calling get_cpu() Avi Kivity
2009-05-24 15:49 ` [PATCH 10/45] KVM: Replace get_mt_mask_shift with get_mt_mask Avi Kivity
2009-05-24 15:49 ` [PATCH 11/45] KVM: Enable snooping control for supported hardware Avi Kivity
2009-05-24 15:49 ` [PATCH 12/45] KVM: VMX: Disable VMX when system shutdown Avi Kivity
2009-05-24 15:49 ` [PATCH 13/45] KVM: Trivial format fix in setup_routing_entry() Avi Kivity
2009-05-24 15:49 ` [PATCH 14/45] KVM: fix apic_debug instances Avi Kivity
2009-05-24 15:50 ` [PATCH 15/45] KVM: SVM: Fix cross vendor migration issue in segment segment descriptor Avi Kivity
2009-05-24 15:50 ` [PATCH 16/45] KVM: SVM: Don't reinject event that caused a task switch Avi Kivity
2009-05-24 15:50 ` [PATCH 17/45] KVM: Drop request_nmi from stats Avi Kivity
2009-05-24 15:50 ` [PATCH 18/45] KVM: Fix cpuid feature misreporting Avi Kivity
2009-05-24 15:50 ` [PATCH 19/45] KVM: Add AMD cpuid bit: cr8_legacy, abm, misaligned sse, sse4, 3dnow prefetch Avi Kivity
2009-05-24 15:50 ` [PATCH 20/45] x86: Add cpu features MOVBE and POPCNT Avi Kivity
2009-05-24 15:50 ` [PATCH 21/45] KVM: Update cpuid 1.ecx reporting Avi Kivity
2009-05-24 15:50 ` [PATCH 22/45] KVM: use smp_send_reschedule in kvm_vcpu_kick Avi Kivity
2009-05-24 15:50 ` [PATCH 23/45] KVM: protect assigned dev workqueue, int handler and irq acker Avi Kivity
2009-05-24 15:50 ` [PATCH 24/45] KVM: Replace ->drop_interrupt_shadow() by ->set_interrupt_shadow() Avi Kivity
2009-05-24 15:50 ` [PATCH 25/45] KVM: Deal with interrupt shadow state for emulated instructions Avi Kivity
2009-05-24 15:50 ` [PATCH 26/45] KVM: MMU: protect kvm_mmu_change_mmu_pages with mmu_lock Avi Kivity
2009-05-24 15:50 ` [PATCH 27/45] KVM: take mmu_lock when updating a deleted slot Avi Kivity
2009-05-24 15:50 ` [PATCH 28/45] KVM: x86: check for cr3 validity in mmu_alloc_roots Avi Kivity
2009-05-24 15:50 ` [PATCH 29/45] KVM: Expand on "help" info to specify kvm intel and amd module names Avi Kivity
2009-05-24 15:50 ` Avi Kivity [this message]
2009-05-24 15:50 ` [PATCH 31/45] KVM: s390: use hrtimer for clock wakeup from idle - v2 Avi Kivity
2009-05-24 15:50 ` [PATCH 32/45] KVM: s390: optimize float int lock: spin_lock_bh --> spin_lock Avi Kivity
2009-05-24 15:50 ` [PATCH 33/45] KVM: s390: Unlink vcpu on destroy - v2 Avi Kivity
2009-05-24 15:50 ` [PATCH 34/45] KVM: s390: Sanity check on validity intercept Avi Kivity
2009-05-24 15:50 ` [PATCH 35/45] KVM: s390: Verify memory in kvm run Avi Kivity
2009-05-24 15:50 ` [PATCH 36/45] KVM: Unprotect a page if #PF happens during NMI injection Avi Kivity
2009-05-24 15:50 ` [PATCH 37/45] KVM: Do not allow interrupt injection from userspace if there is a pending event Avi Kivity
2009-05-24 15:50 ` [PATCH 38/45] KVM: Remove irq_pending bitmap Avi Kivity
2009-05-24 15:50 ` [PATCH 39/45] KVM: skip_emulated_instruction() decode instruction if size is not known Avi Kivity
2009-05-24 15:50 ` [PATCH 40/45] KVM: Do not re-execute INTn instruction Avi Kivity
2009-05-24 15:50 ` [PATCH 41/45] KVM: Always request IRQ/NMI window if an interrupt is pending Avi Kivity
2009-05-24 15:50 ` [PATCH 42/45] KVM: inject NMI after IRET from a previous NMI, not before Avi Kivity
2009-05-24 15:50 ` [PATCH 43/45] KVM: Do not migrate pending software interrupts Avi Kivity
2009-05-24 15:50 ` [PATCH 44/45] KVM: Disable CR8 intercept if tpr patching is active Avi Kivity
2009-05-24 15:50 ` [PATCH 45/45] KVM: Move "exit due to NMI" handling into vmx_complete_interrupts() 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=1243180230-2480-31-git-send-email-avi@redhat.com \
    --to=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.