Skip to contentSkip to conversation

hugetlb: Provide a default HPAGE_SHIFT if !CONFIG_HUGETLB_PAGE

PATCH Superseded David Daney 2 participants 9 messages Nov 16, 2011 – Nov 17, 2011

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hugetlb: Provide a default HPAGE_SHIFT if !CONFIG_HUGETLB_PAGE

From: David Daney <[email protected]>

This is required now to get MIPS kernels to compile with !CONFIG_HUGETLB_PAGE.

---
 include/linux/hugetlb.h |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
include/linux/hugetlb.h +1 -0
index 19644e0..746d543 100644
@@ -113,6 +113,7 @@ static inline void copy_huge_page(struct page *dst, struct page *src)
 #ifndef HPAGE_MASK
 #define HPAGE_MASK	PAGE_MASK		/* Keep the compiler happy */
 #define HPAGE_SIZE	PAGE_SIZE
+#define HPAGE_SHIFT	PAGE_SHIFT
 #endif
 
 #endif /* !CONFIG_HUGETLB_PAGE */
Signature · 1 line
1.7.2.3
#1 lore raw
Quoted 5 lines · David Daney

From: David Daney <[email protected]>

This is required now to get MIPS kernels to compile with !CONFIG_HUGETLB_PAGE.

Why? Apparently there's some config option you've enabled that is causing it to fail but I can't find it. defconfig works fine on my mips crosscompiler and allyesconfig is borked already in other ways.

This is definitely the wrong fix, anyway, and it would require a change to arch/mips/include/asm/page.h instead since it's localized to mips, so nack.

Quoted 17 lines
---
 include/linux/hugetlb.h |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
include/linux/hugetlb.h +1 -0
index 19644e0..746d543 100644
@@ -113,6 +113,7 @@ static inline void copy_huge_page(struct page *dst, struct page *src)
 #ifndef HPAGE_MASK
 #define HPAGE_MASK	PAGE_MASK		/* Keep the compiler happy */
 #define HPAGE_SIZE	PAGE_SIZE
+#define HPAGE_SHIFT	PAGE_SHIFT
 #endif
 
 #endif /* !CONFIG_HUGETLB_PAGE */
#2 lore raw
Quoted 9 lines · David Rientjes
Quoted 5 lines · David Daney

From: David Daney<[email protected]>

This is required now to get MIPS kernels to compile with !CONFIG_HUGETLB_PAGE.

Why?

I should have been more specific. The failure is in Ralf's mips-for-linux-next branch.

Quoted 3 lines

Apparently there's some config option you've enabled that is causing
it to fail but I can't find it. defconfig works fine on my mips crosscompiler and allyesconfig is borked already in other ways.

Please look in the mips-for-linux-next branch.

Quoted 3 lines

This is definitely the wrong fix, anyway, and it would require a change to arch/mips/include/asm/page.h instead since it's localized to mips,

No, all we are doing is supplying a dummy definition for HPAGE_SHIFT as we currently have for HPAGE_SIZE and HPAGE_MASK.

Quoted 7 lines

so nack.

Quoted 5 lines
---
  include/linux/hugetlb.h |    1 +
  1 files changed, 1 insertions(+), 0 deletions(-)
Quoted 8 lines

include/linux/hugetlb.h static inline void copy_huge_page(struct page *dst, struct page *src) · line 115

Quoted 8 lines
include/linux/hugetlb.h +0 -0
index 19644e0..746d543 100644
@@ -113,6 +113,7 @@ static inline void copy_huge_page(struct page *dst, struct page *src)
  #ifndef HPAGE_MASK
  #define HPAGE_MASK	PAGE_MASK		/* Keep the compiler happy */
  #define HPAGE_SIZE	PAGE_SIZE

Why didn't you NACK the addition of these two lines too?

Following your logic, we should remove these and patch up all the architecture specific files instead.

David Daney

Quoted 5 lines
Quoted 4 lines
include/linux/hugetlb.h +1 -0
+#define HPAGE_SHIFT	PAGE_SHIFT
  #endif
 
  #endif /* !CONFIG_HUGETLB_PAGE */
#3 lore raw
Quoted 9 lines · David Daney
Quoted 5 lines
Quoted 3 lines

This is required now to get MIPS kernels to compile with !CONFIG_HUGETLB_PAGE.

Why?

I should have been more specific. The failure is in Ralf's mips-for-linux-next branch.

I can't find that branch (it's not in Ralf's tree at git.kernel.org), so I'm looking at next-20111116. It doesn't compile for mips for other reasons related to arch/mips/sgi-ip22/ip22-gio.c.

Quoted 6 lines
Quoted 2 lines

This is definitely the wrong fix, anyway, and it would require a change to arch/mips/include/asm/page.h instead since it's localized to mips,

No, all we are doing is supplying a dummy definition for HPAGE_SHIFT as we currently have for HPAGE_SIZE and HPAGE_MASK.

Which is wrong. MIPS code should not be using HPAGE_SHIFT without CONFIG_HUGETLB_PAGE and in fact defines it itself for such a configuration in arch/mips/include/asm/page.h. The only generic uses are in page_alloc.c where we need CONFIG_HUGETLB_PAGE_SIZE_VARIABLE, which isn't available on mips, and in mm/hugetlb.c which requires CONFIG_HUGETLB_PAGE by way of CONFIG_HUGETLBFS.

So feel free to show the actual compile error this time and I'll suggest a mips fix for it.

Quoted 20 lines
Quoted 7 lines

so nack.

Quoted 5 lines
---
  include/linux/hugetlb.h |    1 +
  1 files changed, 1 insertions(+), 0 deletions(-)
Quoted 10 lines
Quoted 10 lines
include/linux/hugetlb.h +0 -0
index 19644e0..746d543 100644
@@ -113,6 +113,7 @@ static inline void copy_huge_page(struct page *dst,
 struct page *src)
  #ifndef HPAGE_MASK
  #define HPAGE_MASK	PAGE_MASK		/* Keep the compiler

happy */
#define HPAGE_SIZE PAGE_SIZE

Why didn't you NACK the addition of these two lines too?

Quoted 3 lines

Following your logic, we should remove these and patch up all the architecture specific files instead.

I think it's a worthwhile goal to remove these as well, yes.

#4 lore raw
Quoted 8 lines · David Rientjes
Quoted 6 lines · David Daney
Quoted 5 lines
Quoted 3 lines

This is required now to get MIPS kernels to compile with !CONFIG_HUGETLB_PAGE.

Why?

Quoted 7 lines
Quoted 3 lines

I should have been more specific. The failure is in Ralf's mips-for-linux-next branch.

I can't find that branch (it's not in Ralf's tree at git.kernel.org), so I'm looking at next-20111116. It doesn't compile for mips for other reasons related to arch/mips/sgi-ip22/ip22-gio.c.

Ralf's various trees are accessible via linux-mips.org

Quoted 15 lines
Quoted 7 lines
Quoted 3 lines

This is definitely the wrong fix, anyway, and it would require a change to arch/mips/include/asm/page.h instead since it's localized to mips,

No, all we are doing is supplying a dummy definition for HPAGE_SHIFT as we currently have for HPAGE_SIZE and HPAGE_MASK.

Which is wrong. MIPS code should not be using HPAGE_SHIFT without CONFIG_HUGETLB_PAGE and in fact defines it itself for such a configuration in arch/mips/include/asm/page.h. The only generic uses are in page_alloc.c where we need CONFIG_HUGETLB_PAGE_SIZE_VARIABLE, which isn't available on mips, and in mm/hugetlb.c which requires CONFIG_HUGETLB_PAGE by way of CONFIG_HUGETLBFS.

Quoted 2 lines

So feel free to show the actual compile error this time and I'll suggest a mips fix for it.

arch/mips/mm/tlb-r4k.c: In function ‘local_flush_tlb_range’:
arch/mips/mm/tlb-r4k.c:129:28: error: ‘HPAGE_SHIFT’ undeclared (first use in this function)

However, I call B.S. on your reasoning.

It is a well established kernel idiom to supply dummy values for symbols that are required to be defined in order to form a syntactically correct C program, but that are known by the programmer to be used only on dead code paths.

This is exactly what we are doing here.

To do otherwise requires that code be cluttered with #ifdefery.

David Daney

Quoted 26 lines
Quoted 20 lines
Quoted 7 lines

so nack.

Quoted 5 lines
---
   include/linux/hugetlb.h |    1 +
   1 files changed, 1 insertions(+), 0 deletions(-)
Quoted 10 lines
Quoted 10 lines
include/linux/hugetlb.h +0 -0
index 19644e0..746d543 100644
@@ -113,6 +113,7 @@ static inline void copy_huge_page(struct page *dst,
 struct page *src)
   #ifndef HPAGE_MASK
   #define HPAGE_MASK	PAGE_MASK		/* Keep the compiler

happy */
#define HPAGE_SIZE PAGE_SIZE

Why didn't you NACK the addition of these two lines too?

Quoted 3 lines

Following your logic, we should remove these and patch up all the architecture specific files instead.

I think it's a worthwhile goal to remove these as well, yes.

#5 lore raw
Quoted 10 lines · David Daney
Quoted 10 lines
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines

This is required now to get MIPS kernels to compile with !CONFIG_HUGETLB_PAGE.

Why?

I should have been more specific. The failure is in Ralf's mips-for-linux-next branch.

Quoted 6 lines
Quoted 3 lines

I can't find that branch (it's not in Ralf's tree at git.kernel.org), so I'm looking at next-20111116. It doesn't compile for mips for other reasons related to arch/mips/sgi-ip22/ip22-gio.c.

Ralf's various trees are accessible via linux-mips.org

Wow, we've certainly gone a long way from a patch that appears to be fixing a problem in Linus' tree based on your commit message. You're working from ralf/upstream-sfr.git#mips-for-linux-next from git.linux-mips.org.

Might want to have mentioned that for a patch labeled "hugetlb".

Quoted 7 lines
Quoted 7 lines

Which is wrong. MIPS code should not be using HPAGE_SHIFT without CONFIG_HUGETLB_PAGE and in fact defines it itself for such a configuration in arch/mips/include/asm/page.h. The only generic uses are in page_alloc.c where we need CONFIG_HUGETLB_PAGE_SIZE_VARIABLE, which isn't available on mips, and in mm/hugetlb.c which requires CONFIG_HUGETLB_PAGE by way of CONFIG_HUGETLBFS.

Quoted 7 lines
Quoted 2 lines

So feel free to show the actual compile error this time and I'll suggest a mips fix for it.

arch/mips/mm/tlb-r4k.c: In function ‘local_flush_tlb_range’:
arch/mips/mm/tlb-r4k.c:129:28: error: ‘HPAGE_SHIFT’ undeclared (first use in this function)

Do you see where that file has #ifdef's for CONFIG_HUGETLB_PAGE? You need them here too. The problem is that is_vm_hugetlb_page() is not #define to 0 for CONFIG_HUGETLB_PAGE=n so the clauses using HPAGE_* aren't compiled out like the author is expecting.

Quoted 10 lines

However, I call B.S. on your reasoning.

It is a well established kernel idiom to supply dummy values for symbols that are required to be defined in order to form a syntactically correct C program, but that are known by the programmer to be used only on dead code paths.

This is exactly what we are doing here.

To do otherwise requires that code be cluttered with #ifdefery.

You're wrong, nobody should be using HPAGE_SHIFT unless they are working with hugepages and, in fact, that code that placed those "dummy values" for HPAGE_MASK and HPAGE_SIZE there has since been removed since 2005.

Defining HPAGE_SHIFT to be PAGE_SHIFT is just stupid and doing so may allow the program to compile but will hide real bugs later on. In fact if you merged your patch, it would be a bug since the vma would have VM_HUGETLB but you'd now be operating on PAGE_SIZE pages!

Like I said, we should be removing those existing definitions of HPAGE_MASK and HPAGE_SIZE rather than leaving them so someone like you can come along and pretend there's any legitimacy to them whatsoever and extend the insanity.

You may not realize it, but changes to include/linux/hugetlb.h go through Andrew; Ralf won't be merging anything into this generic header file because of a mips problem.

#6 lore raw
Quoted 16 lines · David Rientjes
Quoted 14 lines · David Daney
Quoted 13 lines
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines

This is required now to get MIPS kernels to compile with !CONFIG_HUGETLB_PAGE.

Why?

I should have been more specific. The failure is in Ralf's mips-for-linux-next branch.

I can't find that branch (it's not in Ralf's tree at git.kernel.org), so I'm looking at next-20111116. It doesn't compile for mips for other reasons related to arch/mips/sgi-ip22/ip22-gio.c.

Quoted 8 lines
Quoted 2 lines

Ralf's various trees are accessible via linux-mips.org

Wow, we've certainly gone a long way from a patch that appears to be fixing a problem in Linus' tree based on your commit message. You're working from ralf/upstream-sfr.git#mips-for-linux-next from git.linux-mips.org.

Yes, as I already said, I should have been more specific about this.

Quoted 12 lines

Might want to have mentioned that for a patch labeled "hugetlb".

Quoted 10 lines
Quoted 9 lines

Which is wrong. MIPS code should not be using HPAGE_SHIFT without CONFIG_HUGETLB_PAGE and in fact defines it itself for such a configuration in arch/mips/include/asm/page.h. The only generic uses are in page_alloc.c where we need CONFIG_HUGETLB_PAGE_SIZE_VARIABLE, which isn't available on mips, and in mm/hugetlb.c which requires CONFIG_HUGETLB_PAGE by way of CONFIG_HUGETLBFS.

So feel free to show the actual compile error this time and I'll suggest a mips fix for it.

Quoted 6 lines
Quoted 4 lines

arch/mips/mm/tlb-r4k.c: In function ‘local_flush_tlb_range’:
arch/mips/mm/tlb-r4k.c:129:28: error: ‘HPAGE_SHIFT’ undeclared (first use in this function)

Do you see where that file has #ifdef's for CONFIG_HUGETLB_PAGE?

Yes I see that. With git annotate we can even see who wrote it.

The code would be much cleaner if that #ifdef were removed. The author was unaware that a dummy version of pmd_huge() existed in hugetlb.h, making the entire if(pmd_huge()) huge block dead code.

I will prepare a patch that gets rid of the #ifdef CONFIG_HUGETLB_PAGE in that file.

Quoted 11 lines

You need
them here too. The problem is that is_vm_hugetlb_page() is not #define to 0 for CONFIG_HUGETLB_PAGE=n so the clauses using HPAGE_* aren't compiled out like the author is expecting.

Quoted 6 lines

However, I call B.S. on your reasoning.

It is a well established kernel idiom to supply dummy values for symbols that are required to be defined in order to form a syntactically correct C program, but that are known by the programmer to be used only on dead code paths.

Quoted 6 lines
Quoted 4 lines

This is exactly what we are doing here.

To do otherwise requires that code be cluttered with #ifdefery.

You're wrong,

Ok, then please tell me why:

1) the dummy version of is_vm_hugetlb_page() exists in hugetlb_inline.h?
2) the dummy version of PageHuge() exists in hugetlb.h
3) the dummy version of reset_vma_resv_huge_pages()
4) the dummy version of hugetlb_total_pages() exists in hugetlb.h
5) the dummy version of follow_hugetlb_page() exists in hugetlb.h
6) the dummy version of follow_huge_addr() exists in hugetlb.h
7) the dummy version of copy_hugetlb_page_range() exists in hugetlb.h
8) the dummy version of hugetlb_prefault() exists in hugetlb.h
9) the dummy version of unmap_hugepage_range() exists in hugetlb.h
10) the dummy version of hugetlb_report_meminfo() exists in hugetlb.h
11) the dummy version of hugetlb_report_node_meminfo() exists in hugetlb.h
12) the dummy version of follow_huge_pmd() exists in hugetlb.h
13) the dummy version of follow_huge_pud() exists in hugetlb.h
14) the dummy version of prepare_hugepage_range() exists in hugetlb.h
15) the dummy version of pmd_huge() exists in hugetlb.h
16) the dummy version of pud_huge() exists in hugetlb.h
17) the dummy version of is_hugepage_only_range() exists in hugetlb.h
17) the dummy version of hugetlb_free_pgd_range() exists in hugetlb.h
18) the dummy version of hugetlb_fault() exists in hugetlb.h
19) the dummy version of huge_pte_offset() exists in hugetlb.h
20) the dummy version of dequeue_hwpoisoned_huge_page() exists in hugetlb.h
21) the dummy version of copy_huge_page() exists in hugetlb.h
22) the dummy version of hugetlb_change_protection() exists in hugetlb.h .
.
.
[Other non HUGETLB_PAGE examples omitted for conciseness]

Quoted 9 lines

nobody should be using HPAGE_SHIFT unless they are working with hugepages and, in fact, that code that placed those "dummy values" for HPAGE_MASK and HPAGE_SIZE there has since been removed since 2005.

Defining HPAGE_SHIFT to be PAGE_SHIFT is just stupid and doing so may allow the program to compile but will hide real bugs later on. In fact if you merged your patch, it would be a bug since the vma would have VM_HUGETLB but you'd now be operating on PAGE_SIZE pages!

Quoted 8 lines

Like I said, we should be removing those existing definitions of HPAGE_MASK and HPAGE_SIZE rather than leaving them so someone like you can come along and pretend there's any legitimacy to them whatsoever and extend the insanity.

You may not realize it, but changes to include/linux/hugetlb.h go through Andrew; Ralf won't be merging anything into this generic header file because of a mips problem.

Indeed, you may not realize that akpm has been on the to or cc list for this entire thread because I explicitly put him there for this exact reason.

Thanks,
David Daney

#7 lore raw
Quoted 34 lines · David Daney
Quoted 6 lines
Quoted 6 lines

It is a well established kernel idiom to supply dummy values for symbols that
are required to be defined in order to form a syntactically correct C program,
but that are known by the programmer to be used only on dead code paths.

Quoted 6 lines
Quoted 4 lines

This is exactly what we are doing here.

To do otherwise requires that code be cluttered with #ifdefery.

You're wrong,

Ok, then please tell me why:

1) the dummy version of is_vm_hugetlb_page() exists in hugetlb_inline.h?
2) the dummy version of PageHuge() exists in hugetlb.h
3) the dummy version of reset_vma_resv_huge_pages()
4) the dummy version of hugetlb_total_pages() exists in hugetlb.h
5) the dummy version of follow_hugetlb_page() exists in hugetlb.h
6) the dummy version of follow_huge_addr() exists in hugetlb.h
7) the dummy version of copy_hugetlb_page_range() exists in hugetlb.h
8) the dummy version of hugetlb_prefault() exists in hugetlb.h
9) the dummy version of unmap_hugepage_range() exists in hugetlb.h
10) the dummy version of hugetlb_report_meminfo() exists in hugetlb.h
11) the dummy version of hugetlb_report_node_meminfo() exists in hugetlb.h
12) the dummy version of follow_huge_pmd() exists in hugetlb.h
13) the dummy version of follow_huge_pud() exists in hugetlb.h
14) the dummy version of prepare_hugepage_range() exists in hugetlb.h
15) the dummy version of pmd_huge() exists in hugetlb.h
16) the dummy version of pud_huge() exists in hugetlb.h
17) the dummy version of is_hugepage_only_range() exists in hugetlb.h
17) the dummy version of hugetlb_free_pgd_range() exists in hugetlb.h
18) the dummy version of hugetlb_fault() exists in hugetlb.h

