Date: Sat, 21 Nov 2015 19:55:01 +0000 (UTC) From: Svatopluk Kraus <skra@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r291142 - in head/sys: arm/arm arm64/arm64 mips/mips powerpc/powerpc x86/x86 Message-ID: <201511211955.tALJt18a052565@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: skra Date: Sat Nov 21 19:55:01 2015 New Revision: 291142 URL: https://svnweb.freebsd.org/changeset/base/291142 Log: Fix BUS_DMA_MIN_ALLOC_COMP flag logic. When bus_dmamap_t map is being created for bus_dma_tag_t tag, bounce pages should be allocated only if needed. Before the fix, they were allocated always if BUS_DMA_COULD_BOUNCE flag was set but BUS_DMA_MIN_ALLOC_COMP not. As bounce pages are never freed, it could cause memory exhaustion when a lot of such tags together with their maps were created. Note that there could be more maps in one tag by current design. However BUS_DMA_MIN_ALLOC_COMP flag is tag's flag. It's set after bounce pages are allocated. Thus, they are allocated only for first tag's map which needs them. Approved by: kib (mentor) Modified: head/sys/arm/arm/busdma_machdep-v6.c head/sys/arm/arm/busdma_machdep.c head/sys/arm64/arm64/busdma_bounce.c head/sys/mips/mips/busdma_machdep.c head/sys/powerpc/powerpc/busdma_machdep.c head/sys/x86/x86/busdma_bounce.c Modified: head/sys/arm/arm/busdma_machdep-v6.c ============================================================================== --- head/sys/arm/arm/busdma_machdep-v6.c Sat Nov 21 18:21:16 2015 (r291141) +++ head/sys/arm/arm/busdma_machdep-v6.c Sat Nov 21 19:55:01 2015 (r291142) @@ -654,8 +654,8 @@ allocate_bz_and_pages(bus_dma_tag_t dmat maxpages = MAX_BPAGES; else maxpages = 2 * bz->map_count; - if ((dmat->flags & BUS_DMA_MIN_ALLOC_COMP) == 0 || - (bz->map_count > 0 && bz->total_bpages < maxpages)) { + if ((dmat->flags & BUS_DMA_MIN_ALLOC_COMP) == 0 && + bz->map_count > 0 && bz->total_bpages < maxpages) { int pages; pages = atop(roundup2(dmat->maxsize, PAGE_SIZE)) + 1; Modified: head/sys/arm/arm/busdma_machdep.c ============================================================================== --- head/sys/arm/arm/busdma_machdep.c Sat Nov 21 18:21:16 2015 (r291141) +++ head/sys/arm/arm/busdma_machdep.c Sat Nov 21 19:55:01 2015 (r291142) @@ -569,8 +569,8 @@ allocate_bz_and_pages(bus_dma_tag_t dmat * basis up to a sane limit. */ maxpages = MAX_BPAGES; - if ((dmat->flags & BUS_DMA_MIN_ALLOC_COMP) == 0 - || (bz->map_count > 0 && bz->total_bpages < maxpages)) { + if ((dmat->flags & BUS_DMA_MIN_ALLOC_COMP) == 0 && + bz->map_count > 0 && bz->total_bpages < maxpages) { int pages; pages = MAX(atop(dmat->maxsize), 1); Modified: head/sys/arm64/arm64/busdma_bounce.c ============================================================================== --- head/sys/arm64/arm64/busdma_bounce.c Sat Nov 21 18:21:16 2015 (r291141) +++ head/sys/arm64/arm64/busdma_bounce.c Sat Nov 21 19:55:01 2015 (r291142) @@ -304,8 +304,8 @@ bounce_bus_dmamap_create(bus_dma_tag_t d else maxpages = MIN(MAX_BPAGES, Maxmem - atop(dmat->common.lowaddr)); - if ((dmat->bounce_flags & BUS_DMA_MIN_ALLOC_COMP) == 0 || - (bz->map_count > 0 && bz->total_bpages < maxpages)) { + if ((dmat->bounce_flags & BUS_DMA_MIN_ALLOC_COMP) == 0 && + bz->map_count > 0 && bz->total_bpages < maxpages) { pages = MAX(atop(dmat->common.maxsize), 1); pages = MIN(maxpages - bz->total_bpages, pages); pages = MAX(pages, 1); Modified: head/sys/mips/mips/busdma_machdep.c ============================================================================== --- head/sys/mips/mips/busdma_machdep.c Sat Nov 21 18:21:16 2015 (r291141) +++ head/sys/mips/mips/busdma_machdep.c Sat Nov 21 19:55:01 2015 (r291142) @@ -560,8 +560,8 @@ bus_dmamap_create(bus_dma_tag_t dmat, in * basis up to a sane limit. */ maxpages = MAX_BPAGES; - if ((dmat->flags & BUS_DMA_MIN_ALLOC_COMP) == 0 - || (bz->map_count > 0 && bz->total_bpages < maxpages)) { + if ((dmat->flags & BUS_DMA_MIN_ALLOC_COMP) == 0 && + bz->map_count > 0 && bz->total_bpages < maxpages) { int pages; pages = MAX(atop(dmat->maxsize), 1); Modified: head/sys/powerpc/powerpc/busdma_machdep.c ============================================================================== --- head/sys/powerpc/powerpc/busdma_machdep.c Sat Nov 21 18:21:16 2015 (r291141) +++ head/sys/powerpc/powerpc/busdma_machdep.c Sat Nov 21 19:55:01 2015 (r291142) @@ -423,8 +423,8 @@ bus_dmamap_create(bus_dma_tag_t dmat, in maxpages = MAX_BPAGES; else maxpages = MIN(MAX_BPAGES, Maxmem -atop(dmat->lowaddr)); - if ((dmat->flags & BUS_DMA_MIN_ALLOC_COMP) == 0 - || (bz->map_count > 0 && bz->total_bpages < maxpages)) { + if ((dmat->flags & BUS_DMA_MIN_ALLOC_COMP) == 0 && + bz->map_count > 0 && bz->total_bpages < maxpages) { int pages; pages = MAX(atop(dmat->maxsize), 1); Modified: head/sys/x86/x86/busdma_bounce.c ============================================================================== --- head/sys/x86/x86/busdma_bounce.c Sat Nov 21 18:21:16 2015 (r291141) +++ head/sys/x86/x86/busdma_bounce.c Sat Nov 21 19:55:01 2015 (r291142) @@ -308,8 +308,8 @@ bounce_bus_dmamap_create(bus_dma_tag_t d else maxpages = MIN(MAX_BPAGES, Maxmem - atop(dmat->common.lowaddr)); - if ((dmat->bounce_flags & BUS_DMA_MIN_ALLOC_COMP) == 0 || - (bz->map_count > 0 && bz->total_bpages < maxpages)) { + if ((dmat->bounce_flags & BUS_DMA_MIN_ALLOC_COMP) == 0 && + bz->map_count > 0 && bz->total_bpages < maxpages) { pages = MAX(atop(dmat->common.maxsize), 1); pages = MIN(maxpages - bz->total_bpages, pages); pages = MAX(pages, 1);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201511211955.tALJt18a052565>