From patchwork Fri Nov 4 19:01:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 59958 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1A6E83857368 for ; Fri, 4 Nov 2022 19:02:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1A6E83857368 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1667588562; bh=0woY+EMgt7ar7mF/5FQNhOpufYgjE/zBTuF4VwR2cfE=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=FhUuX/HeadQZ+w864fL6XkFqoM4gx/dp9VbVQqAVBACDdmYGI5X01uafna9S6scMr gROJq0XPYQx4uuvhX0wit2SoVMpB+SG13SPGVqYIBArd3R7Eb2xU36jZOThEd18yo4 F2GvBCfo/FRRbS5zeJoJryL7+5IntUcXp5cKHcu8= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x232.google.com (mail-oi1-x232.google.com [IPv6:2607:f8b0:4864:20::232]) by sourceware.org (Postfix) with ESMTPS id 4BD1B3858C2B for ; Fri, 4 Nov 2022 19:01:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4BD1B3858C2B Received: by mail-oi1-x232.google.com with SMTP id b124so6118177oia.4 for ; Fri, 04 Nov 2022 12:01:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0woY+EMgt7ar7mF/5FQNhOpufYgjE/zBTuF4VwR2cfE=; b=dS7kZGCB8skaoMczshJEpUp5AS/9LS95ST7YGBSIFmLPokdS5zhAWHPtMSuuKbdOb8 HKg86aDmgyQSw+OPgDZIY8047kWXdUqjOA1JSyJW9PRu1ebUDFuigmvTCgasgVMoK14l fw6kWgvAVw9RppJmc9/pfNtjUCpCs9E33PEMYWyK5fWz7jeE/6hV5EZ5Q812TyzDZ46h T/zxha4aMxmB3nC/FzX+pH3k3DYPpnPmDwxQxDcTl/v2Ah1DMmn8Z8BpYthYYjwD8VfM SfNh3lpIV4rPXjx64Eg+l1zerOK3nt4daM6JZ1VRj7gEILQ/38PBQUBae5YDsrAW8ZSY yZPA== X-Gm-Message-State: ACrzQf1QkXMkcOcQRDA6sCgumNBsT0dEktmWhx/wtElcceYxYOzkr5jO myhXJArzrwd9zR1gJ3JP/pdUazq8ovcVl7lw X-Google-Smtp-Source: AMsMyM7trh7QKBH48zyBSR7bB9WE4773eD6C5StCT5VmdAiwKxSBPYTRJVX8qfFbOVJl9jSpTlhXKg== X-Received: by 2002:a05:6808:1391:b0:35a:6109:c91b with SMTP id c17-20020a056808139100b0035a6109c91bmr1932452oiw.273.1667588478375; Fri, 04 Nov 2022 12:01:18 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:a9f4:f725:94bd:4cc1:1762]) by smtp.gmail.com with ESMTPSA id 24-20020aca1018000000b0035763a9a36csm1764713oiq.44.2022.11.04.12.01.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Nov 2022 12:01:18 -0700 (PDT) To: libc-alpha@sourceware.org, Szabolcs Nagy , "H . J . Lu" Subject: [PATCH v2 01/11] linux: Do not reset signal handler in posix_spawn if it is already SIG_DFL Date: Fri, 4 Nov 2022 16:01:02 -0300 Message-Id: <20221104190112.2566409-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221104190112.2566409-1-adhemerval.zanella@linaro.org> References: <20221104190112.2566409-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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 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-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Cc: Christian Brauner Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" There is no need to issue another sigaction is the disposition is already SIG_DFL. Checked on x86_64-linux-gnu. --- sysdeps/unix/sysv/linux/spawni.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sysdeps/unix/sysv/linux/spawni.c b/sysdeps/unix/sysv/linux/spawni.c index ee843a2247..65ee03c804 100644 --- a/sysdeps/unix/sysv/linux/spawni.c +++ b/sysdeps/unix/sysv/linux/spawni.c @@ -129,7 +129,7 @@ __spawni_child (void *arguments) else { __libc_sigaction (sig, 0, &sa); - if (sa.sa_handler == SIG_IGN) + if (sa.sa_handler == SIG_IGN || sa.sa_handler == SIG_DFL) continue; sa.sa_handler = SIG_DFL; } From patchwork Fri Nov 4 19:01:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 59955 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EB31C3858032 for ; Fri, 4 Nov 2022 19:01:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EB31C3858032 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1667588513; bh=buS1lWL805YydjDHYqz8twFaFsmIee4PaudAdu3a/a0=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=Ivx4deSmnbhYupmf+reApmUyZWSPCPoxfWvEMGY+zT17we2Luo3RnI3B1UDLaYQmz C8blK4iyGqldFHiYDB2xqjdW5hpGpJgcrwWe1QyJ+A5bhOtfCXxT8sky69tQJik+j9 7JlYLPbwtBr5GUpeiL1Byn+7DrQXO9qL8s7IRWWc= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x232.google.com (mail-oi1-x232.google.com [IPv6:2607:f8b0:4864:20::232]) by sourceware.org (Postfix) with ESMTPS id DFDF43858423 for ; Fri, 4 Nov 2022 19:01:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DFDF43858423 Received: by mail-oi1-x232.google.com with SMTP id m204so6113987oib.6 for ; Fri, 04 Nov 2022 12:01:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=buS1lWL805YydjDHYqz8twFaFsmIee4PaudAdu3a/a0=; b=UVsCH/IgFzA9HZZR3A5jLrgpqt/EMov56XE2ZVLXes8HtkaExHWwbTTqyr2jBNsr9C mZ+lUX3UCfvAJEKzCo5mshBrAmKOgdHUNbs8yJzUDXZezYVUTgRjOhLtHYj6FpfKBmQ1 Zp2nIuM3czjAnOEjzMCDLEGadpYza4caPjI4/SL3/SSYR6F8pDA1Ld8FRmIJ2M5gF5LG Aehd4RD8taUN0Ia3US3eCDGKaVK1kJZ8DdWkCzg9dQaKkSVhB7amxJy89wSHtusepUxv HITOJDkMmNYZkhGcQCi8d7IoSQnY2qd9yECB6sRKgXm8pp7u2akjRA3v3MklLJGK6j2/ AwDQ== X-Gm-Message-State: ACrzQf1U1ACE4dzS2fj0ng8Brvc9WkEWYSEIMZuNHRPDkSnJD5SCLF69 6SE6/TvQl4Uj0m6uxcR+PgP4JxRCyOziXDpg X-Google-Smtp-Source: AMsMyM4SXA5CsYu4WOV7Xc/fyKpNWTFYV5TbVgKEgUQQPIt8gr0OTZnoxukBGae2dQxx+m91eCXPEA== X-Received: by 2002:aca:b546:0:b0:35a:51fc:20fb with SMTP id e67-20020acab546000000b0035a51fc20fbmr4822819oif.85.1667588480062; Fri, 04 Nov 2022 12:01:20 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:a9f4:f725:94bd:4cc1:1762]) by smtp.gmail.com with ESMTPSA id 24-20020aca1018000000b0035763a9a36csm1764713oiq.44.2022.11.04.12.01.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Nov 2022 12:01:19 -0700 (PDT) To: libc-alpha@sourceware.org, Szabolcs Nagy , "H . J . Lu" Subject: [PATCH v2 02/11] linux: Extend internal clone3 documentation Date: Fri, 4 Nov 2022 16:01:03 -0300 Message-Id: <20221104190112.2566409-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221104190112.2566409-1-adhemerval.zanella@linaro.org> References: <20221104190112.2566409-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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 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-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Cc: Christian Brauner Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Different than kernel, clone3 returns EINVAL for NULL struct clone_args or function pointer. This is similar to clone interface that return EINVAL for NULL function argument. It also clean up the Linux clone3.h interface, since it not currently exported. Checked on x86_64-linux-gnu. Reviewed-by: Szabolcs Nagy --- include/clone_internal.h | 24 +++++++++++++++++++----- sysdeps/unix/sysv/linux/clone3.h | 10 +--------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/include/clone_internal.h b/include/clone_internal.h index 4b23ef33ce..73b8114df4 100644 --- a/include/clone_internal.h +++ b/include/clone_internal.h @@ -1,10 +1,24 @@ -#ifndef _CLONE3_H -#include_next +#ifndef _CLONE_INTERNAL_H +#define _CLONE_INTERNAL_H -extern __typeof (clone3) __clone3; +#include -/* The internal wrapper of clone/clone2 and clone3. If __clone3 returns - -1 with ENOSYS, fall back to clone or clone2. */ +/* The clone3 syscall provides a superset of the functionality of the clone + interface. The kernel might extend __CL_ARGS struct in the future, with + each version with a diffent __SIZE. If the child is created, it will + start __FUNC function with __ARG arguments. + + Different than kernel, the implementation also returns EINVAL for an + invalid NULL __CL_ARGS or __FUNC (similar to __clone). + + This function is only implemented if the ABI defines HAVE_CLONE3_WRAPPER. +*/ +extern int __clone3 (struct clone_args *__cl_args, size_t __size, + int (*__func) (void *__arg), void *__arg); + +/* The internal wrapper of clone/clone2 and clone3. Different than __clone3, + it will align the stack if required. If __clone3 returns -1 with ENOSYS, + fall back to clone or clone2. */ extern int __clone_internal (struct clone_args *__cl_args, int (*__func) (void *__arg), void *__arg); diff --git a/sysdeps/unix/sysv/linux/clone3.h b/sysdeps/unix/sysv/linux/clone3.h index 889014a6a9..7c7e2cdcb0 100644 --- a/sysdeps/unix/sysv/linux/clone3.h +++ b/sysdeps/unix/sysv/linux/clone3.h @@ -1,4 +1,4 @@ -/* The wrapper of clone3. +/* The clone3 kernel interface definitions. Copyright (C) 2021-2022 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -23,8 +23,6 @@ #include #include -__BEGIN_DECLS - /* The unsigned 64-bit and 8-byte aligned integer type. */ typedef __U64_TYPE __aligned_uint64_t __attribute__ ((__aligned__ (8))); @@ -58,10 +56,4 @@ struct clone_args __aligned_uint64_t cgroup; }; -/* The wrapper of clone3. */ -extern int clone3 (struct clone_args *__cl_args, size_t __size, - int (*__func) (void *__arg), void *__arg); - -__END_DECLS - #endif /* clone3.h */ From patchwork Fri Nov 4 19:01:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 59962 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D2471385741E for ; Fri, 4 Nov 2022 19:04:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D2471385741E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1667588645; bh=gnmIwmLU9JVdyOReTyN46Fa6aAxsdMNzd6qprRaYUBA=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=ds8BDeFPZgU3JejVn73/FmctYDfaCGXbXCGp+baFo6GmvTKre2yc+bgwZ5qBm/L6c pXXXmYBgQKtcIdkXRkVsHU66IRPieHfjlWWOxW9xCXy3MwTA2kRsn0/iQZtmUA6kIU +XqOfTCGRju+n61tVHqXKCgbrQnO+dzoL+MhUK/Y= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oa1-x2e.google.com (mail-oa1-x2e.google.com [IPv6:2001:4860:4864:20::2e]) by sourceware.org (Postfix) with ESMTPS id D3D76385842E for ; Fri, 4 Nov 2022 19:01:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D3D76385842E Received: by mail-oa1-x2e.google.com with SMTP id 586e51a60fabf-13bd2aea61bso6577027fac.0 for ; Fri, 04 Nov 2022 12:01:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gnmIwmLU9JVdyOReTyN46Fa6aAxsdMNzd6qprRaYUBA=; b=zkwVLQkQMBvaejQg80AoErGCa4RTyBDj0QBPkFwMBQFBfP+H3rMHJU/wODpNv2l35G qbIP0ufe6V9Mw9e7ikMPsKPYspCepkH7tZUzMjnH+MY6lWVHoowV0IPNtYJe4LpWBZox emc0ydt9ZqvPLkx5B0CsD0NwHkCmjzhk/dlzLWHMnm01aGv0aKv0XOqSbUes8ZuaVV1O PaGpUXYPuDCRPk7hQeesBUtM72tE3QmxeT8UQO6i3SQLppdW36onaGTiDHLpjHAT4hGT tne8N4Q466jeqqE4VoeXFJLvpK5bgJyPCvBO4Pf7+i6VqcTg40Ebq/Uf4bGBgALNnIOL 98QA== X-Gm-Message-State: ACrzQf184t8JFogcRIe+OLZBzPBIMdoqLqkWiz1tO2wLoRYV4H3d43s+ 3uyn46EVDgzdFjrSuxhpmFa/mv0GNLD6A8Lo X-Google-Smtp-Source: AMsMyM6c9qoMUrjC700i5QLayMq3jdQtMSGWx7jeCplDJkMotHPXmVL7NLolbRaEA+U0pDrpMENOGA== X-Received: by 2002:a05:6870:d285:b0:12b:cdce:63d8 with SMTP id d5-20020a056870d28500b0012bcdce63d8mr31011948oae.140.1667588481928; Fri, 04 Nov 2022 12:01:21 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:a9f4:f725:94bd:4cc1:1762]) by smtp.gmail.com with ESMTPSA id 24-20020aca1018000000b0035763a9a36csm1764713oiq.44.2022.11.04.12.01.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Nov 2022 12:01:21 -0700 (PDT) To: libc-alpha@sourceware.org, Szabolcs Nagy , "H . J . Lu" Subject: [PATCH v2 03/11] Linux: Do not align the stack for __clone3 Date: Fri, 4 Nov 2022 16:01:04 -0300 Message-Id: <20221104190112.2566409-4-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221104190112.2566409-1-adhemerval.zanella@linaro.org> References: <20221104190112.2566409-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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 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-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Cc: Christian Brauner Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Adjusting the stack on child thread is not async-signal safe, since kernel does not enforce stack alignmnet. Although, all the internal usage of __clone_internal are done with all signal masked, removing stack alignment of __clone3 is still a net gain: is simplifies the function contract detail (mask/unmarsk signals) and simplifies the arch-specific code. The internal users are responsible for correct stack alignment. If glibc ever exports a clone3 wrapper, it should adjust stack alignment. Checked on x86_64-linux-gnu. --- include/clone_internal.h | 5 ++ .../sysv/linux/tst-misalign-clone-internal.c | 74 ------------------- sysdeps/unix/sysv/linux/x86_64/clone3.S | 3 - 3 files changed, 5 insertions(+), 77 deletions(-) delete mode 100644 sysdeps/unix/sysv/linux/tst-misalign-clone-internal.c diff --git a/include/clone_internal.h b/include/clone_internal.h index 73b8114df4..5a48c7caa5 100644 --- a/include/clone_internal.h +++ b/include/clone_internal.h @@ -11,6 +11,11 @@ Different than kernel, the implementation also returns EINVAL for an invalid NULL __CL_ARGS or __FUNC (similar to __clone). + The stack is not aligned prior the syscall, different than exported + __clone. Adjusting the stack on child is not async-signal safe and since + it is used only internally the caller is responsible for proper stack + alignment. + This function is only implemented if the ABI defines HAVE_CLONE3_WRAPPER. */ extern int __clone3 (struct clone_args *__cl_args, size_t __size, diff --git a/sysdeps/unix/sysv/linux/tst-misalign-clone-internal.c b/sysdeps/unix/sysv/linux/tst-misalign-clone-internal.c deleted file mode 100644 index e039ca5a3a..0000000000 --- a/sysdeps/unix/sysv/linux/tst-misalign-clone-internal.c +++ /dev/null @@ -1,74 +0,0 @@ -/* Verify that __clone_internal properly aligns the child stack. - Copyright (C) 2021-2022 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static int -check_stack_alignment (void *arg) -{ - puts ("in f"); - - return TEST_STACK_ALIGN () ? 1 : 0; -} - -static int -do_test (void) -{ - puts ("in do_test"); - - if (TEST_STACK_ALIGN ()) - FAIL_EXIT1 ("stack isn't aligned\n"); - -#ifdef __ia64__ -# define STACK_SIZE (256 * 1024) -#else -# define STACK_SIZE (128 * 1024) -#endif - char st[STACK_SIZE + 1]; - /* NB: Align child stack to 1 byte. */ - char *stack = PTR_ALIGN_UP (&st[0], 2) + 1; - struct clone_args clone_args = - { - .stack = (uintptr_t) stack, - .stack_size = STACK_SIZE, - }; - pid_t p = __clone_internal (&clone_args, check_stack_alignment, 0); - - /* Clone must not fail. */ - TEST_VERIFY_EXIT (p != -1); - - int e; - xwaitpid (p, &e, __WCLONE); - TEST_VERIFY (WIFEXITED (e)); - TEST_COMPARE (WEXITSTATUS (e), 0); - - return 0; -} - -#include diff --git a/sysdeps/unix/sysv/linux/x86_64/clone3.S b/sysdeps/unix/sysv/linux/x86_64/clone3.S index 18fc2ee966..989b62bdf6 100644 --- a/sysdeps/unix/sysv/linux/x86_64/clone3.S +++ b/sysdeps/unix/sysv/linux/x86_64/clone3.S @@ -73,9 +73,6 @@ L(thread_start): the outermost frame obviously. */ xorl %ebp, %ebp - /* Align stack to 16 bytes per the x86-64 psABI. */ - and $-16, %RSP_LP - /* Set up arguments for the function call. */ mov %R8_LP, %RDI_LP /* Argument. */ call *%rdx /* Call function. */ From patchwork Fri Nov 4 19:01:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 59957 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CAC6D38582B1 for ; Fri, 4 Nov 2022 19:02:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CAC6D38582B1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1667588535; bh=UxhPxAR3X0b7CyHw9aEUddL4LU/ruOKsSXNbFOwO1r0=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=ExY0kC9eE8qMgzWWbyYZv+lNtLU7opFtmDyIb5Fs3S84Y76chJXfFxugh2fU9m66z C8zFefk2u5QmtVTSmBoWkOAXJ6S6ZMuv0TcTNUiZ2kSgMDax7AlYrzdx6bHie62uHQ 8UiN2aHaLevT81UbwW7CTwKvpoZ0Lpcd4hXpuzlY= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x231.google.com (mail-oi1-x231.google.com [IPv6:2607:f8b0:4864:20::231]) by sourceware.org (Postfix) with ESMTPS id CE583385842F for ; Fri, 4 Nov 2022 19:01:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CE583385842F Received: by mail-oi1-x231.google.com with SMTP id y67so6137164oiy.1 for ; Fri, 04 Nov 2022 12:01:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UxhPxAR3X0b7CyHw9aEUddL4LU/ruOKsSXNbFOwO1r0=; b=T/KRRHV1SERGIB7QWAhauTKqlVxo0PgDDI/k2M3rsD08ZNSJ5TPJNCUWdUg8jrZGl4 L56694D8ohhmiUva8mPN8QQNS/2L21BZBcPj/YJpcM+r07/eatB97tqCC/Wt83x7O/aq 8jcxnNlMgjXkCOh7Cp/p8y+l+PV7wWvxXuuSs7bku53X5LcQrIkA7f8Mf0DPIZwSnBmD YUOR/Y3G787184EhWSsApUds1KZYckCPMSXThBNHfUt3p2oIoTRupQduLI5QtQ14Z5vE soWVvqO0AbP70Jgvp9U6vJ95MAW+Le1IVJYywTfsoMC4JRua7T26KnpBw8ffnxBw3B3B 338A== X-Gm-Message-State: ACrzQf1szHWrhdGf/n79m1dn+cfjUyxHqZb/aPZzlzQhCppyF8U4F9J4 3Nsf4toC9bgxf8ulEMjMax6zIhXP3EG+3ijw X-Google-Smtp-Source: AMsMyM7wQ4P3JTZMYE4NhZikUYVDM9Y5xk9J9mjl05uFLdqwtYLQlByQklDhTeBirPRM/uk55L65nA== X-Received: by 2002:a05:6808:218c:b0:355:231d:54a6 with SMTP id be12-20020a056808218c00b00355231d54a6mr20362015oib.4.1667588483711; Fri, 04 Nov 2022 12:01:23 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:a9f4:f725:94bd:4cc1:1762]) by smtp.gmail.com with ESMTPSA id 24-20020aca1018000000b0035763a9a36csm1764713oiq.44.2022.11.04.12.01.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Nov 2022 12:01:23 -0700 (PDT) To: libc-alpha@sourceware.org, Szabolcs Nagy , "H . J . Lu" Subject: [PATCH v2 04/11] linux: Add clone3 CLONE_CLEAR_SIGHAND optimization to posix_spawn Date: Fri, 4 Nov 2022 16:01:05 -0300 Message-Id: <20221104190112.2566409-5-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221104190112.2566409-1-adhemerval.zanella@linaro.org> References: <20221104190112.2566409-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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 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-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Cc: Christian Brauner Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" The clone3 flag resets all signal handlers of the child not set to SIG_IGN to SIG_DFL. It allows to skip most of the sigaction calls to setup child signal handling, where previously a posix_spawn has to issue 2 times NSIG sigaction calls (one to obtain the current disposition and another to set either SIG_DFL or SIG_IGN). The expection is POSIX_SPAWN_SETSIGDEF the child still setup the signal for the case the disposition is SIG_IGN. It also need to handle the fallback where clone3 is not available, to set the fallback in child. This is done by splitting of __clone_internal_fallback from __clone_internal. Checked on x86_64-linux-gnu. --- include/clone_internal.h | 5 + posix/Makefile | 3 +- posix/tst-spawn7.c | 179 +++++++++++++++++++++++ sysdeps/unix/sysv/linux/Makefile | 3 +- sysdeps/unix/sysv/linux/clone-internal.c | 37 +++-- sysdeps/unix/sysv/linux/clone3.h | 7 + sysdeps/unix/sysv/linux/spawni.c | 31 ++-- 7 files changed, 238 insertions(+), 27 deletions(-) create mode 100644 posix/tst-spawn7.c diff --git a/include/clone_internal.h b/include/clone_internal.h index 5a48c7caa5..81292b3eb1 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); +/* 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), + void *__arg) + attribute_hidden; #ifndef _ISOMAC libc_hidden_proto (__clone3) diff --git a/posix/Makefile b/posix/Makefile index 4d60449426..6e61ce50f2 100644 --- a/posix/Makefile +++ b/posix/Makefile @@ -109,7 +109,7 @@ tests := test-errno tstgetopt testfnm runtests runptests \ tst-glob-tilde test-ssize-max tst-spawn4 bug-regex37 \ bug-regex38 tst-regcomp-truncated tst-spawn-chdir \ tst-wordexp-nocmd tst-execveat tst-spawn5 \ - tst-sched_getaffinity tst-spawn6 + tst-sched_getaffinity tst-spawn6 tst-spawn7 # Test for the glob symbol version that was replaced in glibc 2.27. ifeq ($(have-GLIBC_2.26)$(build-shared),yesyes) @@ -291,6 +291,7 @@ tst-spawn-ARGS = -- $(host-test-program-cmd) tst-spawn-static-ARGS = $(tst-spawn-ARGS) tst-spawn5-ARGS = -- $(host-test-program-cmd) tst-spawn6-ARGS = -- $(host-test-program-cmd) +tst-spawn7-ARGS = -- $(host-test-program-cmd) tst-dir-ARGS = `pwd` `cd $(common-objdir)/$(subdir); pwd` `cd $(common-objdir); pwd` $(objpfx)tst-dir tst-chmod-ARGS = $(objdir) tst-vfork3-ARGS = --test-dir=$(objpfx) diff --git a/posix/tst-spawn7.c b/posix/tst-spawn7.c new file mode 100644 index 0000000000..7cb7347c58 --- /dev/null +++ b/posix/tst-spawn7.c @@ -0,0 +1,179 @@ +/* Tests for posix_spawn signal handling. + Copyright (C) 2022 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 +#include +#include +#include +#include +#include +#include + +/* Nonzero if the program gets called via `exec'. */ +#define CMDLINE_OPTIONS \ + { "restart", no_argument, &restart, 1 }, +static int restart; + +/* Hold the four initial argument used to respawn the process, plus the extra + '--direct', '--restart', the check type ('SIG_IGN' or 'SIG_DFL'), and a + final NULL. */ +static char *spargs[8]; +static int check_type_argc; + +/* Called on process re-execution. */ +_Noreturn static void +handle_restart (int argc, char *argv[]) +{ + assert (argc == 1); + + if (strcmp (argv[0], "SIG_DFL") == 0) + { + for (int i = 1; i < NSIG; i++) + { + struct sigaction sa; + int r = sigaction (i, NULL, &sa); + /* Skip internal signals (such as SIGCANCEL). */ + if (r == -1) + continue; + TEST_VERIFY_EXIT (sa.sa_handler == SIG_DFL); + } + exit (EXIT_SUCCESS); + } + else if (strcmp (argv[0], "SIG_IGN") == 0) + { + for (int i = 1; i < NSIG; i++) + { + struct sigaction sa; + int r = sigaction (i, NULL, &sa); + /* Skip internal signals (such as SIGCANCEL). */ + if (r == -1) + continue; + if (i == SIGUSR1 || i == SIGUSR2) + TEST_VERIFY_EXIT (sa.sa_handler == SIG_IGN); + else + TEST_VERIFY_EXIT (sa.sa_handler == SIG_DFL); + } + exit (EXIT_SUCCESS); + } + + exit (EXIT_FAILURE); +} + +static void +spawn_signal_test (const char *type, const posix_spawnattr_t *attr) +{ + spargs[check_type_argc] = (char*) type; + + pid_t pid; + int status; + + TEST_COMPARE (posix_spawn (&pid, spargs[0], NULL, attr, spargs, environ), 0); + TEST_COMPARE (xwaitpid (pid, &status, 0), pid); + TEST_VERIFY (WIFEXITED (status)); + TEST_VERIFY (!WIFSIGNALED (status)); + TEST_COMPARE (WEXITSTATUS (status), 0); +} + +static void +dummy_sa_handler (int) +{ +} + +static void +do_test_signals (void) +{ + { + /* Check if all signals handler are set to SIG_DFL on spawned process. */ + spawn_signal_test ("SIG_DFL", NULL); + } + + { + /* Same as before, but set SIGUSR1 and SIGUSR2 to a handler different than + SIG_IGN or SIG_DFL. */ + struct sigaction sa = { 0 }; + sa.sa_handler = dummy_sa_handler; + xsigaction (SIGUSR1, &sa, NULL); + xsigaction (SIGUSR2, &sa, NULL); + spawn_signal_test ("SIG_DFL", NULL); + } + + { + /* Check if SIG_IGN is keep as is. */ + struct sigaction sa = { 0 }; + sa.sa_handler = SIG_IGN; + xsigaction (SIGUSR1, &sa, NULL); + xsigaction (SIGUSR2, &sa, NULL); + spawn_signal_test ("SIG_IGN", NULL); + } + + { + /* Check if SIG_IGN handlers are set to SIG_DFL. */ + posix_spawnattr_t attr; + posix_spawnattr_init (&attr); + sigset_t mask; + sigemptyset (&mask); + sigaddset (&mask, SIGUSR1); + sigaddset (&mask, SIGUSR2); + posix_spawnattr_setsigdefault (&attr, &mask); + posix_spawnattr_setflags (&attr, POSIX_SPAWN_SETSIGDEF); + spawn_signal_test ("SIG_DFL", &attr); + posix_spawnattr_destroy (&attr); + } +} + +static int +do_test (int argc, char *argv[]) +{ + /* We must have either: + + - one or four parameters if called initially: + + argv[1]: path for ld.so optional + + argv[2]: "--library-path" optional + + argv[3]: the library path optional + + argv[4]: the application name + + - six parameters left if called through re-execution: + + argv[1]: the application name + + argv[2]: check SIG_IGN/SIG_DFL. + + * When built with --enable-hardcoded-path-in-tests or issued without + using the loader directly. */ + + if (restart) + handle_restart (argc - 1, &argv[1]); + + TEST_VERIFY_EXIT (argc == 2 || argc == 5); + + int i; + for (i = 0; i < argc - 1; i++) + spargs[i] = argv[i + 1]; + spargs[i++] = (char *) "--direct"; + spargs[i++] = (char *) "--restart"; + check_type_argc = i++; + spargs[i] = NULL; + + + do_test_signals (); + + return 0; +} + +#define TEST_FUNCTION_ARGV do_test +#include diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index 60e4cb1521..c183ccd4ab 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -175,8 +175,7 @@ tests-clone-internal = \ tst-align-clone-internal \ tst-clone2-internal \ tst-clone3-internal \ - tst-getpid1-internal \ - tst-misalign-clone-internal + tst-getpid1-internal tests-internal += $(tests-clone-internal) tests-static += $(tests-clone-internal) diff --git a/sysdeps/unix/sysv/linux/clone-internal.c b/sysdeps/unix/sysv/linux/clone-internal.c index a71effcbd3..7bc991e033 100644 --- a/sysdeps/unix/sysv/linux/clone-internal.c +++ b/sysdeps/unix/sysv/linux/clone-internal.c @@ -44,27 +44,15 @@ _Static_assert (sizeof (struct clone_args) == CLONE_ARGS_SIZE_VER2, "sizeof (struct clone_args) != CLONE_ARGS_SIZE_VER2"); int -__clone_internal (struct clone_args *cl_args, - int (*func) (void *arg), void *arg) +__clone_internal_fallback (struct clone_args *cl_args, + int (*func) (void *arg), void *arg) { - int ret; -#ifdef HAVE_CLONE3_WRAPPER - /* Try clone3 first. */ - int saved_errno = errno; - ret = __clone3 (cl_args, sizeof (*cl_args), func, arg); - if (ret != -1 || errno != ENOSYS) - return ret; - - /* NB: Restore errno since errno may be checked against non-zero - return value. */ - __set_errno (saved_errno); -#endif - /* Map clone3 arguments to clone arguments. NB: No need to check invalid clone3 specific bits in flags nor exit_signal since this is an internal function. */ int flags = cl_args->flags | cl_args->exit_signal; void *stack = cast_to_pointer (cl_args->stack); + int ret; #ifdef __ia64__ ret = __clone2 (func, stack, cl_args->stack_size, @@ -88,4 +76,23 @@ __clone_internal (struct clone_args *cl_args, return ret; } + +int +__clone_internal (struct clone_args *cl_args, + int (*func) (void *arg), void *arg) +{ +#ifdef HAVE_CLONE3_WRAPPER + int saved_errno = errno; + int ret = __clone3 (cl_args, sizeof (*cl_args), func, arg); + if (ret != -1 || errno != ENOSYS) + return ret; + + /* NB: Restore errno since errno may be checked against non-zero + return value. */ + __set_errno (saved_errno); +#endif + + return __clone_internal_fallback (cl_args, func, arg); +} + libc_hidden_def (__clone_internal) diff --git a/sysdeps/unix/sysv/linux/clone3.h b/sysdeps/unix/sysv/linux/clone3.h index 7c7e2cdcb0..7dd42ec2d2 100644 --- a/sysdeps/unix/sysv/linux/clone3.h +++ b/sysdeps/unix/sysv/linux/clone3.h @@ -23,6 +23,13 @@ #include #include + +/* Flags for the clone3 syscall. */ +#define CLONE_CLEAR_SIGHAND 0x100000000ULL /* Clear any signal handler and + reset to SIG_DFL. */ +#define CLONE_INTO_CGROUP 0x200000000ULL /* Clone into a specific cgroup given + the right permissions. */ + /* The unsigned 64-bit and 8-byte aligned integer type. */ typedef __U64_TYPE __aligned_uint64_t __attribute__ ((__aligned__ (8))); diff --git a/sysdeps/unix/sysv/linux/spawni.c b/sysdeps/unix/sysv/linux/spawni.c index 65ee03c804..ebc3c3e521 100644 --- a/sysdeps/unix/sysv/linux/spawni.c +++ b/sysdeps/unix/sysv/linux/spawni.c @@ -66,6 +66,7 @@ struct posix_spawn_args ptrdiff_t argc; char *const *envp; int xflags; + bool use_clone3; int err; }; @@ -104,12 +105,11 @@ __spawni_child (void *arguments) const posix_spawnattr_t *restrict attr = args->attr; const posix_spawn_file_actions_t *file_actions = args->fa; - /* The child must ensure that no signal handler are enabled because it shared - memory with parent, so the signal disposition must be either SIG_DFL or - SIG_IGN. It does by iterating over all signals and although it could - possibly be more optimized (by tracking which signal potentially have a - signal handler), it might requires system specific solutions (since the - sigset_t data type can be very different on different architectures). */ + /* The child must ensure that no signal handler is enabled because it + shares memory with parent, so all signal dispositions must be either + SIG_DFL or SIG_IGN. If clone3/CLONE_CLEAR_SIGHAND is used, there is + only need to set the defined signals POSIX_SPAWN_SETSIGDEF to SIG_DFL; + otherwise, the code iterates over all signals. */ struct sigaction sa; memset (&sa, '\0', sizeof (sa)); @@ -122,7 +122,7 @@ __spawni_child (void *arguments) { sa.sa_handler = SIG_DFL; } - else if (__sigismember (&hset, sig)) + else if (!args->use_clone3 && __sigismember (&hset, sig)) { if (is_internal_signal (sig)) sa.sa_handler = SIG_IGN; @@ -382,12 +382,25 @@ __spawnix (pid_t * pid, const char *file, for instance). */ struct clone_args clone_args = { - .flags = CLONE_VM | CLONE_VFORK, + /* Unsupported flags like CLONE_CLEAR_SIGHAND will be cleared up by + __clone_internal_fallback. */ + .flags = CLONE_CLEAR_SIGHAND | CLONE_VM | CLONE_VFORK, .exit_signal = SIGCHLD, .stack = (uintptr_t) stack, .stack_size = stack_size, }; - new_pid = __clone_internal (&clone_args, __spawni_child, &args); +#ifdef HAVE_CLONE3_WRAPPER + args.use_clone3 = true; + new_pid = __clone3 (&clone_args, sizeof (clone_args), __spawni_child, + &args); + /* clone3 was added on 5.3 and CLONE_CLEAR_SIGHAND on 5.5. */ + if (new_pid == -1 && (errno == ENOSYS || errno == EINVAL)) +#endif + { + args.use_clone3 = false; + new_pid = __clone_internal_fallback (&clone_args, __spawni_child, + &args); + } /* It needs to collect the case where the auxiliary process was created but failed to execute the file (due either any preparation step or From patchwork Fri Nov 4 19:01:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 59956 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6E4D13857B93 for ; Fri, 4 Nov 2022 19:02:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6E4D13857B93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1667588523; bh=WOzJnK4dUbVJjEMosjqWdgj7T+rfV6rYotCI/W1++Xc=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=WTsPQKtRiWnBFKl6bUFYkJCp145v20HhfXPt9C0qEtk4XAvpXS8Zv4O7aW1G8QLnC 4+OktxDmduC6GNISh3v+gfGDbbEGzI5qZakiDdOHmLFzeO16yFyAsPDErhYQysORaP DLmPskhGYfxQia49TRl2wC/zgWLbzpx9O7EiGXC0= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x332.google.com (mail-ot1-x332.google.com [IPv6:2607:f8b0:4864:20::332]) by sourceware.org (Postfix) with ESMTPS id A22C13858287 for ; Fri, 4 Nov 2022 19:01:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A22C13858287 Received: by mail-ot1-x332.google.com with SMTP id r13-20020a056830418d00b0065601df69c0so3170415otu.7 for ; Fri, 04 Nov 2022 12:01:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WOzJnK4dUbVJjEMosjqWdgj7T+rfV6rYotCI/W1++Xc=; b=pY5n3uGy8ukYn8iszsoICLjiFyfwirFbcrHTcCVDE1yvoUGTWvGyZQ+ZdfiyOKe2os CBU1kLGnLAMJxGfXXescxyQj6ZmmkbRiTFsqKoP+ph8JPShZvwcM0afq2YKUMS2UYOx2 JUXkYvVXss0RP/k7YKlOVL07Oy3u+6sxF1boo585DmtW1ez+crA7etxqYCw4wZckcF/y PeqYMp9RziKyx+aNquEdrNZLgGMwxtA786NEZdtciiZAcc8Z1pL7fy5+TmfOxZRwSAjc Ic7jpvOU+0kI1zp7XyXQqG3qX/nIwRPDsofRJpm/QeTb+fDR89msJcfYOgZT9txNtEw9 xL+g== X-Gm-Message-State: ACrzQf3cNK1W13McW4xTAIxrM50faG4xhHKQBHmF/CkxaPnh7NpN8GIe BXvzVtc1lZHD1xfYbVBy3pdi/nCnMoKo9JoS X-Google-Smtp-Source: AMsMyM64ittUyr0dl7ohbih4iOivc0RZnMQuzSmhvdVa7cX5whCu04oj95JxZkP9qNrYGzCGM9mSdQ== X-Received: by 2002:a9d:4b19:0:b0:66c:55d2:c58a with SMTP id q25-20020a9d4b19000000b0066c55d2c58amr13623267otf.273.1667588485612; Fri, 04 Nov 2022 12:01:25 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:a9f4:f725:94bd:4cc1:1762]) by smtp.gmail.com with ESMTPSA id 24-20020aca1018000000b0035763a9a36csm1764713oiq.44.2022.11.04.12.01.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Nov 2022 12:01:25 -0700 (PDT) To: libc-alpha@sourceware.org, Szabolcs Nagy , "H . J . Lu" Subject: [PATCH v2 05/11] powerpc64: Add the clone3 wrapper Date: Fri, 4 Nov 2022 16:01:06 -0300 Message-Id: <20221104190112.2566409-6-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221104190112.2566409-1-adhemerval.zanella@linaro.org> References: <20221104190112.2566409-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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 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-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Cc: Christian Brauner Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" It follows the internal signature: extern int clone3 (struct clone_args *__cl_args, size_t __size, int (*__func) (void *__arg), void *__arg); The powerpc64 ABI requires an initial stackframe so the child can store/restore the TOC. Iit is create prior calling clone3 by adjusting the stack size (since kernel will compute the stack as stack plus size). Checked on powerpc64-linux-gnu (power8, kernel 6.0) and powerpc64le-linux-gnu (power9, kernel 4.18). --- .../sysv/linux/powerpc/powerpc64/clone3.S | 152 ++++++++++++++++++ sysdeps/unix/sysv/linux/powerpc/sysdep.h | 1 + 2 files changed, 153 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/powerpc/powerpc64/clone3.S diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/clone3.S b/sysdeps/unix/sysv/linux/powerpc/powerpc64/clone3.S new file mode 100644 index 0000000000..0fe2fe91db --- /dev/null +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/clone3.S @@ -0,0 +1,152 @@ +/* The clone3 syscall wrapper. Linux/powerpc64 version. + Copyright (C) 2022 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 +#define _ERRNO_H 1 +#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: + r3: cl_args + r4: size + r5: func + r6: arg */ + + .text +ENTRY(__clone3) + CALL_MCOUNT 4 + + /* Sanity checks args. */ + cmpdi cr0, r3, 0 + cmpdi cr1, r5, 0 + cror cr0*4+eq, cr1*4+eq, cr0*4+eq + beq cr0,L(badargs) + + /* Save some regs in the "red zone". */ +#ifdef USE_PPC_SCV + std r28, -24(r1) + cfi_offset (r28, -24) +#endif + std r29, -16(r1) + std r30, -8(r1) + cfi_offset (r29, -16) + cfi_offset (r30, -8) + + /* Save fn and args across syscall. */ + mr r30, r5 /* Function in r30. */ + mr r29, r6 /* Argument in r29. */ + + /* End FDE now, because in the child the unwind info will be + wrong. */ + cfi_endproc + + /* Setup a minimum stack fram for child. It needs to first calculate + the effective stack address, write the start NULL frame-pointer, + and update the frame size in the input cl_args. */ + ld r7, 40(r3) /* Load stack value. */ + ld r8, 48(r3) /* Load stack_size value. */ + li r10, 0 + add r7, r7, r8 /* Calculate effective stack address. */ + std r10, -FRAME_MIN_SIZE_PARM(r7) + addi r8, r8, -FRAME_MIN_SIZE_PARM + std r8, 48(r3) + + /* Do the system call, the kernel expects: + r0: system call numer + r3: cl_args + r4: size */ + li r0, SYS_ify(clone3) +#ifdef USE_PPC_SCV + CHECK_SCV_SUPPORT r28 0f + /* This is equivalent to DO_CALL_SCV, but we cannot use the macro here + because it uses CFI directives and we just called cfi_endproc. */ + mflr r9 + std r9, FRAME_LR_SAVE(r1) + .machine "push" + .machine "power9" + scv 0 + .machine "pop" + ld r9, FRAME_LR_SAVE(r1) + mtlr r9 + + /* When using scv, error is indicated by negative r3. */ + cmpdi cr1, r3, 0 + b 1f +#endif +0: DO_CALL_SC + + /* With sc, error is indicated by cr0.SO. */ + cmpdi cr1, r3, 0 + crandc cr1*4+eq, cr1*4+eq, cr0*4+so + +1: bne- cr1,L(parent) + + /* Child, load the function and arguments. */ + std r2, FRAME_TOC_SAVE(r1) + PPC64_LOAD_FUNCPTR r30 + mr r3, r29 + bctrl + ld r2, FRAME_TOC_SAVE(r1) + + li r0, SYS_ify(exit) + DO_CALL_SC + /* We won't ever get here but provide a nop so that the linker + will insert a toc adjusting stub if necessary. */ + nop + +L(badargs): + cfi_startproc + li r3, EINVAL + TAIL_CALL_SYSCALL_ERROR + +L(parent): + /* Check if svc is available. */ + cmpdi cr1, r28, 0 + + /* Parent. Restore registers & return. */ +#ifdef USE_PPC_SCV + cfi_offset (r28, -24) + ld r28, -24(r1) + cfi_restore (r28) +#endif + cfi_offset (r29,-16) + cfi_offset (r30,-8) + ld r29, -16(r1) + ld r30, -8(r1) + cfi_restore (r29) + cfi_restore (r30) + +#ifdef USE_PPC_SCV + beq cr1, 0f + RET_SCV + b 1f +#endif +0: RET_SC +1: TAIL_CALL_SYSCALL_ERROR + +PSEUDO_END (__clone3) + +libc_hidden_def (__clone3) +weak_alias (__clone3, clone3) diff --git a/sysdeps/unix/sysv/linux/powerpc/sysdep.h b/sysdeps/unix/sysv/linux/powerpc/sysdep.h index 9e44818978..af63b3974b 100644 --- a/sysdeps/unix/sysv/linux/powerpc/sysdep.h +++ b/sysdeps/unix/sysv/linux/powerpc/sysdep.h @@ -214,6 +214,7 @@ #if defined(__PPC64__) || defined(__powerpc64__) #define HAVE_CLOCK_GETRES64_VSYSCALL "__kernel_clock_getres" #define HAVE_CLOCK_GETTIME64_VSYSCALL "__kernel_clock_gettime" +#define HAVE_CLONE3_WRAPPER 1 #else #define HAVE_CLOCK_GETRES_VSYSCALL "__kernel_clock_getres" #define HAVE_CLOCK_GETTIME_VSYSCALL "__kernel_clock_gettime" From patchwork Fri Nov 4 19:01:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 59963 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C75603858288 for ; Fri, 4 Nov 2022 19:05:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C75603858288 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1667588733; bh=SCdFZC4yIzi2+pZdhiVHA3Fw2dQ1lGJ95UCYYNgkWWg=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=gMSzarSb5NsXw2AqjG62oGDjRgTDBZ5c48cTWkFIPpLyuBmXAPXCAeM6yZGk4I4f9 uqJtxli/SCR2DThV4+FacOOH3n8IT0L2UDd6qX3TZ4OC76kL4b+On1CyCAht9ctuUW M2Oa8Ajf2WDSM1GOW8JghlM8EzEHjM9ras7GbrHs= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oa1-x34.google.com (mail-oa1-x34.google.com [IPv6:2001:4860:4864:20::34]) by sourceware.org (Postfix) with ESMTPS id A734E3858431 for ; Fri, 4 Nov 2022 19:01:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A734E3858431 Received: by mail-oa1-x34.google.com with SMTP id 586e51a60fabf-13c2cfd1126so6499312fac.10 for ; Fri, 04 Nov 2022 12:01:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SCdFZC4yIzi2+pZdhiVHA3Fw2dQ1lGJ95UCYYNgkWWg=; b=xw1hwg6G9QHa3aQRUbD6qRc30sj/tPUdmlfV+BidRw08LhWQ9q5J512xLVQch3U14f v4YnmA+4J1nEb/J3lQBR/LSp1G7KzMklAeuZS4NcovqUYlGi1ADG0rzAktn5nR+/fqPL T84xhphTlJDN3uSTfwKRQ0TtQvJc8gnnc+Kimzb0vy9WIkE96QA4ZVcVYTI+D+UAktUi fbqddUEHp9ur2kyrD7lmzrs1JQOC5EGQUb8dE98GKF5Ba6ggnLdTiYqARxhSC8v050t/ zntqsCKZEiFKfgLZe/zAxyFrmkpDTki8ui3ADzT0upKO/q5DkAH1hbtTftAIPGv3J3uw q4ng== X-Gm-Message-State: ACrzQf1yiSO/jq3jFh4XyDZCMHQ1UnDqzI9wl5UI7TQkfEik4vTb6KFv W4moPFwS5fvS2Q+o8hddzBgfgNqhX8RTImRl X-Google-Smtp-Source: AMsMyM5nstneTmgwk7OaCesVAYboWCsz1f8v6snGHukjdwd1I7rzYROT3k8ESfk7XCEvCF1FkjqIkw== X-Received: by 2002:a05:6870:a997:b0:12a:e54e:c8ee with SMTP id ep23-20020a056870a99700b0012ae54ec8eemr30773918oab.172.1667588487355; Fri, 04 Nov 2022 12:01:27 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:a9f4:f725:94bd:4cc1:1762]) by smtp.gmail.com with ESMTPSA id 24-20020aca1018000000b0035763a9a36csm1764713oiq.44.2022.11.04.12.01.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Nov 2022 12:01:27 -0700 (PDT) To: libc-alpha@sourceware.org, Szabolcs Nagy , "H . J . Lu" Subject: [PATCH v2 06/11] aarch64: Add the clone3 wrapper Date: Fri, 4 Nov 2022 16:01:07 -0300 Message-Id: <20221104190112.2566409-7-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221104190112.2566409-1-adhemerval.zanella@linaro.org> References: <20221104190112.2566409-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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 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-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Cc: Christian Brauner Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" It follow the internal signature: extern int clone3 (struct clone_args *__cl_args, size_t __size, int (*__func) (void *__arg), void *__arg); Checked on aarch64-linux-gnu. Reviewed-by: Szabolcs Nagy --- sysdeps/unix/sysv/linux/aarch64/clone3.S | 85 ++++++++++++++++++++++++ sysdeps/unix/sysv/linux/aarch64/sysdep.h | 2 + 2 files changed, 87 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/aarch64/clone3.S diff --git a/sysdeps/unix/sysv/linux/aarch64/clone3.S b/sysdeps/unix/sysv/linux/aarch64/clone3.S new file mode 100644 index 0000000000..5d42bc03e9 --- /dev/null +++ b/sysdeps/unix/sysv/linux/aarch64/clone3.S @@ -0,0 +1,85 @@ +/* The clone3 syscall wrapper. Linux/aarch64 version. + Copyright (C) 2022 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 +#define _ERRNO_H 1 +#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: + x0: cl_args + x1: size + x2: func + x3: arg */ + + .text +ENTRY(__clone3) + PTR_ARG (0) + PTR_ARG (1) + PTR_ARG (3) + PTR_ARG (4) + /* Save args for the child. */ + mov x10, x0 /* cl_args */ + mov x11, x2 /* func */ + mov x12, x3 /* args */ + + /* Sanity check args. */ + mov x0, #-EINVAL + cbz x10, .Lsyscall_error /* No NULL cl_args pointer. */ + cbz x2, .Lsyscall_error /* No NULL function pointer. */ + + /* Do the system call, the kernel expects: + x8: system call number + x0: cl_args + x1: size */ + mov x0, x10 + mov x8, #SYS_ify(clone3) + svc 0x0 + + cmp x0, #0 + beq thread_start + blt .Lsyscall_error + RET +PSEUDO_END (__clone3) + + .align 4 + .type thread_start, %function +thread_start: + cfi_startproc + cfi_undefined (x30) + mov x29, 0 + + /* Pick the function arg and execute. */ + mov x0, x12 + blr x11 + + /* We are done, pass the return value through x0. */ + mov x8, #SYS_ify(exit) + svc 0x0 + cfi_endproc + .size thread_start, .-thread_start + +libc_hidden_def (__clone3) +weak_alias (__clone3, clone3) diff --git a/sysdeps/unix/sysv/linux/aarch64/sysdep.h b/sysdeps/unix/sysv/linux/aarch64/sysdep.h index 8ba50dab8f..00c0a02693 100644 --- a/sysdeps/unix/sysv/linux/aarch64/sysdep.h +++ b/sysdeps/unix/sysv/linux/aarch64/sysdep.h @@ -164,6 +164,8 @@ # define HAVE_CLOCK_GETTIME64_VSYSCALL "__kernel_clock_gettime" # define HAVE_GETTIMEOFDAY_VSYSCALL "__kernel_gettimeofday" +# define HAVE_CLONE3_WRAPPER 1 + # undef INTERNAL_SYSCALL_RAW # define INTERNAL_SYSCALL_RAW(name, nr, args...) \ ({ long _sys_result; \ From patchwork Fri Nov 4 19:01:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 59964 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 52DF93857B83 for ; Fri, 4 Nov 2022 19:06:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 52DF93857B83 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1667588789; bh=7ojRMpkpulgGcXzz+J8CnuKEEQTMhW0aHtFC9MnA4bU=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=KssWxSsCt3jw8N+n/3/G50WEaCDVR+FjsWHZXcBabys6jlCykvZO0cn1v/LWhzQVq jL2bXoya6FNKrr7c/tn5uLpryDsL96D9C0C9C5Pphuj8aD7m5H995NOHNdZ4f95jje ClkK3GQSiCOvfOS3qx9qh2FyMB11f3yfx2kop9rc= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oa1-x34.google.com (mail-oa1-x34.google.com [IPv6:2001:4860:4864:20::34]) by sourceware.org (Postfix) with ESMTPS id EF988385828B for ; Fri, 4 Nov 2022 19:01:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EF988385828B Received: by mail-oa1-x34.google.com with SMTP id 586e51a60fabf-13ba86b5ac0so6535383fac.1 for ; Fri, 04 Nov 2022 12:01:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7ojRMpkpulgGcXzz+J8CnuKEEQTMhW0aHtFC9MnA4bU=; b=0VkQD1bmIPQ0g5PucKQBXPehT3WiUjbmpsTgcb/uc+lcQrWX8BlNgQ2Dbj4gKQFB0M tsD2P2BGhb2Q+HNKatqn9fYVRLCeE6Nm+eEYljOXl6yvbgc/quyeLlniLZx0u8ilObpa DcAoGYEBg91ap5+PtMO4oH6CgfHssNRXdFpVHkm/lzJ0y8bB0dLpt1GbnHCzi5DSXi76 aBSCebSJs/03OzMBvKzCM/rzSpbH2S8CzIY6VWyWwYD/98uFHz7LvJxX0Rgqno4+fwbY g3kzfOAWswZCZZtWQlSjAvm3kz+iq0a3vxF8aZRYHsMaAYZrYY6x48tRbpieyWAQrPRP STxw== X-Gm-Message-State: ACrzQf2j/E+T0hT2G/pCrLMPGIsoNNlValok2ftjBM8aU1ulFr83WuRF JrxrwkF2hbNOYQROcX+kVUPgLI6vcZdbTK7U X-Google-Smtp-Source: AMsMyM76yvZ8NNa6u2TpHAmHhhrKJrsUEkdkeUyetOQfB0MsaVP5LIhbMV9dW5dE6OW1/5yvnpfuYw== X-Received: by 2002:a05:6870:9597:b0:13b:c024:8ed7 with SMTP id k23-20020a056870959700b0013bc0248ed7mr21480612oao.112.1667588489041; Fri, 04 Nov 2022 12:01:29 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:a9f4:f725:94bd:4cc1:1762]) by smtp.gmail.com with ESMTPSA id 24-20020aca1018000000b0035763a9a36csm1764713oiq.44.2022.11.04.12.01.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Nov 2022 12:01:28 -0700 (PDT) To: libc-alpha@sourceware.org, Szabolcs Nagy , "H . J . Lu" Subject: [PATCH v2 07/11] s390x: Add the clone3 wrapper Date: Fri, 4 Nov 2022 16:01:08 -0300 Message-Id: <20221104190112.2566409-8-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221104190112.2566409-1-adhemerval.zanella@linaro.org> References: <20221104190112.2566409-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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 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-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Cc: Christian Brauner Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" It follows the internal signature: extern int clone3 (struct clone_args *__cl_args, size_t __size, int (*__func) (void *__arg), void *__arg); Checked on s390x-linux-gnu. --- sysdeps/unix/sysv/linux/s390/s390-64/clone3.S | 81 +++++++++++++++++++ sysdeps/unix/sysv/linux/s390/sysdep.h | 1 + 2 files changed, 82 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/s390/s390-64/clone3.S diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/clone3.S b/sysdeps/unix/sysv/linux/s390/s390-64/clone3.S new file mode 100644 index 0000000000..873d9a74b7 --- /dev/null +++ b/sysdeps/unix/sysv/linux/s390/s390-64/clone3.S @@ -0,0 +1,81 @@ +/* The clone3 syscall wrapper. Linux/s390x version. + Copyright (C) 2022 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 +#define _ERRNO_H 1 +#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: + r2: cl_args + r3: size + r4: func + r5: arg */ + + .text +ENTRY(__clone3) + stg %r6, 48(%r15) + + /* Sanity check args. */ + ltgr %r2, %r2 + je error + ltgr %r6, %r4 + je error + + /* Do the system call, the kernel expects: + r1: system call number + r2: cl_args + r3: size */ + lghi %r1, SYS_ify(clone3) + svc 0 + ltgr %r2,%r2 /* check return code */ + jz thread_start + lg %r6, 48(%r15) + jgm SYSCALL_ERROR_LABEL + br %r14 +error: + lghi %r2,-EINVAL + jg SYSCALL_ERROR_LABEL +PSEUDO_END (__clone3) + + .align 4 + .type thread_start, %function +thread_start: + cfi_startproc + /* Mark r14 as undefined in order to stop unwinding here. */ + cfi_undefined (r14) + + /* func is in gpr 6, arg in gpr 5. */ + lgr %r2, %r5 + aghi %r15, -160 + xc 0(8,%r15),0(%r15) + basr %r14, %r6 + + DO_CALL (exit, 1) + cfi_endproc + .size thread_start, .-thread_start + +libc_hidden_def (__clone3) +weak_alias (__clone3, clone3) diff --git a/sysdeps/unix/sysv/linux/s390/sysdep.h b/sysdeps/unix/sysv/linux/s390/sysdep.h index 930d7efe03..366c797ef1 100644 --- a/sysdeps/unix/sysv/linux/s390/sysdep.h +++ b/sysdeps/unix/sysv/linux/s390/sysdep.h @@ -72,6 +72,7 @@ #ifdef __s390x__ #define HAVE_CLOCK_GETRES64_VSYSCALL "__kernel_clock_getres" #define HAVE_CLOCK_GETTIME64_VSYSCALL "__kernel_clock_gettime" +#define HAVE_CLONE3_WRAPPER 1 #else #define HAVE_CLOCK_GETRES_VSYSCALL "__kernel_clock_getres" #define HAVE_CLOCK_GETTIME_VSYSCALL "__kernel_clock_gettime" From patchwork Fri Nov 4 19:01:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 59965 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 549103857C4D for ; Fri, 4 Nov 2022 19:07:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 549103857C4D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1667588836; bh=TEF/e0Qu1ELImS8QEfEA17XxJ0bdkBd+TojrodhyJ4U=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=AxdZY6GlWRLf6Liqh+zjFtToY8z7+Q0wMNepbzj+OWuoVCB5FIyxALpvd9bqhXEDv dJMZ9xwZnO1E3Jnly+ROir4ywvx4CrWY3PX5bLSdtMdnChYQUlHRZ1HyZpbnreWocf ThaYroE03ufeIjwO+pJcFV+WChRs1n55OEa2HzX0= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oa1-x2c.google.com (mail-oa1-x2c.google.com [IPv6:2001:4860:4864:20::2c]) by sourceware.org (Postfix) with ESMTPS id C678A385843B for ; Fri, 4 Nov 2022 19:01:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C678A385843B Received: by mail-oa1-x2c.google.com with SMTP id 586e51a60fabf-13c569e5ff5so6522383fac.6 for ; Fri, 04 Nov 2022 12:01:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TEF/e0Qu1ELImS8QEfEA17XxJ0bdkBd+TojrodhyJ4U=; b=q2CUxTlircSp2cyAENMm0B5ttayvRLCpKNak9lRCyRsZi+5Pe7nAQrbGz3+BSnhf+K jRL3M3sOOOlgf0UW1Y8BMs3XeUUBBG0FKh+40WC0cbLYgoaJtTXwtJxJV0NL9aYeyesm CDdQhf3AJ09QIvVXXIfJYeSTXWFPH6Mtld+/qxF3clwUH+RvrAk54OqwlhFfRnsheocE yKmouaVUAwZrGke1dpgwi9wai7jAzMOZ/GJayP7xwmrkXQTzYmpZR1hXnE8sszSTuI6M eCehSL4rOntSmxSvWxFjBBzalb7ftZqRhyk8ozhqILxE0pf0q744vcgojKk3zvUU34C/ xW2A== X-Gm-Message-State: ACrzQf2PbQUvjnbwleI/6eFNsTWASkwWLUlVNm1022AJST9shGeDAVTP C+GqVRDmL4Sbi6OkJIHRB08T3B6gKWvDSbaC X-Google-Smtp-Source: AMsMyM4g3G5K2mmzq9IqKPWL+PfsprgmuhKcpKgiEAQkSoZnU8Gv3oprUGOf1Pdo+TKU84M/ZVFIFQ== X-Received: by 2002:a05:6870:41cb:b0:131:9656:cc30 with SMTP id z11-20020a05687041cb00b001319656cc30mr32862030oac.51.1667588490926; Fri, 04 Nov 2022 12:01:30 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:a9f4:f725:94bd:4cc1:1762]) by smtp.gmail.com with ESMTPSA id 24-20020aca1018000000b0035763a9a36csm1764713oiq.44.2022.11.04.12.01.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Nov 2022 12:01:30 -0700 (PDT) To: libc-alpha@sourceware.org, Szabolcs Nagy , "H . J . Lu" Subject: [PATCH v2 08/11] riscv: Add the clone3 wrapper Date: Fri, 4 Nov 2022 16:01:09 -0300 Message-Id: <20221104190112.2566409-9-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221104190112.2566409-1-adhemerval.zanella@linaro.org> References: <20221104190112.2566409-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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 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-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Cc: Christian Brauner Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" 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. --- 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..ddbcbe36e5 --- /dev/null +++ b/sysdeps/unix/sysv/linux/riscv/clone3.S @@ -0,0 +1,80 @@ +/* The clone3 syscall wrapper. Linux/RISC-V version. + Copyright (C) 2022 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 + 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. */ + 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 c9af888132..4fb92d2406 100644 --- a/sysdeps/unix/sysv/linux/riscv/sysdep.h +++ b/sysdeps/unix/sysv/linux/riscv/sysdep.h @@ -150,6 +150,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). */ From patchwork Fri Nov 4 19:01:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 59959 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 08AC8385829B for ; Fri, 4 Nov 2022 19:03:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 08AC8385829B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1667588581; bh=lD00FDa5c+CKfGJRd2q1PYDIyqpXXcfg5csxz1To1Xc=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=jLkYZs4TPNs6t7MTpQB3u+vrZKjD2j3QSbMZmiHYR07ZizOYituXvDPo593KZFSLj lcPAci/pevMYXVcmc5eslBMyxnlF3TLDaP5ATRKi2Nc848vgVNuv7cMWGxmRwDybSp PrQ/7hZBmO1RNMStbSmAMzaWfyqyuO8uwz/EUsnU= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oo1-xc32.google.com (mail-oo1-xc32.google.com [IPv6:2607:f8b0:4864:20::c32]) by sourceware.org (Postfix) with ESMTPS id ED9333858432 for ; Fri, 4 Nov 2022 19:01:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org ED9333858432 Received: by mail-oo1-xc32.google.com with SMTP id v7-20020a4aa507000000b00496e843fdfeso793013ook.7 for ; Fri, 04 Nov 2022 12:01:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lD00FDa5c+CKfGJRd2q1PYDIyqpXXcfg5csxz1To1Xc=; b=xViu8SZI8EurZ2Uzh5HIIvknBORR1GjGWYSmAQzax2B7HfpWr4558pJZSNSefD+rWq KchrjCvU4mHd43kSm1LJG3SDRqdsdzwfn8rV/LuDZDEo6cE6su3fqL12TzFMfN2/Y/N9 6e9hGHuzZ0X9fYW0jS+Qu/sQz3GnL9R9Z/1Li/T4vZdG7TX4gFl6skyWu0cqMMqWU5IY F+i1pP+pHDTWhAH/5Dcb0PipzVCPt1EE5qgdY/1A8yidrtISc2zzujjZywhPntH+wXX0 ZmyU5nqHZAh2acDV30pnR3IDFZrifZBqdGNNNhX45mvVbhEjM8q308iCYcvz5VvrnbdP qpPQ== X-Gm-Message-State: ACrzQf21D7X3GDBKwzdLauGeEOSSc7YQeTXby0T0B8qLDaV6T1I1QlPi /Zp75fJzrQGGNbnQMRUMbfSiOQnsUp1xD3pU X-Google-Smtp-Source: AMsMyM4RH03p7khuqbyMOGebqtf0Xe/5blujAc3FiylgQMVrHDHMeXYECQYYTEDSIv1O8DhscjyS1g== X-Received: by 2002:a4a:9683:0:b0:485:880b:aacb with SMTP id s3-20020a4a9683000000b00485880baacbmr15792506ooi.8.1667588492592; Fri, 04 Nov 2022 12:01:32 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:a9f4:f725:94bd:4cc1:1762]) by smtp.gmail.com with ESMTPSA id 24-20020aca1018000000b0035763a9a36csm1764713oiq.44.2022.11.04.12.01.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Nov 2022 12:01:32 -0700 (PDT) To: libc-alpha@sourceware.org, Szabolcs Nagy , "H . J . Lu" Subject: [PATCH v2 09/11] arm: Add the clone3 wrapper Date: Fri, 4 Nov 2022 16:01:10 -0300 Message-Id: <20221104190112.2566409-10-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221104190112.2566409-1-adhemerval.zanella@linaro.org> References: <20221104190112.2566409-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, KAM_STOCKGEN, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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 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-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Cc: Christian Brauner Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" It follows the internal signature: extern int clone3 (struct clone_args *__cl_args, size_t __size, int (*__func) (void *__arg), void *__arg); Checked on arm-linux-gnueabihf. --- sysdeps/unix/sysv/linux/arm/clone3.S | 80 ++++++++++++++++++++++++++++ sysdeps/unix/sysv/linux/arm/sysdep.h | 1 + 2 files changed, 81 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/arm/clone3.S diff --git a/sysdeps/unix/sysv/linux/arm/clone3.S b/sysdeps/unix/sysv/linux/arm/clone3.S new file mode 100644 index 0000000000..d5949fae77 --- /dev/null +++ b/sysdeps/unix/sysv/linux/arm/clone3.S @@ -0,0 +1,80 @@ +/* The clone3 syscall wrapper. Linux/arm version. + Copyright (C) 2022 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 +#define _ERRNO_H 1 +#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: + r0: cl_args + r1: size + r2: func + r3: arg */ + + .text +ENTRY(__clone3) + /* Sanity check args. */ + cmp r0, #0 + ite ne + cmpne r1, #0 + moveq r0, #-EINVAL + beq PLTJMP(syscall_error) + + /* Do the syscall, the kernel expects: + r7: system call number: + r0: cl_args + r1: size */ + push { r7 } + cfi_adjust_cfa_offset (4) + cfi_rel_offset (r7, 0) + ldr r7, =SYS_ify(clone3) + swi 0x0 + cfi_endproc + + cmp r0, #0 + beq 1f + pop {r7} + blt PLTJMP(C_SYMBOL_NAME(__syscall_error)) + RETINSTR(, lr) + + cfi_startproc +PSEUDO_END (__clone3) + +1: + .fnstart + .cantunwind + mov r0, r3 + mov ip, r2 + BLX (ip) + + /* And we are done, passing the return value through r0. */ + ldr r7, =SYS_ify(exit) + swi 0x0 + + .fnend + +libc_hidden_def (__clone3) +weak_alias (__clone3, clone3) diff --git a/sysdeps/unix/sysv/linux/arm/sysdep.h b/sysdeps/unix/sysv/linux/arm/sysdep.h index 1f270b961e..fcc86189d6 100644 --- a/sysdeps/unix/sysv/linux/arm/sysdep.h +++ b/sysdeps/unix/sysv/linux/arm/sysdep.h @@ -362,6 +362,7 @@ __local_syscall_error: \ #define HAVE_CLOCK_GETTIME_VSYSCALL "__vdso_clock_gettime" #define HAVE_CLOCK_GETTIME64_VSYSCALL "__vdso_clock_gettime64" #define HAVE_GETTIMEOFDAY_VSYSCALL "__vdso_gettimeofday" +#define HAVE_CLONE3_WRAPPER 1 #define LOAD_ARGS_0() #define ASM_ARGS_0 From patchwork Fri Nov 4 19:01:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 59961 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 716C4385769F for ; Fri, 4 Nov 2022 19:03:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 716C4385769F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1667588634; bh=HY+9TtZCCYTyiqKk/qCnx/8ZDNkrXmJ66btZ0AMHVzw=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=IFbpoMgrAV5jaALbZ9c353w1QJAht7qI+WIcsz3ZwNzc0lKmdrRIcLiHX+f6DHurY /jWUSaSF34sn9Ys20Zx2HtRKokBOvhVzVGW+N9Nspo3aXpuqfF2Nx0HjvwBBwmd0hE WETd7DsBQfQtWKqUwrIbxtTmNyVCY9IyPJGAqwms= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oa1-x2b.google.com (mail-oa1-x2b.google.com [IPv6:2001:4860:4864:20::2b]) by sourceware.org (Postfix) with ESMTPS id 3BD703858C2B for ; Fri, 4 Nov 2022 19:01:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3BD703858C2B Received: by mail-oa1-x2b.google.com with SMTP id 586e51a60fabf-13b23e29e36so6493446fac.8 for ; Fri, 04 Nov 2022 12:01:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HY+9TtZCCYTyiqKk/qCnx/8ZDNkrXmJ66btZ0AMHVzw=; b=uC0rbhhO+/fOT3fKXCIxw0bVWdhMVRmtVN1jyT5ArsIiE3zXmAyKYV55LNXa4SNzxl SoDvZ98sMbsnbs5R0oVJ6BeJCRUkA9U8R6T5cytSsSfuABfDovGuekPFWlFtJKQGXAap RQEAMqMlTIsl0XKJ5yw30Pcd6/EuDLy2PkirL2+Gpi9r+Nr+SPc9Wdi3VMEWg1I627eb JCPVNalGbJc18h+6JNb9zk8Ul5MnQsJlBhfrAq/oH3fRM2AbEXbl9KMyXAAHkFlA4fW1 O2mvev0Vh1AUu6CKQH3I95EHGIWq4JsWSFMb+bZ5YbKH4BzwbObO3J5xM000SEM+X5hy KqoQ== X-Gm-Message-State: ANoB5plMnnctUYYdqcoWte72iPAtQ/Xd3gzFzAUxQw17xfUB1ysFEg3H 2Q9trEpdCjm5kFt1ZMBsaPYyhj7lZwhMJN3P X-Google-Smtp-Source: AA0mqf4EcCfrhDSHb6D37hFL3SBNP/gHY05kTTTMsw2vyk2rbSqOQlME2tEwYO+frdb7qKqa0uCnZw== X-Received: by 2002:a05:6870:d352:b0:140:816d:c1f9 with SMTP id h18-20020a056870d35200b00140816dc1f9mr1913181oag.231.1667588494403; Fri, 04 Nov 2022 12:01:34 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:a9f4:f725:94bd:4cc1:1762]) by smtp.gmail.com with ESMTPSA id 24-20020aca1018000000b0035763a9a36csm1764713oiq.44.2022.11.04.12.01.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Nov 2022 12:01:34 -0700 (PDT) To: libc-alpha@sourceware.org, Szabolcs Nagy , "H . J . Lu" Subject: [PATCH v2 10/11] mips: Add the clone3 wrapper Date: Fri, 4 Nov 2022 16:01:11 -0300 Message-Id: <20221104190112.2566409-11-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221104190112.2566409-1-adhemerval.zanella@linaro.org> References: <20221104190112.2566409-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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 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-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Cc: Christian Brauner Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" It follows the internal signature: extern int clone3 (struct clone_args *__cl_args, size_t __size, int (*__func) (void *__arg), void *__arg); Checked on mips64el-linux-gnueabihf and mipsel-linux-gnu. --- sysdeps/unix/sysv/linux/mips/clone3.S | 139 ++++++++++++++++++++++++++ sysdeps/unix/sysv/linux/mips/sysdep.h | 2 + 2 files changed, 141 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/mips/clone3.S diff --git a/sysdeps/unix/sysv/linux/mips/clone3.S b/sysdeps/unix/sysv/linux/mips/clone3.S new file mode 100644 index 0000000000..7810994264 --- /dev/null +++ b/sysdeps/unix/sysv/linux/mips/clone3.S @@ -0,0 +1,139 @@ +/* The clone3 syscall wrapper. Linux/mips version. + Copyright (C) 2022 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 +#define _ERRNO_H 1 +#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/$4: cl_args + a1/$5: size + a2/$6: func + a3/$7: arg */ + + .text + .set nomips16 +#if _MIPS_SIM == _ABIO32 +# define EXTRA_LOCALS 1 +#else +# define EXTRA_LOCALS 0 +#endif +#define FRAMESZ ((NARGSAVE*SZREG)+ALSZ)&ALMASK +GPOFF= FRAMESZ-(1*SZREG) +NESTED(__clone3, SZREG, sp) +#ifdef __PIC__ + SETUP_GP +#endif +#if FRAMESZ + PTR_SUBU sp, FRAMESZ + cfi_adjust_cfa_offset (FRAMESZ) +#endif + SETUP_GP64_STACK (GPOFF, __clone) +#ifdef __PIC__ + SAVE_GP (GPOFF) +#endif +#ifdef PROF + .set noat + move $1,ra + jal _mcount + .set at +#endif + + /* Sanity check args. */ + li v0, EINVAL + beqz a0, L(error) /* No NULL cl_args pointer. */ + beqz a2, L(error) /* No NULL function pointer. */ + + move $8, a3 /* a3 is set to 0/1 for syscall success/error + while a4/$8 is returned unmodified. */ + + /* Do the system call, the kernel expects: + v0: system call number + a0: cl_args + a1: size */ + li v0, __NR_clone3 + cfi_endproc + syscall + + bnez a3, L(error) + beqz v0, L(thread_start_clone3) + + /* Successful return from the parent */ + cfi_startproc +#if FRAMESZ + cfi_adjust_cfa_offset (FRAMESZ) +#endif + SETUP_GP64_STACK_CFI (GPOFF) + cfi_remember_state + RESTORE_GP64_STACK +#if FRAMESZ + PTR_ADDU sp, FRAMESZ + cfi_adjust_cfa_offset (-FRAMESZ) +#endif + ret + +L(error): + cfi_restore_state +#ifdef __PIC__ + PTR_LA t9,__syscall_error + RESTORE_GP64_STACK + PTR_ADDU sp, FRAMESZ + cfi_adjust_cfa_offset (-FRAMESZ) + jr t9 +#else + RESTORE_GP64_STACK + PTR_ADDU sp, FRAMESZ + cfi_adjust_cfa_offset (-FRAMESZ) + j __syscall_error +#endif +END (__clone3) + +/* Load up the arguments to the function. Put this block of code in + its own function so that we can terminate the stack trace with our + debug info. */ + +ENTRY(__thread_start_clone3) +L(thread_start_clone3): + cfi_undefined ($31) + /* cp is already loaded. */ + SAVE_GP (GPOFF) + /* The stackframe has been created on entry of clone3. */ + + /* Restore the arg for user's function. */ + move t9, a2 /* Function pointer. */ + move a0, $8 /* Argument pointer. */ + + /* Call the user's function. */ + jal t9 + + move a0, v0 + li v0, __NR_exit + syscall +END(__thread_start_clone3) + +libc_hidden_def (__clone3) +weak_alias (__clone3, clone3) diff --git a/sysdeps/unix/sysv/linux/mips/sysdep.h b/sysdeps/unix/sysv/linux/mips/sysdep.h index 2515dadc26..3f464925e7 100644 --- a/sysdeps/unix/sysv/linux/mips/sysdep.h +++ b/sysdeps/unix/sysv/linux/mips/sysdep.h @@ -28,3 +28,5 @@ #endif #define HAVE_GETTIMEOFDAY_VSYSCALL "__vdso_gettimeofday" #define HAVE_CLOCK_GETRES_VSYSCALL "__vdso_clock_getres" + +#define HAVE_CLONE3_WRAPPER 1 From patchwork Fri Nov 4 19:01:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 59960 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 134293857689 for ; Fri, 4 Nov 2022 19:03:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 134293857689 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1667588617; bh=uF584Pe2FhYRMf139O4h3BC4O+5B/Oe/B7HT6TbD91k=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=fDsZrGj09Sog6ylXXtDfcgLO1Jwo1bNXRsXSCzfmkdPAo/c/37LGQterwt6d64L9z +/9bw1OGsYgHBJoK7FUSNmdSuz+EpQJ36lTpnwpm7eUc8w8I4i9z3Xic+imTfoMzqA CaTe735ebyKGTw87J9gEDNO2a96SkijusFtq0uaU= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x22c.google.com (mail-oi1-x22c.google.com [IPv6:2607:f8b0:4864:20::22c]) by sourceware.org (Postfix) with ESMTPS id 99BFB3858429 for ; Fri, 4 Nov 2022 19:01:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 99BFB3858429 Received: by mail-oi1-x22c.google.com with SMTP id b124so6119005oia.4 for ; Fri, 04 Nov 2022 12:01:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uF584Pe2FhYRMf139O4h3BC4O+5B/Oe/B7HT6TbD91k=; b=k2hV3YZfXuCspCXte4S5RucIxTTZEWSYLkdXxrV3TGhRtl0ThdjGcSOID9XmH3Xkm4 1bQnuB0UF9aCdzjSyPOVslxqd42grq+8LQX+YLcvLLsmqWrldzWbtvNkRYO4jxs1cjq2 oR2eSPlMYv8M32DPguB8BgmKZyzbYojJRy5pPewA+gP0w0oQ9LiKeKYwa8bL7NvQoDQp 4NBKahaEziTketLyAgVeWfzyqD8T0Lb2NL/O68urtHwHwoQZMaOuxsuS0/nBWzomnXJb kEK6jf1L1uv9RyU+rj6uNvPi+mB5Z8mbss+OvydfY41yTl+N56YPT25bd8RY/IJjKtsU 8ilA== X-Gm-Message-State: ACrzQf1h/PzZNx8/BBZ44YrphP61N3llmJeaxfsEJCdRANgNRWF29NyU 2t+C0gyheoQoV1Z9vFOP4HGMln73aU9+91Cr X-Google-Smtp-Source: AMsMyM55CF8lMzmd4y7L8FnnRdjd3vumPWAIVyFZxdko5WHmkCzfUjjARhz8ysHXX8npQi8225k1bg== X-Received: by 2002:a05:6808:1245:b0:350:c462:1528 with SMTP id o5-20020a056808124500b00350c4621528mr19337434oiv.112.1667588496121; Fri, 04 Nov 2022 12:01:36 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:a9f4:f725:94bd:4cc1:1762]) by smtp.gmail.com with ESMTPSA id 24-20020aca1018000000b0035763a9a36csm1764713oiq.44.2022.11.04.12.01.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Nov 2022 12:01:35 -0700 (PDT) To: libc-alpha@sourceware.org, Szabolcs Nagy , "H . J . Lu" Subject: [PATCH v2 11/11] Linux: optimize clone3 internal usage Date: Fri, 4 Nov 2022 16:01:12 -0300 Message-Id: <20221104190112.2566409-12-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221104190112.2566409-1-adhemerval.zanella@linaro.org> References: <20221104190112.2566409-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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 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-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Cc: Christian Brauner Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" 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. --- 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 */