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=1796383811; b=jKnQ6dsEvdazBjrw07CyieobiE0ixsza3b4Dn249FMGoVTKDNQZqJQBgk2LbP2KR8ZvF MNr4UyUp6G/8jsx+CgYCYYu9P+ha5ZGjPrZnkENuaCNvrwGlWD9kYG4IVPE1+xUmgdfzy AT8+NF5wAnVs5T7zW/cB1GlDmtsBRautbfiqpTTQBtbxb2Ra66EylOcRRUKW3+bhzYBAr kptTvY0qAjQxsG7S5DbubE4CSx74/rlxyxyeYd6cCOas9vxgv/FVvFzyeAF02P8dlUpim a/165uan9OpVRfV2ZaQysxtuXFVoZoazpwqv21NbxWsNk8wdbxLVJTJMMxaM8JI8lgg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796383811; 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=Rwrk0iw3aZpJlufiEMKSWwMnDEw4UDnHSu5tCaPAhO4=; b=llMR8SWs5K58BOcJ8Tz07fZF2JbjUrEGOgu5aS6HQTE2h33WoQqrmOPpOQx1VIoAKwrI 6Chf1uz7ndXrOoBSL7Q1Hc1IaJeX5XQztKTKx7oLsULcHoL0nszAfICW4jE5LxyiYBoG2 NXRvz1SOBE5G5wtyeKbumhOkOfWou81+RbPE27DY2N99NNYJthX7yaOSL7/4BkWjl79qG dtx0QvRvtY0/nKhRVMVmpVQA+IgKHx4ztLRPkbEWlN8+vVYtwFFb2M0xMm8ygXYAOAuXK 43WDhizSmobbBRt8j2AJGcroADqza6thLCfZ+7QLKU8RF8RHhjj7Fda8mOPx7MebdMw== 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=TTwaA4Rz; 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 C5811606A32F; Fri, 4 Dec 2026 11:30:11 +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=TTwaA4Rz Received: by smtp.kernel.org (Postfix) with ESMTPSA id EC5781F000C2; Fri, 4 Dec 2026 11:30:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796383811; bh=Rwrk0iw3aZpJlufiEMKSWwMnDEw4UDnHSu5tCaPAhO4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=TTwaA4Rz4xiE8stmBc1eNCQRAYtTSiLmTnrELSnmFoxT4GCtAwmf+5+SCP3hInyvp v9vQmodmWelsaPYqkSB+enFLoSFEqY3W0Q3Vy37eeznQ1PX+a9AS6IIQFhCyJE1eZA HDldR8U0UCb5zkal7Mw0E7sqjPqMco5FF8z22uUQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Marek Szyprowski Subject: [PATCH 6.12 370/555] dma: swiotlb: Serialize restricted DMA pool initialization Date: Fri, 4 Dec 2026 19:06:53 +0900 Message-ID: <20261204100624.034568448@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@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.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Marek Szyprowski commit 7ad92b81b415de806957b19828fc4777a9cf2216 upstream. Multiple devices can share the same restricted DMA pool, in which case the io_tlb_mem structure is allocated and initialized by the first device attached to it and stored in rmem->priv. To avoid the potential race, serialize the check and initialization of rmem->priv with a mutex. Fixes: 0b84e4f8b793 ("swiotlb: Add restricted DMA pool initialization") Closes: https://sashiko.dev/#/bug/linux-6fda7589-591d-4a68-b6e1-b1561f867319 Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20261026095423.966856-3-m.szyprowski@samsung.com Signed-off-by: Marek Szyprowski Signed-off-by: Greg Kroah-Hartman --- kernel/dma/swiotlb.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -1823,10 +1824,12 @@ bool swiotlb_free(struct device *dev, st return true; } +static DEFINE_MUTEX(rmem_swiotlb_mutex); + static int rmem_swiotlb_device_init(struct reserved_mem *rmem, struct device *dev) { - struct io_tlb_mem *mem = rmem->priv; + struct io_tlb_mem *mem; unsigned long nslabs = rmem->size >> IO_TLB_SHIFT; /* Set Per-device io tlb area to one */ @@ -1840,8 +1843,10 @@ static int rmem_swiotlb_device_init(stru /* * Since multiple devices can share the same pool, the private data, * io_tlb_mem struct, will be initialized by the first device attached - * to it. + * to it. Serialize this, as devices may be probed concurrently. */ + guard(mutex)(&rmem_swiotlb_mutex); + mem = rmem->priv; if (!mem) { struct io_tlb_pool *pool;