Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2806095yba; Sun, 28 Apr 2019 09:26:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqxs8vYCg+4r7bMvOBOnKjWAtmHoYkrdQ4wjb2Ft/0cNCdIzMAbjPkDcXFKEMb3aX+0Fay4J X-Received: by 2002:aa7:9a99:: with SMTP id w25mr36762036pfi.240.1556468814096; Sun, 28 Apr 2019 09:26:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556468814; cv=none; d=google.com; s=arc-20160816; b=ZOhXPZSPvYLIDV5Dqv2YIxPt/OUwqfCCEI2fsK6lDRP22PX7pMmikUH1Nt2sOBqa1y Rz0GvGjznWUPD4wamK+F2LnRlhAlU9mSAhuVuqQotOn8W2nCXw09vhAorPkx/c+yZzJv np377osjXkILO/p/zRpBVlgtdbDTiffDFDF0J1tZNBIHlyQmR0E5JCul+mv+UlrGtxTy zu4RVSqAaqb8MH2w7X+5nGsNRPWfbGU1EZ3J1vsuXYnrSAnamVBTIyEz2tmxA4X4E3qf r5eme56N1+SVc/T0KrTP9B0vVaN+3HfWG7ZmVJnKdiPkxMOPpCDSw1M0b3HihrGOPmmo TR1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=8ZmCMOfYCwhmlu6N65rshnyAhorSqstsHKWcORDHWkU=; b=xoxImdj3y94kKI7rgdL+yeyDG7WaVypj6NDTFXwYwg5TMw3vWTyEyPPDYcYXPjEdM+ nPrMHZoSu6tUgXXxnK3EbQtgjaftfn0n32JOgVnZXAjSw875FdiCc373go2ecKSIZgSr PEsNuVK2Qtafj+mbFNgNoKhTfWkSkU9tLxg0A6lu41viFR+VLbUZhkRzdI1CM54yiP4d Ki4MTRE7dL8pnPgEgIAdvKe+mlUJvQSIQ37w43ahEBrMyRy7vY1QcdZgSwBO3Enma13k XktNCOi/GuQsnW639/olIz0tDxA7p/2FaAyhgWgzIHwzzk4q5+5lXk44d+y8uuldZ54w b0mg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r124si29030645pgr.201.2019.04.28.09.26.37; Sun, 28 Apr 2019 09:26:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726933AbfD1QYP (ORCPT + 99 others); Sun, 28 Apr 2019 12:24:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35860 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726674AbfD1QYO (ORCPT ); Sun, 28 Apr 2019 12:24:14 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 89F6A13BF43; Sun, 28 Apr 2019 16:24:13 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.43.17.159]) by smtp.corp.redhat.com (Postfix) with SMTP id 837F268729; Sun, 28 Apr 2019 16:24:07 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Sun, 28 Apr 2019 18:24:12 +0200 (CEST) Date: Sun, 28 Apr 2019 18:24:06 +0200 From: Oleg Nesterov To: Christian Brauner Cc: "Joel Fernandes (Google)" , linux-kernel@vger.kernel.org, luto@amacapital.net, rostedt@goodmis.org, dancol@google.com, sspatil@google.com, jannh@google.com, surenb@google.com, timmurray@google.com, Jonathan Kowalski , torvalds@linux-foundation.org, kernel-team@android.com, Andrew Morton , Arnd Bergmann , "Eric W. Biederman" , Greg Kroah-Hartman , Ingo Molnar , Jann Horn , linux-kselftest@vger.kernel.org, Michal Hocko , "Peter Zijlstra (Intel)" , Serge Hallyn , Shuah Khan , Stephen Rothwell , Thomas Gleixner , Tycho Andersen , viro@zeniv.linux.org.uk, linux-api@vger.kernel.org Subject: Re: [PATCH v1 1/2] Add polling support to pidfd Message-ID: <20190428162405.GA6757@redhat.com> References: <20190425190010.46489-1-joel@joelfernandes.org> <20190425222359.sqhboc4x4daznr6r@brauner.io> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190425222359.sqhboc4x4daznr6r@brauner.io> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Sun, 28 Apr 2019 16:24:14 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Thanks for cc'ing me... On 04/26, Christian Brauner wrote: > > On Thu, Apr 25, 2019 at 03:00:09PM -0400, Joel Fernandes (Google) wrote: > > +static unsigned int pidfd_poll(struct file *file, struct poll_table_struct *pts) > > +{ > > + struct task_struct *task; > > + struct pid *pid; > > + int poll_flags = 0; > > + > > + /* > > + * 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); > > + pid = file->private_data; > > + task = pid_task(pid, PIDTYPE_PID); > > + WARN_ON_ONCE(task && !thread_group_leader(task)); > > + > > + if (!task || (task->exit_state && thread_group_empty(task))) > > + poll_flags = POLLIN | POLLRDNORM; Joel, I still can't understand why do we need tasklist... and I don't really understand the comment. The code looks as if you are trying to avoid poll_wait(), but this would be strange. OK, why can't pidfd_poll() do poll_wait(file, &pid->wait_pidfd, pts); rcu_read_lock(); task = pid_task(pid, PIDTYPE_PID); if (!task || task->exit_state && thread_group_empty(task)) poll_flags = POLLIN | ...; rcu_read_unlock(); return poll_flags; ? > > +static void do_notify_pidfd(struct task_struct *task) > > Maybe a short command that this helper can only be called when we know > that task is a thread-group leader wouldn't hurt so there's no confusion > later. Not really. If the task is traced, do_notify_parent() (and thus do_notify_pidfd()) can be called to notify the debugger even if the task is not a leader and/or if it is not the last thread. The latter means a spurious wakeup for pidfd_poll(). > > +{ > > + struct pid *pid; > > + > > + lockdep_assert_held(&tasklist_lock); > > + > > + pid = get_task_pid(task, PIDTYPE_PID); > > + wake_up_all(&pid->wait_pidfd); > > + put_pid(pid); Why get/put? Oleg.