From patchwork Fri Jun 12 07:09:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greentime Hu X-Patchwork-Id: 11601331 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7A759138C for ; Fri, 12 Jun 2020 07:10:20 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 4460920838 for ; Fri, 12 Jun 2020 07:10:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="qg21XEth"; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="NR8c5r2k" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4460920838 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To: Cc:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=sg9Lm/YutbN5f9zW+xwWCgs+u3zx03mdOZcDLL5rZHc=; b=qg21XEthFcn4udQ2VoPFosSPyn /R2fU4QKw/uHpj26eI1eh7pxz+/DyJNB89Ibfegt3Xy+0MkLw5DEBlBxJb5yxq4mK6QTi0RTXmGF8 mj437qbm4lbUy5mXgVbhRTTfYQknNFWR1d5bLJ5hVlbWC7VA9at4GFHTaA+CqKjSnwHNugje56E+l w1BuFClenj7Nb7ZZv3/dlQmf/gjRArUC5eFUH0wovN8MUssZ/RcI0gQlvSqRevcoK2VWZ+axDaPmm elJbJ9KrE+p53ixePuCDbNdEh3zdc7OicES0Ub1naZuPjXY7j0ATBkvPJSdLTbkQmYGcuiDDgA1PK /YpsE6pw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jjdpQ-00051g-U3; Fri, 12 Jun 2020 07:10:16 +0000 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jjdpN-0004yx-Fv for linux-riscv@lists.infradead.org; Fri, 12 Jun 2020 07:10:14 +0000 Received: by mail-pg1-x541.google.com with SMTP id l63so1466510pge.12 for ; Fri, 12 Jun 2020 00:10:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=sg9Lm/YutbN5f9zW+xwWCgs+u3zx03mdOZcDLL5rZHc=; b=NR8c5r2kPGt+D0zWH9UJWCDD2OEW7VmcBPlOHMIBQUrkGr2OhTIWw3v/sA0WFNp0l8 oIiWwckAic2yAcXOdvffdq2BnAXDFzUrfjAyhGtO1RkrWvLtaUDvJGqmHnwK89xPw4BT R2hLzzQUUinFlUjDgqWv3xAcmzsKa2KRV4ijhNJspVA6jeqMLl4qRP4J6R84fvoO7Lz1 SqynqQGZqLAn0ljjQ6Ep92AC/MEF0A/XtrgvXND0Hlf3h+MatmYKE5PFso3iSbtHKmaN /PqC7EDDJ1MCj0DI4vtRbnB9V7RvxNU43bhjmwj99gXsyea2BpM+xCVxZJkexlIhH9Xk dkRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sg9Lm/YutbN5f9zW+xwWCgs+u3zx03mdOZcDLL5rZHc=; b=CS9TR6Ua1aSsaOCgNocm9USelTjL2vNYMMUP3lBYP3SWHQBv1PKsjnr+z5oZSoe5hz sh06lp+MmVurby9EaJs0ucYEffMp1cYOm2Ib4unHGsBPW1ZecJF+GaVpv3YgdQCLlHSZ 4ILTUdNQfUMZ24AT5zDmm9snyrg98yFM+10DUBh2anNaQgIWARd7fjw7IvOXRgxIBFqq fHEGgD/hWlLUSP7v2uCbbJPoaw+UCkwfc53EaUSVR3LFdOQVRMauiCc3Sf+PuQzHAVfe 1DAPLyZpw+5x6CeoXvlTAyHpTs4N2aj7eOsxoiQ+76J/vBVMTO7SMU/RVP8iFzKnWssu VUiQ== X-Gm-Message-State: AOAM5303Nc6oVeZY2AWdJmwQoA8OvDlC68LU1Gkbn8OTncQED7N6/zw9 Y4e4K8N70uzOAG0E1wsY5SOhF7eGAbTFrA== X-Google-Smtp-Source: ABdhPJw5olV/JxsKv5JjihxwMCdrSsnylXvH/fyL7TAdlyOQFSWFNE+nFZeLa7jXucofV5WiDoQU9g== X-Received: by 2002:aa7:85da:: with SMTP id z26mr10312343pfn.13.1591945812666; Fri, 12 Jun 2020 00:10:12 -0700 (PDT) Received: from hsinchu02.internal.sifive.com (114-34-229-221.HINET-IP.hinet.net. [114.34.229.221]) by smtp.gmail.com with ESMTPSA id d2sm4336919pgp.56.2020.06.12.00.10.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jun 2020 00:10:12 -0700 (PDT) From: Greentime Hu To: greentime.hu@sifive.com, oleg@redhat.com, guoren@linux.alibaba.com, vincent.chen@sifive.com, paul.walmsley@sifive.com, palmerdabbelt@google.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 01/13] ptrace: Use regset_size() for dynamic regset Date: Fri, 12 Jun 2020 15:09:50 +0800 Message-Id: <8dbfdc77d4fac81a113ae2572ff9d01d9f155bfb.1591344965.git.greentime.hu@sifive.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200612_001013_533861_1BDBBABC X-CRM114-Status: UNSURE ( 8.77 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:541 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org This patch uses regset_size() instead of using regset->n and regset->size directly. In this case, it will call the get_size() ported by arch dynamically to support dynamic regset size case. Signed-off-by: Greentime Hu Acked-by: Oleg Nesterov --- kernel/ptrace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/ptrace.c b/kernel/ptrace.c index 43d6179508d6..946b2c4ec4fa 100644 --- a/kernel/ptrace.c +++ b/kernel/ptrace.c @@ -888,7 +888,7 @@ static int ptrace_regset(struct task_struct *task, int req, unsigned int type, regset_no = regset - view->regsets; kiov->iov_len = min(kiov->iov_len, - (__kernel_size_t) (regset->n * regset->size)); + (__kernel_size_t) regset_size(task, regset)); if (req == PTRACE_GETREGSET) return copy_regset_to_user(task, view, regset_no, 0, From patchwork Fri Jun 12 07:09:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greentime Hu X-Patchwork-Id: 11601333 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A5F3E912 for ; Fri, 12 Jun 2020 07:10:24 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 814832081A for ; Fri, 12 Jun 2020 07:10:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="E+OCc3J8"; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="Vk8nXv4l" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 814832081A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To: Cc:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=TqEeZZCFAo9j2EFFuYpPOcmAMjD+t0h5vXYjlCC88NI=; b=E+OCc3J8I6/AfWDVxushZBFIIw VS2ePZSypHPnVaGMlnklwxnJ8ARo6AxYOvKgQprehwg+PEC0XxFX7HOadlzIWCLhOJZ9heUFEh4hF ys2SvwXx8Bwsx45qC8Fz/hkr/q1TEs1z/3HODSGR6OYslzwvSyQcgSQ/+FMRNIJcT0JoCQzEsftpp KYFOQvpbPuSUE0D0sSUJTC9WHQQsyq5f8p101aiGk4k5H/FnXj5ELC4WPpjx81Zj6wbSYVH2q+Di/ /o2LjEJKUbZLKUUt1UWwC1tvZpt4MavPtSEsJ0az0285v+JM1bxmww0lbYeu08a8No6VmyNsqoDXq WJsEUTEw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jjdpT-00054p-R8; Fri, 12 Jun 2020 07:10:19 +0000 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jjdpP-000503-Ke for linux-riscv@lists.infradead.org; Fri, 12 Jun 2020 07:10:17 +0000 Received: by mail-pf1-x444.google.com with SMTP id d66so3878700pfd.6 for ; Fri, 12 Jun 2020 00:10:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=TqEeZZCFAo9j2EFFuYpPOcmAMjD+t0h5vXYjlCC88NI=; b=Vk8nXv4lbi60VdlETy0d9EHMvCMv6fvKZN7WSJqO8Yazl8SmgsXXBVnpEdhhbfA6U6 IsRjgiXT1RcyvifqbfANAKXfWf9zgSjGNNC8zwH2SOwquvk0yPTzl/bgCFuQvzFqJVyx T/QnIAE8JHW27tQv2laLYiXgPZnqbMeTEMiE2nvFH+fCSSAfZjuwOK4wkAmNt3J4egyL gktCEfFKGLc2yAws1DCe3q7msFiIg+t0pCeXmtIz1dc3lyIA1jA4hgQBOWSVnW1zVIaZ xRD8wy6R1sSLyOKQ3EMRr9OAKnrmjNq17Y7jyMTfEQM9LNMIv38SwTMU/MwVxNnmXpwG mlyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TqEeZZCFAo9j2EFFuYpPOcmAMjD+t0h5vXYjlCC88NI=; b=sg3nozIJId5yPQorYsZxv3Lhh+3dCYGWgK7bOFI0sQPf7DNbaWt5oXCHuEmJa22ExS QAeUCSvhdNJXaymHxt0miDlF76R4mu0oB93uTbf8PpD4CVzc2fwuDa8S17iEpwGuVEYH 66fyScCSIRLiVyAWfn4q/oRxWwi68NQ9JAYY3BRo1xs5l50S0WeL2p4yjAdC3f3D8N3t jxWHc7E9h5ky/XpOYspGbResweuJFOfrN9ERIdO6pZ5dL3TugthuTC6vE0ySesP31Y1M c2+gMF1MhabrrZPuAzkVE9pOGyus+4caUMZzMWd6NB0eassC8dvxPUTHgB1qvJPowzqG hHow== X-Gm-Message-State: AOAM531jfZs4ezoZz6j4tt7ZUhWE/KYbyS8glMpUkblAg9WA5qo9J+u9 Vm7zxV2950lt490B6n9cAKUObw== X-Google-Smtp-Source: ABdhPJyjEH+ADL2W4THCxsHXC9WxaaeveHWyMCLC47yacVreM5QB1kMYVKztlYuLn7XFuwTbzNN8eQ== X-Received: by 2002:a62:7b41:: with SMTP id w62mr9986107pfc.142.1591945814828; Fri, 12 Jun 2020 00:10:14 -0700 (PDT) Received: from hsinchu02.internal.sifive.com (114-34-229-221.HINET-IP.hinet.net. [114.34.229.221]) by smtp.gmail.com with ESMTPSA id d2sm4336919pgp.56.2020.06.12.00.10.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jun 2020 00:10:14 -0700 (PDT) From: Greentime Hu To: greentime.hu@sifive.com, oleg@redhat.com, guoren@linux.alibaba.com, vincent.chen@sifive.com, paul.walmsley@sifive.com, palmerdabbelt@google.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 02/13] riscv: Separate patch for cflags and aflags Date: Fri, 12 Jun 2020 15:09:51 +0800 Message-Id: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200612_001015_707699_3D574AF2 X-CRM114-Status: UNSURE ( 6.55 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:444 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org From: Guo Ren From: Guo Ren Use "subst fd" in Makefile is a hack way and it's not convenient to add new ISA feature. Just separate them into riscv-march-cflags and riscv-march-aflags. Signed-off-by: Guo Ren --- arch/riscv/Makefile | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile index fb6e37db836d..957d064bead0 100644 --- a/arch/riscv/Makefile +++ b/arch/riscv/Makefile @@ -37,12 +37,18 @@ else endif # ISA string setting -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 -KBUILD_CFLAGS += -march=$(subst fd,,$(riscv-march-y)) -KBUILD_AFLAGS += -march=$(riscv-march-y) +riscv-march-cflags-$(CONFIG_ARCH_RV32I) := rv32ima +riscv-march-cflags-$(CONFIG_ARCH_RV64I) := rv64ima +riscv-march-$(CONFIG_FPU) := $(riscv-march-y)fd +riscv-march-cflags-$(CONFIG_RISCV_ISA_C) := $(riscv-march-cflags-y)c + +riscv-march-aflags-$(CONFIG_ARCH_RV32I) := rv32ima +riscv-march-aflags-$(CONFIG_ARCH_RV64I) := rv64ima +riscv-march-aflags-$(CONFIG_FPU) := $(riscv-march-aflags-y)fd +riscv-march-aflags-$(CONFIG_RISCV_ISA_C) := $(riscv-march-aflags-y)c + +KBUILD_CFLAGS += -march=$(riscv-march-cflags-y) +KBUILD_AFLAGS += -march=$(riscv-march-aflags-y) KBUILD_CFLAGS += -mno-save-restore KBUILD_CFLAGS += -DCONFIG_PAGE_OFFSET=$(CONFIG_PAGE_OFFSET) From patchwork Fri Jun 12 07:09:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greentime Hu X-Patchwork-Id: 11601335 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 33A11912 for ; Fri, 12 Jun 2020 07:10:27 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id D15B2207D8 for ; Fri, 12 Jun 2020 07:10:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ioHXnU7z"; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="lj5U69Ck" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D15B2207D8 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date :Subject:To:From:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=zQ9MqfWdvKY0A/nub4Fo1FL/E8bJu3O4TVW1RUvcWdg=; b=ioHXnU7zY7laSF J21kWWZxI487U/shxRKk6VNxI8eQepVapumraDTqXDmc3jE0tDXiAZrFu3XW6erNRnZsabcODFR/S Cd5fVWTYG5L/pInF52D7SQO56JnAN5CNaUksLT/U81zkF62fmL/kd4hMHf3dsDywEHy3aIn4ZgQzw ITcLcTxS7fSufCietFo5H9Ju1qnbPmtYGLy/nantB5WLQY2Th2IzUYonNZifImsHgjWn7+fNkybPS bkT068w98XA+o0iSxqwdqfyaTgtWUUN0xH3zTI454x4b0nBuUqX1DIwRW1qCh5h1wbAim2Ld2P+9x WObaP/41PLT0ja57RidA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jjdpW-00059R-JB; Fri, 12 Jun 2020 07:10:22 +0000 Received: from mail-pj1-x1041.google.com ([2607:f8b0:4864:20::1041]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jjdpR-00052E-IK for linux-riscv@lists.infradead.org; Fri, 12 Jun 2020 07:10:19 +0000 Received: by mail-pj1-x1041.google.com with SMTP id k2so3292196pjs.2 for ; Fri, 12 Jun 2020 00:10:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zQ9MqfWdvKY0A/nub4Fo1FL/E8bJu3O4TVW1RUvcWdg=; b=lj5U69Cksq6OCRUwr5FSFcfeGktJxkA9FTX+22+Wu+8dwxBHR77hXuHnIPRGOGie44 ERN9/bY0xBVAOg9TX0F1fwANzNIdEZDZ8O4zqyQKeVct1npSg+vhxUXazCaPOanobztU 9IPlSXq8y3X0DOryWc0JvgfCJkQrIvmRxtFpBJoIO0umdmsg88SzIQzbrWuSS5IaaqiC 7jVNrkCGrcOhX9nUMKOmAks8AXBrZNwWlqrDsZmzAFXqqRLSuMEsdwLqtJCyTc7uVnbg trwbYhhJV97v47brW5F6K0w52j/zZa2BihQAIGVXfIz7oMjc6oE8qumbzxHB5NHRp0JI AMPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zQ9MqfWdvKY0A/nub4Fo1FL/E8bJu3O4TVW1RUvcWdg=; b=NPbrK0eYJKsb2ZazZ1CXDO6ojNuleAbUVhJCET6hQgIg/CcV5fCHBSbgltx4Pv7QpR IwLC199sY1xEDdf6uQXlzblOjnrGQIqf24/fNvQjKmAig1p8Q9Q/mXahYdEUVok+opjj iyag0+60jUC9xJp4ZpRdzKp+QRxMwH/Xl+SLbCZ5E15Yd9J3yygUO7I3BHTnzGIfiZun iAw2BsEqOrGnZoUjiyHGYMCk9zIsCUo+38l7iZ+z5tME9Z4OfDHgUEoii+4JBMi/JnGv ZawI2FfWhqJxdzi1K6eA4SUbEsQeHzGqywb0Sz3Q9Yo75CA/3OlEI7J/NazHft/VgHgX EOIQ== X-Gm-Message-State: AOAM531fScSIqvWV1Rc6xKr1q8IzymYVZvS4obdSeNwXtgrGoASSygF5 kGFUfHnzXLFTdwGvHCEyZca/ig== X-Google-Smtp-Source: ABdhPJwXTT29gm2ifat7CTG4weeyGOi00tGqBa0Ywljl2zNKwiR1hC9l0czmEkulm7P+V+zLBD+x/w== X-Received: by 2002:a17:90a:3b09:: with SMTP id d9mr12421250pjc.225.1591945817016; Fri, 12 Jun 2020 00:10:17 -0700 (PDT) Received: from hsinchu02.internal.sifive.com (114-34-229-221.HINET-IP.hinet.net. [114.34.229.221]) by smtp.gmail.com with ESMTPSA id d2sm4336919pgp.56.2020.06.12.00.10.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jun 2020 00:10:16 -0700 (PDT) From: Greentime Hu To: greentime.hu@sifive.com, oleg@redhat.com, guoren@linux.alibaba.com, vincent.chen@sifive.com, paul.walmsley@sifive.com, palmerdabbelt@google.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 03/13] riscv: Rename __switch_to_aux -> fpu Date: Fri, 12 Jun 2020 15:09:52 +0800 Message-Id: <28ce87a2bf6b73b01faa33b35df440effaab9a8b.1591344965.git.greentime.hu@sifive.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200612_001017_621356_53D39A07 X-CRM114-Status: UNSURE ( 9.78 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:1041 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anup Patel Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org From: Guo Ren 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 Reviewed-by: Anup Patel --- 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 407bcc96a710..b9234e7178d0 100644 --- a/arch/riscv/include/asm/switch_to.h +++ b/arch/riscv/include/asm/switch_to.h @@ -44,7 +44,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; @@ -60,7 +60,7 @@ extern bool has_fpu; #define has_fpu 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 *, @@ -71,7 +71,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 Fri Jun 12 07:09:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greentime Hu X-Patchwork-Id: 11601337 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7EDB2912 for ; Fri, 12 Jun 2020 07:10:34 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 5B348207D8 for ; Fri, 12 Jun 2020 07:10:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="KVhUt003"; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="doTShxH7" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5B348207D8 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date :Subject:To:From:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Qon66DpP/9C+tl7pgvKjepLx67Alsh8Vu/kEKeYzw5s=; b=KVhUt003FGzcyT G5DT7PAEcQ0Rc9nm1+mmFytNnHYTi+yjhBfrrqXN2mY2eeIFPZjwcM+q++sbWwbBIGhT6yjzwTW7n 3pPNBILBhk10CmRGxFL89ibBK3f8naaR68yrTGkoiZ6UyhjfomC+b+gLkS0Mu+fgdYaLvw82s4cWz z6AGW6sHmHo9ZBpD+XxwTCGOwi5i0I2LTOHReDfGK5H13wABLNYPu5uEnlr4rSPe2oCLLD+g9tTye +kS4ycZrdjN/IZ8UZtgS5da95Xxer2p1RQ1s73go54EH86nIRFLUgr5NFKOzzjMGWS/eBRHbn4Rvm oqCSSslfypo+X6iJv56Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jjdpc-0005Go-Tx; Fri, 12 Jun 2020 07:10:28 +0000 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jjdpU-00054f-2V for linux-riscv@lists.infradead.org; Fri, 12 Jun 2020 07:10:21 +0000 Received: by mail-pl1-x642.google.com with SMTP id y17so3382865plb.8 for ; Fri, 12 Jun 2020 00:10:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Qon66DpP/9C+tl7pgvKjepLx67Alsh8Vu/kEKeYzw5s=; b=doTShxH7Y/dsPbNJ+cLPM0V+vYloqDfRvNPzA9RkizxyoybW7ndmznNSSY+wG1kDqm Ng+Eel87SwVZG83rOIZadRsSt3gxAR7jpYOX2FZ+aSDonbP5BgLDL9Pv325SEpwng3zr w+fgz2zljiaSQJmyjD/FhBu/apLQfKrqkwC4woE4TkgM4xjLq/JnzouAN3b30HOUFFUq +OMlTPdI6Dd6ZD9Ai/V7Lk7hnrJ/taVd8hS3a4cJ3DTtV/4eTt8VuXGsKw90DlX7CIdA DDYzPhr/m3TDfkbCMK1PRnMVDq436bX1UGTNY4/lsHiPOywNL9Z2r7AkZSQTb0np1pfc QLjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Qon66DpP/9C+tl7pgvKjepLx67Alsh8Vu/kEKeYzw5s=; b=N9TkRuNEl1VzGLU+8WDv/CngRFfyTa8kg5FYiqnFwgSiO78dkIoDYJtslzBM7H3/ov sTsssKyRoTxMuyYcsGQxqxFCytg5az6WgtgzzFG00rVHuSH7W2Nt1s7KnJyGaboXlolQ fo+GMTFvGYtR6ThAxJCaIWQhg3S4tjgQ4ts3vN1QCntc3wXRc7MPRH6DKX/puFjDxZo1 SNvWB1wzbsJ3nE2JXVBdW04e/zLBKbRVoGGo2GqByp8dtmQVIFpezflXmRBWLLfD3qdu uiAnKNBGTLpMRv77UQ6BJ+iT8LkAHwgZ6z4ilooPLFKm0jiGe65bDl4A/k6XqxNB2dkX Ahcg== X-Gm-Message-State: AOAM532BbM86KGsVxoDpm1xnQxzSnx32n8LL7AlgEs0a7wWFIRzavP5/ OzVQJAbqXhkiIuaB0LVqHmT5bw== X-Google-Smtp-Source: ABdhPJxdL3oZhAFHxU1Uft6EO9Gm7i++9n8ABoOq3s6toXlmfYm7sY3HquRLodQM9zQo9yUiedVebQ== X-Received: by 2002:a17:90b:882:: with SMTP id bj2mr12458129pjb.122.1591945819238; Fri, 12 Jun 2020 00:10:19 -0700 (PDT) Received: from hsinchu02.internal.sifive.com (114-34-229-221.HINET-IP.hinet.net. [114.34.229.221]) by smtp.gmail.com with ESMTPSA id d2sm4336919pgp.56.2020.06.12.00.10.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jun 2020 00:10:18 -0700 (PDT) From: Greentime Hu To: greentime.hu@sifive.com, oleg@redhat.com, guoren@linux.alibaba.com, vincent.chen@sifive.com, paul.walmsley@sifive.com, palmerdabbelt@google.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 04/13] riscv: Extending cpufeature.c to detect V-extension Date: Fri, 12 Jun 2020 15:09:53 +0800 Message-Id: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200612_001020_137633_C48CBC91 X-CRM114-Status: UNSURE ( 8.96 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:642 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anup Patel Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org From: Guo Ren From: Guo Ren Current cpufeature.c doesn't support detecting V-extension, because "rv64" also contain a 'v' letter and we need to skip it. Signed-off-by: Guo Ren Reviewed-by: Anup Patel --- arch/riscv/include/uapi/asm/hwcap.h | 1 + arch/riscv/kernel/cpufeature.c | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/riscv/include/uapi/asm/hwcap.h b/arch/riscv/include/uapi/asm/hwcap.h index dee98ee28318..a913e9a38819 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 a5ad00043104..c8527d770c98 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -30,6 +30,7 @@ void riscv_fill_hwcap(void) isa2hwcap['f'] = isa2hwcap['F'] = COMPAT_HWCAP_ISA_F; isa2hwcap['d'] = isa2hwcap['D'] = COMPAT_HWCAP_ISA_D; isa2hwcap['c'] = isa2hwcap['C'] = COMPAT_HWCAP_ISA_C; + isa2hwcap['v'] = isa2hwcap['V'] = COMPAT_HWCAP_ISA_V; elf_hwcap = 0; @@ -44,7 +45,8 @@ void riscv_fill_hwcap(void) continue; } - for (i = 0; i < strlen(isa); ++i) + /* Skip rv64/rv32 to support v/V:vector */ + for (i = 4; i < strlen(isa); ++i) this_hwcap |= isa2hwcap[(unsigned char)(isa[i])]; /* From patchwork Fri Jun 12 07:09:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greentime Hu X-Patchwork-Id: 11601339 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1A31B138C for ; Fri, 12 Jun 2020 07:10:37 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id EB4B6207D8 for ; Fri, 12 Jun 2020 07:10:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="I6/hLphM"; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="BdOZaJOG" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EB4B6207D8 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date :Subject:To:From:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=9hbkAgC+PquBUrK8WyR9UJ24ePGDUqr+apyFl5WJvPs=; b=I6/hLphM+ihzaX /mY/MGc05F17vUD4iGpUgD8aX1sNSW/TVDiBx/12pZLJWBIX6IGuWyc6Mv4+gyI7t+PZsxA8GZihM 5xuL63xvA3sUHzNiEV98KHORaJ3ZHOQ6p0JuRJELT2bxMVy5C+Zl9y8BuUhtRnoHra9NwFrMHH9qt 2cb6Zy/Mqvd3y0/LLP1t5uQZPs1imWLoyOiU3aAHNXr1Px3t2P7q9pVm0nWTwmBSbk/ZtoVe4m0z5 2svyvtJTzJM0ePtq7g4Q23eK9F6ojdpctZnoe5O55wkdsHZ1Iv7jbuoEXv8DTesrACgD0Zn93FDvN g4zCdWVF5OWx69kzoTCw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jjdph-0005Lt-0Z; Fri, 12 Jun 2020 07:10:33 +0000 Received: from mail-pj1-x1042.google.com ([2607:f8b0:4864:20::1042]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jjdpW-00059M-JK for linux-riscv@lists.infradead.org; Fri, 12 Jun 2020 07:10:25 +0000 Received: by mail-pj1-x1042.google.com with SMTP id ne5so3283029pjb.5 for ; Fri, 12 Jun 2020 00:10:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9hbkAgC+PquBUrK8WyR9UJ24ePGDUqr+apyFl5WJvPs=; b=BdOZaJOGUOxHwgLXTREzQQgP8IdkkhhphjMQdSk4LAZItT68fp4I7T5uLiQmW5eB83 Y0/HdgMcCcyAXQSt9i1JrgNLyRbXymJB+E+El2K57HK08ChYQreNSfO3lm7AHEx4yx51 6RYoVnY2m1QhDzqT5X+mKTGBYfPn7negLN43JapDLw2h9AHt+YB50s/W2d5+CujebY7T jSqFMNWEg+nJZkPVyMSL7prSubRAa6GzZ0o0OQgu2aj/VNCQmRJPHxeqlx9Xbhq8+jut E5O2Z+TELL7sIdOWkJw8rgl8cRDatcdBo96GiF+6hdkEzqvAc80AGxXLHZtr3b1jZNay QVQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9hbkAgC+PquBUrK8WyR9UJ24ePGDUqr+apyFl5WJvPs=; b=Q+4EfPVy77X/QAqYYV2CQ4SFaAtkpeAG01xtmItI2kVRTj6PWKerb1gFoAPprrIlcr pt4vhxOzJFNeQ5SeIX6A4ZEan2ZhSzzNiM0ILSxIhThcivYuvZrqnan3Lxyjjev32TeR ikFKVWgC12cW2YdeYREnxHC3i/mIWNgL9rmPL5eEhis3TfJifL2XUjzum8QYKhA2wIGj 9lFX72BbAZXVGkiT1BmmOSdhdUBAsq8UqrxPS2uP4PJjpcwkDgh+bXduWhzLW9SXJM4N 6JJhpaVneFKg5UtcXoZ69eOkH6DVAFkbmNj7SSPpJ1vAluGzCmUnm8HUcPX+Cq5VB/Lm hnxQ== X-Gm-Message-State: AOAM533w643CkhjgFY7q50+t/Oo/RYBUzl3qFIzrr2mISEe1GH+neBl/ K/0a8yvCtq1wgk7WkgRCsi2DAQ== X-Google-Smtp-Source: ABdhPJx1ZHDZwPoaF4NxRGDU4vmr387qwe9VI25z+habDuxWepIlSNSsC2mvx4ylZT2lUrL0Vd9VPw== X-Received: by 2002:a17:90a:e983:: with SMTP id v3mr11563272pjy.71.1591945821531; Fri, 12 Jun 2020 00:10:21 -0700 (PDT) Received: from hsinchu02.internal.sifive.com (114-34-229-221.HINET-IP.hinet.net. [114.34.229.221]) by smtp.gmail.com with ESMTPSA id d2sm4336919pgp.56.2020.06.12.00.10.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jun 2020 00:10:20 -0700 (PDT) From: Greentime Hu To: greentime.hu@sifive.com, oleg@redhat.com, guoren@linux.alibaba.com, vincent.chen@sifive.com, paul.walmsley@sifive.com, palmerdabbelt@google.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 05/13] riscv: Add new csr defines related to vector extension Date: Fri, 12 Jun 2020 15:09:54 +0800 Message-Id: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200612_001022_736472_1487022E X-CRM114-Status: UNSURE ( 7.35 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:1042 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Guo Ren Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org Follow the riscv vector spec to add new csr numbers. [guoren@linux.alibaba.com: first porting for new vector related csr] Signed-off-by: Greentime Hu Signed-off-by: Guo Ren Acked-by: Guo Ren --- arch/riscv/include/asm/csr.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/arch/riscv/include/asm/csr.h b/arch/riscv/include/asm/csr.h index 8e18d2c64399..cc13626c4bbe 100644 --- a/arch/riscv/include/asm/csr.h +++ b/arch/riscv/include/asm/csr.h @@ -24,6 +24,12 @@ #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) @@ -31,9 +37,9 @@ #define SR_XS_DIRTY _AC(0x00018000, UL) #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 /* SATP flags */ @@ -114,6 +120,12 @@ #define CSR_PMPADDR0 0x3b0 #define CSR_MHARTID 0xf14 +#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 Fri Jun 12 07:09:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greentime Hu X-Patchwork-Id: 11601341 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4BCB0912 for ; Fri, 12 Jun 2020 07:10:42 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 2817D207D8 for ; Fri, 12 Jun 2020 07:10:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="gnDbrkHK"; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="f1Z7wn8O" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2817D207D8 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To: Cc:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=4+NJ3t8NefDvMBlOVrpO6HJOHxIomSxMyV3y0MN34qw=; b=gnDbrkHK0/OjBtS0sBHjnkkC/z fz6ss+Z/Eiyk/R7xQ+RXcWi4bMlnGceSz78fAXDBLXCyasDLA0/0lVChieMHVPm/s1sH6XQS4KWcd 78SLqFi/UGlDqXVRYFKC9drkfs4BKXfNVyRcBuIs+zhEgxERPJcf3xwPkEM9JoGcRSZVIAiIsbkvG ctpXKMCcla/q/2Gs2eO9CzJiWijRbOXioDC6YUWKm1o6pqfQTQMhylRsp0lAtkBE6nEuSens3Bkac SPGMFxKiOdiZtz18Y8aHsK6YqsAk3PjE35s1HGICzFPu35ADMVBdpmtYCfRX7bfnGMT3LueoXvPRZ bBYz3+ww==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jjdpl-0005RG-MJ; Fri, 12 Jun 2020 07:10:37 +0000 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jjdpY-0005CV-PA for linux-riscv@lists.infradead.org; Fri, 12 Jun 2020 07:10:26 +0000 Received: by mail-pg1-x541.google.com with SMTP id b5so2756429pgm.8 for ; Fri, 12 Jun 2020 00:10:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=4+NJ3t8NefDvMBlOVrpO6HJOHxIomSxMyV3y0MN34qw=; b=f1Z7wn8ODMszNV5yRo5L00AOwSuvcWankDXBey/J0QSLJG9bar/NSgUX25Wf91d1YQ 5jTTw17cQ1hw7xOBPBBQ9dTwf/asfw6P4tueUtHCjF6xfDYqvxV+RbjLrEf3JSYufQrq SVFqIwb6LJdn0xkyOOzidLm8X73EuPp9qtXWZORQIpHfsKWED3a62HM+Y6vnNy8R9OYX mZnTkDgGWrW/CVOneAPhCKGFArrxn/ktvFFwvSZppc2iPRm8nHWorVISFKCnohdbsYEc xMtJi/eOG58tRvohlc9pV8PNIPF5KlTlxs79VRmAmjTH/CXwVma5BI1Ymc36kILlHImI D+0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4+NJ3t8NefDvMBlOVrpO6HJOHxIomSxMyV3y0MN34qw=; b=CgRESzkbb+rcOOs9sM6C8XHLLu/b0OrDL4L5Yyt/UCq2J2ROPDI/SEFHi+E4GGh9a1 vA1igkGG//ARITuwqyd5GA6AtNN1dwhDDIaVkiCaNAhykx5IR8JeZZEeqeuTRs7XH8LD mxHDS7212N0qb7aeekMyy45j8inVFmw0Nhb/QK3uiLVulTlxcz1KImAUsiucpyDil18V g1KAXoLWfkOQsmhxxaLtp5jz9Nm8dI25PksoMShaSwJqu7PPRouh46T0rmViAwOBp3Jh awc/qRe54h1IAVl/tOoM+5sv9XMq4iCvgMnpdzU4nuULt43jWMKiUxXpoUvCFykwEqbV JhWw== X-Gm-Message-State: AOAM530rqv5/fogY/1JqfUCPATrS9GFWOzLV/24AlxkEkpq5q2lMwXe3 9qYyV0XBZ0Vwiq9pjaPvQnvsdA== X-Google-Smtp-Source: ABdhPJxIEogp+RWDoHXMgGJLewWmgiLwJtVEzXgBro7HgtTSJx6CPinawDSwZAjC+NoKJKtLZwdlng== X-Received: by 2002:aa7:9439:: with SMTP id y25mr10621687pfo.268.1591945823802; Fri, 12 Jun 2020 00:10:23 -0700 (PDT) Received: from hsinchu02.internal.sifive.com (114-34-229-221.HINET-IP.hinet.net. [114.34.229.221]) by smtp.gmail.com with ESMTPSA id d2sm4336919pgp.56.2020.06.12.00.10.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jun 2020 00:10:23 -0700 (PDT) From: Greentime Hu To: greentime.hu@sifive.com, oleg@redhat.com, guoren@linux.alibaba.com, vincent.chen@sifive.com, paul.walmsley@sifive.com, palmerdabbelt@google.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 06/13] riscv: Add vector feature to compile Date: Fri, 12 Jun 2020 15:09:55 +0800 Message-Id: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200612_001024_907717_D1DFBDA2 X-CRM114-Status: UNSURE ( 8.58 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:541 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org From: Guo Ren This patch adds a new config option which could enable assembler's vector feature. Signed-off-by: Guo Ren --- arch/riscv/Kconfig | 9 +++++++++ arch/riscv/Makefile | 1 + 2 files changed, 10 insertions(+) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 74f82cf4f781..3b742d949a09 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -305,6 +305,15 @@ config FPU If you don't know what to do here, say Y. +config VECTOR + bool "VECTOR support" + default n + 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. + endmenu menu "Kernel features" diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile index 957d064bead0..7c80c95582e3 100644 --- a/arch/riscv/Makefile +++ b/arch/riscv/Makefile @@ -46,6 +46,7 @@ riscv-march-aflags-$(CONFIG_ARCH_RV32I) := rv32ima riscv-march-aflags-$(CONFIG_ARCH_RV64I) := rv64ima riscv-march-aflags-$(CONFIG_FPU) := $(riscv-march-aflags-y)fd riscv-march-aflags-$(CONFIG_RISCV_ISA_C) := $(riscv-march-aflags-y)c +riscv-march-aflags-$(CONFIG_VECTOR) := $(riscv-march-aflags-y)v KBUILD_CFLAGS += -march=$(riscv-march-cflags-y) KBUILD_AFLAGS += -march=$(riscv-march-aflags-y) From patchwork Fri Jun 12 07:09:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greentime Hu X-Patchwork-Id: 11601343 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 83732138C for ; Fri, 12 Jun 2020 07:10:44 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 60F57207D8 for ; Fri, 12 Jun 2020 07:10:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="gYyosmBy"; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="OFiDcEYW" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 60F57207D8 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To: Cc:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=pbP82gUL18C1Fla9shgiQQ97uS+492J9jEgfpwVcbPY=; b=gYyosmByLysmk7QRqJzAvSkuYZ bUKDAnQyGaxXjSredODI/GoM2CiyC9TPkiNWS+Vp2IGMRMdNoxMueYZuYy+rFLVn2x0UsCzE+le6U JReXvZWbiTyOldHbFCzvPw+FhE8nujQu0xKL+u3rZ454x7esl8yqhtcE0DKMydJ8FRZePRuHNIfQo j7XDeJHfLc+Fy95BSlf7ZKbtGlugJ5tgb6+0cIj0LCeZuDbL/Pt23civayGIyQGl0etObBnr4bOwA X1Mkwaf+zRp3CUjlDM65j/+s7haHnAnosOuceHbMLmuRf2cR0GJYmVGGOt7UriTb0I+9uwEGX5pQ2 zCjyCePA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jjdpq-0005Wq-3Z; Fri, 12 Jun 2020 07:10:42 +0000 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jjdpb-0005Em-Em for linux-riscv@lists.infradead.org; Fri, 12 Jun 2020 07:10:28 +0000 Received: by mail-pg1-x544.google.com with SMTP id e9so3704536pgo.9 for ; Fri, 12 Jun 2020 00:10:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=pbP82gUL18C1Fla9shgiQQ97uS+492J9jEgfpwVcbPY=; b=OFiDcEYWxQE3WkBK3dTvh348Jh2eoGWIzY5+cfmABqwb4g9kCFVGZIM9AlCnv/9Q4w b1QHy35qJGWGkZzFRlEo3wz1VFv3YEkzl4ypBsfEEpldy7BHJoozzE9WyJcWaKMuD+CB 1kt+dzz2ZiLJt2ntDrB7ezZdqkR0kec032PVhQljIxRVHF89Ah+Uerk5E9XeNAYUU+Lh D9VNWWwbZdAmy4VGcNiMbAaYcqwlKCCjfVQR9ZTXm93aAg4gSkK/hFWdC/+TcA33ViGi 4PeliW1MnMFo2qlbw3xTD3UUSmjEibBSBbaGbMQ3+/0QcRVTDsgPKpHq4dhrLRPezY5q LczA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pbP82gUL18C1Fla9shgiQQ97uS+492J9jEgfpwVcbPY=; b=luWDOpzP6s6U03fXzDU6ZEzGYCowjsTl/BpTyvOzhaiaYEMHhpwBkHD2XXIwNZhJdU nj8tGq3W9+Sa1XHWuaFOGZi7c/IlBYQo/724CQOJgMLL4UGrsNdjqpl2Yn4/gM+8DyFw UK7Z1EdD9ly6aHtSeUqJ6W09OzLHNNTYAcDGJTo4/hNqcB2ald6busdfgngunh32Q8XW 05BWwTziY71sI1QlgVZ2P9YK3fkD2s/IsDjMPFXBeyhJjJU+z9XUlRnoAVFA9yKeflSt aUCDUkyrgg3cvPYpCXDqW/Csv9NWG7LhDHa27Jt5VvK2RcmKyavP86gxeLhce2t7tdo7 1hrw== X-Gm-Message-State: AOAM533to5l3UOS5HiaGIDuwtlt4fUo3/zFebDckd7q8yJ7vSWCR/vl+ o3+kcJEHFBZzXQESIbkb6y2BlrVqJtGvdQ== X-Google-Smtp-Source: ABdhPJzYsgrvRY/e0uV567qf3OJr/AS7IFAJducWNceLl4M2iwG28zBHaJD4Zo9jtBYytldPZjj34A== X-Received: by 2002:aa7:9a9c:: with SMTP id w28mr9821650pfi.295.1591945825946; Fri, 12 Jun 2020 00:10:25 -0700 (PDT) Received: from hsinchu02.internal.sifive.com (114-34-229-221.HINET-IP.hinet.net. [114.34.229.221]) by smtp.gmail.com with ESMTPSA id d2sm4336919pgp.56.2020.06.12.00.10.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jun 2020 00:10:25 -0700 (PDT) From: Greentime Hu To: greentime.hu@sifive.com, oleg@redhat.com, guoren@linux.alibaba.com, vincent.chen@sifive.com, paul.walmsley@sifive.com, palmerdabbelt@google.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 07/13] riscv: Add has_vector/riscv_vsize to save vector features. Date: Fri, 12 Jun 2020 15:09:56 +0800 Message-Id: <02932e625077902209ab9967735607f6054cd4d6.1591344965.git.greentime.hu@sifive.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200612_001027_559711_32F1BF5D X-CRM114-Status: UNSURE ( 8.72 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:544 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org This patch is used to detect vector support status of CPU and use riscv_vsize to save the size of all the vector registers. It assumes all harts has the same capabilities in SMP system. [guoren@linux.alibaba.com: add has_vector checking] Signed-off-by: Greentime Hu Signed-off-by: Guo Ren --- arch/riscv/kernel/cpufeature.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index c8527d770c98..9b02d8b069e3 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -16,6 +16,10 @@ unsigned long elf_hwcap __read_mostly; #ifdef CONFIG_FPU bool has_fpu __read_mostly; #endif +#ifdef CONFIG_VECTOR +bool has_vector __read_mostly; +unsigned long riscv_vsize __read_mostly; +#endif void riscv_fill_hwcap(void) { @@ -73,4 +77,12 @@ void riscv_fill_hwcap(void) if (elf_hwcap & (COMPAT_HWCAP_ISA_F | COMPAT_HWCAP_ISA_D)) has_fpu = true; #endif + +#ifdef CONFIG_VECTOR + if (elf_hwcap & COMPAT_HWCAP_ISA_V) { + has_vector = true; + /* There are 32 vector registers with vlenb length. */ + riscv_vsize = csr_read(CSR_VLENB) * 32; + } +#endif } From patchwork Fri Jun 12 07:09:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greentime Hu X-Patchwork-Id: 11601345 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EAD3A912 for ; Fri, 12 Jun 2020 07:10:48 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id C63AC207D8 for ; Fri, 12 Jun 2020 07:10:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="MlQ2P0hE"; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="Fc/RmOfg" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C63AC207D8 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To: Cc:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Bt52k9Bvf6mwoBH8BO99Cl1SZAUWj8JPjBOKu49Dflg=; b=MlQ2P0hEG1uEql2YWiVLw0ZhkO Et0Wogs3nXXhY2PsTmW4j5ie9Mqel1Y9msQV1RmCxwnO3r0LYuh0uaNAr6hi1JHi2AOC0CfxjqlSo /LJyIOh1XY8bMezagQTH164qI9cq9JTtQfw+cMB0MI4wMqZor97GahZqTwE4yOSUpoeoR+qbM3bQI WDtrdy2ZJ0rvdw4PNUg7sKJPiD/pKpndXFUUPTJjVCV3mfPVctg6t6VSx+n/niUR4Ro2FCqJs6YrX KKnDHmx4Vnuz0e6dbGWmdts9T1DsT0vAuGYadcJE/w5y3hrjpFSOQK0Wfz0ovUZOcTxT6v39UMkp4 VPWdImtQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jjdps-0005aC-DA; Fri, 12 Jun 2020 07:10:44 +0000 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jjdpd-0005HS-9x for linux-riscv@lists.infradead.org; Fri, 12 Jun 2020 07:10:30 +0000 Received: by mail-pf1-x429.google.com with SMTP id h185so3885124pfg.2 for ; Fri, 12 Jun 2020 00:10:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=Bt52k9Bvf6mwoBH8BO99Cl1SZAUWj8JPjBOKu49Dflg=; b=Fc/RmOfgUenC1huViLl/zLKhIYopdecJLV5VD2dJhaN267VO6VkoMGplqRcZ7bos2+ Wb+yl4Cd5cB8HwFCeCFWz42VYHvuzOcw8O3LW7JJ5vvZndUYNM/B8JOs2x9JBEheZQmR R94SW60bIr/7HaO6oNg1yMXH1Htlxkwt36l/C3KR+1kfnJhgMbydFY96Vp7NIHRXxxLm fzs/HMyxeNFHl1wdrdNPMaL06WQMM+GHIcSK/JL7Y+VYwaHPqiNQOxxcP5OGSEpa59rA uT3nUgYAtPpwmiipEPCZk0Aqjs6puRTNijHtj+C13r6ciR7iu4xkPSz4R1ta6nyv2RuS Fjgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Bt52k9Bvf6mwoBH8BO99Cl1SZAUWj8JPjBOKu49Dflg=; b=XO8dP8mRCl4iZbI6JCs82yC2vTulSmpjcQbYEBCAcB6GTxnuXG0iBt45sk9jjiXzTu duTD5uOq4D1ruxk/Rv13u6VEnNerwL9ZP6ITMh6raYpeG4bsE5402DHVyS25iHo/pV3C 4L6Bj7bsM5OPDtWSVxlk6VjS1ovJE7NGya7pdFZ2CMzjEPzW+9MrmGVZsDwAGhsJg764 UpNdtpI1/RVU/DThvq60Csx5LS9FskDIE9quEKyAv1kCOJzHCTkwKVBXzcrOiVPCyU3q 0TmHj14hDgkMp8BC+7+bNtgJR0pFRAt/MPkRiCRd9ZWHN0IIQ+vvdz+8eQR5R+6Rjyvr bKRg== X-Gm-Message-State: AOAM5307JMcxxsxNpoZwQhBIDDut04DOrrvsOYW2YfoZQQnygf/CM+ZP Ip30pbYUnWYzhAHVfmpx0Mla0Q== X-Google-Smtp-Source: ABdhPJzcGkM7/3ILCBONGZKG4PpCtorJ3xtsrdL+K4vr+cBUu+pfS0s625IeEIqoX+ldCpeFmfNF/A== X-Received: by 2002:a63:7f5d:: with SMTP id p29mr9628085pgn.337.1591945828140; Fri, 12 Jun 2020 00:10:28 -0700 (PDT) Received: from hsinchu02.internal.sifive.com (114-34-229-221.HINET-IP.hinet.net. [114.34.229.221]) by smtp.gmail.com with ESMTPSA id d2sm4336919pgp.56.2020.06.12.00.10.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jun 2020 00:10:27 -0700 (PDT) From: Greentime Hu To: greentime.hu@sifive.com, oleg@redhat.com, guoren@linux.alibaba.com, vincent.chen@sifive.com, paul.walmsley@sifive.com, palmerdabbelt@google.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 08/13] riscv: Reset vector register Date: Fri, 12 Jun 2020 15:09:57 +0800 Message-Id: <63ca68cb344d18fdae0036e1b66770f1f9a90fbc.1591344965.git.greentime.hu@sifive.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200612_001029_375687_170E2F74 X-CRM114-Status: UNSURE ( 9.85 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:429 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org From: Guo Ren Reset vector registers at boot-time and disable vector instructions execution for kernel mode. [greentime.hu@sifive.com: add comments] Signed-off-by: Greentime Hu Signed-off-by: Guo Ren --- arch/riscv/kernel/entry.S | 6 ++--- arch/riscv/kernel/head.S | 49 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S index 56d071b2c0a1..2184153836ca 100644 --- a/arch/riscv/kernel/entry.S +++ b/arch/riscv/kernel/entry.S @@ -67,10 +67,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 | SR_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 98a406474e7d..1290ef680125 100644 --- a/arch/riscv/kernel/head.S +++ b/arch/riscv/kernel/head.S @@ -181,10 +181,10 @@ ENTRY(_start_kernel) .option pop /* - * Disable FPU to detect illegal usage of + * Disable FPU & VECTOR to detect illegal usage of * floating point in kernel space */ - li t0, SR_FS + li t0, SR_FS | SR_VS csrc CSR_STATUS, t0 #ifdef CONFIG_SMP @@ -341,6 +341,51 @@ ENTRY(reset_regs) csrw fcsr, 0 /* note that the caller must clear SR_FS */ #endif /* CONFIG_FPU */ + +#ifdef CONFIG_VECTOR + csrr t0, CSR_MISA + li t1, (COMPAT_HWCAP_ISA_V >> 16) + slli t1, t1, 16 + and t0, t0, t1 + beqz t0, .Lreset_regs_done + + li t1, SR_VS + csrs CSR_STATUS, t1 + vmv.v.i v0, 0 + vmv.v.i v1, 0 + vmv.v.i v2, 0 + vmv.v.i v3, 0 + vmv.v.i v4, 0 + vmv.v.i v5, 0 + vmv.v.i v6, 0 + vmv.v.i v7, 0 + vmv.v.i v8, 0 + vmv.v.i v9, 0 + vmv.v.i v10, 0 + vmv.v.i v11, 0 + vmv.v.i v12, 0 + vmv.v.i v13, 0 + vmv.v.i v14, 0 + vmv.v.i v15, 0 + vmv.v.i v16, 0 + vmv.v.i v17, 0 + vmv.v.i v18, 0 + vmv.v.i v19, 0 + vmv.v.i v20, 0 + vmv.v.i v21, 0 + vmv.v.i v22, 0 + vmv.v.i v23, 0 + vmv.v.i v24, 0 + vmv.v.i v25, 0 + vmv.v.i v26, 0 + vmv.v.i v27, 0 + vmv.v.i v28, 0 + vmv.v.i v29, 0 + vmv.v.i v30, 0 + vmv.v.i v31, 0 + /* note that the caller must clear SR_VS */ +#endif /* CONFIG_VECTOR */ + .Lreset_regs_done: ret END(reset_regs) From patchwork Fri Jun 12 07:09:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greentime Hu X-Patchwork-Id: 11601347 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6A132912 for ; Fri, 12 Jun 2020 07:10:51 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 47686207D8 for ; Fri, 12 Jun 2020 07:10:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="jT4tT7Dy"; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="j34D/ROQ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 47686207D8 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To: Cc:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=hj2dPYxf9ChP39UbQUHFbp9CrwoiANKLX5kN73nw2wo=; b=jT4tT7DyrX/sdksCq5RgB8Efuc ER81+cTphj9RP27zM5gMg4+/+4PwXU87affDPg3BSbuEuq7NcDzsF6d6+RnMUTMmiycAj8ytNPrN0 MyEWHfcvCKHTcqiRNLyGPce48IvopBgJzg32gzkghYTDsYPGdRuy4oWZ6sQy7hFSZIfiPLq4qFGr3 zWbvIKmGMm/E87j2aRF8d7ZD4t/vL0PmWT//JCtXB7xFKTHgyuLDdpMZaQ+vfQKXjdwuFa3BAh6ic Ixmb7ukxbKuiQPskufxMfwrEjWj0MOWrfrRk8a7y0FYKxWChLgzdl1JE8ySl/N14Uqv7UNCEPJIx6 ExKVoRaw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jjdpv-0005ez-L1; Fri, 12 Jun 2020 07:10:47 +0000 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jjdpf-0005Jj-8f for linux-riscv@lists.infradead.org; Fri, 12 Jun 2020 07:10:32 +0000 Received: by mail-pf1-x444.google.com with SMTP id h185so3885157pfg.2 for ; Fri, 12 Jun 2020 00:10:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=hj2dPYxf9ChP39UbQUHFbp9CrwoiANKLX5kN73nw2wo=; b=j34D/ROQjnhONX4zQlk9GKNvkSsVJAjFQ5qEvF4lY3wxw8UUtWollpSadUBzL2YJhg R03cWdRvP2V8n2uD0EJgysBgnDW1YP4h4QuIy5QhUmezjvvVIE/9OBfz757j6vaf7WzZ 5A2T5z0iTYn1t3Bdlb5aEQ3yIUf8S7jVMP2jOuyRC6HmbWJIGiItS98O1eqwUVX3KjfT 4hbPlGd5HumJ+uYiiI6t1m1uvmlnYxtX7KEfyk840xrff2G0I73+qQTxJ0r1FAbLFISu Tz09DL1YGzTf14uBNYzY5760j/Xw5mwwO4y8o40BgXE9/zzKV/jKXrM3pSCmlBGnFi3J UTeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hj2dPYxf9ChP39UbQUHFbp9CrwoiANKLX5kN73nw2wo=; b=PpWkFePyMAx4Jv9j/Dq3mXUBpLvL98b3jdtHba1l6b0igcBvz3yuFZ4MK9NBWkFo/F jgw3QqJSEDpym0V6WODME1ROUA3OcZzNZ4FJiZexvIjP9PgcEgUP1Z13gZUpxdvsmX6Y 1uf/vnVVJbvtOanKRSBbQ9oMZ3ectiJQhcwTlIoOObuuo2niv70Ik3874Bx2+7cFUg2Q 131boum71WgtJxCeTJqmmdBrC9o8ROuGBSghqyQKZJQrbZvvrT5ln87+oqloQdUdfYSP 3ATLahs4z4stxkJoCA+RSzAE+8umkBUhaU0OktYZcDV8nL0e/yGOhaPPU0WHKGnNKSpQ EL3A== X-Gm-Message-State: AOAM5338fiY5YP81sLEm1czY29cfWeLzYdv39RWbaiJG6ArWnAD7bcXc nlpkjcK5E97W6MziA6zRNsPI7g== X-Google-Smtp-Source: ABdhPJzSQsT2X/6m8pvPFSpq5aCtQwFbocucHDtZ7VPPrFY8MzbWGMx0sQXNb2xDQ+3qFy+gaPtJNw== X-Received: by 2002:a63:7c51:: with SMTP id l17mr9664899pgn.303.1591945830320; Fri, 12 Jun 2020 00:10:30 -0700 (PDT) Received: from hsinchu02.internal.sifive.com (114-34-229-221.HINET-IP.hinet.net. [114.34.229.221]) by smtp.gmail.com with ESMTPSA id d2sm4336919pgp.56.2020.06.12.00.10.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jun 2020 00:10:29 -0700 (PDT) From: Greentime Hu To: greentime.hu@sifive.com, oleg@redhat.com, guoren@linux.alibaba.com, vincent.chen@sifive.com, paul.walmsley@sifive.com, palmerdabbelt@google.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 09/13] riscv: Add vector struct and assembler definitions Date: Fri, 12 Jun 2020 15:09:58 +0800 Message-Id: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200612_001031_356135_4822E4F5 X-CRM114-Status: UNSURE ( 9.05 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:444 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org Add vector state context struct in struct thread and asm-offsets.c definitions. The vector registers will be saved in datap pointer of __riscv_v_state. It will be dynamically allocated in kernel space. It will be put right after the __riscv_v_state data structure in user space. [guoren@linux.alibaba.com: first version vector porting] Signed-off-by: Greentime Hu Signed-off-by: Guo Ren --- arch/riscv/include/asm/processor.h | 1 + arch/riscv/include/uapi/asm/ptrace.h | 13 +++++++++++++ arch/riscv/kernel/asm-offsets.c | 8 ++++++++ 3 files changed, 22 insertions(+) diff --git a/arch/riscv/include/asm/processor.h b/arch/riscv/include/asm/processor.h index 3ddb798264f1..217273375cfb 100644 --- a/arch/riscv/include/asm/processor.h +++ b/arch/riscv/include/asm/processor.h @@ -32,6 +32,7 @@ struct thread_struct { unsigned long sp; /* Kernel mode stack */ unsigned long s[12]; /* s[0]: frame pointer */ struct __riscv_d_ext_state fstate; + struct __riscv_v_state vstate; }; #define INIT_THREAD { \ diff --git a/arch/riscv/include/uapi/asm/ptrace.h b/arch/riscv/include/uapi/asm/ptrace.h index 882547f6bd5c..661b0466b850 100644 --- a/arch/riscv/include/uapi/asm/ptrace.h +++ b/arch/riscv/include/uapi/asm/ptrace.h @@ -77,6 +77,19 @@ union __riscv_fp_state { struct __riscv_q_ext_state q; }; +struct __riscv_v_state { + __u32 magic; + __u32 size; + unsigned long vstart; + unsigned long vl; + unsigned long vtype; + unsigned long vcsr; + void *datap; +#if __riscv_xlen == 32 + __u32 __padding; +#endif +} __attribute__((aligned(16))); + #endif /* __ASSEMBLY__ */ #endif /* _UAPI_ASM_RISCV_PTRACE_H */ diff --git a/arch/riscv/kernel/asm-offsets.c b/arch/riscv/kernel/asm-offsets.c index 07cb9c10de4e..6627fde230b2 100644 --- a/arch/riscv/kernel/asm-offsets.c +++ b/arch/riscv/kernel/asm-offsets.c @@ -70,6 +70,14 @@ void asm_offsets(void) OFFSET(TASK_THREAD_F31, task_struct, thread.fstate.f[31]); OFFSET(TASK_THREAD_FCSR, task_struct, thread.fstate.fcsr); + OFFSET(RISCV_V_STATE_MAGIC, __riscv_v_state, magic); + OFFSET(RISCV_V_STATE_SIZE, __riscv_v_state, size); + OFFSET(RISCV_V_STATE_VSTART, __riscv_v_state, vstart); + OFFSET(RISCV_V_STATE_VL, __riscv_v_state, vl); + OFFSET(RISCV_V_STATE_VTYPE, __riscv_v_state, vtype); + OFFSET(RISCV_V_STATE_VCSR, __riscv_v_state, vcsr); + OFFSET(RISCV_V_STATE_DATAP, __riscv_v_state, datap); + DEFINE(PT_SIZE, sizeof(struct pt_regs)); OFFSET(PT_EPC, pt_regs, epc); OFFSET(PT_RA, pt_regs, ra); From patchwork Fri Jun 12 07:09:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greentime Hu X-Patchwork-Id: 11601349 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BD1F4912 for ; Fri, 12 Jun 2020 07:10:55 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 88826207D8 for ; Fri, 12 Jun 2020 07:10:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Pb8IceK9"; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="bYf2ca0p" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 88826207D8 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date :Subject:To:From:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=oxY+GEGW58gRs4X3wAEY9YflVh8sZNhuS06ZzQHTlOU=; b=Pb8IceK9Kfqa+7 YcHdf6G0t2ibh6FQEIzdvzusEJYEyBpMPvM3T+7eC4lDsCuCMFfuhdetWNrXV77a6eAGFEe+vKBMn uJB8HfrafBhTPJ3mmjvn85jkOt+ByO2euw6RIL+dGA5BOFqee4FEqdHz5RPUjJncyjU+EJs7hsStP /pqlXCOzf+8q0PTGrwlX0J3sKVIQ6Z81A7iL1D4mdoWMtW7aWZR4C7hsKXBo/fJFWQFMNrZL9MH7m QwhxVwcVPGY/cKX4IW/XBE9Antu+62p/LLDpEfJzEdjObBOILQ8xxDgY6H+VpBCzu2ek3CWXUE6vF yTr73EKb+fWFZYUtCpow==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jjdpy-0005ix-79; Fri, 12 Jun 2020 07:10:50 +0000 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jjdph-0005M9-B1 for linux-riscv@lists.infradead.org; Fri, 12 Jun 2020 07:10:35 +0000 Received: by mail-pl1-x643.google.com with SMTP id j4so133755plk.3 for ; Fri, 12 Jun 2020 00:10:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oxY+GEGW58gRs4X3wAEY9YflVh8sZNhuS06ZzQHTlOU=; b=bYf2ca0prWH5VkCAX0BKWaVwimC2C3YOvMCg9eNTbmfw5UDY5oRv2hJTZOzZJiNXJ/ UydYZv2pwrhTdIfN8BHiou4PGeBuPiO7qwYweHfxT3aDxNh+gnBnCDkcy5aaEQq8Cejo mjIwKOtzvVlCUrgnR6MiquRuDwa/j4kt6TjBT1PML91QcxFW14HZxgiKTd33+Wj2UxMY eq0+yuFXbRtJHt+wgG10k5i01wHnW8b8H6LbcTRxAcIwA18Jv13+k9miBGj9XEPtMUtD pSaxRemoysoyJ8dQXZM5UH1nQD8SKPa+6H4dGCBFwIEPeQ+TA3A5S3+E5Wd+jSRUKspJ ehmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oxY+GEGW58gRs4X3wAEY9YflVh8sZNhuS06ZzQHTlOU=; b=iDdl/NrI7rfyrVZR/1+oNuAAqfeqXEsnKk+7UNp/x0cx6vQTl4CPBMCElJ9lbZIh8F u8dOE4PS4dxqqxEsEp9bjgf5kEcrF/UpFSvlWuYGuLxpYvavb1Jlqna3FzqfCroW37Sj BDY7JuAvvj1Do8t5RRdjvZTwKiQQhTDcQoctElG4AKIGqvK6+7r1ZdOyqMzI49qvwgyk 2KJylRofXIiaDBclJ+avPhDSC24x+hCLKeFn6KQ/v3hvPkZ79XZnFId6KdU78AN8C0N1 1HgfxAYsX+6xlxcR9LaPc8d/5lOr9kLRM7Zpa2y66Fn0sCgMWf5HwlOXKvuHis+Ddydw YH6g== X-Gm-Message-State: AOAM53282IMSurZNqV7GU0cdI4O3e9cgq2DbovbCr/HeDS8HVPFS+NKu KGbI02E1NaexgaVPVGQu4jF0Og== X-Google-Smtp-Source: ABdhPJyFG6z1DGdSbNi4UEz2b4RML3S9N58L5su0dAAyi8LgzJF1AKeDdZV2+FRyX3g2Ij4kQtmORg== X-Received: by 2002:a17:90a:ae11:: with SMTP id t17mr12268990pjq.157.1591945832518; Fri, 12 Jun 2020 00:10:32 -0700 (PDT) Received: from hsinchu02.internal.sifive.com (114-34-229-221.HINET-IP.hinet.net. [114.34.229.221]) by smtp.gmail.com with ESMTPSA id d2sm4336919pgp.56.2020.06.12.00.10.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jun 2020 00:10:32 -0700 (PDT) From: Greentime Hu To: greentime.hu@sifive.com, oleg@redhat.com, guoren@linux.alibaba.com, vincent.chen@sifive.com, paul.walmsley@sifive.com, palmerdabbelt@google.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 10/13] riscv: Add task switch support for vector Date: Fri, 12 Jun 2020 15:09:59 +0800 Message-Id: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200612_001033_458020_9B0A202F X-CRM114-Status: GOOD ( 17.63 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:643 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Nick Knight Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org This patch adds task switch support for vector. It supports lazy save and restore mechanism. It also supports all lengths of vlen. [guoren@linux.alibaba.com: First available porting to support vector context switching] [nick.knight@sifive.com: Rewrite vector.S to support dynamic vlen, xlen and code refine] Signed-off-by: Nick Knight Signed-off-by: Greentime Hu Signed-off-by: Guo Ren --- arch/riscv/include/asm/switch_to.h | 71 +++++++++++++++++++++++++ arch/riscv/kernel/Makefile | 1 + arch/riscv/kernel/process.c | 40 ++++++++++++++ arch/riscv/kernel/vector.S | 84 ++++++++++++++++++++++++++++++ 4 files changed, 196 insertions(+) create mode 100644 arch/riscv/kernel/vector.S diff --git a/arch/riscv/include/asm/switch_to.h b/arch/riscv/include/asm/switch_to.h index b9234e7178d0..a047dd75e09d 100644 --- a/arch/riscv/include/asm/switch_to.h +++ b/arch/riscv/include/asm/switch_to.h @@ -6,10 +6,12 @@ #ifndef _ASM_RISCV_SWITCH_TO_H #define _ASM_RISCV_SWITCH_TO_H +#include #include #include #include #include +#include #ifdef CONFIG_FPU extern void __fstate_save(struct task_struct *save_to); @@ -63,6 +65,73 @@ extern bool has_fpu; #define __switch_to_fpu(__prev, __next) do { } while (0) #endif +#ifdef CONFIG_VECTOR +extern bool has_vector; +extern unsigned long riscv_vsize; +extern void __vstate_save(struct __riscv_v_state *save_to, void *datap); +extern void __vstate_restore(struct __riscv_v_state *restore_from, void *datap); + +static inline void __vstate_clean(struct pt_regs *regs) +{ + regs->status = (regs->status & ~(SR_VS)) | SR_VS_CLEAN; +} + +static inline void vstate_off(struct task_struct *task, + struct pt_regs *regs) +{ + regs->status = (regs->status & ~SR_VS) | SR_VS_OFF; +} + +static inline void vstate_save(struct task_struct *task, + struct pt_regs *regs) +{ + if ((regs->status & SR_VS) == SR_VS_DIRTY) { + struct __riscv_v_state *vstate = &(task->thread.vstate); + + /* Allocate space for vector registers. */ + if (!vstate->datap) { + vstate->datap = kzalloc(riscv_vsize, GFP_KERNEL); + vstate->size = riscv_vsize; + } + __vstate_save(vstate, vstate->datap); + __vstate_clean(regs); + } +} + +static inline void vstate_restore(struct task_struct *task, + struct pt_regs *regs) +{ + if ((regs->status & SR_VS) != SR_VS_OFF) { + struct __riscv_v_state *vstate = &(task->thread.vstate); + + /* Allocate space for vector registers. */ + if (!vstate->datap) { + vstate->datap = kzalloc(riscv_vsize, GFP_KERNEL); + vstate->size = riscv_vsize; + } + __vstate_restore(vstate, vstate->datap); + __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); + if (unlikely(regs->status & SR_SD)) + vstate_save(prev, regs); + vstate_restore(next, task_pt_regs(next)); +} + +#else +#define has_vector false +#define vstate_save(task, regs) do { } while (0) +#define vstate_restore(task, regs) do { } while (0) +#define __switch_to_vector(__prev, __next) do { } while (0) +#endif + extern struct task_struct *__switch_to(struct task_struct *, struct task_struct *); @@ -72,6 +141,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/kernel/Makefile b/arch/riscv/kernel/Makefile index 86c83081044f..dee489a1a526 100644 --- a/arch/riscv/kernel/Makefile +++ b/arch/riscv/kernel/Makefile @@ -33,6 +33,7 @@ obj-$(CONFIG_MMU) += vdso.o vdso/ obj-$(CONFIG_RISCV_M_MODE) += clint.o traps_misaligned.o obj-$(CONFIG_FPU) += fpu.o +obj-$(CONFIG_VECTOR) += vector.o obj-$(CONFIG_SMP) += smpboot.o obj-$(CONFIG_SMP) += smp.o obj-$(CONFIG_SMP) += cpu_ops.o diff --git a/arch/riscv/kernel/process.c b/arch/riscv/kernel/process.c index 610c11e91606..fc8761c04e9f 100644 --- a/arch/riscv/kernel/process.c +++ b/arch/riscv/kernel/process.c @@ -76,6 +76,16 @@ void start_thread(struct pt_regs *regs, unsigned long pc, */ fstate_restore(current, regs); } + + if (has_vector) { + regs->status |= SR_VS_INITIAL; + /* + * Restore the initial value to the vector register + * before starting the user program. + */ + vstate_restore(current, regs); + } + regs->epc = pc; regs->sp = sp; set_fs(USER_DS); @@ -92,15 +102,45 @@ void flush_thread(void) fstate_off(current, task_pt_regs(current)); memset(¤t->thread.fstate, 0, sizeof(current->thread.fstate)); #endif +#ifdef CONFIG_VECTOR + /* Reset vector state */ + vstate_off(current, task_pt_regs(current)); + memset(¤t->thread.vstate, 0, sizeof(current->thread.vstate)); +#endif } int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src) { fstate_save(src, task_pt_regs(src)); + if (has_vector) + /* To make sure every dirty vector context is saved. */ + vstate_save(src, task_pt_regs(src)); *dst = *src; + if (has_vector) { + /* Copy vector context to the forked task from parent. */ + if ((task_pt_regs(src)->status & SR_VS) != SR_VS_OFF) { + unsigned long size = src->thread.vstate.size; + + dst->thread.vstate.datap = kzalloc(size, GFP_KERNEL); + /* Failed to allocate memory. */ + if (!dst->thread.vstate.datap) + return -ENOMEM; + /* Copy the src vector context to dst. */ + memcpy(dst->thread.vstate.datap, + src->thread.vstate.datap, size); + } + } + return 0; } +void arch_release_task_struct(struct task_struct *tsk) +{ + /* Free the vector context of datap. */ + if (has_vector) + kfree(tsk->thread.vstate.datap); +} + int copy_thread_tls(unsigned long clone_flags, unsigned long usp, unsigned long arg, struct task_struct *p, unsigned long tls) { diff --git a/arch/riscv/kernel/vector.S b/arch/riscv/kernel/vector.S new file mode 100644 index 000000000000..4c880b1c32aa --- /dev/null +++ b/arch/riscv/kernel/vector.S @@ -0,0 +1,84 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2012 Regents of the University of California + * Copyright (C) 2017 SiFive + * Copyright (C) 2019 Alibaba Group Holding Limited + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, version 2. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include + +#include +#include +#include + +#define vstatep a0 +#define datap a1 +#define x_vstart t0 +#define x_vtype t1 +#define x_vl t2 +#define x_vcsr t3 +#define incr t4 +#define m_one t5 +#define status t6 + +ENTRY(__vstate_save) + li status, SR_VS + csrs sstatus, status + + csrr x_vstart, CSR_VSTART + csrr x_vtype, CSR_VTYPE + csrr x_vl, CSR_VL + csrr x_vcsr, CSR_VCSR + li m_one, -1 + vsetvli incr, m_one, e8, m8 + vse8.v v0, (datap) + add datap, datap, incr + vse8.v v8, (datap) + add datap, datap, incr + vse8.v v16, (datap) + add datap, datap, incr + vse8.v v24, (datap) + + REG_S x_vstart, RISCV_V_STATE_VSTART(vstatep) + REG_S x_vtype, RISCV_V_STATE_VTYPE(vstatep) + REG_S x_vl, RISCV_V_STATE_VL(vstatep) + REG_S x_vcsr, RISCV_V_STATE_VCSR(vstatep) + + csrc sstatus, status + ret +ENDPROC(__vstate_save) + +ENTRY(__vstate_restore) + li status, SR_VS + csrs sstatus, status + + li m_one, -1 + vsetvli incr, m_one, e8, m8 + vle8.v v0, (datap) + add datap, datap, incr + vle8.v v8, (datap) + add datap, datap, incr + vle8.v v16, (datap) + add datap, datap, incr + vle8.v v24, (datap) + + REG_L x_vstart, RISCV_V_STATE_VSTART(vstatep) + REG_L x_vtype, RISCV_V_STATE_VTYPE(vstatep) + REG_L x_vl, RISCV_V_STATE_VL(vstatep) + REG_L x_vcsr, RISCV_V_STATE_VCSR(vstatep) + vsetvl x0, x_vl, x_vtype + csrw CSR_VSTART, x_vstart + csrw CSR_VCSR, x_vcsr + + csrc sstatus, status + ret +ENDPROC(__vstate_restore) From patchwork Fri Jun 12 07:10:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greentime Hu X-Patchwork-Id: 11601351 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EE2FB14B7 for ; Fri, 12 Jun 2020 07:10:55 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id CBC72207D8 for ; Fri, 12 Jun 2020 07:10:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="uhZApzYj"; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="lzm/7SHi" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CBC72207D8 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To: Cc:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=A2QaBTJhBJQRzylOX9vPhPzTgEPwvSh2CxTZj+1fI78=; b=uhZApzYjlbtPU9oCM3VHICgFA2 4I4c93vWZmpQNVecYfu4Li5yeD3cBRCINdUXdegCUAFr/sj8Y+PH1kYNwOKU55k5vjNiISaC4O/ZG sx3SDXj69g7cej6EIum8NQl14IOvjK5RQy/CQBaflIB93rrXMcmMYLvfL4otxNmEWw6yp6Fu0b+hz Aa78bci0XJwjNFcv7qAN4/Hqi24Ba4UNJnfj9fIXaj6G45/AWIgvSdu15I/4Kc0Yjl1Cx6IBj9/fl CO/6SZys96gIDFHoUO69Zlpoeo9lvK0LokVEbK7qHzbvDb8VbaDadls6O+D9LVn830IzLGcvhRKKX QD/qpM7Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jjdq0-0005mV-LC; Fri, 12 Jun 2020 07:10:52 +0000 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jjdpj-0005Oj-9S for linux-riscv@lists.infradead.org; Fri, 12 Jun 2020 07:10:37 +0000 Received: by mail-pl1-x641.google.com with SMTP id k1so3285888pls.2 for ; Fri, 12 Jun 2020 00:10:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=A2QaBTJhBJQRzylOX9vPhPzTgEPwvSh2CxTZj+1fI78=; b=lzm/7SHi4Y2LnyTA2A6iUc8tChivg1S6hfjql+7CInfU7VGpxRokFhUHYMnD8+Wi91 ctpVZi3Rn9n6ZrzfRbrfTLRxG1DorH3KDQrEWyhdGpOZpg414iGAyH8q+vT64LqlgLwY aRBMLWzD2ce9ZQJ5LbdubChokm0OqeOeklDcc10mRMUO/SVoR1PT5nI58TZm8JRTOPdK qtwfn78qSOYNsOC8XPIX08/SLIY03WtsZfThrWRmErGEFoBydRpxcNK8y9/HlTABJspM V0OIZiy+xSK37sJlqwy4MLNvhX09bUHvwuoZKk76m7a/+Tyu2Xm0IJ+HHWqH1iZRudDU IlwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=A2QaBTJhBJQRzylOX9vPhPzTgEPwvSh2CxTZj+1fI78=; b=UKgBdtXEn1dJziKf+MkSuVAZyBIK6XMZVLOZtCGq7zUNoTvcjZJ+Tg8cdLb18YDeSf HjM7cBVvabtJKUDkZRs9JGL+hJ/QOwqx7V/3y4gIig/qexm/E4oiq/rhA7TJF9wyKPW4 ve8DDgOibGVRlN9j4bIWbYZzSof5hssqu7Rdz6t0732pJW1JAdFU0jpygQjSBLXliWjz vXoh7bUB6/p8g4PfaF6xzuuhm5Iyz0UnW0rQxGIL0lJ1MG+nijN1/hKDKfAOpZrfgcK1 4gpucCQZFBjGH1z7xHL2XVQg1z79XriYvhiU2GsOnFLOMDyUFjoUj+/UXtLYooRDSnOd s0bA== X-Gm-Message-State: AOAM533erVgfzRo8LmpcOs6su5GoUMVFlLE/xMa/nSCM7FZpIwXRajhH LOF+Jwjlme5qcllfVYJJmdrU4A== X-Google-Smtp-Source: ABdhPJyoKYtGQArQjTuuVyk6DTQSNswCQAgwB0evJSXQ5wo1oNwLXoJhzMrYI9PQQTF4Yt6WX7vQ+A== X-Received: by 2002:a17:902:8342:: with SMTP id z2mr10294966pln.300.1591945834535; Fri, 12 Jun 2020 00:10:34 -0700 (PDT) Received: from hsinchu02.internal.sifive.com (114-34-229-221.HINET-IP.hinet.net. [114.34.229.221]) by smtp.gmail.com with ESMTPSA id d2sm4336919pgp.56.2020.06.12.00.10.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jun 2020 00:10:34 -0700 (PDT) From: Greentime Hu To: greentime.hu@sifive.com, oleg@redhat.com, guoren@linux.alibaba.com, vincent.chen@sifive.com, paul.walmsley@sifive.com, palmerdabbelt@google.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 11/13] riscv: Add ptrace vector support Date: Fri, 12 Jun 2020 15:10:00 +0800 Message-Id: <32bf683f9e25b3dd291edd77cc9a75c7bac07e88.1591344965.git.greentime.hu@sifive.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200612_001035_357233_48974784 X-CRM114-Status: GOOD ( 15.64 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:641 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org This patch adds ptrace support for riscv vector. The vector registers will be saved in datap pointer of __riscv_v_state. This pointer will be set right after the __riscv_v_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. [guoren@linux.alibaba.com: Add the first version porting to support vector of ptrace] Signed-off-by: Greentime Hu Signed-off-by: Guo Ren --- arch/riscv/include/uapi/asm/elf.h | 1 + arch/riscv/kernel/ptrace.c | 114 ++++++++++++++++++++++++++++++ include/uapi/linux/elf.h | 1 + 3 files changed, 116 insertions(+) diff --git a/arch/riscv/include/uapi/asm/elf.h b/arch/riscv/include/uapi/asm/elf.h index d696d6610231..099434d075a7 100644 --- a/arch/riscv/include/uapi/asm/elf.h +++ b/arch/riscv/include/uapi/asm/elf.h @@ -23,6 +23,7 @@ typedef struct user_regs_struct elf_gregset_t; typedef __u64 elf_fpreg_t; typedef union __riscv_fp_state elf_fpregset_t; #define ELF_NFPREG (sizeof(struct __riscv_d_ext_state) / sizeof(elf_fpreg_t)) +#define ELF_NVREG (sizeof(struct __riscv_v_state) / sizeof(elf_greg_t)) #if __riscv_xlen == 64 #define ELF_RISCV_R_SYM(r_info) ELF64_R_SYM(r_info) diff --git a/arch/riscv/kernel/ptrace.c b/arch/riscv/kernel/ptrace.c index 444dc7b0fd78..b5b83260e674 100644 --- a/arch/riscv/kernel/ptrace.c +++ b/arch/riscv/kernel/ptrace.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -26,6 +27,9 @@ enum riscv_regset { #ifdef CONFIG_FPU REGSET_F, #endif +#ifdef CONFIG_VECTOR + REGSET_V, +#endif }; static int riscv_gpr_get(struct task_struct *target, @@ -92,6 +96,106 @@ static int riscv_fpr_set(struct task_struct *target, } #endif +#ifdef CONFIG_VECTOR +static int riscv_vr_get(struct task_struct *target, + const struct user_regset *regset, + unsigned int pos, unsigned int count, + void *kbuf, void __user *ubuf) +{ + int ret; + struct __riscv_v_state *vstate = &target->thread.vstate; + /* Set the datap right after the address of vstate. */ + void *datap = ubuf + sizeof(struct __riscv_v_state); + u32 magic = RVV_MAGIC; + + /* Copy the magic number. */ + ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &magic, 0, + sizeof(u32)); + if (unlikely(ret)) + return ret; + + /* Copy rest of vstate except datap. */ + ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, vstate, 0, + RISCV_V_STATE_DATAP); + if (unlikely(ret)) + return ret; + + /* Copy the pointer datap itself. */ + pos = 0; + ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &datap, 0, + sizeof(vstate->datap)); + if (unlikely(ret)) + return ret; + +#if __riscv_xlen == 32 + /* Skip copy _padding. */ + count -= sizeof(vstate->__padding); + ubuf += sizeof(vstate->__padding); +#endif + + /* Copy all the vector registers. */ + pos = 0; + ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, + vstate->datap, 0, vstate->size); + return ret; +} + +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_state *vstate = &target->thread.vstate; + const void *datap = ubuf + sizeof(struct __riscv_v_state); + const void *datap_addr = ubuf + RISCV_V_STATE_DATAP; + long val_datap; + + /* Skip copy magic because kernel doesn't need to use it. */ + size = sizeof(vstate->magic); + pos += size; + count -= size; + ubuf += size; + + /* Copy rest of the vstate except datap and __padding. */ + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, vstate, 0, + RISCV_V_STATE_DATAP); + if (unlikely(ret)) + return ret; + + /* Check if the datap is correct address of ubuf. */ + __get_user(val_datap, (long *)datap_addr); + if (val_datap != (long)datap) + return -EFAULT; + + /* Skip copy datap. */ + size = sizeof(vstate->datap); + count -= size; + ubuf += size; + +#if __riscv_xlen == 32 + /* Skip copy _padding. */ + size = sizeof(vstate->__padding); + count -= size; + ubuf += size; +#endif + + /* Copy all the vector registers. */ + pos = 0; + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, vstate->datap, + 0, vstate->size); + return ret; +} +static unsigned int riscv_vr_get_size(struct task_struct *target, + const struct user_regset *regset) +{ + if (!has_vector) + return 0; + + return sizeof(struct __riscv_v_state) + riscv_vsize; +} +#endif + static const struct user_regset riscv_user_regset[] = { [REGSET_X] = { .core_note_type = NT_PRSTATUS, @@ -111,6 +215,16 @@ static const struct user_regset riscv_user_regset[] = { .set = &riscv_fpr_set, }, #endif +#ifdef CONFIG_VECTOR + [REGSET_V] = { + .core_note_type = NT_RISCV_VECTOR, + .align = 16, + .size = sizeof(unsigned long), + .get = riscv_vr_get, + .set = riscv_vr_set, + .get_size = riscv_vr_get_size, + }, +#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 34c02e4290fe..e428f9e8710a 100644 --- a/include/uapi/linux/elf.h +++ b/include/uapi/linux/elf.h @@ -428,6 +428,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 */ /* Note header in a PT_NOTE section */ typedef struct elf32_note { From patchwork Fri Jun 12 07:10:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greentime Hu X-Patchwork-Id: 11601353 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8464D138C for ; Fri, 12 Jun 2020 07:11:01 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 4B88C207D8 for ; Fri, 12 Jun 2020 07:11:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="tJAdZShP"; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="YPopjf7B" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4B88C207D8 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To: Cc:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=P9Pa9sX2hCWEpSvVJf+FpLMUkYZkkhyDVpp3YBSMMho=; b=tJAdZShP9WOAEtWPCHvumm5XZ4 Md7nJNuqdPEKeptyYx9Nw4tZVI9Otk0IzgLSW+iD0car36na4CKeNO8N1Iwcy8EJbN8B3P/UrCYGE 0pYULdy/34KRo3DOt2E5wwTg+fKlMt4iqVg2qK/X5BilO1i68c52BweBDBrSJEIoppPwbUEQnrZD2 rAn7A5I7kw0Q9K4V0rAXUv8ITHAdyH48YxYZ4ctmQmEKhZHfTnKAN5VLiXVthL9bVnhITRDHNWitJ tPvs4yU+dTwSlg4EP1vktmZKvW3zWIQSR/65ZcNaC9ay8we6pq38ehEDAdKngIphSUYnkD2ZZI9Vi +5tKgCSw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jjdq4-0005rc-Cf; Fri, 12 Jun 2020 07:10:56 +0000 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jjdpl-0005Qu-7b for linux-riscv@lists.infradead.org; Fri, 12 Jun 2020 07:10:39 +0000 Received: by mail-pf1-x442.google.com with SMTP id h185so3885245pfg.2 for ; Fri, 12 Jun 2020 00:10:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=P9Pa9sX2hCWEpSvVJf+FpLMUkYZkkhyDVpp3YBSMMho=; b=YPopjf7BjgfR9P6MH2P5gmjjphEm5PftEMUk4KVtGergK6VXmdMIvx8AbuVSTla928 Pyk7F+QztXyTZr2LFXm+lhPMTgPxHj/w5rLH2FkDJ6DCT3M4KfifnsIBHl98QJMk8kPL aaYxBV6sXMijkd2fNrlTv5/gyEYQZmKNnFi6m50G43UohbFWL+/TZHCNbmC4UNXrA8fC Vbk5pN6LQsWxIK0jxq/hpdlswusFQZyG8PXy4JKC0hTn9QbE+fX6s2MHpzfW48YtXKDy t/j4SQPEkhRrXsZnwHKxPmosWimYFMBJaOKDggmdjJPzFNZrLzdhPFfeM7EdkOwotr8i nE5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=P9Pa9sX2hCWEpSvVJf+FpLMUkYZkkhyDVpp3YBSMMho=; b=pErUuEcHn0dain432kWcDqMjIp3AmZURyrGxCSZEiz9z42jIysHmW4/CccpSqvEb1D YIe6xCQqnZR9XJJLfaEUcE2LljiGkPnfOQEotVxyV6QZ/9nTlRiKxb0cecS8/jkLRtHv erJ79UkpQGUxPEsH3v90ul0OEOVqM90lRFHlyLooHUejB1ITFpvLr+uDQ2K7efBidRjf zoNdsb9iTSSXC0eL2fR2ndjANz8qKG8DNFvIYDHM6O8vJ/g19g/lFr1r8nuqD/vrt66u IoaORdmkEwOEYlKcf7Z7w1cW0tQ5Q38kybpRF7EFJbv1ZgIcgJLeVUlTRaweHsOVpfxv 5CQQ== X-Gm-Message-State: AOAM531tCkPuyr9hFKoYRW7ZPLpH8GAL1j69u2UG33gzyO20atlyFxVF 9YwPcF0H6Me8IwbQrHAjRUUmTQ== X-Google-Smtp-Source: ABdhPJzsRw6oDxsMkoH09iu+rTk7MoFSiqjbxsoMOkY49g2MoPX+b/PCxGziRX2lD3N4N5swVaZc2w== X-Received: by 2002:a63:235c:: with SMTP id u28mr9409667pgm.278.1591945836587; Fri, 12 Jun 2020 00:10:36 -0700 (PDT) Received: from hsinchu02.internal.sifive.com (114-34-229-221.HINET-IP.hinet.net. [114.34.229.221]) by smtp.gmail.com with ESMTPSA id d2sm4336919pgp.56.2020.06.12.00.10.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jun 2020 00:10:36 -0700 (PDT) From: Greentime Hu To: greentime.hu@sifive.com, oleg@redhat.com, guoren@linux.alibaba.com, vincent.chen@sifive.com, paul.walmsley@sifive.com, palmerdabbelt@google.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 12/13] riscv: Add sigcontext save/restore for vector Date: Fri, 12 Jun 2020 15:10:01 +0800 Message-Id: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200612_001037_326928_0356F3FC X-CRM114-Status: GOOD ( 11.23 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:442 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org This patch adds sigcontext save/restore for vector. The vector registers will be saved in datap pointer. The datap pointer will be allocaed dynamically when the task needs in kernel space. The datap pointer will be set right after the __riscv_v_state data structure to save all the vector registers in the signal handler stack. [guoren@linux.alibaba.com: add the first porting for vector signal and sigcontext support] Signed-off-by: Greentime Hu Signed-off-by: Guo Ren --- arch/riscv/include/uapi/asm/sigcontext.h | 2 + arch/riscv/kernel/signal.c | 92 +++++++++++++++++++++++- 2 files changed, 91 insertions(+), 3 deletions(-) diff --git a/arch/riscv/include/uapi/asm/sigcontext.h b/arch/riscv/include/uapi/asm/sigcontext.h index 84f2dfcfdbce..4217f3f1c8ba 100644 --- a/arch/riscv/include/uapi/asm/sigcontext.h +++ b/arch/riscv/include/uapi/asm/sigcontext.h @@ -8,6 +8,7 @@ #include +#define RVV_MAGIC 0x53465457 /* * Signal context structure * @@ -17,6 +18,7 @@ struct sigcontext { struct user_regs_struct sc_regs; union __riscv_fp_state sc_fpregs; + struct __riscv_v_state sc_vregs; }; #endif /* _UAPI_ASM_RISCV_SIGCONTEXT_H */ diff --git a/arch/riscv/kernel/signal.c b/arch/riscv/kernel/signal.c index 17ba190e84a5..9ada6f74bb95 100644 --- a/arch/riscv/kernel/signal.c +++ b/arch/riscv/kernel/signal.c @@ -83,6 +83,80 @@ static long save_fp_state(struct pt_regs *regs, #define restore_fp_state(task, regs) (0) #endif +#ifdef CONFIG_VECTOR +static long restore_v_state(struct pt_regs *regs, struct sigcontext *sc) +{ + long err; + struct __riscv_v_state __user *state = &sc->sc_vregs; + void *datap; + __u32 magic; + + /* Get magic number and check it. */ + err = __get_user(magic, &state->magic); + if (unlikely(err)) + return err; + + if (magic != RVV_MAGIC) + return -EINVAL; + + /* Copy everything of __riscv_v_state except datap. */ + err = __copy_from_user(¤t->thread.vstate, state, + RISCV_V_STATE_DATAP); + if (unlikely(err)) + return err; + + /* Copy the pointer datap itself. */ + err = __get_user(datap, &state->datap); + if (unlikely(err)) + return err; + + + /* Copy the whole vector content from user space datap. */ + err = __copy_from_user(current->thread.vstate.datap, datap, + current->thread.vstate.size); + if (unlikely(err)) + return err; + + vstate_restore(current, regs); + + return err; +} + +static long save_v_state(struct pt_regs *regs, struct sigcontext *sc) +{ + long err; + struct __riscv_v_state __user *state = &sc->sc_vregs; + /* Set the datap right after the sigcntext structure. */ + void *datap = sc + 1; + + vstate_save(current, regs); + /* Copy everything of vstate but datap. */ + err = __copy_to_user(state, ¤t->thread.vstate, + RISCV_V_STATE_DATAP); + if (unlikely(err)) + return err; + + /* Copy the magic number. */ + err = __put_user(RVV_MAGIC, &state->magic); + if (unlikely(err)) + return err; + + /* Copy the pointer datap itself. */ + err = __put_user(datap, &state->datap); + if (unlikely(err)) + return err; + + /* Copy the whole vector content to user space datap. */ + err = __copy_to_user(datap, current->thread.vstate.datap, + current->thread.vstate.size); + + 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) { @@ -92,6 +166,9 @@ static long restore_sigcontext(struct pt_regs *regs, /* Restore the floating-point state. */ if (has_fpu) err |= restore_fp_state(regs, &sc->sc_fpregs); + /* Restore the vector state. */ + if (has_vector) + err |= restore_v_state(regs, sc); return err; } @@ -101,13 +178,16 @@ SYSCALL_DEFINE0(rt_sigreturn) struct rt_sigframe __user *frame; struct task_struct *task; sigset_t set; + size_t frame_size = sizeof(*frame); /* 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 (has_vector) + frame_size += current->thread.vstate.size; + if (!access_ok(frame, frame_size)) goto badframe; if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) @@ -145,6 +225,9 @@ static long setup_sigcontext(struct rt_sigframe __user *frame, /* Save the floating-point state. */ if (has_fpu) err |= save_fp_state(regs, &sc->sc_fpregs); + /* Save the vector state. */ + if (has_vector) + err |= save_v_state(regs, sc); return err; } @@ -176,9 +259,12 @@ static int setup_rt_frame(struct ksignal *ksig, sigset_t *set, { struct rt_sigframe __user *frame; long err = 0; + size_t frame_size = sizeof(*frame); - frame = get_sigframe(ksig, regs, sizeof(*frame)); - if (!access_ok(frame, sizeof(*frame))) + if (has_vector) + frame_size += current->thread.vstate.size; + frame = get_sigframe(ksig, regs, frame_size); + if (!access_ok(frame, frame_size)) return -EFAULT; err |= copy_siginfo_to_user(&frame->info, &ksig->info); From patchwork Fri Jun 12 07:10:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greentime Hu X-Patchwork-Id: 11601355 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 22909912 for ; Fri, 12 Jun 2020 07:11:02 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id F413B207D8 for ; Fri, 12 Jun 2020 07:11:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="j1cDRGCQ"; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="cwKOxHAe" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F413B207D8 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To: Cc:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=ExzTv3ZkZVen5FhxnWerxBjdzkt+ghuUco0ZAfafnJw=; b=j1cDRGCQ6pYW2oqmCTYSZ/sTE7 km4DW1MZo9CmN/r7OyyZEog+dlTiOr27A+7y73Qmepeu/v24FcZCFHHCBTiiBK3ifmX4O4qRYwkAM 335i4AKktrTPw4UPAocRev94gbtCsLIk2YuNgn0YUPr6VNqwWUpvNrZh/XilpaluxPR9qodaqjfZP zGx/Vyo07vsR0MCQrOdxWi/NX5Gnhgcp9Pw4Eg6vYAq9VX8zWibEEMAiXyifENbUnZNkmNVN5VlSb 9hq5f9Nmu4uocR3p60dTxW0TkpqU8wxONIjtnvFkmd/MDwpJD87vvpw129ogjswpJwk/W33EAx9Tj IgQqiGuQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jjdq7-0005w7-CZ; Fri, 12 Jun 2020 07:10:59 +0000 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jjdpn-0005TK-5t for linux-riscv@lists.infradead.org; Fri, 12 Jun 2020 07:10:40 +0000 Received: by mail-pl1-x644.google.com with SMTP id j4so133842plk.3 for ; Fri, 12 Jun 2020 00:10:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=ExzTv3ZkZVen5FhxnWerxBjdzkt+ghuUco0ZAfafnJw=; b=cwKOxHAe99ZMwtzUWEEjI6Dys+A9NSr9KO59dHNuuuyKEu3c/VQhZfNJkSmzBysEg2 o8jAHEQDBFsXubzXYnN1IJ9oedPCTzedeW4/E217vaIBl4A99Adj0W17b0sRWFSDZZdz EheWkL9Mwk8E78ynURMpkyfBtLteB8J3FhdIhC0CBFjyKVS1IRXJC/sajcjEoq+4vl7T GQiZiW8E4gxcETU24vijqPJbqyz8I2qCfp2TogdxPb1KZ2iUeT2ZpZWgU0Sjej4ZeLGf e+B02bk9GuH30Hk3QDQ0h+qvZXIxxlFe3ViVIS5CtJJ0l0MiL83hXF8L9GKC7pWpz0VC Y5Ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ExzTv3ZkZVen5FhxnWerxBjdzkt+ghuUco0ZAfafnJw=; b=FW3GpKSvR3pUHnmlQG2BLxA5DNCsWreW8Wb6QqxDctiFmwju4wXd1+Zq8SkGZVi8wY bXDwLn40Z03h8SxSKlUAJrlPyx8SV8w8RccjEAnD4mnNX43uRin+fJAVCyhh3X0wq8NM 8PR/3jklyyyDMPOufRYCshAfdTD/2DxA/JBBPWXlkLHr4F0RPLwRdUp7l758jHABIkbD EeG+OGgzBVUwwjK9U/FRPPpeNWjilG0aiXetQhsx8NK8LGtKnoKEw73IocDN1ZCDnC+P ZNycaQlB8FhKOPTuHL6gx4heypaJzZH1syrxSKgJWrl/jnlJuBrNM4MF4IFEKRRBYYYs 0KvA== X-Gm-Message-State: AOAM532zXLkKYAC1vCyEJV6O2nLtGGnevrSnXsr2oM8F1Przuq1wGgIl HLATaRsfr6BDs24uE/p6uoMJFA== X-Google-Smtp-Source: ABdhPJzDg6V83DZh/Z6VDxkVqWFHImz9fQIlhPx6VLCrIYP/KpY/gBOfiZoJoAs6a2sgDex53/jCzw== X-Received: by 2002:a17:90a:a40b:: with SMTP id y11mr12358468pjp.54.1591945838626; Fri, 12 Jun 2020 00:10:38 -0700 (PDT) Received: from hsinchu02.internal.sifive.com (114-34-229-221.HINET-IP.hinet.net. [114.34.229.221]) by smtp.gmail.com with ESMTPSA id d2sm4336919pgp.56.2020.06.12.00.10.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jun 2020 00:10:38 -0700 (PDT) From: Greentime Hu To: greentime.hu@sifive.com, oleg@redhat.com, guoren@linux.alibaba.com, vincent.chen@sifive.com, paul.walmsley@sifive.com, palmerdabbelt@google.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 13/13] riscv: signal: Report signal frame size to userspace via auxv Date: Fri, 12 Jun 2020 15:10:02 +0800 Message-Id: <3871f758564a156b4932a1bde19022edd556baf6.1591344965.git.greentime.hu@sifive.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200612_001039_269271_0525624A X-CRM114-Status: GOOD ( 12.29 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:644 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.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^(XLEN-1). Hence, if userspace refers to the MINSIGSTKSZ #define (2KB) 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. Signed-off-by: Vincent Chen --- arch/riscv/include/asm/elf.h | 17 +++++++++++++---- arch/riscv/include/asm/processor.h | 2 ++ arch/riscv/include/uapi/asm/auxvec.h | 2 ++ arch/riscv/kernel/setup.c | 5 +++++ arch/riscv/kernel/signal.c | 16 ++++++++++++++++ 5 files changed, 38 insertions(+), 4 deletions(-) diff --git a/arch/riscv/include/asm/elf.h b/arch/riscv/include/asm/elf.h index d83a4efd052b..b6b15fc5f784 100644 --- a/arch/riscv/include/asm/elf.h +++ b/arch/riscv/include/asm/elf.h @@ -57,10 +57,19 @@ extern unsigned long elf_hwcap; #define ELF_PLATFORM (NULL) #ifdef CONFIG_MMU -#define ARCH_DLINFO \ -do { \ - NEW_AUX_ENT(AT_SYSINFO_EHDR, \ - (elf_addr_t)current->mm->context.vdso); \ +#define ARCH_DLINFO \ +do { \ + NEW_AUX_ENT(AT_SYSINFO_EHDR, \ + (elf_addr_t)current->mm->context.vdso); \ + /* \ + * 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 217273375cfb..5be2da702897 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 @@ -79,6 +80,7 @@ int riscv_of_processor_hartid(struct device_node *node); extern void riscv_fill_hwcap(void); +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 d86cb17bbabe..9745a01e5e61 100644 --- a/arch/riscv/include/uapi/asm/auxvec.h +++ b/arch/riscv/include/uapi/asm/auxvec.h @@ -10,4 +10,6 @@ /* vDSO location */ #define AT_SYSINFO_EHDR 33 +#define AT_MINSIGSTKSZ 51 + #endif /* _UAPI_ASM_RISCV_AUXVEC_H */ diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c index 145128a7e560..6220e25ea9b0 100644 --- a/arch/riscv/kernel/setup.c +++ b/arch/riscv/kernel/setup.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -62,6 +63,8 @@ void __init parse_dtb(void) #endif } +extern void __init minsigstksz_setup(void); + void __init setup_arch(char **cmdline_p) { init_mm.start_code = (unsigned long) _stext; @@ -95,6 +98,8 @@ void __init setup_arch(char **cmdline_p) #endif riscv_fill_hwcap(); + + minsigstksz_setup(); } static int __init topology_init(void) diff --git a/arch/riscv/kernel/signal.c b/arch/riscv/kernel/signal.c index 9ada6f74bb95..4f81251867e6 100644 --- a/arch/riscv/kernel/signal.c +++ b/arch/riscv/kernel/signal.c @@ -404,3 +404,19 @@ asmlinkage __visible void do_notify_resume(struct pt_regs *regs, tracehook_notify_resume(regs); } } + +unsigned long __ro_after_init signal_minsigstksz; + +/* + * Determine the stack space required for guaranteed signal devliery. + * This function is used to populate AT_MINSIGSTKSZ at process startup. + * cpufeatures setup is assumed to be complete. + */ +void __init minsigstksz_setup(void) +{ + signal_minsigstksz = sizeof(struct rt_sigframe); +#ifdef CONFIG_VECTOR + if (has_vector) + signal_minsigstksz += riscv_vsize; +#endif +}