mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] io_uring/cancel: futex and waitid cancel results
@ 2026-10-24 16:31 agxr
  2026-10-24 16:31 ` [PATCH 1/2] io_uring/cancel: count all canceled futex and waitid requests on CANCEL_ALL agxr
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: agxr @ 2026-10-24 16:31 UTC (permalink / raw)
  To: Jens Axboe, io-uring; +Cc: agxr, linux-kernel, Josef Bacik

io_futex_cancel() and io_waitid_cancel() return the number of requests
they canceled, where the rest of what io_try_cancel() calls returns 0.
Commit c74193430feb ("io_uring/timeout: don't end a linked timeout with
1") took care of what that did to a linked timeout.

liburing's futex, waitid, io-cancel, sync-cancel, poll-cancel-all,
cancel-race, futex-kill, link-timeout, timeout and poll-cancel tests
pass on both patched kernels. Unchanged liburing tests pass with patch
1 and fail with patch 2, where they check for the 1.

agxr (2):
  io_uring/cancel: count all canceled futex and waitid requests on
    CANCEL_ALL
  io_uring/cancel: complete single futex or waitid cancel with 0

 io_uring/cancel.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)


base-commit: ecb6817b769fd7d71af2c9f446188649020b2e53
-- 
2.56.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] io_uring/cancel: count all canceled futex and waitid requests on CANCEL_ALL
  2026-10-24 16:31 [PATCH 0/2] io_uring/cancel: futex and waitid cancel results agxr
@ 2026-10-24 16:31 ` agxr
  2026-10-24 16:31 ` [PATCH 2/2] io_uring/cancel: complete single futex or waitid cancel with 0 agxr
  2026-10-25  3:23 ` [PATCH 0/2] io_uring/cancel: futex and waitid cancel results Jens Axboe
  2 siblings, 0 replies; 4+ messages in thread
From: agxr @ 2026-10-24 16:31 UTC (permalink / raw)
  To: Jens Axboe, io-uring; +Cc: agxr, linux-kernel, Josef Bacik

With IORING_ASYNC_CANCEL_ALL, __io_async_cancel() calls io_try_cancel()
until it finds nothing more and adds 1 to the count for each call that
found something, which is correct for poll, io-wq and timeouts, which
cancel one request per call. io_futex_cancel() and io_waitid_cancel()
cancel all matches in a single call and return how many they canceled.
Three futex waits with the same user_data are all canceled by the first
call, which counts as one, and the cancel completes with 1, not 3.

Sum the return values of io_try_cancel() instead, so that the count is
the number of canceled requests, as io_uring_prep_cancel(3) documents.

Fixes: 194bb58c6090 ("io_uring: add support for futex wake and wait")
Fixes: f31ecf671ddc ("io_uring: add IORING_OP_WAITID support")
Signed-off-by: agxr <agxr@disroot.org>
---
 io_uring/cancel.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/io_uring/cancel.c b/io_uring/cancel.c
index 6f7a6cf356c2..e4b27b79b05c 100644
--- a/io_uring/cancel.c
+++ b/io_uring/cancel.c
@@ -198,7 +198,7 @@ static int __io_async_cancel(struct io_cancel_data *cd,
 			break;
 		if (!all)
 			return ret;
-		nr++;
+		nr += ret > 0 ? ret : 1;
 	} while (1);
 
 	/* slow path, try all io-wq's */
