Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp4394732pxb; Wed, 20 Apr 2022 02:11:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwvsGFpD2F4ncjYWf7f/jsywr4qwnuBvX7TtJN0Ret24f6Uhg9NA0rLRWLxqYWgNWBiGc99 X-Received: by 2002:a05:6a00:2284:b0:50a:40b8:28ff with SMTP id f4-20020a056a00228400b0050a40b828ffmr22525133pfe.17.1650445888969; Wed, 20 Apr 2022 02:11:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650445888; cv=none; d=google.com; s=arc-20160816; b=QSMKMg1Eae+njv05PcLnwMAwf9re8w1liNubbGvWSSQCTfRuoLNj4885FsYVNmvta/ Uojzk8Rzi5a6dcXJfHyBJvzAHGCQrzOiUh84GyCUrkx4EKgQvM0ZVOm2s/xC9S7H6obj a3C4gO344A9kP/TcCtRUyznOWecSH2Yv2qLhzH+GJUGtogj+68Y4h0RMZWScTNQ0H0QN QzfJUkuojbhFLAuEk905WsZH5BbeAvxW6OtOYpYfaU1WXxXaRIJPfrg4qY11mdzn8j0v HCfycssgzieXALrkA5M+x41vTLJ4kmoYps58PnoQMZRM/pIMa1iQAchQu+7Z2FPYVlNL fGYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=sCKh9fKeNxfMXh4t1jTd2sRlnMvxlUGBQPDbUNeNRpQ=; b=szGMDRA1YKWh5d+D1XQqbGSBaJPyUKXDR4Rtr+gmLLt5TpT89vZOMHoXuuPU4+/vNP 3ILR8av/wyZCbFK08c0jmR1+L8pBRmAUKmZggypAqkRdkKkyCjn95slhHraDdmohwUV+ Y5jqQqLJ9CWOUHTGZhkY4Z9Pi9AZfvLHRKNAYMsBaUhWHbcZ/a1D+TJ6sLmeiuNEkXhS E0hkaHwGFl1UKTWNoGde1fXM6tncoIZuC/nVbeH8Y4XWGRTHSreb3gJGSKdL95NU1KrC aLKB7RMj/oA7fkiu8nZA7FzF/D51N7dZL9OrRpgMa1sMew/IgCG6U8UPj0pSDlaUAwzO E2Ww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=HY8JOZ6i; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u42-20020a056a0009aa00b0050a952467b5si1732472pfg.338.2022.04.20.02.11.14; Wed, 20 Apr 2022 02:11:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=HY8JOZ6i; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S1356094AbiDSTrz (ORCPT + 99 others); Tue, 19 Apr 2022 15:47:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356090AbiDSTry (ORCPT ); Tue, 19 Apr 2022 15:47:54 -0400 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36DE011A35 for ; Tue, 19 Apr 2022 12:45:10 -0700 (PDT) Received: by mail-lf1-x133.google.com with SMTP id p10so31210778lfa.12 for ; Tue, 19 Apr 2022 12:45:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=sCKh9fKeNxfMXh4t1jTd2sRlnMvxlUGBQPDbUNeNRpQ=; b=HY8JOZ6iIKeHPspSmy2AgIRVE6CChfYXGxFCFhD41hKaTAIWq4QhUfdBoczr10gI8p rMAqOIhNxaIhPX5LGuCmeCKjXeW78TC+QX0KSoITDShfpmJNCAac3goF6R9nCxYdqK9P jiF0BvDBaJ+1dHWEucNx9JJxLHYivAoTSdPA1ZH4fs91Ib5qa3hVCAFktYtevFJHu/ZP MGiXoTVsqxMyMvbUvEnTOsFSs78L0r9z+hUUfHQpnT7MEm2NKvjyCr7EOUhJXaaVklPY 2zl18NTmr+9s1aVO3YyrTFMQ1NoqpoiWv9ZIDnpxoqaeNoEyhDR8e/jNTTFXDRh1+ul9 Lnog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=sCKh9fKeNxfMXh4t1jTd2sRlnMvxlUGBQPDbUNeNRpQ=; b=Bl69z42IcCyeGc0ZTPDliEHrZYeByzpDGrFhVf1hTOisMrxqgj9O9ybJkWo/uu86Wu YCN1toisRa1WSDGGxPx+jyl6z+1gX6b314l46+ci5OuRRI81Dhggwzfn9E+9+FrPFP0I uv+qPwMn/gIwQcdpP5r0NaAHBlaxOLDAFQ7c4bj1U4DzQQbz9SyDw0IKHLSKptGySx25 T0psATDlwvuMBrh84tX//vK8Xx0etDBQ51pLfLnf6X0lm9XUIacxoY25DOIKheyo47Dz 5WHL/wym5S1RKfmomGljYmUtPxbeNPpJCjE26ul2gMZalbZtNkt687Hf8x5XfyMlQsK3 LIcw== X-Gm-Message-State: AOAM531KHmvWXZCYgQ9YiN3zF4WQOECnNkY4LJHYXQPN+LeNGzgb3BTV +hlmxTUUke7KV2pemkmoHIvb5kIBscvL1ZJG3fNYWA== X-Received: by 2002:a05:6512:1322:b0:44b:75d:ac8 with SMTP id x34-20020a056512132200b0044b075d0ac8mr11627642lfu.213.1650397508242; Tue, 19 Apr 2022 12:45:08 -0700 (PDT) MIME-Version: 1.0 References: <20220419160407.1740458-1-Jason@zx2c4.com> In-Reply-To: From: Jann Horn Date: Tue, 19 Apr 2022 21:44:31 +0200 Message-ID: Subject: Re: [PATCH] random: add fork_event sysctl for polling VM forks To: "Jason A. Donenfeld" Cc: LKML , Linux Crypto Mailing List , Alexander Graf , Dominik Brodowski , Greg Kroah-Hartman , "Theodore Ts'o" , Colm MacCarthaigh Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 19, 2022 at 6:42 PM Jason A. Donenfeld wrote: > Hey Jann, > > On Tue, Apr 19, 2022 at 6:38 PM Jann Horn wrote: > > This is a bit of a weird API, because normally .poll is supposed to be > > level-triggered rather than edge-triggered... and AFAIK things like > > epoll also kinda assume that ->poll() doesn't modify state (but that > > only _really_ matters in weird cases). But at the same time, it looks > > like the existing proc_sys_poll() already goes against that? So I > > don't know what the right thing to do there is... > > Doesn't the level vs edge distinction apply to POLLIN/POLLOUT events? I don't see why it would be limited to that. > In this case, the event generated is actually POLLERR. On one hand, > this is sort of weird. On the other hand, it perhaps makes sense, > since nothing changes respect to its readability/writeability. And it > also happens to be how the sysctl poll() infrastructure was designed; > I didn't need to change anything for this behavior, and it comes as a > result of this rather trivial commit only. Looking at where else it's > used, it appears to be the intended use case for changes to > hostname/domainname. So while it's unusual, it also appears to be the > usual way that sysctl poll() works. So perhaps we're quite lucky here > in that sysctl poll() winds up being the correct interface for what we > want? AFAIK this also means that if you make an epoll watch for /proc/sys/kernel/random/fork_event, and then call poll() *on the epoll fd* for some reason, that will probably already consume the event; and if you then try to actually receive the epoll event via epoll_wait(), it'll already be gone (because epoll tries to re-poll the "ready" files to figure out what state those files are at now). Similarly if you try to create an epoll watch for an FD that already has an event pending: Installing the watch will call the ->poll handler once, resetting the file's state, and the following epoll_wait() will call ->poll again and think the event is already gone. See the call paths to vfs_poll() in fs/eventpoll.c. Maybe we don't care about such exotic usage, and are willing to accept the UAPI inconsistency and slight epoll breakage of plumbing edge-triggered polling through APIs designed for level-triggered polling. IDK.