Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp190949ybm; Wed, 27 May 2020 23:47:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxCxl8sDufQFIh/GgEiSWBrYIdjKABn12Kru2lE++1rBcaGsKZhj87VgmQie2yTzj4OpiJk X-Received: by 2002:aa7:cd0e:: with SMTP id b14mr1599973edw.319.1590648447577; Wed, 27 May 2020 23:47:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590648447; cv=none; d=google.com; s=arc-20160816; b=YGjLo/aq5wiyQcA96CIrsf05tyUdsuif/87VmYWvtXO80x3EoGp4laUDHRNTSQ8o6h VE1Oz3xPDgPeoZTuBGJ60uWigcoH5lalyHYRRmXedZJoYDS5u71hfzXL51nsvzGYVlwb pMmNHuU8AaKmZWL6DobJ0Bd6BL/Rprv2AY8si0UDDFFMlTbFpTF194mRGdE2/xdXLDYr ZCBHnO+jp3mvFbTMIpoR0mc1TH5qcWSdIm/mw5F4B/MlM78nCjV5CjeUXZ8uAf5v2LY5 SVsKQvN02AWz9V8JXzDEiu1Ub0CnEgnRSoC/zoRfpGRuzi15aKywSUFOEX9B7lR+cYbO NVNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=UTa6e4uati/mC1lpRGebfubs1gwZzy90fbCylq5T17w=; b=NCg3HQRkGPmdjXppfuhCq8xOaQElCSeuDbJ3b/M0sS1OfUDoaG6X+AnCZf969T6nCx MzLY1+2Nms4z/VJGOYCfPuF5MuhvhKZcHGI5/Bes+3SGa23TdV3+3R5w6tmY5FWFP9HD afw4YWfwQQquQucKnXl06JmMhRoXCpBcJLwIDz8FLmFMO0EhZY3M+q6j01zMHY9MZQcP 0BNBq+7c4TrSKGN2jmV6+W8yctWOQwvJb80W8AhZz9GsHbBX7Ql8Gf5Et4OfC9gnpl3M 7DYP8tlTTVeaM8fmow7UVleh9UIMQ7G+/3wR/QZCQAH/2SKPPvGt6NHepm5K6+RvNHUU zzsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=nBAgyVs7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e21si1757553edq.505.2020.05.27.23.47.04; Wed, 27 May 2020 23:47:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=nBAgyVs7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726883AbgE1Gls (ORCPT + 99 others); Thu, 28 May 2020 02:41:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726857AbgE1Glp (ORCPT ); Thu, 28 May 2020 02:41:45 -0400 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54CD6C05BD1E for ; Wed, 27 May 2020 23:41:45 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id e11so12035072pfn.3 for ; Wed, 27 May 2020 23:41:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=UTa6e4uati/mC1lpRGebfubs1gwZzy90fbCylq5T17w=; b=nBAgyVs7kuci9NuPXNtYk8Tb/OOy1i02RCbHGyKgq/9nN8fNht5vgWXkHSoPQ1JfS/ zSctN/LU6GXWJ4UVvmtyx0Pnn8XzuoHBzHa72o7y/FJIQUshImPMKxKJzjb6bFZUWXgS KtinXDUx1Mnk+wlUFWVwg1p5lvHvS2WbbK2Pbsf/u5mip+v7f7TgQmPcnyPnTNjIk3oR A/Rf1yJIt/54oXe2AjqPbgMhEwE/fi9keeBJiXW2YacbaAplKsnDCGPR63TMJFGxETqJ QKttRaozF522XuqveJVM6FOWiHDg1k4asLID008w2Sl4QW6wq25ylEgl/T0NqVwztzvR XlHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UTa6e4uati/mC1lpRGebfubs1gwZzy90fbCylq5T17w=; b=uDuhfoEUapVJzz2PAfQFtPPzJHWBO+SvtOXfrEqB1GIu/wAiIEAE6/fAEeR6KkygWP lcN0Zrci1Z1CeJ5R695YODgj3+BuPpgLRpSE/RzTwH1w3upyIsKe6OEve1OQSPQsNbEa Z4UaEp8qFw0vHXH9wsgkMNPxGJPDQWeSqAgT2Mscdznj5N73iGGV3Q0elvTSZPY4plFE Aunis6P2tKZp5jrgCz2LtO22wpXCBdNE5rA1qlOhksxpg32pwzUvCL8mJv9mKntdesWh XrbjHzEHTjRjz0QZ5s0uGM4IqI/UbglrR5aaHa8hqmjHVoYajwzvOlnR2MPjkSepXfbN BoFQ== X-Gm-Message-State: AOAM531SBncngUk3ZLmPw3NJ3YcJKiwtIev6TI7O4/JAFJOnCXwUYK+g 2H1cXm9TiZ7oKBFI1Eba24YGtA== X-Received: by 2002:a63:a36e:: with SMTP id v46mr1472228pgn.378.1590648104866; Wed, 27 May 2020 23:41:44 -0700 (PDT) Received: from hsinchu02.internal.sifive.com (114-34-229-221.HINET-IP.hinet.net. [114.34.229.221]) by smtp.gmail.com with ESMTPSA id q29sm3773366pfg.79.2020.05.27.23.41.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 May 2020 23:41:44 -0700 (PDT) From: Greentime Hu To: greentime.hu@sifive.com, guoren@linux.alibaba.com, vincent.chen@sifive.com, paul.walmsley@sifive.com, palmerdabbelt@google.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, oleg@redhat.com Subject: [RFC PATCH v5 13/13] riscv: signal: Report signal frame size to userspace via auxv Date: Thu, 28 May 2020 14:41:01 +0800 Message-Id: X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org 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 #define (2KB) 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: Vincent Chen --- arch/riscv/include/asm/elf.h | 17 +++++++++++++---- arch/riscv/include/asm/processor.h | 2 ++ arch/riscv/include/uapi/asm/auxvec.h | 2 ++ arch/riscv/kernel/setup.c | 5 +++++ arch/riscv/kernel/signal.c | 16 ++++++++++++++++ 5 files changed, 38 insertions(+), 4 deletions(-) diff --git a/arch/riscv/include/asm/elf.h b/arch/riscv/include/asm/elf.h index d83a4efd052b..b6b15fc5f784 100644 --- a/arch/riscv/include/asm/elf.h +++ b/arch/riscv/include/asm/elf.h @@ -57,10 +57,19 @@ extern unsigned long elf_hwcap; #define ELF_PLATFORM (NULL) #ifdef CONFIG_MMU -#define ARCH_DLINFO \ -do { \ - NEW_AUX_ENT(AT_SYSINFO_EHDR, \ - (elf_addr_t)current->mm->context.vdso); \ +#define ARCH_DLINFO \ +do { \ + NEW_AUX_ENT(AT_SYSINFO_EHDR, \ + (elf_addr_t)current->mm->context.vdso); \ + /* \ + * 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 217273375cfb..5be2da702897 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 @@ -79,6 +80,7 @@ int riscv_of_processor_hartid(struct device_node *node); extern void riscv_fill_hwcap(void); +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 d86cb17bbabe..9745a01e5e61 100644 --- a/arch/riscv/include/uapi/asm/auxvec.h +++ b/arch/riscv/include/uapi/asm/auxvec.h @@ -10,4 +10,6 @@ /* vDSO location */ #define AT_SYSINFO_EHDR 33 +#define AT_MINSIGSTKSZ 51 + #endif /* _UAPI_ASM_RISCV_AUXVEC_H */ diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c index 145128a7e560..6220e25ea9b0 100644 --- a/arch/riscv/kernel/setup.c +++ b/arch/riscv/kernel/setup.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -62,6 +63,8 @@ void __init parse_dtb(void) #endif } +extern void __init minsigstksz_setup(void); + void __init setup_arch(char **cmdline_p) { init_mm.start_code = (unsigned long) _stext; @@ -95,6 +98,8 @@ void __init setup_arch(char **cmdline_p) #endif riscv_fill_hwcap(); + + minsigstksz_setup(); } static int __init topology_init(void) diff --git a/arch/riscv/kernel/signal.c b/arch/riscv/kernel/signal.c index 9ada6f74bb95..4f81251867e6 100644 --- a/arch/riscv/kernel/signal.c +++ b/arch/riscv/kernel/signal.c @@ -404,3 +404,19 @@ asmlinkage __visible void do_notify_resume(struct pt_regs *regs, tracehook_notify_resume(regs); } } + +unsigned long __ro_after_init signal_minsigstksz; + +/* + * Determine the stack space required for guaranteed signal devliery. + * This function is used to populate AT_MINSIGSTKSZ at process startup. + * cpufeatures setup is assumed to be complete. + */ +void __init minsigstksz_setup(void) +{ + signal_minsigstksz = sizeof(struct rt_sigframe); +#ifdef CONFIG_VECTOR + if (has_vector) + signal_minsigstksz += riscv_vsize; +#endif +} -- 2.26.2