From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 3C3423858D28 for ; Wed, 18 Jan 2023 22:31:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3C3423858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1674081099; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=y/1jmLGqq0pYYGtyVQz23oyOAWFtsgYDSfDboGu1jG0=; b=WvEpm7kyT30/EV6WOU6d8YvN21+Qc0hmFGG0PQ96lGD3EmgjcBkafETDxsjVqLh7bbGz5n k0bRRwO5MJ/HRgwfbewQpdxd95zpDXFUcRRXYrwPbWwt4jORXFp1SLgi5uObDUIswojiCT yVRwalri5M0f7OuWMlPtxUtus7HnY/4= 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-663-8GwyM5hsNSyf4ydoq3bZ5Q-1; Wed, 18 Jan 2023 17:31:38 -0500 X-MC-Unique: 8GwyM5hsNSyf4ydoq3bZ5Q-1 Received: by mail-io1-f70.google.com with SMTP id f12-20020a056602038c00b00704b6f4685dso196286iov.9 for ; Wed, 18 Jan 2023 14:31:38 -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 :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=y/1jmLGqq0pYYGtyVQz23oyOAWFtsgYDSfDboGu1jG0=; b=GLfvnWIeS/glOxwj0QKx6QWwhaqhMB7+q3GWYO9JfWpqPXiLYRVZrhkciOxoNo9wK0 hXBkk8MTVYqTKlRi1cY2yCOjmgGCIfPanIoFNhUlGrgDZOhjzNNM/janQtezZX92vmlG DhxtYL1fK1HLUOxTGR52oTpPVkN8qYbMg1S5UycGExThj0HPlvkxsAxCuOBA8P5eY8g3 tHuHcJOmr3UmmcaJG1wLWGHum/bLfum4rDXac6SgI0aRuhJASK/e3r2fCu7MteDxs+vl 7ZAoKZuLSdTlQTg8Fd55Cz94ABHpEnmYmHtHjXLRM+q59e1pwLCodLh148SKhLlodr+a nMgA== X-Gm-Message-State: AFqh2kqFOsCZ8tpl8gcT0mFCKFnEhyF5RG0hDnHXTVko1S6siBS9YHHz E0oetsOJMI7h5ZBz23HRXNXA3JaAj+1IYMO1ZVnlfQxqAqusswL0Lf9+xWMc0pDR4ytLpEyiXAf JceA1OJ1G9uvHvVX/9w9n X-Received: by 2002:a05:6e02:ef0:b0:30d:7ed1:6e90 with SMTP id j16-20020a056e020ef000b0030d7ed16e90mr6901783ilk.28.1674081097141; Wed, 18 Jan 2023 14:31:37 -0800 (PST) X-Google-Smtp-Source: AMrXdXt1PKf2gxZpVkZ11JEUmmO5JUMyiDEMmUuS/lpzFLCNQDwCr4wbeUFek/516ZbGLEBzVQ6aKg== X-Received: by 2002:a05:6e02:ef0:b0:30d:7ed1:6e90 with SMTP id j16-20020a056e020ef000b0030d7ed16e90mr6901772ilk.28.1674081096891; Wed, 18 Jan 2023 14:31:36 -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 e16-20020a92de50000000b0030db1001846sm7563244ilr.82.2023.01.18.14.31.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 Jan 2023 14:31:36 -0800 (PST) Message-ID: Date: Wed, 18 Jan 2023 17:31:35 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Subject: Re: [PATCH v4 6/6] Linux: optimize clone3 internal usage To: Adhemerval Zanella , libc-alpha@sourceware.org References: <20230112135853.3786675-1-adhemerval.zanella@linaro.org> <20230112135853.3786675-7-adhemerval.zanella@linaro.org> From: Carlos O'Donell Organization: Red Hat In-Reply-To: <20230112135853.3786675-7-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-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,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 1/12/23 08:58, Adhemerval Zanella wrote: > Add an optimization to avoid calling clone3 when glibc detects that > there is no kernel support. It also adds __ASSUME_CLONE3, which allows > skipping this optimization and issuing the 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. OK for 2.28. Reviewed-by: Carlos O'Donell > --- > 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 3b6cd85f02..dd380f119e 100644 > --- a/include/clone_internal.h > +++ b/include/clone_internal.h > @@ -24,6 +24,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-issuing 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 e125c9125e..790739cfce 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; > +} OK. > > 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 a23d0079a1..4b5c4afbc1 100644 > --- a/sysdeps/unix/sysv/linux/kernel-features.h > +++ b/sysdeps/unix/sysv/linux/kernel-features.h > @@ -241,4 +241,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.