From owner-svn-src-all@freebsd.org Mon Nov 2 23:37:20 2015 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B0D40A2525F; Mon, 2 Nov 2015 23:37:20 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 727951F4A; Mon, 2 Nov 2015 23:37:20 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id tA2NbJfl004681; Mon, 2 Nov 2015 23:37:19 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id tA2NbJSh004677; Mon, 2 Nov 2015 23:37:19 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201511022337.tA2NbJSh004677@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Mon, 2 Nov 2015 23:37:19 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r290316 - in head/sys: arm64/arm64 powerpc/powerpc sparc64/sparc64 x86/x86 X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 02 Nov 2015 23:37:20 -0000 Author: ian Date: Mon Nov 2 23:37:19 2015 New Revision: 290316 URL: https://svnweb.freebsd.org/changeset/base/290316 Log: 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: head/sys/arm64/arm64/busdma_bounce.c head/sys/powerpc/powerpc/busdma_machdep.c head/sys/sparc64/sparc64/bus_machdep.c head/sys/x86/x86/busdma_bounce.c Modified: head/sys/arm64/arm64/busdma_bounce.c ============================================================================== --- head/sys/arm64/arm64/busdma_bounce.c Mon Nov 2 23:09:21 2015 (r290315) +++ head/sys/arm64/arm64/busdma_bounce.c Mon Nov 2 23:37:19 2015 (r290316) @@ -401,14 +401,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); Modified: head/sys/powerpc/powerpc/busdma_machdep.c ============================================================================== --- head/sys/powerpc/powerpc/busdma_machdep.c Mon Nov 2 23:09:21 2015 (r290315) +++ head/sys/powerpc/powerpc/busdma_machdep.c Mon Nov 2 23:37:19 2015 (r290316) @@ -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: head/sys/sparc64/sparc64/bus_machdep.c ============================================================================== --- head/sys/sparc64/sparc64/bus_machdep.c Mon Nov 2 23:09:21 2015 (r290315) +++ head/sys/sparc64/sparc64/bus_machdep.c Mon Nov 2 23:37:19 2015 (r290316) @@ -518,14 +518,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: head/sys/x86/x86/busdma_bounce.c ============================================================================== --- head/sys/x86/x86/busdma_bounce.c Mon Nov 2 23:09:21 2015 (r290315) +++ head/sys/x86/x86/busdma_bounce.c Mon Nov 2 23:37:19 2015 (r290316) @@ -398,14 +398,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);