From ba74ba674f65215b648f7bd9043ef0523bb68b4f Mon Sep 17 00:00:00 2001 From: Scott Long Date: Sat, 12 Mar 2005 07:01:53 +0000 Subject: [PATCH] Guard against an integer underflow that could cause busdma to eat up all available RAM. This also results in the global bounce page limit being applied to zones instead of globally. Submitted by: Petr Lampa (in part) --- sys/i386/i386/busdma_machdep.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/sys/i386/i386/busdma_machdep.c b/sys/i386/i386/busdma_machdep.c index ed18997fd06c..3c9a7e001fd1 100644 --- a/sys/i386/i386/busdma_machdep.c +++ b/sys/i386/i386/busdma_machdep.c @@ -382,12 +382,14 @@ bus_dmamap_create(bus_dma_tag_t dmat, int flags, bus_dmamap_t *mapp) if (dmat->flags & BUS_DMA_COULD_BOUNCE) { /* Must bounce */ + struct bounce_zone *bz; int maxpages; if (dmat->bounce_zone == NULL) { if ((error = alloc_bounce_zone(dmat)) != 0) return (error); } + bz = dmat->bounce_zone; *mapp = (bus_dmamap_t)malloc(sizeof(**mapp), M_DEVBUF, M_NOWAIT | M_ZERO); @@ -404,13 +406,17 @@ bus_dmamap_create(bus_dma_tag_t dmat, int flags, bus_dmamap_t *mapp) * Attempt to add pages to our pool on a per-instance * basis up to a sane limit. */ - maxpages = MIN(MAX_BPAGES, Maxmem - atop(dmat->lowaddr)); + if (dmat->alignment > 1) + maxpages = MAX_BPAGES; + else + maxpages = MIN(MAX_BPAGES, Maxmem -atop(dmat->lowaddr)); if ((dmat->flags & BUS_DMA_MIN_ALLOC_COMP) == 0 - || (dmat->map_count > 0 && total_bpages < maxpages)) { + || (dmat->map_count > 0 && bz->total_bpages < maxpages)) { int pages; pages = MAX(atop(dmat->maxsize), 1); - pages = MIN(maxpages - total_bpages, pages); + pages = MIN(maxpages - bz->total_bpages, pages); + pages = MAX(pages, 1); if (alloc_bounce_pages(dmat, pages) < pages) error = ENOMEM;