Re: [PATCH 11/24] x86/entry: Replace the most of asm code of error_entry to C code

From: Lai Jiangshan
Date: Thu Sep 02 2021 - 08:08:54 EST




On 2021/9/2 18:16, Peter Zijlstra wrote:
On Wed, Sep 01, 2021 at 01:50:12AM +0800, Lai Jiangshan wrote:
diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S
index 42d2918f5646..bc9e2f5ad370 100644
--- a/arch/x86/entry/entry_64.S
+++ b/arch/x86/entry/entry_64.S
@@ -972,83 +972,14 @@ SYM_CODE_START_LOCAL(error_entry)
cld
PUSH_AND_CLEAR_REGS save_ret=1
ENCODE_FRAME_POINTER 8
popq %r12 /* save return addr in %12 */
movq %rsp, %rdi /* arg0 = pt_regs pointer */
+ call do_error_entry
movq %rax, %rsp /* switch stack */
ENCODE_FRAME_POINTER
pushq %r12
ret

There's only a single error_entry callsite, which is idtentry_body. One
of the things I wanted to do is change this lot so we change to the
task_stack in 'C', using an adaptation of call_on_irqstack() and
basically don't return frrom C until we're done with \cfunc.

That is, once we call C, stay there, and don't do this back and forth
between C and asm.

I haven't figured out how can an adaptation of call_on_irqstack() can do it.
The original stack need to be "free" for next task. And we can't switch
the stack before error_entry() since the CR3 is not switched.

I believe the ASM code here can be simplified and clearer further. But I don't
think going back and forth between C and ASM is real issue if the ASM code is
short and simple enough.



As is, the resulting asm in error_entry is somewhat confusing given that
we sometimes don't actually switch stacks.