Message ID | 20240205145532.GA28823@redhat.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-52855-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp926479dyb; Mon, 5 Feb 2024 06:57:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IEXLBsBpaw1r2fDgogd/0c08lSHf3KheKVdDi1gj7MMKmWV58ozMnF3tlSf1zA4SmvXIKNV X-Received: by 2002:a17:906:3111:b0:a37:1e9a:c94f with SMTP id 17-20020a170906311100b00a371e9ac94fmr5577000ejx.6.1707145034134; Mon, 05 Feb 2024 06:57:14 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707145034; cv=pass; d=google.com; s=arc-20160816; b=hgts/qqOx8ntUmLQy340M57R+i6YgRREyeXDuHN75M4KqnjKPYQpXLDq5dfR3NLDZ4 L0YHGnlfI6ukdnkFWXBcQX1nnFBASPD2WIm6KROs9pFLnMiT0EctEjaG+XbS/5YZZJQ+ iTEsA9JX3bkK6pG+tp+WKaCOcAvxAi4LtsAN+40h07Un70LXwbsvxbbCyL4GYRFgusPZ awyHbN5g6UwDYysFNSW+7EbyloR83Q9WkyGcbdWHWdP5Ur1hBe2fMj7dFjsmwOqF6dRA 13wp8Z0LPz+pZYALX9PiSDoOhXx+fWxwfp26h9R111rGCHYK4JRACAJ5tjCMIO/m4PzI 85zw== 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=Yhjz9FNe2Taqk/PvmxiVDGb+oYojAOzPOzydshJe2uc=; b=poGZw5UyV3hzZC+NkdpnWu0oQD7xCYtrJ+nOam/nXXI35LXSQ1f8rXQGF0LlTVnsnQ 8g1GG0cx41R/u2mBG07Bk6HgVE8qNAtMKKEbAg9MSNZQk2O1bBbLxSNO4WoxjtJaCaQJ dygrdrqQOv+bvBT3Y9l3B7YXDA8MDYMtZps8YWApoqLNe1/ihdp7mK85FqcpGud6w8PK xkkgWh3Bg1YKyb8zIhtjZGlxWLXa1cubeHzMWeq9JRmoZHmTNAJtyQYqevmegkCJeA04 nXjpredZA8l5qLt4/gUx2tXlkm6fEDeX3XEa27Ykj2Xn7HOq4MakZK7kHJoBZ5OWJ5AQ TeqQ==; 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-52855-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Forwarded-Encrypted: i=1; AJvYcCXeAKhIpYNhqK0pFFTLQGOqTODj90fQY4nFgLzPcynGOps5dtylqRf+L6guNOrHp7rT1cWVE5xItHdPZOzWaQtGgyf7hw== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id p27-20020a1709060ddb00b00a37af9e566dsi1325298eji.953.2024.02.05.06.57.13 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 06:57:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-52855-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-52855-ouuuleilei=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 am.mirrors.kernel.org (Postfix) with ESMTPS id B962D1F246D3 for <ouuuleilei@gmail.com>; Mon, 5 Feb 2024 14:57:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0B1AD2C6B5; Mon, 5 Feb 2024 14:57:00 +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 <linux-kernel@vger.kernel.org>; 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 <oleg@redhat.com> To: Christian Brauner <brauner@kernel.org> Cc: Andy Lutomirski <luto@amacapital.net>, "Eric W. Biederman" <ebiederm@xmission.com>, Tycho Andersen <tycho@tycho.pizza>, 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: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790071310918795807 X-GMAIL-MSGID: 1790071310918795807 |
Series |
pidfd: clone: allow CLONE_THREAD | CLONE_PIDFD together
|
|
Commit Message
Oleg Nesterov
Feb. 5, 2024, 2:55 p.m. UTC
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 <tycho@tycho.pizza>
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
kernel/fork.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
Comments
On Mon, 05 Feb 2024 15:55:32 +0100, Oleg Nesterov wrote: > 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. > > > [...] Applied to the vfs.pidfd branch of the vfs/vfs.git tree. Patches in the vfs.pidfd branch should appear in linux-next soon. Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it. It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated. Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch. tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs.pidfd [1/1] pidfd: clone: allow CLONE_THREAD | CLONE_PIDFD together https://git.kernel.org/vfs/vfs/c/572a94c5290e
On Mon, Feb 05, 2024 at 03:55:32PM +0100, Oleg Nesterov wrote: > 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 <tycho@tycho.pizza> Goes without saying I suppose, but, Reviewed-by: Tycho Andersen <tandersen@netflix.com> as well. Tycho
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;