Message ID | 20230629062730.985184-1-bjorn@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp9439938vqr; Wed, 28 Jun 2023 23:47:18 -0700 (PDT) X-Google-Smtp-Source: APBJJlEyuTLgv94gpEoVeZYdbRVTD3TPH0DkFRzKFNDS8aqk53SA4h2zZ83Aj1wvIXPMSdf/4vLH X-Received: by 2002:a17:902:8e8c:b0:1b3:d8ac:8db3 with SMTP id bg12-20020a1709028e8c00b001b3d8ac8db3mr1636396plb.6.1688021238440; Wed, 28 Jun 2023 23:47:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688021238; cv=none; d=google.com; s=arc-20160816; b=ispJ1O/AkybGCKCfOwVtsEtRSmlFAwSIWErcx/+a3Ui9nkHdC9QjL+FBKWJqQiC/km oR56YftYiOk+5uA6kMAO6rza3DxMIbeIH7p5bvCwIZfAj86nIwtah88iPRSgtAeuWJD5 2jRn6Uyx6sUyET+7HENouD8W8IMk3JXIer019O1cW9ezy9KluAr4zcL/opzzQxHBnkZ+ w93w+QuxwcjYRpbJYDi4I4570Kc0LoPSX+bvXPRgujW1BcDN5Lw8NmM4e2O/yURm6S3o OktsysVmULUTAyfMoOCFHz6I8jhBmnAYuS9TgRB+kHTiwJz8SdnuImM3EX5pmwkWNjbB IVgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=qbLWi+8RNVpeq5Qf4axjADrk784JcyyauNjxIzQb0i8=; fh=Lc4xJUxtxPbSXfpuhYZmykIgJInIiT0KA89XVpMZAuY=; b=e0kmkJaCqu2bHgZh52U53NrloUDdlRQ92u+w5ZrFuHkvMQxfLJBCoZ9THJ//f9XCA7 lYh7evUCX4GnipHEcdXcaMcqVb8MRLBcBcsSPvsD/bGrn+a5uEL0Iqg87MVY2I1jZtbV mle+Qlg5SAWMPKxm8+aQ05cdYC6Hjk3bbJ8lLv3CkkVB4Y2cNn42PeASno8P3GS+1fpc c0Ldvz2frTA/JgiN3L8Ud+ZToAUWbppZL/ZHNW9Ie8v7D47j2B+b6bTD5eES6DSVBLmC 1fpiQL4t9Rsvw/992QMstk/fnRLu7tZtlePWPp066JskzOSUyEiwTKhikXag5K+3JnXG ZCpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=cP051lzR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u2-20020a170902bf4200b001b68a92c33asi9792414pls.47.2023.06.28.23.47.05; Wed, 28 Jun 2023 23:47:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=cP051lzR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230523AbjF2G22 (ORCPT <rfc822;ivan.orlov0322@gmail.com> + 99 others); Thu, 29 Jun 2023 02:28:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231981AbjF2G1j (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 29 Jun 2023 02:27:39 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5B2A1B2 for <linux-kernel@vger.kernel.org>; Wed, 28 Jun 2023 23:27:38 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 44733614AC for <linux-kernel@vger.kernel.org>; Thu, 29 Jun 2023 06:27:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 299C7C433C8; Thu, 29 Jun 2023 06:27:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1688020057; bh=YQhuBQ3j9NEc7Bo7uyfWxsU+RoSkYIM6Un+O+o02yNs=; h=From:To:Cc:Subject:Date:From; b=cP051lzRT7C0TFbto2MNtQweDI2SV7bTfB3NWG1Z/1EupqLqJ/CaA3IX1ktNKgb33 YUvDm45rLg6NfT1gpm2ur6hJWTGvVbqUHdrpJ4zXqLIzMhaRk33/HZzkTkxOzRWFK8 42BOLaDhgD1s37sWxWV3TtwtFvyzPm9IBgrhWywoT8pUnD52ECgcBZ/jyzozJSrRIy 4S2S4/JrHdwSe2cvBaARUn/L74WIL58VVxNfB4sb/BIvO3rhlg7Xa29kmeSISaqe/Q BEbbdPW+IcUa+n0ir3tldKu/VDDytX5Ay9l+j3ueELp/hWspZ5J4pYmdy5bZw1IOXS 9DmFiTgRVP/5A== From: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= <bjorn@kernel.org> To: Paul Walmsley <paul.walmsley@sifive.com>, Palmer Dabbelt <palmer@dabbelt.com>, Albert Ou <aou@eecs.berkeley.edu>, linux-riscv@lists.infradead.org, Andy Chiu <andy.chiu@sifive.com> Cc: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= <bjorn@rivosinc.com>, linux-kernel@vger.kernel.org, linux@rivosinc.com, Palmer Dabbelt <palmer@rivosinc.com>, =?utf-8?q?R=C3=A9mi_Denis-Courmont?= <remi@remlab.net>, Darius Rad <darius@bluespec.com> Subject: [PATCH v3] riscv: Discard vector state on syscalls Date: Thu, 29 Jun 2023 08:27:30 +0200 Message-Id: <20230629062730.985184-1-bjorn@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769427069733835730?= X-GMAIL-MSGID: =?utf-8?q?1770018558062993798?= |
Series |
[v3] riscv: Discard vector state on syscalls
|
|
Commit Message
Björn Töpel
June 29, 2023, 6:27 a.m. UTC
From: Björn Töpel <bjorn@rivosinc.com> The RISC-V vector specification states: Executing a system call causes all caller-saved vector registers (v0-v31, vl, vtype) and vstart to become unspecified. The vector registers are set to all 1s, vill is set (invalid), and the vector status is set to Dirty. That way we can prevent userspace from accidentally relying on the stated save. Rémi pointed out [1] that writing to the registers might be superfluous, and setting vill is sufficient. Link: https://lore.kernel.org/linux-riscv/12784326.9UPPK3MAeB@basile.remlab.net/ # [1] Suggested-by: Darius Rad <darius@bluespec.com> Suggested-by: Palmer Dabbelt <palmer@rivosinc.com> Suggested-by: Rémi Denis-Courmont <remi@remlab.net> Signed-off-by: Björn Töpel <bjorn@rivosinc.com> --- v2->v3: Set state to Dirty after discard, for proper ptrace() handling (Andy) v1->v2: Proper register restore for initial state (Andy) Set registers to 1s, and not 0s (Darius) --- arch/riscv/include/asm/vector.h | 33 +++++++++++++++++++++++++++++++++ arch/riscv/kernel/traps.c | 2 ++ 2 files changed, 35 insertions(+) base-commit: 488833ccdcac118da16701f4ee0673b20ba47fe3
Comments
Hey, On Thu, Jun 29, 2023 at 08:27:30AM +0200, Björn Töpel wrote: > From: Björn Töpel <bjorn@rivosinc.com> > > The RISC-V vector specification states: > Executing a system call causes all caller-saved vector registers > (v0-v31, vl, vtype) and vstart to become unspecified. > > The vector registers are set to all 1s, vill is set (invalid), and the > vector status is set to Dirty. > > That way we can prevent userspace from accidentally relying on the > stated save. > > Rémi pointed out [1] that writing to the registers might be > superfluous, and setting vill is sufficient. > > Link: https://lore.kernel.org/linux-riscv/12784326.9UPPK3MAeB@basile.remlab.net/ # [1] > Suggested-by: Darius Rad <darius@bluespec.com> > Suggested-by: Palmer Dabbelt <palmer@rivosinc.com> > Suggested-by: Rémi Denis-Courmont <remi@remlab.net> > Signed-off-by: Björn Töpel <bjorn@rivosinc.com> clang allmodconfig and rv32_defconfig fail to build with this patch, according to patchwork: ../arch/riscv/kernel/traps.c:299:3: error: call to undeclared function 'riscv_v_vstate_discard'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] Cheers, Conor. > --- > > v2->v3: > Set state to Dirty after discard, for proper ptrace() handling > (Andy) > > v1->v2: > Proper register restore for initial state (Andy) > Set registers to 1s, and not 0s (Darius) > > --- > arch/riscv/include/asm/vector.h | 33 +++++++++++++++++++++++++++++++++ > arch/riscv/kernel/traps.c | 2 ++ > 2 files changed, 35 insertions(+) > > diff --git a/arch/riscv/include/asm/vector.h b/arch/riscv/include/asm/vector.h > index 04c0b07bf6cd..0b23056503c5 100644 > --- a/arch/riscv/include/asm/vector.h > +++ b/arch/riscv/include/asm/vector.h > @@ -33,6 +33,11 @@ static inline void __riscv_v_vstate_clean(struct pt_regs *regs) > regs->status = (regs->status & ~SR_VS) | SR_VS_CLEAN; > } > > +static inline void __riscv_v_vstate_dirty(struct pt_regs *regs) > +{ > + regs->status = (regs->status & ~SR_VS) | SR_VS_DIRTY; > +} > + > static inline void riscv_v_vstate_off(struct pt_regs *regs) > { > regs->status = (regs->status & ~SR_VS) | SR_VS_OFF; > @@ -128,6 +133,34 @@ static inline void __riscv_v_vstate_restore(struct __riscv_v_ext_state *restore_ > riscv_v_disable(); > } > > +static inline void __riscv_v_vstate_discard(void) > +{ > + unsigned long vl, vtype_inval = 1UL << (BITS_PER_LONG - 1); > + > + riscv_v_enable(); > + asm volatile ( > + ".option push\n\t" > + ".option arch, +v\n\t" > + "vsetvli %0, x0, e8, m8, ta, ma\n\t" > + "vmv.v.i v0, -1\n\t" > + "vmv.v.i v8, -1\n\t" > + "vmv.v.i v16, -1\n\t" > + "vmv.v.i v24, -1\n\t" > + "vsetvl %0, x0, %1\n\t" > + ".option pop\n\t" > + : "=&r" (vl) : "r" (vtype_inval) : "memory"); > + riscv_v_disable(); > +} > + > +static inline void riscv_v_vstate_discard(struct pt_regs *regs) > +{ > + if ((regs->status & SR_VS) == SR_VS_OFF) > + return; > + > + __riscv_v_vstate_discard(); > + __riscv_v_vstate_dirty(regs); > +} > + > static inline void riscv_v_vstate_save(struct task_struct *task, > struct pt_regs *regs) > { > diff --git a/arch/riscv/kernel/traps.c b/arch/riscv/kernel/traps.c > index 5158961ea977..5ff63a784a6d 100644 > --- a/arch/riscv/kernel/traps.c > +++ b/arch/riscv/kernel/traps.c > @@ -296,6 +296,8 @@ asmlinkage __visible __trap_section void do_trap_ecall_u(struct pt_regs *regs) > regs->epc += 4; > regs->orig_a0 = regs->a0; > > + riscv_v_vstate_discard(regs); > + > syscall = syscall_enter_from_user_mode(regs, syscall); > > if (syscall < NR_syscalls) > > base-commit: 488833ccdcac118da16701f4ee0673b20ba47fe3 > -- > 2.39.2 >
Hi Björn, kernel test robot noticed the following build errors: [auto build test ERROR on 488833ccdcac118da16701f4ee0673b20ba47fe3] url: https://github.com/intel-lab-lkp/linux/commits/Bj-rn-T-pel/riscv-Discard-vector-state-on-syscalls/20230629-142852 base: 488833ccdcac118da16701f4ee0673b20ba47fe3 patch link: https://lore.kernel.org/r/20230629062730.985184-1-bjorn%40kernel.org patch subject: [PATCH v3] riscv: Discard vector state on syscalls config: riscv-randconfig-r042-20230629 (https://download.01.org/0day-ci/archive/20230629/202306291513.DwaMo6k7-lkp@intel.com/config) compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project.git 4a5ac14ee968ff0ad5d2cc1ffa0299048db4c88a) reproduce: (https://download.01.org/0day-ci/archive/20230629/202306291513.DwaMo6k7-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202306291513.DwaMo6k7-lkp@intel.com/ All errors (new ones prefixed by >>): | ~~~~~~~~~~ ^ In file included from arch/riscv/kernel/traps.c:15: In file included from include/linux/kprobes.h:28: In file included from include/linux/ftrace.h:10: In file included from include/linux/trace_recursion.h:5: In file included from include/linux/interrupt.h:11: In file included from include/linux/hardirq.h:11: In file included from ./arch/riscv/include/generated/asm/hardirq.h:1: In file included from include/asm-generic/hardirq.h:17: In file included from include/linux/irq.h:20: In file included from include/linux/io.h:13: In file included from arch/riscv/include/asm/io.h:136: include/asm-generic/io.h:751:2: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 751 | insw(addr, buffer, count); | ^~~~~~~~~~~~~~~~~~~~~~~~~ arch/riscv/include/asm/io.h:105:53: note: expanded from macro 'insw' 105 | #define insw(addr, buffer, count) __insw(PCI_IOBASE + (addr), buffer, count) | ~~~~~~~~~~ ^ In file included from arch/riscv/kernel/traps.c:15: In file included from include/linux/kprobes.h:28: In file included from include/linux/ftrace.h:10: In file included from include/linux/trace_recursion.h:5: In file included from include/linux/interrupt.h:11: In file included from include/linux/hardirq.h:11: In file included from ./arch/riscv/include/generated/asm/hardirq.h:1: In file included from include/asm-generic/hardirq.h:17: In file included from include/linux/irq.h:20: In file included from include/linux/io.h:13: In file included from arch/riscv/include/asm/io.h:136: include/asm-generic/io.h:759:2: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 759 | insl(addr, buffer, count); | ^~~~~~~~~~~~~~~~~~~~~~~~~ arch/riscv/include/asm/io.h:106:53: note: expanded from macro 'insl' 106 | #define insl(addr, buffer, count) __insl(PCI_IOBASE + (addr), buffer, count) | ~~~~~~~~~~ ^ In file included from arch/riscv/kernel/traps.c:15: In file included from include/linux/kprobes.h:28: In file included from include/linux/ftrace.h:10: In file included from include/linux/trace_recursion.h:5: In file included from include/linux/interrupt.h:11: In file included from include/linux/hardirq.h:11: In file included from ./arch/riscv/include/generated/asm/hardirq.h:1: In file included from include/asm-generic/hardirq.h:17: In file included from include/linux/irq.h:20: In file included from include/linux/io.h:13: In file included from arch/riscv/include/asm/io.h:136: include/asm-generic/io.h:768:2: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 768 | outsb(addr, buffer, count); | ^~~~~~~~~~~~~~~~~~~~~~~~~~ arch/riscv/include/asm/io.h:118:55: note: expanded from macro 'outsb' 118 | #define outsb(addr, buffer, count) __outsb(PCI_IOBASE + (addr), buffer, count) | ~~~~~~~~~~ ^ In file included from arch/riscv/kernel/traps.c:15: In file included from include/linux/kprobes.h:28: In file included from include/linux/ftrace.h:10: In file included from include/linux/trace_recursion.h:5: In file included from include/linux/interrupt.h:11: In file included from include/linux/hardirq.h:11: In file included from ./arch/riscv/include/generated/asm/hardirq.h:1: In file included from include/asm-generic/hardirq.h:17: In file included from include/linux/irq.h:20: In file included from include/linux/io.h:13: In file included from arch/riscv/include/asm/io.h:136: include/asm-generic/io.h:777:2: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 777 | outsw(addr, buffer, count); | ^~~~~~~~~~~~~~~~~~~~~~~~~~ arch/riscv/include/asm/io.h:119:55: note: expanded from macro 'outsw' 119 | #define outsw(addr, buffer, count) __outsw(PCI_IOBASE + (addr), buffer, count) | ~~~~~~~~~~ ^ In file included from arch/riscv/kernel/traps.c:15: In file included from include/linux/kprobes.h:28: In file included from include/linux/ftrace.h:10: In file included from include/linux/trace_recursion.h:5: In file included from include/linux/interrupt.h:11: In file included from include/linux/hardirq.h:11: In file included from ./arch/riscv/include/generated/asm/hardirq.h:1: In file included from include/asm-generic/hardirq.h:17: In file included from include/linux/irq.h:20: In file included from include/linux/io.h:13: In file included from arch/riscv/include/asm/io.h:136: include/asm-generic/io.h:786:2: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 786 | outsl(addr, buffer, count); | ^~~~~~~~~~~~~~~~~~~~~~~~~~ arch/riscv/include/asm/io.h:120:55: note: expanded from macro 'outsl' 120 | #define outsl(addr, buffer, count) __outsl(PCI_IOBASE + (addr), buffer, count) | ~~~~~~~~~~ ^ In file included from arch/riscv/kernel/traps.c:15: In file included from include/linux/kprobes.h:28: In file included from include/linux/ftrace.h:10: In file included from include/linux/trace_recursion.h:5: In file included from include/linux/interrupt.h:11: In file included from include/linux/hardirq.h:11: In file included from ./arch/riscv/include/generated/asm/hardirq.h:1: In file included from include/asm-generic/hardirq.h:17: In file included from include/linux/irq.h:20: In file included from include/linux/io.h:13: In file included from arch/riscv/include/asm/io.h:136: include/asm-generic/io.h:1134:55: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 1134 | return (port > MMIO_UPPER_LIMIT) ? NULL : PCI_IOBASE + port; | ~~~~~~~~~~ ^ >> arch/riscv/kernel/traps.c:299:3: error: call to undeclared function 'riscv_v_vstate_discard'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] 299 | riscv_v_vstate_discard(regs); | ^ arch/riscv/kernel/traps.c:299:3: note: did you mean 'riscv_v_vstate_query'? arch/riscv/include/asm/vector.h:206:20: note: 'riscv_v_vstate_query' declared here 206 | static inline bool riscv_v_vstate_query(struct pt_regs *regs) { return false; } | ^ 13 warnings and 1 error generated. vim +/riscv_v_vstate_discard +299 arch/riscv/kernel/traps.c 290 291 asmlinkage __visible __trap_section void do_trap_ecall_u(struct pt_regs *regs) 292 { 293 if (user_mode(regs)) { 294 ulong syscall = regs->a7; 295 296 regs->epc += 4; 297 regs->orig_a0 = regs->a0; 298 > 299 riscv_v_vstate_discard(regs); 300 301 syscall = syscall_enter_from_user_mode(regs, syscall); 302 303 if (syscall < NR_syscalls) 304 syscall_handler(regs, syscall); 305 else 306 regs->a0 = -ENOSYS; 307 308 syscall_exit_to_user_mode(regs); 309 } else { 310 irqentry_state_t state = irqentry_nmi_enter(regs); 311 312 do_trap_error(regs, SIGILL, ILL_ILLTRP, regs->epc, 313 "Oops - environment call from U-mode"); 314 315 irqentry_nmi_exit(regs, state); 316 } 317
Hi Björn, kernel test robot noticed the following build errors: [auto build test ERROR on 488833ccdcac118da16701f4ee0673b20ba47fe3] url: https://github.com/intel-lab-lkp/linux/commits/Bj-rn-T-pel/riscv-Discard-vector-state-on-syscalls/20230629-142852 base: 488833ccdcac118da16701f4ee0673b20ba47fe3 patch link: https://lore.kernel.org/r/20230629062730.985184-1-bjorn%40kernel.org patch subject: [PATCH v3] riscv: Discard vector state on syscalls config: riscv-allnoconfig (https://download.01.org/0day-ci/archive/20230629/202306292011.OGfLGBam-lkp@intel.com/config) compiler: riscv64-linux-gcc (GCC) 12.3.0 reproduce: (https://download.01.org/0day-ci/archive/20230629/202306292011.OGfLGBam-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202306292011.OGfLGBam-lkp@intel.com/ All errors (new ones prefixed by >>): arch/riscv/kernel/traps.c: In function 'do_trap_ecall_u': >> arch/riscv/kernel/traps.c:299:17: error: implicit declaration of function 'riscv_v_vstate_discard'; did you mean 'riscv_v_vstate_restore'? [-Werror=implicit-function-declaration] 299 | riscv_v_vstate_discard(regs); | ^~~~~~~~~~~~~~~~~~~~~~ | riscv_v_vstate_restore cc1: some warnings being treated as errors vim +299 arch/riscv/kernel/traps.c 290 291 asmlinkage __visible __trap_section void do_trap_ecall_u(struct pt_regs *regs) 292 { 293 if (user_mode(regs)) { 294 ulong syscall = regs->a7; 295 296 regs->epc += 4; 297 regs->orig_a0 = regs->a0; 298 > 299 riscv_v_vstate_discard(regs); 300 301 syscall = syscall_enter_from_user_mode(regs, syscall); 302 303 if (syscall < NR_syscalls) 304 syscall_handler(regs, syscall); 305 else 306 regs->a0 = -ENOSYS; 307 308 syscall_exit_to_user_mode(regs); 309 } else { 310 irqentry_state_t state = irqentry_nmi_enter(regs); 311 312 do_trap_error(regs, SIGILL, ILL_ILLTRP, regs->epc, 313 "Oops - environment call from U-mode"); 314 315 irqentry_nmi_exit(regs, state); 316 } 317
Conor Dooley <conor.dooley@microchip.com> writes: > clang allmodconfig and rv32_defconfig fail to build with this patch, > according to patchwork: > ../arch/riscv/kernel/traps.c:299:3: error: call to undeclared function 'riscv_v_vstate_discard'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] Ugh. Sloppy. :-( Thank you! Björn
diff --git a/arch/riscv/include/asm/vector.h b/arch/riscv/include/asm/vector.h index 04c0b07bf6cd..0b23056503c5 100644 --- a/arch/riscv/include/asm/vector.h +++ b/arch/riscv/include/asm/vector.h @@ -33,6 +33,11 @@ static inline void __riscv_v_vstate_clean(struct pt_regs *regs) regs->status = (regs->status & ~SR_VS) | SR_VS_CLEAN; } +static inline void __riscv_v_vstate_dirty(struct pt_regs *regs) +{ + regs->status = (regs->status & ~SR_VS) | SR_VS_DIRTY; +} + static inline void riscv_v_vstate_off(struct pt_regs *regs) { regs->status = (regs->status & ~SR_VS) | SR_VS_OFF; @@ -128,6 +133,34 @@ static inline void __riscv_v_vstate_restore(struct __riscv_v_ext_state *restore_ riscv_v_disable(); } +static inline void __riscv_v_vstate_discard(void) +{ + unsigned long vl, vtype_inval = 1UL << (BITS_PER_LONG - 1); + + riscv_v_enable(); + asm volatile ( + ".option push\n\t" + ".option arch, +v\n\t" + "vsetvli %0, x0, e8, m8, ta, ma\n\t" + "vmv.v.i v0, -1\n\t" + "vmv.v.i v8, -1\n\t" + "vmv.v.i v16, -1\n\t" + "vmv.v.i v24, -1\n\t" + "vsetvl %0, x0, %1\n\t" + ".option pop\n\t" + : "=&r" (vl) : "r" (vtype_inval) : "memory"); + riscv_v_disable(); +} + +static inline void riscv_v_vstate_discard(struct pt_regs *regs) +{ + if ((regs->status & SR_VS) == SR_VS_OFF) + return; + + __riscv_v_vstate_discard(); + __riscv_v_vstate_dirty(regs); +} + static inline void riscv_v_vstate_save(struct task_struct *task, struct pt_regs *regs) { diff --git a/arch/riscv/kernel/traps.c b/arch/riscv/kernel/traps.c index 5158961ea977..5ff63a784a6d 100644 --- a/arch/riscv/kernel/traps.c +++ b/arch/riscv/kernel/traps.c @@ -296,6 +296,8 @@ asmlinkage __visible __trap_section void do_trap_ecall_u(struct pt_regs *regs) regs->epc += 4; regs->orig_a0 = regs->a0; + riscv_v_vstate_discard(regs); + syscall = syscall_enter_from_user_mode(regs, syscall); if (syscall < NR_syscalls)