From: Lai Jiangshan <jiangshanlai@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: Lai Jiangshan <laijs@linux.alibaba.com>,
Andy Lutomirski <luto@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
Joerg Roedel <jroedel@suse.de>,
Youquan Song <youquan.song@intel.com>,
Tony Luck <tony.luck@intel.com>, Juergen Gross <jgross@suse.com>,
"Peter Zijlstra (Intel)" <peterz@infradead.org>
Subject: [PATCH 17/24] x86/entry: Introduce struct ist_regs
Date: Wed, 1 Sep 2021 01:50:18 +0800 [thread overview]
Message-ID: <20210831175025.27570-18-jiangshanlai@gmail.com> (raw)
In-Reply-To: <20210831175025.27570-1-jiangshanlai@gmail.com>
From: Lai Jiangshan <laijs@linux.alibaba.com>
struct ist_regs is the upmost stack frame for IST interrupt, it
consists of struct pt_regs and other fields which will be added in
later patch.
Make vc_switch_off_ist() take ist_regs as its argument and it will switch
the whole ist_regs if needed.
Make the frame before calling paranoid_entry() and paranoid_exit() be
struct ist_regs.
This patch is prepared for converting paranoid_entry() and paranoid_exit()
into C code which will need the additinal fields to store the results in
paranoid_entry() and to use them in paranoid_exit().
The C interrupt handlers don't use struct ist_regs due to they don't need
the additional fields in the struct ist_regs, and they still use pt_regs.
No functional change intended and IST_pt_reg is still 0.
Signed-off-by: Lai Jiangshan <laijs@linux.alibaba.com>
---
arch/x86/entry/entry_64.S | 37 ++++++++++++++++++--------------
arch/x86/entry/traps.c | 16 +++++++-------
arch/x86/include/asm/traps.h | 10 ++++++++-
arch/x86/kernel/asm-offsets_64.c | 2 ++
4 files changed, 40 insertions(+), 25 deletions(-)
diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S
index e968074046c3..1ae10ca351f4 100644
--- a/arch/x86/entry/entry_64.S
+++ b/arch/x86/entry/entry_64.S
@@ -431,13 +431,14 @@ SYM_CODE_START(\asmsym)
/* paranoid_entry returns GS information for paranoid_exit in EBX. */
call paranoid_entry
- UNWIND_HINT_REGS
+ UNWIND_HINT_REGS offset=IST_pt_regs
- movq %rsp, %rdi /* pt_regs pointer */
+ leaq IST_pt_regs(%rsp), %rdi /* pt_regs pointer */
call \cfunc
call paranoid_exit
+ addq $IST_pt_regs, %rsp /* put %rsp back to pt_regs */
jmp restore_regs_and_return_to_kernel
/* Switch to the regular task stack and use the noist entry point */
@@ -488,7 +489,7 @@ SYM_CODE_START(\asmsym)
*/
call paranoid_entry
- UNWIND_HINT_REGS
+ UNWIND_HINT_REGS offset=IST_pt_regs
/*
* Switch off the IST stack to make it free for nested exceptions. The
@@ -496,17 +497,17 @@ SYM_CODE_START(\asmsym)
* stack if it is safe to do so. If not it switches to the VC fall-back
* stack.
*/
- movq %rsp, %rdi /* pt_regs pointer */
+ movq %rsp, %rdi /* ist_regs pointer */
call vc_switch_off_ist
movq %rax, %rsp /* Switch to new stack */
- UNWIND_HINT_REGS
+ UNWIND_HINT_REGS offset=IST_pt_regs
- /* Update pt_regs */
- movq ORIG_RAX(%rsp), %rsi /* get error code into 2nd argument*/
- movq $-1, ORIG_RAX(%rsp) /* no syscall to restart */
+ leaq IST_pt_regs(%rsp), %rdi /* pt_regs pointer */
- movq %rsp, %rdi /* pt_regs pointer */
+ /* Update pt_regs */
+ movq ORIG_RAX(%rdi), %rsi /* get error code into 2nd argument*/
+ movq $-1, ORIG_RAX(%rdi) /* no syscall to restart */
call kernel_\cfunc
@@ -516,6 +517,7 @@ SYM_CODE_START(\asmsym)
* so it is definitely mapped even with PTI enabled.
*/
call paranoid_exit
+ addq $IST_pt_regs, %rsp /* put %rsp back to pt_regs */
jmp restore_regs_and_return_to_kernel
/* Switch to the regular task stack */
@@ -539,14 +541,15 @@ SYM_CODE_START(\asmsym)
/* paranoid_entry returns GS information for paranoid_exit in EBX. */
call paranoid_entry
- UNWIND_HINT_REGS
+ UNWIND_HINT_REGS offset=IST_pt_regs
- movq %rsp, %rdi /* pt_regs pointer into first argument */
- movq ORIG_RAX(%rsp), %rsi /* get error code into 2nd argument*/
- movq $-1, ORIG_RAX(%rsp) /* no syscall to restart */
+ leaq IST_pt_regs(%rsp), %rdi /* pt_regs pointer into first argument */
+ movq ORIG_RAX(%rdi), %rsi /* get error code into 2nd argument*/
+ movq $-1, ORIG_RAX(%rdi) /* no syscall to restart */
call \cfunc
call paranoid_exit
+ addq $IST_pt_regs, %rsp /* put %rsp back to pt_regs */
jmp restore_regs_and_return_to_kernel
_ASM_NOKPROBE(\asmsym)
@@ -852,8 +855,9 @@ SYM_CODE_START_LOCAL(paranoid_entry)
PUSH_AND_CLEAR_REGS skip_rdi=1
movq RDI(%rsp), %rsi /* temporarily store the return address in %rsi */
movq %rdi, RDI(%rsp) /* put %rdi onto pt_regs */
+ subq $IST_pt_regs, %rsp /* reserve room for ist_regs */
pushq %rsi /* put the return address onto the stack */
- ENCODE_FRAME_POINTER 8
+ ENCODE_FRAME_POINTER 8+IST_pt_regs
/*
* Always stash CR3 in %r14. This value will be restored,
@@ -1294,9 +1298,9 @@ end_repeat_nmi:
* Use paranoid_entry to handle SWAPGS and CR3.
*/
call paranoid_entry
- UNWIND_HINT_REGS
+ UNWIND_HINT_REGS offset=IST_pt_regs
- movq %rsp, %rdi
+ leaq IST_pt_regs(%rsp), %rdi /* pt_regs pointer */
movq $-1, %rsi
call exc_nmi
@@ -1305,6 +1309,7 @@ end_repeat_nmi:
* restore_regs_and_return_to_kernel as we must handle nested NMI.
*/
call paranoid_exit
+ addq $IST_pt_regs, %rsp /* put %rsp back to pt_regs */
POP_REGS
diff --git a/arch/x86/entry/traps.c b/arch/x86/entry/traps.c
index 40722a2f61ae..da55565d43ef 100644
--- a/arch/x86/entry/traps.c
+++ b/arch/x86/entry/traps.c
@@ -693,17 +693,17 @@ struct pt_regs *sync_regs(struct pt_regs *eregs)
}
#ifdef CONFIG_AMD_MEM_ENCRYPT
-asmlinkage __visible noinstr struct pt_regs *vc_switch_off_ist(struct pt_regs *regs)
+asmlinkage __visible noinstr struct ist_regs *vc_switch_off_ist(struct ist_regs *ist)
{
unsigned long sp, *stack;
struct stack_info info;
- struct pt_regs *regs_ret;
+ struct ist_regs *ist_ret;
/*
* In the SYSCALL entry path the RSP value comes from user-space - don't
* trust it and switch to the current kernel stack
*/
- if (ip_within_syscall_gap(regs)) {
+ if (ip_within_syscall_gap(&ist->regs)) {
sp = this_cpu_read(cpu_current_top_of_stack);
goto sync;
}
@@ -713,7 +713,7 @@ asmlinkage __visible noinstr struct pt_regs *vc_switch_off_ist(struct pt_regs *r
* happened from a safe stack. Not safe are the entry or unknown stacks,
* use the fall-back stack instead in this case.
*/
- sp = regs->sp;
+ sp = ist->regs.sp;
stack = (unsigned long *)sp;
if (!get_stack_info_noinstr(stack, current, &info) || info.type == STACK_TYPE_ENTRY ||
@@ -726,12 +726,12 @@ asmlinkage __visible noinstr struct pt_regs *vc_switch_off_ist(struct pt_regs *r
* IST stack. The code below only copies pt_regs, the real switch happens
* in assembly code.
*/
- sp = ALIGN_DOWN(sp, 8) - sizeof(*regs_ret);
+ sp = ALIGN_DOWN(sp, 8) - sizeof(*ist_ret);
- regs_ret = (struct pt_regs *)sp;
- *regs_ret = *regs;
+ ist_ret = (struct ist_regs *)sp;
+ *ist_ret = *ist;
- return regs_ret;
+ return ist_ret;
}
#endif
diff --git a/arch/x86/include/asm/traps.h b/arch/x86/include/asm/traps.h
index 5c41a279c1e0..e24c63bbc30a 100644
--- a/arch/x86/include/asm/traps.h
+++ b/arch/x86/include/asm/traps.h
@@ -11,9 +11,17 @@
#include <asm/trap_pf.h>
#ifdef CONFIG_X86_64
+struct ist_regs {
+ /*
+ * ist specific fields must be defined before pt_regs
+ * and they are located below pt_regs on the stacks.
+ */
+ struct pt_regs regs;
+};
+
asmlinkage __visible notrace struct pt_regs *do_error_entry(struct pt_regs *eregs);
void __init trap_init(void);
-asmlinkage __visible noinstr struct pt_regs *vc_switch_off_ist(struct pt_regs *eregs);
+asmlinkage __visible noinstr struct ist_regs *vc_switch_off_ist(struct ist_regs *ist);
#endif
#ifdef CONFIG_X86_F00F_BUG
diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
index b14533af7676..3cffadf64ac2 100644
--- a/arch/x86/kernel/asm-offsets_64.c
+++ b/arch/x86/kernel/asm-offsets_64.c
@@ -4,6 +4,7 @@
#endif
#include <asm/ia32.h>
+#include <asm/traps.h>
#if defined(CONFIG_KVM_GUEST) && defined(CONFIG_PARAVIRT_SPINLOCKS)
#include <asm/kvm_para.h>
@@ -55,6 +56,7 @@ int main(void)
#undef ENTRY
BLANK();
+ DEFINE(IST_pt_regs, offsetof(struct ist_regs, regs));
#ifdef CONFIG_STACKPROTECTOR
DEFINE(stack_canary_offset, offsetof(struct fixed_percpu_data, stack_canary));
--
2.19.1.6.gb485710b
next prev parent reply other threads:[~2021-08-31 17:52 UTC|newest]
Thread overview: 72+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-31 17:50 [PATCH 00/24] x86/entry/64: Convert a bunch of ASM entry code into C code Lai Jiangshan
2021-08-31 17:50 ` [PATCH 01/24] x86/traps: Remove stack-protector from traps.c Lai Jiangshan
2021-08-31 17:50 ` [PATCH 02/24] x86/traps: Move arch/x86/kernel/traps.c to arch/x86/entry/ Lai Jiangshan
2021-09-02 8:09 ` Joerg Roedel
2021-09-02 9:21 ` Lai Jiangshan
2021-09-02 10:50 ` Peter Zijlstra
2021-09-02 11:54 ` Lai Jiangshan
2021-09-02 12:05 ` Peter Zijlstra
2021-09-02 13:34 ` Peter Zijlstra
2021-09-02 17:05 ` Nick Desaulniers
2021-09-02 17:19 ` Miguel Ojeda
2021-09-02 17:23 ` Nick Desaulniers
2021-09-03 7:36 ` Martin Liška
2021-09-07 21:12 ` Nick Desaulniers
2021-09-08 7:33 ` Martin Liška
2021-08-31 17:50 ` [PATCH 03/24] x86/traps: Move declaration of native_irq_return_iret up Lai Jiangshan
2021-08-31 17:50 ` [PATCH 04/24] x86/entry: Expose the address of .Lgs_change to traps.c Lai Jiangshan
2021-09-02 9:14 ` Peter Zijlstra
2021-09-02 9:20 ` Lai Jiangshan
2021-08-31 17:50 ` [PATCH 05/24] x86/entry: Introduce __entry_text for entry code written in C Lai Jiangshan
2021-08-31 19:34 ` Peter Zijlstra
2021-09-01 0:23 ` Lai Jiangshan
2021-08-31 17:50 ` [PATCH 06/24] x86/entry: Move PTI_USER_* to arch/x86/include/asm/processor-flags.h Lai Jiangshan
2021-08-31 17:50 ` [PATCH 07/24] x86: Mark __native_read_cr3() & native_write_cr3() as __always_inline Lai Jiangshan
2021-08-31 17:50 ` [PATCH 08/24] x86/traps: Add C verion of SWITCH_TO_KERNEL_CR3 as switch_to_kernel_cr3() Lai Jiangshan
2021-08-31 17:50 ` [PATCH 09/24] x86/traps: Add fence_swapgs_{user,kernel}_entry() Lai Jiangshan
2021-09-02 9:25 ` Peter Zijlstra
2021-08-31 17:50 ` [PATCH 10/24] x86/traps: Move pt_regs only in fixup_bad_iret() Lai Jiangshan
2021-08-31 17:50 ` [PATCH 11/24] x86/entry: Replace the most of asm code of error_entry to C code Lai Jiangshan
2021-09-02 10:16 ` Peter Zijlstra
2021-09-02 12:08 ` Lai Jiangshan
2021-08-31 17:50 ` [PATCH 12/24] x86/traps: Reconstruct pt_regs on task stack directly in fixup_bad_iret() Lai Jiangshan
2021-08-31 17:50 ` [PATCH 13/24] x86/traps: Mark sync_regs() and fixup_bad_iret() as static __always_inline Lai Jiangshan
2021-08-31 17:50 ` [PATCH 14/24] x86/entry: Make paranoid_exit() callable Lai Jiangshan
2021-08-31 17:50 ` [PATCH 15/24] x86/entry: Call paranoid_exit() in asm_exc_nmi() Lai Jiangshan
2021-08-31 17:50 ` [PATCH 16/24] x86/entry: Use skip_rdi instead of save_ret for PUSH_AND_CLEAR_REGS Lai Jiangshan
2021-08-31 17:50 ` Lai Jiangshan [this message]
2021-09-10 0:18 ` [PATCH 17/24] x86/entry: Introduce struct ist_regs Lai Jiangshan
2021-09-10 0:36 ` Lai Jiangshan
2021-09-10 4:31 ` H. Peter Anvin
2021-09-10 7:13 ` Lai Jiangshan
2021-09-10 7:14 ` H. Peter Anvin
2021-09-10 4:50 ` H. Peter Anvin
2021-09-10 4:51 ` H. Peter Anvin
2021-08-31 17:50 ` [PATCH 18/24] x86/entry: Add the C version ist_switch_to_kernel_cr3() Lai Jiangshan
2021-08-31 17:50 ` [PATCH 19/24] x86/entry: Add the C version ist_restore_cr3() Lai Jiangshan
2021-08-31 17:50 ` [PATCH 20/24] x86/entry: Add the C version get_percpu_base() Lai Jiangshan
2021-08-31 17:50 ` [PATCH 21/24] x86/entry: Add the C version ist_switch_to_kernel_gsbase() Lai Jiangshan
2021-08-31 17:50 ` [PATCH 22/24] x86/entry: Implement and use do_paranoid_entry() and paranoid_exit() Lai Jiangshan
2021-09-02 10:33 ` Peter Zijlstra
2021-09-02 10:42 ` Lai Jiangshan
2021-09-02 12:02 ` Peter Zijlstra
2021-09-02 11:58 ` Lai Jiangshan
2021-09-02 12:29 ` Joerg Roedel
2021-08-31 17:50 ` [PATCH 23/24] x86/entry: Remove the unused ASM macros Lai Jiangshan
2021-08-31 17:50 ` [PATCH 24/24] x86/syscall/64: Move the checking for sysret to C code Lai Jiangshan
2021-09-10 7:20 ` Nikolay Borisov
2021-09-10 7:30 ` Lai Jiangshan
2021-08-31 20:44 ` [PATCH 00/24] x86/entry/64: Convert a bunch of ASM entry code into " Peter Zijlstra
2021-09-02 6:28 ` Lai Jiangshan
2021-09-02 7:44 ` Peter Zijlstra
2021-09-02 10:50 ` [PATCH 25/24] x86/traps: Rewrite native_load_gs_index in " Lai Jiangshan
2021-09-08 1:38 ` H. Peter Anvin
2021-09-08 4:42 ` H. Peter Anvin
2021-09-08 5:00 ` H. Peter Anvin
2021-09-08 7:12 ` Lai Jiangshan
2021-09-09 23:16 ` H. Peter Anvin
2021-09-13 20:01 ` Andy Lutomirski
2021-09-14 2:04 ` Lai Jiangshan
2021-09-14 8:14 ` Peter Zijlstra
2021-09-14 8:17 ` Borislav Petkov
2021-09-14 8:40 ` Lai Jiangshan
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=20210831175025.27570-18-jiangshanlai@gmail.com \
--to=jiangshanlai@gmail.com \
--cc=bp@alien8.de \
--cc=hpa@zytor.com \
--cc=jgross@suse.com \
--cc=jroedel@suse.de \
--cc=laijs@linux.alibaba.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=tony.luck@intel.com \
--cc=x86@kernel.org \
--cc=youquan.song@intel.com \
/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
all inboxes | Powered by JetHome®