Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp2781216pxb; Thu, 3 Feb 2022 14:20:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJxqERpJXPCDjPUN6viyeyAAUF/PJjm00jQbG6hGAPqud0KhmvGv43SN3imnrMCTpqRkW9sI X-Received: by 2002:a63:6842:: with SMTP id d63mr130708pgc.213.1643926828361; Thu, 03 Feb 2022 14:20:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643926828; cv=none; d=google.com; s=arc-20160816; b=NsMc+cJTYU3w5i8desM+dGgaJd9t2a1nz8j0gLFuHk4x7h1WVMbuKffkRFmLpbAi13 EeY2wO9V8/3L+7fN721l2LXvDPaxyqBiVDzBgvTFMMCrQ7naxsNfbTJNcMuPuz2MwyIa tPpDhVW6Eeg/1ZY1Jp91vDz7rbh2WSYokgX8aUVMrTC6XXLHobpqw6xTYiEb3+u/gaSz XqweV/vCzFX/Ar+sGYFFKi+lTk3cAll3zoKILojvu/XeJjwjFhIVOeGCXq6621pKptR5 clEWOuLELsyGcoA6r94nqQ9RbHNZxs38UkvRbZ01QIhCWixByGSdN8b98/QXlMKCYsXb WtoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=w2pv08NOU3KU2lIlQuwAWBX3jpye2DFb+MEiE68cpW4=; b=kBqTK1ycxjWDydc2hOHR4ECK9DtJp3GZ2q0nZ0ZNc0Z3rCz0Gy7WKC1kFSoJcGAUEX lZpcrz78RREe+A4dh2kqZmb7FI2gHVIMwM/0LTHpIXIc62UoHDnkfemrG00M6dtTpCLa sF7cwtdBW/W0bjEzJhXWQ5Hr3XJxp5AI+AYe/socv2sgycwXqwAJNMXh9jREWAdE7BAv vaJvs41pGelZcySuKAK8UzlCv9HZtgJW9GW45NUfcLxSFjDNIxneQwtYCdMRURpy3Xfg lWwh50BUsbxvRh7RsGEvEncGoEe8Z1Ff1LMmuzKyVsU7k6ivZNHq10lmDYCPsN1JIaT0 umYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20210112.gappssmtp.com header.s=20210112 header.b=h1iCk0Aw; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j125si147083pfd.42.2022.02.03.14.20.16; Thu, 03 Feb 2022 14:20:28 -0800 (PST) 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=@kernel-dk.20210112.gappssmtp.com header.s=20210112 header.b=h1iCk0Aw; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353495AbiBCS3z (ORCPT + 99 others); Thu, 3 Feb 2022 13:29:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230107AbiBCS3x (ORCPT ); Thu, 3 Feb 2022 13:29:53 -0500 Received: from mail-io1-xd2c.google.com (mail-io1-xd2c.google.com [IPv6:2607:f8b0:4864:20::d2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD9CFC06173B for ; Thu, 3 Feb 2022 10:29:53 -0800 (PST) Received: by mail-io1-xd2c.google.com with SMTP id h7so4405936iof.3 for ; Thu, 03 Feb 2022 10:29:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=w2pv08NOU3KU2lIlQuwAWBX3jpye2DFb+MEiE68cpW4=; b=h1iCk0AwBLtt+QD/Mwlw3HzGkdprr4NwzHHC+wAFuzPkSB986b6eOLszxktDOv3NzX Za01y5W/wBCUdAMWjXaPXIjgI0hUEhyOph8ryqYYpmfaPUeJTLCAS+UhlgTXhOVK1PWU xlrix/NdZ3asXRAhgLAiBNLxeFI30j14h489+J/208X2qS4bZ+jatg1xdtREIHT4fUxI b7GuJaFWef53w0WUJ+bILCSX6ylyrqEuFqEqwMdyVSyDnDm+WP+onZyIrF2+a5MjSfn5 2AY7BXZPqF/BtQer4iqanqzgAi4kPvYdGt8oML6iMoE4yhCE8UeZNX+GaHsuV6IAytoy eTcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=w2pv08NOU3KU2lIlQuwAWBX3jpye2DFb+MEiE68cpW4=; b=1XVfQ3wEeXwz/EgQr1wzWNQOPCq8nLnkGecr2s2Z5hN5YNyVDIAAw5Eu21YfyplYeM vEn01nmL+mfK4auhFCf9Ne5T+PufxgIiue9Yn+/928sqqVCBLJi2Rt2GuFpevmj84Kf8 aUV/VvQI6P7hB4jnbi9G4yQK4xLxU2Ai0OFaLbtPXbp+6sWErc4OUwHTk+yYSouemls6 cRvw4EceVuMokP+hIcW5z2sIX2hyrMGrYZwDsT+FzSdOoIU0wMWK2fbTFmvzyIyCQzRr /U0bjPFZUgO/h+ZH6EWtqlZYLCX5jn26l51hcKL6zVGg3v2eR0vURxTNMtaANYpMZ8K9 3Y0w== X-Gm-Message-State: AOAM531Zb68I/QLyLrk2u4CGjf1oRhvCh5q6SAW70KtKibiwXFkqrm5d hvLKyCLCk6IYCA18xhUvGhoAYw== X-Received: by 2002:a05:6638:38a8:: with SMTP id b40mr13899658jav.134.1643912993131; Thu, 03 Feb 2022 10:29:53 -0800 (PST) Received: from [192.168.1.30] ([207.135.234.126]) by smtp.gmail.com with ESMTPSA id u26sm18117218ior.52.2022.02.03.10.29.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 03 Feb 2022 10:29:52 -0800 (PST) Subject: Re: [External] Re: [PATCH v3 2/3] io_uring: avoid ring quiesce while registering/unregistering eventfd To: Usama Arif , io-uring@vger.kernel.org, asml.silence@gmail.com, linux-kernel@vger.kernel.org Cc: fam.zheng@bytedance.com References: <20220203174108.668549-1-usama.arif@bytedance.com> <20220203174108.668549-3-usama.arif@bytedance.com> <877d54b9-5baa-f0b5-23fe-25aef78e37c4@bytedance.com> From: Jens Axboe Message-ID: Date: Thu, 3 Feb 2022 11:29:52 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <877d54b9-5baa-f0b5-23fe-25aef78e37c4@bytedance.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/3/22 11:26 AM, Usama Arif wrote: > Hmm, maybe i didn't understand you and Pavel correctly. Are you > suggesting to do the below diff over patch 3? I dont think that would be > correct, as it is possible that just after checking if ctx->io_ev_fd is > present unregister can be called by another thread and set ctx->io_ev_fd > to NULL that would cause a NULL pointer exception later? In the current > patch, the check of whether ev_fd exists happens as the first thing > after rcu_read_lock and the rcu_read_lock are extremely cheap i believe. They are cheap, but they are still noticeable at high requests/sec rates. So would be best to avoid them. And yes it's obviously racy, there's the potential to miss an eventfd notification if it races with registering an eventfd descriptor. But that's not really a concern, as if you register with inflight IO pending, then that always exists just depending on timing. The only thing I care about here is that it's always _safe_. Hence something ala what you did below is totally fine, as we're re-evaluating under rcu protection. > diff --git a/fs/io_uring.c b/fs/io_uring.c > index 25ed86533910..0cf282fba14d 100644 > --- a/fs/io_uring.c > +++ b/fs/io_uring.c > @@ -1736,12 +1736,13 @@ static void io_eventfd_signal(struct io_ring_ctx > *ctx) > { > struct io_ev_fd *ev_fd; > > + if (likely(!ctx->io_ev_fd)) > + return; > + > rcu_read_lock(); > /* rcu_dereference ctx->io_ev_fd once and use it for both for > checking and eventfd_signal */ > ev_fd = rcu_dereference(ctx->io_ev_fd); > > - if (likely(!ev_fd)) > - goto out; > if (READ_ONCE(ctx->rings->cq_flags) & IORING_CQ_EVENTFD_DISABLED) > goto out; > > >> synchronize_rcu() can take a long time, and I think this is in the wrong >> spot. It should be on the register side, IFF we need to expedite the >> completion of a previous event fd unregistration. If we do it that way, >> at least it'll only happen if it's necessary. What do you think? >> > > > How about the approach in v4? so switching back to call_rcu as in v2 and > if ctx->io_ev_fd is NULL then we call rcu_barrier to make sure all rcu > callbacks are finished and check for NULL again. I'll check, haven't looked at v4 yet! -- Jens Axboe