From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from omta38.uswest2.a.cloudfilter.net (omta38.uswest2.a.cloudfilter.net [35.89.44.37]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6804F2F547F for ; Tue, 19 May 2026 08:28:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=35.89.44.37 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779179330; cv=none; b=mPyna/UoxfIRwbPKSn716PV3cR5i/Imi5nW3+14KCMs77YbAUCGOi4y7ExLKBob30lFJoAvd2kjj79UeD1H14KcGY8lvbZpaDHOD2rkkl8RKeorDIJk6U6uOkH2LPr+6EFzASe9ODg1E17/FtNYoOzmC6H9uprAocj38C43OmTQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779179330; c=relaxed/simple; bh=DFrVOZnlJXxSU6f++OQxDSFyE6KougMIb9M/doCmjcQ=; h=Message-ID:Date:MIME-Version:Subject:To:References:From: In-Reply-To:Content-Type; b=HJx+QJn1vxyOe1q9sdmDMWNZ2Y8uqkPKOWRCvKNilldNAgO8ApD1HLzboGDhCLyDObhWaPSZeRyU5+K39nslNp80EnQoAkNpFh5LAyoW20+VskEVMEUhitmu6ouGsNTxD2ne8qyz1572HJc2g7VbXD4RlplEZ0gm0T5MjyLyuxI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=w6rz.net; spf=pass smtp.mailfrom=w6rz.net; dkim=pass (2048-bit key) header.d=w6rz.net header.i=@w6rz.net header.b=YDPikdm4; arc=none smtp.client-ip=35.89.44.37 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=w6rz.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=w6rz.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=w6rz.net header.i=@w6rz.net header.b="YDPikdm4" Received: from eig-obgw-6007b.ext.cloudfilter.net ([10.0.30.166]) by cmsmtp with ESMTPS id P4RhwM6Fnjw8YPFogwzKUm; Tue, 19 May 2026 08:28:42 +0000 Received: from box5620.bluehost.com ([162.241.219.59]) by cmsmtp with ESMTPS id PFofwmZW3tuVJPFogwyce5; Tue, 19 May 2026 08:28:42 +0000 X-Authority-Analysis: v=2.4 cv=BNWzrEQG c=1 sm=1 tr=0 ts=6a0c1f3a a=30941lsx5skRcbJ0JMGu9A==:117 a=30941lsx5skRcbJ0JMGu9A==:17 a=IkcTkHD0fZMA:10 a=NGcC8JguVDcA:10 a=7vwVE5O1G3EA:10 a=pGLkceISAAAA:8 a=pFyQfRViAAAA:8 a=dOPtARG4wUHVzOZUDtUA:9 a=QEXdDO2ut3YA:10 a=oJz5jJLG1JtSoe7EL652:22 a=L5EjiQpGQaFGZdqT14z7:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=w6rz.net; s=default; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:From: References:To:Subject:MIME-Version:Date:Message-ID:Sender:Reply-To:Cc: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=dUVG5hW1tXzZ+39lX1QRkXzsTcX3CBxGtHk6r82iEg4=; b=YDPikdm4uUSuK87uwhvRyWshIH xW/H5KRIDLw7GN00u9zUJw4FIR6/H9DH7nyWYiQoSzOvUFKIbKhayURyx5HXhPAJtg+zr5Ly+dqhq Kko2AmUaq5YWSFk/tARHTraoAlunnmzPjhryfxHAHkmEwJUd2fpNtx6uQoO0HIainLcO0gN51Zgae Xs3Z5Do0bYNfsxKnyMVRfMTUh1DxSpc40ZpKSBN84GwiRSVzYNbzJfGzgah/uVlmAlJCacAIsyAUR ecqT9EA+GEY/QJEF37cC3dT3jBIG0afNVwdM1rZI47PBIy0GdVK2bfGoMmInmtYdtOK0PjTTgEwCP /8gh1pog==; Received: from c-73-162-206-103.hsd1.ca.comcast.net ([73.162.206.103]:35914 helo=[10.0.1.180]) by box5620.bluehost.com with esmtpsa (TLS1.3) tls TLS_AES_128_GCM_SHA256 (Exim 4.99.2) (envelope-from ) id 1wPFof-00000000mHd-2kFT; Tue, 19 May 2026 02:28:41 -0600 Message-ID: Date: Tue, 19 May 2026 01:28:40 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v5] riscv: cif: reduce shadow stack size limit from 4GB to 512MB To: Zong Li , pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr, debug@rivosinc.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, david.laight.linux@gmail.com References: <20260519071809.3823470-1-zong.li@sifive.com> Content-Language: en-US From: Ron Economos In-Reply-To: <20260519071809.3823470-1-zong.li@sifive.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5620.bluehost.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - w6rz.net X-BWhitelist: no X-Source-IP: 73.162.206.103 X-Source-L: No X-Exim-ID: 1wPFof-00000000mHd-2kFT X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: c-73-162-206-103.hsd1.ca.comcast.net ([10.0.1.180]) [73.162.206.103]:35914 X-Source-Auth: re@w6rz.net X-Email-Count: 2 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: d3NpeHJ6bmU7d3NpeHJ6bmU7Ym94NTYyMC5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfAu7gLWhTYfgZSu+cl2NGMDCXNK/EF17A5id7LFiRT7aODNcM1LWjVE4QwNnxHF5RR3n2Zg2ee/fdlISkPyFLhjOt5rWEie7AvTY7zb0M+xAX4caoGD5 1EInlLRm8r/FAbKJuDKOv3F3acinYF21X31yBwft2uNYcbAgR+QYQuXRaYNh80JbTqJMTijSJYW7JBapWkV2x9Ws2cAfDVn6jaY= On 5/19/26 00:18, Zong Li wrote: > Rationale: > > 1. Shadow stacks only store return addresses (8 bytes per entry), not > local variables, function parameters, or saved registers. A 512MB > shadow stack is far more than sufficient for any practical > application, even with extremely deep recursion. This size > maintains adequate while being more resource-efficient margin > > 2. On memory-constrained systems (e.g., platforms with only 4GB of > physical memory, which is a common configuration), allocating 4GB > of virtual address space for shadow stack per process/thread can > lead to virtual memory allocation failures when the overcommit mode > is set to OVERCOMMIT_GUESS or OVERCOMMIT_NEVER: > Error: "__vm_enough_memory: not enough memory for the allocation" > > Suggested-by: David Laight > Signed-off-by: Zong Li > --- > > Changed in v4: > - Fix wrong subject. It is 512MB instead of 2GB > > Changed in v3: > - Remove max(). PAGE_ALIGN() already rounds up > - Change stack size to RLIMIT_STACK/8 with SZ_512M cap. Suggested by David Laight > > Changed in v2: > - Add max() in case RLIMIT_STACK is smaller than PAGE_SIZE. Suggested by > Paul Walmsley and Sashiko > > Changed in v1: > - Use min() instead of min_t(). Suggested by David Laight > > arch/riscv/kernel/usercfi.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/arch/riscv/kernel/usercfi.c b/arch/riscv/kernel/usercfi.c > index 6eaa0d94fdfe..2036918a77db 100644 > --- a/arch/riscv/kernel/usercfi.c > +++ b/arch/riscv/kernel/usercfi.c > @@ -109,15 +109,15 @@ void set_indir_lp_lock(struct task_struct *task, bool lock) > task->thread_info.user_cfi_state.ufcfi_locked = lock; > } > /* > - * If size is 0, then to be compatible with regular stack we want it to be as big as > - * regular stack. Else PAGE_ALIGN it and return back > + * The shadow stack only stores the return address and not any variables > + * 512M should be more than sufficient for most applications. > */ > static unsigned long calc_shstk_size(unsigned long size) > { > if (size) > return PAGE_ALIGN(size); > > - return PAGE_ALIGN(min_t(unsigned long long, rlimit(RLIMIT_STACK), SZ_4G)); > + return PAGE_ALIGN(min(rlimit(RLIMIT_STACK) / 8, SZ_512M)); > } > > /* Just FYI, your V2 version of this patch was merged in Linux 7.1-rc4 (commit 6c7674b5b7ae513cecae22aa9dcdcf533862cf5c). You need to rebase, otherwise this patch won't apply.