Skip to contentSkip to conversation

arm64: kvm: fix gcc-10 shift warning

PATCH In review Arnd Bergmann 4 participants 7 messages Apr 29, 2020 – Apr 30, 2020 KVM arm64

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm64: kvm: fix gcc-10 shift warning

gcc-10 warns that the 32-bit zero cannot be shifted more than 32 bits to the right:

arch/arm64/kvm/../../../virt/kvm/arm/mmu.c: In function 'clear_hyp_p4d_entry':
arch/arm64/include/asm/pgtable.h:630:35: error: right shift count >= width of type [-Werror=shift-count-overflow]
630 | #define pud_index(addr) (((addr) >> PUD_SHIFT) & (PTRS_PER_PUD - 1))
| ^~
arch/arm64/include/asm/memory.h:271:45: note: in definition of macro '__phys_to_virt'
271 | #define __phys_to_virt(x) ((unsigned long)((x) - physvirt_offset))
| ^
arch/arm64/include/asm/pgtable.h:633:42: note: in expansion of macro '__va'
633 | #define pud_offset(dir, addr) ((pud_t *)__va(pud_offset_phys((dir), (addr))))
| ^~~~
arch/arm64/include/asm/pgtable.h:632:73: note: in expansion of macro 'pud_index'
632 | #define pud_offset_phys(dir, addr) (p4d_page_paddr(READ_ONCE(*(dir))) + pud_index(addr) * sizeof(pud_t))
| ^~~~~~~~~
arch/arm64/include/asm/pgtable.h:633:47: note: in expansion of macro 'pud_offset_phys'
633 | #define pud_offset(dir, addr) ((pud_t *)__va(pud_offset_phys((dir), (addr))))

      |                                               ^~~~~~~~~~~~~~~

arch/arm64/kvm/../../../virt/kvm/arm/mmu.c:510:36: note: in expansion of macro 'pud_offset'
510 | pud_t *pud_table __maybe_unused = pud_offset(p4d, 0);
| ^~~~~~~~~~

This is harmless, and the warning is a little bit silly for a zero constant, but it's trivial to fix by making it an unsigned long, so do that.

Fixes 22998131ab33 ("arm64: add support for folded p4d page tables")
---
 virt/kvm/arm/mmu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
