From patchwork Thu Nov 21 23:43:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Schubert X-Patchwork-Id: 13882475 Received: from outbound-ip168b.ess.barracuda.com (outbound-ip168b.ess.barracuda.com [209.222.82.102]) (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 C5C9F5680 for ; Fri, 22 Nov 2024 00:16:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=209.222.82.102 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732234615; cv=fail; b=ckD/s73d9q9z+Gq2umxw8/5UQw5mE0L+NoQetzUINp5fKfp23FcU0y8SvxrAs8badRFmr3aE0Qq/pF/DrOij2juNKzYWRuIZ/LJBgrd2Kiujl8XH5DjS7AxfkY4hkHtcifykWuiihaQyRUKmS8Ynjap5sdrX1vSVxFJMiubolsc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732234615; c=relaxed/simple; bh=2Luee4LJP7dDyAS7bu0Pq+sCS6Tayg+HsMqk/18uS2c=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mQlGTV6nL5cETTP/KLlGaJiTTWhNDneyiJ1M/BfuvUMs5CZge4kfUT3u3VVzYrYURIEdC1ICYYc6o42oFb5XVr9Oq5nmzJ+FLcInzHGW2uPl+iqTYlWGXMPYRcaDVcHpoH16p8LCUquJuq8tNnfjvhwz+nTOwrzS8zLDCisM0gE= 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=hiZhILI9; arc=fail smtp.client-ip=209.222.82.102 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="hiZhILI9" Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2170.outbound.protection.outlook.com [104.47.57.170]) by mx-outbound47-71.us-east-2c.ess.aws.cudaops.com (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 22 Nov 2024 00:16:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=kV4Nxkog4PEIwhW8uuif0H03eCRnqC5EulijrETzJwhTt7F2hzlHzCRuArOZthnWYKbQ6X57sGKS2Qvmq52PekMWOb8rfXUwmNCDJzP4OcB9QhzvC8WWWBR0TNMVE1BVpRO6ivyPvBnJe7/1+O9AUoCw0HRYlIzKnzZJuy32Wg4+3SfqKN4Lb5HZukzl9yzOKJxeNLoKPkb8KccJ33J8f6pBHGUVVmx/tNtuhAVhDMRIGoC7TDBVhcDLmFC6gInCvhgcseyzpKQ9ZJ5UhN2qk5yWZFeY3wCPmCSsn21cRiiRK3KvB6W+NgBj6U+Wd8KJmhLGHSgpgpD5mMuZedLKoQ== 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=FC8P0EzozdIp8fFeo4tlulUzBMRxS4NMCTc9gKCnZvk=; b=oU7wX17F5KOEU22IHKgtaFWype8LKHhSS/QG2IhkM1nlR3h8tVmrNxWWdg64c5UmVD/4/rRfU8/0Ow4iSjtzPE1dUmjSjOf3KVsULQGcfUwooFNnGkMaUZGUYTZUUmCE6a1LC9ZnB1f4a/ieOqQ9bueI3AnjoFkggimw8Lw04K0kKSHdV5vsMSQLbpSB+onaiMlTHMC5rmMkfBo42IEUBGzChlcUdE16VrYiq85eyMbT6Xv6A3Dzjw/VBl2jmoBY3T94defwvlDZJ5uhOE73wIuziVeZ/lcUykithxMpkhGqUPfdfpXbyfEM6JnhAAQ6hBEdHKSbLZuPod0boBp5Sw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 50.222.100.11) smtp.rcpttodomain=bsbernd.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=FC8P0EzozdIp8fFeo4tlulUzBMRxS4NMCTc9gKCnZvk=; b=hiZhILI9NLNnaRj28TwVXiYNyFYagRwQqGtKBXarsUEDgP9murEBm9cZC6pjV14WHZ10ok2foqsL0Lx/FYh5KlbETdLgSJdTqgxZbiPcyu/V/dyTOZDvwrAVAddUQZVev9LQEIgUNmwXSKog+pM4YVbrWL1PT5r0tiAvHxhEnn8= Received: from BN9P221CA0029.NAMP221.PROD.OUTLOOK.COM (2603:10b6:408:10a::27) by SA1PR19MB7087.namprd19.prod.outlook.com (2603:10b6:806:2b8::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.24; Thu, 21 Nov 2024 23:44:06 +0000 Received: from BL02EPF0002992D.namprd02.prod.outlook.com (2603:10b6:408:10a:cafe::9f) by BN9P221CA0029.outlook.office365.com (2603:10b6:408:10a::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8182.15 via Frontend Transport; Thu, 21 Nov 2024 23:44:05 +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 BL02EPF0002992D.mail.protection.outlook.com (10.167.249.58) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8182.16 via Frontend Transport; Thu, 21 Nov 2024 23:44:05 +0000 Received: from localhost (unknown [10.68.0.8]) by uww-mrp-01.datadirectnet.com (Postfix) with ESMTP id 812CA2D; Thu, 21 Nov 2024 23:44:04 +0000 (UTC) From: Bernd Schubert Date: Fri, 22 Nov 2024 00:43:31 +0100 Subject: [PATCH RFC v6 15/16] fuse: {io-uring} Prevent mount point hang on fuse-server termination Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241122-fuse-uring-for-6-10-rfc4-v6-15-28e6cdd0e914@ddn.com> References: <20241122-fuse-uring-for-6-10-rfc4-v6-0-28e6cdd0e914@ddn.com> In-Reply-To: <20241122-fuse-uring-for-6-10-rfc4-v6-0-28e6cdd0e914@ddn.com> To: Miklos Szeredi Cc: Jens Axboe , Pavel Begunkov , linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, Joanne Koong , Josef Bacik , Amir Goldstein , Ming Lei , David Wei , bernd@bsbernd.com, Bernd Schubert X-Mailer: b4 0.15-dev-2a633 X-Developer-Signature: v=1; a=ed25519-sha256; t=1732232629; l=10060; i=bschubert@ddn.com; s=20240529; h=from:subject:message-id; bh=2Luee4LJP7dDyAS7bu0Pq+sCS6Tayg+HsMqk/18uS2c=; b=2VgyTA1IDBmL7v1AnjF44TmcI+9Dwi8cBHujzShH0UbjeSR4PJlvCsqo0yMCW+9AfWhHSz0yI nSZPwwfwaFIBl9fWemVq06CQoGH1pIZhN0oVraKRv8ph723ilUsxlii X-Developer-Key: i=bschubert@ddn.com; a=ed25519; pk=EZVU4bq64+flgoWFCVQoj0URAs3Urjno+1fIq9ZJx8Y= X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0002992D:EE_|SA1PR19MB7087:EE_ X-MS-Office365-Filtering-Correlation-Id: ec518bcc-920d-4c06-db16-08dd0a8662e7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|1800799024|36860700013|82310400026|376014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?bR21F/e3gVaAlIfKien2MKfzg2ynU5z?= =?utf-8?q?bgUYdwZP83gR0SCKZxvMXb20mZ6xHV62W0anQEyV+3Ynv4+5i6pg0Qor7ixF6odAy?= =?utf-8?q?SN7688zeakuNYJjcdsJA17UBsff3iJZVdWmF56sTuzGXJLH9qhBPLX+BrVA1fQChf?= =?utf-8?q?QJh62Qokj7VdxqQYknHubBVw0xYcvGkg+rAOhhGy5H/BU4tnDZ0Oy6tRQJZkfvnGb?= =?utf-8?q?R5q9WdFXndaEWCZ+MAaG/6XwrprrvXkEyIgPPr8mFO5hnKhJs++qfAPevz1VrMv4W?= =?utf-8?q?SPHdf4N6BvBkQTxiLeHTjVJh/fUke5xIctF/G+2uL/uTMwXv/bMuqaqhfwviK8mQ/?= =?utf-8?q?pPxnPgqBvsOQhob2j0NFiiqR8SFduL70EfpGZPa7mbuNaWmyX+DiLbkRBtxrqwXsC?= =?utf-8?q?B7xXMaKDJN+zquyovQQkmmpzrvSpHjJjW017K9ZIfn/27PF+ReGoHmTJygR8j4m0V?= =?utf-8?q?00PcmpXvlT2xeOACd49C3e6/IswP9zE/XRsXgnPDjz1ebCdKbfj/On9EQ9K4WKOh2?= =?utf-8?q?HsA6WCn8rUDPuS3Dpk9WAzBFuFiCzOcz9yDuc5BINYALvW5pMlQ23FlVlEmsMK+Bb?= =?utf-8?q?6YauVPiKmrgLevd3XZ+j4z8F5ZQz0nRtNEfiRRa3f9ON/haLHANJ1jyJpTZn193pT?= =?utf-8?q?dRnS2mLf/00SoEbkI0AOr6axS6NVxbtt6+TYv/Fhr1o+OANRpD0PfDyto87UYuwZf?= =?utf-8?q?TKEYy9Th1onIrCHGyCC/jEcoA/tamIDgFW+UMLYTpNbR/CiTWaRjVA/0nPLpvZNhf?= =?utf-8?q?ArYm0ZSzlRs1b5oNOSNQtDYTe2xjclWNjf23tXkykcTxB5oyrlycKJGiNLzQ5wHxE?= =?utf-8?q?ggluFR/kSTEmuNrlFjWefoaEnyOh15i+nvzg6T+C93edzOrtLoaEfdok0bHjz/T+u?= =?utf-8?q?ylOll7uHxHNdh1l61IbvY3T73/toOvtEMv+f5mXOGTZGOj3eW39EeFHqycDLNBi4d?= =?utf-8?q?nAzOUXG24TCw1SkKJl840rS1L6N1tIWCjsIazuvAEKzuo4G4F1yA2xjuZ8SqWL/EZ?= =?utf-8?q?e7JsqGho9JpqHwSwtMrUk7VgbwJod5Wmnt7Z8wYzr57jes7g878gAuco3EJMnUI4S?= =?utf-8?q?b1f0EmlOBI+ULLkdwyocDRqYLr9tiZxW2J4+P4u3o+Yy92YAq4RxZiUTekpmQoQ6Z?= =?utf-8?q?mKXsBddu4eay7+jxE9P0HfCvaOvEGLGsUk2ecFXUzndIRoEpGuv9dz+Is6m7+hG8B?= =?utf-8?q?5EsplFJW/WHq3EnDHCDE3t830o/jnO+3xtO63gyqEU0qlrz04GcFjTP15DQw9ukHR?= =?utf-8?q?aQfbjaISyVp70G5c2DUk5xn4ulgzPAtrc0MfcI02rpjR4dxHeCiBIOGpwVfhetnaD?= =?utf-8?q?GOk7bYHkwOpS9tLl39JDhQn9h0DznhwSiw=3D=3D?= 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)(7416014)(1800799024)(36860700013)(82310400026)(376014);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: FqvvPrhHaNpnJMh6oxaNq9RFqwEuL0q9OjELF7mEnMz+5ypLnpo3GCxuvr9qpwg5q53wKNoo2r1jbpcl/7CXQgMOS3nx8kKJmzjOzxOhEPEvC0sxvanq46hhFqVSVHo5nOp60AbwbahHFtB2pKpATLIejhgfgpNhSQm9ctwrjWz8hoxEvVJ2IDmI87yhzEe49b0QAnAL65jODm6qBpsf0xu25meglrHfGwVQpDnITLTwr0EL3g8xUtgMivhjPaKq4V7+LFotADtICt94mk8Ttm+BrcD9iB0lqECNlsjS1z+ydJ3GAvauWEwKJXHtUx1fbObFHvwqYPKmCAkn81S3Gt5jX564qPCdPIOmqgMSwrFCaxFPF+7I6gqUF9NMYWWtFuLvVeehqTdvjHM6kjJaZixOtMfA5NgqbW1scJa3F5njlO3tlCTh6+cgbSW2FGx/CXEpc4h2JjTneT+RvZ/eshLB0GYHB9GcgGiOpeG5GW41BxVIOpN19wG8g9gfsJEnC17QANwyOTEUKIEH30DpS8RH2rDJ6TvkQF7qe3jSQwsi7FVS/BXfoMoD4xPNeZHUo4Kp24+8FzhGwCjmCuJ9LVRHGFWW/T4DWebG7RX+Sc9cbhAIpYkvbYt8MzXjGa4sfow7bzrEcQ2CHfN3YBot9A== X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Nov 2024 23:44:05.6329 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ec518bcc-920d-4c06-db16-08dd0a8662e7 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: BL02EPF0002992D.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR19MB7087 X-OriginatorOrg: ddn.com X-BESS-ID: 1732234612-112103-13741-60790-1 X-BESS-VER: 2019.1_20241121.1615 X-BESS-Apparent-Source-IP: 104.47.57.170 X-BESS-Parts: H4sIAAAAAAACA4uuVkqtKFGyUioBkjpK+cVKVpbmppZAVgZQ0MzAyMDIJNksNd XQyDgt2dA4xdQyycAoLTHF2NTC0NxYqTYWAOoQU0xBAAAA X-BESS-Outbound-Spam-Score: 0.50 X-BESS-Outbound-Spam-Report: Code version 3.2, rules version 3.2.2.260588 [from cloudscan23-156.us-east-2b.ess.aws.cudaops.com] Rule breakdown below pts rule name description ---- ---------------------- -------------------------------- 0.50 BSF_RULE7568M META: Custom Rule 7568M 0.00 BSF_BESS_OUTBOUND META: BESS Outbound 0.00 BSF_SC0_MISMATCH_TO META: Envelope rcpt doesn't match header X-BESS-Outbound-Spam-Status: SCORE=0.50 using account:ESS124931 scores of KILL_LEVEL=7.0 tests=BSF_RULE7568M, BSF_BESS_OUTBOUND, BSF_SC0_MISMATCH_TO X-BESS-BRTS-Status: 1 When the fuse-server terminates while the fuse-client or kernel still has queued URING_CMDs, these commands retain references to the struct file used by the fuse connection. This prevents fuse_dev_release() from being invoked, resulting in a hung mount point. This patch addresses the issue by making queued URING_CMDs cancelable, allowing fuse_dev_release() to proceed as expected and preventing the mount point from hanging. Signed-off-by: Bernd Schubert --- fs/fuse/dev_uring.c | 103 ++++++++++++++++++++++++++++++++++++++++---------- fs/fuse/dev_uring_i.h | 12 ++++++ 2 files changed, 94 insertions(+), 21 deletions(-) diff --git a/fs/fuse/dev_uring.c b/fs/fuse/dev_uring.c index d0f8f0932e1715babebbc715c1846a5052419eb9..b7a6c3946611a9fdecd4996117b45b3081ad6edd 100644 --- a/fs/fuse/dev_uring.c +++ b/fs/fuse/dev_uring.c @@ -23,6 +23,7 @@ MODULE_PARM_DESC(enable_uring, struct fuse_uring_cmd_pdu { struct fuse_ring_ent *ring_ent; + struct fuse_ring_queue *queue; }; const struct fuse_iqueue_ops fuse_io_uring_ops; @@ -221,6 +222,7 @@ static struct fuse_ring_queue *fuse_uring_create_queue(struct fuse_ring *ring, struct fuse_conn *fc = ring->fc; struct fuse_ring_queue *queue; struct list_head *pq; + struct fuse_ring_ent *ent, *next; queue = kzalloc(sizeof(*queue), GFP_KERNEL_ACCOUNT); if (!queue) @@ -249,6 +251,12 @@ static struct fuse_ring_queue *fuse_uring_create_queue(struct fuse_ring *ring, INIT_LIST_HEAD(&queue->ent_in_userspace); INIT_LIST_HEAD(&queue->fuse_req_queue); INIT_LIST_HEAD(&queue->fuse_req_bg_queue); + INIT_LIST_HEAD(&queue->ent_released); + + list_for_each_entry_safe(ent, next, &queue->ent_released, list) { + list_del_init(&ent->list); + kfree(ent); + } queue->fpq.processing = pq; fuse_pqueue_init(&queue->fpq); @@ -281,8 +289,7 @@ static void fuse_uring_stop_fuse_req_end(struct fuse_ring_ent *ent) /* * Release a request/entry on connection tear down */ -static void fuse_uring_entry_teardown(struct fuse_ring_ent *ent, - bool need_cmd_done) +static void fuse_uring_entry_teardown(struct fuse_ring_ent *ent) { struct fuse_ring_queue *queue = ent->queue; @@ -292,7 +299,7 @@ static void fuse_uring_entry_teardown(struct fuse_ring_ent *ent, */ lockdep_assert_not_held(&ent->queue->lock); - if (need_cmd_done) { + if (ent->need_cmd_done) { pr_devel("qid=%d sending cmd_done\n", queue->qid); io_uring_cmd_done(ent->cmd, -ENOTCONN, 0, @@ -302,8 +309,16 @@ static void fuse_uring_entry_teardown(struct fuse_ring_ent *ent, if (ent->fuse_req) fuse_uring_stop_fuse_req_end(ent); - list_del_init(&ent->list); - kfree(ent); + /* + * The entry must not be freed immediately, due to access of direct + * pointer access of entries through IO_URING_F_CANCEL - there is a risk + * of race between daemon termination (which triggers IO_URING_F_CANCEL + * and accesses entries without checking the list state first + */ + spin_lock(&queue->lock); + list_move(&ent->list, &queue->ent_released); + ent->state = FRRS_RELEASED; + spin_unlock(&queue->lock); } static void fuse_uring_stop_list_entries(struct list_head *head, @@ -323,15 +338,15 @@ static void fuse_uring_stop_list_entries(struct list_head *head, continue; } + ent->need_cmd_done = ent->state != FRRS_USERSPACE; + ent->state = FRRS_TEARDOWN; list_move(&ent->list, &to_teardown); } spin_unlock(&queue->lock); /* no queue lock to avoid lock order issues */ list_for_each_entry_safe(ent, next, &to_teardown, list) { - bool need_cmd_done = ent->state != FRRS_USERSPACE; - - fuse_uring_entry_teardown(ent, need_cmd_done); + fuse_uring_entry_teardown(ent); queue_refs = atomic_dec_return(&ring->queue_refs); if (WARN_ON_ONCE(queue_refs < 0)) @@ -442,6 +457,49 @@ void fuse_uring_stop_queues(struct fuse_ring *ring) } } +/* + * Handle IO_URING_F_CANCEL, typically should come on daemon termination + */ +static void fuse_uring_cancel(struct io_uring_cmd *cmd, + unsigned int issue_flags, struct fuse_conn *fc) +{ + struct fuse_uring_cmd_pdu *pdu = (struct fuse_uring_cmd_pdu *)cmd->pdu; + struct fuse_ring_queue *queue = pdu->queue; + struct fuse_ring_ent *ent = pdu->ring_ent; + bool need_cmd_done = false; + + /* + * direct access on ent - it must not be destructed as long as + * IO_URING_F_CANCEL might come up + */ + spin_lock(&queue->lock); + if (ent->state == FRRS_WAIT) { + ent->state = FRRS_USERSPACE; + list_move(&ent->list, &queue->ent_in_userspace); + need_cmd_done = true; + } + spin_unlock(&queue->lock); + + if (need_cmd_done) + io_uring_cmd_done(cmd, -ENOTCONN, 0, issue_flags); + + /* + * releasing the last entry should trigger fuse_dev_release() if + * the daemon was terminated + */ +} + +static void fuse_uring_prepare_cancel(struct io_uring_cmd *cmd, int issue_flags, + struct fuse_ring_ent *ring_ent) +{ + struct fuse_uring_cmd_pdu *pdu = (struct fuse_uring_cmd_pdu *)cmd->pdu; + + pdu->ring_ent = ring_ent; + pdu->queue = ring_ent->queue; + + io_uring_cmd_mark_cancelable(cmd, issue_flags); +} + /* * Checks for errors and stores it into the request */ @@ -665,7 +723,8 @@ static int fuse_uring_send_next_to_ring(struct fuse_ring_ent *ring_ent) * Put a ring request onto hold, it is no longer used for now. */ static void fuse_uring_ent_avail(struct fuse_ring_ent *ring_ent, - struct fuse_ring_queue *queue) + struct fuse_ring_queue *queue, + unsigned int issue_flags) __must_hold(&queue->lock) { struct fuse_ring *ring = queue->ring; @@ -682,6 +741,7 @@ static void fuse_uring_ent_avail(struct fuse_ring_ent *ring_ent, return; } + fuse_uring_prepare_cancel(ring_ent->cmd, issue_flags, ring_ent); list_move(&ring_ent->list, &queue->ent_avail_queue); ring_ent->state = FRRS_WAIT; @@ -789,7 +849,8 @@ static void fuse_uring_commit(struct fuse_ring_ent *ring_ent, * Get the next fuse req and send it */ static void fuse_uring_next_fuse_req(struct fuse_ring_ent *ring_ent, - struct fuse_ring_queue *queue) + struct fuse_ring_queue *queue, + unsigned int issue_flags) { int has_next, err; int prev_state = ring_ent->state; @@ -798,7 +859,7 @@ static void fuse_uring_next_fuse_req(struct fuse_ring_ent *ring_ent, spin_lock(&queue->lock); has_next = fuse_uring_ent_assign_req(ring_ent); if (!has_next) { - fuse_uring_ent_avail(ring_ent, queue); + fuse_uring_ent_avail(ring_ent, queue, issue_flags); spin_unlock(&queue->lock); break; /* no request left */ } @@ -873,7 +934,7 @@ static int fuse_uring_commit_fetch(struct io_uring_cmd *cmd, int issue_flags, * and fetching is done in one step vs legacy fuse, which has separated * read (fetch request) and write (commit result). */ - fuse_uring_next_fuse_req(ring_ent, queue); + fuse_uring_next_fuse_req(ring_ent, queue, issue_flags); return 0; } @@ -915,7 +976,7 @@ static void _fuse_uring_fetch(struct fuse_ring_ent *ring_ent, struct fuse_iqueue *fiq = &fc->iq; spin_lock(&queue->lock); - fuse_uring_ent_avail(ring_ent, queue); + fuse_uring_ent_avail(ring_ent, queue, issue_flags); ring_ent->cmd = cmd; spin_unlock(&queue->lock); @@ -1085,6 +1146,11 @@ int fuse_uring_cmd(struct io_uring_cmd *cmd, unsigned int issue_flags) if (fc->aborted) return err; + if ((unlikely(issue_flags & IO_URING_F_CANCEL))) { + fuse_uring_cancel(cmd, issue_flags, fc); + return 0; + } + switch (cmd_op) { case FUSE_URING_REQ_FETCH: err = fuse_uring_fetch(cmd, issue_flags, fc); @@ -1142,7 +1208,7 @@ fuse_uring_send_req_in_task(struct io_uring_cmd *cmd, return; err: - fuse_uring_next_fuse_req(ring_ent, queue); + fuse_uring_next_fuse_req(ring_ent, queue, issue_flags); } static struct fuse_ring_queue *fuse_uring_task_to_queue(struct fuse_ring *ring) @@ -1197,14 +1263,11 @@ void fuse_uring_queue_fuse_req(struct fuse_iqueue *fiq, struct fuse_req *req) if (ring_ent) { struct io_uring_cmd *cmd = ring_ent->cmd; - struct fuse_uring_cmd_pdu *pdu = - (struct fuse_uring_cmd_pdu *)cmd->pdu; - err = -EIO; if (WARN_ON_ONCE(ring_ent->state != FRRS_FUSE_REQ)) goto err; - pdu->ring_ent = ring_ent; + /* pdu already set by preparing IO_URING_F_CANCEL */ io_uring_cmd_complete_in_task(cmd, fuse_uring_send_req_in_task); } @@ -1257,12 +1320,10 @@ bool fuse_uring_queue_bq_req(struct fuse_req *req) list); if (ring_ent && req) { struct io_uring_cmd *cmd = ring_ent->cmd; - struct fuse_uring_cmd_pdu *pdu = - (struct fuse_uring_cmd_pdu *)cmd->pdu; fuse_uring_add_req_to_ring_ent(ring_ent, req); - pdu->ring_ent = ring_ent; + /* pdu already set by preparing IO_URING_F_CANCEL */ io_uring_cmd_complete_in_task(cmd, fuse_uring_send_req_in_task); } spin_unlock(&queue->lock); diff --git a/fs/fuse/dev_uring_i.h b/fs/fuse/dev_uring_i.h index 8426337361c72a30dca8f6fd9012ea3827160091..6af7754249623102f48a4c5c924a21b20851925f 100644 --- a/fs/fuse/dev_uring_i.h +++ b/fs/fuse/dev_uring_i.h @@ -28,6 +28,12 @@ enum fuse_ring_req_state { /* The ring entry is in or on the way to user space */ FRRS_USERSPACE, + + /* The ring entry is in teardown */ + FRRS_TEARDOWN, + + /* The ring entry is released, but not freed yet */ + FRRS_RELEASED, }; /** A fuse ring entry, part of the ring queue */ @@ -52,6 +58,9 @@ struct fuse_ring_ent { */ unsigned int state; + /* The entry needs io_uring_cmd_done for teardown */ + unsigned int need_cmd_done; + struct fuse_req *fuse_req; }; @@ -84,6 +93,9 @@ struct fuse_ring_queue { /* entries in userspace */ struct list_head ent_in_userspace; + /* entries that are released */ + struct list_head ent_released; + /* fuse requests waiting for an entry slot */ struct list_head fuse_req_queue;