From owner-freebsd-hackers@FreeBSD.ORG Fri Jan 8 16:13:34 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 AB106106568B for ; Fri, 8 Jan 2010 16:13:34 +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 7C4618FC25 for ; Fri, 8 Jan 2010 16:13:34 +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 2BBD946B09; Fri, 8 Jan 2010 11:13:34 -0500 (EST) Received: from jhbbsd.localnet (smtp.hudson-trading.com [209.249.190.9]) by bigwig.baldwin.cx (Postfix) with ESMTPA id D106C8A025; Fri, 8 Jan 2010 11:13:32 -0500 (EST) From: John Baldwin To: Mark Tinguely Date: Fri, 8 Jan 2010 11:13:29 -0500 User-Agent: KMail/1.12.1 (FreeBSD/7.2-CBSD-20091103; KDE/4.3.1; amd64; ; ) References: <201001081414.o08EEaBM053148@casselton.net> In-Reply-To: <201001081414.o08EEaBM053148@casselton.net> MIME-Version: 1.0 Message-Id: <201001081113.30008.jhb@freebsd.org> Content-Type: Text/Plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.0.1 (bigwig.baldwin.cx); Fri, 08 Jan 2010 11:13:33 -0500 (EST) X-Virus-Scanned: clamav-milter 0.95.1 at bigwig.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-2.5 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: freebsd-hackers@freebsd.org Subject: Re: bus_dmamap_load_uio() and user data 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: Fri, 08 Jan 2010 16:13:34 -0000 On Friday 08 January 2010 9:14:36 am Mark Tinguely wrote: > > You should use the pmap from the thread in the uio structure. Similar to > > this from the x86 bus_dma code: > > > > if (uio->uio_segflg == UIO_USERSPACE) { > > KASSERT(uio->uio_td != NULL, > > ("bus_dmamap_load_uio: USERSPACE but no proc")); > > pmap = vmspace_pmap(uio->uio_td->td_proc->p_vmspace); > > } else > > pmap = NULL; > > > > Later when doing VA -> PA conversions the code does this: > > > > if (pmap) > > paddr = pmap_extract(pmap, vaddr); > > else > > paddr = pmap_kextract(vaddr); > > > > We do that, but I notice that all the architecture that implement > bounce buffers assume the VA is in the current map. Most of the > addresses are KVA, but bus_dmamap_load_uio() can be in the user space. > > I was wondering about the sequence: > > bus_dmamap_load_uio() user space > dma_load_buffer() > add bounce page save UVA (in caller user map) > > later: > > bus_dma_sync > copies bounce buffer from saved UVA. <- here is my concern. The user pmap > is not remembered use current pmap. > > Since the bounce buffer copy routines have been running in other architectures > for years without corruption, I was wondering we can safely assume that the > dma sync is running in the same thread/address space as the bus_dmamap_load_uio > call. I was hoping you would say, don't worry the scheduler would always > reload the same thread to execute the dma sync code ... Ahh. I think bus_dmamap_load_uio() doesn't do deferred callbacks (i.e. mandates BUS_DMA_NOWAIT), and probably is always invoked from curthread. Even in the case of aio, the thread's vmspace is the effective one at the time bus_dmamap_load_uio() would be invoked, so in practice it is safe. -- John Baldwin