From mboxrd@z Thu Jan 1 00:00:00 1970 From: Daniel Vetter Subject: Re: [PATCH 3/7] drm/udl: import prime-fds with proper page-alignment Date: Tue, 21 Jan 2014 10:41:50 +0100 Message-ID: <20140121094150.GN15089@phenom.ffwll.local> References: <1390245989-13280-1-git-send-email-dh.herrmann@gmail.com> <1390245989-13280-3-git-send-email-dh.herrmann@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail-ee0-f45.google.com (mail-ee0-f45.google.com [74.125.83.45]) by gabe.freedesktop.org (Postfix) with ESMTP id 955CBFB231 for ; Tue, 21 Jan 2014 01:41:54 -0800 (PST) Received: by mail-ee0-f45.google.com with SMTP id b15so3871818eek.4 for ; Tue, 21 Jan 2014 01:41:53 -0800 (PST) Content-Disposition: inline In-Reply-To: <1390245989-13280-3-git-send-email-dh.herrmann@gmail.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dri-devel-bounces@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org To: David Herrmann Cc: Daniel Vetter , dri-devel@lists.freedesktop.org List-Id: dri-devel@lists.freedesktop.org On Mon, Jan 20, 2014 at 08:26:25PM +0100, David Herrmann wrote: > Instead of rounding down to the next lower page-boundary, round up. > dma-buf guarantees that we can map buffers in multiples of a page, so if > an exporter does not page-align, do it ourselves. > > This avoids issues if the exported buffer contains an unaligned size and > we crop it. In this case, the buffer is too small for the UDL CRTC. So we > round up to page-size now and avoid black borders. Worst case is we end up > reading out some random kernel memory, but we can never fault as the whole > page has the same access-rights. And in this case it's an issue of the > buggy exporting driver, not the importing one. > > Signed-off-by: David Herrmann > --- > drivers/gpu/drm/udl/udl_gem.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/gpu/drm/udl/udl_gem.c b/drivers/gpu/drm/udl/udl_gem.c > index df963a1..1069e57 100644 > --- a/drivers/gpu/drm/udl/udl_gem.c > +++ b/drivers/gpu/drm/udl/udl_gem.c > @@ -227,7 +227,7 @@ static int udl_prime_create(struct drm_device *dev, > struct udl_gem_object *obj; > int npages; > > - npages = size / PAGE_SIZE; > + npages = PAGE_ALIGN(size) >> PAGE_SHIFT; Imo the proper patch would be to reject exporting anything which isn't page-aligned as a dma-buf in the driver core (together with a quick review of the docs to make sure this requirement is clear). This is just a bug in the exporter. -Daniel > > *obj_p = NULL; > obj = udl_gem_alloc_object(dev, npages * PAGE_SIZE); > -- > 1.8.5.3 > -- Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch