From patchwork Thu May 18 16:19:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Chiu X-Patchwork-Id: 13247164 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 C7D5AC77B7D for ; Thu, 18 May 2023 17:30:48 +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=ouudiRHdDqYhRJyMVqjr7OGs7TIswItqnBrrQh+2J7c=; b=Xk6qPmSxZruv8s g5QD383mTdLT8gAPmC6FkLSrgL7eCy4xVyC+jKtdGKR7uaeULqzDjJMs4pbJPLfUowTBTpwRkBe95 A0SWBkI4MJmqKwuaSR0MxHNrhMwxWaWMpYboFigUD3Sfi4xyu+sDwjZDqM7/S6RgdJ8n78JckXHJB TL+Hbs/UeYY/R96oYGzIGyEkH2bKNs546W5Mx8V4X77YIKNFgvsPeL6mgQt42cCI7fE/wl4vJGyE4 AD3Fo8sv52gsjXpnfQALpySMGKJNB55TAYyuuXTQCHagLBsblHhPx/ESWm/bKZA+1AOlXKefEXOo5 qzgGo+F1OkL78hVr14jw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzhSe-00Ddzf-0f; Thu, 18 May 2023 17:30:44 +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 1pzgMY-00DQqO-1q for linux-riscv@bombadil.infradead.org; Thu, 18 May 2023 16:20:22 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=References:In-Reply-To:Message-Id:Date :Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description; bh=xZD7AFVtobxh1FGjEKQD2QW8IDIT5bzbSx/S1GQl+8U=; b=no7QIhnv+pstQv7T13kmtlc+FC JRKsXqPFClGegPC/OHHqJrJKX/WBrdMMmAyZocDIopKZJ8ZRUuFNwo/q1L8WxO7fkzr/r/iP0HRo2 XbmmJuGSXMXmsn83jeyJge4DDxBIY01hLPU/6U9tH1mqo5Xj9yUCWyL3aZp3DrYstgHEpZKzSncHs X0G6Ir8IP2zp4gPB1aMtlm7F5p8fn8uezoTKyy03S7NhdhiEpWXCKTQW52wTStqTiadEdwzNGY2vL lBtuRlOq2Bomxy3cqSB7RSCHUIst6b9VZQaV33RedEmVVJjkGiScKMnurBnKlLc6MZcZRkoayzDk0 BEChTHfQ==; Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzgMV-00ErIW-0Y for linux-riscv@lists.infradead.org; Thu, 18 May 2023 16:20:21 +0000 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-64d2b42a8f9so208905b3a.3 for ; Thu, 18 May 2023 09:20:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1684426813; x=1687018813; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=xZD7AFVtobxh1FGjEKQD2QW8IDIT5bzbSx/S1GQl+8U=; b=gEhgqju2wKcCZblFZ8N5g54ria8NkU2Jrsgh2HBQGp1B76OifXlhO1uLHApY5O5kRL JgXeGtEK+yBT3f196jJibssDuX0BZNoMdmDYyzKG57miQI76MrZYtHf/Hdej1odY0EQF H+gt+Wp63F/cMyYkBpPWKNs5G8/uhRWkmPKiabu33P+e00RvvF4lUnd2MRunJYWkLbRr Hj7VtF7r5cdTKk0Hbe7hnlU02gQ7WZv3EoJUJfNOxfgvMD1M5+Ww54ZODZbVJ+nyos7D +rHJgLWHxZcNpuL8QHIu5pL7EH9QCKNiXxUYpKxXIRFKJbD1zXGZw0ggmfrcbxdzAnz7 sLvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684426813; x=1687018813; 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=xZD7AFVtobxh1FGjEKQD2QW8IDIT5bzbSx/S1GQl+8U=; b=l4kUT5IdvyvzafIwH/EhI0U3Qzuuu2Dhtr2JeWFrGCaV+E1jwOIA6VW70LempTRBvv OM4S2rBW3ZWO3pvuW5u+s2rdcbOwvAMF6ZavWfu6W+YXR70LVq3uc7VaxS7uDfVlluxp oWwUM1jqNCYy2osSxENHHsE2eXAV8xOqYRVV39dyc/kWgMiAakvVKNH5okO7g2V8/lxR Ccyj1QM/tSCJbYDj1h08nLqUmOUKK67URsiWbzyfeLBdHV/H6PfiFESwETAf30O6MIUP ko0emGltjihx4kZuaKnn4A1pGa6EOJZ7oKpNCim/hSBX2K3d5CgFj1YjfKA5XNwagltS Whlg== X-Gm-Message-State: AC+VfDwrhcYMQ0Xn9EP5sb7TfY/3jb5Rn9TyJYO+VK2pbqA4Lewgqo3D RJK8FrkRXqVff+8OKT2vMp9UdtHwXc03jsgReHXS/z1495rNPLlPm7GeKNBdovrzTxP3oJrEAEW ACI5hjgh5kC1j/QAnldffTM67Xt/dNFvut3b5g/rNiq9Mv9M2OmlApRU8VQm/ZZYvNngN+OpDMN wHzqnBnDhn46zVRso= X-Google-Smtp-Source: ACHHUZ5WSoRIzD52+jf7cC9k7jLjwXrMwTQkVVpxACYNriXgtThbxraiZXQUJAzcqiQXme89jFje+w== X-Received: by 2002:a05:6a20:9d92:b0:100:49d1:6fc7 with SMTP id mu18-20020a056a209d9200b0010049d16fc7mr208625pzb.34.1684426813385; Thu, 18 May 2023 09:20:13 -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.20.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 May 2023 09:20:12 -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, Guo Ren , Andy Chiu , Paul Walmsley , Albert Ou , Heiko Stuebner , Guo Ren , Conor Dooley , Jisheng Zhang Subject: [PATCH -next v20 01/26] riscv: Rename __switch_to_aux() -> fpu Date: Thu, 18 May 2023 16:19:24 +0000 Message-Id: <20230518161949.11203-2-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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230518_172019_333715_799B164B X-CRM114-Status: GOOD ( 10.55 ) 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 From: Guo Ren The name of __switch_to_aux() is not clear and rename it with the determine function: __switch_to_fpu(). Next we could add other regs' switch. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Signed-off-by: Greentime Hu Reviewed-by: Anup Patel Reviewed-by: Palmer Dabbelt Signed-off-by: Andy Chiu Tested-by: Heiko Stuebner Reviewed-by: Heiko Stuebner Reviewed-by: Conor Dooley --- arch/riscv/include/asm/switch_to.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/riscv/include/asm/switch_to.h b/arch/riscv/include/asm/switch_to.h index 60f8ca01d36e..4b96b13dee27 100644 --- a/arch/riscv/include/asm/switch_to.h +++ b/arch/riscv/include/asm/switch_to.h @@ -46,7 +46,7 @@ static inline void fstate_restore(struct task_struct *task, } } -static inline void __switch_to_aux(struct task_struct *prev, +static inline void __switch_to_fpu(struct task_struct *prev, struct task_struct *next) { struct pt_regs *regs; @@ -66,7 +66,7 @@ static __always_inline bool has_fpu(void) static __always_inline bool has_fpu(void) { return false; } #define fstate_save(task, regs) do { } while (0) #define fstate_restore(task, regs) do { } while (0) -#define __switch_to_aux(__prev, __next) do { } while (0) +#define __switch_to_fpu(__prev, __next) do { } while (0) #endif extern struct task_struct *__switch_to(struct task_struct *, @@ -77,7 +77,7 @@ do { \ struct task_struct *__prev = (prev); \ struct task_struct *__next = (next); \ if (has_fpu()) \ - __switch_to_aux(__prev, __next); \ + __switch_to_fpu(__prev, __next); \ ((last) = __switch_to(__prev, __next)); \ } while (0) From patchwork Thu May 18 16:19:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Chiu X-Patchwork-Id: 13247081 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 85AF5C77B7D for ; Thu, 18 May 2023 16:20:31 +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=zTY0kX/7DpaF+YLS6mHBrPVEn1p/4PSwymvcyWiUPgc=; b=kqNxcfkRUbJfou l+VpS5ZruHuH5tAGh+0HREy8ww4PsrGum5q/GasN0mrGoUKKJ7LAd5DbrwNL/otNqAPgo8OYwgCyV AA9XqaiNZofVi6wKS7bDPDW1dkmv4omjaMbfDUjDni1exw+5vmXnjctXUSPjTi3LSaSAUEf90ysX+ G5g7ZOrQ1IDbHbopaLPQxQIkAUTqJmrJoX2ZXDsnc2lveyzTTfrFkWLD4ShyOQDDfD7hSRGbfLx82 MT0nx803BG+Q/NUeEIiWJ5vUUPnM3ZXmsI3frugKwuM6+FG+5QTgRSOxS14EiGbt6qfWnUAKzP6B3 Xx+Uhv3K274GAiJEheUQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzgMd-00DQty-1Y; Thu, 18 May 2023 16:20:27 +0000 Received: from mail-pf1-f169.google.com ([209.85.210.169]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzgMa-00DQqt-25 for linux-riscv@lists.infradead.org; Thu, 18 May 2023 16:20:26 +0000 Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-643bb9cdd6eso2375060b3a.1 for ; Thu, 18 May 2023 09:20:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1684426822; x=1687018822; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=QTuL2uiI0oFuPEE6djzm9/PdbC+T6hk/9J64Mz+FPUg=; b=atqqhQ6bg0qzbUUjo5+wTqp1lCQJlJSArV+/esa+5v4VQwmaTHLCfewsvdyo352GBl ON0OeJ+GgvVpDUQq+u1C2xFIAnTXoGbFseX5aYMObIwNUovL25NUjTlllQbf93U5NY6l gMe7Sz50/E+2ZZjaYonWe/T0NMfLOOrBlfQuET+fmtb+Nv8Rw6avvoXyKaVYtBS7MT5P 9pCEMTeJLNoRTpajPDJySCUqGjmPqrVvysYicCrPfDXGjyABcAJHMjfPYXdpK/lNPYVc jc3qBoLbMq0jBal1io27SGE4igdkOpSBHLpFMJxhqftslmgnWfQR4RM23lDDjoiPRii+ E6/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684426822; x=1687018822; 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=QTuL2uiI0oFuPEE6djzm9/PdbC+T6hk/9J64Mz+FPUg=; b=gQLZOyB80MlAExwj4cwIIvay9S34JyhgoI+UN9hN3tjXJMG4wqj5ywudWICB+xMWx6 Hzp77r/ChlY07kywGfQI+DRxLkAt4pNJkEBomSyklqc1LfwGd6uB+YSGxBqs2Pd4WUBO URMgju0rvKICzYKodrK0ZV3YRcLGISOUw3HPYqWyVF/mmGvsCj/6KVCdVWq6TNu5nJ7I 7FlA4y1DylsaYlTEqHfavufn1hLBjdmmkjsvT6bKHprUoYN9QcD8iTLWpiWIeP2BcVNZ nL3P3pvo6HHYN26EnGPmiLAMQJVHiO9PGcVBeaiwgnlI29YltTKcAJb3F5QcTSvZxXq1 TBNg== X-Gm-Message-State: AC+VfDzQK9P8BeqMvpqPA1m3z8nMSZ7b8tiF14otJM2cjeCFJ76CE20r OtEu/2lmzlYAjN5Rew4tKxhBOt+mctZ9eS+Zt7tLJYkUHe8W4GD1c2FLyH+3orI2R7iUuYQKDct lzw+V4mxDwPHqgCFveVp1wFyOCvTBEds3R+8U7+yeYNMWYMaq/vMCCuJhEbscR2nS47JrhcYiH/ zfpzDbTZLipf0VrRI= X-Google-Smtp-Source: ACHHUZ4r9JCFvloZNOQ7tvRAromreCSi7ksq0FlhVujkrAR1Xi3R0RKL050Z8B4irZlUVCaAtxSnOw== X-Received: by 2002:a05:6a20:748e:b0:101:9344:bf89 with SMTP id p14-20020a056a20748e00b001019344bf89mr154013pzd.49.1684426821876; Thu, 18 May 2023 09:20:21 -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.20.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 May 2023 09:20:21 -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, Guo Ren , Andy Chiu , Paul Walmsley , Albert Ou , Conor Dooley , Andrew Jones , Heiko Stuebner , Anup Patel , Jisheng Zhang , Vincent Chen , Guo Ren Subject: [PATCH -next v20 02/26] riscv: Extending cpufeature.c to detect V-extension Date: Thu, 18 May 2023 16:19:25 +0000 Message-Id: <20230518161949.11203-3-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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230518_092024_695856_5592274B X-CRM114-Status: GOOD ( 16.04 ) 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 From: Guo Ren Add V-extension into riscv_isa_ext_keys array and detect it with isa string parsing. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Signed-off-by: Greentime Hu Suggested-by: Vineet Gupta Co-developed-by: Andy Chiu Signed-off-by: Andy Chiu Reviewed-by: Conor Dooley Reviewed-by: Heiko Stuebner Tested-by: Heiko Stuebner Reviewed-by: Palmer Dabbelt --- Changelog v20: s/riscv_has_extension_likely/riscv_has_extension_unlikely/ (Palmer) --- arch/riscv/include/asm/hwcap.h | 1 + arch/riscv/include/asm/vector.h | 26 ++++++++++++++++++++++++++ arch/riscv/include/uapi/asm/hwcap.h | 1 + arch/riscv/kernel/cpufeature.c | 11 +++++++++++ 4 files changed, 39 insertions(+) create mode 100644 arch/riscv/include/asm/vector.h diff --git a/arch/riscv/include/asm/hwcap.h b/arch/riscv/include/asm/hwcap.h index e0c40a4c63d5..574385930ba7 100644 --- a/arch/riscv/include/asm/hwcap.h +++ b/arch/riscv/include/asm/hwcap.h @@ -22,6 +22,7 @@ #define RISCV_ISA_EXT_m ('m' - 'a') #define RISCV_ISA_EXT_s ('s' - 'a') #define RISCV_ISA_EXT_u ('u' - 'a') +#define RISCV_ISA_EXT_v ('v' - 'a') /* * These macros represent the logical IDs of each multi-letter RISC-V ISA diff --git a/arch/riscv/include/asm/vector.h b/arch/riscv/include/asm/vector.h new file mode 100644 index 000000000000..bdbb05b70151 --- /dev/null +++ b/arch/riscv/include/asm/vector.h @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2020 SiFive + */ + +#ifndef __ASM_RISCV_VECTOR_H +#define __ASM_RISCV_VECTOR_H + +#include + +#ifdef CONFIG_RISCV_ISA_V + +#include + +static __always_inline bool has_vector(void) +{ + return riscv_has_extension_unlikely(RISCV_ISA_EXT_v); +} + +#else /* ! CONFIG_RISCV_ISA_V */ + +static __always_inline bool has_vector(void) { return false; } + +#endif /* CONFIG_RISCV_ISA_V */ + +#endif /* ! __ASM_RISCV_VECTOR_H */ diff --git a/arch/riscv/include/uapi/asm/hwcap.h b/arch/riscv/include/uapi/asm/hwcap.h index 46dc3f5ee99f..c52bb7bbbabe 100644 --- a/arch/riscv/include/uapi/asm/hwcap.h +++ b/arch/riscv/include/uapi/asm/hwcap.h @@ -21,5 +21,6 @@ #define COMPAT_HWCAP_ISA_F (1 << ('F' - 'A')) #define COMPAT_HWCAP_ISA_D (1 << ('D' - 'A')) #define COMPAT_HWCAP_ISA_C (1 << ('C' - 'A')) +#define COMPAT_HWCAP_ISA_V (1 << ('V' - 'A')) #endif /* _UAPI_ASM_RISCV_HWCAP_H */ diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index b1d6b7e4b829..7aaf92fff64e 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -107,6 +107,7 @@ void __init riscv_fill_hwcap(void) isa2hwcap['f' - 'a'] = COMPAT_HWCAP_ISA_F; isa2hwcap['d' - 'a'] = COMPAT_HWCAP_ISA_D; isa2hwcap['c' - 'a'] = COMPAT_HWCAP_ISA_C; + isa2hwcap['v' - 'a'] = COMPAT_HWCAP_ISA_V; elf_hwcap = 0; @@ -267,6 +268,16 @@ void __init riscv_fill_hwcap(void) elf_hwcap &= ~COMPAT_HWCAP_ISA_F; } + if (elf_hwcap & COMPAT_HWCAP_ISA_V) { + /* + * ISA string in device tree might have 'v' flag, but + * CONFIG_RISCV_ISA_V is disabled in kernel. + * Clear V flag in elf_hwcap if CONFIG_RISCV_ISA_V is disabled. + */ + if (!IS_ENABLED(CONFIG_RISCV_ISA_V)) + elf_hwcap &= ~COMPAT_HWCAP_ISA_V; + } + memset(print_str, 0, sizeof(print_str)); for (i = 0, j = 0; i < NUM_ALPHA_EXTS; i++) if (riscv_isa[0] & BIT_MASK(i)) From patchwork Thu May 18 16:19:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Chiu X-Patchwork-Id: 13247166 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 512E8C7EE25 for ; Thu, 18 May 2023 17:30:50 +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=SVvTHMhjiIq8IhKaNtMNcpmPGcTVkulLxaDeCc/wS+w=; b=qEFiO65uLn/0uH 9DzHf2gjEyBUhuCj9sHx/efMx4dlKODbsEgQURLKEpWooAoTaxouLnBYl66zvgRZdRk8y6260an6l j3wFmlTLt4gNg9CD9WaKm2eu1ZFBzzQT+/OnoHZl9BVolpndZWsT5Eaevu6bjTuHT3jBwmSZyCyKb /JKgY59WQXEPGnHlsycThSv+htn1egxoxFmk8/2mLmb5bUDYiPsxOMDg2gPBY6TGgU7u5DiSWKLq1 VKJ4O7wqS+oh5vSERpzrhhjWVviDQkK/n25pqOUmTFp6AXfv+/+1DoCf1BBLM3wUIcX8s9wxR0WGg QrZld4L0yiO+1DUOucxg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzhSf-00De09-01; Thu, 18 May 2023 17:30:45 +0000 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzgMh-00DQvk-1Q for linux-riscv@lists.infradead.org; Thu, 18 May 2023 16:20:32 +0000 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-64d1a0d640cso637624b3a.1 for ; Thu, 18 May 2023 09:20:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1684426829; x=1687018829; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=UCneMDdINnXxGFonqkgOoODJ+YC49qYwF4COaw1Z14o=; b=GUxVbM4pzCCxfmJ1sLQJe45OkM/xPmw8ia4snr3DB9rSBBUbWxqdqg5SGaL3gt8QPN BNIPca9Jfoopz4JHgr0zUAv7BuNZE6UkJwsmqwjiehqioQCh2wxQHM2PKymqk9ucIfqE 61abNkeWmBu+m9qNDu3FgPK+y05UuYLDbz+y+l8CuMwLrMscJ1d8c8kfyXQDct5UooUy Swtwk8CLKzJkzePV67fpwq3acbGHNarB3PUhB1Zq4dab2VM43eocYiXeyJe2dqBmcXJx YjyZy/gSP6Lvcg5hPqHFdXLOD3ylpmIN+/56R7P0ukMm4/JIshLodNko0ZRdEoWYTTxQ 4cug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684426829; x=1687018829; 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=UCneMDdINnXxGFonqkgOoODJ+YC49qYwF4COaw1Z14o=; b=JF6pR4cH1sYSzeL+A3IRze7LbnYDzzKDkmtRbulCdPKM3kUNZMgSgDVkKFApsIylYL m7fR7u64oQIgvXKBt7MvIROAY8OFxiB1p8JxtRzNKdZds40tiag8I9hyKmsOT6rlrDb7 pFM8ig8HSconWg2lcbJW4rTuRdKy0SttA7gRH7JS69bZJXweO8OXEQetdyiey6EaqvNk i6xITuueFtTF8MMsVUJl9+KarxUrw2kNCMyTUfuQzS2yHgwzkwBaLnI7SXHD1pFqW7WC 4CPd6lY8sjsktgVO61sQCzxwbpr3vPgJy//7elNLzocGrlydB36z0bozexNbIPoBGA1S rVdQ== X-Gm-Message-State: AC+VfDwebGLSnRPVDrCev0t1xNI3WYXpzkRlImOiIC3S7vtoA4bcOhSj sMOr1kiBrlI1hJZqwcq87VpPkpnsoJCNKzkC6ubIc/jl0VkZzIIu0H67HwuXhCb6LyMLLXPxpq7 w4sz+ExvGkl9b1HDzSEBolIa39+Qoq7pXpsiOHAqBvyiueXxeYR/CVZQr2FTLOco2NNZ2XIYrHG 6Ciqay/dMNcEwp8Sc= X-Google-Smtp-Source: ACHHUZ4gHnZwEo4v5N/LppQGYlH/FEjfcRk20N94BNcL2iprlv2xnz7gkTmTs7GcCM6dtPmNeMDIqQ== X-Received: by 2002:aa7:8885:0:b0:643:59ed:5dc9 with SMTP id z5-20020aa78885000000b0064359ed5dc9mr5814862pfe.12.1684426829473; Thu, 18 May 2023 09:20:29 -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.20.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 May 2023 09:20:28 -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 , Jonathan Corbet , Paul Walmsley , Albert Ou , Heiko Stuebner , Conor Dooley , Evan Green , Andrew Jones , Andrew Bresticker , Celeste Liu Subject: [PATCH -next v20 03/26] riscv: hwprobe: Add support for probing V in RISCV_HWPROBE_KEY_IMA_EXT_0 Date: Thu, 18 May 2023 16:19:26 +0000 Message-Id: <20230518161949.11203-4-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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230518_092031_487261_70C63C0A X-CRM114-Status: GOOD ( 11.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: , MIME-Version: 1.0 Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Probing kernel support for Vector extension is available now. This only add detection for V only. Extenions like Zvfh, Zk are not in this scope. Signed-off-by: Andy Chiu Reviewed-by: Evan Green Reviewed-by: Palmer Dabbelt Reviewed-by: Guo Ren --- Changelog v20: - Fix a typo in document, and remove duplicated probes (Heiko) - probe V extension in RISCV_HWPROBE_KEY_IMA_EXT_0 key only (Palmer, Evan) --- Documentation/riscv/hwprobe.rst | 3 +++ arch/riscv/include/uapi/asm/hwprobe.h | 1 + arch/riscv/kernel/sys_riscv.c | 4 ++++ 3 files changed, 8 insertions(+) diff --git a/Documentation/riscv/hwprobe.rst b/Documentation/riscv/hwprobe.rst index 9f0dd62dcb5d..7431d9d01c73 100644 --- a/Documentation/riscv/hwprobe.rst +++ b/Documentation/riscv/hwprobe.rst @@ -64,6 +64,9 @@ The following keys are defined: * :c:macro:`RISCV_HWPROBE_IMA_C`: The C extension is supported, as defined by version 2.2 of the RISC-V ISA manual. + * :c:macro:`RISCV_HWPROBE_IMA_V`: The V extension is supported, as defined by + version 1.0 of the RISC-V Vector extension manual. + * :c:macro:`RISCV_HWPROBE_KEY_CPUPERF_0`: A bitmask that contains performance information about the selected set of processors. diff --git a/arch/riscv/include/uapi/asm/hwprobe.h b/arch/riscv/include/uapi/asm/hwprobe.h index 8d745a4ad8a2..7c6fdcf7ced5 100644 --- a/arch/riscv/include/uapi/asm/hwprobe.h +++ b/arch/riscv/include/uapi/asm/hwprobe.h @@ -25,6 +25,7 @@ struct riscv_hwprobe { #define RISCV_HWPROBE_KEY_IMA_EXT_0 4 #define RISCV_HWPROBE_IMA_FD (1 << 0) #define RISCV_HWPROBE_IMA_C (1 << 1) +#define RISCV_HWPROBE_IMA_V (1 << 2) #define RISCV_HWPROBE_KEY_CPUPERF_0 5 #define RISCV_HWPROBE_MISALIGNED_UNKNOWN (0 << 0) #define RISCV_HWPROBE_MISALIGNED_EMULATED (1 << 0) diff --git a/arch/riscv/kernel/sys_riscv.c b/arch/riscv/kernel/sys_riscv.c index 5db29683ebee..88357a848797 100644 --- a/arch/riscv/kernel/sys_riscv.c +++ b/arch/riscv/kernel/sys_riscv.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -171,6 +172,9 @@ static void hwprobe_one_pair(struct riscv_hwprobe *pair, if (riscv_isa_extension_available(NULL, c)) pair->value |= RISCV_HWPROBE_IMA_C; + if (has_vector()) + pair->value |= RISCV_HWPROBE_IMA_V; + break; case RISCV_HWPROBE_KEY_CPUPERF_0: From patchwork Thu May 18 16:19:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Chiu X-Patchwork-Id: 13247098 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 B9B9CC77B7A for ; Thu, 18 May 2023 16:40:38 +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=cWE0WNTDcIJGT/EIxnpE8HahZhonS2BjUM7ROH4ynOU=; b=JyKzA5aH0MFLP8 P6PK1sRqUCN6s9SIIDSXOdhbh2h6cx3cLnnqcpfNYWcQXcgqFQQdsQHqX0mqzMHlOiIw0drdvk2zW AxKZP2QqBh/9Ob/sx/h2dY6qr3Ge6oppoYE5DMHHAqA1b8NKUkTq26ORXJN6v73VtEosuOwqQbXiu gfvl6/bMz05Eod+YRw20eh2IwrUvBhWYh8GTDWNL0onW2+xpurab3pSdnMW+ZJX2taSoJg0oqESe7 9XdkpTmt4j/v+4+1Vmd3SAiCESQkPoIZKsOq0sGT8kTaCqFDRL7b2ETmbDRaE+u9CsYcpzUv+mbEC KiKsoTc3wd9RZRzAZgkQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzgg6-00DV2y-2U; Thu, 18 May 2023 16:40:34 +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 1pzgg5-00DV1c-1m for linux-riscv@bombadil.infradead.org; Thu, 18 May 2023 16:40:33 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=References:In-Reply-To:Message-Id:Date :Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description; bh=d1t0mcJTBhtsZBYqWTjUk/5U+5ffoYMHXYjoCjqrD1Y=; b=K/OWGA4BgcuSB4qiyu1jF6LuOl A+wFcZ9e9vafe90+DwsDNkHuoqHSbVWs8yECfmA6CxHx/7v40WtOJr2kE9GTMFXvbqM09IfRceurY L7f9X5Z0Hq8uXSiQYPAoJRL+6OBz3g+8ztne1BmcogRVB9uS0njMxAlT0i78vaNQKXoYvDVz67IhE JpK8NS7szROwWStYhLqU1W4DTtpNxcjXgacB8Wl05nYId1dXRFTdBoyoOkNVWVACKV5wmDlsCklfu euT1N9kKdAtfrkq1yPrRg0TXfW6JwFWL75rjZrIw4H1N4g+MuyQaGDTpjfsgc8o/oDIpWCG9OGe57 0/Wb/inA==; Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzgMm-00ErJB-18 for linux-riscv@lists.infradead.org; Thu, 18 May 2023 16:20:38 +0000 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-64d2a889722so266547b3a.3 for ; Thu, 18 May 2023 09:20:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1684426834; x=1687018834; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=d1t0mcJTBhtsZBYqWTjUk/5U+5ffoYMHXYjoCjqrD1Y=; b=j/lNhEwTb7JEJPIuoeqzcOoNlaE9EqVE/MZI6+2DWzQNO6XCErcOE2TDOSR7eIsYwX nuo+9r/OqRnGOX5t07Sxq0Q8Vzs4aWyTIxF+ZXQYje5CTeltNr00p47KJsH1aSEVqs2U brOJOywB1UfvF7mHrkMp+tc5M1tR5tMy/k0eV1Td+kCt7ThlX/IFBLXM8A1YMn2ZovuO dWuUezKtPO4fvLtFmXbmPhIW2DheeIb2VUF4qT0ApoFG36ruAHlBM4fQBy12OVhR+o5w E4pw3Sr507bSIqgvvz/+/0ft9ai4MCLwdiyFsKlcD6a1nD0wITeZxQDUSUzetmMfeTVo QaYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684426834; x=1687018834; 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=d1t0mcJTBhtsZBYqWTjUk/5U+5ffoYMHXYjoCjqrD1Y=; b=ljkI5TrdFdu7SQ5zolUbpTD264IkPCEN/vF4K4NXE8D0RTVIx9rnfYyghhzvVx88sF y0n6niGwDtTJ6TFZzT2aUR22pycQs9yo8HiGwzxWuc2KCIjbwHfzzeE862A+JPt4Q2iN vqzu9C/fBqqWTQAwjucD4Gt0+uydQC5ceMxEshEEAB2Epr1ubEQE/RzQs9x+1dGL49dL MHI+lSca2x83jYo/SuLh0sKKbXywqcnqEpX5HdrZ2RUBrbXboqLjh3Fysbr7Gavd7w6B imDJrjl74L24ZCPVTtyhGXVEm6wyw6lShEifnKSJv/m9sBRPXSdgzl39lvJ1c0wci+xf zBuw== X-Gm-Message-State: AC+VfDwLWe2J0iCZMMQhDo8ICzjttaPYDEAjKK9bUSp/ulsp5MZrwBdn dFU/psSmGZgVD9ji7gil/5vq77gYjUHNWSkraKz9DpJr4ZATMQCrPboz1n6w/RGam6nTpGXz7O3 g6bprFT84Pljq1O87Tadspy+1oyAwGC7d+OI3NY/YFY4rPSrsO5jW2NbaW3ujJ1hdJSVQTZsvoQ 1e/SygAmpkSSB2BeY= X-Google-Smtp-Source: ACHHUZ5PIN2Byi+riolmbgeoMB+vCD0zudt7ZJVUoMZ3UWR2Wl5reYAaZjZzQ8xTchHoGIInJ8gAzA== X-Received: by 2002:a05:6a21:3701:b0:100:cb5f:5b91 with SMTP id yl1-20020a056a21370100b00100cb5f5b91mr196914pzb.25.1684426833823; Thu, 18 May 2023 09:20:33 -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.20.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 May 2023 09:20:33 -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, Vincent Chen , Andy Chiu , Paul Walmsley , Albert Ou , Anup Patel , Guo Ren , Atish Patra , Heiko Stuebner Subject: [PATCH -next v20 04/26] riscv: Add new csr defines related to vector extension Date: Thu, 18 May 2023 16:19:27 +0000 Message-Id: <20230518161949.11203-5-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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230518_172036_440387_83D7CE36 X-CRM114-Status: UNSURE ( 8.39 ) 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 From: Greentime Hu Follow the riscv vector spec to add new csr numbers. Acked-by: Guo Ren Co-developed-by: Guo Ren Signed-off-by: Guo Ren Co-developed-by: Vincent Chen Signed-off-by: Vincent Chen Signed-off-by: Greentime Hu Reviewed-by: Palmer Dabbelt Suggested-by: Vineet Gupta Signed-off-by: Andy Chiu Reviewed-by: Conor Dooley Reviewed-by: Heiko Stuebner Tested-by: Heiko Stuebner --- arch/riscv/include/asm/csr.h | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/arch/riscv/include/asm/csr.h b/arch/riscv/include/asm/csr.h index b6acb7ed115f..b98b3b6c9da2 100644 --- a/arch/riscv/include/asm/csr.h +++ b/arch/riscv/include/asm/csr.h @@ -24,16 +24,24 @@ #define SR_FS_CLEAN _AC(0x00004000, UL) #define SR_FS_DIRTY _AC(0x00006000, UL) +#define SR_VS _AC(0x00000600, UL) /* Vector Status */ +#define SR_VS_OFF _AC(0x00000000, UL) +#define SR_VS_INITIAL _AC(0x00000200, UL) +#define SR_VS_CLEAN _AC(0x00000400, UL) +#define SR_VS_DIRTY _AC(0x00000600, UL) + #define SR_XS _AC(0x00018000, UL) /* Extension Status */ #define SR_XS_OFF _AC(0x00000000, UL) #define SR_XS_INITIAL _AC(0x00008000, UL) #define SR_XS_CLEAN _AC(0x00010000, UL) #define SR_XS_DIRTY _AC(0x00018000, UL) +#define SR_FS_VS (SR_FS | SR_VS) /* Vector and Floating-Point Unit */ + #ifndef CONFIG_64BIT -#define SR_SD _AC(0x80000000, UL) /* FS/XS dirty */ +#define SR_SD _AC(0x80000000, UL) /* FS/VS/XS dirty */ #else -#define SR_SD _AC(0x8000000000000000, UL) /* FS/XS dirty */ +#define SR_SD _AC(0x8000000000000000, UL) /* FS/VS/XS dirty */ #endif #ifdef CONFIG_64BIT @@ -375,6 +383,12 @@ #define CSR_MVIPH 0x319 #define CSR_MIPH 0x354 +#define CSR_VSTART 0x8 +#define CSR_VCSR 0xf +#define CSR_VL 0xc20 +#define CSR_VTYPE 0xc21 +#define CSR_VLENB 0xc22 + #ifdef CONFIG_RISCV_M_MODE # define CSR_STATUS CSR_MSTATUS # define CSR_IE CSR_MIE From patchwork Thu May 18 16:19:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Chiu X-Patchwork-Id: 13247082 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 AAD71C7EE23 for ; Thu, 18 May 2023 16:20:45 +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=ikdIZ+BSpvXmJaLJSHdgBOuTiiiyQ6iH5Vgj6WzlVlk=; b=H+CBgq5h+JyyCw 0nrZR5QZOTIU1yrhavVcKkxIQqF4Oa1SqTlI/iJIe0s8/sebAFmQRRs2BuYsmv2nuGKvvS3Gk+Qb0 5yqgqlrxgGDy9XzR73lZvkdiEJ6bkBescCPkCdmegqhs/Sf9nD5qO+xIlXdKUrT8g49pcg1qqkm/X WlJelmoQVmUjjlQNWUzsUF0VwM21mfZs5Hr6jDcezvp2LCpVjRJiaIoxzwrZZDXNsHM1yDTlklzq2 yQQCxcZ+SbZtdTb2KRSUiEWhRpcM6+mt//L+aXtpY5nTge8Q8S+l+kBp6mpqe1WYPxWW0DFJcDDzF RMYvbzg6ythb05CUqS0w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzgMr-00DR3G-1k; Thu, 18 May 2023 16:20:41 +0000 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzgMo-00DQvk-32 for linux-riscv@lists.infradead.org; Thu, 18 May 2023 16:20:40 +0000 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-64d1a0d640cso637736b3a.1 for ; Thu, 18 May 2023 09:20:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1684426838; x=1687018838; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=peA7uNBICYxq78TCCLilok9fr+B5gTYL7MG+xHpLNFU=; b=e/Cx4vjZipW38IBRBhUU8aPV0WQ9CDgtfZvd9+SXlt/oc76sjLdLw5K70UY3tOULvQ Uo75q6vV/vSwRTYT52hqBU4Qo0xGiFYv/bSmD02LXYS5IUu+ULXNazVfHjLoBc9p4Liq fmcbqts6++pNaHxtj++N4bKR61wnEPDpjKXniaxs0OZqL0JWm9isHY7z3n6rwKC9vbFk iU/dZG5sehiRUg9heZN+R/XkqC0f10nDGhyqVSgy23w0V5bOs9MdYSsM+pSqvvWef+5R 2j/s3iCLJRzL0Njc1G8wnZoViBzLBV0/EoxVNNNJ1l8IV0YN/C9XFGV2dwmkynCe3Iw8 L53A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684426838; x=1687018838; 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=peA7uNBICYxq78TCCLilok9fr+B5gTYL7MG+xHpLNFU=; b=WHFmfJCBzvq6etIMFbXhvhtWXJkPEgoV8xRT1dzHrj1dNulCmWQLW+6gaQG99/nHxv iZm3vXYRCc6tPRCtT37nBrE7vxYYcT0dwMIP2tRAw5b++Ubsw4L7cQ+AYZdyBoLnE87x HEbHPPccy9XE7AexmDOzjIvwIYJ0Zq9swwnh4bpE/WLxSga+eQ18BY440p/DrfOcYkW8 UesIyTupWqiYJaLbcXi40Xe6r+h6xhHdRx4+fhgY/TSFbG54zIuVG5xx2VQGiOGzULdd mXyLZ8BGuDIMjmKOPy9lxMQozcnTCbkz3Tr50pW54DJWUXWcnjDd30kMLU8HN9qEPY8V U8qg== X-Gm-Message-State: AC+VfDzlbshWKF/4cLs3h/HYum8Tgiwk5CM8OI2vMkieP5J9562hScMi ke1dAwAkTX2Iad0EqRQNIVnQzyDC7fZpxubIqqk++FMmBFW8HjoMayg+dzHdK4oCNkmQc+85Srj zib1xE65Fq2mopaKWiTjlO205ca+ZONHHxk1+6+La0PV1p/AjpdENCEi0/8E/loUE+JG+800jsY i8cEXXrL/swARRBwk= X-Google-Smtp-Source: ACHHUZ6GXeuq6ac3dk1QjIBXlTMLesMB0FjJ96RzZemGCdDJ9H4Rc4dGccTHPTd/M9zRn4/iLuk+DQ== X-Received: by 2002:a05:6a00:1908:b0:646:59e4:9514 with SMTP id y8-20020a056a00190800b0064659e49514mr5466238pfi.7.1684426838150; Thu, 18 May 2023 09:20:38 -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.20.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 May 2023 09:20:37 -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 , Heiko Stuebner , Vincent Chen , Guo Ren , Masahiro Yamada , Alexandre Ghiti Subject: [PATCH -next v20 05/26] riscv: Clear vector regfile on bootup Date: Thu, 18 May 2023 16:19:28 +0000 Message-Id: <20230518161949.11203-6-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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230518_092038_980860_A988B668 X-CRM114-Status: GOOD ( 10.17 ) 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 From: Greentime Hu clear vector registers on boot if kernel supports V. Signed-off-by: Greentime Hu Signed-off-by: Vineet Gupta Signed-off-by: Andy Chiu Acked-by: Conor Dooley Reviewed-by: Heiko Stuebner Tested-by: Heiko Stuebner Reviewed-by: Palmer Dabbelt --- arch/riscv/kernel/head.S | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S index 4bf6c449d78b..3fd6a4bd9c3e 100644 --- a/arch/riscv/kernel/head.S +++ b/arch/riscv/kernel/head.S @@ -392,7 +392,7 @@ ENTRY(reset_regs) #ifdef CONFIG_FPU csrr t0, CSR_MISA andi t0, t0, (COMPAT_HWCAP_ISA_F | COMPAT_HWCAP_ISA_D) - beqz t0, .Lreset_regs_done + beqz t0, .Lreset_regs_done_fpu li t1, SR_FS csrs CSR_STATUS, t1 @@ -430,8 +430,31 @@ ENTRY(reset_regs) fmv.s.x f31, zero csrw fcsr, 0 /* note that the caller must clear SR_FS */ +.Lreset_regs_done_fpu: #endif /* CONFIG_FPU */ -.Lreset_regs_done: + +#ifdef CONFIG_RISCV_ISA_V + csrr t0, CSR_MISA + li t1, COMPAT_HWCAP_ISA_V + and t0, t0, t1 + beqz t0, .Lreset_regs_done_vector + + /* + * Clear vector registers and reset vcsr + * VLMAX has a defined value, VLEN is a constant, + * and this form of vsetvli is defined to set vl to VLMAX. + */ + li t1, SR_VS + csrs CSR_STATUS, t1 + csrs CSR_VCSR, x0 + vsetvli t1, x0, e8, m8, ta, ma + vmv.v.i v0, 0 + vmv.v.i v8, 0 + vmv.v.i v16, 0 + vmv.v.i v24, 0 + /* note that the caller must clear SR_VS */ +.Lreset_regs_done_vector: +#endif /* CONFIG_RISCV_ISA_V */ ret END(reset_regs) #endif /* CONFIG_RISCV_M_MODE */ From patchwork Thu May 18 16:19:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Chiu X-Patchwork-Id: 13247083 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 377A1C7EE23 for ; Thu, 18 May 2023 16:20:54 +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=rdXZ5+zte1XpAiQJQMa52XSjn0CEX4m8cL1wov7+8og=; b=j5HgaaiGhOyeiH pGtryH9jDmRTx89Ae/8od9wU9tRXUmVzqbj9fwknYO+dGCisMvv7vVvVEL56jOZLCwSdBimzWj0fx KDY/Ik6c/ZfnINygJvhzHQ9w4mNMQll3/ZeY8k6UHUvHHiFnMAOWwENmO+51QRoQHDSRIYm8gPXDq mDrDCyNY35nXIR6t03soZfh0Hj0pxbmu2vUM6b0RJabVDX5lRLG3jbqYEpg7V4Bjw6SCooHWJhQTo 8VvMnGS8VJHJV1zUoMHpKjQmSoldj+fCE8MNOT1qhFqIrMo0USFtSU0zIhKMhBJ9mdRiE6Sbf79mN l/Mp/KSpaBd7GHnaG1sA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzgN0-00DR7b-12; Thu, 18 May 2023 16:20:50 +0000 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzgMx-00DR52-37 for linux-riscv@lists.infradead.org; Thu, 18 May 2023 16:20:49 +0000 Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-64d293746e0so429838b3a.2 for ; Thu, 18 May 2023 09:20:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1684426844; x=1687018844; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=FRXZE7cUr4vJpRYfnGIy+KdEpJQsKyQubDyjJds5WmA=; b=K0sq07ep0xgW47SiAQZ3mrkYd3ihUXW1o5X2dmqk+KHaUmfcKz7iDdZbdlGDrN2YTp 5DeGUsMaYYBoNo7OPUrnB1o1Aduw2SsRWM4a4jUKNvE7hnIYIdFSEZfMIqChaZplAtkn VaGio+9asUumTMS4/QJbogfBlyh/ynUvshblsUweW1qZ1wrYI97TOIuwXgaQlBlO97Mt ZdnsUeMXWkIpdDHxMNdj1cUTf4lmv6Tgd8b0dMHDDbJe7XKCfQb5bLiyeQuJ8lfutKH6 uVJWnniozsnYEgHJhkcF8L0OIw9sYYEN63jl+nKGMnkPaVbrz/a/jQbWk+w8RRlPxY7D jZZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684426844; x=1687018844; 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=FRXZE7cUr4vJpRYfnGIy+KdEpJQsKyQubDyjJds5WmA=; b=ZuGanQiRRdbqkYhRqeHMsygVn7jRT+HGUySmZh9Y/KlOC7L5mzYm/w5zy0OWcVv2uX 7a/vM7jX13+UKV6aWuNGZjHRX89bSjWoq5T7VTT8N0eQ/QnCx98dq0GIVO3dtq6HOjIN 2FUqkZ+yanxlPRmYXe14aEDZIQS9ugbsMXyIxduHxlXJrRNWE5+IhlvAd70uCz1uZpfM BqeuljoR8PpVc3TxesC/UzY6mTX0J4jCbSmWU3Joc/LRQcApDSsndq3HxexBU6MrH32q I8pYgAiNUf4Za89YJLwCqlOhvJFZlqyMmujI2sCkfoRH01UDCNOxxjmo6y1hiBM79JUx JT5A== X-Gm-Message-State: AC+VfDzmZbmIfqikuB33DCIqg/41Flu814VtxlxvESPOn1jyb/qnDR3n eZ+z2EvRfg/PEvNGjEi+N23RGyCtgPwgTLOaJfojUH/tzAxqZUKCjMu+8ImZLWDfWdtYfJRMiA1 q9a2xXPxfNv89WxK6ppOlvlVJgwdITB9exPwOMWWsyPvlOhGK3aaoF9qA0XltNoy/JOopg1Xwh3 JZVJiXfcVnG4Owe90= X-Google-Smtp-Source: ACHHUZ5FXgh1BaQAiszAq3zIK5JJX/Mc9ezgyx9aawTK/ZyCwI2FrNTtaURsYq3P2rJD9AlJKANUsw== X-Received: by 2002:a05:6a20:4321:b0:104:3c82:38c0 with SMTP id h33-20020a056a20432100b001043c8238c0mr206284pzk.41.1684426844233; Thu, 18 May 2023 09:20:44 -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.20.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 May 2023 09:20:43 -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, Vincent Chen , Han-Kuan Chen , Andy Chiu , Paul Walmsley , Albert Ou , Guo Ren , Jisheng Zhang , Nicolas Saenz Julienne , =?utf-8?b?QmrDtnJuIFTDtnBl?= =?utf-8?b?bA==?= , Frederic Weisbecker , Andrew Bresticker , Heiko Stuebner , Conor Dooley , Masahiro Yamada , Alexandre Ghiti Subject: [PATCH -next v20 06/26] riscv: Disable Vector Instructions for kernel itself Date: Thu, 18 May 2023 16:19:29 +0000 Message-Id: <20230518161949.11203-7-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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230518_092048_008215_15734F38 X-CRM114-Status: GOOD ( 11.79 ) 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 From: Guo Ren Disable vector instructions execution for kernel mode at its entrances. This helps find illegal uses of vector in the kernel space, which is similar to the fpu. Signed-off-by: Guo Ren Co-developed-by: Vincent Chen Signed-off-by: Vincent Chen Co-developed-by: Han-Kuan Chen Signed-off-by: Han-Kuan Chen Co-developed-by: Greentime Hu Signed-off-by: Greentime Hu Signed-off-by: Vineet Gupta Signed-off-by: Andy Chiu Reviewed-by: Conor Dooley Reviewed-by: Heiko Stuebner Tested-by: Heiko Stuebner Reviewed-by: Palmer Dabbelt --- Changelog V19: - Add description in commit msg (Heiko's suggestion on v17) --- arch/riscv/kernel/entry.S | 6 +++--- arch/riscv/kernel/head.S | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S index 3fbb100bc9e4..e9ae284a55c1 100644 --- a/arch/riscv/kernel/entry.S +++ b/arch/riscv/kernel/entry.S @@ -48,10 +48,10 @@ _save_context: * Disable user-mode memory access as it should only be set in the * actual user copy routines. * - * Disable the FPU to detect illegal usage of floating point in kernel - * space. + * Disable the FPU/Vector to detect illegal usage of floating point + * or vector in kernel space. */ - li t0, SR_SUM | SR_FS + li t0, SR_SUM | SR_FS_VS REG_L s0, TASK_TI_USER_SP(tp) csrrc s1, CSR_STATUS, t0 diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S index 3fd6a4bd9c3e..e16bb2185d55 100644 --- a/arch/riscv/kernel/head.S +++ b/arch/riscv/kernel/head.S @@ -140,10 +140,10 @@ secondary_start_sbi: .option pop /* - * Disable FPU to detect illegal usage of - * floating point in kernel space + * Disable FPU & VECTOR to detect illegal usage of + * floating point or vector in kernel space */ - li t0, SR_FS + li t0, SR_FS_VS csrc CSR_STATUS, t0 /* Set trap vector to spin forever to help debug */ @@ -234,10 +234,10 @@ pmp_done: .option pop /* - * Disable FPU to detect illegal usage of - * floating point in kernel space + * Disable FPU & VECTOR to detect illegal usage of + * floating point or vector in kernel space */ - li t0, SR_FS + li t0, SR_FS_VS csrc CSR_STATUS, t0 #ifdef CONFIG_RISCV_BOOT_SPINWAIT From patchwork Thu May 18 16:19:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Chiu X-Patchwork-Id: 13247084 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 547FCC77B7D for ; Thu, 18 May 2023 16:20:58 +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=4k3nCaEbxEK6Q97cKvkDXNBXRksU/riV0XuPNkPtg/Q=; b=XaUH6Ate0dDr0G XF9wFIIuY4t/KcqNcjUZ4PS/mElreHc05P0TwEGmI0n2RhI1D+CE7ZMnOQ+5OKPKWLUZqmUr2sndQ 7Az27JwdzEiiN6Ik5Yd1aXGfCmoDo+aLF9GhEp7NkU186UoI12mH1FsoxuN38HLCw0PIBp7YJ493h 3QhSvsE11zaKqMIXjTOVu022Ri81D7geWfI49rkUp+z8x1b7ma4zBD2gYJdNvPrA87dKrNDbPSeo3 kjq79DO58HXquZYlKhvjT6kjEmacGCdqBjN1skKLGFAAm2ztbVx8LBe5/zfLaea/0FEnUdLq/xBcL Y8L/l3B2h40q39aN2ZMA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzgN4-00DR9f-14; Thu, 18 May 2023 16:20:54 +0000 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzgN2-00DR7P-1Z for linux-riscv@lists.infradead.org; Thu, 18 May 2023 16:20:53 +0000 Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-64d18d772bdso1023915b3a.3 for ; Thu, 18 May 2023 09:20:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1684426849; x=1687018849; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=EvrLPd1cTqQ0pEVjiT8YUKSvx/1xPgu8clZhUQSofCQ=; b=FtLX8JHMQVKFgHWdhhjDwu5jM+3buCm2ENvMKVrAVq3ECMS1bVPyUMeq2sWQDArIBS weDpuuKtqbRkamnCmrUT2qEzUeeJUuFLpxRfpG+7cRZ+TBvXVMhFeTMlvz62Szg5I53a 2w9TC3AuvI6dJyYFj6+rtYIp2YS+SK4mhZqne9iu1i/N+c1OofX9baV5rP7q+pT1k9XC e2HV/TAzc8dM18AE/dYTLU4qH91Z1fROP1jdnrYvxyJtKJ6MOJou2kOJXVOqlS6psFHq dOQYanISqH6CNTuS8uHjbkKImoTX0yDVWEWXOk7LhLR+PMPEZ1WzsBnw3geXeADcfiZZ MKbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684426849; x=1687018849; 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=EvrLPd1cTqQ0pEVjiT8YUKSvx/1xPgu8clZhUQSofCQ=; b=C1AtFoFeEW4KGgUTi7SORPDOWpZuG/VIFEyUaubIG+C1fw5YFm1ZMyrSrKthfqsyNW dZ4bGtwZ3rEbqWtQ9sjaYKPjh7JFIFVfbbxpcfc6n7uZGkBg66zG0PORg1eA11J7YB7M 0OyC81wQlksXtDx1wWe/GsGq8cZqI87EaW/6bGFDkherjwWauxIGlybXv88fvvX9tyXi kcXFZQZi2AEEN5aHH60l3Q6I+DiMUaNXqceLSz9aDhiXSm8PF7Mjm80xzWNl9E1dJmvV HL6wjoYBfCqELHD3rD8uNWqERjIw3SF1RkaQuMyjPuqFju7iZhNpfVA9WVS8PGPMZXU0 WJYg== X-Gm-Message-State: AC+VfDyJvpsdD88Ln+9caqyPCtrBDORDyF7uq5YO9kO8l6nBHgMnCte6 EBfcoSIPO7zlkLoYstJDQotCD+F5K66EQLYYnxj9sTv8blNrkvw8vjoF3JqJevzZ8YGzYf37quu X3hngOQSIVV1gz0BVd/lZFDeh3waCi3FHEWjqy4fERZJPobWzgi8vm4DvajV55o/Zxkou0d2T31 hLQ1+SmhzOBGjuav8= X-Google-Smtp-Source: ACHHUZ5F3YhKPesHs63kyS2hI87hWRcOXYkoisFdhsrt59NTCICskzaqIsvfB/OKK4tRgfNkxyJKRg== X-Received: by 2002:a05:6a00:2ea4:b0:64a:9090:5147 with SMTP id fd36-20020a056a002ea400b0064a90905147mr5497396pfb.10.1684426848755; Thu, 18 May 2023 09:20:48 -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.20.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 May 2023 09:20:48 -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, Vincent Chen , Andy Chiu , Paul Walmsley , Albert Ou , Heiko Stuebner , Guo Ren Subject: [PATCH -next v20 07/26] riscv: Introduce Vector enable/disable helpers Date: Thu, 18 May 2023 16:19:30 +0000 Message-Id: <20230518161949.11203-8-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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230518_092052_522383_5173244F X-CRM114-Status: UNSURE ( 6.74 ) 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 From: Greentime Hu These are small and likely to be frequently called so implement as inline routines (vs. function call). Co-developed-by: Guo Ren Signed-off-by: Guo Ren Co-developed-by: Vincent Chen Signed-off-by: Vincent Chen Signed-off-by: Greentime Hu Signed-off-by: Vineet Gupta Signed-off-by: Andy Chiu Reviewed-by: Conor Dooley Reviewed-by: Heiko Stuebner Tested-by: Heiko Stuebner Reviewed-by: Palmer Dabbelt --- arch/riscv/include/asm/vector.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/arch/riscv/include/asm/vector.h b/arch/riscv/include/asm/vector.h index bdbb05b70151..51bb37232943 100644 --- a/arch/riscv/include/asm/vector.h +++ b/arch/riscv/include/asm/vector.h @@ -11,12 +11,23 @@ #ifdef CONFIG_RISCV_ISA_V #include +#include static __always_inline bool has_vector(void) { return riscv_has_extension_unlikely(RISCV_ISA_EXT_v); } +static __always_inline void riscv_v_enable(void) +{ + csr_set(CSR_SSTATUS, SR_VS); +} + +static __always_inline void riscv_v_disable(void) +{ + csr_clear(CSR_SSTATUS, SR_VS); +} + #else /* ! CONFIG_RISCV_ISA_V */ static __always_inline bool has_vector(void) { return false; } From patchwork Thu May 18 16:19:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Chiu X-Patchwork-Id: 13247165 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 5907FC7EE2A for ; Thu, 18 May 2023 17:30:50 +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:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=vE/l4yB4ms2V5pqI3X9m+JnWe3bqn22meZww2BJF5iE=; b=NwyJkivpZJ1PHE4pSh3v+ecTxh UKp0DPEktfLwFt5zZAj6YG9WNVZVGh7itf7PZ6j1tfnm/AOWEA+CBy1gbYwLl5AtnsucEOo59gLGN ZpvU6ABAswTPxkHH+GLbuSev4smXqii180DTB1220FurhCDhl6C/fVL46bc6K+TkeJOuyvU1sY0AK xxu9avvxmFMezGSOMpqdmjasFSUh838F8M0gUfTGzBJohwjhoPqNvcn920ooVkyltaxobQVMwxFcG qA//BTYPHfZbS/SYGq4ATbsmDZYdRqnxV3x40jj3gI0RTdp16imsvD8LoT2fKdzlTybvQEX9aB5qa HTBeSXrw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzhSg-00De0x-12; Thu, 18 May 2023 17:30:46 +0000 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzgNF-00DRD2-2A for linux-riscv@lists.infradead.org; Thu, 18 May 2023 16:21:07 +0000 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-64388cf3263so1615090b3a.3 for ; Thu, 18 May 2023 09:21:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1684426860; x=1687018860; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=ShTLilbxMyWLUQGoTSAD12rpTJu8sGTqDWBHoo4WTRA=; b=j/b6no5b61h4cLD0MeMj8ztuxkCuqZ1vb5Vk1nLx3vXkVHmADEC3+8goQLfitPW88G T7v7IlOWLfQAU4HDE1hLFH+ks0ECTVPiOAbOKOmZ/ByDjs3sQjeAyw8wSuoFlkU80/nr U59r1B7AE6Ptk9R2mWZC53lvDTxGjhonX8oam9ZxM6MxTNxOMijLfNuOH6qLKNv87wK0 //CFVLRkh6iSX6gVYNgOcWUgYktjG7fJ8DRGqvkT/ynRkecNTRu3gW3GBJDtq1UR5o53 SoHriCZykj0bSEBu21oANOp/Sk0CZWAcT35ZfARI/cnySA+9JfJ5lLdcfwtoKADNKVby a1zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684426860; x=1687018860; 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=ShTLilbxMyWLUQGoTSAD12rpTJu8sGTqDWBHoo4WTRA=; b=UbYGXKT3/Sd12E8knOjR9uTjHUJO+HennJ1hCvSc7JDdLy5uoA9TkcjgYxLbN1K+iV aDd6uj/Igq2YdufEQFGoL6oGBHM6iB901KjlaDjRrwvgkAX2o9rNRFa9E9RNZH43UBaL S6rMGK2zLyGf/9cp5EgWZ1OYp4Cg1ZbHrQI7jXYLIjoAYodUFhpjJ097mhgmx/xUyuzz dHZr0Jv1kXVJfdSoGwLOlujWBXGaKsfRXD7firQt7j8tFneoXRpgglNzfq2YpKCpbxFY ePZgZBql5jegHDxlOmaX2DeR2B80CTexPxqGD23qHfxuKxv4FUeQsVxLKKgYqsz8/iQN kjSQ== X-Gm-Message-State: AC+VfDz43piaRpSJPohY8slrkrogIoxe5h7SwMA1MQUBwDobW3ngHp/T 2meLpiKZpT9csT3PoygbLPhJcMdhZ/k7xpoTnYXU9EwTyA+RGssO1IiIGmLz6oEwBjNDKEdF/uJ idfRKcaaU+LEL7zDN+wwgz32A9zj+kQbdXOnOOzGUFSFT22dFBwnVKXqAIkCfAJ19Fcw1XUaGhG 3Uwfiy0n1weR0gp50= X-Google-Smtp-Source: ACHHUZ7YkWvX/tqItDMFWCkxRS+F2Fxhk5OtrMbd1658dUwowW9yV9Fwym+hly8gnFJ9ny7Oh6doTQ== X-Received: by 2002:a05:6a00:1a05:b0:64d:88b:a342 with SMTP id g5-20020a056a001a0500b0064d088ba342mr4655900pfv.30.1684426859642; Thu, 18 May 2023 09:20:59 -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.20.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 May 2023 09:20:58 -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 Subject: [PATCH -next v20 08/26] riscv: Introduce riscv_v_vsize to record size of Vector context Date: Thu, 18 May 2023 16:19:31 +0000 Message-Id: <20230518161949.11203-9-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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230518_092105_707246_F4F2C520 X-CRM114-Status: GOOD ( 19.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: , Cc: Anup Patel , guoren@linux.alibaba.com, Alexandre Ghiti , Jisheng Zhang , Sia Jee Heng , Masahiro Yamada , vineetg@rivosinc.com, =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Vincent Chen , Conor Dooley , Albert Ou , Guo Ren , Evan Green , Andy Chiu , Paul Walmsley , Ley Foon Tan , greentime.hu@sifive.com, Heiko Stuebner , Li Zhengyu , Andrew Jones MIME-Version: 1.0 Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org From: Greentime Hu This patch is used to detect the size of CPU vector registers and use riscv_v_vsize to save the size of all the vector registers. It assumes all harts has the same capabilities in a SMP system. If a core detects VLENB that is different from the boot core, then it warns and turns off V support for user space. Co-developed-by: Guo Ren Signed-off-by: Guo Ren Co-developed-by: Vincent Chen Signed-off-by: Vincent Chen Signed-off-by: Greentime Hu Signed-off-by: Andy Chiu Reviewed-by: Conor Dooley Reviewed-by: Heiko Stuebner Tested-by: Heiko Stuebner Reviewed-by: Palmer Dabbelt --- Changelog V19: - Fix grammar in WARN() (Conor) Changelog V18: - Detect inconsistent VLEN setup on an SMP system (Heiko). --- arch/riscv/include/asm/vector.h | 8 ++++++++ arch/riscv/kernel/Makefile | 1 + arch/riscv/kernel/cpufeature.c | 2 ++ arch/riscv/kernel/smpboot.c | 7 +++++++ arch/riscv/kernel/vector.c | 36 +++++++++++++++++++++++++++++++++ 5 files changed, 54 insertions(+) create mode 100644 arch/riscv/kernel/vector.c diff --git a/arch/riscv/include/asm/vector.h b/arch/riscv/include/asm/vector.h index 51bb37232943..df3b5caecc87 100644 --- a/arch/riscv/include/asm/vector.h +++ b/arch/riscv/include/asm/vector.h @@ -7,12 +7,16 @@ #define __ASM_RISCV_VECTOR_H #include +#include #ifdef CONFIG_RISCV_ISA_V #include #include +extern unsigned long riscv_v_vsize; +int riscv_v_setup_vsize(void); + static __always_inline bool has_vector(void) { return riscv_has_extension_unlikely(RISCV_ISA_EXT_v); @@ -30,7 +34,11 @@ static __always_inline void riscv_v_disable(void) #else /* ! CONFIG_RISCV_ISA_V */ +struct pt_regs; + +static inline int riscv_v_setup_vsize(void) { return -EOPNOTSUPP; } static __always_inline bool has_vector(void) { return false; } +#define riscv_v_vsize (0) #endif /* CONFIG_RISCV_ISA_V */ diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile index fbdccc21418a..c51f34c2756a 100644 --- a/arch/riscv/kernel/Makefile +++ b/arch/riscv/kernel/Makefile @@ -56,6 +56,7 @@ obj-$(CONFIG_MMU) += vdso.o vdso/ obj-$(CONFIG_RISCV_M_MODE) += traps_misaligned.o obj-$(CONFIG_FPU) += fpu.o +obj-$(CONFIG_RISCV_ISA_V) += vector.o obj-$(CONFIG_SMP) += smpboot.o obj-$(CONFIG_SMP) += smp.o obj-$(CONFIG_SMP) += cpu_ops.o diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index 7aaf92fff64e..28032b083463 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -18,6 +18,7 @@ #include #include #include +#include #define NUM_ALPHA_EXTS ('z' - 'a' + 1) @@ -269,6 +270,7 @@ void __init riscv_fill_hwcap(void) } if (elf_hwcap & COMPAT_HWCAP_ISA_V) { + riscv_v_setup_vsize(); /* * ISA string in device tree might have 'v' flag, but * CONFIG_RISCV_ISA_V is disabled in kernel. diff --git a/arch/riscv/kernel/smpboot.c b/arch/riscv/kernel/smpboot.c index 445a4efee267..66011bf2b36e 100644 --- a/arch/riscv/kernel/smpboot.c +++ b/arch/riscv/kernel/smpboot.c @@ -31,6 +31,8 @@ #include #include #include +#include +#include #include "head.h" @@ -169,6 +171,11 @@ asmlinkage __visible void smp_callin(void) set_cpu_online(curr_cpuid, 1); probe_vendor_features(curr_cpuid); + if (has_vector()) { + if (riscv_v_setup_vsize()) + elf_hwcap &= ~COMPAT_HWCAP_ISA_V; + } + /* * Remote TLB flushes are ignored while the CPU is offline, so emit * a local TLB flush right now just in case. diff --git a/arch/riscv/kernel/vector.c b/arch/riscv/kernel/vector.c new file mode 100644 index 000000000000..120f1ce9abf9 --- /dev/null +++ b/arch/riscv/kernel/vector.c @@ -0,0 +1,36 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2023 SiFive + * Author: Andy Chiu + */ +#include + +#include +#include +#include +#include + +unsigned long riscv_v_vsize __read_mostly; +EXPORT_SYMBOL_GPL(riscv_v_vsize); + +int riscv_v_setup_vsize(void) +{ + unsigned long this_vsize; + + /* There are 32 vector registers with vlenb length. */ + riscv_v_enable(); + this_vsize = csr_read(CSR_VLENB) * 32; + riscv_v_disable(); + + if (!riscv_v_vsize) { + riscv_v_vsize = this_vsize; + return 0; + } + + if (riscv_v_vsize != this_vsize) { + WARN(1, "RISCV_ISA_V only supports one vlenb on SMP systems"); + return -EOPNOTSUPP; + } + + return 0; +} From patchwork Thu May 18 16:19:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andy Chiu X-Patchwork-Id: 13247095 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 04E6EC77B7A for ; Thu, 18 May 2023 16:40:28 +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=i/rDMSs5+iY2woHYJMhPSh0mUnR5d595KEHgWmVao7I=; b=skI+iaeTKL91lp t5CYQTA+Zow6P9wBaGdHuGvLgWTFi0k5nMaAKmwW24uzuZiVId7m+jNE8/CcrkgTYcUjfkxv5qXpt qzQc7LLeVGZnwzWHEIm3shBUxkD/eKK14CCfaErKdNnwBfdYYQqK0xMhL0JzvPPTa66x/rQLrlTYn 5yxK0Thrv+opWnUCTt+0/tdWn7doLrgPQ5tBRgQ8JEmXuyy09e+H5+jIQ9W4J5SvzkGLfJLd3/LYN BhAvrZcoyqd9izkXVhG1dIPdPhEyLyUtDJlTKyvOF3tNqUWygpqYCCcaYti3goI0d1b7h1pyIFI2a /Jw5xcleiChpxCl/ZAqg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzgfv-00DUuZ-1q; Thu, 18 May 2023 16:40:23 +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 1pzgft-00DUtP-1Z for linux-riscv@bombadil.infradead.org; Thu, 18 May 2023 16:40:21 +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=Zgwm1t43SJfpy9DrAiV+ciMDfg3wElSoTQtIFJq3cgU=; b=GEjjdWNzu8p1/+Zwyo1Als6MPf BzxJrR1Zog0bxkQeUwd7cy6cZti8ZcdF+RKzLB6jltGDGE7WnBq6Gzjzy0mapdWK9ApbrK8dKd21N 0rJW9Lm8mIGjFPHSmV/SeWoN4HUHaa6tO4xaVnZ1gT+dEFpu15HXLyVjvSpHirjeE86eNqWCF7IGz kMgS8aqHn6xhhJz/DQrCbfnLsS47/DbjEHsSFtP1n+D6vulCkjLrpqCe/xV3p0u66yjmBlMk+qTjZ VjUSSnDmBBvXN8YjOxHQyc6s7lLSsUyoZvsS6+f53j6FGEdB8JpJaCVcttljjzZEM2dHfhzkECPrH yYsQynJw==; Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzgNH-00ErLT-2S for linux-riscv@lists.infradead.org; Thu, 18 May 2023 16:21:09 +0000 Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-64d2981e3abso287098b3a.1 for ; Thu, 18 May 2023 09:21:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1684426865; x=1687018865; 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=Zgwm1t43SJfpy9DrAiV+ciMDfg3wElSoTQtIFJq3cgU=; b=LyM9bhV16q6PUaafI2xVfP/P6GftAZwrqsnAY/9ocZAILuEt68EoHhLyrLnBNgiwY8 mdEbS8Cv745w6pvBD+bVERM37H23B6k94R+f4dn+tcsczxbm2LcdlWghGtMYi+IwOM/4 uPXSpwg/fKsKa3rqdcoXou4ru1OC+JNKCh7LfVkO5Jo9E1Gep+cJ1ar4UpiGy6iehbAV 3U4Hjx1mKN6ePhw8rlKZHMm4rdpmAivPOgwWllE49OevgFtaewRVis3H62WSBmi0bJMb CvpoRr/XstvU04g8s6rLfdOCkjVpJhwwOu2KOJdwtro9N2s8tMdz+2ifmgRCDb3NfZ3h gHPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684426865; x=1687018865; 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=Zgwm1t43SJfpy9DrAiV+ciMDfg3wElSoTQtIFJq3cgU=; b=GsteRav4gTRIJupBJ7BXgsh6P3CuHGX7kmq0D2DwhKGHg7k5fbaFUoVy0zv5wEkIr3 KWsq0a/rK+rpLeCGIbnL//GD9cdjJLJO8Gn8LCSvWiD3cimWJXcnjFEPwNi+oDGEuC4k h3AalcsR8TwKqtE1pK5nVMm9p5stw4fPrlNkj2ZgUwONA89lcz1k+OczxJi61FMFK+1j dhLVRYBmZk5csThTYTlEqvB0z2slCVDZylffmWcBFMVPnkrWKQROBLTrW2CzYhVUnInY xdGoGzNF/pqa+VzDjCsbzxPcJoLSNDHLzHHSYjqsXEMF1heFy3jag19Z+5Mp4TTRnasG /1ag== X-Gm-Message-State: AC+VfDzy64oYWrLc6xz+Efctv5Fcg/EpW0Apzr9uvLO27+BCqzqUnjm4 W74WeAKT6MrU1LSI56Unjt37O5gvZAk3bP69hDqcLw14KJnO3P3UWCgGunt874xwAKxs7Xu8zBH jhQZUITtzvtoKHaK2qUxlR+S8tjq+ziT/u0vlkVXMK/Gg+/AuFvP8CzelfyIiwSaIWbZCSlO7IW GtamTHCMJayiPNbWU= X-Google-Smtp-Source: ACHHUZ5/uqfj4c5FsQaeIh/+by7OIWeOL9yYb4WWUqPBhdAtvNIA/9TgeTb0VHs89J84EarVxCDTbg== X-Received: by 2002:a05:6a00:24d1:b0:643:2559:80f3 with SMTP id d17-20020a056a0024d100b00643255980f3mr6553015pfv.2.1684426865160; Thu, 18 May 2023 09:21:05 -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.21.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 May 2023 09:21:04 -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, Vincent Chen , Andy Chiu , Paul Walmsley , Albert Ou , Heiko Stuebner , Guo Ren , Conor Dooley Subject: [PATCH -next v20 09/26] riscv: Introduce struct/helpers to save/restore per-task Vector state Date: Thu, 18 May 2023 16:19:32 +0000 Message-Id: <20230518161949.11203-10-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_172107_906694_5F1AB653 X-CRM114-Status: GOOD ( 12.36 ) 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 From: Greentime Hu Add vector state context struct to be added later in thread_struct. And prepare low-level helper functions to save/restore vector contexts. This include Vector Regfile and CSRs holding dynamic configuration state (vstart, vl, vtype, vcsr). The Vec Register width could be implementation defined, but same for all processes, so that is saved separately. This is not yet wired into final thread_struct - will be done when __switch_to actually starts doing this in later patches. Given the variable (and potentially large) size of regfile, they are saved in dynamically allocated memory, pointed to by datap pointer in __riscv_v_ext_state. Co-developed-by: Vincent Chen Signed-off-by: Vincent Chen Signed-off-by: Greentime Hu Signed-off-by: Vineet Gupta Signed-off-by: Andy Chiu Acked-by: Conor Dooley Reviewed-by: Guo Ren Reviewed-by: Björn Töpel Reviewed-by: Heiko Stuebner Tested-by: Heiko Stuebner Reviewed-by: Palmer Dabbelt --- arch/riscv/include/asm/vector.h | 95 ++++++++++++++++++++++++++++ arch/riscv/include/uapi/asm/ptrace.h | 17 +++++ 2 files changed, 112 insertions(+) diff --git a/arch/riscv/include/asm/vector.h b/arch/riscv/include/asm/vector.h index df3b5caecc87..3c29f4eb552a 100644 --- a/arch/riscv/include/asm/vector.h +++ b/arch/riscv/include/asm/vector.h @@ -11,8 +11,10 @@ #ifdef CONFIG_RISCV_ISA_V +#include #include #include +#include extern unsigned long riscv_v_vsize; int riscv_v_setup_vsize(void); @@ -22,6 +24,26 @@ static __always_inline bool has_vector(void) return riscv_has_extension_unlikely(RISCV_ISA_EXT_v); } +static inline void __riscv_v_vstate_clean(struct pt_regs *regs) +{ + regs->status = (regs->status & ~SR_VS) | SR_VS_CLEAN; +} + +static inline void riscv_v_vstate_off(struct pt_regs *regs) +{ + regs->status = (regs->status & ~SR_VS) | SR_VS_OFF; +} + +static inline void riscv_v_vstate_on(struct pt_regs *regs) +{ + regs->status = (regs->status & ~SR_VS) | SR_VS_INITIAL; +} + +static inline bool riscv_v_vstate_query(struct pt_regs *regs) +{ + return (regs->status & SR_VS) != 0; +} + static __always_inline void riscv_v_enable(void) { csr_set(CSR_SSTATUS, SR_VS); @@ -32,13 +54,86 @@ static __always_inline void riscv_v_disable(void) csr_clear(CSR_SSTATUS, SR_VS); } +static __always_inline void __vstate_csr_save(struct __riscv_v_ext_state *dest) +{ + asm volatile ( + "csrr %0, " __stringify(CSR_VSTART) "\n\t" + "csrr %1, " __stringify(CSR_VTYPE) "\n\t" + "csrr %2, " __stringify(CSR_VL) "\n\t" + "csrr %3, " __stringify(CSR_VCSR) "\n\t" + : "=r" (dest->vstart), "=r" (dest->vtype), "=r" (dest->vl), + "=r" (dest->vcsr) : :); +} + +static __always_inline void __vstate_csr_restore(struct __riscv_v_ext_state *src) +{ + asm volatile ( + ".option push\n\t" + ".option arch, +v\n\t" + "vsetvl x0, %2, %1\n\t" + ".option pop\n\t" + "csrw " __stringify(CSR_VSTART) ", %0\n\t" + "csrw " __stringify(CSR_VCSR) ", %3\n\t" + : : "r" (src->vstart), "r" (src->vtype), "r" (src->vl), + "r" (src->vcsr) :); +} + +static inline void __riscv_v_vstate_save(struct __riscv_v_ext_state *save_to, + void *datap) +{ + unsigned long vl; + + riscv_v_enable(); + __vstate_csr_save(save_to); + asm volatile ( + ".option push\n\t" + ".option arch, +v\n\t" + "vsetvli %0, x0, e8, m8, ta, ma\n\t" + "vse8.v v0, (%1)\n\t" + "add %1, %1, %0\n\t" + "vse8.v v8, (%1)\n\t" + "add %1, %1, %0\n\t" + "vse8.v v16, (%1)\n\t" + "add %1, %1, %0\n\t" + "vse8.v v24, (%1)\n\t" + ".option pop\n\t" + : "=&r" (vl) : "r" (datap) : "memory"); + riscv_v_disable(); +} + +static inline void __riscv_v_vstate_restore(struct __riscv_v_ext_state *restore_from, + void *datap) +{ + unsigned long vl; + + riscv_v_enable(); + asm volatile ( + ".option push\n\t" + ".option arch, +v\n\t" + "vsetvli %0, x0, e8, m8, ta, ma\n\t" + "vle8.v v0, (%1)\n\t" + "add %1, %1, %0\n\t" + "vle8.v v8, (%1)\n\t" + "add %1, %1, %0\n\t" + "vle8.v v16, (%1)\n\t" + "add %1, %1, %0\n\t" + "vle8.v v24, (%1)\n\t" + ".option pop\n\t" + : "=&r" (vl) : "r" (datap) : "memory"); + __vstate_csr_restore(restore_from); + riscv_v_disable(); +} + #else /* ! CONFIG_RISCV_ISA_V */ struct pt_regs; static inline int riscv_v_setup_vsize(void) { return -EOPNOTSUPP; } static __always_inline bool has_vector(void) { return false; } +static inline bool riscv_v_vstate_query(struct pt_regs *regs) { return false; } #define riscv_v_vsize (0) +#define riscv_v_vstate_off(regs) do {} while (0) +#define riscv_v_vstate_on(regs) do {} while (0) #endif /* CONFIG_RISCV_ISA_V */ diff --git a/arch/riscv/include/uapi/asm/ptrace.h b/arch/riscv/include/uapi/asm/ptrace.h index 882547f6bd5c..586786d023c4 100644 --- a/arch/riscv/include/uapi/asm/ptrace.h +++ b/arch/riscv/include/uapi/asm/ptrace.h @@ -77,6 +77,23 @@ union __riscv_fp_state { struct __riscv_q_ext_state q; }; +struct __riscv_v_ext_state { + unsigned long vstart; + unsigned long vl; + unsigned long vtype; + unsigned long vcsr; + void *datap; + /* + * In signal handler, datap will be set a correct user stack offset + * and vector registers will be copied to the address of datap + * pointer. + * + * In ptrace syscall, datap will be set to zero and the vector + * registers will be copied to the address right after this + * structure. + */ +}; + #endif /* __ASSEMBLY__ */ #endif /* _UAPI_ASM_RISCV_PTRACE_H */ From patchwork Thu May 18 16:19:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andy Chiu X-Patchwork-Id: 13247169 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 B2E76C7EE23 for ; Thu, 18 May 2023 17:30:53 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Seu/MrU2yY9IWgI5K3L1ZbsF/9VtC5q+jQYZ/GDA0jk=; b=ngfi6Gv2xlIHkF pWTOrsfjaNbxbzDapWE4YmGGKMFtnD8wLuA/TK06AW9RoxuLc/S3ovfd3enEiOH0w9H/QtZktVDKy XiedycrVYNgo+61KpdF121ePnLGhHGWm8FmlakN1IGh/Y/ZcBSE/JrZPQ1N/qEmTqR0hhJiZlZcs4 sBWiT5Aon4p7OyPgHRtAkGltQsNu1YAqjDBrk2Qwh5jdFhqs9shwuti8VmN/sY+WTwcr3YdozlnyB cJodPlq7ICNH5v53UbrKN1wa7EaH/N5bO28zr6V8W8jMXAQidVbwKj6eyGs4pK0ZpD8O7LbdhyLUi I6RRqjxfK5pV1tYtIHEw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzhSh-00De1S-0C; Thu, 18 May 2023 17:30:47 +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 1pzgNP-00DRKK-0c for linux-riscv@lists.infradead.org; Thu, 18 May 2023 16:21:16 +0000 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-64d247a023aso478429b3a.2 for ; Thu, 18 May 2023 09:21:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1684426874; x=1687018874; 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=UElBVrkqMO4WVRUcV67o7DLF+YtWWWQQqoV8c4X2CtE=; b=Scde8osi/RJWI78dDSKr9Z8zWs3x8xPBm7l1tsizui43fhRived2P29XpJ+Tr3cfUw O+Msaan3TmLTy2WSQlVsaVY+AKWfCkMVXM6ruBeqLn38u1LI1STlqIJ6gq2JHVSzi9dn q3oJpW4k2Ck4yskG1u74t4T4UGzN2EHF6wryxDyyb8YNnTYwINS3zGwrc/tonnvVkEDV hxSbmgO9XxYbna0eYq9P16kZZ+oWfcD5/HkY8zV1qS2+zLWE+RQUh7DaL+87Go0G5dFP MnMYiupH+f/cnwSLLxCTIZy/mf6AkkoYAmgdP57+MNywsFnztrio0DPW4ryIPJaO6+MI Sqcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684426874; x=1687018874; 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=UElBVrkqMO4WVRUcV67o7DLF+YtWWWQQqoV8c4X2CtE=; b=FuyKCwZTd1oZmT3g1nTqL8cBksg77BrDUfdaLAxj56lvA7jcmow/8yMDVIJhMQiIas VzCZXd3Bw/v5cLlZbdr7im4XsOEJ6kWIv7Po+F2CuMXtaIx4bZeuKCtVQEXzKQxd8opE Kvh6P+Uc2s2WTfSoRI8j1YcjdhMnYpok5lfXbAmHnLEy4UDdlWphj/YLN7p4D1mkJdyD K1xpoxoLS4SBhZh3eUvL/W+0Tbtw4DzGTMBVfYtQSKy69MYj02BZvLVLL4TQXC+0zy5I Cz+BvOCyppEk8UcUYIAWxCLMx+BzGVZLJjF9rdZcXuuyYbQthTyzYNZl5Skjb6M7AfQ8 4bxQ== X-Gm-Message-State: AC+VfDxu0PojSAeGnp3/kgGWlal6M9A0cmvd4uv8XAaF9BF6mZKmT2li Ez3gUu9MXz9h+FbU3M78+sEeCXfPz68UONmWc/FJx/y9FDrQcmhmW3H6caGo4lgq2REK/gb5PZ/ n8IMJjwNkNzGcETtBXs6cnkGaWVLQx2OBkT0+A4V2oBIUehQfaOnXFfccGczh/qCuoWRIMES71r DSzxLYICDzeDAJcUU= X-Google-Smtp-Source: ACHHUZ7mYJfDn8dYj10Uzy8lAsi6jLSO38aJQ0xk/g4kw/WOaV0IOZxx9B9xtvb9xbMssxcC1CskWw== X-Received: by 2002:a05:6a00:1ace:b0:644:18fe:91cc with SMTP id f14-20020a056a001ace00b0064418fe91ccmr5785812pfv.12.1684426874115; Thu, 18 May 2023 09:21:14 -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.21.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 May 2023 09:21:13 -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 Subject: [PATCH -next v20 10/26] riscv: Add task switch support for vector Date: Thu, 18 May 2023 16:19:33 +0000 Message-Id: <20230518161949.11203-11-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_092115_232444_0F341880 X-CRM114-Status: GOOD ( 16.69 ) 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: , Cc: Kefeng Wang , guoren@linux.alibaba.com, Jisheng Zhang , Nick Knight , Peter Zijlstra , vineetg@rivosinc.com, =?utf-8?b?Qmo=?= =?utf-8?b?w7ZybiBUw7ZwZWw=?= , Vincent Chen , Conor Dooley , Albert Ou , Guo Ren , Ruinland Tsai , Andy Chiu , Paul Walmsley , greentime.hu@sifive.com, Heiko Stuebner Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org From: Greentime Hu This patch adds task switch support for vector. It also supports all lengths of vlen. Suggested-by: Andrew Waterman Co-developed-by: Nick Knight Signed-off-by: Nick Knight Co-developed-by: Guo Ren Signed-off-by: Guo Ren Co-developed-by: Vincent Chen Signed-off-by: Vincent Chen Co-developed-by: Ruinland Tsai Signed-off-by: Ruinland Tsai Signed-off-by: Greentime Hu Signed-off-by: Vineet Gupta Signed-off-by: Andy Chiu Reviewed-by: Conor Dooley Reviewed-by: Björn Töpel Reviewed-by: Heiko Stuebner Tested-by: Heiko Stuebner --- arch/riscv/include/asm/processor.h | 1 + arch/riscv/include/asm/switch_to.h | 3 +++ arch/riscv/include/asm/thread_info.h | 3 +++ arch/riscv/include/asm/vector.h | 38 ++++++++++++++++++++++++++++ arch/riscv/kernel/process.c | 18 +++++++++++++ 5 files changed, 63 insertions(+) diff --git a/arch/riscv/include/asm/processor.h b/arch/riscv/include/asm/processor.h index 94a0590c6971..f0ddf691ac5e 100644 --- a/arch/riscv/include/asm/processor.h +++ b/arch/riscv/include/asm/processor.h @@ -39,6 +39,7 @@ struct thread_struct { unsigned long s[12]; /* s[0]: frame pointer */ struct __riscv_d_ext_state fstate; unsigned long bad_cause; + struct __riscv_v_ext_state vstate; }; /* Whitelist the fstate from the task_struct for hardened usercopy */ diff --git a/arch/riscv/include/asm/switch_to.h b/arch/riscv/include/asm/switch_to.h index 4b96b13dee27..a727be723c56 100644 --- a/arch/riscv/include/asm/switch_to.h +++ b/arch/riscv/include/asm/switch_to.h @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -78,6 +79,8 @@ do { \ struct task_struct *__next = (next); \ if (has_fpu()) \ __switch_to_fpu(__prev, __next); \ + if (has_vector()) \ + __switch_to_vector(__prev, __next); \ ((last) = __switch_to(__prev, __next)); \ } while (0) diff --git a/arch/riscv/include/asm/thread_info.h b/arch/riscv/include/asm/thread_info.h index e0d202134b44..97e6f65ec176 100644 --- a/arch/riscv/include/asm/thread_info.h +++ b/arch/riscv/include/asm/thread_info.h @@ -81,6 +81,9 @@ struct thread_info { .preempt_count = INIT_PREEMPT_COUNT, \ } +void arch_release_task_struct(struct task_struct *tsk); +int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src); + #endif /* !__ASSEMBLY__ */ /* diff --git a/arch/riscv/include/asm/vector.h b/arch/riscv/include/asm/vector.h index 3c29f4eb552a..ce6a75e9cf62 100644 --- a/arch/riscv/include/asm/vector.h +++ b/arch/riscv/include/asm/vector.h @@ -12,6 +12,9 @@ #ifdef CONFIG_RISCV_ISA_V #include +#include +#include +#include #include #include #include @@ -124,6 +127,38 @@ static inline void __riscv_v_vstate_restore(struct __riscv_v_ext_state *restore_ riscv_v_disable(); } +static inline void riscv_v_vstate_save(struct task_struct *task, + struct pt_regs *regs) +{ + if ((regs->status & SR_VS) == SR_VS_DIRTY) { + struct __riscv_v_ext_state *vstate = &task->thread.vstate; + + __riscv_v_vstate_save(vstate, vstate->datap); + __riscv_v_vstate_clean(regs); + } +} + +static inline void riscv_v_vstate_restore(struct task_struct *task, + struct pt_regs *regs) +{ + if ((regs->status & SR_VS) != SR_VS_OFF) { + struct __riscv_v_ext_state *vstate = &task->thread.vstate; + + __riscv_v_vstate_restore(vstate, vstate->datap); + __riscv_v_vstate_clean(regs); + } +} + +static inline void __switch_to_vector(struct task_struct *prev, + struct task_struct *next) +{ + struct pt_regs *regs; + + regs = task_pt_regs(prev); + riscv_v_vstate_save(prev, regs); + riscv_v_vstate_restore(next, task_pt_regs(next)); +} + #else /* ! CONFIG_RISCV_ISA_V */ struct pt_regs; @@ -132,6 +167,9 @@ static inline int riscv_v_setup_vsize(void) { return -EOPNOTSUPP; } static __always_inline bool has_vector(void) { return false; } static inline bool riscv_v_vstate_query(struct pt_regs *regs) { return false; } #define riscv_v_vsize (0) +#define riscv_v_vstate_save(task, regs) do {} while (0) +#define riscv_v_vstate_restore(task, regs) do {} while (0) +#define __switch_to_vector(__prev, __next) do {} while (0) #define riscv_v_vstate_off(regs) do {} while (0) #define riscv_v_vstate_on(regs) do {} while (0) diff --git a/arch/riscv/kernel/process.c b/arch/riscv/kernel/process.c index e2a060066730..b7a10361ddc6 100644 --- a/arch/riscv/kernel/process.c +++ b/arch/riscv/kernel/process.c @@ -24,6 +24,7 @@ #include #include #include +#include register unsigned long gp_in_global __asm__("gp"); @@ -146,12 +147,28 @@ void flush_thread(void) fstate_off(current, task_pt_regs(current)); memset(¤t->thread.fstate, 0, sizeof(current->thread.fstate)); #endif +#ifdef CONFIG_RISCV_ISA_V + /* Reset vector state */ + riscv_v_vstate_off(task_pt_regs(current)); + kfree(current->thread.vstate.datap); + memset(¤t->thread.vstate, 0, sizeof(struct __riscv_v_ext_state)); +#endif +} + +void arch_release_task_struct(struct task_struct *tsk) +{ + /* Free the vector context of datap. */ + if (has_vector()) + kfree(tsk->thread.vstate.datap); } int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src) { fstate_save(src, task_pt_regs(src)); *dst = *src; + /* clear entire V context, including datap for a new task */ + memset(&dst->thread.vstate, 0, sizeof(struct __riscv_v_ext_state)); + return 0; } @@ -184,6 +201,7 @@ int copy_thread(struct task_struct *p, const struct kernel_clone_args *args) p->thread.s[0] = 0; } p->thread.ra = (unsigned long)ret_from_fork; + riscv_v_vstate_off(childregs); p->thread.sp = (unsigned long)childregs; /* kernel sp */ return 0; } From patchwork Thu May 18 16:19: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: 13247094 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 0A64CC7EE25 for ; Thu, 18 May 2023 16:40:28 +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=7xdozoaYoXnmPRVACpNcB23bSFc41KefaaK6MQMebxU=; b=lL2ubh28su5iH0 8mRkmCGzf4Of+NOEJE4lwM7Yo0sArAOjROlL9LxpcLigXSKWji6njT6w1l/dKcqAVtJzBaI24SnG6 ESG1E0RuvdzRgJXoGlkTTAtZRwUhr2gSLQ14E9TzxM9+EW7z70dh8aVijppnNnyV2V2o899Ng5ved 9Cp0d3CUjIXksDpk3TMNF6qW/OygPxDn4TPw8WpMXUxzQNVwTKj3iHM2AfYxdTgQcdA6cspq6ps3w uHQM+Piln4OhB2Nmif9AcabFYxfilkkr/+4LEfrpnFkDfNfD5V47cA0Uy6uTDVQ+SUGoQUyV/R68k +i5J1im/6iqNdSNxwMXQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzgfu-00DUtz-2R; Thu, 18 May 2023 16:40:22 +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 1pzgfr-00DUsZ-1o for linux-riscv@bombadil.infradead.org; Thu, 18 May 2023 16:40:19 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=References:In-Reply-To:Message-Id:Date :Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description; bh=HHZOWh/r4jeE4wxD75AjHIbdq/sIHY6iL533NUj3STA=; b=jtwkI+nU4QKJ+0k9hDRMDZVkPZ 1pxp3MYfcKJFMzw0PbIzbvbqwPsA8hp4x95fhbGWxF48kiw8vUxuBl+EEixyGL6DCSH9JtAc7tEF9 7sBtRtSwazjHw1bZY5TduMxTYIZ2ZdglasxI8mm1e4tSMNVHgWrHytv5155SUlsOxuKrEZE0opgGQ yYP5fM//rmFwh/fJeAC1u1SKTxPkjQrAd2TtkeqI5AzNBRR1RBpfhz6wQ1/X/U6mZIlrXAMj9kKB5 Us7xgWXAwnh9ffE1q26g8srzmnRoI4M4K8z1hdTvgRFsZJWJ+RBnFu0qWEGkXOV1QGBHK4uN+8pFk ZBo3M3Lw==; Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzgNY-00ErM2-28 for linux-riscv@lists.infradead.org; Thu, 18 May 2023 16:21:26 +0000 Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-64359d9c531so1620736b3a.3 for ; Thu, 18 May 2023 09:21:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1684426883; x=1687018883; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=HHZOWh/r4jeE4wxD75AjHIbdq/sIHY6iL533NUj3STA=; b=dLHfl5a0nVi6sSmJy4P0JlepGXH5lAgKBUCjL6EGXyyUr7Geg5XzGSNS0nbPRvJI91 fJsgu+o3FZf2lirWKa+n2yhsGPcCDflgJw6UmwPq5PA7bNwGShVi8KGdRZeowztOHvPh WqHDRHWMa93d5jNlvb5dXf6ed6qnovF/yog76ZBhy+mO1+fZWuZy9WnMSnZ3uM9vMf4c p8/FSAT0uj59cVRAMaVJoewGvZfC+8adl3rxWql+IXF2cAJMNUI0vzhkQjITfuHw4vLQ NO9h7zimNGvQtxfgJORYQIGFHo/h7IkyV7HYRcF4kV3sIv+rHQ7xyWQeHSFZaW4JMhs2 nS8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684426883; x=1687018883; 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=HHZOWh/r4jeE4wxD75AjHIbdq/sIHY6iL533NUj3STA=; b=EV7rQfZcTm4PJ5L6d/0nAHDpKGav6Wyw3Y9Q5NOlMKQxa2bsiB6u2p9+HtaoOIakoT CfmbzkqPREjBN2tsDtWemWmv9lYosPmW1h9uGwtALwOs1fsjz57gLs2HQOMwZF7LZnHi B6JzNpSZ8o/N+AcU3XpKJFRoKHEzSt2/5ROTEi9rJ9asIb0M8IzxeQ/QnutnQhzv1AFU Pv+Znh1PwRnODt4WRQf32QCUoOCqmKyfzwWwMyx+wF3LDncKd+BXcFG0jlMx9qVzV2K2 bDfJsPhOdh996voGLIkSq9XXNrHKJ+vUjkstHJMnT8BO/wTJgl9ukFTDPSsVRlRn/SvM vy+g== X-Gm-Message-State: AC+VfDyGH3Ev6TI3L4Dn8xqdAUYdH+N+PdARFVuOK2w8wV/fmaVJmuZH U9gr7sN9M0t6KIKqTxyToCZObDsHmiHfhNYp+XSiY0trCd9nXxJQDkl7aJ8AZ3BAdV6uw1xvNBp p7gSG578mfzz9QVPIrfyaPgqqnhwfKJ7/LMay6GF54gbbXIREQDYxmFDT1GXNwHl/rIvWOFdQ2y CtvbDCIh91vEir8Pk= X-Google-Smtp-Source: ACHHUZ7RN8E8/QRXY2Vl6LI6cXXQ4zILXEnT0BQBeqjKlcJUDpaiRQ1JJy4MynBwXNJHOoBGzduUHA== X-Received: by 2002:a05:6a20:4421:b0:104:6432:270 with SMTP id ce33-20020a056a20442100b0010464320270mr243449pzb.46.1684426882671; Thu, 18 May 2023 09:21:22 -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.21.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 May 2023 09:21:22 -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 , Andrew Jones , Heiko Stuebner , Conor Dooley , Lad Prabhakar , Liao Chang , Jisheng Zhang , Vincent Chen , Guo Ren , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Mattias Nissler Subject: [PATCH -next v20 11/26] riscv: Allocate user's vector context in the first-use trap Date: Thu, 18 May 2023 16:19:34 +0000 Message-Id: <20230518161949.11203-12-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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230518_172124_806444_6A31974A X-CRM114-Status: GOOD ( 20.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: , MIME-Version: 1.0 Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Vector unit is disabled by default for all user processes. Thus, a process will take a trap (illegal instruction) into kernel at the first time when it uses Vector. Only after then, the kernel allocates V context and starts take care of the context for that user process. Suggested-by: Richard Henderson Link: https://lore.kernel.org/r/3923eeee-e4dc-0911-40bf-84c34aee962d@linaro.org Signed-off-by: Andy Chiu Reviewed-by: Conor Dooley Reviewed-by: Palmer Dabbelt --- Hey Heiko and Conor, I am dropping you guys' A-b, T-b, and R-b because I added a check in riscv_v_first_use_handler(). Changelog v20: - move has_vector() into vector.c for better code readibility - check elf_hwcap in the first-use trap because it might get turned off if cores have different VLENs. Changelog v18: - Add blank lines (Heiko) - Return immediately in insn_is_vector() if an insn matches (Heiko) --- arch/riscv/include/asm/insn.h | 29 ++++++++++ arch/riscv/include/asm/vector.h | 2 + arch/riscv/kernel/traps.c | 26 ++++++++- arch/riscv/kernel/vector.c | 95 +++++++++++++++++++++++++++++++++ 4 files changed, 150 insertions(+), 2 deletions(-) diff --git a/arch/riscv/include/asm/insn.h b/arch/riscv/include/asm/insn.h index 8d5c84f2d5ef..4e1505cef8aa 100644 --- a/arch/riscv/include/asm/insn.h +++ b/arch/riscv/include/asm/insn.h @@ -137,6 +137,26 @@ #define RVG_OPCODE_JALR 0x67 #define RVG_OPCODE_JAL 0x6f #define RVG_OPCODE_SYSTEM 0x73 +#define RVG_SYSTEM_CSR_OFF 20 +#define RVG_SYSTEM_CSR_MASK GENMASK(12, 0) + +/* parts of opcode for RVF, RVD and RVQ */ +#define RVFDQ_FL_FS_WIDTH_OFF 12 +#define RVFDQ_FL_FS_WIDTH_MASK GENMASK(3, 0) +#define RVFDQ_FL_FS_WIDTH_W 2 +#define RVFDQ_FL_FS_WIDTH_D 3 +#define RVFDQ_LS_FS_WIDTH_Q 4 +#define RVFDQ_OPCODE_FL 0x07 +#define RVFDQ_OPCODE_FS 0x27 + +/* parts of opcode for RVV */ +#define RVV_OPCODE_VECTOR 0x57 +#define RVV_VL_VS_WIDTH_8 0 +#define RVV_VL_VS_WIDTH_16 5 +#define RVV_VL_VS_WIDTH_32 6 +#define RVV_VL_VS_WIDTH_64 7 +#define RVV_OPCODE_VL RVFDQ_OPCODE_FL +#define RVV_OPCODE_VS RVFDQ_OPCODE_FS /* parts of opcode for RVC*/ #define RVC_OPCODE_C0 0x0 @@ -304,6 +324,15 @@ static __always_inline bool riscv_insn_is_branch(u32 code) (RVC_X(x_, RVC_B_IMM_7_6_OPOFF, RVC_B_IMM_7_6_MASK) << RVC_B_IMM_7_6_OFF) | \ (RVC_IMM_SIGN(x_) << RVC_B_IMM_SIGN_OFF); }) +#define RVG_EXTRACT_SYSTEM_CSR(x) \ + ({typeof(x) x_ = (x); RV_X(x_, RVG_SYSTEM_CSR_OFF, RVG_SYSTEM_CSR_MASK); }) + +#define RVFDQ_EXTRACT_FL_FS_WIDTH(x) \ + ({typeof(x) x_ = (x); RV_X(x_, RVFDQ_FL_FS_WIDTH_OFF, \ + RVFDQ_FL_FS_WIDTH_MASK); }) + +#define RVV_EXRACT_VL_VS_WIDTH(x) RVFDQ_EXTRACT_FL_FS_WIDTH(x) + /* * Get the immediate from a J-type instruction. * diff --git a/arch/riscv/include/asm/vector.h b/arch/riscv/include/asm/vector.h index ce6a75e9cf62..8e56da67b5cf 100644 --- a/arch/riscv/include/asm/vector.h +++ b/arch/riscv/include/asm/vector.h @@ -21,6 +21,7 @@ extern unsigned long riscv_v_vsize; int riscv_v_setup_vsize(void); +bool riscv_v_first_use_handler(struct pt_regs *regs); static __always_inline bool has_vector(void) { @@ -165,6 +166,7 @@ struct pt_regs; static inline int riscv_v_setup_vsize(void) { return -EOPNOTSUPP; } static __always_inline bool has_vector(void) { return false; } +static inline bool riscv_v_first_use_handler(struct pt_regs *regs) { return false; } static inline bool riscv_v_vstate_query(struct pt_regs *regs) { return false; } #define riscv_v_vsize (0) #define riscv_v_vstate_save(task, regs) do {} while (0) diff --git a/arch/riscv/kernel/traps.c b/arch/riscv/kernel/traps.c index 8c258b78c925..05ffdcd1424e 100644 --- a/arch/riscv/kernel/traps.c +++ b/arch/riscv/kernel/traps.c @@ -26,6 +26,7 @@ #include #include #include +#include int show_unhandled_signals = 1; @@ -145,8 +146,29 @@ DO_ERROR_INFO(do_trap_insn_misaligned, SIGBUS, BUS_ADRALN, "instruction address misaligned"); DO_ERROR_INFO(do_trap_insn_fault, SIGSEGV, SEGV_ACCERR, "instruction access fault"); -DO_ERROR_INFO(do_trap_insn_illegal, - SIGILL, ILL_ILLOPC, "illegal instruction"); + +asmlinkage __visible __trap_section void do_trap_insn_illegal(struct pt_regs *regs) +{ + if (user_mode(regs)) { + irqentry_enter_from_user_mode(regs); + + local_irq_enable(); + + if (!riscv_v_first_use_handler(regs)) + do_trap_error(regs, SIGILL, ILL_ILLOPC, regs->epc, + "Oops - illegal instruction"); + + irqentry_exit_to_user_mode(regs); + } else { + irqentry_state_t state = irqentry_nmi_enter(regs); + + do_trap_error(regs, SIGILL, ILL_ILLOPC, regs->epc, + "Oops - illegal instruction"); + + irqentry_nmi_exit(regs, state); + } +} + DO_ERROR_INFO(do_trap_load_fault, SIGSEGV, SEGV_ACCERR, "load access fault"); #ifndef CONFIG_RISCV_M_MODE diff --git a/arch/riscv/kernel/vector.c b/arch/riscv/kernel/vector.c index 120f1ce9abf9..0080798e8d2e 100644 --- a/arch/riscv/kernel/vector.c +++ b/arch/riscv/kernel/vector.c @@ -4,10 +4,19 @@ * Author: Andy Chiu */ #include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include +#include #include unsigned long riscv_v_vsize __read_mostly; @@ -34,3 +43,89 @@ int riscv_v_setup_vsize(void) return 0; } + +static bool insn_is_vector(u32 insn_buf) +{ + u32 opcode = insn_buf & __INSN_OPCODE_MASK; + u32 width, csr; + + /* + * All V-related instructions, including CSR operations are 4-Byte. So, + * do not handle if the instruction length is not 4-Byte. + */ + if (unlikely(GET_INSN_LENGTH(insn_buf) != 4)) + return false; + + switch (opcode) { + case RVV_OPCODE_VECTOR: + return true; + case RVV_OPCODE_VL: + case RVV_OPCODE_VS: + width = RVV_EXRACT_VL_VS_WIDTH(insn_buf); + if (width == RVV_VL_VS_WIDTH_8 || width == RVV_VL_VS_WIDTH_16 || + width == RVV_VL_VS_WIDTH_32 || width == RVV_VL_VS_WIDTH_64) + return true; + + break; + case RVG_OPCODE_SYSTEM: + csr = RVG_EXTRACT_SYSTEM_CSR(insn_buf); + if ((csr >= CSR_VSTART && csr <= CSR_VCSR) || + (csr >= CSR_VL && csr <= CSR_VLENB)) + return true; + } + + return false; +} + +static int riscv_v_thread_zalloc(void) +{ + void *datap; + + datap = kzalloc(riscv_v_vsize, GFP_KERNEL); + if (!datap) + return -ENOMEM; + + current->thread.vstate.datap = datap; + memset(¤t->thread.vstate, 0, offsetof(struct __riscv_v_ext_state, + datap)); + return 0; +} + +bool riscv_v_first_use_handler(struct pt_regs *regs) +{ + u32 __user *epc = (u32 __user *)regs->epc; + u32 insn = (u32)regs->badaddr; + + /* Do not handle if V is not supported, or disabled */ + if (!has_vector() || !(elf_hwcap & COMPAT_HWCAP_ISA_V)) + return false; + + /* If V has been enabled then it is not the first-use trap */ + if (riscv_v_vstate_query(regs)) + return false; + + /* Get the instruction */ + if (!insn) { + if (__get_user(insn, epc)) + return false; + } + + /* Filter out non-V instructions */ + if (!insn_is_vector(insn)) + return false; + + /* Sanity check. datap should be null by the time of the first-use trap */ + WARN_ON(current->thread.vstate.datap); + + /* + * Now we sure that this is a V instruction. And it executes in the + * context where VS has been off. So, try to allocate the user's V + * context and resume execution. + */ + if (riscv_v_thread_zalloc()) { + force_sig(SIGKILL); + return true; + } + riscv_v_vstate_on(regs); + return true; +} From patchwork Thu May 18 16:19:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Chiu X-Patchwork-Id: 13247085 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 A29A2C77B7D for ; Thu, 18 May 2023 16:21:36 +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=4+OSBnHmt/23BgsYvoL+Ct33PI+Y3v93YVSNTkZeXKU=; b=Kuq9HhA9ZQPGXR XDEnwBWGkmrKhUNGkYOjDq5G7hKDU4c/+j3l18ByvHFFgfPZD18Clx69AqZ3+7BegOJvdyv5+S6iQ XlxcAIHx5Fuly4nd/4vg3HRnS2WCXam5lvTCbNLk6fhj028UISLKKF4un+xXDhh6Dd5GyK9/70vaJ tRbsJAtM5ZFqmpLy+/JJ3ByyJEjQPE4buBIoIQOlAPYGQGt0OR9lONd6vmyejsMaLBZcUjapymdXl 7TLMnEHKsOMYI/JdSwmuAFpDqaGFpnGUMkTiMe45APJnCZkY4mqxQ1smbCC1v2lyznNLjihgC1kls 8rXsXI8VJ/EpbP0AkrzA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzgNg-00DRQn-2D; Thu, 18 May 2023 16:21:32 +0000 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzgNd-00DRPb-2A for linux-riscv@lists.infradead.org; Thu, 18 May 2023 16:21:31 +0000 Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-64d15660784so678383b3a.0 for ; Thu, 18 May 2023 09:21:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1684426889; x=1687018889; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=eqKkCeR0VN0glMEno0S7kDNRAT+sQdtfWCgUmgho7EE=; b=JGvytAiN65NOxv76crIl40AXKEIP/sWmG8yvMkjF3KKE23IIWW87rBuagXBqsMd862 oOpqbE+De3pq2z4IE4yC8VRSi0KOpQq9NPHM9odhbdcp9SB+u22iOrO4iupAKghr9Muu Qs1gaNew8qgMfDiNf0yE6CgYoGrC0Dh/dqtkslRo1OXaPbTEVBfyo8VBlrgvLsSnWDP5 NDbx4n6+SrblQfsNIxatTRYWQxnOLtPZQ/xeJmEctOf+YvE0YsKqC9Xi+lkkOd6qBp0n Udj1ruPoW9iytMnPRjeuMeb/yn1qkUbUcX83SbRDSfaNSQuXCeErDRSQOnUGPRoM2UKk EO6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684426889; x=1687018889; 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=eqKkCeR0VN0glMEno0S7kDNRAT+sQdtfWCgUmgho7EE=; b=jVRgdYJdXIf8B1b5UDpBAgpMXjW5QL2mwuaBq+F9YT44iELAU9GO8etJlViMWmmNj6 Vg+3R3VXtYggqDKUZBNS1oTIuKlkZdlOG8Fm5JadVpRh8mvrux0/WwnWCyM980McTNl1 UcgZEFCmLRmWiN4UoEZoSHf5kJPww8/3sjWkbEhVJItsk701uFF5ZoJ/ZFSPY64bWkpE hrn9XReTQKk3OMd80fugl4SuFd4iesLqvDsRQmNsp0oskSNl6T1OhyU3z9WJRmTGWVTO UUQtm/YlbetVsch1hb1Zc0lLLzhdssGEXoq1LDk9aDfU7frokqi5eDqJY9utfbKxFCKL bfQg== X-Gm-Message-State: AC+VfDwgIzYRcTlWKjfIRBYEy5IkVor2pBNSgM8Ud0M4PfVEh2OlBnKc 6N9QVgw1Hj2xhj0OvNfSSDc4IioIgBemrTqdVKbScIkpqFdnR3DEoP9FSBXYHIp6sy0Judts2A6 BGWpFKMoyLzdR38aVLJN79a96J2j8J7RhUPULEmM+xUI8sqy1XJ7jle/Wk3WsTozA1SfqQTvOVf D4n4vzSAgwAjqMsic= X-Google-Smtp-Source: ACHHUZ6E0KyTQdG2PV+0wjQp8/IFxiwtOAx76jX0jhBczfqnPbcEEag/w5G4YJmKSnucFVwUhNYdfA== X-Received: by 2002:a05:6a20:12d3:b0:101:5f33:94ad with SMTP id v19-20020a056a2012d300b001015f3394admr194997pzg.52.1684426888575; Thu, 18 May 2023 09:21:28 -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.21.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 May 2023 09:21:27 -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, Vincent Chen , Andy Chiu , Paul Walmsley , Albert Ou , Oleg Nesterov , Eric Biederman , Kees Cook , Heiko Stuebner , Conor Dooley , Huacai Chen , Janosch Frank , Qing Zhang , Rolf Eike Beer Subject: [PATCH -next v20 12/26] riscv: Add ptrace vector support Date: Thu, 18 May 2023 16:19:35 +0000 Message-Id: <20230518161949.11203-13-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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230518_092129_713119_4D944932 X-CRM114-Status: GOOD ( 21.19 ) 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 From: Greentime Hu This patch adds ptrace support for riscv vector. The vector registers will be saved in datap pointer of __riscv_v_ext_state. This pointer will be set right after the __riscv_v_ext_state data structure then it will be put in ubuf for ptrace system call to get or set. It will check if the datap got from ubuf is set to the correct address or not when the ptrace system call is trying to set the vector registers. Co-developed-by: Vincent Chen Signed-off-by: Vincent Chen Signed-off-by: Greentime Hu Signed-off-by: Andy Chiu Reviewed-by: Conor Dooley Reviewed-by: Palmer Dabbelt # aside from NT_RISCV_VECTOR --- Changelog V18: - Use sizeof(vstate->datap) instead of sizeof(void*) (Eike) --- arch/riscv/include/uapi/asm/ptrace.h | 7 +++ arch/riscv/kernel/ptrace.c | 70 ++++++++++++++++++++++++++++ include/uapi/linux/elf.h | 1 + 3 files changed, 78 insertions(+) diff --git a/arch/riscv/include/uapi/asm/ptrace.h b/arch/riscv/include/uapi/asm/ptrace.h index 586786d023c4..e8d127ec5cf7 100644 --- a/arch/riscv/include/uapi/asm/ptrace.h +++ b/arch/riscv/include/uapi/asm/ptrace.h @@ -94,6 +94,13 @@ struct __riscv_v_ext_state { */ }; +/* + * According to spec: The number of bits in a single vector register, + * VLEN >= ELEN, which must be a power of 2, and must be no greater than + * 2^16 = 65536bits = 8192bytes + */ +#define RISCV_MAX_VLENB (8192) + #endif /* __ASSEMBLY__ */ #endif /* _UAPI_ASM_RISCV_PTRACE_H */ diff --git a/arch/riscv/kernel/ptrace.c b/arch/riscv/kernel/ptrace.c index 23c48b14a0e7..1d572cf3140f 100644 --- a/arch/riscv/kernel/ptrace.c +++ b/arch/riscv/kernel/ptrace.c @@ -7,6 +7,7 @@ * Copied from arch/tile/kernel/ptrace.c */ +#include #include #include #include @@ -24,6 +25,9 @@ enum riscv_regset { #ifdef CONFIG_FPU REGSET_F, #endif +#ifdef CONFIG_RISCV_ISA_V + REGSET_V, +#endif }; static int riscv_gpr_get(struct task_struct *target, @@ -80,6 +84,61 @@ static int riscv_fpr_set(struct task_struct *target, } #endif +#ifdef CONFIG_RISCV_ISA_V +static int riscv_vr_get(struct task_struct *target, + const struct user_regset *regset, + struct membuf to) +{ + struct __riscv_v_ext_state *vstate = &target->thread.vstate; + + if (!riscv_v_vstate_query(task_pt_regs(target))) + return -EINVAL; + + /* + * Ensure the vector registers have been saved to the memory before + * copying them to membuf. + */ + if (target == current) + riscv_v_vstate_save(current, task_pt_regs(current)); + + /* Copy vector header from vstate. */ + membuf_write(&to, vstate, offsetof(struct __riscv_v_ext_state, datap)); + membuf_zero(&to, sizeof(vstate->datap)); + + /* Copy all the vector registers from vstate. */ + return membuf_write(&to, vstate->datap, riscv_v_vsize); +} + +static int riscv_vr_set(struct task_struct *target, + const struct user_regset *regset, + unsigned int pos, unsigned int count, + const void *kbuf, const void __user *ubuf) +{ + int ret, size; + struct __riscv_v_ext_state *vstate = &target->thread.vstate; + + if (!riscv_v_vstate_query(task_pt_regs(target))) + return -EINVAL; + + /* Copy rest of the vstate except datap */ + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, vstate, 0, + offsetof(struct __riscv_v_ext_state, datap)); + if (unlikely(ret)) + return ret; + + /* Skip copy datap. */ + size = sizeof(vstate->datap); + count -= size; + ubuf += size; + + /* Copy all the vector registers. */ + pos = 0; + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, vstate->datap, + 0, riscv_v_vsize); + return ret; +} +#endif + static const struct user_regset riscv_user_regset[] = { [REGSET_X] = { .core_note_type = NT_PRSTATUS, @@ -99,6 +158,17 @@ static const struct user_regset riscv_user_regset[] = { .set = riscv_fpr_set, }, #endif +#ifdef CONFIG_RISCV_ISA_V + [REGSET_V] = { + .core_note_type = NT_RISCV_VECTOR, + .align = 16, + .n = ((32 * RISCV_MAX_VLENB) + + sizeof(struct __riscv_v_ext_state)) / sizeof(__u32), + .size = sizeof(__u32), + .regset_get = riscv_vr_get, + .set = riscv_vr_set, + }, +#endif }; static const struct user_regset_view riscv_user_native_view = { diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h index ac3da855fb19..7d8d9ae36615 100644 --- a/include/uapi/linux/elf.h +++ b/include/uapi/linux/elf.h @@ -440,6 +440,7 @@ typedef struct elf64_shdr { #define NT_MIPS_DSP 0x800 /* MIPS DSP ASE registers */ #define NT_MIPS_FP_MODE 0x801 /* MIPS floating-point mode */ #define NT_MIPS_MSA 0x802 /* MIPS SIMD registers */ +#define NT_RISCV_VECTOR 0x900 /* RISC-V vector registers */ #define NT_LOONGARCH_CPUCFG 0xa00 /* LoongArch CPU config registers */ #define NT_LOONGARCH_CSR 0xa01 /* LoongArch control and status registers */ #define NT_LOONGARCH_LSX 0xa02 /* LoongArch Loongson SIMD Extension registers */ From patchwork Thu May 18 16:19:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Chiu X-Patchwork-Id: 13247086 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 6EEE0C7EE23 for ; Thu, 18 May 2023 16:21: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: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=TZKjtlwj+2E27RE9ws1BdnHe2nxEy130Ys/PBRrEPaY=; b=u21pG/sPxqjTYL szrHvmsFsvrU/Kopr027ZQiXvohx8UMFS/baPnzvcYgCdSzd58zJQxGUNmNcfs7Fvh2hl4xfqqJZ+ xTnN6LrJaBhSqFCEXzYbIw/eoC6aQgoNJ3w6APgZcFs8bJf5UlaHson3pPbPpp7hQEbGNiqVxjw1x zKEFYZZtRUu4j+HhBE3tQS4COEcdAzD1aOimnBZpIYgSN2TbQWVAx885tDGIkJZjmoTcGM7pTOGfH X/TQRouAdXyp6dz7F112ru8StoKWMwpvnPY5GWzdknze1ovwOQtwxC0v/QPY/9f36DohemAjRCwpX 89vcuQalQOT5aDNWWSeg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzgNn-00DRTB-1M; Thu, 18 May 2023 16:21:39 +0000 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzgNk-00DRRO-2c for linux-riscv@lists.infradead.org; Thu, 18 May 2023 16:21:38 +0000 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-643b60855c8so2373374b3a.2 for ; Thu, 18 May 2023 09:21:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1684426893; x=1687018893; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=wN7ZHBcxzp7ZsRkqqH3xjhadPlnuKqjQR/mkhzwbhmg=; b=Ey/Kv6fYqD5T2pRmNIkZHqJshDKHFn1o47rgVMEFXsZRdMgpK3CFT3ChQdXNj+0lPp cdQu5Z9sN2SUfEM6Hmmj4aYIuB4U/tSGiJBgfoTCFqzmlnE3V2E8mEIPDuH8h7/Txnx1 Sr2bCL/qlpo1cpsoKKFQasew6RJx+SprdF2Wvzp05nqmQlePetF85bxnX1tYcTEKXdXo 1aw87RDL/IxOfdvvtijNlkciAYbhhVZDhkCYHcICqnxTdCJC69Z+IFTBP6wWSC847GBn aTWDg2TkfMWts3N0POuvP8VKR7dpn3p8cSiCq7TrIyeRFws/SAGA2caP8DgZdHG9DO8v hI4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684426893; x=1687018893; 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=wN7ZHBcxzp7ZsRkqqH3xjhadPlnuKqjQR/mkhzwbhmg=; b=dVe34REdXnqMFUz7smPr8e70kIsRcvJYFWq6X4BKW417UI5zrEw57DBc5aI0G5y05y +MApTgLjIBhm68KrRc57AnMGTf1GgqZhOdbIORax2T44TlW+DHtPNOMdKQtQEmK6VnOA GLeHceGEMOFU21lxfLZ+hjQEnCK08kz9wFWfL1h1ZIvuVLFWFA1Q6h2lq3/0JL0LUZob YDjv7+h6pyZK4BPK6QWK3Rj5vxJHkP+Sa/HssXoQB4c/61ZdNtsHQesxbdnDlhqixZvh wbhNpac3c1or5OOZZlHDB8U+91HFVXdmq+eY/UtRKFaoPjdMPrl67szfzWkqKcQ6en0E MDkQ== X-Gm-Message-State: AC+VfDyPZds51Ud+h+rN2Hv9hn9NQGxB6pimo0mydGwvrPKfDMvvV2rc ntJY/WQ3BE4TOquLdtOVtxx4Vu/wbnzP2i0UkkguAEstAF/Z99YEAGYPVd1T+hQKvHuNi4UGsTt RHM2t1QYf0E3bo4UA1vd4ut6/NdUILNdKmaYo73hykkZf6ttZU+3hyFif7DJAvry9TzhQkBo16Z 7+dVe+Y32FM5gw45A= X-Google-Smtp-Source: ACHHUZ5a7mpnEfLkm2ncBuEwvmz7HinzrDjpZDDOTe33aa1+1AbH0IGdXd8YEL4Z6HnfYyEePA9Dow== X-Received: by 2002:a05:6a00:2d0c:b0:643:aa2:4dcd with SMTP id fa12-20020a056a002d0c00b006430aa24dcdmr5636544pfb.16.1684426893158; Thu, 18 May 2023 09:21:33 -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.21.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 May 2023 09:21:32 -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 , Heiko Stuebner , Conor Dooley , Guo Ren , Vincent Chen , Al Viro , Andrew Bresticker Subject: [PATCH -next v20 13/26] riscv: signal: check fp-reserved words unconditionally Date: Thu, 18 May 2023 16:19:36 +0000 Message-Id: <20230518161949.11203-14-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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230518_092136_852243_90DF9DC4 X-CRM114-Status: GOOD ( 17.83 ) 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 In order to let kernel/user locate and identify an extension context on the existing sigframe, we are going to utilize reserved space of fp and encode the information there. And since the sigcontext has already preserved a space for fp context w or w/o CONFIG_FPU, we move those reserved words checking/setting routine back into generic code. This commit also undone an additional logical change carried by the refactor commit 007f5c3589578 ("Refactor FPU code in signal setup/return procedures"). Originally we did not restore fp context if restoring of gpr have failed. And it was fine on the other side. In such way the kernel could keep the regfiles intact, and potentially react at the failing point of restore. Signed-off-by: Andy Chiu Acked-by: Conor Dooley Acked-by: Heiko Stuebner Tested-by: Heiko Stuebner --- arch/riscv/kernel/signal.c | 55 +++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/arch/riscv/kernel/signal.c b/arch/riscv/kernel/signal.c index 9aff9d720590..6b4a5c90bd87 100644 --- a/arch/riscv/kernel/signal.c +++ b/arch/riscv/kernel/signal.c @@ -40,26 +40,13 @@ static long restore_fp_state(struct pt_regs *regs, { long err; struct __riscv_d_ext_state __user *state = &sc_fpregs->d; - size_t i; err = __copy_from_user(¤t->thread.fstate, state, sizeof(*state)); if (unlikely(err)) return err; fstate_restore(current, regs); - - /* We support no other extension state at this time. */ - for (i = 0; i < ARRAY_SIZE(sc_fpregs->q.reserved); i++) { - u32 value; - - err = __get_user(value, &sc_fpregs->q.reserved[i]); - if (unlikely(err)) - break; - if (value != 0) - return -EINVAL; - } - - return err; + return 0; } static long save_fp_state(struct pt_regs *regs, @@ -67,20 +54,9 @@ static long save_fp_state(struct pt_regs *regs, { long err; struct __riscv_d_ext_state __user *state = &sc_fpregs->d; - size_t i; fstate_save(current, regs); err = __copy_to_user(state, ¤t->thread.fstate, sizeof(*state)); - if (unlikely(err)) - return err; - - /* We support no other extension state at this time. */ - for (i = 0; i < ARRAY_SIZE(sc_fpregs->q.reserved); i++) { - err = __put_user(0, &sc_fpregs->q.reserved[i]); - if (unlikely(err)) - break; - } - return err; } #else @@ -92,11 +68,30 @@ static long restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc) { long err; + size_t i; + /* sc_regs is structured the same as the start of pt_regs */ err = __copy_from_user(regs, &sc->sc_regs, sizeof(sc->sc_regs)); + if (unlikely(err)) + return err; + /* Restore the floating-point state. */ - if (has_fpu()) - err |= restore_fp_state(regs, &sc->sc_fpregs); + if (has_fpu()) { + err = restore_fp_state(regs, &sc->sc_fpregs); + if (unlikely(err)) + return err; + } + + /* We support no other extension state at this time. */ + for (i = 0; i < ARRAY_SIZE(sc->sc_fpregs.q.reserved); i++) { + u32 value; + + err = __get_user(value, &sc->sc_fpregs.q.reserved[i]); + if (unlikely(err)) + break; + if (value != 0) + return -EINVAL; + } return err; } @@ -147,11 +142,17 @@ static long setup_sigcontext(struct rt_sigframe __user *frame, { struct sigcontext __user *sc = &frame->uc.uc_mcontext; long err; + size_t i; + /* sc_regs is structured the same as the start of pt_regs */ err = __copy_to_user(&sc->sc_regs, regs, sizeof(sc->sc_regs)); /* Save the floating-point state. */ if (has_fpu()) err |= save_fp_state(regs, &sc->sc_fpregs); + /* We support no other extension state at this time. */ + for (i = 0; i < ARRAY_SIZE(sc->sc_fpregs.q.reserved); i++) + err |= __put_user(0, &sc->sc_fpregs.q.reserved[i]); + return err; } From patchwork Thu May 18 16:19:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Chiu X-Patchwork-Id: 13247099 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 DBE1AC7EE23 for ; Thu, 18 May 2023 16:40: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: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=oxG/lvSGnazsO+XCkZn1RHjB6mTYltD0+GXNTzyxkzE=; b=vhP8Y7iafxnE32 b0ci9Wf/uAeRw1T4rqzlPkJxX6q87ef1oTVAakUrGzIDcINFmk7TCDmJxZYJYyucjuOSvdJrKrNLT 4zIq5ujk3hWhKihwfvgACqMPLxC2TVk7p3t7MhpIog0tp88OrSswAELvArNHeZfVlZiThkHy3yO8i 5pjTwhNQOoXqg3uWZTCX3/AyOhbPcBFNuiiwX4E1+TMd6d2dLNgRIRrBYdxncWqYwZ+ZJz/h53x5F piAPbuXhXpK4oF3QaoWoZZLabFFxX8ADRwI4ShcyTAzqnwX3B//35WuR7L3j3Xg5zD61dCMdlESq7 zzY+kDMSQxDNDFA79csw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzggB-00DV6f-1d; Thu, 18 May 2023 16:40:39 +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 1pzggA-00DV5Q-0j for linux-riscv@bombadil.infradead.org; Thu, 18 May 2023 16:40:38 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=References:In-Reply-To:Message-Id:Date :Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description; bh=MdADAAcqMqw/ern4VfZKqbSeESM813gLnUOdgVy5HP8=; b=pXawSlyW3gjxf3y4kpsXVJNBRP Ncp/KQmAmObgmH5EDPVWC3gAjyQYrMIHr+tCSHjOxZ9HpdbmoGtZX+YJ64fAuD25BOuBw+QfgwJmK yq40SlT2slcKYhyAvpZdEIt+uT8nbb99mHxLysUyZK/Da7S6dUUt3g7XZw9uYZNf1krvdDwmLITxV wC2WEKHGIlG3emE8f3f2qi5uF7yvGd1JjRNAKyxCkufokDOI+1kFRogfq8tbVzI8Lj3RXIvOnYveS N8NG+fpJe2znWNaFjk/njOsxqptoLd0GmddnYxKK2et1CNn8QgkzgFipSuL9/XItSC6GFyO+yDZA4 tKOuJcag==; Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzgNq-00ErLT-0a for linux-riscv@lists.infradead.org; Thu, 18 May 2023 16:21:44 +0000 Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-64d2981e3abso287586b3a.1 for ; Thu, 18 May 2023 09:21:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1684426901; x=1687018901; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=MdADAAcqMqw/ern4VfZKqbSeESM813gLnUOdgVy5HP8=; b=DsD4bfuQ0ck0Mu9xk6ELw2lMsNx98Fo8tuHMtKU/AurmkwMgZxjQquwRiD4Vixkacd JWEp/I3QbfM9hIwjheoagkuouiVjrpts3JyiCL+YGwLf5FPBq/JaEklinCOupQtUoaDC raLbhFqhBaLRsHUB2tO7iK28Bguyvke+nuRoNYn4aZ7AESnBek0SEsxIjFVxixhl1MD9 v6SyyGI8ETCa7jf2gwWpYPHtsN3xIHuntY1/2v0FVfzRmxRSxYoKR369QJ1JlYRpPbtA X4ROgWlBpLcIT2LOidC37rn/fI/XROlI5E0s4msnzzbYheSAcVH3J0MqDyC3AsbS7SoG 80xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684426901; x=1687018901; 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=MdADAAcqMqw/ern4VfZKqbSeESM813gLnUOdgVy5HP8=; b=EyjWhwRmPTds3rAblHz3k2s+/P7B3EUGRPrjzvRUJOJMfR+2pdsErXo28U5LAzhJ2W t9yA05GkzyyHd5diPvRfGqvzFLhpYDTqXYS+9dkgPS82Z9XMfeTvPjA9rEyTG6geiLgt ghZ9zc4Aevntw1l1sH4rrrA/JdOvCst2v87M4oiaVNEFmCq0QVPjRlgflVDXB9q/JVxQ Oif/WwGz3yUSQ3kxC2Wm4WLUyVpWx+nHPOUTovZm3MuM4Bw3MsSxzB76kSQ70csQWqMA HrnWOmED9+D7c3oDSdXaknXkj45YODKEyIfukDAU8HO70iJBvfxUi/LUpzvd5GVAWS4F LIyA== X-Gm-Message-State: AC+VfDwgG+LubhGNm3Px/JMVuhYPoj37F+9DFYxAS1t7szBRb0hT2FuP JUTiv79V35mMRo5rv8JKvJ6u9uiLwLpP6jsg6cNwCtsE95jFE6z+VbL3KHlhrJsl9j8qQqJOuVU gYJOy8v3Zk9oXtFqK5bBKgjKhAjtWOIE4k7Lmu2Tk6JADtVscze/oQljCztvbQ8R83ipXbfN707 sjayt4/Wi3y0RXxLc= X-Google-Smtp-Source: ACHHUZ7QiVaag4rNNZLH+44L+w+ar03lTDTdo4OwXTqB8nbNeXyPsARBYf0hZdM2vL7+xOGI3q/kXw== X-Received: by 2002:a05:6a00:1a08:b0:64d:1185:2414 with SMTP id g8-20020a056a001a0800b0064d11852414mr4494399pfv.4.1684426901007; Thu, 18 May 2023 09:21:41 -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.21.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 May 2023 09:21:40 -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, Vincent Chen , Andy Chiu , Paul Walmsley , Albert Ou , Heiko Stuebner , Conor Dooley , Alexandre Ghiti , Andrew Jones , Xianting Tian , Jisheng Zhang , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Wenting Zhang , Guo Ren , Mathis Salmen , Andrew Bresticker Subject: [PATCH -next v20 14/26] riscv: signal: Add sigcontext save/restore for vector Date: Thu, 18 May 2023 16:19:37 +0000 Message-Id: <20230518161949.11203-15-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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230518_172142_337847_21F1DC71 X-CRM114-Status: GOOD ( 32.04 ) 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 From: Greentime Hu This patch facilitates the existing fp-reserved words for placement of the first extension's context header on the user's sigframe. A context header consists of a distinct magic word and the size, including the header itself, of an extension on the stack. Then, the frame is followed by the context of that extension, and then a header + context body for another extension if exists. If there is no more extension to come, then the frame must be ended with a null context header. A special case is rv64gc, where the kernel support no extensions requiring to expose additional regfile to the user. In such case the kernel would place the null context header right after the first reserved word of __riscv_q_ext_state when saving sigframe. And the kernel would check if all reserved words are zeros when a signal handler returns. __riscv_q_ext_state---->| |<-__riscv_extra_ext_header ~ ~ .reserved[0]--->|0 |<- .reserved <-------|magic |<- .hdr | |size |_______ end of sc_fpregs | |ext-bdy| | ~ ~ +)size ------->|magic |<- another context header |size | |ext-bdy| ~ ~ |magic:0|<- null context header |size:0 | The vector registers will be saved in datap pointer. The datap pointer will be allocated dynamically when the task needs in kernel space. On the other hand, datap pointer on the sigframe will be set right after the __riscv_v_ext_state data structure. Co-developed-by: Vincent Chen Signed-off-by: Vincent Chen Signed-off-by: Greentime Hu Suggested-by: Vineet Gupta Suggested-by: Richard Henderson Co-developed-by: Andy Chiu Signed-off-by: Andy Chiu Acked-by: Conor Dooley Acked-by: Heiko Stuebner Tested-by: Heiko Stuebner --- Changelog V19: - Fix a conflict in signal.c due to commit 8d736482749f ("riscv: add icache flush for nommu sigreturn trampoline") --- arch/riscv/include/uapi/asm/ptrace.h | 15 ++ arch/riscv/include/uapi/asm/sigcontext.h | 16 ++- arch/riscv/kernel/setup.c | 3 + arch/riscv/kernel/signal.c | 174 +++++++++++++++++++++-- 4 files changed, 193 insertions(+), 15 deletions(-) diff --git a/arch/riscv/include/uapi/asm/ptrace.h b/arch/riscv/include/uapi/asm/ptrace.h index e8d127ec5cf7..e17c550986a6 100644 --- a/arch/riscv/include/uapi/asm/ptrace.h +++ b/arch/riscv/include/uapi/asm/ptrace.h @@ -71,6 +71,21 @@ struct __riscv_q_ext_state { __u32 reserved[3]; }; +struct __riscv_ctx_hdr { + __u32 magic; + __u32 size; +}; + +struct __riscv_extra_ext_header { + __u32 __padding[129] __attribute__((aligned(16))); + /* + * Reserved for expansion of sigcontext structure. Currently zeroed + * upon signal, and must be zero upon sigreturn. + */ + __u32 reserved; + struct __riscv_ctx_hdr hdr; +}; + union __riscv_fp_state { struct __riscv_f_ext_state f; struct __riscv_d_ext_state d; diff --git a/arch/riscv/include/uapi/asm/sigcontext.h b/arch/riscv/include/uapi/asm/sigcontext.h index 84f2dfcfdbce..8b8a8541673a 100644 --- a/arch/riscv/include/uapi/asm/sigcontext.h +++ b/arch/riscv/include/uapi/asm/sigcontext.h @@ -8,6 +8,17 @@ #include +/* The Magic number for signal context frame header. */ +#define RISCV_V_MAGIC 0x53465457 +#define END_MAGIC 0x0 + +/* The size of END signal context header. */ +#define END_HDR_SIZE 0x0 + +struct __sc_riscv_v_state { + struct __riscv_v_ext_state v_state; +} __attribute__((aligned(16))); + /* * Signal context structure * @@ -16,7 +27,10 @@ */ struct sigcontext { struct user_regs_struct sc_regs; - union __riscv_fp_state sc_fpregs; + union { + union __riscv_fp_state sc_fpregs; + struct __riscv_extra_ext_header sc_extdesc; + }; }; #endif /* _UAPI_ASM_RISCV_SIGCONTEXT_H */ diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c index 36b026057503..60ebe757ef20 100644 --- a/arch/riscv/kernel/setup.c +++ b/arch/riscv/kernel/setup.c @@ -262,6 +262,8 @@ static void __init parse_dtb(void) #endif } +extern void __init init_rt_signal_env(void); + void __init setup_arch(char **cmdline_p) { parse_dtb(); @@ -295,6 +297,7 @@ void __init setup_arch(char **cmdline_p) riscv_init_cbo_blocksizes(); riscv_fill_hwcap(); + init_rt_signal_env(); apply_boot_alternatives(); if (IS_ENABLED(CONFIG_RISCV_ISA_ZICBOM) && riscv_isa_extension_available(NULL, ZICBOM)) diff --git a/arch/riscv/kernel/signal.c b/arch/riscv/kernel/signal.c index 6b4a5c90bd87..c46f3dc039bb 100644 --- a/arch/riscv/kernel/signal.c +++ b/arch/riscv/kernel/signal.c @@ -19,10 +19,12 @@ #include #include #include +#include #include #include extern u32 __user_rt_sigreturn[2]; +static size_t riscv_v_sc_size __ro_after_init; #define DEBUG_SIG 0 @@ -64,12 +66,87 @@ static long save_fp_state(struct pt_regs *regs, #define restore_fp_state(task, regs) (0) #endif +#ifdef CONFIG_RISCV_ISA_V + +static long save_v_state(struct pt_regs *regs, void __user **sc_vec) +{ + struct __riscv_ctx_hdr __user *hdr; + struct __sc_riscv_v_state __user *state; + void __user *datap; + long err; + + hdr = *sc_vec; + /* Place state to the user's signal context space after the hdr */ + state = (struct __sc_riscv_v_state __user *)(hdr + 1); + /* Point datap right after the end of __sc_riscv_v_state */ + datap = state + 1; + + /* datap is designed to be 16 byte aligned for better performance */ + WARN_ON(unlikely(!IS_ALIGNED((unsigned long)datap, 16))); + + riscv_v_vstate_save(current, regs); + /* Copy everything of vstate but datap. */ + err = __copy_to_user(&state->v_state, ¤t->thread.vstate, + offsetof(struct __riscv_v_ext_state, datap)); + /* Copy the pointer datap itself. */ + err |= __put_user(datap, &state->v_state.datap); + /* Copy the whole vector content to user space datap. */ + err |= __copy_to_user(datap, current->thread.vstate.datap, riscv_v_vsize); + /* Copy magic to the user space after saving all vector conetext */ + err |= __put_user(RISCV_V_MAGIC, &hdr->magic); + err |= __put_user(riscv_v_sc_size, &hdr->size); + if (unlikely(err)) + return err; + + /* Only progress the sv_vec if everything has done successfully */ + *sc_vec += riscv_v_sc_size; + return 0; +} + +/* + * Restore Vector extension context from the user's signal frame. This function + * assumes a valid extension header. So magic and size checking must be done by + * the caller. + */ +static long __restore_v_state(struct pt_regs *regs, void __user *sc_vec) +{ + long err; + struct __sc_riscv_v_state __user *state = sc_vec; + void __user *datap; + + /* Copy everything of __sc_riscv_v_state except datap. */ + err = __copy_from_user(¤t->thread.vstate, &state->v_state, + offsetof(struct __riscv_v_ext_state, datap)); + if (unlikely(err)) + return err; + + /* Copy the pointer datap itself. */ + err = __get_user(datap, &state->v_state.datap); + if (unlikely(err)) + return err; + /* + * Copy the whole vector content from user space datap. Use + * copy_from_user to prevent information leak. + */ + err = copy_from_user(current->thread.vstate.datap, datap, riscv_v_vsize); + if (unlikely(err)) + return err; + + riscv_v_vstate_restore(current, regs); + + return err; +} +#else +#define save_v_state(task, regs) (0) +#define __restore_v_state(task, regs) (0) +#endif + static long restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc) { + void __user *sc_ext_ptr = &sc->sc_extdesc.hdr; + __u32 rsvd; long err; - size_t i; - /* sc_regs is structured the same as the start of pt_regs */ err = __copy_from_user(regs, &sc->sc_regs, sizeof(sc->sc_regs)); if (unlikely(err)) @@ -82,32 +159,81 @@ static long restore_sigcontext(struct pt_regs *regs, return err; } - /* We support no other extension state at this time. */ - for (i = 0; i < ARRAY_SIZE(sc->sc_fpregs.q.reserved); i++) { - u32 value; + /* Check the reserved word before extensions parsing */ + err = __get_user(rsvd, &sc->sc_extdesc.reserved); + if (unlikely(err)) + return err; + if (unlikely(rsvd)) + return -EINVAL; + + while (!err) { + __u32 magic, size; + struct __riscv_ctx_hdr __user *head = sc_ext_ptr; - err = __get_user(value, &sc->sc_fpregs.q.reserved[i]); + err |= __get_user(magic, &head->magic); + err |= __get_user(size, &head->size); if (unlikely(err)) + return err; + + sc_ext_ptr += sizeof(*head); + switch (magic) { + case END_MAGIC: + if (size != END_HDR_SIZE) + return -EINVAL; + + return 0; + case RISCV_V_MAGIC: + if (!has_vector() || !riscv_v_vstate_query(regs) || + size != riscv_v_sc_size) + return -EINVAL; + + err = __restore_v_state(regs, sc_ext_ptr); break; - if (value != 0) + default: return -EINVAL; + } + sc_ext_ptr = (void __user *)head + size; } return err; } +static size_t get_rt_frame_size(void) +{ + struct rt_sigframe __user *frame; + size_t frame_size; + size_t total_context_size = 0; + + frame_size = sizeof(*frame); + + if (has_vector() && 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; + + frame_size = round_up(frame_size, 16); + return frame_size; +} + SYSCALL_DEFINE0(rt_sigreturn) { struct pt_regs *regs = current_pt_regs(); struct rt_sigframe __user *frame; struct task_struct *task; sigset_t set; + size_t frame_size = get_rt_frame_size(); /* Always make any pending restarted system calls return -EINTR */ current->restart_block.fn = do_no_restart_syscall; frame = (struct rt_sigframe __user *)regs->sp; - if (!access_ok(frame, sizeof(*frame))) + if (!access_ok(frame, frame_size)) goto badframe; if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) @@ -141,17 +267,22 @@ static long setup_sigcontext(struct rt_sigframe __user *frame, struct pt_regs *regs) { struct sigcontext __user *sc = &frame->uc.uc_mcontext; + struct __riscv_ctx_hdr __user *sc_ext_ptr = &sc->sc_extdesc.hdr; long err; - size_t i; /* sc_regs is structured the same as the start of pt_regs */ err = __copy_to_user(&sc->sc_regs, regs, sizeof(sc->sc_regs)); /* Save the floating-point state. */ if (has_fpu()) err |= save_fp_state(regs, &sc->sc_fpregs); - /* We support no other extension state at this time. */ - for (i = 0; i < ARRAY_SIZE(sc->sc_fpregs.q.reserved); i++) - err |= __put_user(0, &sc->sc_fpregs.q.reserved[i]); + /* Save the vector state. */ + if (has_vector() && riscv_v_vstate_query(regs)) + err |= save_v_state(regs, (void __user **)&sc_ext_ptr); + /* Write zero to fp-reserved space and check it on restore_sigcontext */ + err |= __put_user(0, &sc->sc_extdesc.reserved); + /* And put END __riscv_ctx_hdr at the end. */ + err |= __put_user(END_MAGIC, &sc_ext_ptr->magic); + err |= __put_user(END_HDR_SIZE, &sc_ext_ptr->size); return err; } @@ -176,6 +307,13 @@ static inline void __user *get_sigframe(struct ksignal *ksig, /* Align the stack frame. */ sp &= ~0xfUL; + /* + * Fail if the size of the altstack is not large enough for the + * sigframe construction. + */ + if (current->sas_ss_size && sp < current->sas_ss_sp) + return (void __user __force *)-1UL; + return (void __user *)sp; } @@ -185,9 +323,10 @@ 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(); - frame = get_sigframe(ksig, regs, sizeof(*frame)); - if (!access_ok(frame, sizeof(*frame))) + frame = get_sigframe(ksig, regs, frame_size); + if (!access_ok(frame, frame_size)) return -EFAULT; err |= copy_siginfo_to_user(&frame->info, &ksig->info); @@ -320,3 +459,10 @@ void arch_do_signal_or_restart(struct pt_regs *regs) */ restore_saved_sigmask(); } + +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; +} From patchwork Thu May 18 16:19:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andy Chiu X-Patchwork-Id: 13247087 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 02083C7EE25 for ; Thu, 18 May 2023 16:21:56 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Tx/8lnt9t/rMLVspknLD3NwxhKfkjlzOORZxl9++VVY=; b=keWgNRvNhYHg+7 eKK960iZ5HqFmGLN55NJ9w0A2dP6HLWut95lns8cV+ILavMaqIyC95DR3m+QWqBt/F81cYqVl4IaX Ljq7Es2OGs+CRS0ULshEH6jv/DUPwBMoQpfTYES8sX+lidu5Bgrfr3HRIvate/soHvYwtN4bHFSK0 ZR3XtD/SYtW+Tx+lahKmqS1cJ3JKMpD1QAyXsd6/hBjlHkrR50ERk6r/EZh27VBJso7ii46EFgLwh 8NuAqKf0b9I5w0c6ijrd474Tu+LlT82wbM/TUY0sVKPcXSD8GrcpcmwT6A4iOk+wsmGid2dj/gow9 dTEmwHMXZjRqVvssKXgA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzgO0-00DRY5-28; Thu, 18 May 2023 16:21:52 +0000 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzgNx-00DRX3-2y for linux-riscv@lists.infradead.org; Thu, 18 May 2023 16:21:51 +0000 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-64d1a0d640cso638621b3a.1 for ; Thu, 18 May 2023 09:21:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1684426909; x=1687018909; 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=MpPHieyVlo9+c3IVReFx0FCE99hnAu9eLlwHEwust2g=; b=YNh1bjHhC0PX/83QQu1B6ejCif5zTb5j50ETUL0+ruUxYTH4sGyPYtyuXxPD9l0/iI CgM6OIYGAwenJ/H34CFPXew2FUqbD4EmhAd+xRh4Rpjf9D0AhE0gx1k9AwOnOeuZalW6 PCDRogUsEW1DHv4kKquU21wxqf7Rv+/SPqLoc5Edau+HxYneBy/BPJXlhalSH00FxXod QCdeSMM/c2fGjqkEeI8lVSwOkBELTRAg6Fquof4zsd2GvHwxLB+68PjWiJxS3mnSj8hc dWj64vlNP3iyOdBBUncyMFguyR0sBsCDyBFjVAI4V0vpls+QxK3R75PNoC7jh0mwVebK 4W6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684426909; x=1687018909; 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=MpPHieyVlo9+c3IVReFx0FCE99hnAu9eLlwHEwust2g=; b=GXHNR32fizwX23oKuKANEiANUja234Kagdsn7WsPnTtDsLKEgE1IhbxjgFND6w99WQ YBBnKUzmhhKuUhkXnmGWKnKYPVIXjCV8K2dGLmW3OttyBrqK5lVcoKf6yYHCAWVSLGux Pet1uPUmiDK2sDXD1RBhnjInLpotiIpYY/K7ldTsWmx1AqUwZKdup900qn+sZwTdU9j3 y+h7UxBY5966LGdjNiGxmUXmeaUWY1m4Afuy0REdeyYJdyb6nQYPPGHbple+oY22IEQ7 rya6Y8FcxHIp6igdxiSAX2yCEzHCq8w3Z4pP3kwhOvyP9aR09M9gVFK2Qlp4nO1ycE1W Ke8g== X-Gm-Message-State: AC+VfDzE1tUiM7IKzbX7f9FouPJgSTLRbek9r6kKhe5fiHuIBADutPda 5vNErtM0cKOsYls2H+jOJc4tMQClex5xFxHilqdVxb+9pvcPfYB3vdXBHEoEe5Hh5yFnf6NPOMS /pPZChvETDmDzV7pyUddMjTlSw6hAboZLIIpgevJYe8xCRjPWywQz1JBTOrw657lL96l0a2P/jM Hs4qKZ+IrnNm0IVZM= X-Google-Smtp-Source: ACHHUZ4ILVOpRISB/8OeR2wlUwEvyc+WA3RrvOZm2XX5avau/XyDylpxRD5A38OMlF8KZoVHY3Ck9g== X-Received: by 2002:a05:6a20:9148:b0:104:f534:6c8d with SMTP id x8-20020a056a20914800b00104f5346c8dmr264980pzc.33.1684426908735; Thu, 18 May 2023 09:21:48 -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.21.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 May 2023 09:21:48 -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 Subject: [PATCH -next v20 15/26] riscv: signal: Report signal frame size to userspace via auxv Date: Thu, 18 May 2023 16:19:38 +0000 Message-Id: <20230518161949.11203-16-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_092149_958398_085E6AB5 X-CRM114-Status: GOOD ( 23.54 ) 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: , Cc: Kefeng Wang , guoren@linux.alibaba.com, Mathis Salmen , Kees Cook , Andrew Bresticker , vineetg@rivosinc.com, Vincent Chen , Conor Dooley , Albert Ou , Guo Ren , Eric Biederman , Andy Chiu , Paul Walmsley , greentime.hu@sifive.com, Zong Li , Heiko Stuebner , Al Viro Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.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^16. Hence, if userspace refers to the MINSIGSTKSZ 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. Note that auxv always reports size of the sigframe as if V exists for all starting processes, whenever the kernel has CONFIG_RISCV_ISA_V. The reason is that users usually reference this value to allocate an alternative signal stack, and the user may use V anytime. So the user must reserve a space for V-context in sigframe in case that the signal handler invokes after the kernel allocating V. Signed-off-by: Greentime Hu Signed-off-by: Vincent Chen Signed-off-by: Andy Chiu Acked-by: Conor Dooley Reviewed-by: Björn Töpel Reviewed-by: Guo Ren Reviewed-by: Heiko Stuebner Tested-by: Heiko Stuebner --- Changelog V19: - Fix a conflict in signal.c due to commit 8d736482749f ("riscv: add icache flush for nommu sigreturn trampoline") --- arch/riscv/include/asm/elf.h | 9 +++++++++ arch/riscv/include/asm/processor.h | 2 ++ arch/riscv/include/uapi/asm/auxvec.h | 1 + arch/riscv/kernel/signal.c | 20 +++++++++++++++----- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/arch/riscv/include/asm/elf.h b/arch/riscv/include/asm/elf.h index 30e7d2455960..ca23c4f6c440 100644 --- a/arch/riscv/include/asm/elf.h +++ b/arch/riscv/include/asm/elf.h @@ -105,6 +105,15 @@ do { \ get_cache_size(3, CACHE_TYPE_UNIFIED)); \ NEW_AUX_ENT(AT_L3_CACHEGEOMETRY, \ get_cache_geometry(3, CACHE_TYPE_UNIFIED)); \ + /* \ + * 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 f0ddf691ac5e..38ded8c5f207 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 @@ -81,6 +82,7 @@ int riscv_of_parent_hartid(struct device_node *node, unsigned long *hartid); extern void riscv_fill_hwcap(void); extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src); +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 fb187a33ce58..10aaa83db89e 100644 --- a/arch/riscv/include/uapi/asm/auxvec.h +++ b/arch/riscv/include/uapi/asm/auxvec.h @@ -35,5 +35,6 @@ /* entries in ARCH_DLINFO */ #define AT_VECTOR_SIZE_ARCH 9 +#define AT_MINSIGSTKSZ 51 #endif /* _UAPI_ASM_RISCV_AUXVEC_H */ diff --git a/arch/riscv/kernel/signal.c b/arch/riscv/kernel/signal.c index c46f3dc039bb..f117641c1c49 100644 --- a/arch/riscv/kernel/signal.c +++ b/arch/riscv/kernel/signal.c @@ -23,6 +23,8 @@ #include #include +unsigned long signal_minsigstksz __ro_after_init; + extern u32 __user_rt_sigreturn[2]; static size_t riscv_v_sc_size __ro_after_init; @@ -197,7 +199,7 @@ static long restore_sigcontext(struct pt_regs *regs, return err; } -static size_t get_rt_frame_size(void) +static size_t get_rt_frame_size(bool cal_all) { struct rt_sigframe __user *frame; size_t frame_size; @@ -205,8 +207,10 @@ static size_t get_rt_frame_size(void) frame_size = sizeof(*frame); - if (has_vector() && riscv_v_vstate_query(task_pt_regs(current))) - total_context_size += riscv_v_sc_size; + if (has_vector()) { + 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 @@ -226,7 +230,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(); + size_t frame_size = get_rt_frame_size(false); /* Always make any pending restarted system calls return -EINTR */ current->restart_block.fn = do_no_restart_syscall; @@ -323,7 +327,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(); + size_t frame_size = get_rt_frame_size(false); frame = get_sigframe(ksig, regs, frame_size); if (!access_ok(frame, frame_size)) @@ -465,4 +469,10 @@ 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; + /* + * 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); } From patchwork Thu May 18 16:19:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Chiu X-Patchwork-Id: 13247167 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 04CA5C77B7D for ; Thu, 18 May 2023 17:30:52 +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=s5LqxxpFVCjPfNdoxB3TWHJj9h54K0yGxDCMBztb/JQ=; b=PZTI7X00TZW+Rr wVsLiCR44H3Vn0Ma82YPRQFZeQn2yGkqBGBx/pOlllgyPjdsKuU80nViRmPbxvpQQdqATccj1rAQw L2+y+wNj9IEMqYn4e0QRVmGbVBYPngVVmh9LpLV7JF5rgNRIWcbKaqkhEpQ4LEwb2WLEcptzDePjp oWTW5qa3D85YfjV1aUVgYB9cFb1Dt63Z9wBoNYSc5Uh4n5hZUZmPbRTTOMCMYQKWSN+i3HtIfgKbF 3R0mPuJG0S4DAbyLGL6gzrREyc20pBCUv7V3fQCtJ8QqM+XQjhBp+7Gy3hwRhV0iZ3FL5Fmvgp7bV YDFQRAre78k0kx85oKqw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzhSi-00De2J-0Q; Thu, 18 May 2023 17:30:48 +0000 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzgO2-00DRYe-0Q for linux-riscv@lists.infradead.org; Thu, 18 May 2023 16:21:56 +0000 Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-64d2981e3abso287719b3a.1 for ; Thu, 18 May 2023 09:21:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1684426913; x=1687018913; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=le6WsiFFpntTNhwR6ZdThyFuzfVMTXPYkTAyRr8nwRI=; b=fXXOF4/Pv9vy548q3wB5i638VAiAI5RYEsTrUBc+Lb3gM4Hwm4KD7C22YFD2UYd0ML EIj0bIxGhmH+aHUWUB9gwOOaPmFfXe5AqyUqObzTgtiqqDzj5Q4VW4HNpdCjTrhZLV9j 9oqEDZAwj/wvOqjtp1dRpunkjC/CHuxw0voOQEY7kBVb2SRDde19L3W5bAC8TptVZFqK 6LZe3vGGTBKDzTJrE62LgcbN2Ok7fJT2iGeFx69qUBMnA8AkjWLkOU4j/UqY74sTYCP0 OiVpmvYhYne29PDTYzXxEAv6pis1jBjDNnuC79vttpOziIMEnRmCcYdyb61Vi7lRumPc kgnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684426913; x=1687018913; 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=le6WsiFFpntTNhwR6ZdThyFuzfVMTXPYkTAyRr8nwRI=; b=IUocdO/yp/qdR0t/lCMBQVE2zM7OxgM2zZvnjjHX0XOcFKEq4Rj+KDROqj25658JbZ ek6jPdT4gn7AN1bkaNX3vv+00P6D4c2jTxn+V80Inu3pJdNFR6dqrt6rc4bKYOpc+PRp UfJwBiC1CgxcetxQYow38L2VFdJuRj3VLQAmdlzWM2hKT3LMAqot8qo80Pl84PM2eHMo aCe/fGiYsfFZH742oCifI01zPJ3/3mQN3/it+C4yorI+LrJytHMxgCqvka2B76hmLlXf 31NRwOEbM0GrTkRO/jsUeLfayEnxYPU1QvlhzWg4hbyX7ZginC4UhiFcDrF1RpStJwNJ QNIw== X-Gm-Message-State: AC+VfDwP7Th0N0oHKlt0QZoBYdz9y3S0TaP8+YZhGn3oHzLxAcNG6Qjg nzBLwcYvQktXV6gwq2V24l3UHjfPJIrIoINwMqM1KoR57MGx7gDTRFWVIIPPNdN7Zdle1YvvulY bObVZO/QyqFZVOAKbfPnT90ITHNtJbDXZDr/v/s8bcAv1wrYJj1etS59H5w1XpW7fVT4VSEHbGy y8cn95xxHRTQOZDgg= X-Google-Smtp-Source: ACHHUZ5zF66YmJviWU3jMsRmaNPWP5h2OCQhUdkxpbsBNEDtT+ng2Q1VyqjENFKM+MPelZ+ItaoLOA== X-Received: by 2002:a05:6a00:17a0:b0:643:ba77:f265 with SMTP id s32-20020a056a0017a000b00643ba77f265mr6240882pfg.25.1684426913165; Thu, 18 May 2023 09:21:53 -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.21.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 May 2023 09:21: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 , Heiko Stuebner , Conor Dooley , Vincent Chen , Al Viro , Andrew Bresticker , Guo Ren Subject: [PATCH -next v20 16/26] riscv: signal: validate altstack to reflect Vector Date: Thu, 18 May 2023 16:19:39 +0000 Message-Id: <20230518161949.11203-17-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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230518_092154_169712_7E4F77DC X-CRM114-Status: GOOD ( 10.77 ) 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 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 Reviewed-by: Heiko Stuebner Tested-by: Heiko Stuebner --- arch/riscv/kernel/signal.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/riscv/kernel/signal.c b/arch/riscv/kernel/signal.c index f117641c1c49..180d951d3624 100644 --- a/arch/riscv/kernel/signal.c +++ b/arch/riscv/kernel/signal.c @@ -476,3 +476,10 @@ 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 */ From patchwork Thu May 18 16:19:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Chiu X-Patchwork-Id: 13247100 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 9EFCCC7EE23 for ; Thu, 18 May 2023 16:40:47 +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=9W40tXwBb/IHTOhUfEvR1aMXU7QRaUyhQIV3Viue5JM=; b=ina1sp+k0fGVjX KvoRctcUfhFll4r8qSvPnE/iYrqNbuwXyx7wLxyNvzRVQH/alni/OcUPbBVNm0IjIsJN50wA3cTYG crRPfkGBeexfEovyOzLNBl04pXXOR/AlMUMvjW+gjUln4FaFBIb2lEuGZwtWer9DZZAS6E0OiZb4i IGYnrKu4mEFaI2MBUWQoCbjke2ul459aQZgQL9TkoKohGH/qcZNbz1O9GnpHajDjmBIaC0aJ75ZDp fBagJprOYNqmfnj8MzaWwZ1mpt4sCmSeTVLY7TVCoCXiVDmz/HOZ5JYuh8mcOw4AP7Hza7+bCbBqj KeyAByhxSKXz5YnRxaVw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzggF-00DVA3-2C; Thu, 18 May 2023 16:40:43 +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 1pzggC-00DV6M-0E for linux-riscv@bombadil.infradead.org; Thu, 18 May 2023 16:40:40 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=References:In-Reply-To:Message-Id:Date :Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description; bh=hWB54ZotS7Y2ZgKJV1SIpYTu+cs8XvC1qHz0MxJpXfU=; b=DkX9OC8+dTbwIyj+O6faUNwoVv +JuVX3P/brHS1KMNcoRcPxoJ8VHL/wK9wiug+RlrpoXyUzoQPpH1CMNdJgKpbVV/bg7v2zwaJ4H4T pJFvDWhv4zo7XQ4f17DPD9/rFv3wwMSYh5hmnI+UnEWCCgN+ViCdBV1Y/GlN/rsT40bg4y+I2yEt/ 0BoWGgrCXr+G6Le2f3ERUmkhI1ktkm7WW2kg0P1dc6yJ8M4ZBHp4uu1bOghGyKqPo0oXnZC4UGk/z pBIlSgNJ553XH1TCiINBjmR7bNrEDhlPDoUAI7GjFHIcOiPdzMta17VnQV6G7nkcqvV01ih6u3127 dTAnh0HQ==; Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzgO7-00ErNo-1L for linux-riscv@lists.infradead.org; Thu, 18 May 2023 16:22:01 +0000 Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-6434e65d808so2219345b3a.3 for ; Thu, 18 May 2023 09:21:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1684426918; x=1687018918; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=hWB54ZotS7Y2ZgKJV1SIpYTu+cs8XvC1qHz0MxJpXfU=; b=FGv5VC8qd8ZaQHUAio11tWcVOAJTKDCLg3ky/g5iw3BFCvNjeka0E7pQM453bzoCKP wIxdZ5sP4PNjcALeoHIQWRy7mvKcBilJMow0FYi+Sz/KKNVPQVkWqtUNvCSlPka2E35d ysRCCyw5nlr/j+xavMp8+mW/BTJpm+6Dk+MrHTjWeMKfKuHWa2fPfoHdJezy5vH2Lka6 DcvQ/QCttbC9mzeOGRrl1q0iLM2uuUgLRluzeecoD8qOkGr49tUbE0owx5FGYmUkfZXf htSbdS/C3MBoF6QegQH4RlgfbsSVTOsKv7As2f6/WCIW+zs9XdTfhkxPwBVxJAXHLdft +17g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684426918; x=1687018918; 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=hWB54ZotS7Y2ZgKJV1SIpYTu+cs8XvC1qHz0MxJpXfU=; b=glO0D3mQ8FUbqUaW6zbvP3mypEiycNFRCToUyDnAIE9wB/1pfMiSs5Z/Nlam+9O4p+ nM747cZQNev2G3BLA18kI/o3Aw0i+VcRx0L/wwL7fdcHCbrqqwi5uG8W24K/t6jaaMX5 Y2VTIdHUeCFSd7tMOpAecbtYQpFtvqdnn68fr1SQ9vC4qQYBYDjUJ2IJDDosHUycq9zG zsZNN70MJmhfuR0J4U5IZAnBM8MR7Bqem+zzaximO8sLeZmOJ4Z32BxEU588ERp/vsdy wXIlbgvGB34UVvWolPUloYOKLbIp+R/7VEH5Zh0oCzZOryY22MTLA3kE41bqW3SzMIJn 0VVA== X-Gm-Message-State: AC+VfDzf6ubOGAdjTJe0ULBK3J6+0YAO0DSly2Wrdo3d5gI+yubr1wQV gOoLhQfekp1HLgj214lOYmQMyeHNE6F7Dp6KdZh7CwOXquRXxogpz0EpR2pFCNph2j5uJKRUYgf GK1ONlKmqioDbalimjx3NCrO2+d15zfGon5aj9BoYpmlwYR+6/OVz4/OFy8GrszwDIQ5js59dum x1Kfv+GucQWKPFS1k= X-Google-Smtp-Source: ACHHUZ7DzGc8mbcm6gyG1FaCHM1UkX6ZTTMNq1vqBYdrEFA512Vhot+N0Bt1uC5VXAF+cM6Xb4Xpjw== X-Received: by 2002:a05:6a20:7489:b0:102:3f67:dbe1 with SMTP id p9-20020a056a20748900b001023f67dbe1mr422644pzd.4.1684426917627; Thu, 18 May 2023 09:21:57 -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.21.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 May 2023 09:21:57 -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, ShihPo Hung , Vincent Chen , Andy Chiu , Paul Walmsley , Albert Ou , Heiko Stuebner , Masahiro Yamada , Alexandre Ghiti , Guo Ren Subject: [PATCH -next v20 17/26] riscv: prevent stack corruption by reserving task_pt_regs(p) early Date: Thu, 18 May 2023 16:19:40 +0000 Message-Id: <20230518161949.11203-18-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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230518_172159_530581_D5662647 X-CRM114-Status: UNSURE ( 9.51 ) 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 From: Greentime Hu Early function calls, such as setup_vm(), relocate_enable_mmu(), soc_early_init() etc, are free to operate on stack. However, PT_SIZE_ON_STACK bytes at the head of the kernel stack are purposedly reserved for the placement of per-task register context pointed by task_pt_regs(p). Those functions may corrupt task_pt_regs if we overlap the $sp with it. In fact, we had accidentally corrupted sstatus.VS in some tests, treating the kernel to save V context before V was actually allocated, resulting in a kernel panic. Thus, we should skip PT_SIZE_ON_STACK for $sp before making C function calls from the top-level assembly. Co-developed-by: ShihPo Hung Signed-off-by: ShihPo Hung Co-developed-by: Vincent Chen Signed-off-by: Vincent Chen Signed-off-by: Greentime Hu Signed-off-by: Andy Chiu Reviewed-by: Conor Dooley Reviewed-by: Heiko Stuebner Tested-by: Heiko Stuebner --- arch/riscv/kernel/head.S | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S index e16bb2185d55..11c3b94c4534 100644 --- a/arch/riscv/kernel/head.S +++ b/arch/riscv/kernel/head.S @@ -301,6 +301,7 @@ clear_bss_done: la tp, init_task la sp, init_thread_union + THREAD_SIZE XIP_FIXUP_OFFSET sp + addi sp, sp, -PT_SIZE_ON_STACK #ifdef CONFIG_BUILTIN_DTB la a0, __dtb_start XIP_FIXUP_OFFSET a0 @@ -318,6 +319,7 @@ clear_bss_done: /* Restore C environment */ la tp, init_task la sp, init_thread_union + THREAD_SIZE + addi sp, sp, -PT_SIZE_ON_STACK #ifdef CONFIG_KASAN call kasan_early_init From patchwork Thu May 18 16:19:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Chiu X-Patchwork-Id: 13247092 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 A0E4FC77B7A for ; Thu, 18 May 2023 16:40:22 +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=J7Zpk/i0vy9xvBHfYOIufpEZ46C+ZgqW+byMyoUfrIg=; b=hHxFEydgyTV/DD haMFJM7d126FpUd5pmAizzlX8g/DS+r8XUNkzTVlslsePBZVAbt6+tMDOjGoNd7DPMHu6L+xwr2F5 3vfmVRrndi/707uin+OQUdNepVtfInPOIijIDglLdOZp7I8Ei38/1Avj4wus8AAH2F3QPG6Wqt4+c +iHFVsvzsiQrOvqRrtPzEsA7+Bgxpf2Ge0LBz1UkUK1DUIpOWKGXOmp/gMtT004l1c8YL4L2y3OdU Bt8SRlSlPVUH8vegFE88Kz76wG79Vv6VlO3jmesl9VQttlO4OeHtBQ8Rd2mlu4FNyApzlk1Fn720s 2UO+q7OIFztL3Kq1q8pg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzgfn-00DUrj-1k; Thu, 18 May 2023 16:40:15 +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 1pzgfm-00DUr7-0E for linux-riscv@bombadil.infradead.org; Thu, 18 May 2023 16:40:14 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=References:In-Reply-To:Message-Id:Date :Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description; bh=2CmyEkggETxM6j+XfIPwTDc2gU78hVyVqaTRQMELVN4=; b=UhcZmbZzE7zHOLcxHCK3n5tEJZ GKC2CICtdVfObLMP5V1jyP6JgLSMo+qGatFK7TZCD6AYik4EcyJNhd+SQdCjBcoa0rHQp8JEFrz0j xqxcqrQVcbKo8TdIqFk0trAFLW25rKl3T96OvBMeySsJJOJeviK/8cX8MTstsQ3um4E8FAKKubKvJ X8pqWN9y8fwIGSgnbGNKhvJAu0aSLKx07Uz+4wKHgzgcr82cFc1wZ/aCSPv0GPGXafuROgwwhL3z4 +u9CKYacAyYE0x1X1vbpnLxB8uT1Ug+E7Icecb6owLtMZ/a5TJba34rnnRdKqyHEobm0YRAH0CwK6 IfIZrb5A==; Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzgOB-00ErOJ-0V for linux-riscv@lists.infradead.org; Thu, 18 May 2023 16:22:05 +0000 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-64d24136663so465686b3a.0 for ; Thu, 18 May 2023 09:22:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1684426921; x=1687018921; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=2CmyEkggETxM6j+XfIPwTDc2gU78hVyVqaTRQMELVN4=; b=AHgrGM3jlPNTSTiBOZXW97pWonk960v7FCpKkUSFO/Y9Nn3G9p9ifI4xumGalBeD8a ye8dx3J5sseaWNgTc1TBQ7/a6nk7QMlGOlqzMw6kg+gxxAkK+3l1DMvdTf1vk6fhg6OG oztqOYqxmsS2pUFQlHThd3wa/fD7Q3CCR6R3K8I57MHd5LkfVpOv+ruiHpZujgdrEUbC 3gWDPmYGpAEeAgbphIJo5F1qtYBcSAxzbpC0GNT/QYDn7G9FDXkdkW8XdeZDPkJOyVEF bikoNET83RWv57aiVG/MG45EkIUd7gwBDGYmy5weNCoTa90jf9OSsIgefh06scr1ZJhc zGTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684426921; x=1687018921; 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=2CmyEkggETxM6j+XfIPwTDc2gU78hVyVqaTRQMELVN4=; b=dAq3RZLzD5PvGEUKvalvtOhrBVcH7i+h97UmpS/trtpxrq7ywA7V/5tKqE0oGhopa/ GCIpNYF2J6mI2xriAZYkJHu+YtwvdMK9wwL0QB5s5N/hZYPbjCsN1uzFQ2WLj3dUfH9D Vg+EqFwWG+W+k0TZi/qCrzaMvd5PnNHMvQQnI0M/JOud8kmfJw2k1Q2fddEU7s0c9qvo jdm8/5pMy5n/dtNXLBkdYUoFbE24Xu/isvNvOgXBNKvoHQl+IaztDiJBQp4pm1XZmu/p SCk7jgr+IV8NGPdIGSjgtlcqiXog7GlojJzxHUScC1ygdqSQ2e6U0qNC0DFU6TtJuCJ1 67gA== X-Gm-Message-State: AC+VfDxFIG1LNdRAaPw4cc/xcJZmxdgmn3E6tj1CYmF7FHbwbSQXdLO2 nSDQJYYxtlCKAENybfmV38kG8L6ps1RVKE5QNqeGflSYrv9VPWVe4n+Ap1tk+NdMYL3mTre8Ls4 wM0ckvFblGRcBs85HBJ4TczLK26PperpPCAcI99FNg4vymew2+l88deXjBdsMm4Fvq1NQt8nDjE hEJe5cBdnTcWFHbms= X-Google-Smtp-Source: ACHHUZ6zEjYzMrp4gF79neLgZkrJ+BeVeXYBeUFIHe55QmvShuoHFiUoi5uBX6k4SWgM8gl2g1pynQ== X-Received: by 2002:a05:6a00:21ca:b0:64c:ecf7:f49a with SMTP id t10-20020a056a0021ca00b0064cecf7f49amr6056402pfj.21.1684426920701; Thu, 18 May 2023 09:22:00 -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.21.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 May 2023 09:22:00 -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, Vincent Chen , Andy Chiu , Paul Walmsley , Albert Ou Subject: [PATCH -next v20 18/26] riscv: kvm: Add V extension to KVM ISA Date: Thu, 18 May 2023 16:19:41 +0000 Message-Id: <20230518161949.11203-19-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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230518_172203_666260_011A4917 X-CRM114-Status: UNSURE ( 9.02 ) 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 From: Vincent Chen Add V extension to KVM isa extension list to enable supporting of V extension on VCPUs. Signed-off-by: Vincent Chen Signed-off-by: Greentime Hu Signed-off-by: Andy Chiu Reviewed-by: Conor Dooley Reviewed-by: Anup Patel Acked-by: Anup Patel Reviewed-by: Heiko Stuebner --- arch/riscv/include/uapi/asm/kvm.h | 1 + arch/riscv/kvm/vcpu.c | 1 + 2 files changed, 2 insertions(+) diff --git a/arch/riscv/include/uapi/asm/kvm.h b/arch/riscv/include/uapi/asm/kvm.h index f92790c9481a..8feb57c4c2e8 100644 --- a/arch/riscv/include/uapi/asm/kvm.h +++ b/arch/riscv/include/uapi/asm/kvm.h @@ -121,6 +121,7 @@ enum KVM_RISCV_ISA_EXT_ID { KVM_RISCV_ISA_EXT_ZICBOZ, KVM_RISCV_ISA_EXT_ZBB, KVM_RISCV_ISA_EXT_SSAIA, + KVM_RISCV_ISA_EXT_V, KVM_RISCV_ISA_EXT_MAX, }; diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c index 8bd9f2a8a0b9..f3282ff371ca 100644 --- a/arch/riscv/kvm/vcpu.c +++ b/arch/riscv/kvm/vcpu.c @@ -57,6 +57,7 @@ static const unsigned long kvm_isa_ext_arr[] = { [KVM_RISCV_ISA_EXT_H] = RISCV_ISA_EXT_h, [KVM_RISCV_ISA_EXT_I] = RISCV_ISA_EXT_i, [KVM_RISCV_ISA_EXT_M] = RISCV_ISA_EXT_m, + [KVM_RISCV_ISA_EXT_V] = RISCV_ISA_EXT_v, KVM_ISA_EXT_ARR(SSAIA), KVM_ISA_EXT_ARR(SSTC), From patchwork Thu May 18 16:19:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Chiu X-Patchwork-Id: 13247093 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 42251C7EE23 for ; Thu, 18 May 2023 16:40:23 +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=ZWpIycgQwJtKn4dWrVvNze1hG8GFqLC9XgTa9LLW6ZA=; b=uUU4j1+PYW9134 cJ7q1q0u2xUr/vIGUOJPRz//W/wOWXNwfqrT8bMA+HCZIZ2g7l+RjnIIE4QnUVqqadB3AMg9mjfr8 1mgU+BndCKnLVuirdEOOGijCcLTSraO4P1LZcTZCH64dp9QdmocwMty9/A21UauaWCrjPLtCjBApf p6ccg3OuU03UyPBJI4rEmAv+2Nsrr+4E5RfwEEqBhIGBayjQtXYIteVv1ic0ECpo62B6b40dfNw07 NRt5gIA+9ePQloR8sVZaZyGqQ5LwVUngWK2K/U0t/Z/FQPnd4vkql/e9D3NFoV9kir6M7j8xjdSx4 xl7SzlL/OBjZyIzwjcXA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzgfr-00DUsf-0T; Thu, 18 May 2023 16:40:19 +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 1pzgfo-00DUrq-1m for linux-riscv@bombadil.infradead.org; Thu, 18 May 2023 16:40:16 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=References:In-Reply-To:Message-Id:Date :Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description; bh=zzVQEtVE9GUiE8tfgntIQRd4M5KNUPh8Pcnqg79C1jo=; b=iilzFBLz4b5HCJljKWF8tXnZk/ 79NyTK9O8s8rhUUl5ahtkIlv4Mrv5tvvqIOTa8zQA4b8oObPd8GN4XKf5TTniiRpRrkO+H42kDfLY pVKQ8QHO1e0/E7uykFu+NBvHM7FuL0MJ7qlaVc84Pgo/VifHyG4YJmiC/Ax71Ro/2srtjjrG9YUzr UMmWNDSNSDZqXZopWs8Syh15vk0WRpx8gbi58oxwwvTByilOBQMrq/ZhNBojsfRC++vGxQOmfZLtk csnZj/CWQN01dsDofMX7Fkoku+qqIL8Ejo7uQWaDkm9R3wH8qLVgqwa63DMJTWNaBsmplGk5r4b2S 5P70MeBg==; Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzgOF-00ErPU-2V for linux-riscv@lists.infradead.org; Thu, 18 May 2023 16:22:10 +0000 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-64354231003so1047983b3a.0 for ; Thu, 18 May 2023 09:22:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1684426925; x=1687018925; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=zzVQEtVE9GUiE8tfgntIQRd4M5KNUPh8Pcnqg79C1jo=; b=XFVj8XyZyTYF2ZpZcQjF1y0XX4/GR60W/6ZDLkC+yGpklLsYbc1Y56Q3YO9KYsSsPX kXUupFLNs/fIJJUKI5+rtH9S+9KDC7K6MhzYlmS/fj7AvcxJXpxw7nwpJQ5aAJPpJ8Wj XBVWOofEtQsQfLXltVrMd5k5FHHKkZNv4ONJ1VCi6tGO+ekTBFrcTI7M+ICtZ+23/XiY AhJoXPR9Ve5SIX8utYQcWifsPR+GqPAe4r7+oqSQd92T6PbgVTwOHF6/YWKdARjf6Yi+ 0j3/CnGLx0CMWIvbPIewwuvK/KAbhUxWtpkWVwQci0QH8Qp6cP3pIOlnszBEj39gEitR 9m1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684426925; x=1687018925; 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=zzVQEtVE9GUiE8tfgntIQRd4M5KNUPh8Pcnqg79C1jo=; b=gfktSuvBkBsy7sKlrwUUZ7xFdjKaKTbHyDPDlcE3K6CpyCCeGuQ/we93lPNQFNKdBu DqZvv8dzxUvcHdFYJjrY0Vaal83rFA95M6AuHr7RKq8JT2dmJry26LfLHH32xhi1Pe0+ zFXm0K9vNcMWnJb1ZKRM9qGte9NApfYOW1ArObqGJ4BMYNP7Bd0BVmyH2yEmVkKwy3Hc HFWh1ShhN0WbL68dIBWz/SYxQO5iceWsKoSZ5/Zru4QKlFN4i+iEhGpwnMWQWlkFzYza yBoTMyYzWkhaZRw2ujOPYoj76xGxtF/4gGtV+oOudPQeT+VaA7QSlKUP7LYENUDikYIF VcWQ== X-Gm-Message-State: AC+VfDzWuNJ4PQAiWvePxPXiWXzRu/nITxo4PiL+80+QwF9BsJHAsPFI qAujQEdD283zYk8r38RPHkVSyae57s3vNfsEmy+Ef3Vfdiako82qriNT/ceKO5PwwxjFhApRsHb 7AuNZdBrwNmFtJ0c3FmO+NE9yi//dw2+NYgd5LrABgi+tknD6kEKj1GC6tpr9U+OemoggFPKEhp nB3t2Y4RaO3GAN1gk= X-Google-Smtp-Source: ACHHUZ7cdXo5rGmP2cC2zzKjlEYfemA3sM6wmUhh3PujaFw5aSNllJTkdCmjAltgMnDAHr6SoxPHrQ== X-Received: by 2002:a05:6a00:4c0a:b0:63c:56f5:5053 with SMTP id ea10-20020a056a004c0a00b0063c56f55053mr4861091pfb.13.1684426925087; Thu, 18 May 2023 09:22:05 -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.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 May 2023 09:22:04 -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, Vincent Chen , Andy Chiu , Paul Walmsley , Albert Ou Subject: [PATCH -next v20 19/26] riscv: KVM: Add vector lazy save/restore support Date: Thu, 18 May 2023 16:19:42 +0000 Message-Id: <20230518161949.11203-20-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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230518_172208_027255_9E04E76E X-CRM114-Status: GOOD ( 24.30 ) 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 From: Vincent Chen This patch adds vector context save/restore for guest VCPUs. To reduce the impact on KVM performance, the implementation imitates the FP context switch mechanism to lazily store and restore the vector context only when the kernel enters/exits the in-kernel run loop and not during the KVM world switch. Signed-off-by: Vincent Chen Signed-off-by: Greentime Hu Signed-off-by: Andy Chiu Reviewed-by: Anup Patel Acked-by: Anup Patel --- Changelog V19: - remap V extension registers as type 9 in uapi/asm/kvm.h --- arch/riscv/include/asm/kvm_host.h | 2 + arch/riscv/include/asm/kvm_vcpu_vector.h | 82 ++++++++++ arch/riscv/include/uapi/asm/kvm.h | 7 + arch/riscv/kvm/Makefile | 1 + arch/riscv/kvm/vcpu.c | 22 +++ arch/riscv/kvm/vcpu_vector.c | 186 +++++++++++++++++++++++ 6 files changed, 300 insertions(+) create mode 100644 arch/riscv/include/asm/kvm_vcpu_vector.h create mode 100644 arch/riscv/kvm/vcpu_vector.c diff --git a/arch/riscv/include/asm/kvm_host.h b/arch/riscv/include/asm/kvm_host.h index ee0acccb1d3b..bd47a1dc2ff8 100644 --- a/arch/riscv/include/asm/kvm_host.h +++ b/arch/riscv/include/asm/kvm_host.h @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -145,6 +146,7 @@ struct kvm_cpu_context { unsigned long sstatus; unsigned long hstatus; union __riscv_fp_state fp; + struct __riscv_v_ext_state vector; }; struct kvm_vcpu_csr { diff --git a/arch/riscv/include/asm/kvm_vcpu_vector.h b/arch/riscv/include/asm/kvm_vcpu_vector.h new file mode 100644 index 000000000000..ff994fdd6d0d --- /dev/null +++ b/arch/riscv/include/asm/kvm_vcpu_vector.h @@ -0,0 +1,82 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (C) 2022 SiFive + * + * Authors: + * Vincent Chen + * Greentime Hu + */ + +#ifndef __KVM_VCPU_RISCV_VECTOR_H +#define __KVM_VCPU_RISCV_VECTOR_H + +#include + +#ifdef CONFIG_RISCV_ISA_V +#include +#include + +static __always_inline void __kvm_riscv_vector_save(struct kvm_cpu_context *context) +{ + __riscv_v_vstate_save(&context->vector, context->vector.datap); +} + +static __always_inline void __kvm_riscv_vector_restore(struct kvm_cpu_context *context) +{ + __riscv_v_vstate_restore(&context->vector, context->vector.datap); +} + +void kvm_riscv_vcpu_vector_reset(struct kvm_vcpu *vcpu); +void kvm_riscv_vcpu_guest_vector_save(struct kvm_cpu_context *cntx, + unsigned long *isa); +void kvm_riscv_vcpu_guest_vector_restore(struct kvm_cpu_context *cntx, + unsigned long *isa); +void kvm_riscv_vcpu_host_vector_save(struct kvm_cpu_context *cntx); +void kvm_riscv_vcpu_host_vector_restore(struct kvm_cpu_context *cntx); +int kvm_riscv_vcpu_alloc_vector_context(struct kvm_vcpu *vcpu, + struct kvm_cpu_context *cntx); +void kvm_riscv_vcpu_free_vector_context(struct kvm_vcpu *vcpu); +#else + +struct kvm_cpu_context; + +static inline void kvm_riscv_vcpu_vector_reset(struct kvm_vcpu *vcpu) +{ +} + +static inline void kvm_riscv_vcpu_guest_vector_save(struct kvm_cpu_context *cntx, + unsigned long *isa) +{ +} + +static inline void kvm_riscv_vcpu_guest_vector_restore(struct kvm_cpu_context *cntx, + unsigned long *isa) +{ +} + +static inline void kvm_riscv_vcpu_host_vector_save(struct kvm_cpu_context *cntx) +{ +} + +static inline void kvm_riscv_vcpu_host_vector_restore(struct kvm_cpu_context *cntx) +{ +} + +static inline int kvm_riscv_vcpu_alloc_vector_context(struct kvm_vcpu *vcpu, + struct kvm_cpu_context *cntx) +{ + return 0; +} + +static inline void kvm_riscv_vcpu_free_vector_context(struct kvm_vcpu *vcpu) +{ +} +#endif + +int kvm_riscv_vcpu_get_reg_vector(struct kvm_vcpu *vcpu, + const struct kvm_one_reg *reg, + unsigned long rtype); +int kvm_riscv_vcpu_set_reg_vector(struct kvm_vcpu *vcpu, + const struct kvm_one_reg *reg, + unsigned long rtype); +#endif diff --git a/arch/riscv/include/uapi/asm/kvm.h b/arch/riscv/include/uapi/asm/kvm.h index 8feb57c4c2e8..855c047e86d4 100644 --- a/arch/riscv/include/uapi/asm/kvm.h +++ b/arch/riscv/include/uapi/asm/kvm.h @@ -204,6 +204,13 @@ enum KVM_RISCV_SBI_EXT_ID { #define KVM_REG_RISCV_SBI_MULTI_REG_LAST \ KVM_REG_RISCV_SBI_MULTI_REG(KVM_RISCV_SBI_EXT_MAX - 1) +/* V extension registers are mapped as type 9 */ +#define KVM_REG_RISCV_VECTOR (0x09 << KVM_REG_RISCV_TYPE_SHIFT) +#define KVM_REG_RISCV_VECTOR_CSR_REG(name) \ + (offsetof(struct __riscv_v_ext_state, name) / sizeof(unsigned long)) +#define KVM_REG_RISCV_VECTOR_REG(n) \ + ((n) + sizeof(struct __riscv_v_ext_state) / sizeof(unsigned long)) + #endif #endif /* __LINUX_KVM_RISCV_H */ diff --git a/arch/riscv/kvm/Makefile b/arch/riscv/kvm/Makefile index 8031b8912a0d..7b4c21f9aa6a 100644 --- a/arch/riscv/kvm/Makefile +++ b/arch/riscv/kvm/Makefile @@ -17,6 +17,7 @@ kvm-y += mmu.o kvm-y += vcpu.o kvm-y += vcpu_exit.o kvm-y += vcpu_fp.o +kvm-y += vcpu_vector.o kvm-y += vcpu_insn.o kvm-y += vcpu_switch.o kvm-y += vcpu_sbi.o diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c index f3282ff371ca..e5e045852e6a 100644 --- a/arch/riscv/kvm/vcpu.c +++ b/arch/riscv/kvm/vcpu.c @@ -22,6 +22,8 @@ #include #include #include +#include +#include const struct _kvm_stats_desc kvm_vcpu_stats_desc[] = { KVM_GENERIC_VCPU_STATS(), @@ -139,6 +141,8 @@ static void kvm_riscv_reset_vcpu(struct kvm_vcpu *vcpu) kvm_riscv_vcpu_fp_reset(vcpu); + kvm_riscv_vcpu_vector_reset(vcpu); + kvm_riscv_vcpu_timer_reset(vcpu); kvm_riscv_vcpu_aia_reset(vcpu); @@ -199,6 +203,9 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu) cntx->hstatus |= HSTATUS_SPVP; cntx->hstatus |= HSTATUS_SPV; + if (kvm_riscv_vcpu_alloc_vector_context(vcpu, cntx)) + return -ENOMEM; + /* By default, make CY, TM, and IR counters accessible in VU mode */ reset_csr->scounteren = 0x7; @@ -242,6 +249,9 @@ void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu) /* Free unused pages pre-allocated for G-stage page table mappings */ kvm_mmu_free_memory_cache(&vcpu->arch.mmu_page_cache); + + /* Free vector context space for host and guest kernel */ + kvm_riscv_vcpu_free_vector_context(vcpu); } int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu) @@ -680,6 +690,9 @@ static int kvm_riscv_vcpu_set_reg(struct kvm_vcpu *vcpu, return kvm_riscv_vcpu_set_reg_isa_ext(vcpu, reg); case KVM_REG_RISCV_SBI_EXT: return kvm_riscv_vcpu_set_reg_sbi_ext(vcpu, reg); + case KVM_REG_RISCV_VECTOR: + return kvm_riscv_vcpu_set_reg_vector(vcpu, reg, + KVM_REG_RISCV_VECTOR); default: break; } @@ -709,6 +722,9 @@ static int kvm_riscv_vcpu_get_reg(struct kvm_vcpu *vcpu, return kvm_riscv_vcpu_get_reg_isa_ext(vcpu, reg); case KVM_REG_RISCV_SBI_EXT: return kvm_riscv_vcpu_get_reg_sbi_ext(vcpu, reg); + case KVM_REG_RISCV_VECTOR: + return kvm_riscv_vcpu_get_reg_vector(vcpu, reg, + KVM_REG_RISCV_VECTOR); default: break; } @@ -1003,6 +1019,9 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) kvm_riscv_vcpu_host_fp_save(&vcpu->arch.host_context); kvm_riscv_vcpu_guest_fp_restore(&vcpu->arch.guest_context, vcpu->arch.isa); + kvm_riscv_vcpu_host_vector_save(&vcpu->arch.host_context); + kvm_riscv_vcpu_guest_vector_restore(&vcpu->arch.guest_context, + vcpu->arch.isa); kvm_riscv_vcpu_aia_load(vcpu, cpu); @@ -1022,6 +1041,9 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) kvm_riscv_vcpu_host_fp_restore(&vcpu->arch.host_context); kvm_riscv_vcpu_timer_save(vcpu); + kvm_riscv_vcpu_guest_vector_save(&vcpu->arch.guest_context, + vcpu->arch.isa); + kvm_riscv_vcpu_host_vector_restore(&vcpu->arch.host_context); csr->vsstatus = csr_read(CSR_VSSTATUS); csr->vsie = csr_read(CSR_VSIE); diff --git a/arch/riscv/kvm/vcpu_vector.c b/arch/riscv/kvm/vcpu_vector.c new file mode 100644 index 000000000000..edd2eecbddc2 --- /dev/null +++ b/arch/riscv/kvm/vcpu_vector.c @@ -0,0 +1,186 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2022 SiFive + * + * Authors: + * Vincent Chen + * Greentime Hu + */ + +#include +#include +#include +#include +#include +#include +#include + +#ifdef CONFIG_RISCV_ISA_V +void kvm_riscv_vcpu_vector_reset(struct kvm_vcpu *vcpu) +{ + unsigned long *isa = vcpu->arch.isa; + struct kvm_cpu_context *cntx = &vcpu->arch.guest_context; + + cntx->sstatus &= ~SR_VS; + if (riscv_isa_extension_available(isa, v)) { + cntx->sstatus |= SR_VS_INITIAL; + WARN_ON(!cntx->vector.datap); + memset(cntx->vector.datap, 0, riscv_v_vsize); + } else { + cntx->sstatus |= SR_VS_OFF; + } +} + +static void kvm_riscv_vcpu_vector_clean(struct kvm_cpu_context *cntx) +{ + cntx->sstatus &= ~SR_VS; + cntx->sstatus |= SR_VS_CLEAN; +} + +void kvm_riscv_vcpu_guest_vector_save(struct kvm_cpu_context *cntx, + unsigned long *isa) +{ + if ((cntx->sstatus & SR_VS) == SR_VS_DIRTY) { + if (riscv_isa_extension_available(isa, v)) + __kvm_riscv_vector_save(cntx); + kvm_riscv_vcpu_vector_clean(cntx); + } +} + +void kvm_riscv_vcpu_guest_vector_restore(struct kvm_cpu_context *cntx, + unsigned long *isa) +{ + if ((cntx->sstatus & SR_VS) != SR_VS_OFF) { + if (riscv_isa_extension_available(isa, v)) + __kvm_riscv_vector_restore(cntx); + kvm_riscv_vcpu_vector_clean(cntx); + } +} + +void kvm_riscv_vcpu_host_vector_save(struct kvm_cpu_context *cntx) +{ + /* No need to check host sstatus as it can be modified outside */ + if (riscv_isa_extension_available(NULL, v)) + __kvm_riscv_vector_save(cntx); +} + +void kvm_riscv_vcpu_host_vector_restore(struct kvm_cpu_context *cntx) +{ + if (riscv_isa_extension_available(NULL, v)) + __kvm_riscv_vector_restore(cntx); +} + +int kvm_riscv_vcpu_alloc_vector_context(struct kvm_vcpu *vcpu, + struct kvm_cpu_context *cntx) +{ + cntx->vector.datap = kmalloc(riscv_v_vsize, GFP_KERNEL); + if (!cntx->vector.datap) + return -ENOMEM; + + vcpu->arch.host_context.vector.datap = kzalloc(riscv_v_vsize, GFP_KERNEL); + if (!vcpu->arch.host_context.vector.datap) + return -ENOMEM; + + return 0; +} + +void kvm_riscv_vcpu_free_vector_context(struct kvm_vcpu *vcpu) +{ + kfree(vcpu->arch.guest_reset_context.vector.datap); + kfree(vcpu->arch.host_context.vector.datap); +} +#endif + +static void *kvm_riscv_vcpu_vreg_addr(struct kvm_vcpu *vcpu, + unsigned long reg_num, + size_t reg_size) +{ + struct kvm_cpu_context *cntx = &vcpu->arch.guest_context; + void *reg_val; + size_t vlenb = riscv_v_vsize / 32; + + if (reg_num < KVM_REG_RISCV_VECTOR_REG(0)) { + if (reg_size != sizeof(unsigned long)) + return NULL; + switch (reg_num) { + case KVM_REG_RISCV_VECTOR_CSR_REG(vstart): + reg_val = &cntx->vector.vstart; + break; + case KVM_REG_RISCV_VECTOR_CSR_REG(vl): + reg_val = &cntx->vector.vl; + break; + case KVM_REG_RISCV_VECTOR_CSR_REG(vtype): + reg_val = &cntx->vector.vtype; + break; + case KVM_REG_RISCV_VECTOR_CSR_REG(vcsr): + reg_val = &cntx->vector.vcsr; + break; + case KVM_REG_RISCV_VECTOR_CSR_REG(datap): + default: + return NULL; + } + } else if (reg_num <= KVM_REG_RISCV_VECTOR_REG(31)) { + if (reg_size != vlenb) + return NULL; + reg_val = cntx->vector.datap + + (reg_num - KVM_REG_RISCV_VECTOR_REG(0)) * vlenb; + } else { + return NULL; + } + + return reg_val; +} + +int kvm_riscv_vcpu_get_reg_vector(struct kvm_vcpu *vcpu, + const struct kvm_one_reg *reg, + unsigned long rtype) +{ + unsigned long *isa = vcpu->arch.isa; + unsigned long __user *uaddr = + (unsigned long __user *)(unsigned long)reg->addr; + unsigned long reg_num = reg->id & ~(KVM_REG_ARCH_MASK | + KVM_REG_SIZE_MASK | + rtype); + void *reg_val = NULL; + size_t reg_size = KVM_REG_SIZE(reg->id); + + if (rtype == KVM_REG_RISCV_VECTOR && + riscv_isa_extension_available(isa, v)) { + reg_val = kvm_riscv_vcpu_vreg_addr(vcpu, reg_num, reg_size); + } + + if (!reg_val) + return -EINVAL; + + if (copy_to_user(uaddr, reg_val, reg_size)) + return -EFAULT; + + return 0; +} + +int kvm_riscv_vcpu_set_reg_vector(struct kvm_vcpu *vcpu, + const struct kvm_one_reg *reg, + unsigned long rtype) +{ + unsigned long *isa = vcpu->arch.isa; + unsigned long __user *uaddr = + (unsigned long __user *)(unsigned long)reg->addr; + unsigned long reg_num = reg->id & ~(KVM_REG_ARCH_MASK | + KVM_REG_SIZE_MASK | + rtype); + void *reg_val = NULL; + size_t reg_size = KVM_REG_SIZE(reg->id); + + if (rtype == KVM_REG_RISCV_VECTOR && + riscv_isa_extension_available(isa, v)) { + reg_val = kvm_riscv_vcpu_vreg_addr(vcpu, reg_num, reg_size); + } + + if (!reg_val) + return -EINVAL; + + if (copy_from_user(reg_val, uaddr, reg_size)) + return -EFAULT; + + return 0; +} From patchwork Thu May 18 16:19:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Chiu X-Patchwork-Id: 13247168 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 1ED5AC7EE2A for ; Thu, 18 May 2023 17:30:53 +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:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=SzOjzXjhLXBoVyGDx3GDNxkEn5zEgrB0U6obuWbpY/c=; b=JTYKIx0uxVwV7xO2xC5MRGuuQ+ fhekKzV3uFgiBaLpABusd540Ud/VpS1W2lXF5WMCpXi/Aeb1u3Lyux1sqx7JAI6Z07U95cUa21UFG 7W5vGhomRdT7FqYBxaxySqZE8R66OBxsjMHfM29zO2vjIIDeRNGXM7VGlVXjlvYFLNXdbTVVFcYsU vbuJ/O5GW/ffFYNz7ba30pMzUsbi17LwR307UPg0RWQJtAzkoji1Wf6y3MGGrIvZ+9q8EVBG012AM /pLB+TuSmbKncFGHFezL8ua20KgIYUkMegQN3AK+oXnDOrRgxlUIrYwW4CG2cON/MFGyBsIyAap81 xHROT7jw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzhSj-00De3Z-02; Thu, 18 May 2023 17:30:49 +0000 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzgOP-00DRlA-2V for linux-riscv@lists.infradead.org; Thu, 18 May 2023 16:22:21 +0000 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-64d247a023aso479484b3a.2 for ; Thu, 18 May 2023 09:22:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1684426937; x=1687018937; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=ncTIQezxeKc2e5vuyalJDNkk7vKyJY85lFnJByk0alw=; b=kdxiy5ubQuYBUhBUsiVfJzzn1mfGp7DL3g9c8BoGvJdtZNuRZvoF2I0mFfFTwQ8cuB QkOoE4IZMls7xAzj5erjd89AQVWAz5V5JghcDc7Vehl3oQgqqj1nvRimCL/IBHbFx3N5 S/Zk0V09/lAyf3y2qMG/5Y8vMBPOUfa1xcibOXEgVgRXg/0O03hB3bBAeMkar+qybiVh RKZL7xkMtmduyl6cR4Soxz/YtPlxsWmg4aWkz+R73EjIesutGJDDJw5lWRvMbOHaq6rQ 5Mi9rLVzRxyi6pPTVezD1sL6s342Ndi5nEIU3poNxYKSncsj9gbSo8vwubDtaHHBT5zs liLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684426937; x=1687018937; 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=ncTIQezxeKc2e5vuyalJDNkk7vKyJY85lFnJByk0alw=; b=dGOjqrgqS+suGY6X/92LuEs0wrHL/+KCCq4RxBO3GTLAt6F6PZfpiCDsu31CPzndix 6cAn19Krd6e8fsGkh2BVEHyn+imyyNUgIcRZOzJCXKry4dOuuH0kr27EZrCFl6umSQ8q Qgqu5dMbgvk2NWUtF5MUjOaXJyFqlRO9dEsz9WMuC25zOldIE227iwl5hwBcIkq0t311 riTgbfgSEHEZaGxsLBEqFEPQygdD6q20NMp+IG/5QWp5rkbc4u7qdSH76hars0Y1eY0W sZNwaNC7aFeKw6zkbWbd5xYqR3ExNH6OhhzJh/Ixt3ysOEH+oSTkexzfkTvfWnjgCig3 cxeQ== X-Gm-Message-State: AC+VfDxKHiSAsQhb8udAgqjeV13sg8sJNA7frYYACLotrNxU7S9PvqJo wwWBNV0N43J5/8aQ3PUYRXNmwO3zBW8bFD9X8ImtTrBZ8a7yde6ykJCg+uqtYndooRGUaErLvRo wfu4e9uSY5O4NYhF40gHhhEp8/4nvmwMjvLPcBvToluGsn4x0A6GFjf8QOR9x63EnclDacZBDNP UcN3JKviZ0/aETik8= X-Google-Smtp-Source: ACHHUZ4TGhqqgD6f5M/yFjzXk6qf/ooHc8yuIkCYiSwA5MT+jm/9oIwXT7hkdUqrzepv0p7PbxrEoQ== X-Received: by 2002:a05:6a20:734e:b0:f0:dedb:83b8 with SMTP id v14-20020a056a20734e00b000f0dedb83b8mr341518pzc.19.1684426936354; Thu, 18 May 2023 09:22:16 -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.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 May 2023 09:22:15 -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 Subject: [PATCH -next v20 20/26] riscv: Add prctl controls for userspace vector management Date: Thu, 18 May 2023 16:19:43 +0000 Message-Id: <20230518161949.11203-21-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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230518_092217_815719_0C16B4BC X-CRM114-Status: GOOD ( 23.58 ) 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: , Cc: Kefeng Wang , guoren@linux.alibaba.com, David Hildenbrand , Peter Zijlstra , Catalin Marinas , "Jason A. Donenfeld" , Joey Gouly , Guo Ren , Jisheng Zhang , greentime.hu@sifive.com, Albert Ou , Stefan Roesch , vineetg@rivosinc.com, Josh Triplett , Paul Walmsley , Heiko Stuebner , Jordy Zomer , Ondrej Mosnacek , Vincent Chen , "Eric W. Biederman" , Andy Chiu , Andrew Morton , Alexey Gladkov MIME-Version: 1.0 Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org This patch add two riscv-specific prctls, to allow usespace control the use of vector unit: * PR_RISCV_V_SET_CONTROL: control the permission to use Vector at next, or all following execve for a thread. Turning off a thread's Vector live is not possible since libraries may have registered ifunc that may execute Vector instructions. * PR_RISCV_V_GET_CONTROL: get the same permission setting for the current thread, and the setting for following execve(s). Signed-off-by: Andy Chiu Reviewed-by: Greentime Hu Reviewed-by: Vincent Chen --- Changelog v20: - address build issue when KVM is compile as a module (Heiko) - s/RISCV_V_DISABLE/RISCV_ISA_V_DEFAULT_ENABLE/ (Conor) - change function names to have better scoping - check has_vector() before accessing vstate_ctrl - use proper return type for prctl calls (long instead of uint) --- arch/riscv/include/asm/processor.h | 13 ++++ arch/riscv/include/asm/vector.h | 4 + arch/riscv/kernel/process.c | 1 + arch/riscv/kernel/vector.c | 118 +++++++++++++++++++++++++++++ arch/riscv/kvm/vcpu.c | 2 + include/uapi/linux/prctl.h | 11 +++ kernel/sys.c | 12 +++ 7 files changed, 161 insertions(+) diff --git a/arch/riscv/include/asm/processor.h b/arch/riscv/include/asm/processor.h index 38ded8c5f207..17829c3003c8 100644 --- a/arch/riscv/include/asm/processor.h +++ b/arch/riscv/include/asm/processor.h @@ -40,6 +40,7 @@ struct thread_struct { unsigned long s[12]; /* s[0]: frame pointer */ struct __riscv_d_ext_state fstate; unsigned long bad_cause; + unsigned long vstate_ctrl; struct __riscv_v_ext_state vstate; }; @@ -83,6 +84,18 @@ extern void riscv_fill_hwcap(void); extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src); extern unsigned long signal_minsigstksz __ro_after_init; + +#ifdef CONFIG_RISCV_ISA_V +/* Userspace interface for PR_RISCV_V_{SET,GET}_VS prctl()s: */ +#define RISCV_V_SET_CONTROL(arg) riscv_v_vstate_ctrl_set_current(arg) +#define RISCV_V_GET_CONTROL() riscv_v_vstate_ctrl_get_current() +extern long riscv_v_vstate_ctrl_set_current(unsigned long arg); +extern long riscv_v_vstate_ctrl_get_current(void); +#else /* !CONFIG_RISCV_ISA_V */ +#define RISCV_V_SET_CONTROL(arg) (-EINVAL) +#define RISCV_V_GET_CONTROL() (-EINVAL) +#endif /* CONFIG_RISCV_ISA_V */ + #endif /* __ASSEMBLY__ */ #endif /* _ASM_RISCV_PROCESSOR_H */ diff --git a/arch/riscv/include/asm/vector.h b/arch/riscv/include/asm/vector.h index 8e56da67b5cf..04c0b07bf6cd 100644 --- a/arch/riscv/include/asm/vector.h +++ b/arch/riscv/include/asm/vector.h @@ -160,6 +160,9 @@ static inline void __switch_to_vector(struct task_struct *prev, riscv_v_vstate_restore(next, task_pt_regs(next)); } +void riscv_v_vstate_ctrl_init(struct task_struct *tsk); +bool riscv_v_vstate_ctrl_user_allowed(void); + #else /* ! CONFIG_RISCV_ISA_V */ struct pt_regs; @@ -168,6 +171,7 @@ static inline int riscv_v_setup_vsize(void) { return -EOPNOTSUPP; } static __always_inline bool has_vector(void) { return false; } static inline bool riscv_v_first_use_handler(struct pt_regs *regs) { return false; } static inline bool riscv_v_vstate_query(struct pt_regs *regs) { return false; } +static inline bool riscv_v_vstate_ctrl_user_allowed(void) { return false; } #define riscv_v_vsize (0) #define riscv_v_vstate_save(task, regs) do {} while (0) #define riscv_v_vstate_restore(task, regs) do {} while (0) diff --git a/arch/riscv/kernel/process.c b/arch/riscv/kernel/process.c index b7a10361ddc6..60278233926c 100644 --- a/arch/riscv/kernel/process.c +++ b/arch/riscv/kernel/process.c @@ -149,6 +149,7 @@ void flush_thread(void) #endif #ifdef CONFIG_RISCV_ISA_V /* Reset vector state */ + riscv_v_vstate_ctrl_init(current); riscv_v_vstate_off(task_pt_regs(current)); kfree(current->thread.vstate.datap); memset(¤t->thread.vstate, 0, sizeof(struct __riscv_v_ext_state)); diff --git a/arch/riscv/kernel/vector.c b/arch/riscv/kernel/vector.c index 0080798e8d2e..9bee7a201106 100644 --- a/arch/riscv/kernel/vector.c +++ b/arch/riscv/kernel/vector.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -19,6 +20,8 @@ #include #include +static bool riscv_v_implicit_uacc = IS_ENABLED(CONFIG_RISCV_ISA_V_DEFAULT_ENABLE); + unsigned long riscv_v_vsize __read_mostly; EXPORT_SYMBOL_GPL(riscv_v_vsize); @@ -91,6 +94,43 @@ static int riscv_v_thread_zalloc(void) return 0; } +#define VSTATE_CTRL_GET_CUR(x) ((x) & PR_RISCV_V_VSTATE_CTRL_CUR_MASK) +#define VSTATE_CTRL_GET_NEXT(x) (((x) & PR_RISCV_V_VSTATE_CTRL_NEXT_MASK) >> 2) +#define VSTATE_CTRL_MAKE_NEXT(x) (((x) << 2) & PR_RISCV_V_VSTATE_CTRL_NEXT_MASK) +#define VSTATE_CTRL_GET_INHERIT(x) (!!((x) & PR_RISCV_V_VSTATE_CTRL_INHERIT)) +static inline int riscv_v_ctrl_get_cur(struct task_struct *tsk) +{ + return VSTATE_CTRL_GET_CUR(tsk->thread.vstate_ctrl); +} + +static inline int riscv_v_ctrl_get_next(struct task_struct *tsk) +{ + return VSTATE_CTRL_GET_NEXT(tsk->thread.vstate_ctrl); +} + +static inline bool riscv_v_ctrl_test_inherit(struct task_struct *tsk) +{ + return VSTATE_CTRL_GET_INHERIT(tsk->thread.vstate_ctrl); +} + +static inline void riscv_v_ctrl_set(struct task_struct *tsk, int cur, int nxt, + bool inherit) +{ + unsigned long ctrl; + + ctrl = cur & PR_RISCV_V_VSTATE_CTRL_CUR_MASK; + ctrl |= VSTATE_CTRL_MAKE_NEXT(nxt); + if (inherit) + ctrl |= PR_RISCV_V_VSTATE_CTRL_INHERIT; + tsk->thread.vstate_ctrl = ctrl; +} + +bool riscv_v_vstate_ctrl_user_allowed(void) +{ + return riscv_v_ctrl_get_cur(current) == PR_RISCV_V_VSTATE_CTRL_ON; +} +EXPORT_SYMBOL_GPL(riscv_v_vstate_ctrl_user_allowed); + bool riscv_v_first_use_handler(struct pt_regs *regs) { u32 __user *epc = (u32 __user *)regs->epc; @@ -100,6 +140,10 @@ bool riscv_v_first_use_handler(struct pt_regs *regs) if (!has_vector() || !(elf_hwcap & COMPAT_HWCAP_ISA_V)) return false; + /* Do not handle the trap if V is not allowed for this process*/ + if (!riscv_v_vstate_ctrl_user_allowed()) + return false; + /* If V has been enabled then it is not the first-use trap */ if (riscv_v_vstate_query(regs)) return false; @@ -129,3 +173,77 @@ bool riscv_v_first_use_handler(struct pt_regs *regs) riscv_v_vstate_on(regs); return true; } + +void riscv_v_vstate_ctrl_init(struct task_struct *tsk) +{ + bool inherit; + int cur, next; + + if (!has_vector()) + return; + + next = riscv_v_ctrl_get_next(tsk); + if (!next) { + if (riscv_v_implicit_uacc) + cur = PR_RISCV_V_VSTATE_CTRL_ON; + else + cur = PR_RISCV_V_VSTATE_CTRL_OFF; + } else { + cur = next; + } + /* Clear next mask if inherit-bit is not set */ + inherit = riscv_v_ctrl_test_inherit(tsk); + if (!inherit) + next = PR_RISCV_V_VSTATE_CTRL_DEFAULT; + + riscv_v_ctrl_set(tsk, cur, next, inherit); +} + +long riscv_v_vstate_ctrl_get_current(void) +{ + if (!has_vector()) + return -EINVAL; + + return current->thread.vstate_ctrl & PR_RISCV_V_VSTATE_CTRL_MASK; +} + +long riscv_v_vstate_ctrl_set_current(unsigned long arg) +{ + bool inherit; + int cur, next; + + if (!has_vector()) + return -EINVAL; + + if (arg & ~PR_RISCV_V_VSTATE_CTRL_MASK) + return -EINVAL; + + cur = VSTATE_CTRL_GET_CUR(arg); + switch (cur) { + case PR_RISCV_V_VSTATE_CTRL_OFF: + /* Do not allow user to turn off V if current is not off */ + if (riscv_v_ctrl_get_cur(current) != PR_RISCV_V_VSTATE_CTRL_OFF) + return -EPERM; + + break; + case PR_RISCV_V_VSTATE_CTRL_ON: + break; + case PR_RISCV_V_VSTATE_CTRL_DEFAULT: + cur = riscv_v_ctrl_get_cur(current); + break; + default: + return -EINVAL; + } + + next = VSTATE_CTRL_GET_NEXT(arg); + inherit = VSTATE_CTRL_GET_INHERIT(arg); + switch (next) { + case PR_RISCV_V_VSTATE_CTRL_DEFAULT: + case PR_RISCV_V_VSTATE_CTRL_OFF: + case PR_RISCV_V_VSTATE_CTRL_ON: + riscv_v_ctrl_set(current, cur, next, inherit); + return 0; + } + + return -EINVAL; +} diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c index e5e045852e6a..de24127e7e93 100644 --- a/arch/riscv/kvm/vcpu.c +++ b/arch/riscv/kvm/vcpu.c @@ -88,6 +88,8 @@ static bool kvm_riscv_vcpu_isa_enable_allowed(unsigned long ext) switch (ext) { case KVM_RISCV_ISA_EXT_H: return false; + case KVM_RISCV_ISA_EXT_V: + return riscv_v_vstate_ctrl_user_allowed(); default: break; } diff --git a/include/uapi/linux/prctl.h b/include/uapi/linux/prctl.h index f23d9a16507f..3c36aeade991 100644 --- a/include/uapi/linux/prctl.h +++ b/include/uapi/linux/prctl.h @@ -294,4 +294,15 @@ struct prctl_mm_map { #define PR_SET_MEMORY_MERGE 67 #define PR_GET_MEMORY_MERGE 68 + +#define PR_RISCV_V_SET_CONTROL 69 +#define PR_RISCV_V_GET_CONTROL 70 +# define PR_RISCV_V_VSTATE_CTRL_DEFAULT 0 +# define PR_RISCV_V_VSTATE_CTRL_OFF 1 +# define PR_RISCV_V_VSTATE_CTRL_ON 2 +# define PR_RISCV_V_VSTATE_CTRL_INHERIT (1 << 4) +# define PR_RISCV_V_VSTATE_CTRL_CUR_MASK 0x3 +# define PR_RISCV_V_VSTATE_CTRL_NEXT_MASK 0xc +# define PR_RISCV_V_VSTATE_CTRL_MASK 0x1f + #endif /* _LINUX_PRCTL_H */ diff --git a/kernel/sys.c b/kernel/sys.c index 339fee3eff6a..d0d3106698a1 100644 --- a/kernel/sys.c +++ b/kernel/sys.c @@ -140,6 +140,12 @@ #ifndef GET_TAGGED_ADDR_CTRL # define GET_TAGGED_ADDR_CTRL() (-EINVAL) #endif +#ifndef PR_RISCV_V_SET_CONTROL +# define RISCV_V_SET_CONTROL(a) (-EINVAL) +#endif +#ifndef PR_RISCV_V_GET_CONTROL +# define RISCV_V_GET_CONTROL() (-EINVAL) +#endif /* * this is where the system-wide overflow UID and GID are defined, for @@ -2708,6 +2714,12 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3, error = !!test_bit(MMF_VM_MERGE_ANY, &me->mm->flags); break; #endif + case PR_RISCV_V_SET_CONTROL: + error = RISCV_V_SET_CONTROL(arg2); + break; + case PR_RISCV_V_GET_CONTROL: + error = RISCV_V_GET_CONTROL(); + break; default: error = -EINVAL; break; 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); From patchwork Thu May 18 16:19:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Chiu X-Patchwork-Id: 13247170 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 7ADD8C77B7D for ; Thu, 18 May 2023 17:30:55 +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=1GPLtW/TuHg6KoOshQ6ax3kZwDybZyRr1BYPdqVgRwY=; b=JWyB9oZGTa18LO ZsvumXVg3ZrR4YLvYgv18TsVjgp8LqKq4mLBM6ozQnO7rMTG8xPhe0pkYN2N2HfXuobBJQ8iuA1hc /PMEnNdjkdLW3S/Bsbt6wImJQBal01VpC0K5QrOpTuMU737xo2hF3k0Q5QzdWpy+4qSpS6hiL30MO tYPJVolMihJKT/a2XxThIIgs5NGQK00EvECSMU4iymrX/xqy4vddWiXg8j/y+WggphyzCqMH6eb3G xSRPD29N1IaHQhVPZXHDh57lTuCi/JKvqGEZC7GmtY9fSaicFMB+Hc/Ohh7eg1naD/Fe9PJBkwlOF eWqIlsSm4IpGjOauKFUQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzhSk-00De4x-0d; Thu, 18 May 2023 17:30:50 +0000 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzgOX-00DRoB-1P for linux-riscv@lists.infradead.org; Thu, 18 May 2023 16:22:26 +0000 Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-64d2c865e4eso117524b3a.0 for ; Thu, 18 May 2023 09:22:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1684426944; x=1687018944; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=otAeXCQ9wHQgYb9XVLjxDELtJAEuURMD8rtVKOhLCTY=; b=D/9sOFm0nUPg7worQhPCe8AEkybdsphU5jCDpgLdO9TLPPtzwMLnHN4CNVbP429e3D eULZY3lyqSOBA1qyH0PHY7QdZLNl777TdCjPBf1rE74ioqjMdTXrdFsVY8DvG+GbMSOD Md4+ngoAXRWb9Qg3zYkRZa7wl7u+CQYE9+Df8UAb09fw6XXjdBAqgFHk2VNMiWrDCgEE byFdEbpAzIt1KIR2OsmKXQRjz/sTGjLSoWvBSh+x0JH8Ag3df79t2YgbZdahgQMMoKlS GtiUQBhjGH9oPM/6XGYQ8dkfVFRqub3su28Hq5uY8n/6k2vchxT1eCdiAdkgwCUZjeab Tylw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684426944; x=1687018944; 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=otAeXCQ9wHQgYb9XVLjxDELtJAEuURMD8rtVKOhLCTY=; b=Jq88GikXVcUlHLnunybG5ku5v5dYdDqv6N6c4Vph8BZnQGwW91L5HuQbbK54M8SbGD Z+dJJfIw/V5PPxSQ3+1DTOML3LClASHInwwasSHLtHyGeZ9Wsx6lNvm5iMQ5JZcYGKDI 7CnKoYuyyCDNtorwA8aGtTazYCEvMeCVbOD4mwXYXLAcQTfOLVGx4K7SeSO8jo8lk9l6 4upbtlcvSjEZYe3s2ISksp+LqSZoT4ic2eDQCH2vVWVXK2Yqf9X1FGUWrcm3999ZEdbv u9JQB4sR7TAFTcKapy98ZQk0JP3gEIkM3o8OUe0byS2GStd4OqD0OREd9GtjKYLLq4Hc FKnQ== X-Gm-Message-State: AC+VfDwn4E/cCYv9eb0RG5vEhvgmJCYuKiIMEZJc4p2evRj6NNcxBOjb IoJ0340yWGHVZr3hj8gcoONoqzWNNytEPxFXrRJ7KigxNH71EEH9gytE2DwvVVIDNLmlwr20KaK il+0cyACddbCSIo9z/YqHYPunRG0338A3vB3QuqUCCKyMPTYt5dWJz8FN/l0qmOO6U48+PwWGZL a7FX19LmR1wu8IGS8= X-Google-Smtp-Source: ACHHUZ7Wb2l5IYTrIfdDslfKAs+d+oKUxRkxvubNrCroZUnDUOrovMWjksdkc3+3iJAItG2BSv0b0Q== X-Received: by 2002:a05:6a00:1acd:b0:63b:6149:7ad6 with SMTP id f13-20020a056a001acd00b0063b61497ad6mr4711081pfv.34.1684426944416; Thu, 18 May 2023 09:22:24 -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.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 May 2023 09:22:23 -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 , Nathan Chancellor , Nick Desaulniers , Tom Rix Subject: [PATCH -next v20 22/26] riscv: detect assembler support for .option arch Date: Thu, 18 May 2023 16:19:45 +0000 Message-Id: <20230518161949.11203-23-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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230518_092225_474881_5E80A8A1 X-CRM114-Status: GOOD ( 10.61 ) 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 Some extensions use .option arch directive to selectively enable certain extensions in parts of its assembly code. For example, Zbb uses it to inform assmebler to emit bit manipulation instructions. However, supporting of this directive only exist on GNU assembler and has not landed on clang at the moment, making TOOLCHAIN_HAS_ZBB depend on AS_IS_GNU. While it is still under review at https://reviews.llvm.org/D123515, the upcoming Vector patch also requires this feature in assembler. Thus, provide Kconfig AS_HAS_OPTION_ARCH to detect such feature. Then TOOLCHAIN_HAS_XXX will be turned on automatically when the feature land. Suggested-by: Nathan Chancellor Signed-off-by: Andy Chiu Reviewed-by: Conor Dooley Reviewed-by: Nathan Chancellor Reviewed-by: Heiko Stuebner Tested-by: Heiko Stuebner --- arch/riscv/Kconfig | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 348c0fa1fc8c..1019b519d590 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -262,6 +262,12 @@ config RISCV_DMA_NONCOHERENT config AS_HAS_INSN def_bool $(as-instr,.insn r 51$(comma) 0$(comma) 0$(comma) t0$(comma) t0$(comma) zero) +config AS_HAS_OPTION_ARCH + # https://reviews.llvm.org/D123515 + def_bool y + depends on $(as-instr, .option arch$(comma) +m) + depends on !$(as-instr, .option arch$(comma) -i) + source "arch/riscv/Kconfig.socs" source "arch/riscv/Kconfig.errata" @@ -466,7 +472,7 @@ config TOOLCHAIN_HAS_ZBB depends on !64BIT || $(cc-option,-mabi=lp64 -march=rv64ima_zbb) depends on !32BIT || $(cc-option,-mabi=ilp32 -march=rv32ima_zbb) depends on LLD_VERSION >= 150000 || LD_VERSION >= 23900 - depends on AS_IS_GNU + depends on AS_HAS_OPTION_ARCH config RISCV_ISA_ZBB bool "Zbb extension support for bit manipulation instructions" From patchwork Thu May 18 16:19:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Chiu X-Patchwork-Id: 13247096 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 35969C7EE23 for ; Thu, 18 May 2023 16:40:32 +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=V3c6zG/eX8JLfkQzS/VvavecQgutzVG8EiKL6F1m65g=; b=nBX+u+DrB+rcTO xxyFvWwPg4nX6mwmAhKzBnpZWkSEU67Q+UMhB5SehGDjFizG+icijHrp2nIW993RlrL8JJYOQ3DGX 7DmQYOiR4OBCkP5e6TBUJk3mlV7M/cVmkvXUnsc6BI1+VdFpSTK9pQVA8XndokhYy8dfPQ6tdsgGp pgr3vDsUA+yC9Z11xwwrT6zvvyY5wHblH7lbujkyA4D0HrHoKLEEb1t5ML+RbzdOL0fWUExJEwBR1 uKgthQ8cIlW5UwT4cVemZt3WV2e4YJcB/TV6CxgGEJBnzvqUJuimYpQQOUY5h2Kyn4E5EZPdAgldg tTW3JFQS4BMyvxCR5mWg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzgg0-00DUxO-0T; Thu, 18 May 2023 16:40:28 +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 1pzgfz-00DUvv-0Y for linux-riscv@bombadil.infradead.org; Thu, 18 May 2023 16:40:27 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=References:In-Reply-To:Message-Id:Date :Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description; bh=b1b0xsw8eifEcqL65SiaBPERh4ugWqVSP6XmDavWWMY=; b=Wb8v0r4pncMDboqQ1+8qOz2E5/ 9Ln55R37FPdOxIx0CTXrNugUcKUbJxF1p6+MmloCpy62oHZTN/57bIy/wNn5g8sahN0GhIAlmoWyU 8VnsL9E5/sILIdjUh5mpC6m2A8/ICJBznje7UF+QiSrnsMfadj04iXT1ogFck7PxARuv0fhMC4sjb M+RFv/aXX3cquO4iYtxLUf73uRjPy1ijQTpTD3bXpBqk+6mK6+t+pm+Luz3kOBeQA5AgDsdqCe2bJ bWHfKxEi+NpKjIZ5JyZ19dwjYY3zQBuJfMtbbLEWo15IIKSsxELfXv5rMDBixkZqQmlx1pgrSYAsi cNqkq1jw==; Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzgOb-00ErRN-2J for linux-riscv@lists.infradead.org; Thu, 18 May 2023 16:22:31 +0000 Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-64d2467d63fso470348b3a.0 for ; Thu, 18 May 2023 09:22:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1684426947; x=1687018947; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=b1b0xsw8eifEcqL65SiaBPERh4ugWqVSP6XmDavWWMY=; b=Bu4ilTdIWMMLwOpy8XcilklIFvmsG1OLuzriOCTkzbwfTbqiNCEtaBOhxbztiyfwBt CjgHcX+6xdognvyr8lvQr2KMYLXtUuXQITKj2rzHK1dNcc8lzlqwzC5RRbA7HHfDX3eT Kre9Fg0TQW7jwPTdwt5kOtnYMCa8JQpx8J5ZfIMuWgpmuMAwh8BOrpYliGHVT4ZIkWze JB3W3ALQUJLceu6qiy/n1YkCe538v+FxM87UuRBPcmm/gbmpK9w9wiDu4+yP0GDLqTZ1 b2zmmu3IiCEJiJ1dN71Og53pP9cypGH7kXje3Jx3lyeU4NYBucj7SKB367wODjVB9d2Y vqEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684426947; x=1687018947; 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=b1b0xsw8eifEcqL65SiaBPERh4ugWqVSP6XmDavWWMY=; b=aKlzJlaeydO+deIq2eSEvToTNBQvqWWmaEX0/UmEHigoQQHDvQujVSyHxrz5fgaTCj z+Q3rqfR81V7UPoNQRZpQDFQD9Untu31rhpvQRFOjrwCyd1PoiR7C+zWx2w+7/93aWo6 el6tCtBg8EJ7cLaz4xBbpAhD5Q/DEe+8velps/tZkOezbynKufbbbCbdDYnRD4oxG2qi bR01DkwipAWgF0M75d9L0Hnrrw8z0ZV2tMMbN6it3elH1DLu6dfvjIG5f94vUsEJjStv wA8X1WxzwavpcSbVPpsWKFbe92lHlhke0GJxNu9gKTHj0uF16j19i+yF51mwxRB+S7jV 4djg== X-Gm-Message-State: AC+VfDy6HDIlJT3Q+irzeg1hsNG2jhVYLAFPIC0D8+7sDnLcbzP+0TO1 J5GNPF6G9Ii1xoIRTQxZRh3XeLRU+Bz/hPJb+lkmyB25VnA1xY6uglkATSVeIm9VM/fHX4TI8ri LeEXpQ3skQV0BCROnKSf4fkKaSl0O4q0iqYc4js/Vz7NUOqjg/4F3yismEUNKMwgvIoi5wxNoso ztRTOCpxpLm0ZSLQc= X-Google-Smtp-Source: ACHHUZ5GRXU6Qwibs9ZDmbkxXzE0v0HGP/aPJjeuRkEgLEfzKhZeZnfeHFwA+sFaC/31wIIPeoVRnw== X-Received: by 2002:aa7:888b:0:b0:64d:fd0:dd1a with SMTP id z11-20020aa7888b000000b0064d0fd0dd1amr5499091pfe.16.1684426947363; Thu, 18 May 2023 09:22:27 -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.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 May 2023 09:22:26 -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 Subject: [PATCH -next v20 23/26] riscv: Enable Vector code to be built Date: Thu, 18 May 2023 16:19:46 +0000 Message-Id: <20230518161949.11203-24-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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230518_172229_853457_D53C48D6 X-CRM114-Status: GOOD ( 11.58 ) 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 From: Guo Ren This patch adds configs for building Vector code. First it detects the reqired toolchain support for building the code. Then it provides an option setting whether Vector is implicitly enabled to userspace. Signed-off-by: Guo Ren Co-developed-by: Greentime Hu Signed-off-by: Greentime Hu Suggested-by: Conor Dooley > Co-developed-by: Andy Chiu Signed-off-by: Andy Chiu Reviewed-by: Conor Dooley --- Changelog v20: - s/RISCV_V_DISABLE/RISCV_ISA_V_DEFAULT_ENABLE/ for better understanding (Conor) - Update commit message (Conor) Changelog V19: - Add RISCV_V_DISABLE to set compile-time default. --- arch/riscv/Kconfig | 31 +++++++++++++++++++++++++++++++ arch/riscv/Makefile | 6 +++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 1019b519d590..f3ba0a8b085e 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -466,6 +466,37 @@ config RISCV_ISA_SVPBMT If you don't know what to do here, say Y. +config TOOLCHAIN_HAS_V + bool + default y + depends on !64BIT || $(cc-option,-mabi=lp64 -march=rv64iv) + depends on !32BIT || $(cc-option,-mabi=ilp32 -march=rv32iv) + depends on LLD_VERSION >= 140000 || LD_VERSION >= 23800 + depends on AS_HAS_OPTION_ARCH + +config RISCV_ISA_V + bool "VECTOR extension support" + depends on TOOLCHAIN_HAS_V + depends on FPU + select DYNAMIC_SIGFRAME + default y + help + Say N here if you want to disable all vector related procedure + in the kernel. + + If you don't know what to do here, say Y. + +config RISCV_ISA_V_DEFAULT_ENABLE + bool "Enable userspace Vector by default" + depends on RISCV_ISA_V + default y + help + Say Y here if you want to enable Vector in userspace by default. + Otherwise, userspace has to make explicit prctl() call to enable + Vector, or enable it via the sysctl interface. + + If you don't know what to do here, say Y. + config TOOLCHAIN_HAS_ZBB bool default y diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile index 0fb256bf8270..6ec6d52a4180 100644 --- a/arch/riscv/Makefile +++ b/arch/riscv/Makefile @@ -60,6 +60,7 @@ riscv-march-$(CONFIG_ARCH_RV32I) := rv32ima riscv-march-$(CONFIG_ARCH_RV64I) := rv64ima riscv-march-$(CONFIG_FPU) := $(riscv-march-y)fd riscv-march-$(CONFIG_RISCV_ISA_C) := $(riscv-march-y)c +riscv-march-$(CONFIG_RISCV_ISA_V) := $(riscv-march-y)v ifdef CONFIG_TOOLCHAIN_NEEDS_OLD_ISA_SPEC KBUILD_CFLAGS += -Wa,-misa-spec=2.2 @@ -71,7 +72,10 @@ endif # Check if the toolchain supports Zihintpause extension riscv-march-$(CONFIG_TOOLCHAIN_HAS_ZIHINTPAUSE) := $(riscv-march-y)_zihintpause -KBUILD_CFLAGS += -march=$(subst fd,,$(riscv-march-y)) +# Remove F,D,V from isa string for all. Keep extensions between "fd" and "v" by +# matching non-v and non-multi-letter extensions out with the filter ([^v_]*) +KBUILD_CFLAGS += -march=$(shell echo $(riscv-march-y) | sed -E 's/(rv32ima|rv64ima)fd([^v_]*)v?/\1\2/') + KBUILD_AFLAGS += -march=$(riscv-march-y) KBUILD_CFLAGS += -mno-save-restore 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. From patchwork Thu May 18 16:19:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Chiu X-Patchwork-Id: 13247089 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 45FC0C7EE25 for ; Thu, 18 May 2023 16:22:55 +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=B+MqIVrQzp4vmaH4a5qCewSMT4ZyoVGiZnARf/2Z8d8=; b=1CcdKU1cBbtgRr LL57hJk2Lb+xsmBMaBgbYeUAzVSpjgyYS5W/5rBwk4x1lNm5aHjvy3h8WDaldBrSfHZw0yNA7G+K3 z6YGTbyxIOkGwcn7g77hVOzLUGo/I6oml4BP6mG8lwC5uXIGzaZhvDSywUWIpBVTH0IoH9NmqwNlu jffKnbvYiej5XuOiyELQSqGuUkuG98hAjdf4aGHyBBMVznwLMIYkKvkX5yvLhl6934TmqHPdWaXJk VjKH1qcRm77bKDHr4UmM3R1qqYw1e63NPb0neHb3CorHSfj+ma6Uu4xTo1uxq0/5J1QEmWpTpZ7xl QnVy0+y5mGVDjGfHm2vQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzgOx-00DRxD-0G; Thu, 18 May 2023 16:22:51 +0000 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzgOt-00DRvn-3D for linux-riscv@lists.infradead.org; Thu, 18 May 2023 16:22:49 +0000 Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-64d2ca9ef0cso107649b3a.1 for ; Thu, 18 May 2023 09:22:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1684426967; x=1687018967; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=DUVXHBR1wkNxT0wOTAVxttFccgUOF7kcLoBjUYXBqWs=; b=RmsyqDtixA9d40WGB2+ewkRJXbAbmcHiHrmnFjYIMoX+1KRp80VKc0jE5HvbCUSlNW 9lTkR+2iciWcmwwNHsatLkcSL5hNX/EkOHX8ZGg1KnizuOkrYwY5JUj8N3RTl+vthVx5 tWsBWx+fEqnRkswV4Wc32lwdc3rvsZpqeBkUZrQOI6Fdye6keuC7GoLZXgpGxsvJOxnN XHNqvkwRGAoZRPGIQo6mskRfyvn9uQ4zOUubbEO+9RMUn2vQTVvxJOor7YRpaYdiugKg iiCmL6prpazWZr8FEGNblwtWY8Fsk3aMb2zhpqrwagoLnCK6FIQZcMJ7w2+3y5kGrks2 SZ2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684426967; x=1687018967; 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=DUVXHBR1wkNxT0wOTAVxttFccgUOF7kcLoBjUYXBqWs=; b=UCSOXnwmxqJCkSaFv0zT/0bRoFFy9A2xzlilThirtCZtsVroWXH6PcstHe76obhlME PS+OdhvnvvB8zH1S56+QU/IoY84AOVk4TDTvkUB0a8dpSY98DZ1jJJDqVTorVNixRUsy NIIRsVM7ROGo9d8S72BUyzWu/bg8jA2o1GJmssfpeNafO4TH4H7Mj0hvpOZw2jo3sZrU bLaljZVpNberqopE/hb3M7z0iyRNcqaadw+6SPz5axFKrOkAAq/losj/m+c1kFzr67R8 HXxJof4I5ygI2mIenloLUrXgAKeUJRVMursmWX1vaQrFTPUuS67tV7Mh6pR+TCifVqFQ xFpw== X-Gm-Message-State: AC+VfDySh77iS2fFAw8yjfOVIRX909wZeduTPZ4eCyirzpG4KOjXblhl InnefLJexmY89KpXikjl7BUGXi+bzGUCZ8phx29mWWD4dIPgfy8jMOa5nlrLk3pEG7jagkvhcjN gDiUxO1mZahmSBA0cJ3gDlIyfNyiYVOU/GoXKZvpXgiwiSI454CJvFSckEtqip9vIYX+ZxfwSQ/ oahL+1Eq6aDhpNzjQ= X-Google-Smtp-Source: ACHHUZ6vyYtlBdSkdSHYeVzI3iXRymDGrAOwy7m6x8IxaET2P8QNIPLM/BTxFuOyugdPDEK2hFApwQ== X-Received: by 2002:a05:6a00:2ea4:b0:64a:f8c9:a421 with SMTP id fd36-20020a056a002ea400b0064af8c9a421mr5461304pfb.32.1684426966909; Thu, 18 May 2023 09:22:46 -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.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 May 2023 09:22:46 -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 , Shuah Khan , Paul Walmsley , Albert Ou , Evan Green Subject: [PATCH -next v20 25/26] selftests: Test RISC-V Vector prctl interface Date: Thu, 18 May 2023 16:19:48 +0000 Message-Id: <20230518161949.11203-26-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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230518_092248_035089_5FE05189 X-CRM114-Status: GOOD ( 23.97 ) 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 This add a test for prctl interface that controls the use of userspace Vector. Signed-off-by: Andy Chiu --- tools/testing/selftests/riscv/Makefile | 2 +- .../testing/selftests/riscv/vector/.gitignore | 2 + tools/testing/selftests/riscv/vector/Makefile | 15 ++ .../riscv/vector/vstate_exec_nolibc.c | 111 ++++++++++ .../selftests/riscv/vector/vstate_prctl.c | 189 ++++++++++++++++++ 5 files changed, 318 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/riscv/vector/.gitignore create mode 100644 tools/testing/selftests/riscv/vector/Makefile create mode 100644 tools/testing/selftests/riscv/vector/vstate_exec_nolibc.c create mode 100644 tools/testing/selftests/riscv/vector/vstate_prctl.c diff --git a/tools/testing/selftests/riscv/Makefile b/tools/testing/selftests/riscv/Makefile index 32a72902d045..9dd629cc86aa 100644 --- a/tools/testing/selftests/riscv/Makefile +++ b/tools/testing/selftests/riscv/Makefile @@ -5,7 +5,7 @@ ARCH ?= $(shell uname -m 2>/dev/null || echo not) ifneq (,$(filter $(ARCH),riscv)) -RISCV_SUBTARGETS ?= hwprobe +RISCV_SUBTARGETS ?= hwprobe vector else RISCV_SUBTARGETS := endif diff --git a/tools/testing/selftests/riscv/vector/.gitignore b/tools/testing/selftests/riscv/vector/.gitignore new file mode 100644 index 000000000000..4f2b4e8a3b08 --- /dev/null +++ b/tools/testing/selftests/riscv/vector/.gitignore @@ -0,0 +1,2 @@ +vstate_exec_nolibc +vstate_prctl diff --git a/tools/testing/selftests/riscv/vector/Makefile b/tools/testing/selftests/riscv/vector/Makefile new file mode 100644 index 000000000000..cd6e80bf995d --- /dev/null +++ b/tools/testing/selftests/riscv/vector/Makefile @@ -0,0 +1,15 @@ +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2021 ARM Limited +# Originally tools/testing/arm64/abi/Makefile + +TEST_GEN_PROGS := vstate_prctl +TEST_GEN_PROGS_EXTENDED := vstate_exec_nolibc + +include ../../lib.mk + +$(OUTPUT)/vstate_prctl: vstate_prctl.c ../hwprobe/sys_hwprobe.S + $(CC) -static -o$@ $(CFLAGS) $(LDFLAGS) $^ + +$(OUTPUT)/vstate_exec_nolibc: vstate_exec_nolibc.c + $(CC) -nostdlib -static -include ../../../../include/nolibc/nolibc.h \ + -Wall $(CFLAGS) $(LDFLAGS) $^ -o $@ -lgcc diff --git a/tools/testing/selftests/riscv/vector/vstate_exec_nolibc.c b/tools/testing/selftests/riscv/vector/vstate_exec_nolibc.c new file mode 100644 index 000000000000..5cbc392944a6 --- /dev/null +++ b/tools/testing/selftests/riscv/vector/vstate_exec_nolibc.c @@ -0,0 +1,111 @@ +// SPDX-License-Identifier: GPL-2.0-only +#include + +#define THIS_PROGRAM "./vstate_exec_nolibc" + +int main(int argc, char **argv) +{ + int rc, pid, status, test_inherit = 0; + long ctrl, ctrl_c; + char *exec_argv[2], *exec_envp[2]; + + if (argc > 1) + test_inherit = 1; + + ctrl = my_syscall1(__NR_prctl, PR_RISCV_V_GET_CONTROL); + if (ctrl < 0) { + puts("PR_RISCV_V_GET_CONTROL is not supported\n"); + return ctrl; + } + + if (test_inherit) { + pid = fork(); + if (pid == -1) { + puts("fork failed\n"); + exit(-1); + } + + /* child */ + if (!pid) { + exec_argv[0] = THIS_PROGRAM; + exec_argv[1] = NULL; + exec_envp[0] = NULL; + exec_envp[1] = NULL; + /* launch the program again to check inherit */ + rc = execve(THIS_PROGRAM, exec_argv, exec_envp); + if (rc) { + puts("child execve failed\n"); + exit(-1); + } + } + + } else { + pid = fork(); + if (pid == -1) { + puts("fork failed\n"); + exit(-1); + } + + if (!pid) { + rc = my_syscall1(__NR_prctl, PR_RISCV_V_GET_CONTROL); + if (rc != ctrl) { + puts("child's vstate_ctrl not equal to parent's\n"); + exit(-1); + } + asm volatile (".option push\n\t" + ".option arch, +v\n\t" + "vsetvli x0, x0, e32, m8, ta, ma\n\t" + ".option pop\n\t" + ); + exit(ctrl); + } + } + + rc = waitpid(-1, &status, 0); + + if (WIFEXITED(status) && WEXITSTATUS(status) == -1) { + puts("child exited abnormally\n"); + exit(-1); + } + + if (WIFSIGNALED(status)) { + if (WTERMSIG(status) != SIGILL) { + puts("child was terminated by unexpected signal\n"); + exit(-1); + } + + if ((ctrl & PR_RISCV_V_VSTATE_CTRL_CUR_MASK) != PR_RISCV_V_VSTATE_CTRL_OFF) { + puts("child signaled by illegal V access but vstate_ctrl is not off\n"); + exit(-1); + } + + /* child terminated, and its vstate_ctrl is off */ + exit(ctrl); + } + + ctrl_c = WEXITSTATUS(status); + if (test_inherit) { + if (ctrl & PR_RISCV_V_VSTATE_CTRL_INHERIT) { + if (!(ctrl_c & PR_RISCV_V_VSTATE_CTRL_INHERIT)) { + puts("parent has inherit bit, but child has not\n"); + exit(-1); + } + } + rc = (ctrl & PR_RISCV_V_VSTATE_CTRL_NEXT_MASK) >> 2; + if (rc != PR_RISCV_V_VSTATE_CTRL_DEFAULT) { + if (rc != (ctrl_c & PR_RISCV_V_VSTATE_CTRL_CUR_MASK)) { + puts("parent's next setting does not equal to child's\n"); + exit(-1); + } + + if (!(ctrl & PR_RISCV_V_VSTATE_CTRL_INHERIT)) { + if ((ctrl_c & PR_RISCV_V_VSTATE_CTRL_NEXT_MASK) != + PR_RISCV_V_VSTATE_CTRL_DEFAULT) { + puts("must clear child's next vstate_ctrl if !inherit\n"); + exit(-1); + } + } + } + } + return ctrl; +} diff --git a/tools/testing/selftests/riscv/vector/vstate_prctl.c b/tools/testing/selftests/riscv/vector/vstate_prctl.c new file mode 100644 index 000000000000..b348b475be57 --- /dev/null +++ b/tools/testing/selftests/riscv/vector/vstate_prctl.c @@ -0,0 +1,189 @@ +// SPDX-License-Identifier: GPL-2.0-only +#include +#include +#include +#include +#include + +#include "../../kselftest.h" + +/* + * Rather than relying on having a new enough libc to define this, just do it + * ourselves. This way we don't need to be coupled to a new-enough libc to + * contain the call. + */ +long riscv_hwprobe(struct riscv_hwprobe *pairs, size_t pair_count, + size_t cpu_count, unsigned long *cpus, unsigned int flags); + +#define NEXT_PROGRAM "./vstate_exec_nolibc" +static int launch_test(int test_inherit) +{ + char *exec_argv[3], *exec_envp[1]; + int rc, pid, status; + + pid = fork(); + if (pid < 0) { + ksft_test_result_fail("fork failed %d", pid); + return -1; + } + + if (!pid) { + exec_argv[0] = NEXT_PROGRAM; + exec_argv[1] = test_inherit != 0 ? "x" : NULL; + exec_argv[2] = NULL; + exec_envp[0] = NULL; + /* launch the program again to check inherit */ + rc = execve(NEXT_PROGRAM, exec_argv, exec_envp); + if (rc) { + perror("execve"); + ksft_test_result_fail("child execve failed %d\n", rc); + exit(-1); + } + } + + rc = waitpid(-1, &status, 0); + if (rc < 0) { + ksft_test_result_fail("waitpid failed\n"); + return -3; + } + + if ((WIFEXITED(status) && WEXITSTATUS(status) == -1) || + WIFSIGNALED(status)) { + ksft_test_result_fail("child exited abnormally\n"); + return -4; + } + + return WEXITSTATUS(status); +} + +int test_and_compare_child(long provided, long expected, int inherit) +{ + int rc; + + rc = prctl(PR_RISCV_V_SET_CONTROL, provided); + if (rc != 0) { + ksft_test_result_fail("prctl with provided arg %lx failed with code %d\n", + provided, rc); + return -1; + } + rc = launch_test(inherit); + if (rc != expected) { + ksft_test_result_fail("Test failed, check %d != %d\n", rc, + expected); + return -2; + } + return 0; +} + +#define PR_RISCV_V_VSTATE_CTRL_CUR_SHIFT 0 +#define PR_RISCV_V_VSTATE_CTRL_NEXT_SHIFT 2 + +int main(void) +{ + struct riscv_hwprobe pair; + long flag, expected; + long rc; + + pair.key = RISCV_HWPROBE_KEY_IMA_EXT_0; + rc = riscv_hwprobe(&pair, 1, 0, NULL, 0); + if (rc < 0) { + ksft_test_result_fail("hwprobe() failed with %d\n", rc); + return -1; + } + + if (pair.key != RISCV_HWPROBE_KEY_IMA_EXT_0) { + ksft_test_result_fail("hwprobe cannot probe RISCV_HWPROBE_KEY_IMA_EXT_0\n"); + return -2; + } + + if (!(pair.value & RISCV_HWPROBE_IMA_V)) { + rc = prctl(PR_RISCV_V_GET_CONTROL); + if (rc != -1 || errno != EINVAL) { + ksft_test_result_fail("GET_CONTROL should fail on kernel/hw without V\n"); + return -3; + } + + rc = prctl(PR_RISCV_V_SET_CONTROL, PR_RISCV_V_VSTATE_CTRL_ON); + if (rc != -1 || errno != EINVAL) { + ksft_test_result_fail("GET_CONTROL should fail on kernel/hw without V\n"); + return -4; + } + + ksft_test_result_skip("Vector not supported\n"); + return 0; + } + + flag = PR_RISCV_V_VSTATE_CTRL_ON; + rc = prctl(PR_RISCV_V_SET_CONTROL, flag); + if (rc != 0) { + ksft_test_result_fail("Enabling V for current should always success\n"); + return -5; + } + + flag = PR_RISCV_V_VSTATE_CTRL_OFF; + rc = prctl(PR_RISCV_V_SET_CONTROL, flag); + if (rc != -1 || errno != EPERM) { + ksft_test_result_fail("Disabling current's V alive must fail with EPERM(%d)\n", + errno); + return -5; + } + + /* Turn on next's vector explicitly and test */ + flag = PR_RISCV_V_VSTATE_CTRL_ON << PR_RISCV_V_VSTATE_CTRL_NEXT_SHIFT; + if (test_and_compare_child(flag, PR_RISCV_V_VSTATE_CTRL_ON, 0)) + return -6; + + /* Turn off next's vector explicitly and test */ + flag = PR_RISCV_V_VSTATE_CTRL_OFF << PR_RISCV_V_VSTATE_CTRL_NEXT_SHIFT; + if (test_and_compare_child(flag, PR_RISCV_V_VSTATE_CTRL_OFF, 0)) + return -7; + + /* Turn on next's vector explicitly and test inherit */ + flag = PR_RISCV_V_VSTATE_CTRL_ON << PR_RISCV_V_VSTATE_CTRL_NEXT_SHIFT; + flag |= PR_RISCV_V_VSTATE_CTRL_INHERIT; + expected = flag | PR_RISCV_V_VSTATE_CTRL_ON; + if (test_and_compare_child(flag, expected, 0)) + return -8; + + if (test_and_compare_child(flag, expected, 1)) + return -9; + + /* Turn off next's vector explicitly and test inherit */ + flag = PR_RISCV_V_VSTATE_CTRL_OFF << PR_RISCV_V_VSTATE_CTRL_NEXT_SHIFT; + flag |= PR_RISCV_V_VSTATE_CTRL_INHERIT; + expected = flag | PR_RISCV_V_VSTATE_CTRL_OFF; + if (test_and_compare_child(flag, expected, 0)) + return -10; + + if (test_and_compare_child(flag, expected, 1)) + return -11; + + /* arguments should fail with EINVAL */ + rc = prctl(PR_RISCV_V_SET_CONTROL, 0xff0); + if (rc != -1 || errno != EINVAL) { + ksft_test_result_fail("Undefined control argument should return EINVAL\n"); + return -12; + } + + rc = prctl(PR_RISCV_V_SET_CONTROL, 0x3); + if (rc != -1 || errno != EINVAL) { + ksft_test_result_fail("Undefined control argument should return EINVAL\n"); + return -12; + } + + rc = prctl(PR_RISCV_V_SET_CONTROL, 0xc); + if (rc != -1 || errno != EINVAL) { + ksft_test_result_fail("Undefined control argument should return EINVAL\n"); + return -12; + } + + rc = prctl(PR_RISCV_V_SET_CONTROL, 0xc); + if (rc != -1 || errno != EINVAL) { + ksft_test_result_fail("Undefined control argument should return EINVAL\n"); + return -12; + } + + ksft_test_result_pass("tests for riscv_v_vstate_ctrl pass\n"); + ksft_exit_pass(); + return 0; +} From patchwork Thu May 18 16:19:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Chiu X-Patchwork-Id: 13247090 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 EE278C77B7D for ; Thu, 18 May 2023 16:22:58 +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=fIHZnlA3+UKnCyRiuHa18BkrbFCweBbChddIrC77k0A=; b=5BDPQN4DwWx3xs X+WUSziR00gzDS68YnVtWwsGW2M+da7b+tOFp2YqXMraBdewpymgEQ6n0HMWW/ylr9PYaFVJD6oco 0p09IbKPC7CQSvU+FzSWoGsBK8Q9rDZs3X8re9drPnLR0gHiEnJaPgBfwYtud1Uc99wg9LfeBeixm 0Z4pKT9G+tlyuG16qP1ubl6mexcO99tMKmPR0PfjXHqvzy4GgkwJFfjgGN6J1dcY28JQ1gm6cIZdh SJPyynzX5mS2z7FUXc6iPHJp45BorOxhqei/4YoUA5YwrM3k5LD3KG4hxB1Uje1IpM5NIl636Nkcy rZwlaZh6gf7uQeIHbxQQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzgP1-00DRzJ-0C; Thu, 18 May 2023 16:22:55 +0000 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzgOy-00DRy4-37 for linux-riscv@lists.infradead.org; Thu, 18 May 2023 16:22:54 +0000 Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-64d2b42a8f9so211512b3a.3 for ; Thu, 18 May 2023 09:22:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1684426972; x=1687018972; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=GbKkWHcrIgmeU53Vku19x3Zfwadjf8vHA4LYRH5wmCY=; b=NEzuFRUUhNOcH1q+Rm2j6i6gqGIp6xJPZ7cmA5mkGLFv+USZnOvW7CPzqUHuq0jVHu GtA7ZEFRhmBIY4mXuhnEnYyqYwcE+TU3PjI6DHlKhvnDeybKpslFBiEnvmkF/gS22vvD HHSJJElg9ZauzU3ulLEqqbltCizHYYAiTB0PEj5PhBig4wJl7H8VgLLgx/R7TNvTn0rC eMlyKdU5WWy6/GzMGahUnd0JVXFLZq0/+vTrnvDRootsNqND47vi78ULS+0TqeeadBGI Z+r3F1+htzAnsixZgXU6oR1vcL0hrQbjsFwGymu+x/afZ/DEKYgEmIqavy48mY8M9S6d ziKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684426972; x=1687018972; 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=GbKkWHcrIgmeU53Vku19x3Zfwadjf8vHA4LYRH5wmCY=; b=B2yGS+FYPH2+x+r+PWH4pRqApjMOWT2aR0CCf3aShUkNGWKe8xBVkvDRzOPzqw1UD7 0gVZiQEsR1fhEyAJdDwHbAELCpSqrkTgCtb5P/tIwWPOBdRJO+0KktTvbF1v2ahSrLKc MukfoE7rfk4lVU2S2ZZCPPOLz6wPdqt6cJaStuCKLNBm8t4jjknOkvTYdDNWzzyMPMSL b9Qg7elaq+reeGOBxvxxxmuJallgtzHjJ9nijOj/SftRWwlAhBe5SwPTGEk7KdWUSz5N CLgsy9CK78BDSjzcQApTar/tvrUUFre1Hn7961LlLS6kJPZDUlkVbOCUHQbTHJJPvMsk yeZA== X-Gm-Message-State: AC+VfDzKQlfWI3UkKWNmx/oIzZGYH8FZvy+DHMXKyBFlYVkxoBy58suD 7lYwoHchaIUVU++Rx7lszXTznnf87UJOgJJF2J1PPUW/fLKrpWEGQfrM9rTCOUA/yHi3mplv41F MXLQNr9kPYCA67kxyJT2p4p/9bxLOrgzcRItWR9uPaRqaoS1ns/9ehokbP5GAInhS+iAKLsryRE NtwSnLdPgATMXWePA= X-Google-Smtp-Source: ACHHUZ4cNt92/WP2ysaHY9D2AcqqSWS+D+pEmSvvEFQxQEF0lgCg7dMBCSKN+WsgVX9S5/lGcyi2ig== X-Received: by 2002:a05:6a00:1a55:b0:648:d20c:37dd with SMTP id h21-20020a056a001a5500b00648d20c37ddmr5634519pfv.18.1684426971795; Thu, 18 May 2023 09:22:51 -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.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 May 2023 09:22:51 -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 , Shuah Khan , Paul Walmsley , Albert Ou Subject: [PATCH -next v20 26/26] selftests: add .gitignore file for RISC-V hwprobe Date: Thu, 18 May 2023 16:19:49 +0000 Message-Id: <20230518161949.11203-27-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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230518_092253_001647_BE4F855E X-CRM114-Status: UNSURE ( 9.71 ) 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 executable file "hwprobe" should be ignored by git, adding it to fix that. Signed-off-by: Andy Chiu --- tools/testing/selftests/riscv/hwprobe/.gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 tools/testing/selftests/riscv/hwprobe/.gitignore diff --git a/tools/testing/selftests/riscv/hwprobe/.gitignore b/tools/testing/selftests/riscv/hwprobe/.gitignore new file mode 100644 index 000000000000..8113dc3bdd03 --- /dev/null +++ b/tools/testing/selftests/riscv/hwprobe/.gitignore @@ -0,0 +1 @@ +hwprobe