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=1796389263; b=D4NknP7QIxj99Totw5apcA0+brj8jJA8KHeCuc9Cu18MesGJnnQiAt1nHd7i+Y/gr6xJ gNUInx2IO28ELuoZempJefgbEVgSZKIeQ0QmlNSFIghXlSqCTOS403yNVL/okq+2XWFWR et2NeNrSCuLU3mFZJpIJ4O8ViTim6tjiGvgh53ACfm08WjhEmdkUg5WXlyf6KohdM3D+G tVPP3tiB+RSX6NFlw23IaT3KZUqRZ79696dp2GtpyJE0zS1q68Lb9qjiyAIvgAH/qU+wY w7ZGAZM2fXCRB7BT3cIXS9tufoB9qHciK2V7NFsP7H1PNOhDlDvL4H6AKSb6Gi7aQoQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796389263; 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=MOcCOMk9ZfetMgVPCBbcrmieQlYoldn2r4JvDiQ3Cp0=; b=a2JWGvKZEJSuQD6ccK5ZslhzIw3ydt3VVdSxvAnMuMl/ZwmNzFXYyRQ0dkSJUXxSLHIW H/oVmO4ysUD4gfKJfrZ83T/zaPKDQ6mOiwXXXHdWAW8GIbvOSEN0jE3Glaq6L9xIQBYlW GpfI/xIrSQwLKT982p5/K/zlN02+YoIcwl5zQcDAs5+BqaB4uzkaWj9Xs3kRTunVfXqDc D96odcekCqcdq/7eJABIi4UpdQCAyDKjh7zJrqAVxjYIryjECjTYHU8Yb+DXh/FHFdob3 zYtH3a9rQeOS5A2IU1iAKBYpAIIuvL/keYEQUKpRz8TpSNg2b+TU3jS0GStZsRrXYOw== 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=egT7yk1k; 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 3C858606A330; Fri, 4 Dec 2026 13:01:03 +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=egT7yk1k Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8D9E21F000C2; Fri, 4 Dec 2026 13:01:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796389263; bh=MOcCOMk9ZfetMgVPCBbcrmieQlYoldn2r4JvDiQ3Cp0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=egT7yk1kDXYXF8FcNxyA+4CwVQJHIWxU/oIi3m+Zh6oXAMUREZmm21Be0yNGOdYiP kaRDdRQguN8AvNUEhRkkyGBYUtYjP/K++H1eJ/6369F2+Xx0RR5AL7zN6HxIfAwT6E xuNgASuzPrPVzqA9s//xlLVxfCo7UtyRKSiTRmzI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Marek Szyprowski Subject: [PATCH 6.1 0925/1059] dma: swiotlb: Serialize restricted DMA pool initialization Date: Fri, 4 Dec 2026 19:07:36 +0900 Message-ID: <20261204100707.983100359@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-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 @@ -1044,10 +1045,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 */ @@ -1061,8 +1064,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) { mem = kzalloc(sizeof(*mem), GFP_KERNEL); if (!mem)