linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Inki Dae <inki.dae@samsung.com>
To: 'Jerome Glisse' <j.glisse@gmail.com>
Cc: airlied@linux.ie, dri-devel@lists.freedesktop.org,
	linux-mm@kvack.org, minchan@kernel.org,
	kosaki.motohiro@gmail.com, kyungmin.park@samsung.com,
	sw0312.kim@samsung.com, jy0922.shim@samsung.com
Subject: RE: [PATCH 2/2 v4] drm/exynos: added userptr feature.
Date: Wed, 16 May 2012 17:49:18 +0900	[thread overview]
Message-ID: <003401cd3340$c814c3e0$583e4ba0$%dae@samsung.com> (raw)
In-Reply-To: <CAH3drwZcBY71FpFAhqAaXWCWR4vBPi2PRqh034DBJ_NiffQztA@mail.gmail.com>



> -----Original Message-----
> From: Jerome Glisse [mailto:j.glisse@gmail.com]
> Sent: Tuesday, May 15, 2012 11:31 PM
> To: Inki Dae
> Cc: airlied@linux.ie; dri-devel@lists.freedesktop.org; linux-mm@kvack.org;
> minchan@kernel.org; kosaki.motohiro@gmail.com; kyungmin.park@samsung.com;
> sw0312.kim@samsung.com; jy0922.shim@samsung.com
> Subject: Re: [PATCH 2/2 v4] drm/exynos: added userptr feature.
> 
> On Tue, May 15, 2012 at 12:33 AM, Inki Dae <inki.dae@samsung.com> wrote:
> > Hi Jerome,
> >
> >> -----Original Message-----
> >> From: Jerome Glisse [mailto:j.glisse@gmail.com]
> >> Sent: Tuesday, May 15, 2012 4:27 AM
> >> To: Inki Dae
> >> Cc: airlied@linux.ie; dri-devel@lists.freedesktop.org;
> minchan@kernel.org;
> >> kosaki.motohiro@gmail.com; kyungmin.park@samsung.com;
> >> sw0312.kim@samsung.com; jy0922.shim@samsung.com
> >> Subject: Re: [PATCH 2/2 v4] drm/exynos: added userptr feature.
> >>
> >> On Mon, May 14, 2012 at 2:17 AM, Inki Dae <inki.dae@samsung.com> wrote:
> >> > this feature is used to import user space region allocated by
malloc()
> >> or
> >> > mmaped into a gem. for this, we uses get_user_pages() to get all the
> >> pages
> >> > to VMAs within user address space. However we should pay attention to
> >> use
> >> > this userptr feature like below.
> >> >
> >> > The migration issue.
> >> > - Pages reserved by CMA for some device using DMA could be used by
> >> > kernel and if the device driver wants to use those pages
> >> > while being used by kernel then the pages are copied into
> >> > other ones allocated to migrate them and then finally,
> >> > the device driver can use the pages for itself.
> >> > Thus, migrated, the pages being accessed by DMA could be changed
> >> > to other so this situation may incur that DMA accesses any pages
> >> > it doesn't want.
> >> >
> >> > The COW issue.
> >> > - while DMA of a device is using the pages to VMAs, if current
> >> > process was forked then the pages being accessed by the DMA
> >> > would be copied into child's pages.(Copy On Write) so
> >> > these pages may not have coherrency with parent's ones if
> >> > child process wrote something on those pages so we need to
> >> > flag VM_DONTCOPY to prevent pages from being COWed.
> >>
> >> Note that this is a massive change in behavior of anonymous mapping
> >> this effectively completely change the linux API from application
> >> point of view on your platform. Any application that have memory
> >> mapped by your ioctl will have different fork behavior that other
> >> application. I think this should be stressed, it's one of the thing i
> >> am really uncomfortable with i would rather not have the dont copy
> >> flag and have the page cowed and have the child not working with the
> >> 3d/2d/drm driver. That would means that your driver (opengl
> >> implementation for instance) would have to detect fork and work around
> >> it, nvidia closed source driver do that.
> >>
> >
> > First of all, thank you for your comments.
> >
> > Right, VM_DONTCOPY flag would change original behavior of user. Do you
> think
> > this way has no problem but no generic way? anyway our issue was that
> the
> > pages to VMAs are copied into child's ones(COW) so we prevented those
> pages
> > from being COWed with using VM_DONTCOPY flag.
> >
> > For this, I have three questions below
> >
> > 1. in case of not using VM_DONTCOPY flag, you think that the application
> > using our userptr feature has COW issue; parent's pages being accessed
> by
> > DMA of some device would be copied into child's ones if the child wrote
> > something on the pages. after that, DMA of a device could access pages
> user
> > doesn't want. I'm not sure but I think such behavior has no any problem
> and
> > is generic behavior and it's role of user to do fork or not. Do you
> think
> > such COW behavior could create any issue I don't aware of so we have to
> > prevent that somehow?
> 
> My point is the father will keep the page that the GPU know about as
> long as the father dont destroy the associated object. But if the
> child expect to be able to use the same GPU object and still be able
> to change the content through its anonymous mapping than i would
> consider this behavior buggy (ie application have wrong expectation).
> So i am all for only the father is able to keep its memory mapped into
> GPU address space through same GEM object.
> 
> > 2. so we added VM_DONTCOPY flag to prevent the pages from being COWed
> but
> > this changes original behavior of user. Do you think this is not generic
> way
> > or could create any issue also?
> 
> I would say don't add the flag and consider application that do fork
> as special case in userspace. See below for how i would handle it.
> 
> > 3. and last one, what is the difference between to flag VM_DONTCOPY and
> to
> > detect fork? I mean the device driver should do something to need after
> > detecting fork. and I'm not sure but I think the something may also
> change
> > original behavior of user.
> >
> > Please let me know if there is my missing point.
> 
> I would detect fork by storing process id along gem object. So
> something like (userspace code that could be in your pixman library):
> 
> struct gpu_object_process {
>   struct list list;
>   uint32_t gem_handle;
>   unsigned process_id;
> };
> 
> struct gpu_object {
>   struct list gpu_object_process;
>   void *ptr;
>   unsigned size;
>   ...
> }
> 
> When creating a GPU object from userptr you fill the above structure
> in the userspace code. Then whenever you library want to use this
> object it call something like:
> 
> int gpu_object_validate(struct gpu_object *bo)
> 
> Which check if there is the current process id in the
> gpu_object_process list, if there is one then use the gem object
> handle, otherwise you create a new GEM object using this userptr and
> same size and other properties.
> 
> Note you really need this only in case you expect application using
> you library to fork and still expect to use your gpu accelerated
> library in the same way.
> 
> So doing this you conserve proper unix fork behavior, child change to
> anonymous memory don't reflect into the father anonymous memory and
> that should be the expected behavior even regarding GPU object. Of
> course this means there would be memcpy btw father and child on write
> but that's the expected behavior of fork.
> 
> Note also that i don't expect any of your graphic application to use
> fork so in most case your  gpu_object_process list would be only one
> element.
> 

