Re: [PATCH 2/3] x86: Convert vdso to use vm_fault_t

2018-08-03 Thread Souptick Joarder
On Mon, Jul 16, 2018 at 2:47 PM, Thomas Gleixner  wrote:
> On Tue, 3 Jul 2018, Matthew Wilcox wrote:
>
>> Return vm_fault_t codes directly from the appropriate mm routines instead
>> of converting from errnos ourselves.  Fixes a minor bug where we'd return
>> SIGBUS instead of the correct OOM code if we ran out of memory allocating
>> page tables.
>>
>> Signed-off-by: Matthew Wilcox 
>
> Reviewed-by: Thomas Gleixner 
>

Thomas, are these 3 patches part of this series will be queued
for 4.19 ?


[PATCH] x86/vdso: Change return type to vm_fault_t for fault handlers

2018-06-25 Thread Souptick Joarder
Use new return type vm_fault_t for fault handler. For
now, this is just documenting that the function returns
a VM_FAULT value rather than an errno. Once all instances
are converted, vm_fault_t will become a distinct type.

Ref-> commit 1c8f422059ae ("mm: change return type to vm_fault_t")

Previously vm_insert_pfn() returns err which has to
mapped into VM_FAULT_* type. The new function
vmf_insert_pfn() will replace this inefficiency by
returning VM_FAULT_* type.

Signed-off-by: Souptick Joarder 
---
 arch/x86/entry/vdso/vma.c | 19 ---
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/arch/x86/entry/vdso/vma.c b/arch/x86/entry/vdso/vma.c
index 5b8b556..3679885 100644
--- a/arch/x86/entry/vdso/vma.c
+++ b/arch/x86/entry/vdso/vma.c
@@ -39,7 +39,7 @@ void __init init_vdso_image(const struct vdso_image *image)
 
 struct linux_binprm;
 
-static int vdso_fault(const struct vm_special_mapping *sm,
+static vm_fault_t vdso_fault(const struct vm_special_mapping *sm,
  struct vm_area_struct *vma, struct vm_fault *vmf)
 {
const struct vdso_image *image = vma->vm_mm->context.vdso_image;
@@ -84,15 +84,15 @@ static int vdso_mremap(const struct vm_special_mapping *sm,
return 0;
 }
 
-static int vvar_fault(const struct vm_special_mapping *sm,
+static vm_fault_t vvar_fault(const struct vm_special_mapping *sm,
  struct vm_area_struct *vma, struct vm_fault *vmf)
 {
const struct vdso_image *image = vma->vm_mm->context.vdso_image;
long sym_offset;
-   int ret = -EFAULT;
+   vm_fault_t ret = VM_FAULT_SIGBUS;
 
if (!image)
-   return VM_FAULT_SIGBUS;
+   return ret;
 
sym_offset = (long)(vmf->pgoff << PAGE_SHIFT) +
image->sym_vvar_start;
@@ -105,10 +105,10 @@ static int vvar_fault(const struct vm_special_mapping *sm,
 * the page past the end of the vvar mapping.
 */
if (sym_offset == 0)
-   return VM_FAULT_SIGBUS;
+   return ret;
 
if (sym_offset == image->sym_vvar_page) {
-   ret = vm_insert_pfn(vma, vmf->address,
+   ret = vmf_insert_pfn(vma, vmf->address,
__pa_symbol(&__vvar_page) >> PAGE_SHIFT);
} else if (sym_offset == image->sym_pvclock_page) {
struct pvclock_vsyscall_time_info *pvti =
@@ -124,14 +124,11 @@ static int vvar_fault(const struct vm_special_mapping *sm,
struct ms_hyperv_tsc_page *tsc_pg = hv_get_tsc_page();
 
if (tsc_pg && vclock_was_used(VCLOCK_HVCLOCK))
-   ret = vm_insert_pfn(vma, vmf->address,
+   ret = vmf_insert_pfn(vma, vmf->address,
vmalloc_to_pfn(tsc_pg));
}
 
-   if (ret == 0 || ret == -EBUSY)
-   return VM_FAULT_NOPAGE;
-
-   return VM_FAULT_SIGBUS;
+   return ret;
 }
 
 static const struct vm_special_mapping vdso_mapping = {
-- 
1.9.1



Re: [PATCH 2/3] x86: Convert vdso to use vm_fault_t

2018-08-27 Thread Souptick Joarder
On Fri, Aug 3, 2018 at 6:44 PM Thomas Gleixner  wrote:
>
> On Fri, 3 Aug 2018, Souptick Joarder wrote:
> > On Mon, Jul 16, 2018 at 2:47 PM, Thomas Gleixner  wrote:
> > > On Tue, 3 Jul 2018, Matthew Wilcox wrote:
> > >
> > >> Return vm_fault_t codes directly from the appropriate mm routines instead
> > >> of converting from errnos ourselves.  Fixes a minor bug where we'd return
> > >> SIGBUS instead of the correct OOM code if we ran out of memory allocating
> > >> page tables.
> > >>
> > >> Signed-off-by: Matthew Wilcox 
> > >
> > > Reviewed-by: Thomas Gleixner 
> > >
> >
> > Thomas, are these 3 patches part of this series will be queued
> > for 4.19 ?
>
> I don't know. I expected that these go through the mm tree, but if nobody
> feels responsible, I could pick up the whole lot. But I'd like to see acks
> from the mm folks for [1/3] and [3/3]
>
>   https://lkml.kernel.org/r/20180703123910.2180-1-wi...@infradead.org
>
> Thanks,
>
> tglx
>

Any comment from mm reviewers for patch [1/3] and [3/3] ??

https://lkml.kernel.org/r/20180703123910.2180-1-wi...@infradead.org


[PATCH] fs: iomap: Change return type to vm_fault_t

2018-08-27 Thread Souptick Joarder
Return type has been changed to vm_fault_t type for
iomap_page_mkwrite().

see commit 1c8f422059ae ("mm: change return type to
vm_fault_t") for reference.

Signed-off-by: Souptick Joarder 
Reviewed-by: Matthew Wilcox 
---
 fs/iomap.c| 2 +-
 include/linux/iomap.h | 4 +++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/fs/iomap.c b/fs/iomap.c
index afd1635..58477ee 100644
--- a/fs/iomap.c
+++ b/fs/iomap.c
@@ -443,7 +443,7 @@ static int iomap_dax_zero(loff_t pos, unsigned offset, 
unsigned bytes,
return length;
 }
 
-int iomap_page_mkwrite(struct vm_fault *vmf, const struct iomap_ops *ops)
+vm_fault_t iomap_page_mkwrite(struct vm_fault *vmf, const struct iomap_ops 
*ops)
 {
struct page *page = vmf->page;
struct inode *inode = file_inode(vmf->vma->vm_file);
diff --git a/include/linux/iomap.h b/include/linux/iomap.h
index 19a07de..666b717 100644
--- a/include/linux/iomap.h
+++ b/include/linux/iomap.h
@@ -3,6 +3,7 @@
 #define LINUX_IOMAP_H 1
 
 #include 
+#include 
 
 struct fiemap_extent_info;
 struct inode;
@@ -88,7 +89,8 @@ int iomap_zero_range(struct inode *inode, loff_t pos, loff_t 
len,
bool *did_zero, const struct iomap_ops *ops);
 int iomap_truncate_page(struct inode *inode, loff_t pos, bool *did_zero,
const struct iomap_ops *ops);
-int iomap_page_mkwrite(struct vm_fault *vmf, const struct iomap_ops *ops);
+vm_fault_t iomap_page_mkwrite(struct vm_fault *vmf,
+   const struct iomap_ops *ops);
 int iomap_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
loff_t start, loff_t len, const struct iomap_ops *ops);
 loff_t iomap_seek_hole(struct inode *inode, loff_t offset,
-- 
1.9.1



Re: [PATCH 2/3] x86: Convert vdso to use vm_fault_t

2018-08-27 Thread Souptick Joarder
On Mon, Aug 27, 2018 at 11:35 PM Matthew Wilcox  wrote:
>
> On Mon, Aug 27, 2018 at 09:01:48PM +0530, Souptick Joarder wrote:
> > On Fri, Aug 3, 2018 at 6:44 PM Thomas Gleixner  wrote:
> > >
> > > On Fri, 3 Aug 2018, Souptick Joarder wrote:
> > > > On Mon, Jul 16, 2018 at 2:47 PM, Thomas Gleixner  
> > > > wrote:
> > > > > On Tue, 3 Jul 2018, Matthew Wilcox wrote:
> > > > >
> > > > >> Return vm_fault_t codes directly from the appropriate mm routines 
> > > > >> instead
> > > > >> of converting from errnos ourselves.  Fixes a minor bug where we'd 
> > > > >> return
> > > > >> SIGBUS instead of the correct OOM code if we ran out of memory 
> > > > >> allocating
> > > > >> page tables.
> > > > >>
> > > > >> Signed-off-by: Matthew Wilcox 
> > > > >
> > > > > Reviewed-by: Thomas Gleixner 
> > > > >
> > > >
> > > > Thomas, are these 3 patches part of this series will be queued
> > > > for 4.19 ?
> > >
> > > I don't know. I expected that these go through the mm tree, but if nobody
> > > feels responsible, I could pick up the whole lot. But I'd like to see acks
> > > from the mm folks for [1/3] and [3/3]
> > >
> > >   https://lkml.kernel.org/r/20180703123910.2180-1-wi...@infradead.org
> > >
> > > Thanks,
> > >
> > > tglx
> > >
> >
> > Any comment from mm reviewers for patch [1/3] and [3/3] ??
> >
> > https://lkml.kernel.org/r/20180703123910.2180-1-wi...@infradead.org
>
> I think at this point, it would probably be best to ask Andrew to pick
> up all three of these patches.

Do we need to repost these three patches or lkml link
https://lkml.kernel.org/r/20180703123910.2180-1-wi...@infradead.org
is fine to request Andrew ??


> In addition to these three, I see the following places that need to be 
> changed:
>
> Documentation/gpu/drm-mm.rst:300:   int (*fault)(struct vm_fault 
> *vmf);
ok, I will add this.

>
> drivers/gpu/drm/virtio/virtgpu_ttm.c:117:static int 
> virtio_gpu_ttm_fault(struct vm_fault *vmf)
>  - #if 0 code.  convert anyway.

https://lkml.org/lkml/2018/7/2/795
Gerd Hoffmann, agreed to remove this dead code, but queued for 4.20.
I think, this shouldn't be a blocker for us.

>
> drivers/gpu/drm/vkms/vkms_drv.h:68:int vkms_gem_fault(struct vm_fault *vmf);
> drivers/gpu/drm/vkms/vkms_gem.c:46:int vkms_gem_fault(struct vm_fault *vmf)

This was not queued for 4.19. Would you like to see this patch in 4.19-rc-x ?
https://lkml.org/lkml/2018/7/30/767

>
> fs/ext4/ext4.h:2472:extern int ext4_page_mkwrite(struct vm_fault *vmf);
> fs/ext4/ext4.h:2473:extern int ext4_filemap_fault(struct vm_fault *vmf);
> fs/ext4/inode.c:6154:int ext4_page_mkwrite(struct vm_fault *vmf)
> fs/ext4/inode.c:6251:int ext4_filemap_fault(struct vm_fault *vmf)

I have this patch ready in my local tree based on review comment
from Ted. Ted was planning to take it in next merge window.
I will post it on mailing list.

>
> fs/iomap.c:1059:int iomap_page_mkwrite(struct vm_fault *vmf, const struct 
> iomap_ops *ops)
> include/linux/iomap.h:144:int iomap_page_mkwrite(struct vm_fault *vmf, const 
> struct iomap_ops *ops);
>  - I saw you just resent this patch.

Now added to mm-tree.

> mm/filemap.c:2751:int filemap_page_mkwrite(struct vm_fault *vmf)
>  - This is the NOMMU case, so I suspect your testing didn't catch it.
Sorry, I missed it.


[PATCH] mm: Conveted to use vm_fault_t

2018-08-28 Thread Souptick Joarder
As part of vm_fault_t conversion filemap_page_mkwrite()
for NOMMU case was missed. Now converted.

Signed-off-by: Souptick Joarder 
---
 mm/filemap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mm/filemap.c b/mm/filemap.c
index 52517f2..de6fed2 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -2748,9 +2748,9 @@ int generic_file_readonly_mmap(struct file *file, struct 
vm_area_struct *vma)
return generic_file_mmap(file, vma);
 }
 #else
-int filemap_page_mkwrite(struct vm_fault *vmf)
+vm_fault_t filemap_page_mkwrite(struct vm_fault *vmf)
 {
-   return -ENOSYS;
+   return VM_FAULT_SIGBUS;
 }
 int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
 {
-- 
1.9.1



Re: [PATCH] mm: Conveted to use vm_fault_t

2018-08-28 Thread Souptick Joarder
On Tue, Aug 28, 2018 at 11:18 PM Souptick Joarder  wrote:
>
> As part of vm_fault_t conversion filemap_page_mkwrite()
> for NOMMU case was missed. Now converted.
>
> Signed-off-by: Souptick Joarder 

cc: Matthew Wilcox 

> ---
>  mm/filemap.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/mm/filemap.c b/mm/filemap.c
> index 52517f2..de6fed2 100644
> --- a/mm/filemap.c
> +++ b/mm/filemap.c
> @@ -2748,9 +2748,9 @@ int generic_file_readonly_mmap(struct file *file, 
> struct vm_area_struct *vma)
> return generic_file_mmap(file, vma);
>  }
>  #else
> -int filemap_page_mkwrite(struct vm_fault *vmf)
> +vm_fault_t filemap_page_mkwrite(struct vm_fault *vmf)
>  {
> -   return -ENOSYS;
> +   return VM_FAULT_SIGBUS;
>  }
>  int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
>  {
> --
> 1.9.1
>


[PATCH] fs: Convert return type int to vm_fault_t

2018-08-28 Thread Souptick Joarder
Return type for fault handlers  in ext4 and nilfs are
changed to use vm_fault_t.

Return type of block_page_mkwrite() is changed from
int to vm_fault_t. The function signature of
block_page_mkwrite() is changed to add one new parameter
int *err. This will provide a way for caller functions
to get error number along with VM_FAULT return value and
use it further.

Return type of block_page_mkwrite_return() is also changed
to use new vm_fault_t type.

Signed-off-by: Souptick Joarder 
---
 fs/buffer.c | 20 +++-
 fs/ext4/ext4.h  |  4 ++--
 fs/ext4/inode.c | 34 ++
 fs/nilfs2/file.c| 16 ++--
 include/linux/buffer_head.h |  7 ---
 5 files changed, 45 insertions(+), 36 deletions(-)

diff --git a/fs/buffer.c b/fs/buffer.c
index ebf78ab..aacfc73 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -2487,21 +2487,21 @@ int block_commit_write(struct page *page, unsigned 
from, unsigned to)
  * Direct callers of this function should protect against filesystem freezing
  * using sb_start_pagefault() - sb_end_pagefault() functions.
  */
-int block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf,
-get_block_t get_block)
+vm_fault_t block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf,
+get_block_t get_block, int *err)
 {
struct page *page = vmf->page;
struct inode *inode = file_inode(vma->vm_file);
unsigned long end;
loff_t size;
-   int ret;
+   int err1;
 
lock_page(page);
size = i_size_read(inode);
if ((page->mapping != inode->i_mapping) ||
(page_offset(page) > size)) {
/* We overload EFAULT to mean page got truncated */
-   ret = -EFAULT;
+   err1 = -EFAULT;
goto out_unlock;
}
 
@@ -2511,18 +2511,20 @@ int block_page_mkwrite(struct vm_area_struct *vma, 
struct vm_fault *vmf,
else
end = PAGE_SIZE;
 
-   ret = __block_write_begin(page, 0, end, get_block);
-   if (!ret)
-   ret = block_commit_write(page, 0, end);
+   err1 = __block_write_begin(page, 0, end, get_block);
+   if (!err1)
+   err1 = block_commit_write(page, 0, end);
 
-   if (unlikely(ret < 0))
+   if (unlikely(err1 < 0))
goto out_unlock;
+   *err = err1;
set_page_dirty(page);
wait_for_stable_page(page);
return 0;
 out_unlock:
unlock_page(page);
-   return ret;
+   *err = err1;
+   return block_page_mkwrite_return(err1);
 }
 EXPORT_SYMBOL(block_page_mkwrite);
 
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 0f0edd1..8506b14 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -2469,8 +2469,8 @@ int do_journal_get_write_access(handle_t *handle,
 extern int ext4_chunk_trans_blocks(struct inode *, int nrblocks);
 extern int ext4_zero_partial_blocks(handle_t *handle, struct inode *inode,
 loff_t lstart, loff_t lend);
-extern int ext4_page_mkwrite(struct vm_fault *vmf);
-extern int ext4_filemap_fault(struct vm_fault *vmf);
+extern vm_fault_t ext4_page_mkwrite(struct vm_fault *vmf);
+extern vm_fault_t ext4_filemap_fault(struct vm_fault *vmf);
 extern qsize_t *ext4_get_reserved_space(struct inode *inode);
 extern int ext4_get_projid(struct inode *inode, kprojid_t *projid);
 extern void ext4_da_update_reserve_space(struct inode *inode,
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 82adee7..1062a8e 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -6151,39 +6151,40 @@ static int ext4_bh_unmapped(handle_t *handle, struct 
buffer_head *bh)
return !buffer_mapped(bh);
 }
 
-int ext4_page_mkwrite(struct vm_fault *vmf)
+vm_fault_t ext4_page_mkwrite(struct vm_fault *vmf)
 {
struct vm_area_struct *vma = vmf->vma;
struct page *page = vmf->page;
loff_t size;
unsigned long len;
-   int ret;
+   vm_fault_t ret;
struct file *file = vma->vm_file;
struct inode *inode = file_inode(file);
struct address_space *mapping = inode->i_mapping;
handle_t *handle;
get_block_t *get_block;
-   int retries = 0;
+   int retries = 0, err;
 
sb_start_pagefault(inode->i_sb);
file_update_time(vma->vm_file);
 
down_read(&EXT4_I(inode)->i_mmap_sem);
 
-   ret = ext4_convert_inline_data(inode);
-   if (ret)
+   err = ext4_convert_inline_data(inode);
+   if (err)
goto out_ret;
 
+   err = 0;
/* Delalloc case is easy... */
if (test_opt(inode->i_sb, DELALLOC) &&
!ext4_should_journal_data(inode) &&
!ext4_nonda_switch(inode->i_sb)) {
do {
ret = block_page_mkwrite(vma, vmf,
-   

Re: [PATCH 1/3] mm: Introduce vmf_insert_pfn_prot

2018-07-26 Thread Souptick Joarder
On Tue, Jul 3, 2018 at 6:09 PM, Matthew Wilcox  wrote:
> Like vm_insert_pfn_prot(), but returns a vm_fault_t instead of an errno.
> Also unexport vm_insert_pfn_prot as it has no modular users.
>
> Signed-off-by: Matthew Wilcox 
> ---

Any comment on this patch ?

>  include/linux/mm.h |  2 ++
>  mm/memory.c| 47 ++
>  2 files changed, 33 insertions(+), 16 deletions(-)
>
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index 1a9d6bd97f00..3cb763a38642 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -2441,6 +2441,8 @@ int vm_insert_pfn(struct vm_area_struct *vma, unsigned 
> long addr,
> unsigned long pfn);
>  int vm_insert_pfn_prot(struct vm_area_struct *vma, unsigned long addr,
> unsigned long pfn, pgprot_t pgprot);
> +vm_fault_t vmf_insert_pfn_prot(struct vm_area_struct *vma, unsigned long 
> addr,
> +   unsigned long pfn, pgprot_t pgprot);
>  int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
> pfn_t pfn);
>  vm_fault_t vmf_insert_mixed_mkwrite(struct vm_area_struct *vma,
> diff --git a/mm/memory.c b/mm/memory.c
> index b9ebd883e27c..caecb4d995ac 100644
> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -1852,21 +1852,6 @@ int vm_insert_pfn(struct vm_area_struct *vma, unsigned 
> long addr,
>  }
>  EXPORT_SYMBOL(vm_insert_pfn);
>
> -/**
> - * vm_insert_pfn_prot - insert single pfn into user vma with specified pgprot
> - * @vma: user vma to map to
> - * @addr: target user address of this page
> - * @pfn: source kernel pfn
> - * @pgprot: pgprot flags for the inserted page
> - *
> - * This is exactly like vm_insert_pfn, except that it allows drivers to
> - * to override pgprot on a per-page basis.
> - *
> - * This only makes sense for IO mappings, and it makes no sense for
> - * cow mappings.  In general, using multiple vmas is preferable;
> - * vm_insert_pfn_prot should only be used if using multiple VMAs is
> - * impractical.
> - */
>  int vm_insert_pfn_prot(struct vm_area_struct *vma, unsigned long addr,
> unsigned long pfn, pgprot_t pgprot)
>  {
> @@ -1893,7 +1878,37 @@ int vm_insert_pfn_prot(struct vm_area_struct *vma, 
> unsigned long addr,
>
> return ret;
>  }
> -EXPORT_SYMBOL(vm_insert_pfn_prot);
> +
> +/**
> + * vmf_insert_pfn_prot - insert single pfn into user vma with specified 
> pgprot
> + * @vma: user vma to map to
> + * @addr: target user address of this page
> + * @pfn: source kernel pfn
> + * @pgprot: pgprot flags for the inserted page
> + *
> + * This is exactly like vmf_insert_pfn(), except that it allows drivers to
> + * to override pgprot on a per-page basis.
> + *
> + * This only makes sense for IO mappings, and it makes no sense for
> + * COW mappings.  In general, using multiple vmas is preferable;
> + * vm_insert_pfn_prot should only be used if using multiple VMAs is
> + * impractical.
> + *
> + * Return: vm_fault_t value.
> + */
> +vm_fault_t vmf_insert_pfn_prot(struct vm_area_struct *vma, unsigned long 
> addr,
> +   unsigned long pfn, pgprot_t pgprot)
> +{
> +   int err = vm_insert_pfn_prot(vma, addr, pfn, pgprot);
> +
> +   if (err == -ENOMEM)
> +   return VM_FAULT_OOM;
> +   if (err < 0 && err != -EBUSY)
> +   return VM_FAULT_SIGBUS;
> +
> +   return VM_FAULT_NOPAGE;
> +}
> +EXPORT_SYMBOL(vmf_insert_pfn_prot);
>
>  static bool vm_mixed_ok(struct vm_area_struct *vma, pfn_t pfn)
>  {
> --
> 2.18.0
>


Re: [PATCH 3/3] mm: Make vm_insert_pfn_prot static

2018-07-26 Thread Souptick Joarder
On Tue, Jul 3, 2018 at 6:09 PM, Matthew Wilcox  wrote:
> Now this is no longer used outside mm/memory.c, make it static.
>
> Signed-off-by: Matthew Wilcox 
> ---

Any comment on this patch ?

>  include/linux/mm.h |  2 --
>  mm/memory.c| 50 +++---
>  2 files changed, 25 insertions(+), 27 deletions(-)
>
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index 3cb763a38642..703a9962103e 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -2439,8 +2439,6 @@ int remap_pfn_range(struct vm_area_struct *, unsigned 
> long addr,
>  int vm_insert_page(struct vm_area_struct *, unsigned long addr, struct page 
> *);
>  int vm_insert_pfn(struct vm_area_struct *vma, unsigned long addr,
> unsigned long pfn);
> -int vm_insert_pfn_prot(struct vm_area_struct *vma, unsigned long addr,
> -   unsigned long pfn, pgprot_t pgprot);
>  vm_fault_t vmf_insert_pfn_prot(struct vm_area_struct *vma, unsigned long 
> addr,
> unsigned long pfn, pgprot_t pgprot);
>  int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
> diff --git a/mm/memory.c b/mm/memory.c
> index caecb4d995ac..73c5682310c7 100644
> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -1828,31 +1828,7 @@ static int insert_pfn(struct vm_area_struct *vma, 
> unsigned long addr,
> return retval;
>  }
>
> -/**
> - * vm_insert_pfn - insert single pfn into user vma
> - * @vma: user vma to map to
> - * @addr: target user address of this page
> - * @pfn: source kernel pfn
> - *
> - * Similar to vm_insert_page, this allows drivers to insert individual pages
> - * they've allocated into a user vma. Same comments apply.
> - *
> - * This function should only be called from a vm_ops->fault handler, and
> - * in that case the handler should return NULL.
> - *
> - * vma cannot be a COW mapping.
> - *
> - * As this is called only for pages that do not currently exist, we
> - * do not need to flush old virtual caches or the TLB.
> - */
> -int vm_insert_pfn(struct vm_area_struct *vma, unsigned long addr,
> -   unsigned long pfn)
> -{
> -   return vm_insert_pfn_prot(vma, addr, pfn, vma->vm_page_prot);
> -}
> -EXPORT_SYMBOL(vm_insert_pfn);
> -
> -int vm_insert_pfn_prot(struct vm_area_struct *vma, unsigned long addr,
> +static int vm_insert_pfn_prot(struct vm_area_struct *vma, unsigned long addr,
> unsigned long pfn, pgprot_t pgprot)
>  {
> int ret;
> @@ -1879,6 +1855,30 @@ int vm_insert_pfn_prot(struct vm_area_struct *vma, 
> unsigned long addr,
> return ret;
>  }
>
> +/**
> + * vm_insert_pfn - insert single pfn into user vma
> + * @vma: user vma to map to
> + * @addr: target user address of this page
> + * @pfn: source kernel pfn
> + *
> + * Similar to vm_insert_page, this allows drivers to insert individual pages
> + * they've allocated into a user vma. Same comments apply.
> + *
> + * This function should only be called from a vm_ops->fault handler, and
> + * in that case the handler should return NULL.
> + *
> + * vma cannot be a COW mapping.
> + *
> + * As this is called only for pages that do not currently exist, we
> + * do not need to flush old virtual caches or the TLB.
> + */
> +int vm_insert_pfn(struct vm_area_struct *vma, unsigned long addr,
> +   unsigned long pfn)
> +{
> +   return vm_insert_pfn_prot(vma, addr, pfn, vma->vm_page_prot);
> +}
> +EXPORT_SYMBOL(vm_insert_pfn);
> +
>  /**
>   * vmf_insert_pfn_prot - insert single pfn into user vma with specified 
> pgprot
>   * @vma: user vma to map to
> --
> 2.18.0
>


[PATCH] ext4: Convert int to vm_fault_t type

2018-07-28 Thread Souptick Joarder
Use new return type vm_fault_t for ext4_page_mkwrite
handler and block_page_mkwrite_return.

Signed-off-by: Souptick Joarder 
---
 fs/ext4/ext4.h  |  2 +-
 fs/ext4/inode.c | 20 ++--
 include/linux/buffer_head.h |  3 ++-
 3 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index aec0010..1183773 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -2469,7 +2469,7 @@ int do_journal_get_write_access(handle_t *handle,
 extern int ext4_chunk_trans_blocks(struct inode *, int nrblocks);
 extern int ext4_zero_partial_blocks(handle_t *handle, struct inode *inode,
 loff_t lstart, loff_t lend);
-extern int ext4_page_mkwrite(struct vm_fault *vmf);
+extern vm_fault_t ext4_page_mkwrite(struct vm_fault *vmf);
 extern vm_fault_t ext4_filemap_fault(struct vm_fault *vmf);
 extern qsize_t *ext4_get_reserved_space(struct inode *inode);
 extern int ext4_get_projid(struct inode *inode, kprojid_t *projid);
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 03ac322..b491fdb 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -6108,27 +6108,27 @@ static int ext4_bh_unmapped(handle_t *handle, struct 
buffer_head *bh)
return !buffer_mapped(bh);
 }
 
-int ext4_page_mkwrite(struct vm_fault *vmf)
+vm_fault_t ext4_page_mkwrite(struct vm_fault *vmf)
 {
struct vm_area_struct *vma = vmf->vma;
struct page *page = vmf->page;
loff_t size;
unsigned long len;
-   int ret;
+   vm_fault_t ret;
struct file *file = vma->vm_file;
struct inode *inode = file_inode(file);
struct address_space *mapping = inode->i_mapping;
handle_t *handle;
get_block_t *get_block;
-   int retries = 0;
+   int retries = 0, err;
 
sb_start_pagefault(inode->i_sb);
file_update_time(vma->vm_file);
 
down_read(&EXT4_I(inode)->i_mmap_sem);
 
-   ret = ext4_convert_inline_data(inode);
-   if (ret)
+   err = ext4_convert_inline_data(inode);
+   if (err)
goto out_ret;
 
/* Delalloc case is easy... */
@@ -6138,9 +6138,9 @@ int ext4_page_mkwrite(struct vm_fault *vmf)
do {
ret = block_page_mkwrite(vma, vmf,
   ext4_da_get_block_prep);
-   } while (ret == -ENOSPC &&
+   } while (ret == VM_FAULT_SIGBUS &&
   ext4_should_retry_alloc(inode->i_sb, &retries));
-   goto out_ret;
+   goto out;
}
 
lock_page(page);
@@ -6188,17 +6188,17 @@ int ext4_page_mkwrite(struct vm_fault *vmf)
if (ext4_walk_page_buffers(handle, page_buffers(page), 0,
  PAGE_SIZE, NULL, do_journal_get_write_access)) {
unlock_page(page);
-   ret = VM_FAULT_SIGBUS;
ext4_journal_stop(handle);
goto out;
}
ext4_set_inode_state(inode, EXT4_STATE_JDATA);
}
ext4_journal_stop(handle);
-   if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries))
+   if (ret == VM_FAULT_SIGBUS &&
+   ext4_should_retry_alloc(inode->i_sb, &retries))
goto retry_alloc;
 out_ret:
-   ret = block_page_mkwrite_return(ret);
+   ret = block_page_mkwrite_return(err);
 out:
up_read(&EXT4_I(inode)->i_mmap_sem);
sb_end_pagefault(inode->i_sb);
diff --git a/include/linux/buffer_head.h b/include/linux/buffer_head.h
index 96225a7..ed7a81b 100644
--- a/include/linux/buffer_head.h
+++ b/include/linux/buffer_head.h
@@ -14,6 +14,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #ifdef CONFIG_BLOCK
 
@@ -242,7 +243,7 @@ int cont_write_begin(struct file *, struct address_space *, 
loff_t,
 int block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf,
get_block_t get_block);
 /* Convert errno to return value from ->page_mkwrite() call */
-static inline int block_page_mkwrite_return(int err)
+static inline vm_fault_t block_page_mkwrite_return(int err)
 {
if (err == 0)
return VM_FAULT_LOCKED;
-- 
1.9.1



Re: [PATCH] ext4: Convert int to vm_fault_t type

2018-07-28 Thread Souptick Joarder
On Sat, Jul 28, 2018 at 2:20 PM, Souptick Joarder  wrote:
> Use new return type vm_fault_t for ext4_page_mkwrite
> handler and block_page_mkwrite_return.
>
> Signed-off-by: Souptick Joarder 

As part of commit 2fae376c0a16db42eb438 in linux-next tree,
this conversion was missed. Sorry about it.

> ---
>  fs/ext4/ext4.h  |  2 +-
>  fs/ext4/inode.c | 20 ++--
>  include/linux/buffer_head.h |  3 ++-
>  3 files changed, 13 insertions(+), 12 deletions(-)
>
> diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
> index aec0010..1183773 100644
> --- a/fs/ext4/ext4.h
> +++ b/fs/ext4/ext4.h
> @@ -2469,7 +2469,7 @@ int do_journal_get_write_access(handle_t *handle,
>  extern int ext4_chunk_trans_blocks(struct inode *, int nrblocks);
>  extern int ext4_zero_partial_blocks(handle_t *handle, struct inode *inode,
>  loff_t lstart, loff_t lend);
> -extern int ext4_page_mkwrite(struct vm_fault *vmf);
> +extern vm_fault_t ext4_page_mkwrite(struct vm_fault *vmf);
>  extern vm_fault_t ext4_filemap_fault(struct vm_fault *vmf);
>  extern qsize_t *ext4_get_reserved_space(struct inode *inode);
>  extern int ext4_get_projid(struct inode *inode, kprojid_t *projid);
> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index 03ac322..b491fdb 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -6108,27 +6108,27 @@ static int ext4_bh_unmapped(handle_t *handle, struct 
> buffer_head *bh)
> return !buffer_mapped(bh);
>  }
>
> -int ext4_page_mkwrite(struct vm_fault *vmf)
> +vm_fault_t ext4_page_mkwrite(struct vm_fault *vmf)
>  {
> struct vm_area_struct *vma = vmf->vma;
> struct page *page = vmf->page;
> loff_t size;
> unsigned long len;
> -   int ret;
> +   vm_fault_t ret;
> struct file *file = vma->vm_file;
> struct inode *inode = file_inode(file);
> struct address_space *mapping = inode->i_mapping;
> handle_t *handle;
> get_block_t *get_block;
> -   int retries = 0;
> +   int retries = 0, err;
>
> sb_start_pagefault(inode->i_sb);
> file_update_time(vma->vm_file);
>
> down_read(&EXT4_I(inode)->i_mmap_sem);
>
> -   ret = ext4_convert_inline_data(inode);
> -   if (ret)
> +   err = ext4_convert_inline_data(inode);
> +   if (err)
> goto out_ret;
>
> /* Delalloc case is easy... */
> @@ -6138,9 +6138,9 @@ int ext4_page_mkwrite(struct vm_fault *vmf)
> do {
> ret = block_page_mkwrite(vma, vmf,
>ext4_da_get_block_prep);
> -   } while (ret == -ENOSPC &&
> +   } while (ret == VM_FAULT_SIGBUS &&
>ext4_should_retry_alloc(inode->i_sb, &retries));
> -   goto out_ret;
> +   goto out;
> }
>
> lock_page(page);
> @@ -6188,17 +6188,17 @@ int ext4_page_mkwrite(struct vm_fault *vmf)
> if (ext4_walk_page_buffers(handle, page_buffers(page), 0,
>   PAGE_SIZE, NULL, do_journal_get_write_access)) {
> unlock_page(page);
> -   ret = VM_FAULT_SIGBUS;
> ext4_journal_stop(handle);
> goto out;
> }
> ext4_set_inode_state(inode, EXT4_STATE_JDATA);
> }
> ext4_journal_stop(handle);
> -   if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries))
> +   if (ret == VM_FAULT_SIGBUS &&
> +   ext4_should_retry_alloc(inode->i_sb, &retries))
> goto retry_alloc;
>  out_ret:
> -   ret = block_page_mkwrite_return(ret);
> +   ret = block_page_mkwrite_return(err);
>  out:
> up_read(&EXT4_I(inode)->i_mmap_sem);
> sb_end_pagefault(inode->i_sb);
> diff --git a/include/linux/buffer_head.h b/include/linux/buffer_head.h
> index 96225a7..ed7a81b 100644
> --- a/include/linux/buffer_head.h
> +++ b/include/linux/buffer_head.h
> @@ -14,6 +14,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>
>  #ifdef CONFIG_BLOCK
>
> @@ -242,7 +243,7 @@ int cont_write_begin(struct file *, struct address_space 
> *, loff_t,
>  int block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf,
> get_block_t get_block);
>  /* Convert errno to return value from ->page_mkwrite() call */
> -static inline int block_page_mkwrite_return(int err)
> +static inline vm_fault_t block_page_mkwrite_return(int err)
>  {
> if (err == 0)
> return VM_FAULT_LOCKED;
> --
> 1.9.1
>


[PATCH] fs/buffer: Convert return type int to vm_fault_t

2018-07-28 Thread Souptick Joarder
Return type of block_page_mkwrite() is converted to
vm_fault_t type. The caller of block_page_mkwrite
inside fs/nilfs2 nilfs_page_mkwrite converted accordingly.

Signed-off-by: Souptick Joarder 
---
 fs/buffer.c | 16 +---
 fs/nilfs2/file.c| 13 -
 include/linux/buffer_head.h |  2 +-
 3 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/fs/buffer.c b/fs/buffer.c
index be31e28..463aa27 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -2456,21 +2456,22 @@ int block_commit_write(struct page *page, unsigned 
from, unsigned to)
  * Direct callers of this function should protect against filesystem freezing
  * using sb_start_pagefault() - sb_end_pagefault() functions.
  */
-int block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf,
+vm_fault_t block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf,
 get_block_t get_block)
 {
struct page *page = vmf->page;
struct inode *inode = file_inode(vma->vm_file);
unsigned long end;
+   vm_fault_t ret;
loff_t size;
-   int ret;
+   int err;
 
lock_page(page);
size = i_size_read(inode);
if ((page->mapping != inode->i_mapping) ||
(page_offset(page) > size)) {
/* We overload EFAULT to mean page got truncated */
-   ret = -EFAULT;
+   err = -EFAULT;
goto out_unlock;
}
 
@@ -2480,17 +2481,18 @@ int block_page_mkwrite(struct vm_area_struct *vma, 
struct vm_fault *vmf,
else
end = PAGE_SIZE;
 
-   ret = __block_write_begin(page, 0, end, get_block);
-   if (!ret)
-   ret = block_commit_write(page, 0, end);
+   err = __block_write_begin(page, 0, end, get_block);
+   if (!err)
+   err = block_commit_write(page, 0, end);
 
-   if (unlikely(ret < 0))
+   if (unlikely(err < 0))
goto out_unlock;
set_page_dirty(page);
wait_for_stable_page(page);
return 0;
 out_unlock:
unlock_page(page);
+   ret = block_page_mkwrite_return(err);
return ret;
 }
 EXPORT_SYMBOL(block_page_mkwrite);
diff --git a/fs/nilfs2/file.c b/fs/nilfs2/file.c
index 7da0fac..3733883 100644
--- a/fs/nilfs2/file.c
+++ b/fs/nilfs2/file.c
@@ -57,7 +57,8 @@ static vm_fault_t nilfs_page_mkwrite(struct vm_fault *vmf)
struct page *page = vmf->page;
struct inode *inode = file_inode(vma->vm_file);
struct nilfs_transaction_info ti;
-   int ret = 0;
+   vm_fault_t ret = VM_FAULT_LOCKED;
+   int err = 0;
 
if (unlikely(nilfs_near_disk_full(inode->i_sb->s_fs_info)))
return VM_FAULT_SIGBUS; /* -ENOSPC */
@@ -67,7 +68,7 @@ static vm_fault_t nilfs_page_mkwrite(struct vm_fault *vmf)
if (page->mapping != inode->i_mapping ||
page_offset(page) >= i_size_read(inode) || !PageUptodate(page)) {
unlock_page(page);
-   ret = -EFAULT;  /* make the VM retry the fault */
+   ret = VM_FAULT_NOPAGE;  /* make the VM retry the fault */
goto out;
}
 
@@ -99,10 +100,12 @@ static vm_fault_t nilfs_page_mkwrite(struct vm_fault *vmf)
/*
 * fill hole blocks
 */
-   ret = nilfs_transaction_begin(inode->i_sb, &ti, 1);
+   err = nilfs_transaction_begin(inode->i_sb, &ti, 1);
/* never returns -ENOMEM, but may return -ENOSPC */
-   if (unlikely(ret))
+   if (unlikely(err)) {
+   ret = block_page_mkwrite_return(err);
goto out;
+   }
 
file_update_time(vma->vm_file);
ret = block_page_mkwrite(vma, vmf, nilfs_get_block);
@@ -117,7 +120,7 @@ static vm_fault_t nilfs_page_mkwrite(struct vm_fault *vmf)
wait_for_stable_page(page);
  out:
sb_end_pagefault(inode->i_sb);
-   return block_page_mkwrite_return(ret);
+   return ret;
 }
 
 static const struct vm_operations_struct nilfs_file_vm_ops = {
diff --git a/include/linux/buffer_head.h b/include/linux/buffer_head.h
index 96225a7..1aeeb54 100644
--- a/include/linux/buffer_head.h
+++ b/include/linux/buffer_head.h
@@ -239,7 +239,7 @@ int cont_write_begin(struct file *, struct address_space *, 
loff_t,
get_block_t *, loff_t *);
 int generic_cont_expand_simple(struct inode *inode, loff_t size);
 int block_commit_write(struct page *page, unsigned from, unsigned to);
-int block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf,
+vm_fault_t block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf,
get_block_t get_block);
 /* Convert errno to return value from ->page_mkwrite() call */
 static inline int block_page_mkwrite_return(int err)
-- 
1.9.1



Re: [PATCH] fs/buffer: Convert return type int to vm_fault_t

2018-07-29 Thread Souptick Joarder
On Sat, Jul 28, 2018 at 8:34 PM, Jens Axboe  wrote:
> On 7/28/18 3:50 AM, Souptick Joarder wrote:
>>  out_unlock:
>>   unlock_page(page);
>> + ret = block_page_mkwrite_return(err);
>>   return ret;
>
> return block_page_mkwrite_return(err);
>
> --
> Jens Axboe
>

OK, I will post v2.


[PATCH v2] fs/buffer: Convert return type int to vm_fault_t

2018-07-30 Thread Souptick Joarder
Return type of block_page_mkwrite() is converted to
vm_fault_t type. The caller of block_page_mkwrite
inside fs/nilfs2 nilfs_page_mkwrite converted accordingly.

Signed-off-by: Souptick Joarder 
---
v2: Address Jens's comment. Remove ret variable
from block_page_mkwrite().

 fs/buffer.c | 16 
 fs/nilfs2/file.c| 13 -
 include/linux/buffer_head.h |  2 +-
 3 files changed, 17 insertions(+), 14 deletions(-)

diff --git a/fs/buffer.c b/fs/buffer.c
index cabc045..aeed99f 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -2444,21 +2444,21 @@ int block_commit_write(struct page *page, unsigned 
from, unsigned to)
  * Direct callers of this function should protect against filesystem freezing
  * using sb_start_pagefault() - sb_end_pagefault() functions.
  */
-int block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf,
+vm_fault_t block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf,
 get_block_t get_block)
 {
struct page *page = vmf->page;
struct inode *inode = file_inode(vma->vm_file);
unsigned long end;
loff_t size;
-   int ret;
+   int err;
 
lock_page(page);
size = i_size_read(inode);
if ((page->mapping != inode->i_mapping) ||
(page_offset(page) > size)) {
/* We overload EFAULT to mean page got truncated */
-   ret = -EFAULT;
+   err = -EFAULT;
goto out_unlock;
}
 
@@ -2468,18 +2468,18 @@ int block_page_mkwrite(struct vm_area_struct *vma, 
struct vm_fault *vmf,
else
end = PAGE_SIZE;
 
-   ret = __block_write_begin(page, 0, end, get_block);
-   if (!ret)
-   ret = block_commit_write(page, 0, end);
+   err = __block_write_begin(page, 0, end, get_block);
+   if (!err)
+   err = block_commit_write(page, 0, end);
 
-   if (unlikely(ret < 0))
+   if (unlikely(err < 0))
goto out_unlock;
set_page_dirty(page);
wait_for_stable_page(page);
return 0;
 out_unlock:
unlock_page(page);
-   return ret;
+   return block_page_mkwrite_return(err);
 }
 EXPORT_SYMBOL(block_page_mkwrite);
 
diff --git a/fs/nilfs2/file.c b/fs/nilfs2/file.c
index c5fa3de..da2759e 100644
--- a/fs/nilfs2/file.c
+++ b/fs/nilfs2/file.c
@@ -57,7 +57,8 @@ static int nilfs_page_mkwrite(struct vm_fault *vmf)
struct page *page = vmf->page;
struct inode *inode = file_inode(vma->vm_file);
struct nilfs_transaction_info ti;
-   int ret = 0;
+   vm_fault_t ret = VM_FAULT_LOCKED;
+   int err = 0;
 
if (unlikely(nilfs_near_disk_full(inode->i_sb->s_fs_info)))
return VM_FAULT_SIGBUS; /* -ENOSPC */
@@ -67,7 +68,7 @@ static int nilfs_page_mkwrite(struct vm_fault *vmf)
if (page->mapping != inode->i_mapping ||
page_offset(page) >= i_size_read(inode) || !PageUptodate(page)) {
unlock_page(page);
-   ret = -EFAULT;  /* make the VM retry the fault */
+   ret = VM_FAULT_NOPAGE;  /* make the VM retry the fault */
goto out;
}
 
@@ -99,10 +100,12 @@ static int nilfs_page_mkwrite(struct vm_fault *vmf)
/*
 * fill hole blocks
 */
-   ret = nilfs_transaction_begin(inode->i_sb, &ti, 1);
+   err = nilfs_transaction_begin(inode->i_sb, &ti, 1);
/* never returns -ENOMEM, but may return -ENOSPC */
-   if (unlikely(ret))
+   if (unlikely(err)) {
+   ret = block_page_mkwrite_return(err);
goto out;
+   }
 
file_update_time(vma->vm_file);
ret = block_page_mkwrite(vma, vmf, nilfs_get_block);
@@ -117,7 +120,7 @@ static int nilfs_page_mkwrite(struct vm_fault *vmf)
wait_for_stable_page(page);
  out:
sb_end_pagefault(inode->i_sb);
-   return block_page_mkwrite_return(ret);
+   return ret;
 }
 
 static const struct vm_operations_struct nilfs_file_vm_ops = {
diff --git a/include/linux/buffer_head.h b/include/linux/buffer_head.h
index ed7a81b..7184c6e 100644
--- a/include/linux/buffer_head.h
+++ b/include/linux/buffer_head.h
@@ -240,7 +240,7 @@ int cont_write_begin(struct file *, struct address_space *, 
loff_t,
get_block_t *, loff_t *);
 int generic_cont_expand_simple(struct inode *inode, loff_t size);
 int block_commit_write(struct page *page, unsigned from, unsigned to);
-int block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf,
+vm_fault_t block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf,
get_block_t get_block);
 /* Convert errno to return value from ->page_mkwrite() call */
 static inline vm_fault_t block_page_mkwrite_return(int err)
-- 
1.9.1



[PATCH] gpu/drm/hisilicon: Convert drm_atomic_helper_suspend/resume()

2018-07-19 Thread Souptick Joarder
convert drm_atomic_helper_suspend/resume() to use
drm_mode_config_helper_suspend/resume().

Fixed one sparse warning by making hibmc_drm_interrupt
static.

Signed-off-by: Souptick Joarder 
Signed-off-by: Ajit Negi 
---
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c | 24 
 1 file changed, 8 insertions(+), 16 deletions(-)

diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c 
b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
index d4f6f1f..2261676 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
@@ -37,7 +37,7 @@
.llseek = no_llseek,
 };
 
-irqreturn_t hibmc_drm_interrupt(int irq, void *arg)
+static irqreturn_t hibmc_drm_interrupt(int irq, void *arg)
 {
struct drm_device *dev = (struct drm_device *)arg;
struct hibmc_drm_private *priv =
@@ -74,30 +74,22 @@ static int __maybe_unused hibmc_pm_suspend(struct device 
*dev)
 {
struct pci_dev *pdev = to_pci_dev(dev);
struct drm_device *drm_dev = pci_get_drvdata(pdev);
-   struct hibmc_drm_private *priv = drm_dev->dev_private;
-
-   drm_kms_helper_poll_disable(drm_dev);
-   priv->suspend_state = drm_atomic_helper_suspend(drm_dev);
-   if (IS_ERR(priv->suspend_state)) {
-   DRM_ERROR("drm_atomic_helper_suspend failed: %ld\n",
- PTR_ERR(priv->suspend_state));
-   drm_kms_helper_poll_enable(drm_dev);
-   return PTR_ERR(priv->suspend_state);
-   }
+   int ret = 0;
 
-   return 0;
+   ret = drm_mode_config_helper_suspend(drm_dev);
+
+   return ret;
 }
 
 static int  __maybe_unused hibmc_pm_resume(struct device *dev)
 {
struct pci_dev *pdev = to_pci_dev(dev);
struct drm_device *drm_dev = pci_get_drvdata(pdev);
-   struct hibmc_drm_private *priv = drm_dev->dev_private;
+   int ret = 0;
 
-   drm_atomic_helper_resume(drm_dev, priv->suspend_state);
-   drm_kms_helper_poll_enable(drm_dev);
+   ret = drm_mode_config_helper_resume(drm_dev);
 
-   return 0;
+   return ret;
 }
 
 static const struct dev_pm_ops hibmc_pm_ops = {
-- 
1.9.1



Re: [PATCH] fs: iomap: Change return type to vm_fault_t

2018-07-19 Thread Souptick Joarder
On Wed, Jul 4, 2018 at 3:22 AM, Andreas Gruenbacher  wrote:
> On 3 July 2018 at 23:39, Darrick J. Wong  wrote:
>> On Mon, Jul 02, 2018 at 07:52:41PM +0200, Andreas Gruenbacher wrote:
>>> On 2 July 2018 at 17:43, Souptick Joarder  wrote:
>>> > Return type has been changed to vm_fault_t type for
>>> > iomap_page_mkwrite().
>>> >
>>> > see commit 1c8f422059ae ("mm: change return type to
>>> > vm_fault_t") for reference.
>>> >
>>> > Signed-off-by: Souptick Joarder 
>>> > Reviewed-by: Matthew Wilcox 
>>
>> I don't recall Christoph [now cc'd] rescinding his NAK of the previous
>> version of this patch[1].  Has he changed his mind since May?
>
> Oops, a reply gone wrong -- I was meaning to reply to Souptick
> Joarder's gfs2 change which I've added to the gfs2 for-next branch.
> Not the iomap change. Sorry for the confusion.
>
>> [1] https://spinics.net/lists/linux-fsdevel/msg126032.html
>>
>> Now granted I didn't have a problem with the code (and applied the xfs
>> version to 4.18 after monitoring to satisfy myself that nothing
>> particularly weird happened during 4.17) but seeing as most of the iomap
>> changes have gone through hch's review and landed via the xfs tree...

Darrick, is this patch going to 4.19 through xfs tree ?


Re: [PATCH] fs: iomap: Change return type to vm_fault_t

2018-07-19 Thread Souptick Joarder
On Fri, Jul 20, 2018 at 11:39 AM, Darrick J. Wong
 wrote:
> On Fri, Jul 20, 2018 at 10:31:30AM +0530, Souptick Joarder wrote:
>> On Wed, Jul 4, 2018 at 3:22 AM, Andreas Gruenbacher  
>> wrote:
>> > On 3 July 2018 at 23:39, Darrick J. Wong  wrote:
>> >> On Mon, Jul 02, 2018 at 07:52:41PM +0200, Andreas Gruenbacher wrote:
>> >>> On 2 July 2018 at 17:43, Souptick Joarder  wrote:
>> >>> > Return type has been changed to vm_fault_t type for
>> >>> > iomap_page_mkwrite().
>> >>> >
>> >>> > see commit 1c8f422059ae ("mm: change return type to
>> >>> > vm_fault_t") for reference.
>> >>> >
>> >>> > Signed-off-by: Souptick Joarder 
>> >>> > Reviewed-by: Matthew Wilcox 
>> >>
>> >> I don't recall Christoph [now cc'd] rescinding his NAK of the previous
>> >> version of this patch[1].  Has he changed his mind since May?
>> >  /|\
>> > Oops, a reply gone wrong -- I was me  |   to reply to Souptick
>> > Joarder's gfs2 change which I've add  |   the gfs2 for-next branch.
>> > Not the iomap change. Sorry for the   |  sion.
>> >   |
>> >> [1] https://spinics.net/lists/linux  |  vel/msg126032.html
>> >>  |
>> >> Now granted I didn't have a problem  |   the code (and applied the xfs
>> >> version to 4.18 after monitoring to  |  sfy myself that nothing
>> >> particularly weird happened during   |   but seeing as most of the iomap
>> >> changes have gone through hch's rev  |  nd landed via the xfs tree...
>   |
> --D   |
>   |
> I wasn't planning on it, due to aforementioned NAK still being in place
> to the best of my knowledge, at least for the iomap patch.
>
>> Darrick, is this patch going to 4.19 through xfs tree ?

Well,  the original patch was NAK by Christoph because he wanted
to see the complete vm_fault_t migration picture in a patch series
where Matthew mentioned to send one patch per driver through
different maintainers tree to upstream the changes. This discussion
went on into two separate mail threads.

At this point we are almost done with vm_fault_t migration in all drivers/fs
except 3 patches and all the changes will be available in 4.19-rc1. We followed
one patch per driver mechanism and I believe we not are going to adopt other
mechanism (patch series) to upstream these vm_fault_t patches.

This particular patch is struggling for more than 3 months now.

Christoph, would you still like to maintain NAK on this patch ? :-)


[PATCH] fs: ceph: Adding new return type vm_fault_t

2018-07-22 Thread Souptick Joarder
Use new return type vm_fault_t for page_mkwrite
and fault handler.

vmf_error() is the newly introduce inline function
in 4.17

Signed-off-by: Souptick Joarder 
Reviewed-by: Matthew Wilcox 
---
 fs/ceph/addr.c | 62 ++
 1 file changed, 32 insertions(+), 30 deletions(-)

diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c
index b4336b4..3031d44 100644
--- a/fs/ceph/addr.c
+++ b/fs/ceph/addr.c
@@ -1427,7 +1427,7 @@ static void ceph_restore_sigs(sigset_t *oldset)
 /*
  * vm ops
  */
-static int ceph_filemap_fault(struct vm_fault *vmf)
+static vm_fault_t ceph_filemap_fault(struct vm_fault *vmf)
 {
struct vm_area_struct *vma = vmf->vma;
struct inode *inode = file_inode(vma->vm_file);
@@ -1435,8 +1435,9 @@ static int ceph_filemap_fault(struct vm_fault *vmf)
struct ceph_file_info *fi = vma->vm_file->private_data;
struct page *pinned_page = NULL;
loff_t off = vmf->pgoff << PAGE_SHIFT;
-   int want, got, ret;
+   int want, got, err;
sigset_t oldset;
+   vm_fault_t ret;
 
ceph_block_sigs(&oldset);
 
@@ -1448,8 +1449,8 @@ static int ceph_filemap_fault(struct vm_fault *vmf)
want = CEPH_CAP_FILE_CACHE;
 
got = 0;
-   ret = ceph_get_caps(ci, CEPH_CAP_FILE_RD, want, -1, &got, &pinned_page);
-   if (ret < 0)
+   err = ceph_get_caps(ci, CEPH_CAP_FILE_RD, want, -1, &got, &pinned_page);
+   if (err < 0)
goto out_restore;
 
dout("filemap_fault %p %llu~%zd got cap refs on %s\n",
@@ -1461,16 +1462,17 @@ static int ceph_filemap_fault(struct vm_fault *vmf)
ceph_add_rw_context(fi, &rw_ctx);
ret = filemap_fault(vmf);
ceph_del_rw_context(fi, &rw_ctx);
+   dout("filemap_fault %p %llu~%zd drop cap refs %s ret %x\n",
+   inode, off, (size_t)PAGE_SIZE,
+   ceph_cap_string(got), ret);
} else
-   ret = -EAGAIN;
+   err = -EAGAIN;
 
-   dout("filemap_fault %p %llu~%zd dropping cap refs on %s ret %d\n",
-inode, off, (size_t)PAGE_SIZE, ceph_cap_string(got), ret);
if (pinned_page)
put_page(pinned_page);
ceph_put_cap_refs(ci, got);
 
-   if (ret != -EAGAIN)
+   if (err != -EAGAIN)
goto out_restore;
 
/* read inline data */
@@ -1478,7 +1480,6 @@ static int ceph_filemap_fault(struct vm_fault *vmf)
/* does not support inline data > PAGE_SIZE */
ret = VM_FAULT_SIGBUS;
} else {
-   int ret1;
struct address_space *mapping = inode->i_mapping;
struct page *page = find_or_create_page(mapping, 0,
mapping_gfp_constraint(mapping,
@@ -1487,32 +1488,32 @@ static int ceph_filemap_fault(struct vm_fault *vmf)
ret = VM_FAULT_OOM;
goto out_inline;
}
-   ret1 = __ceph_do_getattr(inode, page,
+   err = __ceph_do_getattr(inode, page,
 CEPH_STAT_CAP_INLINE_DATA, true);
-   if (ret1 < 0 || off >= i_size_read(inode)) {
+   if (err < 0 || off >= i_size_read(inode)) {
unlock_page(page);
put_page(page);
-   if (ret1 < 0)
-   ret = ret1;
+   if (err == -ENOMEM)
+   ret = VM_FAULT_OOM;
else
ret = VM_FAULT_SIGBUS;
goto out_inline;
}
-   if (ret1 < PAGE_SIZE)
-   zero_user_segment(page, ret1, PAGE_SIZE);
+   if (err < PAGE_SIZE)
+   zero_user_segment(page, err, PAGE_SIZE);
else
flush_dcache_page(page);
SetPageUptodate(page);
vmf->page = page;
ret = VM_FAULT_MAJOR | VM_FAULT_LOCKED;
 out_inline:
-   dout("filemap_fault %p %llu~%zd read inline data ret %d\n",
+   dout("filemap_fault %p %llu~%zd read inline data ret %x\n",
 inode, off, (size_t)PAGE_SIZE, ret);
}
 out_restore:
ceph_restore_sigs(&oldset);
-   if (ret < 0)
-   ret = (ret == -ENOMEM) ? VM_FAULT_OOM : VM_FAULT_SIGBUS;
+   if (err < 0)
+   ret = vmf_error(err);
 
return ret;
 }
@@ -1520,7 +1521,7 @@ static int ceph_filemap_fault(struct vm_fault *vmf)
 /*
  * Reuse write_begin here for simplicity.
  */
-static int ceph_page_mkwrite(struct vm_fault *vmf)
+static vm_fault_t ceph_page_mkwrite(struct vm_fault

[PATCH] arch/s390: Use new return type vm_fault_t

2018-07-22 Thread Souptick Joarder
use new return type vm_fault_t for fault handler vdso_fault.

Signed-off-by: Souptick Joarder 
---
 arch/s390/kernel/vdso.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/s390/kernel/vdso.c b/arch/s390/kernel/vdso.c
index 09abae4..3031cc6 100644
--- a/arch/s390/kernel/vdso.c
+++ b/arch/s390/kernel/vdso.c
@@ -47,7 +47,7 @@
  */
 unsigned int __read_mostly vdso_enabled = 1;
 
-static int vdso_fault(const struct vm_special_mapping *sm,
+static vm_fault_t vdso_fault(const struct vm_special_mapping *sm,
  struct vm_area_struct *vma, struct vm_fault *vmf)
 {
struct page **vdso_pagelist;
-- 
1.9.1



Re: [PATCH] ext4: Convert int to vm_fault_t type

2018-08-01 Thread Souptick Joarder
On Wed, Aug 1, 2018 at 6:25 PM, Theodore Y. Ts'o  wrote:
> On Sat, Jul 28, 2018 at 02:20:00PM +0530, Souptick Joarder wrote:
>> Use new return type vm_fault_t for ext4_page_mkwrite
>> handler and block_page_mkwrite_return.
>>
>> Signed-off-by: Souptick Joarder 
>
> FYI, this patch was very sloppy, and didn't do the right thing.  That's
> because of how you messed with the changing how the return codes are
> now handled.
>
>> --- a/fs/ext4/inode.c
>> +++ b/fs/ext4/inode.c
>> @@ -6108,27 +6108,27 @@ static int ext4_bh_unmapped(handle_t *handle, struct 
>> buffer_head *bh)
>>   return !buffer_mapped(bh);
>>  }
>>
>> -int ext4_page_mkwrite(struct vm_fault *vmf)
>> +vm_fault_t ext4_page_mkwrite(struct vm_fault *vmf)
>>  {
>>   struct vm_area_struct *vma = vmf->vma;
>>   struct page *page = vmf->page;
>>   loff_t size;
>>   unsigned long len;
>> - int ret;
>> + vm_fault_t ret;
>>   struct file *file = vma->vm_file;
>>   struct inode *inode = file_inode(file);
>>   struct address_space *mapping = inode->i_mapping;
>>   handle_t *handle;
>>   get_block_t *get_block;
>> - int retries = 0;
>> + int retries = 0, err;
>
> OK, ret now is a vm_fault_t, and err is an error return
>
>> @@ -6138,9 +6138,9 @@ int ext4_page_mkwrite(struct vm_fault *vmf)
>>   do {
>>   ret = block_page_mkwrite(vma, vmf,
>>  ext4_da_get_block_prep);
>
> But block_page_mkwrite() still returns an int, not a vm_fault_t
>
>>  -} while (ret == -ENOSPC &&
>> + } while (ret == VM_FAULT_SIGBUS &&
>>  ext4_should_retry_alloc(inode->i_sb, &retries));
>
> So this is Just wrong,  This needed to be:
>
> do {
> err = block_page_mkwrite(vma, vmf,
>ext4_da_get_block_prep);
> } while (err == -ENOSPC &&
>  ext4_should_retry_alloc(inode->i_sb, &retries));
> goto out_ret;
>
> That's because out_ret is what will translate the int error code to
> the vm_fault_t via:
>
> ret = block_page_mkwrite_return(err);
>
> The fact that ext4_page_mkwrite() returns a vm_fault_t, while
> block_page_mkwrite() returns an int which then has to get translated
> into a vm_fault_t via block_page_mkwrite_return() is I suspect going
> to confuse an awful lot of callers.

We have also changed block_page_mkwrite() to return vm_fault_t, but in
a different patch. Hopefully that patch will be in linux-next tree soon.

>
> I'll fix up the patch, but I just wanted to call your attention to
> this pitfall in the patch which confused even you as the patch author
>
> (BTW, the buggy patch triggered a new failure, ext4/307, which is how
> I noticed that the patch was all wrong.  If you had run any kind of
> static code checker you would have noticed that block_page_mkwrite()
> was returning an int and that was getting assigned into a variable of
> type vm_fault_t.  The fact that you *didn't* notice makes me worry
> that all of this code churn may, in the end, not actually help us as
> much as we thought.  :-(
>
>   - Ted


Re: [PATCH] ext4: Convert int to vm_fault_t type

2018-08-01 Thread Souptick Joarder
On Wed, Aug 1, 2018 at 6:34 PM, Souptick Joarder  wrote:
> On Wed, Aug 1, 2018 at 6:25 PM, Theodore Y. Ts'o  wrote:
>> On Sat, Jul 28, 2018 at 02:20:00PM +0530, Souptick Joarder wrote:
>>> Use new return type vm_fault_t for ext4_page_mkwrite
>>> handler and block_page_mkwrite_return.
>>>
>>> Signed-off-by: Souptick Joarder 
>>
>> FYI, this patch was very sloppy, and didn't do the right thing.  That's
>> because of how you messed with the changing how the return codes are
>> now handled.
>>
>>> --- a/fs/ext4/inode.c
>>> +++ b/fs/ext4/inode.c
>>> @@ -6108,27 +6108,27 @@ static int ext4_bh_unmapped(handle_t *handle, 
>>> struct buffer_head *bh)
>>>   return !buffer_mapped(bh);
>>>  }
>>>
>>> -int ext4_page_mkwrite(struct vm_fault *vmf)
>>> +vm_fault_t ext4_page_mkwrite(struct vm_fault *vmf)
>>>  {
>>>   struct vm_area_struct *vma = vmf->vma;
>>>   struct page *page = vmf->page;
>>>   loff_t size;
>>>   unsigned long len;
>>> - int ret;
>>> + vm_fault_t ret;
>>>   struct file *file = vma->vm_file;
>>>   struct inode *inode = file_inode(file);
>>>   struct address_space *mapping = inode->i_mapping;
>>>   handle_t *handle;
>>>   get_block_t *get_block;
>>> - int retries = 0;
>>> + int retries = 0, err;
>>
>> OK, ret now is a vm_fault_t, and err is an error return
>>
>>> @@ -6138,9 +6138,9 @@ int ext4_page_mkwrite(struct vm_fault *vmf)
>>>   do {
>>>   ret = block_page_mkwrite(vma, vmf,
>>>  ext4_da_get_block_prep);
>>
>> But block_page_mkwrite() still returns an int, not a vm_fault_t
>>
>>>  -} while (ret == -ENOSPC &&
>>> + } while (ret == VM_FAULT_SIGBUS &&
>>>  ext4_should_retry_alloc(inode->i_sb, &retries));
>>
>> So this is Just wrong,  This needed to be:
>>
>> do {
>> err = block_page_mkwrite(vma, vmf,
>>ext4_da_get_block_prep);
>> } while (err == -ENOSPC &&
>>  ext4_should_retry_alloc(inode->i_sb, &retries));
>> goto out_ret;
>>
>> That's because out_ret is what will translate the int error code to
>> the vm_fault_t via:
>>
>> ret = block_page_mkwrite_return(err);
>>
>> The fact that ext4_page_mkwrite() returns a vm_fault_t, while
>> block_page_mkwrite() returns an int which then has to get translated
>> into a vm_fault_t via block_page_mkwrite_return() is I suspect going
>> to confuse an awful lot of callers.
>
> We have also changed block_page_mkwrite() to return vm_fault_t, but in
> a different patch. Hopefully that patch will be in linux-next tree soon.

Link to other patch where block_page_mkwrite() is changed to return
vm_fault_t type.

https://www.spinics.net/lists/linux-fsdevel/msg130670.html

>
>>
>> I'll fix up the patch, but I just wanted to call your attention to
>> this pitfall in the patch which confused even you as the patch author
>>
>> (BTW, the buggy patch triggered a new failure, ext4/307, which is how
>> I noticed that the patch was all wrong.  If you had run any kind of
>> static code checker you would have noticed that block_page_mkwrite()
>> was returning an int and that was getting assigned into a variable of
>> type vm_fault_t.  The fact that you *didn't* notice makes me worry
>> that all of this code churn may, in the end, not actually help us as
>> much as we thought.  :-(
>>
>>   - Ted


Re: [PATCH] drm/rockchip: Convert drm_atomic_helper_suspend/resume()

2018-08-01 Thread Souptick Joarder
On Wed, Aug 1, 2018 at 6:40 PM, Heiko Stuebner  wrote:
> Am Mittwoch, 1. August 2018, 14:43:47 CEST schrieb Souptick Joarder:
>> On Wed, Aug 1, 2018 at 6:03 PM, Heiko Stuebner  wrote:
>> > Hi Souptick,
>> >
>> > Am Dienstag, 31. Juli 2018, 22:34:30 CEST schrieb Souptick Joarder:
>> >> convert drm_atomic_helper_suspend/resume() to use
>> >> drm_mode_config_helper_suspend/resume().
>> >>
>> >> With this conversion, rockchip_drm_fb_resume() and
>> >> rockchip_drm_fb_suspend() will not be used anymore.
>> >> Both of these functions can be removed.
>> >>
>> >> Also, in struct rockchip_drm_private state will not be
>> >> used anymore. So this can be removed forever.
>> >>
>> >> Signed-off-by: Souptick Joarder 
>> >> Signed-off-by: Ajit Negi 
>> >
>> > the patch itself looks great, just a simple bookkeeping question.
>> >
>> > What role did Ajit play in creating the patch? If I remember correctly
>> > it is meant to be
>> > - 1st Signed-off: Patch-Author
>> > - 2nd Signed-off: E-Mail sender + patch possibly patch changes
>> > (optional of course if the same)
>> >
>> > So was this meant to be a Reviewed-by from Ajit?
>>
>> We both are working together for these patches to
>> convert drm_atomic_helper_suspend/resume().
>> That's the reason to add his name in 2nd Signed-off
>> in all similar patches.
>>
>> Is it a incorrect way to put 2nd Signed-off here ?
>
> Thanks for the clarification and the interesting question :-)
>
> I've just read through Documentation/process/submitting-patches.rst
> and it seems there is an "official" way to show that relationship, via a
> tag named "Co-Developed-by:" described under number 12.
>
> So I guess we could just adapt the patch accordingly, if that is ok with
> both of you (i.e. I can change this when applying, so no need to resend).

We are ok with it :-)

>
>
> Heiko
>
>


Re: [PATCH] ext4: Convert int to vm_fault_t type

2018-08-01 Thread Souptick Joarder
On Wed, Aug 1, 2018 at 6:43 PM, Matthew Wilcox  wrote:
> On Wed, Aug 01, 2018 at 06:34:45PM +0530, Souptick Joarder wrote:
>> > The fact that ext4_page_mkwrite() returns a vm_fault_t, while
>> > block_page_mkwrite() returns an int which then has to get translated
>> > into a vm_fault_t via block_page_mkwrite_return() is I suspect going
>> > to confuse an awful lot of callers.
>>
>> We have also changed block_page_mkwrite() to return vm_fault_t, but in
>> a different patch. Hopefully that patch will be in linux-next tree soon.
>
> I didn't sign off on that, so that's not "we", but "I".  And this is
> completely against everything I've been telling you for this whole effort.
> Patches should each make sense individually.  You can't make this patch
> dependent on another patch without putting that in writing.

It was mistake form my side. Sorry about it.

>
> Leave block_page_mkwrite() alone for now.  Eventually it should return
> a vm_fault_t, probably.  But that patch needs to be delayed at least
> one kernel cycle.

As caller of block_page_mkwrite() are -
fs/ext4/inode.c
fs/nilfs2/file.c

I will merge both changes in a single patch and send it.


Re: [PATCH v2] fs/buffer: Convert return type int to vm_fault_t

2018-08-01 Thread Souptick Joarder
On Mon, Jul 30, 2018 at 8:31 PM, Souptick Joarder  wrote:
> Return type of block_page_mkwrite() is converted to
> vm_fault_t type. The caller of block_page_mkwrite
> inside fs/nilfs2 nilfs_page_mkwrite converted accordingly.
>
> Signed-off-by: Souptick Joarder 
> ---
> v2: Address Jens's comment. Remove ret variable
> from block_page_mkwrite().

I am dropping this for now. This will be merged with another
patch and I will resend it.

>
>  fs/buffer.c | 16 
>  fs/nilfs2/file.c| 13 -
>  include/linux/buffer_head.h |  2 +-
>  3 files changed, 17 insertions(+), 14 deletions(-)
>
> diff --git a/fs/buffer.c b/fs/buffer.c
> index cabc045..aeed99f 100644
> --- a/fs/buffer.c
> +++ b/fs/buffer.c
> @@ -2444,21 +2444,21 @@ int block_commit_write(struct page *page, unsigned 
> from, unsigned to)
>   * Direct callers of this function should protect against filesystem freezing
>   * using sb_start_pagefault() - sb_end_pagefault() functions.
>   */
> -int block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf,
> +vm_fault_t block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault 
> *vmf,
>  get_block_t get_block)
>  {
> struct page *page = vmf->page;
> struct inode *inode = file_inode(vma->vm_file);
> unsigned long end;
> loff_t size;
> -   int ret;
> +   int err;
>
> lock_page(page);
> size = i_size_read(inode);
> if ((page->mapping != inode->i_mapping) ||
> (page_offset(page) > size)) {
> /* We overload EFAULT to mean page got truncated */
> -   ret = -EFAULT;
> +   err = -EFAULT;
> goto out_unlock;
> }
>
> @@ -2468,18 +2468,18 @@ int block_page_mkwrite(struct vm_area_struct *vma, 
> struct vm_fault *vmf,
> else
> end = PAGE_SIZE;
>
> -   ret = __block_write_begin(page, 0, end, get_block);
> -   if (!ret)
> -   ret = block_commit_write(page, 0, end);
> +   err = __block_write_begin(page, 0, end, get_block);
> +   if (!err)
> +   err = block_commit_write(page, 0, end);
>
> -   if (unlikely(ret < 0))
> +   if (unlikely(err < 0))
> goto out_unlock;
> set_page_dirty(page);
> wait_for_stable_page(page);
> return 0;
>  out_unlock:
> unlock_page(page);
> -   return ret;
> +   return block_page_mkwrite_return(err);
>  }
>  EXPORT_SYMBOL(block_page_mkwrite);
>
> diff --git a/fs/nilfs2/file.c b/fs/nilfs2/file.c
> index c5fa3de..da2759e 100644
> --- a/fs/nilfs2/file.c
> +++ b/fs/nilfs2/file.c
> @@ -57,7 +57,8 @@ static int nilfs_page_mkwrite(struct vm_fault *vmf)
> struct page *page = vmf->page;
> struct inode *inode = file_inode(vma->vm_file);
> struct nilfs_transaction_info ti;
> -   int ret = 0;
> +   vm_fault_t ret = VM_FAULT_LOCKED;
> +   int err = 0;
>
> if (unlikely(nilfs_near_disk_full(inode->i_sb->s_fs_info)))
> return VM_FAULT_SIGBUS; /* -ENOSPC */
> @@ -67,7 +68,7 @@ static int nilfs_page_mkwrite(struct vm_fault *vmf)
> if (page->mapping != inode->i_mapping ||
> page_offset(page) >= i_size_read(inode) || !PageUptodate(page)) {
> unlock_page(page);
> -   ret = -EFAULT;  /* make the VM retry the fault */
> +   ret = VM_FAULT_NOPAGE;  /* make the VM retry the fault */
> goto out;
> }
>
> @@ -99,10 +100,12 @@ static int nilfs_page_mkwrite(struct vm_fault *vmf)
> /*
>  * fill hole blocks
>  */
> -   ret = nilfs_transaction_begin(inode->i_sb, &ti, 1);
> +   err = nilfs_transaction_begin(inode->i_sb, &ti, 1);
> /* never returns -ENOMEM, but may return -ENOSPC */
> -   if (unlikely(ret))
> +   if (unlikely(err)) {
> +   ret = block_page_mkwrite_return(err);
> goto out;
> +   }
>
> file_update_time(vma->vm_file);
> ret = block_page_mkwrite(vma, vmf, nilfs_get_block);
> @@ -117,7 +120,7 @@ static int nilfs_page_mkwrite(struct vm_fault *vmf)
> wait_for_stable_page(page);
>   out:
> sb_end_pagefault(inode->i_sb);
> -   return block_page_mkwrite_return(ret);
> +   return ret;
>  }
>
>  static const struct vm_operations_struct nilfs_file_vm_ops = {
> diff --git a/include/linux/buffer_head.h b/include/linux/buffer_head.h
> index ed7a81b..7184c6e 100644
> --- a/include/linux/

[PATCH v2] fs: ceph: Adding new return type vm_fault_t

2018-07-23 Thread Souptick Joarder
Use new return type vm_fault_t for page_mkwrite
and fault handler.

Signed-off-by: Souptick Joarder 
Reviewed-by: Matthew Wilcox 
---
v2: Fixed kbuild warning

 fs/ceph/addr.c | 62 ++
 1 file changed, 32 insertions(+), 30 deletions(-)

diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c
index 292b3d7..26beebe 100644
--- a/fs/ceph/addr.c
+++ b/fs/ceph/addr.c
@@ -1431,7 +1431,7 @@ static void ceph_restore_sigs(sigset_t *oldset)
 /*
  * vm ops
  */
-static int ceph_filemap_fault(struct vm_fault *vmf)
+static vm_fault_t ceph_filemap_fault(struct vm_fault *vmf)
 {
struct vm_area_struct *vma = vmf->vma;
struct inode *inode = file_inode(vma->vm_file);
@@ -1439,8 +1439,9 @@ static int ceph_filemap_fault(struct vm_fault *vmf)
struct ceph_file_info *fi = vma->vm_file->private_data;
struct page *pinned_page = NULL;
loff_t off = vmf->pgoff << PAGE_SHIFT;
-   int want, got, ret;
+   int want, got, err;
sigset_t oldset;
+   vm_fault_t ret = VM_FAULT_SIGBUS;
 
ceph_block_sigs(&oldset);
 
@@ -1452,8 +1453,8 @@ static int ceph_filemap_fault(struct vm_fault *vmf)
want = CEPH_CAP_FILE_CACHE;
 
got = 0;
-   ret = ceph_get_caps(ci, CEPH_CAP_FILE_RD, want, -1, &got, &pinned_page);
-   if (ret < 0)
+   err = ceph_get_caps(ci, CEPH_CAP_FILE_RD, want, -1, &got, &pinned_page);
+   if (err < 0)
goto out_restore;
 
dout("filemap_fault %p %llu~%zd got cap refs on %s\n",
@@ -1465,16 +1466,17 @@ static int ceph_filemap_fault(struct vm_fault *vmf)
ceph_add_rw_context(fi, &rw_ctx);
ret = filemap_fault(vmf);
ceph_del_rw_context(fi, &rw_ctx);
+   dout("filemap_fault %p %llu~%zd drop cap refs %s ret %x\n",
+   inode, off, (size_t)PAGE_SIZE,
+   ceph_cap_string(got), ret);
} else
-   ret = -EAGAIN;
+   err = -EAGAIN;
 
-   dout("filemap_fault %p %llu~%zd dropping cap refs on %s ret %d\n",
-inode, off, (size_t)PAGE_SIZE, ceph_cap_string(got), ret);
if (pinned_page)
put_page(pinned_page);
ceph_put_cap_refs(ci, got);
 
-   if (ret != -EAGAIN)
+   if (err != -EAGAIN)
goto out_restore;
 
/* read inline data */
@@ -1482,7 +1484,6 @@ static int ceph_filemap_fault(struct vm_fault *vmf)
/* does not support inline data > PAGE_SIZE */
ret = VM_FAULT_SIGBUS;
} else {
-   int ret1;
struct address_space *mapping = inode->i_mapping;
struct page *page = find_or_create_page(mapping, 0,
mapping_gfp_constraint(mapping,
@@ -1491,32 +1492,32 @@ static int ceph_filemap_fault(struct vm_fault *vmf)
ret = VM_FAULT_OOM;
goto out_inline;
}
-   ret1 = __ceph_do_getattr(inode, page,
+   err = __ceph_do_getattr(inode, page,
 CEPH_STAT_CAP_INLINE_DATA, true);
-   if (ret1 < 0 || off >= i_size_read(inode)) {
+   if (err < 0 || off >= i_size_read(inode)) {
unlock_page(page);
put_page(page);
-   if (ret1 < 0)
-   ret = ret1;
+   if (err == -ENOMEM)
+   ret = VM_FAULT_OOM;
else
ret = VM_FAULT_SIGBUS;
goto out_inline;
}
-   if (ret1 < PAGE_SIZE)
-   zero_user_segment(page, ret1, PAGE_SIZE);
+   if (err < PAGE_SIZE)
+   zero_user_segment(page, err, PAGE_SIZE);
else
flush_dcache_page(page);
SetPageUptodate(page);
vmf->page = page;
ret = VM_FAULT_MAJOR | VM_FAULT_LOCKED;
 out_inline:
-   dout("filemap_fault %p %llu~%zd read inline data ret %d\n",
+   dout("filemap_fault %p %llu~%zd read inline data ret %x\n",
 inode, off, (size_t)PAGE_SIZE, ret);
}
 out_restore:
ceph_restore_sigs(&oldset);
-   if (ret < 0)
-   ret = (ret == -ENOMEM) ? VM_FAULT_OOM : VM_FAULT_SIGBUS;
+   if (err < 0)
+   ret = vmf_error(err);
 
return ret;
 }
@@ -1524,7 +1525,7 @@ static int ceph_filemap_fault(struct vm_fault *vmf)
 /*
  * Reuse write_begin here for simplicity.
  */
-static int ceph_page_mkwrite(struct vm_fault *vmf)
+static vm_fault_t ceph_page_mkwrite(struct vm_fault *vmf)
 {
struct 

[PATCH] char: agp: Change return type to vm_fault_t

2018-07-13 Thread Souptick Joarder
Use new return type vm_fault_t for fault handler. For now,
this is just documenting that the function returns a
VM_FAULT value rather than an errno. Once all instances are
converted, vm_fault_t will become a distinct type.

Ref-> commit 1c8f422059ae ("mm: change return type to
vm_fault_t") was added in 4.17-rc1 to introduce the new
typedef vm_fault_t. Currently we are making change to all
drivers to return vm_fault_t for page fault handlers. As
part of that char/agp driver is also getting changed to
return vm_fault_t type from fault handler.

Signed-off-by: Souptick Joarder 
Reviewed-by: Matthew Wilcox 
---
 drivers/char/agp/alpha-agp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/char/agp/alpha-agp.c b/drivers/char/agp/alpha-agp.c
index 53fe633..c9bf2c2 100644
--- a/drivers/char/agp/alpha-agp.c
+++ b/drivers/char/agp/alpha-agp.c
@@ -11,7 +11,7 @@
 
 #include "agp.h"
 
-static int alpha_core_agp_vm_fault(struct vm_fault *vmf)
+static vm_fault_t alpha_core_agp_vm_fault(struct vm_fault *vmf)
 {
alpha_agp_info *agp = agp_bridge->dev_private_data;
dma_addr_t dma_addr;
-- 
1.9.1



Re: [PATCH v3] mm: Change return type int to vm_fault_t for fault handlers

2018-07-13 Thread Souptick Joarder
On Tue, Jun 19, 2018 at 10:26 AM, Souptick Joarder  wrote:
> On Mon, Jun 4, 2018 at 10:47 PM, Souptick Joarder  
> wrote:
>> Use new return type vm_fault_t for fault handler. For
>> now, this is just documenting that the function returns
>> a VM_FAULT value rather than an errno. Once all instances
>> are converted, vm_fault_t will become a distinct type.
>>
>> Ref-> commit 1c8f422059ae ("mm: change return type to vm_fault_t")
>>
>> The aim is to change the return type of finish_fault()
>> and handle_mm_fault() to vm_fault_t type. As part of
>> that clean up return type of all other recursively called
>> functions have been changed to vm_fault_t type.
>>
>> The places from where handle_mm_fault() is getting invoked
>> will be change to vm_fault_t type but in a separate patch.
>>
>> vmf_error() is the newly introduce inline function
>> in 4.17-rc6.
>>
>> Signed-off-by: Souptick Joarder 
>> Reviewed-by: Matthew Wilcox 
>> ---
>> v2: Change patch title and fixed sparse warning.
>>
>> v3: Reviewed by Matthew Wilcox
>>
>>  fs/userfaultfd.c  |  6 +--
>>  include/linux/huge_mm.h   | 10 +++--
>>  include/linux/hugetlb.h   |  2 +-
>>  include/linux/mm.h| 14 +++
>>  include/linux/oom.h   |  2 +-
>>  include/linux/swapops.h   |  5 ++-
>>  include/linux/userfaultfd_k.h |  5 ++-
>>  kernel/memremap.c |  2 +-
>>  mm/gup.c  |  4 +-
>>  mm/huge_memory.c  | 25 ++--
>>  mm/hugetlb.c  | 29 +++---
>>  mm/internal.h |  2 +-
>>  mm/khugepaged.c   |  3 +-
>>  mm/memory.c   | 90 
>> ++-
>>  mm/shmem.c| 17 
>>  15 files changed, 110 insertions(+), 106 deletions(-)
>>
>> diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c
>> index cec550c..bf60c6a 100644
>> --- a/fs/userfaultfd.c
>> +++ b/fs/userfaultfd.c
>> @@ -336,17 +336,15 @@ static inline bool userfaultfd_must_wait(struct 
>> userfaultfd_ctx *ctx,
>>   * fatal_signal_pending()s, and the mmap_sem must be released before
>>   * returning it.
>>   */
>> -int handle_userfault(struct vm_fault *vmf, unsigned long reason)
>> +vm_fault_t handle_userfault(struct vm_fault *vmf, unsigned long reason)
>>  {
>> struct mm_struct *mm = vmf->vma->vm_mm;
>> struct userfaultfd_ctx *ctx;
>> struct userfaultfd_wait_queue uwq;
>> -   int ret;
>> +   vm_fault_t ret = VM_FAULT_SIGBUS;
>> bool must_wait, return_to_userland;
>> long blocking_state;
>>
>> -   ret = VM_FAULT_SIGBUS;
>> -
>> /*
>>  * We don't do userfault handling for the final child pid update.
>>  *
>> diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h
>> index a8a1262..8c4f0a6 100644
>> --- a/include/linux/huge_mm.h
>> +++ b/include/linux/huge_mm.h
>> @@ -3,10 +3,11 @@
>>  #define _LINUX_HUGE_MM_H
>>
>>  #include 
>> +#include 
>>
>>  #include  /* only for vma_is_dax() */
>>
>> -extern int do_huge_pmd_anonymous_page(struct vm_fault *vmf);
>> +extern vm_fault_t do_huge_pmd_anonymous_page(struct vm_fault *vmf);
>>  extern int copy_huge_pmd(struct mm_struct *dst_mm, struct mm_struct *src_mm,
>>  pmd_t *dst_pmd, pmd_t *src_pmd, unsigned long addr,
>>  struct vm_area_struct *vma);
>> @@ -23,7 +24,7 @@ static inline void huge_pud_set_accessed(struct vm_fault 
>> *vmf, pud_t orig_pud)
>>  }
>>  #endif
>>
>> -extern int do_huge_pmd_wp_page(struct vm_fault *vmf, pmd_t orig_pmd);
>> +extern vm_fault_t do_huge_pmd_wp_page(struct vm_fault *vmf, pmd_t orig_pmd);
>>  extern struct page *follow_trans_huge_pmd(struct vm_area_struct *vma,
>>   unsigned long addr,
>>   pmd_t *pmd,
>> @@ -216,7 +217,7 @@ struct page *follow_devmap_pmd(struct vm_area_struct 
>> *vma, unsigned long addr,
>>  struct page *follow_devmap_pud(struct vm_area_struct *vma, unsigned long 
>> addr,
>> pud_t *pud, int flags);
>>
>> -extern int do_huge_pmd_numa_page(struct vm_fault *vmf, pmd_t orig_pmd);
>> +extern vm_fault_t do_huge_pmd_numa_page(struct vm_fault *vmf, pmd_t 
>> orig_pmd);
>>
>>  extern struct page *huge_zero_page;
>>
>> @@ -321,7 +322,8

Re: [PATCH] fs: ext4: use new return type vm_fault_t

2018-07-15 Thread Souptick Joarder
On Sat, Jul 7, 2018 at 4:00 PM, Souptick Joarder  wrote:
> Use new return type vm_fault_t for fault handler
> ext4_filemap_fault.
>
> Signed-off-by: Souptick Joarder 

Any comment on this patch ?
> ---
>  fs/ext4/ext4.h  | 2 +-
>  fs/ext4/inode.c | 8 
>  2 files changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
> index 0b12785..aec0010 100644
> --- a/fs/ext4/ext4.h
> +++ b/fs/ext4/ext4.h
> @@ -2470,7 +2470,7 @@ int do_journal_get_write_access(handle_t *handle,
>  extern int ext4_zero_partial_blocks(handle_t *handle, struct inode *inode,
>  loff_t lstart, loff_t lend);
>  extern int ext4_page_mkwrite(struct vm_fault *vmf);
> -extern int ext4_filemap_fault(struct vm_fault *vmf);
> +extern vm_fault_t ext4_filemap_fault(struct vm_fault *vmf);
>  extern qsize_t *ext4_get_reserved_space(struct inode *inode);
>  extern int ext4_get_projid(struct inode *inode, kprojid_t *projid);
>  extern void ext4_da_update_reserve_space(struct inode *inode,
> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index 2ea07ef..03ac322 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -6205,14 +6205,14 @@ int ext4_page_mkwrite(struct vm_fault *vmf)
> return ret;
>  }
>
> -int ext4_filemap_fault(struct vm_fault *vmf)
> +vm_fault_t ext4_filemap_fault(struct vm_fault *vmf)
>  {
> struct inode *inode = file_inode(vmf->vma->vm_file);
> -   int err;
> +   vm_fault_t ret;
>
> down_read(&EXT4_I(inode)->i_mmap_sem);
> -   err = filemap_fault(vmf);
> +   ret = filemap_fault(vmf);
> up_read(&EXT4_I(inode)->i_mmap_sem);
>
> -   return err;
> +   return ret;
>  }
> --
> 1.9.1
>


[PATCH] mm/filemap.c: Use vmf_error()

2018-09-27 Thread Souptick Joarder
These codes can be replaced with new inline vmf_error().

Signed-off-by: Souptick Joarder 
---
 mm/filemap.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/mm/filemap.c b/mm/filemap.c
index 52517f2..7d04d7c 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -2581,9 +2581,7 @@ vm_fault_t filemap_fault(struct vm_fault *vmf)
 * system is low on memory, or a problem occurs while trying
 * to schedule I/O.
 */
-   if (error == -ENOMEM)
-   return VM_FAULT_OOM;
-   return VM_FAULT_SIGBUS;
+   return vmf_error(error);
 
 page_not_uptodate:
/*
-- 
1.9.1



[PATCH] mm: Introduce new function vm_insert_kmem_page

2018-09-27 Thread Souptick Joarder
vm_insert_kmem_page is similar to vm_insert_page and will
be used by drivers to map kernel (kmalloc/vmalloc/pages)
allocated memory to user vma.

Previously vm_insert_page is used for both page fault
handlers and outside page fault handlers context. When
vm_insert_page is used in page fault handlers context,
each driver have to map errno to VM_FAULT_CODE in their
own way. But as part of vm_fault_t migration all the
page fault handlers are cleaned up by using new vmf_insert_page.
Going forward, vm_insert_page will be removed by converting
it to vmf_insert_page.
 
But their are places where vm_insert_page is used outside
page fault handlers context and converting those to
vmf_insert_page is not a good approach as drivers will end
up with new VM_FAULT_CODE to errno conversion code and it will
make each user more complex.

So this new vm_insert_kmem_page can be used to map kernel
memory to user vma outside page fault handler context.

In short, vmf_insert_page will be used in page fault handlers
context and vm_insert_kmem_page will be used to map kernel
memory to user vma outside page fault handlers context.

We will slowly convert all the user of vm_insert_page to
vm_insert_kmem_page after this API be available in linus tree.

Signed-off-by: Souptick Joarder 
---
 include/linux/mm.h |  2 ++
 mm/memory.c| 69 ++
 mm/nommu.c |  7 ++
 3 files changed, 78 insertions(+)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index a61ebe8..5f42d35 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -2477,6 +2477,8 @@ unsigned long change_prot_numa(struct vm_area_struct *vma,
 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
unsigned long pfn, unsigned long size, pgprot_t);
+int vm_insert_kmem_page(struct vm_area_struct *vma, unsigned long addr,
+   struct page *page);
 int vm_insert_page(struct vm_area_struct *, unsigned long addr, struct page *);
 int vm_insert_pfn(struct vm_area_struct *vma, unsigned long addr,
unsigned long pfn);
diff --git a/mm/memory.c b/mm/memory.c
index c467102..b800c10 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -1682,6 +1682,75 @@ pte_t *__get_locked_pte(struct mm_struct *mm, unsigned 
long addr,
return pte_alloc_map_lock(mm, pmd, addr, ptl);
 }
 
+static int insert_kmem_page(struct vm_area_struct *vma, unsigned long addr,
+   struct page *page, pgprot_t prot)
+{
+   struct mm_struct *mm = vma->vm_mm;
+   int retval;
+   pte_t *pte;
+   spinlock_t *ptl;
+
+   retval = -EINVAL;
+   if (PageAnon(page))
+   goto out;
+   retval = -ENOMEM;
+   flush_dcache_page(page);
+   pte = get_locked_pte(mm, addr, &ptl);
+   if (!pte)
+   goto out;
+   retval = -EBUSY;
+   if (!pte_none(*pte))
+   goto out_unlock;
+
+   get_page(page);
+   inc_mm_counter_fast(mm, mm_counter_file(page));
+   page_add_file_rmap(page, false);
+   set_pte_at(mm, addr, pte, mk_pte(page, prot));
+
+   retval = 0;
+   pte_unmap_unlock(pte, ptl);
+   return retval;
+out_unlock:
+   pte_unmap_unlock(pte, ptl);
+out:
+   return retval;
+}
+
+/**
+ * vm_insert_kmem_page - insert single page into user vma
+ * @vma: user vma to map to
+ * @addr: target user address of this page
+ * @page: source kernel page
+ *
+ * This allows drivers to insert individual kernel memory into a user vma.
+ * This API should be used outside page fault handlers context.
+ *
+ * Previously the same has been done with vm_insert_page by drivers. But
+ * vm_insert_page will be converted to vmf_insert_page and will be used
+ * in fault handlers context and return type of vmf_insert_page will be
+ * vm_fault_t type.
+ *
+ * But there are places where drivers need to map kernel memory into user
+ * vma outside fault handlers context. As vmf_insert_page will be restricted
+ * to use within page fault handlers, vm_insert_kmem_page could be used
+ * to map kernel memory to user vma outside fault handlers context.
+ */
+int vm_insert_kmem_page(struct vm_area_struct *vma, unsigned long addr,
+   struct page *page)
+{
+   if (addr < vma->vm_start || addr >= vma->vm_end)
+   return -EFAULT;
+   if (!page_count(page))
+   return -EINVAL;
+   if (!(vma->vm_flags & VM_MIXEDMAP)) {
+   BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
+   BUG_ON(vma->vm_flags & VM_PFNMAP);
+   vma->vm_flags |= VM_MIXEDMAP;
+   }
+   return insert_kmem_page(vma, addr, page, vma->vm_page_prot);
+}
+EXPORT_SYMBOL(vm_insert_kmem_page);
+
 /*
  * This is the old fallback for page remapping.
  *
diff --git a/mm/nommu.c b/mm/nommu.c
index e4aac33..153b8c8 1

Re: [PATCH] mm: Introduce new function vm_insert_kmem_page

2018-09-28 Thread Souptick Joarder
On Fri, Sep 28, 2018 at 12:02 AM Michal Hocko  wrote:
>
> On Thu 27-09-18 23:21:23, Souptick Joarder wrote:
> > vm_insert_kmem_page is similar to vm_insert_page and will
> > be used by drivers to map kernel (kmalloc/vmalloc/pages)
> > allocated memory to user vma.
> >
> > Previously vm_insert_page is used for both page fault
> > handlers and outside page fault handlers context. When
> > vm_insert_page is used in page fault handlers context,
> > each driver have to map errno to VM_FAULT_CODE in their
> > own way. But as part of vm_fault_t migration all the
> > page fault handlers are cleaned up by using new vmf_insert_page.
> > Going forward, vm_insert_page will be removed by converting
> > it to vmf_insert_page.
> >
> > But their are places where vm_insert_page is used outside
> > page fault handlers context and converting those to
> > vmf_insert_page is not a good approach as drivers will end
> > up with new VM_FAULT_CODE to errno conversion code and it will
> > make each user more complex.
> >
> > So this new vm_insert_kmem_page can be used to map kernel
> > memory to user vma outside page fault handler context.
> >
> > In short, vmf_insert_page will be used in page fault handlers
> > context and vm_insert_kmem_page will be used to map kernel
> > memory to user vma outside page fault handlers context.
> >
> > We will slowly convert all the user of vm_insert_page to
> > vm_insert_kmem_page after this API be available in linus tree.
>
> In general I do not like patches adding a new exports/functionality
> without any user added at the same time. I am not going to look at the
> implementation right now but the above opens more questions than it
> gives answers. Why do we have to distinguish #PF from other paths?

Going forward, the plan is to restrict future drivers not to use vm_insert_page
( *it will generate new errno to VM_FAULT_CODE mapping code for new drivers
which were already cleaned up for existing drivers*) in #PF context but to make
use of vmf_insert_page which returns VMF_FAULT_CODE and that is not possible
until both vm_insert_page and vmf_insert_page API exists.

But there are some consumers of vm_insert_page which use it outside #PF context.
straight forward conversion of vm_insert_page to vmf_insert_page won't
work there as
those function calls expects errno not vm_fault_t in return.

e.g - drivers/auxdisplay/cfag12864bfb.c, line 55
drivers/auxdisplay/ht16k33.c, line 227
drivers/firewire/core-iso.c, line 115
drivers/gpu/drm/rockchip/rockchip_drm_gem.c, line 237
drivers/gpu/drm/xen/xen_drm_front_gem.c, line 253
drivers/iommu/dma-iommu.c, line 600
drivers/media/common/videobuf2/videobuf2-dma-sg.c, line 343
drivers/media/usb/usbvision/usbvision-video.c, line 1056
drivers/xen/gntalloc.c, line 548
drivers/xen/gntdev.c, line 1149
drivers/xen/privcmd-buf.c, line 184
mm/vmalloc.c, line 2254
net/ipv4/tcp.c, line 1806
net/packet/af_packet.c, line 4407

These are the approaches which could have been taken to handle this scenario -

1. Replace vm_insert_page with vmf_insert_page and then write few
   extra lines of code to convert VM_FAULT_CODE to errno which
   makes driver users more complex ( also the reverse mapping errno to
   VM_FAULT_CODE have been cleaned up as part of vm_fault_t migration ,
   not preferred to introduce anything similar again)

2. Maintain both vm_insert_page and vmf_insert_page and use it in
   respective places. But it won't gurantee that vm_insert_page will
   never be used in #PF context.

3. Introduce a similar API like vm_insert_page, convert all non #PF
   consumer to use it and finally remove vm_insert_page by converting
   it to vmf_insert_page.

And the 3rd approach was taken by introducing vm_insert_kmem_page().


Re: [PATCH v3] mm: Create the new vm_fault_t type

2018-11-23 Thread Souptick Joarder
On Thu, Nov 15, 2018 at 7:17 AM Mike Rapoport  wrote:
>
> On Tue, Nov 06, 2018 at 05:36:42PM +0530, Souptick Joarder wrote:
> > Page fault handlers are supposed to return VM_FAULT codes,
> > but some drivers/file systems mistakenly return error
> > numbers. Now that all drivers/file systems have been converted
> > to use the vm_fault_t return type, change the type definition
> > to no longer be compatible with 'int'. By making it an unsigned
> > int, the function prototype becomes incompatible with a function
> > which returns int. Sparse will detect any attempts to return a
> > value which is not a VM_FAULT code.
> >
> > VM_FAULT_SET_HINDEX and VM_FAULT_GET_HINDEX values are changed
> > to avoid conflict with other VM_FAULT codes.
> >
> > Signed-off-by: Souptick Joarder 
>
> For the docs part
> Reviewed-by: Mike Rapoport 
>
> > ---
> > v2: Updated the change log and corrected the document part.
> > name added to the enum that kernel-doc able to parse it.
> >
> > v3: Corrected the documentation.

If no further comment, can we get this patch in queue for 4.21 ?

> >
> >  include/linux/mm.h   | 46 --
> >  include/linux/mm_types.h | 73 
> > +++-
> >  2 files changed, 72 insertions(+), 47 deletions(-)
> >
> > diff --git a/include/linux/mm.h b/include/linux/mm.h
> > index fcf9cc9..511a3ce 100644
> > --- a/include/linux/mm.h
> > +++ b/include/linux/mm.h
> > @@ -1267,52 +1267,6 @@ static inline void clear_page_pfmemalloc(struct page 
> > *page)
> >  }
> >
> >  /*
> > - * Different kinds of faults, as returned by handle_mm_fault().
> > - * Used to decide whether a process gets delivered SIGBUS or
> > - * just gets major/minor fault counters bumped up.
> > - */
> > -
> > -#define VM_FAULT_OOM 0x0001
> > -#define VM_FAULT_SIGBUS  0x0002
> > -#define VM_FAULT_MAJOR   0x0004
> > -#define VM_FAULT_WRITE   0x0008  /* Special case for get_user_pages */
> > -#define VM_FAULT_HWPOISON 0x0010 /* Hit poisoned small page */
> > -#define VM_FAULT_HWPOISON_LARGE 0x0020  /* Hit poisoned large page. Index 
> > encoded in upper bits */
> > -#define VM_FAULT_SIGSEGV 0x0040
> > -
> > -#define VM_FAULT_NOPAGE  0x0100  /* ->fault installed the pte, not 
> > return page */
> > -#define VM_FAULT_LOCKED  0x0200  /* ->fault locked the returned page */
> > -#define VM_FAULT_RETRY   0x0400  /* ->fault blocked, must retry */
> > -#define VM_FAULT_FALLBACK 0x0800 /* huge page fault failed, fall back 
> > to small */
> > -#define VM_FAULT_DONE_COW   0x1000   /* ->fault has fully handled COW */
> > -#define VM_FAULT_NEEDDSYNC  0x2000   /* ->fault did not modify page tables
> > -  * and needs fsync() to complete (for
> > -  * synchronous page faults in DAX) */
> > -
> > -#define VM_FAULT_ERROR   (VM_FAULT_OOM | VM_FAULT_SIGBUS | 
> > VM_FAULT_SIGSEGV | \
> > -  VM_FAULT_HWPOISON | VM_FAULT_HWPOISON_LARGE | \
> > -  VM_FAULT_FALLBACK)
> > -
> > -#define VM_FAULT_RESULT_TRACE \
> > - { VM_FAULT_OOM, "OOM" }, \
> > - { VM_FAULT_SIGBUS,  "SIGBUS" }, \
> > - { VM_FAULT_MAJOR,   "MAJOR" }, \
> > - { VM_FAULT_WRITE,   "WRITE" }, \
> > - { VM_FAULT_HWPOISON,"HWPOISON" }, \
> > - { VM_FAULT_HWPOISON_LARGE,  "HWPOISON_LARGE" }, \
> > - { VM_FAULT_SIGSEGV, "SIGSEGV" }, \
> > - { VM_FAULT_NOPAGE,  "NOPAGE" }, \
> > - { VM_FAULT_LOCKED,  "LOCKED" }, \
> > - { VM_FAULT_RETRY,   "RETRY" }, \
> > - { VM_FAULT_FALLBACK,"FALLBACK" }, \
> > - { VM_FAULT_DONE_COW,"DONE_COW" }, \
> > - { VM_FAULT_NEEDDSYNC,   "NEEDDSYNC" }
> > -
> > -/* Encode hstate index for a hwpoisoned large page */
> > -#define VM_FAULT_SET_HINDEX(x) ((x) << 12)
> > -#define VM_FAULT_GET_HINDEX(x) (((x) >> 12) & 0xf)
> > -
> > -/*
> >   * Can be called by the pagefault handler when it gets a VM_FAULT_OOM.
> >   */
> >  extern void pagefault_out_of_memory(void);
> > diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
> > index 5ed8f62..cb25016 100644
> >

Re: [PATCH 2/9] arch/arm/mm/dma-mapping.c: Convert to use vm_insert_range

2018-11-25 Thread Souptick Joarder
Hi Russell,

On Thu, Nov 15, 2018 at 9:13 PM Souptick Joarder  wrote:
>
> Convert to use vm_insert_range() to map range of kernel
> memory to user vma.
>
> Signed-off-by: Souptick Joarder 

Any comment on this patch ?

> ---
>  arch/arm/mm/dma-mapping.c | 21 +++--
>  1 file changed, 7 insertions(+), 14 deletions(-)
>
> diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
> index 661fe48..4eec323 100644
> --- a/arch/arm/mm/dma-mapping.c
> +++ b/arch/arm/mm/dma-mapping.c
> @@ -1582,31 +1582,24 @@ static int __arm_iommu_mmap_attrs(struct device *dev, 
> struct vm_area_struct *vma
> void *cpu_addr, dma_addr_t dma_addr, size_t size,
> unsigned long attrs)
>  {
> -   unsigned long uaddr = vma->vm_start;
> -   unsigned long usize = vma->vm_end - vma->vm_start;
> +   unsigned long page_count = vma_pages(vma);
> struct page **pages = __iommu_get_pages(cpu_addr, attrs);
> unsigned long nr_pages = PAGE_ALIGN(size) >> PAGE_SHIFT;
> unsigned long off = vma->vm_pgoff;
> +   int err;
>
> if (!pages)
> return -ENXIO;
>
> -   if (off >= nr_pages || (usize >> PAGE_SHIFT) > nr_pages - off)
> +   if (off >= nr_pages || page_count > nr_pages - off)
> return -ENXIO;
>
> pages += off;
> +   err = vm_insert_range(vma, vma->vm_start, pages, page_count);
> +   if (err)
> +   pr_err("Remapping memory failed: %d\n", err);
>
> -   do {
> -   int ret = vm_insert_page(vma, uaddr, *pages++);
> -   if (ret) {
> -   pr_err("Remapping memory failed: %d\n", ret);
> -   return ret;
> -   }
> -   uaddr += PAGE_SIZE;
> -   usize -= PAGE_SIZE;
> -   } while (usize > 0);
> -
> -   return 0;
> +   return err;
>  }
>  static int arm_iommu_mmap_attrs(struct device *dev,
> struct vm_area_struct *vma, void *cpu_addr,
> --
> 1.9.1
>


Re: [PATCH 1/9] mm: Introduce new vm_insert_range API

2018-11-19 Thread Souptick Joarder
On Mon, Nov 19, 2018 at 9:56 PM Mike Rapoport  wrote:
>
> On Mon, Nov 19, 2018 at 08:43:09PM +0530, Souptick Joarder wrote:
> > Hi Mike,
> >
> > On Sat, Nov 17, 2018 at 8:07 PM Matthew Wilcox  wrote:
> > >
> > > On Sat, Nov 17, 2018 at 12:26:38PM +0530, Souptick Joarder wrote:
> > > > On Fri, Nov 16, 2018 at 11:59 PM Mike Rapoport  
> > > > wrote:
> > > > > > + * vm_insert_range - insert range of kernel pages into user vma
> > > > > > + * @vma: user vma to map to
> > > > > > + * @addr: target user address of this page
> > > > > > + * @pages: pointer to array of source kernel pages
> > > > > > + * @page_count: no. of pages need to insert into user vma
> > > > > > + *
> > > > > > + * This allows drivers to insert range of kernel pages they've 
> > > > > > allocated
> > > > > > + * into a user vma. This is a generic function which drivers can 
> > > > > > use
> > > > > > + * rather than using their own way of mapping range of kernel 
> > > > > > pages into
> > > > > > + * user vma.
> > > > >
> > > > > Please add the return value and context descriptions.
> > > > >
> > > >
> > > > Sure I will wait for some time to get additional review comments and
> > > > add all of those requested changes in v2.
> > >
> > > You could send your proposed wording now which might remove the need
> > > for a v3 if we end up arguing about the wording.
> >
> > Does this description looks good ?
> >
> > /**
> >  * vm_insert_range - insert range of kernel pages into user vma
> >  * @vma: user vma to map to
> >  * @addr: target user address of this page
> >  * @pages: pointer to array of source kernel pages
> >  * @page_count: number of pages need to insert into user vma
> >  *
> >  * This allows drivers to insert range of kernel pages they've allocated
> >  * into a user vma. This is a generic function which drivers can use
> >  * rather than using their own way of mapping range of kernel pages into
> >  * user vma.
> >  *
> >  * Context - Process context. Called by mmap handlers.
>
> Context:
>
> >  * Return - int error value
>
> Return:
>
> >  * 0- OK
> >  * -EINVAL  - Invalid argument
> >  * -ENOMEM  - No memory
> >  * -EFAULT  - Bad address
> >  * -EBUSY   - Device or resource busy
>
> I don't think that elaborate description of error values is needed, just "0
> on success and error code otherwise" would be sufficient.

/**
 * vm_insert_range - insert range of kernel pages into user vma
 * @vma: user vma to map to
 * @addr: target user address of this page
 * @pages: pointer to array of source kernel pages
 * @page_count: number of pages need to insert into user vma
 *
 * This allows drivers to insert range of kernel pages they've allocated
 * into a user vma. This is a generic function which drivers can use
 * rather than using their own way of mapping range of kernel pages into
 * user vma.
 *
 * Context: Process context. Called by mmap handlers.
 * Return: 0 on success and error code otherwise
 */


[PATCH 2/9] arch/arm/mm/dma-mapping.c: Convert to use vm_insert_range

2018-11-15 Thread Souptick Joarder
Convert to use vm_insert_range() to map range of kernel
memory to user vma.

Signed-off-by: Souptick Joarder 
---
 arch/arm/mm/dma-mapping.c | 21 +++--
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index 661fe48..4eec323 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -1582,31 +1582,24 @@ static int __arm_iommu_mmap_attrs(struct device *dev, 
struct vm_area_struct *vma
void *cpu_addr, dma_addr_t dma_addr, size_t size,
unsigned long attrs)
 {
-   unsigned long uaddr = vma->vm_start;
-   unsigned long usize = vma->vm_end - vma->vm_start;
+   unsigned long page_count = vma_pages(vma);
struct page **pages = __iommu_get_pages(cpu_addr, attrs);
unsigned long nr_pages = PAGE_ALIGN(size) >> PAGE_SHIFT;
unsigned long off = vma->vm_pgoff;
+   int err;
 
if (!pages)
return -ENXIO;
 
-   if (off >= nr_pages || (usize >> PAGE_SHIFT) > nr_pages - off)
+   if (off >= nr_pages || page_count > nr_pages - off)
return -ENXIO;
 
pages += off;
+   err = vm_insert_range(vma, vma->vm_start, pages, page_count);
+   if (err)
+   pr_err("Remapping memory failed: %d\n", err);
 
-   do {
-   int ret = vm_insert_page(vma, uaddr, *pages++);
-   if (ret) {
-   pr_err("Remapping memory failed: %d\n", ret);
-   return ret;
-   }
-   uaddr += PAGE_SIZE;
-   usize -= PAGE_SIZE;
-   } while (usize > 0);
-
-   return 0;
+   return err;
 }
 static int arm_iommu_mmap_attrs(struct device *dev,
struct vm_area_struct *vma, void *cpu_addr,
-- 
1.9.1



[PATCH 3/9] drivers/firewire/core-iso.c: Convert to use vm_insert_range

2018-11-15 Thread Souptick Joarder
Convert to use vm_insert_range to map range of kernel memory
to user vma.

Signed-off-by: Souptick Joarder 
Reviewed-by: Matthew Wilcox 
---
 drivers/firewire/core-iso.c | 15 ++-
 1 file changed, 2 insertions(+), 13 deletions(-)

diff --git a/drivers/firewire/core-iso.c b/drivers/firewire/core-iso.c
index 35e784c..7bf28bb 100644
--- a/drivers/firewire/core-iso.c
+++ b/drivers/firewire/core-iso.c
@@ -107,19 +107,8 @@ int fw_iso_buffer_init(struct fw_iso_buffer *buffer, 
struct fw_card *card,
 int fw_iso_buffer_map_vma(struct fw_iso_buffer *buffer,
  struct vm_area_struct *vma)
 {
-   unsigned long uaddr;
-   int i, err;
-
-   uaddr = vma->vm_start;
-   for (i = 0; i < buffer->page_count; i++) {
-   err = vm_insert_page(vma, uaddr, buffer->pages[i]);
-   if (err)
-   return err;
-
-   uaddr += PAGE_SIZE;
-   }
-
-   return 0;
+   return vm_insert_range(vma, vma->vm_start, buffer->pages,
+   buffer->page_count);
 }
 
 void fw_iso_buffer_destroy(struct fw_iso_buffer *buffer,
-- 
1.9.1



Re: [Xen-devel] [PATCH 5/9] drm/xen/xen_drm_front_gem.c: Convert to use vm_insert_range

2018-11-19 Thread Souptick Joarder
On Mon, Nov 19, 2018 at 3:22 PM Oleksandr Andrushchenko
 wrote:
>
> On 11/15/18 5:49 PM, Souptick Joarder wrote:
> > Convert to use vm_insert_range() to map range of kernel
> > memory to user vma.
> >
> > Signed-off-by: Souptick Joarder 
> > Reviewed-by: Matthew Wilcox 
> > ---
> >   drivers/gpu/drm/xen/xen_drm_front_gem.c | 20 ++--
> >   1 file changed, 6 insertions(+), 14 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/xen/xen_drm_front_gem.c 
> > b/drivers/gpu/drm/xen/xen_drm_front_gem.c
> > index 47ff019..a3eade6 100644
> > --- a/drivers/gpu/drm/xen/xen_drm_front_gem.c
> > +++ b/drivers/gpu/drm/xen/xen_drm_front_gem.c
> > @@ -225,8 +225,7 @@ struct drm_gem_object *
> >   static int gem_mmap_obj(struct xen_gem_object *xen_obj,
> >   struct vm_area_struct *vma)
> >   {
> > - unsigned long addr = vma->vm_start;
> > - int i;
> > + int err;
> I would love to keep ret, not err

Sure, will add it in v2.
But I think, err is more appropriate here.

> >
> >   /*
> >* clear the VM_PFNMAP flag that was set by drm_gem_mmap(), and set 
> > the
> > @@ -247,18 +246,11 @@ static int gem_mmap_obj(struct xen_gem_object 
> > *xen_obj,
> >* FIXME: as we insert all the pages now then no .fault handler must
> >* be called, so don't provide one
> >*/
> > - for (i = 0; i < xen_obj->num_pages; i++) {
> > - int ret;
> > -
> > - ret = vm_insert_page(vma, addr, xen_obj->pages[i]);
> > - if (ret < 0) {
> > - DRM_ERROR("Failed to insert pages into vma: %d\n", 
> > ret);
> > - return ret;
> > - }
> > -
> > - addr += PAGE_SIZE;
> > - }
> > - return 0;
> > + err = vm_insert_range(vma, vma->vm_start, xen_obj->pages,
> > + xen_obj->num_pages);
> > + if (err < 0)
> > + DRM_ERROR("Failed to insert pages into vma: %d\n", err);
> > + return err;
> >   }
> >
> >   int xen_drm_front_gem_mmap(struct file *filp, struct vm_area_struct *vma)
>
> With the above fixed,
>
> Reviewed-by: Oleksandr Andrushchenko 
>


Re: [PATCH 1/9] mm: Introduce new vm_insert_range API

2018-11-19 Thread Souptick Joarder
Hi Mike,

On Sat, Nov 17, 2018 at 8:07 PM Matthew Wilcox  wrote:
>
> On Sat, Nov 17, 2018 at 12:26:38PM +0530, Souptick Joarder wrote:
> > On Fri, Nov 16, 2018 at 11:59 PM Mike Rapoport  wrote:
> > > > + * vm_insert_range - insert range of kernel pages into user vma
> > > > + * @vma: user vma to map to
> > > > + * @addr: target user address of this page
> > > > + * @pages: pointer to array of source kernel pages
> > > > + * @page_count: no. of pages need to insert into user vma
> > > > + *
> > > > + * This allows drivers to insert range of kernel pages they've 
> > > > allocated
> > > > + * into a user vma. This is a generic function which drivers can use
> > > > + * rather than using their own way of mapping range of kernel pages 
> > > > into
> > > > + * user vma.
> > >
> > > Please add the return value and context descriptions.
> > >
> >
> > Sure I will wait for some time to get additional review comments and
> > add all of those requested changes in v2.
>
> You could send your proposed wording now which might remove the need
> for a v3 if we end up arguing about the wording.

Does this description looks good ?

/**
 * vm_insert_range - insert range of kernel pages into user vma
 * @vma: user vma to map to
 * @addr: target user address of this page
 * @pages: pointer to array of source kernel pages
 * @page_count: number of pages need to insert into user vma
 *
 * This allows drivers to insert range of kernel pages they've allocated
 * into a user vma. This is a generic function which drivers can use
 * rather than using their own way of mapping range of kernel pages into
 * user vma.
 *
 * Context - Process context. Called by mmap handlers.
 * Return - int error value
 * 0- OK
 * -EINVAL  - Invalid argument
 * -ENOMEM  - No memory
 * -EFAULT  - Bad address
 * -EBUSY   - Device or resource busy
 */


Re: [PATCH v3] mm: Create the new vm_fault_t type

2018-11-13 Thread Souptick Joarder
On Tue, Nov 6, 2018 at 5:33 PM Souptick Joarder  wrote:
>
> Page fault handlers are supposed to return VM_FAULT codes,
> but some drivers/file systems mistakenly return error
> numbers. Now that all drivers/file systems have been converted
> to use the vm_fault_t return type, change the type definition
> to no longer be compatible with 'int'. By making it an unsigned
> int, the function prototype becomes incompatible with a function
> which returns int. Sparse will detect any attempts to return a
> value which is not a VM_FAULT code.
>
> VM_FAULT_SET_HINDEX and VM_FAULT_GET_HINDEX values are changed
> to avoid conflict with other VM_FAULT codes.
>
> Signed-off-by: Souptick Joarder 

Any further comment on this patch ?
> ---
> v2: Updated the change log and corrected the document part.
> name added to the enum that kernel-doc able to parse it.
>
> v3: Corrected the documentation.
>
>  include/linux/mm.h   | 46 --
>  include/linux/mm_types.h | 73 
> +++-
>  2 files changed, 72 insertions(+), 47 deletions(-)
>
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index fcf9cc9..511a3ce 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -1267,52 +1267,6 @@ static inline void clear_page_pfmemalloc(struct page 
> *page)
>  }
>
>  /*
> - * Different kinds of faults, as returned by handle_mm_fault().
> - * Used to decide whether a process gets delivered SIGBUS or
> - * just gets major/minor fault counters bumped up.
> - */
> -
> -#define VM_FAULT_OOM   0x0001
> -#define VM_FAULT_SIGBUS0x0002
> -#define VM_FAULT_MAJOR 0x0004
> -#define VM_FAULT_WRITE 0x0008  /* Special case for get_user_pages */
> -#define VM_FAULT_HWPOISON 0x0010   /* Hit poisoned small page */
> -#define VM_FAULT_HWPOISON_LARGE 0x0020  /* Hit poisoned large page. Index 
> encoded in upper bits */
> -#define VM_FAULT_SIGSEGV 0x0040
> -
> -#define VM_FAULT_NOPAGE0x0100  /* ->fault installed the pte, not 
> return page */
> -#define VM_FAULT_LOCKED0x0200  /* ->fault locked the returned page */
> -#define VM_FAULT_RETRY 0x0400  /* ->fault blocked, must retry */
> -#define VM_FAULT_FALLBACK 0x0800   /* huge page fault failed, fall back 
> to small */
> -#define VM_FAULT_DONE_COW   0x1000 /* ->fault has fully handled COW */
> -#define VM_FAULT_NEEDDSYNC  0x2000 /* ->fault did not modify page tables
> -* and needs fsync() to complete (for
> -* synchronous page faults in DAX) */
> -
> -#define VM_FAULT_ERROR (VM_FAULT_OOM | VM_FAULT_SIGBUS | VM_FAULT_SIGSEGV | \
> -VM_FAULT_HWPOISON | VM_FAULT_HWPOISON_LARGE | \
> -VM_FAULT_FALLBACK)
> -
> -#define VM_FAULT_RESULT_TRACE \
> -   { VM_FAULT_OOM, "OOM" }, \
> -   { VM_FAULT_SIGBUS,  "SIGBUS" }, \
> -   { VM_FAULT_MAJOR,   "MAJOR" }, \
> -   { VM_FAULT_WRITE,   "WRITE" }, \
> -   { VM_FAULT_HWPOISON,"HWPOISON" }, \
> -   { VM_FAULT_HWPOISON_LARGE,  "HWPOISON_LARGE" }, \
> -   { VM_FAULT_SIGSEGV, "SIGSEGV" }, \
> -   { VM_FAULT_NOPAGE,  "NOPAGE" }, \
> -   { VM_FAULT_LOCKED,  "LOCKED" }, \
> -   { VM_FAULT_RETRY,   "RETRY" }, \
> -   { VM_FAULT_FALLBACK,"FALLBACK" }, \
> -   { VM_FAULT_DONE_COW,"DONE_COW" }, \
> -   { VM_FAULT_NEEDDSYNC,   "NEEDDSYNC" }
> -
> -/* Encode hstate index for a hwpoisoned large page */
> -#define VM_FAULT_SET_HINDEX(x) ((x) << 12)
> -#define VM_FAULT_GET_HINDEX(x) (((x) >> 12) & 0xf)
> -
> -/*
>   * Can be called by the pagefault handler when it gets a VM_FAULT_OOM.
>   */
>  extern void pagefault_out_of_memory(void);
> diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
> index 5ed8f62..cb25016 100644
> --- a/include/linux/mm_types.h
> +++ b/include/linux/mm_types.h
> @@ -22,7 +22,6 @@
>  #endif
>  #define AT_VECTOR_SIZE (2*(AT_VECTOR_SIZE_ARCH + AT_VECTOR_SIZE_BASE + 1))
>
> -typedef int vm_fault_t;
>
>  struct address_space;
>  struct mem_cgroup;
> @@ -609,6 +608,78 @@ static inline bool mm_tlb_flush_nested(struct mm_struct 
> *mm)
>
>  struct vm_fault;
>
> +/**
> + * typedef vm_fault_t - Return type for page fault handlers.
> + *
> + * Page fault handlers return a bitmask of %VM_FAULT values.
> + */
>

[PATCH v3 2/9] arch/arm/mm/dma-mapping.c: Convert to use vm_insert_range

2018-12-06 Thread Souptick Joarder
Convert to use vm_insert_range() to map range of kernel
memory to user vma.

Signed-off-by: Souptick Joarder 
---
 arch/arm/mm/dma-mapping.c | 21 +++--
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index 661fe48..4eec323 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -1582,31 +1582,24 @@ static int __arm_iommu_mmap_attrs(struct device *dev, 
struct vm_area_struct *vma
void *cpu_addr, dma_addr_t dma_addr, size_t size,
unsigned long attrs)
 {
-   unsigned long uaddr = vma->vm_start;
-   unsigned long usize = vma->vm_end - vma->vm_start;
+   unsigned long page_count = vma_pages(vma);
struct page **pages = __iommu_get_pages(cpu_addr, attrs);
unsigned long nr_pages = PAGE_ALIGN(size) >> PAGE_SHIFT;
unsigned long off = vma->vm_pgoff;
+   int err;
 
if (!pages)
return -ENXIO;
 
-   if (off >= nr_pages || (usize >> PAGE_SHIFT) > nr_pages - off)
+   if (off >= nr_pages || page_count > nr_pages - off)
return -ENXIO;
 
pages += off;
+   err = vm_insert_range(vma, vma->vm_start, pages, page_count);
+   if (err)
+   pr_err("Remapping memory failed: %d\n", err);
 
-   do {
-   int ret = vm_insert_page(vma, uaddr, *pages++);
-   if (ret) {
-   pr_err("Remapping memory failed: %d\n", ret);
-   return ret;
-   }
-   uaddr += PAGE_SIZE;
-   usize -= PAGE_SIZE;
-   } while (usize > 0);
-
-   return 0;
+   return err;
 }
 static int arm_iommu_mmap_attrs(struct device *dev,
struct vm_area_struct *vma, void *cpu_addr,
-- 
1.9.1



[PATCH v3 3/9] drivers/firewire/core-iso.c: Convert to use vm_insert_range

2018-12-06 Thread Souptick Joarder
Convert to use vm_insert_range to map range of kernel memory
to user vma.

Signed-off-by: Souptick Joarder 
Reviewed-by: Matthew Wilcox 
---
 drivers/firewire/core-iso.c | 15 ++-
 1 file changed, 2 insertions(+), 13 deletions(-)

diff --git a/drivers/firewire/core-iso.c b/drivers/firewire/core-iso.c
index 35e784c..7bf28bb 100644
--- a/drivers/firewire/core-iso.c
+++ b/drivers/firewire/core-iso.c
@@ -107,19 +107,8 @@ int fw_iso_buffer_init(struct fw_iso_buffer *buffer, 
struct fw_card *card,
 int fw_iso_buffer_map_vma(struct fw_iso_buffer *buffer,
  struct vm_area_struct *vma)
 {
-   unsigned long uaddr;
-   int i, err;
-
-   uaddr = vma->vm_start;
-   for (i = 0; i < buffer->page_count; i++) {
-   err = vm_insert_page(vma, uaddr, buffer->pages[i]);
-   if (err)
-   return err;
-
-   uaddr += PAGE_SIZE;
-   }
-
-   return 0;
+   return vm_insert_range(vma, vma->vm_start, buffer->pages,
+   buffer->page_count);
 }
 
 void fw_iso_buffer_destroy(struct fw_iso_buffer *buffer,
-- 
1.9.1



Re: [PATCH v3 2/9] arch/arm/mm/dma-mapping.c: Convert to use vm_insert_range

2018-12-08 Thread Souptick Joarder
Hi Robin,

On Fri, Dec 7, 2018 at 12:07 AM Souptick Joarder  wrote:
>
> Convert to use vm_insert_range() to map range of kernel
> memory to user vma.
>
> Signed-off-by: Souptick Joarder 
> ---
>  arch/arm/mm/dma-mapping.c | 21 +++--
>  1 file changed, 7 insertions(+), 14 deletions(-)
>
> diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
> index 661fe48..4eec323 100644
> --- a/arch/arm/mm/dma-mapping.c
> +++ b/arch/arm/mm/dma-mapping.c
> @@ -1582,31 +1582,24 @@ static int __arm_iommu_mmap_attrs(struct device *dev, 
> struct vm_area_struct *vma
> void *cpu_addr, dma_addr_t dma_addr, size_t size,
> unsigned long attrs)
>  {
> -   unsigned long uaddr = vma->vm_start;
> -   unsigned long usize = vma->vm_end - vma->vm_start;
> +   unsigned long page_count = vma_pages(vma);
> struct page **pages = __iommu_get_pages(cpu_addr, attrs);
> unsigned long nr_pages = PAGE_ALIGN(size) >> PAGE_SHIFT;
> unsigned long off = vma->vm_pgoff;
> +   int err;
>
> if (!pages)
> return -ENXIO;
>
> -   if (off >= nr_pages || (usize >> PAGE_SHIFT) > nr_pages - off)
> +   if (off >= nr_pages || page_count > nr_pages - off)
> return -ENXIO;
>
> pages += off;
> +   err = vm_insert_range(vma, vma->vm_start, pages, page_count);

Just to clarify, do we need to adjust page_count with vma->vm_pgoff as
original code
have not consider it and run the loop for entire range irrespective of
vma->vm_pgoff value ?

> +   if (err)
> +   pr_err("Remapping memory failed: %d\n", err);
>
> -   do {
> -   int ret = vm_insert_page(vma, uaddr, *pages++);
> -   if (ret) {
> -   pr_err("Remapping memory failed: %d\n", ret);
> -   return ret;
> -   }
> -   uaddr += PAGE_SIZE;
> -   usize -= PAGE_SIZE;
> -   } while (usize > 0);
> -
> -   return 0;
> +   return err;
>  }
>  static int arm_iommu_mmap_attrs(struct device *dev,
> struct vm_area_struct *vma, void *cpu_addr,
> --
> 1.9.1
>


[PATCH v3 0/9] Use vm_insert_range

2018-12-06 Thread Souptick Joarder
Previouly drivers have their own way of mapping range of
kernel pages/memory into user vma and this was done by
invoking vm_insert_page() within a loop.

As this pattern is common across different drivers, it can
be generalized by creating a new function and use it across
the drivers.

vm_insert_range is the new API which will be used to map a
range of kernel memory/pages to user vma.

All the applicable places are converted to use new vm_insert_range
in this patch series.

v1 -> v2:
Address review comment on mm/memory.c. Add EXPORT_SYMBOL
for vm_insert_range and corrected the documentation part
for this API.

In drivers/gpu/drm/xen/xen_drm_front_gem.c, replace err
with ret as suggested.

In drivers/iommu/dma-iommu.c, handle the scenario of partial
mmap() of large buffer by passing *pages + vma->vm_pgoff* to
vm_insert_range().

v2 -> v3:
Declaration of vm_insert_range() moved to include/linux/mm.h

Souptick Joarder (9):
  mm: Introduce new vm_insert_range API
  arch/arm/mm/dma-mapping.c: Convert to use vm_insert_range
  drivers/firewire/core-iso.c: Convert to use vm_insert_range
  drm/rockchip/rockchip_drm_gem.c: Convert to use vm_insert_range
  drm/xen/xen_drm_front_gem.c: Convert to use vm_insert_range
  iommu/dma-iommu.c: Convert to use vm_insert_range
  videobuf2/videobuf2-dma-sg.c: Convert to use vm_insert_range
  xen/gntdev.c: Convert to use vm_insert_range
  xen/privcmd-buf.c: Convert to use vm_insert_range

 arch/arm/mm/dma-mapping.c | 21 +
 drivers/firewire/core-iso.c   | 15 ++---
 drivers/gpu/drm/rockchip/rockchip_drm_gem.c   | 20 ++--
 drivers/gpu/drm/xen/xen_drm_front_gem.c   | 20 
 drivers/iommu/dma-iommu.c | 13 ++--
 drivers/media/common/videobuf2/videobuf2-dma-sg.c | 23 +-
 drivers/xen/gntdev.c  | 11 +++
 drivers/xen/privcmd-buf.c |  8 ++---
 include/linux/mm.h|  2 ++
 mm/memory.c   | 38 +++
 mm/nommu.c|  7 +
 11 files changed, 80 insertions(+), 98 deletions(-)

-- 
1.9.1



[PATCH v3 1/9] mm: Introduce new vm_insert_range API

2018-12-06 Thread Souptick Joarder
Previouly drivers have their own way of mapping range of
kernel pages/memory into user vma and this was done by
invoking vm_insert_page() within a loop.

As this pattern is common across different drivers, it can
be generalized by creating a new function and use it across
the drivers.

vm_insert_range is the new API which will be used to map a
range of kernel memory/pages to user vma.

This API is tested by Heiko for Rockchip drm driver, on rk3188,
rk3288, rk3328 and rk3399 with graphics.

Signed-off-by: Souptick Joarder 
Reviewed-by: Matthew Wilcox 
Reviewed-by: Mike Rapoport 
Tested-by: Heiko Stuebner 
---
 include/linux/mm.h |  2 ++
 mm/memory.c| 38 ++
 mm/nommu.c |  7 +++
 3 files changed, 47 insertions(+)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index fcf9cc9..2bc399f 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -2506,6 +2506,8 @@ unsigned long change_prot_numa(struct vm_area_struct *vma,
 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
unsigned long pfn, unsigned long size, pgprot_t);
 int vm_insert_page(struct vm_area_struct *, unsigned long addr, struct page *);
+int vm_insert_range(struct vm_area_struct *vma, unsigned long addr,
+   struct page **pages, unsigned long page_count);
 vm_fault_t vmf_insert_pfn(struct vm_area_struct *vma, unsigned long addr,
unsigned long pfn);
 vm_fault_t vmf_insert_pfn_prot(struct vm_area_struct *vma, unsigned long addr,
diff --git a/mm/memory.c b/mm/memory.c
index 15c417e..84ea46c 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -1478,6 +1478,44 @@ static int insert_page(struct vm_area_struct *vma, 
unsigned long addr,
 }
 
 /**
+ * vm_insert_range - insert range of kernel pages into user vma
+ * @vma: user vma to map to
+ * @addr: target user address of this page
+ * @pages: pointer to array of source kernel pages
+ * @page_count: number of pages need to insert into user vma
+ *
+ * This allows drivers to insert range of kernel pages they've allocated
+ * into a user vma. This is a generic function which drivers can use
+ * rather than using their own way of mapping range of kernel pages into
+ * user vma.
+ *
+ * If we fail to insert any page into the vma, the function will return
+ * immediately leaving any previously-inserted pages present.  Callers
+ * from the mmap handler may immediately return the error as their caller
+ * will destroy the vma, removing any successfully-inserted pages. Other
+ * callers should make their own arrangements for calling unmap_region().
+ *
+ * Context: Process context. Called by mmap handlers.
+ * Return: 0 on success and error code otherwise
+ */
+int vm_insert_range(struct vm_area_struct *vma, unsigned long addr,
+   struct page **pages, unsigned long page_count)
+{
+   unsigned long uaddr = addr;
+   int ret = 0, i;
+
+   for (i = 0; i < page_count; i++) {
+   ret = vm_insert_page(vma, uaddr, pages[i]);
+   if (ret < 0)
+   return ret;
+   uaddr += PAGE_SIZE;
+   }
+
+   return ret;
+}
+EXPORT_SYMBOL(vm_insert_range);
+
+/**
  * vm_insert_page - insert single page into user vma
  * @vma: user vma to map to
  * @addr: target user address of this page
diff --git a/mm/nommu.c b/mm/nommu.c
index 749276b..d6ef5c7 100644
--- a/mm/nommu.c
+++ b/mm/nommu.c
@@ -473,6 +473,13 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned 
long addr,
 }
 EXPORT_SYMBOL(vm_insert_page);
 
+int vm_insert_range(struct vm_area_struct *vma, unsigned long addr,
+   struct page **pages, unsigned long page_count)
+{
+   return -EINVAL;
+}
+EXPORT_SYMBOL(vm_insert_range);
+
 /*
  *  sys_brk() for the most part doesn't need the global kernel
  *  lock, except when an application is doing something nasty
-- 
1.9.1



[PATCH v3 4/9] drm/rockchip/rockchip_drm_gem.c: Convert to use vm_insert_range

2018-12-06 Thread Souptick Joarder
Convert to use vm_insert_range() to map range of kernel
memory to user vma.

Signed-off-by: Souptick Joarder 
Tested-by: Heiko Stuebner 
Acked-by: Heiko Stuebner 
---
 drivers/gpu/drm/rockchip/rockchip_drm_gem.c | 20 ++--
 1 file changed, 2 insertions(+), 18 deletions(-)

diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_gem.c 
b/drivers/gpu/drm/rockchip/rockchip_drm_gem.c
index a8db758..2cb83bb 100644
--- a/drivers/gpu/drm/rockchip/rockchip_drm_gem.c
+++ b/drivers/gpu/drm/rockchip/rockchip_drm_gem.c
@@ -221,26 +221,10 @@ static int rockchip_drm_gem_object_mmap_iommu(struct 
drm_gem_object *obj,
  struct vm_area_struct *vma)
 {
struct rockchip_gem_object *rk_obj = to_rockchip_obj(obj);
-   unsigned int i, count = obj->size >> PAGE_SHIFT;
unsigned long user_count = vma_pages(vma);
-   unsigned long uaddr = vma->vm_start;
-   unsigned long offset = vma->vm_pgoff;
-   unsigned long end = user_count + offset;
-   int ret;
-
-   if (user_count == 0)
-   return -ENXIO;
-   if (end > count)
-   return -ENXIO;
 
-   for (i = offset; i < end; i++) {
-   ret = vm_insert_page(vma, uaddr, rk_obj->pages[i]);
-   if (ret)
-   return ret;
-   uaddr += PAGE_SIZE;
-   }
-
-   return 0;
+   return vm_insert_range(vma, vma->vm_start, rk_obj->pages,
+   user_count);
 }
 
 static int rockchip_drm_gem_object_mmap_dma(struct drm_gem_object *obj,
-- 
1.9.1



[PATCH v3 5/9] drm/xen/xen_drm_front_gem.c: Convert to use vm_insert_range

2018-12-06 Thread Souptick Joarder
Convert to use vm_insert_range() to map range of kernel
memory to user vma.

Signed-off-by: Souptick Joarder 
Reviewed-by: Matthew Wilcox 
Reviewed-by: Oleksandr Andrushchenko 
---
 drivers/gpu/drm/xen/xen_drm_front_gem.c | 20 ++--
 1 file changed, 6 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/xen/xen_drm_front_gem.c 
b/drivers/gpu/drm/xen/xen_drm_front_gem.c
index 47ff019..c21e5d1 100644
--- a/drivers/gpu/drm/xen/xen_drm_front_gem.c
+++ b/drivers/gpu/drm/xen/xen_drm_front_gem.c
@@ -225,8 +225,7 @@ struct drm_gem_object *
 static int gem_mmap_obj(struct xen_gem_object *xen_obj,
struct vm_area_struct *vma)
 {
-   unsigned long addr = vma->vm_start;
-   int i;
+   int ret;
 
/*
 * clear the VM_PFNMAP flag that was set by drm_gem_mmap(), and set the
@@ -247,18 +246,11 @@ static int gem_mmap_obj(struct xen_gem_object *xen_obj,
 * FIXME: as we insert all the pages now then no .fault handler must
 * be called, so don't provide one
 */
-   for (i = 0; i < xen_obj->num_pages; i++) {
-   int ret;
-
-   ret = vm_insert_page(vma, addr, xen_obj->pages[i]);
-   if (ret < 0) {
-   DRM_ERROR("Failed to insert pages into vma: %d\n", ret);
-   return ret;
-   }
-
-   addr += PAGE_SIZE;
-   }
-   return 0;
+   ret = vm_insert_range(vma, vma->vm_start, xen_obj->pages,
+   xen_obj->num_pages);
+   if (ret < 0)
+   DRM_ERROR("Failed to insert pages into vma: %d\n", ret);
+   return ret;
 }
 
 int xen_drm_front_gem_mmap(struct file *filp, struct vm_area_struct *vma)
-- 
1.9.1



[PATCH v3 6/9] iommu/dma-iommu.c: Convert to use vm_insert_range

2018-12-06 Thread Souptick Joarder
Convert to use vm_insert_range() to map range of kernel
memory to user vma.

Signed-off-by: Souptick Joarder 
Reviewed-by: Matthew Wilcox 
---
 drivers/iommu/dma-iommu.c | 13 +++--
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
index d1b0475..a2c65e2 100644
--- a/drivers/iommu/dma-iommu.c
+++ b/drivers/iommu/dma-iommu.c
@@ -622,17 +622,10 @@ struct page **iommu_dma_alloc(struct device *dev, size_t 
size, gfp_t gfp,
 
 int iommu_dma_mmap(struct page **pages, size_t size, struct vm_area_struct 
*vma)
 {
-   unsigned long uaddr = vma->vm_start;
-   unsigned int i, count = PAGE_ALIGN(size) >> PAGE_SHIFT;
-   int ret = -ENXIO;
+   unsigned long count = PAGE_ALIGN(size) >> PAGE_SHIFT;
 
-   for (i = vma->vm_pgoff; i < count && uaddr < vma->vm_end; i++) {
-   ret = vm_insert_page(vma, uaddr, pages[i]);
-   if (ret)
-   break;
-   uaddr += PAGE_SIZE;
-   }
-   return ret;
+   return vm_insert_range(vma, vma->vm_start,
+   pages + vma->vm_pgoff, count);
 }
 
 static dma_addr_t __iommu_dma_map(struct device *dev, phys_addr_t phys,
-- 
1.9.1



[PATCH v3 7/9] videobuf2/videobuf2-dma-sg.c: Convert to use vm_insert_range

2018-12-06 Thread Souptick Joarder
Convert to use vm_insert_range to map range of kernel memory
to user vma.

Signed-off-by: Souptick Joarder 
Reviewed-by: Matthew Wilcox 
Acked-by: Marek Szyprowski 
---
 drivers/media/common/videobuf2/videobuf2-dma-sg.c | 23 +++
 1 file changed, 7 insertions(+), 16 deletions(-)

diff --git a/drivers/media/common/videobuf2/videobuf2-dma-sg.c 
b/drivers/media/common/videobuf2/videobuf2-dma-sg.c
index 015e737..898adef 100644
--- a/drivers/media/common/videobuf2/videobuf2-dma-sg.c
+++ b/drivers/media/common/videobuf2/videobuf2-dma-sg.c
@@ -328,28 +328,19 @@ static unsigned int vb2_dma_sg_num_users(void *buf_priv)
 static int vb2_dma_sg_mmap(void *buf_priv, struct vm_area_struct *vma)
 {
struct vb2_dma_sg_buf *buf = buf_priv;
-   unsigned long uaddr = vma->vm_start;
-   unsigned long usize = vma->vm_end - vma->vm_start;
-   int i = 0;
+   unsigned long page_count = vma_pages(vma);
+   int err;
 
if (!buf) {
printk(KERN_ERR "No memory to map\n");
return -EINVAL;
}
 
-   do {
-   int ret;
-
-   ret = vm_insert_page(vma, uaddr, buf->pages[i++]);
-   if (ret) {
-   printk(KERN_ERR "Remapping memory, error: %d\n", ret);
-   return ret;
-   }
-
-   uaddr += PAGE_SIZE;
-   usize -= PAGE_SIZE;
-   } while (usize > 0);
-
+   err = vm_insert_range(vma, vma->vm_start, buf->pages, page_count);
+   if (err) {
+   printk(KERN_ERR "Remapping memory, error: %d\n", err);
+   return err;
+   }
 
/*
 * Use common vm_area operations to track buffer refcount.
-- 
1.9.1



[PATCH v3 8/9] xen/gntdev.c: Convert to use vm_insert_range

2018-12-06 Thread Souptick Joarder
Convert to use vm_insert_range() to map range of kernel
memory to user vma.

Signed-off-by: Souptick Joarder 
Reviewed-by: Matthew Wilcox 
Reviewed-by: Boris Ostrovsky 
---
 drivers/xen/gntdev.c | 11 ---
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/drivers/xen/gntdev.c b/drivers/xen/gntdev.c
index b0b02a5..430d4cb 100644
--- a/drivers/xen/gntdev.c
+++ b/drivers/xen/gntdev.c
@@ -1084,7 +1084,7 @@ static int gntdev_mmap(struct file *flip, struct 
vm_area_struct *vma)
int index = vma->vm_pgoff;
int count = vma_pages(vma);
struct gntdev_grant_map *map;
-   int i, err = -EINVAL;
+   int err = -EINVAL;
 
if ((vma->vm_flags & VM_WRITE) && !(vma->vm_flags & VM_SHARED))
return -EINVAL;
@@ -1145,12 +1145,9 @@ static int gntdev_mmap(struct file *flip, struct 
vm_area_struct *vma)
goto out_put_map;
 
if (!use_ptemod) {
-   for (i = 0; i < count; i++) {
-   err = vm_insert_page(vma, vma->vm_start + i*PAGE_SIZE,
-   map->pages[i]);
-   if (err)
-   goto out_put_map;
-   }
+   err = vm_insert_range(vma, vma->vm_start, map->pages, count);
+   if (err)
+   goto out_put_map;
} else {
 #ifdef CONFIG_X86
/*
-- 
1.9.1



[PATCH v3 9/9] xen/privcmd-buf.c: Convert to use vm_insert_range

2018-12-06 Thread Souptick Joarder
Convert to use vm_insert_range() to map range of kernel
memory to user vma.

Signed-off-by: Souptick Joarder 
Reviewed-by: Matthew Wilcox 
Reviewed-by: Boris Ostrovsky 
---
 drivers/xen/privcmd-buf.c | 8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/xen/privcmd-buf.c b/drivers/xen/privcmd-buf.c
index df1ed37..8d8255b 100644
--- a/drivers/xen/privcmd-buf.c
+++ b/drivers/xen/privcmd-buf.c
@@ -180,12 +180,8 @@ static int privcmd_buf_mmap(struct file *file, struct 
vm_area_struct *vma)
if (vma_priv->n_pages != count)
ret = -ENOMEM;
else
-   for (i = 0; i < vma_priv->n_pages; i++) {
-   ret = vm_insert_page(vma, vma->vm_start + i * PAGE_SIZE,
-vma_priv->pages[i]);
-   if (ret)
-   break;
-   }
+   ret = vm_insert_range(vma, vma->vm_start, vma_priv->pages,
+   vma_priv->n_pages);
 
if (ret)
privcmd_buf_vmapriv_free(vma_priv);
-- 
1.9.1



Re: [PATCH v3 1/9] mm: Introduce new vm_insert_range API

2018-12-07 Thread Souptick Joarder
On Fri, Dec 7, 2018 at 10:41 PM Matthew Wilcox  wrote:
>
> On Fri, Dec 07, 2018 at 03:34:56PM +, Robin Murphy wrote:
> > > +int vm_insert_range(struct vm_area_struct *vma, unsigned long addr,
> > > +   struct page **pages, unsigned long page_count)
> > > +{
> > > +   unsigned long uaddr = addr;
> > > +   int ret = 0, i;
> >
> > Some of the sites being replaced were effectively ensuring that vma and
> > pages were mutually compatible as an initial condition - would it be worth
> > adding something here for robustness, e.g.:
> >
> > + if (page_count != vma_pages(vma))
> > + return -ENXIO;
>
> I think we want to allow this to be used to populate part of a VMA.
> So perhaps:
>
> if (page_count > vma_pages(vma))
> return -ENXIO;

Ok, This can be added.

I think Patch [2/9] is the only leftover place where this
check could be removed.


Re: [PATCH v3 4/9] drm/rockchip/rockchip_drm_gem.c: Convert to use vm_insert_range

2018-12-07 Thread Souptick Joarder
On Fri, Dec 7, 2018 at 8:20 PM Robin Murphy  wrote:
>
> On 06/12/2018 18:42, Souptick Joarder wrote:
> > Convert to use vm_insert_range() to map range of kernel
> > memory to user vma.
> >
> > Signed-off-by: Souptick Joarder 
> > Tested-by: Heiko Stuebner 
> > Acked-by: Heiko Stuebner 
> > ---
> >   drivers/gpu/drm/rockchip/rockchip_drm_gem.c | 20 ++--
> >   1 file changed, 2 insertions(+), 18 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_gem.c 
> > b/drivers/gpu/drm/rockchip/rockchip_drm_gem.c
> > index a8db758..2cb83bb 100644
> > --- a/drivers/gpu/drm/rockchip/rockchip_drm_gem.c
> > +++ b/drivers/gpu/drm/rockchip/rockchip_drm_gem.c
> > @@ -221,26 +221,10 @@ static int rockchip_drm_gem_object_mmap_iommu(struct 
> > drm_gem_object *obj,
> > struct vm_area_struct *vma)
> >   {
> >   struct rockchip_gem_object *rk_obj = to_rockchip_obj(obj);
> > - unsigned int i, count = obj->size >> PAGE_SHIFT;
> >   unsigned long user_count = vma_pages(vma);
> > - unsigned long uaddr = vma->vm_start;
> > - unsigned long offset = vma->vm_pgoff;
> > - unsigned long end = user_count + offset;
> > - int ret;
> > -
> > - if (user_count == 0)
> > - return -ENXIO;
> > - if (end > count)
> > - return -ENXIO;
> >
> > - for (i = offset; i < end; i++) {
> > - ret = vm_insert_page(vma, uaddr, rk_obj->pages[i]);
> > - if (ret)
> > - return ret;
> > - uaddr += PAGE_SIZE;
> > - }
> > -
> > - return 0;
> > + return vm_insert_range(vma, vma->vm_start, rk_obj->pages,
> > + user_count);
>
> We're losing vm_pgoff handling here, which given the implication in
> 57de50af162b, may well be a regression for at least some combination of
> GPU and userspace driver (I assume that commit was in the context of
> some version of the Arm Mali driver, possibly on RK3288).

In commit  57de50af162b, vma->vm_pgoff = 0 for GEM mmap handler context
and removing it from common path which means if call stack looks like
rockchip_gem_mmap_buf() -> rockchip_drm_gem_object_mmap() ->
rockchip_drm_gem_object_mmap_iommu(), then we might have a non zero
vma->vm_pgoff context which is not handled.

This is the problem you are pointing ? right ?


Re: [PATCH v3 6/9] iommu/dma-iommu.c: Convert to use vm_insert_range

2018-12-07 Thread Souptick Joarder
On Fri, Dec 7, 2018 at 7:17 PM Robin Murphy  wrote:
>
> On 06/12/2018 18:43, Souptick Joarder wrote:
> > Convert to use vm_insert_range() to map range of kernel
> > memory to user vma.
> >
> > Signed-off-by: Souptick Joarder 
> > Reviewed-by: Matthew Wilcox 
> > ---
> >   drivers/iommu/dma-iommu.c | 13 +++--
> >   1 file changed, 3 insertions(+), 10 deletions(-)
> >
> > diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
> > index d1b0475..a2c65e2 100644
> > --- a/drivers/iommu/dma-iommu.c
> > +++ b/drivers/iommu/dma-iommu.c
> > @@ -622,17 +622,10 @@ struct page **iommu_dma_alloc(struct device *dev, 
> > size_t size, gfp_t gfp,
> >
> >   int iommu_dma_mmap(struct page **pages, size_t size, struct 
> > vm_area_struct *vma)
> >   {
> > - unsigned long uaddr = vma->vm_start;
> > - unsigned int i, count = PAGE_ALIGN(size) >> PAGE_SHIFT;
> > - int ret = -ENXIO;
> > + unsigned long count = PAGE_ALIGN(size) >> PAGE_SHIFT;
> >
> > - for (i = vma->vm_pgoff; i < count && uaddr < vma->vm_end; i++) {
> > - ret = vm_insert_page(vma, uaddr, pages[i]);
> > - if (ret)
> > - break;
> > - uaddr += PAGE_SIZE;
> > - }
> > - return ret;
> > + return vm_insert_range(vma, vma->vm_start,
> > + pages + vma->vm_pgoff, count);
>
> You also need to adjust count to compensate for the pages skipped by
> vm_pgoff, otherwise you've got an out-of-bounds dereference triggered
> from userspace, which is pretty high up the "not good" scale (not to
> mention the entire call would then propagate -EFAULT back from
> vm_insert_page() and thus always appear to fail for nonzero offsets).

So this should something similar to ->

return vm_insert_range(vma, vma->vm_start,
pages + vma->vm_pgoff, count - vma->vm_pgoff);


Re: [PATCH v3 1/9] mm: Introduce new vm_insert_range API

2018-12-07 Thread Souptick Joarder
On Sat, Dec 8, 2018 at 2:40 AM Robin Murphy  wrote:
>
> On 2018-12-07 7:28 pm, Souptick Joarder wrote:
> > On Fri, Dec 7, 2018 at 10:41 PM Matthew Wilcox  wrote:
> >>
> >> On Fri, Dec 07, 2018 at 03:34:56PM +, Robin Murphy wrote:
> >>>> +int vm_insert_range(struct vm_area_struct *vma, unsigned long addr,
> >>>> +   struct page **pages, unsigned long page_count)
> >>>> +{
> >>>> +   unsigned long uaddr = addr;
> >>>> +   int ret = 0, i;
> >>>
> >>> Some of the sites being replaced were effectively ensuring that vma and
> >>> pages were mutually compatible as an initial condition - would it be worth
> >>> adding something here for robustness, e.g.:
> >>>
> >>> + if (page_count != vma_pages(vma))
> >>> + return -ENXIO;
> >>
> >> I think we want to allow this to be used to populate part of a VMA.
> >> So perhaps:
> >>
> >>  if (page_count > vma_pages(vma))
> >>  return -ENXIO;
> >
> > Ok, This can be added.
> >
> > I think Patch [2/9] is the only leftover place where this
> > check could be removed.
>
> Right, 9/9 could also have relied on my stricter check here, but since
> it's really testing whether it actually managed to allocate vma_pages()
> worth of pages earlier, Matthew's more lenient version won't help for
> that one.


(Why privcmd_buf_mmap() doesn't clean up and return an error
> as soon as that allocation loop fails, without taking the mutex under
> which it still does a bunch more pointless work to only undo it again,
> is a mind-boggling mystery, but that's not our problem here...)

I think some clean up can be done here in a separate patch.


[PATCH v2 2/9] arch/arm/mm/dma-mapping.c: Convert to use vm_insert_range

2018-12-01 Thread Souptick Joarder
Convert to use vm_insert_range() to map range of kernel
memory to user vma.

Signed-off-by: Souptick Joarder 
---
 arch/arm/mm/dma-mapping.c | 21 +++--
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index 661fe48..4eec323 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -1582,31 +1582,24 @@ static int __arm_iommu_mmap_attrs(struct device *dev, 
struct vm_area_struct *vma
void *cpu_addr, dma_addr_t dma_addr, size_t size,
unsigned long attrs)
 {
-   unsigned long uaddr = vma->vm_start;
-   unsigned long usize = vma->vm_end - vma->vm_start;
+   unsigned long page_count = vma_pages(vma);
struct page **pages = __iommu_get_pages(cpu_addr, attrs);
unsigned long nr_pages = PAGE_ALIGN(size) >> PAGE_SHIFT;
unsigned long off = vma->vm_pgoff;
+   int err;
 
if (!pages)
return -ENXIO;
 
-   if (off >= nr_pages || (usize >> PAGE_SHIFT) > nr_pages - off)
+   if (off >= nr_pages || page_count > nr_pages - off)
return -ENXIO;
 
pages += off;
+   err = vm_insert_range(vma, vma->vm_start, pages, page_count);
+   if (err)
+   pr_err("Remapping memory failed: %d\n", err);
 
-   do {
-   int ret = vm_insert_page(vma, uaddr, *pages++);
-   if (ret) {
-   pr_err("Remapping memory failed: %d\n", ret);
-   return ret;
-   }
-   uaddr += PAGE_SIZE;
-   usize -= PAGE_SIZE;
-   } while (usize > 0);
-
-   return 0;
+   return err;
 }
 static int arm_iommu_mmap_attrs(struct device *dev,
struct vm_area_struct *vma, void *cpu_addr,
-- 
1.9.1



[PATCH v2 3/9] drivers/firewire/core-iso.c: Convert to use vm_insert_range

2018-12-01 Thread Souptick Joarder
Convert to use vm_insert_range to map range of kernel memory
to user vma.

Signed-off-by: Souptick Joarder 
Reviewed-by: Matthew Wilcox 
---
 drivers/firewire/core-iso.c | 15 ++-
 1 file changed, 2 insertions(+), 13 deletions(-)

diff --git a/drivers/firewire/core-iso.c b/drivers/firewire/core-iso.c
index 35e784c..7bf28bb 100644
--- a/drivers/firewire/core-iso.c
+++ b/drivers/firewire/core-iso.c
@@ -107,19 +107,8 @@ int fw_iso_buffer_init(struct fw_iso_buffer *buffer, 
struct fw_card *card,
 int fw_iso_buffer_map_vma(struct fw_iso_buffer *buffer,
  struct vm_area_struct *vma)
 {
-   unsigned long uaddr;
-   int i, err;
-
-   uaddr = vma->vm_start;
-   for (i = 0; i < buffer->page_count; i++) {
-   err = vm_insert_page(vma, uaddr, buffer->pages[i]);
-   if (err)
-   return err;
-
-   uaddr += PAGE_SIZE;
-   }
-
-   return 0;
+   return vm_insert_range(vma, vma->vm_start, buffer->pages,
+   buffer->page_count);
 }
 
 void fw_iso_buffer_destroy(struct fw_iso_buffer *buffer,
-- 
1.9.1



Re: [PATCH v2 1/9] mm: Introduce new vm_insert_range API

2018-12-02 Thread Souptick Joarder
Hi Mike,

On Sun, Dec 2, 2018 at 4:43 PM Mike Rapoport  wrote:
>
> On Sun, Dec 02, 2018 at 11:49:44AM +0530, Souptick Joarder wrote:
> > Previouly drivers have their own way of mapping range of
> > kernel pages/memory into user vma and this was done by
> > invoking vm_insert_page() within a loop.
> >
> > As this pattern is common across different drivers, it can
> > be generalized by creating a new function and use it across
> > the drivers.
> >
> > vm_insert_range is the new API which will be used to map a
> > range of kernel memory/pages to user vma.
> >
> > This API is tested by Heiko for Rockchip drm driver, on rk3188,
> > rk3288, rk3328 and rk3399 with graphics.
> >
> > Signed-off-by: Souptick Joarder 
> > Reviewed-by: Matthew Wilcox 
> > Tested-by: Heiko Stuebner 
> > ---
> >  include/linux/mm_types.h |  3 +++
> >  mm/memory.c  | 38 ++
> >  mm/nommu.c   |  7 +++
> >  3 files changed, 48 insertions(+)
> >
> > diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
> > index 5ed8f62..15ae24f 100644
> > --- a/include/linux/mm_types.h
> > +++ b/include/linux/mm_types.h
> > @@ -523,6 +523,9 @@ extern void tlb_gather_mmu(struct mmu_gather *tlb, 
> > struct mm_struct *mm,
> >  extern void tlb_finish_mmu(struct mmu_gather *tlb,
> >   unsigned long start, unsigned long end);
> >
> > +int vm_insert_range(struct vm_area_struct *vma, unsigned long addr,
> > + struct page **pages, unsigned long page_count);
> > +
>
> This seem to belong to include/linux/mm.h, near vm_insert_page()

Ok, I will change it. Apart from this change does it looks good ?

>
> >  static inline void init_tlb_flush_pending(struct mm_struct *mm)
> >  {
> >   atomic_set(&mm->tlb_flush_pending, 0);
> > diff --git a/mm/memory.c b/mm/memory.c
> > index 15c417e..84ea46c 100644
> > --- a/mm/memory.c
> > +++ b/mm/memory.c
> > @@ -1478,6 +1478,44 @@ static int insert_page(struct vm_area_struct *vma, 
> > unsigned long addr,
> >  }
> >
> >  /**
> > + * vm_insert_range - insert range of kernel pages into user vma
> > + * @vma: user vma to map to
> > + * @addr: target user address of this page
> > + * @pages: pointer to array of source kernel pages
> > + * @page_count: number of pages need to insert into user vma
> > + *
> > + * This allows drivers to insert range of kernel pages they've allocated
> > + * into a user vma. This is a generic function which drivers can use
> > + * rather than using their own way of mapping range of kernel pages into
> > + * user vma.
> > + *
> > + * If we fail to insert any page into the vma, the function will return
> > + * immediately leaving any previously-inserted pages present.  Callers
> > + * from the mmap handler may immediately return the error as their caller
> > + * will destroy the vma, removing any successfully-inserted pages. Other
> > + * callers should make their own arrangements for calling unmap_region().
> > + *
> > + * Context: Process context. Called by mmap handlers.
> > + * Return: 0 on success and error code otherwise
> > + */
> > +int vm_insert_range(struct vm_area_struct *vma, unsigned long addr,
> > + struct page **pages, unsigned long page_count)
> > +{
> > + unsigned long uaddr = addr;
> > + int ret = 0, i;
> > +
> > + for (i = 0; i < page_count; i++) {
> > + ret = vm_insert_page(vma, uaddr, pages[i]);
> > + if (ret < 0)
> > + return ret;
> > + uaddr += PAGE_SIZE;
> > + }
> > +
> > + return ret;
> > +}
> > +EXPORT_SYMBOL(vm_insert_range);
> > +
> > +/**
> >   * vm_insert_page - insert single page into user vma
> >   * @vma: user vma to map to
> >   * @addr: target user address of this page
> > diff --git a/mm/nommu.c b/mm/nommu.c
> > index 749276b..d6ef5c7 100644
> > --- a/mm/nommu.c
> > +++ b/mm/nommu.c
> > @@ -473,6 +473,13 @@ int vm_insert_page(struct vm_area_struct *vma, 
> > unsigned long addr,
> >  }
> >  EXPORT_SYMBOL(vm_insert_page);
> >
> > +int vm_insert_range(struct vm_area_struct *vma, unsigned long addr,
> > + struct page **pages, unsigned long page_count)
> > +{
> > + return -EINVAL;
> > +}
> > +EXPORT_SYMBOL(vm_insert_range);
> > +
> >  /*
> >   *  sys_brk() for the most part doesn't need the global kernel
> >   *  lock, except when an application is doing something nasty
> > --
> > 1.9.1
> >
>
> --
> Sincerely yours,
> Mike.
>


Re: [PATCH] infiniband/hw/hns/hns_roce_hw_v2.c: Use dma_zalloc_coherent

2018-11-09 Thread Souptick Joarder
On Fri, Nov 9, 2018 at 8:08 PM Sabyasachi Gupta
 wrote:
>
> Replaced dma_alloc_coherent + memset with dma_zalloc_coherent

There are few other places in this file where same is applicable.
Can we get those changes in same patch ?
>
> Signed-off-by: Sabyasachi Gupta 
> ---
>  drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c 
> b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
> index a4c62ae..c9966ec 100644
> --- a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
> +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
> @@ -4972,13 +4972,12 @@ static int hns_roce_mhop_alloc_eq(struct hns_roce_dev 
> *hr_dev,
> eqe_alloc = i * (buf_chk_sz / eq->eqe_size);
> size = (eq->entries - eqe_alloc) * 
> eq->eqe_size;
> }
> -   eq->buf[i] = dma_alloc_coherent(dev, size,
> +   eq->buf[i] = dma_zalloc_coherent(dev, size,
> &(eq->buf_dma[i]),
> GFP_KERNEL);
> if (!eq->buf[i])
> goto err_dma_alloc_buf;
>
> -   memset(eq->buf[i], 0, size);
> *(eq->bt_l0 + i) = eq->buf_dma[i];
>
> eq_buf_cnt++;
> --
> 2.7.4
>


Re: [PATCH] drivers/android/binder.c: Remove duplicate header

2018-11-09 Thread Souptick Joarder
On Fri, Nov 9, 2018 at 8:17 PM Greg KH  wrote:
>
> On Fri, Nov 09, 2018 at 10:40:14PM +0800, kbuild test robot wrote:
> > Hi Brajeswar,
> >
> > Thank you for the patch! Yet something to improve:
> >
> > [auto build test ERROR on staging/staging-testing]
> > [also build test ERROR on v4.20-rc1 next-20181109]
> > [if your patch is applied to the wrong git tree, please drop us a note to 
> > help improve the system]
> >
> > url:
> > https://github.com/0day-ci/linux/commits/Brajeswar-Ghosh/drivers-android-binder-c-Remove-duplicate-header/20181109-154717
> > config: i386-allmodconfig (attached as .config)
> > compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
> > reproduce:
> > # save the attached .config to linux build tree
> > make ARCH=i386
> >
> > All errors (new ones prefixed by >>):
>
> 
>
> Yeah, I was right :(
>
> Always test-build your patches.

Sorry about it. It was a mistake from our side.


[PATCH] fs: afs: Adding new return type vm_fault_t

2018-07-02 Thread Souptick Joarder
Use new return type vm_fault_t for fault handler
in struct vm_operations_struct. For now, this is
just documenting that the function returns a 
VM_FAULT value rather than an errno.  Once all
instances are converted, vm_fault_t will become
a distinct type.

see commit 1c8f422059ae ("mm: change return type to
vm_fault_t") for reference.

Signed-off-by: Souptick Joarder 
Reviewed-by: Matthew Wilcox 
---
 fs/afs/internal.h | 3 ++-
 fs/afs/write.c| 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/fs/afs/internal.h b/fs/afs/internal.h
index f38d6a5..35e405c 100644
--- a/fs/afs/internal.h
+++ b/fs/afs/internal.h
@@ -21,6 +21,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 

@@ -949,7 +950,7 @@ extern int afs_write_end(struct file *file, struct 
address_space *mapping,
 extern ssize_t afs_file_write(struct kiocb *, struct iov_iter *);
 extern int afs_flush(struct file *, fl_owner_t);
 extern int afs_fsync(struct file *, loff_t, loff_t, int);
-extern int afs_page_mkwrite(struct vm_fault *);
+extern vm_fault_t afs_page_mkwrite(struct vm_fault *vmf);
 extern void afs_prune_wb_keys(struct afs_vnode *);
 extern int afs_launder_page(struct page *);

diff --git a/fs/afs/write.c b/fs/afs/write.c
index 9370e2f..5c41274 100644
--- a/fs/afs/write.c
+++ b/fs/afs/write.c
@@ -751,7 +751,7 @@ int afs_flush(struct file *file, fl_owner_t id)
  * notification that a previously read-only page is about to become writable
  * - if it returns an error, the caller will deliver a bus error signal
  */
-int afs_page_mkwrite(struct vm_fault *vmf)
+vm_fault_t afs_page_mkwrite(struct vm_fault *vmf)
 {
struct file *file = vmf->vma->vm_file;
struct inode *inode = file_inode(file);
--
1.9.1



[PATCH] fs: nfs: Adding new return type vm_fault_t

2018-07-02 Thread Souptick Joarder
Use new return type vm_fault_t for fault handler
in struct vm_operations_struct. For now, this is
just documenting that the function returns a 
VM_FAULT value rather than an errno.  Once all
instances are converted, vm_fault_t will become
a distinct type.

see commit 1c8f422059ae ("mm: change return type to
vm_fault_t") for reference.

Signed-off-by: Souptick Joarder 
Reviewed-by: Matthew Wilcox 
---
 fs/nfs/file.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/nfs/file.c b/fs/nfs/file.c
index 81cca49..29553fd 100644
--- a/fs/nfs/file.c
+++ b/fs/nfs/file.c
@@ -532,13 +532,13 @@ static void nfs_swap_deactivate(struct file *file)
  * writable, implying that someone is about to modify the page through a
  * shared-writable mapping
  */
-static int nfs_vm_page_mkwrite(struct vm_fault *vmf)
+static vm_fault_t nfs_vm_page_mkwrite(struct vm_fault *vmf)
 {
struct page *page = vmf->page;
struct file *filp = vmf->vma->vm_file;
struct inode *inode = file_inode(filp);
unsigned pagelen;
-   int ret = VM_FAULT_NOPAGE;
+   vm_fault_t ret = VM_FAULT_NOPAGE;
struct address_space *mapping;

dfprintk(PAGECACHE, "NFS: vm_page_mkwrite(%pD2(%lu), offset %lld)\n",
--
1.9.1



[PATCH] fs: proc: Adding new typedef vm_fault_t

2018-07-02 Thread Souptick Joarder
Use new return type vm_fault_t for fault handler
in struct vm_operations_struct. For now, this is
just documenting that the function returns a 
VM_FAULT value rather than an errno.  Once all
instances are converted, vm_fault_t will become
a distinct type.

see commit 1c8f422059ae ("mm: change return type to
vm_fault_t") for reference.

Signed-off-by: Souptick Joarder 
Reviewed-by: Matthew Wilcox 
---
 fs/proc/vmcore.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
index a45f0af..7243e94 100644
--- a/fs/proc/vmcore.c
+++ b/fs/proc/vmcore.c
@@ -265,7 +265,7 @@ static ssize_t read_vmcore(struct file *file, char __user 
*buffer,
  * On s390 the fault handler is used for memory regions that can't be mapped
  * directly with remap_pfn_range().
  */
-static int mmap_vmcore_fault(struct vm_fault *vmf)
+static vm_fault_t mmap_vmcore_fault(struct vm_fault *vmf)
 {
 #ifdef CONFIG_S390
struct address_space *mapping = vmf->vma->vm_file->f_mapping;
-- 
1.9.1



[PATCH] fs: iomap: Change return type to vm_fault_t

2018-07-02 Thread Souptick Joarder
Return type has been changed to vm_fault_t type for
iomap_page_mkwrite().

see commit 1c8f422059ae ("mm: change return type to
vm_fault_t") for reference.

Signed-off-by: Souptick Joarder 
Reviewed-by: Matthew Wilcox 
---
 fs/iomap.c| 2 +-
 include/linux/iomap.h | 4 +++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/fs/iomap.c b/fs/iomap.c
index afd1635..58477ee 100644
--- a/fs/iomap.c
+++ b/fs/iomap.c
@@ -443,7 +443,7 @@ static int iomap_dax_zero(loff_t pos, unsigned offset, 
unsigned bytes,
return length;
 }
 
-int iomap_page_mkwrite(struct vm_fault *vmf, const struct iomap_ops *ops)
+vm_fault_t iomap_page_mkwrite(struct vm_fault *vmf, const struct iomap_ops 
*ops)
 {
struct page *page = vmf->page;
struct inode *inode = file_inode(vmf->vma->vm_file);
diff --git a/include/linux/iomap.h b/include/linux/iomap.h
index 19a07de..666b717 100644
--- a/include/linux/iomap.h
+++ b/include/linux/iomap.h
@@ -3,6 +3,7 @@
 #define LINUX_IOMAP_H 1
 
 #include 
+#include 
 
 struct fiemap_extent_info;
 struct inode;
@@ -88,7 +89,8 @@ int iomap_zero_range(struct inode *inode, loff_t pos, loff_t 
len,
bool *did_zero, const struct iomap_ops *ops);
 int iomap_truncate_page(struct inode *inode, loff_t pos, bool *did_zero,
const struct iomap_ops *ops);
-int iomap_page_mkwrite(struct vm_fault *vmf, const struct iomap_ops *ops);
+vm_fault_t iomap_page_mkwrite(struct vm_fault *vmf,
+   const struct iomap_ops *ops);
 int iomap_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
loff_t start, loff_t len, const struct iomap_ops *ops);
 loff_t iomap_seek_hole(struct inode *inode, loff_t offset,
-- 
1.9.1



[PATCH] fs: 9p: Adding new return type vm_fault_t

2018-07-02 Thread Souptick Joarder
Use new return type vm_fault_t for page_mkwrite
handler.

see commit 1c8f422059ae ("mm: change return type to
vm_fault_t") for reference.

Signed-off-by: Souptick Joarder 
Reviewed-by: Matthew Wilcox 
---
 fs/9p/vfs_file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/9p/vfs_file.c b/fs/9p/vfs_file.c
index 03c9e32..5f2e48d 100644
--- a/fs/9p/vfs_file.c
+++ b/fs/9p/vfs_file.c
@@ -533,7 +533,7 @@ int v9fs_file_fsync_dotl(struct file *filp, loff_t start, 
loff_t end,
return retval;
 }

-static int
+static vm_fault_t
 v9fs_vm_page_mkwrite(struct vm_fault *vmf)
 {
struct v9fs_inode *v9inode;
--
1.9.1



[PATCH] hwtracing: intel_th: Change return type to vm_fault_t

2018-07-02 Thread Souptick Joarder
Use new return type vm_fault_t for fault handler. For
now, this is just documenting that the function returns
a VM_FAULT value rather than an errno. Once all instances
are converted, vm_fault_t will become a distinct type.

see commit 1c8f422059ae ("mm: change return type to
vm_fault_t") for reference.

Signed-off-by: Souptick Joarder 
---
 drivers/hwtracing/intel_th/msu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hwtracing/intel_th/msu.c b/drivers/hwtracing/intel_th/msu.c
index dfb57ea..0ac84eb 100644
--- a/drivers/hwtracing/intel_th/msu.c
+++ b/drivers/hwtracing/intel_th/msu.c
@@ -1190,7 +1190,7 @@ static void msc_mmap_close(struct vm_area_struct *vma)
mutex_unlock(&msc->buf_mutex);
 }

-static int msc_mmap_fault(struct vm_fault *vmf)
+static vm_fault_t msc_mmap_fault(struct vm_fault *vmf)
 {
struct msc_iter *iter = vmf->vma->vm_file->private_data;
struct msc *msc = iter->msc;
--
1.9.1



Re: [PATCH v2] char: agp: Change return type to vm_fault_t

2018-07-02 Thread Souptick Joarder
On Mon, Jun 18, 2018 at 5:07 PM, Souptick Joarder  wrote:
> On Thu, May 31, 2018 at 10:38 AM, Souptick Joarder  
> wrote:
>> On Mon, May 21, 2018 at 11:47 PM, Souptick Joarder  
>> wrote:
>>> Use new return type vm_fault_t for fault handler. For now,
>>> this is just documenting that the function returns a
>>> VM_FAULT value rather than an errno. Once all instances are
>>> converted, vm_fault_t will become a distinct type.
>>>
>>> Ref-> commit 1c8f422059ae ("mm: change return type to
>>> vm_fault_t") was added in 4.17-rc1 to introduce the new
>>> typedef vm_fault_t. Currently we are making change to all
>>> drivers to return vm_fault_t for page fault handlers. As
>>> part of that char/agp driver is also getting changed to
>>> return vm_fault_t type from fault handler.
>>>
>>> Signed-off-by: Souptick Joarder 
>>> Reviewed-by: Matthew Wilcox 
>>> ---
>>>  drivers/char/agp/alpha-agp.c | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/char/agp/alpha-agp.c b/drivers/char/agp/alpha-agp.c
>>> index 53fe633..c9bf2c2 100644
>>> --- a/drivers/char/agp/alpha-agp.c
>>> +++ b/drivers/char/agp/alpha-agp.c
>>> @@ -11,7 +11,7 @@
>>>
>>>  #include "agp.h"
>>>
>>> -static int alpha_core_agp_vm_fault(struct vm_fault *vmf)
>>> +static vm_fault_t alpha_core_agp_vm_fault(struct vm_fault *vmf)
>>>  {
>>> alpha_agp_info *agp = agp_bridge->dev_private_data;
>>> dma_addr_t dma_addr;
>>> --
>>> 1.9.1
>>>
>>
>> Any comment for this patch ?
>
> Any further comment on this patch ?

Greg, Can we get this patch in queue for 4.19 ?


Re: [PATCH v2] char: agp: Change return type to vm_fault_t

2018-07-02 Thread Souptick Joarder
On Mon, Jul 2, 2018 at 9:42 PM, Greg KH  wrote:
> On Mon, Jul 02, 2018 at 09:33:19PM +0530, Souptick Joarder wrote:
>> On Mon, Jun 18, 2018 at 5:07 PM, Souptick Joarder  
>> wrote:
>> > On Thu, May 31, 2018 at 10:38 AM, Souptick Joarder  
>> > wrote:
>> >> On Mon, May 21, 2018 at 11:47 PM, Souptick Joarder  
>> >> wrote:
>> >>> Use new return type vm_fault_t for fault handler. For now,
>> >>> this is just documenting that the function returns a
>> >>> VM_FAULT value rather than an errno. Once all instances are
>> >>> converted, vm_fault_t will become a distinct type.
>> >>>
>> >>> Ref-> commit 1c8f422059ae ("mm: change return type to
>> >>> vm_fault_t") was added in 4.17-rc1 to introduce the new
>> >>> typedef vm_fault_t. Currently we are making change to all
>> >>> drivers to return vm_fault_t for page fault handlers. As
>> >>> part of that char/agp driver is also getting changed to
>> >>> return vm_fault_t type from fault handler.
>> >>>
>> >>> Signed-off-by: Souptick Joarder 
>> >>> Reviewed-by: Matthew Wilcox 
>> >>> ---
>> >>>  drivers/char/agp/alpha-agp.c | 2 +-
>> >>>  1 file changed, 1 insertion(+), 1 deletion(-)
>> >>>
>> >>> diff --git a/drivers/char/agp/alpha-agp.c b/drivers/char/agp/alpha-agp.c
>> >>> index 53fe633..c9bf2c2 100644
>> >>> --- a/drivers/char/agp/alpha-agp.c
>> >>> +++ b/drivers/char/agp/alpha-agp.c
>> >>> @@ -11,7 +11,7 @@
>> >>>
>> >>>  #include "agp.h"
>> >>>
>> >>> -static int alpha_core_agp_vm_fault(struct vm_fault *vmf)
>> >>> +static vm_fault_t alpha_core_agp_vm_fault(struct vm_fault *vmf)
>> >>>  {
>> >>> alpha_agp_info *agp = agp_bridge->dev_private_data;
>> >>> dma_addr_t dma_addr;
>> >>> --
>> >>> 1.9.1
>> >>>
>> >>
>> >> Any comment for this patch ?
>> >
>> > Any further comment on this patch ?
>>
>> Greg, Can we get this patch in queue for 4.19 ?
>
> I am not the agp maintainer, am I?  That would be David...

Sorry about it.


David, can we get this patch in queue for 4.19 ?


Re: [PATCH v2] x86/vdso: Change return type to vm_fault_t for fault handlers

2018-07-03 Thread Souptick Joarder
On Tue, Jul 3, 2018 at 4:47 PM, Matthew Wilcox  wrote:
> On Mon, Jun 25, 2018 at 11:27:37PM +0530, Souptick Joarder wrote:
>> Use new return type vm_fault_t for both fault handler
>> vdso_fault() and vvar_fault(). Previously vm_insert_pfn()
>> returns err which has to mapped into VM_FAULT_* type.
>> The new function vmf_insert_pfn() will replace this
>> inefficiency by returning correct VM_FAULT_* type.
>
>> @@ -105,10 +105,10 @@ static int vvar_fault(const struct vm_special_mapping 
>> *sm,
>>* the page past the end of the vvar mapping.
>>*/
>>   if (sym_offset == 0)
>> - return VM_FAULT_SIGBUS;
>> + return ret;
>>
>>   if (sym_offset == image->sym_vvar_page) {
>> - ret = vm_insert_pfn(vma, vmf->address,
>> + ret = vmf_insert_pfn(vma, vmf->address,
>>   __pa_symbol(&__vvar_page) >> PAGE_SHIFT);
>>   } else if (sym_offset == image->sym_pvclock_page) {
>>   struct pvclock_vsyscall_time_info *pvti =
>> @@ -124,14 +124,11 @@ static int vvar_fault(const struct vm_special_mapping 
>> *sm,
>
> Haven't you missed converting vm_insert_pfn_prot() at line 117?
> Did you test-compile this?
>

I left it intentionally in this patch. When we will be replacing
vm_insert_foo() with new API vmf_insert_foo(), vm_insert_pfn_prot
need to be changed to return vm_fault_t type.

I will change the return type of vm_insert_pfn_prot() in that patch.


Re: [PATCH v2] x86/vdso: Change return type to vm_fault_t for fault handlers

2018-07-03 Thread Souptick Joarder
On Tue, Jul 3, 2018 at 5:41 PM, Matthew Wilcox  wrote:
> On Tue, Jul 03, 2018 at 05:18:30PM +0530, Souptick Joarder wrote:
>> On Tue, Jul 3, 2018 at 4:47 PM, Matthew Wilcox  wrote:
>> > On Mon, Jun 25, 2018 at 11:27:37PM +0530, Souptick Joarder wrote:
>> >> Use new return type vm_fault_t for both fault handler
>> >> vdso_fault() and vvar_fault(). Previously vm_insert_pfn()
>> >> returns err which has to mapped into VM_FAULT_* type.
>> >> The new function vmf_insert_pfn() will replace this
>> >> inefficiency by returning correct VM_FAULT_* type.
>> >
>> >> @@ -105,10 +105,10 @@ static int vvar_fault(const struct 
>> >> vm_special_mapping *sm,
>> >>* the page past the end of the vvar mapping.
>> >>*/
>> >>   if (sym_offset == 0)
>> >> - return VM_FAULT_SIGBUS;
>> >> + return ret;
>> >>
>> >>   if (sym_offset == image->sym_vvar_page) {
>> >> - ret = vm_insert_pfn(vma, vmf->address,
>> >> + ret = vmf_insert_pfn(vma, vmf->address,
>> >>   __pa_symbol(&__vvar_page) >> 
>> >> PAGE_SHIFT);
>> >>   } else if (sym_offset == image->sym_pvclock_page) {
>> >>   struct pvclock_vsyscall_time_info *pvti =
>> >> @@ -124,14 +124,11 @@ static int vvar_fault(const struct 
>> >> vm_special_mapping *sm,
>> >
>> > Haven't you missed converting vm_insert_pfn_prot() at line 117?
>> > Did you test-compile this?
>> >
>>
>> I left it intentionally in this patch. When we will be replacing
>> vm_insert_foo() with new API vmf_insert_foo(), vm_insert_pfn_prot
>> need to be changed to return vm_fault_t type.
>>
>> I will change the return type of vm_insert_pfn_prot() in that patch.
>
> What?!  That's just broken.  vm_insert_pfn_prot returns an errno, so
> this patch introduces a bug where sometimes 'ret' contains a vm_fault_t
> and sometimes contains an errno.  That's exactly the kind of thing this
> patch series is supposed to be *preventing*, not introducing!
>

It was my wrong understanding which create this issue. Sorry about it.
I though to change the return type of vm_insert_pfn_prot() to vm_fault_t
type directly along with the caller of vm_insert_pfn_prot(), but in a separate
patch.

But introducing vmf_insert_pfn_prot() is much simpler approach here.

Sorry for making things complex.


[PATCH] fs: ext4: use new return type vm_fault_t

2018-07-07 Thread Souptick Joarder
Use new return type vm_fault_t for fault handler
ext4_filemap_fault.

Signed-off-by: Souptick Joarder 
---
 fs/ext4/ext4.h  | 2 +-
 fs/ext4/inode.c | 8 
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 0b12785..aec0010 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -2470,7 +2470,7 @@ int do_journal_get_write_access(handle_t *handle,
 extern int ext4_zero_partial_blocks(handle_t *handle, struct inode *inode,
 loff_t lstart, loff_t lend);
 extern int ext4_page_mkwrite(struct vm_fault *vmf);
-extern int ext4_filemap_fault(struct vm_fault *vmf);
+extern vm_fault_t ext4_filemap_fault(struct vm_fault *vmf);
 extern qsize_t *ext4_get_reserved_space(struct inode *inode);
 extern int ext4_get_projid(struct inode *inode, kprojid_t *projid);
 extern void ext4_da_update_reserve_space(struct inode *inode,
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 2ea07ef..03ac322 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -6205,14 +6205,14 @@ int ext4_page_mkwrite(struct vm_fault *vmf)
return ret;
 }
 
-int ext4_filemap_fault(struct vm_fault *vmf)
+vm_fault_t ext4_filemap_fault(struct vm_fault *vmf)
 {
struct inode *inode = file_inode(vmf->vma->vm_file);
-   int err;
+   vm_fault_t ret;
 
down_read(&EXT4_I(inode)->i_mmap_sem);
-   err = filemap_fault(vmf);
+   ret = filemap_fault(vmf);
up_read(&EXT4_I(inode)->i_mmap_sem);
 
-   return err;
+   return ret;
 }
-- 
1.9.1



Re: [PATCH] orangefs: Adding new return type vm_fault_t

2018-07-10 Thread Souptick Joarder
On Wed, Jul 11, 2018 at 1:13 AM, Mike Marshall  wrote:
> Hi...
>
> I applied this patch to 4.18.0-rc4. It applied cleanly and there's no xfstests
> regressions. Sorry if I held you up any...
>
> You can add: Tested-By: Mike Marshall 
>

Thanks Mike. Can we get this patch in queue for 4.19 merge window ?

> -Mike
>
> On Fri, Jul 6, 2018 at 10:05 AM, Mike Marshall  wrote:
>> Souptick Joarder: Any comment for this patch?
>>
>> Thanks for sending it ...
>>
>> I have it in my stack, but I haven't studied it, or xfstested it yet, so
>> no useful comments yet...
>>
>> -Mike
>>
>>
>>
>> On Fri, Jul 6, 2018 at 2:44 AM, Souptick Joarder  
>> wrote:
>>> On Fri, Jun 29, 2018 at 12:12 AM, Souptick Joarder  
>>> wrote:
>>>> Use new return type vm_fault_t for fault handler. For now,
>>>> this is just documenting that the function returns a VM_FAULT
>>>> value rather than an errno. Once all instances are converted,
>>>> vm_fault_t will become a distinct type.
>>>>
>>>> See the following
>>>> commit 1c8f422059ae ("mm: change return type to vm_fault_t")
>>>>
>>>> Fixed checkpatch.pl warning.
>>>>
>>>> Signed-off-by: Souptick Joarder 
>>>> ---
>>>>  fs/orangefs/file.c | 19 ++-
>>>>  1 file changed, 10 insertions(+), 9 deletions(-)
>>>>
>>>> diff --git a/fs/orangefs/file.c b/fs/orangefs/file.c
>>>> index db0b521..a5a2fe7 100644
>>>> --- a/fs/orangefs/file.c
>>>> +++ b/fs/orangefs/file.c
>>>> @@ -528,18 +528,19 @@ static long orangefs_ioctl(struct file *file, 
>>>> unsigned int cmd, unsigned long ar
>>>> return ret;
>>>>  }
>>>>
>>>> -static int orangefs_fault(struct vm_fault *vmf)
>>>> +static vm_fault_t orangefs_fault(struct vm_fault *vmf)
>>>>  {
>>>> struct file *file = vmf->vma->vm_file;
>>>> -   int rc;
>>>> -   rc = orangefs_inode_getattr(file->f_mapping->host, 0, 1,
>>>> +   int ret;
>>>> +
>>>> +   ret = orangefs_inode_getattr(file->f_mapping->host, 0, 1,
>>>> STATX_SIZE);
>>>> -   if (rc == -ESTALE)
>>>> -   rc = -EIO;
>>>> -   if (rc) {
>>>> -   gossip_err("%s: orangefs_inode_getattr failed, "
>>>> -   "rc:%d:.\n", __func__, rc);
>>>> -   return rc;
>>>> +   if (ret == -ESTALE)
>>>> +   ret = -EIO;
>>>> +   if (ret) {
>>>> +   gossip_err("%s: orangefs_inode_getattr failed, ret:%d:.\n",
>>>> +   __func__, ret);
>>>> +   return VM_FAULT_SIGBUS;
>>>> }
>>>> return filemap_fault(vmf);
>>>>  }
>>>> --
>>>> 1.9.1
>>>>
>>>
>>> Any comment for this patch ?


Re: [PATCH] x86/vdso: Change return type to vm_fault_t for fault handlers

2018-06-25 Thread Souptick Joarder
On Mon, Jun 25, 2018 at 9:41 PM, Andy Lutomirski  wrote:
> On Mon, Jun 25, 2018 at 8:55 AM Souptick Joarder  wrote:
>>
>> Use new return type vm_fault_t for fault handler. For
>> now, this is just documenting that the function returns
>> a VM_FAULT value rather than an errno. Once all instances
>> are converted, vm_fault_t will become a distinct type.
>
> Whoa there..  Your commit message makes it sound like you're just
> changing the return type, but:
>
>> if (tsc_pg && vclock_was_used(VCLOCK_HVCLOCK))
>> -   ret = vm_insert_pfn(vma, vmf->address,
>> +   ret = vmf_insert_pfn(vma, vmf->address,
>> vmalloc_to_pfn(tsc_pg));
>> }
>>
>> -   if (ret == 0 || ret == -EBUSY)
>> -   return VM_FAULT_NOPAGE;
>> -
>> -   return VM_FAULT_SIGBUS;
>> +   return ret;
>
> You're refactoring the code, too.
>
> Please fix your changelog.


I have mentioned it.


Ref-> commit 1c8f422059ae ("mm: change return type to vm_fault_t")

Previously vm_insert_pfn() returns err which has to
mapped into VM_FAULT_* type. The new function
vmf_insert_pfn() will replace this inefficiency by
returning VM_FAULT_* type.
*


[PATCH v2] x86/vdso: Change return type to vm_fault_t for fault handlers

2018-06-25 Thread Souptick Joarder
Use new return type vm_fault_t for both fault handler
vdso_fault() and vvar_fault(). Previously vm_insert_pfn()
returns err which has to mapped into VM_FAULT_* type.
The new function vmf_insert_pfn() will replace this
inefficiency by returning correct VM_FAULT_* type.

See the following commit:

  1c8f422059ae ("mm: change return type to vm_fault_t")
  b3ec9f33acb8 ("mm: change return type to vm_fault_t")

Signed-off-by: Souptick Joarder 
---

v2: Updated the change log

 arch/x86/entry/vdso/vma.c | 19 ---
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/arch/x86/entry/vdso/vma.c b/arch/x86/entry/vdso/vma.c
index 5b8b556..3679885 100644
--- a/arch/x86/entry/vdso/vma.c
+++ b/arch/x86/entry/vdso/vma.c
@@ -39,7 +39,7 @@ void __init init_vdso_image(const struct vdso_image *image)
 
 struct linux_binprm;
 
-static int vdso_fault(const struct vm_special_mapping *sm,
+static vm_fault_t vdso_fault(const struct vm_special_mapping *sm,
  struct vm_area_struct *vma, struct vm_fault *vmf)
 {
const struct vdso_image *image = vma->vm_mm->context.vdso_image;
@@ -84,15 +84,15 @@ static int vdso_mremap(const struct vm_special_mapping *sm,
return 0;
 }
 
-static int vvar_fault(const struct vm_special_mapping *sm,
+static vm_fault_t vvar_fault(const struct vm_special_mapping *sm,
  struct vm_area_struct *vma, struct vm_fault *vmf)
 {
const struct vdso_image *image = vma->vm_mm->context.vdso_image;
long sym_offset;
-   int ret = -EFAULT;
+   vm_fault_t ret = VM_FAULT_SIGBUS;
 
if (!image)
-   return VM_FAULT_SIGBUS;
+   return ret;
 
sym_offset = (long)(vmf->pgoff << PAGE_SHIFT) +
image->sym_vvar_start;
@@ -105,10 +105,10 @@ static int vvar_fault(const struct vm_special_mapping *sm,
 * the page past the end of the vvar mapping.
 */
if (sym_offset == 0)
-   return VM_FAULT_SIGBUS;
+   return ret;
 
if (sym_offset == image->sym_vvar_page) {
-   ret = vm_insert_pfn(vma, vmf->address,
+   ret = vmf_insert_pfn(vma, vmf->address,
__pa_symbol(&__vvar_page) >> PAGE_SHIFT);
} else if (sym_offset == image->sym_pvclock_page) {
struct pvclock_vsyscall_time_info *pvti =
@@ -124,14 +124,11 @@ static int vvar_fault(const struct vm_special_mapping *sm,
struct ms_hyperv_tsc_page *tsc_pg = hv_get_tsc_page();
 
if (tsc_pg && vclock_was_used(VCLOCK_HVCLOCK))
-   ret = vm_insert_pfn(vma, vmf->address,
+   ret = vmf_insert_pfn(vma, vmf->address,
vmalloc_to_pfn(tsc_pg));
}
 
-   if (ret == 0 || ret == -EBUSY)
-   return VM_FAULT_NOPAGE;
-
-   return VM_FAULT_SIGBUS;
+   return ret;
 }
 
 static const struct vm_special_mapping vdso_mapping = {
-- 
1.9.1



[PATCH] orangefs: Adding new return type vm_fault_t

2018-06-28 Thread Souptick Joarder
Use new return type vm_fault_t for fault handler. For now,
this is just documenting that the function returns a VM_FAULT
value rather than an errno. Once all instances are converted,
vm_fault_t will become a distinct type.

See the following
commit 1c8f422059ae ("mm: change return type to vm_fault_t")

Fixed checkpatch.pl warning.

Signed-off-by: Souptick Joarder 
---
 fs/orangefs/file.c | 19 ++-
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/fs/orangefs/file.c b/fs/orangefs/file.c
index db0b521..a5a2fe7 100644
--- a/fs/orangefs/file.c
+++ b/fs/orangefs/file.c
@@ -528,18 +528,19 @@ static long orangefs_ioctl(struct file *file, unsigned 
int cmd, unsigned long ar
return ret;
 }
 
-static int orangefs_fault(struct vm_fault *vmf)
+static vm_fault_t orangefs_fault(struct vm_fault *vmf)
 {
struct file *file = vmf->vma->vm_file;
-   int rc;
-   rc = orangefs_inode_getattr(file->f_mapping->host, 0, 1,
+   int ret;
+
+   ret = orangefs_inode_getattr(file->f_mapping->host, 0, 1,
STATX_SIZE);
-   if (rc == -ESTALE)
-   rc = -EIO;
-   if (rc) {
-   gossip_err("%s: orangefs_inode_getattr failed, "
-   "rc:%d:.\n", __func__, rc);
-   return rc;
+   if (ret == -ESTALE)
+   ret = -EIO;
+   if (ret) {
+   gossip_err("%s: orangefs_inode_getattr failed, ret:%d:.\n",
+   __func__, ret);
+   return VM_FAULT_SIGBUS;
}
return filemap_fault(vmf);
 }
-- 
1.9.1



Re: [PATCH] gpu: drm: vgem: Change return type to vm_fault_t

2018-05-24 Thread Souptick Joarder
On Thu, May 24, 2018 at 6:27 PM, Daniel Vetter  wrote:
> On Wed, May 23, 2018 at 03:05:35PM +0530, Souptick Joarder wrote:
>> On Mon, May 14, 2018 at 9:56 PM, Daniel Vetter  wrote:
>> > On Thu, May 10, 2018 at 02:51:38PM -0400, Sean Paul wrote:
>> >> On Thu, May 10, 2018 at 07:58:11PM +0530, Souptick Joarder wrote:
>> >> > Hi Sean,
>> >> >
>> >> > On Mon, Apr 16, 2018 at 8:32 PM, Souptick Joarder 
>> >> >  wrote:
>> >> > > Use new return type vm_fault_t for fault handler.
>> >> > >
>> >> > > Signed-off-by: Souptick Joarder 
>> >> > > Reviewed-by: Matthew Wilcox 
>> >> > > ---
>> >> > >  drivers/gpu/drm/vgem/vgem_drv.c | 5 ++---
>> >> > >  1 file changed, 2 insertions(+), 3 deletions(-)
>> >> > >
>> >> > > diff --git a/drivers/gpu/drm/vgem/vgem_drv.c 
>> >> > > b/drivers/gpu/drm/vgem/vgem_drv.c
>> >> > > index 2524ff1..c64a859 100644
>> >> > > --- a/drivers/gpu/drm/vgem/vgem_drv.c
>> >> > > +++ b/drivers/gpu/drm/vgem/vgem_drv.c
>> >> > > @@ -61,13 +61,13 @@ static void vgem_gem_free_object(struct 
>> >> > > drm_gem_object *obj)
>> >> > > kfree(vgem_obj);
>> >> > >  }
>> >> > >
>> >> > > -static int vgem_gem_fault(struct vm_fault *vmf)
>> >> > > +static vm_fault_t vgem_gem_fault(struct vm_fault *vmf)
>> >> > >  {
>> >> > > struct vm_area_struct *vma = vmf->vma;
>> >> > > struct drm_vgem_gem_object *obj = vma->vm_private_data;
>> >> > > /* We don't use vmf->pgoff since that has the fake offset */
>> >> > > unsigned long vaddr = vmf->address;
>> >> > > -   int ret;
>> >> > > +   vm_fault_t ret = VM_FAULT_SIGBUS;
>> >> > > loff_t num_pages;
>> >> > > pgoff_t page_offset;
>> >> > > page_offset = (vaddr - vma->vm_start) >> PAGE_SHIFT;
>> >> > > @@ -77,7 +77,6 @@ static int vgem_gem_fault(struct vm_fault *vmf)
>> >> > > if (page_offset > num_pages)
>> >> > > return VM_FAULT_SIGBUS;
>> >> > >
>> >> > > -   ret = -ENOENT;
>> >> > > mutex_lock(&obj->pages_lock);
>> >> > > if (obj->pages) {
>> >> > > get_page(obj->pages[page_offset]);
>> >> > > --
>> >> > > 1.9.1
>> >> > >
>> >> >
>> >> > Any further comment on this patch ?
>> >>
>> >> Patch looks good to me. My build test fails, though, since vm_fault_t 
>> >> doesn't
>> >> exist in drm-misc-next yet.
>> >
>> > vm_fault_t is already in upstream, just needs Maarten to do a backmerge.
>> > Which I think he's done by now ... Otherwise nag him more :-)
>> > -Daniel
>> >
>> >>
>> >> So, for now,
>> >>
>> >> Reviewed-by: Sean Paul 
>> >>
>> >>
>> >> --
>> >> Sean Paul, Software Engineer, Google / Chromium OS
>> >> ___
>> >> dri-devel mailing list
>> >> dri-de...@lists.freedesktop.org
>> >> https://lists.freedesktop.org/mailman/listinfo/dri-devel
>> >
>> > --
>> > Daniel Vetter
>> > Software Engineer, Intel Corporation
>> > http://blog.ffwll.ch
>>
>> Daniel/ Sean, is this patch already merged for 4.18 ?
>
> Nope, fell through the cracks. Thanks for the reminder, queued for 4.18
> now.
> -Daniel

Thanks Daniel :).
Few other similar drm driver patches are also candidates
for 4.18. Are you the right Maintainer to make a request
for the same ?


Re: [PATCH] gpu: drm: drm_vm: Adding new typedef vm_fault_t

2018-05-24 Thread Souptick Joarder
On Wed, May 16, 2018 at 10:09 AM, Souptick Joarder  wrote:
> On Thu, May 10, 2018 at 7:12 PM, Souptick Joarder  
> wrote:
>> Use new return type vm_fault_t for fault handler. For
>> now, this is just documenting that the function returns
>> a VM_FAULT value rather than an errno. Once all instances
>> are converted, vm_fault_t will become a distinct type.
>>
>> commit 1c8f422059ae ("mm: change return type to vm_fault_t")
>>
>> Signed-off-by: Souptick Joarder 
>> Reviewed-by: Matthew Wilcox 
>> ---
>>  drivers/gpu/drm/drm_vm.c | 10 +-
>>  1 file changed, 5 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/drm_vm.c b/drivers/gpu/drm/drm_vm.c
>> index 2660543..c330104 100644
>> --- a/drivers/gpu/drm/drm_vm.c
>> +++ b/drivers/gpu/drm/drm_vm.c
>> @@ -100,7 +100,7 @@ static pgprot_t drm_dma_prot(uint32_t map_type, struct 
>> vm_area_struct *vma)
>>   * map, get the page, increment the use count and return it.
>>   */
>>  #if IS_ENABLED(CONFIG_AGP)
>> -static int drm_vm_fault(struct vm_fault *vmf)
>> +static vm_fault_t drm_vm_fault(struct vm_fault *vmf)
>>  {
>> struct vm_area_struct *vma = vmf->vma;
>> struct drm_file *priv = vma->vm_file->private_data;
>> @@ -173,7 +173,7 @@ static int drm_vm_fault(struct vm_fault *vmf)
>> return VM_FAULT_SIGBUS; /* Disallow mremap */
>>  }
>>  #else
>> -static int drm_vm_fault(struct vm_fault *vmf)
>> +static vm_fault_t drm_vm_fault(struct vm_fault *vmf)
>>  {
>> return VM_FAULT_SIGBUS;
>>  }
>> @@ -189,7 +189,7 @@ static int drm_vm_fault(struct vm_fault *vmf)
>>   * Get the mapping, find the real physical page to map, get the page, and
>>   * return it.
>>   */
>> -static int drm_vm_shm_fault(struct vm_fault *vmf)
>> +static vm_fault_t drm_vm_shm_fault(struct vm_fault *vmf)
>>  {
>> struct vm_area_struct *vma = vmf->vma;
>> struct drm_local_map *map = vma->vm_private_data;
>> @@ -291,7 +291,7 @@ static void drm_vm_shm_close(struct vm_area_struct *vma)
>>   *
>>   * Determine the page number from the page offset and get it from 
>> drm_device_dma::pagelist.
>>   */
>> -static int drm_vm_dma_fault(struct vm_fault *vmf)
>> +static vm_fault_t drm_vm_dma_fault(struct vm_fault *vmf)
>>  {
>> struct vm_area_struct *vma = vmf->vma;
>> struct drm_file *priv = vma->vm_file->private_data;
>> @@ -326,7 +326,7 @@ static int drm_vm_dma_fault(struct vm_fault *vmf)
>>   *
>>   * Determine the map offset from the page offset and get it from 
>> drm_sg_mem::pagelist.
>>   */
>> -static int drm_vm_sg_fault(struct vm_fault *vmf)
>> +static vm_fault_t drm_vm_sg_fault(struct vm_fault *vmf)
>>  {
>> struct vm_area_struct *vma = vmf->vma;
>> struct drm_local_map *map = vma->vm_private_data;
>> --
>> 1.9.1
>>
>
> Daniel, if no further comment, we would like to get this patch
> in queue for 4.18.

We would like to get this in queue for 4.18.


Re: [PATCH v2] gpu: drm: gma500: Change return type to vm_fault_t

2018-05-26 Thread Souptick Joarder
On Sat, May 26, 2018 at 8:11 AM, kbuild test robot  wrote:
> Hi Souptick,
>
> Thank you for the patch! Perhaps something to improve:
>
> [auto build test WARNING on drm/drm-next]
> [also build test WARNING on v4.17-rc6]
> [if your patch is applied to the wrong git tree, please drop us a note to 
> help improve the system]
>
> url:
> https://github.com/0day-ci/linux/commits/Souptick-Joarder/gpu-drm-gma500-Change-return-type-to-vm_fault_t/20180526-084629
> base:   git://people.freedesktop.org/~airlied/linux.git drm-next
> config: x86_64-randconfig-x013-201820 (attached as .config)
> compiler: gcc-7 (Debian 7.3.0-16) 7.3.0
> reproduce:
> # save the attached .config to linux build tree
> make ARCH=x86_64
>
> Note: it may well be a FALSE warning. FWIW you are at least aware of it now.
> http://gcc.gnu.org/wiki/Better_Uninitialized_Warnings
>
> All warnings (new ones prefixed by >>):
>
>drivers/gpu//drm/gma500/framebuffer.c: In function 'psbfb_vm_fault':
>>> drivers/gpu//drm/gma500/framebuffer.c:143:9: warning: 'ret' may be used 
>>> uninitialized in this function [-Wmaybe-uninitialized]
>  return ret;
> ^~~

Sorrry about it. Will fix and send v3.


[PATCH v3] gpu: drm: gma500: Change return type to vm_fault_t

2018-05-26 Thread Souptick Joarder
Use new return type vm_fault_t for fault handler. For
now, this is just documenting that the function returns
a VM_FAULT value rather than an errno. Once all instances
are converted, vm_fault_t will become a distinct type.

Ref-> commit 1c8f422059ae ("mm: change return type to vm_fault_t")

Previously vm_insert_{pfn,mixed} returns err which driver
mapped into VM_FAULT_* type. The new function
vmf_insert_{pfn,mixed} will replace this inefficiency by
returning VM_FAULT_* type.

vmf_error() is the newly introduce inline function
in 4.17-rc6.

Signed-off-by: Souptick Joarder 
Reviewed-by: Matthew Wilcox 
---
v2: updated the change log

v3: Fixed kbuild error

 drivers/gpu/drm/gma500/framebuffer.c | 14 +-
 drivers/gpu/drm/gma500/gem.c | 27 ++-
 drivers/gpu/drm/gma500/psb_drv.h |  3 ++-
 3 files changed, 17 insertions(+), 27 deletions(-)

diff --git a/drivers/gpu/drm/gma500/framebuffer.c 
b/drivers/gpu/drm/gma500/framebuffer.c
index cb0a2ae..632aadb 100644
--- a/drivers/gpu/drm/gma500/framebuffer.c
+++ b/drivers/gpu/drm/gma500/framebuffer.c
@@ -111,7 +111,7 @@ static int psbfb_pan(struct fb_var_screeninfo *var, struct 
fb_info *info)
 return 0;
 }
 
-static int psbfb_vm_fault(struct vm_fault *vmf)
+static vm_fault_t psbfb_vm_fault(struct vm_fault *vmf)
 {
struct vm_area_struct *vma = vmf->vma;
struct psb_framebuffer *psbfb = vma->vm_private_data;
@@ -120,7 +120,7 @@ static int psbfb_vm_fault(struct vm_fault *vmf)
int page_num;
int i;
unsigned long address;
-   int ret;
+   vm_fault_t ret = VM_FAULT_SIGBUS;
unsigned long pfn;
unsigned long phys_addr = (unsigned long)dev_priv->stolen_base +
  psbfb->gtt->offset;
@@ -133,18 +133,14 @@ static int psbfb_vm_fault(struct vm_fault *vmf)
for (i = 0; i < page_num; i++) {
pfn = (phys_addr >> PAGE_SHIFT);
 
-   ret = vm_insert_mixed(vma, address,
+   ret = vmf_insert_mixed(vma, address,
__pfn_to_pfn_t(pfn, PFN_DEV));
-   if (unlikely((ret == -EBUSY) || (ret != 0 && i > 0)))
+   if (unlikely(ret & VM_FAULT_ERROR))
break;
-   else if (unlikely(ret != 0)) {
-   ret = (ret == -ENOMEM) ? VM_FAULT_OOM : VM_FAULT_SIGBUS;
-   return ret;
-   }
address += PAGE_SIZE;
phys_addr += PAGE_SIZE;
}
-   return VM_FAULT_NOPAGE;
+   return ret;
 }
 
 static void psbfb_vm_open(struct vm_area_struct *vma)
diff --git a/drivers/gpu/drm/gma500/gem.c b/drivers/gpu/drm/gma500/gem.c
index 1312397..e7be5c9 100644
--- a/drivers/gpu/drm/gma500/gem.c
+++ b/drivers/gpu/drm/gma500/gem.c
@@ -134,12 +134,13 @@ int psb_gem_dumb_create(struct drm_file *file, struct 
drm_device *dev,
  * vma->vm_private_data points to the GEM object that is backing this
  * mapping.
  */
-int psb_gem_fault(struct vm_fault *vmf)
+vm_fault_t psb_gem_fault(struct vm_fault *vmf)
 {
struct vm_area_struct *vma = vmf->vma;
struct drm_gem_object *obj;
struct gtt_range *r;
-   int ret;
+   int err;
+   vm_fault_t ret;
unsigned long pfn;
pgoff_t page_offset;
struct drm_device *dev;
@@ -158,9 +159,10 @@ int psb_gem_fault(struct vm_fault *vmf)
/* For now the mmap pins the object and it stays pinned. As things
   stand that will do us no harm */
if (r->mmapping == 0) {
-   ret = psb_gtt_pin(r);
-   if (ret < 0) {
-   dev_err(dev->dev, "gma500: pin failed: %d\n", ret);
+   err = psb_gtt_pin(r);
+   if (err < 0) {
+   dev_err(dev->dev, "gma500: pin failed: %d\n", err);
+   ret = vmf_error(err);
goto fail;
}
r->mmapping = 1;
@@ -175,18 +177,9 @@ int psb_gem_fault(struct vm_fault *vmf)
pfn = (dev_priv->stolen_base + r->offset) >> PAGE_SHIFT;
else
pfn = page_to_pfn(r->pages[page_offset]);
-   ret = vm_insert_pfn(vma, vmf->address, pfn);
-
+   ret = vmf_insert_pfn(vma, vmf->address, pfn);
 fail:
mutex_unlock(&dev_priv->mmap_mutex);
-   switch (ret) {
-   case 0:
-   case -ERESTARTSYS:
-   case -EINTR:
-   return VM_FAULT_NOPAGE;
-   case -ENOMEM:
-   return VM_FAULT_OOM;
-   default:
-   return VM_FAULT_SIGBUS;
-   }
+
+   return ret;
 }
diff --git a/drivers/gpu/drm/gma500/psb_drv.h b/drivers/gpu/drm/gma500/psb_drv.h
index e8300f5..93d2f40 100644
--- a/drivers/gpu/drm/gma500/psb_drv.h
+++ b/drivers/gpu/drm/gma500/psb_drv.h
@@ -21,6 +21,7 @@
 #define _PSB_DRV_H_
 
 #i

Re: [PATCH] gpu: drm: msm: Change return type to vm_fault_t

2018-05-28 Thread Souptick Joarder
On Mon, May 21, 2018 at 10:59 PM, Souptick Joarder  wrote:
> Use new return type vm_fault_t for fault handler. For
> now, this is just documenting that the function returns
> a VM_FAULT value rather than an errno. Once all instances
> are converted, vm_fault_t will become a distinct type.
>
> Ref- commit 1c8f422059ae ("mm: change return type to vm_fault_t")
>
> Previously vm_insert_mixed() returns err which driver
> mapped into VM_FAULT_* type. The new function
> vmf_insert_mixed() will replace this inefficiency by
> returning VM_FAULT_* type.
>
> vmf_error() is the newly introduce inline function
> in 4.17-rc6.
>
> Signed-off-by: Souptick Joarder 
> Reviewed-by: Matthew Wilcox 
> ---
>  drivers/gpu/drm/msm/msm_drv.h |  3 ++-
>  drivers/gpu/drm/msm/msm_gem.c | 33 ++---
>  2 files changed, 12 insertions(+), 24 deletions(-)
>
> diff --git a/drivers/gpu/drm/msm/msm_drv.h b/drivers/gpu/drm/msm/msm_drv.h
> index 0a653dd..44b4ca7 100644
> --- a/drivers/gpu/drm/msm/msm_drv.h
> +++ b/drivers/gpu/drm/msm/msm_drv.h
> @@ -33,6 +33,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>
>  #include 
>  #include 
> @@ -188,7 +189,7 @@ int msm_ioctl_gem_submit(struct drm_device *dev, void 
> *data,
>  int msm_gem_mmap_obj(struct drm_gem_object *obj,
> struct vm_area_struct *vma);
>  int msm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
> -int msm_gem_fault(struct vm_fault *vmf);
> +vm_fault_t msm_gem_fault(struct vm_fault *vmf);
>  uint64_t msm_gem_mmap_offset(struct drm_gem_object *obj);
>  int msm_gem_get_iova(struct drm_gem_object *obj,
> struct msm_gem_address_space *aspace, uint64_t *iova);
> diff --git a/drivers/gpu/drm/msm/msm_gem.c b/drivers/gpu/drm/msm/msm_gem.c
> index 07376de..27a5ab5 100644
> --- a/drivers/gpu/drm/msm/msm_gem.c
> +++ b/drivers/gpu/drm/msm/msm_gem.c
> @@ -217,7 +217,7 @@ int msm_gem_mmap(struct file *filp, struct vm_area_struct 
> *vma)
> return msm_gem_mmap_obj(vma->vm_private_data, vma);
>  }
>
> -int msm_gem_fault(struct vm_fault *vmf)
> +vm_fault_t msm_gem_fault(struct vm_fault *vmf)
>  {
> struct vm_area_struct *vma = vmf->vma;
> struct drm_gem_object *obj = vma->vm_private_data;
> @@ -225,15 +225,18 @@ int msm_gem_fault(struct vm_fault *vmf)
> struct page **pages;
> unsigned long pfn;
> pgoff_t pgoff;
> -   int ret;
> +   int err;
> +   vm_fault_t ret;
>
> /*
>  * vm_ops.open/drm_gem_mmap_obj and close get and put
>  * a reference on obj. So, we dont need to hold one here.
>  */
> -   ret = mutex_lock_interruptible(&msm_obj->lock);
> -   if (ret)
> +   err = mutex_lock_interruptible(&msm_obj->lock);
> +   if (err) {
> +   ret = VM_FAULT_NOPAGE;
> goto out;
> +   }
>
> if (WARN_ON(msm_obj->madv != MSM_MADV_WILLNEED)) {
> mutex_unlock(&msm_obj->lock);
> @@ -243,7 +246,7 @@ int msm_gem_fault(struct vm_fault *vmf)
> /* make sure we have pages attached now */
> pages = get_pages(obj);
> if (IS_ERR(pages)) {
> -   ret = PTR_ERR(pages);
> +   ret = vmf_error(PTR_ERR(pages));
> goto out_unlock;
> }
>
> @@ -255,27 +258,11 @@ int msm_gem_fault(struct vm_fault *vmf)
> VERB("Inserting %p pfn %lx, pa %lx", (void *)vmf->address,
> pfn, pfn << PAGE_SHIFT);
>
> -   ret = vm_insert_mixed(vma, vmf->address, __pfn_to_pfn_t(pfn, 
> PFN_DEV));
> -
> +   ret = vmf_insert_mixed(vma, vmf->address, __pfn_to_pfn_t(pfn, 
> PFN_DEV));
>  out_unlock:
> mutex_unlock(&msm_obj->lock);
>  out:
> -   switch (ret) {
> -   case -EAGAIN:
> -   case 0:
> -   case -ERESTARTSYS:
> -   case -EINTR:
> -   case -EBUSY:
> -   /*
> -* EBUSY is ok: this just means that another thread
> -* already did the job.
> -*/
> -   return VM_FAULT_NOPAGE;
> -   case -ENOMEM:
> -   return VM_FAULT_OOM;
> -   default:
> -   return VM_FAULT_SIGBUS;
> -   }
> +   return ret;
>  }
>
>  /** get mmap offset */
> --
> 1.9.1
>

Any comment for this patch ?


[PATCH v4] dax: Change return type to vm_fault_t

2018-05-11 Thread Souptick Joarder
Use new return type vm_fault_t for fault handler. For
now, this is just documenting that the function returns
a VM_FAULT value rather than an errno. Once all instances
are converted, vm_fault_t will become a distinct type.

Commit 1c8f422059ae ("mm: change return type to vm_fault_t")

Previously vm_insert_mixed() returns err which driver
mapped into VM_FAULT_* type. The new function 
vmf_insert_mixed() will replace this inefficiency by
returning VM_FAULT_* type.

Signed-off-by: Souptick Joarder 
Reviewed-by: Matthew Wilcox 
Reviewed-by: Ross Zwisler 
---
v2: Modified the change log

v3: Updated the change log and
added Ross in review list

v4: Addressed David's comment.
Changes in huge_memory.c put
together in a single patch that
it is bisectable in furture

 drivers/dax/device.c| 26 +++---
 include/linux/huge_mm.h |  5 +++--
 mm/huge_memory.c|  4 ++--
 3 files changed, 16 insertions(+), 19 deletions(-)

diff --git a/drivers/dax/device.c b/drivers/dax/device.c
index 2137dbc..a122701 100644
--- a/drivers/dax/device.c
+++ b/drivers/dax/device.c
@@ -243,11 +243,11 @@ __weak phys_addr_t dax_pgoff_to_phys(struct dev_dax 
*dev_dax, pgoff_t pgoff,
return -1;
 }
 
-static int __dev_dax_pte_fault(struct dev_dax *dev_dax, struct vm_fault *vmf)
+static vm_fault_t __dev_dax_pte_fault(struct dev_dax *dev_dax,
+   struct vm_fault *vmf)
 {
struct device *dev = &dev_dax->dev;
struct dax_region *dax_region;
-   int rc = VM_FAULT_SIGBUS;
phys_addr_t phys;
pfn_t pfn;
unsigned int fault_size = PAGE_SIZE;
@@ -274,17 +274,11 @@ static int __dev_dax_pte_fault(struct dev_dax *dev_dax, 
struct vm_fault *vmf)
 
pfn = phys_to_pfn_t(phys, dax_region->pfn_flags);
 
-   rc = vm_insert_mixed(vmf->vma, vmf->address, pfn);
-
-   if (rc == -ENOMEM)
-   return VM_FAULT_OOM;
-   if (rc < 0 && rc != -EBUSY)
-   return VM_FAULT_SIGBUS;
-
-   return VM_FAULT_NOPAGE;
+   return vmf_insert_mixed(vmf->vma, vmf->address, pfn);
 }
 
-static int __dev_dax_pmd_fault(struct dev_dax *dev_dax, struct vm_fault *vmf)
+static vm_fault_t __dev_dax_pmd_fault(struct dev_dax *dev_dax,
+   struct vm_fault *vmf)
 {
unsigned long pmd_addr = vmf->address & PMD_MASK;
struct device *dev = &dev_dax->dev;
@@ -335,7 +329,8 @@ static int __dev_dax_pmd_fault(struct dev_dax *dev_dax, 
struct vm_fault *vmf)
 }
 
 #ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD
-static int __dev_dax_pud_fault(struct dev_dax *dev_dax, struct vm_fault *vmf)
+static vm_fault_t __dev_dax_pud_fault(struct dev_dax *dev_dax,
+   struct vm_fault *vmf)
 {
unsigned long pud_addr = vmf->address & PUD_MASK;
struct device *dev = &dev_dax->dev;
@@ -386,13 +381,14 @@ static int __dev_dax_pud_fault(struct dev_dax *dev_dax, 
struct vm_fault *vmf)
vmf->flags & FAULT_FLAG_WRITE);
 }
 #else
-static int __dev_dax_pud_fault(struct dev_dax *dev_dax, struct vm_fault *vmf)
+static vm_fault_t __dev_dax_pud_fault(struct dev_dax *dev_dax,
+   struct vm_fault *vmf)
 {
return VM_FAULT_FALLBACK;
 }
 #endif /* !CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD */
 
-static int dev_dax_huge_fault(struct vm_fault *vmf,
+static vm_fault_t dev_dax_huge_fault(struct vm_fault *vmf,
enum page_entry_size pe_size)
 {
int rc, id;
@@ -423,7 +419,7 @@ static int dev_dax_huge_fault(struct vm_fault *vmf,
return rc;
 }
 
-static int dev_dax_fault(struct vm_fault *vmf)
+static vm_fault_t dev_dax_fault(struct vm_fault *vmf)
 {
return dev_dax_huge_fault(vmf, PE_SIZE_PTE);
 }
diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h
index a8a1262..d3bbf6b 100644
--- a/include/linux/huge_mm.h
+++ b/include/linux/huge_mm.h
@@ -3,6 +3,7 @@
 #define _LINUX_HUGE_MM_H
 
 #include 
+#include 
 
 #include  /* only for vma_is_dax() */
 
@@ -46,9 +47,9 @@ extern bool move_huge_pmd(struct vm_area_struct *vma, 
unsigned long old_addr,
 extern int change_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd,
unsigned long addr, pgprot_t newprot,
int prot_numa);
-int vmf_insert_pfn_pmd(struct vm_area_struct *vma, unsigned long addr,
+vm_fault_t vmf_insert_pfn_pmd(struct vm_area_struct *vma, unsigned long addr,
pmd_t *pmd, pfn_t pfn, bool write);
-int vmf_insert_pfn_pud(struct vm_area_struct *vma, unsigned long addr,
+vm_fault_t vmf_insert_pfn_pud(struct vm_area_struct *vma, unsigned long addr,
pud_t *pud, pfn_t pfn, bool write);
 enum transparent_hugepage_flag {
TRANSPARENT_HUGEPAGE_FLAG,
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 87ab9b8..1fe4705 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -75

Re: [PATCH v4] dax: Change return type to vm_fault_t

2018-05-11 Thread Souptick Joarder
On Fri, May 11, 2018 at 10:04 PM, Dan Williams  wrote:
> On Fri, May 11, 2018 at 9:34 AM, Souptick Joarder  
> wrote:
>> Use new return type vm_fault_t for fault handler. For
>> now, this is just documenting that the function returns
>> a VM_FAULT value rather than an errno. Once all instances
>> are converted, vm_fault_t will become a distinct type.
>>
>> Commit 1c8f422059ae ("mm: change return type to vm_fault_t")
>>
>> Previously vm_insert_mixed() returns err which driver
>> mapped into VM_FAULT_* type. The new function
>> vmf_insert_mixed() will replace this inefficiency by
>> returning VM_FAULT_* type.
>>
>> Signed-off-by: Souptick Joarder 
>> Reviewed-by: Matthew Wilcox 
>> Reviewed-by: Ross Zwisler 
>> ---
>> v2: Modified the change log
>>
>> v3: Updated the change log and
>> added Ross in review list
>>
>> v4: Addressed David's comment.
>> Changes in huge_memory.c put
>> together in a single patch that
>> it is bisectable in furture
>
> Thanks, I'll carry this in the nvdimm tree since it collides with some
> work-in progress development.

Thanks Dan :)


[PATCH v2] mm: Change return type to vm_fault_t

2018-05-11 Thread Souptick Joarder
Use new return type vm_fault_t for fault handler
in struct vm_operations_struct. For now, this is
just documenting that the function returns a 
VM_FAULT value rather than an errno.  Once all
instances are converted, vm_fault_t will become
a distinct type.

commit 1c8f422059ae ("mm: change return type to
vm_fault_t")

Signed-off-by: Souptick Joarder 
Reviewed-by: Matthew Wilcox 
---
v2: Updated the change log

 mm/hugetlb.c | 2 +-
 mm/mmap.c| 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 7c204e3..acb432a 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -3158,7 +3158,7 @@ static int hugetlb_vm_op_split(struct vm_area_struct 
*vma, unsigned long addr)
  * hugegpage VMA.  do_page_fault() is supposed to trap this, so BUG is we get
  * this far.
  */
-static int hugetlb_vm_op_fault(struct vm_fault *vmf)
+static vm_fault_t hugetlb_vm_op_fault(struct vm_fault *vmf)
 {
BUG();
return 0;
diff --git a/mm/mmap.c b/mm/mmap.c
index 9efdc021..ac41b34 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -3208,7 +3208,7 @@ void vm_stat_account(struct mm_struct *mm, vm_flags_t 
flags, long npages)
mm->data_vm += npages;
 }
 
-static int special_mapping_fault(struct vm_fault *vmf);
+static vm_fault_t special_mapping_fault(struct vm_fault *vmf);
 
 /*
  * Having a close hook prevents vma merging regardless of flags.
@@ -3247,7 +3247,7 @@ static int special_mapping_mremap(struct vm_area_struct 
*new_vma)
.fault = special_mapping_fault,
 };
 
-static int special_mapping_fault(struct vm_fault *vmf)
+static vm_fault_t special_mapping_fault(struct vm_fault *vmf)
 {
struct vm_area_struct *vma = vmf->vma;
pgoff_t pgoff;
-- 
1.9.1



Re: [PATCH] gpu: drm: tegra: Adding new typedef vm_fault_t

2018-05-11 Thread Souptick Joarder
On Mon, Apr 23, 2018 at 4:24 PM, Matthew Wilcox  wrote:
> On Wed, Apr 18, 2018 at 10:24:39AM +0200, Thierry Reding wrote:
>> > @@ -437,20 +436,7 @@ static int tegra_bo_fault(struct vm_fault *vmf)
>> > offset = (vmf->address - vma->vm_start) >> PAGE_SHIFT;
>> > page = bo->pages[offset];
>> >
>> > -   err = vm_insert_page(vma, vmf->address, page);
>> > -   switch (err) {
>> > -   case -EAGAIN:
>> > -   case 0:
>> > -   case -ERESTARTSYS:
>> > -   case -EINTR:
>> > -   case -EBUSY:
>> > -   return VM_FAULT_NOPAGE;
>> > -
>> > -   case -ENOMEM:
>> > -   return VM_FAULT_OOM;
>> > -   }
>> > -
>> > -   return VM_FAULT_SIGBUS;
>> > +   return vmf_insert_page(vma, vmf->address, page);
>> >  }
>>
>> This new function returns VM_FAULT_NOPAGE only for 0 and -EBUSY, whereas
>> we used to return VM_FAULT_NOPAGE for -EAGAIN, -ERESTARTSYS and -EINTR
>> as well. Was this previously wrong?
>
> Not so much wrong as unnecessary.  vm_insert_page() can't return -EAGAIN,
> -ERESTARTSYS or -EINTR.

If no further comment on this patch, We would like to get this patch
queued for 4.18.


Re: [PATCH v2] mm: Change return type to vm_fault_t

2018-05-11 Thread Souptick Joarder
On Fri, May 11, 2018 at 11:45 PM, Matthew Wilcox  wrote:
> On Fri, May 11, 2018 at 11:36:39PM +0530, Souptick Joarder wrote:
>>  mm/hugetlb.c | 2 +-
>>  mm/mmap.c| 4 ++--
>>  2 files changed, 3 insertions(+), 3 deletions(-)
>
> Don't we also need to convert include/linux/mm_types.h:
>
> @@ -621,7 +621,7 @@ struct vm_special_mapping {
>  * If non-NULL, then this is called to resolve page faults
>  * on the special mapping.  If used, .pages is not checked.
>  */
> -   int (*fault)(const struct vm_special_mapping *sm,
> +   vm_fault_t (*fault)(const struct vm_special_mapping *sm,
>  struct vm_area_struct *vma,
>  struct vm_fault *vmf);
>
> or are you leaving that for a later patch?

Ahh, I didn't realise. No I think, we can add it as part of this
patch. Will send v3.


[PATCH v2] mm: Adding new return type vm_fault_t

2018-05-11 Thread Souptick Joarder
Use new return type vm_fault_t for fault handler
in struct vm_operations_struct. For now, this is
just documenting that the function returns a 
VM_FAULT value rather than an errno.  Once all
instances are converted, vm_fault_t will become
a distinct type.

commit 1c8f422059ae ("mm: change return type to
vm_fault_t")

Signed-off-by: Souptick Joarder 
Reviewed-by: Matthew Wilcox 
---
v2: updated the change log

 include/linux/mm.h | 4 ++--
 mm/filemap.c   | 8 
 mm/nommu.c | 2 +-
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index ad06d42..7fc4baf 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -2281,10 +2281,10 @@ extern void truncate_inode_pages_range(struct 
address_space *,
 extern void truncate_inode_pages_final(struct address_space *);

 /* generic vm_area_ops exported for stackable file systems */
-extern int filemap_fault(struct vm_fault *vmf);
+extern vm_fault_t filemap_fault(struct vm_fault *vmf);
 extern void filemap_map_pages(struct vm_fault *vmf,
pgoff_t start_pgoff, pgoff_t end_pgoff);
-extern int filemap_page_mkwrite(struct vm_fault *vmf);
+extern vm_fault_t filemap_page_mkwrite(struct vm_fault *vmf);

 /* mm/page-writeback.c */
 int __must_check write_one_page(struct page *page);
diff --git a/mm/filemap.c b/mm/filemap.c
index 693f622..cae7e4f 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -2491,7 +2491,7 @@ static void do_async_mmap_readahead(struct vm_area_struct 
*vma,
  *
  * We never return with VM_FAULT_RETRY and a bit from VM_FAULT_ERROR set.
  */
-int filemap_fault(struct vm_fault *vmf)
+vm_fault_t filemap_fault(struct vm_fault *vmf)
 {
int error;
struct file *file = vmf->vma->vm_file;
@@ -2501,7 +2501,7 @@ int filemap_fault(struct vm_fault *vmf)
pgoff_t offset = vmf->pgoff;
pgoff_t max_off;
struct page *page;
-   int ret = 0;
+   vm_fault_t ret = 0;

max_off = DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE);
if (unlikely(offset >= max_off))
@@ -2696,11 +2696,11 @@ void filemap_map_pages(struct vm_fault *vmf,
 }
 EXPORT_SYMBOL(filemap_map_pages);

-int filemap_page_mkwrite(struct vm_fault *vmf)
+vm_fault_t filemap_page_mkwrite(struct vm_fault *vmf)
 {
struct page *page = vmf->page;
struct inode *inode = file_inode(vmf->vma->vm_file);
-   int ret = VM_FAULT_LOCKED;
+   vm_fault_t ret = VM_FAULT_LOCKED;

sb_start_pagefault(inode->i_sb);
file_update_time(vmf->vma->vm_file);
diff --git a/mm/nommu.c b/mm/nommu.c
index ebb6e61..90456a6 100644
--- a/mm/nommu.c
+++ b/mm/nommu.c
@@ -1788,7 +1788,7 @@ unsigned long arch_get_unmapped_area(struct file *file, 
unsigned long addr,
return -ENOMEM;
 }

-int filemap_fault(struct vm_fault *vmf)
+vm_fault_t filemap_fault(struct vm_fault *vmf)
 {
BUG();
return 0;
--
1.9.1



[PATCH v3] mm: Change return type to vm_fault_t

2018-05-11 Thread Souptick Joarder
Use new return type vm_fault_t for fault handler
in struct vm_operations_struct. For now, this is
just documenting that the function returns a
VM_FAULT value rather than an errno.  Once all
instances are converted, vm_fault_t will become
a distinct type.

commit 1c8f422059ae ("mm: change return type to
vm_fault_t")

Signed-off-by: Souptick Joarder 
Reviewed-by: Matthew Wilcox 
---
v2: updated the change log

v3: added  changes
into the same patch

 include/linux/mm_types.h | 2 +-
 mm/hugetlb.c | 2 +-
 mm/mmap.c| 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
index 2161234..11acfdb 100644
--- a/include/linux/mm_types.h
+++ b/include/linux/mm_types.h
@@ -627,7 +627,7 @@ struct vm_special_mapping {
 * If non-NULL, then this is called to resolve page faults
 * on the special mapping.  If used, .pages is not checked.
 */
-   int (*fault)(const struct vm_special_mapping *sm,
+   vm_fault_t (*fault)(const struct vm_special_mapping *sm,
 struct vm_area_struct *vma,
 struct vm_fault *vmf);
 
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 2186791..7e00bd3 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -3159,7 +3159,7 @@ static unsigned long hugetlb_vm_op_pagesize(struct 
vm_area_struct *vma)
  * hugegpage VMA.  do_page_fault() is supposed to trap this, so BUG is we get
  * this far.
  */
-static int hugetlb_vm_op_fault(struct vm_fault *vmf)
+static vm_fault_t hugetlb_vm_op_fault(struct vm_fault *vmf)
 {
BUG();
return 0;
diff --git a/mm/mmap.c b/mm/mmap.c
index 188f195..bdd4ba9a 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -3228,7 +3228,7 @@ void vm_stat_account(struct mm_struct *mm, vm_flags_t 
flags, long npages)
mm->data_vm += npages;
 }
 
-static int special_mapping_fault(struct vm_fault *vmf);
+static vm_fault_t special_mapping_fault(struct vm_fault *vmf);
 
 /*
  * Having a close hook prevents vma merging regardless of flags.
@@ -3267,7 +3267,7 @@ static int special_mapping_mremap(struct vm_area_struct 
*new_vma)
.fault = special_mapping_fault,
 };
 
-static int special_mapping_fault(struct vm_fault *vmf)
+static vm_fault_t special_mapping_fault(struct vm_fault *vmf)
 {
struct vm_area_struct *vma = vmf->vma;
pgoff_t pgoff;
-- 
1.9.1



Re: [PATCH v3] mm: Change return type to vm_fault_t

2018-05-11 Thread Souptick Joarder
On Sat, May 12, 2018 at 11:50 AM, Joe Perches  wrote:
> On Sat, 2018-05-12 at 11:47 +0530, Souptick Joarder wrote:
>> Use new return type vm_fault_t for fault handler
>> in struct vm_operations_struct. For now, this is
>> just documenting that the function returns a
>> VM_FAULT value rather than an errno.  Once all
>> instances are converted, vm_fault_t will become
>> a distinct type.
>
> trivia:
>
>> diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
> []
>> @@ -627,7 +627,7 @@ struct vm_special_mapping {
>>* If non-NULL, then this is called to resolve page faults
>>* on the special mapping.  If used, .pages is not checked.
>>*/
>> - int (*fault)(const struct vm_special_mapping *sm,
>> + vm_fault_t (*fault)(const struct vm_special_mapping *sm,
>>struct vm_area_struct *vma,
>>struct vm_fault *vmf);
>
>
> It'd be nicer to realign the 2nd and 3rd arguments
> on the subsequent lines.
>
> vm_fault_t (*fault)(const struct vm_special_mapping *sm,
> struct vm_area_struct *vma,
> struct vm_fault *vmf);
>

Just now posted v3. Do you want me to send v4 again with
realignment ?


Re: [PATCH v3] mm: Change return type to vm_fault_t

2018-05-11 Thread Souptick Joarder
On Sat, May 12, 2018 at 11:55 AM, Souptick Joarder  wrote:
> On Sat, May 12, 2018 at 11:50 AM, Joe Perches  wrote:
>> On Sat, 2018-05-12 at 11:47 +0530, Souptick Joarder wrote:
>>> Use new return type vm_fault_t for fault handler
>>> in struct vm_operations_struct. For now, this is
>>> just documenting that the function returns a
>>> VM_FAULT value rather than an errno.  Once all
>>> instances are converted, vm_fault_t will become
>>> a distinct type.
>>
>> trivia:
>>
>>> diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
>> []
>>> @@ -627,7 +627,7 @@ struct vm_special_mapping {
>>>* If non-NULL, then this is called to resolve page faults
>>>* on the special mapping.  If used, .pages is not checked.
>>>*/
>>> - int (*fault)(const struct vm_special_mapping *sm,
>>> + vm_fault_t (*fault)(const struct vm_special_mapping *sm,
>>>struct vm_area_struct *vma,
>>>struct vm_fault *vmf);
>>
>>
>> It'd be nicer to realign the 2nd and 3rd arguments
>> on the subsequent lines.
>>
>> vm_fault_t (*fault)(const struct vm_special_mapping *sm,
>> struct vm_area_struct *vma,
>> struct vm_fault *vmf);
>>
>
> Just now posted v3. Do you want me to send v4 again with
> realignment ?

Sorry, please ignore this mail.


[PATCH v4] mm: Change return type to vm_fault_t

2018-05-11 Thread Souptick Joarder
Use new return type vm_fault_t for fault handler
in struct vm_operations_struct. For now, this is
just documenting that the function returns a
VM_FAULT value rather than an errno.  Once all
instances are converted, vm_fault_t will become
a distinct type.

commit 1c8f422059ae ("mm: change return type to
vm_fault_t")

Signed-off-by: Souptick Joarder 
Reviewed-by: Matthew Wilcox 
---
 include/linux/mm_types.h | 6 +++---
 mm/hugetlb.c | 2 +-
 mm/mmap.c| 4 ++--
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
index 2161234..cde40e6 100644
--- a/include/linux/mm_types.h
+++ b/include/linux/mm_types.h
@@ -627,9 +627,9 @@ struct vm_special_mapping {
 * If non-NULL, then this is called to resolve page faults
 * on the special mapping.  If used, .pages is not checked.
 */
-   int (*fault)(const struct vm_special_mapping *sm,
-struct vm_area_struct *vma,
-struct vm_fault *vmf);
+   vm_fault_t (*fault)(const struct vm_special_mapping *sm,
+   struct vm_area_struct *vma,
+   struct vm_fault *vmf);
 
int (*mremap)(const struct vm_special_mapping *sm,
 struct vm_area_struct *new_vma);
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 2186791..7e00bd3 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -3159,7 +3159,7 @@ static unsigned long hugetlb_vm_op_pagesize(struct 
vm_area_struct *vma)
  * hugegpage VMA.  do_page_fault() is supposed to trap this, so BUG is we get
  * this far.
  */
-static int hugetlb_vm_op_fault(struct vm_fault *vmf)
+static vm_fault_t hugetlb_vm_op_fault(struct vm_fault *vmf)
 {
BUG();
return 0;
diff --git a/mm/mmap.c b/mm/mmap.c
index 188f195..bdd4ba9a 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -3228,7 +3228,7 @@ void vm_stat_account(struct mm_struct *mm, vm_flags_t 
flags, long npages)
mm->data_vm += npages;
 }
 
-static int special_mapping_fault(struct vm_fault *vmf);
+static vm_fault_t special_mapping_fault(struct vm_fault *vmf);
 
 /*
  * Having a close hook prevents vma merging regardless of flags.
@@ -3267,7 +3267,7 @@ static int special_mapping_mremap(struct vm_area_struct 
*new_vma)
.fault = special_mapping_fault,
 };
 
-static int special_mapping_fault(struct vm_fault *vmf)
+static vm_fault_t special_mapping_fault(struct vm_fault *vmf)
 {
struct vm_area_struct *vma = vmf->vma;
pgoff_t pgoff;
-- 
1.9.1



Re: [PATCH v3] mm: Change return type to vm_fault_t

2018-05-12 Thread Souptick Joarder
>> It'd be nicer to realign the 2nd and 3rd arguments
>> on the subsequent lines.

>>
>>   vm_fault_t (*fault)(const struct vm_special_mapping *sm,
>>   struct vm_area_struct *vma,
>>   struct vm_fault *vmf);
>>
>

> It'd be nicer if people didn't try to line up arguments at all and
> just indented by an extra two tabs when they had to break a logical
> line due to the 80-column limit.

Matthew, there are two different opinions. Which one to take ?


Re: [PATCH] gpu: drm: qxl: Adding new typedef vm_fault_t

2018-05-14 Thread Souptick Joarder
On Mon, May 14, 2018 at 2:32 PM, Gerd Hoffmann  wrote:
>   Hi,
>
>> > So my expectation that a backmerge happens anyway after -rc1/2 is in
>> > line with reality, it is just to be delayed this time.  I'll stay
>> > tuned ;)
>>
>> Is this patch already merged in drm-misc-next tree ?
>
> Pushed now.
>

Thanks Gerd :)


Re: [PATCH] hwtracing: intel_th: Change return type to vm_fault_t

2018-06-16 Thread Souptick Joarder
On Wed, May 2, 2018 at 7:32 PM, Souptick Joarder  wrote:
> On 02-May-2018 7:28 PM, "Alexander Shishkin"
>  wrote:
>>
>> On Wed, May 02, 2018 at 11:14:48AM +0530, Souptick Joarder wrote:
>> > Any comment for this patch ?
>>
>> Looks good, I'm queuing this one for the next merge window.
>>

This patch is not merged in 4.18-rc-1.


Re: [Freedreno] [PATCH] gpu: drm: msm: Change return type to vm_fault_t

2018-06-17 Thread Souptick Joarder
On Thu, May 31, 2018 at 11:29 PM, Jordan Crouse  wrote:
> On Mon, May 28, 2018 at 12:38:41PM +0530, Souptick Joarder wrote:
>> On Mon, May 21, 2018 at 10:59 PM, Souptick Joarder  
>> wrote:
>> > Use new return type vm_fault_t for fault handler. For
>> > now, this is just documenting that the function returns
>> > a VM_FAULT value rather than an errno. Once all instances
>> > are converted, vm_fault_t will become a distinct type.
>> >
>> > Ref- commit 1c8f422059ae ("mm: change return type to vm_fault_t")
>> >
>> > Previously vm_insert_mixed() returns err which driver
>> > mapped into VM_FAULT_* type. The new function
>> > vmf_insert_mixed() will replace this inefficiency by
>> > returning VM_FAULT_* type.
>> >
>> > vmf_error() is the newly introduce inline function
>> > in 4.17-rc6.
>> >
>> > Signed-off-by: Souptick Joarder 
>> > Reviewed-by: Matthew Wilcox 
>> > ---
>> >  drivers/gpu/drm/msm/msm_drv.h |  3 ++-
>> >  drivers/gpu/drm/msm/msm_gem.c | 33 ++---
>> >  2 files changed, 12 insertions(+), 24 deletions(-)
>> >
>> > diff --git a/drivers/gpu/drm/msm/msm_drv.h b/drivers/gpu/drm/msm/msm_drv.h
>> > index 0a653dd..44b4ca7 100644
>> > --- a/drivers/gpu/drm/msm/msm_drv.h
>> > +++ b/drivers/gpu/drm/msm/msm_drv.h
>> > @@ -33,6 +33,7 @@
>> >  #include 
>> >  #include 
>> >  #include 
>> > +#include 
>> >
>> >  #include 
>> >  #include 
>> > @@ -188,7 +189,7 @@ int msm_ioctl_gem_submit(struct drm_device *dev, void 
>> > *data,
>> >  int msm_gem_mmap_obj(struct drm_gem_object *obj,
>> > struct vm_area_struct *vma);
>> >  int msm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
>> > -int msm_gem_fault(struct vm_fault *vmf);
>> > +vm_fault_t msm_gem_fault(struct vm_fault *vmf);
>> >  uint64_t msm_gem_mmap_offset(struct drm_gem_object *obj);
>> >  int msm_gem_get_iova(struct drm_gem_object *obj,
>> > struct msm_gem_address_space *aspace, uint64_t *iova);
>> > diff --git a/drivers/gpu/drm/msm/msm_gem.c b/drivers/gpu/drm/msm/msm_gem.c
>> > index 07376de..27a5ab5 100644
>> > --- a/drivers/gpu/drm/msm/msm_gem.c
>> > +++ b/drivers/gpu/drm/msm/msm_gem.c
>> > @@ -217,7 +217,7 @@ int msm_gem_mmap(struct file *filp, struct 
>> > vm_area_struct *vma)
>> > return msm_gem_mmap_obj(vma->vm_private_data, vma);
>> >  }
>> >
>> > -int msm_gem_fault(struct vm_fault *vmf)
>> > +vm_fault_t msm_gem_fault(struct vm_fault *vmf)
>> >  {
>> > struct vm_area_struct *vma = vmf->vma;
>> > struct drm_gem_object *obj = vma->vm_private_data;
>> > @@ -225,15 +225,18 @@ int msm_gem_fault(struct vm_fault *vmf)
>> > struct page **pages;
>> > unsigned long pfn;
>> > pgoff_t pgoff;
>> > -   int ret;
>> > +   int err;
>> > +   vm_fault_t ret;
>> >
>> > /*
>> >  * vm_ops.open/drm_gem_mmap_obj and close get and put
>> >  * a reference on obj. So, we dont need to hold one here.
>> >  */
>> > -   ret = mutex_lock_interruptible(&msm_obj->lock);
>> > -   if (ret)
>> > +   err = mutex_lock_interruptible(&msm_obj->lock);
>> > +   if (err) {
>> > +   ret = VM_FAULT_NOPAGE;
>> > goto out;
>> > +   }
>> >
>> > if (WARN_ON(msm_obj->madv != MSM_MADV_WILLNEED)) {
>> > mutex_unlock(&msm_obj->lock);
>> > @@ -243,7 +246,7 @@ int msm_gem_fault(struct vm_fault *vmf)
>> > /* make sure we have pages attached now */
>> > pages = get_pages(obj);
>> > if (IS_ERR(pages)) {
>> > -   ret = PTR_ERR(pages);
>> > +   ret = vmf_error(PTR_ERR(pages));
>> > goto out_unlock;
>> > }
>> >
>> > @@ -255,27 +258,11 @@ int msm_gem_fault(struct vm_fault *vmf)
>> > VERB("Inserting %p pfn %lx, pa %lx", (void *)vmf->address,
>> > pfn, pfn << PAGE_SHIFT);
>> >
>> > -   ret = vm_insert_mixed(vma, vmf->address, __pfn_to_pfn_t(pfn, 
>> > PFN_DEV));
>> > -
>> > +   ret = vmf_insert_mixed(vma, vmf->address, __pfn_to_pfn_t(pfn, 
>> > PFN_DEV));
>> >  out_unlock:
>> > mutex_unlock(&msm_obj->lock);
>> >  out:
>> > -   switch (ret) {
>> > -   case -EAGAIN:
>> > -   case 0:
>> > -   case -ERESTARTSYS:
>> > -   case -EINTR:
>> > -   case -EBUSY:
>> > -   /*
>> > -* EBUSY is ok: this just means that another thread
>> > -* already did the job.
>> > -*/
>> > -   return VM_FAULT_NOPAGE;
>> > -   case -ENOMEM:
>> > -   return VM_FAULT_OOM;
>> > -   default:
>> > -   return VM_FAULT_SIGBUS;
>> > -   }
>> > +   return ret;
>> >  }
>> >
>> >  /** get mmap offset */
>> > --
>> > 1.9.1
>> >
>>
>> Any comment for this patch ?
>
> Sorry for the delay, I wanted to get a chance to test it. It seems to pass the
> usual regression tests. LGTM.
>

Jordan, This patch is not merged in 4.18-rc-1.


Re: [PATCH v2] char: agp: Change return type to vm_fault_t

2018-06-18 Thread Souptick Joarder
On Thu, May 31, 2018 at 10:38 AM, Souptick Joarder  wrote:
> On Mon, May 21, 2018 at 11:47 PM, Souptick Joarder  
> wrote:
>> Use new return type vm_fault_t for fault handler. For now,
>> this is just documenting that the function returns a
>> VM_FAULT value rather than an errno. Once all instances are
>> converted, vm_fault_t will become a distinct type.
>>
>> Ref-> commit 1c8f422059ae ("mm: change return type to
>> vm_fault_t") was added in 4.17-rc1 to introduce the new
>> typedef vm_fault_t. Currently we are making change to all
>> drivers to return vm_fault_t for page fault handlers. As
>> part of that char/agp driver is also getting changed to
>> return vm_fault_t type from fault handler.
>>
>> Signed-off-by: Souptick Joarder 
>> Reviewed-by: Matthew Wilcox 
>> ---
>>  drivers/char/agp/alpha-agp.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/char/agp/alpha-agp.c b/drivers/char/agp/alpha-agp.c
>> index 53fe633..c9bf2c2 100644
>> --- a/drivers/char/agp/alpha-agp.c
>> +++ b/drivers/char/agp/alpha-agp.c
>> @@ -11,7 +11,7 @@
>>
>>  #include "agp.h"
>>
>> -static int alpha_core_agp_vm_fault(struct vm_fault *vmf)
>> +static vm_fault_t alpha_core_agp_vm_fault(struct vm_fault *vmf)
>>  {
>> alpha_agp_info *agp = agp_bridge->dev_private_data;
>> dma_addr_t dma_addr;
>> --
>> 1.9.1
>>
>
> Any comment for this patch ?

Any further comment on this patch ?


Re: [PATCH v3] mm: Change return type int to vm_fault_t for fault handlers

2018-06-18 Thread Souptick Joarder
On Mon, Jun 4, 2018 at 10:47 PM, Souptick Joarder  wrote:
> Use new return type vm_fault_t for fault handler. For
> now, this is just documenting that the function returns
> a VM_FAULT value rather than an errno. Once all instances
> are converted, vm_fault_t will become a distinct type.
>
> Ref-> commit 1c8f422059ae ("mm: change return type to vm_fault_t")
>
> The aim is to change the return type of finish_fault()
> and handle_mm_fault() to vm_fault_t type. As part of
> that clean up return type of all other recursively called
> functions have been changed to vm_fault_t type.
>
> The places from where handle_mm_fault() is getting invoked
> will be change to vm_fault_t type but in a separate patch.
>
> vmf_error() is the newly introduce inline function
> in 4.17-rc6.
>
> Signed-off-by: Souptick Joarder 
> Reviewed-by: Matthew Wilcox 
> ---
> v2: Change patch title and fixed sparse warning.
>
> v3: Reviewed by Matthew Wilcox
>
>  fs/userfaultfd.c  |  6 +--
>  include/linux/huge_mm.h   | 10 +++--
>  include/linux/hugetlb.h   |  2 +-
>  include/linux/mm.h| 14 +++
>  include/linux/oom.h   |  2 +-
>  include/linux/swapops.h   |  5 ++-
>  include/linux/userfaultfd_k.h |  5 ++-
>  kernel/memremap.c |  2 +-
>  mm/gup.c  |  4 +-
>  mm/huge_memory.c  | 25 ++--
>  mm/hugetlb.c  | 29 +++---
>  mm/internal.h |  2 +-
>  mm/khugepaged.c   |  3 +-
>  mm/memory.c   | 90 
> ++-
>  mm/shmem.c| 17 
>  15 files changed, 110 insertions(+), 106 deletions(-)
>
> diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c
> index cec550c..bf60c6a 100644
> --- a/fs/userfaultfd.c
> +++ b/fs/userfaultfd.c
> @@ -336,17 +336,15 @@ static inline bool userfaultfd_must_wait(struct 
> userfaultfd_ctx *ctx,
>   * fatal_signal_pending()s, and the mmap_sem must be released before
>   * returning it.
>   */
> -int handle_userfault(struct vm_fault *vmf, unsigned long reason)
> +vm_fault_t handle_userfault(struct vm_fault *vmf, unsigned long reason)
>  {
> struct mm_struct *mm = vmf->vma->vm_mm;
> struct userfaultfd_ctx *ctx;
> struct userfaultfd_wait_queue uwq;
> -   int ret;
> +   vm_fault_t ret = VM_FAULT_SIGBUS;
> bool must_wait, return_to_userland;
> long blocking_state;
>
> -   ret = VM_FAULT_SIGBUS;
> -
> /*
>  * We don't do userfault handling for the final child pid update.
>  *
> diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h
> index a8a1262..8c4f0a6 100644
> --- a/include/linux/huge_mm.h
> +++ b/include/linux/huge_mm.h
> @@ -3,10 +3,11 @@
>  #define _LINUX_HUGE_MM_H
>
>  #include 
> +#include 
>
>  #include  /* only for vma_is_dax() */
>
> -extern int do_huge_pmd_anonymous_page(struct vm_fault *vmf);
> +extern vm_fault_t do_huge_pmd_anonymous_page(struct vm_fault *vmf);
>  extern int copy_huge_pmd(struct mm_struct *dst_mm, struct mm_struct *src_mm,
>  pmd_t *dst_pmd, pmd_t *src_pmd, unsigned long addr,
>  struct vm_area_struct *vma);
> @@ -23,7 +24,7 @@ static inline void huge_pud_set_accessed(struct vm_fault 
> *vmf, pud_t orig_pud)
>  }
>  #endif
>
> -extern int do_huge_pmd_wp_page(struct vm_fault *vmf, pmd_t orig_pmd);
> +extern vm_fault_t do_huge_pmd_wp_page(struct vm_fault *vmf, pmd_t orig_pmd);
>  extern struct page *follow_trans_huge_pmd(struct vm_area_struct *vma,
>   unsigned long addr,
>   pmd_t *pmd,
> @@ -216,7 +217,7 @@ struct page *follow_devmap_pmd(struct vm_area_struct 
> *vma, unsigned long addr,
>  struct page *follow_devmap_pud(struct vm_area_struct *vma, unsigned long 
> addr,
> pud_t *pud, int flags);
>
> -extern int do_huge_pmd_numa_page(struct vm_fault *vmf, pmd_t orig_pmd);
> +extern vm_fault_t do_huge_pmd_numa_page(struct vm_fault *vmf, pmd_t 
> orig_pmd);
>
>  extern struct page *huge_zero_page;
>
> @@ -321,7 +322,8 @@ static inline spinlock_t *pud_trans_huge_lock(pud_t *pud,
> return NULL;
>  }
>
> -static inline int do_huge_pmd_numa_page(struct vm_fault *vmf, pmd_t orig_pmd)
> +static inline vm_fault_t do_huge_pmd_numa_page(struct vm_fault *vmf,
> +   pmd_t orig_pmd)
>  {
> return 0;
>  }
> diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
> index 36fa6a2..c779b2f 100644
> --- a/include/linux/hugetlb.h
> +++ b/include/linux/huge

Re: [PATCH] mm: Change return type to vm_fault_t

2018-05-29 Thread Souptick Joarder
On Tue, May 29, 2018 at 11:04 PM, Matthew Wilcox  wrote:
> On Tue, May 29, 2018 at 09:25:05PM +0530, Souptick Joarder wrote:
>> On Tue, May 29, 2018 at 8:20 PM, Matthew Wilcox  wrote:
>> > On Tue, May 29, 2018 at 08:01:26PM +0530, Souptick Joarder wrote:
>> >> Use new return type vm_fault_t for fault handler. For
>> >> now, this is just documenting that the function returns
>> >> a VM_FAULT value rather than an errno. Once all instances
>> >> are converted, vm_fault_t will become a distinct type.
>> >
>> > I don't believe you've checked this with sparse.
>> >
>> >> @@ -802,7 +802,8 @@ int fixup_user_fault(struct task_struct *tsk, struct 
>> >> mm_struct *mm,
>> >>bool *unlocked)
>> >>  {
>> >>   struct vm_area_struct *vma;
>> >> - int ret, major = 0;
>> >> + int major = 0;
>> >> + vm_fault_t ret;
>> >>
>> >>   if (unlocked)
>> >>   fault_flags |= FAULT_FLAG_ALLOW_RETRY;
>> >
>> > ...
>> > major |= ret & VM_FAULT_MAJOR;
>> >
>> > That should be throwing a warning.
>>
>> Sorry, but I verified again and didn't see similar warnings.
>>
>> steps followed -
>>
>> apply the patch
>> make c=2 -j4 ( build for x86_64)
>> looking for warnings in files because of this patch.
>>
>> The only error I am seeing "error: undefined identifier '__COUNTER__' "
>> which is pointing to BUG(). There are few warnings but those are not
>> related to this patch.
>>
>> In my test tree the final patch to create new vm_fault_t type is
>> already applied.
>>
>> Do you want me to verify in some other way ?
>
> I see:
>
> mm/gup.c:817:15: warning: invalid assignment: |=
> mm/gup.c:817:15:left side has type int
> mm/gup.c:817:15:right side has type restricted vm_fault_t
>
> are you building with 'c=2' or 'C=2'?

Building with C=2.
Do I need to enable any separate FLAG ?


Re: [PATCH v2] char: agp: Change return type to vm_fault_t

2018-05-30 Thread Souptick Joarder
On Mon, May 21, 2018 at 11:47 PM, Souptick Joarder  wrote:
> Use new return type vm_fault_t for fault handler. For now,
> this is just documenting that the function returns a
> VM_FAULT value rather than an errno. Once all instances are
> converted, vm_fault_t will become a distinct type.
>
> Ref-> commit 1c8f422059ae ("mm: change return type to
> vm_fault_t") was added in 4.17-rc1 to introduce the new
> typedef vm_fault_t. Currently we are making change to all
> drivers to return vm_fault_t for page fault handlers. As
> part of that char/agp driver is also getting changed to
> return vm_fault_t type from fault handler.
>
> Signed-off-by: Souptick Joarder 
> Reviewed-by: Matthew Wilcox 
> ---
>  drivers/char/agp/alpha-agp.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/char/agp/alpha-agp.c b/drivers/char/agp/alpha-agp.c
> index 53fe633..c9bf2c2 100644
> --- a/drivers/char/agp/alpha-agp.c
> +++ b/drivers/char/agp/alpha-agp.c
> @@ -11,7 +11,7 @@
>
>  #include "agp.h"
>
> -static int alpha_core_agp_vm_fault(struct vm_fault *vmf)
> +static vm_fault_t alpha_core_agp_vm_fault(struct vm_fault *vmf)
>  {
> alpha_agp_info *agp = agp_bridge->dev_private_data;
> dma_addr_t dma_addr;
> --
> 1.9.1
>

Any comment for this patch ?


Re: [PATCH] mm: Change return type to vm_fault_t

2018-06-02 Thread Souptick Joarder
On Wed, May 30, 2018 at 4:46 PM, Matthew Wilcox  wrote:
> On Wed, May 30, 2018 at 09:10:47AM +0530, Souptick Joarder wrote:
>> On Tue, May 29, 2018 at 11:04 PM, Matthew Wilcox  wrote:
>> > I see:
>> >
>> > mm/gup.c:817:15: warning: invalid assignment: |=
>> > mm/gup.c:817:15:left side has type int
>> > mm/gup.c:817:15:right side has type restricted vm_fault_t
>> >
>> > are you building with 'c=2' or 'C=2'?
>>
>> Building with C=2.
>> Do I need to enable any separate FLAG ?
>
> Nope.  Here's what I have:
>
> willy@bobo:~/kernel/souptick$ make C=2 mm/gup.o
>   CHK include/config/kernel.release
>   CHK include/generated/uapi/linux/version.h
>   CHK include/generated/utsrelease.h
>   CHECK   arch/x86/purgatory/purgatory.c
>   CHECK   arch/x86/purgatory/sha256.c
>   CHECK   arch/x86/purgatory/string.c
> arch/x86/purgatory/../boot/string.c:134:6: warning: symbol 'simple_strtol' 
> was not declared. Should it be static?
>   CHK include/generated/bounds.h
>   CHK include/generated/timeconst.h
>   CHK include/generated/asm-offsets.h
>   CALLscripts/checksyscalls.sh
>   DESCEND  objtool
>   CHECK   scripts/mod/empty.c
>   CHK scripts/mod/devicetable-offsets.h
>   CHECK   mm/gup.c
> mm/gup.c:817:15: warning: invalid assignment: |=
> mm/gup.c:817:15:left side has type int
> mm/gup.c:817:15:right side has type restricted vm_fault_t
>   CC  mm/gup.o
>

Matthew,

Due to some unidentified error still not able to catch this warning
in (X86_64 + sparse) compilation. It is constantly showing below error.

Documents/linux-4.17-rc7$ make C=2 -j4 mm/gup.o
  CHK include/config/kernel.release
  CHK include/generated/uapi/linux/version.h
  DESCEND  objtool
  CHK include/generated/utsrelease.h
  CHECK   scripts/mod/empty.c
  CHK scripts/mod/devicetable-offsets.h
  CHK include/generated/bounds.h
  CHK include/generated/timeconst.h
  CHK include/generated/asm-offsets.h
  CALLscripts/checksyscalls.sh
  CHECK   mm/gup.c
mm/gup.c:394:17: error: undefined identifier '__COUNTER__'
mm/gup.c:439:9: error: undefined identifier '__COUNTER__'
mm/gup.c:441:9: error: undefined identifier '__COUNTER__'
mm/gup.c:443:9: error: undefined identifier '__COUNTER__'
mm/gup.c:508:17: error: undefined identifier '__COUNTER__'
mm/gup.c:716:25: error: undefined identifier '__COUNTER__'
mm/gup.c:826:17: error: undefined identifier '__COUNTER__'
mm/gup.c:863:17: error: undefined identifier '__COUNTER__'
mm/gup.c:865:17: error: undefined identifier '__COUNTER__'
mm/gup.c:882:25: error: undefined identifier '__COUNTER__'
mm/gup.c:883:25: error: undefined identifier '__COUNTER__'
mm/gup.c:920:25: error: undefined identifier '__COUNTER__'
./include/linux/hugetlb.h:239:9: error: undefined identifier '__COUNTER__'


But able to capture it in (powerpc + sparse) compilation.
I will fix it in v2.

/Documents/linux-4.17-rc7$ make C=2 ARCH=powerpc
CROSS_COMPILE=powerpc-linux-gnu- mm/gup.o
  CHK include/config/kernel.release
  CHK include/generated/uapi/linux/version.h
  CHK include/generated/utsrelease.h
  CHK include/generated/bounds.h
  CHK include/generated/timeconst.h
  CHK include/generated/asm-offsets.h
  CALLscripts/checksyscalls.sh
  CHECK   scripts/mod/empty.c
  CHK scripts/mod/devicetable-offsets.h
  CHECK   mm/gup.c
./arch/powerpc/include/asm/book3s/64/pgtable.h:669:24: warning:
restricted __be64 degrades to integer
mm/gup.c:820:15: warning: incorrect type in assignment (different base types)
mm/gup.c:820:15:expected int [signed] major
mm/gup.c:820:15:got restricted vm_fault_t
mm/gup.c:1247:24: warning: expression using sizeof bool
mm/gup.c:1247:24: warning: expression using sizeof(void)
mm/gup.c:1247:24: warning: expression using sizeof(void)
./arch/powerpc/include/asm/book3s/64/pgtable.h:667:20: warning:
incorrect type in initializer (different base types)
./arch/powerpc/include/asm/book3s/64/pgtable.h:667:20:expected
unsigned long long [unsigned] [usertype] mask
./arch/powerpc/include/asm/book3s/64/pgtable.h:667:20:got
restricted __be64 [usertype] 
mm/gup.c:1735:6: warning: symbol 'gup_fast_permitted' was not
declared. Should it be static?
  CC  mm/gup.o


Sparse is throwing below warning ->

/Documents/linux-4.17-rc7$ make C=2 ARCH=powerpc
CROSS_COMPILE=powerpc-linux-gnu- mm/hugetlb.o
  CHK include/config/kernel.release
  CHK include/generated/uapi/linux/version.h
  CHK include/generated/utsrelease.h
  CHK include/generated/bounds.h
  CHK include/generated/timeconst.h
  CHK include/generated/asm-offsets.h
  CALLscripts/checksyscalls.sh
  CHECK   script

Re: [PATCH] mm: Change return type to vm_fault_t

2018-06-02 Thread Souptick Joarder
Please ignoe this mail. I send it by mistake.

On Sat, Jun 2, 2018 at 8:14 PM, Souptick Joarder  wrote:
> On Wed, May 30, 2018 at 4:46 PM, Matthew Wilcox  wrote:
>> On Wed, May 30, 2018 at 09:10:47AM +0530, Souptick Joarder wrote:
>>> On Tue, May 29, 2018 at 11:04 PM, Matthew Wilcox  
>>> wrote:
>>> > I see:
>>> >
>>> > mm/gup.c:817:15: warning: invalid assignment: |=
>>> > mm/gup.c:817:15:left side has type int
>>> > mm/gup.c:817:15:right side has type restricted vm_fault_t
>>> >
>>> > are you building with 'c=2' or 'C=2'?
>>>
>>> Building with C=2.
>>> Do I need to enable any separate FLAG ?
>>
>> Nope.  Here's what I have:
>>
>> willy@bobo:~/kernel/souptick$ make C=2 mm/gup.o
>>   CHK include/config/kernel.release
>>   CHK include/generated/uapi/linux/version.h
>>   CHK include/generated/utsrelease.h
>>   CHECK   arch/x86/purgatory/purgatory.c
>>   CHECK   arch/x86/purgatory/sha256.c
>>   CHECK   arch/x86/purgatory/string.c
>> arch/x86/purgatory/../boot/string.c:134:6: warning: symbol 'simple_strtol' 
>> was not declared. Should it be static?
>>   CHK include/generated/bounds.h
>>   CHK include/generated/timeconst.h
>>   CHK include/generated/asm-offsets.h
>>   CALLscripts/checksyscalls.sh
>>   DESCEND  objtool
>>   CHECK   scripts/mod/empty.c
>>   CHK scripts/mod/devicetable-offsets.h
>>   CHECK   mm/gup.c
>> mm/gup.c:817:15: warning: invalid assignment: |=
>> mm/gup.c:817:15:left side has type int
>> mm/gup.c:817:15:right side has type restricted vm_fault_t
>>   CC  mm/gup.o
>>
>
> Matthew,
>
> Due to some unidentified error still not able to catch this warning
> in (X86_64 + sparse) compilation. It is constantly showing below error.
>
> Documents/linux-4.17-rc7$ make C=2 -j4 mm/gup.o
>   CHK include/config/kernel.release
>   CHK include/generated/uapi/linux/version.h
>   DESCEND  objtool
>   CHK include/generated/utsrelease.h
>   CHECK   scripts/mod/empty.c
>   CHK scripts/mod/devicetable-offsets.h
>   CHK include/generated/bounds.h
>   CHK include/generated/timeconst.h
>   CHK include/generated/asm-offsets.h
>   CALLscripts/checksyscalls.sh
>   CHECK   mm/gup.c
> mm/gup.c:394:17: error: undefined identifier '__COUNTER__'
> mm/gup.c:439:9: error: undefined identifier '__COUNTER__'
> mm/gup.c:441:9: error: undefined identifier '__COUNTER__'
> mm/gup.c:443:9: error: undefined identifier '__COUNTER__'
> mm/gup.c:508:17: error: undefined identifier '__COUNTER__'
> mm/gup.c:716:25: error: undefined identifier '__COUNTER__'
> mm/gup.c:826:17: error: undefined identifier '__COUNTER__'
> mm/gup.c:863:17: error: undefined identifier '__COUNTER__'
> mm/gup.c:865:17: error: undefined identifier '__COUNTER__'
> mm/gup.c:882:25: error: undefined identifier '__COUNTER__'
> mm/gup.c:883:25: error: undefined identifier '__COUNTER__'
> mm/gup.c:920:25: error: undefined identifier '__COUNTER__'
> ./include/linux/hugetlb.h:239:9: error: undefined identifier '__COUNTER__'
>
>
> But able to capture it in (powerpc + sparse) compilation.
> I will fix it in v2.
>
> /Documents/linux-4.17-rc7$ make C=2 ARCH=powerpc
> CROSS_COMPILE=powerpc-linux-gnu- mm/gup.o
>   CHK include/config/kernel.release
>   CHK include/generated/uapi/linux/version.h
>   CHK include/generated/utsrelease.h
>   CHK include/generated/bounds.h
>   CHK include/generated/timeconst.h
>   CHK include/generated/asm-offsets.h
>   CALLscripts/checksyscalls.sh
>   CHECK   scripts/mod/empty.c
>   CHK scripts/mod/devicetable-offsets.h
>   CHECK   mm/gup.c
> ./arch/powerpc/include/asm/book3s/64/pgtable.h:669:24: warning:
> restricted __be64 degrades to integer
> mm/gup.c:820:15: warning: incorrect type in assignment (different base types)
> mm/gup.c:820:15:expected int [signed] major
> mm/gup.c:820:15:got restricted vm_fault_t
> mm/gup.c:1247:24: warning: expression using sizeof bool
> mm/gup.c:1247:24: warning: expression using sizeof(void)
> mm/gup.c:1247:24: warning: expression using sizeof(void)
> ./arch/powerpc/include/asm/book3s/64/pgtable.h:667:20: warning:
> incorrect type in initializer (different base types)
> ./arch/powerpc/include/asm/book3s/64/pgtable.h:667:20:expected
> unsigned long long [unsigned] [usertype] mask
> ./arch/powerpc/include/asm/book3s/64/pgtable.h:667:20:got
> restricted __be64

  1   2   3   4   5   6   7   >