From patchwork Fri Mar 17 11:35:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Chiu X-Patchwork-Id: 1758241 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=acfu6FN6; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.a=rsa-sha256 header.s=google header.b=kgz33J1K; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PdMZJ269vz2470 for ; Fri, 17 Mar 2023 22:38:00 +1100 (AEDT) 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=8qT6AT1ot4UiXwQMsjKm3iCnKGvW6vDEq9bWKmdplzA=; b=acfu6FN6I+YGFd qfZEOK1fgw831YWarwNAIHvAHkRKMOt4OloduoRU7F08JDnukC5m94UaXDz2JRRCteMkjC6aWsxnX 0sr4ts47YIXV1nWY3webm9Dw9Vpw+jN3ooaz2wfY9E8Eh3aGRp0CFo31SteaaXg4IxgqktZluWsyj 82ChDkmWXglgDP6uXvNrAJJ3Zz1ubH9bQEFiYr67fFkTQ1J686pihHJh/Ew3FlnZ8DnyHJyBM6haO 6FKgwht7Ed+uMibsdOzQBOenXYszsvkTm0L90npZyyYQN1g5iBRngRWh8eR5+7fYQCXVTjM1p+UTk NJd5OydlBvlCk8RXmDjw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pd8PD-0025gC-2q; Fri, 17 Mar 2023 11:37:55 +0000 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pd8PB-0025LB-0Y for kvm-riscv@lists.infradead.org; Fri, 17 Mar 2023 11:37:54 +0000 Received: by mail-pl1-x62d.google.com with SMTP id h8so4971791plf.10 for ; Fri, 17 Mar 2023 04:37:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1679053073; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=+aD01a07TD9YiAyArNVpoWUMoGh41bK5OsvLALwwGTk=; b=kgz33J1KTriakXGsceNyZdDcVQmgksAsmhVAl/JM3kI+JZxyb7q9TueRxzUxqrnVL2 kZ1EPX+wNxy+z5TjRoyR5BMjusEV+Jg6LxJHWmM63Elm3em3Y7vFS720jxtTKOgj1k/H gY3ZfvYcvi0ErSlRIpNvm3Xq2umG0E47PJJA/9gNsWMMG/XMpB3fb5I3vZ/akzgBmYlj 8GVJxiSl+BAdndoDCsSv3H8mfB4HiU/jlGF7zHOhoSiIsVueDXlJ6O9iOZDKvhUADYpe IdiqrLUuq/jRHt6/pLTAwAVDHf4fGULXgYZKDH0z3U7JduJGGKkW9HGS3vD3G9S6pHjm sVwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679053073; 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=+aD01a07TD9YiAyArNVpoWUMoGh41bK5OsvLALwwGTk=; b=tOgrLrfRlfw0uaWrHgkJjANaFDTYhSHNM2GDqvW0FohE81mF7gwCel5biz0bJVg/5B LkQ/n64FB6BrsVomN/2zlEqAIikQtZaNNfrHqN88wJiv0EhWeOzKBQ2mGA6TOk0O0Zoe 10y22lMnumabwAz0ogoYKFmxUIrBjFvmBKaCzgMElpnZsIoCi7Vm4JYw3OHB0pcG8b9P WswwqORNeazcBRGmKBlXux9t6q0fnp9J1IBEIfyy9r+rB8VXAbCJm/WcHETOovc9dNY4 35CMZy7qA2jYf3D26G6cByahrgsM8Ly92mp2L1EkrxKrm8/+9c7TaKLrCG+ZNT8m+MEM 9kNQ== X-Gm-Message-State: AO0yUKUoYHUuHt/tEfSHYRI9FjiwiMNskryTLQlNiKqM0O5k1yUQ+2mI aCVvdSFHxNRurQB9YH+Vz2RjSw== X-Google-Smtp-Source: AK7set+QG1o+yUDrVrmWTPRkmTPPW7OcS7fKYgXunBMDI70R12mYh+xc8Szb1J7aY+sAETv+D8BIqA== X-Received: by 2002:a17:90b:1d87:b0:23b:53d3:b537 with SMTP id pf7-20020a17090b1d8700b0023b53d3b537mr2943778pjb.1.1679053072800; Fri, 17 Mar 2023 04:37:52 -0700 (PDT) Received: from hsinchu25.internal.sifive.com (59-124-168-89.hinet-ip.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id n63-20020a17090a2cc500b0023d3845b02bsm1188740pjd.45.2023.03.17.04.37.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Mar 2023 04:37:52 -0700 (PDT) From: Andy Chiu To: linux-riscv@lists.infradead.org, palmer@dabbelt.com, anup@brainfault.org, atishp@atishpatra.org, kvm-riscv@lists.infradead.org, kvm@vger.kernel.org Cc: vineetg@rivosinc.com, greentime.hu@sifive.com, guoren@linux.alibaba.com, Andy Chiu , Paul Walmsley , Albert Ou , Vincent Chen , Conor Dooley , Guo Ren , Al Viro , Andrew Bresticker Subject: [PATCH -next v15 15/19] riscv: signal: validate altstack to reflect Vector Date: Fri, 17 Mar 2023 11:35:34 +0000 Message-Id: <20230317113538.10878-16-andy.chiu@sifive.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230317113538.10878-1-andy.chiu@sifive.com> References: <20230317113538.10878-1-andy.chiu@sifive.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230317_043753_214250_64204CD7 X-CRM114-Status: GOOD ( 10.54 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Some extensions, such as Vector, dynamically change footprint on a signal frame, so MINSIGSTKSZ is no longer accurate. For example, an RV64V implementation with vlen = 512 may occupy 2K + 40 + 12 Byte [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:62d listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: kvm-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: "kvm-riscv" Errors-To: kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Some extensions, such as Vector, dynamically change footprint on a signal frame, so MINSIGSTKSZ is no longer accurate. For example, an RV64V implementation with vlen = 512 may occupy 2K + 40 + 12 Bytes of a signal frame with the upcoming support. And processes that do not execute any vector instructions do not need to reserve the extra sigframe. So we need a way to guard the allocation size of the sigframe at process runtime according to current status of V. Thus, provide the function sigaltstack_size_valid() to validate its size based on current allocation status of supported extensions. Signed-off-by: Andy Chiu Reviewed-by: Conor Dooley --- arch/riscv/kernel/signal.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/riscv/kernel/signal.c b/arch/riscv/kernel/signal.c index d2d9232498ca..b8ad9a7fc0ad 100644 --- a/arch/riscv/kernel/signal.c +++ b/arch/riscv/kernel/signal.c @@ -494,3 +494,11 @@ void __init init_rt_signal_env(void) */ signal_minsigstksz = get_rt_frame_size(true); } + +#ifdef CONFIG_DYNAMIC_SIGFRAME +bool sigaltstack_size_valid(size_t ss_size) +{ + return ss_size > get_rt_frame_size(false); +} +#endif /* CONFIG_DYNAMIC_SIGFRAME */ +