From patchwork Thu May 18 16:19:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andy Chiu X-Patchwork-Id: 13247088 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 A5DF0C7EE23 for ; Thu, 18 May 2023 16:22:43 +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=I5kMADLC8sEgb8TzWw/ODSlEjffqIkD1gEVHGZg1tlI=; b=K6dJ4cYyYwvjvG jbtd8GOYlcNTGbHNZZXKjBU2su+11ELSHXsCPv5N4VHj/bOwVmID6PjPe9pmIgAPaodRj87mtSkSv lutxBPUpe1uDncPZoaCUGkYbfKjRRju9E+LIdIMFlwHxcr2yOe3lX/qCkeNHD/Acw3Xy6agXII4jd YHGnk2oEkaBYR9j40QznY9zAsCfFKpfd3Gi61+z4fA7gKZsvpXbCAQbuBOjJvBETDxsumzcbMFYEw xqLKBzZ1lPHcHqSsBCzcufLXqxSwJKiEFkbADnWym0GI2PGQqwICRSBWBlEB7Rn0oVJt+8aR3cTak zGBGuQno/1TUrl9wsl+w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzgOl-00DRsZ-0l; Thu, 18 May 2023 16:22:39 +0000 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzgOh-00DRrP-2l for linux-riscv@lists.infradead.org; Thu, 18 May 2023 16:22:37 +0000 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-643b60855c8so2374755b3a.2 for ; Thu, 18 May 2023 09:22:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1684426955; x=1687018955; 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=N+MDCRro9Xf50+QJNvlhYGv12fy+n0EAq9lKznlrmn0=; b=dI2lUVtcWdnnndgRtINY/ZSV1RMXEiah5l8Nv2d4Tb3ZnEkqMkveETcc7/S8uOoNyS QwmLuihecc+W7fdv7QLY5dikWZjluTxnEpFQxuce39ldhA37AyqT3GrBwg3RidIWy71u le+Ht0tz3SkDK/BcQ6Pf5bAy/35uWXUMMDCoQdgXQeGHh3Qb4vphOosBl8KtXOOMmaIF ZV8MyqmvnbaawWMpKaZErCjgtjymx7Dsw5obx9dcxU3/5sFxSboJEiPd6z/0/8K5s6TA /gmwokF5YRtQ6/J2RS5VU8s/JT2nkFu7fUEXpgUOBS6V8XKnv9RSnhUWoJNu6R5SRAR7 Yvpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684426955; x=1687018955; 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=N+MDCRro9Xf50+QJNvlhYGv12fy+n0EAq9lKznlrmn0=; b=dZBBOE/wHYQNThQXE6JSeI8i/obwe8iMLCu4BqfZqZ/aRtjDSvlLNK6ktUuuR0cD2d s/3Ta0lKYVvAxffDROV1wpr3Z99jf4RQeuSOuVU+tBibrbNVqAHlf5XwRwN/V+Prwi7U dAiK61ycJrvXJHEc0Vlzzlp5mMnouge3g8weNf+Fwq+L03hiqRNNj0zO8zwRioLP60Rj KSQ1CEUfrWLbPYGxR/sTVCo8hyFtWNE88m3EBa/VhIB4YQS8/BW5/GvTz5mKwa2aD+jK lD6gkkWMDzi81dfFRydLZUVgRaYGSgCkx4NvHbLVTtdQeNXT+h9EejAP5d7oVWAmmExT jagg== X-Gm-Message-State: AC+VfDy2dhqY5lm632BCSWkeOqoWqNCbqXKojZb/k3ilI5OKTvy68RAT NwUrGEMVEMfhNZm0UidFT5kLW2lvDNUJyfCkJHoqfWj8DH+lbBT8RzoY9b0Ceoj17u6E08f+PXz LNWoOACJZTKWNIZzYQgv/lJEzbblPaC1GcbRJDqjygEnViu1rR5QoiKvu3ZDjwyhm2o0oB5wZjX jjtFD6eT69XO+Fs+U= X-Google-Smtp-Source: ACHHUZ5lZGUdhh230ULPpQTyLuMbqnQU18JBqRp6StmIPyw1vtFKIhtu4JXH5qp913PbkJwmAtmtvA== X-Received: by 2002:a05:6a00:b45:b0:64c:c5c0:6e01 with SMTP id p5-20020a056a000b4500b0064cc5c06e01mr6494433pfo.31.1684426954742; Thu, 18 May 2023 09:22:34 -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.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 May 2023 09:22:34 -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 , Bagas Sanjaya , Jonathan Corbet , Paul Walmsley , Albert Ou , Heiko Stuebner , Evan Green , Vincent Chen Subject: [PATCH -next v20 24/26] riscv: Add documentation for Vector Date: Thu, 18 May 2023 16:19:47 +0000 Message-Id: <20230518161949.11203-25-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_092235_895865_65EF4895 X-CRM114-Status: GOOD ( 25.32 ) 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 This patch add a brief documentation of the userspace interface in regard to the RISC-V Vector extension. Signed-off-by: Andy Chiu Reviewed-by: Greentime Hu Reviewed-by: Vincent Chen Co-developed-by: Bagas Sanjaya Signed-off-by: Bagas Sanjaya --- Changelog v20: - Drop bit-field repressentation and typos (Björn) - Fix document styling (Bagas) --- Documentation/riscv/index.rst | 1 + Documentation/riscv/vector.rst | 120 +++++++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+) create mode 100644 Documentation/riscv/vector.rst diff --git a/Documentation/riscv/index.rst b/Documentation/riscv/index.rst index 175a91db0200..95cf9c1e1da1 100644 --- a/Documentation/riscv/index.rst +++ b/Documentation/riscv/index.rst @@ -10,6 +10,7 @@ RISC-V architecture hwprobe patch-acceptance uabi + vector features diff --git a/Documentation/riscv/vector.rst b/Documentation/riscv/vector.rst new file mode 100644 index 000000000000..5d37fd212720 --- /dev/null +++ b/Documentation/riscv/vector.rst @@ -0,0 +1,120 @@ +.. SPDX-License-Identifier: GPL-2.0 + +========================================= +Vector Extension Support for RISC-V Linux +========================================= + +This document briefly outlines the interface provided to userspace by Linux in +order to support the use of the RISC-V Vector Extension. + +1. prctl() Interface +--------------------- + +Two new prctl() calls are added to allow programs to manage the enablement +status for the use of Vector in userspace: + +* prctl(PR_RISCV_V_SET_CONTROL, unsigned long arg) + + Sets the Vector enablement status of the calling thread, where the control + argument consists of two 2-bit enablement statuses and a bit for inheritance + mode. Other threads of the calling process are unaffected. + + Enablement status is a tri-state value each occupying 2-bit of space in + the control argument: + + * :c:macro:`PR_RISCV_V_VSTATE_CTRL_DEFAULT`: Use the system-wide default + enablement status on execve(). The system-wide default setting can be + controlled via sysctl interface (see sysctl section below). + + * :c:macro:`PR_RISCV_V_VSTATE_CTRL_ON`: Allow Vector to be run for the + thread. + + * :c:macro:`PR_RISCV_V_VSTATE_CTRL_OFF`: Disallow Vector. Executing Vector + instructions under such condition will trap and casuse the termination of the thread. + + arg: The control argument is a 5-bit value consisting of 3 parts, and + accessed by 3 masks respectively. + + The 3 masks, PR_RISCV_V_VSTATE_CTRL_CUR_MASK, + PR_RISCV_V_VSTATE_CTRL_NEXT_MASK, and PR_RISCV_V_VSTATE_CTRL_INHERIT + represents bit[1:0], bit[3:2], and bit[4]. bit[1:0] accounts for the + enablement status of current thread, and the setting at bit[3:2] takes place + at next execve(). bit[4] defines the inheritance mode of the setting in + bit[3:2]. + + * :c:macro:`PR_RISCV_V_VSTATE_CTRL_CUR_MASK`: bit[1:0]: Account for the + Vector enablement status for the calling thread. The calling thread is + not able to turn off Vector once it has been enabled. The prctl() call + fails with EPERM if the value in this mask is PR_RISCV_V_VSTATE_CTRL_OFF + but the current enablement status is not off. Setting + PR_RISCV_V_VSTATE_CTRL_DEFAULT here takes no effect but to set back + the original enablement status. + + * :c:macro:`PR_RISCV_V_VSTATE_CTRL_NEXT_MASK`: bit[3:2]: Account for the + Vector enablement setting for the calling thread at the next execve() + system call. If PR_RISCV_V_VSTATE_CTRL_DEFAULT is used in this mask, + then the enablement status will be decided by the system-wide + enablement status when execve() happen. + + * :c:macro:`PR_RISCV_V_VSTATE_CTRL_INHERIT`: bit[4]: the inheritance + mode for the setting at PR_RISCV_V_VSTATE_CTRL_NEXT_MASK. If the bit + is set then the following execve() will not clear the setting in both + PR_RISCV_V_VSTATE_CTRL_NEXT_MASK and PR_RISCV_V_VSTATE_CTRL_INHERIT. + This setting persists across changes in the system-wide default value. + + Return value: + * 0 on success; + * EINVAL: Vector not supported, invalid enablement status for current or + next mask; + * EPERM: Turning off Vector in PR_RISCV_V_VSTATE_CTRL_CUR_MASK if Vector + was enabled for the calling thread. + + On success: + * A valid setting for PR_RISCV_V_VSTATE_CTRL_CUR_MASK takes place + immediately. The enablement status specified in + PR_RISCV_V_VSTATE_CTRL_NEXT_MASK happens at the next execve() call, or + all following execve() calls if PR_RISCV_V_VSTATE_CTRL_INHERIT bit is + set. + * Every successful call overwrites a previous setting for the calling + thread. + +* prctl(PR_RISCV_V_GET_CONTROL) + + Gets the same Vector enablement status for the calling thread. Setting for + next execve() call and the inheritance bit are all OR-ed together. + + Return value: + * a nonnegative value on success; + * EINVAL: Vector not supported. + +2. System runtime configuration (sysctl) +----------------------------------------- + +To mitigate the ABI impact of expansion of the signal stack, a +policy mechanism is provided to the administrators, distro maintainers, and +developers to control the default Vector enablement status for userspace +processes in form of sysctl knob: + +* /proc/sys/abi/riscv_v_default_allow + + Writing the text representation of 0 or 1 to this file sets the default + system enablement status for new starting userspace programs. Valid values + are: + + * 0: Do not allow Vector code to be executed as the default for new processes. + * 1: Allow Vector code to be executed as the default for new processes. + + Reading this file returns the current system default enablement status. + + At every execve() call, a new enablement status of the new process is set to + the system default, unless: + + * PR_RISCV_V_VSTATE_CTRL_INHERIT is set for the calling process, and the + setting in PR_RISCV_V_VSTATE_CTRL_NEXT_MASK is not + PR_RISCV_V_VSTATE_CTRL_DEFAULT. Or, + + * The setting in PR_RISCV_V_VSTATE_CTRL_NEXT_MASK is not + PR_RISCV_V_VSTATE_CTRL_DEFAULT. + + Modifying the system default enablement status does not affect the enablement + status of any existing process of thread that do not make an execve() call.