Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp752065pxa; Tue, 11 Aug 2020 14:15:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyc9cTZ3Jo9tb7xRMhR54yVK4+6/sjIRG+D+n3vUyBb9hpYMUQUcYg9oDfta5lzwvdDNBZT X-Received: by 2002:a05:6402:3113:: with SMTP id dc19mr26393735edb.280.1597180506528; Tue, 11 Aug 2020 14:15:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597180506; cv=none; d=google.com; s=arc-20160816; b=HMbE8vSeFzL0ZDcSKkQo3YFz/LCkkKe3bP7cJcZyyw8k2gDPaR+CRYrVJ8H8Sn3kD8 /WpsGtJP6uBZONS9qgEa5+XTlyLBmLaZIcSxk4msdoVNSB5VPX+Odwx3HjVhLtFt5jTF m2okNhzGQzINFZVpCABPX1Mx/yujT2MExQLpgoxM+igywEbj/A1GdEBDRTEJTUuOIo6z Pjkh7jZZnI2AITLl16+BhlxY7MQ+bkOUuYGAqjwcLMKp41pfIGiIYMVQ3HI/u//3MDP/ 8H1MfLuglruERI4CoWzKpEBm2yFb2Q12KBOYNVV51iLkFkYKvWQ/g/TCwm6AxB9QEO/u lJQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=nFH7+Tcy5gtRGAVx+M+dnbOMU/G1ObtFwVSkLEZVv2g=; b=0wiqqSHTRg38DFp9TlzvtKYrakF82rFUpFOU0Irq/W9KheU22pwREfrTtKtY8l07lm MqZlc9oWA/LyXZJrZxG20eWpc6r+5y/ePLoZrCHuq0s7YB7SRD3KJizRxkWRnFKdFCG6 8SeaGPaiRk1NJIGPuGH30Y6krHYP4EUCCxBjOIhVkchq/hYl+wN4FV4VUfvn0/yt0OpU 5d8J48vsbbC4KlaDsH3+6lWhDnHIY1QK246zqoNFZz//KBwVD8dTzMzEB6sbijd3i9Ce tUrIuDD0/ADg+bgame51H7vlhqFWYJLyO5j5whmw+oD3sf+nP6PtsHE8+Vbgvru2ZOb+ +RyQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q21si13064704edg.71.2020.08.11.14.14.43; Tue, 11 Aug 2020 14:15:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726271AbgHKVOF (ORCPT + 99 others); Tue, 11 Aug 2020 17:14:05 -0400 Received: from relay6-d.mail.gandi.net ([217.70.183.198]:33687 "EHLO relay6-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725987AbgHKVOF (ORCPT ); Tue, 11 Aug 2020 17:14:05 -0400 X-Originating-IP: 50.39.163.217 Received: from localhost (50-39-163-217.bvtn.or.frontiernet.net [50.39.163.217]) (Authenticated sender: josh@joshtriplett.org) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id DF780C0003; Tue, 11 Aug 2020 21:14:00 +0000 (UTC) Date: Tue, 11 Aug 2020 14:13:58 -0700 From: Josh Triplett To: Christian Brauner Cc: linux-kernel@vger.kernel.org, Christian Brauner , Jens Axboe , Michael Kerrisk , linux-doc@vger.kernel.org Subject: Re: pidfd and O_NONBLOCK Message-ID: <20200811211358.GA24721@localhost> References: <20200811181236.GA18763@localhost> <20200811201045.jw2bc3yegrgrvnpz@wittgenstein> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200811201045.jw2bc3yegrgrvnpz@wittgenstein> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 11, 2020 at 10:10:45PM +0200, Christian Brauner wrote: > On Tue, Aug 11, 2020 at 11:12:36AM -0700, Josh Triplett wrote: > > As far as I can tell, O_NONBLOCK has no effect on a pidfd. When calling > > waitid on a pidfd for a running process, it always blocks unless you > > provide WNOHANG. > > > > I don't think anything depends on that behavior. Would it be possible to > > make O_NONBLOCK on a pidfd cause waitid on a running process to return > > EWOULDBLOCK? > > > > This would make it easier to use pidfd in some non-blocking event loops. > > Hey Josh, > > Just to see I did a _horrible_ draft (cf. [1]) and it seems doable to me > and if you can provide a good rationale and a use-case then I think that > would be ok. Rationale and use case: there are some non-blocking event loop libraries, such as the Rust async-io library, that help build epoll-based event loops around file descriptors. Those libraries automatically set O_NONBLOCK on the file descriptors they manage, and they treat EWOULDBLOCK errno codes specially, with semantics like "call this function, if it returns EWOULDBLOCK then don't call it again until epoll says the fd is ready". If setting O_NONBLOCK on pidfd caused waitid to return EWOULDBLOCK, such libraries would Just Work with very little effort. Also, pidfd_open should accept O_NONBLOCK as a flag, which in addition to saving a call to fcntl would allow userspace to detect if this works. (Even if you want to use fcntl to set it later, you can always just open your own PID with pidfd_open and check if you get EINVAL to know that your kernel doesn't support this.) Thanks, Josh Triplett