From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C407944BC87; Thu, 30 Jul 2026 15:29:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785425377; cv=none; b=qc7TU62BLEY/hTG6zUkpEDWqmOgf0nB+uvbFMAIjk2r9IwVk8iBAJVN8IQ27kpjPWx+wrD1vbyLrFPtchafJzj+cHFISpH2iBUMaairIYtqgPxNUMBUOpMqggRrbwYNQiztH9svdIyw8pm2tUlQrn4oVokNNKUBy5vMygdZHdBI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785425377; c=relaxed/simple; bh=cZoKjXa5WYY0YuaLPRxnfVUc/kRAV0mO7rUCgvRcLZw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HE43bCARTtsd444Cr8aQS3SH8Y05hfirQ3khZN4kdXUfEjAf8yGEj6g3FZ0sR7bU0AK0Agp23TqJUVa2P0Mc9dPlVTdF1spui+FWnNabkknqetsk0d17LmDSVzY06y5maXfY5UxUd+N8979GCuBq2Q5MyCKAdmmbXRLKJtATnBg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=HaHXUEgA; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="HaHXUEgA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BF3BF1F00A3A; Thu, 30 Jul 2026 15:29:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1785425375; bh=GfNKNZt38hfvRFNs+8ZAej6N/0HLnWSh+RH3kQActA8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=HaHXUEgAKHQNfUQpN2QiFsTDO9EqLcwOtOhAQfgjcTawYl0tA+D0v+nAmvFmONY4W QToKGW/8yRadZHmaCrBAXvQvAsya1AEyKeyLfB8hQY3+VBcoC93nsqmg825P7KLh8q s+hcnIAoE/ZiUmoF+mOZnRASOf+2dcdTV0kEAGFI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Hyunwoo Kim , Sean Christopherson , Paolo Bonzini Subject: [PATCH 6.12 014/602] KVM: x86: Check for invalid/obsolete root *after* making MMU pages available Date: Thu, 30 Jul 2026 16:06:46 +0200 Message-ID: <20260730141436.298853843@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260730141435.976815864@linuxfoundation.org> References: <20260730141435.976815864@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Sean Christopherson commit 2abd5287f08319fa35764566b15c6e22cb1068db upstream. Check for a "stale" page fault, i.e. for an invalid and/or obsolete root, after making MMU pages available for the shadow MMU. If reclaiming shadow pages zaps an in-use root, i.e. marks it invalid, then KVM will attempt to map memory into an invalid root. On its own, populating an invalid root is "fine", but because child shadow pages inherit their parent's role, any children created during the map/fetch will be created as invalid pages, thus violating KVM's invariant that invalid pages are never on the list of active MMU pages. Note, the underlying flaw has existed since KVM first started tracking invalid roots in 2008 (commit 2e53d63acba7, "KVM: MMU: ignore zapped root pagetables"), but the true badness only came along in 2020 (Linux 5.9) with the invariant that invalid shadow pages can't be on the list of active pages. Note #2, inheriting role.invalid when creating child shadow pages is also far from ideal; that flaw will be addressed separately. Reported-by: Hyunwoo Kim Fixes: f95eec9bed76 ("KVM: x86/mmu: Don't put invalid SPs back on the list of active pages") Cc: stable@vger.kernel.org Signed-off-by: Sean Christopherson Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/mmu/mmu.c | 9 +++++---- arch/x86/kvm/mmu/paging_tmpl.h | 10 ++++++---- 2 files changed, 11 insertions(+), 8 deletions(-) --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -4601,16 +4601,17 @@ static int direct_page_fault(struct kvm_ orig_pfn = fault->pfn; - r = RET_PF_RETRY; write_lock(&vcpu->kvm->mmu_lock); - if (is_page_fault_stale(vcpu, fault)) - goto out_unlock; - r = make_mmu_pages_available(vcpu); if (r) goto out_unlock; + if (is_page_fault_stale(vcpu, fault)) { + r = RET_PF_RETRY; + goto out_unlock; + } + r = direct_map(vcpu, fault); out_unlock: --- a/arch/x86/kvm/mmu/paging_tmpl.h +++ b/arch/x86/kvm/mmu/paging_tmpl.h @@ -839,15 +839,17 @@ static int FNAME(page_fault)(struct kvm_ orig_pfn = fault->pfn; - r = RET_PF_RETRY; write_lock(&vcpu->kvm->mmu_lock); - if (is_page_fault_stale(vcpu, fault)) - goto out_unlock; - r = make_mmu_pages_available(vcpu); if (r) goto out_unlock; + + if (is_page_fault_stale(vcpu, fault)) { + r = RET_PF_RETRY; + goto out_unlock; + } + r = FNAME(fetch)(vcpu, fault, &walker); out_unlock: