Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp757971ybz; Wed, 15 Apr 2020 18:18:13 -0700 (PDT) X-Google-Smtp-Source: APiQypIkGdDcaCYZUH0kD8NIPlaucH/5KPLYHgIm111N0QdgXRSAVnf6NzDUizP/YfPSsKo73Dlh X-Received: by 2002:a05:6402:1b0b:: with SMTP id by11mr8807276edb.269.1586999893183; Wed, 15 Apr 2020 18:18:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586999893; cv=none; d=google.com; s=arc-20160816; b=GETWGIg0iZYoTwdBad6ep/qyCwyUWXk8figAuB4a59hzvFNhAClExfVsiVJpJG4pOS Hj3EGxIuyfIwL9CQFXWbCXJHzK92Y2b5DjDxHX9abuWIw9FDJDXQ64ch9k/F4suNecIh OqLWzp7s0JJ64uZQ8prnOUW0zz6s/0jPTgS4uh8Zkx0MN1Lwh8e7nBgSQxxwcBTuXS/k h//5obnv0ywxZcEZn3A0sYUrhCsN0HNMHWoS5i7/zc89pbmpQ+E26c1EdaLgulvWxlaK rE66F7Tvj1XVueeXxa089ZwEYOsg0M9j5nwAhVMwvo0BAq/ArpSRHZfs2nxYvlSIHUTC lIaA== 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=DqhZGRoL70sm5/RzVHO716gnr2CLOKeQ+jLS9k1/y4Y=; b=bG4WREYEByAqL73ifZt/7s7aTgbdKSaXZGiYzknrHygVhjf98RqInOF0ZrIrQ2aieU W/lGquk0OhlRWdffB3exba3/JQVmAx/O31wTrWFVAV5J1ARjqZyE6Zr8DQMdu7DA6aCK xXrG9XIwrbBS/kybwUSSjVGG7Go/CIu76/FHpmkR4F0dmyHes/++MVhL5locLNXizAJF KBaGfVpaYzBqgi6uGRRN8OVViXpnx5mOp4KRpC5TCiOSk17882XI5Krc/ua0/1A3yTNH kgPXjXS/BpfFYsiWda7N9jheuYhd5rT/J2sgKH20lQRiAJR0/DCVBLNq0TmLOUDHAWls qcDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=rFyRARAR; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ce7si13038776edb.534.2020.04.15.18.17.50; Wed, 15 Apr 2020 18:18:13 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=rFyRARAR; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730515AbgDPBQw (ORCPT + 99 others); Wed, 15 Apr 2020 21:16:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725805AbgDPBQG (ORCPT ); Wed, 15 Apr 2020 21:16:06 -0400 Received: from mail-ed1-x543.google.com (mail-ed1-x543.google.com [IPv6:2a00:1450:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17460C061A0C for ; Wed, 15 Apr 2020 18:16:05 -0700 (PDT) Received: by mail-ed1-x543.google.com with SMTP id ca21so7322658edb.7 for ; Wed, 15 Apr 2020 18:16:05 -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=DqhZGRoL70sm5/RzVHO716gnr2CLOKeQ+jLS9k1/y4Y=; b=rFyRARARoNvifTie3IBinXaGw3HxWbMokaBEk9FRXHKnN2o9HQhSGjBCrKKdNUYv+q ySccDKON48Kn5CX1Hb2xKb3O+fhncJOjdCjC0t2l1Q6XCKyMahaZUP34nUWaFw0LiVI9 r3pjyTURPGWopwqma4Z6YJa5jtcZf1Bz+K56h45IUS205NJ3gScZV0yC5wQSyQ8z50l1 Gvin7IoCG734F0kcIVUghxfJXGxvt9U2omfAFExwvrNieQpeK98ioL52hWBJ5aGWexXy 3kD1KIFDI5I4GMiAAQlLfEpqutRTj6lMTdeNaJftbg1z01fnoFuiQqpeAYHnmay+F6J9 rd/g== 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=DqhZGRoL70sm5/RzVHO716gnr2CLOKeQ+jLS9k1/y4Y=; b=CJjq6EhlLT0HLSEsrwaJVWq5yMpizRBYWT+VJlLBXPhnOJ+aHYiAeXCrn1Nw6Coy4h sX55DyUoo9kLE/s51JwXWD/hrsiRl2FYsDV2/j7rtmtXEEBQASdAFx35j8SnFO2xvx1b F3urlohvbjw4fBH8CPieP6I8A39nzeaSW9lcDjKfkQ+3wOFmX2YmDg1azbopaW+lqzHn 5eRQ1O+WsR9wIMDklakczEWGGrfftDaUvKsNu9sST4M3MwnfBo1s4Guc65fa36Dq3nfv QMfLeVeWPYoDs3nDxOGOV2wnDNm8OW5vd3WWhcJTPyAMPBoH4Uzeh902dYHnPMOM0gE1 DqSw== X-Gm-Message-State: AGi0PuYayGss6YeYsJ9q5ywifVUmwNeHKhgcTlgkoEbRTsGKOH2NuBUO mzTnJgWNaWC4k8NAxd+1mSr/Wr3RQ8Zs8ZRvqSTw/A== X-Received: by 2002:a50:a9c5:: with SMTP id n63mr27903084edc.312.1586999763505; Wed, 15 Apr 2020 18:16:03 -0700 (PDT) MIME-Version: 1.0 References: <20200414214516.GA182757@xz-x1> <20200415031602.22348-1-hdanton@sina.com> <20200415142546.GO5100@ziepe.ca> <20200416000229.GA9922@redhat.com> In-Reply-To: <20200416000229.GA9922@redhat.com> From: Brian Geffon Date: Wed, 15 Apr 2020 18:15:26 -0700 Message-ID: Subject: Re: Userfaultfd doesn't seem to break out of poll on fd close To: Andrea Arcangeli Cc: Jason Gunthorpe , Hillf Danton , Peter Xu , linux-mm , LKML , Sonny Rao 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 Hi Andrea, Thanks for taking the time to reply. > static int userfaultfd_flush(struct file *file, fl_owner_t id) > { > struct userfaultfd_ctx *ctx = file->private_data; > wake_up_poll(&ctx->fd_wqh, EPOLLHUP); > } > Yes, I think that something like this would work for this situation and eventfd. > If eventfd and pipes all behave identical to uffd (they should as they > don't seem to implement flush) I'm not sure if there's good enough > justification to deviate from the default VFS behavior here. Pipes actually behave a little differently, in the case that you close the write end of the pipe the read end will break out of the poll with EPOLLHUP, but I suppose closing the read end while the read end is being polled would be more analogous to what I'm describing here. And this is why it felt weird to me, in these situations the kernel _knows_ that after the close nothing can happen on the file descriptor, so what's the point of keeping it in a poll? As soon as the poll breaks any read, write, ioctl, etc on the fd whether it's a userfaultfd or an eventfd would fail with -EBADF. And all of that I guess makes sense in the case of a non-blocking fd, but what about the case of a blocking file descriptor? Both userfaultfd and eventfd can seemingly be stuck in a read syscall with no way to break them out when the userfaultfd/eventfd has no further utility. Here is an example: https://gist.github.com/bgaff/607302d86d99ac539efca307ce2dd679 For my use case adding an eventfd on poll works well, so thank you for that suggestion. But the behavior just seemed odd to me which is why I started this thread. Thanks, Brian