From patchwork Thu May 18 16:19:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andy Chiu X-Patchwork-Id: 13247097 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 487C1C77B7A for ; Thu, 18 May 2023 16:40:35 +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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=X6yZ59ceIU8lTYJWptpZ+JgN6CsEg7U62IRdelH+Bxo=; b=I34jVRr+setPpW 1JSrShUKBeyCSaZf4t242c0pg5JZ1A0VWB1c6samdyApqybnqq8Jc+BWfIRs1fJ0Ed2ADk1YELQfi 6ndqapmV5om83l2XpRY/0DOe/wQvMp/xpebZaSjkaioluTprEWgzBaky93x2cFwzn/Xx7x7yBLQBS OEqeOE64nxkV/uoBdRiMH4tO5heMCMn6LiRCF+hW9OOH9cnzAbP/olyvn7Yk1W69rMEZv/i0r5jrr Me0ZYmvrmpTQPEnfXhxpnOtOnntf87M8IARlXRrjC0FZMp8b3sJFdg5fLVhOhqvOFdjY298CkZdda Qmv+G+aRTqhkRynXBZGg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzgg3-00DUzl-0X; Thu, 18 May 2023 16:40:31 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzgg2-00DUyU-0a for linux-riscv@bombadil.infradead.org; Thu, 18 May 2023 16:40:30 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:Content-Type :MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:Content-ID:Content-Description; bh=oXLmDwuFl1hIBYmEn8BiIjw8uR8exImuk7v2QQ06HGI=; b=Hk6MoDpp1mFWlWzqsOKj0g7Gbp 7sy188OaU+oTyoXdIZaH9Vfqt/V/NKONcw721zfovk/u6EwjU8b7TIymlK4lTMSjOH1l9uWmKZUxG FHBEI4gKVrWeA1U6MpbRiJ4F7quAEMtNOd6+PlY12mxKUxVZqgz1VdQg5rPo0yZjTOV7MJSj9kjwU y9NHdXLWOdZTpEkZHVcyidphycnqKdNHXIBoa+bpKTuHBHIGasow1eq1yIg6p8wVc3xk1zZDJcbEP T2GjM8jOUmz7fSFPGXKi2z3k784XKM3YQ9XswiDR/3/EWmNsZSumVIsoXp1Aivg/Lp23J0kGLNTUf 8YkngsGA==; Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzgOV-00ErPu-0j for linux-riscv@lists.infradead.org; Thu, 18 May 2023 16:22:25 +0000 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-64d18d772bdso1025978b3a.3 for ; Thu, 18 May 2023 09:22:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1684426941; x=1687018941; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=oXLmDwuFl1hIBYmEn8BiIjw8uR8exImuk7v2QQ06HGI=; b=V+Us4Le6T3lwbiDvi+H91rnJIcZgu0unNFqjLvxRdYA+JPyR7Hkga5r3hCCKzkKCyI 3dXM73umBgTF8zahR9lApj8gFkl4iEIO2EYh+9R7vUzW4je/Vc8oJgY25O8qat+ASZFg vuy3SjHBbYw8ltUsFBkh4jmHCEKnyR38quaPdAF+CWZugimUFtgsb8cYDo5vLB2fwrjt dmVwNoi3++6JmFGeDwRl3c+SE1n/w8tTdhN+Fe4AtjPfLbELEWxMrtcNlREP6s3zm7dW K+6Tenwl0fr+uwvvoxlZxzbUAAjG7oiMUxkeltkc4p/MTfaqtaGccbq6NZFspFEf+Gpo PliQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684426941; x=1687018941; 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:message-id:reply-to; bh=oXLmDwuFl1hIBYmEn8BiIjw8uR8exImuk7v2QQ06HGI=; b=QlP1xa2JRUMCUjKwT9ZIAjSV0VRMnkAS4I5IQruBM7wEKdBnnnXgZtS7aHva0Kru6o b4UQIC3uLROL6yW7qq1xFmIQ7nYufgOCnruljQs29leTqC593/4mJJQbdJJ+1gsQyz5I A2IA7Q9NWYSoZcQNi3ns1fA0dFnlIN7H6aYyv0K6q+gygW13lsK9RXkkHET58Ze/S577 VsyiKMubXyPVc9fnssbgVlZfzD8F6sI/197Ik17nug9mq/vlfTHSiZ1FYTYxDauYkyhV Mur1B0ST4BXqGHXTV/o0RNUz5Y/6jqIJZtFl6T/DROTJHFF3BAp9YH8bLplyeHck07UH ypbg== X-Gm-Message-State: AC+VfDwT2PY58ztFF4O0WKxEcUn9CcbeVCUc5e+zX5+mBKZWRIhUq5as zdGuKX3TuL2lpOTj89m2LKXNdMGwvJVV2mVNeiEy6s/P2GP0d38HtmZI5TU1A0qbPVgRZ/0l+Gz D7FXPnewkIrLhgU2MVBBvA2enZHHjaQpyVhFQmGXBEm7bzTHvxCThggbdvsQVUcw1bUcBDs+6xy IIvcW0/jDbB4mgh/s= X-Google-Smtp-Source: ACHHUZ7pspQwthnUGGL7Ub1wIr9lCRm7UtPbxjpJc4ghLwvFfMdQFoJ0eppPqiny7eMwhjcpJ/snQg== X-Received: by 2002:a05:6a21:32a8:b0:100:9969:8cf with SMTP id yt40-20020a056a2132a800b00100996908cfmr194460pzb.49.1684426940992; Thu, 18 May 2023 09:22:20 -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 x23-20020a62fb17000000b006414b2c9efasm1515862pfm.123.2023.05.18.09.22.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 May 2023 09:22:20 -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 , Guo Ren , Heiko Stuebner Subject: [PATCH -next v20 21/26] riscv: Add sysctl to set the default vector rule for new processes Date: Thu, 18 May 2023 16:19:44 +0000 Message-Id: <20230518161949.11203-22-andy.chiu@sifive.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230518161949.11203-1-andy.chiu@sifive.com> References: <20230518161949.11203-1-andy.chiu@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230518_172223_315440_B68779D1 X-CRM114-Status: GOOD ( 15.96 ) 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: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org To support Vector extension, the series exports variable-length vector registers on the signal frame. However, this potentially breaks abi if processing vector registers is required in the signal handler for old binaries. For example, there is such need if user-level context switch is triggerred via signals[1]. For this reason, it is best to leave a decision to distro maintainers, where the enablement of userspace Vector for new launching programs can be controlled. Developers may also need the switch to experiment with. The parameter is configurable through sysctl interface so a distro may turn off Vector early at init script if the break really happens in the wild. The switch will only take effects on new execve() calls once set. This will not effect existing processes that do not call execve(), nor processes which has been set with a non-default vstate_ctrl by making explicit PR_RISCV_V_SET_CONTROL prctl() calls. Link: https://lore.kernel.org/all/87cz4048rp.fsf@all.your.base.are.belong.to.us/ Signed-off-by: Andy Chiu Reviewed-by: Greentime Hu Reviewed-by: Vincent Chen Reviewed-by: Björn Töpel --- Changelog v20: - Use READ_ONCE to access riscv_v_implicit_uacc (Björn) --- arch/riscv/kernel/vector.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/arch/riscv/kernel/vector.c b/arch/riscv/kernel/vector.c index 9bee7a201106..25c7f5c93b00 100644 --- a/arch/riscv/kernel/vector.c +++ b/arch/riscv/kernel/vector.c @@ -184,7 +184,7 @@ void riscv_v_vstate_ctrl_init(struct task_struct *tsk) next = riscv_v_ctrl_get_next(tsk); if (!next) { - if (riscv_v_implicit_uacc) + if (READ_ONCE(riscv_v_implicit_uacc)) cur = PR_RISCV_V_VSTATE_CTRL_ON; else cur = PR_RISCV_V_VSTATE_CTRL_OFF; @@ -247,3 +247,34 @@ long riscv_v_vstate_ctrl_set_current(unsigned long arg) return -EINVAL; } + +#ifdef CONFIG_SYSCTL + +static struct ctl_table riscv_v_default_vstate_table[] = { + { + .procname = "riscv_v_default_allow", + .data = &riscv_v_implicit_uacc, + .maxlen = sizeof(riscv_v_implicit_uacc), + .mode = 0644, + .proc_handler = proc_dobool, + }, + { } +}; + +static int __init riscv_v_sysctl_init(void) +{ + if (has_vector()) + if (!register_sysctl("abi", riscv_v_default_vstate_table)) + return -EINVAL; + return 0; +} + +#else /* ! CONFIG_SYSCTL */ +static int __init riscv_v_sysctl_init(void) { return 0; } +#endif /* ! CONFIG_SYSCTL */ + +static int riscv_v_init(void) +{ + return riscv_v_sysctl_init(); +} +core_initcall(riscv_v_init);