Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp24446ybt; Tue, 23 Jun 2020 14:17:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxC1SsFcyUdE4keQbNquSvqdwawaA1AK0vCGoL+X5KKXmoOed7hqvd7d+hWw0kTTqnyXITd X-Received: by 2002:aa7:c986:: with SMTP id c6mr24367694edt.335.1592947064603; Tue, 23 Jun 2020 14:17:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592947064; cv=none; d=google.com; s=arc-20160816; b=Tu9MkC6dKTUdOQ4eCiMaequxsXnSE09UFSroPhiz2h1jWBAgKEvVYBuc0cD0G/czNc XPpb6Bqsp38CumfkzFcZ7lKTldiL7GcEuBvFOJ8dtU9+1Z4XTgojXZOVy2EFXE/6x7Wu yOElvW2JZHXqNEKdoT+bpurXg5Jd3qv3rpwJqnMUupfzI2ex2WQjRu2GJalwA/6BAFG+ u4mI7hxE81FPiaxBgKCY1UkpMncgmQy+Uv9rzCMK5YrRHnNxSVfgu+qxCkUI5INRadcq dtfFDRd8Xobyk0YyJF8F5AdJPGNby3bRTK1XLmuJeljeDB5aq/Hj6vxGPpunS9aU33Os 7Ssw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=P5UNTUR/q9352l4Mlr6IfyTScpTOUF+qqIDl8m4Q5dI=; b=HKx8zLtuTFxWhEdk4PRkSkm9QYtqJc9oNiJQy8MZzTCAcIK/paj/QvMPUygMtdAErv yyDSBCOac3wbKz0kPT9NRXjObeiVr28XGUMfMr+X4omRAZpSlNx5DN7fVZe+aY4gXjLX 4MORmr1Sk48t3wT54aZQuxGe/lmkM4CDd79OZl1tL+euhemL1E6RivwxN5HwvOInE3nb hR1Zhx89bCAhhLyJ0jUsC2dRkFSu3yLVkAut0V0hirGG0FU8iquAFs1iySEb2vRvOLB1 JUS6PosOT9ITHfa4BLE5YbLMDvITKEVV73zEjTAJY4r6v8KjAXZI5TZPom8G3QG6KKp3 clTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=pXBP0dYr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c10si12169473ejr.522.2020.06.23.14.17.21; Tue, 23 Jun 2020 14:17:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=pXBP0dYr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391221AbgFWVP5 (ORCPT + 99 others); Tue, 23 Jun 2020 17:15:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390360AbgFWU2K (ORCPT ); Tue, 23 Jun 2020 16:28:10 -0400 Received: from mail-io1-xd44.google.com (mail-io1-xd44.google.com [IPv6:2607:f8b0:4864:20::d44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1DBE6C061755 for ; Tue, 23 Jun 2020 13:28:11 -0700 (PDT) Received: by mail-io1-xd44.google.com with SMTP id m81so25417066ioa.1 for ; Tue, 23 Jun 2020 13:28:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=P5UNTUR/q9352l4Mlr6IfyTScpTOUF+qqIDl8m4Q5dI=; b=pXBP0dYrp0aWb7reKttRpg7fCJP6uN8YEsLqzatG5AfZRlHt2wzho0utGEdiM74V9Q gPei1v8ea5yzziraZW3573GE451dop8lq6t4TNAyjWVZmmH2ktSHjzTk50ivD0+8AJBG 7YY6MGutzQ7cv+ofQUhtxHi8d0/mILk9ALk6CheDXG9koxRmWYnTK5oswDM7wMKcV55v V5XgDf8ektorep4GCw6hyLwBcm1VyAjbjood7QMOMgLPgAAlRD4+HOKZ7tB3pvkEq3zO SfYvM/mrGa6UURTxJmBFNQ1GA7vJ8pV1gswC2Lw9gMWMKj0rGpngsPejkNnfpvqmckqo TTjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=P5UNTUR/q9352l4Mlr6IfyTScpTOUF+qqIDl8m4Q5dI=; b=pBsfUG6jwf8PxLQd+mkaBIZHhJADmjF1/5eOHWhq04be+OYW47NR72nrP6y37U+SBS UlYOX+a+TJ5l9yPv2pJSVff7PzDLGu3PcQJ96qEbPyIv7+PjU46TIJ77JyRq6g5WKlmB kyLUENw4SNhgs8RCE9HkjW9qCdIahbQ4zzhA30aFMWuvlwfbruOYr7iNo9dytzJx57FR vdcLNM9deSgfPZ6K5U2rm/YA9GCxQESEmnRxdqVVhoyl8+xtERxf2CjO2cAxJcG6z1vJ wboxoXYGrfqxI9PgNfkhSFLbqLmt6KXDCmTkLudfE54MKAKj9+xzp1Fz6bVD0YvHyH6d L0Sg== X-Gm-Message-State: AOAM531Mp2+xRtODBhWDGFfL0whw8kuFgD/dfn9UKaHdoSYRLWaXv28e US+lgKumDV8fLhJIVjtdGNiGCpqSZpZ8MjPU8DbQ6A== X-Received: by 2002:a02:cced:: with SMTP id l13mr24583703jaq.68.1592944090180; Tue, 23 Jun 2020 13:28:10 -0700 (PDT) MIME-Version: 1.0 References: <20200623194027.23135-1-sean.j.christopherson@intel.com> <20200623194027.23135-2-sean.j.christopherson@intel.com> In-Reply-To: <20200623194027.23135-2-sean.j.christopherson@intel.com> From: Jon Cargille Date: Tue, 23 Jun 2020 13:27:58 -0700 Message-ID: Subject: Re: [PATCH 1/2] KVM: x86/mmu: Avoid multiple hash lookups in kvm_get_mmu_page() To: Sean Christopherson Cc: Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Peter Feiner Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org LGTM. Reviewed-By: Jon Cargille On Tue, Jun 23, 2020 at 12:40 PM Sean Christopherson wrote: > > Refactor for_each_valid_sp() to take the list of shadow pages instead of > retrieving it from a gfn to avoid doing the gfn->list hash and lookup > multiple times during kvm_get_mmu_page(). > > Cc: Peter Feiner > Cc: Jon Cargille > Cc: Jim Mattson > Signed-off-by: Sean Christopherson > --- > arch/x86/kvm/mmu/mmu.c | 17 +++++++++-------- > 1 file changed, 9 insertions(+), 8 deletions(-) > > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c > index 3dd0af7e7515..67f8f82e9783 100644 > --- a/arch/x86/kvm/mmu/mmu.c > +++ b/arch/x86/kvm/mmu/mmu.c > @@ -2258,15 +2258,14 @@ static bool kvm_mmu_prepare_zap_page(struct kvm *kvm, struct kvm_mmu_page *sp, > static void kvm_mmu_commit_zap_page(struct kvm *kvm, > struct list_head *invalid_list); > > - > -#define for_each_valid_sp(_kvm, _sp, _gfn) \ > - hlist_for_each_entry(_sp, \ > - &(_kvm)->arch.mmu_page_hash[kvm_page_table_hashfn(_gfn)], hash_link) \ > +#define for_each_valid_sp(_kvm, _sp, _list) \ > + hlist_for_each_entry(_sp, _list, hash_link) \ > if (is_obsolete_sp((_kvm), (_sp))) { \ > } else > > #define for_each_gfn_indirect_valid_sp(_kvm, _sp, _gfn) \ > - for_each_valid_sp(_kvm, _sp, _gfn) \ > + for_each_valid_sp(_kvm, _sp, \ > + &(_kvm)->arch.mmu_page_hash[kvm_page_table_hashfn(_gfn)]) \ > if ((_sp)->gfn != (_gfn) || (_sp)->role.direct) {} else > > static inline bool is_ept_sp(struct kvm_mmu_page *sp) > @@ -2477,6 +2476,7 @@ static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu, > unsigned int access) > { > union kvm_mmu_page_role role; > + struct hlist_head *sp_list; > unsigned quadrant; > struct kvm_mmu_page *sp; > bool need_sync = false; > @@ -2496,7 +2496,9 @@ static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu, > quadrant &= (1 << ((PT32_PT_BITS - PT64_PT_BITS) * level)) - 1; > role.quadrant = quadrant; > } > - for_each_valid_sp(vcpu->kvm, sp, gfn) { > + > + sp_list = &vcpu->kvm->arch.mmu_page_hash[kvm_page_table_hashfn(gfn)]; > + for_each_valid_sp(vcpu->kvm, sp, sp_list) { > if (sp->gfn != gfn) { > collisions++; > continue; > @@ -2533,8 +2535,7 @@ static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu, > > sp->gfn = gfn; > sp->role = role; > - hlist_add_head(&sp->hash_link, > - &vcpu->kvm->arch.mmu_page_hash[kvm_page_table_hashfn(gfn)]); > + hlist_add_head(&sp->hash_link, sp_list); > if (!direct) { > /* > * we should do write protection before syncing pages > -- > 2.26.0 >