From patchwork Wed Feb 5 20:26:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13961903 Received: from mail-io1-f52.google.com (mail-io1-f52.google.com [209.85.166.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 B24B5846F for ; Wed, 5 Feb 2025 20:26:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738787209; cv=none; b=tbRTbApJMf8vJ87nf9X3B60uYJgW8jHS5VovSj1ZlkyPzCsBjaurSLejupu5Vv7iLH2DLy7BqGE4gPIedBvzmPCaNn/bStBdMbf/5ZG3eLNIfbPpCd9GIz+dvsDYqtyqoXmJET2AU/VVZeAq1aur7imEiwOVeZ5G1kA2AUsSBDE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738787209; c=relaxed/simple; bh=XbXrFPR4SUQbYJLt5pV6inp6Pk3BI743HQarBjRbC7U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y+M5ZxkjumTbW4I/9PfhOqfnk24EtomWu3hvjBFbcJPEsTDkMiZkb4dbUS1WnghbdgWOCL6OAkFGv0wJRcVp2XNyUj4Zv6DgDJqjNicBR9YBY4AYkpzxS0Yg5RNzJXnmKvOAaJycLvobcUmQJt0WwbQS8yX5XbVrnAXFQX/I8kw= 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=ODqt8Yks; arc=none smtp.client-ip=209.85.166.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="ODqt8Yks" Received: by mail-io1-f52.google.com with SMTP id ca18e2360f4ac-844e61f3902so17218339f.0 for ; Wed, 05 Feb 2025 12:26:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1738787205; x=1739392005; 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=FWpQv0/6LvA/sNw8SE72PAuyQcKgPaKQsYMrFISK8xE=; b=ODqt8YksvuZGX92P4QuiA7K/u8a/8PFVQCDKLs8/dJHP0pKaCNPZMsEgQDe2Ek86qB rhbfZKUseQaFKxidgYyoZK0JDD7drL1KvZn5BnTClkuWWKNvrIRQwim8K2eakY3UCtPV MgrXhlL4qmPqXiBf/2rLj9kZKcxGL3wiwT8T2ot0if4WlDvxinMtIqjfAf3i/7kIagtG jp2KX/ePWZaqgi3RlTiEyjydryhQE/RgITaXBDb6wlfE9GY6yVIHeB0xzUX2xkm63WgP Dj3ZAAn3pCA9jgkppPyHtyulk0HMhBzFMZX6atf+OwkZvfl7QroGP9r9PtyYB/npvT4v 1bvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738787205; x=1739392005; 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=FWpQv0/6LvA/sNw8SE72PAuyQcKgPaKQsYMrFISK8xE=; b=Wd02kNYfd7zTHastREq98ShWK+1cm5PsR5Z0TdIH8pDxJ8z2kDtJipTtsNJ0w7Q5Kg r9FCahO3U2UQkrF3NFqkmcHQtWTQ2p9saM32pemqE3dYILM+yEisItRTEUv74VAiMuSk Pe0fbg8k7Lgd+Q6gF+KEhG6/cACMk87LwOdkQptlLVze8qLzYePfp8fVZd3W/5xJQVL5 ERVU4OaY/daQZC+PGidqaSzHk3+QIV5Clq89q02EimVbzmR86LY+BXzJewN6n/4FIlp+ wdNPfibD0v41T5zParDV0uQT5RoWJrpRXoEPSx2WWYFukd2x6idRsiFPNvG1rPj0rbcB OyNg== X-Gm-Message-State: AOJu0YxytmyAEV73sP2B1d+z6kyMHPyn84byc0JfztkwpVJMcPW8dKHH 8xGHp+oHqnLIr9TYeoVFYGum2DLLStphPbekedTKlPEKrzMoWdJEJcWqh7USNTRUjN/nxXc6Czs 5 X-Gm-Gg: ASbGncv9C93SWFi43qNTf0ns1on8QsrIsnuJ1CfW7WyaDfUi9skOQQigiU9txrv5Ual Hkediuy3h3bBxgb7P19eOEMG9bovnsX/3W+nXuIpZdIDrOvEbLXx+Hgn67m6Hv0ulDRMyVJRwZ6 2yqZ5rBjW67D9QBCWqE8n56kMhXnEnJE9Taxp9Lg4FQQ6uTN24bBPTBnvkvhhAdzAcH46mWQiH8 iCvSct1k/gRCpZZYgMrzEVhTJkYF1OLfZqXzLWe4VpLpynwWN6WziaghBi1p9d94BOLXI2ZaumK iVEHzRUchQhjalyrnsE= X-Google-Smtp-Source: AGHT+IGIgUHJY4O5eNa61WbrZN9BXML6Eb2GzoqwH42eWQ3au231qq+NCqwQpqyddDMqtAqPVEBAyw== X-Received: by 2002:a05:6602:3810:b0:84f:41d9:9932 with SMTP id ca18e2360f4ac-854ea514f79mr454306239f.9.1738787205124; Wed, 05 Feb 2025 12:26:45 -0800 (PST) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4ec7458ed51sm3352071173.23.2025.02.05.12.26.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Feb 2025 12:26:43 -0800 (PST) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 1/6] io_uring/cancel: add generic remove_all helper Date: Wed, 5 Feb 2025 13:26:08 -0700 Message-ID: <20250205202641.646812-2-axboe@kernel.dk> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250205202641.646812-1-axboe@kernel.dk> References: <20250205202641.646812-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Any opcode that is cancelable ends up defining its own remove all helper, which iterates the pending list and cancels matches. Add a generic helper for it, which can be used by them. Signed-off-by: Jens Axboe --- io_uring/cancel.c | 20 ++++++++++++++++++++ io_uring/cancel.h | 4 ++++ 2 files changed, 24 insertions(+) diff --git a/io_uring/cancel.c b/io_uring/cancel.c index 484193567839..0565dc0d7611 100644 --- a/io_uring/cancel.c +++ b/io_uring/cancel.c @@ -341,3 +341,23 @@ int io_sync_cancel(struct io_ring_ctx *ctx, void __user *arg) fput(file); return ret; } + +bool io_cancel_remove_all(struct io_ring_ctx *ctx, struct io_uring_task *tctx, + struct hlist_head *list, bool cancel_all, + bool (*cancel)(struct io_kiocb *)) +{ + struct hlist_node *tmp; + struct io_kiocb *req; + bool found = false; + + lockdep_assert_held(&ctx->uring_lock); + + hlist_for_each_entry_safe(req, tmp, list, hash_node) { + if (!io_match_task_safe(req, tctx, cancel_all)) + continue; + if (cancel(req)) + found = true; + } + + return found; +} diff --git a/io_uring/cancel.h b/io_uring/cancel.h index bbfea2cd00ea..80734a0a2b26 100644 --- a/io_uring/cancel.h +++ b/io_uring/cancel.h @@ -24,6 +24,10 @@ int io_try_cancel(struct io_uring_task *tctx, struct io_cancel_data *cd, int io_sync_cancel(struct io_ring_ctx *ctx, void __user *arg); bool io_cancel_req_match(struct io_kiocb *req, struct io_cancel_data *cd); +bool io_cancel_remove_all(struct io_ring_ctx *ctx, struct io_uring_task *tctx, + struct hlist_head *list, bool cancel_all, + bool (*cancel)(struct io_kiocb *)); + static inline bool io_cancel_match_sequence(struct io_kiocb *req, int sequence) { if (req->cancel_seq_set && sequence == req->work.cancel_seq) From patchwork Wed Feb 5 20:26:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13961904 Received: from mail-il1-f175.google.com (mail-il1-f175.google.com [209.85.166.175]) (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 0A5421FFC61 for ; Wed, 5 Feb 2025 20:26:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738787209; cv=none; b=VB3zNy1ln6HX0W549fhORvbkZfrhI3JFidpKbTSZlqWq9boPZaGnGl5A7vOGOmshYejFHCFGP22psE/FxdomEQTrODlJHJVtlxkjz1oBBIlZnT+J0xXYD9Ewpd+7vTWc4V1rF4Y+Hk9M4VhHZ+HXY0uzYWam3DDNgNTJPWB5xTw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738787209; c=relaxed/simple; bh=BaG0fC8mluz5KK+jZ5W5qp6lqQP67PRE8cYYmd9FqE8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mMF1EJmn9SDt0lat0E6HnCFOpuEEhpd+XO7cgXOoqruEvRT9AmmIfIo+9Oq11KTv57SsfVLIApdDoBpUBQ7/Az2US1bk7nT3N2D0lHGFcMakZCIs0D4NM717e82t9M+zW11W44ZGwnNfWd+CEM2uG+5DmcmzI7QaY5LTGjqiWL0= 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=0m6u4qnr; arc=none smtp.client-ip=209.85.166.175 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="0m6u4qnr" Received: by mail-il1-f175.google.com with SMTP id e9e14a558f8ab-3d05b672ee6so304815ab.1 for ; Wed, 05 Feb 2025 12:26:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1738787206; x=1739392006; 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=YIwFMglSOtaxOsPT8tG38CRBLxBiRH/jcEcw4vmicEE=; b=0m6u4qnr80OC0jqVyz4Ngp36N0Zbajq9nnpJsFiST/dA+rK9SBd5UtHZLLtb5LQ0OL SoOeNgnyrZM+/0QrvRDJndyYRitxIsYpr6xE+8moF9Q3q46cDrty7W/dF9aqPDQB0fV3 qpElSSbaqKQ24s6N1l3Xt15SDa2H+oZYrxah4zQLFsPQz66ThEzXaDGQd4HCmV3eGhnN dIBGV9VEscB9p+BAm/7GOitSkVnu/wjCywt1vZAv+AGSEoAInPnfYJjYuWrF/CsHkUKF gs2o8lPrkS1885FcASJkqFOWREJNkZnM4k+DKTYK5rbXBhIFKCK/sOU51+19o66IJxuJ 1yoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738787206; x=1739392006; 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=YIwFMglSOtaxOsPT8tG38CRBLxBiRH/jcEcw4vmicEE=; b=VfSwpWwf+YiODjyFWZBQvaL3YONyEfLJ5MJgcqKdciTpPxe1ob5j3IAqTXw7Ca6Omk 7bKbNjHa3EQrrOXEXhsT5q3Au5C+RjLmU+iZVVSMvfsxpTw15M1yQgceMP5EyNa9dpW9 BZU0CvhogMi+VA8osF5kWknsEPKL1KQbMBmn/jO3KLIVwm3jUFugWvaeETjvIuhHr9uH rSRzEj3fRtMLrtJ8KK+Hyc6PU08ubxjouVf4Acyk5QA0aMrkt3WJnztV+AJMthLFzyQC hxXgXgsAhHlpyX9a6d6SB/m5n5fYYzj27NVebNx4Y2a+1cQg/IxoY7oxB3fmqJmVf9B+ JZqg== X-Gm-Message-State: AOJu0YzRj/RXC0gEWBikRAMESUu4xuEDdvaPMumTaeWg9cLbcnl/NBYv OoPXG8xDHC9nktkjLWoKt8Mzk51bO57jPPyBo1sIoBF6/aEDck8JAWj2kzDhF2OaYWgVus73KHt K X-Gm-Gg: ASbGnct1xc+fjLFwiKYY6zRGV/UfdaVtUpPD4D9oANQ2l6EmTfr018UcVBZRYnat1xm BfXhRa5NwL0QcoLidLLnI6P1qvhFOOEVmiDSAziRGvM3uhIY4o1Epm0VYzXwjr9pvyh+vAs5ZY0 ztnY8VbazjKaIPZX94bY6V6th8TEtihb8Uc9yDJpgisr/1UXdl9+4OaM5hWiAc6J+2Ks0zMw75g 4cPYstTiXjUKYfmF7Xw9ahrwmQwrDtI8WPqeOn78t1UpNDw0px4n9MLLeH2E+hQ42dWOFI0hQ73 Y0WBfy4OLA0MPzdO4Xc= X-Google-Smtp-Source: AGHT+IGky6IrdcLrmZxqvOb3hvV2shJ170EyL51zhdUSUFSxfSIdEQVufiNdlqOUXl83+BFA8ChsDA== X-Received: by 2002:a05:6e02:216b:b0:3a9:cc7f:2bc5 with SMTP id e9e14a558f8ab-3d05a56c270mr9547515ab.3.1738787206578; Wed, 05 Feb 2025 12:26:46 -0800 (PST) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4ec7458ed51sm3352071173.23.2025.02.05.12.26.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Feb 2025 12:26:45 -0800 (PST) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 2/6] io_uring/futex: convert to io_cancel_remove_all() Date: Wed, 5 Feb 2025 13:26:09 -0700 Message-ID: <20250205202641.646812-3-axboe@kernel.dk> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250205202641.646812-1-axboe@kernel.dk> References: <20250205202641.646812-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use the generic helper for cancelations. Signed-off-by: Jens Axboe --- io_uring/futex.c | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/io_uring/futex.c b/io_uring/futex.c index 3159a2b7eeca..808eb57f1210 100644 --- a/io_uring/futex.c +++ b/io_uring/futex.c @@ -90,7 +90,7 @@ static bool io_futexv_claim(struct io_futex *iof) return true; } -static bool __io_futex_cancel(struct io_ring_ctx *ctx, struct io_kiocb *req) +static bool __io_futex_cancel(struct io_kiocb *req) { /* futex wake already done or in progress */ if (req->opcode == IORING_OP_FUTEX_WAIT) { @@ -128,7 +128,7 @@ int io_futex_cancel(struct io_ring_ctx *ctx, struct io_cancel_data *cd, if (req->cqe.user_data != cd->data && !(cd->flags & IORING_ASYNC_CANCEL_ANY)) continue; - if (__io_futex_cancel(ctx, req)) + if (__io_futex_cancel(req)) nr++; if (!(cd->flags & IORING_ASYNC_CANCEL_ALL)) break; @@ -144,21 +144,7 @@ int io_futex_cancel(struct io_ring_ctx *ctx, struct io_cancel_data *cd, bool io_futex_remove_all(struct io_ring_ctx *ctx, struct io_uring_task *tctx, bool cancel_all) { - struct hlist_node *tmp; - struct io_kiocb *req; - bool found = false; - - lockdep_assert_held(&ctx->uring_lock); - - hlist_for_each_entry_safe(req, tmp, &ctx->futex_list, hash_node) { - if (!io_match_task_safe(req, tctx, cancel_all)) - continue; - hlist_del_init(&req->hash_node); - __io_futex_cancel(ctx, req); - found = true; - } - - return found; + return io_cancel_remove_all(ctx, tctx, &ctx->futex_list, cancel_all, __io_futex_cancel); } int io_futex_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) From patchwork Wed Feb 5 20:26:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13961905 Received: from mail-il1-f172.google.com (mail-il1-f172.google.com [209.85.166.172]) (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 68DD11519AD for ; Wed, 5 Feb 2025 20:26:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738787211; cv=none; b=amEadifTwydt3mv5kbycEIR871sZi3fOEp1yEyzb0dE2Wd4J7IwRVigdYLC2gf117AtdbrpmUq4hUutGvScvKVsBSLO4FKZBa2Gig9YLZdBpsH59pKIQa7xTm2o15UW7kUYBNWtNmuz75ljLWaKITKR2TxvvnhyCgQW3NoX9Iv0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738787211; c=relaxed/simple; bh=XTlAYiw5UKAMNfS75alH+uIT5uySR0K5F0uAEM5VvdU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aEvNn+vC5B4zrcLBfRdCXW+nfwlbJCget4zdtKq564HlzInSqJ0DsS2PE3sd6aOSC1AiLBxFVqfL2Dfvk25yebrabDqXqMa4tJi8f7JLoFnYb2o4foXG6xlKGoN7ZbDjESCjwbUWC5xv10uff1DiUNMkjNKXGXkxgWEQ6SZMhW4= 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=Xhz3cJfS; arc=none smtp.client-ip=209.85.166.172 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="Xhz3cJfS" Received: by mail-il1-f172.google.com with SMTP id e9e14a558f8ab-3d051dca3b6so539495ab.1 for ; Wed, 05 Feb 2025 12:26:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1738787208; x=1739392008; 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=Rs2bYp+mu5LOxnJJsb9Nh078jFzipYdZ38rrKzvGzEA=; b=Xhz3cJfSQh4mzgwcgQHVDPD6SvXGyheIcKoIFfVpKyGTIodv/IwPkVAp/M0Tzye3hY N488hlhMWq5YQMxYhj+V7z4PAGTt7nQzKoUjw9V181Ewtvu+Iu8jev7MPzClaflbUQs2 oWacqcWYmMJdmd72aWhH/lmwoXW1qAkyPtKW6TEp8UILUU/UV/KO8Vbtj4oA4jbWiLHi /5OKJVaFmKyzS5o4c9foKeOVcRiHHpnaXBWdIsmUmdgXQEbNKFp21KzSF934WRHfw8ug opTlULRO85hp4hT8cwlZfh3GqzCmwGEl5vh94iORyFAN9p7aP4lvxc0TsoLBbGuQ2wju CuKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738787208; x=1739392008; 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=Rs2bYp+mu5LOxnJJsb9Nh078jFzipYdZ38rrKzvGzEA=; b=Y1/2UaHivoYzFv3/IcZIH+6mv+C05VSQ4Q1YdbkUMJV4ZwWub/+Fc70EgYKSSSYpbP xy/OGQjobke5/HudlLxGlQiWJ4zbDo3/w1LVSHS4CGzfuyTYDgWDKQNDWGtORgdKeOk/ iyPbWOCQ9XLsD6xDbu2eTlHLEJMhq9xhLOM2hK8a65xqGYuf73rfrcK08PAQWnYEHVtF dxgRE9ke/vC+CDSY1J1S44nv7W9fAbV1oDnEJPCGHW6MLi+i9pNoPR+GO4kdZVWKej3r 3UmT2rGpLxx1y6/QY3Ag9xwUpAwjJF1kKHWIFMchH2SVkfetIkZiUcIYQxjE/p3QJdwq 9mBQ== X-Gm-Message-State: AOJu0Yxzc+rqgltDFsfIABPjLRxrBlXlOJueeeorn82m5+rYFeUdmTnL 7SYO4Z8VkysakMeId5sLoCh05bY8JllmSFBOCx94ux+UEiNvKFtTIOGqpMhnklxbwI0ZpXvpsyU E X-Gm-Gg: ASbGncv0tZNjbd3y9NmSyYZtYDnPjoIBnXWvGrmt0FodxjPxugouQ6FlWQ2CS4xo9Mm NBPpsDiHFBc03r8B5+chXmCNra8RDtI2f8PeJrjGCKm2xlDvBu5iGF0fn1LGGQ0yyReqOxVsrqr A63nwHuhtHrMJOxQQFsBfPj0ANk0c0u3i6c6xel31osx6Ra001a9Vs2ribRuAS/wE5uX4znIaAQ qABLBVH/YGgeaQG+uiCIYE5hSHg+URYScX0poOJbvdGxf9TR2qLE6gmXx93IFFEVHToPCWdGu4o DljYZfB7tpDs3t21QGE= X-Google-Smtp-Source: AGHT+IEXUjZKKsNuKThvEY5zv+hDPxB+J5aaArYiNIZV/6eRu5dRxmzAx5UFUnc1POKfyghbMwqIOw== X-Received: by 2002:a05:6e02:1746:b0:3d0:24c0:bd37 with SMTP id e9e14a558f8ab-3d04f459238mr38569475ab.11.1738787207975; Wed, 05 Feb 2025 12:26:47 -0800 (PST) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4ec7458ed51sm3352071173.23.2025.02.05.12.26.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Feb 2025 12:26:47 -0800 (PST) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 3/6] io_uring/waitid: convert to io_cancel_remove_all() Date: Wed, 5 Feb 2025 13:26:10 -0700 Message-ID: <20250205202641.646812-4-axboe@kernel.dk> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250205202641.646812-1-axboe@kernel.dk> References: <20250205202641.646812-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use the generic helper for cancelations. Signed-off-by: Jens Axboe --- io_uring/waitid.c | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/io_uring/waitid.c b/io_uring/waitid.c index 853e97a7b0ec..ed7c76426358 100644 --- a/io_uring/waitid.c +++ b/io_uring/waitid.c @@ -134,7 +134,7 @@ static void io_waitid_complete(struct io_kiocb *req, int ret) io_req_task_complete(req, &ts); } -static bool __io_waitid_cancel(struct io_ring_ctx *ctx, struct io_kiocb *req) +static bool __io_waitid_cancel(struct io_kiocb *req) { struct io_waitid *iw = io_kiocb_to_cmd(req, struct io_waitid); struct io_waitid_async *iwa = req->async_data; @@ -171,7 +171,7 @@ int io_waitid_cancel(struct io_ring_ctx *ctx, struct io_cancel_data *cd, if (req->cqe.user_data != cd->data && !(cd->flags & IORING_ASYNC_CANCEL_ANY)) continue; - if (__io_waitid_cancel(ctx, req)) + if (__io_waitid_cancel(req)) nr++; if (!(cd->flags & IORING_ASYNC_CANCEL_ALL)) break; @@ -187,21 +187,7 @@ int io_waitid_cancel(struct io_ring_ctx *ctx, struct io_cancel_data *cd, bool io_waitid_remove_all(struct io_ring_ctx *ctx, struct io_uring_task *tctx, bool cancel_all) { - struct hlist_node *tmp; - struct io_kiocb *req; - bool found = false; - - lockdep_assert_held(&ctx->uring_lock); - - hlist_for_each_entry_safe(req, tmp, &ctx->waitid_list, hash_node) { - if (!io_match_task_safe(req, tctx, cancel_all)) - continue; - hlist_del_init(&req->hash_node); - __io_waitid_cancel(ctx, req); - found = true; - } - - return found; + return io_cancel_remove_all(ctx, tctx, &ctx->waitid_list, cancel_all, __io_waitid_cancel); } static inline bool io_waitid_drop_issue_ref(struct io_kiocb *req) From patchwork Wed Feb 5 20:26:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13961906 Received: from mail-io1-f45.google.com (mail-io1-f45.google.com [209.85.166.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 C2BA41FFC61 for ; Wed, 5 Feb 2025 20:26:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738787212; cv=none; b=DN2hDg/DApJjsBpdWIX3RDbNeWngQP5FpCKbbxGDOFnJbeVAlEck65Xx5ZRn3prS5MFUlkroj4WhQqRZ2cqKVdXkis5wKarHBkUImJZFndlc6ipOtWABgnW1aBkiftD64h+me4LH+vachs0JLWDHoIlygS7PpNaDyXIbq7ndDoQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738787212; c=relaxed/simple; bh=VSh/qgctDDo70xZToc2xt44ObMTteCk44UQDOLdRMfY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QKPxiOYkjaAUPhXPUQ3SBMJ8IVeXeYOBvNr1cxAxB1akNfDdfI4oawB8TNAc8aUBcqqvpwyWnmBTQFl/u+zxQIJDC3pg8oDS2WYYy3fAlpNQKOQe3Slc27ub5FGZ0FuQtl4zN98G8n3Mu+nNm+LIIaY+wF9S9e3ZLku2QQqI164= 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=waGbaed6; arc=none smtp.client-ip=209.85.166.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="waGbaed6" Received: by mail-io1-f45.google.com with SMTP id ca18e2360f4ac-844df397754so7043939f.2 for ; Wed, 05 Feb 2025 12:26:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1738787209; x=1739392009; 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=9w38RAf5sLwFs/ZAYF5KaZ561nlRfCQe/pBXsxlr91I=; b=waGbaed6qFDGkoMp+3IJW94Z0tcKhSm1nCGvgNS8ulTWgEl+emt1HicdG6i8mkr1XB pnISdGM4n7W/sSRbeIpE2ynbVz9c3UM3YKkT85dWsLGh7WeEGBfW5Epdwlfnq0mIstK5 oodtYRN1gN6TwokuDswsNjQEMvrUsE/yCcH7XNQi9FCgtc6Z/35Dwwhn+gd0oBDDzD8C ITFySSDD6mHNxEjSrrLrE+g5nCJLthlfhBBDb3MDwUXM5uLNFpU7NqDnlm6PcqODim7H YX8IJBfWuzsVlj2jAe/AHF48Ktnx3HtMSBTUKwRGtcOOqgoUiAuZ21jJOL+iHt95xjao zmJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738787209; x=1739392009; 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=9w38RAf5sLwFs/ZAYF5KaZ561nlRfCQe/pBXsxlr91I=; b=V4zQqWkh0mQlRATMEXCp4QHal+7ddYglNzAR9roa1HJZ73jkLj0QJf1EtnnZdgyuMm QPNQ7mgY8QjKAWgBwMJxO0BRDkLyIt3ejtIN0O+120buVKsWHcwT71s4U4nYA6K8f0/G af6l+fivxWUVDxfle/EIsgIN/Zd1lKbYfpi4M6yTGsk4N1DC1Q+RuDQR/IAicw+O0V9f bbn9vUQNADQFgmsWaS5z5NV4qL+5XBfqQqcACF/XLFXPpTIIGeHrWCuNgAu0eIpiQVfF 8mjfNUWiCZ5IQR00WCljdPLet+3u+vetox1xRzp/3Db6AqCItzzlQPkn1gzHVbkoKRgl yagQ== X-Gm-Message-State: AOJu0YxKB7YxbIPnPooFUuvAsE2ph9irpBTtpJd7HGsHsGFqCT0Pdgk2 oEpaqueSbATAa3PeV4nnAkHvU6i2KEpFHdD+5o0gXiW3RrffKHe+oYfVTnCS68ndISJ/og1wQsE g X-Gm-Gg: ASbGncs0UHekV1aPd8o7/+8SuuHblQPD68bzVkjAxpggpH72jwn4n82yyW56evlLehe WCBNJE6NYlquWRwvgRjnPkDq9VozoJhDYfcoEUrD8FjxekUOjMW4OHWfZ8IJa8jTC7yu3k2p4RI kUsy//hx8QWDYJNnmBaK7NLne6FYCrsO/IzTTKPjjLtWtrPJ1ZVb9Ed0Ry35ho8NWK5XoXptsLx QKkn0Bw9KRVzqeHsjwPOVVveYmJA2df70u3N3o0b3nt2Uhn5PYOd+UBGYzNI4O/Eq7Ybx6nTaoq R0m5Frsm7LPA5UUelw4= X-Google-Smtp-Source: AGHT+IGmuMVnewpmLgLianVG4flO1vjA12na7iPrShrn9Yjp97PhsDXU2y2Ms3mXHJqxVfoAkBeOgw== X-Received: by 2002:a05:6602:750e:b0:843:ec8d:be00 with SMTP id ca18e2360f4ac-854ea5188ccmr438213139f.13.1738787209453; Wed, 05 Feb 2025 12:26:49 -0800 (PST) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4ec7458ed51sm3352071173.23.2025.02.05.12.26.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Feb 2025 12:26:48 -0800 (PST) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 4/6] io_uring/cancel: add generic cancel helper Date: Wed, 5 Feb 2025 13:26:11 -0700 Message-ID: <20250205202641.646812-5-axboe@kernel.dk> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250205202641.646812-1-axboe@kernel.dk> References: <20250205202641.646812-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Any opcode that is cancelable ends up defining its own cancel helper for finding and canceling a specific request. Add a generic helper that can be used for this purpose. Signed-off-by: Jens Axboe --- io_uring/cancel.c | 21 +++++++++++++++++++++ io_uring/cancel.h | 4 ++++ 2 files changed, 25 insertions(+) diff --git a/io_uring/cancel.c b/io_uring/cancel.c index 0565dc0d7611..4ff3771131c2 100644 --- a/io_uring/cancel.c +++ b/io_uring/cancel.c @@ -361,3 +361,24 @@ bool io_cancel_remove_all(struct io_ring_ctx *ctx, struct io_uring_task *tctx, return found; } + +int io_cancel_remove(struct io_ring_ctx *ctx, struct io_cancel_data *cd, + unsigned int issue_flags, struct hlist_head *list, + bool (*cancel)(struct io_kiocb *)) +{ + struct hlist_node *tmp; + struct io_kiocb *req; + int nr = 0; + + io_ring_submit_lock(ctx, issue_flags); + hlist_for_each_entry_safe(req, tmp, list, hash_node) { + if (!io_cancel_req_match(req, cd)) + continue; + if (cancel(req)) + nr++; + if (!(cd->flags & IORING_ASYNC_CANCEL_ALL)) + break; + } + io_ring_submit_unlock(ctx, issue_flags); + return nr ?: -ENOENT; +} diff --git a/io_uring/cancel.h b/io_uring/cancel.h index 80734a0a2b26..43e9bb74e9d1 100644 --- a/io_uring/cancel.h +++ b/io_uring/cancel.h @@ -28,6 +28,10 @@ bool io_cancel_remove_all(struct io_ring_ctx *ctx, struct io_uring_task *tctx, struct hlist_head *list, bool cancel_all, bool (*cancel)(struct io_kiocb *)); +int io_cancel_remove(struct io_ring_ctx *ctx, struct io_cancel_data *cd, + unsigned int issue_flags, struct hlist_head *list, + bool (*cancel)(struct io_kiocb *)); + static inline bool io_cancel_match_sequence(struct io_kiocb *req, int sequence) { if (req->cancel_seq_set && sequence == req->work.cancel_seq) From patchwork Wed Feb 5 20:26:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13961907 Received: from mail-il1-f182.google.com (mail-il1-f182.google.com [209.85.166.182]) (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 303C01519AD for ; Wed, 5 Feb 2025 20:26:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738787214; cv=none; b=trl0S6YUHhb9/DwHv65SShDjwXsLtr+ZsuldiJa47dQT+bwymJNqO5HeIPQwp4VxsO7WiQUoYL0z0nRHZ/Myh5z5hnEnG2OW81hymEYK3wdEUjFPwhgUIdO56hQtcH8TYrzC2V3ZhjGCnxTNHO8p6fu2j0V6/fKsmpkohHSpIzw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738787214; c=relaxed/simple; bh=JvgOl6fhWtHjM/9fdnV3rMW77gb/+BxjpwZhpMiIXNM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ifAy3RmZjugKrNmn83vIaBaXoJzwWCfCh9niZEWvJvJWzMm9fP81SpymQ+SNHbsLgrDdpiCM3JN9SAoTrSfiqMPXxn+F5o+ejjlvP8gYvvMHISEtuRAxCIDCbNTApU6WRlPi0Y3iQphQ9aTFUanhAQ80MdqW3zGV4mI9Iv809W4= 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=n+r1szEk; arc=none smtp.client-ip=209.85.166.182 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="n+r1szEk" Received: by mail-il1-f182.google.com with SMTP id e9e14a558f8ab-3d04e7f284aso575755ab.0 for ; Wed, 05 Feb 2025 12:26:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1738787211; x=1739392011; 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=/1wpsdoKO+e203lnxZDiW2FYjIL66DuwOXiWNJha8FI=; b=n+r1szEkE6IO4sjUiL8l9TF9BqzllNobHTmS3Q9jUXHvIW9OONS0a/E4s/WUt5apHp JwqG1XjhHue4MaInYjRETvYfbJkXntRl8pBDHNIQcZrzTu6P4qN0VD0MjPzWUSP8qrA+ TKaAbpRcMM9kla4oIvQZLDI3VufX1sejkl6I5sjyTi+cEQvYlJu8d2BHOcgvqB3pwzWP V7335VKwU6FO5zg0CIwTYmjcYorjYb/bBKLFyU0vlFYIswr2QadbbwzAD9DKcsc8WFr2 1p6Rxpg2p17sj6tQvxgC8CW2aOXJaRLpd3EabUhqY8/cicsskTAMbmw59pH5mfLSgVtm jn+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738787211; x=1739392011; 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=/1wpsdoKO+e203lnxZDiW2FYjIL66DuwOXiWNJha8FI=; b=KAgjgl6FYhCdYbe/8UwvarGwk8kRpfERSdB0RA8cpOByvBpVrAcxaRUhgsHvfcrv6g OhNB1ulcv/NoOIhpcp4KPguNEPjWfr7BlMYBD+sBQKUlt01vQIQ2q8EmW9hdeYcpXKJ7 f5VE6N5gjCszIsR0HvNF7cDFT4YbQ6s0sC2fZjsHZPNCYZnvIYeBLQuR8V+kXNKtv18v OUC42HmQLWEpaucdqk7Jb0k9aXny/lAuSXvMeAUq0LXty8chmqlc94SLft/gA7XzRDk4 BDWJC9N/SjXRDg8qA8TO3tFFyMsF+PUFVNbAH7dcP+UFEDO805b8aGPf6UZZvYDfIOPp XiVg== X-Gm-Message-State: AOJu0YyzJT5k64vqx2SIqjZp9z1mzVlAGiTHcUzSi9PanhBxLi9u971v qRdyoLdPihRhVX+YywtPFCrrriFAA5XE/iFaslA0+VhfjRhCdbN39ePwNsBP19vC9oXnF/rxBfm 5 X-Gm-Gg: ASbGncsgM+ycLh/8dXdTxZFGkKGElVLoydIUwCPEfsi7S9a0OEy6JxqCC1GJ0Ea4qVC TPpa++bFtzxrdX6xbfoaxlvBd+Y8PTgeoHlahSJlpiEHYtQimoRt3qowDGD0BpftO+xHlIkGRXP HIKxoq8H70Sx991AKUvHwgVRyYwBpkUrLWGm8icBUKIJ+2YqZ4pPDY38MV9FcAl9p32ZX20IwsA 5kyK4dhDfoG5GEnWoz805mrjvj1Ft3JQQCQjr7wAuZjLCNa/98fsHFthSZnDKZ0pAV7QzLEhXYk Hz6maLIej645U9v75Jw= X-Google-Smtp-Source: AGHT+IGSEfvT/OcL29G5bcrhzNEf/bzbVzKhqQMNEVccCa+byXLsFAwqexrHc5geqn3d/EVnivEaOg== X-Received: by 2002:a05:6e02:2183:b0:3d0:1abc:fe03 with SMTP id e9e14a558f8ab-3d04f91b165mr37882505ab.15.1738787210693; Wed, 05 Feb 2025 12:26:50 -0800 (PST) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4ec7458ed51sm3352071173.23.2025.02.05.12.26.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Feb 2025 12:26:49 -0800 (PST) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 5/6] io_uring/futex: use generic io_cancel_remove() helper Date: Wed, 5 Feb 2025 13:26:12 -0700 Message-ID: <20250205202641.646812-6-axboe@kernel.dk> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250205202641.646812-1-axboe@kernel.dk> References: <20250205202641.646812-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Don't implement our own loop rolling and checking, just use the generic helper to find and cancel requests. Signed-off-by: Jens Axboe --- io_uring/futex.c | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/io_uring/futex.c b/io_uring/futex.c index 808eb57f1210..54b9760f2aa6 100644 --- a/io_uring/futex.c +++ b/io_uring/futex.c @@ -116,29 +116,7 @@ static bool __io_futex_cancel(struct io_kiocb *req) int io_futex_cancel(struct io_ring_ctx *ctx, struct io_cancel_data *cd, unsigned int issue_flags) { - struct hlist_node *tmp; - struct io_kiocb *req; - int nr = 0; - - if (cd->flags & (IORING_ASYNC_CANCEL_FD|IORING_ASYNC_CANCEL_FD_FIXED)) - return -ENOENT; - - io_ring_submit_lock(ctx, issue_flags); - hlist_for_each_entry_safe(req, tmp, &ctx->futex_list, hash_node) { - if (req->cqe.user_data != cd->data && - !(cd->flags & IORING_ASYNC_CANCEL_ANY)) - continue; - if (__io_futex_cancel(req)) - nr++; - if (!(cd->flags & IORING_ASYNC_CANCEL_ALL)) - break; - } - io_ring_submit_unlock(ctx, issue_flags); - - if (nr) - return nr; - - return -ENOENT; + return io_cancel_remove(ctx, cd, issue_flags, &ctx->futex_list, __io_futex_cancel); } bool io_futex_remove_all(struct io_ring_ctx *ctx, struct io_uring_task *tctx, From patchwork Wed Feb 5 20:26:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13961908 Received: from mail-io1-f54.google.com (mail-io1-f54.google.com [209.85.166.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 46D0C211A0B for ; Wed, 5 Feb 2025 20:26:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738787214; cv=none; b=KydloR1THBUBBUuhGVb4yS9u7m4WjZ5M+iO2xr8UfgcyegT5VI0rEGsoPnPQ2logwDnixeE/+AsiTZ2CzrMnKyJLV2+0hgiUhrmPO9kxUmgOFfdr4CGL2sOp86QYn+AwWyPK9W8Ons9EMYru7DlcbZ47GBaXEonrKkFkUzvdIrU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738787214; c=relaxed/simple; bh=42bNpDZeuVDAuMUQFLIssqZ9JSXExnqO5Lq8mGUQLug=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=H2sdnhS2eniUoBEcvnx+AeSmlbDTDIJJ26EyklwAhs7Rw3+SQpORQiPLkfkVt5b5SP0VdzwOYLLolxm+tWEFB64Mmfn/Wd49lQMWN0tTKsMfrEPh5vyMr14PGZPjyCrQShThnp8aQlmYZALt6lGpKQl/XXExH/zkmNRLcl+g+rU= 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=ppDfKdVg; arc=none smtp.client-ip=209.85.166.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="ppDfKdVg" Received: by mail-io1-f54.google.com with SMTP id ca18e2360f4ac-84ceaf2667aso13671739f.3 for ; Wed, 05 Feb 2025 12:26:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1738787212; x=1739392012; 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=vba7+r7gu6BsgHeCtt02tOKMD0rn8QytXeaRi/JBOmk=; b=ppDfKdVgSQfcfcns3ci2o8I5yoDH34juiH2mf1XjQQTa8LyBD0j81copUsaC+PExEK MQ2f/fd+OmDJT7rBf0WqX2neATfAgWg7SgWMDxLjTzTovrSIj8suU9eQxo1mecPh2l3m +UaTv+j1JrMVjcGGOHzMgPsQXUWp2S+Una1kNXjJ9kVA7zgDGTS5zv6Yvi7r5sDRrWHh fMnj6QkZX5dXwIJamFsq2fsYMpgPm/jtiVdSHRkM5yOIfQRaczHCOuB3D0ctV6I4AEUJ oKGCDdLwWQBn8ashP+hEBve1xiqKVNdB+TsCoRmceUgUnqQW55NboX+dbcfC/og6t3ww N3Jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738787212; x=1739392012; 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=vba7+r7gu6BsgHeCtt02tOKMD0rn8QytXeaRi/JBOmk=; b=q3DNanp7VbmKW5jmxdTgAOMISyhU8YfEtkbV/EN5ORQ90CZlZKBz1y9gXU+IIsmjzn mLdvuDM/Ewl4h7AmuDXZUpFwDs7jMrwMxPhDMPikUAVOxrmNjuDuF6bnCk4L0HdXHsuC TnfWOfMzfy1xufnBAMOX2uLjgELfwtoQXbcfBlfqkZLSyiFC5Ox/88Zb6uXEA2hNclkO /0RTf/n9jgMfOPMZrTaS/+nvfcxpuOxLRe+x3WJb1bLELrg2xBw15+Fg1tCT84h152GE iv9k4pUylhlGvQ2k53bpgBJ3thF8wRsMf40IcBr8k7N9GXWMpLgAiF21/ZbGnwIhBckr ChSQ== X-Gm-Message-State: AOJu0Yzz8+FTQAMtR003f+gXjUUlvbCVD5WCt+62ryr5MCI6TzEiMdrJ jeM/edIatkLYzFYxCrulnwEitlcKiuDqjNbUWdVbRh9rS0s46kG3gydl0eb8dMFkC/iMZNtnqt1 B X-Gm-Gg: ASbGnctmx7843ggISSaWunrDYC52rbLjBxgjOGpNc1PCOyxSjGbEGNt3viBglr38DC6 tF7z3f8CFN3sof65pk7iUBOJ4y/VCsux08oPvxa/sESeXmqB5lyjNvFyQIvOF75CdhyYGDA4bDN AqwUp0Np0u+JFajfoZBk+uD/WCZSKm5Bbh2UqNorJxdUB9BtH7BflYV+z+D3cdG197HR3Mjq8Tr I3qAGRo42hWY6mt4JoZUgHmmtZxqg43N9wAK+a/6o9o5wmF/2yChZ6gi8fDpyUqIrjqRSccsPT5 7CaB4OlbUhdMmxs0TRA= X-Google-Smtp-Source: AGHT+IH1Sy8dutgN5WJ3P5+RSU2YarbbZz2xOryZ7hURKMJ5X90tbOtSkLenpAQeqjHA50Ru1Zl9rw== X-Received: by 2002:a92:ca0a:0:b0:3cf:cd87:1bf9 with SMTP id e9e14a558f8ab-3d04f97d889mr38331725ab.22.1738787212072; Wed, 05 Feb 2025 12:26:52 -0800 (PST) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4ec7458ed51sm3352071173.23.2025.02.05.12.26.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Feb 2025 12:26:51 -0800 (PST) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 6/6] io_uring/waitid: use generic io_cancel_remove() helper Date: Wed, 5 Feb 2025 13:26:13 -0700 Message-ID: <20250205202641.646812-7-axboe@kernel.dk> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250205202641.646812-1-axboe@kernel.dk> References: <20250205202641.646812-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Don't implement our own loop rolling and checking, just use the generic helper to find and cancel requests. Signed-off-by: Jens Axboe --- io_uring/waitid.c | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/io_uring/waitid.c b/io_uring/waitid.c index ed7c76426358..4fb465b48560 100644 --- a/io_uring/waitid.c +++ b/io_uring/waitid.c @@ -159,29 +159,7 @@ static bool __io_waitid_cancel(struct io_kiocb *req) int io_waitid_cancel(struct io_ring_ctx *ctx, struct io_cancel_data *cd, unsigned int issue_flags) { - struct hlist_node *tmp; - struct io_kiocb *req; - int nr = 0; - - if (cd->flags & (IORING_ASYNC_CANCEL_FD|IORING_ASYNC_CANCEL_FD_FIXED)) - return -ENOENT; - - io_ring_submit_lock(ctx, issue_flags); - hlist_for_each_entry_safe(req, tmp, &ctx->waitid_list, hash_node) { - if (req->cqe.user_data != cd->data && - !(cd->flags & IORING_ASYNC_CANCEL_ANY)) - continue; - if (__io_waitid_cancel(req)) - nr++; - if (!(cd->flags & IORING_ASYNC_CANCEL_ALL)) - break; - } - io_ring_submit_unlock(ctx, issue_flags); - - if (nr) - return nr; - - return -ENOENT; + return io_cancel_remove(ctx, cd, issue_flags, &ctx->waitid_list, __io_waitid_cancel); } bool io_waitid_remove_all(struct io_ring_ctx *ctx, struct io_uring_task *tctx,