unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Waterman <andrew@sifive.com>
To: Palmer Dabbelt <palmer@rivosinc.com>
Cc: libc-alpha@sourceware.org, Vineet Gupta <vineetg@rivosinc.com>
Subject: Re: [PATCH] RISC-V: Clobber V state on system calls
Date: Wed, 27 Mar 2024 14:48:45 -0700	[thread overview]
Message-ID: <CA++6G0CX19CSS7tVtgzKwUwf20GtGmzTHs9t2aEfam-bv3QkGw@mail.gmail.com> (raw)
In-Reply-To: <20240327193601.28903-2-palmer@rivosinc.com>

LGTM.  I suspect this hasn't manifested as a bug because a glibc
routine with an inline syscall would need to be vectorized for this to
be a potential problem.  But the prophylaxis is a good idea.


On Wed, Mar 27, 2024 at 2:37 PM Palmer Dabbelt <palmer@rivosinc.com> wrote:
>
> The Linux uABI clobbers all V state on syscalls (similar to SVE), but
> the syscall inline asm macros don't enforce this.  So just explicitly
> clobber everything.
>
> Reported-by: Vineet Gupta <vineetg@rivosinc.com>
> Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
> ---
> Vineet's been debugging a userspace hang, and it looks like it's
> uncovered at least three issues:
>
> * Linux isn't properly tracking V state, which results in some
>   signal-based userpace return paths missing the V state save.  This is
>   almost certainly a Linux bug, Charlie is looking at it.
> * GCC only discards the V register state on function calls, despite the
>   ABI also mandating that the V CSR state is discarded.  I'm not 100% on
>   this one as I don't really understand the vsetvl passes, but we were
>   talking about it on the GCC call yesterday and that's our best guess
>   right now.
> * glibc doesn't mark the V state as clobbered by syscalls.
>
> I don't know if we can actually manifest incorrect behavior here and it
> definately doesn't build (GCC doesn't support vxsat [1]).  I'm sort of
> just sending this as a placeholder, but I figured with all the other
> chaos I should send it rather than risking forgetting about it.
>
> [1]: https://inbox.sourceware.org/gcc-patches/20240327195403.29732-2-palmer@rivosinc.com/
> ---
>  sysdeps/unix/sysv/linux/riscv/sysdep.h | 10 ++++++++++
>  1 file changed, 10 insertions(+)
>
> diff --git a/sysdeps/unix/sysv/linux/riscv/sysdep.h b/sysdeps/unix/sysv/linux/riscv/sysdep.h
> index ee015dfeb6..3e3971e321 100644
> --- a/sysdeps/unix/sysv/linux/riscv/sysdep.h
> +++ b/sysdeps/unix/sysv/linux/riscv/sysdep.h
> @@ -354,7 +354,17 @@
>         _sys_result;                                                    \
>  })
>
> +#ifdef __riscv_vector
> +# define __SYSCALL_CLOBBERS "memory", "vl", "vtype", "vxrm", "vxsat",  \
> +                           "v0",   "v1",  "v2",  "v3",  "v4",  "v5",   \
> +                           "v6",   "v7",  "v8",  "v9", "v10", "v11",   \
> +                           "v12", "v13", "v14", "v15", "v16", "v17",   \
> +                           "v18", "v18", "v19", "v20", "v21", "v22",   \
> +                           "v23", "v24", "v25", "v26", "v27", "v28",   \
> +                           "v29", "v30", "v31"
> +#else
>  # define __SYSCALL_CLOBBERS "memory"
> +#endif
>
>  extern long int __syscall_error (long int neg_errno);
>
> --
> 2.44.0
>

  reply	other threads:[~2024-03-27 21:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-27 19:36 [PATCH] RISC-V: Clobber V state on system calls Palmer Dabbelt
2024-03-27 21:48 ` Andrew Waterman [this message]
2024-03-27 21:53   ` Palmer Dabbelt
2024-03-27 22:16     ` Vineet Gupta

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

  List information: https://www.gnu.org/software/libc/involved.html

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

  git send-email \
    --in-reply-to=CA++6G0CX19CSS7tVtgzKwUwf20GtGmzTHs9t2aEfam-bv3QkGw@mail.gmail.com \
    --to=andrew@sifive.com \
    --cc=libc-alpha@sourceware.org \
    --cc=palmer@rivosinc.com \
    --cc=vineetg@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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).