linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] hugetlbfs: convert macros to static inline, fix sparse warning
@ 2019-11-12 19:45 Mike Kravetz
  2019-11-12 19:45 ` [PATCH 1/2] powerpc/mm: remove pmd_huge/pud_huge stubs and include hugetlb.h Mike Kravetz
  2019-11-12 19:45 ` [PATCH 2/2] hugetlbfs: convert macros to static inline, fix sparse warning Mike Kravetz
  0 siblings, 2 replies; 5+ messages in thread
From: Mike Kravetz @ 2019-11-12 19:45 UTC (permalink / raw)
  To: linux-mm, linux-kernel
  Cc: Michael Ellerman, Ben Dooks, Jason Gunthorpe, kbuild,
	Andrew Morton, Mike Kravetz

The definition for huge_pte_offset() in <linux/hugetlb.h> causes a sparse
warning in the !CONFIG_HUGETLB_PAGE.  Fix this as well as converting
all macros in this block of definitions to static inlines for better type
checking.

When making the above changes, build errors were found in powerpc due to
duplicate definitions.  A separate powerpc specific patch is included as
a requisite to remove the definitions and get them from <linux/hugetlb.h>.

Cc: kbuild@lists.01.org in an attmept to flush out any other build issues.

Mike Kravetz (2):
  powerpc/mm: remove pmd_huge/pud_huge stubs and include hugetlb.h
  hugetlbfs: convert macros to static inline, fix sparse warning

 .../include/asm/book3s/64/pgtable-4k.h        |   3 -
 .../include/asm/book3s/64/pgtable-64k.h       |   3 -
 arch/powerpc/mm/book3s64/radix_pgtable.c      |   1 +
 include/linux/hugetlb.h                       | 137 +++++++++++++++---
 4 files changed, 116 insertions(+), 28 deletions(-)

-- 
2.23.0


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

* [PATCH 1/2] powerpc/mm: remove pmd_huge/pud_huge stubs and include hugetlb.h
  2019-11-12 19:45 [PATCH 0/2] hugetlbfs: convert macros to static inline, fix sparse warning Mike Kravetz
@ 2019-11-12 19:45 ` Mike Kravetz
  2019-11-12 19:45 ` [PATCH 2/2] hugetlbfs: convert macros to static inline, fix sparse warning Mike Kravetz
  1 sibling, 0 replies; 5+ messages in thread
From: Mike Kravetz @ 2019-11-12 19:45 UTC (permalink / raw)
  To: linux-mm, linux-kernel
  Cc: Michael Ellerman, Ben Dooks, Jason Gunthorpe, kbuild,
	Andrew Morton, Mike Kravetz

This removes the power specific stubs created by commit aad71e3928be
("powerpc/mm: Fix build break with RADIX=y & HUGETLBFS=n") used when
!CONFIG_HUGETLB_PAGE.  Instead, it addresses the build break by
getting the definitions from <linux/hugetlb.h>.  This allows the
macros in <linux/hugetlb.h> to be replaced with static inlines.

Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>
Acked-by: Michael Ellerman <mpe@ellerman.id.au>
---
 arch/powerpc/include/asm/book3s/64/pgtable-4k.h  | 3 ---
 arch/powerpc/include/asm/book3s/64/pgtable-64k.h | 3 ---
 arch/powerpc/mm/book3s64/radix_pgtable.c         | 1 +
 3 files changed, 1 insertion(+), 6 deletions(-)

diff --git a/arch/powerpc/include/asm/book3s/64/pgtable-4k.h b/arch/powerpc/include/asm/book3s/64/pgtable-4k.h
index a069dfcac9a9..4e697bc2f4cd 100644
--- a/arch/powerpc/include/asm/book3s/64/pgtable-4k.h
+++ b/arch/powerpc/include/asm/book3s/64/pgtable-4k.h
@@ -70,9 +70,6 @@ static inline int get_hugepd_cache_index(int index)
 	/* should not reach */
 }
 
-#else /* !CONFIG_HUGETLB_PAGE */
-static inline int pmd_huge(pmd_t pmd) { return 0; }
-static inline int pud_huge(pud_t pud) { return 0; }
 #endif /* CONFIG_HUGETLB_PAGE */
 
 #endif /* __ASSEMBLY__ */
diff --git a/arch/powerpc/include/asm/book3s/64/pgtable-64k.h b/arch/powerpc/include/asm/book3s/64/pgtable-64k.h
index e3d4dd4ae2fa..34d1018896b3 100644
--- a/arch/powerpc/include/asm/book3s/64/pgtable-64k.h
+++ b/arch/powerpc/include/asm/book3s/64/pgtable-64k.h
@@ -59,9 +59,6 @@ static inline int get_hugepd_cache_index(int index)
 	BUG();
 }
 
