Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp297429rwb; Mon, 26 Sep 2022 19:17:45 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5r+3VAPBhHSvyRRBXj0mvhd0ad3hTMXDU1tBCRO6frRwOPCk5fheWvt7sftGLEmCZVcMpR X-Received: by 2002:a50:ab53:0:b0:456:ec7a:4335 with SMTP id t19-20020a50ab53000000b00456ec7a4335mr15780051edc.400.1664245064855; Mon, 26 Sep 2022 19:17:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664245064; cv=none; d=google.com; s=arc-20160816; b=KC1tK3WCvm5t2NN108cziuh7LKGaD5BakBCohWTpwLBjqrgwT6AVH3p1att0Htfut5 ky4JZ6b2YmdyfOd5V/wUnNOUzypMo6HA4NirwcoqvKhd6SX4xhvPlrzWVPy4uqekZ3sQ sOflk97HMpTf2X5KteMWqD4ZgRPZ0G5z4C11cpQ4uA5WJuYjeBVHNwt+HdvAofqpmaL4 dPVLkxmZ9chN01so1BsLaLJaOtcB7eDCcOC2CowYo11wN2gNl10qcEnmVKRK2aUzAMDi c/RS36ea8aYJz8SJUCo71lFae8/V0jUzXf3qhtvgWqJts3BzA+7mAsmzxlP9rFGCQSGj aqvA== 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=ikbCqkdSfI8UjC4Rb7Y6G1uDpDq1Tv7tt/uNPqkFTFk=; b=OHevJBIiHR7iyy4qoAZSr3S2OPCFubelropbDo0lTYaDXkRUtfMG1TTrdLwa+WeUX7 twn76RxUbgFSYlr2tMXHFUBqyYORk7DSnt7kEpBZPAcQMdiT362plfiZAXwEKnvNcu7V kn0MAtcPbz+vKKM+kth75yHEsuZmsTlw23PSnFN6+PqNW9FOmSusSw4RlKF02AOb9KtD 7K9C321K0otcxGh40iv4vx1vdHB3ePQfRfwdEiSkrIGdi8pDp57BA0n91O/eoPoUfCnG +5dq9BXyTMXwG0ZZY82P/y/WGpTFBe+lt1lNovNipeZo9HZ1/Ios4du1sp3sWJ/VXmtq z0wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UycWZTDW; 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 o9-20020a509b09000000b00457137b2571si343902edi.346.2022.09.26.19.17.19; Mon, 26 Sep 2022 19:17:44 -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=UycWZTDW; 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 S229994AbiI0CAi (ORCPT + 99 others); Mon, 26 Sep 2022 22:00:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229998AbiI0CAg (ORCPT ); Mon, 26 Sep 2022 22:00:36 -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 5C777868B0 for ; Mon, 26 Sep 2022 19:00:35 -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 F02C7B81693 for ; Tue, 27 Sep 2022 02:00:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A2DFFC4347C for ; Tue, 27 Sep 2022 02:00:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1664244032; bh=19gy2EXbjjLD/l6XeEJeQfh5wNSKslif73XxWJJiya4=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=UycWZTDWCpwFEzNOCYzx0660ef5vI8AHfyoSmAGCveyhYBvSAuNxwgJA/vQsJV97o +S54clXZbOM3d7MoE0FvzwTOK0HGrNwPwp8yX4GWqhg8qZ82AvjLVgQEGkmajpiKal TsNeZ9ZBSWai24xZDwzpQQ4GVsGyCbMMA/TfdFVDQ5f3MQQgwheis7qbNUsWeD7n++ oJLT1YOU9vWDnreDLshC+mDdOByl/rfHot2LU7npXCXPz5Z42Vn2zvninr7YXD/+gB KlOFx/YbLe1AcP3WN9HiKszD4IL5nX05NYGl8ii1PxUAJXiQ30CLXgfuivTlPreosu QRnftSuWrko6g== Received: by mail-oa1-f48.google.com with SMTP id 586e51a60fabf-127dca21a7dso11551651fac.12 for ; Mon, 26 Sep 2022 19:00:32 -0700 (PDT) X-Gm-Message-State: ACrzQf3P5NKJm/eaSh0b35qU8RpARlKlNWaisk4Zdl6HodKeUvkJ6Y3X 5b9rfFvYW6+5H1lAjjHG1uwQBaF+MV0HKdwghMA= X-Received: by 2002:a05:6870:a78e:b0:12b:542b:e5b2 with SMTP id x14-20020a056870a78e00b0012b542be5b2mr937824oao.112.1664244031696; Mon, 26 Sep 2022 19:00:31 -0700 (PDT) MIME-Version: 1.0 References: <20220925175356.681-1-jszhang@kernel.org> <20220925175356.681-4-jszhang@kernel.org> In-Reply-To: From: Guo Ren Date: Tue, 27 Sep 2022 10:00:19 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 3/4] riscv: fix race when vmap stack overflow and remove shadow_stack To: Jisheng Zhang Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , Nathan Chancellor , Nick Desaulniers , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.2 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 Tue, Sep 27, 2022 at 8:28 AM Jisheng Zhang wrote: > > > > > #ifdef CONFIG_VMAP_STACK > > > -static DEFINE_PER_CPU(unsigned long [OVERFLOW_STACK_SIZE/sizeof(long)], > > > - overflow_stack)__aligned(16); > > > -/* > > > - * shadow stack, handled_ kernel_ stack_ overflow(in kernel/entry.S) is used > > > - * to get per-cpu overflow stack(get_overflow_stack). > > > - */ > > > -long shadow_stack[SHADOW_OVERFLOW_STACK_SIZE/sizeof(long)]; > > > -asmlinkage unsigned long get_overflow_stack(void) > > > -{ > > > - return (unsigned long)this_cpu_ptr(overflow_stack) + > > > - OVERFLOW_STACK_SIZE; > > > -} > > > +unsigned long overflow_stack[NR_CPUS][OVERFLOW_STACK_SIZE/sizeof(long)] __aligned(16); > > If NR_CPUS is large, there's a non-trival memory waste, I have a > solution for this case, will send a new version today. Er... Yes, we can't bypass the percpu mechanism. I also forgot the percpu basic concept. In the end, I prefer the previous solution, maybe just simply giving an atomic flag would be okay. (But we only have one register (sp) which could be used, it seems not simple.) > > Thanks -- Best Regards Guo Ren