From owner-freebsd-hackers@FreeBSD.ORG Mon Sep 27 15:49:41 2010 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 468451065784 for ; Mon, 27 Sep 2010 15:49:41 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id 15AE08FC0A for ; Mon, 27 Sep 2010 15:49:41 +0000 (UTC) Received: from bigwig.baldwin.cx (66.111.2.69.static.nyinternet.net [66.111.2.69]) by cyrus.watson.org (Postfix) with ESMTPSA id 9B20946B94; Mon, 27 Sep 2010 11:49:40 -0400 (EDT) Received: from jhbbsd.localnet (smtp.hudson-trading.com [209.249.190.9]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 19B868A050; Mon, 27 Sep 2010 11:49:39 -0400 (EDT) From: John Baldwin To: freebsd-hackers@freebsd.org Date: Mon, 27 Sep 2010 11:04:17 -0400 User-Agent: KMail/1.13.5 (FreeBSD/7.3-CBSD-20100819; KDE/4.4.5; amd64; ; ) References: In-Reply-To: MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201009271104.17478.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.0.1 (bigwig.baldwin.cx); Mon, 27 Sep 2010 11:49:39 -0400 (EDT) X-Virus-Scanned: clamav-milter 0.95.1 at bigwig.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-2.6 required=4.2 tests=AWL,BAYES_00 autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on bigwig.baldwin.cx Cc: Neel Natu Subject: Re: PATCH: fix bogus error message "bus_dmamem_alloc failed to align memory properly" X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 Sep 2010 15:49:41 -0000 On Friday, September 24, 2010 9:00:44 pm Neel Natu wrote: > Hi, > > This patch fixes the bogus error message from bus_dmamem_alloc() about > the buffer not being aligned properly. > > The problem is that the check is against a virtual address as opposed > to the physical address. contigmalloc() makes guarantees about > the alignment of physical addresses but not the virtual address > mapping it. > > Any objections if I commit this patch? Hmmm, I guess you are doing super-page alignment rather than sub-page alignment? In general I thought the busdma code only handled sub-page alignment and doesn't fully handle requests for super-page alignment. For example, since it insists on walking individual pages at a time, if you had an alignment setting of 4 pages and passed in a single, aligned 4-page buffer, bus_dma would actually bounce the last 3 pages so that each individual page is 4-page aligned. At least, I think that is what would happen. For sub-page alignment, the virtual and physical address alignments should be the same. > best > Neel > > Index: sys/powerpc/powerpc/busdma_machdep.c > =================================================================== > --- sys/powerpc/powerpc/busdma_machdep.c (revision 213113) > +++ sys/powerpc/powerpc/busdma_machdep.c (working copy) > @@ -529,7 +529,7 @@ > CTR4(KTR_BUSDMA, "%s: tag %p tag flags 0x%x error %d", > __func__, dmat, dmat->flags, ENOMEM); > return (ENOMEM); > - } else if ((uintptr_t)*vaddr & (dmat->alignment - 1)) { > + } else if (vtophys(*vaddr) & (dmat->alignment - 1)) { > printf("bus_dmamem_alloc failed to align memory properly.\n"); > } > #ifdef NOTYET > Index: sys/sparc64/sparc64/bus_machdep.c > =================================================================== > --- sys/sparc64/sparc64/bus_machdep.c (revision 213113) > +++ sys/sparc64/sparc64/bus_machdep.c (working copy) > @@ -652,7 +652,7 @@ > } > if (*vaddr == NULL) > return (ENOMEM); > - if ((uintptr_t)*vaddr % dmat->dt_alignment) > + if (vtophys(*vaddr) % dmat->dt_alignment) > printf("%s: failed to align memory properly.\n", __func__); > return (0); > } > Index: sys/ia64/ia64/busdma_machdep.c > =================================================================== > --- sys/ia64/ia64/busdma_machdep.c (revision 213113) > +++ sys/ia64/ia64/busdma_machdep.c (working copy) > @@ -455,7 +455,7 @@ > } > if (*vaddr == NULL) > return (ENOMEM); > - else if ((uintptr_t)*vaddr & (dmat->alignment - 1)) > + else if (vtophys(*vaddr) & (dmat->alignment - 1)) > printf("bus_dmamem_alloc failed to align memory properly.\n"); > return (0); > } > Index: sys/i386/i386/busdma_machdep.c > =================================================================== > --- sys/i386/i386/busdma_machdep.c (revision 213113) > +++ sys/i386/i386/busdma_machdep.c (working copy) > @@ -540,7 +540,7 @@ > CTR4(KTR_BUSDMA, "%s: tag %p tag flags 0x%x error %d", > __func__, dmat, dmat->flags, ENOMEM); > return (ENOMEM); > - } else if ((uintptr_t)*vaddr & (dmat->alignment - 1)) { > + } else if (vtophys(*vaddr) & (dmat->alignment - 1)) { > printf("bus_dmamem_alloc failed to align memory properly.\n"); > } > if (flags & BUS_DMA_NOCACHE) > Index: sys/amd64/amd64/busdma_machdep.c > =================================================================== > --- sys/amd64/amd64/busdma_machdep.c (revision 213113) > +++ sys/amd64/amd64/busdma_machdep.c (working copy) > @@ -526,7 +526,7 @@ > CTR4(KTR_BUSDMA, "%s: tag %p tag flags 0x%x error %d", > __func__, dmat, dmat->flags, ENOMEM); > return (ENOMEM); > - } else if ((uintptr_t)*vaddr & (dmat->alignment - 1)) { > + } else if (vtophys(*vaddr) & (dmat->alignment - 1)) { > printf("bus_dmamem_alloc failed to align memory properly.\n"); > } > if (flags & BUS_DMA_NOCACHE) > _______________________________________________ > freebsd-hackers@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-hackers > To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org" > -- John Baldwin