From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qc0-f177.google.com (mail-qc0-f177.google.com [209.85.216.177]) by kanga.kvack.org (Postfix) with ESMTP id 5161990008B for ; Wed, 29 Oct 2014 13:36:25 -0400 (EDT) Received: by mail-qc0-f177.google.com with SMTP id l6so2770104qcy.22 for ; Wed, 29 Oct 2014 10:36:24 -0700 (PDT) Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id s20si8451926qay.118.2014.10.29.10.36.23 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Oct 2014 10:36:24 -0700 (PDT) Date: Wed, 29 Oct 2014 17:39:08 +0100 From: Andrea Arcangeli Subject: Re: [PATCH 2/4] mm: gup: add get_user_pages_locked and get_user_pages_unlocked Message-ID: <20141029163908.GI19606@redhat.com> References: <1412153797-6667-1-git-send-email-aarcange@redhat.com> <1412153797-6667-3-git-send-email-aarcange@redhat.com> <20141009105037.GM4750@worktop.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20141009105037.GM4750@worktop.programming.kicks-ass.net> Sender: owner-linux-mm@kvack.org List-ID: To: Peter Zijlstra Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andres Lagar-Cavilla , Gleb Natapov , Radim Krcmar , Paolo Bonzini , Rik van Riel , Mel Gorman , Andy Lutomirski , Andrew Morton , Sasha Levin , Jianyu Zhan , Paul Cassella , Hugh Dickins , Peter Feiner , "\\\"Dr. David Alan Gilbert\\\"" On Thu, Oct 09, 2014 at 12:50:37PM +0200, Peter Zijlstra wrote: > On Wed, Oct 01, 2014 at 10:56:35AM +0200, Andrea Arcangeli wrote: > > > +static inline long __get_user_pages_locked(struct task_struct *tsk, > > + struct mm_struct *mm, > > + unsigned long start, > > + unsigned long nr_pages, > > + int write, int force, > > + struct page **pages, > > + struct vm_area_struct **vmas, > > + int *locked, > > + bool notify_drop) > > +{ > > > + if (notify_drop && lock_dropped && *locked) { > > + /* > > + * We must let the caller know we temporarily dropped the lock > > + * and so the critical section protected by it was lost. > > + */ > > + up_read(&mm->mmap_sem); > > + *locked = 0; > > + } > > + return pages_done; > > +} > > > +long get_user_pages_locked(struct task_struct *tsk, struct mm_struct *mm, > > + unsigned long start, unsigned long nr_pages, > > + int write, int force, struct page **pages, > > + int *locked) > > +{ > > + return __get_user_pages_locked(tsk, mm, start, nr_pages, write, force, > > + pages, NULL, locked, true); > > +} > > > +long get_user_pages_unlocked(struct task_struct *tsk, struct mm_struct *mm, > > + unsigned long start, unsigned long nr_pages, > > + int write, int force, struct page **pages) > > +{ > > + long ret; > > + int locked = 1; > > + down_read(&mm->mmap_sem); > > + ret = __get_user_pages_locked(tsk, mm, start, nr_pages, write, force, > > + pages, NULL, &locked, false); > > + if (locked) > > + up_read(&mm->mmap_sem); > > + return ret; > > +} > > > long get_user_pages(struct task_struct *tsk, struct mm_struct *mm, > > unsigned long start, unsigned long nr_pages, int write, > > int force, struct page **pages, struct vm_area_struct **vmas) > > { > > + return __get_user_pages_locked(tsk, mm, start, nr_pages, write, force, > > + pages, vmas, NULL, false); > > } > > I'm wondering about that notify_drop parameter, what's the added > benefit? If you look at these 3 callers we can do away with it, since in > the second called where we have locked but !notify_drop we seem to do The second (and third) caller pass notify_drop=false, so the notify_drop parameter is always a noop for them. They certainly could get away without it. > the exact same thing afterwards anyway. It makes a difference only to the first caller, if it wasn't for the first caller notify_drop could be dropped. The first caller does this: return __get_user_pages_locked(tsk, mm, start, nr_pages, write, force, pages, NULL, locked, true, FOLL_TOUCH); ^ notify_drop = true Without "notify_drop=true" the first caller could make its own respective caller think the lock has never been dropped, just because it is locked by the time get_user_pages_locked returned. But the caller must be made aware that the lock has been dropped during the call and in turn any "vma" it got before inside the mmap_sem critical section is now stale. That's all notify_drop achieves. Thanks, Andrea -- 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: email@kvack.org