Received: by 2002:a05:6a10:8a4d:0:0:0:0 with SMTP id dn13csp87248pxb; Thu, 12 Aug 2021 11:23:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyxVMl/EtkCfl5HtKjhQbLKav55GASnOXU98JERW4UyIEWTuNv1G7Ctno4G7tX47+D2qXn6 X-Received: by 2002:a5e:dd49:: with SMTP id u9mr3924590iop.102.1628792611718; Thu, 12 Aug 2021 11:23:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628792611; cv=none; d=google.com; s=arc-20160816; b=yTjegj7lP4X6T9cTZpgN3/KXW7tyOKYTs9VCZ/G80ugLgL/r0Toc+p93mSmBMzsz29 aZCG9FKtog3sbTBquPab2dRGmp/xIkob4igq5JXAm2mp2PbLwLST7O1/v+4U/8IDOPLL u6NMUaCZ0kU5oNQp/eiP42rDUJZn0lEbkNi1AWjC0LS3Ii5yLjjtqqcDCahCQGbYldXF 18w2aUcACA8xcVgAOhd1ChbwrYK/+iGr3MqYbkN8CVqt5Z3gl0KQTPNy76lovGvrNIOB 8/bdv+hq0GbT8q16vOW/n7bDpOMGRAAxBj8Mlp3C2zHoSdNjsUZlepPeMFs67Zek9lNF OZ6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=yvJ9x4SLfenexXQQA9JFifSbykJiiyHkKwAxOj9DqUA=; b=QXb8D2VD0CtcdrtBSr8etNHo17bMCAxMd2S6XsuNygb3Vrw8Gpzyqoyp/YEBnOBK3g J0ybB7WyFUjUYDhInwhG7T8/5dmOy/7m+JA33kPa/Co2QLOO3Xku88wVzBk3kCVW17Mk Ag0Zi64EmAY0nEhrbljSfz2E/MqX9BsytruLRWRVRrAxgz6NO56e9YDh3JB32ClegDe+ CFizC7bDrfnR5xO7hJt36EhaV0p5mzlUowy2f0F1yMJDf0R7+uqFU7zRbJqAsBgOp9Ko xLSzPeTC72Shp6xD63O9K2/dlWK7MWbnsVQ5rSeTj+H7oB2KB6RqpyFrooiq0MlaLHgr Uh9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=lrAhMH+t; 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 l6si3719738ios.26.2021.08.12.11.23.21; Thu, 12 Aug 2021 11:23:31 -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=lrAhMH+t; 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 S233254AbhHLQsg (ORCPT + 99 others); Thu, 12 Aug 2021 12:48:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233213AbhHLQsf (ORCPT ); Thu, 12 Aug 2021 12:48:35 -0400 Received: from mail-io1-xd2a.google.com (mail-io1-xd2a.google.com [IPv6:2607:f8b0:4864:20::d2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54B7FC061756 for ; Thu, 12 Aug 2021 09:48:10 -0700 (PDT) Received: by mail-io1-xd2a.google.com with SMTP id s184so9349522ios.2 for ; Thu, 12 Aug 2021 09:48:10 -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=yvJ9x4SLfenexXQQA9JFifSbykJiiyHkKwAxOj9DqUA=; b=lrAhMH+t9sGAoPAFE5RJh+ziEafVJJARhDWK1fUgGew1wWGRWeyQSmT8+CC8xemO+d x7arzC0WWE6fQ1qV4K6/icgkxMh4rP8lFIdPqrrwtNtSOrtRMfu2Kg1U+WtnDY4BRPmF U71o7oC/yKl52sHkInoq7OdIQxNfVjMjsbt2/79IlPndC7kOQQvZwmj2Dr2G5k16Y9He AiavkhxuSJM7Ohxz7YhO+3LjaIUJlChXqnarB4TiIXeIZFWtG8vESQcMIrssE3VxyVhG XYcKmymXk7yiBX0ANdIvFfrJOzJ/LALzr6TkCKJgXSHmzr8Xbj4gUl/jRULG68O3Vj2o itZQ== 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=yvJ9x4SLfenexXQQA9JFifSbykJiiyHkKwAxOj9DqUA=; b=SnSZyJGXGJrYnSWmQSgOwk6JFwFkaIRoeeXaJGg1qZ0zVV8wBIB6dFEayY6/FTbJTK M+sAD73Zz2KUaD3P9gUoklPb9j9i87udrdwRdcde2k+9mIj8slHcqzg1BAK1l9pFoa/z PxGOfPRxxnHbbsO1FuR3rfySv5ln+nDZ5hbyRL/kWvkQfEfiRpTO4ayZDDwZTAL1iRE3 KVpjDPmc1nKjo4PaqHuV/r3DNASUpKpfbxkWyjg1VH30o2IL4OwFcsVz7iz+VzGc9y5N A5k5CT3JLj9Bd7rMf/58U6UV87hjzVlOi0UyuL8xAdKnL6bg1X6+Ffb2LX439SOK2Sn/ qzMg== X-Gm-Message-State: AOAM530NO6HiqwrzMamOrCz9DNMlbMeWWI3suY5EV05NTW1U9T7lmIfG wQgwO2HOhxQALHKkStu5KUxqQs6opVzLqJAv3tPG3w== X-Received: by 2002:a02:2243:: with SMTP id o64mr4666627jao.40.1628786889496; Thu, 12 Aug 2021 09:48:09 -0700 (PDT) MIME-Version: 1.0 References: <20210812050717.3176478-1-seanjc@google.com> <20210812050717.3176478-3-seanjc@google.com> In-Reply-To: <20210812050717.3176478-3-seanjc@google.com> From: Ben Gardon Date: Thu, 12 Aug 2021 09:47:58 -0700 Message-ID: Subject: Re: [PATCH 2/2] KVM: x86/mmu: Don't step down in the TDP iterator when zapping all SPTEs To: Sean Christopherson Cc: Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm , LKML Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 11, 2021 at 10:07 PM Sean Christopherson wrote: > > Set the min_level for the TDP iterator at the root level when zapping all > SPTEs so that the _iterator_ only processes top-level SPTEs. Zapping a > non-leaf SPTE will recursively zap all its children, thus there is no > need for the iterator to attempt to step down. This avoids rereading all > the top-level SPTEs after they are zapped by causing try_step_down() to > short-circuit. > > Cc: Ben Gardon > Signed-off-by: Sean Christopherson This change looks functionally correct, but I'm not sure it's worth adding more code special cased on zap-all for what seems like a small performance improvement in a context which shouldn't be particularly performance sensitive. Change is a correct optimization though and it's not much extra code, so I'm happy to give a: Reviewed-by: Ben Gardon > --- > arch/x86/kvm/mmu/tdp_mmu.c | 13 ++++++++++++- > 1 file changed, 12 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c > index 6566f70a31c1..aec069c18d82 100644 > --- a/arch/x86/kvm/mmu/tdp_mmu.c > +++ b/arch/x86/kvm/mmu/tdp_mmu.c > @@ -751,6 +751,16 @@ static bool zap_gfn_range(struct kvm *kvm, struct kvm_mmu_page *root, > { > bool zap_all = (end == ZAP_ALL_END); > struct tdp_iter iter; > + int min_level; > + > + /* > + * No need to step down in the iterator when zapping all SPTEs, zapping > + * the top-level non-leaf SPTEs will recurse on all their children. > + */ > + if (zap_all) > + min_level = root->role.level; > + else > + min_level = PG_LEVEL_4K; > > /* > * Bound the walk at host.MAXPHYADDR, guest accesses beyond that will > @@ -763,7 +773,8 @@ static bool zap_gfn_range(struct kvm *kvm, struct kvm_mmu_page *root, > > rcu_read_lock(); > > - tdp_root_for_each_pte(iter, root, start, end) { > + for_each_tdp_pte_min_level(iter, root->spt, root->role.level, > + min_level, start, end) { > retry: > if (can_yield && > tdp_mmu_iter_cond_resched(kvm, &iter, flush, shared)) { > -- > 2.33.0.rc1.237.g0d66db33f3-goog >