From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF3FD65192; Wed, 30 Sep 2026 18:13:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790792022; cv=none; b=ul3wbqbJYrmj4NzxomrRKukEY3ILNvTJZxchgO4bcb4mRhU4iNz0Ajg5Bu8f/NfPdr+jQJVH+A2iQRtLCdz1t6hwbfg/FoO9IIuzLaAYE0H/P+UPimpxCYaXgUTb4NpOOaLaw9CnUMMZue5JIIaovI6LMhSVfCvJFBymGVKREWI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790792022; c=relaxed/simple; bh=AcoNk3T1r7xNl9tER4hweyzdltWd1LRT4ssfZOh2cVQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JaNwuR7s2sNHDYdoVbvviPpYkdIqYTh2Ol2/+ebN5XL6Jl4l4AXu+NoxT0pPp7F4yEAjeoAajK1RkSZGShYYo8s0jSyCN5xruX5d782QTf6OV6aEccyvLgsBmISX1xy3onNmNAo4fUA20L70fADMPtBSQWDY3wD3KTpPPcbQr+s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=H/TsYNbW; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="H/TsYNbW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2A2E91F00899; Wed, 30 Sep 2026 18:13:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1790792021; bh=TNRM00BOn5Pqs/ykN4rJYcqFLCMdezryhELDWXEc4iQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=H/TsYNbWVLpJylKvibyepmv98GYbZUBgMmQUZvPK2o/kwlmzZk1Pv7n8znmCSu/od AbFnV3+HO2gntefffWJm2Mwwuq/iFBSlj8g5vclnXs85bWtYSN1IYHnsAL6jjl9LK4 LS5oxVln7q3kdRomW+ix4P20Tqpv0CfmPn7iBrQM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, "Ritesh Harjani (IBM)" , R Nageswara Sastry , Amit Machhiwal , Gautam Menghani , Madhavan Srinivasan , Sasha Levin Subject: [PATCH 5.15 506/752] KVM: PPC: Book3S HV: fix secure device page leak on uv_page_in() failure Date: Wed, 30 Sep 2026 17:26:16 +0200 Message-ID: <20260930152409.209076413@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260930152358.131179731@linuxfoundation.org> References: <20260930152358.131179731@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Amit Machhiwal [ Upstream commit 0a416ee20bcccddf91ca5b63696a23b9d11d73aa ] In kvmppc_svm_page_in(), if uv_page_in() fails after kvmppc_uvmem_get_page() has succeeded, the secure device page is never released. kvmppc_uvmem_get_page() sets a bit in kvmppc_uvmem_bitmap, allocates a kvmppc_uvmem_page_pvt struct, marks the GFN as KVMPPC_GFN_UVMEM_PFN, and calls zone_device_page_init() which sets refcount=1 and locks the page. The subsequent goto out_finalize skips the *mig.dst assignment, so migrate_vma_finalize() is a no-op for the page, and none of those resources are ever reclaimed. Each occurrence permanently consumes one entry from the firmware-bounded secure memory pool (kvmppc_uvmem_bitmap), leaks pvt, and leaves the GFN marked as secure — making it unusable for the lifetime of the VM. The twin __kvmppc_svm_page_out() already handles the analogous uv_page_out() failure correctly with unlock_page(dpage); __free_page(dpage). Apply the same pattern here: unlock_page() followed by put_page(), which chains through free_zone_device_folio() into kvmppc_uvmem_folio_free() to clear the bitmap bit, free pvt, and reset the GFN state. Reachable whenever uv_page_in() returns an error (e.g. UV pool exhaustion) on any POWER9/10 + Ultravisor/PEF system. Fixes: ca9f4942670c ("KVM: PPC: Book3S HV: Support for running secure guests") Reviewed-by: Ritesh Harjani (IBM) Tested-by: R Nageswara Sastry Signed-off-by: Amit Machhiwal Signed-off-by: Gautam Menghani Signed-off-by: Madhavan Srinivasan Signed-off-by: Sasha Levin --- arch/powerpc/kvm/book3s_hv_uvmem.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/kvm/book3s_hv_uvmem.c b/arch/powerpc/kvm/book3s_hv_uvmem.c index 3d4ee75b0fb76..dba93ee7b613b 100644 --- a/arch/powerpc/kvm/book3s_hv_uvmem.c +++ b/arch/powerpc/kvm/book3s_hv_uvmem.c @@ -771,8 +771,11 @@ static int kvmppc_svm_page_in(struct vm_area_struct *vma, if (spage) { ret = uv_page_in(kvm->arch.lpid, pfn << page_shift, gpa, 0, page_shift); - if (ret) + if (ret) { + unlock_page(dpage); + put_page(dpage); goto out_finalize; + } } } -- 2.53.0