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=1796382436; b=Rm5gzTlsQj4dMcQaoeDEHZ00ZUnRHzihT/akUe6Ex69invXSWPiUjx+tNxZ6mct0PJtT 31FmQrFLeep7nvuj9B2j8LTA2m7ggJksxYt/pjHZ+/Db4Et2SdE7VWQyJsxwiJ8Mk7QeJ 9R9MDsEKEEbYRaCiiS9tMPkhF8VJknwBHovttzHTYLMbQimTBrCQjVDfpO4AxgtX5kykP gcRNabLtwDMf7SHC9rTy1xWFW3hCp6qFV8tlQi7pv44BT1XwuTOnZoFXzWUiQ2r7FXsiC ZjXmj406hKQQAI3eWx/nFwqrSzVBDw9C16pga2cy/KIMraohBqhIJoX5//+XeWyXvEg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382436; 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=sUaKx9qFPDnKjFxDvjFSfnRGvIbJSP+rKEwODzBQCP0=; b=zPh1jfHwQRk1SSjhbiqk76uG6IhOC+4lVBTxlfgh2fznU/rm3a0Ne4FXYCKWqkQmYYUo 9jukR7s/c/25/kmSwZIoHYqUHoyOWJL+lnpIfde/Y/0snzqlGX4Rh/rikl15LtpEd8Tiv /2Qy4+VMgPzybosKeLRiyQjPynyiJ25yM2NmtGS46TsPGuzaETgO1JoxyRRwSGQh3vSdT lxJWPptKkcXnq1kvRLxfTkniDbAPszqTnsmeeopFsFKkiJstvTCi2T7GUJyP5I/79m53K qbmhRu7wssFHWefwtWsWr1vz8Zqi+2QajQfXTHrZ0ayhLTkg6KKliGJ8rkOUKwj97/g== 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="FP6/DQIU"; 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 07BE8606A33A; Fri, 4 Dec 2026 11:07:16 +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=FP6/DQIU Received: by smtp.kernel.org (Postfix) with ESMTPSA id 741C91F00933; Fri, 4 Dec 2026 11:07:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382435; bh=sUaKx9qFPDnKjFxDvjFSfnRGvIbJSP+rKEwODzBQCP0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=FP6/DQIU2fx5sERiX0BRnWtVEGo4svb/4oC6ZpLZCWy3XqTJnEa+zsDZkdJcOzCSO UbvFQChfyeoITZrqzIUDC+fu3HbKpotI941VukOt4RRGEGxsod5aJbtuM4E8bTUStf 4avdES1PbgwiZnjcg6A6Ov4OpXRY1MueLd39XQ3o= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Marek Szyprowski Subject: [PATCH 6.18 411/703] dma-coherent: serialize reserved memory pool initialization Date: Fri, 4 Dec 2026 19:05:10 +0900 Message-ID: <20261204100638.767577783@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: 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.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Marek Szyprowski commit 494f40ffabcdc8d9fa4012b2c972690f25a0a40f upstream. Multiple devices can share the same "shared-dma-pool" reserved memory region, in which case the dma_coherent_mem structure is created 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: 7bfa5ab6fa1b ("drivers: dma-coherent: add initialization from device tree") Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20261026095423.966856-2-m.szyprowski@samsung.com Signed-off-by: Marek Szyprowski Signed-off-by: Greg Kroah-Hartman --- kernel/dma/coherent.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) --- a/kernel/dma/coherent.c +++ b/kernel/dma/coherent.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -334,10 +335,18 @@ static phys_addr_t dma_reserved_default_ static phys_addr_t dma_reserved_default_memory_size __initdata; #endif +static DEFINE_MUTEX(rmem_dma_mutex); + static int rmem_dma_device_init(struct reserved_mem *rmem, struct device *dev) { - struct dma_coherent_mem *mem = rmem->priv; + struct dma_coherent_mem *mem; + /* + * Multiple devices can share the same pool and may be probed + * concurrently, so serialize the initialization of rmem->priv. + */ + guard(mutex)(&rmem_dma_mutex); + mem = rmem->priv; if (!mem) { mem = dma_init_coherent_memory(rmem->base, rmem->base, rmem->size, true);