From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F2D40C43458 for ; Wed, 1 Jul 2026 05:50:27 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4gqpyV4vJzz2ygJ; Wed, 01 Jul 2026 15:50:26 +1000 (AEST) Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2600:3c0a:e001:78e:0:1991:8:25" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1782885026; cv=none; b=PTsT8srcY9iKsb7f3a7e9OWFMYy9OTR3ikHr83h8m+qKcb5BEtzGwr5h/AA1wbBg4Pj83PutzJu83w2FmDa0adObhsSxx6ewKA2fhHvnC/niyRIppopUmNWF2qpXiFeTMW3teLBjSK8xFL/1eCs94ygxLNfXLHoOKSX0lFnl2gAUgSpI7L4JegMxqAmZasFRXJjidWFGK+ZtsP5ZWke2piIwskHOJ9ww3RwIWZsuaMct+uXlis6Dl8z4igd0aC5oJRv9ULv6GDwv9IFW/ucF8460ctL/If3+t/LvQLtVui5yTUq65x9IQp6fONVriHuuC4MG55e7LISvX0v4e2Ch5A== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1782885026; c=relaxed/relaxed; bh=zIStNUVzsvlerZ+QizOjlOviNoWs8cBtD6MZ6LvxLus=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AqkspZ0yNTSmxwDd5mm5Ycxg/5aMq+Fhsg+jz0w6Ent0FfsqlYp0Z8Fh5e0CrP7Ok84wpBy7X3cl7SzWwMI2O7kN36IUOmd4ilHQCNdsadAieeIkZ7XO6OFgiwTgiv1eVPajEHVTM6qN9salftQvdg/78voB6H65XF6QGVIxgzHzp7V9AULf1ijXp0qYAuwvRfdaiJHz9zK26NXyxhGk2Zb6Rn8ogRvO8GtUjs3veMrJxOOU9MDLuZ00fYT7PlCXKSxC2+rDBGqIvCtxbLl8to/hSRKhIerHXc3bcp0H1wVCosCcN2v+d5213PI8LUGbs6qB8RHCdiw/QM20tEnxAw== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=PqLZczq9; dkim-atps=neutral; spf=pass (client-ip=2600:3c0a:e001:78e:0:1991:8:25; helo=sea.source.kernel.org; envelope-from=aneesh.kumar@kernel.org; receiver=lists.ozlabs.org) smtp.mailfrom=kernel.org Authentication-Results: lists.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=PqLZczq9; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=kernel.org (client-ip=2600:3c0a:e001:78e:0:1991:8:25; helo=sea.source.kernel.org; envelope-from=aneesh.kumar@kernel.org; receiver=lists.ozlabs.org) Received: from sea.source.kernel.org (sea.source.kernel.org [IPv6:2600:3c0a:e001:78e:0:1991:8:25]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4gqpyT1Bwfz2yfy for ; Wed, 01 Jul 2026 15:50:25 +1000 (AEST) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 778D3418A6; Wed, 1 Jul 2026 05:50:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 384CC1F000E9; Wed, 1 Jul 2026 05:50:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1782885017; bh=zIStNUVzsvlerZ+QizOjlOviNoWs8cBtD6MZ6LvxLus=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=PqLZczq9nytjMBIz1gRDydlihYseOQeVOh/BvcuAXuc9JPjZOlmiht58x0FPEjo+t hRTrQEt8VRYn0Dmcz4xIr9jogYS72zVWWm9a1wZ1RRULLb64cBOhUMCrYC/swel+dA ZyoLBtoKkFRKCuwhTEHXgXRQoGO1RCGg0G9QHrwCdVZWRp3/5fgBR2fo9OtJT9KpMy XL/T7gq6c3pHw6pRYYctQ9qxoPHQ6jOcXx9d8+17+Dj+FsUiao8LxmkbJRnelGgGGu dfjeSVnAKzkDyZ9j/uewEKB74utsKJdh7dQJNELbyyNu9l2yEGf0+ry2LSNxuS+LBI 0P6ZUT1CXWeLw== From: "Aneesh Kumar K.V (Arm)" To: iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-coco@lists.linux.dev Cc: "Aneesh Kumar K.V (Arm)" , Robin Murphy , Marek Szyprowski , Will Deacon , Marc Zyngier , Steven Price , Suzuki K Poulose , Catalin Marinas , Jiri Pirko , Jason Gunthorpe , Mostafa Saleh , Petr Tesarik , Alexey Kardashevskiy , Dan Williams , Xu Yilun , linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , "Christophe Leroy (CS GROUP)" , Alexander Gordeev , Gerald Schaefer , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Sven Schnelle , x86@kernel.org, Michael Kelley Subject: [PATCH v7 03/22] iommu/dma: Check atomic pool allocation result directly Date: Wed, 1 Jul 2026 11:19:07 +0530 Message-ID: <20260701054926.825925-4-aneesh.kumar@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260701054926.825925-1-aneesh.kumar@kernel.org> References: <20260701054926.825925-1-aneesh.kumar@kernel.org> X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Owner: List-Post: List-Archive: , List-Subscribe: , , List-Unsubscribe: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The non-blocking, non-coherent allocation path uses dma_alloc_from_pool(), which returns the allocated page and fills cpu_addr only on success. Do not rely on cpu_addr to detect allocation failure in this path. Check the returned page directly before using it for the IOMMU mapping. Fixes: 9420139f516d ("dma-pool: fix coherent pool allocations for IOMMU mappings") Tested-by: Michael Kelley Tested-by: Mostafa Saleh Reviewed-by: Petr Tesarik Signed-off-by: Aneesh Kumar K.V (Arm) --- drivers/iommu/dma-iommu.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 9abaec0703ef..68c686c1e81a 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -1671,13 +1671,16 @@ void *iommu_dma_alloc(struct device *dev, size_t size, dma_addr_t *handle, } if (IS_ENABLED(CONFIG_DMA_DIRECT_REMAP) && - !gfpflags_allow_blocking(gfp) && !coherent) + !gfpflags_allow_blocking(gfp) && !coherent) { page = dma_alloc_from_pool(dev, PAGE_ALIGN(size), &cpu_addr, - gfp, NULL); - else + gfp, NULL); + if (!page) + return NULL; + } else { cpu_addr = iommu_dma_alloc_pages(dev, size, &page, gfp, attrs); - if (!cpu_addr) - return NULL; + if (!cpu_addr) + return NULL; + } *handle = __iommu_dma_map(dev, page_to_phys(page), size, ioprot, dev->coherent_dma_mask); -- 2.43.0