From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.1 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 484FB1F47C for ; Wed, 11 Jan 2023 21:45:34 +0000 (UTC) Authentication-Results: dcvr.yhbt.net; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=kaiFN41D; dkim-atps=neutral Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9B4FA3856975 for ; Wed, 11 Jan 2023 21:45:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9B4FA3856975 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1673473533; bh=QLZLbZwxmJ9hBXvtFZbC0Q6OxBkEvbzS8Broaa+wqow=; h=Date:Subject:To:Cc:References:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=kaiFN41DAETU64b0sR9g/GiI9AWnJQZ5v6szLd2E8Ry0fLglyJIwPhcW+U+HlvkSp B7OMhUUsNT6lJf24XOQSNmBWedESTHxVHh9KoXQVrbyeVwXivrtuLSnxG/wYVW2rb3 Ked9rDNi0SU+JJZYocKADNv48mp7GWeusHam3k0M= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 5F2643858C83 for ; Wed, 11 Jan 2023 21:45:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5F2643858C83 Received: from mail-io1-f70.google.com (mail-io1-f70.google.com [209.85.166.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-190-SbB2MKsTNtiH_wzg31ujXA-1; Wed, 11 Jan 2023 16:45:13 -0500 X-MC-Unique: SbB2MKsTNtiH_wzg31ujXA-1 Received: by mail-io1-f70.google.com with SMTP id be25-20020a056602379900b006f166af94d6so9799970iob.8 for ; Wed, 11 Jan 2023 13:45:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=QLZLbZwxmJ9hBXvtFZbC0Q6OxBkEvbzS8Broaa+wqow=; b=4UXhjzhc7SaoholcMj3eAoJ/QT1XZRNZbYsKBKtPJqIsPPqo6/Xx3FILUyZfC1Lq2I cR2rpgKMhOFx3nW2h3Gveibj7A2Xfhoz2JUKyzmiKby+mMbp0VTPYdHDPoO1OYGNgL4r szq1ci2BHA9yPVM/YLbs2TEBANBZBBI2FXRfY0U7BnuS+q4qIBH339JFFp/rQ75Wjfdz 87lQlM8BtOiZYxLK7eTzHdjG7Xz4x/U8XBIScVWUnyIdzl3zvuEWLQKCfrCDvC+5wBJ2 6al5b61QTDc9ZeND+NgFd5yxs4V1/BHrthucdBX2FNTjMLjAgEdDLXelGIjGvm5fShkw 1O3w== X-Gm-Message-State: AFqh2konQmltnRiCgNuwH9fwX8HgUiQmbdVhYTtb8ODo7s37qYWtR6N/ UX3o+L57BmaLn6job2hQtHzf/OtsIbnEs3f4gDjSXTe4ey6t0dEDEOjLx6xPT32wcaGpgFqioG4 E/TKwAVq/1NDy8XVRorhl X-Received: by 2002:a92:da42:0:b0:302:a58f:38ab with SMTP id p2-20020a92da42000000b00302a58f38abmr48794668ilq.0.1673473512370; Wed, 11 Jan 2023 13:45:12 -0800 (PST) X-Google-Smtp-Source: AMrXdXti98UCnUnE0rvO8V50kl1mdLwb0T+45xGxni5+iapwawAzQxDGFLY2faWOuyQBdCrqS6jDwA== X-Received: by 2002:a92:da42:0:b0:302:a58f:38ab with SMTP id p2-20020a92da42000000b00302a58f38abmr48794658ilq.0.1673473512134; Wed, 11 Jan 2023 13:45:12 -0800 (PST) Received: from [192.168.0.241] (192-0-145-146.cpe.teksavvy.com. [192.0.145.146]) by smtp.gmail.com with ESMTPSA id l10-20020a02664a000000b0038826e709e2sm4647648jaf.111.2023.01.11.13.45.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 11 Jan 2023 13:45:11 -0800 (PST) Message-ID: Date: Wed, 11 Jan 2023 16:45:10 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 Subject: Re: [PATCH v2 11/11] Linux: optimize clone3 internal usage To: Adhemerval Zanella , libc-alpha@sourceware.org, Szabolcs Nagy , "H . J . Lu" Cc: Christian Brauner References: <20221104190112.2566409-1-adhemerval.zanella@linaro.org> <20221104190112.2566409-12-adhemerval.zanella@linaro.org> Organization: Red Hat In-Reply-To: <20221104190112.2566409-12-adhemerval.zanella@linaro.org> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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: , From: Carlos O'Donell via Libc-alpha Reply-To: Carlos O'Donell Errors-To: libc-alpha-bounces+e=80x24.org@sourceware.org Sender: "Libc-alpha" On 11/4/22 15:01, Adhemerval Zanella via Libc-alpha wrote: > Now that clone3 is used on more architectures, add an optimization > to avoid calling when glibc detects that it is no supported by the > kernel. It also adds __ASSUME_CLONE3, which allows skip this > optimization and issue clone3 syscall directly. > > It does not handle the the small window between 5.3 and 5.5 for > posix_spawn (CLONE_CLEAR_SIGHAND was added in 5.5). > > Checked on x86_64-linux-gnu. Please see original v2 review. Please post v4. > --- > include/clone_internal.h | 5 +++++ > sysdeps/unix/sysv/linux/clone-internal.c | 24 ++++++++++++++++++++++- > sysdeps/unix/sysv/linux/kernel-features.h | 9 +++++++++ > 3 files changed, 37 insertions(+), 1 deletion(-) > > diff --git a/include/clone_internal.h b/include/clone_internal.h > index 81292b3eb1..5f936dd8dc 100644 > --- a/include/clone_internal.h > +++ b/include/clone_internal.h > @@ -26,6 +26,11 @@ extern int __clone3 (struct clone_args *__cl_args, size_t __size, > fall back to clone or clone2. */ > extern int __clone_internal (struct clone_args *__cl_args, > int (*__func) (void *__arg), void *__arg); > +/* clone3 wrapper with a sticky check to avoid re-issue the syscall if > + it fails with ENOSYS. */ > +extern int __clone3_internal (struct clone_args *cl_args, > + int (*func) (void *args), void *arg) > + attribute_hidden; > /* The fallback code which calls clone/clone2 based on clone3 arguments. */ > extern int __clone_internal_fallback (struct clone_args *__cl_args, > int (*__func) (void *__arg), > diff --git a/sysdeps/unix/sysv/linux/clone-internal.c b/sysdeps/unix/sysv/linux/clone-internal.c > index 7bc991e033..39d76733db 100644 > --- a/sysdeps/unix/sysv/linux/clone-internal.c > +++ b/sysdeps/unix/sysv/linux/clone-internal.c > @@ -76,6 +76,28 @@ __clone_internal_fallback (struct clone_args *cl_args, > return ret; > } > > +int > +__clone3_internal (struct clone_args *cl_args, int (*func) (void *args), > + void *arg) > +{ > +#ifdef HAVE_CLONE3_WRAPPER > +# if __ASSUME_CLONE3 > + return __clone3 (cl_args, sizeof (*cl_args), func, arg); > +# else > + static int clone3_supported = 1; > + if (atomic_load_relaxed (&clone3_supported) == 1) > + { > + int ret = __clone3 (cl_args, sizeof (*cl_args), func, arg); > + if (ret != -1 || errno != ENOSYS) > + return ret; > + > + atomic_store_relaxed (&clone3_supported, 0); > + } > +# endif > +#endif > + __set_errno (ENOSYS); > + return -1; > +} > > int > __clone_internal (struct clone_args *cl_args, > @@ -83,7 +105,7 @@ __clone_internal (struct clone_args *cl_args, > { > #ifdef HAVE_CLONE3_WRAPPER > int saved_errno = errno; > - int ret = __clone3 (cl_args, sizeof (*cl_args), func, arg); > + int ret = __clone3_internal (cl_args, func, arg); > if (ret != -1 || errno != ENOSYS) > return ret; > > diff --git a/sysdeps/unix/sysv/linux/kernel-features.h b/sysdeps/unix/sysv/linux/kernel-features.h > index 74adc3956b..4ecd08a98f 100644 > --- a/sysdeps/unix/sysv/linux/kernel-features.h > +++ b/sysdeps/unix/sysv/linux/kernel-features.h > @@ -236,4 +236,13 @@ > # define __ASSUME_FUTEX_LOCK_PI2 0 > #endif > > +/* The clone3 system call was introduced across on most architectures in > + Linux 5.3. Not all ports implements it, so it should be used along > + HAVE_CLONE3_WRAPPER define. */ > +#if __LINUX_KERNEL_VERSION >= 0x050300 > +# define __ASSUME_CLONE3 1 > +#else > +# define __ASSUME_CLONE3 0 > +#endif > + > #endif /* kernel-features.h */ -- Cheers, Carlos.