From patchwork Tue Dec 10 14:23:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yong-Xuan Wang X-Patchwork-Id: 13901546 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7068EE7717F for ; Tue, 10 Dec 2024 14:41:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=j1L0RJKNmHjTwsFnBcp6cwLjujkn8ANf6jITKfN91hI=; b=Gi4fdgctE4V7L8 S9EnwLM+I2lTeM2w3VlbjEH1/AGysPi4LtlmnfBD4Z4i2F8VNr5wMYCXIX+ShIURAu2pIQ11FTolJ pn+9KlISEN+gC3PDVn4GuaTQw+9g6ntF0EoGNw3xcTXKgG1D5K5nqvQZ6sEw+qXGZ7jfdVtRgQFUD qFC+Q9nnCGZ6Cv6loHbfNbPP1ld6E/CLp/ThOvn/FQruukpKXPLgh3sK8/3bDQspRl1WMOHmLPSgk Zc1aPEX0Ly6d2BDlWPBprEvLG1xz0ou60tPP/0mUymmWmZxnZVdlCWnu6vNqmlN1dob0xCQOhWDlD G6k5WQzxv96Hw/NNRVvw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tL1Q0-0000000BoBr-1aet; Tue, 10 Dec 2024 14:40:56 +0000 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tL19m-0000000BkA1-2b8m for linux-riscv@lists.infradead.org; Tue, 10 Dec 2024 14:24:11 +0000 Received: by mail-pj1-x1034.google.com with SMTP id 98e67ed59e1d1-2ef89dbd8eeso2081287a91.0 for ; Tue, 10 Dec 2024 06:24:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1733840649; x=1734445449; darn=lists.infradead.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=5cyw5f/C2V37Mp3ln9xoUKSHP1fOBqKDeQ6bS/ukoVw=; b=Dq5Vn706TDH1XURtG3HyBy4xbGcLp7HUjr89p8hfJyys/XgEWaJa3zlxKhHArqEmOH 2E2POdfM4wT56bPu57t7HFMr3JpeHd36nL8S7oOK8r6QofyJ6riDxHSPmop9H6xMUf+p P9fiBbwbMm6m8J9v7hyX9oVleCGI4ODfwKpDHqgAU2SgYzaZ8Szc/pTpb8g4/7MVJCqX zTkyX+1SXjyHZeVieDWppuykCepiP1Ca5e+KFSabOO44EyAa2A3xwdshgWp2S4GQwIya H9YxV5i4BCRG0Gvbw+NdhtFRw3rbYFsVmjOaH5Dv6WPulLiQ4bDF3KG82g9qPQGU91zZ wGxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733840649; x=1734445449; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=5cyw5f/C2V37Mp3ln9xoUKSHP1fOBqKDeQ6bS/ukoVw=; b=QHvMifTHlnKO9awuh3jaaIxsjF2vQcdmH7qsRg+RpYJE/WxmIKKxT0O9mNjxIkwFj3 EkLUKjD+cHKcwUPa2vaPD65cUNjc++ozfHnUW2fyKD4gPD0l3Ep1rF/UDcPr5If9Elr3 j2YoOKCChyauaZ0zauAL9M/Ant5RS7KMuL+OpC5jfoDjmtt8JChD6tMWbz6jBb8BetzM KSIK1ii80E2OIwCyEzBrt2vcNum+a4/yLA1kESHl2+yByhWqihavQ7M0NX8L8SaWcz3w y1ANJsIYd3uFHipYX0trvCu+0hbNTVuBuhLSEHF2YtutWiuotOkgaulbapVVA5wJTnzb oU7Q== X-Forwarded-Encrypted: i=1; AJvYcCW0EISnOJP6BlQBkVSAoc4z6yvjYcwPjAte8mLgQCkkzcU1naNJpBWUym9kNr/jX5ZrYBBFM7Y5T224og==@lists.infradead.org X-Gm-Message-State: AOJu0YyETDNXpRiA1JZQZWs90FWiZ61UMsL/IBimPNWNps7vltSX4I/T 3leiLg2n+E/wopD3pZCUsaFXGa71t/xKOsnz/9LUKOvt+3Boa2GnQA2TocfnD/Q= X-Gm-Gg: ASbGncsYn98EU7Uf5PfK+KFg6hPMVF5JxUNjMabQTf/sTSPnzEFeBWnCPiln0V+9gWy 7dsWVfej7aRgWjfDCFxck8Mu3U7NLfFLTu94wAYydrE+qATH/eHlDfk0bdTK/0uiCLQt70ceI+P /aO7sKRtIOaBmP1EHXA/kTANbMn/YmUQVT86dc+AwQtmRqHC6fLTTUtoSA27gziiPGlK0TNoP1A GIZ3443qLZ5oQDZ3AGh7wZgAGyli3H0Z6CbND7+UfwJYgvu6tvGwlpZNox7xXaZer/g9TjbmsBq nGPC6/CR X-Google-Smtp-Source: AGHT+IF/eLNCS1WvrJyj5WY1drdW6oiQGMzfyH0Ke6hYhFaWTOwYF6DioSEMu//To8sMbC82xu9nsA== X-Received: by 2002:a17:90b:5205:b0:2ee:d7d3:3019 with SMTP id 98e67ed59e1d1-2ef69fffa68mr29462379a91.12.1733840649478; Tue, 10 Dec 2024 06:24:09 -0800 (PST) Received: from hsinchu26.internal.sifive.com ([210.176.154.34]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2ef7315fd3asm7538444a91.44.2024.12.10.06.24.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2024 06:24:09 -0800 (PST) From: Yong-Xuan Wang To: linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Cc: greentime.hu@sifive.com, vincent.chen@sifive.com, Yong-Xuan Wang , Paul Walmsley , Palmer Dabbelt , Albert Ou , Andy Chiu , Zong Li , Conor Dooley , Zhongqiu Han , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Ben Dooks , Heiko Stuebner Subject: [PATCH 1/2] riscv: signal: fix signal frame size Date: Tue, 10 Dec 2024 22:23:49 +0800 Message-Id: <20241210142353.6457-2-yongxuan.wang@sifive.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20241210142353.6457-1-yongxuan.wang@sifive.com> References: <20241210142353.6457-1-yongxuan.wang@sifive.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241210_062410_657648_FCB384C1 X-CRM114-Status: UNSURE ( 7.77 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org The signal context of certain RISC-V extensions will be appended after struct __riscv_extra_ext_header, which already includes an empty context header. Therefore, there is no need to preserve a separate hdr for the END of signal context. Fixes: 8ee0b41898fa ("riscv: signal: Add sigcontext save/restore for vector") Signed-off-by: Yong-Xuan Wang Reviewed-by: Zong Li Reviewed-by: Andy Chiu --- arch/riscv/kernel/signal.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/arch/riscv/kernel/signal.c b/arch/riscv/kernel/signal.c index dcd282419456..c3c517b9eee5 100644 --- a/arch/riscv/kernel/signal.c +++ b/arch/riscv/kernel/signal.c @@ -215,12 +215,6 @@ static size_t get_rt_frame_size(bool cal_all) if (cal_all || riscv_v_vstate_query(task_pt_regs(current))) total_context_size += riscv_v_sc_size; } - /* - * Preserved a __riscv_ctx_hdr for END signal context header if an - * extension uses __riscv_extra_ext_header - */ - if (total_context_size) - total_context_size += sizeof(struct __riscv_ctx_hdr); frame_size += total_context_size; From patchwork Tue Dec 10 14:23:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yong-Xuan Wang X-Patchwork-Id: 13901547 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2D4FCE7717F for ; Tue, 10 Dec 2024 14:41:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=f9T7xhf8/e/IR1ozR427FJGthCDnxkA08GcwcStjBJk=; b=EMAO9ga8chyVuI 45GyfskwdJliDrzrbvJgMFm2bylcwQIQm82ok3cA9c8slH+Vji4ZP/Yqi390iWCzjWGtfMB/SwLP3 6cvwVkcqbBOBe1F89iAzjQTWcJl97Gjfwz/9CJiqd3KUGfu21H64ku2Wq63gEQzYa28dTHHk5hxs5 ZnejKLs8mjIQQ32RKAxLKbpRmQRXdOWRZpl18DvB6M9nR7oun1ARuh0m7cqtTmm2zEqrma86Dfd/e yNfCr7LQod8bPkSzsZoY1gGVPBXGHyODIKSAb2Mxwky5P/ocCrsNAwbOKMfgCRpM9IeA+D7Mh7HJ3 VLvZngco2zDwpsXYdQ0g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tL1Q1-0000000BoCM-0E74; Tue, 10 Dec 2024 14:40:57 +0000 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tL19r-0000000BkCD-43n2 for linux-riscv@lists.infradead.org; Tue, 10 Dec 2024 14:24:17 +0000 Received: by mail-pj1-x102a.google.com with SMTP id 98e67ed59e1d1-2ef89dbd8eeso2081411a91.0 for ; Tue, 10 Dec 2024 06:24:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1733840655; x=1734445455; darn=lists.infradead.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=K5qH0MfXKfA82FtJGAtiD9e44kpeNSF59qHyzqUktew=; b=iJQzriXYEGU1HkAcU7XrZ6TlnEf1ef9+2orhzR2WN/Y0nIdcV/WftgNWzwzHie+9C5 HAjb86M1bHa6oDgA+iJc6BGIUGpXF4E+W4dcOcjSunejRQ5+kjmETXGV56a9KmPu2aZI UA1OGCkQgMalAMWLDZP5ng5y8L91HSti80bPYN4txltxLYl0UybVViNQQrvpcY52eZv5 jC7JqqLiYf4H283Uc+A4RFDOagrqIyCSd8D+FlxmUbiW/79N4cTTKga5zhgsQboN12d/ ozsELJH8e1dLbtTGw3WHAtgypNFLhnLte3rl1VStiTv4IacM8Vr4JWjXoTPsfozDB/OM W/Ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733840655; x=1734445455; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=K5qH0MfXKfA82FtJGAtiD9e44kpeNSF59qHyzqUktew=; b=OHY2p3MmFq9qD0PkKKD1Oj5l0ksMhgs3eu1QKh20mWHKibQpWeITE8rUmyHbknlPw1 nJyNDRSfDXsDg/Iyf8vy1KyWvSZUfLqnTtTV2fzRPmOFBp79Yp8eXSyh8cjLs+U/suOE I7Iy6hK19MjmVoA+3WIapu4bqV3DbZWAbI5bqwr2ngLLf5VSdHC7QqZKq9Jfe6xvpzwt 2k6G3Cg8YFgIEItuoiwtBHTWavUO4GwG61lax2UsGm6bdQWUyqFQmBdHecvBzrUE2Bw0 RNx6439BNeM74KSADOxtjnEHt3Yn54zRdRsE4Oh655t9zZmg+V4B7UKNi3s+jiqMc9jf NbcQ== X-Forwarded-Encrypted: i=1; AJvYcCVr5YJWj8V5B2mOpn1qE6Bo7xTta3o/ZBpFLFyhPluRizHUVhQA2JbIkj+Dmr0t3F6HMfQPr8CqApaBDw==@lists.infradead.org X-Gm-Message-State: AOJu0Yz+burZbg1WO3PD0/HJa2mwYLx+Vqqk4lNXnh9aYi6E7uMCSfjc Skbuqzetf3kyTQn+O4H9Lf5AkLXENKfkvQT+s+1fju07oXLHUrIVxsTfgCxNjpw= X-Gm-Gg: ASbGncvLwixdJ8SwVP/8oF4AvTgiTHqGVf+jNkUDr4SVeelfcazfwIXDGBqUsUJeEFD Ovb/s4scYf6fR+XR0qWoSNlrl2pQtF7Armdj81aqPsiH56ZtGppep1OG7YAHfB3I2LRnLE5LOFP mvcVvOBD2HOnG1u2Vfs7JzTELXRjeWpvRCiVk8BLDuQTNEXyggBbuOSw9DJGpROer9peUwwJ5bN um/kroBrP7rr18uqbY5wyB6dbD0WjF2uLgbF/W8/RSChGm6PBzLGJing3Bk7Jn5HW06m7p/2S4G /c1meB8C X-Google-Smtp-Source: AGHT+IE4HixJrIDtqZonmKGjORacp6uNTwKs9GuvdA/FUm9KmXGsasElmICG8/zrqS2NRhVFZTIRCA== X-Received: by 2002:a17:90b:52d0:b0:2ee:741c:e9f4 with SMTP id 98e67ed59e1d1-2ef69fffa77mr23841080a91.11.1733840654766; Tue, 10 Dec 2024 06:24:14 -0800 (PST) Received: from hsinchu26.internal.sifive.com ([210.176.154.34]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2ef7315fd3asm7538444a91.44.2024.12.10.06.24.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2024 06:24:14 -0800 (PST) From: Yong-Xuan Wang To: linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Cc: greentime.hu@sifive.com, vincent.chen@sifive.com, Yong-Xuan Wang , Paul Walmsley , Palmer Dabbelt , Albert Ou , Andy Chiu , Zong Li , Conor Dooley , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Zhongqiu Han , Ben Dooks , Guo Ren , Heiko Stuebner Subject: [PATCH 2/2] riscv: signal: fix signal_minsigstksz Date: Tue, 10 Dec 2024 22:23:50 +0800 Message-Id: <20241210142353.6457-3-yongxuan.wang@sifive.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20241210142353.6457-1-yongxuan.wang@sifive.com> References: <20241210142353.6457-1-yongxuan.wang@sifive.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241210_062416_003261_13ED17BF X-CRM114-Status: GOOD ( 16.86 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org The init_rt_signal_env() funciton is called before the alternative patch is applied, so using the alternative-related API to check the availability of an extension within this function doesn't have the intended effect. Instead, the riscv_isa bitmap should be used to properly check whether given extension is available. This patch also refactors the estimation of signal_minsigstksz by extracting it from the get_rt_frame_size() funciton. Fixes: e92f469b0771 ("riscv: signal: Report signal frame size to userspace via auxv") Signed-off-by: Yong-Xuan Wang Reviewed-by: Zong Li --- arch/riscv/kernel/signal.c | 40 ++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/arch/riscv/kernel/signal.c b/arch/riscv/kernel/signal.c index c3c517b9eee5..85eac84719e9 100644 --- a/arch/riscv/kernel/signal.c +++ b/arch/riscv/kernel/signal.c @@ -203,22 +203,18 @@ static long restore_sigcontext(struct pt_regs *regs, return err; } -static size_t get_rt_frame_size(bool cal_all) +static size_t get_rt_frame_size(struct pt_regs *regs) { struct rt_sigframe __user *frame; - size_t frame_size; + size_t frame_size = sizeof(*frame); size_t total_context_size = 0; - frame_size = sizeof(*frame); - - if (has_vector()) { - if (cal_all || riscv_v_vstate_query(task_pt_regs(current))) - total_context_size += riscv_v_sc_size; - } + if (has_vector() && riscv_v_vstate_query(regs)) + total_context_size += riscv_v_sc_size; frame_size += total_context_size; - frame_size = round_up(frame_size, 16); + return frame_size; } @@ -228,7 +224,7 @@ SYSCALL_DEFINE0(rt_sigreturn) struct rt_sigframe __user *frame; struct task_struct *task; sigset_t set; - size_t frame_size = get_rt_frame_size(false); + size_t frame_size = get_rt_frame_size(regs); /* Always make any pending restarted system calls return -EINTR */ current->restart_block.fn = do_no_restart_syscall; @@ -318,7 +314,7 @@ static int setup_rt_frame(struct ksignal *ksig, sigset_t *set, struct rt_sigframe __user *frame; long err = 0; unsigned long __maybe_unused addr; - size_t frame_size = get_rt_frame_size(false); + size_t frame_size = get_rt_frame_size(regs); frame = get_sigframe(ksig, regs, frame_size); if (!access_ok(frame, frame_size)) @@ -465,19 +461,33 @@ void arch_do_signal_or_restart(struct pt_regs *regs) void init_rt_signal_env(void); void __init init_rt_signal_env(void) { - riscv_v_sc_size = sizeof(struct __riscv_ctx_hdr) + - sizeof(struct __sc_riscv_v_state) + riscv_v_vsize; + struct rt_sigframe __user *frame; + size_t frame_size = sizeof(*frame); + + /* + * init_rt_signal_env() is called before applying alternative patch. Do not use + * __riscv_has_extension_likely()/__riscv_has_extension_unlikely() to check the + * availiablity of an extension in this function. + */ + if (__riscv_isa_extension_available(NULL, RISCV_ISA_EXT_v)) { + riscv_v_sc_size = sizeof(struct __riscv_ctx_hdr) + + sizeof(struct __sc_riscv_v_state) + riscv_v_vsize; + frame_size += riscv_v_sc_size; + } + + frame_size = round_up(frame_size, 16); + /* * 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 = get_rt_frame_size(true); + signal_minsigstksz = frame_size; } #ifdef CONFIG_DYNAMIC_SIGFRAME bool sigaltstack_size_valid(size_t ss_size) { - return ss_size > get_rt_frame_size(false); + return ss_size > get_rt_frame_size(current_pt_regs()); } #endif /* CONFIG_DYNAMIC_SIGFRAME */