From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-xd34.google.com (mail-io1-xd34.google.com [IPv6:2607:f8b0:4864:20::d34]) by sourceware.org (Postfix) with ESMTPS id 50EC23858D20 for ; Wed, 27 Mar 2024 21:48:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 50EC23858D20 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=sifive.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 50EC23858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::d34 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711576140; cv=none; b=LN2VlgZ4cuFipeiG3X0ZaeUQrwAvfSIRz9zOtKmgyyYo8As2rXuMDYst4fHvGAYVKOqlX6E+Eh/zjnBGMhia2KHd3q7r3v4GVJApFSRpON5Uly+mrEu7zXAoHfz/olLQ4gnMfo5fzXJt/9EIka0PgJVZOkTwDJ1/3ty+C3MTJt0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711576140; c=relaxed/simple; bh=fhAtBFXc9nPNGYhIkHkXWELlx316chXqt/R3NTaKaHU=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=OawU07hWBo7vcxlJ+pXgCs29fbQ+TPNtC0I59SZL8fbycxrCwdJXLw6E01jQg/sZ7xgXfAZm1jZQHN78ygjW2xJMUbjOipWy/Cu5Xxlzz2xGdbjJi5E284BMj0ummu025/pQWQQyyLwNCP34/SP2BXpFrCYdhxRZbtzskRy7Oa8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-io1-xd34.google.com with SMTP id ca18e2360f4ac-7d08aea7546so4043339f.0 for ; Wed, 27 Mar 2024 14:48:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1711576137; x=1712180937; darn=sourceware.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=TuuYx+A6tHZ28/hG0dcE4O9kMvzIIxJJ9/n7Gqr0jVo=; b=QnCdGQkoz7kFJklfMbn5rs4lNViLSIiXZ8bWBm2jAGnmDR4jSdMBt5Ipteykv5IjKj aO25jLM9488+41KpU9azsoi98vEvwgU3h0yv+PBjVICtvrlWl84W3ifDuwklIfe7W4H1 bIKhb/oEGq7+TGpE4nxgxax8MwmPjUSNjKEaQAyE+pEKh/kzJUDYevxp2LsbgmuK9SmN ye2djy4BeihPmRytgyHfeqMB015TQjL0ATxkURaaNC1otBHq7BcvIO3mdXsuKms/5yEd 92y1a4bFvhUPYk2HrG/kACnDRNrPUk4uRZgYLm9w1zd+Gs+ngW7fGISigL47a74z82y/ ogPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711576137; x=1712180937; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TuuYx+A6tHZ28/hG0dcE4O9kMvzIIxJJ9/n7Gqr0jVo=; b=fBcXGsSWHjlWr03q7wz5j22zkzZ4yTchJKESh2nYLi7UzoTbupgrx3lgNWMoEnK3NZ arTPQYTxmuPqEjp9bjs1DEOdTwsyesAczfm3Uvi3eYjxzDQk50iW5O7qV/iDdzaH6O5h w+wEPCEXuRjOZwiqT8uxN4ABg3Pz4u1n7i01K5Z8mFbIh4PyZ+YFLxfJDRRGYeH/0YWm P0JsPOt4CNTScIzJu8ckUwVhZGO7AOcG64MAjKrmKFMaW1eZjKtImMZrkp6GwqhhEXDe JbexkCTRDvj34EwYtnITTGj3MYJY06rya9zU0tmrnexTIOEHEpEueByclqiEDev7IpjX szBg== X-Gm-Message-State: AOJu0Yw8gQqC3ZsU6n1ibCSAUOqoIx+LT4MG3i6fJQ4au+/ih+BUFp4D n6cKlWp38fHO1TxZIkuwrg3bIDEUA1VjrEn5lgky5tJ+7mi3aXypE5ivJB2kfydlCXSCFRjuLj3 SP+I4LthgDC6f4Xo/AGRAa2qJMeFhhD4NoS1U77rbQ+h1RqecadK5eVVX7nbCuEaIGOUTR3uc2e m3AWRU8/nhpBW7BxL5GQ9GkhR9B8Ka6rxyqwa2AQ== X-Google-Smtp-Source: AGHT+IEaH9Vkbbpbf43wQoZeAwDKJfefq3ViXnsdmuFBjIsjetMqUSfdeXeipZoJU9R0bvGzzbtkDA== X-Received: by 2002:a5e:d604:0:b0:7d0:848f:fb26 with SMTP id w4-20020a5ed604000000b007d0848ffb26mr785415iom.16.1711576137197; Wed, 27 Mar 2024 14:48:57 -0700 (PDT) Received: from mail-il1-f170.google.com (mail-il1-f170.google.com. [209.85.166.170]) by smtp.gmail.com with ESMTPSA id fh1-20020a056638628100b0047ec029412fsm457521jab.12.2024.03.27.14.48.56 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 27 Mar 2024 14:48:56 -0700 (PDT) Received: by mail-il1-f170.google.com with SMTP id e9e14a558f8ab-3668fd6952bso866195ab.1 for ; Wed, 27 Mar 2024 14:48:56 -0700 (PDT) X-Received: by 2002:a05:6e02:1384:b0:368:85c6:6bd1 with SMTP id d4-20020a056e02138400b0036885c66bd1mr897315ilo.10.1711576136440; Wed, 27 Mar 2024 14:48:56 -0700 (PDT) MIME-Version: 1.0 References: <20240327193601.28903-2-palmer@rivosinc.com> In-Reply-To: <20240327193601.28903-2-palmer@rivosinc.com> From: Andrew Waterman Date: Wed, 27 Mar 2024 14:48:45 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] RISC-V: Clobber V state on system calls To: Palmer Dabbelt Cc: libc-alpha@sourceware.org, Vineet Gupta Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-9.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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=E2=80=AFPM Palmer Dabbelt 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 > Signed-off-by: Palmer Dabbelt > --- > 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-palm= er@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/l= inux/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 >