linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: KOSAKI Motohiro <kosaki.motohiro@gmail.com>
To: Jan Kara <jack@suse.cz>
Cc: Christoph Hellwig <hch@infradead.org>,
	LKML <linux-kernel@vger.kernel.org>,
	linux-mm@kvack.org, Alexander Viro <viro@zeniv.linux.org.uk>,
	Andreas Dilger <andreas.dilger@intel.com>,
	Andy Walls <awalls@md.metrocast.net>,
	Arnd Bergmann <arnd@arndb.de>, Benjamin LaHaise <bcrl@kvack.org>,
	ceph-devel@vger.kernel.org,
	Dan Williams <dan.j.williams@intel.com>,
	David Airlie <airlied@linux.ie>,
	dri-devel@lists.freedesktop.org, Gleb Natapov <gleb@redhat.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	hpdd-discuss@ml01.01.org, Jarod Wilson <jarod@wilsonet.com>,
	Jayant Mangalampalli <jayant.mangalampalli@intel.com>,
	Jean-Christophe Plagniol-Villard <plagnioj@jcrosoft.com>,
	Jesper Nilsson <jesper.nilsson@axis.com>,
	Kai Makisara <Kai.Makisara@kolumbus.fi>,
	kvm@vger.kernel.org,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	linux-aio@kvack.org, linux-cris-kernel@axis.com,
	linux-fbdev@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	linux-ia64@vger.kernel.org, linux-media@vger.kernel.org,
	linux-nfs@vger.kernel.org, linux-rdma@vger.kernel.org,
	linux-scsi@vger.kernel.org, Manu Abraham <abraham.manu@gmail.com>,
	Mark Allyn <mark.a.allyn@intel.com>,
	Mikael Starvik <starvik@axis.com>,
	Mike Marciniszyn <infinipath@intel.com>,
	Naren Sankar <nsankar@broadcom.com>,
	Paolo Bonzini <pbonzini@redhat.com>, Peng Tao <tao.peng@emc.com>,
	Roland Dreier <roland@kernel.org>, Sage Weil <sage@inktank.com>,
	Scott Davilla <davilla@4pi.com>, Timur Tabi <timur@freescale.com>,
	Tomi Valkeinen <tomi.valkeinen@ti.com>,
	Tony Luck <tony.luck@intel.com>,
	Trond Myklebust <Trond.Myklebust@netapp.com>
Subject: Re: [PATCH 0/26] get_user_pages() cleanup
Date: Fri, 04 Oct 2013 16:42:19 -0400	[thread overview]
Message-ID: <524F282B.2080809@gmail.com> (raw)
In-Reply-To: <524F2592.1040305@gmail.com>

(10/4/13 4:31 PM), KOSAKI Motohiro wrote:
> (10/2/13 4:29 PM), Jan Kara wrote:
>> On Wed 02-10-13 09:20:09, Christoph Hellwig wrote:
>>> On Wed, Oct 02, 2013 at 04:27:41PM +0200, Jan Kara wrote:
>>>>     Hello,
>>>>
>>>>     In my quest for changing locking around page faults to make things easier for
>>>> filesystems I found out get_user_pages() users could use a cleanup.  The
>>>> knowledge about necessary locking for get_user_pages() is in tons of places in
>>>> drivers and quite a few of them actually get it wrong (don't have mmap_sem when
>>>> calling get_user_pages() or hold mmap_sem when calling copy_from_user() in the
>>>> surrounding code). Rather often this actually doesn't seem necessary. This
>>>> patch series converts lots of places to use either get_user_pages_fast()
>>>> or a new simple wrapper get_user_pages_unlocked() to remove the knowledge
>>>> of mmap_sem from the drivers. I'm still looking into converting a few remaining
>>>> drivers (most notably v4l2) which are more complex.
>>>
>>> Even looking over the kerneldoc comment next to it I still fail to
>>> understand when you'd want to use get_user_pages_fast and when not.
>>     AFAIU get_user_pages_fast() should be used
>> 1) if you don't need any special get_user_pages() arguments (like calling
>>      it for mm of a different process, forcing COW, or similar).
>> 2) you don't expect pages to be unmapped (then get_user_pages_fast() is
>> actually somewhat slower because it walks page tables twice).
>
> If target page point to anon or private mapping pages, get_user_pages_fast()
> is fork unsafe. O_DIRECT man pages describe a bit about this.
>
>
> see http://man7.org/linux/man-pages/man2/open.2.html
>
>>        O_DIRECT I/Os should never be run concurrently with the fork(2)
>>        system call, if the memory buffer is a private mapping (i.e., any
>>        mapping created with the mmap(2) MAP_PRIVATE flag; this includes
>>        memory allocated on the heap and statically allocated buffers).  Any
>>        such I/Os, whether submitted via an asynchronous I/O interface or
>>        from another thread in the process, should be completed before
>>        fork(2) is called.  Failure to do so can result in data corruption
>>        and undefined behavior in parent and child processes.  This
>>        restriction does not apply when the memory buffer for the O_DIRECT
>>        I/Os was created using shmat(2) or mmap(2) with the MAP_SHARED flag.
>>        Nor does this restriction apply when the memory buffer has been
>>        advised as MADV_DONTFORK with madvise(2), ensuring that it will not
>>        be available to the child after fork(2).

