From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C7136CCD199 for ; Fri, 17 Oct 2025 00:33:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Reply-To:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID :References:Mime-Version:In-Reply-To:Date:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=QzJzu9VLJz9K70QPBnd9PE9JM7cw1Ir4+dFJWPBBCjI=; b=Bi932850j9JnH+ EqDdWrXLL0c3nKUBrF/CcffZUiQhvuzaqXdjdpMD/ryAMVVf3fxWQCH99oAB/z84LEc8YEO/o8nOQ /P6/tRJhxgZw4o7V2cs19cUHZFeejRTbSscndaa72UULXtf51SrqForCkAlNgTH3x9wptcmz+mHlR xdE8BoAvxtvQVuHlqULhwSKXk2lawZgKzTq9bWaVb9DmhXhKLHMk4HT1XODYlAR/LsjZfE96ybU8R B45YMHHRxXyAf7rodOS7H+E52ToMQ5EwnRl78lMo8ynrmfXynUsXe2iwAbDkXEVTf+tO9SfSkQpqJ oh3HnY2op5h58iISdjWw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1v9YOz-00000006CiQ-37uM; Fri, 17 Oct 2025 00:33:01 +0000 Received: from mail-pj1-x104a.google.com ([2607:f8b0:4864:20::104a]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1v9YOs-00000006CXn-3JFS for linux-riscv@lists.infradead.org; Fri, 17 Oct 2025 00:32:56 +0000 Received: by mail-pj1-x104a.google.com with SMTP id 98e67ed59e1d1-32eb18b5659so1155865a91.2 for ; Thu, 16 Oct 2025 17:32:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1760661174; x=1761265974; darn=lists.infradead.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=ufVneY39YrbdCfRZpp0jVK1n9RSn66wnVA9SJtGGBdY=; b=4oa6caSMum2WHT2zMG3xhhyI3dNcRr8cDPoC20Ij26eNiFw28CZibjrprKTlm6MKe5 POttPdnydUnKx5yqKvgRAZdQGxc2DcC6isz+c75l9gHqGxKHqWxzO2oS6qmcrJzgqOvK p+blFmKjfF157bQ/sqZkxQf61/3CoqikYQxe6AWy9yjd4DuO/eqvR1zvD9Gt2dIG93mV NzBgf5IXDwCi9IsHNYJTNxwk12CUBeY/jW5svIUe2ZgUzzbcUQJJzBcmlNfg2RXRjj9O LiJ0haW04bt3YRqyGI7Ji7e5el68eSOi9qfn87Y4XInxgMA1HlOKArcGrDiZC9BFclm/ E5xA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760661174; x=1761265974; 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=ufVneY39YrbdCfRZpp0jVK1n9RSn66wnVA9SJtGGBdY=; b=kbby6Marknm2uiIcx6VpLBYR4eBSK9UySv6WPoi33PQKRZx9TUfHqP57v/no1utLJj 0dxhmlZJiPU4h2DnCfoIKdwtvla6p5zcM2g4PHtS98oTr0bRvFWOZdYUBVlS915yhj5/ OTxMtYMNUmuZXReOLsAyyd10tCWoLVCHbNjcXq3hw5VMiIVsZDXo6QUwlPpoutk5OQ5n q9wOfY2LzuuSP3LOmDbxPP06g/GUCiJHYSOpl6wHpBnWPr3fpgqn80pwT834llG0KHjP 7aDOY4PKMBY/exP21pIu3Uzb9VfpR/oOPkcqG0CeBPLKhqHk/OVkLPpuLU0cOxTUobpB +kzA== X-Forwarded-Encrypted: i=1; AJvYcCUdhLHvTUe2kHdqznCLq4hoN6z767fcfNYPcApCPD6mxXZ7oxwd+snJD2DeZzVVN3Rxr9boVK/V25PkVw==@lists.infradead.org X-Gm-Message-State: AOJu0YzlfSEe2eq0vxUSBNXwN/KVllBU7JJVY9oEvzC3Lop4aeRrStz7 6P7zKFTQ2udvB9WZCZa15ZitdaQq+N9YC2pT8UFE9eD/dBnaS7dDwyevXWMC5sqJEkT4A6w33oS 3jyZ1ig== X-Google-Smtp-Source: AGHT+IGBsD40M1TCHpceHuTvrzQu31EsWCpow7sShvAnQiEKP0H9VSo9B6k/+Ftt8wsphMd8FgX3xhZLFrA= X-Received: from pjop7.prod.google.com ([2002:a17:90a:9307:b0:33b:aa58:175c]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:2fd0:b0:32d:601d:f718 with SMTP id 98e67ed59e1d1-33bcf8f9c16mr1675095a91.31.1760661173675; Thu, 16 Oct 2025 17:32:53 -0700 (PDT) Date: Thu, 16 Oct 2025 17:32:21 -0700 In-Reply-To: <20251017003244.186495-1-seanjc@google.com> Mime-Version: 1.0 References: <20251017003244.186495-1-seanjc@google.com> X-Mailer: git-send-email 2.51.0.858.gf9c4a03a3a-goog Message-ID: <20251017003244.186495-4-seanjc@google.com> Subject: [PATCH v3 03/25] KVM: TDX: Drop PROVE_MMU=y sanity check on to-be-populated mappings From: Sean Christopherson To: Marc Zyngier , Oliver Upton , Tianrui Zhao , Bibo Mao , Huacai Chen , Madhavan Srinivasan , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Sean Christopherson , Paolo Bonzini , "Kirill A. Shutemov" Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvm@vger.kernel.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, x86@kernel.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, Ira Weiny , Kai Huang , Michael Roth , Yan Zhao , Vishal Annapurve , Rick Edgecombe , Ackerley Tng , Binbin Wu X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20251016_173254_882167_135DDD40 X-CRM114-Status: GOOD ( 19.38 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Sean Christopherson Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Drop TDX's sanity check that a mirror EPT mapping isn't zapped between creating said mapping and doing TDH.MEM.PAGE.ADD, as the check is simultaneously superfluous and incomplete. Per commit 2608f1057601 ("KVM: x86/tdp_mmu: Add a helper function to walk down the TDP MMU"), the justification for introducing kvm_tdp_mmu_gpa_is_mapped() was to check that the target gfn was pre-populated, with a link that points to this snippet: : > One small question: : > : > What if the memory region passed to KVM_TDX_INIT_MEM_REGION hasn't been pre- : > populated? If we want to make KVM_TDX_INIT_MEM_REGION work with these regions, : > then we still need to do the real map. Or we can make KVM_TDX_INIT_MEM_REGION : > return error when it finds the region hasn't been pre-populated? : : Return an error. I don't love the idea of bleeding so many TDX details into : userspace, but I'm pretty sure that ship sailed a long, long time ago. But that justification makes little sense for the final code, as the check on nr_premapped after TDH.MEM.PAGE.ADD will detect and return an error if KVM attempted to zap a S-EPT entry (tdx_sept_zap_private_spte() will fail on TDH.MEM.RANGE.BLOCK due lack of a valid S-EPT entry). And as evidenced by the "is mapped?" code being guarded with CONFIG_KVM_PROVE_MMU=y, KVM is NOT relying on the check for general correctness. The sanity check is also incomplete in the sense that mmu_lock is dropped between the check and TDH.MEM.PAGE.ADD, i.e. will only detect KVM bugs that zap SPTEs in a very specific window (note, this also applies to the check on nr_premapped). Removing the sanity check will allow removing kvm_tdp_mmu_gpa_is_mapped(), which has no business being exposed to vendor code, and more importantly will pave the way for eliminating the "pre-map" approach entirely in favor of doing TDH.MEM.PAGE.ADD under mmu_lock. Reviewed-by: Ira Weiny Reviewed-by: Kai Huang Signed-off-by: Sean Christopherson --- arch/x86/kvm/vmx/tdx.c | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c index 326db9b9c567..4c3014befe9f 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -3181,20 +3181,6 @@ static int tdx_gmem_post_populate(struct kvm *kvm, gfn_t gfn, kvm_pfn_t pfn, if (ret < 0) goto out; - /* - * The private mem cannot be zapped after kvm_tdp_map_page() - * because all paths are covered by slots_lock and the - * filemap invalidate lock. Check that they are indeed enough. - */ - if (IS_ENABLED(CONFIG_KVM_PROVE_MMU)) { - scoped_guard(read_lock, &kvm->mmu_lock) { - if (KVM_BUG_ON(!kvm_tdp_mmu_gpa_is_mapped(vcpu, gpa), kvm)) { - ret = -EIO; - goto out; - } - } - } - ret = 0; err = tdh_mem_page_add(&kvm_tdx->td, gpa, pfn_to_page(pfn), src_page, &entry, &level_state); -- 2.51.0.858.gf9c4a03a3a-goog _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv