From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) (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 C94C036A03F for ; Wed, 26 Aug 2026 09:02:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.69 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787734926; cv=none; b=Ve0QGsSikGIE+wo/S+wYr6WH4Y/Fp2irVp4lgiv5bx1a94ItGxIZS3TCBA5B5Dhr+Bf9nSuFEMvlL/3VpWmzhBX767hWgFDstuBOA5x8Yq6Yx8fMuOVsL0T9SoyCUku83QgDJhemZaxM6427qvx+gQgy5h8h15ZlWXrLFs9+MaY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787734926; c=relaxed/simple; bh=tBQj3Zs/zFgJuqob5UUxqzp8WSGa3DX0/uF2e5leoMQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=QIDYt7bhQd0pzpX6P4YcbznOkrOxlau+wQCEc3xbsvV55wncsfVogIpAG/30fl46+FKufLIggSxaqGzrzI5xyDDvWtN11yAB4P6TNLKXR49Noqdz+S3eoIDBO+y3jYd+c3EYz9G2/yNS1wFRzqLGFvRKNQoJQHMWC7U+vlJl5qo= 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=p7MLEpKK; arc=none smtp.client-ip=209.85.216.69 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="p7MLEpKK" Received: by mail-pj1-f69.google.com with SMTP id 98e67ed59e1d1-3954def0191so1622169a91.3 for ; Wed, 26 Aug 2026 02:02:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1787734924; x=1788339724; 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=DUYw+bKmtZMKiUuqmTKklNQo1kdVyC2ASm9zrjeaODY=; b=p7MLEpKKeUZpVNX7qpkrV/b5uhkdrb+LxJ2BcsqAZgv5XKRUJytOE/hhRpzEhSkfzo rbkuwA5Bh0etx30osZvXXhx4ckcmZRw8Xk5tCWpQ45XQH5BwGKhl7w7MGtdHSEJf7St8 CXkC7SWzokp+FAq8NegC46kXUCs0wf+TMD+AxV48l1RskTfCp4Of+thPT+c3qgeKQNe7 Khp3rYzJWfaDmB7B5dUj9jda2gNyLHcT3fTW3GNWjTcqnKW2pdMPSfBn01Ebzz6osFOc 8RPGfxCLE6asYrLWQ4OK9ONLX4496OY3/+Ps7MUnA3s138Pja89psKvE+hqsR2a40CjP l2qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787734924; x=1788339724; 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=DUYw+bKmtZMKiUuqmTKklNQo1kdVyC2ASm9zrjeaODY=; b=WT7vZZeO4P766lVxRHpZZQi35r8ODJrZHPYQpQwSSEcaxorQ2DRQgVwONCYQi+DJKN tifCggS34NwmsYh4/4BQe0dSfoi9q/cMrB8QKCPj2NM7GpSoItbX8oeTP8ZaTOwI6S27 xrkhZbu60DSSJkrWfIJTbuSnt3a5BvjAFtQ+Jyld72u5vUPVFljCugPz9DIZMB/LhFaX 0yp4q9aflzSh37k7XBO85UcVqkG1U/5A8WABO/y9HsJstRfxZUoQfPLlSBKZ0t2kLADf gu9eAVtHNjmdkZAAU5ihG9F214IChDhPVs8R0Fa8y+jvbymGjIlGICl/JQAVeHg60Vvf CecQ== X-Forwarded-Encrypted: i=1; AHgh+Rqitw5UUo22dRGBOxgA9yGxErXqkMLACJBtZkVrrHgJSmE4UO9yQoWF4DPWmtbnEN/EtXs6X6YMu59ugrM=@vger.kernel.org X-Gm-Message-State: AFuF++kVy1aABs1Ai8/Zgpv9cxViu4Q/SVd7lb9HN4wb3OlPQY/gfhYr tlcja693KY/AnGiD8z27il6UzRuKMn/PnZfkqSe6EVXZuOy8natCysI4JtE90DGyII+TuXr1BR8 TT7Pr5T8Qa8cJ0YSfjlrqoEl8ig== X-Received: from plhk3.prod.google.com ([2002:a17:902:d583:b0:2cf:7c8c:cf2c]) (user=ackerleytng job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:1c83:b0:393:19a3:4f1 with SMTP id 98e67ed59e1d1-3966d1a48b7mr9860233a91.6.1787734923676; Wed, 26 Aug 2026 02:02:03 -0700 (PDT) Date: Wed, 26 Aug 2026 09:01:46 +0000 In-Reply-To: <20260826-gmem-no-return-page-v4-0-3bb9c1ddb4e3@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260826-gmem-no-return-page-v4-0-3bb9c1ddb4e3@google.com> X-Developer-Key: i=ackerleytng@google.com; a=ed25519; pk=sAZDYXdm6Iz8FHitpHeFlCMXwabodTm7p8/3/8xUxuU= X-Developer-Signature: v=1; a=ed25519-sha256; t=1787734920; l=2054; i=ackerleytng@google.com; s=20260225; h=from:subject:message-id; bh=tBQj3Zs/zFgJuqob5UUxqzp8WSGa3DX0/uF2e5leoMQ=; b=nHLIey2i5u9SSFrucSIZdJ1XmfoAN4s5aKHgC3ZELugP1EEPbj+x4Hm6gj03zMVF4F5nca+id ZU3e9ubiktdC65mxiZZgRyVvXsoN/yMoCRncYdGQyOWDEy2KAsc3df+ X-Mailer: b4 0.16.0 Message-ID: <20260826-gmem-no-return-page-v4-1-3bb9c1ddb4e3@google.com> Subject: [PATCH v4 1/5] KVM: SEV: Treat unassigned RMP entry as benign race on PSMASH failure 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 , Yan Zhao , "Edgecombe, Rick P" , Vishal Annapurve , Fuad Tabba 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" When handling an RMP fault, KVM attempts to split a 2MB page via PSMASH. If PSMASH fails, the only expected return value is FAIL_BADADDR, which does not distinguish the reason for the bad address. Hence, another RMP entry lookup is required to determine whether the failure was benign. Specifically, KVM re-checks the RMP entry to determine if another CPU raced and already smashed the entry into 4KB pages. A concurrent operation (such as guest_memfd truncation or hole punching) can also race and transition the page to shared, removing the page from the RMP table and causing PSMASH to fail. This can happen even if the page is still referenced by KVM, because guest_memfd reclaim transitions the RMP entry to shared when the folio is removed from the page cache. Treat an unassigned RMP entry as an expected race when re-checking after a failed PSMASH, and skip logging an error warning. Fixes: c63cf135cc99 ("KVM: SEV: Add support to handle RMP nested page faults") Reviewed-by: Michael Roth Signed-off-by: Ackerley Tng --- arch/x86/kvm/svm/sev.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 5705723f1f412..e198469eb074c 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -5090,10 +5090,11 @@ void sev_handle_rmp_fault(struct kvm_vcpu *vcpu, gpa_t gpa, u64 error_code) /* * Look it up again. If it's 4K now then the PSMASH may have * raced with another process and the issue has already resolved - * itself. + * itself. If it's not assigned, then this must have raced with + * another process that made this page shared. */ if (!snp_lookup_rmpentry(pfn, &assigned, &rmp_level) && - assigned && rmp_level == PG_LEVEL_4K) + ((assigned && rmp_level == PG_LEVEL_4K) || !assigned)) goto out; pr_warn_ratelimited("SEV: Unable to split RMP entry for GPA 0x%llx PFN 0x%llx ret %d\n", -- 2.55.0.887.g758fc8c411-goog