arch/x86/include/asm/preempt.h:27:55: sparse: sparse: incompatible types for operation (&):
Subsystems (3)
kernel test robot
build bottree: https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git x86/percpu head: ca4256348660cb2162668ec3d13d1f921d05374a commit: ca4256348660cb2162668ec3d13d1f921d05374a [12/12] x86/percpu: Use C for percpu read/write accessors config: x86_64-randconfig-122-20231007 (https://download.01.org/0day-ci/archive/20231008/[email protected]/config) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231008/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
sparse warnings: (new ones prefixed by >>)
kernel/bpf/percpu_freelist.c: note: in included file (through arch/x86/include/asm/preempt.h, include/linux/preempt.h, include/linux/spinlock.h, ...):
arch/x86/include/asm/percpu.h:550:49: sparse: sparse: Expected ) at end of cast operator
arch/x86/include/asm/percpu.h:550:49: sparse: sparse: got __seg_gs
arch/x86/include/asm/percpu.h:564:33: sparse: sparse: Expected ) at end of cast operator
arch/x86/include/asm/percpu.h:564:33: sparse: sparse: got __seg_gs
kernel/bpf/percpu_freelist.c: note: in included file (through arch/x86/include/asm/cpufeature.h, arch/x86/include/asm/thread_info.h, include/linux/thread_info.h, ...):
arch/x86/include/asm/processor.h:504:9: sparse: sparse: Expected ) at end of cast operator
arch/x86/include/asm/processor.h:504:9: sparse: sparse: got __seg_gs
arch/x86/include/asm/processor.h:504:9: sparse: sparse: Expected ) at end of cast operator
arch/x86/include/asm/processor.h:504:9: sparse: sparse: got __seg_gs
arch/x86/include/asm/processor.h:504:9: sparse: sparse: Expected ) at end of cast operator
arch/x86/include/asm/processor.h:504:9: sparse: sparse: got __seg_gs
arch/x86/include/asm/processor.h:504:9: sparse: sparse: Expected ) at end of cast operator
arch/x86/include/asm/processor.h:504:9: sparse: sparse: got __seg_gs
kernel/bpf/percpu_freelist.c: note: in included file (through include/linux/preempt.h, include/linux/spinlock.h, kernel/bpf/percpu_freelist.h):
arch/x86/include/asm/preempt.h:27:16: sparse: sparse: Expected ) at end of cast operator
arch/x86/include/asm/preempt.h:27:16: sparse: sparse: got __seg_gs
arch/x86/include/asm/preempt.h:34:15: sparse: sparse: Expected ) at end of cast operator
arch/x86/include/asm/preempt.h:34:15: sparse: sparse: got __seg_gs
arch/x86/include/asm/preempt.h:38:19: sparse: sparse: Expected ) at end of cast operator
arch/x86/include/asm/preempt.h:38:19: sparse: sparse: got __seg_gs
arch/x86/include/asm/preempt.h:61:9: sparse: sparse: Expected ) at end of cast operator
arch/x86/include/asm/preempt.h:61:9: sparse: sparse: got __seg_gs
arch/x86/include/asm/preempt.h:66:9: sparse: sparse: Expected ) at end of cast operator
arch/x86/include/asm/preempt.h:66:9: sparse: sparse: got __seg_gs
arch/x86/include/asm/preempt.h:71:18: sparse: sparse: Expected ) at end of cast operator
arch/x86/include/asm/preempt.h:71:18: sparse: sparse: got __seg_gs
arch/x86/include/asm/preempt.h:80:9: sparse: sparse: Expected ) at end of cast operator
arch/x86/include/asm/preempt.h:80:9: sparse: sparse: got __seg_gs
arch/x86/include/asm/preempt.h:80:9: sparse: sparse: Expected ) at end of cast operator
arch/x86/include/asm/preempt.h:80:9: sparse: sparse: got __seg_gs
arch/x86/include/asm/preempt.h:80:9: sparse: sparse: Expected ) at end of cast operator
arch/x86/include/asm/preempt.h:80:9: sparse: sparse: got __seg_gs
arch/x86/include/asm/preempt.h:85:9: sparse: sparse: Expected ) at end of cast operator
arch/x86/include/asm/preempt.h:85:9: sparse: sparse: got __seg_gs
arch/x86/include/asm/preempt.h:85:9: sparse: sparse: Expected ) at end of cast operator
arch/x86/include/asm/preempt.h:85:9: sparse: sparse: got __seg_gs
arch/x86/include/asm/preempt.h:85:9: sparse: sparse: Expected ) at end of cast operator
arch/x86/include/asm/preempt.h:85:9: sparse: sparse: got __seg_gs
arch/x86/include/asm/preempt.h:95:16: sparse: sparse: Expected ) at end of cast operator
arch/x86/include/asm/preempt.h:95:16: sparse: sparse: got __seg_gs
arch/x86/include/asm/preempt.h:104:16: sparse: sparse: Expected ) at end of cast operator
arch/x86/include/asm/preempt.h:104:16: sparse: sparse: got __seg_gs
kernel/bpf/percpu_freelist.c:61:20: sparse: sparse: Expected ) at end of cast operator
kernel/bpf/percpu_freelist.c:61:20: sparse: sparse: got __seg_gs
kernel/bpf/percpu_freelist.c:61:20: sparse: sparse: Expected ) at end of cast operator
kernel/bpf/percpu_freelist.c:61:20: sparse: sparse: got __seg_gs
kernel/bpf/percpu_freelist.c:61:20: sparse: sparse: Expected ) at end of cast operator
kernel/bpf/percpu_freelist.c:61:20: sparse: sparse: got __seg_gs
kernel/bpf/percpu_freelist.c:61:20: sparse: sparse: Expected ) at end of cast operator
kernel/bpf/percpu_freelist.c:61:20: sparse: sparse: got __seg_gs
kernel/bpf/percpu_freelist.c:86:39: sparse: sparse: Expected ) at end of cast operator
kernel/bpf/percpu_freelist.c:86:39: sparse: sparse: got __seg_gs
kernel/bpf/percpu_freelist.c:127:9: sparse: sparse: Expected ) at end of cast operator
kernel/bpf/percpu_freelist.c:127:9: sparse: sparse: got __seg_gs
kernel/bpf/percpu_freelist.c:127:9: sparse: sparse: Expected ) at end of cast operator
kernel/bpf/percpu_freelist.c:127:9: sparse: sparse: got __seg_gs
kernel/bpf/percpu_freelist.c:127:9: sparse: sparse: Expected ) at end of cast operator
kernel/bpf/percpu_freelist.c:127:9: sparse: sparse: got __seg_gs
kernel/bpf/percpu_freelist.c:127:9: sparse: sparse: Expected ) at end of cast operator
kernel/bpf/percpu_freelist.c:127:9: sparse: sparse: got __seg_gs
kernel/bpf/percpu_freelist.c:127:9: sparse: sparse: Expected ) at end of cast operator
kernel/bpf/percpu_freelist.c:127:9: sparse: sparse: got __seg_gs
kernel/bpf/percpu_freelist.c:127:9: sparse: sparse: Expected ) at end of cast operator
kernel/bpf/percpu_freelist.c:127:9: sparse: sparse: got __seg_gs
kernel/bpf/percpu_freelist.c:127:9: sparse: sparse: Expected ) at end of cast operator
kernel/bpf/percpu_freelist.c:127:9: sparse: sparse: got __seg_gs
kernel/bpf/percpu_freelist.c:127:9: sparse: sparse: Expected ) at end of cast operator
kernel/bpf/percpu_freelist.c:127:9: sparse: sparse: got __seg_gs
kernel/bpf/percpu_freelist.c:159:9: sparse: sparse: Expected ) at end of cast operator
kernel/bpf/percpu_freelist.c:159:9: sparse: sparse: got __seg_gs
kernel/bpf/percpu_freelist.c:159:9: sparse: sparse: Expected ) at end of cast operator
kernel/bpf/percpu_freelist.c:159:9: sparse: sparse: got __seg_gs
kernel/bpf/percpu_freelist.c:159:9: sparse: sparse: Expected ) at end of cast operator
kernel/bpf/percpu_freelist.c:159:9: sparse: sparse: got __seg_gs
kernel/bpf/percpu_freelist.c:159:9: sparse: sparse: Expected ) at end of cast operator
kernel/bpf/percpu_freelist.c:159:9: sparse: sparse: got __seg_gs
kernel/bpf/percpu_freelist.c:159:9: sparse: sparse: Expected ) at end of cast operator
kernel/bpf/percpu_freelist.c:159:9: sparse: sparse: got __seg_gs
kernel/bpf/percpu_freelist.c:159:9: sparse: sparse: Expected ) at end of cast operator
kernel/bpf/percpu_freelist.c:159:9: sparse: sparse: got __seg_gs
kernel/bpf/percpu_freelist.c:159:9: sparse: sparse: Expected ) at end of cast operator
kernel/bpf/percpu_freelist.c:159:9: sparse: sparse: got __seg_gs
kernel/bpf/percpu_freelist.c:159:9: sparse: sparse: Expected ) at end of cast operator
kernel/bpf/percpu_freelist.c:159:9: sparse: sparse: got __seg_gs
>> arch/x86/include/asm/preempt.h:27:55: sparse: sparse: incompatible types for operation (&): >> arch/x86/include/asm/preempt.h:27:55: sparse: void >> arch/x86/include/asm/preempt.h:27:55: sparse: unsigned int >> arch/x86/include/asm/preempt.h:27:55: sparse: sparse: incompatible types for operation (&): >> arch/x86/include/asm/preempt.h:27:55: sparse: void >> arch/x86/include/asm/preempt.h:27:55: sparse: unsigned int
vim +27 arch/x86/include/asm/preempt.h
ba1f14fbe70965 Peter Zijlstra 2013-11-28 20
c2daa3bed53a81 Peter Zijlstra 2013-08-14 21 /*
c2daa3bed53a81 Peter Zijlstra 2013-08-14 22 * We mask the PREEMPT_NEED_RESCHED bit so as not to confuse all current users
c2daa3bed53a81 Peter Zijlstra 2013-08-14 23 * that think a non-zero value indicates we cannot preempt.
c2daa3bed53a81 Peter Zijlstra 2013-08-14 24 */
c2daa3bed53a81 Peter Zijlstra 2013-08-14 25 static __always_inline int preempt_count(void)
c2daa3bed53a81 Peter Zijlstra 2013-08-14 26 {
64701838bf0575 Thomas Gleixner 2022-09-15 @27 return raw_cpu_read_4(pcpu_hot.preempt_count) & ~PREEMPT_NEED_RESCHED;
c2daa3bed53a81 Peter Zijlstra 2013-08-14 28 }
c2daa3bed53a81 Peter Zijlstra 2013-08-14 29 :::::: The code at line 27 was first introduced by commit
:::::: 64701838bf0575ef8acb1ad2db5934e864f3e6c3 x86/percpu: Move preempt_count next to current_task
:::::: TO: Thomas Gleixner <[email protected]>
:::::: CC: Peter Zijlstra <[email protected]>
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Quoted 13 lines · kernel test robot
tree: https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git x86/percpu head: ca4256348660cb2162668ec3d13d1f921d05374a commit: ca4256348660cb2162668ec3d13d1f921d05374a [12/12] x86/percpu: Use C for percpu read/write accessors config: x86_64-randconfig-122-20231007 (https://download.01.org/0day-ci/archive/20231008/[email protected]/config) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231008/[email protected]/reproduce)If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
Quoted 6 lines
sparse warnings: (new ones prefixed by >>)
kernel/bpf/percpu_freelist.c: note: in included file (througharch/x86/include/asm/preempt.h,include/linux/preempt.h,include/linux/spinlock.h, ...):
arch/x86/include/asm/percpu.h:550:49: sparse: sparse: Expected ) at end of cast operatorarch/x86/include/asm/percpu.h:550:49: sparse: sparse: got__seg_gs
arch/x86/include/asm/percpu.h:564:33: sparse: sparse: Expected ) at end of cast operatorarch/x86/include/asm/percpu.h:564:33: sparse: sparse: got__seg_gs
sparse is too strict here. The following code is perfectly legal:
--cut here--
int __seg_gs foo;
int bar (int *pcp)
{
return *(typeof (*pcp) __seg_gs *)(unsigned long)(pcp);
}
--cut here--
$ gcc -O2 -S -Wextra -Wall test.c $ $ sparse test.c test.c:1:14: error: Expected ; at end of declaration test.c:1:14: error: got foo test.c:5:26: error: Expected ) at end of cast operator test.c:5:26: error: got __seg_gs $
Uros.
sparse: Expected ) at end of cast operator, got __seg_gs
Forwarded from [email protected]
---------- Forwarded message ---------
From: Uros Bizjak <[email protected]>
Date: Fri, Dec 1, 2023 at 2:57 PM
Subject: Re: [tip:x86/percpu 12/12] arch/x86/include/asm/preempt.h:27:55: sparse: sparse: incompatible types for operation (&):
To: kernel test robot <[email protected]>
Cc: <[email protected]>, <[email protected]>, <[email protected]>, Ingo Molnar <[email protected]>, Nadav Amit <[email protected]>
Quoted 13 lines · kernel test robot
tree: https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git x86/percpu head: ca4256348660cb2162668ec3d13d1f921d05374a commit: ca4256348660cb2162668ec3d13d1f921d05374a [12/12] x86/percpu: Use C for percpu read/write accessors config: x86_64-randconfig-122-20231007 (https://download.01.org/0day-ci/archive/20231008/[email protected]/config) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231008/[email protected]/reproduce)If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
Quoted 6 lines
sparse warnings: (new ones prefixed by >>)
kernel/bpf/percpu_freelist.c: note: in included file (througharch/x86/include/asm/preempt.h,include/linux/preempt.h,include/linux/spinlock.h, ...):
arch/x86/include/asm/percpu.h:550:49: sparse: sparse: Expected ) at end of cast operatorarch/x86/include/asm/percpu.h:550:49: sparse: sparse: got__seg_gs
arch/x86/include/asm/percpu.h:564:33: sparse: sparse: Expected ) at end of cast operatorarch/x86/include/asm/percpu.h:564:33: sparse: sparse: got__seg_gs
sparse is too strict here. The following code is perfectly legal:
--cut here--
int __seg_gs foo;
int bar (int *pcp)
{
return *(typeof (*pcp) __seg_gs *)(unsigned long)(pcp);
}
--cut here--
$ gcc -O2 -S -Wextra -Wall test.c $ $ sparse test.c test.c:1:14: error: Expected ; at end of declaration test.c:1:14: error: got foo test.c:5:26: error: Expected ) at end of cast operator test.c:5:26: error: got __seg_gs $
Uros.
Re: sparse: Expected ) at end of cast operator, got __seg_gs
I patched Smatch to just ignore it. I think Luc is on sabatical and it's not clear if anyone is applying patches now.
--- parse.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
parse.c +13 -0
@@ -74,6 +74,7 @@ static struct token *parse_range_statement(struct token *token, struct statementstatic struct token *parse_asm_statement (struct token *token,struct statement *stmt);static struct token *toplevel_asm_declaration (struct token *token,struct symbol_list **list);static struct token *parse_static_assert (struct token *token,struct symbol_list **unused); +static struct token *ignore_seg_gs (struct token *token,struct symbol_list **unused);typedef struct token *attr_t (struct token *,struct symbol *,struct decl_state *);
@@ -354,6 +355,10 @@ static struct symbol_op static_assert_op = { .toplevel = parse_static_assert, }; +static struct symbol_op seg_gs = { + .toplevel = ignore_seg_gs, +}; +static struct symbol_op packed_op = { .attribute = attribute_packed, };
@@ -521,6 +526,9 @@ static struct init_keyword { N("_Float64x", &spec_op, .type = &float64x_ctype), N("_Float128", &spec_op, .type = &float128_ctype), N("__float128", &spec_op, .type = &float128_ctype), + +N ("__seg_gs" , &seg_gs), + }, keywords[] = {/* Statements */ N("if", &if_op),
@@ -2130,6 +2138,11 @@ static struct token *parse_static_assert(struct token *token, struct symbol_listreturn token; } +static struct token *ignore_seg_gs (struct token *token,struct symbol_list **unused) +{ +return token->next; +} +/* Make a statement out of an expression */ static struct statement *make_statement (struct expression *expr) {
Signature · 1 line
2.42.0
Re: sparse: Expected ) at end of cast operator, got __seg_gs
Quoted 3 lines · Dan Carpenter
I patched Smatch to just ignore it. I think Luc is on sabatical and it's not clear if anyone is applying patches now.
I think you should also include __seg_fs, this is the x86_32 counterpart to __seg_gs.
Uros.
Quoted 54 lines
Signed-off-by Dan Carpenter <[email protected]>--- parse.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)parse.c +13
-1@@ -74,6 +74,7 @@ static struct token *parse_range_statement(struct token *token, struct statementstatic struct token *parse_asm_statement (struct token *token,struct statement *stmt);static struct token *toplevel_asm_declaration (struct token *token,struct symbol_list **list);static struct token *parse_static_assert (struct token *token,struct symbol_list **unused); +static struct token *ignore_seg_gs (struct token *token,struct symbol_list **unused);typedef struct token *attr_t (struct token *,struct symbol *,struct decl_state *);@@ -354,6 +355,10 @@ static struct symbol_op static_assert_op = { .toplevel = parse_static_assert, }; +static struct symbol_op seg_gs = { + .toplevel = ignore_seg_gs, +}; +static struct symbol_op packed_op = { .attribute = attribute_packed, };@@ -521,6 +526,9 @@ static struct init_keyword { N("_Float64x", &spec_op, .type = &float64x_ctype), N("_Float128", &spec_op, .type = &float128_ctype), N("__float128", &spec_op, .type = &float128_ctype), + +N ("__seg_gs" , &seg_gs), + }, keywords[] = {/* Statements */ N("if", &if_op),@@ -2130,6 +2138,11 @@ static struct token *parse_static_assert(struct token *token, struct symbol_listreturn token; } +static struct token *ignore_seg_gs (struct token *token,struct symbol_list **unused) +{ +return token->next; +} +/* Make a statement out of an expression */ static struct statement *make_statement (struct expression *expr) { --2.42.0
Re: sparse: Expected ) at end of cast operator, got __seg_gs
In reply to Uros BizjakQuoted 9 lines · Uros Bizjak
Quoted 6 lines
sparse warnings: (new ones prefixed by >>)
kernel/bpf/percpu_freelist.c: note: in included file (througharch/x86/include/asm/preempt.h,include/linux/preempt.h,include/linux/spinlock.h, ...):
arch/x86/include/asm/percpu.h:550:49: sparse: sparse: Expected ) at end of cast operatorarch/x86/include/asm/percpu.h:550:49: sparse: sparse: got__seg_gs
arch/x86/include/asm/percpu.h:564:33: sparse: sparse: Expected ) at end of cast operatorarch/x86/include/asm/percpu.h:564:33: sparse: sparse: got__seg_gssparse is too strict here. The following code is perfectly legal:
It's not that sparse is too strict, it's because it knows nothing about __seg_gs.
What is missing is:
include/linux/compiler_types.h +1 -0
@@ -23,6 +23,7 @@# define __iomem __attribute__((noderef, address_space(__iomem)))# define __percpu __attribute__((noderef, address_space(__percpu)))# define __rcu __attribute__((noderef, address_space(__rcu))) +# define __seg_gs __attribute__((noderef, address_space(__seg_gs)))static inline void __chk_user_ptr (const volatile void __user *ptr) { }static inline void __chk_io_ptr (const volatile void __iomem *ptr) { }/* context/locking */
But with this patch sparse will now complain with 'warning: dereference of noderef expression' which are quite legit given the noderef and the way __seg_gs is used.
You have two choices quiet these:
1) If variables qualified with __seg_gs should only be dereferenced via some special accessor like __raw_cpu_{read,write}() the patch here above is correct and you need to fix the typing inside these accessors (using __force or casting to unsigned long like already done anyway in __my_cpu_ptr()).
I think this is the correct solution.
2) If it's OK to dereference __seg_gs qualified variables anywhere in the code (I don't think we should), then the 'noderef' in the patch should be removed.
Sorry, I can't currently do any testing or so.
Best regards
-- Luc
Re: sparse: Expected ) at end of cast operator, got __seg_gs
Quoted 29 lines · Luc Van Oostenryck
Quoted 9 lines · Uros Bizjak
Quoted 6 lines
sparse warnings: (new ones prefixed by >>)
kernel/bpf/percpu_freelist.c: note: in included file (througharch/x86/include/asm/preempt.h,include/linux/preempt.h,include/linux/spinlock.h, ...):
arch/x86/include/asm/percpu.h:550:49: sparse: sparse: Expected ) at end of cast operatorarch/x86/include/asm/percpu.h:550:49: sparse: sparse: got__seg_gs
arch/x86/include/asm/percpu.h:564:33: sparse: sparse: Expected ) at end of cast operatorarch/x86/include/asm/percpu.h:564:33: sparse: sparse: got__seg_gssparse is too strict here. The following code is perfectly legal:
It's not that sparse is too strict, it's because it knows nothing about
__seg_gs.What is missing is:
include/linux/compiler_types.h +1
-0@@ -23,6 +23,7 @@# define __iomem __attribute__((noderef, address_space(__iomem)))# define __percpu __attribute__((noderef, address_space(__percpu)))# define __rcu __attribute__((noderef, address_space(__rcu))) +# define __seg_gs __attribute__((noderef, address_space(__seg_gs)))static inline void __chk_user_ptr (const volatile void __user *ptr) { }static inline void __chk_io_ptr (const volatile void __iomem *ptr) { }/* context/locking */
Quoted 10 lines
But with this patch sparse will now complain with 'warning: dereference of noderef expression' which are quite legit given the noderef and the way
__seg_gsis used.
You have two choices quiet these:
1) If variables qualified with__seg_gsshould only be dereferenced via some special accessor like __raw_cpu_{read,write}() the patch here above is correct and you need to fix the typing inside these accessors (using__forceor casting to unsigned long like already done anyway in__my_cpu_ptr()).
I think this is the correct solution.
2) If it's OK to dereference__seg_gsqualified variables anywhere in the code (I don't think we should), then the 'noderef' in the patch should be removed.
__seg_gs qualified variables can be referenced anywhere in the code, e.g.:
--cut here--__seg_gs int m;
int foo (void)
{
return m + m;
}
--cut here--
so option 2) should be the correct option here.
These __seg_gs and __seg_fs qualifiers are specific to x86, so I'd put the definitions in the x86 specific percpu header, as in the attached patch. The patch solves the reported issue.
Thanks,
Uros.
arch/x86/include/asm/percpu.h +5 -0
@@ -95,6 +95,11 @@#endif /* CONFIG_SMP */ +#ifdef __CHECKER__ +#define __seg_gs __attribute__((address_space(__seg_gs))) +#define __seg_fs __attribute__((address_space(__seg_fs))) +#endif +#define __my_cpu_type (var) typeof(var) __percpu_seg_override#define __my_cpu_ptr (ptr) (__my_cpu_type(*ptr) *)(uintptr_t)(ptr)#define __my_cpu_var (var) (*__my_cpu_ptr(&var))
Re: sparse: Expected ) at end of cast operator, got __seg_gs
Quoted 11 lines · Uros Bizjak
On Mon, Dec 4, 2023 at 2:05 PM Luc Van Oostenryck <[email protected]> wrote:
__seg_gsqualified variables can be referenced anywhere in the code, e.g.:--cut here--
__seg_gsint m;int foo (void)
{
return m + m;
}
Yes, of course. But my point was not if they *can* be dereferenced but rather if *in the kernel, do want or not to use 'naked' __seg_gs qualified variable*. In other words, do we want to be warned if someone, somewhere try to dereference such qualified variable without using the accessor function? And I think the answer to this question should be 'yes'.
-- Luc
Re: sparse: Expected ) at end of cast operator, got __seg_gs
Quoted 14 lines · Luc Van Oostenryck
Quoted 11 lines · Uros Bizjak
On Mon, Dec 4, 2023 at 2:05 PM Luc Van Oostenryck <[email protected]> wrote:
__seg_gsqualified variables can be referenced anywhere in the code, e.g.:--cut here--
__seg_gsint m;int foo (void)
{
return m + m;
}
Quoted 5 lines
Yes, of course. But my point was not if they *can* be dereferenced but rather if *in the kernel, do want or not to use 'naked'
__seg_gsqualified variable*. In other words, do we want to be warned if someone, somewhere try to dereference such qualified variable without using the accessor function? And I think the answer to this question should be 'yes'.
Not really - when used as e.g.:
extern const struct pcpu_hot __seg_gs const_pcpu_hot;
we can use variable directly, e.g.:
return const_pcpu_hot.current_task;
This way, the compiler is able to significantly reduce the number of loads from current_task, which is not achievable when the accessor is used to dereference the structure. In the x86/percpu branch, the number of loads from current_task were reduced from ~4700 to 3201 by using 'naked' __seg_gs qualified variable. IOW, the benefit of using __seg_gs is to be able to access the naked variable.
Uros.
Re: sparse: Expected ) at end of cast operator, got __seg_gs
Quoted 29 lines · Uros Bizjak
Quoted 14 lines · Luc Van Oostenryck
Quoted 11 lines · Uros Bizjak
On Mon, Dec 4, 2023 at 2:05 PM Luc Van Oostenryck <[email protected]> wrote:
__seg_gsqualified variables can be referenced anywhere in the code, e.g.:--cut here--
__seg_gsint m;int foo (void)
{
return m + m;
}Quoted 5 lines
Yes, of course. But my point was not if they *can* be dereferenced but rather if *in the kernel, do want or not to use 'naked'
__seg_gsqualified variable*. In other words, do we want to be warned if someone, somewhere try to dereference such qualified variable without using the accessor function? And I think the answer to this question should be 'yes'.Not really - when used as e.g.:
extern const struct
pcpu_hot__seg_gsconst_pcpu_hot;we can use variable directly, e.g.:
Quoted 8 lines
return const_pcpu_hot.current_task;
This way, the compiler is able to significantly reduce the number of loads from
current_task, which is not achievable when the accessor is used to dereference the structure. In the x86/percpu branch, the number of loads fromcurrent_taskwere reduced from ~4700 to 3201 by using 'naked'__seg_gsqualified variable. IOW, the benefit of using__seg_gsis to be able to access the naked variable.
Additionally, the compiler checks access to this internal ("named") address space, and will prevent dereference from "generic" address space without appropriate casts. So, compiling:
--cut here--__seg_gs int *m;
int *foo (void)
{
return m;
}
--cut here--
will generate "error: return from pointer to non-enclosed address space".
But the following is allowed:
int *foo (void)
{
return (int *)(unsigned long) m;
}
Uros.