Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp917274yba; Thu, 18 Apr 2019 11:45:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqxqyuwwOe+OG6pI6ziXyZSDCIfusAx9cokdTS+Vkmjx9YWZPLoeOGJdHD8kxpdKaJVAmJsx X-Received: by 2002:a62:47d0:: with SMTP id p77mr97837001pfi.95.1555613155998; Thu, 18 Apr 2019 11:45:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555613155; cv=none; d=google.com; s=arc-20160816; b=g6EKKk3Sl2jhUZlSTa+9WCVnvl7BpfS1mOW/2hK17uV+TnymstE65uE5H6WovOl9rB 0LpUt3frSOlFXOWkNamgbuH+pL8ZqedjKUB1k9pLA0X00Llsu9cSDc/voH+vqHViGb/O y74TtiO0uFvlHuLkFmb41O479xtRqcgabwyPNP4zlKcjAOG8pa4HMhCVNoVoKfNsdv+u xNrWVlCfueIAUsUGiPd/tcnFFL8Z23ZnlLXLnP7DZDVFFhKAptBXOzCuhjeaba6Xeio1 dTv2dL0O4PJWD4NCjRhu9qyDDOBoPfgz2ciTWj8OFm8BFLSR1UmEe5T+fBsRBARSsPaZ c83g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=JgKBWPZ5JhFFELhiC1+JLERcaxYfxu/FE7mY6DY8noc=; b=oYtFvqg/NLmAXFxe46XkS+bR8RajoFv7UJ0+nN0Q6ZvphhZovY7qip/cI920hSKnQJ YzD3GWYk+/rna4MnXt2s2XoHCCan1f5XskfVpTLDdEEPX8Z87UPGpyAWbotQbi9NbSIu NooupYiccUes5lEclAE3ESKG5UNwxxLEG3DHERtbhVL+LQLU8PQO/yOkiqPFv0MTDfY3 yRflPhGLpGq1y61hKolBy7ojSA4Lh5T6CJ2ooaVUhAd+9NYT3LIQWwt6J2lURUQAeFrZ 3sI2gSRXPRvdrfR2vIwo30hev3/R+NI6muba+2Lf0vIyWwa29PodG7EIEfsr14Oe2p3o FYsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=IikLogst; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m7si2519637pgb.374.2019.04.18.11.45.40; Thu, 18 Apr 2019 11:45:55 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=IikLogst; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390089AbfDRSog (ORCPT + 99 others); Thu, 18 Apr 2019 14:44:36 -0400 Received: from mail-lf1-f66.google.com ([209.85.167.66]:37331 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389868AbfDRSoe (ORCPT ); Thu, 18 Apr 2019 14:44:34 -0400 Received: by mail-lf1-f66.google.com with SMTP id o19so2383099lfl.4; Thu, 18 Apr 2019 11:44:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=JgKBWPZ5JhFFELhiC1+JLERcaxYfxu/FE7mY6DY8noc=; b=IikLogstHoyVLau0GkUESJoPGDXUaPFxuAdUrnwVA1Fpq90xXDTJpBPxax7RFBrg6p ZJdNC0NBuzOjRhTeoNkyUTNKN26wE/6pARrAYXHxIERElle7EdhVBRtu118kUHQcXEKZ 85VoXC71bOMPflMyq4iEaZ/f0dze0XarWJu1CuVnhrwG8sZi/H/oiPbg65HHTRKCTGOj lR1mBIMt248ioBKuaBnpSqhirMtgdQPM2zEsjB0zwZJOCKivGdev05fCgjs2jbGGsEsk VYThSxJraQTKMWo73+sQnlSR/bkZ9jb6VhUs6qynfRAg0ggODiwOBKBP/X4n0jae2vPh AWYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=JgKBWPZ5JhFFELhiC1+JLERcaxYfxu/FE7mY6DY8noc=; b=NxTNhGHaukpEh+VJAxpG4vLbHrwzPseVLBhYhdh+FJ6+UAuhjaEPRihVSMNgq4kwDf tPi5yhOcqIGKb8GnjDFQb+vuuIVUvOKjrkZl/DA02H1YmLEH6fLouS2VmphAIHKFZeU1 vAjYBl2jieeX0LsB1ndcepKo6mhmUn31k+hAuj3Ldq1A75a7E/ABAxw9V9gfp3M/Et2k NOw+LYsoDxHqtrKekMjWQbIUHGbJIhrbKOJegLXZJNHPgN35DlzLmcCCSVKEN3pwE68l 34+xxCo7hpSnq9PlSR1RB46uIxyPEFl1TYaVhF23mKohFMBEETxS/sTaPqnuPMjkyn6Q mnNQ== X-Gm-Message-State: APjAAAV/juWbvAI95rBBQXihKPGiUFskuf2hfv3Xg/Gpa0VWm1TRnafp YkCcYAgB552rP+Y4YFH8OMs4+I5uxRwIQUFTF+4= X-Received: by 2002:a19:c113:: with SMTP id r19mr4161282lff.64.1555613072231; Thu, 18 Apr 2019 11:44:32 -0700 (PDT) MIME-Version: 1.0 References: <20190411175043.31207-1-joel@joelfernandes.org> <20190416120430.GA15437@redhat.com> <20190416192051.GA184889@google.com> In-Reply-To: <20190416192051.GA184889@google.com> From: Jonathan Kowalski Date: Thu, 18 Apr 2019 19:44:33 +0100 Message-ID: Subject: Re: [PATCH RFC 1/2] Add polling support to pidfd To: Joel Fernandes Cc: Oleg Nesterov , linux-kernel , Andy Lutomirski , rostedt@goodmis.org, Daniel Colascione , Christian Brauner , Jann Horn , surenb@google.com, Linus Torvalds , 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 , kernel-team@android.com, Tycho Andersen Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 16, 2019 at 8:21 PM Joel Fernandes wrote: > > On Tue, Apr 16, 2019 at 02:04:31PM +0200, Oleg Nesterov wrote: > > 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? > > It returns POLLIN when the task is dead or doesn't exist anymore, or when it > is in a zombie state and there's no other thread in the thread group. > Would using something other than POLLIN be an option (maybe POLLPRI)? The convention is to use it to indicate readability on the descriptor, and also possibly POLLHUP instead of POLLERR (the latter is less of a problem, but FreeBSD also does the same, so it'd help with some consistency for libraries wanting to use this, which aren't interested in other sub states). > > - Joel >