From: Sean Christopherson <seanjc@google.com>
To: Jiaming Fan <fan.jiaming@hotmail.com>
Cc: Ackerley Tng <ackerleytng@google.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: Thu, 3 Dec 2026 09:57:04 -0800 [thread overview]
Message-ID: <axGtcHcmMbT1EXdD@seanjc-mac.roam.internal> (raw)
In-Reply-To: <OS3PR01MB1025187BCC2CA35B063090CCFE7462@OS3PR01MB10251.jpnprd01.prod.outlook.com>
On Sun, Nov 22, 2026, Jiaming Fan wrote:
> On Fri, Nov 20, 2026, Ackerley Tng wrote:
> > + /*
> > + * is_private (set in VM attributes) should never have been used
> > + * with a non-guest_memfd memslot. Return PG_LEVEL_4K to prevent
> > + * hugepage recovery.
> > + */
>
> Hi Ackerley,
>
> This comment feels a bit odd to me. KVM does allow marking a GFN private
> when its memslot has no guest_memfd, since PRIVATE attributes are per VM,
> not per memslot.
100% agreed. And FWIW, I don't love the code, but I also can't come up with a
more elegant solution. To address both to some degree, I'll squash the below.
That way it's more obvious how/why we can end up with a private GFN without an
associated gmem slot, and it makes me dislike the one-off check a bit less.
diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
index 8848ebd9feac..408187ccfdc8 100644
--- a/arch/x86/kvm/mmu/mmu.c
+++ b/arch/x86/kvm/mmu/mmu.c
@@ -3489,14 +3489,10 @@ int kvm_mmu_max_mapping_level(struct kvm *kvm, struct kvm_page_fault *fault,
} else {
max_level = PG_LEVEL_NUM;
is_private = kvm_is_private_gfn(kvm, gfn);
-
- /*
- * is_private (set in VM attributes) should never have been used
- * with a non-guest_memfd memslot. Return PG_LEVEL_4K to prevent
- * hugepage recovery.
- */
- if (is_private && !kvm_slot_has_gmem(slot))
+ if (is_private && !kvm_slot_has_gmem(slot)) {
+ WARN_ON_ONCE(gmem_in_place_conversion);
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>
prev parent reply other threads:[~2026-12-03 17:57 UTC|newest]
Thread overview: 3+ 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 [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=axGtcHcmMbT1EXdD@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®