From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796384733; b=XOEDc7XVtahWn6jGZtyTg9ZDaB2/DXHewMRbOJKV4DmEEvKEgihu59WHOW5v8U1XZDrv 9tnZrz0Da649zsjJBvrKIdYceELUVfQ96hh15mOUl+yu3Ir4IB0r3BIUPA27lsTAKIFQ1 t7sax9zSBOBOiJNIL2DWXJOmfwmFTsDVvHWsUKFJkJx4WIFOysP/xxyvQTLFSnlWw87m7 uTnVe2MmM/kjY9xCzWqROfywyIUPbw8T59SjCg5d9bhcEoP+rVGM1kXvwa84eyv6Jw00m /cNuXOMzkdvFW3vySmvmttMPJkQGgUSVb6gqvIpTgtnZchX762EwrTZn77s99Or8emg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384733; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=4E9hg+/9VL9tJDMWWeZAWVs1/5c15xWrk+S6/2egj4o=; b=XiCjD9lswgb7mqS7GIHVCuE4WYDWKr5Wp+3VY2pmae6CvnTMCuQbXxp4FCXCURKys/db PimHd2D3GhPBCwiaHTH9T2nWOHy8AfCrPDFPO2FOmHyxqA1otCdqljx9OJiUxafBz8wp+ InbeM4BgOjQ4Xr44lJhzunJxiF3O5+dS7+au9Cykk8aRo3HOKmLFFFoq3G2jQuZI/ni+W TyOaBBW2x2CLP6aqf4dZdUIgWXPVcOWbWI9DvZ+93DfRqKRKeqUJA+UlmTUNxUHkHQWwC 4n+JYnETFq5iJi9Hw2UAbXIQmEHqEwqv5458+cePTt/c3qarUZ6mYiV5nW9WbeIRYGw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=rBKNnOxN; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2CEC2606A322; Fri, 4 Dec 2026 11:45:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=rBKNnOxN Received: by smtp.kernel.org (Postfix) with ESMTPSA id 996B01F000C2; Fri, 4 Dec 2026 11:45:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384733; bh=4E9hg+/9VL9tJDMWWeZAWVs1/5c15xWrk+S6/2egj4o=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=rBKNnOxNgtFEoCDTfBUsx5o0TgE1umFLTbjyM7r9WzuqYYAjrIl2aNSXuBsuzoakG 44q+YN0xM78k24LJRMncppaek58FaYg0fLxBWakvXPyB6tz0YDPV4shqt/cz7ReoXn YGq1jNLNf/kMTQXqIS2mNL0J4IuiFdbOvJWbWdfo= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jan Beulich , Juergen Gross , Sasha Levin Subject: [PATCH 6.6 0269/1167] Xen/gnttab: improve error handling in gnttab_dma_{alloc,free}_pages() Date: Fri, 4 Dec 2026 18:54:56 +0900 Message-ID: <20261204100709.065599653@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jan Beulich [ Upstream commit 2b66f2cc753243a6adb3e9a5c038b0fc59ba7ec9 ] Both decrease-reservation and populate-physmap can succeed partially. For the former this may be pretty unlikely, but clearly the latter can hit both out-of-memory conditions in the hypervisor or denial because of the allocation exceeding the domain's allowance (there's no interaction with the balloon driver here either). In gnttab_dma_free_pages() we simply can't give back to the system what hasn't been re-filled with backing memory. For gnttab_dma_alloc_pages() both parts of the overall region need dealing with differently. While no present caller of gnttab_dma_free_pages() checks its return value, also don't use -EFAULT there: It really is an out-of-memory condition. (In gnttab_dma_alloc_pages() -EFAULT doesn't look quite right either, but I couldn't think of a clearly better error code there.) Fixes: 9bdc7304f536 ("xen/grant-table: Allow allocating buffers suitable for DMA") Signed-off-by: Jan Beulich Reviewed-by: Jan Beulich Signed-off-by: Juergen Gross Message-ID: <20261110095605.369848-3-jgross@suse.com> Signed-off-by: Sasha Levin --- drivers/xen/grant-table.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/drivers/xen/grant-table.c b/drivers/xen/grant-table.c index 6678a38870517..4193f0f0b7a95 100644 --- a/drivers/xen/grant-table.c +++ b/drivers/xen/grant-table.c @@ -1098,6 +1098,24 @@ int gnttab_dma_alloc_pages(struct gnttab_dma_alloc_args *args) ret = xenmem_reservation_decrease(args->nr_pages, args->frames); if (ret != args->nr_pages) { pr_debug("Failed to decrease reservation for DMA buffer\n"); + if (ret >= 0) { + /* Free the part where decrease didn't work. */ + size_t done = ret << PAGE_SHIFT; + + if (args->coherent) + dma_free_coherent(args->dev, size - done, + args->vaddr + done, + args->dev_bus_addr + done); + else + dma_free_wc(args->dev, size - done, + args->vaddr + done, + args->dev_bus_addr + done); + + if (!ret) /* Nothing else to do? */ + return -EFAULT; + + args->nr_pages = ret; + } ret = -EFAULT; goto fail; } @@ -1131,7 +1149,12 @@ int gnttab_dma_free_pages(struct gnttab_dma_alloc_args *args) ret = xenmem_reservation_increase(args->nr_pages, args->frames); if (ret != args->nr_pages) { pr_debug("Failed to increase reservation for DMA buffer\n"); - ret = -EFAULT; + /* Can only free what has been re-filled. */ + if (!ret) + return -ENOMEM; + if (ret > 0) + args->nr_pages = ret; + ret = -ENOMEM; } else { ret = 0; } -- 2.53.0