-#else /* !CONFIG_HUGETLB_PAGE */
-static inline int pmd_huge(pmd_t pmd) { return 0; }
-static inline int pud_huge(pud_t pud) { return 0; }
 #endif /* CONFIG_HUGETLB_PAGE */
 
 static inline int remap_4k_pfn(struct vm_area_struct *vma, unsigned long addr,
diff --git a/arch/powerpc/mm/book3s64/radix_pgtable.c b/arch/powerpc/mm/book3s64/radix_pgtable.c
index 6ee17d09649c..974109bb85db 100644
--- a/arch/powerpc/mm/book3s64/radix_pgtable.c
+++ b/arch/powerpc/mm/book3s64/radix_pgtable.c
@@ -13,6 +13,7 @@
 #include <linux/memblock.h>
 #include <linux/of_fdt.h>
 #include <linux/mm.h>
+#include <linux/hugetlb.h>
 #include <linux/string_helpers.h>
 #include <linux/stop_machine.h>
 
-- 
2.23.0


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

* [PATCH 2/2] hugetlbfs: convert macros to static inline, fix sparse warning
  2019-11-12 19:45 [PATCH 0/2] hugetlbfs: convert macros to static inline, fix sparse warning Mike Kravetz
  2019-11-12 19:45 ` [PATCH 1/2] powerpc/mm: remove pmd_huge/pud_huge stubs and include hugetlb.h Mike Kravetz
@ 2019-11-12 19:45 ` Mike Kravetz
  2019-11-12 21:13   ` Joe Perches
  1 sibling, 1 reply; 5+ messages in thread
From: Mike Kravetz @ 2019-11-12 19:45 UTC (permalink / raw)
  To: linux-mm, linux-kernel
  Cc: Michael Ellerman, Ben Dooks, Jason Gunthorpe, kbuild,
	Andrew Morton, Mike Kravetz

huge_pte_offset() produced a sparse warning due to an improper
return type when the kernel was built with !CONFIG_HUGETLB_PAGE.
Fix the bad type and also convert all the macros in this block
to static inline wrappers.  Two existing wrappers in this block
had lines in excess of 80 columns so clean those up as well.

No functional change.

Reported-by: Ben Dooks <ben.dooks@codethink.co.uk>
Suggested-by: Jason Gunthorpe <jgg@ziepe.ca>
Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>
---
 include/linux/hugetlb.h | 137 +++++++++++++++++++++++++++++++++-------
 1 file changed, 115 insertions(+), 22 deletions(-)

diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
index 53fc34f930d0..ef412fe0be3d 100644
--- a/include/linux/hugetlb.h
+++ b/include/linux/hugetlb.h
@@ -164,38 +164,130 @@ static inline void adjust_range_if_pmd_sharing_possible(
 {
 }
 
-#define follow_hugetlb_page(m,v,p,vs,a,b,i,w,n)	({ BUG(); 0; })
-#define follow_huge_addr(mm, addr, write)	ERR_PTR(-EINVAL)
-#define copy_hugetlb_page_range(src, dst, vma)	({ BUG(); 0; })
+static inline long follow_hugetlb_page(struct mm_struct *mm,
+			struct vm_area_struct *vma, struct page **pages,
+			struct vm_area_struct **vmas, unsigned long *position,
+			unsigned long *nr_pages, long i, unsigned int flags,
+			int *nonblocking)
+{
+	BUG();
+	return 0;
+}
+
+static inline struct page *follow_huge_addr(struct mm_struct *mm,
+					unsigned long address, int write)
+{
+	return ERR_PTR(-EINVAL);
+}
+
+static inline int copy_hugetlb_page_range(struct mm_struct *dst,
+			struct mm_struct *src, struct vm_area_struct *vma)
+{
+	BUG();
+	return 0;
+}
+
 static inline void hugetlb_report_meminfo(struct seq_file *m)
 {
 }
-#define hugetlb_report_node_meminfo(n, buf)	0
+
+static inline int hugetlb_report_node_meminfo(int nid, char *buf)
+{
+	return 0;
+}
+
 static inline void hugetlb_show_meminfo(void)
 {
 }
-#define follow_huge_pd(vma, addr, hpd, flags, pdshift) NULL
-#define follow_huge_pmd(mm, addr, pmd, flags)	NULL
-#define follow_huge_pud(mm, addr, pud, flags)	NULL
-#define follow_huge_pgd(mm, addr, pgd, flags)	NULL
-#define prepare_hugepage_range(file, addr, len)	(-EINVAL)
-#define pmd_huge(x)	0
-#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_mcopy_atomic_pte(dst_mm, dst_pte, dst_vma, dst_addr, \
-				src_addr, pagep)	({ BUG(); 0; })
-#define huge_pte_offset(mm, address, sz)	0
+
+static inline struct page *follow_huge_pd(struct vm_area_struct *vma,
+				unsigned long address, hugepd_t hpd, int flags,
+				int pdshift)
+{
+	return NULL;
+}
+
+static inline struct page *follow_huge_pmd(struct mm_struct *mm,
+				unsigned long address, pmd_t *pmd, int flags)
+{
+	return NULL;
+}
+
+static inline struct page *follow_huge_pud(struct mm_struct *mm,
+				unsigned long address, pud_t *pud, int flags)
+{
+	return NULL;
+}
+
+static inline struct page *follow_huge_pgd(struct mm_struct *mm,
+				unsigned long address, pgd_t *pgd, int flags)
+{
+	return NULL;
+}
+
+static inline int prepare_hugepage_range(struct file *file,
+				unsigned long addr, unsigned long len)
+{
+	return -EINVAL;
+}
+
+static inline int pmd_huge(pmd_t pmd)
+{
+	return 0;
+}
+
+static inline int pud_huge(pud_t pud)
+{
+	return 0;
+}
+
+static inline int is_hugepage_only_range(struct mm_struct *mm,
+					unsigned long addr, unsigned long len)
+{
+	return 0;
+}
+
+static inline void hugetlb_free_pgd_range(struct mmu_gather *tlb,
+				unsigned long addr, unsigned long end,
+				unsigned long floor, unsigned long ceiling)
+{
+	BUG();
+}
+
+static inline int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm,
+						pte_t *dst_pte,
+						struct vm_area_struct *dst_vma,
+						unsigned long dst_addr,
+						unsigned long src_addr,
+						struct page **pagep)
+{
+	BUG();
+	return 0;
+}
+
+static inline pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr,
+					unsigned long sz)
+{
+	return NULL;
+}
 
 static inline bool isolate_huge_page(struct page *page, struct list_head *list)
 {
 	return false;
 }
-#define putback_active_hugepage(p)	do {} while (0)
-#define move_hugetlb_state(old, new, reason)	do {} while (0)
 
-static inline unsigned long hugetlb_change_protection(struct vm_area_struct *vma,
-		unsigned long address, unsigned long end, pgprot_t newprot)
+static inline void putback_active_hugepage(struct page *page)
+{
+}
+
+static inline void move_hugetlb_state(struct page *oldpage,
+					struct page *newpage, int reason)
+{
+}
+
+static inline unsigned long hugetlb_change_protection(
+			struct vm_area_struct *vma, unsigned long address,
+			unsigned long end, pgprot_t newprot)
 {
 	return 0;
 }
@@ -213,9 +305,10 @@ 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)
+			struct vm_area_struct *vma, unsigned long address,
+			unsigned int flags)
 {
 	BUG();
 	return 0;
-- 
2.23.0


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

* Re: [PATCH 2/2] hugetlbfs: convert macros to static inline, fix sparse warning
  2019-11-12 19:45 ` [PATCH 2/2] hugetlbfs: convert macros to static inline, fix sparse warning Mike Kravetz
@ 2019-11-12 21:13   ` Joe Perches
  2019-11-13  0:11     ` Mike Kravetz
  0 siblings, 1 reply; 5+ messages in thread
From: Joe Perches @ 2019-11-12 21:13 UTC (permalink / raw)
  To: Mike Kravetz, linux-mm, linux-kernel
  Cc: Michael Ellerman, Ben Dooks, Jason Gunthorpe, kbuild, Andrew Morton

On Tue, 2019-11-12 at 11:45 -0800, Mike Kravetz wrote:
> huge_pte_offset() produced a sparse warning due to an improper
> return type when the kernel was built with !CONFIG_HUGETLB_PAGE.
> Fix the bad type and also convert all the macros in this block
> to static inline wrappers.  Two existing wrappers in this block
> had lines in excess of 80 columns so clean those up as well.
> 
> No functional change.
> 
> Reported-by: Ben Dooks <ben.dooks@codethink.co.uk>
> Suggested-by: Jason Gunthorpe <jgg@ziepe.ca>
> Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>
> ---
>  include/linux/hugetlb.h | 137 +++++++++++++++++++++++++++++++++-------
>  1 file changed, 115 insertions(+), 22 deletions(-)
> 
> diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
> index 53fc34f930d0..ef412fe0be3d 100644
> --- a/include/linux/hugetlb.h
> +++ b/include/linux/hugetlb.h
> @@ -164,38 +164,130 @@ static inline void adjust_range_if_pmd_sharing_possible(
>  {
>  }
>  
> -#define follow_hugetlb_page(m,v,p,vs,a,b,i,w,n)	({ BUG(); 0; })
> -#define follow_huge_addr(mm, addr, write)	ERR_PTR(-EINVAL)
> -#define copy_hugetlb_page_range(src, dst, vma)	({ BUG(); 0; })
> +static inline long follow_hugetlb_page(struct mm_struct *mm,
> +			struct vm_area_struct *vma, struct page **pages,
> +			struct vm_area_struct **vmas, unsigned long *position,
> +			unsigned long *nr_pages, long i, unsigned int flags,
> +			int *nonblocking)
> +{
> +	BUG();

While this is not different from the original, perhaps this is
also an opportunity to change the BUG()s to WARN()s.

> +static inline int copy_hugetlb_page_range(struct mm_struct *dst,
> +			struct mm_struct *src, struct vm_area_struct *vma)
> +{
> +	BUG();
> +	return 0;
> +}
[]
> +static inline void hugetlb_free_pgd_range(struct mmu_gather *tlb,
> +				unsigned long addr, unsigned long end,
> +				unsigned long floor, unsigned long ceiling)
> +{
> +	BUG();
> +}
> +
> +static inline int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm,
> +						pte_t *dst_pte,
> +						struct vm_area_struct *dst_vma,
> +						unsigned long dst_addr,
> +						unsigned long src_addr,
> +						struct page **pagep)
> +{
> +	BUG();
> +	return 0;
> +}



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

* Re: [PATCH 2/2] hugetlbfs: convert macros to static inline, fix sparse warning
  2019-11-12 21:13   ` Joe Perches
@ 2019-11-13  0:11     ` Mike Kravetz
  0 siblings, 0 replies; 5+ messages in thread
From: Mike Kravetz @ 2019-11-13  0:11 UTC (permalink / raw)
  To: Joe Perches, linux-mm, linux-kernel
  Cc: Michael Ellerman, Ben Dooks, Jason Gunthorpe, kbuild, Andrew Morton

On 11/12/19 1:13 PM, Joe Perches wrote:
> On Tue, 2019-11-12 at 11:45 -0800, Mike Kravetz wrote:
>> huge_pte_offset() produced a sparse warning due to an improper
>> return type when the kernel was built with !CONFIG_HUGETLB_PAGE.
>> Fix the bad type and also convert all the macros in this block
>> to static inline wrappers.  Two existing wrappers in this block
>> had lines in excess of 80 columns so clean those up as well.
>>
>> No functional change.
>>
>> Reported-by: Ben Dooks <ben.dooks@codethink.co.uk>
>> Suggested-by: Jason Gunthorpe <jgg@ziepe.ca>
>> Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>
>> ---
>>  include/linux/hugetlb.h | 137 +++++++++++++++++++++++++++++++++-------
>>  1 file changed, 115 insertions(+), 22 deletions(-)
>>
>> diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
>> index 53fc34f930d0..ef412fe0be3d 100644
>> --- a/include/linux/hugetlb.h
>> +++ b/include/linux/hugetlb.h
>> @@ -164,38 +164,130 @@ static inline void adjust_range_if_pmd_sharing_possible(
>>  {
>>  }
>>  
>> -#define follow_hugetlb_page(m,v,p,vs,a,b,i,w,n)	({ BUG(); 0; })
>> -#define follow_huge_addr(mm, addr, write)	ERR_PTR(-EINVAL)
>> -#define copy_hugetlb_page_range(src, dst, vma)	({ BUG(); 0; })
>> +static inline long follow_hugetlb_page(struct mm_struct *mm,
>> +			struct vm_area_struct *vma, struct page **pages,
>> +			struct vm_area_struct **vmas, unsigned long *position,
>> +			unsigned long *nr_pages, long i, unsigned int flags,
>> +			int *nonblocking)
>> +{
>> +	BUG();
> 
> While this is not different from the original, perhaps this is
> also an opportunity to change the BUG()s to WARN()s.

Yes, I saw all those warnings from checkpatch.  I'll add this as a 'to do'.
There are a bunch of these in hugetlbfs code and headers.  I'd really to
take a closer look at all of these and try to do something more intelligent.

-- 
Mike Kravetz

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

end of thread, other threads:[~2019-11-13  0:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-12 19:45 [PATCH 0/2] hugetlbfs: convert macros to static inline, fix sparse warning Mike Kravetz
2019-11-12 19:45 ` [PATCH 1/2] powerpc/mm: remove pmd_huge/pud_huge stubs and include hugetlb.h Mike Kravetz
2019-11-12 19:45 ` [PATCH 2/2] hugetlbfs: convert macros to static inline, fix sparse warning Mike Kravetz
2019-11-12 21:13   ` Joe Perches
2019-11-13  0:11     ` Mike Kravetz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).