From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.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 86030399CED for ; Thu, 20 Aug 2026 23:32:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.200 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787268763; cv=none; b=TWqUC+FNzPdJpfQuhmSHla+IivZehb3xq8rSCsrCiAcrN65hEidni6Xnae2GvwTYObwGog+RggkwzB1nuKDnlkX+FhkZo3gA2Uej6oEQheDV+GXcn2c8vilF7KWqD7/xF0C3leA3ViJrorcg6bMBkYrxIc84SWoGfytuoT4f0AQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787268763; c=relaxed/simple; bh=mNa+pOHnNs9fqxuQsPFY+ubnJ/wGpTSJgDScv2kh/cw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=GFy//iDwPCcIo0c6OMobXqBcIkzfNOANu8nsrV93zfUBGKnDZ6PILPNcXQdx1f1Gz4+gpkkvzvZ2t12ja/gbunnbFRnM/IlReSSOuqxQkzacoVHFL+2Vo4V3BxQHYSr3xOsJLYuW0OCxX7dY3jy7DwSveVuBHiVjPLP4IkplwnE= 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=hvEkbvE2; arc=none smtp.client-ip=209.85.210.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="hvEkbvE2" Received: by mail-pf1-f200.google.com with SMTP id d2e1a72fcca58-84842381150so378039b3a.3 for ; Thu, 20 Aug 2026 16:32:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1787268762; x=1787873562; 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=GOtJGHo3/D29WlRaeSux3KPdmxoRq/W1Kkt3/Ky2TK4=; b=hvEkbvE25vc9nz9jmZFRPmNbsPbZTtIzB8iTTIowOgD6INXhwv8/lj8kxmh0uliBVa kwuMNWwi8UKNUYFZbCm17u315eeFWzPvkNXWmf1vqvbJweZA7JqtfdMRKMtGpIc6bY6c aeRcQZGWXSmnXIUnkixmTvKvhRLuy5RWHrQgX4dS7okNi8RIcnqOsDZpfKXhjjcHqU3G 84QEomPr2zRNLsueq1SQIaeq08oaI2p+brPdET0eLLQUfgcT3w5Bu34k2imYmaZoKhws kHr+Eo1GufialTD/Abd5lao1TDD1NDzhGCqyzkmf80TMBvJCEHgMoPx3Bf2mYPnY0Liz 9vnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787268762; x=1787873562; 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=GOtJGHo3/D29WlRaeSux3KPdmxoRq/W1Kkt3/Ky2TK4=; b=OHpeZPk4jQDd1GXq/6hbP0Y8sbX7tkt595iJFcmXh1p8JrZNhRsoyPh10aWbnYn0Y0 /hqw83lUl++m8TYHQdqvuZ7ufrHCpVCBaJQe1088TNv0hyBIzYuVXCQ275dgtv6nrEu0 8B3IqkI+AZOzCQKTjYW8wJ/2yFw6idNGxCSgCu8xCtl0MCclBlAr7VCaA7WK9ifEBjs7 rSfovSIloDxApKPVObs6LhX0brkRwGRKRD+S0mDwhqA9y596NFkTu+/tS/5ZWK6sHp8N vmB6Itsd9lRgjCfxj83Z4lu+nKb9g2neRzo7Jx0Y6EhaBwI7XvDf9D8YuBMaZeTeqfWB zOwQ== X-Forwarded-Encrypted: i=1; AHgh+RokH5h9eEsiwcHg8l55I31njNqG0NXmSneaKvzWyL95B3fiu2W8519hv14NbrOtt3tDTVwJtQS26La0ot0=@vger.kernel.org X-Gm-Message-State: AFuF++k8Hy9VToNyuGhW+ljdRYp5XY/Do3IqN+Nbvpnnp7k8IVet6UC7 u6VygiR9egHBnVU7HlO/diXVn2W6d2rWFyC09QlIYt5oWQccZGq9T2XX1yPEKTGWn6WhcUaLx2G ZueqXnCX9s6sS+X/z6cNAlKTv0g== X-Received: from pgp16-n2.prod.google.com ([2002:a05:6a02:62d0:20b0:c86:5f41:8c94]) (user=ackerleytng job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:bb91:b0:84e:2382:f4f0 with SMTP id d2e1a72fcca58-851f9a4b169mr3008115b3a.4.1787268761627; Thu, 20 Aug 2026 16:32:41 -0700 (PDT) Date: Thu, 20 Aug 2026 23:32:34 +0000 In-Reply-To: <20260820-gmem-no-return-page-v3-0-3bf8f80a7b4d@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260820-gmem-no-return-page-v3-0-3bf8f80a7b4d@google.com> X-Developer-Key: i=ackerleytng@google.com; a=ed25519; pk=sAZDYXdm6Iz8FHitpHeFlCMXwabodTm7p8/3/8xUxuU= X-Developer-Signature: v=1; a=ed25519-sha256; t=1787268758; l=2054; i=ackerleytng@google.com; s=20260225; h=from:subject:message-id; bh=mNa+pOHnNs9fqxuQsPFY+ubnJ/wGpTSJgDScv2kh/cw=; b=6jdqB/w2bbq3ZNh0ffVDxVWzMNTWlrX73bzku35jkm0BU43Yrh40zgvuTo6drlCXWWiORe1p+ oG8cHQn44j5ACK9QKezxII+AIYAkCbRDpSItfDEuBO1ZfxEg/YLwW8A X-Mailer: b4 0.16.0 Message-ID: <20260820-gmem-no-return-page-v3-1-3bf8f80a7b4d@google.com> Subject: [PATCH v3 1/4] 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 , 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" 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 fcb41dfde4c02..b2738362a928b 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -5074,10 +5074,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.766.g2966f0265a-goog