Date: Sun, 24 Jan 2016 19:21:53 +0000 (UTC) From: Ian Lepore <ian@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r294677 - in stable/10/sys: kern powerpc/powerpc sparc64/sparc64 x86/x86 Message-ID: <201601241921.u0OJLrSa078594@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: ian Date: Sun Jan 24 19:21:53 2016 New Revision: 294677 URL: https://svnweb.freebsd.org/changeset/base/294677 Log: MFC r289618, r290316: Fix printf format to allow for bus_size_t not being u_long on all platforms. Fix an alignment check that is wrong in half the busdma implementations. This will enable the elimination of a workaround in the USB driver that artifically allocates buffers twice as big as they need to be (which actually saves memory for very small buffers on the buggy platforms). When deciding how to allocate a dma buffer, armv4, armv6, mips, and x86/iommu all correctly check for the tag alignment <= maxsize as enabling simple uma/malloc based allocation. Powerpc, sparc64, x86/bounce, and arm64/bounce were all checking for alignment < maxsize; on those platforms when alignment was equal to the max size it would fall back to page-based allocators even for very small buffers. This change makes all platforms use the <= check. It should be noted that on all platforms other than arm[v6] and mips, this check is relying on undocumented behavior in malloc(9) that if you allocate a block of a given size it will be aligned to the next larger power-of-2 boundary. There is nothing in the malloc(9) man page that makes that explicit promise (but the busdma code has been relying on this behavior all along so I guess it works). Arm and mips code uses the allocator in kern/subr_busdma_buffalloc.c, which does explicitly implement this promise about size and alignment. Other platforms probably should switch to the aligned allocator. Modified: stable/10/sys/kern/subr_busdma_bufalloc.c stable/10/sys/powerpc/powerpc/busdma_machdep.c stable/10/sys/sparc64/sparc64/bus_machdep.c stable/10/sys/x86/x86/busdma_bounce.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/kern/subr_busdma_bufalloc.c ============================================================================== --- stable/10/sys/kern/subr_busdma_bufalloc.c Sun Jan 24 19:12:16 2016 (r294676) +++ stable/10/sys/kern/subr_busdma_bufalloc.c Sun Jan 24 19:21:53 2016 (r294677) @@ -94,8 +94,8 @@ busdma_bufalloc_create(const char *name, for (i = 0, bz = ba->buf_zones, cursize = ba->min_size; i < nitems(ba->buf_zones) && cursize <= MAX_ZONE_BUFSIZE; ++i, ++bz, cursize <<= 1) { - snprintf(bz->name, sizeof(bz->name), "dma %.10s %lu", - name, cursize); + snprintf(bz->name, sizeof(bz->name), "dma %.10s %ju", + name, (uintmax_t)cursize); bz->size = cursize; bz->umazone = uma_zcreate(bz->name, bz->size, NULL, NULL, NULL, NULL, bz->size - 1, zcreate_flags); Modified: stable/10/sys/powerpc/powerpc/busdma_machdep.c ============================================================================== --- stable/10/sys/powerpc/powerpc/busdma_machdep.c Sun Jan 24 19:12:16 2016 (r294676) +++ stable/10/sys/powerpc/powerpc/busdma_machdep.c Sun Jan 24 19:21:53 2016 (r294677) @@ -514,14 +514,14 @@ bus_dmamem_alloc(bus_dma_tag_t dmat, voi /* * XXX: - * (dmat->alignment < dmat->maxsize) is just a quick hack; the exact + * (dmat->alignment <= dmat->maxsize) is just a quick hack; the exact * alignment guarantees of malloc need to be nailed down, and the * code below should be rewritten to take that into account. * * In the meantime, we'll warn the user if malloc gets it wrong. */ if ((dmat->maxsize <= PAGE_SIZE) && - (dmat->alignment < dmat->maxsize) && + (dmat->alignment <= dmat->maxsize) && dmat->lowaddr >= ptoa((vm_paddr_t)Maxmem) && attr == VM_MEMATTR_DEFAULT) { *vaddr = malloc(dmat->maxsize, M_DEVBUF, mflags); Modified: stable/10/sys/sparc64/sparc64/bus_machdep.c ============================================================================== --- stable/10/sys/sparc64/sparc64/bus_machdep.c Sun Jan 24 19:12:16 2016 (r294676) +++ stable/10/sys/sparc64/sparc64/bus_machdep.c Sun Jan 24 19:21:53 2016 (r294677) @@ -521,14 +521,14 @@ nexus_dmamem_alloc(bus_dma_tag_t dmat, v /* * XXX: - * (dmat->dt_alignment < dmat->dt_maxsize) is just a quick hack; the + * (dmat->dt_alignment <= dmat->dt_maxsize) is just a quick hack; the * exact alignment guarantees of malloc need to be nailed down, and * the code below should be rewritten to take that into account. * * In the meantime, we'll warn the user if malloc gets it wrong. */ if (dmat->dt_maxsize <= PAGE_SIZE && - dmat->dt_alignment < dmat->dt_maxsize) + dmat->dt_alignment <= dmat->dt_maxsize) *vaddr = malloc(dmat->dt_maxsize, M_DEVBUF, mflags); else { /* Modified: stable/10/sys/x86/x86/busdma_bounce.c ============================================================================== --- stable/10/sys/x86/x86/busdma_bounce.c Sun Jan 24 19:12:16 2016 (r294676) +++ stable/10/sys/x86/x86/busdma_bounce.c Sun Jan 24 19:21:53 2016 (r294677) @@ -402,14 +402,14 @@ bounce_bus_dmamem_alloc(bus_dma_tag_t dm /* * XXX: - * (dmat->alignment < dmat->maxsize) is just a quick hack; the exact + * (dmat->alignment <= dmat->maxsize) is just a quick hack; the exact * alignment guarantees of malloc need to be nailed down, and the * code below should be rewritten to take that into account. * * In the meantime, we'll warn the user if malloc gets it wrong. */ if ((dmat->common.maxsize <= PAGE_SIZE) && - (dmat->common.alignment < dmat->common.maxsize) && + (dmat->common.alignment <= dmat->common.maxsize) && dmat->common.lowaddr >= ptoa((vm_paddr_t)Maxmem) && attr == VM_MEMATTR_DEFAULT) { *vaddr = malloc(dmat->common.maxsize, M_DEVBUF, mflags);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201601241921.u0OJLrSa078594>