From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by sourceware.org (Postfix) with ESMTPS id 40EE73858C55 for ; Wed, 27 Mar 2024 21:54:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 40EE73858C55 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivosinc.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 40EE73858C55 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::536 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711576444; cv=none; b=FIKo9zptuj9PRogQpEnB4ebU6W6sMEs7m6rNAzwOsVugR8pU93QrQyQyiDisHmud8um9rRL92Jg5mAE2jhY15mRQon43z+J3s5pXgNGyViZcLuGBV7lcI+f3BPXkZs/JL35KiZcKF+YND1iGXLSK6PrgcMoL0OhrAZ0NeavRsOo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711576444; c=relaxed/simple; bh=lx4QxbHRXfyWkFsg6JvF8U7AgOmAXbqat+eT2X13i7w=; h=DKIM-Signature:Date:Subject:From:To:Message-ID:Mime-Version; b=ZOppZ71GDLuwD/NneXXFNVcu4fPUxawcG/jIzUuu4nZ5uX+/Pj86tbuG2e8TNgTBoyBElR2nDa0hIqz40ouo3Ytzj1CuT9jeL+7R0LUNk/qOVPiZBEv5BAvFrS/kYFjTYkvcsbsuSZF8vCCYxEAQQY3a/473pE9d4asZUIHLtDk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pg1-x536.google.com with SMTP id 41be03b00d2f7-5d8b70b39efso218441a12.0 for ; Wed, 27 Mar 2024 14:54:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1711576440; x=1712181240; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:to:from:cc :in-reply-to:subject:date:from:to:cc:subject:date:message-id :reply-to; bh=DBU+79D70X8P78ErPHoKPqF3gpFoxl59KRA81hr8mFs=; b=uN/k22pRDDG3TiCXXzcOV561bq6o6g4A8N2o7k59RtrQADpl1eG/Fli2F6kO3CdGJW 6pVDHvhb2iBfC/zJyhw/pKhA887xNqpTYINLpYDJTieuoL5dwvIPZEdffGpwQCq4OY+9 1KU63THdCXUxnV0wTsX8RUbtJk6QQNiLmpya0lWjtVRIiaOvZo19jkMDvQ1ysBNTNC1z SsZsrrrgpqUvYas91waWtJPI8L2bK03W48hFpOCsJo8X4nVWk1GutNo+yZ0AfCgJR2Pn G0/C/biY6S8BQ40cCiLcaFJ7K1ANLSfbV9icBlOp0GKJynbcbjQSdcGIqIyFIseCp24/ LKiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711576440; x=1712181240; h=content-transfer-encoding:mime-version:message-id:to:from:cc :in-reply-to:subject:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=DBU+79D70X8P78ErPHoKPqF3gpFoxl59KRA81hr8mFs=; b=gwB0zBYpLEcMhz2ZmxbDVnO92TvRSULQ7XpIjU7H+9lwDc20uM2wLGmM4xu4X7HUzw 1djB1VdD3JaO7q3YquHvGrHewLkqFOOlh9EajtgSWlC81nvy+Xm0rJvB4FaQNzi2tH07 PhHacgmua+6z5xY2lCOTrlbBQXhDcNQcz701k+Zi81PJ5rv9lPcfYhyAMynmKtGRP7UM I+zim9NBXfDEkyawHCenyy8xTJED/3Itgl8NyKm7uSsyytCo/CtROCRm/FdP8KTvLVE1 ky40EvAyWEmt4DtBKheMlVV7brD+4c9yM1DSXqVBs7Yb4W+72IGuAcR5WllUiMUmh3c+ rgBQ== X-Gm-Message-State: AOJu0YwJzzuXkkQpfBvaM4IV5L8VKPEIuYXXf5STU4pxlX0nU9yWILxU 66tJuFGhHmAN6y3CHyHa06c7E+rQkV5kjJUe/09L5dHrGV6BX5hzuLBPBS+VS/CW5AmcAOZLAmP d X-Google-Smtp-Source: AGHT+IEm738HY1vgQNn6fFuBgTudMltr8UHNUSDLJ6db3VWx9SkcBSWHRmcAO1YA3djTLrf6xgVc9g== X-Received: by 2002:a05:6a20:c887:b0:1a3:52ef:cc84 with SMTP id hb7-20020a056a20c88700b001a352efcc84mr1179375pzb.60.1711576440312; Wed, 27 Mar 2024 14:54:00 -0700 (PDT) Received: from localhost ([192.184.165.199]) by smtp.gmail.com with ESMTPSA id v18-20020aa78512000000b006ead0b03f93sm24670pfn.81.2024.03.27.14.53.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 14:53:59 -0700 (PDT) Date: Wed, 27 Mar 2024 14:53:59 -0700 (PDT) X-Google-Original-Date: Wed, 27 Mar 2024 14:53:55 PDT (-0700) Subject: Re: [PATCH] RISC-V: Clobber V state on system calls In-Reply-To: CC: libc-alpha@sourceware.org, Vineet Gupta From: Palmer Dabbelt To: Andrew Waterman Message-ID: Mime-Version: 1.0 (MHng) Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,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: On Wed, 27 Mar 2024 14:48:45 PDT (-0700), Andrew Waterman wrote: > 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. IIUC we've also got another quirk where GCC discards all V register state on inline ASM blocks (but I think doesn't discard the V CSR state), so it'd be pretty unlikely we actually vectorize anything with the syscall macros. Getting a reproducer for those is next on the TODO list ;) > On Wed, Mar 27, 2024 at 2:37 PM 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-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 >>