diff mbox

[13/21] mm: Pass vm_fault structure into do_page_mkwrite()

Message ID 1478233517-3571-14-git-send-email-jack@suse.cz (mailing list archive)
State Not Applicable
Headers show

Commit Message

Jan Kara Nov. 4, 2016, 4:25 a.m. UTC
We will need more information in the ->page_mkwrite() helper for DAX to
be able to fully finish faults there. Pass vm_fault structure to
do_page_mkwrite() and use it there so that information propagates
properly from upper layers.

Reviewed-by: Ross Zwisler <ross.zwisler@linux.intel.com>
Signed-off-by: Jan Kara <jack@suse.cz>
---
 mm/memory.c | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)

Comments

Kirill A. Shutemov Nov. 15, 2016, 10:40 p.m. UTC | #1
On Fri, Nov 04, 2016 at 05:25:09AM +0100, Jan Kara wrote:
> We will need more information in the ->page_mkwrite() helper for DAX to
> be able to fully finish faults there. Pass vm_fault structure to
> do_page_mkwrite() and use it there so that information propagates
> properly from upper layers.
> 
> Reviewed-by: Ross Zwisler <ross.zwisler@linux.intel.com>
> Signed-off-by: Jan Kara <jack@suse.cz>
> ---
>  mm/memory.c | 19 +++++++------------
>  1 file changed, 7 insertions(+), 12 deletions(-)
> 
> diff --git a/mm/memory.c b/mm/memory.c
> index 4da66c984c2c..c89f99c270bc 100644
> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -2038,20 +2038,14 @@ static gfp_t __get_fault_gfp_mask(struct vm_area_struct *vma)
>   *
>   * We do this without the lock held, so that it can sleep if it needs to.
>   */
> -static int do_page_mkwrite(struct vm_area_struct *vma, struct page *page,
> -	       unsigned long address)
> +static int do_page_mkwrite(struct vm_fault *vmf)
>  {
> -	struct vm_fault vmf;
>  	int ret;
> +	struct page *page = vmf->page;
>  
> -	vmf.address = address;
> -	vmf.pgoff = page->index;
> -	vmf.flags = FAULT_FLAG_WRITE|FAULT_FLAG_MKWRITE;
> -	vmf.gfp_mask = __get_fault_gfp_mask(vma);
> -	vmf.page = page;
> -	vmf.cow_page = NULL;
> +	vmf->flags = FAULT_FLAG_WRITE|FAULT_FLAG_MKWRITE;

This can be destructive: we loose rest of the flags here. It's probably
okay in current state of the code, but may be should restore them before
return from do_page_mkwrite()?
Jan Kara Nov. 16, 2016, 1:34 p.m. UTC | #2
On Wed 16-11-16 01:40:23, Kirill A. Shutemov wrote:
> On Fri, Nov 04, 2016 at 05:25:09AM +0100, Jan Kara wrote:
> > We will need more information in the ->page_mkwrite() helper for DAX to
> > be able to fully finish faults there. Pass vm_fault structure to
> > do_page_mkwrite() and use it there so that information propagates
> > properly from upper layers.
> > 
> > Reviewed-by: Ross Zwisler <ross.zwisler@linux.intel.com>
> > Signed-off-by: Jan Kara <jack@suse.cz>
> > ---
> >  mm/memory.c | 19 +++++++------------
> >  1 file changed, 7 insertions(+), 12 deletions(-)
> > 
> > diff --git a/mm/memory.c b/mm/memory.c
> > index 4da66c984c2c..c89f99c270bc 100644
> > --- a/mm/memory.c
> > +++ b/mm/memory.c
> > @@ -2038,20 +2038,14 @@ static gfp_t __get_fault_gfp_mask(struct vm_area_struct *vma)
> >   *
> >   * We do this without the lock held, so that it can sleep if it needs to.
> >   */
> > -static int do_page_mkwrite(struct vm_area_struct *vma, struct page *page,
> > -	       unsigned long address)
> > +static int do_page_mkwrite(struct vm_fault *vmf)
> >  {
> > -	struct vm_fault vmf;
> >  	int ret;
> > +	struct page *page = vmf->page;
> >  
> > -	vmf.address = address;
> > -	vmf.pgoff = page->index;
> > -	vmf.flags = FAULT_FLAG_WRITE|FAULT_FLAG_MKWRITE;
> > -	vmf.gfp_mask = __get_fault_gfp_mask(vma);
> > -	vmf.page = page;
> > -	vmf.cow_page = NULL;
> > +	vmf->flags = FAULT_FLAG_WRITE|FAULT_FLAG_MKWRITE;
> 
> This can be destructive: we loose rest of the flags here. It's probably
> okay in current state of the code, but may be should restore them before
> return from do_page_mkwrite()?

Yeah, probably makes sense as future-proofing. Changed.

								Honza
diff mbox

Patch

diff --git a/mm/memory.c b/mm/memory.c
index 4da66c984c2c..c89f99c270bc 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -2038,20 +2038,14 @@  static gfp_t __get_fault_gfp_mask(struct vm_area_struct *vma)
  *
  * We do this without the lock held, so that it can sleep if it needs to.
  */
-static int do_page_mkwrite(struct vm_area_struct *vma, struct page *page,
-	       unsigned long address)
+static int do_page_mkwrite(struct vm_fault *vmf)
 {
-	struct vm_fault vmf;
 	int ret;
+	struct page *page = vmf->page;
 
-	vmf.address = address;
-	vmf.pgoff = page->index;
-	vmf.flags = FAULT_FLAG_WRITE|FAULT_FLAG_MKWRITE;
-	vmf.gfp_mask = __get_fault_gfp_mask(vma);
-	vmf.page = page;
-	vmf.cow_page = NULL;
+	vmf->flags = FAULT_FLAG_WRITE|FAULT_FLAG_MKWRITE;
 
-	ret = vma->vm_ops->page_mkwrite(vma, &vmf);
+	ret = vmf->vma->vm_ops->page_mkwrite(vmf->vma, vmf);
 	if (unlikely(ret & (VM_FAULT_ERROR | VM_FAULT_NOPAGE)))
 		return ret;
 	if (unlikely(!(ret & VM_FAULT_LOCKED))) {
@@ -2327,7 +2321,8 @@  static int wp_page_shared(struct vm_fault *vmf, struct page *old_page)
 		int tmp;
 
 		pte_unmap_unlock(vmf->pte, vmf->ptl);
-		tmp = do_page_mkwrite(vma, old_page, vmf->address);
+		vmf->page = old_page;
+		tmp = do_page_mkwrite(vmf);
 		if (unlikely(!tmp || (tmp &
 				      (VM_FAULT_ERROR | VM_FAULT_NOPAGE)))) {
 			put_page(old_page);
@@ -3292,7 +3287,7 @@  static int do_shared_fault(struct vm_fault *vmf)
 	 */
 	if (vma->vm_ops->page_mkwrite) {
 		unlock_page(vmf->page);
-		tmp = do_page_mkwrite(vma, vmf->page, vmf->address);
+		tmp = do_page_mkwrite(vmf);
 		if (unlikely(!tmp ||
 				(tmp & (VM_FAULT_ERROR | VM_FAULT_NOPAGE)))) {
 			put_page(vmf->page);