Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp699483pxb; Thu, 2 Sep 2021 12:58:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxRSKvuEx4BtEkZMDQc3kqS61rlSirbqaqT7pzAVsLoWXoa+ME0buz8OwmdZnlGFJUvT1Xy X-Received: by 2002:aa7:dd12:: with SMTP id i18mr52136edv.368.1630612688475; Thu, 02 Sep 2021 12:58:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630612688; cv=none; d=google.com; s=arc-20160816; b=Tmp/1bdl6BHnoJfkJABVE32MQc0U5t2+KQZySJufg6GpJAxHSvzVRRTdMIOsxkskH4 RCm3MbQMhS0dosbwWhoMC9n+R76bZZwb2D/OGfFc0xzpEr2TYmsHp1J3sGfoUMLD3ia6 /G8s2VUie57Z3KEx0qEZ5KO57RXEbfcbTfqoDEqnEiBxuduomJWRi+k1YF0YRez38sz9 336+aegvcoYpQHMSE4861CNrI6kwn95GQ7yGkarzgFaPmn4bjoC4Y9mA+mRlhaB7/Y5f l+yNj+OjNtd+NTe3POnvPMYXXyi6zbvhCUwTjud06JEOzPA+O4T/sgDM5OplRfckGX4G 66Mg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=xUmdcNtEV9apZavoGjQ4BYi0syruWvFsasGM41epd14=; b=z+G0C4R2IQIhz4iIimaZZ5XNVogL2I0JacTXd2YRy1qJRbqPHAAVko/IvveD2o3fNq N+gF50kTQ6qmxm1CN3wlOpjb6ZJEEK/BkeDJxsDNg+EiLiChvz/MsU6jThjYSP87GJ/V GDF2bR/WK+azn9PUMj7j29eGzHNmcpljTdTV9zAw4lZ2gKnHcHEgUGu65xwCDLho1S8d oF4dFRYIGeUSQGNugi90g593MQdTIR3uGuvgzRhDlr6hhWmhLM6lpy1wxEQ5WZNhTwcJ ZKi8sSTD3oaFMzr+gLZpqr8/+14M5D8xBpSijXWB319UhdEcmAZxRFb2Hv0ECETffFbI u4SQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b6si3665547edu.99.2021.09.02.12.57.43; Thu, 02 Sep 2021 12:58:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343838AbhIBMJu (ORCPT + 99 others); Thu, 2 Sep 2021 08:09:50 -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. >