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.3 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 74598CA9EA0 for ; Tue, 22 Oct 2019 15:31:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 52CE320684 for ; Tue, 22 Oct 2019 15:31:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732391AbfJVPbE (ORCPT ); Tue, 22 Oct 2019 11:31:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:21136 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732228AbfJVPbC (ORCPT ); Tue, 22 Oct 2019 11:31:02 -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 96D3637E80 for ; Tue, 22 Oct 2019 15:31:01 +0000 (UTC) Received: by mail-wr1-f70.google.com with SMTP id j14so9029003wrm.6 for ; Tue, 22 Oct 2019 08:31:01 -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=bYuISgCPeW5+MVYfOIxCD24v5h78aw8/fY5c9Ec2zaE=; b=bMULqvMmPv90dO8yrrcA9pNfuA6ZpSKPgEbyNseYcgbvIV0oipqsDzsdFXjDR7hEv4 lDYe/LBlDyaOm45XeTmYvujEnlePowIfoKZk7fwR+brxbruV85VH08L4Zs5TJorrvEhj zJrMoDXdiDOoP5SP6kHPFLEZy6FE27yeQzJ/r0OiHyYW3Go90wr3wVWa1adXNKFscP4v SwpUpoUoYl215Rtfp8u5O+AoXVm7F3SHSTnSGeB+obj2dMmeJGA8LvmJP4/TwR8woYBv kjIu50I284hfnbAu6nLavehC5eInR+xkanDWNXyBhMy9+bE7jpAEB/LiO6L8xLjRJuMl h2rA== X-Gm-Message-State: APjAAAUxuXQQZIsnJX60zbC+U2+GhKjcL/jKg1h9X6SQvq9rBoToVf3+ e8pdDkzywUiwgZv9L0x/c4UbYnbAKF07dPYiipsGatASJ2R/+rS/dg9np0sNqRHfYLwaa7S58Vk bOPAYJuW0rbfr3ZJp5AsglFEg X-Received: by 2002:a7b:c4c6:: with SMTP id g6mr3605232wmk.126.1571758260030; Tue, 22 Oct 2019 08:31:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqzRNIaPW2VC3E0u/tx9jObrvh39A/kSU1/g2oCY4LzK3jFChqIF1uPjGeoTV55xRLqzG4HUGw== X-Received: by 2002:a7b:c4c6:: with SMTP id g6mr3605195wmk.126.1571758259666; Tue, 22 Oct 2019 08:30:59 -0700 (PDT) Received: from ?IPv6:2001:b07:6468:f312:c0e4:dcf4:b543:ce19? ([2001:b07:6468:f312:c0e4:dcf4:b543:ce19]) by smtp.gmail.com with ESMTPSA id i18sm17512175wrx.14.2019.10.22.08.30.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 22 Oct 2019 08:30:59 -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> From: Paolo Bonzini Openpgp: preference=signencrypt Message-ID: <625e511f-bd35-3b92-0c6d-550c10fc5827@redhat.com> Date: Tue, 22 Oct 2019 17:30:58 +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: <20191022152827.GC2343@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 22/10/19 17:28, Sean Christopherson wrote: > 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. Yes, well all of the comments. You can also keep them in the caller, as you prefer. Paolo