From nobody Fri Apr 26 10:03:25 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1632250219; cv=none; d=zohomail.com; s=zohoarc; b=ekrexXfWDC2Xb6bB/gZhMKc8FAh4ZNyHw9VhvQx+fOhrPQ2rAIgFR6l3866kKqsmyQ/iJRPTOy4FLyLqFSiFUH6MjVy/1wv3RtyOpf7mBUppooCPL8BIfMgEug+vDJh+BTreIaTuKZYe7G+hTkOMt8GASvgaytCFG4xrvRZdhes= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632250219; h=Content-Type:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=intzir0YJZ1KjNOTWEh2CL8gg4rto0czBWNP+7s6oi8=; b=HR408OeFxxRGbSmRCNx5kw5FaNFyB8zUDha9PJdTI9TXU8T7AiGtfMDPy9fb51yYP07+E0i0/kw3WsnzWgg7PufuA5glJo+TPujAMW0dTyIQyQY9W8V5UV4rDxzLQ+5dirO+r06w/aW6jxuN2EUwnfUOvEmzBG8d0JqCICtc7c0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1632250219050218.40400478342713; Tue, 21 Sep 2021 11:50:19 -0700 (PDT) Received: from localhost ([::1]:60624 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mSkqP-0004ps-NO for importer@patchew.org; Tue, 21 Sep 2021 14:50:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54160) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mSkos-0003x0-Bg for qemu-devel@nongnu.org; Tue, 21 Sep 2021 14:48:42 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:42210) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mSkon-0000zE-PR for qemu-devel@nongnu.org; Tue, 21 Sep 2021 14:48:42 -0400 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 1FDAF22172; Tue, 21 Sep 2021 18:48:30 +0000 (UTC) Received: from hawking.suse.de (hawking.suse.de [10.160.4.0]) by relay2.suse.de (Postfix) with ESMTP id 16879A3B85; Tue, 21 Sep 2021 18:48:29 +0000 (UTC) Received: by hawking.suse.de (Postfix, from userid 17005) id E8D06445C9A; Tue, 21 Sep 2021 20:48:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1632250110; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=intzir0YJZ1KjNOTWEh2CL8gg4rto0czBWNP+7s6oi8=; b=ub6rCbaKyN77Ua40F37iDvF4xVFl47Ha/s7i1fLTOzT0kRinCc7Z57ymEzoFxRenzc0Smm vYZxFMJBZA/g12SZ1n4f7ZS+YLE2h0YQpCBnCV9myuQM8L9SGCe+2lmiBEFh0zH4Y1sE4d XpX9AttZctVcEpiR+hRYvhDt+zXct7c= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1632250110; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=intzir0YJZ1KjNOTWEh2CL8gg4rto0czBWNP+7s6oi8=; b=Q9Ktz4M1vxu/S5oX9oVk1iTdlisurzjNZpua1IqMaBVh563rNkY5rLAzu+n1q+oVgUEsFu cn1OAzbw4TxgNzCQ== From: Andreas Schwab To: Laurent Vivier Subject: [PATCH] linux-user/syscall: add support for CLONE_PIDFD X-Yow: Did YOU find a DIGITAL WATCH in YOUR box of VELVEETA? Date: Tue, 21 Sep 2021 20:48:29 +0200 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=195.135.220.28; envelope-from=schwab@suse.de; helo=smtp-out1.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1632250221807100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add basic support for CLONE_PIDFD, only fork-like clone without additional flags. This is enough to make Qt/forkfd working. Signed-off-by: Andreas Schwab --- linux-user/syscall.c | 52 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 544f5b662f..8b40064e75 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -143,6 +143,9 @@ #ifndef CLONE_IO #define CLONE_IO 0x80000000 /* Clone io context */ #endif +#ifndef CLONE_PIDFD +#define CLONE_PIDFD 0x00001000 /* set if a pidfd should b= e placed in parent */ +#endif =20 /* We can't directly call the host clone syscall, because this will * badly confuse libc (breaking mutexes, for example). So we must @@ -169,7 +172,8 @@ /* Flags for fork which we can implement within QEMU itself */ #define CLONE_OPTIONAL_FORK_FLAGS \ (CLONE_SETTLS | CLONE_PARENT_SETTID | \ - CLONE_CHILD_CLEARTID | CLONE_CHILD_SETTID) + CLONE_CHILD_CLEARTID | CLONE_CHILD_SETTID | \ + CLONE_PIDFD) =20 /* Flags for thread creation which we can implement within QEMU itself */ #define CLONE_OPTIONAL_THREAD_FLAGS \ @@ -494,6 +498,39 @@ _syscall4(int, sys_prlimit64, pid_t, pid, int, resourc= e, struct host_rlimit64 *, old_limit) #endif =20 +#if defined __NR_clone2 +#define __NR_sys_clone2 __NR_clone2 +_syscall6(int, sys_clone2, int, flags, void *, child_stack, size_t, stack_= size, + int *, ptid, int *, ctid, void *, newtls); +#else +#define __NR_sys_clone __NR_clone +#if defined __cris__ || defined __s390x__ +_syscall5(int, sys_clone, void *, child_stack, int, flags, int *, ptid, + void *, newtls, int *, ctid); +#elif defined __microblaze__ +_syscall6(int, sys_clone, int, flags, void *, child_stack, size_t, stack_s= ize, + int *, ptid, void *, newtls, int *, ctid); +#else +/* + * Note: ctid and newtls are swapped on some architectures, but both are + * passed as NULL only for now. + */ +_syscall5(int, sys_clone, int, flags, void *, child_stack, int *, ptid, + int *, ctid, void *, newtls); +#endif +#endif +static int sys_clone_pidfd(int flags, int *pidfd) +{ +#ifdef __NR_clone2 + return sys_clone2(flags, NULL, 0, pidfd, NULL, NULL); +#elif defined __cris__ || defined __s390x__ + return sys_clone(NULL, flags, pidfd, NULL, NULL); +#elif defined __microblaze__ + return sys_clone(flags, NULL, 0, pidfd, NULL, NULL); +#else + return sys_clone(flags, NULL, pidfd, NULL, NULL); +#endif +} =20 #if defined(TARGET_NR_timer_create) /* Maximum of 32 active POSIX timers allowed at any one time. */ @@ -6355,6 +6392,7 @@ static int do_fork(CPUArchState *env, unsigned int fl= ags, abi_ulong newsp, CPUState *new_cpu; CPUArchState *new_env; sigset_t sigmask; + int pidfd; =20 flags &=3D ~CLONE_IGNORED_FLAGS; =20 @@ -6362,6 +6400,10 @@ static int do_fork(CPUArchState *env, unsigned int f= lags, abi_ulong newsp, if (flags & CLONE_VFORK) flags &=3D ~(CLONE_VFORK | CLONE_VM); =20 + /* Only basic fork-like clone is supported with CLONE_PIDFD for now. */ + if (flags & CLONE_PIDFD && flags & ~(CLONE_PIDFD|CSIGNAL)) + return -TARGET_EINVAL; + if (flags & CLONE_VM) { TaskState *parent_ts =3D (TaskState *)cpu->opaque; new_thread_info info; @@ -6460,7 +6502,11 @@ static int do_fork(CPUArchState *env, unsigned int f= lags, abi_ulong newsp, } =20 fork_start(); - ret =3D fork(); + if (flags & CLONE_PIDFD) { + ret =3D sys_clone_pidfd(flags, &pidfd); + } else { + ret =3D fork(); + } if (ret =3D=3D 0) { /* Child Process. */ cpu_clone_regs_child(env, newsp, flags); @@ -6483,6 +6529,8 @@ static int do_fork(CPUArchState *env, unsigned int fl= ags, abi_ulong newsp, } else { cpu_clone_regs_parent(env, flags); fork_end(0); + if (flags & CLONE_PIDFD) + put_user_u32(pidfd, parent_tidptr); } } return ret; --=20 2.33.0 --=20 Andreas Schwab, SUSE Labs, schwab@suse.de GPG Key fingerprint =3D 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7 "And now for something completely different."