From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marcelo Tosatti Subject: Re: [patch 06/11] KVM: introduce kvm->srcu and convert kvm_set_memory_region to SRCU update Date: Wed, 23 Dec 2009 13:13:26 -0200 Message-ID: <20091223151326.GB14329@amt.cnet> References: <20091223113833.742662117@redhat.com> <20091223114438.751996250@redhat.com> <4B320DF7.3070005@redhat.com> <20091223141941.GA14329@amt.cnet> <4B322A22.3080705@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: kvm@vger.kernel.org To: Avi Kivity Return-path: Received: from mx1.redhat.com ([209.132.183.28]:30241 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756226AbZLWP0g (ORCPT ); Wed, 23 Dec 2009 10:26:36 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nBNFQa3d026234 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 23 Dec 2009 10:26:36 -0500 Content-Disposition: inline In-Reply-To: <4B322A22.3080705@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On Wed, Dec 23, 2009 at 04:33:06PM +0200, Avi Kivity wrote: > On 12/23/2009 04:19 PM, Marcelo Tosatti wrote: >> On Wed, Dec 23, 2009 at 02:32:55PM +0200, Avi Kivity wrote: >> >>> On 12/23/2009 01:38 PM, Marcelo Tosatti wrote: >>> >>>> Use two steps for memslot deletion: mark the slot invalid (which stops >>>> instantiation of new shadow pages for that slot, but allows destruction), >>>> then instantiate the new empty slot. >>>> >>>> Also simplifies kvm_handle_hva locking. >>>> >>>> >>>> r = kvm_arch_prepare_memory_region(kvm,&new, old, user_alloc); >>>> if (r) >>>> goto out_free; >>>> >>>> >>> r == 0 >>> >> Huh? kvm_arch_prepare_memory_region returns a suitable error code on >> failure, 0 on success. >> > > That's fine here, just pointing out you're inheriting this r == 0 later on. > >> kvm_iommu_map_pages returns 0 on success, error code otherwise? The >> error code of kvm_iommu_map_pages was returned before the patchset, BTW. >> > > Ok, then please fix it separately for easier backporting. Its not a bug. >>>> nr_mmu_pages = nr_pages * KVM_PERMILLE_MMU_PAGES / 1000; >>>> nr_mmu_pages = max(nr_mmu_pages, >>>> (unsigned int) KVM_MIN_ALLOC_MMU_PAGES); >>>> + srcu_read_unlock(&kvm->srcu, idx); >>>> >>>> >>>> >>> Again, would like to move the srcu_locking to an outer scope. >>> >> This one was for documentation purposes only, since >> kvm_mmu_calculate_mmu_pages is only called from commit_memory_region >> (which mutually excludes itself). >> >> I can remove it if you'd prefer. >> > > A comment should be sufficient. Otherwise someone might read the code > and point out it's unnecessary. > > > >>> Shouldn't we already hold the srcu_lock as part of normal guest exit >>> (similar to down_read() we do today)? >>> >> Yes, but: >> >> kvm_arch_vcpu_setup -> vmx_vcpu_reset -> vmx_set_cr0 -> enter_pmode >> >> So its called outside guest context path (memslot info is used outside >> guest context in this case). >> >> > > Didn't we take slots_lock previously? If so, that's a bug. We should > probably make all vcpu ioctls take slots_lock at top level, since many > vcpu ioctls can be caused to access memory. vmx_vcpu_reset takes it, so again, this is for documentation purposes (its easier to make sense of srcu_read_lock + rcu_dereference together). I'll remove it, since rcu_dereference should be enough to document the locking.