public inbox for linux-riscv@lists.infradead.org
 help / color / mirror / Atom feed
From: "Björn Töpel" <bjorn@kernel.org>
To: Palmer Dabbelt <palmer@rivosinc.com>, linux-riscv@lists.infradead.org
Cc: Palmer Dabbelt <palmer@rivosinc.com>
Subject: Re: [PATCH] RISC-V: Clobber V registers on syscalls
Date: Fri, 16 Jun 2023 22:12:14 +0200	[thread overview]
Message-ID: <87sfar2mld.fsf@all.your.base.are.belong.to.us> (raw)
In-Reply-To: <20230614163534.18668-1-palmer@rivosinc.com>

Palmer Dabbelt <palmer@rivosinc.com> writes:

> The V registers are clobbered by standard ABI functions, so userspace
> probably doesn't have anything useful in them by the time we get to the
> kernel.  So let's just document that they're clobbered by syscalls and
> proactively clobber them.
>
> Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
> ---
> IIRC we'd talked about doing this, but I didn't see anything in the
> docs.  I figure it's better to just proactively clobber the registers on
> syscalls, as that way userspace can't end up accidentally depending on
> them.
> ---
>  Documentation/riscv/vector.rst | 5 +++++
>  arch/riscv/kernel/traps.c      | 2 ++
>  2 files changed, 7 insertions(+)
>
> diff --git a/Documentation/riscv/vector.rst b/Documentation/riscv/vector.rst
> index 48f189d79e41..a4dfa954215b 100644
> --- a/Documentation/riscv/vector.rst
> +++ b/Documentation/riscv/vector.rst
> @@ -130,3 +130,8 @@ processes in form of sysctl knob:
>  
>      Modifying the system default enablement status does not affect the enablement
>      status of any existing process of thread that do not make an execve() call.
> +
> +3.  Vector Register State Across System Calls
> +---------------------------------------------
> +
> +Vector registers are clobbered by system calls.
> diff --git a/arch/riscv/kernel/traps.c b/arch/riscv/kernel/traps.c
> index 05ffdcd1424e..bb99a6379b37 100644
> --- a/arch/riscv/kernel/traps.c
> +++ b/arch/riscv/kernel/traps.c
> @@ -295,6 +295,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_off(regs);
> +

Not off, right? Isn't it __riscv_v_vstate_clean() that you'd like to
call? Something like:

static void vstate_discard(struct pt_regs *regs)
{
       if ((regs->status & SR_VS) == SR_VS_DIRTY)
               __riscv_v_vstate_clean(regs);
}

Complemented by a !V config variant.


Björn

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

  parent reply	other threads:[~2023-06-16 20:12 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-14 16:35 [PATCH] RISC-V: Clobber V registers on syscalls Palmer Dabbelt
2023-06-15 17:36 ` Rémi Denis-Courmont
2023-06-15 20:33   ` Palmer Dabbelt
2023-06-16 19:58     ` Rémi Denis-Courmont
2023-06-16 19:47   ` Björn Töpel
2023-06-16 20:12 ` Björn Töpel [this message]
2023-06-19 18:18   ` Palmer Dabbelt
2023-06-19 19:01     ` Björn Töpel
2023-06-19 19:05       ` Palmer Dabbelt
2023-06-21 14:26         ` Björn Töpel
2023-06-21 14:44           ` Darius Rad
2023-06-21 18:16             ` Palmer Dabbelt
2023-06-21 14:50           ` Andy Chiu
2023-06-21 21:40             ` Björn Töpel
2023-06-22 15:47               ` Andy Chiu
2023-06-22 16:38                 ` Björn Töpel
2023-06-24  6:54                   ` Andy Chiu
2023-06-26 15:36                     ` Björn Töpel
2023-06-27  1:07                       ` Andy Chiu
2023-06-27  6:33                         ` Björn Töpel
2023-06-24  8:41                   ` Andy Chiu
2023-06-26 14:54                     ` Björn Töpel
2023-06-21 16:47           ` Rémi Denis-Courmont
2023-06-21 18:16             ` Palmer Dabbelt
2023-06-21 21:42               ` Björn Töpel
2025-06-16 22:30         ` Drew Fustini
2025-06-16 22:48           ` Drew Fustini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87sfar2mld.fsf@all.your.base.are.belong.to.us \
    --to=bjorn@kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=palmer@rivosinc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox