Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4829407yba; Tue, 30 Apr 2019 05:10:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqz16Hbbg15sajUWceJDyIKYqcXk+vJz7COAIkIdWpQ7eKn+1oWM/HKJLiY1Typzou358sAD X-Received: by 2002:a63:cd50:: with SMTP id a16mr46351740pgj.394.1556626246994; Tue, 30 Apr 2019 05:10:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556626246; cv=none; d=google.com; s=arc-20160816; b=uQUvHXKF6MUS0B+Cg5Uxo8g8XjJC8x6AHX/9JcEW1Zp2eM0fH4h3lzjabNQJJEvy2d rlqU8RB5w23o2NreoWZbG2+nZWmZ14tMrwJL5C9V8MQVSZYRUsoTVMc+A3c/uiu1Eod5 OpDhRhVVxpmTERSQCa5gE2EAL5M0XFUbHhjwC8pXe1dC302stqgxBj6foKyPI4KfOo8A qBvyzhRbvG/h3I6fvwx6bWeEA33I7pPyo9+K62daFTsrOlDSpx+FDwd2WShU27FomMdB 7OnXnAKFJOvutLfCG7eqcEciflTgp+0M3HyUK4YfgmasEtHxp/uX151ZEu1rZ5ji3KrK Y/kg== 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=C/7YhCX2HIzSscE5rUgY337I77G7Gh8eWAaLP4A/fEk=; b=M4SOO+1Vxv0gLKGnPWolVodxHXbjg/Oam2l+FryN4kmFNqZA2sxx1cTWhcVgE/cLLQ IE8mxdiiQTwNeECNigDzFs705hD8nlPEXCnQeLSDZjkyuVJyafbz3i1rWULZSXAB7FGg ffI25h9UEsOCdvhy4TbMubbV0oq+KHQ7Pw174/vAZQFIX7GXuQPwkP0Oxe3x8kkIBacy gvHtbVWzCQXDiunWtiqG36wh8Dfzn3pHDbqBJ+fT+zBprwyjaCSOS07soIHKWF+lnRho KB9WDxG+kSLz8s6yEiMQGCVa1mjVmiG/znxoxBLPz3Ddwa/rTDBpZ5B/fgOML9uzVf3v WPOA== 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 q24si16673247pll.181.2019.04.30.05.10.29; Tue, 30 Apr 2019 05:10:46 -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 S1727659AbfD3MIQ (ORCPT + 99 others); Tue, 30 Apr 2019 08:08:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55442 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727341AbfD3MIO (ORCPT ); Tue, 30 Apr 2019 08:08:14 -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 6704930018C2; Tue, 30 Apr 2019 12:08: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 1FDDE78DEC; Tue, 30 Apr 2019 12:08:01 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Tue, 30 Apr 2019 14:08:11 +0200 (CEST) Date: Tue, 30 Apr 2019 14:07:59 +0200 From: Oleg Nesterov To: Joel Fernandes Cc: Christian Brauner , 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: <20190430120759.GC23020@redhat.com> References: <20190425190010.46489-1-joel@joelfernandes.org> <20190425222359.sqhboc4x4daznr6r@brauner.io> <20190428162405.GA6757@redhat.com> <20190429140245.GB233442@google.com> <20190429142030.GA17715@redhat.com> <20190429163259.GA201155@google.com> <20190430115332.GB23020@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190430115332.GB23020@redhat.com> 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.46]); Tue, 30 Apr 2019 12:08:14 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 04/30, Oleg Nesterov wrote: > > > > pidfd_poll() can race with the exiting task, miss exit_code != 0, and return > > > zero. However, do_poll() won't block after that and pidfd_poll() will be called > > > again. > > > > Here also I didn't follow what you mean. If exit_code is read as 0 in > > pidfd_poll(), then in do_poll() the count will be 0 and it will block in > > poll_schedule_timeout(). Right? > > No. Please note the pwq->triggered check and please read __pollwake(). > > But if you want to understand this you can forget about poll/select. It is > a bit complicated, in particular because it has to do set_current_state() > right before schedule() and thus it plays games with pwq->triggered. But in > essence this doesn't differ too much from the plain wait_event-like code > (although you can also look at wait_woken/woken_wake_function). > > If remove_wait_queue() could happem before wake_up_all() (like in your pseudo- > code above), then pidfd_poll() or any other ->poll() method could miss _both_ > the condition and wakeup. But sys_poll() doesn't do this, so it is fine to miss > the condition and rely on wake_up_all() which ensures we won't block and the > next iteration must see condition == T. Oh, just in case... If it is not clear, of course I am talking about the case when wake_up_call() was already called when we check the condition. Otherwise everything is simple. Oleg.