From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: [PATCH 1/6] kvm-s390: Fix memory slot versus run Date: Wed, 06 May 2009 15:01:50 +0300 Message-ID: <4A017C2E.6060306@redhat.com> References: <1241534358-32172-1-git-send-email-ehrhardt@linux.vnet.ibm.com> <1241534358-32172-2-git-send-email-ehrhardt@linux.vnet.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org, Christian Borntraeger , Carsten Otte To: ehrhardt@linux.vnet.ibm.com Return-path: Received: from mx2.redhat.com ([66.187.237.31]:44879 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753184AbZEFMC2 (ORCPT ); Wed, 6 May 2009 08:02:28 -0400 In-Reply-To: <1241534358-32172-2-git-send-email-ehrhardt@linux.vnet.ibm.com> Sender: kvm-owner@vger.kernel.org List-ID: ehrhardt@linux.vnet.ibm.com wrote: > From: Carsten Otte > > 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. > @@ -657,6 +657,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. > @@ -676,13 +678,27 @@ 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); > + } > + > Can't that livelock? Nothing requires a vcpu to ever exit, and if the cpu on which it's running on has no other load and no interrupts, it could remain in guest mode indefinitely, and then the ioctl will hang, waiting for something to happen. On x86, we use slots_lock to protect memory slots. When we change the global memory configuration, we set a bit in vcpu->requests, and send an IPI to all cpus that are currently in guest mode for our guest. This forces the cpu back to host mode. On the next entry, vcpu_run notices vcpu->requests has the bit set and reloads the mmu configuration. Of course, all this may be overkill for s390. -- Do not meddle in the internals of kernels, for they are subtle and quick to panic.