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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2FDB5C32771 for ; Wed, 21 Sep 2022 08:25:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230063AbiIUIZQ (ORCPT ); Wed, 21 Sep 2022 04:25:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231390AbiIUIZJ (ORCPT ); Wed, 21 Sep 2022 04:25:09 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA06389830; Wed, 21 Sep 2022 01:24:21 -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 dfw.source.kernel.org (Postfix) with ESMTPS id C866D62FCA; Wed, 21 Sep 2022 08:24:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 29921C43141; Wed, 21 Sep 2022 08:24:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1663748660; bh=1NzIghPEBpq8uMJRc47K9lfgrGEpRXTiw8izcxlL2xQ=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=OKkCGAhnkRBD6nidQpKm62U9gGhDP7WgV8TW6Usene59SdBqik2nH7gw16qADXB6Q kGN59L+qRA7IlhnmvB0CjAY8ecmvGXDfM40+CS4p2ZDCyDOe+IdPd1Nbg+netY/gG3 DaLsZaJASrsTVZuJcY9A8HtsGfTnIi6xg3laWFI7FW4CY9QONjoSY91XqpN5guqjNv NT0ailSc9zSbCHEc8hVikRtzGJRBea18pdRRQ2FZ9zRjFy2c1+NBqEmjb1Gf9kiz9T h4G5/Y4hjWOWf6RZm/TLBKPfj6oeI3iuTkivN18rfwB5A5srEd1XAQaZhmXiroHJxH AKvLfQkjQq9VA== Received: by mail-oa1-f41.google.com with SMTP id 586e51a60fabf-11eab59db71so7958282fac.11; Wed, 21 Sep 2022 01:24:20 -0700 (PDT) X-Gm-Message-State: ACrzQf2M2H3CnF9vMbKM5UDlxeg0yb92WM51h4Bh3rAjT60d2i7XDio2 qGOHHvrRVevRkwEeYgVmqNt2G8f661pzDJuMICY= X-Google-Smtp-Source: AMsMyM4V0nR6rYDAsi882MI6/ftf77j2yigATQcPA5I8IsYUbEUPObkhTn6sRCtBUuHkFuJRwBsb3fkrstWT3g/H0Qk= X-Received: by 2002:a05:6870:a78e:b0:12b:542b:e5b2 with SMTP id x14-20020a056870a78e00b0012b542be5b2mr4387625oao.112.1663748659200; Wed, 21 Sep 2022 01:24:19 -0700 (PDT) MIME-Version: 1.0 References: <20220908022506.1275799-1-guoren@kernel.org> <20220908022506.1275799-9-guoren@kernel.org> <4babce64-e96d-454c-aa35-243b3f2dc315@www.fastmail.com> <8817af55-de0d-4e8f-a41b-25d01d5fa968@www.fastmail.com> <7a2379cf-c1cf-46af-9172-334d2b9b88d5@www.fastmail.com> In-Reply-To: From: Guo Ren Date: Wed, 21 Sep 2022 16:23:58 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH V4 8/8] riscv: Add config of thread stack size To: Arnd Bergmann Cc: Palmer Dabbelt , Thomas Gleixner , Peter Zijlstra , Andy Lutomirski , "Conor.Dooley" , =?UTF-8?Q?Heiko_St=C3=BCbner?= , Jisheng Zhang , lazyparser@gmail.com, falcon@tinylab.org, Huacai Chen , Anup Patel , Atish Patra , Palmer Dabbelt , Paul Walmsley , Sebastian Andrzej Siewior , Linux-Arch , linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, Guo Ren , Andreas Schwab Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-arch@vger.kernel.org On Wed, Sep 21, 2022 at 2:13 PM Guo Ren wrote: > > On Tue, Sep 20, 2022 at 3:18 PM Arnd Bergmann wrote: > > > > On Tue, Sep 20, 2022, at 2:46 AM, Guo Ren wrote: > > > > > diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig > > > index dfe600f3526c..8def456f328c 100644 > > > --- a/arch/riscv/Kconfig > > > +++ b/arch/riscv/Kconfig > > > @@ -442,6 +442,16 @@ config IRQ_STACKS > > > Add independent irq & softirq stacks for percpu to prevent > > > kernel stack > > > overflows. We may save some memory footprint by disabling IRQ_STACKS. > > > > > > +config THREAD_SIZE > > > + int "Kernel stack size (in bytes)" if EXPERT > > > + range 4096 65536 > > > + default 8192 if 32BIT && !KASAN > > > + default 32768 if 64BIT && KASAN > > > + default 16384 > > > + help > > > + Specify the Pages of thread stack size (from 4KB to 64KB), which also > > > + affects irq stack size, which is equal to thread stack size. > > > > I still think this should be guarded in a way that prevents > > setting the stack to smaller than default values unless VMAP_STACK > > is set as well. > Current VMAP_STACK would double THREAD_SIZE. Let me see how to reduce > the VMAP_STACK. Sorry, for my miss understanding. I have no idea to reduce the VMAP_STACK's THREAD_ALIGN, THREAD_SIZE*2 is fine. Here is my new patch: diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 76bde12d9f8c..669ae57356a2 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -443,6 +443,16 @@ config IRQ_STACKS Add independent irq & softirq stacks for percpu to prevent kernel stack overflows. We may save some memory footprint by disabling IRQ_STACKS. +config THREAD_SIZE + int "Kernel stack size (in bytes)" if VMAP_STACK && EXPERT + range 4096 65536 + default 8192 if 32BIT && !KASAN + default 32768 if 64BIT && KASAN + default 16384 + help + Specify the Pages of thread stack size (from 4KB to 64KB), which also + affects irq stack size, which is equal to thread stack size. + endmenu # "Platform type" menu "Kernel features" diff --git a/arch/riscv/include/asm/thread_info.h b/arch/riscv/include/asm/thread_info.h index 043da8ccc7e6..e7ae3f13b879 100644 --- a/arch/riscv/include/asm/thread_info.h +++ b/arch/riscv/include/asm/thread_info.h @@ -11,32 +11,17 @@ #include #include -#ifdef CONFIG_KASAN -#define KASAN_STACK_ORDER 1 -#else -#define KASAN_STACK_ORDER 0 -#endif - /* thread information allocation */ -#ifdef CONFIG_64BIT -#define THREAD_SIZE_ORDER (2 + KASAN_STACK_ORDER) -#else -#define THREAD_SIZE_ORDER (1 + KASAN_STACK_ORDER) -#endif -#define THREAD_SIZE (PAGE_SIZE << THREAD_SIZE_ORDER) +#define THREAD_SIZE CONFIG_THREAD_SIZE /* * By aligning VMAP'd stacks to 2 * THREAD_SIZE, we can detect overflow by - * checking sp & (1 << THREAD_SHIFT), which we can do cheaply in the entry - * assembly. + * checking sp & THREAD_SIZE, which we can do cheaply in the entry assembly. */ #ifdef CONFIG_VMAP_STACK #define THREAD_ALIGN (2 * THREAD_SIZE) -#else -#define THREAD_ALIGN THREAD_SIZE #endif -#define THREAD_SHIFT (PAGE_SHIFT + THREAD_SIZE_ORDER) #define OVERFLOW_STACK_SIZE SZ_4K #define SHADOW_OVERFLOW_STACK_SIZE (1024) diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S index 2207cf44a3bc..71ea850ff0db 100644 --- a/arch/riscv/kernel/entry.S +++ b/arch/riscv/kernel/entry.S @@ -29,8 +29,8 @@ _restore_kernel_tpsp: #ifdef CONFIG_VMAP_STACK addi sp, sp, -(PT_SIZE_ON_STACK) - srli sp, sp, THREAD_SHIFT - andi sp, sp, 0x1 + srli sp, sp, PAGE_SHIFT + andi sp, sp, (THREAD_ALIGN >> PAGE_SHIFT >> 1) bnez sp, handle_kernel_stack_overflow REG_L sp, TASK_TI_KERNEL_SP(tp) #endif > > > > > Arnd > > > > -- > Best Regards > Guo Ren -- Best Regards Guo Ren