Date: Mon, 27 Jun 2022 05:37:22 GMT From: Doug Moore <dougm@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: 4d517feaea03 - stable/13 - busdma_iommu: simplify split logic Message-ID: <202206270537.25R5bMWv074578@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by dougm: URL: https://cgit.FreeBSD.org/src/commit/?id=4d517feaea0352aea8828a4a07c40ff85036010d commit 4d517feaea0352aea8828a4a07c40ff85036010d Author: Doug Moore <dougm@FreeBSD.org> AuthorDate: 2022-06-02 20:59:57 +0000 Commit: Doug Moore <dougm@FreeBSD.org> CommitDate: 2022-06-27 05:34:59 +0000 busdma_iommu: simplify split logic iommu_bus_dmamap_load_something1 includes code for handling the possibility of splitting a buffer that is needlessly complex. Simplify it. Reviewed by: alc, kib MFC after: 3 weeks Tested by: pho (previous revisions) Differential Revision: https://reviews.freebsd.org/D35232 (cherry picked from commit 04e86ae357b21fce238a90f31198b25975d0f479) --- sys/dev/iommu/busdma_iommu.c | 34 +++++++++------------------------- 1 file changed, 9 insertions(+), 25 deletions(-) diff --git a/sys/dev/iommu/busdma_iommu.c b/sys/dev/iommu/busdma_iommu.c index 02ac5845bdcc..89e5e1bcff39 100644 --- a/sys/dev/iommu/busdma_iommu.c +++ b/sys/dev/iommu/busdma_iommu.c @@ -563,15 +563,16 @@ iommu_bus_dmamap_load_something1(struct bus_dma_tag_iommu *tag, struct iommu_ctx *ctx; struct iommu_domain *domain; struct iommu_map_entry *entry; - iommu_gaddr_t size; bus_size_t buflen1; - int error, idx, gas_flags, seg; + int error, e_flags, idx, gas_flags, seg; KASSERT(offset < IOMMU_PAGE_SIZE, ("offset %d", offset)); if (segs == NULL) segs = tag->segments; ctx = tag->ctx; domain = ctx->domain; + e_flags = IOMMU_MAP_ENTRY_READ | + ((flags & BUS_DMA_NOWRITE) == 0 ? IOMMU_MAP_ENTRY_WRITE : 0); seg = *segp; error = 0; idx = 0; @@ -583,7 +584,6 @@ iommu_bus_dmamap_load_something1(struct bus_dma_tag_iommu *tag, } buflen1 = buflen > tag->common.maxsegsz ? tag->common.maxsegsz : buflen; - size = round_page(offset + buflen1); /* * (Too) optimistically allow split if there are more @@ -593,30 +593,14 @@ iommu_bus_dmamap_load_something1(struct bus_dma_tag_iommu *tag, if (seg + 1 < tag->common.nsegments) gas_flags |= IOMMU_MF_CANSPLIT; - error = iommu_map(domain, &tag->common, size, offset, - IOMMU_MAP_ENTRY_READ | - ((flags & BUS_DMA_NOWRITE) == 0 ? IOMMU_MAP_ENTRY_WRITE : 0), - gas_flags, ma + idx, &entry); + error = iommu_map(domain, &tag->common, + round_page(offset + buflen1), + offset, e_flags, gas_flags, ma + idx, &entry); if (error != 0) break; - if ((gas_flags & IOMMU_MF_CANSPLIT) != 0) { - KASSERT(size >= entry->end - entry->start, - ("split increased entry size %jx %jx %jx", - (uintmax_t)size, (uintmax_t)entry->start, - (uintmax_t)entry->end)); - size = entry->end - entry->start; - if (buflen1 > size) - buflen1 = size; - } else { - KASSERT(entry->end - entry->start == size, - ("no split allowed %jx %jx %jx", - (uintmax_t)size, (uintmax_t)entry->start, - (uintmax_t)entry->end)); - } - if (offset + buflen1 > size) - buflen1 = size - offset; - if (buflen1 > tag->common.maxsegsz) - buflen1 = tag->common.maxsegsz; + /* Update buflen1 in case buffer split. */ + if (buflen1 > entry->end - entry->start - offset) + buflen1 = entry->end - entry->start - offset; KASSERT(((entry->start + offset) & (tag->common.alignment - 1)) == 0,
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202206270537.25R5bMWv074578>