From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 47222606A31C for ; Mon, 30 Nov 2026 08:27:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=sg/zkr0J; dkim=fail reason="signature verification failed" (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=JpT2fOok DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=LJRDysBBZmtQsY9KPFREdPzUac6Unki/G5zs+I/bIBE=; b=sg/zkr0JDtsOsRcFXdcgEWFAH6 xvjOV1nn70sdGVnm2rUQgbdWt033sArN/MBvOxSy7G+HoScqXYB3zC7TxIFA82hqPjKRifafKfWX+ sKPxmD/235vPAt17jDukehS1nnyihtRtKPJEZ8V+T6l6w0nY8WYqkNqFuZcc2gjjMSbzxkESVnBo6 EraFnJmWJUW5oAGjZPdM06CEEYjZ5gDWSyo8/5xXsvJGS2EFdeejhgDoKd0zhNfDL6VBHOPZk7C1j nNEqch3EjZTsf190gcSTQ5A0KaCuD0lhxmZTIQKZGGU50+boIvfN+NL2ZECUJi2jJNWyxmILiXiV6 jyrAMW6g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xXwj4-00000003k4x-4Aqo; Mon, 30 Nov 2026 08:27:06 +0000 Received: from tor.source.kernel.org ([172.105.4.254]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xXwj3-00000003k3m-2JY5 for linux-mtd@lists.infradead.org; Mon, 30 Nov 2026 08:27:05 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id C42036014A; Mon, 30 Nov 2026 08:27:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0544B1F000C1; Mon, 30 Nov 2026 08:26:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796027224; bh=dcicYtM4CXREuCjSkCy3tm2qMSQgS8afAavJazwGu+Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=JpT2fOokwGzKC+vMwbSsengWLu+KrOdsatZo7niaBch3lmIZs5Q9FCKr1EQ9JAQNU JOTBd9AgigXKviwyrHUsD/3L3hXZuBs/JTLBD5b0bKaLzr9fW3A8yachrUfLokqxFp 79Egzd1dWF/ObC3rg+To9ocSkCC18FQQbQ6x4F10dTAktwwEocrbV7Y142DmQQGK3K JocLy09TRCdqsZtzjuBeJNDhTANclTXe3/YO8C2QWaEk5zbUA5beqFj9RBTjhk25BW 3zGPbbNq8kCo3PhLVwXMmnLP9X4bVNEYAJIflzhjSQEqaRvVVkAOfEon8avwowGdQG tTscjDybSqa7g== From: "Richard Weinberger (sigma star gmbh)" To: linux-mtd@lists.infradead.org Cc: fuse-devel@lists.linux.dev, netdev@vger.kernel.org, horms@kernel.org, pabeni@redhat.com, kuba@kernel.org, edumazet@google.com, davem@davemloft.net, miklos@szeredi.hu, vigneshr@ti.com, miquel.raynal@bootlin.com, david.oberhollenzer@sigma-star.at, upstream+linux@sigma-star.at, Richard Weinberger Subject: [PATCH 04/10] fuse: Convert CUSE to the interface for userspace backed devices Date: Mon, 30 Nov 2026 09:26:27 +0100 Message-ID: <20261130082634.2750846-5-rw@kernel.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261130082634.2750846-1-rw@kernel.org> References: <20261130082634.2750846-1-rw@kernel.org> X-Archived-By: MIME-Version: 1.0 X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-mtd" X-Spam-Status: No, score=-16.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 From: Richard Weinberger CUSE embeds struct fuse_conn and struct fuse_mount in struct cuse_conn and sets up the connection, its channel and its device on its own. fuse_conn_new_dev() and fuse_conn_install_dev() do the very same. Use them, and fuse_conn_from_file(), fuse_conn_send_bg() and fuse_conn_abort() too. struct cuse_conn becomes the private data of the connection and is freed by the release callback. CUSE opens files on the dummy mount of its connection. Add fuse_conn_dev_mount() for that, it is not part of . Signed-off-by: Richard Weinberger --- fs/fuse/cuse.c | 56 ++++++++++++++++++++++-------------------------- fs/fuse/fuse_i.h | 3 +++ fs/fuse/helper.c | 10 +++++++++ 3 files changed, 39 insertions(+), 30 deletions(-) diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c index 73512b26da10..c77cc85513e0 100644 --- a/fs/fuse/cuse.c +++ b/fs/fuse/cuse.c @@ -13,7 +13,7 @@ * * A CUSE instance involves the following objects. * - * cuse_conn : contains fuse_conn and serves as bonding structure + * cuse_conn : private data of the fuse_conn, serves as bonding structure * channel : file handle connected to the userland CUSE server * cdev : the implemented character device * dev : generic device for cdev @@ -59,8 +59,7 @@ struct cuse_conn { struct list_head list; /* linked on cuse_conntbl */ - struct fuse_mount fm; /* Dummy mount referencing fc */ - struct fuse_conn fc; /* fuse connection */ + struct fuse_conn *fc; /* fuse connection */ struct cdev *cdev; /* associated character device */ struct device *dev; /* device representing @cdev */ @@ -74,7 +73,7 @@ static struct class *cuse_class; static struct cuse_conn *fc_to_cc(struct fuse_conn *fc) { - return container_of(fc, struct cuse_conn, fc); + return fuse_conn_priv(fc); } static struct list_head *cuse_conntbl_head(dev_t devt) @@ -123,7 +122,7 @@ static int cuse_open(struct inode *inode, struct file *file) mutex_lock(&cuse_lock); list_for_each_entry(pos, cuse_conntbl_head(devt), list) if (pos->dev->devt == devt) { - fuse_conn_get(&pos->fc); + fuse_conn_get(pos->fc); cc = pos; break; } @@ -137,9 +136,9 @@ static int cuse_open(struct inode *inode, struct file *file) * Generic permission check is already done against the chrdev * file, proceed to open. */ - rc = fuse_do_open(&cc->fm, 0, file, 0); + rc = fuse_do_open(fuse_conn_dev_mount(cc->fc), 0, file, 0); if (rc) - fuse_conn_put(&cc->fc); + fuse_conn_put(cc->fc); return rc; } @@ -370,7 +369,7 @@ static void cuse_process_init_reply(struct fuse_args *args, int error) err_region: unregister_chrdev_region(devt, 1); err: - fuse_chan_abort(fc->chan, false); + fuse_conn_abort(fc); goto out; } @@ -378,7 +377,6 @@ static int cuse_send_init(struct cuse_conn *cc) { int rc; struct folio *folio; - struct fuse_mount *fm = &cc->fm; struct cuse_init_args *ia; struct fuse_args_pages *ap; @@ -413,10 +411,10 @@ static int cuse_send_init(struct cuse_conn *cc) ap->descs = &ia->desc; ia->folio = folio; ia->desc.length = ap->args.out_args[1].size; - ia->fc = &cc->fc; + ia->fc = cc->fc; ap->args.end = cuse_process_init_reply; - rc = fuse_simple_background(fm, &ap->args, GFP_KERNEL); + rc = fuse_conn_send_bg(cc->fc, &ap->args, GFP_KERNEL); if (rc) { kfree(ia); err_free_folio: @@ -426,9 +424,9 @@ static int cuse_send_init(struct cuse_conn *cc) return rc; } -static void cuse_fc_release(struct fuse_conn *fc) +static void cuse_conn_release(void *priv) { - kfree(fc_to_cc(fc)); + kfree(priv); } /** @@ -450,32 +448,31 @@ static int cuse_channel_open(struct inode *inode, struct file *file) { struct fuse_dev *fud; struct cuse_conn *cc; - struct fuse_chan *fch __free(fuse_chan_free) = fuse_dev_chan_new(); int rc; - if (!fch) - return -ENOMEM; - /* set up cuse_conn */ cc = kzalloc_obj(*cc); if (!cc) return -ENOMEM; + INIT_LIST_HEAD(&cc->list); + /* * Limit the cuse channel to requests that can * be represented in file->f_cred->user_ns. */ - fuse_conn_init(&cc->fc, &cc->fm, file->f_cred->user_ns, no_free_ptr(fch)); - cc->fc.release = cuse_fc_release; - fud = fuse_dev_alloc_install(cc->fc.chan); - fuse_conn_put(&cc->fc); - if (!fud) + cc->fc = fuse_conn_new_dev(file->f_cred->user_ns, cuse_conn_release, cc); + if (!cc->fc) { + kfree(cc); return -ENOMEM; + } - INIT_LIST_HEAD(&cc->list); + /* From now on the channel holds the connection, and with it cc */ + fud = fuse_conn_install_dev(cc->fc); + fuse_conn_put(cc->fc); + if (!fud) + return -ENOMEM; - /* Pairs with smp_load_acquire() readers of fch->initialized */ - smp_store_release(&cc->fc.chan->initialized, 1); rc = cuse_send_init(cc); if (rc) { fuse_dev_put(fud); @@ -499,8 +496,7 @@ static int cuse_channel_open(struct inode *inode, struct file *file) */ static int cuse_channel_release(struct inode *inode, struct file *file) { - struct fuse_dev *fud = __fuse_get_dev(file); - struct cuse_conn *cc = fc_to_cc(fud->chan->conn); + struct cuse_conn *cc = fc_to_cc(fuse_conn_from_file(file)); /* remove from the conntbl, no more access from this point on */ mutex_lock(&cuse_lock); @@ -532,7 +528,7 @@ static ssize_t cuse_class_waiting_show(struct device *dev, { struct cuse_conn *cc = dev_get_drvdata(dev); - return sprintf(buf, "%d\n", atomic_read(&cc->fc.chan->num_waiting)); + return sprintf(buf, "%d\n", atomic_read(&cc->fc->chan->num_waiting)); } static DEVICE_ATTR(waiting, 0400, cuse_class_waiting_show, NULL); @@ -542,7 +538,7 @@ static ssize_t cuse_class_abort_store(struct device *dev, { struct cuse_conn *cc = dev_get_drvdata(dev); - fuse_chan_abort(cc->fc.chan, false); + fuse_conn_abort(cc->fc); return count; } static DEVICE_ATTR(abort, 0200, NULL, cuse_class_abort_store); @@ -600,7 +596,7 @@ static void __exit cuse_exit(void) class_destroy(cuse_class); /* * Wait for pending call_rcu() callbacks that call back into - * this module via fc->release (cuse_fc_release). + * this module (cuse_conn_release). */ rcu_barrier(); } diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index 8bceab59c1ca..a90ac46f1837 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -1117,6 +1117,9 @@ void fuse_dentry_set_epoch(struct dentry *dentry, u64 epoch); void fuse_conn_init(struct fuse_conn *fc, struct fuse_mount *fm, struct user_namespace *user_ns, struct fuse_chan *fch); +/* The dummy mount of a connection made by fuse_conn_new_dev() */ +struct fuse_mount *fuse_conn_dev_mount(struct fuse_conn *fc); + int fuse_send_init(struct fuse_mount *fm); /** diff --git a/fs/fuse/helper.c b/fs/fuse/helper.c index 5266c4e47eeb..1e389b4f5df9 100644 --- a/fs/fuse/helper.c +++ b/fs/fuse/helper.c @@ -93,6 +93,16 @@ void *fuse_conn_priv(struct fuse_conn *fc) } EXPORT_SYMBOL_GPL(fuse_conn_priv); +/* + * For CUSE, which opens files on the dummy mount of its connection. Not part + * of the interface for users outside of fs/fuse/. + */ +struct fuse_mount *fuse_conn_dev_mount(struct fuse_conn *fc) +{ + return &to_dev_conn(fc)->fm; +} +EXPORT_SYMBOL_GPL(fuse_conn_dev_mount); + /** * fuse_conn_install_dev - attach a connection to its control device * @fc: connection created by fuse_conn_new_dev() -- 2.55.0 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/