Thanks for detailed example and that would be very helpful to me and also I
think gpu_object_validate() should be called in normal case(not userptr
case). User can allocate a new gem and map it with its own user space. after
that, if fork is done then it would have same issue as userptr. so
gpu_object_validate() should be called before mapping the gem with user
space also. I understood what you mention and I will unset VM_DONTCOPY flag
and in our case, EXA backend will check that. for this, I gonna add some
comments enough to next patch. please let me know if there is my missing
point.

Thanks,
Inki Dae

> Cheers,
> Jerome

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

      reply	other threads:[~2012-05-16  8:49 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1335188594-17454-4-git-send-email-inki.dae@samsung.com>
     [not found] ` <1336544259-17222-1-git-send-email-inki.dae@samsung.com>
     [not found]   ` <1336544259-17222-3-git-send-email-inki.dae@samsung.com>
2012-05-09 14:45     ` [PATCH 2/2 v3] drm/exynos: added userptr feature Jerome Glisse
2012-05-09 18:32       ` Jerome Glisse
2012-05-10  2:44         ` Inki Dae
2012-05-10 15:05           ` Jerome Glisse
2012-05-10 15:31             ` Daniel Vetter
2012-05-10 15:52               ` Jerome Glisse
2012-05-11  1:47                 ` Inki Dae
2012-05-11  2:08                   ` Minchan Kim
2012-05-10  1:39       ` Inki Dae
2012-05-10  4:58         ` Minchan Kim
2012-05-10  6:53           ` KOSAKI Motohiro
2012-05-10  7:27             ` Minchan Kim
2012-05-10  7:31               ` Kyungmin Park
2012-05-10  7:56                 ` Minchan Kim
2012-05-10  7:58                   ` Minchan Kim
2012-05-10  6:57           ` Inki Dae
2012-05-10  7:05             ` Minchan Kim
2012-05-10  7:59               ` InKi Dae
2012-05-10  8:11                 ` Minchan Kim
2012-05-10  8:44                   ` Inki Dae
2012-05-10 17:53                     ` KOSAKI Motohiro
2012-05-11  0:50                       ` Minchan Kim
2012-05-11  2:51                         ` KOSAKI Motohiro
2012-05-11  3:01                           ` Jerome Glisse
2012-05-11 21:20                             ` KOSAKI Motohiro
2012-05-11 22:22                               ` Jerome Glisse
2012-05-11 22:59                                 ` KOSAKI Motohiro
2012-05-11 23:29                                   ` Jerome Glisse
2012-05-11 23:39                                     ` KOSAKI Motohiro
2012-05-12  4:48                                       ` InKi Dae
2012-05-14  4:29                                         ` Minchan Kim
     [not found]   ` <1336976268-14328-1-git-send-email-inki.dae@samsung.com>
2012-05-14  8:12     ` [PATCH 0/2 v4] " Inki Dae
     [not found]     ` <1336976268-14328-2-git-send-email-inki.dae@samsung.com>
2012-05-14  8:12       ` [PATCH 1/2 v4] drm/exynos: added userptr limit ioctl Inki Dae
     [not found]     ` <1336976268-14328-3-git-send-email-inki.dae@samsung.com>
     [not found]       ` <CAHGf_=qv45_uuO_JWMXOQp4VymyOxVq76rGXghoNMmDh7mURKQ@mail.gmail.com>
     [not found]         ` <003001cd319e$263c9230$72b5b690$%dae@samsung.com>
     [not found]           ` <4FB0AE87.60800@gmail.com>
2012-05-14  8:13             ` [PATCH 2/2 v4] drm/exynos: added userptr feature Inki Dae
     [not found]       ` <CAH3drwb13T2RXgEuauGchoZUDAgL+wrv3SR66sZNyGk_6tRTFw@mail.gmail.com>
2012-05-15  4:33         ` Inki Dae
2012-05-15 14:31           ` Jerome Glisse
2012-05-16  8:49             ` Inki Dae [this message]

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='003401cd3340$c814c3e0$583e4ba0$%dae@samsung.com' \
    --to=inki.dae@samsung.com \
    --cc=airlied@linux.ie \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=j.glisse@gmail.com \
    --cc=jy0922.shim@samsung.com \
    --cc=kosaki.motohiro@gmail.com \
    --cc=kyungmin.park@samsung.com \
    --cc=linux-mm@kvack.org \
    --cc=minchan@kernel.org \
    --cc=sw0312.kim@samsung.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).