Quoted 9 lines

19) the dummy version of huge_pte_offset() exists in hugetlb.h
20) the dummy version of dequeue_hwpoisoned_huge_page() exists in hugetlb.h
21) the dummy version of copy_huge_page() exists in hugetlb.h
22) the dummy version of hugetlb_change_protection() exists in hugetlb.h .
.
.
[Other non HUGETLB_PAGE examples omitted for conciseness]

To avoid the #ifdef's, but you'll notice that they return either NULL, 0, or are a no-op. We don't substitute real values in dummy functions where they could be used in generic code as though they were valid. That's the problem with defining HPAGE_SHIFT to be PAGE_SHIFT and, yes, defining HPAGE_MASK and HPAGE_SIZE as well shouldn't be done and should be removed.

We expect HPAGE_* to represent hugepages, not the native page size of the bare metal. This is why we do things like

	#define HPAGE_PMD_SHIFT ({ BUG(); 0; })
	#define HPAGE_PMD_MASK ({ BUG(); 0; })
	#define HPAGE_PMD_SIZE ({ BUG(); 0; })

for CONFIG_TRANSPARENT_HUGEPAGE=n. We don't want to pretend that they're valid outside the context of hugepages.

We also never use HPAGE_SHIFT, HPAGE_MASK, or HPAGE_SIZE in generic code that isn't dependent on CONFIG_HUGETLB_PAGE. If you'd like to submit a patch to fix this in the mips tree, then that would be good, and if you'd like to submit a patch to remove these dummy definitions all together by auditing other arch code, then that would be great.

#8 lore raw
Quoted 19 lines · David Rientjes
Quoted 17 lines · David Daney
Quoted 6 lines
Quoted 6 lines

It is a well established kernel idiom to supply dummy values for symbols that
are required to be defined in order to form a syntactically correct C program,
but that are known by the programmer to be used only on dead code paths.

Quoted 6 lines
Quoted 4 lines

This is exactly what we are doing here.

To do otherwise requires that code be cluttered with #ifdefery.

You're wrong,

Ok, then please tell me why:

1) the dummy version of is_vm_hugetlb_page() exists in hugetlb_inline.h?
2) the dummy version of PageHuge() exists in hugetlb.h

[...]

Quoted 2 lines

To avoid the #ifdef's,

Good, now we are on the same page.

The answer is not, as first suggested, to sprinkle #ifdefs all over the place, but ...

Quoted 6 lines

but you'll notice that they return either NULL, 0,
or are a no-op. We don't substitute real values in dummy functions where they could be used in generic code as though they were valid. That's the problem with defining HPAGE_SHIFT to be PAGE_SHIFT and, yes, defining HPAGE_MASK and HPAGE_SIZE as well shouldn't be done and should be removed.

Quoted 6 lines

We expect HPAGE_* to represent hugepages, not the native page size of the bare metal. This is why we do things like

	#define HPAGE_PMD_SHIFT ({ BUG(); 0; })
	#define HPAGE_PMD_MASK ({ BUG(); 0; })
	#define HPAGE_PMD_SIZE ({ BUG(); 0; })

... rather to fix HPAGE_SHIFT, HPAGE_MASK, and HPAGE_SIZE to be more like these.

I will generate a version of the patch that does this, noting that it the addition of a dummy definition of HPAGE_SHIFT is added to facilitate cleaner architecture specific code for MIPS patches in linux-next.

Thanks,
David Daney

Quoted 10 lines

for CONFIG_TRANSPARENT_HUGEPAGE=n. We don't want to pretend that they're valid outside the context of hugepages.

We also never use HPAGE_SHIFT, HPAGE_MASK, or HPAGE_SIZE in generic code that isn't dependent on CONFIG_HUGETLB_PAGE. If you'd like to submit a patch to fix this in the mips tree, then that would be good, and if you'd like to submit a patch to remove these dummy definitions all together by auditing other arch code, then that would be great.