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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9804CC4332F for ; Mon, 20 Dec 2021 13:41:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233003AbhLTNlI (ORCPT ); Mon, 20 Dec 2021 08:41:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230300AbhLTNlG (ORCPT ); Mon, 20 Dec 2021 08:41:06 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78B80C061574; Mon, 20 Dec 2021 05:41:06 -0800 (PST) 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 4E6C9B80EA2; Mon, 20 Dec 2021 13:41:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0B994C36AE9; Mon, 20 Dec 2021 13:41:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1640007663; bh=sEhqYPxM4z19kGZYE2peDh+u0pT/5DH5Q0sa/WgLz2s=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=oT13uPmkAxGD5Bshuprq6DF7tVZgmsbYCW7m81SlEheTzmKYwN9cteS2Qm0f+yzG6 FxEZ90zHRkBUkkldie3P2GUorJw1P9OF2hEnTx8f/v+ToJqdVDYWB/RZ1XHjnjfRxL fLVSWyLXsF5rXhpcI2KLW7oGXDoL1S/kUska8UuCqrAnXLgCH77Juo+nSxz7bV+YX3 3WfuXF6l3rrDlcVq5dlYauRBATyJZitLDYYQCif2MaHz6a5dvEw228kOuvYnysWwa9 APhZ9+umMMMIfdZxyvdYYy+6SLkJwLHrNpa2baLRP4StlCKGzXgQu+j2Qe1Fq0Q/Z8 2W1x/QxmwJyOQ== Received: by mail-ua1-f54.google.com with SMTP id o1so17725858uap.4; Mon, 20 Dec 2021 05:41:02 -0800 (PST) X-Gm-Message-State: AOAM533SMp5A/u+oBrZeD2y/zBD71doYSiFNpX9Sa1mxW40hpKMaRaJr PpTwsONAqV+SNvyXUEDHCIMmWPpjSyzD5j+ow4k= X-Google-Smtp-Source: ABdhPJwGr/+MFfoW7ipUpJBlTl+ZN+AB5Gr6EIJrZEEcp5Ttg/AYr9iCWiGr8Ukebm4uIUfe9nTB/0FRTqyMvS0jIYU= X-Received: by 2002:a05:6102:316e:: with SMTP id l14mr233250vsm.8.1640007662059; Mon, 20 Dec 2021 05:41:02 -0800 (PST) MIME-Version: 1.0 References: <20211206104657.433304-1-alexandre.ghiti@canonical.com> <20211206104657.433304-13-alexandre.ghiti@canonical.com> In-Reply-To: From: Guo Ren Date: Mon, 20 Dec 2021 21:40:51 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3 12/13] riscv: Initialize thread pointer before calling C functions To: Ard Biesheuvel Cc: Alexandre Ghiti , Jonathan Corbet , Paul Walmsley , Palmer Dabbelt , Albert Ou , Zong Li , Anup Patel , Atish Patra , Christoph Hellwig , Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Arnd Bergmann , Kees Cook , Guo Ren , Heinrich Schuchardt , Mayuresh Chitale , panqinglin2020@iscas.ac.cn, Linux Doc Mailing List , linux-riscv , Linux Kernel Mailing List , kasan-dev , linux-efi , linux-arch Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Dec 20, 2021 at 5:17 PM Ard Biesheuvel wrote: > > On Mon, 20 Dec 2021 at 10:11, Guo Ren wrote: > > > > On Tue, Dec 7, 2021 at 11:55 AM Alexandre Ghiti > > wrote: > > > > > > Because of the stack canary feature that reads from the current task > > > structure the stack canary value, the thread pointer register "tp" must > > > be set before calling any C function from head.S: by chance, setup_vm > > Shall we disable -fstack-protector for setup_vm() with __attribute__? > > Don't use __attribute__((optimize())) for that: it is known to be > broken, and documented as debug purposes only in the GCC info pages: > > https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html Oh, thx for the link. > > > > > > Actually, we've already init tp later. > > > > > and all the functions that it calls does not seem to be part of the > > > functions where the canary check is done, but in the following commits, > > > some functions will. > > > > > > Fixes: f2c9699f65557a31 ("riscv: Add STACKPROTECTOR supported") > > > Signed-off-by: Alexandre Ghiti > > > --- > > > arch/riscv/kernel/head.S | 1 + > > > 1 file changed, 1 insertion(+) > > > > > > diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S > > > index c3c0ed559770..86f7ee3d210d 100644 > > > --- a/arch/riscv/kernel/head.S > > > +++ b/arch/riscv/kernel/head.S > > > @@ -302,6 +302,7 @@ clear_bss_done: > > > REG_S a0, (a2) > > > > > > /* Initialize page tables and relocate to virtual addresses */ > > > + la tp, init_task > > > la sp, init_thread_union + THREAD_SIZE > > > XIP_FIXUP_OFFSET sp > > > #ifdef CONFIG_BUILTIN_DTB > > > -- > > > 2.32.0 > > > > > > > > > -- > > Best Regards > > Guo Ren > > > > ML: https://lore.kernel.org/linux-csky/ -- Best Regards Guo Ren ML: https://lore.kernel.org/linux-csky/