virt/kvm/arm/mmu.c +1 -1
index 48d4288c5f1b..534d9798c3cb 100644
@@ -507,7 +507,7 @@ static void clear_hyp_pgd_entry(pgd_t *pgd)
 
 static void clear_hyp_p4d_entry(p4d_t *p4d)
 {
-	pud_t *pud_table __maybe_unused = pud_offset(p4d, 0);
+	pud_t *pud_table __maybe_unused = pud_offset(p4d, 0UL);
 	VM_BUG_ON(p4d_huge(*p4d));
 	p4d_clear(p4d);
 	pud_free(NULL, pud_table);
Signature · 6 lines
2.26.0

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Acked-by on v1 1/1
#1 lore raw
Quoted 48 lines · Arnd Bergmann

gcc-10 warns that the 32-bit zero cannot be shifted more than 32 bits to the right:

arch/arm64/kvm/../../../virt/kvm/arm/mmu.c: In function 'clear_hyp_p4d_entry':
arch/arm64/include/asm/pgtable.h:630:35: error: right shift count >= width of type [-Werror=shift-count-overflow]
630 | #define pud_index(addr) (((addr) >> PUD_SHIFT) & (PTRS_PER_PUD - 1))
| ^~
arch/arm64/include/asm/memory.h:271:45: note: in definition of macro '__phys_to_virt'
271 | #define __phys_to_virt(x) ((unsigned long)((x) - physvirt_offset))
| ^
arch/arm64/include/asm/pgtable.h:633:42: note: in expansion of macro '__va'
633 | #define pud_offset(dir, addr) ((pud_t *)__va(pud_offset_phys((dir), (addr))))
| ^~~~
arch/arm64/include/asm/pgtable.h:632:73: note: in expansion of macro 'pud_index'
632 | #define pud_offset_phys(dir, addr) (p4d_page_paddr(READ_ONCE(*(dir))) + pud_index(addr) * sizeof(pud_t))
| ^~~~~~~~~
arch/arm64/include/asm/pgtable.h:633:47: note: in expansion of macro 'pud_offset_phys'
633 | #define pud_offset(dir, addr) ((pud_t *)__va(pud_offset_phys((dir), (addr))))

      |                                               ^~~~~~~~~~~~~~~

arch/arm64/kvm/../../../virt/kvm/arm/mmu.c:510:36: note: in expansion of macro 'pud_offset'
510 | pud_t *pud_table __maybe_unused = pud_offset(p4d, 0);
| ^~~~~~~~~~

This is harmless, and the warning is a little bit silly for a zero constant, but it's trivial to fix by making it an unsigned long, so do that.

Fixes 22998131ab33 ("arm64: add support for folded p4d page tables")
---
 virt/kvm/arm/mmu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
virt/kvm/arm/mmu.c +1 -1
index 48d4288c5f1b..534d9798c3cb 100644
@@ -507,7 +507,7 @@ static void clear_hyp_pgd_entry(pgd_t *pgd)
 
 static void clear_hyp_p4d_entry(p4d_t *p4d)
 {
-	pud_t *pud_table __maybe_unused = pud_offset(p4d, 0);
+	pud_t *pud_table __maybe_unused = pud_offset(p4d, 0UL);
 	VM_BUG_ON(p4d_huge(*p4d));
 	p4d_clear(p4d);
 	pud_free(NULL, pud_table);
Signature · 1 line
2.26.0

Will

#2 lore raw
In reply to Arnd Bergmann

Hi all,

Quoted 50 lines · On Wed, 29 Apr 2020 20:56:20 +0200 Arnd Bergmann <[email protected]> wrote:

gcc-10 warns that the 32-bit zero cannot be shifted more than 32 bits to the right:

arch/arm64/kvm/../../../virt/kvm/arm/mmu.c: In function 'clear_hyp_p4d_entry':
arch/arm64/include/asm/pgtable.h:630:35: error: right shift count >= width of type [-Werror=shift-count-overflow]
630 | #define pud_index(addr) (((addr) >> PUD_SHIFT) & (PTRS_PER_PUD - 1))
| ^~
arch/arm64/include/asm/memory.h:271:45: note: in definition of macro '__phys_to_virt'
271 | #define __phys_to_virt(x) ((unsigned long)((x) - physvirt_offset))
| ^
arch/arm64/include/asm/pgtable.h:633:42: note: in expansion of macro '__va'
633 | #define pud_offset(dir, addr) ((pud_t *)__va(pud_offset_phys((dir), (addr))))
| ^~~~
arch/arm64/include/asm/pgtable.h:632:73: note: in expansion of macro 'pud_index'
632 | #define pud_offset_phys(dir, addr) (p4d_page_paddr(READ_ONCE(*(dir))) + pud_index(addr) * sizeof(pud_t))
| ^~~~~~~~~
arch/arm64/include/asm/pgtable.h:633:47: note: in expansion of macro 'pud_offset_phys'
633 | #define pud_offset(dir, addr) ((pud_t *)__va(pud_offset_phys((dir), (addr))))

      |                                               ^~~~~~~~~~~~~~~

arch/arm64/kvm/../../../virt/kvm/arm/mmu.c:510:36: note: in expansion of macro 'pud_offset'
510 | pud_t *pud_table __maybe_unused = pud_offset(p4d, 0);
| ^~~~~~~~~~

This is harmless, and the warning is a little bit silly for a zero constant, but it's trivial to fix by making it an unsigned long, so do that.

Fixes 22998131ab33 ("arm64: add support for folded p4d page tables")
---
 virt/kvm/arm/mmu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
virt/kvm/arm/mmu.c +1 -1
index 48d4288c5f1b..534d9798c3cb 100644
@@ -507,7 +507,7 @@ static void clear_hyp_pgd_entry(pgd_t *pgd)
 
 static void clear_hyp_p4d_entry(p4d_t *p4d)
 {
-	pud_t *pud_table __maybe_unused = pud_offset(p4d, 0);
+	pud_t *pud_table __maybe_unused = pud_offset(p4d, 0UL);
 	VM_BUG_ON(p4d_huge(*p4d));
 	p4d_clear(p4d);
 	pud_free(NULL, pud_table);
Signature · 1 line
2.26.0

I have added that patch to linux-next today.

Signature · 2 lines
Cheers,
Stephen Rothwell
maintainer Acked-by on v1 1/1
#3 lore raw
In reply to Arnd Bergmann
Quoted 38 lines · On Wed, 29 Apr 2020 20:56:20 +0200 Arnd Bergmann <[email protected]> wrote:

gcc-10 warns that the 32-bit zero cannot be shifted more than 32 bits to the right:

arch/arm64/kvm/../../../virt/kvm/arm/mmu.c: In function 'clear_hyp_p4d_entry':
arch/arm64/include/asm/pgtable.h:630:35: error: right shift count >= width of type [-Werror=shift-count-overflow]
630 | #define pud_index(addr) (((addr) >> PUD_SHIFT) & (PTRS_PER_PUD - 1))
| ^~
arch/arm64/include/asm/memory.h:271:45: note: in definition of macro '__phys_to_virt'
271 | #define __phys_to_virt(x) ((unsigned long)((x) - physvirt_offset))
| ^
arch/arm64/include/asm/pgtable.h:633:42: note: in expansion of macro '__va'
633 | #define pud_offset(dir, addr) ((pud_t *)__va(pud_offset_phys((dir), (addr))))
| ^~~~
arch/arm64/include/asm/pgtable.h:632:73: note: in expansion of macro 'pud_index'
632 | #define pud_offset_phys(dir, addr) (p4d_page_paddr(READ_ONCE(*(dir))) + pud_index(addr) * sizeof(pud_t))
| ^~~~~~~~~
arch/arm64/include/asm/pgtable.h:633:47: note: in expansion of macro 'pud_offset_phys'
633 | #define pud_offset(dir, addr) ((pud_t *)__va(pud_offset_phys((dir), (addr))))

      |                                               ^~~~~~~~~~~~~~~

arch/arm64/kvm/../../../virt/kvm/arm/mmu.c:510:36: note: in expansion of macro 'pud_offset'
510 | pud_t *pud_table __maybe_unused = pud_offset(p4d, 0);
| ^~~~~~~~~~

This is harmless, and the warning is a little bit silly for a zero constant, but it's trivial to fix by making it an unsigned long, so do that.

Fixes 22998131ab33 ("arm64: add support for folded p4d page tables")
---
 virt/kvm/arm/mmu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
virt/kvm/arm/mmu.c +0 -0
index 48d4288c5f1b..534d9798c3cb 100644

virt/kvm/arm/mmu.c static void clear_hyp_pgd_entry(pgd_t *pgd) · line 513

Quoted 8 lines
virt/kvm/arm/mmu.c +1 -1
@@ -507,7 +507,7 @@ static void clear_hyp_pgd_entry(pgd_t *pgd)
 
 static void clear_hyp_p4d_entry(p4d_t *p4d)
 {
-	pud_t *pud_table __maybe_unused = pud_offset(p4d, 0);
+	pud_t *pud_table __maybe_unused = pud_offset(p4d, 0UL);
 	VM_BUG_ON(p4d_huge(*p4d));
 	p4d_clear(p4d);
 	pud_free(NULL, pud_table);
	M.
Signature · 1 line
Jazz is not dead. It just smells funny...
#4 lore raw
Quoted 42 lines · Marc Zyngier
Quoted 39 lines · On Wed, 29 Apr 2020 20:56:20 +0200 Arnd Bergmann <[email protected]> wrote:

gcc-10 warns that the 32-bit zero cannot be shifted more than 32 bits to the right:

arch/arm64/kvm/../../../virt/kvm/arm/mmu.c: In function 'clear_hyp_p4d_entry':
arch/arm64/include/asm/pgtable.h:630:35: error: right shift count >= width of type [-Werror=shift-count-overflow]
630 | #define pud_index(addr) (((addr) >> PUD_SHIFT) & (PTRS_PER_PUD - 1))
| ^~
arch/arm64/include/asm/memory.h:271:45: note: in definition of macro '__phys_to_virt'
271 | #define __phys_to_virt(x) ((unsigned long)((x) - physvirt_offset))
| ^
arch/arm64/include/asm/pgtable.h:633:42: note: in expansion of macro '__va'
633 | #define pud_offset(dir, addr) ((pud_t *)__va(pud_offset_phys((dir), (addr))))
| ^~~~
arch/arm64/include/asm/pgtable.h:632:73: note: in expansion of macro 'pud_index'
632 | #define pud_offset_phys(dir, addr) (p4d_page_paddr(READ_ONCE(*(dir))) + pud_index(addr) * sizeof(pud_t))
| ^~~~~~~~~
arch/arm64/include/asm/pgtable.h:633:47: note: in expansion of macro 'pud_offset_phys'
633 | #define pud_offset(dir, addr) ((pud_t *)__va(pud_offset_phys((dir), (addr))))

      |                                               ^~~~~~~~~~~~~~~

arch/arm64/kvm/../../../virt/kvm/arm/mmu.c:510:36: note: in expansion of macro 'pud_offset'
510 | pud_t *pud_table __maybe_unused = pud_offset(p4d, 0);
| ^~~~~~~~~~

This is harmless, and the warning is a little bit silly for a zero constant, but it's trivial to fix by making it an unsigned long, so do that.

Fixes 22998131ab33 ("arm64: add support for folded p4d page tables")
---
 virt/kvm/arm/mmu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
virt/kvm/arm/mmu.c +0 -0
index 48d4288c5f1b..534d9798c3cb 100644
@@ -507,7 +507,7 @@ static void clear_hyp_pgd_entry(pgd_t *pgd)
 
Quoted 9 lines

virt/kvm/arm/mmu.c static void clear_hyp_pgd_entry(pgd_t *pgd) · line 513

Quoted 7 lines
virt/kvm/arm/mmu.c +1 -1
 static void clear_hyp_p4d_entry(p4d_t *p4d)
 {
-	pud_t *pud_table __maybe_unused = pud_offset(p4d, 0);
+	pud_t *pud_table __maybe_unused = pud_offset(p4d, 0UL);
 	VM_BUG_ON(p4d_huge(*p4d));
 	p4d_clear(p4d);
 	pud_free(NULL, pud_table);

Happy to queue via arm64 for 5.8. Does that work for you, Arnd, or were you planning to get this in sooner than that?

Cheers,

Will

#5 lore raw

Hi Will,

Quoted 9 lines · On Thu, 30 Apr 2020 09:29:28 +0100 Will Deacon <[email protected]> wrote:
Quoted 4 lines · Marc Zyngier
Quoted 1 line · On Wed, 29 Apr 2020 20:56:20 +0200 Arnd Bergmann <[email protected]> wrote:
Fixes 22998131ab33 ("arm64: add support for folded p4d page tables")

Happy to queue via arm64 for 5.8. Does that work for you, Arnd, or were you planning to get this in sooner than that?

The commit that this fixes is in Andrew's patch series in linux-next, so it should just go in there.

Signature · 2 lines
Cheers,
Stephen Rothwell
#6 lore raw
Quoted 5 lines · Stephen Rothwell
Quoted 4 lines · On Thu, 30 Apr 2020 09:29:28 +0100 Will Deacon <[email protected]> wrote:
Quoted 3 lines · Marc Zyngier

On Wed, 29 Apr 2020 20:56:20 +0200
Arnd Bergmann <[email protected]> wrote:

Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Fixes 22998131ab33 ("arm64: add support for folded p4d page tables")

Happy to queue via arm64 for 5.8. Does that work for you, Arnd, or were you planning to get this in sooner than that?

The commit that this fixes is in Andrew's patch series in linux-next, so it should just go in there.

Yes, you're right. Sorry for the noise.

Will