IMHO, get_user_pages_fast() should be renamed to get_user_pages_quirk(). Its
semantics is not equal to get_user_pages(). When someone simply substitute
get_user_pages() to get_user_pages_fast(), they might see huge trouble.


--
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/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2013-10-04 20:41 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-02 14:27 [PATCH 0/26] get_user_pages() cleanup Jan Kara
2013-10-02 14:27 ` [PATCH 01/26] cris: Convert cryptocop to use get_user_pages_fast() Jan Kara
2013-10-02 14:27 ` [PATCH 02/26] ia64: Use get_user_pages_fast() in err_inject.c Jan Kara
2013-10-02 14:27 ` [PATCH 03/26] dma: Use get_user_pages_fast() in dma_pin_iovec_pages() Jan Kara
2013-10-02 14:27 ` [PATCH 04/26] drm: Convert via driver to use get_user_pages_fast() Jan Kara
2013-10-02 14:27 ` [PATCH 05/26] omap3isp: Make isp_video_buffer_prepare_user() " Jan Kara
2013-10-02 19:41   ` Laurent Pinchart
2013-10-02 20:18     ` Jan Kara
2013-10-02 14:27 ` [PATCH 06/26] vmw_vmci: Convert driver to " Jan Kara
2013-10-02 14:27 ` [PATCH 07/26] st: Convert sgl_map_user_pages() " Jan Kara
2013-10-02 14:27 ` [PATCH 08/26] ced1401: Convert driver " Jan Kara
2013-10-02 14:27 ` [PATCH 09/26] crystalhd: Convert crystalhd_map_dio() " Jan Kara
2013-10-02 14:27 ` [PATCH 10/26] lustre: Convert ll_get_user_pages() " Jan Kara
2013-10-05  6:27   ` Dilger, Andreas
2013-10-02 14:27 ` [PATCH 11/26] sep: Convert sep_lock_user_pages() to get_user_pages_fast() Jan Kara
2013-10-02 14:27 ` [PATCH 12/26] pvr2fb: Convert pvr2fb_write() to use get_user_pages_fast() Jan Kara
2013-10-02 14:27 ` [PATCH 13/26] fsl_hypervisor: Convert ioctl_memcpy() " Jan Kara
2013-10-04  2:38   ` Timur Tabi
2013-10-02 14:27 ` [PATCH 14/26] nfs: Convert direct IO " Jan Kara
2013-10-02 14:27 ` [PATCH 15/26] ceph: Convert ceph_get_direct_page_vector() to get_user_pages_fast() Jan Kara
2013-10-02 14:27 ` [PATCH 16/26] mm: Provide get_user_pages_unlocked() Jan Kara
2013-10-02 16:25   ` Christoph Hellwig
2013-10-02 16:28   ` KOSAKI Motohiro
2013-10-02 19:39     ` Jan Kara
2013-10-02 14:27 ` [PATCH 17/26] kvm: Use get_user_pages_unlocked() in async_pf_execute() Jan Kara
2013-10-02 14:59   ` Gleb Natapov
2013-10-02 14:27 ` [PATCH 18/26] mm: Convert process_vm_rw_pages() to use get_user_pages_unlocked() Jan Kara
2013-10-02 16:32   ` KOSAKI Motohiro
2013-10-02 19:36     ` Jan Kara
2013-10-03 22:40       ` KOSAKI Motohiro
2013-10-07 20:55         ` Jan Kara
2013-10-08  0:10           ` KOSAKI Motohiro
2013-10-02 14:28 ` [PATCH 19/26] ivtv: Convert driver " Jan Kara
2013-10-05 12:02   ` Andy Walls
2013-10-07 17:22     ` Jan Kara
2013-10-02 14:28 ` [PATCH 20/26] ib: Convert ib_umem_get() to get_user_pages_unlocked() Jan Kara
2013-10-02 14:28 ` [PATCH 21/26] ib: Convert ipath_get_user_pages() " Jan Kara
2013-10-02 14:28 ` [PATCH 22/26] ib: Convert ipath_user_sdma_pin_pages() to use get_user_pages_unlocked() Jan Kara
2013-10-02 14:28 ` [PATCH 23/26] ib: Convert qib_get_user_pages() to get_user_pages_unlocked() Jan Kara
2013-10-02 14:54   ` Marciniszyn, Mike
2013-10-02 15:28     ` Jan Kara
2013-10-02 15:32       ` Marciniszyn, Mike
2013-10-02 15:38         ` Jan Kara
2013-10-04 13:39           ` Marciniszyn, Mike
2013-10-04 13:46             ` Marciniszyn, Mike
2013-10-04 13:44         ` Marciniszyn, Mike
2013-10-04 13:52   ` Marciniszyn, Mike
2013-10-04 18:33     ` Jan Kara
2013-10-07 15:20       ` Marciniszyn, Mike
2013-10-07 15:38       ` Marciniszyn, Mike
2013-10-07 17:26         ` Jan Kara
2013-10-08 19:06           ` Jan Kara
2013-10-16 21:39             ` Jan Kara
2013-10-02 14:28 ` [PATCH 24/26] ib: Convert qib_user_sdma_pin_pages() to use get_user_pages_unlocked() Jan Kara
2013-10-02 14:28 ` [PATCH 25/26] ib: Convert mthca_map_user_db() to use get_user_pages_fast() Jan Kara
2013-10-02 14:28 ` [PATCH 26/26] aio: Remove useless get_user_pages() call Jan Kara
2013-10-02 16:20 ` [PATCH 0/26] get_user_pages() cleanup Christoph Hellwig
2013-10-02 20:29   ` Jan Kara
2013-10-04 20:31     ` KOSAKI Motohiro
2013-10-04 20:42       ` KOSAKI Motohiro [this message]
2013-10-07 21:18         ` Jan Kara
2013-10-08  0:27           ` KOSAKI Motohiro
2013-10-08  6:06             ` Jan Kara

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=524F282B.2080809@gmail.com \
    --to=kosaki.motohiro@gmail.com \
    --cc=Kai.Makisara@kolumbus.fi \
    --cc=Trond.Myklebust@netapp.com \
    --cc=abraham.manu@gmail.com \
    --cc=airlied@linux.ie \
    --cc=andreas.dilger@intel.com \
    --cc=arnd@arndb.de \
    --cc=awalls@md.metrocast.net \
    --cc=bcrl@kvack.org \
    --cc=ceph-devel@vger.kernel.org \
    --cc=dan.j.williams@intel.com \
    --cc=davilla@4pi.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gleb@redhat.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hch@infradead.org \
    --cc=hpdd-discuss@ml01.01.org \
    --cc=infinipath@intel.com \
    --cc=jack@suse.cz \
    --cc=jarod@wilsonet.com \
    --cc=jayant.mangalampalli@intel.com \
    --cc=jesper.nilsson@axis.com \
    --cc=kvm@vger.kernel.org \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-aio@kvack.org \
    --cc=linux-cris-kernel@axis.com \
    --cc=linux-fbdev@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-ia64@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=mark.a.allyn@intel.com \
    --cc=nsankar@broadcom.com \
    --cc=pbonzini@redhat.com \
    --cc=plagnioj@jcrosoft.com \
    --cc=roland@kernel.org \
    --cc=sage@inktank.com \
    --cc=starvik@axis.com \
    --cc=tao.peng@emc.com \
    --cc=timur@freescale.com \
    --cc=tomi.valkeinen@ti.com \
    --cc=tony.luck@intel.com \
    --cc=viro@zeniv.linux.org.uk \
    /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).