From nobody Mon Jun 22 18:10:51 2026 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 CA034C433F5 for ; Fri, 18 Mar 2022 16:42:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239328AbiCRQnu (ORCPT ); Fri, 18 Mar 2022 12:43:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234993AbiCRQnr (ORCPT ); Fri, 18 Mar 2022 12:43:47 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3287F20D527 for ; Fri, 18 Mar 2022 09:42:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1647621747; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=1vSc6tKsqTDEdn0ltpuGYsQKefstgNsTqnfTdgOsc7M=; b=Jy/IJrfvHiNx/ehVik76UqtvqXPFT2HkIFNJhn+Y9l7JwXu8r0q7VZS36fmwOyV8VBgu2a nZ6upclEKwD94bESOvZZmeN/ILc9QW1bLe64m2TSv78R2h4GyknN5bPgh9ECiFTvgQG1d0 moXx0SrPtiwCzToG521YhJToVsrBSbQ= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-317-kVmja--TPlqtnoIqShaTJw-1; Fri, 18 Mar 2022 12:42:26 -0400 X-MC-Unique: kVmja--TPlqtnoIqShaTJw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AEB28381748C; Fri, 18 Mar 2022 16:42:25 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9632C40149B5; Fri, 18 Mar 2022 16:42:25 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: [PATCH] KVM: x86/mmu: Recurse down to 1GB level when zapping pages in a range Date: Fri, 18 Mar 2022 12:42:25 -0400 Message-Id: <20220318164225.2743431-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The recursive zapping that was reintroduced by reverting "KVM: x86/mmu: Zap only TDP MMU leafs in kvm_zap_gfn_range()" can be expensive. Allow zap_gfn_range to recurse down to the PDPTE level, so that periodic yielding is possible with a finer granularity. Signed-off-by: Paolo Bonzini --- arch/x86/kvm/mmu/tdp_mmu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c index 87d8910c9ac2..53689603078a 100644 --- a/arch/x86/kvm/mmu/tdp_mmu.c +++ b/arch/x86/kvm/mmu/tdp_mmu.c @@ -926,8 +926,10 @@ static bool zap_gfn_range(struct kvm *kvm, struct kvm_= mmu_page *root, /* * No need to try to step down in the iterator when zapping all SPTEs, * zapping the top-level non-leaf SPTEs will recurse on their children. + * Do not do it above the 1GB level, to avoid making tdp_mmu_set_spte's + * recursion too expensive and allow yielding. */ - int min_level =3D zap_all ? root->role.level : PG_LEVEL_4K; + int min_level =3D zap_all ? PG_LEVEL_1G : PG_LEVEL_4K; =20 end =3D min(end, tdp_mmu_max_gfn_host()); =20 --=20 2.31.1