Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp1363438rdd; Wed, 10 Jan 2024 18:01:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IGhOEFvHWxQmszCCVTPvJ7GZ6H30tDrGaSRdqxcLMGW9d2j6T45s6HLKf4oV/WSYJ+1zcZo X-Received: by 2002:a17:902:e989:b0:1d5:73d0:eb7d with SMTP id f9-20020a170902e98900b001d573d0eb7dmr22283plb.18.1704938510212; Wed, 10 Jan 2024 18:01:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704938510; cv=none; d=google.com; s=arc-20160816; b=t7lcqLqaiKwqm8eavWymW8NJc9yZdZAg2nlT5UaJkIGCYiSoGW8kBytImtg+ZJA6rf Y3dbILQZd01MICyH0G/nIIFBwyyORNwWm7fEiNRiaAfEwXEeg8UwL+gYtc7RhzEU0s0L cyP3bvCxNlaXLZpFR6OqZBiCjgP8LyyqBC9GU6MMvmBqRsyQk5H1Zx8pjJ5iJRzNA1aM RlEKF0bGOqpkZUCsoz4tAYG0xmCRTE/mWDkAyq1144g2+P/wYNd8aJw05m45AX5/RGS6 b5VeYypcLjdSEGAcgsMxutPUSMGf/EeItzc8jsGO7atTbyQ3FNux+xJvyNOpWbN3RUJO T41w== 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=SfisKc9ufFv9a7SmizBx1UAzf631mmq7jI6n3buw95E=; fh=YsubNrZQ0gWuK57m7npwpfEBQGmQ6VfO6ArPkYLo2pk=; b=nMthRRAa34pNGWZ+mk7ZQ30U3xg1IQ6sCGjN42aF+GwBCJ3XLjOgvUx7EPwiDuDHSu C46AQQP6ayEu4uE8Yp34Bujyi6OQA4xQ9gNGR3mUff+SyQ8ZKE1fu0O7CFovH8XSIlQw 87nxSAysV5uoDvk0rOA/W9PZAiEI5NO9xkFWvrV3WiY24bRaBz6qZD18wvID1S3zOCG6 cVclPIt7M4LA6AEX3gjlYzAF9IV+CykqPuokUP7dCIvSNbWr+RRXnmT9Hc4eAn8Uk3Qu SJZidBJz4SdR5KL++tf3Nt00ju4pBL83rzaUou3P8CTYUJczFHL9ST3qobf3jgpPU7+e pCJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="L/Prt7W+"; spf=pass (google.com: domain of linux-kernel+bounces-22944-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-22944-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id f13-20020a170903104d00b001d379d38cccsi24119plc.162.2024.01.10.18.01.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 18:01:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-22944-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="L/Prt7W+"; spf=pass (google.com: domain of linux-kernel+bounces-22944-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-22944-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 16B3128B9D5 for ; Thu, 11 Jan 2024 02:01:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A207E468E; Thu, 11 Jan 2024 02:01:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="L/Prt7W+" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.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 7F1EE110C for ; Thu, 11 Jan 2024 02:00:57 +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-yb1-f201.google.com with SMTP id 3f1490d57ef6-dbf405319b9so104032276.0 for ; Wed, 10 Jan 2024 18:00:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1704938456; x=1705543256; 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=SfisKc9ufFv9a7SmizBx1UAzf631mmq7jI6n3buw95E=; b=L/Prt7W+qLQtSixtHUPxuITHKFxaXo3oNoNS/s50MDDLr25CNooHRVb6lQmHE4VZVu qiZqtgoKBTwGxpSZKEmkXf516KJJP+rapdd4B7tTFTIgl6kTLuIs+j7FYlZhT1UN9t4j WmvG6CLFTejdc7qNhizASNDBbR9XOIT4GVRDgIYWc7urbZ+5nnRTUhHV96ZoMcP1LO1m Afas9nHDqVTU4GMzu82WgIe/mzUduoVv8a5y7NO6oZhQChpUvSMqIOhNzfWQxr7sAOzk k1Zn+NZGPZtWQVHsu1m9Kjdr0aVMNM1XSkuNliOgMjdFLLW+hV9WVsZbyTXNjgt8hr3C E0wQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704938456; x=1705543256; 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=SfisKc9ufFv9a7SmizBx1UAzf631mmq7jI6n3buw95E=; b=Ihlcj8DTzkGhMfkKDGXdlIivceTFXyYBJewIOmq/Pb8SfZItrYPmJAbdd6xjhJLJbc vXBAxR9ksMzOdX4c/PVFqUKrT6Do3ECMTJU/fd9FrDIvBQszBWBOspvI8/B+FXBktYhI MrSn82I5YFayl7KVob+SfkL0Y7/1oNIlzMU72YedgE9M/c/8yEYdeitYhFw8qy6LqGOE 9NXkznKbsdpQzklT6TizgL0kqF4Ago6DP37W5Yy+Ulsiy4kvbHNTVNHt0qWRzP50pJjP sut6oJhI7ETOqBq9xnW6NOQl5Bh/sWoMQOUcIc001tidEwv7OyWUL6Q1U61g5JFuC03M kjvQ== X-Gm-Message-State: AOJu0YxHNJ/RbxmyAwbaRGIz86TodwLK7oxbuV9r2sYr3cDlWqhVGbP7 lemXoWGCZnPy6DqQDO+HICX+Kw+2q7DWVXkXyw== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a25:7404:0:b0:dbe:111b:8875 with SMTP id p4-20020a257404000000b00dbe111b8875mr25375ybc.12.1704938456484; Wed, 10 Jan 2024 18:00:56 -0800 (PST) Reply-To: Sean Christopherson Date: Wed, 10 Jan 2024 18:00:42 -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-3-seanjc@google.com> Subject: [PATCH 2/8] KVM: x86/mmu: Don't do TLB flush when zappings SPTEs in invalid roots 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" Don't force a TLB flush when zapping SPTEs in invalid roots as vCPUs can't be actively using invalid roots (zapping SPTEs in invalid roots is necessary only to ensure KVM doesn't mark a page accessed/dirty after it is freed by the primary MMU). Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/tdp_mmu.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c index 372da098d3ce..68920877370b 100644 --- a/arch/x86/kvm/mmu/tdp_mmu.c +++ b/arch/x86/kvm/mmu/tdp_mmu.c @@ -811,7 +811,13 @@ static bool tdp_mmu_zap_leafs(struct kvm *kvm, struct kvm_mmu_page *root, continue; tdp_mmu_iter_set_spte(kvm, &iter, 0); - flush = true; + + /* + * Zappings SPTEs in invalid roots doesn't require a TLB flush, + * see kvm_tdp_mmu_zap_invalidated_roots() for details. + */ + if (!root->role.invalid) + flush = true; } rcu_read_unlock(); -- 2.43.0.275.g3460e3d667-goog