Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp1220206rwp; Thu, 13 Jul 2023 07:51:48 -0700 (PDT) X-Google-Smtp-Source: APBJJlEj7NTiOdOBCsknCtwxco0uSAOdAuHgY4LMLgw2GrfuemwckZ6FfyPpPdix9/Xjb5z/9f9+ X-Received: by 2002:a05:6402:440b:b0:51f:e0f0:f2cd with SMTP id y11-20020a056402440b00b0051fe0f0f2cdmr7540245eda.3.1689259907732; Thu, 13 Jul 2023 07:51:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689259907; cv=none; d=google.com; s=arc-20160816; b=byR2F5bq4c4FMWJlNOXeA50VqTW8OY4VhUkHTK7x7nh0kwaQzdhYzOtpYHY3N8hslq mLLkzQ3Ivx2OLZTwSG44hTDQoa4t9qV6fLFb4mO/5kJ5MLN0MA/zat4UaHN4lJT4dCkh Ix8GFjzL7R6xbs/G6N6Y98C+Iu6Tqy5VYi4kCZOMC1hE7gRW2EGyVhrRmZ0hQn8T7B63 uZbTt6V/anAvNeSTIy456mQPfraw7bSxir/rWQ/dvmm1UN+lH/4MS2YrfGtuqUw7t6k2 OZc32/swYqsaw5gxTIMiAomZGxqMV41dD/iBgNS60SPDjlhzZm7yb0JTp6/c85ZWULxH yBIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=fr2vYa/Ch6xYV487nmzxcm8iM/FlpnkWVHQ5jynQTbg=; fh=6GC48uiJna3RLc1M6HmBwLHbAvHNhIVT24yNaZmH6a0=; b=Swds8xBu9a5Mbk8MG/i4hNESlVebhzBjpaFrUm6o+nwqWXKgZ2vyB6wDfWsCSIb7Jp ZbJT+QtCO5MHBKOax5U44abISzCZiBrMRPpTC6aEhYvE3YOiK7SQ/TrGdYYl9+bCzfnn ZQbUvzSL1j7z4S4chiHqCkMNTRluZDLATiCEgFJsMKTITOrJ2zmOKTpyhEAS67XJmyuq H3/2Y0ysORhv04Zi5zw6ASrkipc+i6VXSj2rRwQQXzadqerJxRdKyAzz7i/8YzcVd2tp WMJdNXuyk4p4F2XoFn9n7WNX3iobFh8Si1sK6p15HV0Kh85O+QSeYueVE1TK0ti1nZ4B vHaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=jacaK9M2; 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 k23-20020aa7d8d7000000b0051debcd957esi7616044eds.351.2023.07.13.07.51.22; Thu, 13 Jul 2023 07:51:47 -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=20221208 header.b=jacaK9M2; 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 S230456AbjGMOdL (ORCPT + 99 others); Thu, 13 Jul 2023 10:33:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230372AbjGMOdK (ORCPT ); Thu, 13 Jul 2023 10:33:10 -0400 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BC3926B5 for ; Thu, 13 Jul 2023 07:33:07 -0700 (PDT) Received: by mail-pl1-x649.google.com with SMTP id d9443c01a7336-1b8a7734734so3357655ad.2 for ; Thu, 13 Jul 2023 07:33:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689258787; x=1691850787; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=fr2vYa/Ch6xYV487nmzxcm8iM/FlpnkWVHQ5jynQTbg=; b=jacaK9M2p8ae07DYtf3WTwW4sJ88AeR0PMoTM/K8Zom80G9CNsRED8/7OkNACpL4FI vSrK+poAQrpW9b9XXAEX3N+/eJqGG0fl2uSilp/V2zhMmynFGmkNp19rQMAPCUIgro+L 8wZFnIyWuBTpd6inSk0jhwWPq/qOKDhiCmrdy2nICENUOLQPMx4zm5vkc1J+N+jf8F/9 NWijWeXBKP6nhRWfAZooF9dECtwpwP1B06LROVi+ZRGQWEPDlF+8FcWtS7IpVg38LWBC sabPszkfHQCdZSa4qO28HKir4zE3m+cUi5LtAFjCZb9xEKl25slyjVF3CoaXZrvttifT RnQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689258787; x=1691850787; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=fr2vYa/Ch6xYV487nmzxcm8iM/FlpnkWVHQ5jynQTbg=; b=QRTuNFiEFcoj5ZvYfPsnpuU+8/ZjOBJfvFHJntMfzziDxRUpyf4sCsun9FwiCj/W5W gA05Qm/GB1Q6N/LEQtVDvoGU/H/4mOh0VHUkij3k/eOGvJ8K5EKoNI8d2+0mUQk+4TVe dFrN7T6APJs0DIOOOKLXZ8x9ntpQgxEyW6OVhsrivSc36JWlQeuondcTaqw78eAMt/tl kT+v0YWRgk5BK6ZzjWOopXDJfF8DinW5J0fBwcV2exgZIgMd2/ckxenSgdf/QIoj+dlb Tb2loyhtiaqxYJmL8Eh/tmnpJwo5dlV25o5Myfe/XbQDF9FNfPZ0nZVnC2TIMukvihTj vgfg== X-Gm-Message-State: ABy/qLZxnf+aHVeJEgE7IePnHpIzt+edBTYh7baMjoqy/JL+wPEi+3Yy qBYfoj5fKL/hJNvQydzjzhn7rI4xADY= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:902:b282:b0:1ba:1704:89d1 with SMTP id u2-20020a170902b28200b001ba170489d1mr5846plr.10.1689258786828; Thu, 13 Jul 2023 07:33:06 -0700 (PDT) Date: Thu, 13 Jul 2023 07:33:05 -0700 In-Reply-To: <20230713-vfs-eventfd-signal-v1-2-7fda6c5d212b@kernel.org> Mime-Version: 1.0 References: <20230713-vfs-eventfd-signal-v1-0-7fda6c5d212b@kernel.org> <20230713-vfs-eventfd-signal-v1-2-7fda6c5d212b@kernel.org> Message-ID: Subject: Re: [PATCH 2/2] eventfd: simplify eventfd_signal_mask() From: Sean Christopherson To: Christian Brauner Cc: linux-fsdevel@vger.kernel.org, Vitaly Kuznetsov , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, David Woodhouse , Paul Durrant , Oded Gabbay , Wu Hao , Tom Rix , Moritz Fischer , Xu Yilun , Zhenyu Wang , Zhi Wang , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Daniel Vetter , Leon Romanovsky , Jason Gunthorpe , Frederic Barrat , Andrew Donnellan , Arnd Bergmann , Greg Kroah-Hartman , Eric Farman , Matthew Rosato , Halil Pasic , Vineeth Vijayan , Peter Oberparleiter , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Tony Krowiak , Jason Herne , Harald Freudenberger , "Michael S. Tsirkin" , Jason Wang , Xuan Zhuo , Diana Craciun , Alex Williamson , Eric Auger , Fei Li , Benjamin LaHaise , Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Kirti Wankhede , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-fpga@vger.kernel.org, intel-gvt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, linux-rdma@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-usb@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-aio@kvack.org, cgroups@vger.kernel.org, linux-mm@kvack.org, Jens Axboe , Pavel Begunkov , io-uring@vger.kernel.org Content-Type: text/plain; charset="us-ascii" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_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 Thu, Jul 13, 2023, Christian Brauner wrote: > diff --git a/fs/eventfd.c b/fs/eventfd.c > index dc9e01053235..077be5da72bd 100644 > --- a/fs/eventfd.c > +++ b/fs/eventfd.c > @@ -43,9 +43,10 @@ struct eventfd_ctx { > int id; > }; > > -__u64 eventfd_signal_mask(struct eventfd_ctx *ctx, __u64 n, __poll_t mask) > +bool eventfd_signal_mask(struct eventfd_ctx *ctx, __poll_t mask) > { > unsigned long flags; > + __u64 n = 1; > > /* > * Deadlock or stack overflow issues can happen if we recurse here > @@ -68,7 +69,7 @@ __u64 eventfd_signal_mask(struct eventfd_ctx *ctx, __u64 n, __poll_t mask) > current->in_eventfd = 0; > spin_unlock_irqrestore(&ctx->wqh.lock, flags); > > - return n; > + return n == 1; > } ... > @@ -58,13 +58,12 @@ static inline struct eventfd_ctx *eventfd_ctx_fdget(int fd) > return ERR_PTR(-ENOSYS); > } > > -static inline int eventfd_signal(struct eventfd_ctx *ctx) > +static inline bool eventfd_signal(struct eventfd_ctx *ctx) > { > return -ENOSYS; > } > > -static inline int eventfd_signal_mask(struct eventfd_ctx *ctx, __u64 n, > - unsigned mask) > +static inline bool eventfd_signal_mask(struct eventfd_ctx *ctx, unsigned mask) > { > return -ENOSYS; This will morph to "true" for what should be an error case. One option would be to have eventfd_signal_mask() return 0/-errno instead of the count, but looking at all the callers, nothing ever actually consumes the result. KVMGT morphs failure into -EFAULT if (vgpu->msi_trigger && eventfd_signal(vgpu->msi_trigger, 1) != 1) return -EFAULT; but the only caller of that user ignores the return value. if (vgpu_vreg(vgpu, i915_mmio_reg_offset(GEN8_MASTER_IRQ)) & ~GEN8_MASTER_IRQ_CONTROL) inject_virtual_interrupt(vgpu); The sample driver in samples/vfio-mdev/mtty.c uses a similar pattern: prints an error but otherwise ignores the result. So why not return nothing? That will simplify eventfd_signal_mask() a wee bit more, and eliminate that bizarre return value confusion for the ugly stubs, e.g. void eventfd_signal_mask(struct eventfd_ctx *ctx, unsigned mask) { unsigned long flags; /* * Deadlock or stack overflow issues can happen if we recurse here * through waitqueue wakeup handlers. If the caller users potentially * nested waitqueues with custom wakeup handlers, then it should * check eventfd_signal_allowed() before calling this function. If * it returns false, the eventfd_signal() call should be deferred to a * safe context. */ if (WARN_ON_ONCE(current->in_eventfd)) return; spin_lock_irqsave(&ctx->wqh.lock, flags); current->in_eventfd = 1; if (ctx->count < ULLONG_MAX) ctx->count++; if (waitqueue_active(&ctx->wqh)) wake_up_locked_poll(&ctx->wqh, EPOLLIN | mask); current->in_eventfd = 0; spin_unlock_irqrestore(&ctx->wqh.lock, flags); } You could even go further and unify the real and stub versions of eventfd_signal().