From patchwork Wed Sep 21 21:43:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Stillson X-Patchwork-Id: 1680848 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=fIXaW39i; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=rivosinc-com.20210112.gappssmtp.com header.i=@rivosinc-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=2Zivm6A/; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MXsWY4yYXz1ypf for ; Thu, 22 Sep 2022 07:49:29 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=FPEI813Mc3aTMbpSNOBbo/Pu9G5NVax54hj+DA73TsM=; b=fIXaW39i+fFgpx HZOUMxWwHUPRzAG1NXSsgW7qfmHHA504rrCASfq7eA6Cd322jKZd8Tqg4XzZ65zLcgvFhWIYhtyK4 0jhzFLAfW+UiBVrXKMIKFlmLa2SsELSruD6NvsambHHSOuZjT6Apuu3sCt7gq4Ah592UttXpKxya8 CeNyOXBh1NZGAA0fH3iohd04OXxYfaQQN//gXVygJr41dWQo7OstahwSdUMFZ4tyXxRkaYx07R/v5 rw03FWQfJvFplrx+6DErOYLfnCUQ8Uz//PE6hIZpGGLah1ebMRlUfNK5f27S91wQhWTkZ0OAdc+Qt Hy3YCrmzd1zkEsX2OP3Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ob7au-00CllM-9H; Wed, 21 Sep 2022 21:49:24 +0000 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ob7ar-00ClkF-77 for kvm-riscv@lists.infradead.org; Wed, 21 Sep 2022 21:49:22 +0000 Received: by mail-pj1-x1033.google.com with SMTP id o99-20020a17090a0a6c00b002039c4fce53so174891pjo.2 for ; Wed, 21 Sep 2022 14:49:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=BvXu+QXgzcKTzY7GQZ6McuBPlZWnkV19grD1UPI3mnI=; b=2Zivm6A/Q9fjuFhqOz4aFrJ4mttfj+vMvGL/use9tWtM+iU/jGsErSU8dXfCdtWfor IUvGbh/ffs6oX/xp2q/MZQ70jVl31CD2HJY3vZAnoiuaQKaxYLcGlpLizNhlN8f3zwjY 1TT2Rm3DicHIEsCYrDfskgMjR5Ir0ddmdvotGyZ058jsMvazNk6LjNTJOypDRvMi2MCX St1FRq+x9do7SRC9girM6Wh4WIG2Tiv/LfyNa/kuAAg6xYIgD70dJNhJuPErOImfOdfd 5KrMTF84K1GmVIndglT2dW+pgBlozWo6kiFuI7G9rXOLRxDc21UPLEGZlNQP0FEwJWpf qHlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=BvXu+QXgzcKTzY7GQZ6McuBPlZWnkV19grD1UPI3mnI=; b=IV49oV2lyb0CFp6k+V94GOW1dxyg5DpiYXYQTMw6KsK1lhc4Eu83rxG3myTUZeAVih 1yxFNefFE/Kerq6Uqz/wPPPprpeSu18+tSt1NpmGuivRkoiUhbjHMMwVnYBjiAKz+MVs RbZYrT4fPIc+SSP+wz3UE8v/gZUiWsKr22BgE401lom9rIXscU3GFPTjwZi3vUsmw7q6 18AhFB0f0964BsuQSuTNtRLXk/48Y9s+WOgP23qtlz4qzFp/4IQdIU9ahcRjWYHDOpwo qKPF8fpUDDmMrU2ZLKrqd6OYe6Iv4hTbPV/02oraYf6+ni28Vj4epNyBtdy1WXnGsZ9e za8Q== X-Gm-Message-State: ACrzQf2ttlaiHqxWqf7UJ2OkJTTe+3UBHJvLppqe9XfWt9R3Kpd8z7Ym theXLSfxuRDqaAbgu9m2RXoMeA== X-Google-Smtp-Source: AMsMyM76gPT3cfpKVZvjavadgnI5fLw75ySqJIfPm57aR3zJCEDVVRM7IcxWkxdKu0/g+KF3ivDAbA== X-Received: by 2002:a17:903:2346:b0:178:4c17:eef7 with SMTP id c6-20020a170903234600b001784c17eef7mr129194plh.30.1663796960633; Wed, 21 Sep 2022 14:49:20 -0700 (PDT) Received: from stillson.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id k7-20020aa79727000000b005484d133127sm2634536pfg.129.2022.09.21.14.49.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Sep 2022 14:49:20 -0700 (PDT) From: Chris Stillson To: Cc: Greentime Hu , Vincent Chen , Paul Walmsley , Palmer Dabbelt , Albert Ou , Eric Biederman , Kees Cook , Anup Patel , Atish Patra , Oleg Nesterov , Guo Ren , Heinrich Schuchardt , Mayuresh Chitale , Conor Dooley , Chris Stillson , Paolo Bonzini , Qinglin Pan , Alexandre Ghiti , Arnd Bergmann , Heiko Stuebner , Dao Lu , Jisheng Zhang , Sunil V L , Han-Kuan Chen , Li Zhengyu , Changbin Du , Ard Biesheuvel , Tsukasa OI , Yury Norov , Nicolas Saenz Julienne , Mark Rutland , "Paul E. McKenney" , Frederic Weisbecker , Vitaly Wool , Myrtle Shah , Nick Knight , Catalin Marinas , Mark Brown , Will Deacon , Jiaxun Yang , Janosch Frank , Alexey Dobriyan , Huacai Chen , Christian Brauner , Andrew Morton , Colin Cross , Eugene Syromiatnikov , Peter Collingbourne , Barret Rhoden , Suren Baghdasaryan , Davidlohr Bueso , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org Subject: [PATCH v12 07/17] riscv: Add vector struct and assembler definitions Date: Wed, 21 Sep 2022 14:43:49 -0700 Message-Id: <20220921214439.1491510-7-stillson@rivosinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220921214439.1491510-1-stillson@rivosinc.com> References: <20220921214439.1491510-1-stillson@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220921_144921_269481_70386947 X-CRM114-Status: GOOD ( 15.25 ) X-Spam-Score: 0.0 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From: Greentime Hu 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. Content analysis details: (0.0 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:1033 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: kvm-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kvm-riscv" Errors-To: kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Greentime Hu 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. Co-developed-by: Vincent Chen Signed-off-by: Vincent Chen Signed-off-by: Greentime Hu --- arch/riscv/include/asm/processor.h | 1 + arch/riscv/include/uapi/asm/ptrace.h | 17 +++++++++++++++++ arch/riscv/kernel/asm-offsets.c | 6 ++++++ 3 files changed, 24 insertions(+) diff --git a/arch/riscv/include/asm/processor.h b/arch/riscv/include/asm/processor.h index 19eedd4af4cd..95917a2b24f9 100644 --- a/arch/riscv/include/asm/processor.h +++ b/arch/riscv/include/asm/processor.h @@ -39,6 +39,7 @@ struct thread_struct { unsigned long s[12]; /* s[0]: frame pointer */ struct __riscv_d_ext_state fstate; unsigned long bad_cause; + struct __riscv_v_state vstate; }; /* Whitelist the fstate from the task_struct for hardened usercopy */ diff --git a/arch/riscv/include/uapi/asm/ptrace.h b/arch/riscv/include/uapi/asm/ptrace.h index 882547f6bd5c..6ee1ca2edfa7 100644 --- a/arch/riscv/include/uapi/asm/ptrace.h +++ b/arch/riscv/include/uapi/asm/ptrace.h @@ -77,6 +77,23 @@ union __riscv_fp_state { struct __riscv_q_ext_state q; }; +struct __riscv_v_state { + unsigned long vstart; + unsigned long vl; + unsigned long vtype; + unsigned long vcsr; + void *datap; + /* + * In signal handler, datap will be set a correct user stack offset + * and vector registers will be copied to the address of datap + * pointer. + * + * In ptrace syscall, datap will be set to zero and the vector + * registers will be copied to the address right after this + * structure. + */ +}; + #endif /* __ASSEMBLY__ */ #endif /* _UAPI_ASM_RISCV_PTRACE_H */ diff --git a/arch/riscv/kernel/asm-offsets.c b/arch/riscv/kernel/asm-offsets.c index df9444397908..37e3e6a8d877 100644 --- a/arch/riscv/kernel/asm-offsets.c +++ b/arch/riscv/kernel/asm-offsets.c @@ -75,6 +75,12 @@ void asm_offsets(void) OFFSET(TSK_STACK_CANARY, task_struct, stack_canary); #endif + 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);