From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from userp2130.oracle.com ([156.151.31.86]:53222 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727024AbfGLRuu (ORCPT ); Fri, 12 Jul 2019 13:50:50 -0400 Date: Fri, 12 Jul 2019 10:50:40 -0700 From: "Darrick J. Wong" Subject: Re: [PATCH 1/3] mm: Handle MADV_WILLNEED through vfs_fadvise() Message-ID: <20190712175040.GY1404256@magnolia> References: <20190711140012.1671-1-jack@suse.cz> <20190711140012.1671-2-jack@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190711140012.1671-2-jack@suse.cz> Sender: linux-xfs-owner@vger.kernel.org List-ID: List-Id: xfs To: Jan Kara Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-xfs@vger.kernel.org, Amir Goldstein , Boaz Harrosh , stable@vger.kernel.org On Thu, Jul 11, 2019 at 04:00:10PM +0200, Jan Kara wrote: > Currently handling of MADV_WILLNEED hint calls directly into readahead > code. Handle it by calling vfs_fadvise() instead so that filesystem can > use its ->fadvise() callback to acquire necessary locks or otherwise > prepare for the request. > > Suggested-by: Amir Goldstein > CC: stable@vger.kernel.org # Needed by "xfs: Fix stale data exposure > when readahead races with hole punch" > Signed-off-by: Jan Kara Looks reasonable to me, though is this race between readahead and truncate severe enough to try to push it as a fix for 5.3 or are you targetting 5.4? --D > --- > mm/madvise.c | 22 ++++++++++++++++------ > 1 file changed, 16 insertions(+), 6 deletions(-) > > diff --git a/mm/madvise.c b/mm/madvise.c > index 628022e674a7..ae56d0ef337d 100644 > --- a/mm/madvise.c > +++ b/mm/madvise.c > @@ -14,6 +14,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -275,6 +276,7 @@ static long madvise_willneed(struct vm_area_struct *vma, > unsigned long start, unsigned long end) > { > struct file *file = vma->vm_file; > + loff_t offset; > > *prev = vma; > #ifdef CONFIG_SWAP > @@ -298,12 +300,20 @@ static long madvise_willneed(struct vm_area_struct *vma, > return 0; > } > > - start = ((start - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff; > - if (end > vma->vm_end) > - end = vma->vm_end; > - end = ((end - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff; > - > - force_page_cache_readahead(file->f_mapping, file, start, end - start); > + /* > + * Filesystem's fadvise may need to take various locks. We need to > + * explicitly grab a reference because the vma (and hence the > + * vma's reference to the file) can go away as soon as we drop > + * mmap_sem. > + */ > + *prev = NULL; /* tell sys_madvise we drop mmap_sem */ > + get_file(file); > + up_read(¤t->mm->mmap_sem); > + offset = (loff_t)(start - vma->vm_start) > + + ((loff_t)vma->vm_pgoff << PAGE_SHIFT); > + vfs_fadvise(file, offset, end - start, POSIX_FADV_WILLNEED); > + fput(file); > + down_read(¤t->mm->mmap_sem); > return 0; > } > > -- > 2.16.4 >