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=1796380861; b=I8mK1RFJ1ryKevDfcsGcWCnC1RovpXBIQF+ES3feA5f4oAjf5yS8yUz0dw3FTsbGKRw1 rhbQigWC16P/Cbq4PheV5CU3sCC/zr7eSRfj4h9Ff0g+DaJqxCHnSuXYJgaf1owynbJrH HX2ZK2En7km41a6541ZQc2YnaZc+uS6515menO9i0jcdKhmBz1k++lZUODzOrVIhKNyF8 Hz3W92dwM0v9uAZGkhz0+Xeadj5ZL52Q2lYsWc2aQY1SQyRTrzW8upmBWV9Vlb44ZJEWx ZHev0o2cI/siHz51PryA/V7hgvo6W3ofdhMtTZEQ25AlzsSuEnaU4JYTOxrjpd3lqZQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380861; 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=uEgd+FuYPq880FNwHsVEsYRCjrRwkll4x3xUxtRlfnI=; b=nby+inkBEGvnkAYsP8GXU4hvH08utobsa8DN/i1ciQRC6BNJTjTqT81pWDxS5RSmgmS4 IDMQ78HbcsOVNidrA7uCnSfrB1ErKYniL0/8TH2opuTqwaPMiVsxHcZ+RujnGyUvsoRg/ bM0qlHUgUleH9IkaqO4ukC9uaxqn0RKSPgXhW1M1oYWRlqwH1LjO5aF3fqk5rg5ESVn9y AdMv8F6cT1w36go3+dTJ/64VSq/4zUQx0StslOOyqkRupYK1i4IqwIoH/hziJuod148Hg 1vQjscjK+2lo9d4qW7JWVJQ/b0ES3KiIRw3HRUS9K4MWBI+/SiKJpq6BesCP4quk43Q== 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=UQNKKe5M; 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 D41B7606A32C; Fri, 4 Dec 2026 10:41:01 +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=UQNKKe5M Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4FCEC1F000CE; Fri, 4 Dec 2026 10:41:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380861; bh=uEgd+FuYPq880FNwHsVEsYRCjrRwkll4x3xUxtRlfnI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=UQNKKe5MT7l3iO7Xy+3SN8dwtqGwvWbypqG3BtJUF7NUdpv87d95Dm70vvPB+Q+/e PPR88eOXaVJ0zJygVcH/3xY+IoC9utgadnxWcZxkkHrEI3gnHXz4CeWO9hTSG/b/3e covrA5Aw+jmcBQiW0WSx+mA5Gi+I2B4HmBrm15tI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Marek Szyprowski Subject: [PATCH 7.3 457/742] dma: swiotlb: Serialize restricted DMA pool initialization Date: Fri, 4 Dec 2026 19:05:21 +0900 Message-ID: <20261204100647.302809489@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@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 7.3-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 @@ -1999,10 +2000,12 @@ void swiotlb_free_from_pool(struct devic swiotlb_release_slots(dev, tlb_addr, pool); } +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 */ @@ -2016,8 +2019,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; unsigned long aligned_nslabs = ALIGN_DOWN(nslabs, IO_TLB_SEGSIZE);