Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp311989pxt; Wed, 11 Aug 2021 22:12:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+gXXUdhXl0rBeWHOaOTf3mvnYjyv617iPItj0R8ysrohs0x1F0HLLiNUBferPhLVTWuVk X-Received: by 2002:aa7:c3cf:: with SMTP id l15mr3194907edr.83.1628745162081; Wed, 11 Aug 2021 22:12:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628745162; cv=none; d=google.com; s=arc-20160816; b=iU3zilSV4kqoVqRl9wHZYKoZFLkgzEjySrRyhuAAnIdMHqw/uI+yM0h7KYYz13isyh 4FP1n8ZtdcNVc0T2CmzNN+2yValwGpdymXA3u+pkMRusedO3BiR4yBRIS0olmq7suRIQ Pc2hdIf+RdHSn8BD19mqUEGYR/2a/LI04XlEF+uhUCfUUMh/QE7K8jUsA1pO5SqquFcZ oS5dWVIBN6XQB1AGCwTfBJ/AShDDXPord6/4jab6ONykwuPnpb8nebokDEUd1mOfpuFJ bUd7Q2tT8TXckvImsWJBRFWiuDjHU04anf9dCak82P8l6YzBjz1XDktm4ta1bbeCL4OY I/ZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:reply-to:dkim-signature; bh=tu2iufR9aI/LsGWpANNecIoICf6nuJGttYFfk37Urfg=; b=Nb/E7fCQagnAeXH4TEfp8DjyQFZPwZadRhY5WRiKZkMNorvekTDB0FHVZi8cMSL7Cw ZqJP85raq4K3DVIH5jb7v6NHrUJ6HajpTmoiMEdTjVprkeuBD10wC8iahLsqzVKNcLFG 6q1+rcJbVm+gRMGcIb6Z/NQjT0bt0EhwOJKx/KRq4HEG++Rr/MurDYPQ0hViOBync/j3 xxon5Hochh1kScbTaxKNZALSTC/TSyOfyAXiER0BheH31yU4qHPjnONQLZPRcERXE9bv yunbN35+fRGPFbGfUCHQYxg4Pw1IxOi+UkYsiPoWRHo61UnGR8WkE7nLII/IiOhkl6lX rSlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=gDGO2Chg; 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 s5si1638497edr.161.2021.08.11.22.12.19; Wed, 11 Aug 2021 22:12:42 -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=gDGO2Chg; 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 S234207AbhHLFHw (ORCPT + 99 others); Thu, 12 Aug 2021 01:07:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234210AbhHLFHu (ORCPT ); Thu, 12 Aug 2021 01:07:50 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A82BC0613D5 for ; Wed, 11 Aug 2021 22:07:25 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id j9-20020a2581490000b02905897d81c63fso5039065ybm.8 for ; Wed, 11 Aug 2021 22:07:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=tu2iufR9aI/LsGWpANNecIoICf6nuJGttYFfk37Urfg=; b=gDGO2ChgUCHmoQiOTXqkDMN+duj4YxkrJ/UzuL4FTogwGRv3AadGos1imJV/VsqrPt C6vf6hkGnjmL3GVWuhwyh4gpVwx/FranaKpxHrs5tF+lUSBQD6ia4eHmtLY5FAou4Gnw YVYYs2VUdqRTVUBRxx+rmWhnZSmcupoOyVBcuI7uQLQpZUomvt0+nndsPD+2HVyUKE3k itX9sVh8yuORhYy/81vNkmDMVNMX+rMsEzmioXflGzJJHVSjOxdlh1Na06g2bvG5xTtM 1comgk7mTRjn/UWZ7FVcAwhwSpzvni+E4ZqS/JG9tuI4BGNjyE6OvY0rCoz9oPgDH4cY 6cjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=tu2iufR9aI/LsGWpANNecIoICf6nuJGttYFfk37Urfg=; b=hCWriz/eHEc0wJ+ccsHcsWy6Ey2UAohIC6SGYrCMQZS6UNc45QH7MqOfd+dYV3rxGO AHvweYL5imrGAdDBBuPHZQeNnqdNowZnbEKNgMjcIS5telagENzbHqWNvP8Uol2T3jVs 0eZwx9BONZSjeU14CPyoT71KzTjoZXwW93ogPcq193z3QLcw4NMSuHy4+ofRYenfSRHu vYI3ZjGeHssUOzQCx7UkQFTJNmxvmqT8yVNsZb5nkeWpYVBM3zEgveI6UpC7a1Ls6Nik VUlmYinx2xKm4k/8f0d4c5MjQQ8rmStSeLZWDM+rpLVyIm9Gm5J0lhWgBf3fKPmuTfIc E5bw== X-Gm-Message-State: AOAM532bHO9Coagi62FFplpbcA2f6pAzdK+Bgy7dX0luv+HYlwOm8a5l WOiHO7pFKvwho0zoN216PaBohxfDHIU= X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:90:200:f150:c3bd:5e7f:59bf]) (user=seanjc job=sendgmr) by 2002:a25:ba05:: with SMTP id t5mr2017139ybg.120.1628744844668; Wed, 11 Aug 2021 22:07:24 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 11 Aug 2021 22:07:17 -0700 In-Reply-To: <20210812050717.3176478-1-seanjc@google.com> Message-Id: <20210812050717.3176478-3-seanjc@google.com> Mime-Version: 1.0 References: <20210812050717.3176478-1-seanjc@google.com> X-Mailer: git-send-email 2.33.0.rc1.237.g0d66db33f3-goog Subject: [PATCH 2/2] KVM: x86/mmu: Don't step down in the TDP iterator when zapping all SPTEs From: Sean Christopherson To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Ben Gardon Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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