From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751206AbdBBNzm (ORCPT ); Thu, 2 Feb 2017 08:55:42 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:36632 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750877AbdBBNzk (ORCPT ); Thu, 2 Feb 2017 08:55:40 -0500 Date: Thu, 2 Feb 2017 15:54:48 +0200 From: Mike Rapoport To: Andrew Morton Cc: Andrea Arcangeli , "Dr. David Alan Gilbert" , Hillf Danton , Mike Kravetz , Pavel Emelyanov , Linux-MM , LKML Subject: Re: [PATCH v2 3/5] userfaultfd: non-cooperative: add event for exit() notification References: <1485542673-24387-1-git-send-email-rppt@linux.vnet.ibm.com> <1485542673-24387-4-git-send-email-rppt@linux.vnet.ibm.com> <20170131164132.439f9d30e3a9b3c79bcada3a@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170131164132.439f9d30e3a9b3c79bcada3a@linux-foundation.org> User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 17020213-0032-0000-0000-00000715C7DB X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17020213-0033-0000-0000-0000234AD6C9 Message-Id: <20170202135448.GB19804@rapoport-lnx> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-02-02_10:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1612050000 definitions=main-1702020132 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello Andrew, On Tue, Jan 31, 2017 at 04:41:32PM -0800, Andrew Morton wrote: > On Fri, 27 Jan 2017 20:44:31 +0200 Mike Rapoport wrote: > > > Allow userfaultfd monitor track termination of the processes that have > > memory backed by the uffd. > > > > --- a/fs/userfaultfd.c > > +++ b/fs/userfaultfd.c > > @@ -774,6 +774,30 @@ void userfaultfd_unmap_complete(struct mm_struct *mm, struct list_head *uf) > > } > > } > > > > +void userfaultfd_exit(struct mm_struct *mm) > > +{ > > + struct vm_area_struct *vma = mm->mmap; > > + > > + while (vma) { > > + struct userfaultfd_ctx *ctx = vma->vm_userfaultfd_ctx.ctx; > > + > > + if (ctx && (ctx->features & UFFD_FEATURE_EVENT_EXIT)) { > > + struct userfaultfd_wait_queue ewq; > > + > > + userfaultfd_ctx_get(ctx); > > + > > + msg_init(&ewq.msg); > > + ewq.msg.event = UFFD_EVENT_EXIT; > > + > > + userfaultfd_event_wait_completion(ctx, &ewq); > > + > > + ctx->features &= ~UFFD_FEATURE_EVENT_EXIT; > > + } > > + > > + vma = vma->vm_next; > > + } > > +} > > And we can do the vma walk without locking because the caller (exit_mm) > knows it now has exclusive access. Worth a comment? I've just used your wording, seems to me neat and to the point. >>From 74af75b062dcb2dc3cc8d2b57f9388c22c2b89e5 Mon Sep 17 00:00:00 2001 From: Mike Rapoport Date: Thu, 2 Feb 2017 15:50:14 +0200 Subject: [PATCH] userfaultfd: exit event: add comment about lockless vma walk Signed-off-by: Mike Rapoport --- fs/userfaultfd.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index 6587f40..3c421d0 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -778,6 +778,10 @@ void userfaultfd_exit(struct mm_struct *mm) { struct vm_area_struct *vma = mm->mmap; + /* + * We can do the vma walk without locking because the caller + * (exit_mm) knows it now has exclusive access + */ while (vma) { struct userfaultfd_ctx *ctx = vma->vm_userfaultfd_ctx.ctx; -- 1.9.1