From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796309032; b=RAdYAHQpOrN76fvc31S3QmgJsDxouISCLYB9MQdwRPgzBSAeur1AcasLKzBPUfVIBv+K z3fMn2PZjBXo2CeK0WzUBqXkmN6tTMlreMgOpaZnpThYhFUt3EJxydi2SfPZirzL38KtB sUoPh3Eup5x65P40MuJAImfxwR+EXnMNcY9K8n+6bFl2TYyco46yYcqQ3eFyNpInhKn4t hxZlq6yzqVPLxvWneUzXH7leBjm9iOJ+VOCmF+JqlCOXWYc5QfqXtp3iGL7yeZ1jiM2o+ dOp4ZYEulUs8PCuikcBRLHcQIAhvGuhDyYwpWtNolxc2df63onymhz1DwVJEdaS3COg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796309032; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=bBITRHhkZ0dMsmXA7E++ym+eG6msvK1wWU9EO5kauC8=; b=w6g2dXyMx/4WDP9//MmU1HT9V+4+GesSajmp+hJlmHN2S3Yl4hFUHr2y8DPmATH/5xth abKdWL2NFW1rjMsQesQHci/3Sg8/f4hOiUVINprD1cqID3E3Bp497/B7H2OfRk0hrNT6d 2qbGb71D8btvWelY8aLbAY3CseQ7cXYcY5wGb6ZP7Y73tjk5rXcW3svVCm2Sd+rJcMStt 9SfCamGXhNQCyvmTWY5nW95dNLHMCm8s0BV/Dzh4RsuvDxjUlhakF14bxG2vyLigCzP7h GDrzxE6GwSqNFFEPzcrC1nlpd9iCkECx5a5OxenKvQCGjqjlIqPGrT8Ep2OPV+Qk6sw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=M2O+qMDi; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CB3E5606A322 for ; Thu, 3 Dec 2026 14:43:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=M2O+qMDi Received: by smtp.kernel.org (Postfix) with ESMTPSA id 602231F00893; Thu, 3 Dec 2026 14:43:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796309032; bh=bBITRHhkZ0dMsmXA7E++ym+eG6msvK1wWU9EO5kauC8=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=M2O+qMDi+D9qxWp9usBDpU9MN6fFAltBgSdRRNQdS1fiEi1wC5Z8iEdAz+zuxgQsF hx5xAQ0eNAn9iXe3LTxLYCFr25ru1Y2/vTfAac2ePvc+UXJWGqPeUT9m9Z/cglAxNE Iafngi9J9SOIyj1yYzlmpi85TtP/4E3TOqggkWp55GXws0dEsAf9RSqehF4eWOXP+J cWYRn6cujo9IE9VZxTDbl+oT5crQ5DCOL+JdS5ph9fE9vjqn+5nrTIHnsDFSB8zlfy tJszzvDMCOssNv0CMAqV0z+2fJcvtaBTvWBAz7Mf69y/nMwMjjjeIRt3SzmUME5bLi p4GKuMklEbx5A== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2] KVM: x86/mmu: Zap collapsible SPTEs on ranges with active invalidations Reply-To: sashiko-reviews@lists.linux.dev To: =?utf-8?b?S3J6eXN6dG9mIFdvxZs=?= Cc: kvm@vger.kernel.org In-Reply-To: <179630591906.459399.8619305795048760319@gmail.com> References: <179630591906.459399.8619305795048760319@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 14:43:52 +0000 X-Mailing-List: kvm@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] KVM: x86/mmu: recover_huge_pages_range() can zap TDX mirror non-leaf SPTEs -- commit 383a8a9cb0faf2691412211c4c44174397818320 Author: Krzysztof Wo=C5=9B KVM: x86/mmu: Zap collapsible SPTEs on ranges with active invalidations This commit factors out kvm_mmu_invalidate_range_in_progress() and uses it in recover_huge_pages_range() to zap collapsible non-leaf SPTEs instead of promoting them in place when an mmu_notifier invalidation overlaps the hugepage range. > diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c > index 44dad106fad19..af05a91b6fa9c 100644 > --- a/arch/x86/kvm/mmu/tdp_mmu.c > +++ b/arch/x86/kvm/mmu/tdp_mmu.c > @@ -1800,6 +1800,24 @@ static void recover_huge_pages_range(struct kvm *k= vm, > if (max_mapping_level < iter.level) > continue; > =20 > + /* > + * If an in-progress mmu_notifier invalidation overlaps the > + * hugepage range, a subset of child SPTEs may have been zapped > + * while the host mapping is still huge, making in-place > + * promotion unsafe. Fall back to zapping the collapsible > + * non-leaf SPTE, which obeys host_pfn_mapping_level()'s > + * contract and lets subsequent faults rebuild a huge SPTE once > + * the invalidation completes. > + */ > + if (kvm_mmu_invalidate_range_in_progress(kvm, iter.gfn, > + iter.gfn + KVM_PAGES_PER_HPAGE(iter.level))) { > + if (tdp_mmu_set_spte_atomic(kvm, &iter, SHADOW_NONPRESENT_VALUE)) > + goto retry; > + > + flush =3D true; > + continue; > + } > + > r =3D tdp_mmu_make_huge_spte(kvm, &iter, &huge_spte); > if (r =3D=3D -EAGAIN) > goto retry; [Severity: High] Can this zap a lingering non-leaf SPTE in an active TDX mirror root? kvm_tdp_mmu_recover_huge_pages() walks KVM_VALID_ROOTS, which includes mirr= or roots. When a KVM_MEM_GUEST_MEMFD memslot is deleted in a TDX VM, its empty mirror non-leaf SPTEs remain linked until TD teardown. If userspace then clears KVM_MEMORY_ATTRIBUTE_PRIVATE on that range, adds a regular hugepage-backed memslot with KVM_MEM_LOG_DIRTY_PAGES, and disables dirty logging during an overlapping mmu_notifier invalidation, kvm_mmu_max_mapping_level() returns PG_LEVEL_2M via host_pfn_mapping_level(= ). Before this patch, tdp_mmu_make_huge_spte() returned -ENOENT on the empty mirror child page table and skipped the update. Now this fallback runs fir= st and zaps the mirror non-leaf SPTE, calling handle_removed_pt() -> tdx_sept_free_private_spt(). Because the TD HKID is still assigned, tdx_sept_free_private_spt() hits KVM_BUG_ON(is_hkid_assigned(to_kvm_tdx(kvm)), kvm), bugs the VM, and leaks the encrypted S-EPT page in sp->external_spt. Should kvm_tdp_mmu_recover_huge_pages() walk only direct roots? --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/179630591906.459399= .8619305795048760319@gmail.com?part=3D1