From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 58D8C5A026B for ; Thu, 17 Nov 2022 00:27:08 +0100 (CET) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4NCK2G4MGXz4xP9; Thu, 17 Nov 2022 10:27:02 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1668641222; bh=pVeSaL02Cvja8vE7mKB1WTswL7EROafgizWhCMcESFo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=byEWKcprl+IQ/WuEtnfhTnIp6yJUsPtWL749vrLZphdF2NxwSMQ+GBA0Vs7CKFM8i 6StByTl/8K16R/IjYkiVvp9Ydj9FjJkWKMCEzUGJBTw6RAyvTHrSV3SjrxQdCStzIs FKjcvjU/5W0X2a0SfaLus8q+rskrN85clJCR2Dtk= Date: Thu, 17 Nov 2022 10:00:32 +1100 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH v3] util, pasta: Add do_clone() wrapper around __clone2() and clone() Message-ID: References: <20221116163057.2637847-1-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="zlNxfFMAmpsGQYWG" Content-Disposition: inline In-Reply-To: <20221116163057.2637847-1-sbrivio@redhat.com> Message-ID-Hash: 45W4ORBQYLYYGC2DHHLOMYJ44HERRROQ X-Message-ID-Hash: 45W4ORBQYLYYGC2DHHLOMYJ44HERRROQ X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.3 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: --zlNxfFMAmpsGQYWG Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Nov 16, 2022 at 05:30:57PM +0100, Stefano Brivio wrote: > Spotted in Debian's buildd logs: on ia64, clone(2) is not available: > the glibc wrapper is named __clone2() and it takes, additionally, > the size of the stack area passed by the caller. >=20 > Add a do_clone() wrapper handling the different cases, and also > taking care of pointing the child's stack in the middle of the > allocated area: on PA-RISC (hppa), handled by clone(), the stack > grows up, and on ia64 the stack grows down, but the register backing > store grows up -- and I think it might be actually used here. >=20 > Suggested-by: David Gibson > Signed-off-by: Stefano Brivio Heh, my only comment on v2 was going to be that it's not a good idea to name identifiers starting with _ - that's reserved for the system library. Reviewed-by: David Gibson > --- > v3: Don't call it __clone(), it conflicts with glibc on static builds >=20 > v2: Add a wrapper instead of two __ia64__ ifdefs >=20 > pasta.c | 10 +++++----- > util.c | 21 +++++++++++++++++++++ > util.h | 8 +++++--- > 3 files changed, 31 insertions(+), 8 deletions(-) >=20 > diff --git a/pasta.c b/pasta.c > index db86317..528f02a 100644 > --- a/pasta.c > +++ b/pasta.c > @@ -226,11 +226,11 @@ void pasta_start_ns(struct ctx *c, uid_t uid, gid_t= gid, > arg.argv =3D sh_argv; > } > =20 > - pasta_child_pid =3D clone(pasta_spawn_cmd, > - ns_fn_stack + sizeof(ns_fn_stack) / 2, > - CLONE_NEWIPC | CLONE_NEWPID | CLONE_NEWNET | > - CLONE_NEWUTS, > - (void *)&arg); > + pasta_child_pid =3D do_clone(pasta_spawn_cmd, ns_fn_stack, > + sizeof(ns_fn_stack), > + CLONE_NEWIPC | CLONE_NEWPID | CLONE_NEWNET | > + CLONE_NEWUTS, > + (void *)&arg); > =20 > if (pasta_child_pid =3D=3D -1) { > perror("clone"); > diff --git a/util.c b/util.c > index be102e3..2125a67 100644 > --- a/util.c > +++ b/util.c > @@ -482,3 +482,24 @@ int write_file(const char *path, const char *buf) > close(fd); > return len =3D=3D 0 ? 0 : -1; > } > + > +/** > + * do_clone() - Wrapper of __clone2() for ia64, clone() for other archit= ectures > + * @fn: Entry point for child > + * @stack_area: Stack area for child: we'll point callees to the middle = of it > + * @stack_size: Total size of stack area, passed to callee divided by two > + * @flags: clone() system call flags > + * @arg: Argument to @fn > + * > + * Return: thread ID of child, -1 on failure > + */ > +int do_clone(int (*fn)(void *), char *stack_area, size_t stack_size, int= flags, > + void *arg) > +{ > +#ifdef __ia64__ > + return __clone2(fn, stack_area + stack_size / 2, stack_size / 2, > + flags, arg); > +#else > + return clone(fn, stack_area + stack_size / 2, flags, arg); > +#endif > +} > diff --git a/util.h b/util.h > index 2d4e1ff..02b55a9 100644 > --- a/util.h > +++ b/util.h > @@ -81,13 +81,15 @@ > (((struct in_addr *)(a))->s_addr =3D=3D ((struct in_addr *)b)->s_addr) > =20 > #define NS_FN_STACK_SIZE (RLIMIT_STACK_VAL * 1024 / 8) > +int do_clone(int (*fn)(void *), char *stack_area, size_t stack_size, int= flags, > + void *arg); > #define NS_CALL(fn, arg) \ > do { \ > char ns_fn_stack[NS_FN_STACK_SIZE]; \ > \ > - clone((fn), ns_fn_stack + sizeof(ns_fn_stack) / 2, \ > - CLONE_VM | CLONE_VFORK | CLONE_FILES | SIGCHLD, \ > - (void *)(arg)); \ > + do_clone((fn), ns_fn_stack, sizeof(ns_fn_stack), \ > + CLONE_VM | CLONE_VFORK | CLONE_FILES | SIGCHLD,\ > + (void *)(arg)); \ > } while (0) > =20 > #if __BYTE_ORDER =3D=3D __BIG_ENDIAN --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --zlNxfFMAmpsGQYWG Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEoULxWu4/Ws0dB+XtgypY4gEwYSIFAmN1a3YACgkQgypY4gEw YSKMIA/+JYwZxgXWeZEA4cxbvO9qB13buWEkfwdTUYnz4VdvnEIXbwhwFt5w8Bbw YmpTw8XU/8u47gHJTlQLmoFPMGH/MjPpBm9yMd8OZZUylVmiGY/vdKSNxiFE5n93 TFsyBlDalfldCdX1QOf+Fnlx4xYZjZhGXb5yIrnCc6SVfSwxgaOcRjFsVRNv4eA/ Vf0N51pvopVMBhcq8ZMLsoW0wdG5iiioA3Db+t2WsQHiMzA3yXf62AsCKuk6/Qqj go8emCRdFlVtlImDb1oNTdahYipNS8vUBPerh4RxIcs+wtifRpKcXpz2EA1XswJh 4Y6kMK0/+zcavHT/CZvFY1ZV0d6wcSN6JrQSlUe85Dbv/wdoTji0cC1DDtXfkRt7 7OwQI1Cf76vTp3Zkc5h0aJt7Z+HCIDGnHSfmXDqFuf96I548y6caDxAiSLt/Lk8h MCsRVx8bBVr/gN+m8a36UY4NW1m7iFdSGSe4Y6RMesBTOLEMqtY39jnhYG5eaRZq rt8eyyZ5sYWZS2m7cKtzX23nQT9VDU80rtmOvrqcPU8I1ojlqhW+rHvAnTFN+ixZ /vvax8YNyTciy14qrhk4d9UOR2E111NcWmP7SrJGpJ3VBJrwNuUeGGtBcgOp7VDY sOAIkHcH5l71haDCvixL9UPtzdXdRaIjb50XqoUzkOYphqYs27A= =GZ+k -----END PGP SIGNATURE----- --zlNxfFMAmpsGQYWG--