From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by sourceware.org (Postfix) with ESMTPS id 8C26D3858D32 for ; Mon, 29 May 2023 14:04:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8C26D3858D32 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-64d247a023aso2468891b3a.2 for ; Mon, 29 May 2023 07:04:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1685369092; x=1687961092; 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=djFB8JHCZOb8WZ/QP64DwqvtUP+6HVX6YtMgl67JJXU=; b=YF8CULdxEzsICqs806SefMP32FbMcIlS2NeNo4xw9BRwLbxHDuFxVsYlfb0J7dRoAH +iyfvqiaoRJDm/OXAD7unbe6c8NAtZYCrIhWU6ZaU0YEFApUjGNZkfHB2Sbor8lkmBNj YMtm0iOzg0YV1EW2ybvv8nMt02I6Q9qer/R8Ycz/sTfWaF9tnJ3QejI8fOvB1t25/e3S pTaWvupgz6/9UocttcrZVo4QtNK8UW5KA+2k7fqO4BANYVFuWPFpGLckRwjmRQeQwQre wVzgya5v1bNEMcgSwo7H8fF+dsyM4fm9HEXGwzQkXyccqElKHOvLnUz1aY1PRlYY6wmF asNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685369092; x=1687961092; 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=djFB8JHCZOb8WZ/QP64DwqvtUP+6HVX6YtMgl67JJXU=; b=WObSPPJDhDO4dTHeV+BKNsh8pMxjKyV6UBC+TDZXgA3dPbyfI+MoC9+RUltA5cxSEO pWnZRcSDDkzsRxANEJ5c7vpGj4/B7J1oJqGOm/zZljqtx1Ehz+Pe9Qf4ICPZ8h+aPc3y VpNliI6b+obXRgRBLgwDZ7ErHaPOZl3iu6gl+3QhB13x6QyMB25hPEPU3E6XRC1OCkR6 +duSUJ2QJEPoM50qLyKC3sd9wwGFavIHTnw+B0oqKufDnvhXMgzqPYoadaZu7IG4U+RE 8FV8a0R1Gn+EIYgRQpWTpTLPGvYs6FcBXhaZtW3fKC74N1B1BMj89htxpxkIdfoykuVW lLOA== X-Gm-Message-State: AC+VfDxuA4FQCM4xYhyl6quNdMg1vs5PV4ct1HzvZHKYkWai+jBOPEYv q4RsSGKgD7omfkEBNScFDLzetUpg9SfL9o5EsEE= X-Google-Smtp-Source: ACHHUZ5EEio2MBoqB00YqSBthzPc6OQNmZ/4tWDuk8FSPjnQxCX4334Ep9ORiGV73lqgVo/6AxrdpA== X-Received: by 2002:a05:6a00:150a:b0:64c:b460:c47b with SMTP id q10-20020a056a00150a00b0064cb460c47bmr15371358pfu.15.1685369092113; Mon, 29 May 2023 07:04:52 -0700 (PDT) Received: from localhost ([135.180.227.0]) by smtp.gmail.com with ESMTPSA id j4-20020a62e904000000b0063d24fcc2b7sm38084pfh.1.2023.05.29.07.04.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 May 2023 07:04:50 -0700 (PDT) Date: Mon, 29 May 2023 07:04:50 -0700 (PDT) X-Google-Original-Date: Mon, 29 May 2023 07:04:47 PDT (-0700) Subject: Re: [PATCH 3/5] riscv: Add the clone3 wrapper In-Reply-To: <20230203171237.1220878-4-adhemerval.zanella@linaro.org> CC: libc-alpha@sourceware.org From: Palmer Dabbelt To: adhemerval.zanella@linaro.org 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,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,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 server2.sourceware.org List-Id: On Fri, 03 Feb 2023 09:12:35 PST (-0800), adhemerval.zanella@linaro.org wrote: > It follows the internal signature: > > extern int clone3 (struct clone_args *__cl_args, size_t __size, > int (*__func) (void *__arg), void *__arg); > > Checked on riscv64-linux-gnu-rv64imafdc-lp64d. Due to a bug we only had clone3 on rv64 until 59a4e0d5511b ("RISC-V: Include clone3() on rv32"), which landed in 5.15 and was then backported all the way to 5.4. > --- > sysdeps/unix/sysv/linux/riscv/clone3.S | 80 ++++++++++++++++++++++++++ > sysdeps/unix/sysv/linux/riscv/sysdep.h | 1 + > 2 files changed, 81 insertions(+) > create mode 100644 sysdeps/unix/sysv/linux/riscv/clone3.S > > diff --git a/sysdeps/unix/sysv/linux/riscv/clone3.S b/sysdeps/unix/sysv/linux/riscv/clone3.S > new file mode 100644 > index 0000000000..ee5780ee2f > --- /dev/null > +++ b/sysdeps/unix/sysv/linux/riscv/clone3.S > @@ -0,0 +1,80 @@ > +/* The clone3 syscall wrapper. Linux/RISC-V version. > + Copyright (C) 2023 Free Software Foundation, Inc. > + > + This file is part of the GNU C Library. > + > + The GNU C Library is free software; you can redistribute it and/or > + modify it under the terms of the GNU Lesser General Public > + License as published by the Free Software Foundation; either > + version 2.1 of the License, or (at your option) any later version. > + > + The GNU C Library is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + Lesser General Public License for more details. > + > + You should have received a copy of the GNU Lesser General Public > + License along with the GNU C Library; if not, see > + . */ > + > +#include > +#include > +#include > + > +/* The userland implementation is: > + int clone3 (struct clone_args *cl_args, size_t size, > + int (*func)(void *arg), void *arg); > + > + the kernel entry is: > + int clone3 (struct clone_args *cl_args, size_t size); > + > + The parameters are passed in registers from userland: > + a0: cl_args > + a1: size > + a2: func > + a3: arg */ > + > + .text > +ENTRY(__clone3) > + /* Sanity check args. */ > + beqz a0, L(invalid) /* No NULL cl_args pointer. */ > + beqz a2, L(invalid) /* No NULL function pointer. */ > + > + /* Do the system call, the kernel expects: > + a7: system call number > + a0: cl_args > + a1: size */ > + li a7, __NR_clone3 IIUC this only builds with kernel headers 5.15 or newer on rv32. I'm not sure if that's a problem: unless I'm missing something we support building for those systems now, but rv32 is pretty esoteric so I'm not sure anyone cares -- maybe someone uses 5.15 on rv32 (some rv64 hardware is still being released with 5.10-based vendor kernels), but 5.4 is pretty old for us. > + scall > + > + bltz a0, L(error) > + beqz a0, L(thread_start) > + > + ret > + > +L(invalid): > + li a0, -EINVAL > +L(error): > + tail __syscall_error > +END (__clone3) > + > +ENTRY(__thread_start_clone3) > +L(thread_start): > + /* Terminate call stack by noting ra is undefined. Use a dummy > + .cfi_label to force starting the FDE. */ > + .cfi_label .Ldummy > + cfi_undefined (ra) > + > + /* Restore the arg for user's function and call the user's > + function. */ > + mv a1, a2 /* Function pointer. */ I think we don't need that mv, we can just call a2 directly? Unless I'm missing some reason the thread main needs to see a pointer to itself? > + mv a0, a3 /* Argument pointer. */ > + jalr a1 > + > + /* Call exit with the function's return value. */ > + li a7, __NR_exit > + scall > +END(__thread_start_clone3) > + > +libc_hidden_def (__clone3) > +weak_alias (__clone3, clone3) > diff --git a/sysdeps/unix/sysv/linux/riscv/sysdep.h b/sysdeps/unix/sysv/linux/riscv/sysdep.h > index 4af5fe5dbc..e96a930409 100644 > --- a/sysdeps/unix/sysv/linux/riscv/sysdep.h > +++ b/sysdeps/unix/sysv/linux/riscv/sysdep.h > @@ -151,6 +151,7 @@ > > /* RV32 does not support the gettime VDSO syscalls. */ > # endif > +# define HAVE_CLONE3_WRAPPER 1 > > /* List of system calls which are supported as vsyscalls (for RV32 and > RV64). */ That's just some minor comments though, so Reviewed-by: Palmer Dabbelt Thanks! (and sorry I missed it for a bit)