From nobody Wed Feb 11 09:19:15 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 40F022772A for ; Fri, 2 Feb 2024 13:14:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706879649; cv=none; b=P2h2dCcHNbnlH7q+pdjZX3I6ypO5OIgq8T3GzhT68lPq1CMM6RjKaRqQsevcCLm3k7mnJ+PRZJD976UvRRtXAJkarIitK/GfK4cTmalDzNFrXXA1z88yrF3T02VkTViyv00V0sb0m1neBNYt2HwlnExVz519ZeS3+1a69zqm6bQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706879649; c=relaxed/simple; bh=Ll/s1Mpq1wn0WVe7lBWJ6vbuD1ND6xPjIS/Y+odacrw=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; b=P4mz6sCsu7yyYPy/13DcIdYO22B8CAlwrLZU8XEOT0rc4ttclCOh5swlsQXIyZ1q4omP6ceyZOstD8uecDJX4SpQdrnaQ9QtERfFlN4V+hLVQzevnISxHtHxPDKxG1JKyVUR6fpH1ESKrqhlmGrNGXBF451rTsLM7aQfswDQhlM= 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=KX1NJ3mP; arc=none smtp.client-ip=170.10.129.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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="KX1NJ3mP" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706879647; 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: in-reply-to:in-reply-to; bh=hcrUB/TxGDQzkVWVzEEPdidIHt7V/i+DGLB/TQZqAG4=; b=KX1NJ3mPuL8X4OjuyxctE5FOG+qiczWYN/Vo1H5g6BTzhB7FrzzRCMWeewOrNYmj/vV/E7 Ia5MOBDu5418XVNnOSvF5Tw0KeHLp6XHu/wKxwx06Ujc99cZs7Tx/3OQ/u+PxO3TGSRgJh 6X1BY0MSQDbCtdTVWstnxt2c1hVfhuQ= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-639-UFkX2USqOH-HlUQt27oB7w-1; Fri, 02 Feb 2024 08:14:03 -0500 X-MC-Unique: UFkX2USqOH-HlUQt27oB7w-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 614F529AC00E; Fri, 2 Feb 2024 13:14:03 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.226.76]) by smtp.corp.redhat.com (Postfix) with SMTP id 0F4B4400D783; Fri, 2 Feb 2024 13:14:01 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Fri, 2 Feb 2024 14:12:48 +0100 (CET) Date: Fri, 2 Feb 2024 14:12:26 +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 1/3] pidfd_poll: report POLLHUP when pid_task() == NULL Message-ID: <20240202131226.GA26018@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240202131147.GA25988@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add another wake_up_all(wait_pidfd) into __change_pid() and change pidfd_poll() to include EPOLLHUP if task =3D=3D NULL. This allows to wait until the target process/thread is reaped. TODO: change do_notify_pidfd() to use the keyed wakeups. Signed-off-by: Oleg Nesterov --- kernel/fork.c | 22 +++++++--------------- kernel/pid.c | 5 +++++ 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/kernel/fork.c b/kernel/fork.c index b8c6ec9a08dd..8d08a2d1b095 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -2071,20 +2071,6 @@ static void pidfd_show_fdinfo(struct seq_file *m, st= ruct file *f) } #endif =20 -static bool pidfd_task_exited(struct pid *pid, bool thread) -{ - struct task_struct *task; - bool exited; - - rcu_read_lock(); - task =3D pid_task(pid, PIDTYPE_PID); - exited =3D !task || - (READ_ONCE(task->exit_state) && (thread || thread_group_empty(task))); - rcu_read_unlock(); - - return exited; -} - /* * Poll support for process exit notification. */ @@ -2092,6 +2078,7 @@ static __poll_t pidfd_poll(struct file *file, struct = poll_table_struct *pts) { struct pid *pid =3D file->private_data; bool thread =3D file->f_flags & PIDFD_THREAD; + struct task_struct *task; __poll_t poll_flags =3D 0; =20 poll_wait(file, &pid->wait_pidfd, pts); @@ -2099,8 +2086,13 @@ static __poll_t pidfd_poll(struct file *file, struct= poll_table_struct *pts) * Depending on PIDFD_THREAD, inform pollers when the thread * or the whole thread-group exits. */ - if (pidfd_task_exited(pid, thread)) + rcu_read_lock(); + task =3D pid_task(pid, PIDTYPE_PID); + if (!task) + poll_flags =3D EPOLLIN | EPOLLRDNORM | EPOLLHUP; + else if (task->exit_state && (thread || thread_group_empty(task))) poll_flags =3D EPOLLIN | EPOLLRDNORM; + rcu_read_unlock(); =20 return poll_flags; } diff --git a/kernel/pid.c b/kernel/pid.c index e11144466828..62461c7c82b8 100644 --- a/kernel/pid.c +++ b/kernel/pid.c @@ -349,6 +349,11 @@ static void __change_pid(struct task_struct *task, enu= m pid_type type, hlist_del_rcu(&task->pid_links[type]); *pid_ptr =3D new; =20 + if (type =3D=3D PIDTYPE_PID) { + WARN_ON_ONCE(pid_has_task(pid, PIDTYPE_PID)); + wake_up_all(&pid->wait_pidfd); + } + for (tmp =3D PIDTYPE_MAX; --tmp >=3D 0; ) if (pid_has_task(pid, tmp)) return; --=20 2.25.1.362.g51ebf55 From nobody Wed Feb 11 09:19:15 2026 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 ED52146448 for ; Fri, 2 Feb 2024 13:14:14 +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=1706879656; cv=none; b=aNwJiRSwkbNRNs5+3Mc8pkoWiM5XB61nwhpmkJCegb7Xn6HcfktAXdMaBnG8hoA2a9rVOMDMkN6Ugnmt+oAHibvxMAcB7f/mGAyBXPtTKiQ2bmJHRIbTC04OX6ySwsctPm0SPZN+rzwPi+lZBAmNlBRtKNv2BHd0RPwyUQF7Ads= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706879656; c=relaxed/simple; bh=PhX+ubXI7FCPmRXptvhe+J5At0mfznoYNIfO29NGvGQ=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; b=KhX0+YxY37BQK3fsiPYOLDke3Gl24ex/0K/83SkJfrRWVKC8vDb738x+y5STtkAtWzCgIzfv8/N24TS77GauUpW3YSHWSBa2R5CiS9bHx2WaIEXvKkSYV6wIDDSy3AlNzMnZ7SL1/tY4XDb4MqoRBYxO0HAImiAAA7WLbEXROiE= 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=cEuwlN/D; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="cEuwlN/D" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706879654; 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: in-reply-to:in-reply-to; bh=9vsU4UH8CnAe6P5md1iwFJaffq8LntVkCJ8Quv5kMPs=; b=cEuwlN/Dp9bSf2WCIfsmJH6NO8ECqIkDYTe9rV9OHa4FQP6OTj3NEg/hKVQHXHC60PRl5t 3gN5m1zicQDE0dbNDXR1/W0Efa4chOv7hUiXh2N3gPLhMGyMPw/eL4QO13QQ9MjCVi5hzT J+9Y9FRIoaPkdyeaszzeatI7P2ibllA= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-612-1J6EOV-NOzia-1h4KzNwNg-1; Fri, 02 Feb 2024 08:14:10 -0500 X-MC-Unique: 1J6EOV-NOzia-1h4KzNwNg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (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 3F95429AC00C; Fri, 2 Feb 2024 13:14:10 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.226.76]) by smtp.corp.redhat.com (Postfix) with SMTP id 936201121306; Fri, 2 Feb 2024 13:14:08 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Fri, 2 Feb 2024 14:12:54 +0100 (CET) Date: Fri, 2 Feb 2024 14:12:48 +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 2/3] pidfd: kill the no longer needed do_notify_pidfd() in de_thread() Message-ID: <20240202131248.GA26022@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240202131147.GA25988@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Now that __change_pid() does wake_up_all(&pid->wait_pidfd) we can kill do_notify_pidfd(leader) in de_thread(), it calls release_task(leader) right after that and this implies detach_pid(leader, PIDTYPE_PID). Signed-off-by: Oleg Nesterov --- fs/exec.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/fs/exec.c b/fs/exec.c index 0fd7e668c477..acd466f92998 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1143,11 +1143,6 @@ static int de_thread(struct task_struct *tsk) =20 BUG_ON(leader->exit_state !=3D EXIT_ZOMBIE); leader->exit_state =3D EXIT_DEAD; - /* - * leader and tsk exhanged their pids, the old pid dies, - * wake up the PIDFD_THREAD waiters. - */ - do_notify_pidfd(leader); /* * We are going to release_task()->ptrace_unlink() silently, * the tracer can sleep in do_wait(). EXIT_DEAD guarantees --=20 2.25.1.362.g51ebf55 From nobody Wed Feb 11 09:19:15 2026 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 D82A946558 for ; Fri, 2 Feb 2024 13:14:22 +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=1706879664; cv=none; b=mgLDuuKnrZFEFVHt5ScUkfLULDFAMEvWV69W6osusFzrekX0JHc3ucGO92eXbQqf5U/uLZ1DDbS8JvKSYWmZdIgdVK7TAseWNCBNdgI+HO5jPqsU8IElB9x49cG5m8+HFs7Okim5jdxCL2En5Q63cBbp/jmeWgI5uvuqTuITSjk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706879664; c=relaxed/simple; bh=+4rrO1QV60it1fu/bNaIuzNzFnEVuH5GK9jcRGMYtQo=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; b=V/5c/3ZYJlQMLWlEFiwFBeyu1588Lfu7liCJj4TQNvRZj8csMJYdThJV2AoZbEMJkiAYOIwxJssEf3YE6HnfEb7xi/sJ5un4zO/kukTZurNC5orGEehinbDf1kPGKQ1gXelRziPpsRC+eKpqguRTEhPvGkyGQERsgUhkyiErdpM= 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=IQh8y9jM; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="IQh8y9jM" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706879661; 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: in-reply-to:in-reply-to; bh=SUcW1YhSjDQX7WeyM3q0JdmdY1LiP8oScsXALyNsO5g=; b=IQh8y9jMFqNWCqGxzKcyIPOOWp+OzmEdOZCfzr697KU+izMYYRu330zCFPAPWx7ZOkJv9G 8rLWJgwwsCFCRzHSphMuPIFsWV51h/eLb8+Srezt0xSOqn9gevZXB4t59qLvvdNxPov9Nv gvj4TuN3cOs0W3aep0I6j4Vo/6Jac1s= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-106-1uvxbfj6Oq2VwfEIFpopTA-1; Fri, 02 Feb 2024 08:14:17 -0500 X-MC-Unique: 1uvxbfj6Oq2VwfEIFpopTA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 AE193383CCE0; Fri, 2 Feb 2024 13:14:16 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.226.76]) by smtp.corp.redhat.com (Postfix) with SMTP id 8A8C6111F9; Fri, 2 Feb 2024 13:14:15 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Fri, 2 Feb 2024 14:13:01 +0100 (CET) Date: Fri, 2 Feb 2024 14:12:55 +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 3/3] pid: kill the obsolete PIDTYPE_PID code in transfer_pid() Message-ID: <20240202131255.GA26025@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240202131147.GA25988@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" transfer_pid() must be never called with pid =3D=3D PIDTYPE_PID, new_leader->thread_pid should be changed by exchange_tids(). Signed-off-by: Oleg Nesterov --- kernel/pid.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/kernel/pid.c b/kernel/pid.c index 62461c7c82b8..de0bf2f8d18b 100644 --- a/kernel/pid.c +++ b/kernel/pid.c @@ -396,8 +396,7 @@ void exchange_tids(struct task_struct *left, struct tas= k_struct *right) void transfer_pid(struct task_struct *old, struct task_struct *new, enum pid_type type) { - if (type =3D=3D PIDTYPE_PID) - new->thread_pid =3D old->thread_pid; + WARN_ON_ONCE(type =3D=3D PIDTYPE_PID); hlist_replace_rcu(&old->pid_links[type], &new->pid_links[type]); } =20 --=20 2.25.1.362.g51ebf55