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=1796382440; b=E8eV274PsBix6NpK8+cV6uVFX545uwxAIVAcdXm5v3xAQQZuS2RkDVNtVNrXRim0hlvW 95gEP5GASuLkmCzTqzknFXzQGrRPEcxwWoy22fKPb1niUlUIpjL3C/NYhADB66oqHmIg0 0hT4tzd0loAbQIJULHXevNv8XuO2al1AVpqPouTIFPg+qEE4PMAppCBTeRqa+3sFEJd7N 8vKg5PcuBW5IWCKJaDxnQHoUhC38bPZgp6LSu3G3PpWkL3yzAtws6AuYRE1P5QYgrljh8 W7PtnH6b7euv5W50JB65oG+NxXRJ/P3GHMuO/673FyPSmUdjDfpERWLBK6Dova5vjmA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382440; 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=o7RlEOo3cMnVak+hhfkhnmZ8lfIegiRpmZ7/yCbfwy4=; b=RrnmS7EhEIjwaIAZEDju7Y8t6sZqrT8oq6HUz8vrqBzi70TouANct/BO9n+7hQyfl51z m7JE8zuZPDBm/0Qix6HAoDD2eP24pgpK3Tq3y60FXoEAh9zlC5/iGU+VTTbFAtIDpeKo0 J28o6qPE9kUn+lTeVdN2EPjAh8swiod6gZz9c+ErR5G299+dk4XtshzpxOj3p9PZIZi1S lht2xfyH9Wwk/+GEOPl6iKuiJSFAZGGQwyRFfHUHUMg/s/RHggFafho2rdT9VMJtdUY1t i3QWZsHC6Pv099ksiJ+rhxqAubbwWADyyfZC6+wltm6bgx9uDNZQUniU2blq9r8KzUw== 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=s4nySlFa; 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 84741606A336; Fri, 4 Dec 2026 11:07:20 +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=s4nySlFa Received: by smtp.kernel.org (Postfix) with ESMTPSA id F19FC1F00936; Fri, 4 Dec 2026 11:07:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382440; bh=o7RlEOo3cMnVak+hhfkhnmZ8lfIegiRpmZ7/yCbfwy4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=s4nySlFawWsGZLyFd2AGDMP2LPjFSIalPt/1jrxN97c9mZglEXk+x7F7EAzs15HUA /mBfpop4QpnM0Mgy+5q4TRuZ7eo5NmtBIxL/+hCzVfyJ/qPOWuTB2z/0fa6EVrK2TZ tTU6Yaokve2UrF9IgpZ0tmjJCMRORIcshI2tB3KM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Marek Szyprowski Subject: [PATCH 6.18 413/703] dma: swiotlb: Serialize restricted DMA pool initialization Date: Fri, 4 Dec 2026 19:05:12 +0900 Message-ID: <20261204100638.817820290@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@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.18-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;