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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 53ADFC32771 for ; Wed, 21 Sep 2022 21:52:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DE6CE94000B; Wed, 21 Sep 2022 17:52:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D9640940008; Wed, 21 Sep 2022 17:52:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BEA0A94000B; Wed, 21 Sep 2022 17:52:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id B1398940008 for ; Wed, 21 Sep 2022 17:52:09 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 87B89A12DC for ; Wed, 21 Sep 2022 21:52:09 +0000 (UTC) X-FDA: 79937441178.30.DFC038E Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) by imf12.hostedemail.com (Postfix) with ESMTP id 3C6A840064 for ; Wed, 21 Sep 2022 21:52:09 +0000 (UTC) Received: by mail-pf1-f177.google.com with SMTP id 9so7286559pfz.12 for ; Wed, 21 Sep 2022 14:52:09 -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=0RbPUnpKj0YucaSZFi1+HcifLXRp1N0CvMDzyoeI2GIzCfGfjnZWdqf0h0mrjd8m4g kpC5+V/uvdzD+GRg5+CKZyNTkxtVH+SkBL49F1LAbsvEbLkmCTJAgyCWg6RMjtdmKhGj nu5OQhcgokQcOAe1bOXh1OevfNPJgfeQP8Wvzrl2u2nJ91bQPcGIi/ANNHT2xIOPl1dC 2RwFWUGLVVLxf1PeWaaZ6IM3Ox3D7pCC3yvlzQJ1WfwTUKlnVg5FhIP6itO8jbLqxBpl IkRV6Jj0CDvhNhKxXuttGqHnm3lmmdy2e/ximE09SrA+GEUuX3jbdUprnpAEm3vycGxb l2iw== X-Gm-Message-State: ACrzQf3Gr7Pjo4t3iW0VnEPwMJzVqktW5IoBDW5DuPD1HKwS3FaNkI0c A6HR48r7N5pceh8SmR4onzWOhQ== X-Google-Smtp-Source: AMsMyM6FMnAlPzLX6rQkFOPQ7u/0N7HhlBrs8TUoKv04qZnD51TCGGWzU6DRjlPULYMOq1ht5Z7b9w== 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 To: 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663797129; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=pVu+lnUdwFy/wDRUvSag5pYFGjTAxbn9RAYMOsiPMes=; b=26Gn7lBpUcl4B0Z3JzjMqjlJwxDQ9w9rkfQDemvPkkm3ZZEjfEoXbzXDGm9ANYKbxFXzLD IkvxpmlCeq9XbypzrMiXnIk3iMcLvbgIKWlAWriheKRZ/0NK912oulgd6rARdkr6E/ljIW 9DoZHsFuiM1f7MLsMyCibZkNY6qDvDY= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=8CHGaUK4; spf=pass (imf12.hostedemail.com: domain of stillson@rivosinc.com designates 209.85.210.177 as permitted sender) smtp.mailfrom=stillson@rivosinc.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663797129; a=rsa-sha256; cv=none; b=gDCnZfYWmYMXzww2ETej1/LccyimBcVABNAbdFpDFpKp1Xza01PPaZQrG+yy8KiOq8UBRp 6ZgPHiHO9sKTZnpcnGpl0JxyWzjEOA1+eHSY5zysgj9DmiqbsmvG/cHsHEfqBLWM0hbp6/ nkbxOTlVadCuqZD2lJ27QXdQIefLcbc= X-Stat-Signature: hcksoczrujk8poextsts8fqfwqr6zt6z X-Rspamd-Queue-Id: 3C6A840064 X-Rspam-User: Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=8CHGaUK4; spf=pass (imf12.hostedemail.com: domain of stillson@rivosinc.com designates 209.85.210.177 as permitted sender) smtp.mailfrom=stillson@rivosinc.com; dmarc=none X-Rspamd-Server: rspam09 X-HE-Tag: 1663797129-347612 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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