From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.5 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_PASS,USER_AGENT_MUTT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36C82C10F13 for ; Tue, 16 Apr 2019 12:04:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 12A042086A for ; Tue, 16 Apr 2019 12:04:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727952AbfDPMEr (ORCPT ); Tue, 16 Apr 2019 08:04:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37264 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726796AbfDPMEr (ORCPT ); Tue, 16 Apr 2019 08:04:47 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 041573087BC6; Tue, 16 Apr 2019 12:04:41 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.43.17.38]) by smtp.corp.redhat.com (Postfix) with SMTP id 94E9560C61; Tue, 16 Apr 2019 12:04:32 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Tue, 16 Apr 2019 14:04:40 +0200 (CEST) Date: Tue, 16 Apr 2019 14:04:31 +0200 From: Oleg Nesterov To: "Joel Fernandes (Google)" Cc: linux-kernel@vger.kernel.org, luto@amacapital.net, rostedt@goodmis.org, dancol@google.com, christian@brauner.io, jannh@google.com, surenb@google.com, torvalds@linux-foundation.org, Alexey Dobriyan , Al Viro , Andrei Vagin , Andrew Morton , Arnd Bergmann , "Eric W. Biederman" , Kees Cook , linux-fsdevel@vger.kernel.org, linux-kselftest@vger.kernel.org, Michal Hocko , Nadav Amit , Serge Hallyn , Shuah Khan , Stephen Rothwell , Taehee Yoo , Tejun Heo , Thomas Gleixner , Tycho Andersen Subject: Re: [PATCH RFC 1/2] Add polling support to pidfd Message-ID: <20190416120430.GA15437@redhat.com> References: <20190411175043.31207-1-joel@joelfernandes.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190411175043.31207-1-joel@joelfernandes.org> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Tue, 16 Apr 2019 12:04:46 +0000 (UTC) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org On 04/11, Joel Fernandes (Google) wrote: > > +static unsigned int proc_tgid_base_poll(struct file *file, struct poll_table_struct *pts) > +{ > + int poll_flags = 0; > + struct task_struct *task; > + struct pid *pid; > + > + task = get_proc_task(file->f_path.dentry->d_inode); > + > + WARN_ON_ONCE(task && !thread_group_leader(task)); > + > + /* > + * tasklist_lock must be held because to avoid racing with > + * changes in exit_state and wake up. Basically to avoid: > + * > + * P0: read exit_state = 0 > + * P1: write exit_state = EXIT_DEAD > + * P1: Do a wake up - wq is empty, so do nothing > + * P0: Queue for polling - wait forever. > + */ > + read_lock(&tasklist_lock); > + if (!task) > + poll_flags = POLLIN | POLLRDNORM | POLLERR; > + else if (task->exit_state == EXIT_DEAD) > + poll_flags = POLLIN | POLLRDNORM; > + else if (task->exit_state == EXIT_ZOMBIE && thread_group_empty(task)) > + poll_flags = POLLIN | POLLRDNORM; > + > + if (!poll_flags) { > + pid = proc_pid(file->f_path.dentry->d_inode); > + poll_wait(file, &pid->wait_pidfd, pts); > + } can't understand... Could you explain when it should return POLLIN? When the whole process exits? Then all you need is !task || task->exit_state && thread_group_empty(task) Please do not use EXIT_DEAD/EXIT_ZOMBIE. And ->wait_pidfd should probably live in task->signal_struct. Oleg.