From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.198 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796320626; b=z9eqxjFjyod8PcVy6lAVrCu+ilukqrK3/ukNekqQ9qfCluEAT0Eq3mDohF3pEGCcmfpm oVxo0ksKOckQVmQWh2BtGhSU8dk5+QK5xEqjGdaWIzSWPchYEw0Oya6ZM5bZhAoWUAVTW xq2/y6VlERdB6x0+0/IaKD6LId4gxxnSGRPSKN/i5gdiWsdDO/8Nojl8k4pcCGE1+WOXQ TqUq/rmOIp/z4VT/AoIx8WJar+qhdKx1auWNYuvcNeJQSqSBaUaneWDCcEI9/7bPp3G1g wVvIWbTXoRP6uP9dqLX3SjoZyGUWepXher3VXf0VqChk1qoGrTw5dABkPcDY4Re+baw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796320626; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:Message-ID:Subject:From:To:Cc:Content-Type; bh=PAf0gr3zUwk1aupGHBPyeeZuoyboJ7xhCcnIiUVngRE=; b=qzhN7VzRQnZf1fa37XEylGR041FrVNjQen+uX3tRc9vB6UkZPlEETNEV5SCIDoSomzSE t+Qp9bZ4mRz15M7F7YEZBQrxKVWX5a27og3gUpmGulEh1UpV2BYr2WbaWeDoD3bCbE99k ynAhWCNGTluXeFY/zNrgQD2hjVHQSL1El/Y+HCq05NyNrt86CLCzu2DvB3jwI3eF4jv6Z VlPauGUy/ktvrRC/s7lKaovY4mgbzrpHe1t4fVFUAPwqOnZoUbLWDnmhIHK0mZxZyxgxK 3C5TVGOzZqLfCqrxrC8IWqi/8e8F0frrOgVlY2ULkMXdi+VsJVZCDYbwvmCBqnaw8gA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=cNCTJ3KQ; arc=none smtp.remote-ip=209.85.210.198 Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0E4EC606A32C for ; Thu, 3 Dec 2026 17:57:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0E4EC606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=cNCTJ3KQ Received: by mail-pf1-f198.google.com with SMTP id d2e1a72fcca58-8b7cc3f8a4aso49311b3a.3 for ; Thu, 03 Dec 2026 09:57:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796320625; x=1796925425; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=PAf0gr3zUwk1aupGHBPyeeZuoyboJ7xhCcnIiUVngRE=; b=cNCTJ3KQi2livyNvmwe/zEug/uvVESfAx6+SKZ+J+CFNPgp4QVcxOtNiBvdmIA5OUq rJGX+3b6T97DrIRqunqOQN+Ku74F3YWnM8KkuvK7tqOKtTcDWgcT8uoFp7NlredoxMi4 ulFLxqDxJ7oQIV7aL1vrG73830USOB3nGs8AuZMCvU0Jpxr/PjmRq7mgNuXy0CPpUiL3 JlGdttwIwGuyfVA0/tMYmEve8o61zzIAcVHp3Pmu1aTuixUurihO/kN+NtSBj/WHroUK N75C4LBjbMt3xdfXPRcnj3yG1bXgLyhFXGS/oU5vTKE4WF+VOrDoj0BgjkqJILKyT/xF Syow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796320625; x=1796925425; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=PAf0gr3zUwk1aupGHBPyeeZuoyboJ7xhCcnIiUVngRE=; b=BSak/j9/6khMKajWfomps54D2FZFy2CjwAsvWa9fozZxwc6AfkgxzNlQKEyII+TYqo 2sTjYIc7CPWoiAzjDU/2n4YypKyc+fs3uftsbj7ALTOeuFvofwStolYZdg2ZsqrViPkM 07LdbV+nA7PqUABmB1llWpV6NgunUtqQS4/vVlVuV8TCT5jMfVvXWRPhLucCFKr6IPFJ Jksc9qJ7Gy7mGXyaq28XjZ/UsQdc76loy29bd7qiP+3RMiDZrDUwAi3lw5mNGb6yN9BB jX8Vw/jSbi0+25hpdlghoMQ2PehvGNyaFMuze/EQSBk6IWp0UuNRbm5zSuSyoLZrJd8U Jiig== X-Forwarded-Encrypted: i=1; AL+hErHftLF1kN07n5sEE01unEdBhKhem/K0EuyvjXhfQ4I0fBq3MSlYjHqA8KQC0RAZt+I/ChQGEM4d0QvRjsI=@vger.kernel.org X-Gm-Message-State: APuU4Z+s0B0B/Dj+772Tk1fVH1nXn8FEs8b/Mf6/qVD3Q1SKR4s3Enrf tY19uBLW9FuCXTsR6vdgIj6vh9IqoeDY2kwpH/X2R4eBDt3Ycs7L2vY8u5Q4Y8xDcwV6FnRnSab T7fxfEQ== X-Received: from pfbkh9.prod.google.com ([2002:a05:6a00:9449:b0:8a5:a56c:9408]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:14c3:b0:8bb:1a7b:bb8 with SMTP id d2e1a72fcca58-8c8792b690fmr42464588b3a.3.1796320624876; Thu, 03 Dec 2026 09:57:04 -0800 (PST) Date: Thu, 3 Dec 2026 09:57:04 -0800 In-Reply-To: X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261120-gmem-fix-gmem-max-mapping-level-v1-1-108788914fe8@google.com> Message-ID: Subject: Re: [PATCH] KVM: x86/mmu: Prevent hugepage recovery on non-guest_memfd private GFNs From: Sean Christopherson To: Jiaming Fan Cc: Ackerley Tng , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Fuad Tabba , David Hildenbrand , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="us-ascii" 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