From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi1-x22e.google.com (mail-oi1-x22e.google.com [IPv6:2607:f8b0:4864:20::22e]) by sourceware.org (Postfix) with ESMTPS id 1D6A5384BC3C for ; Thu, 18 Mar 2021 23:19:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 1D6A5384BC3C Received: by mail-oi1-x22e.google.com with SMTP id i81so1327686oif.6 for ; Thu, 18 Mar 2021 16:19:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=M4n+GtkElWfbQgWUoe2xuFWFCNiktYg7HvWol5UvZlQ=; b=aj/gNhYiR3ZflWhJBjLhgbMJEA7BAXkZm54poIvw0Tcu2zmwyqf4HSn50mSwvxZdTH AlqjvbQUc7mNoHa+7zyDE74yqNc1sFhkMGFckOXlE3gegha2uLmfbPNnIpS46E8M43XM fzQic9FyCjfEpqPUqoeVJAGAGFyggaVeF8Z/mYXjiHY9bgVLpDajKTI4C8MUvXPYuy/E tWeIS2MkW5Hvf+SSdeaUFSSfCaMvGwm1SKoiC72B6SfjXTCdaiyQQPU+Fry/CgFi51l6 FuN4LG8BpTDSFaptnr2AC9cVIXcZvRfTWNyIcWKnyi5Mh9vdOWEVhI+Twn/gjulRLeOz 3Ixg== X-Gm-Message-State: AOAM531V1S/hKs3aldXLBvRy3mu3LoSQIUBrd1k+r/9Q2g3JecoHX66e ZZn0Oua3Nq9h7fXeAEcBSj6X6QZKz9bCobgah+2yXD18 X-Google-Smtp-Source: ABdhPJxGp09RBrS8vF5JUNyRSu+aIk3JQ/8YFsGkTR10RJEJ3HDFXj9N0EjIS3bbxAS1kgksNgHxnV7tuoB1ovHr56Q= X-Received: by 2002:a54:468f:: with SMTP id k15mr4714791oic.58.1616109561538; Thu, 18 Mar 2021 16:19:21 -0700 (PDT) MIME-Version: 1.0 References: <20210214224505.4448-1-hjl.tools@gmail.com> <87r1lhehkw.fsf@oldenburg.str.redhat.com> <7e132276-269f-b9c6-72fe-9d771e023d29@linaro.org> <20210305083227.hrg5ja5cdzrs3yo3@wittgenstein> In-Reply-To: From: "H.J. Lu" Date: Thu, 18 Mar 2021 16:18:45 -0700 Message-ID: Subject: PING^1 [PATCH v3] Add an internal wrapper for clone, clone2 and clone3 To: Christian Brauner Cc: Adhemerval Zanella , Florian Weimer , "H.J. Lu via Libc-alpha" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3029.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Mar 2021 23:19:23 -0000 On Fri, Mar 5, 2021 at 8:59 AM H.J. Lu wrote: > > On Fri, Mar 5, 2021 at 12:39 AM Christian Brauner > wrote: > > > > On Thu, Mar 04, 2021 at 10:50:29AM -0800, H.J. Lu via Libc-alpha wrote: > > > On Thu, Mar 4, 2021 at 10:40 AM H.J. Lu wrote: > > > > > > > > On Mon, Feb 15, 2021 at 6:56 AM Adhemerval Zanella via Libc-alpha > > > > wrote: > > > > > > > > > > > > > > > > > > > > On 15/02/2021 07:44, Florian Weimer via Libc-alpha wrote: > > > > > > * H. J. Lu via Libc-alpha: > > > > > > > > > > > >> The clone3 system call provides a superset of the functionality of clone > > > > > >> and clone2. It also provides a number of API improve ments, including > > > > > >> the ability to specify the size of the child's stack area which can be > > > > > >> used by kernel to compute the shadow stack size when allocating the > > > > > >> shadow stack. Add: > > > > > >> > > > > > >> extern int __clone_internal (struct clone_args *cl_args, size_t size, > > > > > >> int (*__fn) (void *__arg), void *__arg); > > > > > >> > > > > > >> to provide an abstract interface for clone, clone2 and clone3. > > > > > >> > > > > > >> 1. Simplify stack management for clone by passing stack base and size > > > > > >> to __clone_internal. > > > > > >> 2. Consolidate clone vs clone2 differences into a single file. > > > > > >> 3. Use only __clone_internal to clone a thread. If clone3 returns -1 > > > > > >> with ENOSYS, __clone_internal will fall back to clone or clone2. > > > > > >> 4. Add the x86-64 clone3 wrapper. > > > > > >> 5. Enable the public clone3 wrapper in the future after it has been > > > > > >> added to add targets. > > > > > > > > > > > > What do you think about providing a clone wrapper which reuses the > > > > > > caller's stack? That would be useful for a (v)fork-style clone. This > > > > > > variant could also be exported because the callback inherits a > > > > > > semi-valid TCB in this case. > > > > > I have this one as a TODO to improve the posix_spawn. > > > > > > > > Here is the v2 patch: > > > > > > > > 1. Update the stack size field, instead of the stack field, passed to > > > > clone3. > > > > > > > > OK for master? > > > > > > Really add the patch this time :-). > > > > > > -- > > > H.J. > > > > Just a small comment. > > > > > > + __set_errno (0); > > > + /* Map clone3 arguments to clone arguments. */ > > > + int flags = cl_args->flags | cl_args->exit_signal; > > > + void *stack = (void *) (uintptr_t) cl_args->stack; > > > + > > > +#ifdef __ia64__ > > > + ret = __clone2 (fn, stack, (size_t) cl_args->stack_size, > > > + flags, arg, > > > + (void *) (uintptr_t) cl_args->parent_tid, > > > + (void *) (uintptr_t) cl_args->tls, > > > + (void *) (uintptr_t) cl_args->child_tid); > > > > Should glibc maybe just carry a few simple macros to do this instead of > > open-coding the casting? (We do in systemd and LXC for example.): > > > > #define PTR_TO_INT(p) ((int)((intptr_t)(p))) > > #define INT_TO_PTR(u) ((void *)((intptr_t)(u))) > > > > #define PTR_TO_PID(p) ((pid_t)((intptr_t)(p))) > > #define PID_TO_PTR(u) ((void *)((intptr_t)(u))) > > > > #define PTR_TO_UINT64(p) ((uint64_t)((uintptr_t)(p))) > > > > #define PTR_TO_U64(p) ((__u64)((uintptr_t)(p))) > > > > #define UINT_TO_PTR(u) ((void *) ((uintptr_t) (u))) > > > > #define PTR_TO_USHORT(p) ((unsigned short)((uintptr_t)(p))) > > > > Fixed. > > Here is the v3 patch. OK for master? > > Changes from v2: > > 1. Add cast_to_pointer to cast an integer to void * pointer. > PING. -- H.J.