From patchwork Wed Oct 16 00:05:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Schubert X-Patchwork-Id: 13837442 Received: from outbound-ip191a.ess.barracuda.com (outbound-ip191a.ess.barracuda.com [209.222.82.58]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8816EC2FB for ; Wed, 16 Oct 2024 00:05:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=209.222.82.58 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729037148; cv=fail; b=m+vJgHZ7a7clb8NnD81CkOwOGbJTO9oSt43UFNTOzE8jF7UoJe8YmjkOWeen6EQZfRd0a/2Mf0XrZORaTgZRieBWIiQkoVN+SkBdKkCibjG1G0smy6eI157peu7Lw7lLuM9XIhnD5sgqjC5UZZ9lzDvSiYHOkZXQCA0i0/WyEzc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729037148; c=relaxed/simple; bh=JEJEokcOCc05jtJsubXuaCfG17CCGx3VZOLL4a2JKwI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=p2BNCs2rW6EQaSsehMjIRCbfs0a7aPAV/0A4IxF1kikMjrM+PyveXW0gqIIxevxdtdAtdTyorqCwHr/clrfKHTuZecF4xdYysT9vr1icG2pgmWCsNZfI5Zq2wzTP20mT4mTurKDNUr47zqDH+fqhQfIBZelmhbD/h5qr9v89ph8= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=ddn.com; spf=pass smtp.mailfrom=ddn.com; dkim=pass (1024-bit key) header.d=ddn.com header.i=@ddn.com header.b=DLByn9ZX; arc=fail smtp.client-ip=209.222.82.58 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=ddn.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ddn.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ddn.com header.i=@ddn.com header.b="DLByn9ZX" Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2043.outbound.protection.outlook.com [104.47.58.43]) by mx-outbound13-99.us-east-2a.ess.aws.cudaops.com (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 16 Oct 2024 00:05:42 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=wn2h49Rqdd7phDBFZdx11PcMMXHWY47lXb6F2spItImBhZkRD8q/aUAk4eoiRvpJ306Gjl/HYZ2qPi28tigyCkB3fXnuH9oyTJROhNN8AHMrDIFWOZERiWcM2CfEUbsDUEZ3N2YGhrBJ3s1JNM3A1+tMnsH1LNfYigvoCi3wOaABBLE6O8uPFaXP74CqbAHaf4YcK47cfBAgwZ9P0wauA+YfsflsdNChHY2gkVe40IkMaPoNwGlDEDeXlPt+ut1JSc4+yCPkL/bw7Cgh5T7fs1sWvx/K3NA69XnOl10D/X1n0gi8iMdJWnokjuIitJPJXfO4r9IciBp+Ai6B3Fp4fA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Y4HGVIpBllPu0xVIkA4Sr+ZgSNQ3TER0bdtjkdpsSbU=; b=TJix/MqIXtu750sUku+RM7cFZRMBu5OasMrf4O1EoHfR705HcRvIYQj8XllSYQ8b4lRQ8pb1VueEW3oHM6UFpmXgE4kLMsSwL5LjwqurQaTW2BiEy5UY8gPxhwerwXo6l3GnFiwhDn68YLJyxELiQn9UMhHNKT1swUvGX5iIXX4QMSMb5QhJ9na/zWidveP+YL6me242/i4v03uRpg9wYWayOMGj5XiDBdNR9m8MqxpOyh7Dlp9kg00vg08mK+/pjloVPOb5ZUJs2Wu9G/rPVneFcxcxwryYYyJ5JYOVdIom3Giby591fFtejv4hHIkQ8aXWHcaCY6dr4ONn6JrB2Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 50.222.100.11) smtp.rcpttodomain=ddn.com smtp.mailfrom=ddn.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=ddn.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ddn.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Y4HGVIpBllPu0xVIkA4Sr+ZgSNQ3TER0bdtjkdpsSbU=; b=DLByn9ZXN/yUQGdHIO6dBm/cv+f0Bjrz/zF4YlD+VYX4DvsLk5EdE3dwRBKAg3Ap5MI6aJmS0/hXYY4Gl/2yftQQgxWE1iOmbK3pT1hIq4KipqrRBhQ++EzFj/0RTlm2wQhsv0q94QDQ5G/WCMDhQi1KMYY67zcGQE7aLjNuWpo= Received: from BLAPR03CA0106.namprd03.prod.outlook.com (2603:10b6:208:32a::21) by IA3PR19MB8592.namprd19.prod.outlook.com (2603:10b6:208:524::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.26; Wed, 16 Oct 2024 00:05:38 +0000 Received: from BL6PEPF00020E62.namprd04.prod.outlook.com (2603:10b6:208:32a:cafe::19) by BLAPR03CA0106.outlook.office365.com (2603:10b6:208:32a::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.18 via Frontend Transport; Wed, 16 Oct 2024 00:05:38 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 50.222.100.11) smtp.mailfrom=ddn.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=ddn.com; Received-SPF: Pass (protection.outlook.com: domain of ddn.com designates 50.222.100.11 as permitted sender) receiver=protection.outlook.com; client-ip=50.222.100.11; helo=uww-mrp-01.datadirectnet.com; pr=C Received: from uww-mrp-01.datadirectnet.com (50.222.100.11) by BL6PEPF00020E62.mail.protection.outlook.com (10.167.249.23) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8069.17 via Frontend Transport; Wed, 16 Oct 2024 00:05:38 +0000 Received: from localhost (unknown [10.68.0.8]) by uww-mrp-01.datadirectnet.com (Postfix) with ESMTP id 2EDEA29; Wed, 16 Oct 2024 00:05:36 +0000 (UTC) From: Bernd Schubert Date: Wed, 16 Oct 2024 02:05:24 +0200 Subject: [PATCH RFC v4 12/15] io_uring/cmd: let cmds to know about dying task Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241016-fuse-uring-for-6-10-rfc4-v4-12-9739c753666e@ddn.com> References: <20241016-fuse-uring-for-6-10-rfc4-v4-0-9739c753666e@ddn.com> In-Reply-To: <20241016-fuse-uring-for-6-10-rfc4-v4-0-9739c753666e@ddn.com> To: Miklos Szeredi Cc: Jens Axboe , Pavel Begunkov , linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, Joanne Koong , Amir Goldstein , Ming Lei , Bernd Schubert X-Mailer: b4 0.15-dev-2a633 X-Developer-Signature: v=1; a=ed25519-sha256; t=1729037122; l=1907; i=bschubert@ddn.com; s=20240529; h=from:subject:message-id; bh=+fzHnSTkiWQEiYWdcON6N8NsnwP07vKgm8D+2K3HAhk=; b=lvykcPLOz0+E3lvcXwhaBJsNTfIWpVbAAgFu4RQ2eudgqOaPJRb/85cnvaK58SQsZu+F8MXoz GwppeW90uheAOxnHz2+hpInD/JOGPEnoAmzNiPwi/2gNUyf9rSYCUT4 X-Developer-Key: i=bschubert@ddn.com; a=ed25519; pk=EZVU4bq64+flgoWFCVQoj0URAs3Urjno+1fIq9ZJx8Y= X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF00020E62:EE_|IA3PR19MB8592:EE_ X-MS-Office365-Filtering-Correlation-Id: 204b4fc1-ad94-44fa-ab39-08dced764434 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700013|1800799024|376014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?r0toHosHpZyDoCPwWGzYiuawW0zHPfS?= =?utf-8?q?O3+IFptswkRMHj4Bw4SC60lt3H+TA6xixgjpIBrTS780hxfSlyZihn2cXjzQCG1nE?= =?utf-8?q?NhJty84xsQ1a4FPXxwwr9LURXBt2KYpLeMakdROP3+r92b+yydMhH477Ojuh4T6fW?= =?utf-8?q?rBrwxy032zqv36seoEEhfOUlJZTLQhNwH2qiwLQOksRtxpRQvKiHTzWcdIJ6BMR1u?= =?utf-8?q?iPM9ggWUOZr2kt12ChhwXzPahfmH1W6B2aeegmh5kD7g7dWp5A0qLxXGBzDHElrNn?= =?utf-8?q?9w6kxDVlGD8gY6Ee1da5n3zqC19h54zedcImZS/DSnJOVA7Ypxw6u5Ba8EuyrgD24?= =?utf-8?q?0afc3SAX/unbIpEMeU8v8D1bJGifXKDdeNej7vfOtwFFtZ6oNzXCq8HtxjbyQfMsp?= =?utf-8?q?FyH8xE4MmqAk7E+pijDBJW5E6JCg1qGr0jdJzOSG1B5eFjJxEPAN0g80XTOojr+Xk?= =?utf-8?q?W/EaHu6wulxVJZRdzncBNDhan9PtFs2Und3JCdSx5R5yN9rSPNIW5zban06LTs38J?= =?utf-8?q?1iVOHQJruw89WVl2Df+4x3RW72C+xQMpnu4iBGg8gxqPJwmtJIaq79U1SIU44LuV9?= =?utf-8?q?mWfrmVsccliHlJs2mret7sgWOemRCof0O7/r98PumQkbQDs83F8Nc8WZoZRtXpYP6?= =?utf-8?q?nBdsZWvDnZpQm7786K6LP7mio0sTfBy+NXdVGhij1/kmcZLMcyca4cO/TbAN5EiAT?= =?utf-8?q?N6yl7CCRavfEbGM5rWcAsnaP0I3m8SWGI5RRxz09wUuIgJ6+5tsHXyoMLRZqzfCbe?= =?utf-8?q?jbW91SUPwHt3SGVTPEcWDDwh6v1nWIcut5PxYmsspe3T2Ev0tk0sxcecacjrv2yT2?= =?utf-8?q?NXwsIwZ+Vl7SXVRiVXql1KcryKUXz6WzhN9xsN7CVq68F95og4cY7mM2TGDqkEHeV?= =?utf-8?q?7ZDuxMQ/GmMMOtSSUc6YRZTrPmdLNCRYMHV1gYe8e/R/OrOugnkrmtK3V3yAKWZMF?= =?utf-8?q?3tMp47YNk+4wfgLGSBfG7ppoDuEDBgL6KHIghyjQm/if1wgLTK+KTeGpAQ9+j418h?= =?utf-8?q?xon8MPErgpd32RlebnAu70DHVzznQ4dSBMtucmjRjvYlxOIesoycYQybdCbLc+Kt3?= =?utf-8?q?TOqmkSpHd0P7VSu2Y7c2KbiT1Ospm+ZUpuVcUSY6aMWDYKtjsOa0gERbxq1/1Tw28?= =?utf-8?q?cDzuvWuCD05dkvowXkbtUhg3qZPYSsnosrLYtT+6OJX5mi5Y7E5jxgwF26407r45j?= =?utf-8?q?+wKHOOh5WgslDn2mbwzznsw7Jx45A/jQ7u4kIlN/FEiHtXlHbE5PzXszHGPs6IkCz?= =?utf-8?q?UYEn3EA+h7a+qWmhO9L6GSbsWkZV1ZBLjLX5hI4slnEPBgrTHDpbjSo6AtH/8eMDt?= =?utf-8?q?luh/w8Vgi88y?= X-Forefront-Antispam-Report: CIP:50.222.100.11;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:uww-mrp-01.datadirectnet.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(36860700013)(1800799024)(376014);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: VWoubJttg2/cQ4dbgRowpwZDZHCa0lO20d1mXi9QVNvl2RysZ+ZscgCmq0BkTjmFUdtnuqFClLVf1BFgyiABvgQpLTxGzY9mofKq4jV9LWh1GwMyDNs5B/RWaSOUJcj92zr82HqZfFlVur7A6UfAepxf2aRMVdIz8KPc3EkHPbsQHQfUkMYz1aJwBgEYoUxPAWaWn20gkVe8uxR0CAOgo3YDmzqn7MgxqQLgkdBZXL0sGEboO3hUfplPdiWqawoLyE552/sixqRhrEOb9NchM6i3P+LTQCfqytnUXepCTWjTZqEYLu0i4IE1eD2w09eiwhr+eI5yN56OWbt668H/ulnOEJQlupPS4WicilgK2dW6TFU4dPebTBigJ4JIj5jSzBGZyOD4daMtX3BCmw+PA+ZbLWt+26iUH6U8aYb3jhVf0cZIHYy32JnJ9mSasvOQEoixbDD+hl2Xge5L8MI7WWAQUm5gBFkjjYXQ73O/DRZ+fAUTFIO8Zu0lM8VK2Bb/KvIaQIMa3gB8HibQIPXtSHxfVE2xGRbRWSPa96eBQjjV1FVrQVi9ff9SBsshnDIAbbqR3ZbxGKVc8Xsxif4eFjwIlQg5W+jnpd21/5jvQy1c3qBNjYJA5UWPn2MbB+l6F97w6ErgR/5fbB5TBG5KOg== X-OriginatorOrg: ddn.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2024 00:05:38.4587 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 204b4fc1-ad94-44fa-ab39-08dced764434 X-MS-Exchange-CrossTenant-Id: 753b6e26-6fd3-43e6-8248-3f1735d59bb4 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=753b6e26-6fd3-43e6-8248-3f1735d59bb4;Ip=[50.222.100.11];Helo=[uww-mrp-01.datadirectnet.com] X-MS-Exchange-CrossTenant-AuthSource: BL6PEPF00020E62.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA3PR19MB8592 X-BESS-ID: 1729037142-103427-12893-15047-1 X-BESS-VER: 2019.1_20241015.1627 X-BESS-Apparent-Source-IP: 104.47.58.43 X-BESS-Parts: H4sIAAAAAAACA4uuVkqtKFGyUioBkjpK+cVKVoaWBhZAVgZQ0NDYLMnIJC0pMd EizdLAxNLEzMTczNzQNM3I0tQ8ycBUqTYWAFYIL05BAAAA X-BESS-Outbound-Spam-Score: 0.00 X-BESS-Outbound-Spam-Report: Code version 3.2, rules version 3.2.2.259752 [from cloudscan20-208.us-east-2b.ess.aws.cudaops.com] Rule breakdown below pts rule name description ---- ---------------------- -------------------------------- 0.00 BSF_BESS_OUTBOUND META: BESS Outbound X-BESS-Outbound-Spam-Status: SCORE=0.00 using account:ESS124931 scores of KILL_LEVEL=7.0 tests=BSF_BESS_OUTBOUND X-BESS-BRTS-Status: 1 From: Pavel Begunkov When the taks that submitted a request is dying, a task work for that request might get run by a kernel thread or even worse by a half dismantled task. We can't just cancel the task work without running the callback as the cmd might need to do some clean up, so pass a flag instead. If set, it's not safe to access any task resources and the callback is expected to cancel the cmd ASAP. Signed-off-by: Pavel Begunkov Signed-off-by: initial author Signed-off-by: person 2 --- include/linux/io_uring_types.h | 1 + io_uring/uring_cmd.c | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/include/linux/io_uring_types.h b/include/linux/io_uring_types.h index 7abdc09271245ff7de3fb9a905ca78b7561e37eb..869a81c63e4970576155043fce7fe656293d7f58 100644 --- a/include/linux/io_uring_types.h +++ b/include/linux/io_uring_types.h @@ -37,6 +37,7 @@ enum io_uring_cmd_flags { /* set when uring wants to cancel a previously issued command */ IO_URING_F_CANCEL = (1 << 11), IO_URING_F_COMPAT = (1 << 12), + IO_URING_F_TASK_DEAD = (1 << 13), }; struct io_wq_work_node { diff --git a/io_uring/uring_cmd.c b/io_uring/uring_cmd.c index 21ac5fb2d5f087e1174d5c94815d580972db6e3f..82c6001cc0696bbcbebb92153e1461f2a9aeebc3 100644 --- a/io_uring/uring_cmd.c +++ b/io_uring/uring_cmd.c @@ -119,9 +119,13 @@ EXPORT_SYMBOL_GPL(io_uring_cmd_mark_cancelable); static void io_uring_cmd_work(struct io_kiocb *req, struct io_tw_state *ts) { struct io_uring_cmd *ioucmd = io_kiocb_to_cmd(req, struct io_uring_cmd); + unsigned int flags = IO_URING_F_COMPLETE_DEFER; + + if (req->task != current) + flags |= IO_URING_F_TASK_DEAD; /* task_work executor checks the deffered list completion */ - ioucmd->task_work_cb(ioucmd, IO_URING_F_COMPLETE_DEFER); + ioucmd->task_work_cb(ioucmd, flags); } void __io_uring_cmd_do_in_task(struct io_uring_cmd *ioucmd,