* [PATCH -tip v3 1/3] x86/percpu: Fix "const_pcpu_hot" version generation failure
@ 2023-12-04 21:02 Uros Bizjak
2023-12-04 21:02 ` [PATCH -tip v3 2/3] x86/traps: Use current_top_of_stack() helper in traps.c Uros Bizjak
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Uros Bizjak @ 2023-12-04 21:02 UTC (permalink / raw)
To: x86, linux-kernel
Cc: Uros Bizjak, Andy Lutomirski, Brian Gerst, Denys Vlasenko,
Ingo Molnar, H . Peter Anvin, Linus Torvalds, Peter Zijlstra,
Thomas Gleixner, Josh Poimboeuf
Version generation for "const_pcpu_hot" symbol failed because genksyms
doesn't know the __seg_gs keyword. Revert commit 4604c052b84d
"x86/percpu: Declare const_pcpu_hot as extern const variable" and
use this_cpu_read_const instead to avoid "sparse: dereference of
noderef expression" warning when reading const_pcpu_hot.
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
---
v2: Use BUILD_BUG() instead of BUG().
---
arch/x86/include/asm/current.h | 5 +++--
arch/x86/include/asm/percpu.h | 7 +++++++
arch/x86/include/asm/processor.h | 2 +-
3 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/arch/x86/include/asm/current.h b/arch/x86/include/asm/current.h
index 9fbd7cb2dc86..c8c5674d69f6 100644
--- a/arch/x86/include/asm/current.h
+++ b/arch/x86/include/asm/current.h
@@ -37,12 +37,13 @@ static_assert(sizeof(struct pcpu_hot) == 64);
DECLARE_PER_CPU_ALIGNED(struct pcpu_hot, pcpu_hot);
/* const-qualified alias to pcpu_hot, aliased by linker. */
-extern const struct pcpu_hot __percpu_seg_override const_pcpu_hot;
+DECLARE_PER_CPU_ALIGNED(const struct pcpu_hot __percpu_seg_override,
+ const_pcpu_hot);
static __always_inline struct task_struct *get_current(void)
{
if (IS_ENABLED(CONFIG_USE_X86_SEG_SUPPORT))
- return const_pcpu_hot.current_task;
+ return this_cpu_read_const(const_pcpu_hot.current_task);
return this_cpu_read_stable(pcpu_hot.current_task);
}
diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h
index 0f12b2004b94..3859abad19ec 100644
--- a/arch/x86/include/asm/percpu.h
+++ b/arch/x86/include/asm/percpu.h
@@ -28,6 +28,7 @@
#else /* ...!ASSEMBLY */
+#include <linux/build_bug.h>
#include <linux/kernel.h>
#include <linux/stringify.h>
@@ -462,6 +463,7 @@ do { \
#define this_cpu_write_8(pcp, val) __raw_cpu_write(volatile, pcp, val)
#endif
+#define this_cpu_read_const(pcp) __raw_cpu_read(, pcp)
#else /* CONFIG_USE_X86_SEG_SUPPORT */
#define raw_cpu_read_1(pcp) percpu_from_op(1, , "mov", pcp)
@@ -486,6 +488,11 @@ do { \
#define this_cpu_write_8(pcp, val) percpu_to_op(8, volatile, "mov", (pcp), val)
#endif
+/*
+ * The generic per-cpu infrastrucutre is not suitable for
+ * reading const-qualified variables.
+ */
+#define this_cpu_read_const(pcp) ({ BUILD_BUG(); (typeof(pcp))0; })
#endif /* CONFIG_USE_X86_SEG_SUPPORT */
#define raw_cpu_add_1(pcp, val) percpu_add_op(1, , (pcp), val)
diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index 061aa86b4662..1188e8bf76a2 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -534,7 +534,7 @@ static __always_inline unsigned long current_top_of_stack(void)
* entry trampoline.
*/
if (IS_ENABLED(CONFIG_USE_X86_SEG_SUPPORT))
- return const_pcpu_hot.top_of_stack;
+ return this_cpu_read_const(const_pcpu_hot.top_of_stack);
return this_cpu_read_stable(pcpu_hot.top_of_stack);
}
--
2.42.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH -tip v3 2/3] x86/traps: Use current_top_of_stack() helper in traps.c
2023-12-04 21:02 [PATCH -tip v3 1/3] x86/percpu: Fix "const_pcpu_hot" version generation failure Uros Bizjak
@ 2023-12-04 21:02 ` Uros Bizjak
2023-12-11 12:06 ` [tip: x86/percpu] " tip-bot2 for Uros Bizjak
2023-12-04 21:02 ` [PATCH -tip v3 3/3] x86/percpu: Avoid sparse warning with cast to named address space Uros Bizjak
2023-12-11 12:06 ` [tip: x86/percpu] x86/percpu: Fix "const_pcpu_hot" version generation failure tip-bot2 for Uros Bizjak
2 siblings, 1 reply; 7+ messages in thread
From: Uros Bizjak @ 2023-12-04 21:02 UTC (permalink / raw)
To: x86, linux-kernel
Cc: Uros Bizjak, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen, H. Peter Anvin
Use current_top_of_stack() helper in sync_regs() and vc_switch_off_ist()
instead of reading top_of_stack percpu variable explicitly.
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
---
arch/x86/kernel/traps.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
index c876f1d36a81..78b1d1a6ed2c 100644
--- a/arch/x86/kernel/traps.c
+++ b/arch/x86/kernel/traps.c
@@ -772,7 +772,7 @@ DEFINE_IDTENTRY_RAW(exc_int3)
*/
asmlinkage __visible noinstr struct pt_regs *sync_regs(struct pt_regs *eregs)
{
- struct pt_regs *regs = (struct pt_regs *)this_cpu_read(pcpu_hot.top_of_stack) - 1;
+ struct pt_regs *regs = (struct pt_regs *)current_top_of_stack() - 1;
if (regs != eregs)
*regs = *eregs;
return regs;
@@ -790,7 +790,7 @@ asmlinkage __visible noinstr struct pt_regs *vc_switch_off_ist(struct pt_regs *r
* trust it and switch to the current kernel stack
*/
if (ip_within_syscall_gap(regs)) {
- sp = this_cpu_read(pcpu_hot.top_of_stack);
+ sp = current_top_of_stack();
goto sync;
}
--
2.42.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* [tip: x86/percpu] x86/traps: Use current_top_of_stack() helper in traps.c
2023-12-04 21:02 ` [PATCH -tip v3 2/3] x86/traps: Use current_top_of_stack() helper in traps.c Uros Bizjak
@ 2023-12-11 12:06 ` tip-bot2 for Uros Bizjak
0 siblings, 0 replies; 7+ messages in thread
From: tip-bot2 for Uros Bizjak @ 2023-12-11 12:06 UTC (permalink / raw)
To: linux-tip-commits
Cc: Uros Bizjak, Ingo Molnar, Linus Torvalds, x86, linux-kernel
The following commit has been merged into the x86/percpu branch of tip:
Commit-ID: 13408c6ae684181d53c870cceddbd3a62ae34c3e
Gitweb: https://git.kernel.org/tip/13408c6ae684181d53c870cceddbd3a62ae34c3e
Author: Uros Bizjak <ubizjak@gmail.com>
AuthorDate: Mon, 04 Dec 2023 22:02:30 +01:00
Committer: Ingo Molnar <mingo@kernel.org>
CommitterDate: Mon, 11 Dec 2023 11:47:15 +01:00
x86/traps: Use current_top_of_stack() helper in traps.c
Use current_top_of_stack() helper in sync_regs() and vc_switch_off_ist()
instead of open-coding the reading of the top_of_stack percpu variable
explicitly.
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/r/20231204210320.114429-2-ubizjak@gmail.com
---
arch/x86/kernel/traps.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
index c876f1d..78b1d1a 100644
--- a/arch/x86/kernel/traps.c
+++ b/arch/x86/kernel/traps.c
@@ -772,7 +772,7 @@ DEFINE_IDTENTRY_RAW(exc_int3)
*/
asmlinkage __visible noinstr struct pt_regs *sync_regs(struct pt_regs *eregs)
{
- struct pt_regs *regs = (struct pt_regs *)this_cpu_read(pcpu_hot.top_of_stack) - 1;
+ struct pt_regs *regs = (struct pt_regs *)current_top_of_stack() - 1;
if (regs != eregs)
*regs = *eregs;
return regs;
@@ -790,7 +790,7 @@ asmlinkage __visible noinstr struct pt_regs *vc_switch_off_ist(struct pt_regs *r
* trust it and switch to the current kernel stack
*/
if (ip_within_syscall_gap(regs)) {
- sp = this_cpu_read(pcpu_hot.top_of_stack);
+ sp = current_top_of_stack();
goto sync;
}
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH -tip v3 3/3] x86/percpu: Avoid sparse warning with cast to named address space
2023-12-04 21:02 [PATCH -tip v3 1/3] x86/percpu: Fix "const_pcpu_hot" version generation failure Uros Bizjak
2023-12-04 21:02 ` [PATCH -tip v3 2/3] x86/traps: Use current_top_of_stack() helper in traps.c Uros Bizjak
@ 2023-12-04 21:02 ` Uros Bizjak
2023-12-05 0:21 ` Luc Van Oostenryck
2023-12-11 12:06 ` [tip: x86/percpu] " tip-bot2 for Uros Bizjak
2023-12-11 12:06 ` [tip: x86/percpu] x86/percpu: Fix "const_pcpu_hot" version generation failure tip-bot2 for Uros Bizjak
2 siblings, 2 replies; 7+ messages in thread
From: Uros Bizjak @ 2023-12-04 21:02 UTC (permalink / raw)
To: x86, linux-kernel
Cc: Uros Bizjak, kernel test robot, Luc Van Oostenryck,
Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
H. Peter Anvin
Teach sparse about __seg_fs and __seg_gs named address space
qualifiers to to avoid warnings about unexpected keyword at
the end of cast operator.
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202310080853.UhMe5iWa-lkp@intel.com/
Cc: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
---
v3: Teach sparse about __seg_gs and __seg_fs qualifiers instead
of removing these qualifiers when __CHECKER__ is defined.
---
arch/x86/include/asm/percpu.h | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h
index 3859abad19ec..e56a37886143 100644
--- a/arch/x86/include/asm/percpu.h
+++ b/arch/x86/include/asm/percpu.h
@@ -36,6 +36,11 @@
#ifdef CONFIG_CC_HAS_NAMED_AS
+#ifdef __CHECKER__
+#define __seg_gs __attribute__((address_space(__seg_gs)))
+#define __seg_fs __attribute__((address_space(__seg_fs)))
+#endif
+
#ifdef CONFIG_X86_64
#define __percpu_seg_override __seg_gs
#else
--
2.42.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH -tip v3 3/3] x86/percpu: Avoid sparse warning with cast to named address space
2023-12-04 21:02 ` [PATCH -tip v3 3/3] x86/percpu: Avoid sparse warning with cast to named address space Uros Bizjak
@ 2023-12-05 0:21 ` Luc Van Oostenryck
2023-12-11 12:06 ` [tip: x86/percpu] " tip-bot2 for Uros Bizjak
1 sibling, 0 replies; 7+ messages in thread
From: Luc Van Oostenryck @ 2023-12-05 0:21 UTC (permalink / raw)
To: Uros Bizjak
Cc: x86, linux-kernel, kernel test robot, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin
On Mon, Dec 04, 2023 at 10:02:31PM +0100, Uros Bizjak wrote:
> Teach sparse about __seg_fs and __seg_gs named address space
> qualifiers to to avoid warnings about unexpected keyword at
> the end of cast operator.
>
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202310080853.UhMe5iWa-lkp@intel.com/
> Cc: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: Borislav Petkov <bp@alien8.de>
> Cc: Dave Hansen <dave.hansen@linux.intel.com>
> Cc: "H. Peter Anvin" <hpa@zytor.com>
> Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Acked-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [tip: x86/percpu] x86/percpu: Avoid sparse warning with cast to named address space
2023-12-04 21:02 ` [PATCH -tip v3 3/3] x86/percpu: Avoid sparse warning with cast to named address space Uros Bizjak
2023-12-05 0:21 ` Luc Van Oostenryck
@ 2023-12-11 12:06 ` tip-bot2 for Uros Bizjak
1 sibling, 0 replies; 7+ messages in thread
From: tip-bot2 for Uros Bizjak @ 2023-12-11 12:06 UTC (permalink / raw)
To: linux-tip-commits
Cc: kernel test robot, Luc Van Oostenryck, Uros Bizjak, Ingo Molnar,
x86, linux-kernel
The following commit has been merged into the x86/percpu branch of tip:
Commit-ID: 3a1d3829e193c091475ceab481c5f8deab385023
Gitweb: https://git.kernel.org/tip/3a1d3829e193c091475ceab481c5f8deab385023
Author: Uros Bizjak <ubizjak@gmail.com>
AuthorDate: Mon, 04 Dec 2023 22:02:31 +01:00
Committer: Ingo Molnar <mingo@kernel.org>
CommitterDate: Mon, 11 Dec 2023 11:47:15 +01:00
x86/percpu: Avoid sparse warning with cast to named address space
Teach sparse about __seg_fs and __seg_gs named address space
qualifiers to to avoid warnings about unexpected keyword at
the end of cast operator.
Reported-by: kernel test robot <lkp@intel.com>
Acked-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20231204210320.114429-3-ubizjak@gmail.com
Closes: https://lore.kernel.org/oe-kbuild-all/202310080853.UhMe5iWa-lkp@intel.com/
---
arch/x86/include/asm/percpu.h | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h
index 3859aba..e56a378 100644
--- a/arch/x86/include/asm/percpu.h
+++ b/arch/x86/include/asm/percpu.h
@@ -36,6 +36,11 @@
#ifdef CONFIG_CC_HAS_NAMED_AS
+#ifdef __CHECKER__
+#define __seg_gs __attribute__((address_space(__seg_gs)))
+#define __seg_fs __attribute__((address_space(__seg_fs)))
+#endif
+
#ifdef CONFIG_X86_64
#define __percpu_seg_override __seg_gs
#else
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [tip: x86/percpu] x86/percpu: Fix "const_pcpu_hot" version generation failure
2023-12-04 21:02 [PATCH -tip v3 1/3] x86/percpu: Fix "const_pcpu_hot" version generation failure Uros Bizjak
2023-12-04 21:02 ` [PATCH -tip v3 2/3] x86/traps: Use current_top_of_stack() helper in traps.c Uros Bizjak
2023-12-04 21:02 ` [PATCH -tip v3 3/3] x86/percpu: Avoid sparse warning with cast to named address space Uros Bizjak
@ 2023-12-11 12:06 ` tip-bot2 for Uros Bizjak
2 siblings, 0 replies; 7+ messages in thread
From: tip-bot2 for Uros Bizjak @ 2023-12-11 12:06 UTC (permalink / raw)
To: linux-tip-commits
Cc: Uros Bizjak, Ingo Molnar, Linus Torvalds, x86, linux-kernel
The following commit has been merged into the x86/percpu branch of tip:
Commit-ID: 0e3703630bd3fead041a6bfb3a3f2a9891af6c34
Gitweb: https://git.kernel.org/tip/0e3703630bd3fead041a6bfb3a3f2a9891af6c34
Author: Uros Bizjak <ubizjak@gmail.com>
AuthorDate: Mon, 04 Dec 2023 22:02:29 +01:00
Committer: Ingo Molnar <mingo@kernel.org>
CommitterDate: Mon, 11 Dec 2023 11:47:14 +01:00
x86/percpu: Fix "const_pcpu_hot" version generation failure
Version generation for "const_pcpu_hot" symbol failed because genksyms
doesn't know the __seg_gs keyword. Effectively revert commit 4604c052b84d
("x86/percpu: Declare const_pcpu_hot as extern const variable") and
use this_cpu_read_const() instead to avoid "sparse: dereference of
noderef expression" warning when reading const_pcpu_hot.
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/r/20231204210320.114429-1-ubizjak@gmail.com
---
arch/x86/include/asm/current.h | 5 +++--
arch/x86/include/asm/percpu.h | 7 +++++++
arch/x86/include/asm/processor.h | 2 +-
3 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/arch/x86/include/asm/current.h b/arch/x86/include/asm/current.h
index 9fbd7cb..c8c5674 100644
--- a/arch/x86/include/asm/current.h
+++ b/arch/x86/include/asm/current.h
@@ -37,12 +37,13 @@ static_assert(sizeof(struct pcpu_hot) == 64);
DECLARE_PER_CPU_ALIGNED(struct pcpu_hot, pcpu_hot);
/* const-qualified alias to pcpu_hot, aliased by linker. */
-extern const struct pcpu_hot __percpu_seg_override const_pcpu_hot;
+DECLARE_PER_CPU_ALIGNED(const struct pcpu_hot __percpu_seg_override,
+ const_pcpu_hot);
static __always_inline struct task_struct *get_current(void)
{
if (IS_ENABLED(CONFIG_USE_X86_SEG_SUPPORT))
- return const_pcpu_hot.current_task;
+ return this_cpu_read_const(const_pcpu_hot.current_task);
return this_cpu_read_stable(pcpu_hot.current_task);
}
diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h
index 0f12b20..3859aba 100644
--- a/arch/x86/include/asm/percpu.h
+++ b/arch/x86/include/asm/percpu.h
@@ -28,6 +28,7 @@
#else /* ...!ASSEMBLY */
+#include <linux/build_bug.h>
#include <linux/kernel.h>
#include <linux/stringify.h>
@@ -462,6 +463,7 @@ do { \
#define this_cpu_write_8(pcp, val) __raw_cpu_write(volatile, pcp, val)
#endif
+#define this_cpu_read_const(pcp) __raw_cpu_read(, pcp)
#else /* CONFIG_USE_X86_SEG_SUPPORT */
#define raw_cpu_read_1(pcp) percpu_from_op(1, , "mov", pcp)
@@ -486,6 +488,11 @@ do { \
#define this_cpu_write_8(pcp, val) percpu_to_op(8, volatile, "mov", (pcp), val)
#endif
+/*
+ * The generic per-cpu infrastrucutre is not suitable for
+ * reading const-qualified variables.
+ */
+#define this_cpu_read_const(pcp) ({ BUILD_BUG(); (typeof(pcp))0; })
#endif /* CONFIG_USE_X86_SEG_SUPPORT */
#define raw_cpu_add_1(pcp, val) percpu_add_op(1, , (pcp), val)
diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index f20e876..a94a857 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -519,7 +519,7 @@ static __always_inline unsigned long current_top_of_stack(void)
* entry trampoline.
*/
if (IS_ENABLED(CONFIG_USE_X86_SEG_SUPPORT))
- return const_pcpu_hot.top_of_stack;
+ return this_cpu_read_const(const_pcpu_hot.top_of_stack);
return this_cpu_read_stable(pcpu_hot.top_of_stack);
}
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-12-11 12:06 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-04 21:02 [PATCH -tip v3 1/3] x86/percpu: Fix "const_pcpu_hot" version generation failure Uros Bizjak
2023-12-04 21:02 ` [PATCH -tip v3 2/3] x86/traps: Use current_top_of_stack() helper in traps.c Uros Bizjak
2023-12-11 12:06 ` [tip: x86/percpu] " tip-bot2 for Uros Bizjak
2023-12-04 21:02 ` [PATCH -tip v3 3/3] x86/percpu: Avoid sparse warning with cast to named address space Uros Bizjak
2023-12-05 0:21 ` Luc Van Oostenryck
2023-12-11 12:06 ` [tip: x86/percpu] " tip-bot2 for Uros Bizjak
2023-12-11 12:06 ` [tip: x86/percpu] x86/percpu: Fix "const_pcpu_hot" version generation failure tip-bot2 for Uros Bizjak
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox