Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp1363765rdd; Wed, 10 Jan 2024 18:02:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IHCpLDkUTaEa3SZhg47n+l7jaHDKLAdv5/akZsrDmdnf0pjKMWjbo0ygAk6mx0K9Z01Bp2e X-Received: by 2002:a17:907:c17:b0:a27:efb8:6d51 with SMTP id ga23-20020a1709070c1700b00a27efb86d51mr113884ejc.228.1704938548676; Wed, 10 Jan 2024 18:02:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704938548; cv=none; d=google.com; s=arc-20160816; b=u6RnyvpO1Z4Zle03Wpa6lT66NaSnMMEHj7QtYU8X9vs7pB9wwRj7o8xnGJvx7tUC7i l5OA5w773xNriTYrhdU8PHVwE+LeM7fCQUesTCfE2ISUNJjZYe2Aqn7OeCOOs4gJH/NL Mf+QDe+2hDeh5KLGprym8fd5yJocajQDdmZBOHXmKdVO0O4Jvt7U6KO2JGe9o8WQ1TqY PC3PiaPzpChErxh8Y4z09VOfLk+6kyCsyuafZjeOFqrZgtIi3ylKm6fllWz9XU8n9puQ AvAtbnpjk58q+96AvoJe6voagrWx4Fo6Jmmfa98tFr46jTqSpuKsod1ZR0f6PVNqUsLX palA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :reply-to:dkim-signature; bh=rqBadYBCjb9CMnJD46FFXiqodKZoyoy85BjKjELucac=; fh=YsubNrZQ0gWuK57m7npwpfEBQGmQ6VfO6ArPkYLo2pk=; b=EF65lOcmDFMTxKwH6ZoQaSW8uA0ZHL2e+GtM3nPmt+TK/6G1Z2QgZZ9VAKnDPhdbwf HP9EQQvB4KYKykOxZUywILI7tb6m3fMKDg4uyzrFGBqktyAkauFKhbV1IJlobR7+hWuc 5QsmXFUI3GUNK2uHaJIR8hDt4+vIH0SUCr6hDXCrW555aE5ImHmyY2Je8WNciMg476IR HW9YLRCIpCtAI55w6f+u/a/wO9aKa4IhG9gIRiyZ4zKflnqgdxWwgeQ02hWkOCcc7u7R cDRBQKEes92RIyPcZTx7dLAH3kyrk0rim3Th/8LB5c6tXgzx0HyG7S6mEYQJtUVSBlK+ N8aA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="EGCWAu/R"; spf=pass (google.com: domain of linux-kernel+bounces-22946-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-22946-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id e26-20020a170906249a00b00a2b65e5101dsi18894ejb.998.2024.01.10.18.02.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 18:02:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-22946-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="EGCWAu/R"; spf=pass (google.com: domain of linux-kernel+bounces-22946-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-22946-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 6CD881F2251D for ; Thu, 11 Jan 2024 02:02:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2D8536FC6; Thu, 11 Jan 2024 02:01:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="EGCWAu/R" Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0A2964C8D for ; Thu, 11 Jan 2024 02:01:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-5f9e5455db1so32614747b3.1 for ; Wed, 10 Jan 2024 18:01:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1704938460; x=1705543260; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=rqBadYBCjb9CMnJD46FFXiqodKZoyoy85BjKjELucac=; b=EGCWAu/RoLW5bBt2zCHMnoPeZXE+ZUo7T4XO7g9D9PzcGx42PlKKRO3zAc2XgsgXG0 4YlVgaWoyOOxieQoHrof0fLfqTUh1+DkbELePUrShMEh2nrpDsJ8CFTrOAS9i65K6kQZ st9peNN9CWJd2Mi1LoDjRn2t+dVG6l3yqyZZVhkkR0z4+EItI1V3YBlrGM1MB3grPDCC 2xMi8RsIOPLD7YBkBE8BUQEG2sWN5cyHrINhFNnWo+k5IuP5imfjRYHcL1WT5/ASp/uj RQYNQgbFFpUpctcDDcSwRPnscYuWB/+NXZfsWr/K20sGxKFgWeDr6nH8YhXO8TSCMr9p fpjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704938460; x=1705543260; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=rqBadYBCjb9CMnJD46FFXiqodKZoyoy85BjKjELucac=; b=M7nNQ3gGioEGTj1o4WrUCChVut+MUzqpRz9+hvy2hKSub9b5URgS+7w7BiBBybNsyW ZiXdTmEajTap6tb0Zsq8A+3HMrDOhQoHqrmM+2uOLlNyclfE9AnZiDWKaVbD4G8hAJtT YHnZFD6NFtP7W/q2o+shdP5EuN2pCFnzdwcrB1AKfDEA1biRr7qTVoxUknmVmFgA96dC 2B+nO7G76ptHmqpuNVNt09V9nHKyJUlTTKzha/hYU15QH90kqP66RjwZtwaEgB83yT/Z YDjMT0D0ayytFzV4RZFdlGWWBbsu41G0GnbzDPOy+bYwbP92rbHfjhQAIYvszF+SpmiB z4YQ== X-Gm-Message-State: AOJu0YyXSGINbM4CfbiXt8uRTWcpt2sCU/mSbSXjSsVDsGOjVs9jbwTj ueJr4kFrWcriE+qQW96WTmDFCcW0WjSsbeVbmw== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a0d:fac4:0:b0:5f9:7737:d9a8 with SMTP id k187-20020a0dfac4000000b005f97737d9a8mr228905ywf.7.1704938460020; Wed, 10 Jan 2024 18:01:00 -0800 (PST) Reply-To: Sean Christopherson Date: Wed, 10 Jan 2024 18:00:44 -0800 In-Reply-To: <20240111020048.844847-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240111020048.844847-1-seanjc@google.com> X-Mailer: git-send-email 2.43.0.275.g3460e3d667-goog Message-ID: <20240111020048.844847-5-seanjc@google.com> Subject: [PATCH 4/8] KVM: x86/mmu: Skip invalid roots when zapping leaf SPTEs for GFN range From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, David Matlack , Pattara Teerapong Content-Type: text/plain; charset="UTF-8" When zapping a GFN in response to an APICv or MTRR change, don't zap SPTEs for invalid roots as KVM only needs to ensure the guest can't use stale mappings for the GFN. Unlike kvm_tdp_mmu_unmap_gfn_range(), which must zap "unreachable" SPTEs to ensure KVM doesn't mark a page accessed/dirty, kvm_tdp_mmu_zap_leafs() isn't used (and isn't intended to be used) to handle freeing of host memory. Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/tdp_mmu.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c index 60fff2aad59e..1a9c16e5c287 100644 --- a/arch/x86/kvm/mmu/tdp_mmu.c +++ b/arch/x86/kvm/mmu/tdp_mmu.c @@ -830,16 +830,16 @@ static bool tdp_mmu_zap_leafs(struct kvm *kvm, struct kvm_mmu_page *root, } /* - * Zap leaf SPTEs for the range of gfns, [start, end), for all roots. Returns - * true if a TLB flush is needed before releasing the MMU lock, i.e. if one or - * more SPTEs were zapped since the MMU lock was last acquired. + * Zap leaf SPTEs for the range of gfns, [start, end), for all *VALID** roots. + * Returns true if a TLB flush is needed before releasing the MMU lock, i.e. if + * one or more SPTEs were zapped since the MMU lock was last acquired. */ bool kvm_tdp_mmu_zap_leafs(struct kvm *kvm, gfn_t start, gfn_t end, bool flush) { struct kvm_mmu_page *root; lockdep_assert_held_write(&kvm->mmu_lock); - for_each_tdp_mmu_root_yield_safe(kvm, root) + for_each_valid_tdp_mmu_root_yield_safe(kvm, root, -1) flush = tdp_mmu_zap_leafs(kvm, root, start, end, true, flush); return flush; -- 2.43.0.275.g3460e3d667-goog