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=1796380857; b=Rd4RDhVf3hUHX90xiOkd8fGUBlnFBvdvZG+ptLqScBD58pCuFeHNbvJYxvK7R4UuFWzA Pper2w04fTQ4RQuTL+qYyCoSagYoPLj/XRx3VmoloCru6LIf1tE5hKl98l7JzqQ7c7gnQ zsZQk7pYwsP8HvWq0EEWMTS8SdF1fKsLyH1iu9xe6zwYW8uV+TopAV3MnCqO9ph/RygE8 J0vZInp8dR8I6xYWhH3BIqSBQJQE72YmgnaeHMTDFmR+Y6FPOpDuEewIJRamBJ//0tFnS iRIa9blaMeYDMZCTDCl4xtHDlv/OcyjnZ9DgvYQkmpkQTfuVqO177GIdaGNHIoAwIrw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380857; 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=/+W0iJjMznw+EL2R3XWUwAPTNzEFbmRnE6XqTRHZ/HU=; b=xvquZoXWFX5H4qftUqTDKVZtiR5yKNoWn9BCT0Dj+3IBhzRtWzB3eDay8BeMC62p87it AasmnteazTxKQ+9DsGi6q0kcFx/knBko02jxH03NzMDJVhkRQ+tJL5vfNwMkPf3TAVY66 D15NRfymcMrf1uWihQ6ATqFuhqJKPjjMOUvxwfW+W/SF9nVU9JmGucg+K+GvHGNBmB0eE lZ9ge+7fhE7t5HdGL/pLLiwPJhrQcq99rjw3D+ngDCNaEbp/FqmboDBBtOGcsu+k21ZEi PKOCJtvKi6gwMRIjA35xPdWMmOsgigIdMxbGhaLlcGvROHW/ltHKTQVXmKKanKRg4mw== 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=paj9Bf+S; 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 6024D606A322; Fri, 4 Dec 2026 10:40:57 +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=paj9Bf+S Received: by smtp.kernel.org (Postfix) with ESMTPSA id C64A11F00931; Fri, 4 Dec 2026 10:40:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380857; bh=/+W0iJjMznw+EL2R3XWUwAPTNzEFbmRnE6XqTRHZ/HU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=paj9Bf+SKd80ZxExBnN1YKlKILuxpfezniivnG4MNNiGvKbGxzVANiKBlvrgAeoSV I1uAqBHpLcYgem7/f3fzbAltd6Jnktfox5OvkZWZGq3yiVjAzLVNVWWpRcv2+wQ1M5 NLWlUT6A3o0+797rTYdX29IPKE+vLh5kpg1zfbTU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Marek Szyprowski Subject: [PATCH 7.3 455/742] dma: swiotlb: Properly tear down the default pool on exit Date: Fri, 4 Dec 2026 19:05:19 +0900 Message-ID: <20261204100647.251192026@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 7d4a177d0d9bc0ca04caec9293ccb902a853cc47 upstream. With CONFIG_SWIOTLB_DYNAMIC enabled, the default memory pool is added to the io_tlb_default_mem.pools RCU list during initialization. When an IOMMU takes over DMA translation, swiotlb_exit() tears the default pool down and clears it with memset(), but leaves its node on the pools list. The list then contains a zeroed entry with a NULL next pointer, and any later walk of the list, for example mem_used() when reading the io_tlb_used debugfs file, dereferences an invalid pointer and crashes. swiotlb_exit() also leaves the io_tlb_default_mem fields that describe the pool. io_tlb_default_mem.nslabs and can_grow stay set, so is_swiotlb_allocated() and is_swiotlb_active() keep returning true, and swiotlb_find_slots() can schedule dynamic pool allocation after teardown. Without CONFIG_SWIOTLB_DYNAMIC, a later mapping can reach the zeroed defpool and hit BUG_ON(area_index >= pool->nareas). Before the pool data was split out of struct io_tlb_mem, swiotlb_exit() cleared the whole structure, including nslabs. Clear can_grow and cancel any pending dyn_alloc work, then remove the default pool from the list and subtract its slots from nslabs, and wait for an RCU grace period before clearing it, so that no reader can still see it. Without CONFIG_SWIOTLB_DYNAMIC, reset nslabs directly. As a result, with CONFIG_SWIOTLB_DYNAMIC swiotlb no longer silently keeps working through dynamic or transient pools after an IOMMU has turned it off, so for example dma-iommu bouncing for untrusted devices reports that bounce buffers are inactive, as it did before the dynamic pools support. Fixes: 158dbe9c9a3d ("swiotlb: separate memory pool data from other allocator data") Fixes: 62708b2ba405 ("swiotlb: add a flag whether SWIOTLB is allowed to grow") Fixes: 1aaa736815eb ("swiotlb: allocate a new memory pool when existing pools are full") Closes: https://sashiko.dev/#/bug/linux-f75998aa-65ea-4596-9bb4-fa83773012a3 Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20261109170603.385791-1-m.szyprowski@samsung.com Signed-off-by: Marek Szyprowski Signed-off-by: Greg Kroah-Hartman --- kernel/dma/swiotlb.c | 11 +++++++++++ 1 file changed, 11 insertions(+) --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -666,6 +666,17 @@ void __init swiotlb_exit(void) return; pr_info("tearing down default memory pool\n"); +#ifdef CONFIG_SWIOTLB_DYNAMIC + io_tlb_default_mem.can_grow = false; + cancel_work_sync(&io_tlb_default_mem.dyn_alloc); + spin_lock(&io_tlb_default_mem.lock); + list_del_rcu(&mem->node); + io_tlb_default_mem.nslabs -= mem->nslabs; + spin_unlock(&io_tlb_default_mem.lock); + synchronize_rcu(); +#else + io_tlb_default_mem.nslabs = 0; +#endif tbl_vaddr = (unsigned long)phys_to_virt(mem->start); tbl_size = PAGE_ALIGN(mem->end - mem->start); slots_size = PAGE_ALIGN(array_size(sizeof(*mem->slots), mem->nslabs));