From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DA2E7379C24 for ; Thu, 20 Aug 2026 23:32:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.200 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787268762; cv=none; b=J6qYt3ewsOE/ifQbk5kwqETSnwK+mjLpfiYuFoFxHvXU/NG0U07E/arkNgBAAzKAm4L896bXpPuXdra9+lasbJiAjU7ZQmenVWw7r+PlAobkWKv76Ah3ovuApXBjelmdwefnoGXOXNvPgSpdCZcbTt9NTGQaU1y6Wv4YMdPSnGk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787268762; c=relaxed/simple; bh=0qkgLp/4gNYJUuC928LKmD9dsDMVKNfciXFJMMiMswQ=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=AWlmfME0e7ErLBjouRH7fnssrC/zpMaKNkTnyWob6NvRiYUYbYfyhwmrXO1nTymAvwqeK5+RdiD7A9YxpRNvMj8EU5HxOu/q/kVXQJdgkoJHsvWLF84ZoarKY2PmD2Z8RlBHoHP4Ahqc6u6MqHtGFZURaMcBp9TSpxxWbbsDHY0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ackerleytng.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=wLdY1MpY; arc=none smtp.client-ip=209.85.214.200 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--ackerleytng.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="wLdY1MpY" Received: by mail-pl1-f200.google.com with SMTP id d9443c01a7336-2cf1c86963bso15043925ad.0 for ; Thu, 20 Aug 2026 16:32:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1787268760; x=1787873560; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:mime-version:date:from :to:cc:subject:date:message-id:reply-to:content-type; bh=AMZ8TZYQN/8a08d3ypLOFhqk0OwFZ/bONgMFOnHGK/o=; b=wLdY1MpYx1qqJj5h3ZgSpZ984XLqr3wSrrvQIBTAoDg+9EDqH+d0a+L7Sp+ExcD7P9 FOgeAPnU79dnqFC2ix03sM8DZ/EUF7gQHH32m25xn8FZgqLY8EYEyggdFN2YGav3m3GF nL6UYENmH5nilgAbUezzS9jdfdq0J7XeXP2qGRvTZ7st7t0ZiCZmxWRJkPcpEIZfWfad r2l6Ej/u1GMyRx3dciVLyi7720xdWn+zVj5K1DZAiiheUPGjjBvjALJfpjQcq1f7z/d5 dmOwY3rNo04yOYVWOLv9za7/oGwKL2/q7SdK/3+gj8zKINBE+UBdrpK4pWRZiF1WKUqP 9S7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787268760; x=1787873560; h=content-type:cc:to:from:subject:message-id:mime-version:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=AMZ8TZYQN/8a08d3ypLOFhqk0OwFZ/bONgMFOnHGK/o=; b=c6i6gZZGz3CuCiIJGgeNFJD2mx1RPn5w17jvx8Nf7lezrZaSQZaAtN+bkacIgLLC8n 2FMmp9FTH4cTa6sb+Gou8NH5PuTrPoS13Y0U+i+K/IRHbvjSTS26U7eIVVgyFq4XPszG WSqcAZmFUXI4BsgDaFGDUBJqBsM/b+PASyFhPkZWxUdKvFMPQ289j0sqJJyTlVsZ2w7v sZBLk+CTg1AKAiex/CDd9nLxUYgBrb/fArmdEzRCDRrCIWBw6XhScdFT4G5xyVo2n+x8 B+i3m9lmhRdkFjQtC+DUsuHxrnrizmR4Q+euDg5y7qttylMKrvk1UsNw2ZJPZZLNYx7Q b8TQ== X-Forwarded-Encrypted: i=1; AHgh+RpPaTfzaMzNTkekCMJ+oznJrfLoXgr5TRtWD6EKHbYQCKoQ+QtttA/Ce8y40JruXLb/NcP/uF2s1u9f5Xw=@vger.kernel.org X-Gm-Message-State: AFuF++lnuyD0eGXzHgA6/4G/ZTqm+95X7nslbtgg8Wxvmxtd89hSkIIL WC1oRrg2BXCy8qw3o0DrzfkkZiFAdvckRUaNMQFn14kQO9+S6AmLpoqYp/dcQk5aBpYFAJ+5pMj XueOmWFV/DxuzWyc8KCxX1XKKrA== X-Received: from plpl10.prod.google.com ([2002:a17:903:3dca:b0:2d2:c22c:7b8a]) (user=ackerleytng job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:90d:b0:2d3:6cb4:e79e with SMTP id d9443c01a7336-2d64d2f0e55mr17242035ad.5.1787268759872; Thu, 20 Aug 2026 16:32:39 -0700 (PDT) Date: Thu, 20 Aug 2026 23:32:33 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAJGOh2oC/43NwQ6DIAyA4VcxnMcilSl42nssO6gUJJlgwJEtx ncfettl2fFv2q8riRgsRtIWKwmYbLTe5ahOBRnGzhmkVuUmUEJdCiaomXCiztOAyzM4Ond5pWZ cQtOB1LIh+XIOqO3rUG/33KONiw/v40li+/S3lxgtKddCyUqiVv1wNd6bB54HP5EdTPAHAhm5g BSag+Ky77+Qbds+wNxaIPwAAAA= X-Change-Id: 20260818-gmem-no-return-page-614927a29f97 X-Developer-Key: i=ackerleytng@google.com; a=ed25519; pk=sAZDYXdm6Iz8FHitpHeFlCMXwabodTm7p8/3/8xUxuU= X-Developer-Signature: v=1; a=ed25519-sha256; t=1787268758; l=3107; i=ackerleytng@google.com; s=20260225; h=from:subject:message-id; bh=0qkgLp/4gNYJUuC928LKmD9dsDMVKNfciXFJMMiMswQ=; b=ogJoOeNVzQpGoZquHAyFAMhLUlsTEwH4nWVvd8g1viOFNq1LGLdgW09j6Da0GMCMrYkPKCI0R YUrVrSgZ40hDPh7cUE96XyRxIlKhPEVMZJb7/gE2D0pbDbN+uO8UwO2 X-Mailer: b4 0.16.0 Message-ID: <20260820-gmem-no-return-page-v3-0-3bf8f80a7b4d@google.com> Subject: [PATCH v3 0/4] Stop returning struct page from guest_memfd PFN lookup From: Ackerley Tng To: Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Ashish Kalra , Michael Roth , Brijesh Singh , Marc Zyngier , Oliver Upton , Joey Gouly , Steffen Eiden , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , David Hildenbrand , Fuad Tabba , Yan Zhao , "Edgecombe, Rick P" , Vishal Annapurve Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, Ackerley Tng Content-Type: text/plain; charset="utf-8" KVM currently expects kvm_gmem_get_pfn() to return a refcounted struct page. Callers (such as x86 TDP MMU, arm64 Stage-2 fault handler, and SEV-SNP VMSA / RMP handlers) hold this refcount across page fault handling. CoCo shared-to-private conversion handling must inspect folio refcounts to ensure exclusive ownership by guest_memfd. A concurrent guest page fault taking a temporary reference on the folio causes conversions to fail due to an elevated refcount. While this refcount is also taken on host userspace page faults, that refcount is taken on behalf of the host userspace page tables. This refcount will be dropped when conversions unmaps the page. Either way, once there's an mmap() or userspace mapping, the pages are open to way more refcounts, transient or not. This series focuses on just dropping refcounts before handing KVM a page. guest_memfd already notifies KVM of page invalidations, so callers within KVM only need to respect the MMU invalidation protocol to safely rely on guest_memfd for page presence. guest_memfd already notifies KVM of page invalidations, so users of guest_memfd within KVM only need to respect the MMU invalidation protocol to safely rely on guest_memfd to ensure page presence. This series first prepares the SEV-SNP handlers by treating unassigned RMP entries as benign races on PSMASH failure (which can occur on concurrent truncation) and dropping page references early in the RMP fault and VMSA reload paths. It then updates kvm_gmem_get_pfn() to drop the folio reference internally and stop returning a struct page pointer across x86 and arm64. Removing struct page from kvm_gmem_get_pfn() also moves KVM closer toward supporting memory backends that are not backed by struct page. This is built off Sean's sample code [1]. [1] https://lore.kernel.org/all/an5RJYTwlYeym--O@google.com/ Thank you everybody for your quick reviews and testing, I really appreciate it! Changes from v2: + Picked up Reviewed-bys and Tested-bys + Addressed comments v2: https://patch.msgid.link/20260818-gmem-no-return-page-v2-0-5298f42d49bb@google.com v1: https://patch.msgid.link/20260818-gmem-no-return-page-v1-0-4f8d939efdbc@google.com Signed-off-by: Ackerley Tng --- Ackerley Tng (2): KVM: SEV: Treat unassigned RMP entry as benign race on PSMASH failure KVM: SEV: Drop page refcount early in VMSA reload Sean Christopherson (2): KVM: SEV: Drop page refcount early during RMP fault handling KVM: guest_memfd: Stop returning struct page from PFN lookup arch/arm64/kvm/mmu.c | 4 +--- arch/arm64/kvm/nested.c | 4 ++-- arch/x86/kvm/mmu/mmu.c | 2 +- arch/x86/kvm/svm/sev.c | 53 ++++++++++++++++++++++++++++-------------------- include/linux/kvm_host.h | 6 ++---- virt/kvm/guest_memfd.c | 9 ++------ 6 files changed, 39 insertions(+), 39 deletions(-) --- base-commit: 1b731e5ded480bd1e5546aed35584238661ce72e change-id: 20260818-gmem-no-return-page-614927a29f97 Best regards, -- Ackerley Tng