Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp2445647rdb; Mon, 5 Feb 2024 06:57:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IHpaTx/2xGyrsJxvDzAz9IPSLOazXZBKbDl+BHd4Pzo8DP/j7sEN7D5ya0yzpx/+zMa1508 X-Received: by 2002:ac8:6b8c:0:b0:42b:e4a1:b993 with SMTP id z12-20020ac86b8c000000b0042be4a1b993mr4923908qts.30.1707145024077; Mon, 05 Feb 2024 06:57:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707145024; cv=pass; d=google.com; s=arc-20160816; b=C//HTvwQgbt+pCz9VfDI1gipyhZaElT96kXwkj0syFAUVn7uaInIgNUKsrBABDRUVs G+13HbNUhg8xsteGMxWOK61q6lJZvg6c2ARCUK6eM9hIpbT+CmO7q7VvGUxQeQvpMy0G UzruHSlyaUnY7qjfi4ztCHjDsHgmTbJif2goqb4z3LHReom4U4FerOA4uHXqQ0qSnnd3 2iL7laDSNgCRvXDu0dhxRDlipY+FJQNxVuJ/UamOo4q1xTxrhUCz0cak9EDFRvNL1ugk BHEE7IkZ4WRPL8RP+e23hrbyaCoDUi6Si/5htYSJzH0BCjnaT8VydKsCgjNT5XiuQN2B lkrA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:subject:cc:to:from :date:dkim-signature; bh=3wWFKFwgxakmvKvguQj6wEaI43mBgwyBm4UjoRgLEUY=; fh=C6dO4LNMFhA3rCA/rrSAuXXtNGWseHRSOwDj7h8TJgU=; b=YTQhyrF9qQtuv34Elor5TLqHzHmdJsQa9g0oqISB8Vw8wbqljrmuHvjTJqvID9DNun keQr2PnMz13qJcc72H/4vlUI4GiPXHUcae2eqZRPU4K1FTISZent8kmig+9ljdbrHLIN zzVZiJjCLHEhIDUpPURuoI23/DV7CAA1GqcOwgknyo+KQt8HPXQVZLdIDMA82PdwWqJq dNg/CXkBMe56WEZySPewPRN11Vg42u44Cj+MCnEXgT0xS4hWVIOTeTY6nNIcazbsCRm1 Gr0Nptdy+VggGA8Yxn6qZBBSomWAhku++V3vX4TRyq5O6M620f8HFZmiIJhzFiiny9Mx qaKw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Ao+KaV+K; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-52855-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-52855-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Forwarded-Encrypted: i=1; AJvYcCUGFfuxDIWmz8q6+sHVDzwLXNX24NmJsYKVH4zxiRI/MF9PIQgI30IbNdENnJgAuwCY9WMsQ1/VHtkzyRwH/0u8RqtRyMcL53DgnEuBRg== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id vu17-20020a05620a561100b0078572167359si4819449qkn.629.2024.02.05.06.57.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 06:57:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-52855-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Ao+KaV+K; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-52855-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-52855-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id D08171C21DE1 for ; Mon, 5 Feb 2024 14:57:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 396B02C69F; Mon, 5 Feb 2024 14:56:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Ao+KaV+K" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B3C3C2C684 for ; Mon, 5 Feb 2024 14:56:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707145017; cv=none; b=HeC0gy+cGTvV2/r9bauSmbmVygcR8PMidCULB1NORqNwWOuTyziE2a/uy11B5S6XjiwGpPC0uT/Fu6D5q3ILB2r/C98Att5fZyKYNHBURADsxpKV3X54xrYeRckIQMjcRShaUSQ5HQK0Kt51mnXHG/iM0Gjict3aVQBMoW+NvJ4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707145017; c=relaxed/simple; bh=yml1g8lIUP8NOhlaf1UJ6FHxeNTEQqWwTozbd2chOzM=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=Z6FWFzUwf9mWH+1H+gqKbkXNoJ6RLg93eZMvfixGQ+3nb9F1NFLJXHZtTfwOEf4KnMWmamBFGlTCCEd7WoORjXFbeReDvrJrpR9/Zgp7n/onegRD78p6XcP1QukMwK1T6+eQcu3s9RPY1tUbb30neBlFJIhHqeEK9RC3IbSHsAI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Ao+KaV+K; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707145013; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=3wWFKFwgxakmvKvguQj6wEaI43mBgwyBm4UjoRgLEUY=; b=Ao+KaV+KF1pnbQoNR1x4ZvfaCjtIGQU6oYS62tmeCOwYbaOr26IbBbVIbv1yP8HUZQCZnR h+wi5wGt8ipR3GjcK+ZfeF8FcJ91irvlOUHCSCsl7QZ4EIihmHQWJjmoDu617GAFgLnOW0 pPnfKvTLCw+JfgnKMJqrbw6H4d4Jfxc= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-220-nvK2DcrVMjCHItX-V9VBBA-1; Mon, 05 Feb 2024 09:56:51 -0500 X-MC-Unique: nvK2DcrVMjCHItX-V9VBBA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6801C8432A3; Mon, 5 Feb 2024 14:56:50 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.225.165]) by smtp.corp.redhat.com (Postfix) with SMTP id BC7FB3C2E; Mon, 5 Feb 2024 14:56:48 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Mon, 5 Feb 2024 15:55:34 +0100 (CET) Date: Mon, 5 Feb 2024 15:55:32 +0100 From: Oleg Nesterov To: Christian Brauner Cc: Andy Lutomirski , "Eric W. Biederman" , Tycho Andersen , linux-api@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] pidfd: clone: allow CLONE_THREAD | CLONE_PIDFD together Message-ID: <20240205145532.GA28823@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 copy_process() just needs to pass PIDFD_THREAD to __pidfd_prepare() if clone_flags & CLONE_THREAD. We can also add another CLONE_ flag (or perhaps reuse CLONE_DETACHED) to enforce PIDFD_THREAD without CLONE_THREAD. Originally-from: Tycho Andersen Signed-off-by: Oleg Nesterov --- kernel/fork.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/kernel/fork.c b/kernel/fork.c index 8d08a2d1b095..cd61ca87d0e6 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -2311,9 +2311,8 @@ __latent_entropy struct task_struct *copy_process( /* * - CLONE_DETACHED is blocked so that we can potentially * reuse it later for CLONE_PIDFD. - * - CLONE_THREAD is blocked until someone really needs it. */ - if (clone_flags & (CLONE_DETACHED | CLONE_THREAD)) + if (clone_flags & CLONE_DETACHED) return ERR_PTR(-EINVAL); } @@ -2536,8 +2535,10 @@ __latent_entropy struct task_struct *copy_process( * if the fd table isn't shared). */ if (clone_flags & CLONE_PIDFD) { + int flags = (clone_flags & CLONE_THREAD) ? PIDFD_THREAD : 0; + /* Note that no task has been attached to @pid yet. */ - retval = __pidfd_prepare(pid, 0, &pidfile); + retval = __pidfd_prepare(pid, flags, &pidfile); if (retval < 0) goto bad_fork_free_pid; pidfd = retval; -- 2.25.1.362.g51ebf55