riscv: Fixup compile error BUILD_BUG_ON failed
Subsystems (2)
[email protected]
maintainerPATCH 1/1 riscv: Fixup compile error BUILD_BUG_ON failed
From: Guo Ren <[email protected]>
Unfortunately, the current code couldn't be compiled, because BUILD_BUG_ON needs a static defined value, not a dynamic variable with a0 regs. Just use it inline as a solution.
CC arch/riscv/kernel/patch.o
In file included from ./include/linux/kernel.h:11,
from ./include/linux/list.h:9,
from ./include/linux/preempt.h:11,
from ./include/linux/spinlock.h:51,
from arch/riscv/kernel/patch.c:6:In function ‘fix_to_virt’,
inlined from ‘patch_map’ at arch/riscv/kernel/patch.c:37:17:./include/linux/compiler.h:392:38: error: call to ‘__compiletime_assert_205’ declared with attribute error: BUILD_BUG_ON failed: idx >= __end_of_fixed_addresses
_compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
^
./include/linux/compiler.h:373:4: note: in definition of macro ‘__compiletime_assert’
prefix ## suffix(); \
^~~~~~./include/linux/compiler.h:392:2: note: in expansion of macro ‘_compiletime_assert’
_compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__) ^~~~~~~~~~~~~~~~~~~./include/linux/build_bug.h:39:37: note: in expansion of macro ‘compiletime_assert’
#define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
^~~~~~~~~~~~~~~~~~./include/linux/build_bug.h:50:2: note: in expansion of macro ‘BUILD_BUG_ON_MSG’
BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition) ^~~~~~~~~~~~~~~~./include/asm-generic/fixmap.h:32:2: note: in expansion of macro ‘BUILD_BUG_ON’
BUILD_BUG_ON(idx >= __end_of_fixed_addresses);
^~~~~~~~~~~~
--- arch/riscv/kernel/patch.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
arch/riscv/kernel/patch.c +1 -2
@@ -20,7 +20,7 @@ struct patch_insn { };#ifdef CONFIG_MMU -static void *patch_map (void *addr,int fixmap) +static inline void *patch_map (void *addr,int fixmap) {uintptr_t uintaddr = (uintptr_t ) addr;struct page *page;
@@ -37,7 +37,6 @@ static void *patch_map(void *addr, int fixmap)return (void *)set_fixmap_offset (fixmap,page_to_phys (page) + (uintaddr & ~PAGE_MASK )); } -NOKPROBE_SYMBOL (patch_map);static void patch_unmap (int fixmap) {
Signature · 1 line
2.7.4
Quoted 45 lines · On Sat, 27 Jun 2020 16:20:02 +0000 [email protected] wrote:
From: Guo Ren <[email protected]>
Unfortunately, the current code couldn't be compiled, because
BUILD_BUG_ONneeds a static defined value, not a dynamic variable with a0 regs. Just use it inline as a solution.CC
arch/riscv/kernel/patch.o
In file included from./include/linux/kernel.h:11,from ./include/linux/list.h:9, from ./include/linux/preempt.h:11, from ./include/linux/spinlock.h:51, from arch/riscv/kernel/patch.c:6:In function ‘fix_to_virt’,
inlined from ‘patch_map’ atarch/riscv/kernel/patch.c:37:17:./include/linux/compiler.h:392:38: error: call to ‘__compiletime_assert_205’ declared with attribute error:BUILD_BUG_ONfailed: idx >=__end_of_fixed_addresses
_compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)^ ./include/linux/compiler.h:373:4: note: in definition of macro ‘__compiletime_assert’ prefix ## suffix(); \ ^~~~~~
./include/linux/compiler.h:392:2: note: in expansion of macro ‘_compiletime_assert’
_compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)^~~~~~~~~~~~~~~~~~~./include/linux/build_bug.h:39:37: note: in expansion of macro ‘compiletime_assert’#define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg) ^~~~~~~~~~~~~~~~~~
./include/linux/build_bug.h:50:2: note: in expansion of macro ‘BUILD_BUG_ON_MSG’
BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)^~~~~~~~~~~~~~~~./include/asm-generic/fixmap.h:32:2: note: in expansion of macro ‘BUILD_BUG_ON’
BUILD_BUG_ON(idx >= __end_of_fixed_addresses);
^~~~~~~~~~~~Signed-off-by Guo Ren <[email protected]>Cc Masami Hiramatsu <[email protected]>Cc Zong Li <[email protected]>--- arch/riscv/kernel/patch.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)arch/riscv/kernel/patch.c +0
-0
arch/riscv/kernel/patch.c struct patch_insn { · line 23
Quoted 5 lines
arch/riscv/kernel/patch.c +1
-1@@ -20,7 +20,7 @@ struct patch_insn { };#ifdef CONFIG_MMU -static void *patch_map (void *addr,int fixmap) +static inline void *patch_map (void *addr,int fixmap)
Would we be better to use "__always_inline" as same as fix_to_virt? And also, could you add a comment why we need to make it inline?
Thank you,
Quoted 14 lines
arch/riscv/kernel/patch.c +0
-1{uintptr_t uintaddr = (uintptr_t ) addr;struct page *page;@@ -37,7 +37,6 @@ static void *patch_map(void *addr, int fixmap)return (void *)set_fixmap_offset (fixmap,page_to_phys (page) + (uintaddr & ~PAGE_MASK )); } -NOKPROBE_SYMBOL (patch_map);static void patch_unmap (int fixmap) {Signature · 1 line
2.7.4
Signature · 1 line
Masami Hiramatsu <[email protected]>
Guo Ren
maintainerQuoted 51 lines · Masami Hiramatsu
Quoted 47 lines · On Sat, 27 Jun 2020 16:20:02 +0000 [email protected] wrote:
From: Guo Ren <[email protected]>
Unfortunately, the current code couldn't be compiled, because
BUILD_BUG_ONneeds a static defined value, not a dynamic variable with a0 regs. Just use it inline as a solution.CC
arch/riscv/kernel/patch.o
In file included from./include/linux/kernel.h:11,from ./include/linux/list.h:9, from ./include/linux/preempt.h:11, from ./include/linux/spinlock.h:51, from arch/riscv/kernel/patch.c:6:In function ‘fix_to_virt’,
inlined from ‘patch_map’ atarch/riscv/kernel/patch.c:37:17:./include/linux/compiler.h:392:38: error: call to ‘__compiletime_assert_205’ declared with attribute error:BUILD_BUG_ONfailed: idx >=__end_of_fixed_addresses
_compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)^ ./include/linux/compiler.h:373:4: note: in definition of macro ‘__compiletime_assert’ prefix ## suffix(); \ ^~~~~~
./include/linux/compiler.h:392:2: note: in expansion of macro ‘_compiletime_assert’
_compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)^~~~~~~~~~~~~~~~~~~./include/linux/build_bug.h:39:37: note: in expansion of macro ‘compiletime_assert’#define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg) ^~~~~~~~~~~~~~~~~~
./include/linux/build_bug.h:50:2: note: in expansion of macro ‘BUILD_BUG_ON_MSG’
BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)^~~~~~~~~~~~~~~~./include/asm-generic/fixmap.h:32:2: note: in expansion of macro ‘BUILD_BUG_ON’
BUILD_BUG_ON(idx >= __end_of_fixed_addresses);
^~~~~~~~~~~~Signed-off-by Guo Ren <[email protected]>Cc Masami Hiramatsu <[email protected]>Cc Zong Li <[email protected]>--- arch/riscv/kernel/patch.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)arch/riscv/kernel/patch.c +0
-0@@ -20,7 +20,7 @@ struct patch_insn { };
Quoted 5 lines
arch/riscv/kernel/patch.c struct patch_insn { · line 23
Quoted 3 lines
arch/riscv/kernel/patch.c +1
-1#ifdef CONFIG_MMU -static void *patch_map (void *addr,int fixmap) +static inline void *patch_map (void *addr,int fixmap)Would we be better to use "
__always_inline" as same asfix_to_virt?
Ok
Quoted 1 line
And also, could you add a comment why we need to make it inline?
I've mentioned in comment:
Quoted 2 lines
Quoted 2 lines
BUILD_BUG_ONneeds a static defined value, not a dynamic variable with a0 regs.
idx must be a const unsigned int or it will cause compile error with BUILD_BUG_ON.
/*
* 'index to address' translation. If anyone tries to use the idx
* directly without translation, we catch the bug with a NULL-deference
* kernel oops. Illegal ranges of incoming indices are caught too. */
static __always_inline unsigned long fix_to_virt(const unsigned int idx)
{
BUILD_BUG_ON(idx >= __end_of_fixed_addresses);
return __fix_to_virt(idx);
}Signature · 4 lines
Best Regards Guo Ren ML: https://lore.kernel.org/linux-csky/
Quoted 59 lines · On Sun, 28 Jun 2020 14:12:07 +0800 Guo Ren <[email protected]> wrote:
Quoted 51 lines · Masami Hiramatsu
Quoted 47 lines · On Sat, 27 Jun 2020 16:20:02 +0000 [email protected] wrote:
From: Guo Ren <[email protected]>
Unfortunately, the current code couldn't be compiled, because
BUILD_BUG_ONneeds a static defined value, not a dynamic variable with a0 regs. Just use it inline as a solution.CC
arch/riscv/kernel/patch.o
In file included from./include/linux/kernel.h:11,from ./include/linux/list.h:9, from ./include/linux/preempt.h:11, from ./include/linux/spinlock.h:51, from arch/riscv/kernel/patch.c:6:In function ‘fix_to_virt’,
inlined from ‘patch_map’ atarch/riscv/kernel/patch.c:37:17:./include/linux/compiler.h:392:38: error: call to ‘__compiletime_assert_205’ declared with attribute error:BUILD_BUG_ONfailed: idx >=__end_of_fixed_addresses
_compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)^ ./include/linux/compiler.h:373:4: note: in definition of macro ‘__compiletime_assert’ prefix ## suffix(); \ ^~~~~~
./include/linux/compiler.h:392:2: note: in expansion of macro ‘_compiletime_assert’
_compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)^~~~~~~~~~~~~~~~~~~./include/linux/build_bug.h:39:37: note: in expansion of macro ‘compiletime_assert’#define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg) ^~~~~~~~~~~~~~~~~~
./include/linux/build_bug.h:50:2: note: in expansion of macro ‘BUILD_BUG_ON_MSG’
BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)^~~~~~~~~~~~~~~~./include/asm-generic/fixmap.h:32:2: note: in expansion of macro ‘BUILD_BUG_ON’
BUILD_BUG_ON(idx >= __end_of_fixed_addresses);
^~~~~~~~~~~~Signed-off-by Guo Ren <[email protected]>Cc Masami Hiramatsu <[email protected]>Cc Zong Li <[email protected]>--- arch/riscv/kernel/patch.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)arch/riscv/kernel/patch.c +0
-0@@ -20,7 +20,7 @@ struct patch_insn { };Quoted 5 lines
arch/riscv/kernel/patch.c struct patch_insn { · line 23
Quoted 3 lines
arch/riscv/kernel/patch.c +1
-1#ifdef CONFIG_MMU -static void *patch_map (void *addr,int fixmap) +static inline void *patch_map (void *addr,int fixmap)Would we be better to use "
__always_inline" as same asfix_to_virt?Ok
Quoted 7 lines
Quoted 1 line
And also, could you add a comment why we need to make it inline?
I've mentioned in comment:
Quoted 2 lines
Quoted 2 lines
BUILD_BUG_ONneeds a static defined value, not a dynamic variable with a0 regs.idx must be a const unsigned int or it will cause compile error with
BUILD_BUG_ON.
Ah, sorry for the confusion. I meant the comment line in the code. BTW, can we also use "const unsigned int" for the fixmap index so that no one miss it anymore?
Thank you,
Quoted 17 lines
/*
* 'index to address' translation. If anyone tries to use the idx
* directly without translation, we catch the bug with a NULL-deference
* kernel oops. Illegal ranges of incoming indices are caught too. */
static__always_inlineunsigned longfix_to_virt(const unsigned int idx){ BUILD_BUG_ON(idx >= __end_of_fixed_addresses); return __fix_to_virt(idx); }Signature · 4 lines
Best Regards Guo Ren ML: https://lore.kernel.org/linux-csky/
Signature · 1 line
Masami Hiramatsu <[email protected]>
Guo Ren
maintainerQuoted 64 lines · Masami Hiramatsu
Quoted 60 lines · On Sun, 28 Jun 2020 14:12:07 +0800 Guo Ren <[email protected]> wrote:
Quoted 51 lines · Masami Hiramatsu
Quoted 47 lines · On Sat, 27 Jun 2020 16:20:02 +0000 [email protected] wrote:
From: Guo Ren <[email protected]>
Unfortunately, the current code couldn't be compiled, because
BUILD_BUG_ONneeds a static defined value, not a dynamic variable with a0 regs. Just use it inline as a solution.CC
arch/riscv/kernel/patch.o
In file included from./include/linux/kernel.h:11,from ./include/linux/list.h:9, from ./include/linux/preempt.h:11, from ./include/linux/spinlock.h:51, from arch/riscv/kernel/patch.c:6:In function ‘fix_to_virt’,
inlined from ‘patch_map’ atarch/riscv/kernel/patch.c:37:17:./include/linux/compiler.h:392:38: error: call to ‘__compiletime_assert_205’ declared with attribute error:BUILD_BUG_ONfailed: idx >=__end_of_fixed_addresses
_compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)^ ./include/linux/compiler.h:373:4: note: in definition of macro ‘__compiletime_assert’ prefix ## suffix(); \ ^~~~~~
./include/linux/compiler.h:392:2: note: in expansion of macro ‘_compiletime_assert’
_compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)^~~~~~~~~~~~~~~~~~~./include/linux/build_bug.h:39:37: note: in expansion of macro ‘compiletime_assert’#define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg) ^~~~~~~~~~~~~~~~~~
./include/linux/build_bug.h:50:2: note: in expansion of macro ‘BUILD_BUG_ON_MSG’
BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)^~~~~~~~~~~~~~~~./include/asm-generic/fixmap.h:32:2: note: in expansion of macro ‘BUILD_BUG_ON’
BUILD_BUG_ON(idx >= __end_of_fixed_addresses);
^~~~~~~~~~~~Signed-off-by Guo Ren <[email protected]>Cc Masami Hiramatsu <[email protected]>Cc Zong Li <[email protected]>--- arch/riscv/kernel/patch.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)arch/riscv/kernel/patch.c +0
-0@@ -20,7 +20,7 @@ struct patch_insn { };Quoted 5 lines
arch/riscv/kernel/patch.c struct patch_insn { · line 23
Quoted 3 lines
arch/riscv/kernel/patch.c +1
-1#ifdef CONFIG_MMU -static void *patch_map (void *addr,int fixmap) +static inline void *patch_map (void *addr,int fixmap)Would we be better to use "
__always_inline" as same asfix_to_virt?Ok
Quoted 1 line
And also, could you add a comment why we need to make it inline?
Quoted 8 lines
Quoted 6 lines
I've mentioned in comment:
Quoted 2 lines
Quoted 2 lines
BUILD_BUG_ONneeds a static defined value, not a dynamic variable with a0 regs.idx must be a const unsigned int or it will cause compile error with
BUILD_BUG_ON.Ah, sorry for the confusion. I meant the comment line in the code.
Ok.
Quoted 2 lines
BTW, can we also use "const unsigned int" for the fixmap index so that no one miss it anymore?
Sure, actually I've done it in my patch V2. Thx for mention.
Signature · 4 lines
Best Regards Guo Ren ML: https://lore.kernel.org/linux-csky/