Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp868101yba; Thu, 18 Apr 2019 10:54:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqxqfwa2evBskdV+judPBJx1JD+ImJ1NqItTnCsMbraPlanPrE2SZMIlXldt/39qihv1EFmR X-Received: by 2002:a63:6f0a:: with SMTP id k10mr88229159pgc.78.1555610099356; Thu, 18 Apr 2019 10:54:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555610099; cv=none; d=google.com; s=arc-20160816; b=D6eYijKcX1HZ5HeKHK83L88aCIJm6HbIEDZGPmozPPJhVI4amWNOwFtCIMgZPFkp8L rwlUmAFOpoU/Kq95vJbKJK286kW0L2SjJqKtoyYj0178jxJa5vqjV30+L9JzlHN1ZKXr h27oY7YUufjh3TwNQLUB7vZVl4p5cLyujbu1zrDN2G2x9+A7huGVN7UmAp8KpJ1cS8Ux uS3/xySLnJCdnXIcbSJlHwwuOkmK0NC0hwxIFduQUjbr/xgrfRi1y+Evp5x8p5zLzrMk GY2rf34CpjD3Q3RxfD1tEjGBEJa6axRXEzB/ysLIJCthxM3WIsEtdsZ/I3hxdCmWC372 hGTQ== 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=+aCB51wSzBRb+g6w79GERBDmxHkdK0m0brStvsO0x24=; b=EHGktXKp56on/mU1bCVpkXOdLqVU7n514yO32YPsHNrQHR9TYpfpOry8w/OXW2eH5I qNRQXzBi9PmXnIxCwCcUZ2piyqqKOYRp+8Lx0PYSXL/Z16nR+zVCkRYyQZtFew9iAqID Or3vGXxVIvdAePx8N7oO6bg52iYlos9AIT1LjSWWdo0+B8rASBB31OEyJCNI+/fvFofU fwzT8n9MSmCgU5cHam0hfuWi3+NGKDSb3LinatAsCC52ag66PRhMukzuDbHUhbVHkTiv GESIhI0pWn8sQTqXZBgoLaOZeqsrPu0LfFY1BKBOXIkCvkTRkJOT4iiidRDbPIb49QCz 09yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=SVcgtSBL; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s14si2432078pgs.343.2019.04.18.10.54.43; Thu, 18 Apr 2019 10:54:59 -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=@google.com header.s=20161025 header.b=SVcgtSBL; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389754AbfDRRxr (ORCPT + 99 others); Thu, 18 Apr 2019 13:53:47 -0400 Received: from mail-vs1-f65.google.com ([209.85.217.65]:42528 "EHLO mail-vs1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388716AbfDRRxq (ORCPT ); Thu, 18 Apr 2019 13:53:46 -0400 Received: by mail-vs1-f65.google.com with SMTP id f15so1619125vsk.9 for ; Thu, 18 Apr 2019 10:53:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=+aCB51wSzBRb+g6w79GERBDmxHkdK0m0brStvsO0x24=; b=SVcgtSBLmc2xM0J5DquLhMFb3hyfz4jZTgTJA9db/Q8DtxuxUWeCly6ndSd7MftMTo QSxPEAq4uZJkuDwesNVjJGjqmFdzN6buw4++xszB5VkqtCrdrpX9PieeYFgpI96cXT45 KXQIMoPCG8r/4kLJ+982MtD6FxhXq+tNQPbV781ZYkeXwRkVr0ysQEwRPekTwrcD5x07 SG5s+UWiaynVqfgkx5W66M0NiitSqBM7uZmj/7Dhv6noOVotqh8WVRNN+ThVMo065w6T ljotwg4tXAZEcg+fOmJM3yf8jBBMUVSb1ZU/FGvZVS62zlKzO3C3t/uYTBoME2J/VhkP YkFg== 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=+aCB51wSzBRb+g6w79GERBDmxHkdK0m0brStvsO0x24=; b=lg4ZSI8beqgPrJDT1wSqpu9hs/X6E++ujitXmersWAInDROOiGZcXAt2Ea6/airxpr kbMo/NLBtPuCHn3LTdXk6H0iDqIKbZIOMLuzikKCiPUuomPLsjpAoLfuTzQjkbSaYEHh TXASNxbStoWl0rSWPVFl/CUrSdC/oBzOKDagPnROP4FVRa16IWtwJEYPiSQ7UW6avUJA tcmdRqYWCkKCgeIqYvT/GoWFIsoACGP/LJuSG7vX2gzAuGVXS/5BJbg93m4/Kd6Q4RVa Gu36ZsVOPj9k1iLogRWxWVbmiJPLRTq0/n3NhL0NWDrJhfGErr8dLo8nVd9A+vlDopT1 FhoQ== X-Gm-Message-State: APjAAAXkNRPQl6ybP1oE6/bJmr1sjw+YJQMToE6i55msJxVRD6Y4VBLU mkBv8Wc1fZw9t5lUnKUHR453Cximf38Zo3fq+F+b5Q== X-Received: by 2002:a05:6102:18d:: with SMTP id r13mr55413741vsq.171.1555610025262; Thu, 18 Apr 2019 10:53:45 -0700 (PDT) MIME-Version: 1.0 References: <20190411175043.31207-1-joel@joelfernandes.org> <20190416120430.GA15437@redhat.com> <20190416192051.GA184889@google.com> <20190417130940.GC32622@redhat.com> In-Reply-To: From: Daniel Colascione Date: Thu, 18 Apr 2019 10:53:33 -0700 Message-ID: Subject: Re: [PATCH RFC 1/2] Add polling support to pidfd To: Christian Brauner Cc: Jann Horn , Oleg Nesterov , Joel Fernandes , Florian Weimer , kernel list , Andy Lutomirski , Steven Rostedt , Suren Baghdasaryan , Linus Torvalds , Alexey Dobriyan , Al Viro , Andrei Vagin , Andrew Morton , Arnd Bergmann , "Eric W. Biederman" , Kees Cook , linux-fsdevel , "open list:KERNEL SELFTEST FRAMEWORK" , Michal Hocko , Nadav Amit , Serge Hallyn , Shuah Khan , Stephen Rothwell , Taehee Yoo , Tejun Heo , Thomas Gleixner , kernel-team , 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 Thu, Apr 18, 2019 at 10:26 AM Christian Brauner wrote: > > On April 18, 2019 7:23:38 PM GMT+02:00, Jann Horn wrote: > >On Wed, Apr 17, 2019 at 3:09 PM Oleg Nesterov wrote: > >> On 04/16, Joel Fernandes wrote: > >> > On Tue, Apr 16, 2019 at 02:04:31PM +0200, Oleg Nesterov wrote: > >> > > > >> > > 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. > >> > >> IOW, when the whole thread group exits, so it can't be used to > >monitor sub-threads. > >> > >> just in case... speaking of this patch it doesn't modify > >proc_tid_base_operations, > >> so you can't poll("/proc/sub-thread-tid") anyway, but iiuc you are > >going to use > >> the anonymous file returned by CLONE_PIDFD ? > > > >I don't think procfs works that way. /proc/sub-thread-tid has > >proc_tgid_base_operations despite not being a thread group leader. Huh. That seems very weird. Is that too late to change now? It feels like a bug. > >(Yes, that's kinda weird.) AFAICS the WARN_ON_ONCE() in this code can > >be hit trivially, and then the code will misbehave. > > > >@Joel: I think you'll have to either rewrite this to explicitly bail > >out if you're dealing with a thread group leader If you're _not_ dealing with a leader, right? > , or make the code > >work for threads, too. > The latter case probably being preferred if this API is supposed to be useable for thread management in userspace. IMHO, focusing on the thread group case for now might be best. We can always support thread management in future work. Besides: I'm not sure that we need kernel support for thread monitoring. Can't libc provide a pollable FD for a thread internally? libc can always run code just before thread exit, and it can wake a signalfd at that point. Directly terminating individual threads without going through userland is something that breaks the process anyway: it's legal and normal to SIGKILL a process a whole, but if an individual thread terminates without going through libc, the process is likely going to be fatally broken anyway. (What if it's holding the heap lock?) I know that in some tools want to wait for termination of individual threads in an external monitored process, but couldn't these tools cooperate with libc to get these per-thread eventfds? Is there a use case I'm missing?