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 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4CF95C433F5 for ; Tue, 4 Jan 2022 14:33:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:From: References:Cc:To:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=RhvoxG6/tLgk61HdV/br3zlJoL/Vjrnvj7+xyTF/mKg=; b=EwYZhhr21JYvz2fj4YLSMtGNJ/ x6mBibTZHzqd67x12cOzaHYR7gALxUR0L2deGPc8fNoJR05iag8Ni0aOzed9nOc/ru20lgX5+rbtL pdN/vzsKU9S37iejBs46bfItQC3gHvttN9ZVxCEqiDagWOjV1hQNilUomKpfpH+Of+j7SsZ3lVfZC /86rQ0rvBpyL5vHqiYrg3fGQZFGsdaYve3G3/+ALqneaDE7ZwhChwnyakBe69uhRI019ldNarU2Mi vqGKVXnFSini3/4kS0HV/1pnfXB1CUL+HAps2csm4tu+fc6fb7akD/bYGouDksIZvm+VojjflEmHs 9+9vd9Yw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n4krW-00BjkS-SO; Tue, 04 Jan 2022 14:32:31 +0000 Received: from out30-45.freemail.mail.aliyun.com ([115.124.30.45]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n4krR-00Bjhk-55 for linux-arm-kernel@lists.infradead.org; Tue, 04 Jan 2022 14:32:28 +0000 X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R251e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=e01e04423; MF=ashimida@linux.alibaba.com; NM=1; PH=DS; RN=10; SR=0; TI=SMTPD_---0V0xwPGf_1641306736; Received: from 192.168.193.151(mailfrom:ashimida@linux.alibaba.com fp:SMTPD_---0V0xwPGf_1641306736) by smtp.aliyun-inc.com(127.0.0.1); Tue, 04 Jan 2022 22:32:17 +0800 Subject: Re: [PATCH] [RFC] aarch64: scs: reload shadow call stack in user exception entry To: Mark Rutland Cc: catalin.marinas@arm.com, will@kernel.org, samitolvanen@google.com, maz@kernel.org, joey.gouly@arm.com, pcc@google.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org References: <20211228010604.109572-1-ashimida@linux.alibaba.com> From: Dan Li Message-ID: <4d79d1e0-8320-4d9f-d847-ac83032c71df@linux.alibaba.com> Date: Tue, 4 Jan 2022 06:32:16 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220104_063225_449434_F887FC57 X-CRM114-Status: GOOD ( 23.62 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 1/4/22 2:40 AM, Mark Rutland wrote: > Hi, > > On Mon, Dec 27, 2021 at 05:06:04PM -0800, Dan Li wrote: >> When el0 exception occurs, kernel_entry/exit will load/save tsk->scs_sp >> to ensure scs working properly. AFAIK, the SCS offset should always be >> 0 at this time. >> >> Is it reasonable to reload x18 to scs_base directly in kernel_entry >> here, or am I missing something? >> >> Signed-off-by: Dan Li > > AFAICT the saving here is just that we avoid storing the SCS SP upon return to > EL0, and I suspect that in practice that's not measureable. > > So without numbers to show otherwise, I'd prefer to leave this as-is, though I > agree that this patch should work. If we do want to change this, I think we > need a comment in the `kernel_exit` path to pair with the `scs_load` in > `kernel_entry`. > > Thanks, > Mark. > Yes, there is only one instruction saved here, which should have a minimal impact on performance. The current code is also good for me :) Thanks, Dan. >> --- >> arch/arm64/include/asm/scs.h | 7 +++++++ >> arch/arm64/kernel/entry.S | 3 +-- >> 2 files changed, 8 insertions(+), 2 deletions(-) >> >> diff --git a/arch/arm64/include/asm/scs.h b/arch/arm64/include/asm/scs.h >> index 8297bccf0784..2bc0d0575e75 100644 >> --- a/arch/arm64/include/asm/scs.h >> +++ b/arch/arm64/include/asm/scs.h >> @@ -9,6 +9,10 @@ >> #ifdef CONFIG_SHADOW_CALL_STACK >> scs_sp .req x18 >> >> + .macro scs_reload tsk >> + ldr scs_sp, [\tsk, #TSK_TI_SCS_BASE] >> + .endm >> + >> .macro scs_load tsk >> ldr scs_sp, [\tsk, #TSK_TI_SCS_SP] >> .endm >> @@ -17,6 +21,9 @@ >> str scs_sp, [\tsk, #TSK_TI_SCS_SP] >> .endm >> #else >> + .macro scs_reload tsk >> + .endm >> + >> .macro scs_load tsk >> .endm >> >> diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S >> index bc6d5a970a13..57547a3e4f7c 100644 >> --- a/arch/arm64/kernel/entry.S >> +++ b/arch/arm64/kernel/entry.S >> @@ -265,7 +265,7 @@ alternative_if ARM64_HAS_ADDRESS_AUTH >> alternative_else_nop_endif >> 1: >> >> - scs_load tsk >> + scs_reload tsk >> .else >> add x21, sp, #PT_REGS_SIZE >> get_current_task tsk >> @@ -365,7 +365,6 @@ alternative_if ARM64_WORKAROUND_845719 >> alternative_else_nop_endif >> #endif >> 3: >> - scs_save tsk >> >> /* Ignore asynchronous tag check faults in the uaccess routines */ >> ldr x0, [tsk, THREAD_SCTLR_USER] >> -- >> 2.17.1 >> _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel