From patchwork Fri Jun 23 16:47:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13290814 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 51A34EB64D7 for ; Fri, 23 Jun 2023 16:48:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232476AbjFWQsU (ORCPT ); Fri, 23 Jun 2023 12:48:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232475AbjFWQsO (ORCPT ); Fri, 23 Jun 2023 12:48:14 -0400 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7619E2733 for ; Fri, 23 Jun 2023 09:48:11 -0700 (PDT) Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1b5079b8cb3so1764075ad.1 for ; Fri, 23 Jun 2023 09:48:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20221208.gappssmtp.com; s=20221208; t=1687538890; x=1690130890; 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=UAC7drXqvR4smhcm9JEWe7VO3fT7fkffLKfKJ9HzOJw=; b=ly+JwbnYLHTgdZuKmE+TyZjJZ2K0XgYNj8SPS+d+ZOtfwoN0lhTkheOqgAKk20+uC+ ZiwNbDQsE1c8WWhP5ViKJOfBG/OSGkpnRnPWtVTeM4VIM9psmuyUB1BuXG0LWQL9+50A UAoguXH02Dt9CJdDPO1G2dMxShBr53EFFXNXgXoFbPG4VybZWwUXmQAyrytgZg9psTkO WS80jlmiHrsTznYffGKV5jzVFba3X0LcXPExwtR8uPBKXt+jMmUqdjRDMDSURHwXo+cF vn7ApeHU42klyXep6NF9t65J+yCC77A8RoSjZ+1GmPo9FGCPODGSbhWx98ZQgFMtgRf7 xY5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687538890; x=1690130890; 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=UAC7drXqvR4smhcm9JEWe7VO3fT7fkffLKfKJ9HzOJw=; b=BpR1PwcSlnQKQz2mRmW3QBsKHpjFpUBuaFMUfRSzAZyHcRys864Ab+dxsQoV++k+Yp KwgU42WNil0r/f8liBNRCgcLjQgWRVvJ8tbKG8NlxrYC0lN1hIcZjOvMOI4M41mifvF0 /IfcPsPhH2M+TwFjjpeym1qE1npoQbp+UNlZuvhCYxl+vAUshDx2+e7LSyCXn1IGGnd9 WONzUGg5/2U7aSXBNgRM30WIFnOfiUnH7nX+olfjO1yOhIWUP3I+PeFhdej3EavPbpod Td3vrS8BMYfW54/fjACm9TV7uT+zb7l1ekonTxglqrT7ahjNFsZLfVRvTBLqBjOdw1cq r51Q== X-Gm-Message-State: AC+VfDyDMtPd02+BpARGTzL5Rqpop68taVSu3oR0R7GUtub16nAKBMTV ebub8Tf1EiuGGOmGGRHgXNgFZS/p4FP+XlqW3FY= X-Google-Smtp-Source: ACHHUZ6qwlLwyW2oY9nKPyNIfLgSxd8UmSsXp6cMhdg5AHLLwDLqS5zQnDWw0z4GIrIKQWe4NAhL3g== X-Received: by 2002:a17:902:dac6:b0:1ac:656f:a68d with SMTP id q6-20020a170902dac600b001ac656fa68dmr26265509plx.4.1687538890441; Fri, 23 Jun 2023 09:48:10 -0700 (PDT) Received: from localhost.localdomain ([198.8.77.157]) by smtp.gmail.com with ESMTPSA id n4-20020a170903110400b001b55c0548dfsm7454411plh.97.2023.06.23.09.48.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jun 2023 09:48:09 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 1/8] io_uring/poll: always set 'ctx' in io_cancel_data Date: Fri, 23 Jun 2023 10:47:57 -0600 Message-Id: <20230623164804.610910-2-axboe@kernel.dk> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230623164804.610910-1-axboe@kernel.dk> References: <20230623164804.610910-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org This isn't strictly necessary for this callsite, as it uses it's internal lookup for this cancelation purpose. But let's be consistent with how it's used in general and set ctx as well. Signed-off-by: Jens Axboe --- io_uring/poll.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/io_uring/poll.c b/io_uring/poll.c index d4597efe14a7..c7bb292c9046 100644 --- a/io_uring/poll.c +++ b/io_uring/poll.c @@ -972,8 +972,8 @@ int io_poll_add(struct io_kiocb *req, unsigned int issue_flags) int io_poll_remove(struct io_kiocb *req, unsigned int issue_flags) { struct io_poll_update *poll_update = io_kiocb_to_cmd(req, struct io_poll_update); - struct io_cancel_data cd = { .data = poll_update->old_user_data, }; struct io_ring_ctx *ctx = req->ctx; + struct io_cancel_data cd = { .ctx = ctx, .data = poll_update->old_user_data, }; struct io_hash_bucket *bucket; struct io_kiocb *preq; int ret2, ret = 0; From patchwork Fri Jun 23 16:47:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13290815 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7418AC001DF for ; Fri, 23 Jun 2023 16:48:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232482AbjFWQsX (ORCPT ); Fri, 23 Jun 2023 12:48:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232484AbjFWQsP (ORCPT ); Fri, 23 Jun 2023 12:48:15 -0400 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD710295E for ; Fri, 23 Jun 2023 09:48:12 -0700 (PDT) Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1b3ecb17721so1212345ad.0 for ; Fri, 23 Jun 2023 09:48:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20221208.gappssmtp.com; s=20221208; t=1687538892; x=1690130892; 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=dd/IY/rhGZi+33z0aLAZgR+jpqqduQJQDHihiNUSDnY=; b=MIXBrkFJykHaU5BsR4IZHs+AYkCdYBzKWaUnQaEVGwwwW4a7anD843JxbUxACrpdhg k5FYebv6WVeRgENNp2PxnBkINUR2uAoib1F98W6pj10aHWN4A4ZK5ocD5rmrKMJP9Aqv kzbCMkB4Zm/EE+X7l8dHFBcbi07rAAxq/5wnEZjBdylFhGLdqVkgOatDuNYdyBcpEkya hmFF0im3P96RKNVT0CCoE0UR79dQFTWefVydMCwvVVXjbvK3FcOC06qJLcD/EyPNdIZB D2nx7O+96JNOtxwBgTzXlbl2HSZR/ZTLSfHdvke9TyzgaGtIrEpmWHarbZ2M7/JP7rt+ QPFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687538892; x=1690130892; 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=dd/IY/rhGZi+33z0aLAZgR+jpqqduQJQDHihiNUSDnY=; b=FOnxs1q6A6x/BgLd6DC/MnnorGIp9sIi0DVd1RbxFe6agfr+cKEsoV70+7h9drg7/O zQ6Tt/uJYwM3hqovpYBd72oHdsyaXut7HTYha4eCH3xsRS2/6A+dwHMdfQIAbwuNYpls twGXyab7Wp/rDRS9ujEfrYAimZpxKx2zcBI5q8ZcQtxosPB3+TTyHh3ytbv2UYJu1Srq tYQo0CY0qnK3kpk1V0cbcAet4nW3aJLsAE5k5De6HVNY94n9GIW1Qfl3I9aKgEsEJUXL lGPQ5eE7gAa8y7ALf4swMLli3eBlID+DHFXraY7qsfVhJKAguvtJYNfdq4JVWNUGzhxn +gaQ== X-Gm-Message-State: AC+VfDy1IX7nHd/rwKORztl87NpTojYNE1+KgMyGlyPR1eql4rV9N17N +qHtX247pcjLLMcZ2wSTzifyOc4NmtReZWfgQ7o= X-Google-Smtp-Source: ACHHUZ4Tv/X4BvtZaOoVdX1rYYZ3M/Pf7qEV4Y/SlABn2yEwTzvH0yeZtHofWpZuGzIlfclnmSo6GQ== X-Received: by 2002:a17:902:da91:b0:1b0:3d54:358f with SMTP id j17-20020a170902da9100b001b03d54358fmr25386195plx.0.1687538891750; Fri, 23 Jun 2023 09:48:11 -0700 (PDT) Received: from localhost.localdomain ([198.8.77.157]) by smtp.gmail.com with ESMTPSA id n4-20020a170903110400b001b55c0548dfsm7454411plh.97.2023.06.23.09.48.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jun 2023 09:48:10 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 2/8] io_uring/timeout: always set 'ctx' in io_cancel_data Date: Fri, 23 Jun 2023 10:47:58 -0600 Message-Id: <20230623164804.610910-3-axboe@kernel.dk> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230623164804.610910-1-axboe@kernel.dk> References: <20230623164804.610910-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org In preparation for using a generic handler to match requests for cancelation purposes, ensure that ctx is set in io_cancel_data. The timeout handlers don't check for this as it'll always match, but we'll need it set going forward. Signed-off-by: Jens Axboe --- io_uring/timeout.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/io_uring/timeout.c b/io_uring/timeout.c index fb0547b35dcd..4200099ad96e 100644 --- a/io_uring/timeout.c +++ b/io_uring/timeout.c @@ -409,7 +409,7 @@ static int io_timeout_update(struct io_ring_ctx *ctx, __u64 user_data, struct timespec64 *ts, enum hrtimer_mode mode) __must_hold(&ctx->timeout_lock) { - struct io_cancel_data cd = { .data = user_data, }; + struct io_cancel_data cd = { .ctx = ctx, .data = user_data, }; struct io_kiocb *req = io_timeout_extract(ctx, &cd); struct io_timeout *timeout = io_kiocb_to_cmd(req, struct io_timeout); struct io_timeout_data *data; @@ -473,7 +473,7 @@ int io_timeout_remove(struct io_kiocb *req, unsigned int issue_flags) int ret; if (!(tr->flags & IORING_TIMEOUT_UPDATE)) { - struct io_cancel_data cd = { .data = tr->addr, }; + struct io_cancel_data cd = { .ctx = ctx, .data = tr->addr, }; spin_lock(&ctx->completion_lock); ret = io_timeout_cancel(ctx, &cd); From patchwork Fri Jun 23 16:47:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13290816 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DB50CEB64DD for ; Fri, 23 Jun 2023 16:48:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232569AbjFWQsb (ORCPT ); Fri, 23 Jun 2023 12:48:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232442AbjFWQsT (ORCPT ); Fri, 23 Jun 2023 12:48:19 -0400 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FC2C2738 for ; Fri, 23 Jun 2023 09:48:14 -0700 (PDT) Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-66a2a04de58so179974b3a.1 for ; Fri, 23 Jun 2023 09:48:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20221208.gappssmtp.com; s=20221208; t=1687538893; x=1690130893; 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=g83UyOYA3HEZssvEWqLCOxWbPN+8YNXFzia9GMHc0No=; b=0Hz0e5I0O7YFkss7bQEcXXSKSxi3+2i6XaupVTqoMMcKP0b+gpz+xAZE9nF4G86klD ICAJVyITodyB+MwYsBf6ytSGYhTaHhd7C/ioyK1KmAOJQD49CGqx8zJhCOeueo7ymj89 N7n4DT13slHfSAlcb/NaLnuvQwzhOWTc1K9AtxUPfdrP13mBmCjrDfhBrUKd3z1PSHcQ S5wyFuKQcjVWrbQ+oe+zirzYk6YL5SptaCq2ptkR6S9RqjDXv044nrkvVMMes4NkS2Eb MJc1CCpUKvVEBfbbvZYvzI/GDyrvSl14/NQiTYBwj0Z1/PPI4YunLHevASsgcWYwPcEm YSfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687538893; x=1690130893; 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=g83UyOYA3HEZssvEWqLCOxWbPN+8YNXFzia9GMHc0No=; b=BKoOKYDjL6obAVR6ddE1N87gslFHMFto2JXuPXpvJ9fKUe7PfO9zTJmuuD5LwTUzHG mkNy4ZdJdbwECl62+g5UK7Pme1lwK5KVYH35DOItVMd2r3LiOsepIfPLzJR69cy+noRI rHAEb6ySgPoMzu5tT54Ku3UvPG/bMWSQdDqokk1zRAlCAu0eyqe1fOE6uZZMwdKRRa9q bmJMhjj4DKptspEhzKOQNdImmkuE5EN705DpSvYoksyldWC8c8rP0b+JoUxvvTC8FTiA NdQ6xFm7sY1NgXs5rLu4H182dMZmcxATPsPTt6dIiP9AxdV5WCoduQzVUrRL5kTyq52B YQig== X-Gm-Message-State: AC+VfDwZSj8z25/SMCZDlGZEzRuIFLy+pUtrjYugUWJeZ8lm+0Y2z0kV b/kug+6gnVfFmF87eSgJV9VDyVWJQFl2kWn90dA= X-Google-Smtp-Source: ACHHUZ5c5cKZc9bwxAJ7RWjc/xh6maOe3AHLjEsLq1y27RRgtROLFCSmRutyoXnT19EQlIZbDrkzwA== X-Received: by 2002:a05:6a20:430c:b0:10b:e7d2:9066 with SMTP id h12-20020a056a20430c00b0010be7d29066mr27066062pzk.2.1687538893258; Fri, 23 Jun 2023 09:48:13 -0700 (PDT) Received: from localhost.localdomain ([198.8.77.157]) by smtp.gmail.com with ESMTPSA id n4-20020a170903110400b001b55c0548dfsm7454411plh.97.2023.06.23.09.48.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jun 2023 09:48:12 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 3/8] io_uring/cancel: abstract out request match helper Date: Fri, 23 Jun 2023 10:47:59 -0600 Message-Id: <20230623164804.610910-4-axboe@kernel.dk> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230623164804.610910-1-axboe@kernel.dk> References: <20230623164804.610910-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org We have different match code in a variety of spots. Start the cleanup of this by abstracting out a helper that can be used to check if a given request matches the cancelation criteria outlined in io_cancel_data. Signed-off-by: Jens Axboe --- io_uring/cancel.c | 17 +++++++++++++---- io_uring/cancel.h | 1 + 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/io_uring/cancel.c b/io_uring/cancel.c index 58c46c852bdd..8527ec3cc11f 100644 --- a/io_uring/cancel.c +++ b/io_uring/cancel.c @@ -27,11 +27,11 @@ struct io_cancel { #define CANCEL_FLAGS (IORING_ASYNC_CANCEL_ALL | IORING_ASYNC_CANCEL_FD | \ IORING_ASYNC_CANCEL_ANY | IORING_ASYNC_CANCEL_FD_FIXED) -static bool io_cancel_cb(struct io_wq_work *work, void *data) +/* + * Returns true if the request matches the criteria outlined by 'cd'. + */ +bool io_cancel_req_match(struct io_kiocb *req, struct io_cancel_data *cd) { - struct io_kiocb *req = container_of(work, struct io_kiocb, work); - struct io_cancel_data *cd = data; - if (req->ctx != cd->ctx) return false; if (cd->flags & IORING_ASYNC_CANCEL_ANY) { @@ -48,9 +48,18 @@ static bool io_cancel_cb(struct io_wq_work *work, void *data) return false; req->work.cancel_seq = cd->seq; } + return true; } +static bool io_cancel_cb(struct io_wq_work *work, void *data) +{ + struct io_kiocb *req = container_of(work, struct io_kiocb, work); + struct io_cancel_data *cd = data; + + return io_cancel_req_match(req, cd); +} + static int io_async_cancel_one(struct io_uring_task *tctx, struct io_cancel_data *cd) { diff --git a/io_uring/cancel.h b/io_uring/cancel.h index 6a59ee484d0c..496ce4dac78e 100644 --- a/io_uring/cancel.h +++ b/io_uring/cancel.h @@ -21,3 +21,4 @@ int io_try_cancel(struct io_uring_task *tctx, struct io_cancel_data *cd, void init_hash_table(struct io_hash_table *table, unsigned size); 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); From patchwork Fri Jun 23 16:48:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13290817 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E2CA9EB64D7 for ; Fri, 23 Jun 2023 16:49:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232342AbjFWQtF (ORCPT ); Fri, 23 Jun 2023 12:49:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232489AbjFWQsT (ORCPT ); Fri, 23 Jun 2023 12:48:19 -0400 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C47CA2972 for ; Fri, 23 Jun 2023 09:48:15 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1b5585e84b4so1310955ad.0 for ; Fri, 23 Jun 2023 09:48:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20221208.gappssmtp.com; s=20221208; t=1687538895; x=1690130895; 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=rSZQtoqAzhDTY0MUEMcJJxwF6F54WysrdBrpUmOaDJo=; b=hQSbsO4fStWXkomuzoa6x01KVK6sycjVgyfrluGqVKrP5MxD63ENDWEGjq9vvJ4O0C 9YE9UGjY2/+KEveNTAHkTasxPIT0URnCX4u00IC+Ppbhgc8nlS55yXg6q3SUVC+6R9qP yyh6wTZUF4u2kmf3oZwdYwrFcv6/SblUXUGoak8nKXdWuoeiu0pgqiWSdVusMwaj+GkL 97YZfYrVkrRIR5lk3ti6onv5He9tZAgOiLO5V1UwNFz5VGVTUF8BdU+jvyk1cLbhIQlb IZu+6I/k/MpE+qOTcHylGMu8Vss1zRFTdGITIEz7niKH57t09VfYD0gl+X+zKjIfKbi9 Y94A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687538895; x=1690130895; 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=rSZQtoqAzhDTY0MUEMcJJxwF6F54WysrdBrpUmOaDJo=; b=FgyJlpINwo8SPzHNePUHR9KMghkFcIFJYXnxIPbGTLZvarS71nGAZpeAzcnXCq6xrz xIniGie41Yt5dECzh0G972S4qCWUxoBk85d1Xb7GPDJNIgN/ijHg0XfZVYzXzU/tcWbA F+1KJJkhofP/WW2iqVPDZpo8PHjXJ+6lH9ft+DUhRHAS/099kBawaZed1CSYHfJ0n0d6 j1lbzQYLJulkxCD8kEgfviXAf6mY1HoYzv39vgomZyS7qtUzTTb8Ak3PPnNmOgKXCG+l xmnOM/bwv1D4K48LVDdBuajnb5u64eXMvETQekFNF1pmDxjtVPh34d7Lq9ctN5d7BbIu +yCQ== X-Gm-Message-State: AC+VfDyGpKOQVEX3phFV20SYsUDj8IeibPNEktQ5AqujuwSsC+1Oqay1 gNlf49ea6HFSxYYSydNdpv6O9WIkyLIsIXmrV4M= X-Google-Smtp-Source: ACHHUZ4zl8PHQ4wqc+LcjD9S1KHOK+u6gHQaUAAWxfATJycX3RLZiVgLpDNeo2kwaMFhw92d+vQJPA== X-Received: by 2002:a17:902:d509:b0:1af:a349:3f31 with SMTP id b9-20020a170902d50900b001afa3493f31mr26823977plg.3.1687538894743; Fri, 23 Jun 2023 09:48:14 -0700 (PDT) Received: from localhost.localdomain ([198.8.77.157]) by smtp.gmail.com with ESMTPSA id n4-20020a170903110400b001b55c0548dfsm7454411plh.97.2023.06.23.09.48.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jun 2023 09:48:14 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 4/8] io_uring/cancel: fix sequence matching for IORING_ASYNC_CANCEL_ANY Date: Fri, 23 Jun 2023 10:48:00 -0600 Message-Id: <20230623164804.610910-5-axboe@kernel.dk> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230623164804.610910-1-axboe@kernel.dk> References: <20230623164804.610910-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org We always need to check/update the cancel sequence if IORING_ASYNC_CANCEL_ALL is set. Also kill the redundant check for IORING_ASYNC_CANCEL_ANY at the end, if we get here we know it's not set as we would've matched it higher up. Signed-off-by: Jens Axboe --- io_uring/cancel.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/io_uring/cancel.c b/io_uring/cancel.c index 8527ec3cc11f..bf44563d687d 100644 --- a/io_uring/cancel.c +++ b/io_uring/cancel.c @@ -35,7 +35,7 @@ bool io_cancel_req_match(struct io_kiocb *req, struct io_cancel_data *cd) if (req->ctx != cd->ctx) return false; if (cd->flags & IORING_ASYNC_CANCEL_ANY) { - ; + goto check_seq; } else if (cd->flags & IORING_ASYNC_CANCEL_FD) { if (req->file != cd->file) return false; @@ -43,7 +43,8 @@ bool io_cancel_req_match(struct io_kiocb *req, struct io_cancel_data *cd) if (req->cqe.user_data != cd->data) return false; } - if (cd->flags & (IORING_ASYNC_CANCEL_ALL|IORING_ASYNC_CANCEL_ANY)) { + if (cd->flags & IORING_ASYNC_CANCEL_ALL) { +check_seq: if (cd->seq == req->work.cancel_seq) return false; req->work.cancel_seq = cd->seq; From patchwork Fri Jun 23 16:48:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13290818 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 53CC0EB64D7 for ; Fri, 23 Jun 2023 16:49:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232260AbjFWQtN (ORCPT ); Fri, 23 Jun 2023 12:49:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232499AbjFWQsX (ORCPT ); Fri, 23 Jun 2023 12:48:23 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26FF02941 for ; Fri, 23 Jun 2023 09:48:17 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-668842bc50dso142745b3a.1 for ; Fri, 23 Jun 2023 09:48:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20221208.gappssmtp.com; s=20221208; t=1687538896; x=1690130896; 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=FfegOzu4tZpSz4Tx9eDD3X8u1MA2kW3UGo/SKYKWbW0=; b=0OKXdeZ1q5Tcf8mnhbI/HtvF9pdbEQEifCwFHLjNRm9B9m9HjTBPV8A8TOwWWs1PzK 5C2tkBPbVZ40OlrgVBCiZc5xg3tCmNUipL8OKBou6V/T8ZgAnTH/eVU6gCzN/6pRpALm MTsWdnwlZCOYf2KtF9B1adG7vyrfvT0LqBp/al5UWkh73iCyZ6CUtisLxxShvoreqiQ5 yRdPudJcJo363KqeqKsSBuptfhspyj4S2g4ib8Hi6PNURCjIXMHAOShg+jJp3Ca8SF3I F39nG/iJoQvzqWbVnCBN51di027oE+NNm+1XQar4m7oNab1dJWli0YLzeanVEBAJ0mMy VDRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687538896; x=1690130896; 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=FfegOzu4tZpSz4Tx9eDD3X8u1MA2kW3UGo/SKYKWbW0=; b=lUzCEcth366k2747HuTK5yun/JUOZu/2ZxQd47U2XiBPiNEw0FRcMPVVNriXnIpgUu V5ooDTTbWwUJ8ZGG/KkUwVqSwUFjcyCVb8jn2qDjDrYuBKYDzrN0WR9RmMti4EdAlVfG rWR1mfJc2Jpm4kP9rCzcNpAvyX4t/XmiFq9JhwAkfOrFWuibCVswlhvzIOAKO15UNQ1C /NIN6j8idZqrLbi/jleY/P55kcXDGSzeqn0QXH45lVNDW0dtC8teDvv6pruVDohmYztj 1JkWY/VeEr8cjcEh+UHO2dQ0tmBKR4h0EFZApBP56NMvaJ7cnqBdvIVKs/k3NuCLGbx9 0qOw== X-Gm-Message-State: AC+VfDzKLxfh8Uccr/xwYxiRpTCBxC+d7fgxFw4AePDzPTzGHSSkO2aN ElUNXOP459MgIVKNCyxozakZ4iO76jff93szUEc= X-Google-Smtp-Source: ACHHUZ5CyR4CYZkC4YazfVRWb4Zot+a3hPMb9qRSs45mzU1xkveHVitp9mi+vHJ4Q1MUKVlD3BA4kw== X-Received: by 2002:a05:6a20:8f04:b0:121:d102:248c with SMTP id b4-20020a056a208f0400b00121d102248cmr16511421pzk.6.1687538896033; Fri, 23 Jun 2023 09:48:16 -0700 (PDT) Received: from localhost.localdomain ([198.8.77.157]) by smtp.gmail.com with ESMTPSA id n4-20020a170903110400b001b55c0548dfsm7454411plh.97.2023.06.23.09.48.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jun 2023 09:48:15 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 5/8] io_uring: use cancelation match helper for poll and timeout requests Date: Fri, 23 Jun 2023 10:48:01 -0600 Message-Id: <20230623164804.610910-6-axboe@kernel.dk> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230623164804.610910-1-axboe@kernel.dk> References: <20230623164804.610910-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Get rid of the request vs io_cancel_data checking and just use the exported helper for this. Signed-off-by: Jens Axboe --- io_uring/poll.c | 12 ++++-------- io_uring/timeout.c | 12 +++--------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/io_uring/poll.c b/io_uring/poll.c index c7bb292c9046..dc1219f606e5 100644 --- a/io_uring/poll.c +++ b/io_uring/poll.c @@ -824,14 +824,10 @@ static struct io_kiocb *io_poll_file_find(struct io_ring_ctx *ctx, spin_lock(&hb->lock); hlist_for_each_entry(req, &hb->list, hash_node) { - if (!(cd->flags & IORING_ASYNC_CANCEL_ANY) && - req->file != cd->file) - continue; - if (cd->seq == req->work.cancel_seq) - continue; - req->work.cancel_seq = cd->seq; - *out_bucket = hb; - return req; + if (io_cancel_req_match(req, cd)) { + *out_bucket = hb; + return req; + } } spin_unlock(&hb->lock); } diff --git a/io_uring/timeout.c b/io_uring/timeout.c index 4200099ad96e..6242130e73c6 100644 --- a/io_uring/timeout.c +++ b/io_uring/timeout.c @@ -268,16 +268,10 @@ static struct io_kiocb *io_timeout_extract(struct io_ring_ctx *ctx, list_for_each_entry(timeout, &ctx->timeout_list, list) { struct io_kiocb *tmp = cmd_to_io_kiocb(timeout); - if (!(cd->flags & IORING_ASYNC_CANCEL_ANY) && - cd->data != tmp->cqe.user_data) - continue; - if (cd->flags & (IORING_ASYNC_CANCEL_ALL|IORING_ASYNC_CANCEL_ANY)) { - if (cd->seq == tmp->work.cancel_seq) - continue; - tmp->work.cancel_seq = cd->seq; + if (io_cancel_req_match(tmp, cd)) { + req = tmp; + break; } - req = tmp; - break; } if (!req) return ERR_PTR(-ENOENT); From patchwork Fri Jun 23 16:48:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13290819 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 810F2EB64D7 for ; Fri, 23 Jun 2023 16:49:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232617AbjFWQtQ (ORCPT ); Fri, 23 Jun 2023 12:49:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232508AbjFWQs1 (ORCPT ); Fri, 23 Jun 2023 12:48:27 -0400 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A7BF294E for ; Fri, 23 Jun 2023 09:48:18 -0700 (PDT) Received: by mail-pg1-x534.google.com with SMTP id 41be03b00d2f7-51f64817809so79192a12.1 for ; Fri, 23 Jun 2023 09:48:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20221208.gappssmtp.com; s=20221208; t=1687538897; x=1690130897; 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=O6FRdfzJJ3IE7HGRCoH2KJs1eNi5bWS6uTcalNvOlHo=; b=JPeKt05L98dx42eDLG5Vv349LtnqlOWFBN9fTLOCcg85Rzeeu2PMgqI9kC9UOkrAtS 7hOwLz8dDqE42pcWvvTDhb5Y97V+t5hL3C5n1FGYqIhcx1K42R8/p1fP+7EmSKaMGFqJ ItPpNVwuNkdrIbzY/cp/HaUJVAQjPeBUoSWjwdLEFik3RWZfbyPS9ZUwkoacq5pdY+uL Pp8ZcBPPYMiQz3u/5jLT6rxrmYZbNsSaK4OsWBl7KI77YFszYpSedR8E/cZup2Oj5ogF eEITKt61Df5sFyIley9S9VWeNkyThuoVbd9vDrRfnqEYB+0pK+6ZMGXWdR1hA/eBnGu8 HGxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687538897; x=1690130897; 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=O6FRdfzJJ3IE7HGRCoH2KJs1eNi5bWS6uTcalNvOlHo=; b=jdCiPe5M7JRjfsipedqjlk68KNh3kNHrGemITKAtluylO7JimCiHdWai4lfls8jdyL Iq5JKusSJ7vNuMnaJpsfte7ZyzQ6ZhnvDtrEFNjbITkOxGw8A3kOV3kaZ0In1xjmMJdV kkM5ckvo6MMoW6tkSsNMa2WYKSjY6ogQKWSRYsIiShATGOMwhLSOIFPVYaSruowE26AO KVKfd4DqcXtNmpww9OdgcWWJwxHm/AKpLm7tkUTAsbTYU6bwwY+mJ9+Fet+aVDjMaTR3 WLBC+zX+z5TOaHPh361nlUtT8xezEaZISRXxlhdu2ePl3qennxHPSzZQnKDM/NL7BJ5m OAlA== X-Gm-Message-State: AC+VfDwMMkDit+rD1UYn+4qAXqzbWvYoghvkSfJMyhcz2kSsMM0msF/1 +4pCEpf0Gdqh49ELaincLCkgzVzjkP4Ox9H2Prk= X-Google-Smtp-Source: ACHHUZ7lTe4YFuu3KCZxRvCWJQ7UGhP5PBcYCU0m50HpHVQOYSXhNsuFTiPCNDsgYAWRA52zG4dyDQ== X-Received: by 2002:a17:903:32c4:b0:1b3:e352:6d88 with SMTP id i4-20020a17090332c400b001b3e3526d88mr26730004plr.6.1687538897416; Fri, 23 Jun 2023 09:48:17 -0700 (PDT) Received: from localhost.localdomain ([198.8.77.157]) by smtp.gmail.com with ESMTPSA id n4-20020a170903110400b001b55c0548dfsm7454411plh.97.2023.06.23.09.48.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jun 2023 09:48:16 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 6/8] io_uring/cancel: add IORING_ASYNC_CANCEL_USERDATA Date: Fri, 23 Jun 2023 10:48:02 -0600 Message-Id: <20230623164804.610910-7-axboe@kernel.dk> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230623164804.610910-1-axboe@kernel.dk> References: <20230623164804.610910-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Add a flag to explicitly match on user_data in the request for cancelation purposes. This is the default behavior if none of the other match flags are set, but if we ALSO want to match on user_data, then this flag can be set. Signed-off-by: Jens Axboe --- include/uapi/linux/io_uring.h | 2 ++ io_uring/cancel.c | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h index f222d263bc55..e8bf70610568 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -297,11 +297,13 @@ enum io_uring_op { * request 'user_data' * IORING_ASYNC_CANCEL_ANY Match any request * IORING_ASYNC_CANCEL_FD_FIXED 'fd' passed in is a fixed descriptor + * IORING_ASYNC_CANCEL_USERDATA Match on user_data, default for no other key */ #define IORING_ASYNC_CANCEL_ALL (1U << 0) #define IORING_ASYNC_CANCEL_FD (1U << 1) #define IORING_ASYNC_CANCEL_ANY (1U << 2) #define IORING_ASYNC_CANCEL_FD_FIXED (1U << 3) +#define IORING_ASYNC_CANCEL_USERDATA (1U << 4) /* * send/sendmsg and recv/recvmsg flags (sqe->ioprio) diff --git a/io_uring/cancel.c b/io_uring/cancel.c index bf44563d687d..20612e93a354 100644 --- a/io_uring/cancel.c +++ b/io_uring/cancel.c @@ -25,24 +25,30 @@ struct io_cancel { }; #define CANCEL_FLAGS (IORING_ASYNC_CANCEL_ALL | IORING_ASYNC_CANCEL_FD | \ - IORING_ASYNC_CANCEL_ANY | IORING_ASYNC_CANCEL_FD_FIXED) + IORING_ASYNC_CANCEL_ANY | IORING_ASYNC_CANCEL_FD_FIXED | \ + IORING_ASYNC_CANCEL_USERDATA) /* * Returns true if the request matches the criteria outlined by 'cd'. */ bool io_cancel_req_match(struct io_kiocb *req, struct io_cancel_data *cd) { + bool match_user_data = cd->flags & IORING_ASYNC_CANCEL_USERDATA; + if (req->ctx != cd->ctx) return false; - if (cd->flags & IORING_ASYNC_CANCEL_ANY) { + + if (!(cd->flags & (IORING_ASYNC_CANCEL_FD))) + match_user_data = true; + + if (cd->flags & IORING_ASYNC_CANCEL_ANY) goto check_seq; - } else if (cd->flags & IORING_ASYNC_CANCEL_FD) { + if (cd->flags & IORING_ASYNC_CANCEL_FD) { if (req->file != cd->file) return false; - } else { - if (req->cqe.user_data != cd->data) - return false; } + if (match_user_data && req->cqe.user_data != cd->data) + return false; if (cd->flags & IORING_ASYNC_CANCEL_ALL) { check_seq: if (cd->seq == req->work.cancel_seq) From patchwork Fri Jun 23 16:48:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13290820 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9481FEB64DD for ; Fri, 23 Jun 2023 16:49:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232528AbjFWQtS (ORCPT ); Fri, 23 Jun 2023 12:49:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232537AbjFWQs3 (ORCPT ); Fri, 23 Jun 2023 12:48:29 -0400 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 188222954 for ; Fri, 23 Jun 2023 09:48:20 -0700 (PDT) Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-668842bc50dso142760b3a.1 for ; Fri, 23 Jun 2023 09:48:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20221208.gappssmtp.com; s=20221208; t=1687538899; x=1690130899; 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=v75mpzl9fkP5ZQu9rl58jq//4xdzKQhZFyBCXftL/E4=; b=Hf43mXM8enmbqRUypvAOTaPKQ7lIGzkINharwKgiloWSTvlxaD88JE3Ien8s3I5pJJ +J5la6mRNgJupGn9Qqkl46/icpcgRWrU0xwJE7FxwZvL5tAs479SsJIXxj8ItmcR66JI YY557eEnpuE6h4qINh4vpT6x6cPehJcKGVPNXGIXUGEVIjzcxDom2j7AkdJFPRF46Iaq 0I4h3XtXrIZ3JcadAmHkU2Vmsv/0RYBSDYjVhVWt7u5NDHzBtmP021g70E4mRmYX+rhm ucZBmgAHjSa3Hqu0kS/FCk3rV6Vfzv4CC16K88ZotPgYGqKZjZShr1kGvkGCOMB6JWRk lqgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687538899; x=1690130899; 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=v75mpzl9fkP5ZQu9rl58jq//4xdzKQhZFyBCXftL/E4=; b=gebM4HTNNxVNBcXmXESdvh32a5p9l0z/+0KpnHEMnM2Qm1FUnsIYTrxQDAcSZGxaNY EzstZhobYU9CdRHL6yYbBcMlKK6iMfUm80KK/gfBDihWDuK1QqLQqj4uxprpWo9DX6n7 WEOhoh9JOcwUcT1hLco/TAJqnqp6aRxWPn0HUKMbQRcZB+hqlIExSfNr/wS7kYW1ZjqO k1BEwBQ4OSkInxHH23eO0TEmnlyqxn6KyeHBfYgA0/2mMoHk4/17BgWX28kXVjd9K8ms RUQdZSjly7AbkJWULLBujyjwHFpZ8mjNNEGvIV9tGVs1eXST7ibf+UdLQc+cWLIJY7mX 39/g== X-Gm-Message-State: AC+VfDyAci5rIjNT+eXDDKa4X+kiVFpf1s+S+axlXPkmgNlMpDfTets1 pkF/4VVqHGokdSfx7355J9Z8aPoWZyn5tDGpozI= X-Google-Smtp-Source: ACHHUZ7vuanziOmA7zOqFsyN+qjdoAOt7Pc16Cc7u7ebcfgV4j2Wzc1jN+PY2mFpC7V39iZdy4ArmQ== X-Received: by 2002:a05:6a20:8f04:b0:121:d102:248c with SMTP id b4-20020a056a208f0400b00121d102248cmr16511560pzk.6.1687538898810; Fri, 23 Jun 2023 09:48:18 -0700 (PDT) Received: from localhost.localdomain ([198.8.77.157]) by smtp.gmail.com with ESMTPSA id n4-20020a170903110400b001b55c0548dfsm7454411plh.97.2023.06.23.09.48.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jun 2023 09:48:17 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 7/8] io_uring/cancel: support opcode based lookup and cancelation Date: Fri, 23 Jun 2023 10:48:03 -0600 Message-Id: <20230623164804.610910-8-axboe@kernel.dk> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230623164804.610910-1-axboe@kernel.dk> References: <20230623164804.610910-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Add IORING_ASYNC_CANCEL_OP flag for cancelation, which allows the application to target cancelation based on the opcode of the original request. Signed-off-by: Jens Axboe --- include/uapi/linux/io_uring.h | 2 ++ io_uring/cancel.c | 17 ++++++++++++++--- io_uring/cancel.h | 2 +- io_uring/poll.c | 3 ++- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h index e8bf70610568..af3b862fa905 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -298,12 +298,14 @@ enum io_uring_op { * IORING_ASYNC_CANCEL_ANY Match any request * IORING_ASYNC_CANCEL_FD_FIXED 'fd' passed in is a fixed descriptor * IORING_ASYNC_CANCEL_USERDATA Match on user_data, default for no other key + * IORING_ASYNC_CANCEL_OP Match request based on opcode */ #define IORING_ASYNC_CANCEL_ALL (1U << 0) #define IORING_ASYNC_CANCEL_FD (1U << 1) #define IORING_ASYNC_CANCEL_ANY (1U << 2) #define IORING_ASYNC_CANCEL_FD_FIXED (1U << 3) #define IORING_ASYNC_CANCEL_USERDATA (1U << 4) +#define IORING_ASYNC_CANCEL_OP (1U << 5) /* * send/sendmsg and recv/recvmsg flags (sqe->ioprio) diff --git a/io_uring/cancel.c b/io_uring/cancel.c index 20612e93a354..d91116b032eb 100644 --- a/io_uring/cancel.c +++ b/io_uring/cancel.c @@ -22,11 +22,12 @@ struct io_cancel { u64 addr; u32 flags; s32 fd; + u8 opcode; }; #define CANCEL_FLAGS (IORING_ASYNC_CANCEL_ALL | IORING_ASYNC_CANCEL_FD | \ IORING_ASYNC_CANCEL_ANY | IORING_ASYNC_CANCEL_FD_FIXED | \ - IORING_ASYNC_CANCEL_USERDATA) + IORING_ASYNC_CANCEL_USERDATA | IORING_ASYNC_CANCEL_OP) /* * Returns true if the request matches the criteria outlined by 'cd'. @@ -38,7 +39,7 @@ bool io_cancel_req_match(struct io_kiocb *req, struct io_cancel_data *cd) if (req->ctx != cd->ctx) return false; - if (!(cd->flags & (IORING_ASYNC_CANCEL_FD))) + if (!(cd->flags & (IORING_ASYNC_CANCEL_FD | IORING_ASYNC_CANCEL_OP))) match_user_data = true; if (cd->flags & IORING_ASYNC_CANCEL_ANY) @@ -47,6 +48,10 @@ bool io_cancel_req_match(struct io_kiocb *req, struct io_cancel_data *cd) if (req->file != cd->file) return false; } + if (cd->flags & IORING_ASYNC_CANCEL_OP) { + if (req->opcode != cd->opcode) + return false; + } if (match_user_data && req->cqe.user_data != cd->data) return false; if (cd->flags & IORING_ASYNC_CANCEL_ALL) { @@ -127,7 +132,7 @@ int io_async_cancel_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) if (unlikely(req->flags & REQ_F_BUFFER_SELECT)) return -EINVAL; - if (sqe->off || sqe->len || sqe->splice_fd_in) + if (sqe->off || sqe->splice_fd_in) return -EINVAL; cancel->addr = READ_ONCE(sqe->addr); @@ -139,6 +144,11 @@ int io_async_cancel_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) return -EINVAL; cancel->fd = READ_ONCE(sqe->fd); } + if (cancel->flags & IORING_ASYNC_CANCEL_OP) { + if (cancel->flags & IORING_ASYNC_CANCEL_ANY) + return -EINVAL; + cancel->opcode = READ_ONCE(sqe->len); + } return 0; } @@ -185,6 +195,7 @@ int io_async_cancel(struct io_kiocb *req, unsigned int issue_flags) .ctx = req->ctx, .data = cancel->addr, .flags = cancel->flags, + .opcode = cancel->opcode, .seq = atomic_inc_return(&req->ctx->cancel_seq), }; struct io_uring_task *tctx = req->task->io_uring; diff --git a/io_uring/cancel.h b/io_uring/cancel.h index 496ce4dac78e..fc98622e6166 100644 --- a/io_uring/cancel.h +++ b/io_uring/cancel.h @@ -8,11 +8,11 @@ struct io_cancel_data { u64 data; struct file *file; }; + u8 opcode; u32 flags; int seq; }; - int io_async_cancel_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe); int io_async_cancel(struct io_kiocb *req, unsigned int issue_flags); diff --git a/io_uring/poll.c b/io_uring/poll.c index dc1219f606e5..65ec363f6377 100644 --- a/io_uring/poll.c +++ b/io_uring/poll.c @@ -851,7 +851,8 @@ static int __io_poll_cancel(struct io_ring_ctx *ctx, struct io_cancel_data *cd, struct io_hash_bucket *bucket; struct io_kiocb *req; - if (cd->flags & (IORING_ASYNC_CANCEL_FD|IORING_ASYNC_CANCEL_ANY)) + if (cd->flags & (IORING_ASYNC_CANCEL_FD | IORING_ASYNC_CANCEL_OP | + IORING_ASYNC_CANCEL_ANY)) req = io_poll_file_find(ctx, cd, table, &bucket); else req = io_poll_find(ctx, false, cd, table, &bucket); From patchwork Fri Jun 23 16:48:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13290821 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 662B1C0015E for ; Fri, 23 Jun 2023 16:49:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232575AbjFWQtU (ORCPT ); Fri, 23 Jun 2023 12:49:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232561AbjFWQsb (ORCPT ); Fri, 23 Jun 2023 12:48:31 -0400 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39C1F295B for ; Fri, 23 Jun 2023 09:48:21 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1b5079b8cb3so1764345ad.1 for ; Fri, 23 Jun 2023 09:48:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20221208.gappssmtp.com; s=20221208; t=1687538900; x=1690130900; 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=ikHYZC63ffUOiMeB1sgmZexCpeBnqjH4Ml2zN5xiDow=; b=nYFxLmQX/iYEZsBtBVP/PIrWS3WvnrB2bAbW7XzMFAf7CnPUiPiWymNcCuZPJbZf4V jPS4bP0e0YDCETek+Lm0tPRpRW82/VDjyKPezQt1ZZVK+R8pJYJAG8vVAoqjyHNcGFWd 8gCAHrXXBu9O179a3i+gZYKhxYmAePzIZXDcHldJBx0yX7QgGMiQBF5mwZWP86QVNuc5 fyYv9GBt0OZvykm1M2q5bs7eySLXe+qQWVXus3UbvuavyVjWC9OaG3G0QEFjGt+9xMM9 B2NsLBTmJyhTPBCbI2k/dp9+Xd3Bk7cdyi9wthT1oafo1rD1pcdHG6QyOsmsN+UKi/3c fHgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687538900; x=1690130900; 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=ikHYZC63ffUOiMeB1sgmZexCpeBnqjH4Ml2zN5xiDow=; b=dcP2Gtev2yCqorsZfgSl7i8zZbjR0Q1IY5602jY9/22R+eZ9/wzjFloJyDuPYNt6w1 7cFDd6S5QUtg32OubAzBYMZ+yBIF1PNTDEiJZLnK1khU+a7ZGtOAGHg8dyJ01UdsEJ19 LIkNYXlfB1R0W4aJveR3RNJyzvONSvA22ptlf4HnVTmZRZanuwgBs48DWXueqUH4/K1D lHgEUtrkk7H7ok16nUNGYVpgFAzn/te946e2v6PZD06nWhNcEzHg/x0uZhnGBWX29J0i miT7x7+EaKpOC04uhWzyGeXyv5R67PZ8mnaZekts47IZ3s0zAFea0RLpyiy7m66L9Qhf 9klQ== X-Gm-Message-State: AC+VfDyY6n5F4zgEZLtNdhF19NTYo2y8/A8FCtYUZs3mi4Ox/iOLNR62 QFf2StoG1NKshq6zkrsLPO1OJSpqMzaRX5WxzRM= X-Google-Smtp-Source: ACHHUZ4xSzuaNlQGDQEMQU02nItqUXJyDzP3bCE+TQdSfP8j5P1dk3Yq90RJaNTSVlKsumtqZ+wq1Q== X-Received: by 2002:a17:902:ecc6:b0:1b1:9272:55e2 with SMTP id a6-20020a170902ecc600b001b1927255e2mr26608571plh.3.1687538900202; Fri, 23 Jun 2023 09:48:20 -0700 (PDT) Received: from localhost.localdomain ([198.8.77.157]) by smtp.gmail.com with ESMTPSA id n4-20020a170903110400b001b55c0548dfsm7454411plh.97.2023.06.23.09.48.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jun 2023 09:48:19 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 8/8] io_uring/cancel: wire up IORING_ASYNC_CANCEL_OP for sync cancel Date: Fri, 23 Jun 2023 10:48:04 -0600 Message-Id: <20230623164804.610910-9-axboe@kernel.dk> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230623164804.610910-1-axboe@kernel.dk> References: <20230623164804.610910-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Allow usage of IORING_ASYNC_CANCEL_OP through the sync cancelation API as well. Signed-off-by: Jens Axboe --- include/uapi/linux/io_uring.h | 4 +++- io_uring/cancel.c | 11 ++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h index af3b862fa905..7fbd57f4c2ff 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -699,7 +699,9 @@ struct io_uring_sync_cancel_reg { __s32 fd; __u32 flags; struct __kernel_timespec timeout; - __u64 pad[4]; + __u8 opcode; + __u8 pad[7]; + __u64 pad2[3]; }; /* diff --git a/io_uring/cancel.c b/io_uring/cancel.c index d91116b032eb..7b23607cf4af 100644 --- a/io_uring/cancel.c +++ b/io_uring/cancel.c @@ -265,17 +265,22 @@ int io_sync_cancel(struct io_ring_ctx *ctx, void __user *arg) struct io_uring_sync_cancel_reg sc; struct fd f = { }; DEFINE_WAIT(wait); - int ret; + int ret, i; if (copy_from_user(&sc, arg, sizeof(sc))) return -EFAULT; if (sc.flags & ~CANCEL_FLAGS) return -EINVAL; - if (sc.pad[0] || sc.pad[1] || sc.pad[2] || sc.pad[3]) - return -EINVAL; + for (i = 0; i < ARRAY_SIZE(sc.pad); i++) + if (sc.pad[i]) + return -EINVAL; + for (i = 0; i < ARRAY_SIZE(sc.pad2); i++) + if (sc.pad2[i]) + return -EINVAL; cd.data = sc.addr; cd.flags = sc.flags; + cd.opcode = sc.opcode; /* we can grab a normal file descriptor upfront */ if ((cd.flags & IORING_ASYNC_CANCEL_FD) &&