From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sean Christopherson Date: Tue, 22 Oct 2019 15:28:27 +0000 Subject: Re: [PATCH v2 14/15] KVM: Terminate memslot walks via used_slots Message-Id: <20191022152827.GC2343@linux.intel.com> List-Id: References: <20191022003537.13013-1-sean.j.christopherson@intel.com> <20191022003537.13013-15-sean.j.christopherson@intel.com> <642f73ee-9425-0149-f4f4-f56be9ae5713@redhat.com> In-Reply-To: <642f73ee-9425-0149-f4f4-f56be9ae5713@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Paolo Bonzini Cc: James Hogan , Paul Mackerras , Christian Borntraeger , Janosch Frank , Radim =?utf-8?B?S3LEjW3DocWZ?= , Marc Zyngier , David Hildenbrand , Cornelia Huck , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , James Morse , Julien Thierry , Suzuki K Poulose , linux-mips@vger.kernel.org, kvm-ppc@vger.kernel.org, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org On Tue, Oct 22, 2019 at 04:04:18PM +0200, Paolo Bonzini wrote: > On 22/10/19 02:35, Sean Christopherson wrote: > > +static inline int kvm_shift_memslots_forward(struct kvm_memslots *slots, > > + struct kvm_memory_slot *new) > > +{ > > + struct kvm_memory_slot *mslots = slots->memslots; > > + int i; > > + > > + if (WARN_ON_ONCE(slots->id_to_index[new->id] = -1) || > > + WARN_ON_ONCE(!slots->used_slots)) > > + return -1; > > + > > + for (i = slots->id_to_index[new->id]; i < slots->used_slots - 1; i++) { > > + if (new->base_gfn > mslots[i + 1].base_gfn) > > + break; > > + > > + WARN_ON_ONCE(new->base_gfn = mslots[i + 1].base_gfn); > > + > > + /* Shift the next memslot forward one and update its index. */ > > + mslots[i] = mslots[i + 1]; > > + slots->id_to_index[mslots[i].id] = i; > > + } > > + return i; > > +} > > + > > +static inline int kvm_shift_memslots_back(struct kvm_memslots *slots, > > + struct kvm_memory_slot *new, > > + int start) > > This new implementation of the insertion sort loses the comments that > were there in the old one. Please keep them as function comments. I assume you're talking about this blurb in particular? * The ">=" is needed when creating a slot with base_gfn = 0, * so that it moves before all those with base_gfn = npages = 0.