From patchwork Fri Feb 2 13:12:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleg Nesterov X-Patchwork-Id: 195855 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp417358dyc; Fri, 2 Feb 2024 05:14:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IF6ULkbdi4fOyESKFZfuwNGIdhoeAvMgEfoC9WKFVOt8VjxldQ7rjZAqV1LODtQZgcU6amr X-Received: by 2002:ac8:7f41:0:b0:42b:f776:4181 with SMTP id g1-20020ac87f41000000b0042bf7764181mr5292297qtk.53.1706879665291; Fri, 02 Feb 2024 05:14:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706879665; cv=pass; d=google.com; s=arc-20160816; b=RI1/76LyTENF+kDWDAu/PtLA73SXpBoRk32ag5VN3WXEh3P8VIWYQXBQnWjXwq0o+P fUToXNrcBFtGL1IE5pLBF/De7mi73VPARcYXWkAXZqhKUWsENNphSwRE0n83rqP6ncxh mfPTadKrx3QnYE+3sfQ/rLmIoE170tsRzhwE2M3F/0OW72URJdDmZfiPViX9UyX+dKJ1 aMnNDFplC6WJfHUDCtr9hVew6zZzFhMWCqaWvuLI2URvLIICgCSDIMJMgKuYTuZWxXbo B+kLAjt5lPFFcjfkwLo79n9TODHhdGT1yRnkCkhmnML3Uoy1edrvsFArsW6vd3aQQ+Ta IGmg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-disposition:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:message-id :subject:cc:to:from:date:dkim-signature; bh=hcrUB/TxGDQzkVWVzEEPdidIHt7V/i+DGLB/TQZqAG4=; fh=DR5WObGas1x+fTBskDrgPEL2kdlmtM436EGUlYEKhw8=; b=KU0m5xIs5/y2IuH828MnLYLyv0u9tiJPDXeAc23aGa6VGRg94AztVbdyV/pILd0A9D TNTXUy6N2eG6fewaJjjDM51Ez7l+ngMlIadOGjR4ZiqxJfOHrLskCGYaDBWau9lXzhCF UDM6jZEGdG/sMgw5qPYT/Y2nw7vdXiE0KuprsOJqyu9VOHTeUNTKQ08ZCPo2N/w5bdrU b6VYH587yjbFbuNMtIYckHbDF/+m9UZb6C6PG0kM0RmcDPFQLEqVJsKC0x+iw17SuZiJ LPBwHRpr3baXsWqsTAOJgkLd1UwUnP7pqwu/6YKdwU/LhiNFlT3qMaqkAY2hCp54NBpC viJQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KX1NJ3mP; 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-49883-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49883-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Forwarded-Encrypted: i=1; AJvYcCXuaksSJnlZZ2EDdyvfTdmaQxuEK1syHcTknYkiUmeMXNszYS3VTcRMUJkyQUaCGwuSeAMNxeOlTmIEHbAltD/9K1rc+Q== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id j14-20020a05622a038e00b0042c06c5c1dbsi757650qtx.596.2024.02.02.05.14.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 05:14:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49883-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KX1NJ3mP; 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-49883-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49883-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 16FB71C24AC2 for ; Fri, 2 Feb 2024 13:14:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 85CEB4643A; Fri, 2 Feb 2024 13:14:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="KX1NJ3mP" 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 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789793051890981496 X-GMAIL-MSGID: 1789793051890981496 Add another wake_up_all(wait_pidfd) into __change_pid() and change pidfd_poll() to include EPOLLHUP if task == 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, struct file *f) } #endif -static bool pidfd_task_exited(struct pid *pid, bool thread) -{ - struct task_struct *task; - bool exited; - - rcu_read_lock(); - task = pid_task(pid, PIDTYPE_PID); - exited = !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 = file->private_data; bool thread = file->f_flags & PIDFD_THREAD; + struct task_struct *task; __poll_t poll_flags = 0; 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 = pid_task(pid, PIDTYPE_PID); + if (!task) + poll_flags = EPOLLIN | EPOLLRDNORM | EPOLLHUP; + else if (task->exit_state && (thread || thread_group_empty(task))) poll_flags = EPOLLIN | EPOLLRDNORM; + rcu_read_unlock(); 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, enum pid_type type, hlist_del_rcu(&task->pid_links[type]); *pid_ptr = new; + if (type == PIDTYPE_PID) { + WARN_ON_ONCE(pid_has_task(pid, PIDTYPE_PID)); + wake_up_all(&pid->wait_pidfd); + } + for (tmp = PIDTYPE_MAX; --tmp >= 0; ) if (pid_has_task(pid, tmp)) return; From patchwork Fri Feb 2 13:12:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleg Nesterov X-Patchwork-Id: 195856 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp418638dyc; Fri, 2 Feb 2024 05:16:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IH8V3NInfXXOg75zfDTqsiws3uaJ7+AZscHrkdnFByCHmTbbKRJvfU1IpE2QYIhW8dOtaCs X-Received: by 2002:a17:903:298b:b0:1d8:e935:5765 with SMTP id lm11-20020a170903298b00b001d8e9355765mr7158787plb.18.1706879783892; Fri, 02 Feb 2024 05:16:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706879783; cv=pass; d=google.com; s=arc-20160816; b=ZJ/SAt+owOcUw2nL1EkQbXDOBr+QCgdACj9RrCDSCDTYN4Hfttl+c7hzrjA17w8ahk +0cGt+DtMGP/yyBtzKnByoDmA7E4+JxVrvdVHKANR56JXQw/0Nzwl8GuzAtpoArflCG0 I4BnEhAnb4POtW6KjdDP4EjT2eQJX1A6rOaYGpxNS6xqm4ayXf+qVOHR6NS79GFrj4bK Ij8Vlf3KvJ7nybh5VdCRfrE0J2mMneprL2GUQnQF0wBsGPo3m3Xsq5/OgiihJ92gHi+D rFrUWVtLS+H8GhDimWxTjl/b/uIRCDN2hlOpZ9NUKlTlaxXhLfJVXL/9Egidrb7Of1xf SdJQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-disposition:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:message-id :subject:cc:to:from:date:dkim-signature; bh=9vsU4UH8CnAe6P5md1iwFJaffq8LntVkCJ8Quv5kMPs=; fh=ngcGd+0G1RvnMs/WowVcopiv61nMCJPHdMLwJG+Stg0=; b=hywZzhgjPvXMQk1WfKcApPd263BUMNNvNTdFaJxdFwLMxrgCuPt3LXILzfDRWdSrXM ooMcXkPw8x3V2+7wBRw2pgJUjlk+cBzj7DX0hcQUjpdD5AR6jxZhlSHbEllJ2JSpgrUn XV62sjtmLaibSuYBFIZdsFjbNo9TUtaWBYtQzhkPBqWKXtgrxOGXXsEJWjhYRCCqQwrv vb2kTBf648BVoox0rXRl2Pgl+xbQB0CXaL2gB4SkhOAAq/eKVHFjutju214UkyO7ukvu Gm8pXlVdFHoX6Qnu/Qwiij5zIIvaDIHrPBnukv4G6ttdW73TYQmauQKXd9nktiWYTSVa NZGA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="cEuwlN/D"; 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-49884-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49884-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Forwarded-Encrypted: i=1; AJvYcCVWGJYKkQS6f1pMU8QbW3kwpBOPu9dQ554LIsN77qtb40+shp1eCXu+DjRLTh8A0CoCifR79rLZqBoAr8ficZkTracQpA== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id i19-20020a170902eb5300b001d917fa8be8si1656336pli.257.2024.02.02.05.16.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 05:16:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49884-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="cEuwlN/D"; 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-49884-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49884-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 539CA290663 for ; Fri, 2 Feb 2024 13:14:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0B02646548; Fri, 2 Feb 2024 13:14:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="cEuwlN/D" 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 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789793175971565980 X-GMAIL-MSGID: 1789793175971565980 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) BUG_ON(leader->exit_state != EXIT_ZOMBIE); leader->exit_state = 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 From patchwork Fri Feb 2 13:12:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleg Nesterov X-Patchwork-Id: 195857 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp418780dyc; Fri, 2 Feb 2024 05:16:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IEUYmBAgvHmwV58uORvFsHa3P9MVZNxFX/kFezce4d2Nkarq/L3he1nyj5igUZIj9AXjn/w X-Received: by 2002:a17:903:11c8:b0:1d9:34ff:f807 with SMTP id q8-20020a17090311c800b001d934fff807mr2710309plh.31.1706879797614; Fri, 02 Feb 2024 05:16:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706879797; cv=pass; d=google.com; s=arc-20160816; b=cM06yPuTdL3enIDZRQ2M1keqClAFYFxrowdgtQh8CzdTR5NWIoWyZqujJLuotB5xcL OHtU8H/U6QaTzKDCJFlBCX/qL/A1Ob7nS4gUXpcxrKQQwdCHjkDLG2nAzBgvnQHGZRlq JymQo/8lZd5iR85hnIPvtmt+JQXXCE18go5zvQS45gWDFZ9xZQsTUsLQu2Qt5cFaupAu 3HqwwVeZlJkyDaCDHMqSJ69hbk8bV/ZsEyC+6Jjne/S7CcJtIHUhqon6sRediYKQhEyw RBPK0RFaIf2UvlJfo8ZesnK/5PfnU5AQ3IIUduDMEZs1ZAH0KtScZKqFZesWgO0N8uwM Ks7g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-disposition:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:message-id :subject:cc:to:from:date:dkim-signature; bh=SUcW1YhSjDQX7WeyM3q0JdmdY1LiP8oScsXALyNsO5g=; fh=BjQFsrmpAZdWSJ6EJUDNhx2WMP30+OqQDSCTm/yJ0as=; b=IqKz709HgEy882Kdops5Jpd9fZ0dYn7yPMfcvhRiwlnRHrEY3LA1T3gcjEYDqMF//0 OwZh1R/oOCh0RrTOMTemuYxtL272dCwkJGLGcgy7/1LrZ1W/i1Cm80dNjY4cn5FlGO1U RDJnpTWANw4ybwDo4Y1EP3WDshfUikACIbb60OdVjnXyIh47Jl++0vGGh+fVAxjtTVGC H1qVJeR+d3buMqhiMm2QsaBSgVfiHXUjfTXh74AYu4SJwZUanifFTCFf9w5FmtN2eJKC SdMXNr0CsXaCp0Glti8KrsEV4dMqpwEABN9Lhb+aP+6+Q+7XVVoHN3Rm5ZU5BmeKySE2 L5iQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IQh8y9jM; 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-49885-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49885-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Forwarded-Encrypted: i=1; AJvYcCXB2/ZwDNQEDcy/UyS3Hv6UoqLDTiu84hXnyrG1NwQMTHM1R+bXnHHSxPxJqCRMvIsQUHPgL73zl6kY6E1I2/0wwErcKQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id i19-20020a170902eb5300b001d917fa8be8si1656336pli.257.2024.02.02.05.16.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 05:16:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49885-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IQh8y9jM; 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-49885-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49885-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id AE349290EFC for ; Fri, 2 Feb 2024 13:14:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 144F645BFC; Fri, 2 Feb 2024 13:14:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="IQh8y9jM" 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 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789793190410970651 X-GMAIL-MSGID: 1789793190410970651 transfer_pid() must be never called with pid == 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 task_struct *right) void transfer_pid(struct task_struct *old, struct task_struct *new, enum pid_type type) { - if (type == PIDTYPE_PID) - new->thread_pid = old->thread_pid; + WARN_ON_ONCE(type == PIDTYPE_PID); hlist_replace_rcu(&old->pid_links[type], &new->pid_links[type]); }