Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp5947058rwb; Wed, 21 Sep 2022 15:05:30 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4RwXZXxhzNe6j/iMIDJBRDh97XH141PfyHU09cwpweMBQY5LhsesOppRtrvQTlpxTTKhh7 X-Received: by 2002:a17:907:2d21:b0:77d:4f86:2e65 with SMTP id gs33-20020a1709072d2100b0077d4f862e65mr327280ejc.58.1663797930552; Wed, 21 Sep 2022 15:05:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663797930; cv=none; d=google.com; s=arc-20160816; b=VeoWlcO2tQtL7NiEdwizyrj7W5qfddZsHM+5VroSagLBwjtJDThgBdsnSZVu4RLTSY zOLEUi4FfFjvO/wfDhEtV2GTVIDMWbhyn2GM/wuVDC3O0G6KR0oCzsrmfAEB7uqlXiV/ PZPSUxkt+wyqwkDBwuZxTPyMtN83YOtGIqxGRNHTe2JBBWryd8cd4lRIE9W7upaLpaaq M2zc3JglZBdoi8fNyOyuAP571078x51GYdmSQVp98GKbHeANReNpIxz3BDbcQDk4Cx86 sNYHEdiWx2yUNPtCAwMcq/G4unAW3L4DofycUGejBRNJkKHqT+Snnz7JrttAaL52FerN +y/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from :dkim-signature; bh=pVu+lnUdwFy/wDRUvSag5pYFGjTAxbn9RAYMOsiPMes=; b=dmreNwlr/3sEF29ckZOO2XAvU5rGQacf+xyCX3MlnFZMU+yfdlaUq8zI0KL4jrLzC6 LjFlZwJEarvvkSkv4xEfQb+ajWaMjA+rjd9DF2LS2buRhLM/kTRuzZQE7cB01uWXVuRZ MTVWcqWvCuqJ3qbpji+232TmqDES5NFEKuYNXpvRzsmH7rhrslAn3PPva+G7JrBV80pX wmrZjKdB4GuRo+Ecd2szGIKmBNxTjOimnXpFQqE+/FyVISxoVJ/sLRYfpSmMEhp3HnnR Ie72i+COT+v9KwKUGaxI7CK3am8gF3jfm7TlvGoizauo2Cl+kdL9mgv1qBgQH5ZoZFqA +krw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=8CHGaUK4; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n14-20020a05640205ce00b004537e9a25absi4294522edx.193.2022.09.21.15.04.58; Wed, 21 Sep 2022 15:05:30 -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=fail header.i=@rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=8CHGaUK4; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229459AbiIUVwt (ORCPT + 99 others); Wed, 21 Sep 2022 17:52:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231140AbiIUVwK (ORCPT ); Wed, 21 Sep 2022 17:52:10 -0400 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1C24A7218 for ; Wed, 21 Sep 2022 14:52:08 -0700 (PDT) Received: by mail-pf1-x42c.google.com with SMTP id a80so7327512pfa.4 for ; Wed, 21 Sep 2022 14:52:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=pVu+lnUdwFy/wDRUvSag5pYFGjTAxbn9RAYMOsiPMes=; b=8CHGaUK43VPwaGKy6s0v+4rvx8e033MGQ0SVpV4G3yEDK9Rayoa+OmMR4d3cZNv0Js Ry462tUhf7bod6gBC3mSi/AUOCOl6zUlehF2vJXCAtdQi6W2KDSXX9z22wuPhEdIwNht WBuojWsf+k2PdKRXrDU9uVPMlm91kPVKyFk1ZlLtkFTpoG3Zos969R++Fn2IuIdMoIHt 75KzcQgVLxsbvb3L2eSWfk239Zf6ZvguwHSCj+j8ILd0De26lg0d82tGdpmMwh2PJsoR 59S5RANER+k798B0zKzQVrxtcWj7uJGh4Sj5mmLrux2BdcAG7TelJKVJf3pHMggnY2lR m1/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=pVu+lnUdwFy/wDRUvSag5pYFGjTAxbn9RAYMOsiPMes=; b=po7j7xfgDCXZNvNgPS73OJ4GQGAzs8d3BOwGUycJdCesYEg/tkLijviRaJfFr4OIeB mWtK/CKgTAuFP8SZAWAWIuZfGWzPdDnKt3R/94rsss7DTbYedDsgaP9R0Md/puZuP6dx CwNWzqLW8qZBb10+KCwcVLunTXUpaXxc2qgWtv4AofPm5YIwXT/GVEpbDfhcz7XNe7Ib Vvh4sGRGb86ScyguHK9NoVAOYRhVZdMlJ0nlLbi6gktQTI3sL/1qEvjIoJ8BLMV4FlON SSHK3aHMJUxFQcMdLl8vsUulPnMXvJMWPY2hOk928leexrjnJVYMV1/Dg9OwrrFXKenl U13w== X-Gm-Message-State: ACrzQf0A0LmBDqZe1SoS8c+JL6ESjPHa8UHI0PGILgZuCNKzEJ9oP0km cf8u8CulCvPzMGgHwYdnFWGTuw== X-Received: by 2002:a63:85c3:0:b0:43a:4c05:c313 with SMTP id u186-20020a6385c3000000b0043a4c05c313mr242802pgd.418.1663797128343; Wed, 21 Sep 2022 14:52:08 -0700 (PDT) Received: from stillson.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id k7-20020aa79727000000b005484d133127sm2634536pfg.129.2022.09.21.14.52.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Sep 2022 14:52:07 -0700 (PDT) From: Chris Stillson Cc: Vincent Chen , Greentime Hu , Paul Walmsley , Palmer Dabbelt , Albert Ou , Eric Biederman , Kees Cook , Anup Patel , Atish Patra , Oleg Nesterov , Guo Ren , Heinrich Schuchardt , Arnaud Pouliquen , Conor Dooley , Chris Stillson , Paolo Bonzini , Qinglin Pan , Alexandre Ghiti , Arnd Bergmann , Heiko Stuebner , Dao Lu , Jisheng Zhang , "Russell King (Oracle)" , Sunil V L , Ruinland Tsai , Han-Kuan Chen , Li Zhengyu , Alexander Graf , Ard Biesheuvel , Tsukasa OI , Yury Norov , "Paul E. McKenney" , Mark Rutland , Frederic Weisbecker , Changbin Du , Myrtle Shah , Vitaly Wool , Catalin Marinas , Mark Brown , Will Deacon , Janosch Frank , Alexey Dobriyan , Huacai Chen , Christian Brauner , Evgenii Stepanov , Peter Collingbourne , Eugene Syromiatnikov , Colin Cross , Andrew Morton , Suren Baghdasaryan , Barret Rhoden , Davidlohr Bueso , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org Subject: [PATCH v12 11/17] riscv: signal: Report signal frame size to userspace via auxv Date: Wed, 21 Sep 2022 14:43:53 -0700 Message-Id: <20220921214439.1491510-11-stillson@rivosinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220921214439.1491510-1-stillson@rivosinc.com> References: <20220921214439.1491510-1-stillson@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,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 To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vincent Chen The vector register belongs to the signal context. They need to be stored and restored as entering and leaving the signal handler. According to the V-extension specification, the maximum length of the vector registers can be 2^(XLEN-1). Hence, if userspace refers to the MINSIGSTKSZ to create a sigframe, it may not be enough. To resolve this problem, this patch refers to the commit 94b07c1f8c39c ("arm64: signal: Report signal frame size to userspace via auxv") to enable userspace to know the minimum required sigframe size through the auxiliary vector and use it to allocate enough memory for signal context. Signed-off-by: Greentime Hu Signed-off-by: Vincent Chen --- arch/riscv/include/asm/elf.h | 47 +++++++++++++++------------- arch/riscv/include/asm/processor.h | 2 ++ arch/riscv/include/uapi/asm/auxvec.h | 1 + arch/riscv/kernel/signal.c | 8 +++++ 4 files changed, 36 insertions(+), 22 deletions(-) diff --git a/arch/riscv/include/asm/elf.h b/arch/riscv/include/asm/elf.h index 14fc7342490b..df9047b619e8 100644 --- a/arch/riscv/include/asm/elf.h +++ b/arch/riscv/include/asm/elf.h @@ -77,28 +77,31 @@ extern unsigned long elf_hwcap; #define COMPAT_ELF_PLATFORM (NULL) #ifdef CONFIG_MMU -#define ARCH_DLINFO \ -do { \ - /* \ - * Note that we add ulong after elf_addr_t because \ - * casting current->mm->context.vdso triggers a cast \ - * warning of cast from pointer to integer for \ - * COMPAT ELFCLASS32. \ - */ \ - NEW_AUX_ENT(AT_SYSINFO_EHDR, \ - (elf_addr_t)(ulong)current->mm->context.vdso); \ - NEW_AUX_ENT(AT_L1I_CACHESIZE, \ - get_cache_size(1, CACHE_TYPE_INST)); \ - NEW_AUX_ENT(AT_L1I_CACHEGEOMETRY, \ - get_cache_geometry(1, CACHE_TYPE_INST)); \ - NEW_AUX_ENT(AT_L1D_CACHESIZE, \ - get_cache_size(1, CACHE_TYPE_DATA)); \ - NEW_AUX_ENT(AT_L1D_CACHEGEOMETRY, \ - get_cache_geometry(1, CACHE_TYPE_DATA)); \ - NEW_AUX_ENT(AT_L2_CACHESIZE, \ - get_cache_size(2, CACHE_TYPE_UNIFIED)); \ - NEW_AUX_ENT(AT_L2_CACHEGEOMETRY, \ - get_cache_geometry(2, CACHE_TYPE_UNIFIED)); \ +#define ARCH_DLINFO \ +do { \ + NEW_AUX_ENT(AT_SYSINFO_EHDR, \ + (elf_addr_t)current->mm->context.vdso); \ + NEW_AUX_ENT(AT_L1I_CACHESIZE, \ + get_cache_size(1, CACHE_TYPE_INST)); \ + NEW_AUX_ENT(AT_L1I_CACHEGEOMETRY, \ + get_cache_geometry(1, CACHE_TYPE_INST)); \ + NEW_AUX_ENT(AT_L1D_CACHESIZE, \ + get_cache_size(1, CACHE_TYPE_DATA)); \ + NEW_AUX_ENT(AT_L1D_CACHEGEOMETRY, \ + get_cache_geometry(1, CACHE_TYPE_DATA)); \ + NEW_AUX_ENT(AT_L2_CACHESIZE, \ + get_cache_size(2, CACHE_TYPE_UNIFIED)); \ + NEW_AUX_ENT(AT_L2_CACHEGEOMETRY, \ + get_cache_geometry(2, CACHE_TYPE_UNIFIED)); \ + /* \ + * Should always be nonzero unless there's a kernel bug. \ + * If we haven't determined a sensible value to give to \ + * userspace, omit the entry: \ + */ \ + if (likely(signal_minsigstksz)) \ + NEW_AUX_ENT(AT_MINSIGSTKSZ, signal_minsigstksz); \ + else \ + NEW_AUX_ENT(AT_IGNORE, 0); \ } while (0) #define ARCH_HAS_SETUP_ADDITIONAL_PAGES struct linux_binprm; diff --git a/arch/riscv/include/asm/processor.h b/arch/riscv/include/asm/processor.h index 95917a2b24f9..a09141ecf6aa 100644 --- a/arch/riscv/include/asm/processor.h +++ b/arch/riscv/include/asm/processor.h @@ -7,6 +7,7 @@ #define _ASM_RISCV_PROCESSOR_H #include +#include #include @@ -86,6 +87,7 @@ int riscv_of_parent_hartid(struct device_node *node, unsigned long *hartid); extern void riscv_fill_hwcap(void); extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src); +extern unsigned long signal_minsigstksz __ro_after_init; #endif /* __ASSEMBLY__ */ #endif /* _ASM_RISCV_PROCESSOR_H */ diff --git a/arch/riscv/include/uapi/asm/auxvec.h b/arch/riscv/include/uapi/asm/auxvec.h index 32c73ba1d531..6610d24e6662 100644 --- a/arch/riscv/include/uapi/asm/auxvec.h +++ b/arch/riscv/include/uapi/asm/auxvec.h @@ -33,5 +33,6 @@ /* entries in ARCH_DLINFO */ #define AT_VECTOR_SIZE_ARCH 7 +#define AT_MINSIGSTKSZ 51 #endif /* _UAPI_ASM_RISCV_AUXVEC_H */ diff --git a/arch/riscv/kernel/signal.c b/arch/riscv/kernel/signal.c index 41d9a02c7098..fb1f5012416e 100644 --- a/arch/riscv/kernel/signal.c +++ b/arch/riscv/kernel/signal.c @@ -478,8 +478,16 @@ asmlinkage __visible void do_notify_resume(struct pt_regs *regs, resume_user_mode_work(regs); } +unsigned long __ro_after_init signal_minsigstksz; + void init_rt_signal_env(void); void __init init_rt_signal_env(void) { rvv_sc_size = sizeof(struct __sc_riscv_v_state) + riscv_vsize; + /* + * Determine the stack space required for guaranteed signal delivery. + * The signal_minsigstksz will be populated into the AT_MINSIGSTKSZ entry + * in the auxiliary array at process startup. + */ + signal_minsigstksz = cal_rt_frame_size(); } -- 2.25.1