From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.5 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF327C432BE for ; Thu, 2 Sep 2021 12:08:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A2588610D0 for ; Thu, 2 Sep 2021 12:08:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343981AbhIBMJv (ORCPT ); Thu, 2 Sep 2021 08:09:51 -0400 Received: from out30-57.freemail.mail.aliyun.com ([115.124.30.57]:45283 "EHLO out30-57.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233831AbhIBMJr (ORCPT ); Thu, 2 Sep 2021 08:09:47 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R541e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04394;MF=laijs@linux.alibaba.com;NM=1;PH=DS;RN=12;SR=0;TI=SMTPD_---0Un0Ri4b_1630584526; Received: from C02XQCBJJG5H.local(mailfrom:laijs@linux.alibaba.com fp:SMTPD_---0Un0Ri4b_1630584526) by smtp.aliyun-inc.com(127.0.0.1); Thu, 02 Sep 2021 20:08:46 +0800 Subject: Re: [PATCH 11/24] x86/entry: Replace the most of asm code of error_entry to C code To: Peter Zijlstra , Lai Jiangshan Cc: linux-kernel@vger.kernel.org, Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Joerg Roedel , Youquan Song , Tony Luck References: <20210831175025.27570-1-jiangshanlai@gmail.com> <20210831175025.27570-12-jiangshanlai@gmail.com> From: Lai Jiangshan Message-ID: <44ff16e6-21c8-dbd5-4393-0909162bd241@linux.alibaba.com> Date: Thu, 2 Sep 2021 20:08:46 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. >