From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=210.118.77.12 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795781144; b=H7C6M5W7+X266IJtc46RsPKlZ2JrEyj2eZgxhr3S2FDHmAyAyLK7ZHi5z0/7d5ZGNYX/ WM6I+N3MTDvKpeHahTMRcVpvKVy+qYACwBPBW6f712BQ/hSAmjDM6+uTGWWw/jATJPWmP YtzfRk0ta0HEsO7c3VVVwZ9X04bUJX9cDc6zOevwAK5Dh/x84aucgTsV9ragb4eb6XRwS cx+lIoWu9TlO8Dgd7EgEJlED1ZgaNrCm+M8AWG9y4ZldK6murAvYQRzOFFCyeQtx8CAhV LX34l9vOd0QZZ8alNalQnfJwauhFGbf7P66aZ2TnWWg17OQGTi8W9RIhjKA2nEJOmxg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795781144; h=DMARC-Filter:Received:DKIM-Filter:DKIM-Signature:Received:Received: Message-ID:Date:MIME-Version:User-Agent:Subject:From:To:Cc: Content-Language:In-Reply-To:Content-Transfer-Encoding:X-CMS-MailID: X-Msg-Generator:Content-Type:X-RootMTR:X-EPHeader:X-CMS-RootMailID: References; bh=a9fm/uk5JQ3HNfgBODpdCWOALyft9Wz+Y8nV7YiTAZ4=; b=F+TlfHmRPthv1T9i2CQUPhjQRBH7iin6pRLbacxubMPSDkAXzN3lZNoxnWNu2Ft6RMQJ 5OgcOhBwxyg1d2bgrMcKDvEnihxFz78U3c5SU5TmdAlYJKUXcgWYSqRHZjvtM5VtqmTmn /sNuX0S7vcAI5Wk/0p9XJV1gFe2nnLGJFLA5vn9Q5xk+WQlw6qX01x1KIyRI6UlGl2zSb qUEf/1lo44Y/JHQICemA2eo/aLjRnYCU+4RvZD04251o8U7wBhgI94jAB4Tzb5hzximg8 LmDebYRWZaBb8IAYv9VCmm+AFMQdIJKUaJlkD7MIl1PUFUz96uctFEkoi3shYN6fZMQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass header.d=samsung.com header.i=@samsung.com header.a=rsa-sha256 header.s=mail20170921 header.b="KNGq0ZK/"; arc=none smtp.remote-ip=210.118.77.12 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 411E7606A330 for ; Fri, 27 Nov 2026 12:05:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 411E7606A330 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.a=rsa-sha256 header.s=mail20170921 header.b=KNGq0ZK/ Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20261127120540euoutp02246a0048dadc7af3bf84926a0ead367b~r5W66ICeD2307623076euoutp02I for ; Fri, 27 Nov 2026 12:05:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20261127120540euoutp02246a0048dadc7af3bf84926a0ead367b~r5W66ICeD2307623076euoutp02I DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1795781140; bh=a9fm/uk5JQ3HNfgBODpdCWOALyft9Wz+Y8nV7YiTAZ4=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=KNGq0ZK/A1D5c2Ml3AhUtZiXqmbgvORs6wpuuj660jbSCbmTazbj4gDyBZi+xLwiI jtaDAZpE0HohUhdFj0gD50kJaET1JfCEre56TVD/k5h5NcXWHcg/VQdC+xwKgQDRQI TeRudICmUo1K+W5W9nkh2uKF3tVqVniMXYWMtP4M= Received: from eusmtip2.samsung.com (unknown [203.254.199.222]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20261127120539eucas1p10b2e005bf38fd3ff3ca53b48bf531777~r5W6fzJTf0959809598eucas1p11; Fri, 27 Nov 2026 12:05:39 +0000 (GMT) Received: from [106.210.134.192] (unknown [106.210.134.192]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20261127120538eusmtip27bba0cf597c14302cb8417c82729e000~r5W5u8fKU2205822058eusmtip2X; Fri, 27 Nov 2026 12:05:38 +0000 (GMT) Message-ID: Date: Fri, 27 Nov 2026 13:05:38 +0100 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Betterbird (Windows) Subject: Re: [PATCH] Revert "iommu/dma: simplify dma_iova_destroy() and drop the free_iova helper" From: Marek Szyprowski To: Leon Romanovsky Cc: Sibi Sankar , will@kernel.org, robin.murphy@arm.com, honghuan@amd.com, Jason Gunthorpe , joro@8bytes.org, prakash.gupta@oss.qualcomm.com, iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, stable@vger.kernel.org Content-Language: en-US In-Reply-To: Content-Transfer-Encoding: 8bit X-CMS-MailID: 20261127120539eucas1p10b2e005bf38fd3ff3ca53b48bf531777 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20261125135138eucas1p141ba6b5e09623562e2033e290fba811c X-EPHeader: CA X-CMS-RootMailID: 20261125135138eucas1p141ba6b5e09623562e2033e290fba811c References: <20261125135120.1126571-1-sibi.sankar@oss.qualcomm.com> <20261125183419.GB774860@unreal> On 27.11.2026 12:28, Marek Szyprowski wrote: > On 25.11.2026 19:34, Leon Romanovsky wrote: >> On Wed, Nov 25, 2026 at 06:21:06PM +0100, Marek Szyprowski wrote: >>> On 25.11.2026 14:51, Sibi Sankar wrote: >>>> This reverts commit 1acce29926d93f3eba427696fe3da6451504dae2. >>>> >>>> Before this commit, dma_iova_destroy() unmapped through >>>> __iommu_dma_iova_unlink(..., free_iova=true), which set >>>> iotlb_gather.queued from cookie->fq_domain, skipped iommu_iotlb_sync() >>>> and freed the IOVA with the queued gather, exactly like >>>> __iommu_dma_unmap(). After it, dma_iova_destroy() calls >>>> dma_iova_unlink() and then dma_iova_free(): >>>> >>>> - dma_iova_unlink() never marks its gather as queued and always calls >>>> iommu_iotlb_sync() after iommu_unmap_fast(). >>>> - dma_iova_free() passes a NULL gather to iommu_dma_free_iova(), so >>>> the IOVA goes straight back to the allocator through >>>> free_iova_fast() and never through queue_iova(). >>>> >>>> DMA-FQ domains therefore get strict invalidation on this path. That >>>> includes the block layer's blk_rq_dma_map() path, which NVMe uses for >>>> all data transfers, so iommu.strict=0 has no effect on NVMe I/O. >>>> >>>> hw/sw details: Qualcomm Glymur CRD: SMMUv3 with no RANGE_INV, >>>> 4K pages; NVMe SSD on PCIe Gen5 x4 >>>> >>>> Fio sequential read/write numbers: >>>> Domain seq write seq read >>>> DMA (strict) 2694 MiB/s 2693 MiB/s >>>> DMA-FQ (lazy), flush queue 2707 MiB/s 2803 MiB/s >>>> bypassed (this regression) >>>> DMA-FQ (lazy), flush queue 10.6 GiB/s 11.9 GiB/s >>>> used by dma_iova_destroy() >>>> >>>> Fixes: 1acce29926d9 ("iommu/dma: simplify dma_iova_destroy() and drop the free_iova helper") >>>> Cc: stable@vger.kernel.org # v7.3+ >>>> Signed-off-by: Sibi Sankar >>> The performance data clearly shows that the flush queue was there for >>> the reason. Together with this revert it would probably make sense to >>> apply the v1 of the reverted patch: >>> >>> https://lore.kernel.org/all/20260701092033.422867-1-honghuan@amd.com/ >>> >>> Leon, do You see any other option? >> These numbers shows clearly that we had iotlb_gather.queued != 0 >> and never performed iommu_iotlb_sync(domain, &iotlb_gather); while >> destroying mapped IOVA. >> >> I agree with you, v1 is the easiest solution, however my preferred one >> is to cache gather when it is created and keep it in dma_iova_state >> structure for whole life cycle of that struct. > I've played with the code (using LLM ;) and there are some issues with this > approach: > > 1. tso_dma_map_completion_save() copies the struct dma_iova_state by value, > what breaks internals of the struct iommu_iotlb_gather. > 2. adding iommu_iotlb_gather to dma_iova_state increase the struct size > from 16 to 64 bytes, what lands in every NVMe request, RDMA rw contexts, > TSO maps and HMM. > > I've decided to put only the 'use_fq' bit in the __size entry and baked the > fix. It looks quite nice. This approach solves both above issues, although > it requires to also fix some drivers which already pokes __size directly > instead of calling dma_iova_size(). > > I will post this in a few minutes. For the reference: https://lore.kernel.org/all/20261127115849.2780625-1-m.szyprowski@samsung.com/ Best regards -- Marek Szyprowski, PhD Samsung R&D Institute Poland