-- 
2.56.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/2] io_uring/cancel: complete single futex or waitid cancel with 0
  2026-10-24 16:31 [PATCH 0/2] io_uring/cancel: futex and waitid cancel results agxr
  2026-10-24 16:31 ` [PATCH 1/2] io_uring/cancel: count all canceled futex and waitid requests on CANCEL_ALL agxr
@ 2026-10-24 16:31 ` agxr
  2026-10-25  3:23 ` [PATCH 0/2] io_uring/cancel: futex and waitid cancel results Jens Axboe
  2 siblings, 0 replies; 4+ messages in thread
From: agxr @ 2026-10-24 16:31 UTC (permalink / raw)
  To: Jens Axboe, io-uring; +Cc: agxr, linux-kernel, Josef Bacik

A cancel of one request completes with 0, as io_uring_prep_cancel(3)
documents and as poll, io-wq and timeouts do. For a futex wait or a
waitid it completes with 1. io_futex_cancel() and io_waitid_cancel()
return the number canceled, and __io_async_cancel() hands it on, for
IORING_OP_ASYNC_CANCEL and IORING_REGISTER_SYNC_CANCEL alike.

Turn that count into 0, as io_req_task_link_timeout() does since commit
c74193430feb ("io_uring/timeout: don't end a linked timeout with 1").

liburing's futex and waitid tests expect the 1, and a liburing change
makes them accept 0 as well.

Fixes: 194bb58c6090 ("io_uring: add support for futex wake and wait")
Fixes: f31ecf671ddc ("io_uring: add IORING_OP_WAITID support")
Signed-off-by: agxr <agxr@disroot.org>
---
 io_uring/cancel.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/io_uring/cancel.c b/io_uring/cancel.c
index e4b27b79b05c..20df4e3538f3 100644
--- a/io_uring/cancel.c
+++ b/io_uring/cancel.c
@@ -197,7 +197,7 @@ static int __io_async_cancel(struct io_cancel_data *cd,
 		if (ret == -ENOENT)
 			break;
 		if (!all)
-			return ret;
+			return ret > 0 ? 0 : ret;
 		nr += ret > 0 ? ret : 1;
 	} while (1);
 
-- 
2.56.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] io_uring/cancel: futex and waitid cancel results
  2026-10-24 16:31 [PATCH 0/2] io_uring/cancel: futex and waitid cancel results agxr
  2026-10-24 16:31 ` [PATCH 1/2] io_uring/cancel: count all canceled futex and waitid requests on CANCEL_ALL agxr
  2026-10-24 16:31 ` [PATCH 2/2] io_uring/cancel: complete single futex or waitid cancel with 0 agxr
@ 2026-10-25  3:23 ` Jens Axboe
  2 siblings, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2026-10-25  3:23 UTC (permalink / raw)
  To: agxr, io-uring; +Cc: linux-kernel, Josef Bacik

On 10/24/26 10:31 AM, agxr wrote:
> io_futex_cancel() and io_waitid_cancel() return the number of requests
> they canceled, where the rest of what io_try_cancel() calls returns 0.
> Commit c74193430feb ("io_uring/timeout: don't end a linked timeout with
> 1") took care of what that did to a linked timeout.
> 
> liburing's futex, waitid, io-cancel, sync-cancel, poll-cancel-all,
> cancel-race, futex-kill, link-timeout, timeout and poll-cancel tests
> pass on both patched kernels. Unchanged liburing tests pass with patch
> 1 and fail with patch 2, where they check for the 1.
> 
> agxr (2):
>   io_uring/cancel: count all canceled futex and waitid requests on
>     CANCEL_ALL
>   io_uring/cancel: complete single futex or waitid cancel with 0
> 
>  io_uring/cancel.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

I'll take a look at these - but please note, that:

Signed-off-by: agxr <agxr@disroot.org>

is not going to be adequate for the kernel, we generally ask for
a known identity. That's either a real name or at least a well
known identity, above is neither of those.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-10-25  3:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-24 16:31 [PATCH 0/2] io_uring/cancel: futex and waitid cancel results agxr
2026-10-24 16:31 ` [PATCH 1/2] io_uring/cancel: count all canceled futex and waitid requests on CANCEL_ALL agxr
2026-10-24 16:31 ` [PATCH 2/2] io_uring/cancel: complete single futex or waitid cancel with 0 agxr
2026-10-25  3:23 ` [PATCH 0/2] io_uring/cancel: futex and waitid cancel results Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®