From: Denys Vlasenko <dvlasenk@redhat.com>
To: Andy Lutomirski <luto@amacapital.net>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
Steven Rostedt <rostedt@goodmis.org>,
Ingo Molnar <mingo@kernel.org>, Borislav Petkov <bp@alien8.de>,
"H. Peter Anvin" <hpa@zytor.com>, Oleg Nesterov <oleg@redhat.com>,
Frederic Weisbecker <fweisbec@gmail.com>,
Alexei Starovoitov <ast@plumgrid.com>,
Will Drewry <wad@chromium.org>, Kees Cook <keescook@chromium.org>,
X86 ML <x86@kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/3] x86: get rid of KERNEL_STACK_OFFSET
Date: Thu, 19 Mar 2015 16:47:20 +0100 [thread overview]
Message-ID: <550AEF88.7020209@redhat.com> (raw)
In-Reply-To: <CALCETrWXU9ymWxcS3Vsr0DJ20kagpWkNUOMp_2L_7t8MdMWdxQ@mail.gmail.com>
On 03/19/2015 04:43 PM, Andy Lutomirski wrote:
> On Thu, Mar 19, 2015 at 8:28 AM, Denys Vlasenko <dvlasenk@redhat.com> wrote:
>> On 03/18/2015 09:54 PM, Andy Lutomirski wrote:
>>> On Wed, Mar 18, 2015 at 12:47 PM, Denys Vlasenko <dvlasenk@redhat.com> wrote:
>>>> PER_CPU_VAR(kernel_stack) was set up in a way where it points
>>>> five stack slots below the top of stack.
>>>>
>>>> Presumably, it was done to avoid one "sub $5*8,%rsp"
>>>> in syscall/sysenter code paths, where iret frame needs to be
>>>> created by hand.
>>>>
>>>> Ironically, none of them benefits from this optimization,
>>>> since all of them need to allocate additional data on stack
>>>> (struct pt_regs), so they still have to perform subtraction.
>>>>
>>>> This patch eliminates KERNEL_STACK_OFFSET.
>>>>
>>>> PER_CPU_VAR(kernel_stack) now points directly to top of stack.
>>>> pt_regs allocations are adjusted to allocate iret frame as well.
>>>> Hopefully we can merge it later with 32-bit specific
>>>> PER_CPU_VAR(cpu_current_top_of_stack) variable...
>>>>
>>>> Semi-mysterious expressions THREAD_INFO(%rsp,RIP) - "why RIP??"
>>>> are now replaced by more logical THREAD_INFO(%rsp,SIZEOF_PTREGS) -
>>>> "calculate thread_info's address using information that
>>>> rsp is SIZEOF_PTREGS bytes below the stack top".
>>>>
>>>> Net result in generated code is that constants in several insns
>>>> are changed.
>>>>
>>>> This change is necessary for changing struct pt_regs creation
>>>> in SYSCALL64 code path from MOV to PUSH instructions.
>>>>
>>>
>>> Would it be reasonable to break this up into two pieces: first, remove
>>> KERNEL_STACK_OFFSET from THREAD_INFO and related macros (i.e. make
>>> them relative to current_top_of_stack instead)
>>
>> PER_CPU(cpu_current_top_of_stack) exists only in 32 bits.
>> Can't use it in 64-bit code.
>>
>> PER_CPU(cpu_current_top_of_stack) becomes equal
>> to PER_CPU(kernel_stack) only after this patch.
>
> You could have a #define that gives the top of the stack from asm, though.
>
>>
>> I plan to clean up PER_CPU(cpu_current_top_of_stack)/
>> PER_CPU(kernel_stack)/PER_CPU(tss->sp0) mess
>> on top of my patches.
>>
>> First: this seems to be the easier way.
>
> It's probably easier, but it's harder to review since you're making
> two change at once (changing the rsp loaded during syscall and
> changing the way that GET_THREAD_INFO works).
I will split off the THREAD_INFO() change.
prev parent reply other threads:[~2015-03-19 15:47 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-18 19:47 [PATCH 1/3] x86: get rid of KERNEL_STACK_OFFSET Denys Vlasenko
2015-03-18 19:47 ` [PATCH 2/3] x86: entry_64.S: use PUSH insns to build pt_regs on stack Denys Vlasenko
2015-03-18 21:01 ` Andy Lutomirski
2015-03-18 21:12 ` Denys Vlasenko
2015-03-18 21:22 ` Andy Lutomirski
2015-03-18 21:32 ` Denys Vlasenko
2015-03-18 21:42 ` Andy Lutomirski
2015-03-18 19:47 ` [PATCH 3/3] x86: get rid of FIXUP_TOP_OF_STACK/RESTORE_TOP_OF_STACK Denys Vlasenko
2015-03-18 21:02 ` Andy Lutomirski
2015-03-18 20:47 ` [PATCH 1/3] x86: get rid of KERNEL_STACK_OFFSET Borislav Petkov
2015-03-18 20:54 ` Andy Lutomirski
2015-03-19 15:28 ` Denys Vlasenko
2015-03-19 15:43 ` Andy Lutomirski
2015-03-19 15:47 ` Denys Vlasenko [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=550AEF88.7020209@redhat.com \
--to=dvlasenk@redhat.com \
--cc=ast@plumgrid.com \
--cc=bp@alien8.de \
--cc=fweisbec@gmail.com \
--cc=hpa@zytor.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=mingo@kernel.org \
--cc=oleg@redhat.com \
--cc=rostedt@goodmis.org \
--cc=torvalds@linux-foundation.org \
--cc=wad@chromium.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox