From: tip-bot for Ingo Molnar <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: luto@kernel.org, oleg@redhat.com, dvlasenk@redhat.com,
rostedt@goodmis.org, torvalds@linux-foundation.org,
ast@plumgrid.com, wad@chromium.org, tglx@linutronix.de,
hpa@zytor.com, linux-kernel@vger.kernel.org, bp@suse.de,
bp@alien8.de, mingo@kernel.org, luto@amacapital.net,
keescook@chromium.org, fweisbec@gmail.com
Subject: [tip:x86/asm] x86/asm/entry/64: Improve the THREAD_INFO() macro explanation
Date: Wed, 25 Mar 2015 02:12:27 -0700 [thread overview]
Message-ID: <tip-1ddc6f3c60d75a7577dd33bc441e309febe2fc76@git.kernel.org> (raw)
In-Reply-To: <20150324184311.GA14760@gmail.com>
Commit-ID: 1ddc6f3c60d75a7577dd33bc441e309febe2fc76
Gitweb: http://git.kernel.org/tip/1ddc6f3c60d75a7577dd33bc441e309febe2fc76
Author: Ingo Molnar <mingo@kernel.org>
AuthorDate: Tue, 24 Mar 2015 19:43:11 +0100
Committer: Ingo Molnar <mingo@kernel.org>
CommitDate: Tue, 24 Mar 2015 20:57:30 +0100
x86/asm/entry/64: Improve the THREAD_INFO() macro explanation
Explain the background, and add a real example.
Acked-by: Denys Vlasenko <dvlasenk@redhat.com>
Acked-by: Andy Lutomirski <luto@kernel.org>
Acked-by: Borislav Petkov <bp@suse.de>
Cc: Alexei Starovoitov <ast@plumgrid.com>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Will Drewry <wad@chromium.org>
Link: http://lkml.kernel.org/r/20150324184311.GA14760@gmail.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
arch/x86/include/asm/thread_info.h | 27 +++++++++++++++++++++++----
1 file changed, 23 insertions(+), 4 deletions(-)
diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
index ad0ee34..813dfbb 100644
--- a/arch/x86/include/asm/thread_info.h
+++ b/arch/x86/include/asm/thread_info.h
@@ -206,10 +206,29 @@ static inline unsigned long current_stack_pointer(void)
_ASM_SUB $(THREAD_SIZE),reg ;
/*
- * ASM operand which evaluates to thread_info address
- * if it is known that "reg" is exactly "off" bytes below stack top.
- * Example (fetch thread_info->fieldname):
- * mov TI_fieldname+THREAD_INFO(reg, off),%eax
+ * ASM operand which evaluates to a 'thread_info' address of
+ * the current task, if it is known that "reg" is exactly "off"
+ * bytes below the top of the stack currently.
+ *
+ * ( The kernel stack's size is known at build time, it is usually
+ * 2 or 4 pages, and the bottom of the kernel stack contains
+ * the thread_info structure. So to access the thread_info very
+ * quickly from assembly code we can calculate down from the
+ * top of the kernel stack to the bottom, using constant,
+ * build-time calculations only. )
+ *
+ * For example, to fetch the current thread_info->flags value into %eax
+ * on x86-64 defconfig kernels, in syscall entry code where RSP is
+ * currently at exactly SIZEOF_PTREGS bytes away from the top of the
+ * stack:
+ *
+ * mov TI_flags+THREAD_INFO(%rsp, SIZEOF_PTREGS), %eax
+ *
+ * will translate to:
+ *
+ * 8b 84 24 b8 c0 ff ff mov -0x3f48(%rsp), %eax
+ *
+ * which is below the current RSP by almost 16K.
*/
#define THREAD_INFO(reg, off) ((off)-THREAD_SIZE)(reg)
next prev parent reply other threads:[~2015-03-25 9:13 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-19 17:17 [PATCH 1/5] x86: change THREAD_INFO definition to not depend on KERNEL_STACK_OFFSET Denys Vlasenko
2015-03-19 17:17 ` [PATCH 2/5] x86: get rid of KERNEL_STACK_OFFSET Denys Vlasenko
2015-03-20 16:21 ` Borislav Petkov
2015-03-25 9:10 ` [tip:x86/asm] x86/asm/entry: Get " tip-bot for Denys Vlasenko
2015-03-19 17:17 ` [PATCH 3/5] x86/entry_64.S: use PUSH insns to build pt_regs on stack Denys Vlasenko
2015-03-20 16:35 ` Borislav Petkov
2015-03-25 9:11 ` [tip:x86/asm] x86/asm/entry/64: Use PUSH instructions " tip-bot for Denys Vlasenko
2015-03-19 17:17 ` [PATCH 4/5] x86/entry_64.S: get rid of FIXUP_TOP_OF_STACK/RESTORE_TOP_OF_STACK Denys Vlasenko
2015-03-20 16:38 ` Borislav Petkov
2015-03-25 9:11 ` [tip:x86/asm] x86/asm/entry/64: Get rid of the FIXUP_TOP_OF_STACK /RESTORE_TOP_OF_STACK macros tip-bot for Denys Vlasenko
2015-03-19 17:17 ` [PATCH 5/5] x86/entry_64.S: get rid of int_ret_from_sys_call_fixup Denys Vlasenko
2015-03-20 16:39 ` Borislav Petkov
2015-03-25 9:11 ` [tip:x86/asm] x86/asm/entry/64: Get " tip-bot for Denys Vlasenko
2015-03-20 10:30 ` [PATCH 1/5] x86: change THREAD_INFO definition to not depend on KERNEL_STACK_OFFSET Borislav Petkov
2015-03-20 22:27 ` Andy Lutomirski
2015-03-24 18:09 ` Ingo Molnar
2015-03-24 18:43 ` [PATCH] x86/asm/entry/64: Improve the THREAD_INFO() macro explanation Ingo Molnar
2015-03-24 18:50 ` Denys Vlasenko
2015-03-24 19:07 ` Andy Lutomirski
2015-03-24 19:20 ` Borislav Petkov
2015-03-25 9:12 ` tip-bot for Ingo Molnar [this message]
2015-03-24 18:44 ` [PATCH] x86/asm/entry/64: Merge the field offset into the THREAD_INFO() macro Ingo Molnar
2015-03-24 18:50 ` Denys Vlasenko
2015-03-24 19:29 ` Ingo Molnar
2015-03-24 19:34 ` Denys Vlasenko
2015-03-24 19:08 ` Andy Lutomirski
2015-03-25 9:12 ` [tip:x86/asm] " tip-bot for Ingo Molnar
2015-03-24 18:44 ` [PATCH] x86/asm/entry/64: Rename THREAD_INFO() to ASM_ASM_THREAD_INFO_MEMOP() Ingo Molnar
2015-03-24 19:24 ` Borislav Petkov
2015-03-24 19:34 ` Ingo Molnar
2015-03-25 9:13 ` [tip:x86/asm] x86/asm/entry/64: Rename THREAD_INFO() to ASM_THREAD_INFO() tip-bot for Ingo Molnar
2015-03-25 9:10 ` [tip:x86/asm] x86/asm/entry/64: Change the THREAD_INFO() definition to not depend on KERNEL_STACK_OFFSET tip-bot for Denys Vlasenko
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=tip-1ddc6f3c60d75a7577dd33bc441e309febe2fc76@git.kernel.org \
--to=tipbot@zytor.com \
--cc=ast@plumgrid.com \
--cc=bp@alien8.de \
--cc=bp@suse.de \
--cc=dvlasenk@redhat.com \
--cc=fweisbec@gmail.com \
--cc=hpa@zytor.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=luto@kernel.org \
--cc=mingo@kernel.org \
--cc=oleg@redhat.com \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=wad@chromium.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