All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] include/linux/hugetlb.h: Convert to use vm_fault_t
@ 2019-03-18 16:26 Souptick Joarder
  2019-03-19  0:17 ` Mike Kravetz
  2019-03-19  3:20 ` Matthew Wilcox
  0 siblings, 2 replies; 6+ messages in thread
From: Souptick Joarder @ 2019-03-18 16:26 UTC (permalink / raw)
  To: akpm, mike.kravetz; +Cc: linux-mm, linux-kernel, willy

kbuild produces the below warning ->

tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head:   5453a3df2a5eb49bc24615d4cf0d66b2aae05e5f
commit 3d3539018d2c ("mm: create the new vm_fault_t type")
reproduce:
        # apt-get install sparse
        git checkout 3d3539018d2cbd12e5af4a132636ee7fd8d43ef0
        make ARCH=x86_64 allmodconfig
        make C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'

>> mm/memory.c:3968:21: sparse: incorrect type in assignment (different
>> base types) @@    expected restricted vm_fault_t [usertype] ret @@
>> got e] ret @@
   mm/memory.c:3968:21:    expected restricted vm_fault_t [usertype] ret
   mm/memory.c:3968:21:    got int

This patch will convert to return vm_fault_t type for hugetlb_fault()
when CONFIG_HUGETLB_PAGE =n.

Signed-off-by: Souptick Joarder <jrdr.linux@gmail.com>
---
 include/linux/hugetlb.h | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
index 087fd5f4..0ee502a 100644
--- a/include/linux/hugetlb.h
+++ b/include/linux/hugetlb.h
@@ -203,7 +203,6 @@ static inline void hugetlb_show_meminfo(void)
 #define pud_huge(x)	0
 #define is_hugepage_only_range(mm, addr, len)	0
 #define hugetlb_free_pgd_range(tlb, addr, end, floor, ceiling) ({BUG(); 0; })
-#define hugetlb_fault(mm, vma, addr, flags)	({ BUG(); 0; })
 #define hugetlb_mcopy_atomic_pte(dst_mm, dst_pte, dst_vma, dst_addr, \
 				src_addr, pagep)	({ BUG(); 0; })
 #define huge_pte_offset(mm, address, sz)	0
@@ -234,6 +233,13 @@ static inline void __unmap_hugepage_range(struct mmu_gather *tlb,
 {
 	BUG();
 }
+static inline vm_fault_t hugetlb_fault(struct mm_struct *mm,
+				struct vm_area_struct *vma, unsigned long address,
+				unsigned int flags)
+{
+	BUG();
+	return 0;
+}
 
 #endif /* !CONFIG_HUGETLB_PAGE */
 /*
-- 
1.9.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] include/linux/hugetlb.h: Convert to use vm_fault_t
  2019-03-18 16:26 [PATCH] include/linux/hugetlb.h: Convert to use vm_fault_t Souptick Joarder
@ 2019-03-19  0:17 ` Mike Kravetz
  2019-03-19  2:34     ` Souptick Joarder
  2019-03-19  3:20 ` Matthew Wilcox
  1 sibling, 1 reply; 6+ messages in thread
From: Mike Kravetz @ 2019-03-19  0:17 UTC (permalink / raw)
  To: Souptick Joarder, akpm; +Cc: linux-mm, linux-kernel, willy


On 3/18/19 9:26 AM, Souptick Joarder wrote:
> kbuild produces the below warning ->
> 
> tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
> head:   5453a3df2a5eb49bc24615d4cf0d66b2aae05e5f
> commit 3d3539018d2c ("mm: create the new vm_fault_t type")
> reproduce:
>         # apt-get install sparse
>         git checkout 3d3539018d2cbd12e5af4a132636ee7fd8d43ef0
>         make ARCH=x86_64 allmodconfig
>         make C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'
> 
>>> mm/memory.c:3968:21: sparse: incorrect type in assignment (different
>>> base types) @@    expected restricted vm_fault_t [usertype] ret @@
>>> got e] ret @@
>    mm/memory.c:3968:21:    expected restricted vm_fault_t [usertype] ret
>    mm/memory.c:3968:21:    got int
> 
> This patch will convert to return vm_fault_t type for hugetlb_fault()
> when CONFIG_HUGETLB_PAGE =n.
> 
> Signed-off-by: Souptick Joarder <jrdr.linux@gmail.com>

Thanks for fixing this.

The BUG() here and in several other places in this file is unnecessary
and IMO should be cleaned up.  But that is beyond the scope of this fix.
Added to my to do list.

Reviewed-by: Mike Kravetz <mike.kravetz@oracle.com>
-- 
Mike Kravetz

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] include/linux/hugetlb.h: Convert to use vm_fault_t
  2019-03-19  0:17 ` Mike Kravetz
@ 2019-03-19  2:34     ` Souptick Joarder
  0 siblings, 0 replies; 6+ messages in thread
From: Souptick Joarder @ 2019-03-19  2:34 UTC (permalink / raw)
  To: Mike Kravetz; +Cc: Andrew Morton, Linux-MM, linux-kernel, Matthew Wilcox

On Tue, Mar 19, 2019 at 5:47 AM Mike Kravetz <mike.kravetz@oracle.com> wrote:
>
>
> On 3/18/19 9:26 AM, Souptick Joarder wrote:
> > kbuild produces the below warning ->
> >
> > tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
> > head:   5453a3df2a5eb49bc24615d4cf0d66b2aae05e5f
> > commit 3d3539018d2c ("mm: create the new vm_fault_t type")
> > reproduce:
> >         # apt-get install sparse
> >         git checkout 3d3539018d2cbd12e5af4a132636ee7fd8d43ef0
> >         make ARCH=x86_64 allmodconfig
> >         make C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'
> >
> >>> mm/memory.c:3968:21: sparse: incorrect type in assignment (different
> >>> base types) @@    expected restricted vm_fault_t [usertype] ret @@
> >>> got e] ret @@
> >    mm/memory.c:3968:21:    expected restricted vm_fault_t [usertype] ret
> >    mm/memory.c:3968:21:    got int
> >
> > This patch will convert to return vm_fault_t type for hugetlb_fault()
> > when CONFIG_HUGETLB_PAGE =n.
> >
> > Signed-off-by: Souptick Joarder <jrdr.linux@gmail.com>
>
> Thanks for fixing this.
>
> The BUG() here and in several other places in this file is unnecessary
> and IMO should be cleaned up.  But that is beyond the scope of this fix.
> Added to my to do list.

I can clean it up if you are fine ;-)
>
> Reviewed-by: Mike Kravetz <mike.kravetz@oracle.com>
> --
> Mike Kravetz

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] include/linux/hugetlb.h: Convert to use vm_fault_t
@ 2019-03-19  2:34     ` Souptick Joarder
  0 siblings, 0 replies; 6+ messages in thread
From: Souptick Joarder @ 2019-03-19  2:34 UTC (permalink / raw)
  To: Mike Kravetz; +Cc: Andrew Morton, Linux-MM, linux-kernel, Matthew Wilcox

On Tue, Mar 19, 2019 at 5:47 AM Mike Kravetz <mike.kravetz@oracle.com> wrote:
>
>
> On 3/18/19 9:26 AM, Souptick Joarder wrote:
> > kbuild produces the below warning ->
> >
> > tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
> > head:   5453a3df2a5eb49bc24615d4cf0d66b2aae05e5f
> > commit 3d3539018d2c ("mm: create the new vm_fault_t type")
> > reproduce:
> >         # apt-get install sparse
> >         git checkout 3d3539018d2cbd12e5af4a132636ee7fd8d43ef0
> >         make ARCH=x86_64 allmodconfig
> >         make C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'
> >
> >>> mm/memory.c:3968:21: sparse: incorrect type in assignment (different
> >>> base types) @@    expected restricted vm_fault_t [usertype] ret @@
> >>> got e] ret @@
> >    mm/memory.c:3968:21:    expected restricted vm_fault_t [usertype] ret
> >    mm/memory.c:3968:21:    got int
> >
> > This patch will convert to return vm_fault_t type for hugetlb_fault()
> > when CONFIG_HUGETLB_PAGE =n.
> >
> > Signed-off-by: Souptick Joarder <jrdr.linux@gmail.com>
>
> Thanks for fixing this.
>
> The BUG() here and in several other places in this file is unnecessary
> and IMO should be cleaned up.  But that is beyond the scope of this fix.
> Added to my to do list.

I can clean it up if you are fine ;-)
>
> Reviewed-by: Mike Kravetz <mike.kravetz@oracle.com>
> --
> Mike Kravetz


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] include/linux/hugetlb.h: Convert to use vm_fault_t
  2019-03-18 16:26 [PATCH] include/linux/hugetlb.h: Convert to use vm_fault_t Souptick Joarder
  2019-03-19  0:17 ` Mike Kravetz
@ 2019-03-19  3:20 ` Matthew Wilcox
  2019-03-19 17:51   ` Luc Van Oostenryck
  1 sibling, 1 reply; 6+ messages in thread
From: Matthew Wilcox @ 2019-03-19  3:20 UTC (permalink / raw)
  To: Souptick Joarder; +Cc: akpm, mike.kravetz, linux-mm, linux-kernel, linux-sparse

On Mon, Mar 18, 2019 at 09:56:05PM +0530, Souptick Joarder wrote:
> >> mm/memory.c:3968:21: sparse: incorrect type in assignment (different
> >> base types) @@    expected restricted vm_fault_t [usertype] ret @@
> >> got e] ret @@
>    mm/memory.c:3968:21:    expected restricted vm_fault_t [usertype] ret
>    mm/memory.c:3968:21:    got int

I think this may be a sparse bug.

Compare:

+++ b/mm/memory.c
@@ -3964,6 +3964,9 @@ vm_fault_t handle_mm_fault(struct vm_area_struct *vma, unsigned long address,
        if (flags & FAULT_FLAG_USER)
                mem_cgroup_enter_user_fault();
 
+       ret = 0;
+       ret = ({ BUG(); 0; });
+       ret = 1;
        if (unlikely(is_vm_hugetlb_page(vma)))
                ret = hugetlb_fault(vma->vm_mm, vma, address, flags);
        else

../mm/memory.c:3968:13: sparse: warning: incorrect type in assignment (different base types)
../mm/memory.c:3968:13: sparse:    expected restricted vm_fault_t [assigned] [usertype] ret
../mm/memory.c:3968:13: sparse:    got int
../mm/memory.c:3969:13: sparse: warning: incorrect type in assignment (different base types)
../mm/memory.c:3969:13: sparse:    expected restricted vm_fault_t [assigned] [usertype] ret
../mm/memory.c:3969:13: sparse:    got int

vm_fault_t is __bitwise:

include/linux/mm_types.h:typedef __bitwise unsigned int vm_fault_t;

so simply assigning 0 to ret should work (and does on line 3967), but
sparse doesn't seem to like it as part of a ({ .. }) expression.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] include/linux/hugetlb.h: Convert to use vm_fault_t
  2019-03-19  3:20 ` Matthew Wilcox
@ 2019-03-19 17:51   ` Luc Van Oostenryck
  0 siblings, 0 replies; 6+ messages in thread
From: Luc Van Oostenryck @ 2019-03-19 17:51 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: Souptick Joarder, akpm, mike.kravetz, linux-mm, linux-kernel,
	linux-sparse

On Mon, Mar 18, 2019 at 08:20:22PM -0700, Matthew Wilcox wrote:
> On Mon, Mar 18, 2019 at 09:56:05PM +0530, Souptick Joarder wrote:
> > >> mm/memory.c:3968:21: sparse: incorrect type in assignment (different
> > >> base types) @@    expected restricted vm_fault_t [usertype] ret @@
> > >> got e] ret @@
> >    mm/memory.c:3968:21:    expected restricted vm_fault_t [usertype] ret
> >    mm/memory.c:3968:21:    got int
> 
> I think this may be a sparse bug.
> 
> Compare:
> 
> +++ b/mm/memory.c
> @@ -3964,6 +3964,9 @@ vm_fault_t handle_mm_fault(struct vm_area_struct *vma, unsigned long address,
>         if (flags & FAULT_FLAG_USER)
>                 mem_cgroup_enter_user_fault();
>  
> +       ret = 0;
> +       ret = ({ BUG(); 0; });
> +       ret = 1;
>         if (unlikely(is_vm_hugetlb_page(vma)))
>                 ret = hugetlb_fault(vma->vm_mm, vma, address, flags);
>         else
> 
> ../mm/memory.c:3968:13: sparse: warning: incorrect type in assignment (different base types)
> ../mm/memory.c:3968:13: sparse:    expected restricted vm_fault_t [assigned] [usertype] ret
> ../mm/memory.c:3968:13: sparse:    got int
> ../mm/memory.c:3969:13: sparse: warning: incorrect type in assignment (different base types)
> ../mm/memory.c:3969:13: sparse:    expected restricted vm_fault_t [assigned] [usertype] ret
> ../mm/memory.c:3969:13: sparse:    got int
> 
> vm_fault_t is __bitwise:
> 
> include/linux/mm_types.h:typedef __bitwise unsigned int vm_fault_t;
> 
> so simply assigning 0 to ret should work (and does on line 3967), but
> sparse doesn't seem to like it as part of a ({ .. }) expression.

This is the expected behaviour. The constant 0 is magic regarding
bitwise types but ({ ...; 0; }) is not, it is just an ordinary expression
of type 'int'.

So, IMHO, Souptick's patch is the right thing to do.


Best regards,
-- Luc Van Oostenryck

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-03-19 17:51 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-18 16:26 [PATCH] include/linux/hugetlb.h: Convert to use vm_fault_t Souptick Joarder
2019-03-19  0:17 ` Mike Kravetz
2019-03-19  2:34   ` Souptick Joarder
2019-03-19  2:34     ` Souptick Joarder
2019-03-19  3:20 ` Matthew Wilcox
2019-03-19 17:51   ` Luc Van Oostenryck

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.