powerpc/tlb: Remove BUILD_BUG for book3s/32/tlbflush.h local_flush_tlb_page_psize
PATCH 1/1 powerpc/tlb: Remove BUILD_BUG for book3s/32/tlbflush.h local_flush_tlb_page_psize
Converts the BUILD_BUG to a WARN to allow building with a low/unoptimised compiler.
The original expectation was that a compiler would see that the only usage of this function was in a function that is only called behind radix-only guards. And it worked this way on GCC. It seems Clang does not optimise away this call however, so thinks the function may be invoked and triggers the build bug as reported by the kernel test robot.
https://lore.kernel.org/llvm/[email protected]
This fix converts the build bug to a warning to allow builds without relying on particular compiler optimisation behaviours. The warning is not rate limited because this implementation should still never be called as-is, and anyone who might invoke it might appreciate it being very obvious that it's not behaving as expected.
--- arch/powerpc/include/asm/book3s/32/tlbflush.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/include/asm/book3s/32/tlbflush.h +2 -2
@@ -2,7 +2,7 @@#ifndef _ASM_POWERPC_BOOK3S_32_TLBFLUSH_H#define _ASM_POWERPC_BOOK3S_32_TLBFLUSH_H -#include <linux/build_bug.h> +#include <linux/bug.h> #define MMU_NO_CONTEXT (0)/*
@@ -80,7 +80,7 @@ static inline void local_flush_tlb_page(struct vm_area_struct *vma,static inline void local_flush_tlb_page_psize (struct mm_struct *mm,unsigned long vmaddr,int psize) { -BUILD_BUG (); +WARN (1 ,"Unimplemented local TLB flush with psize" ); }static inline void local_flush_tlb_mm (struct mm_struct *mm)
base-commit: 53ab112a95086d10dc353ea4f979abb01644bbb6
Signature · 1 line
2.39.1
Le 24/01/2023 à 22:54, Benjamin Gray a écrit :
Quoted 2 lines
Converts the
BUILD_BUGto a WARN to allow building with a low/unoptimised compiler.
No no no no. Please don't do that.
That approach is used everywhere in the kernel, why should it be a problem only for local_flush_tlb_page_psize() and not everywhere else ?
Really if it doesn't work it means there is a deep problem in your compiler. We really don't want the overhead of WARN over BUILD_BUG in the normal case.
By the way, are you should the problem is really BUILD_BUG() ? Looking at your patch I would think that the problem is because it is "static inline". Have you tried 'static __always_inline' instead ?
Christophe
Quoted 46 lines
The original expectation was that a compiler would see that the only usage of this function was in a function that is only called behind radix-only guards. And it worked this way on GCC. It seems Clang does not optimise away this call however, so thinks the function may be invoked and triggers the build bug as reported by the kernel test robot.
https://lore.kernel.org/llvm/[email protected]
This fix converts the build bug to a warning to allow builds without relying on particular compiler optimisation behaviours. The warning is not rate limited because this implementation should still never be called as-is, and anyone who might invoke it might appreciate it being very obvious that it's not behaving as expected.
Fixes 274d842fa1ef ("powerpc/tlb: Add local flush for page given mm_struct and psize")Reported-by kernel test robot <[email protected]>Signed-off-by Benjamin Gray <[email protected]>--- arch/powerpc/include/asm/book3s/32/tlbflush.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)arch/powerpc/include/asm/book3s/32/tlbflush.h +2
-2@@ -2,7 +2,7 @@#ifndef _ASM_POWERPC_BOOK3S_32_TLBFLUSH_H#define _ASM_POWERPC_BOOK3S_32_TLBFLUSH_H -#include <linux/build_bug.h> +#include <linux/bug.h> #define MMU_NO_CONTEXT (0)/* @@ -80,7 +80,7 @@ static inline void local_flush_tlb_page(struct vm_area_struct *vma,static inline void local_flush_tlb_page_psize (struct mm_struct *mm,unsigned long vmaddr,int psize) { -BUILD_BUG (); +WARN (1 ,"Unimplemented local TLB flush with psize" ); }static inline void local_flush_tlb_mm (struct mm_struct *mm)base-commit:
53ab112a95086d10dc353ea4f979abb01644bbb6
Quoted 4 lines · Christophe Leroy
By the way, are you should the problem is really
BUILD_BUG()? Looking
at your patch I would think that the problem is because it is "static inline". Have you tried 'static__always_inline' instead ?
I did not try it, so I just did but it doesn't make a difference.
Looking further, the failing config also enabled CONFIG_JUMP_LABEL_FEATURE_CHECK_DEBUG, which causes the mmu_has_feature(MMU_FTR_TYPE_RADIX) call of radix_enabled() to be non- trivial. It must check static_key_initialized, and falls back to early_mmu_has_feature if it triggers. Clang apparently can't see that early_mmu_has_feature will also always return false for Radix, so doesn't see that everything guarded by radix_enabled() is dead code. I suppose it's complicated by the fact it still has to run mmu_has_feature for the assertion side effect despite the return value being knowable at compile time.
So because of this weird interaction, the following should (and does) also prevent the compilation error by making the radix_enabled() return value more obvious to the compiler in the case where Radix is not implemented. (I've put the constant second here so the early usage assertion still runs).
(quoted diff) +0 -0
b/arch/powerpc/include/asm/mmu.h
index 94b981152667..3592ff9a522b 100644
arch/powerpc/include/asm/mmu.h +0 -0
@@ -327,7 +327,7 @@ static inline void assert_pte_locked(struct
mm_struct *mm, unsigned long addr)
static __always_inline bool radix_enabled(void)
{
- return mmu_has_feature(MMU_FTR_TYPE_RADIX);
+ return mmu_has_feature(MMU_FTR_TYPE_RADIX) &&IS_ENABLED(CONFIG_PPC_RADIX_MMU);
}
static __always_inline bool early_radix_enabled(void)
Le 26/01/2023 à 23:30, Benjamin Gray a écrit :
Quoted 20 lines · Christophe Leroy
Quoted 5 lines
By the way, are you should the problem is really
BUILD_BUG()? Looking
at your patch I would think that the problem is because it is "static inline". Have you tried 'static__always_inline' instead ?I did not try it, so I just did but it doesn't make a difference.
Looking further, the failing config also enabled
CONFIG_JUMP_LABEL_FEATURE_CHECK_DEBUG, which causes themmu_has_feature(MMU_FTR_TYPE_RADIX)call ofradix_enabled()to be non- trivial. It must checkstatic_key_initialized, and falls back toearly_mmu_has_featureif it triggers. Clang apparently can't see thatearly_mmu_has_featurewill also always return false for Radix, so doesn't see that everything guarded byradix_enabled()is dead code. I suppose it's complicated by the fact it still has to runmmu_has_featurefor the assertion side effect despite the return value being knowable at compile time.
Quoted 5 lines
So because of this weird interaction, the following should (and does) also prevent the compilation error by making the
radix_enabled()return value more obvious to the compiler in the case where Radix is not implemented. (I've put the constant second here so the early usage assertion still runs).
But then, that's probably not the only place where we may get an issue with radix_enabled() or any other use of mmu_has_feature() by the way.
We are in a trivial situation where the feature check is either always true or always false. Is it worth checking for jump label init in that case ?
I think the best solution should be to move the following trivial checks above the static_key_initialised check:
if (MMU_FTRS_ALWAYS & feature) return true; if (!(MMU_FTRS_POSSIBLE & feature)) return false;
Christophe
Quoted 17 lines
arch/powerpc/include/asm/mmu.h +1
-1@@ -327,7 +327,7 @@ static inline void assert_pte_locked(struct mm_struct *mm, unsigned long addr) static __always_inline bool radix_enabled(void) { -return mmu_has_feature (MMU_FTR_TYPE_RADIX ); +return mmu_has_feature (MMU_FTR_TYPE_RADIX ) &&IS_ENABLED (CONFIG_PPC_RADIX_MMU ); }static
__always_inlineboolearly_radix_enabled(void)
Michael Ellerman
reviewerQuoted 38 lines · Benjamin Gray
Converts the
BUILD_BUGto a WARN to allow building with a low/unoptimised compiler.The original expectation was that a compiler would see that the only usage of this function was in a function that is only called behind radix-only guards. And it worked this way on GCC. It seems Clang does not optimise away this call however, so thinks the function may be invoked and triggers the build bug as reported by the kernel test robot.
https://lore.kernel.org/llvm/[email protected]
This fix converts the build bug to a warning to allow builds without relying on particular compiler optimisation behaviours. The warning is not rate limited because this implementation should still never be called as-is, and anyone who might invoke it might appreciate it being very obvious that it's not behaving as expected.
Fixes 274d842fa1ef ("powerpc/tlb: Add local flush for page given mm_struct and psize")Reported-by kernel test robot <[email protected]>Signed-off-by Benjamin Gray <[email protected]>--- arch/powerpc/include/asm/book3s/32/tlbflush.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)arch/powerpc/include/asm/book3s/32/tlbflush.h +1
-1@@ -2,7 +2,7 @@#ifndef _ASM_POWERPC_BOOK3S_32_TLBFLUSH_H#define _ASM_POWERPC_BOOK3S_32_TLBFLUSH_H -#include <linux/build_bug.h> +#include <linux/bug.h> #define MMU_NO_CONTEXT (0)/*
arch/powerpc/include/asm/book3s/32/tlbflush.h static inline void local_flush_tlb_page(struct vm_area_struct *vma, · line 83
Quoted 5 lines
arch/powerpc/include/asm/book3s/32/tlbflush.h +1
-1@@ -80,7 +80,7 @@ static inline void local_flush_tlb_page(struct vm_area_struct *vma,static inline void local_flush_tlb_page_psize (struct mm_struct *mm,unsigned long vmaddr,int psize) { -BUILD_BUG (); +WARN (1 ,"Unimplemented local TLB flush with psize" );
Can't we just fall back to flush_tlb_page(vma, vmaddr)?
I'd guess those CPUs can't flush based on page size anyway.
cheers
Quoted 5 lines · Michael Ellerman
Can't we just fall back to
flush_tlb_page(vma, vmaddr)?I'd guess those CPUs can't flush based on page size anyway.
cheers
Probably. Do they have a fixed page size? It's not a BUILD_BUG/WARN because it _should_ be unimplemented, just that I don't have an idea of how that target works.
Michael Ellerman
reviewerQuoted 8 lines · Benjamin Gray
Quoted 5 lines · Michael Ellerman
Can't we just fall back to
flush_tlb_page(vma, vmaddr)?I'd guess those CPUs can't flush based on page size anyway.
cheers
Probably. Do they have a fixed page size?
AFAIK yes.
cheers