From mboxrd@z Thu Jan 1 00:00:00 1970 From: Peter Xu Date: Tue, 17 Dec 2019 22:24:46 +0000 Subject: Re: [PATCH v4 07/19] KVM: Explicitly free allocated-but-unused dirty bitmap Message-Id: <20191217222446.GK7258@xz-x1> List-Id: References: <20191217204041.10815-1-sean.j.christopherson@intel.com> <20191217204041.10815-8-sean.j.christopherson@intel.com> In-Reply-To: <20191217204041.10815-8-sean.j.christopherson@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Sean Christopherson Cc: James Hogan , Paul Mackerras , Christian Borntraeger , Janosch Frank , Paolo Bonzini , Marc Zyngier , linux-arm-kernel@lists.infradead.org, Wanpeng Li , Philippe =?utf-8?Q?Mathieu-Daud=C3=A9?= , kvm@vger.kernel.org, David Hildenbrand , Joerg Roedel , Cornelia Huck , linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, kvm-ppc@vger.kernel.org, Vitaly Kuznetsov , kvmarm@lists.cs.columbia.edu, Jim Mattson On Tue, Dec 17, 2019 at 12:40:29PM -0800, Sean Christopherson wrote: > Explicitly free an allocated-but-unused dirty bitmap instead of relying > on kvm_free_memslot() if an error occurs in __kvm_set_memory_region(). > There is no longer a need to abuse kvm_free_memslot() to free arch > specific resources as arch specific code is now called only after the > common flow is guaranteed to succeed. Arch code can still fail, but > it's responsible for its own cleanup in that case. > > Eliminating the error path's abuse of kvm_free_memslot() paves the way > for simplifying kvm_free_memslot(), i.e. dropping its @dont param. > > Signed-off-by: Sean Christopherson > --- > virt/kvm/kvm_main.c | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) > > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c > index d403e93e3028..6b2261a9e139 100644 > --- a/virt/kvm/kvm_main.c > +++ b/virt/kvm/kvm_main.c > @@ -1096,7 +1096,7 @@ int __kvm_set_memory_region(struct kvm *kvm, > > slots = kvzalloc(sizeof(struct kvm_memslots), GFP_KERNEL_ACCOUNT); > if (!slots) > - goto out_free; > + goto out_bitmap; > memcpy(slots, __kvm_memslots(kvm, as_id), sizeof(struct kvm_memslots)); > > if ((change = KVM_MR_DELETE) || (change = KVM_MR_MOVE)) { > @@ -1144,8 +1144,9 @@ int __kvm_set_memory_region(struct kvm *kvm, > if (change = KVM_MR_DELETE || change = KVM_MR_MOVE) > slots = install_new_memslots(kvm, as_id, slots); > kvfree(slots); > -out_free: > - kvm_free_memslot(kvm, &new, &old); > +out_bitmap: > + if (new.dirty_bitmap && !old.dirty_bitmap) > + kvm_destroy_dirty_bitmap(&new); What if both the old and new have KVM_MEM_LOG_DIRTY_PAGES set? kvm_free_memslot() did cover that but I see that you explicitly dropped it. Could I ask why? Thanks, -- Peter Xu