From patchwork Sat Sep 21 07:59:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13808790 Received: from mail-ed1-f54.google.com (mail-ed1-f54.google.com [209.85.208.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5A67E5FEE4 for ; Sat, 21 Sep 2024 08:03:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726905807; cv=none; b=k2V9rWWFJRMS96VhI2kStoptkpjRijrseZkzdjD9oP+hia/48TU+2gfWcrpiq+9k05EI+TIfkRgqHmKm4qzF9WVGkctPJb8THpv5tvJ1LnL48FhwTUBGXfpxCGQqrf+msHOREuj/8Ya4JLz24nPo+p8IzEd+kXHvQ+Q4KZ+We2c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726905807; c=relaxed/simple; bh=mkYEMFNjtOptKYoRJNvnM32o18ZZzOs47rd0niUTsd8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=elPlOxo/ctJM7o5zxmwCXs/geUWXM2TF3fVlcUAnzs92njWKiJtfKM9RQjL0tWoFTkuiOu6k2u8VRT6DeyWEx3Y3sYxN/RQ2E1LLIVwA8lqHQ5fVdr91cfK6nr7R6ZypDKNXyM5q1DVMppGFknrS4h2PxG0qE6mBafMD/mKgNoc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b=hvD1wfLv; arc=none smtp.client-ip=209.85.208.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b="hvD1wfLv" Received: by mail-ed1-f54.google.com with SMTP id 4fb4d7f45d1cf-5c4226a5af8so3545759a12.1 for ; Sat, 21 Sep 2024 01:03:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1726905798; x=1727510598; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IIHhoqouWr+1bAg94n+0B587yCzWhD+Td/cRRJvC/8w=; b=hvD1wfLvaF5J/Z/Z9AB4rI+gniS7hxN/fHliHhnhMCBlixvajSwaTWqALatdNzPf0g wuMcbHFvcBNrKmQphMXjkMdHbE/+85xGjPDMPPgOjLrj/1z3tKOEUr1E0kBpJ+u5IEnO MInuySr/p2vfvY9VRnqiekATCxH2MTiX6pq44/negaypRaMBIFjsLzSSy16hqPoEaPX2 6A88iLYbTIGp8Ir2EzGjlWnhX4i5eJdkIQqk3WFspFAcJ+gpA9yVqjca7rHoaNdWyP3e hwXe/H7uvoui9MiNDe++Ck+BO10mpuloDKbcS7caIxhOZ3o18GNmCMD/U60XWtH2PIzO 9JDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726905798; x=1727510598; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IIHhoqouWr+1bAg94n+0B587yCzWhD+Td/cRRJvC/8w=; b=t5UVnJaz7yxggT7H1rypCJm6V2uvecQeEIpY/4EJI0qUIlSo9yBSvGgFFqEPr38boN Xil5bonHp6JWLksEBuGLR93bOTmYH7FD+DRgBrCj9xJ0PROpy0p98lWY57+6cBtt17tS EMPjiSfgF4TL83SzbnP4mlcZcmuOzgThmre/YQs4A0HUL52AW3KUS0OeyoNoLHJ6dZ31 9woHCKViwMsmJAxZODToc2vYakk1x/SlSmSI+bCWLNLTeFFy7oAR0wf2p4+w3CTOaP2d 7DgcMy9yfBjUYVHU86/TOqFrPWSL/69qcXyLu0FttUENPGiMAlV8h9btE7H/2ohMO8of OxwQ== X-Gm-Message-State: AOJu0YxeXnHN4F9v322m9QeYLVthFylq3yvRIKu7DDEH8HIZCpXUw0/l G10F+mXjxYwjijb/PqEOTNl2e9EiU6K9bH9tLYYZdJKULQ/Eg8DpBzBi85qT5jzmw/yk2R99+7j sQBaSs87j X-Google-Smtp-Source: AGHT+IFjq8fOMIwbl38YMkQFNV44p+Rt1w1qaz3mR8NEO8lZ/wNsI1kUqn6YSz5W85yBLulYvEErcg== X-Received: by 2002:a17:907:6ea2:b0:a7a:ab8a:38f with SMTP id a640c23a62f3a-a90d510bed7mr595430666b.41.1726905798509; Sat, 21 Sep 2024 01:03:18 -0700 (PDT) Received: from localhost.localdomain (cpe.ge-7-3-6-100.bynqe11.dk.customer.tdc.net. [83.91.95.82]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a90612df51asm964583666b.148.2024.09.21.01.03.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Sep 2024 01:03:17 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 1/6] io_uring/eventfd: abstract out ev_fd put helper Date: Sat, 21 Sep 2024 01:59:47 -0600 Message-ID: <20240921080307.185186-2-axboe@kernel.dk> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240921080307.185186-1-axboe@kernel.dk> References: <20240921080307.185186-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We call this in two spot, have a helper for it. In preparation for extending this part. Signed-off-by: Jens Axboe --- io_uring/eventfd.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/io_uring/eventfd.c b/io_uring/eventfd.c index e37fddd5d9ce..8b628ab6bbff 100644 --- a/io_uring/eventfd.c +++ b/io_uring/eventfd.c @@ -41,6 +41,12 @@ static void io_eventfd_do_signal(struct rcu_head *rcu) io_eventfd_free(rcu); } +static void io_eventfd_put(struct io_ev_fd *ev_fd) +{ + if (refcount_dec_and_test(&ev_fd->refs)) + call_rcu(&ev_fd->rcu, io_eventfd_free); +} + void io_eventfd_signal(struct io_ring_ctx *ctx) { struct io_ev_fd *ev_fd = NULL; @@ -77,8 +83,7 @@ void io_eventfd_signal(struct io_ring_ctx *ctx) } } out: - if (refcount_dec_and_test(&ev_fd->refs)) - call_rcu(&ev_fd->rcu, io_eventfd_free); + io_eventfd_put(ev_fd); } void io_eventfd_flush_signal(struct io_ring_ctx *ctx) @@ -152,8 +157,7 @@ int io_eventfd_unregister(struct io_ring_ctx *ctx) if (ev_fd) { ctx->has_evfd = false; rcu_assign_pointer(ctx->io_ev_fd, NULL); - if (refcount_dec_and_test(&ev_fd->refs)) - call_rcu(&ev_fd->rcu, io_eventfd_free); + io_eventfd_put(ev_fd); return 0; } From patchwork Sat Sep 21 07:59:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13808789 Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1BDE9149C50 for ; Sat, 21 Sep 2024 08:03:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726905806; cv=none; b=JfHXBYIbiFPt3bJfCuIGli16/BueV2mDyVC37u65lxQnIw5LCUVFlYk/5hCboWBQx/fNzfdCekOF/+Uapc25bkKHk22AsBSoR+PKGD+aQWVMaqZ2qzwBnXqSmjCBRmCJYW5dbP/59QxGJJKxnAWeRwSx6XYmYhwHB4fawnTJWGs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726905806; c=relaxed/simple; bh=iqtEPxxhQJufhJEFjqHKqOcxDDJaeezgD3I9swoZLmo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eWkbZXb2egevWvyaelVFoV5weBtDWt97lBQL/fA223V94SIRu6RYoyuYPOS7tfCkJCtEZUm6mou+evfXCm4kg2mn7bEodozwR+ob27nPRyOVUmaiOWQ8bBvU898zjRTu8ngy2jFFwSRyr2BC1kGRBJLNwBb/mLQS7/SHYiwkAWw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b=MSAuFgds; arc=none smtp.client-ip=209.85.218.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b="MSAuFgds" Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-a8d60e23b33so327623966b.0 for ; Sat, 21 Sep 2024 01:03:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1726905801; x=1727510601; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=t5DwLe1xcgJOT4lqdoFCiVsuxMWz9fD5sQA3LuR06z0=; b=MSAuFgdsdPIVjQBJhZ+BkIhYBXJtlCZh6U+Hetey0fT5h4+faZTGz1JpeXOEtcspUV HSzGOqvGW2C9jSfqj48KKYGPAiD3raTWIvRC9ITaf7olGHBsQWdz0xrin6iLCW58ncW5 x/q1n0BJS8MH1MTx7LEz0DWQ5CkEEJ8JIdM7/OPPbkTbxpZ5PBZxsQVyyjRisqetpTBU v5bhwVMm1v7yYSlFoHUQMB7b67dMFEqth8+ArG37PzWjzDj7UxwtlCcPykVB+AvR3I6p H0fuydh01ytcV0nGpYvhSKqO/G5JeRM8cgDqOR1CAlFHzxpETK8mhAZIq2O+qisjaGv4 GwOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726905801; x=1727510601; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=t5DwLe1xcgJOT4lqdoFCiVsuxMWz9fD5sQA3LuR06z0=; b=BEj4el5iriNvcNpEeV9tr9OM5Ep2hY0B4kSZWOKdNsJBAU+7CGIlJhTVGvPMVzUQig 98dL8AcRZ0uuMiKo2h3Jbg1PEv8y2vUTo8FqzVPBqjISHTB3z56JifEEM1jIeveITbDZ me3ULI3EkbJYTJ3enr3csgPjIiiYxuAL/lYgHIJ5dqcSgiqQeQsGYz9H1bc668iMrdK1 XZ5ubgZSNKzWyGBnDgnHfATiheSoD3g7SNCwTXv1NPXxCnsWMqoASpjuBvdLvhrhMD2t w8G5mFOXRuQqJKuC6Cah7ll5OPMfKD/22/ZseJ8M55amgjgH1ibV3SJAXYCeF8JwtPmW BhSg== X-Gm-Message-State: AOJu0YyG7nlzgSiBxKN00ptbYszzJEXmZkWOOAyjpCjjLqGbpienligk /J84T+Zy2Pw4Hmo3u8kqnFtLRZYozcfJHFTWyPHZAe8shyHp8mLRyHwj1/RCBPqjPQRRWtqDFe0 EEcqxuq0X X-Google-Smtp-Source: AGHT+IGyfALNaxvW65+Gq2y9YdFcHVIhSbx8uw6MC7PVWrYrCUvVUJqk2aWiouNdTWJ7pB+2Yl6z3A== X-Received: by 2002:a17:907:d599:b0:a8d:5e1a:8d80 with SMTP id a640c23a62f3a-a90d5779864mr477572566b.40.1726905800640; Sat, 21 Sep 2024 01:03:20 -0700 (PDT) Received: from localhost.localdomain (cpe.ge-7-3-6-100.bynqe11.dk.customer.tdc.net. [83.91.95.82]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a90612df51asm964583666b.148.2024.09.21.01.03.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Sep 2024 01:03:18 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 2/6] io_uring/eventfd: check for the need to async notifier earlier Date: Sat, 21 Sep 2024 01:59:48 -0600 Message-ID: <20240921080307.185186-3-axboe@kernel.dk> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240921080307.185186-1-axboe@kernel.dk> References: <20240921080307.185186-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 It's not necessary to do this post grabbing a reference. With that, we can drop the out goto path as well. Signed-off-by: Jens Axboe --- io_uring/eventfd.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/io_uring/eventfd.c b/io_uring/eventfd.c index 8b628ab6bbff..829873806f9f 100644 --- a/io_uring/eventfd.c +++ b/io_uring/eventfd.c @@ -69,10 +69,10 @@ void io_eventfd_signal(struct io_ring_ctx *ctx) */ if (unlikely(!ev_fd)) return; + if (ev_fd->eventfd_async && !io_wq_current_is_worker()) + return; if (!refcount_inc_not_zero(&ev_fd->refs)) return; - if (ev_fd->eventfd_async && !io_wq_current_is_worker()) - goto out; if (likely(eventfd_signal_allowed())) { eventfd_signal_mask(ev_fd->cq_ev_fd, EPOLL_URING_WAKE); @@ -82,7 +82,6 @@ void io_eventfd_signal(struct io_ring_ctx *ctx) return; } } -out: io_eventfd_put(ev_fd); } From patchwork Sat Sep 21 07:59:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13808791 Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A260C14D6F7 for ; Sat, 21 Sep 2024 08:03:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726905807; cv=none; b=UevNZ1ewuouNgCLTX/gHiPLCnOt+GVvI5MT8EAa5IKrxATnT8DkPdyRifJbd0T0Mxp5c4UwlSMtj4xl8EhUW4zyoMT4xSwBbU9dP0Zn9vG/Dw6h5qNNsOYOMuSixddZhD8JtHfeRoOkCdthe46XXlcryixPO/ajEqS6zNq1o6Uc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726905807; c=relaxed/simple; bh=8kpVYAu/rfjpcg1zaI6yoQAGGLSuu+Z19WdJKOJ6tSg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mzv/9DXRFB3j4vxvPtLRY7RTHoVpPSJjDCLAaxP6SeqsChIEwL3TagGptiJP6kECW2l9brBs+1gmr49vnEm5HQqK9Sttfl1A0iX/rLyrhtNKnhabaRjJI1rewCugOD6GLTzT2DhtvebmC27YHWMPkRHXoW/3eeVDAS/HuhS8K68= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b=uqPdCjKh; arc=none smtp.client-ip=209.85.218.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b="uqPdCjKh" Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-a8d6d0fe021so389398266b.1 for ; Sat, 21 Sep 2024 01:03:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1726905803; x=1727510603; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4crEGMlbWLkjKo7VKVg8cTe/h5B6C2vYnkowsodrkr8=; b=uqPdCjKhVH2YaJKS72hp4wFuOt5Hr0poQaw5n1HiDuUc5Mwf1q7/GxQwZpRUZ6+79J HqKd/SoJehzy2FydPdp/s4Oxx3WBe1R7JeUiEggxWhcOCcr6hgVMJcLtc8BGlNk3z1xy l2wI8oqQCJ8hoaUFDhGSkjkziyzYXQfKgc9cfNdVnJi12lZzxYggMBSJv1X726j++F4V AtOAwUTZYu8QHIEycQZ3sdBgIooVD6X83EQbt6uj2AxyMAGK07XDNLZWYk531kMmG3hf bmsGhoJUClQBinJwKQhsPBnYTC0YwrvYdu83sMOl7GG2l5UotmFUlCnHl9L2GZ3p1bP+ KOhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726905803; x=1727510603; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4crEGMlbWLkjKo7VKVg8cTe/h5B6C2vYnkowsodrkr8=; b=pYjH3dp7OKr0rIQ8SUwiCrwjA0Dv9yaxkTUyGKDmtMsFIPKuUjL9p0iU/XYJtdoz+E PYFFkzctWY4EushmQbQ8OfKhhylK1oDzmsmoX0d8CrRAWUC0SljO6cWCpdGJnJOt56RL xU0F9MpaVkKJtbqxTev+tI1G/zDrXN5mE+alROvjn7rsVf5o6q6Dw2sUmGsGXzQgIX0B wk4Y7ncYaTvCzo9gXlPsKByQCP3Kg+G7jHHOidibV8wiUtSNdvbIsr4uAoBfwBytidH5 sIWEYG07JSObBPfXIFOYnMyaNG0aHPk+ne8T7CyNaXupevpkb2DVRm30RWIFT12GUgS4 nkrA== X-Gm-Message-State: AOJu0Yw4QH8NzM6mZzvaNsC960LeF4YlFlXaqaDuIe1lad1tPeaoLR9I Av2sNWBbL9kvxImEtdAfIT/TAJ9FMwHY2Bq6jejltvtX5/UKzonCNDAJ8OcwXvzl9P739TIlmXE SJRzirMui X-Google-Smtp-Source: AGHT+IGNvrHuDYIPePwM2mqWfjCVNGOY3bEcx2+vSs7pZeG9YJU1zgaEahVMkSnoeloXEvBakvU6cg== X-Received: by 2002:a17:907:f721:b0:a8d:51a7:d5e8 with SMTP id a640c23a62f3a-a90d4ffd5d3mr488398766b.15.1726905802688; Sat, 21 Sep 2024 01:03:22 -0700 (PDT) Received: from localhost.localdomain (cpe.ge-7-3-6-100.bynqe11.dk.customer.tdc.net. [83.91.95.82]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a90612df51asm964583666b.148.2024.09.21.01.03.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Sep 2024 01:03:21 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 3/6] io_uring/eventfd: move actual signaling part into separate helper Date: Sat, 21 Sep 2024 01:59:49 -0600 Message-ID: <20240921080307.185186-4-axboe@kernel.dk> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240921080307.185186-1-axboe@kernel.dk> References: <20240921080307.185186-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In preparation for using this from multiple spots, move the signaling into a helper. Signed-off-by: Jens Axboe --- io_uring/eventfd.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/io_uring/eventfd.c b/io_uring/eventfd.c index 829873806f9f..58e76f4d1e00 100644 --- a/io_uring/eventfd.c +++ b/io_uring/eventfd.c @@ -47,6 +47,22 @@ static void io_eventfd_put(struct io_ev_fd *ev_fd) call_rcu(&ev_fd->rcu, io_eventfd_free); } +/* + * Returns true if the caller should put the ev_fd reference, false if not. + */ +static bool __io_eventfd_signal(struct io_ev_fd *ev_fd) +{ + if (eventfd_signal_allowed()) { + eventfd_signal_mask(ev_fd->cq_ev_fd, EPOLL_URING_WAKE); + return true; + } + if (!atomic_fetch_or(BIT(IO_EVENTFD_OP_SIGNAL_BIT), &ev_fd->ops)) { + call_rcu_hurry(&ev_fd->rcu, io_eventfd_do_signal); + return false; + } + return true; +} + void io_eventfd_signal(struct io_ring_ctx *ctx) { struct io_ev_fd *ev_fd = NULL; @@ -73,16 +89,8 @@ void io_eventfd_signal(struct io_ring_ctx *ctx) return; if (!refcount_inc_not_zero(&ev_fd->refs)) return; - - if (likely(eventfd_signal_allowed())) { - eventfd_signal_mask(ev_fd->cq_ev_fd, EPOLL_URING_WAKE); - } else { - if (!atomic_fetch_or(BIT(IO_EVENTFD_OP_SIGNAL_BIT), &ev_fd->ops)) { - call_rcu_hurry(&ev_fd->rcu, io_eventfd_do_signal); - return; - } - } - io_eventfd_put(ev_fd); + if (__io_eventfd_signal(ev_fd)) + io_eventfd_put(ev_fd); } void io_eventfd_flush_signal(struct io_ring_ctx *ctx) From patchwork Sat Sep 21 07:59:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13808792 Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D7D79149C50 for ; Sat, 21 Sep 2024 08:03:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726905808; cv=none; b=jeDWtV9d71B6Uj2NwikPprlTahdv6aptg4h9wU+zM0k//V6n16Itfg6JKPuc9xoPrZjLRG9lc9gWSCyNsQq2cTtbMJeSikqBmO2jP04AG7sb38HlTVtlMmSCjMEmN4tRJuiT5F28FfIQmW+t0fzrmuH2jCyNYvi0Sqqjl/oHuQY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726905808; c=relaxed/simple; bh=WrVTkfnAvzDJx/0lbUHu9OmwXYRQFHd/6xDsnzvPS1w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LlzuLmtRutexB4WvRY4ql+MbkNHFHURZOl4URGRIsM7gTUfkgwWeZjS2CD/qNKEiLaPITyOahgu6SdSffOvgidO5R22FuScdYF2jrkVtlXzDh+d0TaNNXbXRr4EwCPZLTbHYqgzKy1I7ExrBfTfPo7hEfoE+95oltOxavg0upDo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b=W8n+IZ4s; arc=none smtp.client-ip=209.85.218.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b="W8n+IZ4s" Received: by mail-ej1-f45.google.com with SMTP id a640c23a62f3a-a8d13b83511so316126766b.2 for ; Sat, 21 Sep 2024 01:03:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1726905805; x=1727510605; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bO/KRR7ks2vctLl92J7KuMLnkhNzTt8xT10+GbHUAv8=; b=W8n+IZ4sWGdLt0gYjuNwsP9eQiykEOtVpuaQH1mVr5ArAnsPsVCq1cJi04I3yss2/J 6iryVPVqwdzDzMPx0kT3itKhEzEP/XDapGE4VHEvh+IEcfieR4szCC4ip3oClZiiWusP Z9NOrI2+dMGItcmsywYBBE/7qFE4AyHZXj+qm44OCAySyculx8Lg7bcTyDaiBcQjD0xT IM7/lxdKkAxO7ngbzgBE/wBJ5u9g/ZdKKMhJa2lzye6u9WnzWYGR2Hwpkk4Vr4IQlvvW +MKHZsCqWw+l45idMC84/B0wP/iJBeTJS/SKb/T2HaJdjhV2eBxg9qenzd5hp30+d5WO +LQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726905805; x=1727510605; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bO/KRR7ks2vctLl92J7KuMLnkhNzTt8xT10+GbHUAv8=; b=rWlhAIuQbe0S0kGDPbrsKMHG6VauP6ErNTHxELGMA+8AoXclXIPo37GLZx0unNclfy YHXDb1shVfbu5/YGkNv+IqMDbFRQsC41/fM3KXNtMslpAdINC2JhQrnCYPphWLcefPna LyHW2qqjidy9mlXDR2/Aopdv3xITI3txpm2kkAKjo7onsjCZw3dGpUKHeT4XJNFlypwD 6ZMtACuQLL8Hd2WhDGtXzISIg9BI447/w1R82APE32Zl/R5cpi24/IcYfQqPQO2ns9XL BNcFPYLZWUWEijZxI3ZzGx3CeEbbKdTeQdOIz5IuayRCJMn3LPS+dEHsdjyUdKOsF9k7 pDgQ== X-Gm-Message-State: AOJu0Yz03FpkaTSy0qdjH7QKZ0yhC4fzOlxqJ2LG/Z0h3x92cj7FdOfZ /LfdEhjxuz5rvTnz2LRnfsxQ5RU+1kt4WiOuTyjMwhnmVF9nspQCgUWjiIjuZAUyneAxwiZh1QG Ea3i/ltOH X-Google-Smtp-Source: AGHT+IGq1AxHnRUAoIqD2MH72JAbc0JqbhH4k2x6dKO/aVa2WyVRklLhF/uq5bq3pRVdfisWZqeB1w== X-Received: by 2002:a17:907:60d4:b0:a8d:4db5:529 with SMTP id a640c23a62f3a-a90d59299famr457905766b.48.1726905803782; Sat, 21 Sep 2024 01:03:23 -0700 (PDT) Received: from localhost.localdomain (cpe.ge-7-3-6-100.bynqe11.dk.customer.tdc.net. [83.91.95.82]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a90612df51asm964583666b.148.2024.09.21.01.03.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Sep 2024 01:03:23 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 4/6] io_uring/eventfd: move trigger check into a helper Date: Sat, 21 Sep 2024 01:59:50 -0600 Message-ID: <20240921080307.185186-5-axboe@kernel.dk> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240921080307.185186-1-axboe@kernel.dk> References: <20240921080307.185186-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 It's a bit hard to read what guards the triggering, move it into a helper and add a comment explaining it too. This additionally moves the ev_fd == NULL check in there as well. Signed-off-by: Jens Axboe --- io_uring/eventfd.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/io_uring/eventfd.c b/io_uring/eventfd.c index 58e76f4d1e00..0946d3da88d3 100644 --- a/io_uring/eventfd.c +++ b/io_uring/eventfd.c @@ -63,6 +63,17 @@ static bool __io_eventfd_signal(struct io_ev_fd *ev_fd) return true; } +/* + * Trigger if eventfd_async isn't set, or if it's set and the caller is + * an async worker. If ev_fd isn't valid, obviously return false. + */ +static bool io_eventfd_trigger(struct io_ev_fd *ev_fd) +{ + if (ev_fd) + return !ev_fd->eventfd_async || io_wq_current_is_worker(); + return false; +} + void io_eventfd_signal(struct io_ring_ctx *ctx) { struct io_ev_fd *ev_fd = NULL; @@ -83,9 +94,7 @@ void io_eventfd_signal(struct io_ring_ctx *ctx) * completed between the NULL check of ctx->io_ev_fd at the start of * the function and rcu_read_lock. */ - if (unlikely(!ev_fd)) - return; - if (ev_fd->eventfd_async && !io_wq_current_is_worker()) + if (!io_eventfd_trigger(ev_fd)) return; if (!refcount_inc_not_zero(&ev_fd->refs)) return; From patchwork Sat Sep 21 07:59:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13808793 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 66DE6154425 for ; Sat, 21 Sep 2024 08:03:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726905809; cv=none; b=H3NGpZEXnn+t9V2EGOACSuDGBDuVDzDyzok0SCWM4Ku5AyPDfPQdyerY30pOJekcFtlTBYIvh7t+BEsw2DXWELAuul9UBlUxYjzRGqMJ1Rtzqc1V20OYsBygzrzpZTFTmXigfmw0vzQ33GcyVDEW4saqKQbmk59lZii4Js4eRPs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726905809; c=relaxed/simple; bh=YU3USnm0oLLxbM4stWZB12POZPM9SUIUJtu8uHTBrTE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=owXcOBvHq0cF+xLtJxs2MD4VeJcA5+hTD+w8MhgEROoILx2eO7B7MMPVHLiFnNscrVMjNqUWx2RtiaRmssozUtoeJvkROtE3modEpevjS4M8/svyEJFapOS4m+p3/F1cUZrAquduoSaEGAtjTczsXkBranWxWkL+cbI9XdKdkT4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b=K0DcdNG0; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b="K0DcdNG0" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-42cb6f3a5bcso33812645e9.2 for ; Sat, 21 Sep 2024 01:03:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1726905805; x=1727510605; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9G6hzmtkZZlkSzxwyO5DL96eqaxvZuai6ihXU9i9Xao=; b=K0DcdNG0/Ft0O61qPsbx6x9e0IKtoIj5Bi22c6zKUq6G/2sdAQFPFn15zqdBj3NSPM 3XtPcGoJAhDPKFShcOLwaFaZRb5IjXFEmpZSN7us8vEMoh++pYwc0YpTUB+HPO013qU2 lRykcwhvl3o5bBCOu9yDMYuydEgNxFOJpbRwf/wQwpaXPm8p0093w3qRyOmBeG50kiUk laB3uiQ3viERtjxMjGIZ5A05GWdFNiiRnen9o8//mxBuWo9/u2GJE330CH6tzmmAv4NP 1W8huo0R+J13lBpIT27yCI1tkuoOq1vrWKQ44AkygL4Jee8B5WoydV5r7u9Ki1Wopepy vY6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726905805; x=1727510605; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9G6hzmtkZZlkSzxwyO5DL96eqaxvZuai6ihXU9i9Xao=; b=Mv67bhExbM88j15OdhpAhrX6vvVobSdpjATTwL6JzYBhMbjypj1vdj52VFHCv28mGx jUtRouEOGsipyNg8cWSem45aEBOq7SPOI6pwQf7XHkSc3oUTsjKnT07PtPaqjVBoXvvr YIz/xqf3xgcq5XmniDSkpdrPt24m5MRj6fA406seWPHv9chjhAXaCMuFSo+L3frgwD4B 3V4frD5aqVqKdE0gqw2JfaD9Dn0hlJy1f1MHJZ25W04WBjWU8y6psv7hwpn4T8Rzb8iz DcV7UdePYWt71C7f4NCK7jL7uy4YBMq+Jqs4Pc0h3U4QaPt//TDTKZ/Mki67VmmC6Bm5 kH5g== X-Gm-Message-State: AOJu0YyTZzF9GxjTBA+oocntCJG7nY9MHRXFQqYsKft9VDIX9stcogh/ wb/MjPivyb/3ZNJskXzypGmSdEtz1rIrRqbHNIKIJiAkMdEqBZqnCY+eqNyv44kK7pn6vslNj1X gOske2TF9 X-Google-Smtp-Source: AGHT+IGcXFK3aPrP0lM5AB7LTJ0HsyFsnNgSiazOaMMCsNnkQpMyzV8fhXn2pG4hfZUv0gWsjFQRAQ== X-Received: by 2002:a05:6000:2a8:b0:374:c160:269e with SMTP id ffacd0b85a97d-37a42279388mr5001969f8f.22.1726905804873; Sat, 21 Sep 2024 01:03:24 -0700 (PDT) Received: from localhost.localdomain (cpe.ge-7-3-6-100.bynqe11.dk.customer.tdc.net. [83.91.95.82]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a90612df51asm964583666b.148.2024.09.21.01.03.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Sep 2024 01:03:24 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 5/6] io_uring/eventfd: abstract out ev_fd grab + release helpers Date: Sat, 21 Sep 2024 01:59:51 -0600 Message-ID: <20240921080307.185186-6-axboe@kernel.dk> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240921080307.185186-1-axboe@kernel.dk> References: <20240921080307.185186-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In preparation for needing the ev_fd grabbing (and releasing) from another path, abstract out two helpers for that. Signed-off-by: Jens Axboe --- io_uring/eventfd.c | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/io_uring/eventfd.c b/io_uring/eventfd.c index 0946d3da88d3..d1fdecd0c458 100644 --- a/io_uring/eventfd.c +++ b/io_uring/eventfd.c @@ -47,6 +47,13 @@ static void io_eventfd_put(struct io_ev_fd *ev_fd) call_rcu(&ev_fd->rcu, io_eventfd_free); } +static void io_eventfd_release(struct io_ev_fd *ev_fd, bool put_ref) +{ + if (put_ref) + io_eventfd_put(ev_fd); + rcu_read_unlock(); +} + /* * Returns true if the caller should put the ev_fd reference, false if not. */ @@ -74,14 +81,18 @@ static bool io_eventfd_trigger(struct io_ev_fd *ev_fd) return false; } -void io_eventfd_signal(struct io_ring_ctx *ctx) +/* + * On success, returns with an ev_fd reference grabbed and the RCU read + * lock held. + */ +static struct io_ev_fd *io_eventfd_grab(struct io_ring_ctx *ctx) { - struct io_ev_fd *ev_fd = NULL; + struct io_ev_fd *ev_fd; if (READ_ONCE(ctx->rings->cq_flags) & IORING_CQ_EVENTFD_DISABLED) - return; + return NULL; - guard(rcu)(); + rcu_read_lock(); /* * rcu_dereference ctx->io_ev_fd once and use it for both for checking @@ -90,16 +101,24 @@ void io_eventfd_signal(struct io_ring_ctx *ctx) ev_fd = rcu_dereference(ctx->io_ev_fd); /* - * Check again if ev_fd exists incase an io_eventfd_unregister call + * Check again if ev_fd exists in case an io_eventfd_unregister call * completed between the NULL check of ctx->io_ev_fd at the start of * the function and rcu_read_lock. */ - if (!io_eventfd_trigger(ev_fd)) - return; - if (!refcount_inc_not_zero(&ev_fd->refs)) - return; - if (__io_eventfd_signal(ev_fd)) - io_eventfd_put(ev_fd); + if (io_eventfd_trigger(ev_fd) && refcount_inc_not_zero(&ev_fd->refs)) + return ev_fd; + + rcu_read_unlock(); + return NULL; +} + +void io_eventfd_signal(struct io_ring_ctx *ctx) +{ + struct io_ev_fd *ev_fd; + + ev_fd = io_eventfd_grab(ctx); + if (ev_fd) + io_eventfd_release(ev_fd, __io_eventfd_signal(ev_fd)); } void io_eventfd_flush_signal(struct io_ring_ctx *ctx) From patchwork Sat Sep 21 07:59:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13808794 Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AA86B154425 for ; Sat, 21 Sep 2024 08:03:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726905811; cv=none; b=RIPRWgBsUEh1JXB2CX7oWKcYegzUykRrz5EaxqmDcoMkiywrdI4DuGeX2+NjOe8U53/JF/ZEJel8znsS56QNGecHCfMf0A5l+Fl5eLyad2rUxo392x37PNTNXM3OJmwRJNgd+dwjpdCFzl3umbOutHJW+rKESaaICmy8dK6R0t0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726905811; c=relaxed/simple; bh=PzsrtkjKwRx2E7o4j65Cv9HylLcgvaVlipIRHbhoVSA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kYrdvOZxGb/BiBqTmPsnd0CTu6imFMGMJysZ5WLqAbr0odgd9zFWNnRZTImx4VwprvjBSnQWzz4g5Bt3LA4/NCjfJqy5FhPQKr8TF+OPW7ZoZi2rzlaPeAviWmxfHq4WPxC7QzKHff+UpWJ/by1QarPqOSiBqJ7aRclb0HAP8Ew= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b=H2WctHGM; arc=none smtp.client-ip=209.85.218.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b="H2WctHGM" Received: by mail-ej1-f45.google.com with SMTP id a640c23a62f3a-a8d56155f51so311598366b.2 for ; Sat, 21 Sep 2024 01:03:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1726905807; x=1727510607; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=K7T+zO3yL3MLZif62myBqDQzv2a8wUfIb32Bu2v4rpE=; b=H2WctHGM0dTbPNaf9nPYEBzKCOlVtG5BQzpCu10cjJPYEXAHsuvCArqWa69Slhm+sX zoYLV9QZL/dyPVLJVtGNhCKMl0TIAtVAWxvfsQvmD4SMqHJqoeIqoqMXHoLewdo3zXtO pTlPuxJRS8p35RPfCxMzqEakLPAPB5iJTHAAIeMYPHiTKgeBeuKUMyHYLiXR761+KrP+ md+aGeVMfmxXuIRBD5xcOlxvaYPwxpduhwRGr5xCj6UMwplQStqrIicoFohHEebOK3Kf FFYascO34W3YHPzBOBgc2LnEN82ntde6XIBuIGch235uVH3ktxlTHAsczZsCPn6vpSD+ ZDfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726905807; x=1727510607; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=K7T+zO3yL3MLZif62myBqDQzv2a8wUfIb32Bu2v4rpE=; b=j/9aJPlx4eOL4UODjb20pUg5tCrJf3KJKlH79cEnWKDQBa7keCdmFZr9iOXXF3ikfY QNDX5D4NIcrU6RUwapcpDVW3S36Gus/Yz43pqy58Fx5q1GUbuITLYBk4kphhnfG8AdvS qORkOElmOMErADRfXaWzW3dFv25waBUFv42Pdl+Csar1jKRL32QN00H2KdaSE0OJ0Kj9 /o9h/wpP6x9TNnXSudRW7KGCn/ZwgAottmgtCJooJeFyhq6G9P1ZxW/I7U8xDQPbGzeX MadAJ+wSGfg3pvavU/1DuzjS48FF01WywlwThYstnueMUx+KMzfDtZb/dM728hgzbRsD hsnQ== X-Gm-Message-State: AOJu0YxyvDIMEtOLmD1EfMI8I4hnWJ/np1zmAooQEPyRFRsMu94carsH 91WjD/l0jVL4XTD5YngM6qIDbFL/KShjk6cseIodgXnLLg9nEHlRB9ua5aDB3maFyaZVxTWFnDC akIKbLc+n X-Google-Smtp-Source: AGHT+IHGnrZtnO+Q04rpZhPT91GK+goAvLMF6dmLDZsv9o+0qR2/hfPnhc/vRccU/9v+M1eI6I/vkw== X-Received: by 2002:a17:906:d259:b0:a7a:9ca6:528 with SMTP id a640c23a62f3a-a90d4fc8f40mr430336466b.11.1726905807076; Sat, 21 Sep 2024 01:03:27 -0700 (PDT) Received: from localhost.localdomain (cpe.ge-7-3-6-100.bynqe11.dk.customer.tdc.net. [83.91.95.82]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a90612df51asm964583666b.148.2024.09.21.01.03.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Sep 2024 01:03:25 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 6/6] io_uring/eventfd: move ctx->evfd_last_cq_tail into io_ev_fd Date: Sat, 21 Sep 2024 01:59:52 -0600 Message-ID: <20240921080307.185186-7-axboe@kernel.dk> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240921080307.185186-1-axboe@kernel.dk> References: <20240921080307.185186-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Everything else about the io_uring eventfd support is nicely kept private to that code, except the cached_cq_tail tracking. With everything else in place, move io_eventfd_flush_signal() to using the ev_fd grab+release helpers, which then enables the direct use of io_ev_fd for this tracking too. Signed-off-by: Jens Axboe --- io_uring/eventfd.c | 50 +++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/io_uring/eventfd.c b/io_uring/eventfd.c index d1fdecd0c458..fab936d31ba8 100644 --- a/io_uring/eventfd.c +++ b/io_uring/eventfd.c @@ -13,10 +13,12 @@ struct io_ev_fd { struct eventfd_ctx *cq_ev_fd; - unsigned int eventfd_async: 1; - struct rcu_head rcu; + unsigned int eventfd_async; + /* protected by ->completion_lock */ + unsigned last_cq_tail; refcount_t refs; atomic_t ops; + struct rcu_head rcu; }; enum { @@ -123,25 +125,31 @@ void io_eventfd_signal(struct io_ring_ctx *ctx) void io_eventfd_flush_signal(struct io_ring_ctx *ctx) { - bool skip; - - spin_lock(&ctx->completion_lock); - - /* - * Eventfd should only get triggered when at least one event has been - * posted. Some applications rely on the eventfd notification count - * only changing IFF a new CQE has been added to the CQ ring. There's - * no depedency on 1:1 relationship between how many times this - * function is called (and hence the eventfd count) and number of CQEs - * posted to the CQ ring. - */ - skip = ctx->cached_cq_tail == ctx->evfd_last_cq_tail; - ctx->evfd_last_cq_tail = ctx->cached_cq_tail; - spin_unlock(&ctx->completion_lock); - if (skip) - return; + struct io_ev_fd *ev_fd; - io_eventfd_signal(ctx); + ev_fd = io_eventfd_grab(ctx); + if (ev_fd) { + bool skip, put_ref = true; + + /* + * Eventfd should only get triggered when at least one event + * has been posted. Some applications rely on the eventfd + * notification count only changing IFF a new CQE has been + * added to the CQ ring. There's no dependency on 1:1 + * relationship between how many times this function is called + * (and hence the eventfd count) and number of CQEs posted to + * the CQ ring. + */ + spin_lock(&ctx->completion_lock); + skip = ctx->cached_cq_tail == ev_fd->last_cq_tail; + ev_fd->last_cq_tail = ctx->cached_cq_tail; + spin_unlock(&ctx->completion_lock); + + if (!skip) + put_ref = __io_eventfd_signal(ev_fd); + + io_eventfd_release(ev_fd, put_ref); + } } int io_eventfd_register(struct io_ring_ctx *ctx, void __user *arg, @@ -172,7 +180,7 @@ int io_eventfd_register(struct io_ring_ctx *ctx, void __user *arg, } spin_lock(&ctx->completion_lock); - ctx->evfd_last_cq_tail = ctx->cached_cq_tail; + ev_fd->last_cq_tail = ctx->cached_cq_tail; spin_unlock(&ctx->completion_lock); ev_fd->eventfd_async = eventfd_async;