From owner-freebsd-arch@FreeBSD.ORG Sat Apr 25 16:34:50 2015 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 0AC6310C for ; Sat, 25 Apr 2015 16:34:50 +0000 (UTC) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 72EDE114E for ; Sat, 25 Apr 2015 16:34:49 +0000 (UTC) Received: from tom.home (kostik@localhost [127.0.0.1]) by kib.kiev.ua (8.14.9/8.14.9) with ESMTP id t3PGYipw005993 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Sat, 25 Apr 2015 19:34:44 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.9.2 kib.kiev.ua t3PGYipw005993 Received: (from kostik@localhost) by tom.home (8.14.9/8.14.9/Submit) id t3PGYiLE005992; Sat, 25 Apr 2015 19:34:44 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Sat, 25 Apr 2015 19:34:44 +0300 From: Konstantin Belousov To: Jason Harmening Cc: Svatopluk Kraus , FreeBSD Arch Subject: Re: bus_dmamap_sync() for bounced client buffers from user address space Message-ID: <20150425163444.GL2390@kib.kiev.ua> References: <20150425094152.GE2390@kib.kiev.ua> <553B9E64.8030907@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <553B9E64.8030907@gmail.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on tom.home X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 25 Apr 2015 16:34:50 -0000 On Sat, Apr 25, 2015 at 09:02:12AM -0500, Jason Harmening wrote: > It seems like in general it is too hard for drivers using busdma to deal > with usermode memory in a way that's both safe and efficient: > --bus_dmamap_load_uio + UIO_USERSPACE is apparently really unsafe > --if they do things the other way and allocate in the kernel, then then > they better either be willing to do extra copying, or create and > refcount their own vm_objects and use d_mmap_single (I still haven't > seen a good example of that), or leak a bunch of memory (if they use > d_mmap), because the old device pager is also really unsafe. munmap(2) does not free the pages, it removes the mapping and dereferences the backing vm object. If the region was wired, munmap would decrement the wiring count for the pages. So if a kernel code wired the regions pages, they are kept wired, but no longer mapped into the userspace. So bcopy() still does not work. d_mmap_single() is used by GPU, definitely by GEM and TTM code, and possibly by the proprietary nvidia driver. I believe UIO_USERSPACE is almost unused, it might be there for some obscure (and buggy) driver.