* [PATCH 1/2] x86: stop using PER_CPU_VAR(kernel_stack)
@ 2015-03-21 20:44 Denys Vlasenko
2015-03-21 20:44 ` [PATCH 2/2] x86: remove unused kernel_stack per-cpu variable Denys Vlasenko
2015-03-23 14:18 ` [PATCH 1/2] x86: stop using PER_CPU_VAR(kernel_stack) Steven Rostedt
0 siblings, 2 replies; 11+ messages in thread
From: Denys Vlasenko @ 2015-03-21 20:44 UTC (permalink / raw)
To: Andy Lutomirski
Cc: Denys Vlasenko, Linus Torvalds, Steven Rostedt, Ingo Molnar,
Borislav Petkov, H. Peter Anvin, Oleg Nesterov,
Frederic Weisbecker, Alexei Starovoitov, Will Drewry, Kees Cook,
x86, linux-kernel
Instead of PER_CPU_VAR(kernel_stack), 64-bit code
can use PER_CPU_VAR(cpu_tss + TSS_sp0).
32-bit code switches to PER_CPU_VAR(cpu_current_top_of_stack),
which has the same value.
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
CC: Linus Torvalds <torvalds@linux-foundation.org>
CC: Steven Rostedt <rostedt@goodmis.org>
CC: Ingo Molnar <mingo@kernel.org>
CC: Borislav Petkov <bp@alien8.de>
CC: "H. Peter Anvin" <hpa@zytor.com>
CC: Andy Lutomirski <luto@amacapital.net>
CC: Oleg Nesterov <oleg@redhat.com>
CC: Frederic Weisbecker <fweisbec@gmail.com>
CC: Alexei Starovoitov <ast@plumgrid.com>
CC: Will Drewry <wad@chromium.org>
CC: Kees Cook <keescook@chromium.org>
CC: x86@kernel.org
CC: linux-kernel@vger.kernel.org
---
Andy, this patchset goes on top of PUSH conversion patches
arch/x86/ia32/ia32entry.S | 2 +-
arch/x86/include/asm/thread_info.h | 8 +++++++-
arch/x86/kernel/entry_64.S | 2 +-
arch/x86/xen/xen-asm_64.S | 5 +++--
4 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
index acbff3f..0a791c5 100644
--- a/arch/x86/ia32/ia32entry.S
+++ b/arch/x86/ia32/ia32entry.S
@@ -317,7 +317,7 @@ ENTRY(ia32_cstar_target)
SWAPGS_UNSAFE_STACK
movl %esp,%r8d
CFI_REGISTER rsp,r8
- movq PER_CPU_VAR(kernel_stack),%rsp
+ movq PER_CPU_VAR(cpu_tss + TSS_sp0),%rsp
/*
* No need to follow this irqs on/off section: the syscall
* disabled irqs and here we enable it straight after entry:
diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
index 89b814e..5be18d1 100644
--- a/arch/x86/include/asm/thread_info.h
+++ b/arch/x86/include/asm/thread_info.h
@@ -201,9 +201,15 @@ static inline unsigned long current_stack_pointer(void)
#else /* !__ASSEMBLY__ */
/* Load thread_info address into "reg" */
+#ifdef CONFIG_X86_32
#define GET_THREAD_INFO(reg) \
- _ASM_MOV PER_CPU_VAR(kernel_stack),reg ; \
+ _ASM_MOV PER_CPU_VAR(cpu_current_top_of_stack),reg ; \
_ASM_SUB $(THREAD_SIZE),reg ;
+#else
+#define GET_THREAD_INFO(reg) \
+ _ASM_MOV PER_CPU_VAR(cpu_tss + TSS_sp0),reg ; \
+ _ASM_SUB $(THREAD_SIZE),reg ;
+#endif
/*
* ASM operand which evaluates to thread_info address
diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
index 43e7333..e5b5283 100644
--- a/arch/x86/kernel/entry_64.S
+++ b/arch/x86/kernel/entry_64.S
@@ -220,7 +220,7 @@ ENTRY(system_call)
GLOBAL(system_call_after_swapgs)
movq %rsp,PER_CPU_VAR(rsp_scratch)
- movq PER_CPU_VAR(kernel_stack),%rsp
+ movq PER_CPU_VAR(cpu_tss + TSS_sp0),%rsp
/* Construct struct pt_regs on stack */
pushq_cfi $__USER_DS /* pt_regs->ss */
diff --git a/arch/x86/xen/xen-asm_64.S b/arch/x86/xen/xen-asm_64.S
index 985fc3e..acc49e0 100644
--- a/arch/x86/xen/xen-asm_64.S
+++ b/arch/x86/xen/xen-asm_64.S
@@ -15,6 +15,7 @@
#include <asm/percpu.h>
#include <asm/processor-flags.h>
#include <asm/segment.h>
+#include <asm/asm-offsets.h>
#include <xen/interface/xen.h>
@@ -69,7 +70,7 @@ ENTRY(xen_sysret64)
* still with the kernel gs, so we can easily switch back
*/
movq %rsp, PER_CPU_VAR(rsp_scratch)
- movq PER_CPU_VAR(kernel_stack), %rsp
+ movq PER_CPU_VAR(cpu_tss + TSS_sp0), %rsp
pushq $__USER_DS
pushq PER_CPU_VAR(rsp_scratch)
@@ -88,7 +89,7 @@ ENTRY(xen_sysret32)
* still with the kernel gs, so we can easily switch back
*/
movq %rsp, PER_CPU_VAR(rsp_scratch)
- movq PER_CPU_VAR(kernel_stack), %rsp
+ movq PER_CPU_VAR(cpu_tss + TSS_sp0), %rsp
pushq $__USER32_DS
pushq PER_CPU_VAR(rsp_scratch)
--
1.8.1.4
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 2/2] x86: remove unused kernel_stack per-cpu variable
2015-03-21 20:44 [PATCH 1/2] x86: stop using PER_CPU_VAR(kernel_stack) Denys Vlasenko
@ 2015-03-21 20:44 ` Denys Vlasenko
2015-03-23 14:18 ` [PATCH 1/2] x86: stop using PER_CPU_VAR(kernel_stack) Steven Rostedt
1 sibling, 0 replies; 11+ messages in thread
From: Denys Vlasenko @ 2015-03-21 20:44 UTC (permalink / raw)
To: Andy Lutomirski
Cc: Denys Vlasenko, Linus Torvalds, Steven Rostedt, Ingo Molnar,
Borislav Petkov, H. Peter Anvin, Oleg Nesterov,
Frederic Weisbecker, Alexei Starovoitov, Will Drewry, Kees Cook,
x86, linux-kernel
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
CC: Linus Torvalds <torvalds@linux-foundation.org>
CC: Steven Rostedt <rostedt@goodmis.org>
CC: Ingo Molnar <mingo@kernel.org>
CC: Borislav Petkov <bp@alien8.de>
CC: "H. Peter Anvin" <hpa@zytor.com>
CC: Andy Lutomirski <luto@amacapital.net>
CC: Oleg Nesterov <oleg@redhat.com>
CC: Frederic Weisbecker <fweisbec@gmail.com>
CC: Alexei Starovoitov <ast@plumgrid.com>
CC: Will Drewry <wad@chromium.org>
CC: Kees Cook <keescook@chromium.org>
CC: x86@kernel.org
CC: linux-kernel@vger.kernel.org
---
arch/x86/include/asm/thread_info.h | 2 --
arch/x86/kernel/cpu/common.c | 4 ----
arch/x86/kernel/process_32.c | 5 +----
arch/x86/kernel/process_64.c | 3 ---
arch/x86/kernel/smpboot.c | 2 --
arch/x86/xen/smp.c | 3 ---
6 files changed, 1 insertion(+), 18 deletions(-)
diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
index 5be18d1..89f7570 100644
--- a/arch/x86/include/asm/thread_info.h
+++ b/arch/x86/include/asm/thread_info.h
@@ -180,8 +180,6 @@ struct thread_info {
*/
#ifndef __ASSEMBLY__
-DECLARE_PER_CPU(unsigned long, kernel_stack);
-
static inline struct thread_info *current_thread_info(void)
{
return (struct thread_info *)(current_top_of_stack() - THREAD_SIZE);
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index 9461c83..4d52ef5 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -1135,10 +1135,6 @@ static __init int setup_disablecpuid(char *arg)
}
__setup("clearcpuid=", setup_disablecpuid);
-DEFINE_PER_CPU(unsigned long, kernel_stack) =
- (unsigned long)&init_thread_union + THREAD_SIZE;
-EXPORT_PER_CPU_SYMBOL(kernel_stack);
-
#ifdef CONFIG_X86_64
struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
index 5a4c2f8..1a7bf8f 100644
--- a/arch/x86/kernel/process_32.c
+++ b/arch/x86/kernel/process_32.c
@@ -306,13 +306,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
arch_end_context_switch(next_p);
/*
- * Reload esp0, kernel_stack, and current_top_of_stack. This changes
+ * Reload esp0 and cpu_current_top_of_stack. This changes
* current_thread_info().
*/
load_sp0(tss, next);
- this_cpu_write(kernel_stack,
- (unsigned long)task_stack_page(next_p) +
- THREAD_SIZE);
this_cpu_write(cpu_current_top_of_stack,
(unsigned long)task_stack_page(next_p) +
THREAD_SIZE);
diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
index db49063..ae3dcd8 100644
--- a/arch/x86/kernel/process_64.c
+++ b/arch/x86/kernel/process_64.c
@@ -408,9 +408,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
/* Reload esp0 and ss1. This changes current_thread_info(). */
load_sp0(tss, next);
- this_cpu_write(kernel_stack,
- (unsigned long)task_stack_page(next_p) + THREAD_SIZE);
-
/*
* Now maybe reload the debug registers and handle I/O bitmaps
*/
diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
index 7b20ffd..c9647f4 100644
--- a/arch/x86/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot.c
@@ -812,8 +812,6 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
clear_tsk_thread_flag(idle, TIF_FORK);
initial_gs = per_cpu_offset(cpu);
#endif
- per_cpu(kernel_stack, cpu) =
- (unsigned long)task_stack_page(idle) + THREAD_SIZE;
early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
initial_code = (unsigned long)start_secondary;
stack_start = idle->thread.sp;
diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
index 765b768..a2c7e8b 100644
--- a/arch/x86/xen/smp.c
+++ b/arch/x86/xen/smp.c
@@ -451,9 +451,6 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
#else
clear_tsk_thread_flag(idle, TIF_FORK);
#endif
- per_cpu(kernel_stack, cpu) =
- (unsigned long)task_stack_page(idle) + THREAD_SIZE;
-
xen_setup_runstate_info(cpu);
xen_setup_timer(cpu);
xen_init_lock_cpu(cpu);
--
1.8.1.4
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 1/2] x86: stop using PER_CPU_VAR(kernel_stack)
2015-03-21 20:44 [PATCH 1/2] x86: stop using PER_CPU_VAR(kernel_stack) Denys Vlasenko
2015-03-21 20:44 ` [PATCH 2/2] x86: remove unused kernel_stack per-cpu variable Denys Vlasenko
@ 2015-03-23 14:18 ` Steven Rostedt
2015-03-23 17:10 ` Denys Vlasenko
1 sibling, 1 reply; 11+ messages in thread
From: Steven Rostedt @ 2015-03-23 14:18 UTC (permalink / raw)
To: Denys Vlasenko
Cc: Andy Lutomirski, Linus Torvalds, Ingo Molnar, Borislav Petkov,
H. Peter Anvin, Oleg Nesterov, Frederic Weisbecker,
Alexei Starovoitov, Will Drewry, Kees Cook, x86, linux-kernel
On Sat, 21 Mar 2015 21:44:37 +0100
Denys Vlasenko <dvlasenk@redhat.com> wrote:
> Instead of PER_CPU_VAR(kernel_stack), 64-bit code
> can use PER_CPU_VAR(cpu_tss + TSS_sp0).
The change log here is lacking an answer to "why". It only states what
it does. What's wrong with using kernel_stack? The change log should
explicitly state that. I have no idea why this patch is needed.
-- Steve
>
> 32-bit code switches to PER_CPU_VAR(cpu_current_top_of_stack),
> which has the same value.
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/2] x86: stop using PER_CPU_VAR(kernel_stack)
2015-03-23 14:18 ` [PATCH 1/2] x86: stop using PER_CPU_VAR(kernel_stack) Steven Rostedt
@ 2015-03-23 17:10 ` Denys Vlasenko
2015-03-23 17:14 ` Borislav Petkov
2015-03-23 17:28 ` Steven Rostedt
0 siblings, 2 replies; 11+ messages in thread
From: Denys Vlasenko @ 2015-03-23 17:10 UTC (permalink / raw)
To: Steven Rostedt
Cc: Andy Lutomirski, Linus Torvalds, Ingo Molnar, Borislav Petkov,
H. Peter Anvin, Oleg Nesterov, Frederic Weisbecker,
Alexei Starovoitov, Will Drewry, Kees Cook, x86, linux-kernel
On 03/23/2015 03:18 PM, Steven Rostedt wrote:
> On Sat, 21 Mar 2015 21:44:37 +0100
> Denys Vlasenko <dvlasenk@redhat.com> wrote:
>
>> Instead of PER_CPU_VAR(kernel_stack), 64-bit code
>> can use PER_CPU_VAR(cpu_tss + TSS_sp0).
>
> The change log here is lacking an answer to "why". It only states what
> it does. What's wrong with using kernel_stack? The change log should
> explicitly state that. I have no idea why this patch is needed.
Sorry. The reason is:
We want to get rid of kernel_stack, since it is redundant:
in 64-bits, PER_CPU_VAR(cpu_tss + TSS_sp0) can be used instead,
in 32-bits, PER_CPU_VAR(cpu_current_top_of_stack) can be used instead.
Patch 2/2 in the same series removes kernel_stack.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/2] x86: stop using PER_CPU_VAR(kernel_stack)
2015-03-23 17:10 ` Denys Vlasenko
@ 2015-03-23 17:14 ` Borislav Petkov
2015-03-23 17:28 ` Steven Rostedt
1 sibling, 0 replies; 11+ messages in thread
From: Borislav Petkov @ 2015-03-23 17:14 UTC (permalink / raw)
To: Denys Vlasenko
Cc: Steven Rostedt, Andy Lutomirski, Linus Torvalds, Ingo Molnar,
H. Peter Anvin, Oleg Nesterov, Frederic Weisbecker,
Alexei Starovoitov, Will Drewry, Kees Cook, x86, linux-kernel
On Mon, Mar 23, 2015 at 06:10:01PM +0100, Denys Vlasenko wrote:
> We want to get rid of kernel_stack, since it is redundant:
> in 64-bits, PER_CPU_VAR(cpu_tss + TSS_sp0) can be used instead,
> in 32-bits, PER_CPU_VAR(cpu_current_top_of_stack) can be used instead.
We probably should have a macro unifying those on both bitness.
Especially 64-bit is really non-telling - I can't really deduce from
"cpu_tss + TSS_sp0" that it is the kernel stack ptr.
Thanks.
--
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.
--
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/2] x86: stop using PER_CPU_VAR(kernel_stack)
2015-03-23 17:10 ` Denys Vlasenko
2015-03-23 17:14 ` Borislav Petkov
@ 2015-03-23 17:28 ` Steven Rostedt
2015-03-23 17:38 ` Denys Vlasenko
1 sibling, 1 reply; 11+ messages in thread
From: Steven Rostedt @ 2015-03-23 17:28 UTC (permalink / raw)
To: Denys Vlasenko
Cc: Andy Lutomirski, Linus Torvalds, Ingo Molnar, Borislav Petkov,
H. Peter Anvin, Oleg Nesterov, Frederic Weisbecker,
Alexei Starovoitov, Will Drewry, Kees Cook, x86, linux-kernel
On Mon, 23 Mar 2015 18:10:01 +0100
Denys Vlasenko <dvlasenk@redhat.com> wrote:
> On 03/23/2015 03:18 PM, Steven Rostedt wrote:
> > On Sat, 21 Mar 2015 21:44:37 +0100
> > Denys Vlasenko <dvlasenk@redhat.com> wrote:
> >
> >> Instead of PER_CPU_VAR(kernel_stack), 64-bit code
> >> can use PER_CPU_VAR(cpu_tss + TSS_sp0).
> >
> > The change log here is lacking an answer to "why". It only states what
> > it does. What's wrong with using kernel_stack? The change log should
> > explicitly state that. I have no idea why this patch is needed.
>
> Sorry. The reason is:
>
> We want to get rid of kernel_stack, since it is redundant:
> in 64-bits, PER_CPU_VAR(cpu_tss + TSS_sp0) can be used instead,
> in 32-bits, PER_CPU_VAR(cpu_current_top_of_stack) can be used instead.
Can we do a:
#define cpu_current_top_of_stack (cpu_tss + TSS_sp0)
in 64-bit, and make it consistent with i386.
"cpu_tss + TSS_sp0" is rather meaningless. "kernel_stack" or
"top_of_stack" is at least informative.
>
> Patch 2/2 in the same series removes kernel_stack.
Understood, but each commit's change log should be able to stand on its
own.
-- Steve
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/2] x86: stop using PER_CPU_VAR(kernel_stack)
2015-03-23 17:28 ` Steven Rostedt
@ 2015-03-23 17:38 ` Denys Vlasenko
2015-03-23 17:45 ` Steven Rostedt
0 siblings, 1 reply; 11+ messages in thread
From: Denys Vlasenko @ 2015-03-23 17:38 UTC (permalink / raw)
To: Steven Rostedt
Cc: Andy Lutomirski, Linus Torvalds, Ingo Molnar, Borislav Petkov,
H. Peter Anvin, Oleg Nesterov, Frederic Weisbecker,
Alexei Starovoitov, Will Drewry, Kees Cook, x86, linux-kernel
On 03/23/2015 06:28 PM, Steven Rostedt wrote:
> On Mon, 23 Mar 2015 18:10:01 +0100
> Denys Vlasenko <dvlasenk@redhat.com> wrote:
>
>> On 03/23/2015 03:18 PM, Steven Rostedt wrote:
>>> On Sat, 21 Mar 2015 21:44:37 +0100
>>> Denys Vlasenko <dvlasenk@redhat.com> wrote:
>>>
>>>> Instead of PER_CPU_VAR(kernel_stack), 64-bit code
>>>> can use PER_CPU_VAR(cpu_tss + TSS_sp0).
>>>
>>> The change log here is lacking an answer to "why". It only states what
>>> it does. What's wrong with using kernel_stack? The change log should
>>> explicitly state that. I have no idea why this patch is needed.
>>
>> Sorry. The reason is:
>>
>> We want to get rid of kernel_stack, since it is redundant:
>> in 64-bits, PER_CPU_VAR(cpu_tss + TSS_sp0) can be used instead,
>> in 32-bits, PER_CPU_VAR(cpu_current_top_of_stack) can be used instead.
>
> Can we do a:
>
> #define cpu_current_top_of_stack (cpu_tss + TSS_sp0)
We already do something similar:
static inline unsigned long current_top_of_stack(void)
{
#ifdef CONFIG_X86_64
return this_cpu_read_stable(cpu_tss.x86_tss.sp0);
#else
/* sp0 on x86_32 is special in and around vm86 mode. */
return this_cpu_read_stable(cpu_current_top_of_stack);
#endif
}
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/2] x86: stop using PER_CPU_VAR(kernel_stack)
2015-03-23 17:38 ` Denys Vlasenko
@ 2015-03-23 17:45 ` Steven Rostedt
2015-03-23 17:51 ` Denys Vlasenko
0 siblings, 1 reply; 11+ messages in thread
From: Steven Rostedt @ 2015-03-23 17:45 UTC (permalink / raw)
To: Denys Vlasenko
Cc: Andy Lutomirski, Linus Torvalds, Ingo Molnar, Borislav Petkov,
H. Peter Anvin, Oleg Nesterov, Frederic Weisbecker,
Alexei Starovoitov, Will Drewry, Kees Cook, x86, linux-kernel
On Mon, 23 Mar 2015 18:38:09 +0100
Denys Vlasenko <dvlasenk@redhat.com> wrote:
> > Can we do a:
> >
> > #define cpu_current_top_of_stack (cpu_tss + TSS_sp0)
>
> We already do something similar:
>
> static inline unsigned long current_top_of_stack(void)
> {
> #ifdef CONFIG_X86_64
> return this_cpu_read_stable(cpu_tss.x86_tss.sp0);
> #else
> /* sp0 on x86_32 is special in and around vm86 mode. */
> return this_cpu_read_stable(cpu_current_top_of_stack);
> #endif
> }
So can we then have:
#ifdef __ASSEMBLY__
# define cpu_current_top_of_stack (cpu_tss + TSS_sp0)
#else
# define cpu_current_top_of_stack (cpu_tss.x86_tss.sp0)
#endif
And get rid of that if statement in the static inline?
-- Steve
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/2] x86: stop using PER_CPU_VAR(kernel_stack)
2015-03-23 17:45 ` Steven Rostedt
@ 2015-03-23 17:51 ` Denys Vlasenko
2015-03-23 18:27 ` Andy Lutomirski
0 siblings, 1 reply; 11+ messages in thread
From: Denys Vlasenko @ 2015-03-23 17:51 UTC (permalink / raw)
To: Steven Rostedt
Cc: Andy Lutomirski, Linus Torvalds, Ingo Molnar, Borislav Petkov,
H. Peter Anvin, Oleg Nesterov, Frederic Weisbecker,
Alexei Starovoitov, Will Drewry, Kees Cook, x86, linux-kernel
On 03/23/2015 06:45 PM, Steven Rostedt wrote:
> On Mon, 23 Mar 2015 18:38:09 +0100
> Denys Vlasenko <dvlasenk@redhat.com> wrote:
>
>>> Can we do a:
>>>
>>> #define cpu_current_top_of_stack (cpu_tss + TSS_sp0)
>>
>> We already do something similar:
>>
>> static inline unsigned long current_top_of_stack(void)
>> {
>> #ifdef CONFIG_X86_64
>> return this_cpu_read_stable(cpu_tss.x86_tss.sp0);
>> #else
>> /* sp0 on x86_32 is special in and around vm86 mode. */
>> return this_cpu_read_stable(cpu_current_top_of_stack);
>> #endif
>> }
>
> So can we then have:
>
> #ifdef __ASSEMBLY__
> # define cpu_current_top_of_stack (cpu_tss + TSS_sp0)
> #else
> # define cpu_current_top_of_stack (cpu_tss.x86_tss.sp0)
> #endif
>
> And get rid of that if statement in the static inline?
I prefer less macro indirection in assembly code,
but I won't object too strongly if this would be done.
It's up to other x86 maintainers to agree - I'm touching
the code recently changed by Andy, he may see the way forward
somewhat differently.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/2] x86: stop using PER_CPU_VAR(kernel_stack)
2015-03-23 17:51 ` Denys Vlasenko
@ 2015-03-23 18:27 ` Andy Lutomirski
2015-04-24 15:29 ` Denys Vlasenko
0 siblings, 1 reply; 11+ messages in thread
From: Andy Lutomirski @ 2015-03-23 18:27 UTC (permalink / raw)
To: Denys Vlasenko
Cc: Steven Rostedt, Linus Torvalds, Ingo Molnar, Borislav Petkov,
H. Peter Anvin, Oleg Nesterov, Frederic Weisbecker,
Alexei Starovoitov, Will Drewry, Kees Cook, X86 ML,
linux-kernel@vger.kernel.org
On Mon, Mar 23, 2015 at 10:51 AM, Denys Vlasenko <dvlasenk@redhat.com> wrote:
> On 03/23/2015 06:45 PM, Steven Rostedt wrote:
>> On Mon, 23 Mar 2015 18:38:09 +0100
>> Denys Vlasenko <dvlasenk@redhat.com> wrote:
>>
>>>> Can we do a:
>>>>
>>>> #define cpu_current_top_of_stack (cpu_tss + TSS_sp0)
>>>
>>> We already do something similar:
>>>
>>> static inline unsigned long current_top_of_stack(void)
>>> {
>>> #ifdef CONFIG_X86_64
>>> return this_cpu_read_stable(cpu_tss.x86_tss.sp0);
>>> #else
>>> /* sp0 on x86_32 is special in and around vm86 mode. */
>>> return this_cpu_read_stable(cpu_current_top_of_stack);
>>> #endif
>>> }
>>
>> So can we then have:
>>
>> #ifdef __ASSEMBLY__
>> # define cpu_current_top_of_stack (cpu_tss + TSS_sp0)
>> #else
>> # define cpu_current_top_of_stack (cpu_tss.x86_tss.sp0)
>> #endif
>>
>> And get rid of that if statement in the static inline?
>
> I prefer less macro indirection in assembly code,
> but I won't object too strongly if this would be done.
>
> It's up to other x86 maintainers to agree - I'm touching
> the code recently changed by Andy, he may see the way forward
> somewhat differently.
>
I kind of like Steven's idea. Although.. shouldn't we go all the way and do:
#ifdef __ASSEMBLY__
#ifdef CONFIG_X86_64
#define cpu_current_top_of_stack %gs:(cpu_tss + TSS_sp0)
#else
#define cpu_current_top_of_stack %gs:(current_top_of_stack)
#endif
#endif
and just not have a macro for non-asm, since we already have the inline?
But maybe keeping the %gs reference explicit in the asm is better.
--Andy
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/2] x86: stop using PER_CPU_VAR(kernel_stack)
2015-03-23 18:27 ` Andy Lutomirski
@ 2015-04-24 15:29 ` Denys Vlasenko
0 siblings, 0 replies; 11+ messages in thread
From: Denys Vlasenko @ 2015-04-24 15:29 UTC (permalink / raw)
To: Andy Lutomirski
Cc: Steven Rostedt, Linus Torvalds, Ingo Molnar, Borislav Petkov,
H. Peter Anvin, Oleg Nesterov, Frederic Weisbecker,
Alexei Starovoitov, Will Drewry, Kees Cook, X86 ML,
linux-kernel@vger.kernel.org
On 03/23/2015 07:27 PM, Andy Lutomirski wrote:
> On Mon, Mar 23, 2015 at 10:51 AM, Denys Vlasenko <dvlasenk@redhat.com> wrote:
>> On 03/23/2015 06:45 PM, Steven Rostedt wrote:
>>> On Mon, 23 Mar 2015 18:38:09 +0100
>>> Denys Vlasenko <dvlasenk@redhat.com> wrote:
>>>
>>>>> Can we do a:
>>>>>
>>>>> #define cpu_current_top_of_stack (cpu_tss + TSS_sp0)
>>>>
>>>> We already do something similar:
>>>>
>>>> static inline unsigned long current_top_of_stack(void)
>>>> {
>>>> #ifdef CONFIG_X86_64
>>>> return this_cpu_read_stable(cpu_tss.x86_tss.sp0);
>>>> #else
>>>> /* sp0 on x86_32 is special in and around vm86 mode. */
>>>> return this_cpu_read_stable(cpu_current_top_of_stack);
>>>> #endif
>>>> }
>>>
>>> So can we then have:
>>>
>>> #ifdef __ASSEMBLY__
>>> # define cpu_current_top_of_stack (cpu_tss + TSS_sp0)
>>> #else
>>> # define cpu_current_top_of_stack (cpu_tss.x86_tss.sp0)
>>> #endif
>>>
>>> And get rid of that if statement in the static inline?
>>
>> I prefer less macro indirection in assembly code,
>> but I won't object too strongly if this would be done.
>>
>> It's up to other x86 maintainers to agree - I'm touching
>> the code recently changed by Andy, he may see the way forward
>> somewhat differently.
>>
>
> I kind of like Steven's idea. Although.. shouldn't we go all the way and do:
>
> #ifdef __ASSEMBLY__
> #ifdef CONFIG_X86_64
> #define cpu_current_top_of_stack %gs:(cpu_tss + TSS_sp0)
> #else
> #define cpu_current_top_of_stack %gs:(current_top_of_stack)
> #endif
> #endif
Which .h file do you propose to have this in? processor.h is not suitable,
it is not __ASSEMBLY__-fied.
I'm looking at a place where to put it.
For example, one of the users of the (cpu_tss + TSS_sp0) expression,
xen-asm_64.S, has only these few includes:
#include <asm/errno.h>
#include <asm/percpu.h>
#include <asm/processor-flags.h>
#include <asm/segment.h>
#include <asm/asm-offsets.h>
#include <xen/interface/xen.h>
#include "xen-asm.h"
None seems suitable. I will probably have to include thread_info.h too,
and put the define there. Ugly ugly ugly.
I'll resend a patchset where a new patch #3 attempts to do this
"unification". I personally don't see it as a clear improvement.
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2015-04-24 15:30 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-21 20:44 [PATCH 1/2] x86: stop using PER_CPU_VAR(kernel_stack) Denys Vlasenko
2015-03-21 20:44 ` [PATCH 2/2] x86: remove unused kernel_stack per-cpu variable Denys Vlasenko
2015-03-23 14:18 ` [PATCH 1/2] x86: stop using PER_CPU_VAR(kernel_stack) Steven Rostedt
2015-03-23 17:10 ` Denys Vlasenko
2015-03-23 17:14 ` Borislav Petkov
2015-03-23 17:28 ` Steven Rostedt
2015-03-23 17:38 ` Denys Vlasenko
2015-03-23 17:45 ` Steven Rostedt
2015-03-23 17:51 ` Denys Vlasenko
2015-03-23 18:27 ` Andy Lutomirski
2015-04-24 15:29 ` Denys Vlasenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).