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)
This commit is contained in:
Svatopluk Kraus 2015-11-21 19:55:01 +00:00
parent 3bf2363dca
commit 6fa7734d6f
6 changed files with 12 additions and 12 deletions

View File

@ -654,8 +654,8 @@ allocate_bz_and_pages(bus_dma_tag_t dmat, bus_dmamap_t mapp)
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;

View File

@ -569,8 +569,8 @@ allocate_bz_and_pages(bus_dma_tag_t dmat, bus_dmamap_t map)
* 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);

View File

@ -304,8 +304,8 @@ bounce_bus_dmamap_create(bus_dma_tag_t dmat, int flags, bus_dmamap_t *mapp)
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);

View File

@ -560,8 +560,8 @@ bus_dmamap_create(bus_dma_tag_t dmat, int flags, bus_dmamap_t *mapp)
* 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);

View File

@ -423,8 +423,8 @@ bus_dmamap_create(bus_dma_tag_t dmat, int flags, bus_dmamap_t *mapp)
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);

View File

@ -308,8 +308,8 @@ bounce_bus_dmamap_create(bus_dma_tag_t dmat, int flags, bus_dmamap_t *mapp)
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);