Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A4C67C433FE for ; Wed, 1 Dec 2021 03:08:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346386AbhLADL5 (ORCPT ); Tue, 30 Nov 2021 22:11:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346357AbhLADLz (ORCPT ); Tue, 30 Nov 2021 22:11:55 -0500 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AFEBDC061574 for ; Tue, 30 Nov 2021 19:08:34 -0800 (PST) Received: by mail-pl1-x62d.google.com with SMTP id o14so16562313plg.5 for ; Tue, 30 Nov 2021 19:08:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=g/5TnmO0gT6CKLi6q8niA4Xjnk2B+JAa0dgcq+oWmgE=; b=sz8OfTfEdVypCCUplqFm68nLLrB713ifamjo9FNgw6fxytJB7suIkv97dVHhFtHvIp r6xFOTe4ZOtSS6J0BMNf6RUu1F9nxEFmEkOKMeCch/lUeka+ZiZQ94fK7jCzhehNKebD ziGr/lC86orMOySYprMqDlPfD+mdiOcfY1SjLYh599iN7kbsQhMOdf6Y7+zFQIzXU2jg wbdDB+yuWURoVlOjBXma2j4fnxAsm3Za+OU4j8Qz7+WkaPSh8MMq4zGkvx6QgzT0lreJ y23v9KJ76HIwXxCySpNCdkf7NnZ+WMR7ZPgAzissxHyl2iU1M+h98WahNHybCIgmNG5B pPqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=g/5TnmO0gT6CKLi6q8niA4Xjnk2B+JAa0dgcq+oWmgE=; b=XWcGoAGurAosuIoSVdtjoAReqpdXby9jMzqzlVdp2bv/5SbWjiBhej33ML/jAmWRW2 UTc0P/qzDleiwYt6IpMSddy6lDuzxYhT9lzQTPdrxw2PhQ7xiZE2KUfNBTNNW/j//PUF ZQO7YqRpa1cBWpMPq9VUbau6u91yvyvzL14myoHCyLBnTYV8pf6reC/SvM3o/6gpC4t3 +nqIrj6m28q6tXZMYsIKNUbzMs75V876BqG616slxhrj+Nm7jWo1F0oUi6/dGs7EAboO WIgoIzuRSOIF4ZjtCOL82mZBnN/NfaML3HlM8UIRJHvhYvDlu/lPulyP32KORn+7oMd4 eXYQ== X-Gm-Message-State: AOAM533bPxZ2MKCUazBNyrWY62l5b/bbOQHH5Vf0KdvrJgEIs3Xn7ObU Dvdyciik85PD8q/LtsmOA/bRvA== X-Google-Smtp-Source: ABdhPJygWMG8G7zSDce5b011s1X4Xdp56pbQ1mwLc1IlSvA0PgBz9ATqm9E4pHlqKImvPGB6/ds8zA== X-Received: by 2002:a17:90b:3908:: with SMTP id ob8mr3988513pjb.57.1638328114039; Tue, 30 Nov 2021 19:08:34 -0800 (PST) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id b15sm23525916pfl.118.2021.11.30.19.08.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 19:08:33 -0800 (PST) Date: Wed, 1 Dec 2021 03:08:29 +0000 From: Sean Christopherson To: "Maciej S. Szmigiero" Cc: Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Igor Mammedov , Marc Zyngier , James Morse , Julien Thierry , Suzuki K Poulose , Huacai Chen , Aleksandar Markovic , Paul Mackerras , Christian Borntraeger , Janosch Frank , David Hildenbrand , Cornelia Huck , Claudio Imbrenda , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandru Elisei , Atish Patra , Ben Gardon , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v6 27/29] KVM: Optimize overlapping memslots check Message-ID: References: <9698a99ccd1938a36dd0c7399262f888dcdf01ac.1638304316.git.maciej.szmigiero@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <9698a99ccd1938a36dd0c7399262f888dcdf01ac.1638304316.git.maciej.szmigiero@oracle.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 30, 2021, Maciej S. Szmigiero wrote: > From: "Maciej S. Szmigiero" > > Do a quick lookup for possibly overlapping gfns when creating or moving > a memslot instead of performing a linear scan of the whole memslot set. > > Signed-off-by: Maciej S. Szmigiero > [sean: tweaked params to avoid churn in future cleanup] > Signed-off-by: Sean Christopherson > --- > virt/kvm/kvm_main.c | 35 +++++++++++++++++++++-------------- > 1 file changed, 21 insertions(+), 14 deletions(-) > > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c > index 086f18969bc3..52117f65bc5b 100644 > --- a/virt/kvm/kvm_main.c > +++ b/virt/kvm/kvm_main.c > @@ -1817,6 +1817,18 @@ static int kvm_set_memslot(struct kvm *kvm, > return 0; > } > > +static bool kvm_check_memslot_overlap(struct kvm_memslots *slots, int id, > + gfn_t start, gfn_t end) > +{ > + struct kvm_memslot_iter iter; > + > + kvm_for_each_memslot_in_gfn_range(&iter, slots, start, end) The for loop needs curly braces, per coding-style.rst: Also, use braces when a loop contains more than a single simple statement: .. code-block:: c while (condition) { if (test) do_something(); } With that, Reviewed-by: Sean Christopherson