From: Sean Christopherson <seanjc@google.com>
To: Ackerley Tng <ackerleytng@google.com>
Cc: Jiaming Fan <fan.jiaming@hotmail.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Thomas Gleixner <tglx@kernel.org>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
Fuad Tabba <fuad.tabba@linux.dev>,
David Hildenbrand <david@kernel.org>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] KVM: x86/mmu: Prevent hugepage recovery on non-guest_memfd private GFNs
Date: Fri, 4 Dec 2026 16:48:05 -0800 [thread overview]
Message-ID: <axNfRZs8KEYmRgK3@seanjc-mac.roam.internal> (raw)
In-Reply-To: <CAEvNRgGu17vhnbW1sY0bT9g13Gvs6N-2tdi8C2Fzk_dBf0PHBw@mail.gmail.com>
On Fri, Dec 04, 2026, Ackerley Tng wrote:
> Not sure if you want to take this separately, AI found a reproducer to
> hit this WARN_ON_ONCE() you added deterministically.
Separately, I suspect in we have an internal syzkaller report that's hitting
the same underlying flaw.
> With gmem_in_place_conversion=true,
>
> 1. Use a KVM_X86_DEFAULT_VM, where kvm_arch_has_private_mem(kvm) is
> false.
> 2. Create a non-gmem memslot with as_id=1 with dirty logging enabled,
> overlapping with a gmem memslot with as_id=0. The gmem associated
> should be all-private (no INIT_SHARED)
> 3. Disable dirty logging on the as_id=1 memslot.
>
> is_private is true since we consulted as_id=0, kvm_slot_has_gmem(slot)
> is false because we checked on as_id=1.
>
> We've been assuming gmem only works with as_id=0, which is still what we
> want, but kvm_is_private_gfn() always checks as_id=0.
>
> Kinda wonky because if gmem_in_place_conversion=false, VM-level
> privateness is per-VM, which I guess can be thought of as defaulting to
> as_id=0.
>
> So the two options I think are viable are
>
> 1. In kvm_gmem_is_private_gfn(), return false if the
> !kvm_arch_has_private_mem(). This isn't as_id specific but it is correct
> and blocks this path.
>
> 2. Check as_id here in the caller. kvm_mmu_faultin_pfn() will be able to
> fault in a gmem-private page into SMM, but only for VMs that don't
> support private pages... so that's a userspace bug?
Hmm, screw SMM, that's my answer. :-D
#1 is the way to go, but we don't need to add to the hot path. set_attributes()
already disallows marking a GFN private in that case, we just forgot to require
that non-private memory be INIT_SHARED.
diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c
index 93f3d29d5751..778ac32930c5 100644
--- a/virt/kvm/guest_memfd.c
+++ b/virt/kvm/guest_memfd.c
@@ -1007,6 +1007,10 @@ int kvm_gmem_create(struct kvm *kvm, struct kvm_create_guest_memfd *args)
if (flags & ~kvm_gmem_get_supported_flags(kvm))
return -EINVAL;
+ if (!kvm_arch_has_private_mem(kvm) &&
+ !(flags & GUEST_MEMFD_FLAG_INIT_SHARED))
+ return -EINVAL;
+
if (size <= 0 || !PAGE_ALIGNED(size))
return -EINVAL;
> > return PG_LEVEL_4K;
> > + }
> > }
> >
> > max_level = min(max_level, max_huge_page_level);
> >
> >> I could reproduce the WARN with a KVM_X86_SW_PROTECTED_VM on AMD (nested,
> >> not TDX), and it's gone with this patch.
> >>
> >> Tested-by: Jiaming Fan <fan.jiaming@hotmail.com>
>
> Thanks for testing!
>
> Sean, when you said squash, do you mean you'd do that when applying? Do
> you need me to send v2?
No, I already squashed.
prev parent reply other threads:[~2026-12-05 0:48 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 21:07 Ackerley Tng via B4 Relay
2026-11-22 4:52 ` Jiaming Fan
2026-12-03 17:57 ` Sean Christopherson
2026-12-05 0:17 ` Ackerley Tng
2026-12-05 0:48 ` Sean Christopherson [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=axNfRZs8KEYmRgK3@seanjc-mac.roam.internal \
--to=seanjc@google.com \
--cc=ackerleytng@google.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=david@kernel.org \
--cc=fan.jiaming@hotmail.com \
--cc=fuad.tabba@linux.dev \
--cc=hpa@zytor.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=tglx@kernel.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®