All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel@ffwll.ch>
To: Gerd Hoffmann <kraxel@redhat.com>
Cc: dri-devel <dri-devel@lists.freedesktop.org>,
	Thomas Zimmermann <tzimmermann@suse.de>
Subject: Re: [PATCH v2] drm/gem: Fix mmap fake offset handling for drm_gem_object_funcs.mmap
Date: Wed, 13 Nov 2019 17:27:29 +0100	[thread overview]
Message-ID: <20191113162729.GQ23790@phenom.ffwll.local> (raw)
In-Reply-To: <20191113135145.itdsbojzrj5elzvu@sirius.home.kraxel.org>

On Wed, Nov 13, 2019 at 02:51:45PM +0100, Gerd Hoffmann wrote:
>   Hi,
> 
> > > ... but after looking again I think we are all green here.  Given that
> > > only self-import works we'll only see vram gem objects in the mmap code
> > > path, which should have everything set up correctly.  Same goes for qxl.
> > >
> > > All other ttm drivers still use the old mmap code path, so all green
> > > there too I think.  Also I somehow doubt dma-buf mmap vs. drm mmap ends
> > > up using different f_mapping, ttm code has a WARN_ON in ttm_bo_vm_open()
> > > which would fire should that be the case.
> > >
> > > Do imported dma-bufs hit the drm mmap code path in the first place?
> > > Wouldn't mmap be handled by the exporting driver?
> > 
> > drm_gem_dmabuf_mmap -> obj->funcs->mmap -> ttm_bo_mmap_obj
> > 
> > And I'm not seeing anyone adjusting vm_file->f_mapping anywhere here at all.
> 
> [ some more code browsing ]
> 
> Ok, I see.  dma-bufs get their own file, their own anon inode and
> thereby their own address space.  So that it used when mmaping the
> dma-buf.
> 
> drm filehandle's get the shared address space instead, drm_open() sets
> it.
> 
> So, yes, I see the problem.  It's not new though, as far I can see the
> old dma-buf mmap code path doesn't adjust f_mapping anywhere either ...
> 
> > Note to hit this you need userspace to
> > - handle2fd on a buffer to create a dma-buf fd
> > - call mmap directly on that dma-buf fd
> 
> Hmm, seems for handle2fd I need a dummy gem_prime_get_sg_table function
> wired up even when not actually exporting/importing anything.  So I
> think neither qxl nor any of the vram drivers allow to trigger that (and
> no other ttm driver uses the new ttm mmap code yet).
> 
> So, $subject patch should not make things worse in ttm land.
> 
> When hacking the bochs driver to have export callbacks (without
> supporting actual exports) handle2fd + mmap() callback works fine.
> Didn't verify yet I actually get the correct pages mapped.  But maybe
> mmap() isn't the problem when the correct address space is important for
> unmap only.
> 
> Is there a good test case?

You need memory pressure, to force ttm to unmap the bo, not userspace. So
roughly
1. create bo
2. mmap it through drm fd, write some stuff
3. export to dma-buf, mmap it, verify stuff is there
4. create a pile more bo, mmap them write to them
5. once you've thrashed all of vram enough, recheck your original bo. If
I'm right you should get the following:
   - drm fd mmap still show right content
   - dma-buf fd mmap shows random crap that you've written into other
     buffers

Ofc you need to make sure that an mmap actually forces the buffer into
vram. So might need a combo of modeset+mmap, to make that happen. Plain
mmap might just give you ptes that point into system memory, which is not
managed by ttm like vram.

munmap called by userspace isn't a problem, since that starts from the
right struct mm_struct. It's when you start with the object (i.e. in the
driver), and need to figure out where all the various vma that mmap it are
where this matters.
-Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2019-11-13 16:27 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-24 19:18 [PATCH v2] drm/gem: Fix mmap fake offset handling for drm_gem_object_funcs.mmap Rob Herring
2019-10-25  5:34 ` Gerd Hoffmann
2019-10-25  7:30 ` Daniel Vetter
2019-11-08 16:27   ` Daniel Vetter
2019-11-08 16:55     ` Daniel Vetter
2019-11-12  8:52       ` Gerd Hoffmann
2019-11-12  9:35         ` Daniel Vetter
2019-11-12 15:37           ` Rob Herring
2019-11-12 19:06             ` Daniel Vetter
2019-11-12 21:31               ` Rob Herring
2019-11-12 22:14                 ` Daniel Vetter
2019-11-13  7:53                   ` Gerd Hoffmann
2019-11-12  9:26     ` Thomas Zimmermann
2019-11-12  9:32       ` Daniel Vetter
2019-11-12  9:49         ` Thomas Zimmermann
2019-11-12 10:38           ` Gerd Hoffmann
2019-11-12 14:44             ` Daniel Vetter
2019-11-13  7:39               ` Gerd Hoffmann
2019-11-13  8:17                 ` Daniel Vetter
2019-11-13 13:51                   ` Gerd Hoffmann
2019-11-13 16:27                     ` Daniel Vetter [this message]
2019-11-15  9:37                       ` Gerd Hoffmann
2019-11-15 10:18                         ` Daniel Vetter
2019-11-15 10:56                           ` Gerd Hoffmann
2019-11-15 15:31                             ` Daniel Vetter
2019-11-18 10:40                               ` Gerd Hoffmann
2019-11-18 16:49                                 ` Daniel Vetter
2019-11-20  8:05                                   ` Gerd Hoffmann
2019-11-20 10:39                                     ` Daniel Vetter
2019-11-20 11:40                                       ` Gerd Hoffmann
2019-11-20 12:04                                         ` Daniel Vetter
2019-11-20 12:18                                           ` Gerd Hoffmann
2019-11-20 12:34                                             ` Daniel Vetter
2019-11-20 13:08                                               ` Gerd Hoffmann
2019-11-20 13:40                                                 ` Daniel Vetter
2019-11-21  8:10                                                   ` Gerd Hoffmann
2019-11-21  8:47                                                     ` Daniel Vetter
2019-11-21  8:02                                   ` Gerd Hoffmann
2019-11-21  8:49                                     ` Daniel Vetter
2019-11-21 10:18                                       ` Gerd Hoffmann
2019-11-21 10:36                                         ` Daniel Vetter
2019-11-13 13:53                   ` Rob Herring
2019-11-13 16:28                     ` Daniel Vetter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191113162729.GQ23790@phenom.ffwll.local \
    --to=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=kraxel@redhat.com \
    --cc=tzimmermann@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.