Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp116436rwb; Wed, 21 Sep 2022 18:36:22 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6lufXsnYWJo5k/QBTFkATTQ2sIxjYePEMWf+EkogAJpTPxTe78N8aYocNTwmNWGpQR4/FV X-Received: by 2002:a17:907:5ce:b0:730:bae0:deb with SMTP id wg14-20020a17090705ce00b00730bae00debmr827569ejb.181.1663810582094; Wed, 21 Sep 2022 18:36:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663810582; cv=none; d=google.com; s=arc-20160816; b=kEwNjsDCXGZgBCrHJP7iTXffbl9AVA0GKZ4Er3QSi471e0AHIH1gHjkGKwk9G48zHM clALkLXML4hr7CA8K6aVxtjpw1U+ZWXNCZOJ9jSCQbz8QFaTpUOwIK6bWIECAcLd+0D0 +NrhNSQAWQ8qEtF0FDh14RWQ8rG6Wq3wNCHh0Pecd2d15hB1IzCc0ouIQN4pv6CN68IK r3860xz734o2B7LX+iakeUpzDxmDSS5nJBUsAQaGgi+yF/0ZvCk4Bk5/C4GVmqmKdCli v+R5rIuDKYvMaNhdi3D5ghO+tG2ijr5OHoFociZBM7FYNxVvHHyGb2qNY5yBE1wpHjLs NrTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=XCm9t+gwjaz45TJntjkhbU617XyRjBxEA2VIcdUK2vY=; b=1AU493ev1vz1S4zb/KTXvtp+iTdgiAR8ygX/+v63/gCGf0VKqjJLTLFatY4QGkL9GR Pq5xt/W67LfiHcvfQB/cxM03gnRJAE30/sYiaNEndkrbe34FGB1GNZLCkApmGAO81Cjl iZCTCpQK0Byd553ypJ/uyhqe5UdLeu1iJlNbqN+M+5rQ15isqGC4Bh37cEDM/EaeDN4E 1Paxud2FENQfvbNg/YwGn3CX0p8XxYmeJgwL4t+PbvhPw4Qgn0MF8sBwauqPy2AejIRw DTllQvlcHMuIkqFQm9F1y0mwZCs3BNFNERdr2ce17KuOubSagnw+xcRlwBoTvK8dBlSW lskA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=iDuwNAKI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hp20-20020a1709073e1400b0078210c21ecesi2701963ejc.304.2022.09.21.18.35.55; Wed, 21 Sep 2022 18:36:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=iDuwNAKI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230236AbiIVB04 (ORCPT + 99 others); Wed, 21 Sep 2022 21:26:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229604AbiIVB0y (ORCPT ); Wed, 21 Sep 2022 21:26:54 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F04C9DF9D; Wed, 21 Sep 2022 18:26:53 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id DD369B81E1A; Thu, 22 Sep 2022 01:26:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8772AC43145; Thu, 22 Sep 2022 01:26:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1663810010; bh=6OvF45eCl5d2FjxziCWsCcjLdCsAYOFNQse2WIemCjQ=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=iDuwNAKIcR9nkcBbRDkDpjI9/guVnVBkMqVocMaBR6eZPP4O3tNIzJGYFoqk5qlOB T7kXk17eMshImBvw91L9+uk7kj+rNqzlZFAafvDz0lPgAJxI4PnvyGAkCr0U1+kI7X cMSNdQW1QOfQoi81TM2o/9/OK4IIbE1Ge3emToO0KwC3emoXcOdU81e9r7eoA+sqvd eJ7Illgs4SWf91dAn02emRLgcn9kI65JxSIjGn91YIKLJyxlrVkJEJ3SWPCOF+l/hU ySvsvLratHV3Q1BSq4xUvhUsPmRse/JUXGP+Au6rWsbk9hZbvuuBiMos6y4xkNsupp HXjiJUbqr3Q2g== Received: by mail-ot1-f48.google.com with SMTP id j17-20020a9d7f11000000b0065a20212349so5206522otq.12; Wed, 21 Sep 2022 18:26:50 -0700 (PDT) X-Gm-Message-State: ACrzQf2u9YNFGyxFpUtvvLy7cS4SxudTQKys4cpjDIrLiGhm0iHkt3nc byIGcDZYs6gSXAXTxz+zgfKV2iENRk60NWv2Psc= X-Received: by 2002:a05:6830:1213:b0:65a:9a2:daf3 with SMTP id r19-20020a056830121300b0065a09a2daf3mr483252otp.308.1663810009513; Wed, 21 Sep 2022 18:26:49 -0700 (PDT) MIME-Version: 1.0 References: <20220918155246.1203293-1-guoren@kernel.org> <20220918155246.1203293-9-guoren@kernel.org> In-Reply-To: From: Guo Ren Date: Thu, 22 Sep 2022 09:26:37 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH V5 08/11] riscv: Support HAVE_IRQ_EXIT_ON_IRQ_STACK To: Chen Zhongjin Cc: arnd@arndb.de, palmer@rivosinc.com, tglx@linutronix.de, peterz@infradead.org, luto@kernel.org, conor.dooley@microchip.com, heiko@sntech.de, jszhang@kernel.org, lazyparser@gmail.com, falcon@tinylab.org, chenhuacai@kernel.org, apatel@ventanamicro.com, atishp@atishpatra.org, palmer@dabbelt.com, paul.walmsley@sifive.com, mark.rutland@arm.com, zouyipeng@huawei.com, bigeasy@linutronix.de, David.Laight@aculab.com, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, Guo Ren Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 21, 2022 at 7:56 PM Chen Zhongjin wrote: > > Hi, > > Sorry to bother again, I just finished the test with your patches on > mine patch set. > > On 2022/9/21 17:53, Guo Ren wrote: > > On Wed, Sep 21, 2022 at 4:34 PM Chen Zhongjin wrote: > >> Hi, > >> > >> On 2022/9/18 23:52, guoren@kernel.org wrote: > >>> diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S > >>> index 5f49517cd3a2..426529b84db0 100644 > >>> --- a/arch/riscv/kernel/entry.S > >>> +++ b/arch/riscv/kernel/entry.S > >>> @@ -332,6 +332,33 @@ ENTRY(ret_from_kernel_thread) > >>> tail syscall_exit_to_user_mode > >>> ENDPROC(ret_from_kernel_thread) > >>> > >>> +#ifdef CONFIG_IRQ_STACKS > >>> +ENTRY(call_on_stack) > >>> + /* Create a frame record to save our ra and fp */ > >>> + addi sp, sp, -RISCV_SZPTR > >>> + REG_S ra, (sp) > >>> + addi sp, sp, -RISCV_SZPTR > >>> + REG_S fp, (sp) > >>> + > >>> + /* Save sp in fp */ > >>> + move fp, sp > >>> + > > Considering that s0 points to previous sp normally, I think here we > should have 'addi fp, sp, 2*RISCV_SZPTR'. > > An example below: > > addi sp, sp, -16 > sd ra, 8(sp) > sd s0, 0(sp) > addi s0, sp, 16 <- s0 is set to previous sp > ... > > ld ra,8(sp) > ld s0,0(sp) > addi sp,sp,16 > > So maybe it's better to save the stack frame as below: > > addi sp, sp, -2*RISCV_SZPTR > REG_S ra, RISCV_SZPTR(sp) > REG_S s0, (sp) > > /* Save sp in fp */ > addi s0, sp, 2*RISCV_SZPTR > > ... > > /* > * Restore sp from prev fp, and fp, ra from the frame > */ > addi sp, s0, -2*RISCV_SZPTR > REG_L ra, RISCV_SZPTR(sp) > REG_L s0, (sp) > addi sp, sp, 2*RISCV_SZPTR > > > Anyway, lets set fp as sp + 2 * RISCV_SZPTR, so that unwinder can > connect two stacks same as normal function. > > I tested this with my patch and the unwinder works properly. Thx, you got it. My patch broke the fp chain. I would fix it in the next version. > > > Thanks for your time! > > Best, > > Chen > > >>> + /* Move to the new stack and call the function there */ > >>> + li a3, IRQ_STACK_SIZE > >>> + add sp, a1, a3 > >>> + jalr a2 > >>> + > >>> + /* > >>> + * Restore sp from prev fp, and fp, ra from the frame > >>> + */ > >>> + move sp, fp > >>> + REG_L fp, (sp) > >>> + addi sp, sp, RISCV_SZPTR > >>> + REG_L ra, (sp) > >>> + addi sp, sp, RISCV_SZPTR > >>> + ret > >>> +ENDPROC(call_on_stack) > >>> +#endif > >> Seems my compiler (riscv64-linux-gnu-gcc 8.4.0, cross compiling from > >> x86) cannot recognize the register `fp`. > > The whole entry.S uses s0 instead of fp, so I approve of your advice. Thx. > > > >> After I changed it to `s0` this can pass compiling. > >> > >> > >> Seems there is nowhere else using `fp`, can this just using `s0` instead? > >> > >> Best, > >> > >> Chen > >> > >> -- Best Regards Guo Ren