From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ot1-x335.google.com (mail-ot1-x335.google.com [IPv6:2607:f8b0:4864:20::335]) by sourceware.org (Postfix) with ESMTPS id 697DF3969007 for ; Mon, 19 Apr 2021 12:57:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 697DF3969007 Received: by mail-ot1-x335.google.com with SMTP id c8-20020a9d78480000b0290289e9d1b7bcso18371406otm.4 for ; Mon, 19 Apr 2021 05:57:01 -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=tbO4hHDq68mM30tEjdmfYQ7N5CwfEedbI1bVMjYskJ4=; b=sA0L+xWK/BBCx72Got6KimK+OKdSpVPOMGkpDuAdqAKTxq50+OLYjLD39bM8VFLhIq VF+tyk1X8/EvJVluwhRTYUi8jUDvb99o8SI+82dvVVKhSrP918t4EAo2Q9rev6//EqfK cKOokSqgolHaKkqlcaqr9gK6BULVtRSxfXLj6obuO+gThYKvImbb2u6ejctHGpLPMNWF hDOb2HBTSQGIno8TWBs40kpUgqvqY3NjZojJTdx95sSfHTIGivTCOSxTvxoubQvRj3wN m7I2l9s3eoCDsKPwvXDui9QYBoG2ssCblblXskbBsJVBI1ZZYZINOVxrdlaj0WwVd9QE P6QA== X-Gm-Message-State: AOAM532qkib/6lXXOdczpl9M68w6RTeXno/JmZ1+/u8exm29H9FjzTMw bEY59238cw/RYhBJGQbGKrK8qBxekS9tjH7u8Gg= X-Google-Smtp-Source: ABdhPJyVwV6oh3tLXmnvA53HdkfzuC43nWPc/F87ZapXtKid0wUsJyuduQfAIshyNPdRLcQlqpqWtKARnf7A5A13RHE= X-Received: by 2002:a05:6830:1515:: with SMTP id k21mr14620565otp.269.1618837020879; Mon, 19 Apr 2021 05:57:00 -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: Mon, 19 Apr 2021 05:56:25 -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=-3028.6 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: Mon, 19 Apr 2021 12:57:11 -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. > > -- > H.J. PING. -- H.J.