From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CD863CA9EBB for ; Thu, 24 Oct 2019 20:24:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AC30221655 for ; Thu, 24 Oct 2019 20:24:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727482AbfJXUYO (ORCPT ); Thu, 24 Oct 2019 16:24:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50234 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727453AbfJXUYO (ORCPT ); Thu, 24 Oct 2019 16:24:14 -0400 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 498D44E83E for ; Thu, 24 Oct 2019 20:24:13 +0000 (UTC) Received: by mail-wr1-f70.google.com with SMTP id f4so13391872wrj.12 for ; Thu, 24 Oct 2019 13:24:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:openpgp:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=ZRT3dVDu4csQhfGia5nCcLIZe2YAZImGVAl5gr6pUcE=; b=ThmJHHMlUUnvHttZkQbBH7mF8bE595+yvymy7pd/ktqmczkzDGJfnDW+yLkiotQzg8 MS65k7EcIY/7t0gYaS1ZftfAVIYuoTr9TbhYdwLss/Ed6x0XD7AcKoEan4J040XKz3pY ZwMW2tP9SON/FSykpndcHWCtUPsBixj9xjp1XMRbzDZhipKlLNydds/WAhoy8BxkkQ+Y KfX5p6sJid4IkTdjzGPo9lI02zdNeotV6CMY/lHD5pyVl77DiSIx2f3n8/YgUFTSE5Dw Yw+g29eIpBzFc7+mMi4iyEePTXd0yk+2j5ux/J7RZkWZejJBkJEVXBP1VLT1Rl1H4tuq wiaw== X-Gm-Message-State: APjAAAW8pgFnvOm6cV/VCx3/b2fJy7sLDTdXqsOXOExR44INALjMbfgl pe/QEAU+SDoPyGyjfx5KA8ViU5lvH4WQLc5jTKGKOUVbdxQXPsoznxrzFHyBGN785jXR4SzYEbH RKohDlPGyg6Jq+3XalV55Ek5i X-Received: by 2002:a5d:4a03:: with SMTP id m3mr5578387wrq.359.1571948651615; Thu, 24 Oct 2019 13:24:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqx4p9hq+y70/y8WlLn0/OTguCJ96CcuhVxxvxeJyvnyp8Rzk3Jc6wiDxI+nnKN+OJXQKdf4DA== X-Received: by 2002:a5d:4a03:: with SMTP id m3mr5578369wrq.359.1571948651305; Thu, 24 Oct 2019 13:24:11 -0700 (PDT) Received: from ?IPv6:2001:b07:6468:f312:302c:998e:a769:c583? ([2001:b07:6468:f312:302c:998e:a769:c583]) by smtp.gmail.com with ESMTPSA id v128sm5252067wmb.14.2019.10.24.13.24.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 24 Oct 2019 13:24:10 -0700 (PDT) Subject: Re: [PATCH v2 14/15] KVM: Terminate memslot walks via used_slots To: Sean Christopherson Cc: James Hogan , Paul Mackerras , Christian Borntraeger , Janosch Frank , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , 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 References: <20191022003537.13013-1-sean.j.christopherson@intel.com> <20191022003537.13013-15-sean.j.christopherson@intel.com> <642f73ee-9425-0149-f4f4-f56be9ae5713@redhat.com> <20191022152827.GC2343@linux.intel.com> <625e511f-bd35-3b92-0c6d-550c10fc5827@redhat.com> <20191022155220.GD2343@linux.intel.com> <5c61c094-ee32-4dcf-b3ae-092eba0159c5@redhat.com> <20191024193856.GA28043@linux.intel.com> From: Paolo Bonzini Openpgp: preference=signencrypt Message-ID: <5320341c-1abb-610b-8f5e-090a6726a9b1@redhat.com> Date: Thu, 24 Oct 2019 22:24:09 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20191024193856.GA28043@linux.intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 24/10/19 21:38, Sean Christopherson wrote: > only > * its new index into the array is update. s/update/tracked/? Returns the changed memslot's > * current index into the memslots array. > */ > static inline int kvm_memslot_move_backward(struct kvm_memslots *slots, > struct kvm_memory_slot *memslot) > { > struct kvm_memory_slot *mslots = slots->memslots; > int i; > > if (WARN_ON_ONCE(slots->id_to_index[memslot->id] == -1) || > WARN_ON_ONCE(!slots->used_slots)) > return -1; > > for (i = slots->id_to_index[memslot->id]; i < slots->used_slots - 1; i++) { > if (memslot->base_gfn > mslots[i + 1].base_gfn) > break; > > WARN_ON_ONCE(memslot->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; > } > > /* > * Move a changed memslot forwards in the array by shifting existing slots with > * a lower GFN toward the back of the array. Note, the changed memslot itself > * is not preserved in the array, i.e. not swapped at this time, only its new > * index into the array is updated Same here? > * Note, slots are sorted from highest->lowest instead of lowest->highest for > * historical reasons. Not just that, the largest slot (with all RAM above 4GB) is also often at the highest address at least on x86. But we could sort them by size now, so I agree to call these historical reasons. The code itself is fine, thanks for the work on documenting it. Paolo