Skip to contentSkip to conversation

MUSE: Userspace backed MTD v3

PATCH In review Richard Weinberger 5 participants 38 messages Jan 24, 2021 – Apr 13, 2021

Subsystems (5)
lore
Share & tools
lore

Richard Weinberger

author maintainer
#0 lore raw

cover MUSE: Userspace backed MTD v3

I'm happy to announce the first non-RFC version of this patch set. Over the xmas holidays I found some time to experiment with various userspace implementations of MTDs and gave the kernel side more fine-tuning.

Rationale:
----------

When working with flash devices a common task is emulating them to run various tests or inspect dumps from real hardware. To achieve that we have plenty of emulators in the MTD subsystem: mtdram, block2mtd, nandsim.

Each of them implements an ad-hoc MTD and have various drawbacks. Over the last years some developers tried to extend them but these attempts often got rejected because they added just more adhoc feature instead of addressing overall problems.

MUSE is a novel approach to address the need of advanced MTD emulators. Advanced means in this context supporting different (vendor specific) image formats, different ways for fault injection (fuzzing) and recoding/replaying IOs to emulate power cuts.

The core goal of MUSE is having the complexity on the userspace side and only a small MTD driver in kernelspace.
While playing with different approaches I realized that FUSE offers everything we need. So MUSE is a little like CUSE except that it does not implement a bare character device but an MTD.

Notes:
------

- OOB support is currently limited. Currently MUSE has no support for processing in- and out-band in the same MTD operation. It is good enough to make JFFS2 happy. This limitation is because FUSE has no support more than one variable length buffer in a FUSE request.
At least I didn’t find a good way to pass more than one buffer to a request. Maybe FUSE folks can correct me. :-)

- Every MTD read/write operation maps 1:1 to a MUSE_READ/WRITE opcode. Since FUSE requests are not cheap, the amount of read/written bytes in a MTD operation as a huge impact on the performance. Especially when NOR style MTDs are implemented in userspace a large writebufsize should be requested to gain good write performance.
On the other hand, MTD operations with lengths larger than writesize are *not* split up into multiple MUSE_READ/WRITE requests. This means that userspace has to split them manually when doing power-cut emulation.

- MUSE is not super fast. On my i5 workstation nandsim is almost twice as fast as a NAND flash in userspace. But MUSE is still magnitudes faster than any real world MTD out there. So it is good enough for the use cases I have in mind.

Changelog:
----------

Changes since v2 (RFC):
- OOB support
- MUSE_READ/WRITE opcodes are no longer a min IO MTD unit
- MTD partitions support via mtdparts string
- More code cleanup
- Code rebased to 5.11-rc4

Changes since v1 (RFC):
- Rewrote IO path, fuse_direct_io() is no longer used. Instead of cheating fuse_direct_io() use custom ops to implement reading and writing. That way MUSE no longer needs a dummy file object nor a fuse file object.
In MTD all IO is synchronous and operations on kernel buffers, this makes IO processing simple for MUSE.
- Support for bad blocks.
- No more (ab)use of FUSE ops such as FUSE_FSYNC.
- Major code cleanup.

This series can also be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/rw/misc.git muse_v3

Richard Weinberger (8):
fuse: Export fuse_simple_request
fuse: Export IO helpers
fuse: Make cuse_parse_one a common helper
mtd: Add MTD_MUSE flag
mtd: Allow passing a custom cmdline to cmdline line parser
fuse: Add MUSE specific defines FUSE interface
fuse: Implement MUSE - MTD in userspace
MAINTAINERS: Add entry for MUSE

 Documentation/ABI/testing/sysfs-class-mtd |    8 +
 MAINTAINERS                               |    7 +
 drivers/mtd/parsers/cmdlinepart.c         |   73 +-
 fs/fuse/Kconfig                           |   15 +
 fs/fuse/Makefile                          |    2 +
 fs/fuse/cuse.c                            |   58 +-
 fs/fuse/dev.c                             |    1 +
 fs/fuse/file.c                            |   16 +-
 fs/fuse/fuse_i.h                          |   18 +
 fs/fuse/helper.c                          |   70 ++
 fs/fuse/muse.c                            | 1086 +++++++++++++++++++++
 include/linux/mtd/partitions.h            |    2 +
 include/uapi/linux/fuse.h                 |   76 ++
 include/uapi/mtd/mtd-abi.h                |    1 +
 14 files changed, 1346 insertions(+), 87 deletions(-)
 create mode 100644 fs/fuse/helper.c
 create mode 100644 fs/fuse/muse.c
Signature · 6 lines
2.26.2


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
author maintainer
#1 lore raw

PATCH 1/8 fuse: Export fuse_simple_request

MUSE will use this function to issue requests,
so export it.

---
 fs/fuse/dev.c | 1 +
 1 file changed, 1 insertion(+)
fs/fuse/dev.c +1 -0
index 588f8d1240aa..8b7209537683 100644
@@ -522,6 +522,7 @@ ssize_t fuse_simple_request(struct fuse_mount *fm, struct fuse_args *args)
 
 	return ret;
 }
+EXPORT_SYMBOL_GPL(fuse_simple_request);
 
 static bool fuse_request_queue_background(struct fuse_req *req)
 {
Signature · 6 lines
2.26.2


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
author maintainer
#2 lore raw

PATCH 2/8 fuse: Export IO helpers

In reply to Richard Weinberger

MUSE will use this functions in its IO path,
so export them.

---
 fs/fuse/file.c   | 16 +++-------------
 fs/fuse/fuse_i.h | 16 ++++++++++++++++
 2 files changed, 19 insertions(+), 13 deletions(-)
fs/fuse/file.c +3 -13
index 8cccecb55fb8..d41660b7f5bc 100644
@@ -20,8 +20,8 @@
 #include <linux/uio.h>
 #include <linux/fs.h>
 
-static struct page **fuse_pages_alloc(unsigned int npages, gfp_t flags,
-				      struct fuse_page_desc **desc)
+struct page **fuse_pages_alloc(unsigned int npages, gfp_t flags,
+			       struct fuse_page_desc **desc)
 {
 	struct page **pages;
 
@@ -31,6 +31,7 @@ static struct page **fuse_pages_alloc(unsigned int npages, gfp_t flags,
 
 	return pages;
 }
+EXPORT_SYMBOL_GPL(fuse_pages_alloc);
 
 static int fuse_send_open(struct fuse_mount *fm, u64 nodeid, struct file *file,
 			  int opcode, struct fuse_open_out *outargp)
@@ -1356,17 +1357,6 @@ static inline void fuse_page_descs_length_init(struct fuse_page_desc *descs,
 		descs[i].length = PAGE_SIZE - descs[i].offset;
 }
 
-static inline unsigned long fuse_get_user_addr(const struct iov_iter *ii)
-{
-	return (unsigned long)ii->iov->iov_base + ii->iov_offset;
-}
-
-static inline size_t fuse_get_frag_size(const struct iov_iter *ii,
-					size_t max_size)
-{
-	return min(iov_iter_single_seg_count(ii), max_size);
-}
-
 static int fuse_get_user_pages(struct fuse_args_pages *ap, struct iov_iter *ii,
 			       size_t *nbytesp, int write,
 			       unsigned int max_pages)
fs/fuse/fuse_i.h +16 -0
index 7c4b8cb93f9f..8c56a3fd2c4e 100644
@@ -31,6 +31,7 @@
 #include <linux/pid_namespace.h>
 #include <linux/refcount.h>
 #include <linux/user_namespace.h>
+#include <linux/uio.h>
 
 /** Default max number of pages that can be used in a single read request */
 #define FUSE_DEFAULT_MAX_PAGES_PER_REQ 32
@@ -871,6 +872,17 @@ static inline bool fuse_is_bad(struct inode *inode)
 	return unlikely(test_bit(FUSE_I_BAD, &get_fuse_inode(inode)->state));
 }
 
+static inline unsigned long fuse_get_user_addr(const struct iov_iter *ii)
+{
+	return (unsigned long)ii->iov->iov_base + ii->iov_offset;
+}
+
+static inline size_t fuse_get_frag_size(const struct iov_iter *ii,
+					size_t max_size)
+{
+	return min(iov_iter_single_seg_count(ii), max_size);
+}
+
 /** Device operations */
 extern const struct file_operations fuse_dev_operations;
 
@@ -1213,4 +1225,8 @@ void fuse_dax_inode_cleanup(struct inode *inode);
 bool fuse_dax_check_alignment(struct fuse_conn *fc, unsigned int map_alignment);
 void fuse_dax_cancel_work(struct fuse_conn *fc);
 
+/* file.c */
+struct page **fuse_pages_alloc(unsigned int npages, gfp_t flags,
+			       struct fuse_page_desc **desc);
+
 #endif /* _FS_FUSE_I_H */
Signature · 1 line
2.26.2
author maintainer
#3 lore raw

PATCH 3/8 fuse: Make cuse_parse_one a common helper

In reply to Richard Weinberger

This function will be used by MUSE too, let's share it.

---
 fs/fuse/Kconfig  |  4 +++
 fs/fuse/Makefile |  1 +
 fs/fuse/cuse.c   | 58 +--------------------------------------
 fs/fuse/fuse_i.h |  2 ++
 fs/fuse/helper.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 78 insertions(+), 57 deletions(-)
 create mode 100644 fs/fuse/helper.c
fs/fuse/Kconfig +4 -0
index 40ce9a1c12e5..9c8cc1e7b3a5 100644
@@ -18,9 +18,13 @@ config FUSE_FS
 	  If you want to develop a userspace FS, or if you want to use
 	  a filesystem based on FUSE, answer Y or M.
 
+config FUSE_HELPER
+	def_bool n
+
 config CUSE
 	tristate "Character device in Userspace support"
 	depends on FUSE_FS
+	select FUSE_HELPER
 	help
 	  This FUSE extension allows character devices to be
 	  implemented in userspace.
fs/fuse/Makefile +1 -0
index 8c7021fb2cd4..7a5768cce6be 100644
@@ -9,5 +9,6 @@ obj-$(CONFIG_VIRTIO_FS) += virtiofs.o
 
 fuse-y := dev.o dir.o file.o inode.o control.o xattr.o acl.o readdir.o
 fuse-$(CONFIG_FUSE_DAX) += dax.o
+fuse-$(CONFIG_FUSE_HELPER) += helper.o
 
 virtiofs-y := virtio_fs.o
fs/fuse/cuse.c +1 -57

70 lines not on this page · raw message

fs/fuse/fuse_i.h +2 -0
index 8c56a3fd2c4e..555856b0d998 100644
@@ -1228,5 +1228,7 @@ void fuse_dax_cancel_work(struct fuse_conn *fc);
 /* file.c */
 struct page **fuse_pages_alloc(unsigned int npages, gfp_t flags,
 			       struct fuse_page_desc **desc);
+/* helper.c */
+int fuse_kv_parse_one(char **pp, char *end, char **keyp, char **valp);
 
 #endif /* _FS_FUSE_I_H */
fs/fuse/helper.c new file +70 -0

70 lines not on this page · raw message

Signature · 6 lines
2.26.2


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
author maintainer
#4 lore raw

PATCH 4/8 mtd: Add MTD_MUSE flag

In reply to Richard Weinberger

This flag will be set if an MTD is implemeted in userspace using MUSE.

---
 include/uapi/mtd/mtd-abi.h | 1 +
 1 file changed, 1 insertion(+)
include/uapi/mtd/mtd-abi.h +1 -0
index 65b9db936557..2ad2217e3a96 100644
@@ -105,6 +105,7 @@ struct mtd_write_req {
 #define MTD_NO_ERASE		0x1000	/* No erase necessary */
 #define MTD_POWERUP_LOCK	0x2000	/* Always locked after reset */
 #define MTD_SLC_ON_MLC_EMULATION 0x4000	/* Emulate SLC behavior on MLC NANDs */
+#define MTD_MUSE		0x8000 /* This MTD is implemented in userspace */
 
 /* Some common devices / combinations of capabilities */
 #define MTD_CAP_ROM		0
Signature · 6 lines
2.26.2


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
author maintainer
#5 lore raw

PATCH 5/8 mtd: Allow passing a custom cmdline to cmdline line parser

In reply to Richard Weinberger

The cmdline parser uses usually the mtdparts string from the kernel cmdline. For special purpose MTDs like MUSE it is useful to pass a custom mtdparts string to the parser. This allows the MTD simulator in userspace directly passing a mtdparts string and the new MTD partitioned.

To achieve this, struct mtd_part_parser_data now has a mtdparts pointer where a custom mtdparts string can be provided, it overrules the kernel cmdline.
Since the cmdline parser stays for ever in the kernel, the memory lifecycle had to be changed a little such that custom mtdparts string don't result in memory leaks.

---
 drivers/mtd/parsers/cmdlinepart.c | 73 ++++++++++++++++++++++++-------
 include/linux/mtd/partitions.h    |  2 +
 2 files changed, 58 insertions(+), 17 deletions(-)
drivers/mtd/parsers/cmdlinepart.c +56 -17
index 0ddff1a4b51f..f0fe87267380 100644
@@ -64,7 +64,7 @@ struct cmdline_mtd_partition {
 };
 
 /* mtdpart_setup() parses into here */
-static struct cmdline_mtd_partition *partitions;
+static struct cmdline_mtd_partition *cmdline_partitions;
 
 /* the command line passed to mtdpart_setup() */
 static char *mtdparts;
@@ -138,9 +138,6 @@ static struct mtd_partition * newpart(char *s,
 		name_len = 13; /* Partition_000 */
 	}
 
-	/* record name length for memory allocation later */
-	extra_mem_size += name_len + 1;
-
 	/* test for options */
 	if (strncmp(s, "ro", 2) == 0) {
 		mask_flags |= MTD_WRITEABLE;
@@ -192,12 +189,17 @@ static struct mtd_partition * newpart(char *s,
 	parts[this_part].offset = offset;
 	parts[this_part].mask_flags = mask_flags;
 	parts[this_part].add_flags = add_flags;
+
+	/*
+	 * Will get free()'ed in ->cleanup()
+	 */
 	if (name)
-		strlcpy(extra_mem, name, name_len + 1);
+		parts[this_part].name = kmemdup_nul(name, name_len, GFP_KERNEL);
 	else
-		sprintf(extra_mem, "Partition_%03d", this_part);
-	parts[this_part].name = extra_mem;
-	extra_mem += name_len + 1;
+		parts[this_part].name = kasprintf(GFP_KERNEL, "Partition_%03d", this_part);
+
+	if (!parts[this_part].name)
+		return ERR_PTR(-ENOMEM);
 
 	dbg(("partition %d: name <%s>, offset %llx, size %llx, mask flags %x\n",
 	     this_part, parts[this_part].name, parts[this_part].offset,
@@ -217,7 +219,7 @@ static struct mtd_partition * newpart(char *s,
 /*
  * Parse the command line.
  */
-static int mtdpart_setup_real(char *s)
+static int mtdpart_setup_real(char *s, struct cmdline_mtd_partition **partitions)
 {
 	cmdline_parsed = 1;
 
@@ -301,8 +303,8 @@ static int mtdpart_setup_real(char *s)
 		strlcpy(this_mtd->mtd_id, mtd_id, mtd_id_len + 1);
 
 		/* link into chain */
-		this_mtd->next = partitions;
-		partitions = this_mtd;
+		this_mtd->next = *partitions;
+		*partitions = this_mtd;
 
 		dbg(("mtdid=<%s> num_parts=<%d>\n",
 		     this_mtd->mtd_id, this_mtd->num_parts));
@@ -335,13 +337,23 @@ static int parse_cmdline_partitions(struct mtd_info *master,
 				    struct mtd_part_parser_data *data)
 {
 	unsigned long long offset;
-	int i, err;
+	int i, err, num_parts;
 	struct cmdline_mtd_partition *part;
 	const char *mtd_id = master->name;
+	struct cmdline_mtd_partition *parsed_parts = cmdline_partitions;
+	bool free_parts = false;
+
+	if (data && data->mtdparts) {
+		parsed_parts = NULL;
 
-	/* parse command line */
-	if (!cmdline_parsed) {
-		err = mtdpart_setup_real(cmdline);
+		err = mtdpart_setup_real(data->mtdparts, &parsed_parts);
+		if (err)
+			return err;
+
+		free_parts = true;
+	} else if (!cmdline_parsed) {
+		/* parse command line */
+		err = mtdpart_setup_real(cmdline, &cmdline_partitions);
 		if (err)
 			return err;
 	}
@@ -350,7 +362,7 @@ static int parse_cmdline_partitions(struct mtd_info *master,
 	 * Search for the partition definition matching master->name.
 	 * If master->name is not set, stop at first partition definition.
 	 */
-	for (part = partitions; part; part = part->next) {
+	for (part = parsed_parts; part; part = part->next) {
 		if ((!mtd_id) || (!strcmp(part->mtd_id, mtd_id)))
 			break;
 	}
@@ -384,12 +396,38 @@ static int parse_cmdline_partitions(struct mtd_info *master,
 		}
 	}
 
+	/*
+	 * Will get free()'ed in ->cleanup()
+	 */
 	*pparts = kmemdup(part->parts, sizeof(*part->parts) * part->num_parts,
 			  GFP_KERNEL);
 	if (!*pparts)
 		return -ENOMEM;
 
-	return part->num_parts;
+	num_parts = part->num_parts;
+
+	if (free_parts == true) {
+		part = parsed_parts;
+		while (part) {
+			struct cmdline_mtd_partition *next = part->next;
+
+			kfree(part->parts);
+			part = next;
+		}
+	}
+
+	return num_parts;
+}
+
+static void cmdline_partitions_cleanup(const struct mtd_partition *pparts,
+				       int nr_parts)
+{
+	int i;
+
+	for (i = 0; i < nr_parts; i++)
+		kfree(pparts[i].name);
+
+	kfree(pparts);
 }
 
 
@@ -410,6 +448,7 @@ __setup("mtdparts=", mtdpart_setup);
 
 static struct mtd_part_parser cmdline_parser = {
 	.parse_fn = parse_cmdline_partitions,
+	.cleanup = cmdline_partitions_cleanup,
 	.name = "cmdlinepart",
 };
 
include/linux/mtd/partitions.h +2 -0
index b74a539ec581..6c8b3399143d 100644
@@ -65,9 +65,11 @@ struct device_node;
 /**
  * struct mtd_part_parser_data - used to pass data to MTD partition parsers.
  * @origin: for RedBoot, start address of MTD device
+ * @mtdparts: for cmdline parser, use this string instead of mtdparts= from cmdline
  */
 struct mtd_part_parser_data {
 	unsigned long origin;
+	char *mtdparts;
 };
 
 
Signature · 6 lines
2.26.2


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
author maintainer
#6 lore raw

PATCH 6/8 fuse: Add MUSE specific defines FUSE interface

In reply to Richard Weinberger

Raise the FUSE API minor version to 34 and add all MUSE specific operations and data structures.

MUSE_INIT: Initialize a new connection and installs the MTD
MUSE_ERASE: Erases a block
MUSE_READ: Reads a page with or without OOB
MUSE_WRITE: Writes a page with or without OOB
MUSE_MARKBAD: Marks a block as bad
MUSE_ISBAD: Checks whether a block is bad
MUSE_SYNC: Flushes all cached data

---
 include/uapi/linux/fuse.h | 76 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 76 insertions(+)
include/uapi/linux/fuse.h +76 -0
index 98ca64d1beb6..1c8fa9e42e73 100644
@@ -179,6 +179,10 @@
  *  7.33
  *  - add FUSE_HANDLE_KILLPRIV_V2, FUSE_WRITE_KILL_SUIDGID, FATTR_KILL_SUIDGID
  *  - add FUSE_OPEN_KILL_SUIDGID
+ *
+ *  7.34
+ *  - add support for MUSE: MUSE_INIT, MUSE_ERASE, MUSE_READ, MUSE_WRITE,
+ *    MUSE_MARKBAD, MUSE_ISBAD and MUSE_SYNC
  */
 
 #ifndef _LINUX_FUSE_H
@@ -503,6 +507,15 @@ enum fuse_opcode {
 	/* CUSE specific operations */
 	CUSE_INIT		= 4096,
 
+	/* MUSE specific operations */
+	MUSE_INIT		= 8192,
+	MUSE_ERASE		= 8193,
+	MUSE_READ		= 8194,
+	MUSE_WRITE		= 8195,
+	MUSE_MARKBAD		= 8196,
+	MUSE_ISBAD		= 8197,
+	MUSE_SYNC		= 8198,
+
 	/* Reserved opcodes: helpful to detect structure endian-ness */
 	CUSE_INIT_BSWAP_RESERVED	= 1048576,	/* CUSE_INIT << 8 */
 	FUSE_INIT_BSWAP_RESERVED	= 436207616,	/* FUSE_INIT << 24 */
@@ -956,4 +969,67 @@ struct fuse_removemapping_one {
 #define FUSE_REMOVEMAPPING_MAX_ENTRY   \
 		(PAGE_SIZE / sizeof(struct fuse_removemapping_one))
 
+#define MUSE_INIT_INFO_MAX 4096
+
+struct muse_init_in {
+	uint32_t	fuse_major;
+	uint32_t	fuse_minor;
+};
+
+struct muse_init_out {
+	uint32_t	fuse_major;
+	uint32_t	fuse_minor;
+	uint32_t	max_read;
+	uint32_t	max_write;
+};
+
+struct muse_erase_in {
+	uint64_t	addr;
+	uint64_t	len;
+};
+
+#define MUSE_IO_INBAND		(1 << 0)
+#define MUSE_IO_OOB_AUTO	(1 << 1)
+#define MUSE_IO_OOB_PLACE	(1 << 2)
+#define MUSE_IO_RAW		(1 << 3)
+
+struct muse_read_in {
+	uint64_t	addr;
+	uint64_t	len;
+	uint32_t	flags;
+	uint32_t	padding;
+};
+
+struct muse_read_out {
+	uint64_t	len;
+	uint32_t	soft_error;
+	uint32_t	padding;
+};
+
+struct muse_write_in {
+	uint64_t	addr;
+	uint64_t	len;
+	uint32_t	flags;
+	uint32_t	padding;
+};
+
+struct muse_write_out {
+	uint64_t	len;
+	uint32_t	soft_error;
+	uint32_t	padding;
+};
+
+struct muse_markbad_in {
+	uint64_t	addr;
+};
+
+struct muse_isbad_in {
+	uint64_t	addr;
+};
+
+struct muse_isbad_out {
+	uint32_t	result;
+	uint32_t	padding;
+};
+
 #endif /* _LINUX_FUSE_H */
Signature · 6 lines
2.26.2


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
author maintainer
#7 lore raw

PATCH 7/8 fuse: Implement MUSE - MTD in userspace

In reply to Richard Weinberger

MUSE allows implementing a MTD in userspace.
So far userspace has control over mtd_read, mtd_write, mtd_erase, mtd_block_isbad, mtd_block_markbad, and mtd_sync.
It can also set the various MTD parameters such as name, flags, site, writesize and erasesize.

That way advanced simulators for many types of flashes can be implemented in userspace such that the complexity is in userspace. Furthermore at some point we can depricate ad-hoc in-kernel MTD simulators such as nandsim.

---
 Documentation/ABI/testing/sysfs-class-mtd |    8 +
 fs/fuse/Kconfig                           |   11 +
 fs/fuse/Makefile                          |    1 +
 fs/fuse/muse.c                            | 1086 +++++++++++++++++++++
 4 files changed, 1106 insertions(+)
 create mode 100644 fs/fuse/muse.c
Documentation/ABI/testing/sysfs-class-mtd +8 -0
index 3bc7c0a95c92..1aa8d7855f9c 100644
@@ -240,3 +240,11 @@ Contact:	[email protected]
 Description:
 		Number of bytes available for a client to place data into
 		the out of band area.
+
+What:		/sys/class/mtd/mtdX/muse_pid
+Date:		January 2021
+KernelVersion:	5.12
+Contact:	[email protected]
+Description:
+		If this MTD is a userspace driven MTD, muse_pid shows the PID
+		of the process behind it at creation time.
fs/fuse/Kconfig +11 -0
index 9c8cc1e7b3a5..2fc63dc18a53 100644
@@ -56,3 +56,14 @@ config FUSE_DAX
 
 	  If you want to allow mounting a Virtio Filesystem with the "dax"
 	  option, answer Y.
+
+config MUSE
+	tristate "Memory Technology Device (MTD) in Userspace support"
+	depends on FUSE_FS
+	select FUSE_HELPER
+	select MTD
+	help
+	  This FUSE extension allows an MTD to be implemented in userspace.
+
+	  If you want to develop or use a userspace MTD based on MUSE,
+	  answer Y or M.
fs/fuse/Makefile +1 -0
index 7a5768cce6be..67a7af3fb047 100644
@@ -6,6 +6,7 @@
 obj-$(CONFIG_FUSE_FS) += fuse.o
 obj-$(CONFIG_CUSE) += cuse.o
 obj-$(CONFIG_VIRTIO_FS) += virtiofs.o
+obj-$(CONFIG_MUSE) += muse.o
 
 fuse-y := dev.o dir.o file.o inode.o control.o xattr.o acl.o readdir.o
 fuse-$(CONFIG_FUSE_DAX) += dax.o
fs/fuse/muse.c new file +1086 -0

1,086 lines not on this page · raw message

Signature · 6 lines
2.26.2


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
author maintainer
#8 lore raw

PATCH 8/8 MAINTAINERS: Add entry for MUSE

In reply to Richard Weinberger

Since MUSE lives in fs/fuse/, make sure that linux-mtd@ is CC'ed on patches such that MTD related aspects of changes can be reviewed.

---
 MAINTAINERS | 7 +++++++
 1 file changed, 7 insertions(+)
MAINTAINERS +7 -0
index f79ec98bbb29..dabd9fd2e5e4 100644
@@ -12151,6 +12151,13 @@ L:	[email protected]
 S:	Maintained
 F:	drivers/usb/musb/
 
+MUSE: MTD IN USERSPACE DRIVER
+M:	Richard Weinberger <[email protected]>
+L:	[email protected]
+L:	[email protected]
+S:	Maintained
+F:	fs/fuse/muse.c
+
 MXL301RF MEDIA DRIVER
 M:	Akihiro Tsukada <[email protected]>
 L:	[email protected]
Signature · 6 lines
2.26.2


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
maintainer
#9 lore raw
In reply to Richard Weinberger

Hi Richard,

Richard Weinberger <[email protected]> wrote on Mon, 25 Jan 2021 00:19:59 +0100:

Quoted 21 lines

I'm happy to announce the first non-RFC version of this patch set. Over the xmas holidays I found some time to experiment with various userspace implementations of MTDs and gave the kernel side more fine-tuning.

Rationale:
----------

When working with flash devices a common task is emulating them to run various tests or inspect dumps from real hardware. To achieve that we have plenty of emulators in the MTD subsystem: mtdram, block2mtd, nandsim.

Each of them implements an ad-hoc MTD and have various drawbacks. Over the last years some developers tried to extend them but these attempts often got rejected because they added just more adhoc feature instead of addressing overall problems.

MUSE is a novel approach to address the need of advanced MTD emulators. Advanced means in this context supporting different (vendor specific) image formats, different ways for fault injection (fuzzing) and recoding/replaying IOs to emulate power cuts.

Quoted 5 lines

The core goal of MUSE is having the complexity on the userspace side and only a small MTD driver in kernelspace.
While playing with different approaches I realized that FUSE offers everything we need. So MUSE is a little like CUSE except that it does not implement a bare character device but an MTD.

I can't tell if your MUSE implementation is right but it looks fine on the MTD side.

This is following the right path, I look forward to merging it soon!

Thanks for your contribution,
Miquèl

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

#10 lore raw
In reply to Richard Weinberger

*friendly FUSE maintainer ping* :-)

Quoted 107 lines · Richard Weinberger

I'm happy to announce the first non-RFC version of this patch set. Over the xmas holidays I found some time to experiment with various userspace implementations of MTDs and gave the kernel side more fine-tuning.

Rationale:
----------

When working with flash devices a common task is emulating them to run various tests or inspect dumps from real hardware. To achieve that we have plenty of emulators in the MTD subsystem: mtdram, block2mtd, nandsim.

Each of them implements an ad-hoc MTD and have various drawbacks. Over the last years some developers tried to extend them but these attempts often got rejected because they added just more adhoc feature instead of addressing overall problems.

MUSE is a novel approach to address the need of advanced MTD emulators. Advanced means in this context supporting different (vendor specific) image formats, different ways for fault injection (fuzzing) and recoding/replaying IOs to emulate power cuts.

The core goal of MUSE is having the complexity on the userspace side and only a small MTD driver in kernelspace.
While playing with different approaches I realized that FUSE offers everything we need. So MUSE is a little like CUSE except that it does not implement a bare character device but an MTD.

Notes:
------

- OOB support is currently limited. Currently MUSE has no support for processing in- and out-band in the same MTD operation. It is good enough to make JFFS2 happy. This limitation is because FUSE has no support more than one variable length buffer in a FUSE request.
At least I didn’t find a good way to pass more than one buffer to a request. Maybe FUSE folks can correct me. :-)

- Every MTD read/write operation maps 1:1 to a MUSE_READ/WRITE opcode. Since FUSE requests are not cheap, the amount of read/written bytes in a MTD operation as a huge impact on the performance. Especially when NOR style MTDs are implemented in userspace a large writebufsize should be requested to gain good write performance.
On the other hand, MTD operations with lengths larger than writesize are *not* split up into multiple MUSE_READ/WRITE requests. This means that userspace has to split them manually when doing power-cut emulation.

- MUSE is not super fast. On my i5 workstation nandsim is almost twice as fast as a NAND flash in userspace. But MUSE is still magnitudes faster than any real world MTD out there. So it is good enough for the use cases I have in mind.

Changelog:
----------

Changes since v2 (RFC):
- OOB support
- MUSE_READ/WRITE opcodes are no longer a min IO MTD unit
- MTD partitions support via mtdparts string
- More code cleanup
- Code rebased to 5.11-rc4

Changes since v1 (RFC):
- Rewrote IO path, fuse_direct_io() is no longer used. Instead of cheating fuse_direct_io() use custom ops to implement reading and writing. That way MUSE no longer needs a dummy file object nor a fuse file object.
In MTD all IO is synchronous and operations on kernel buffers, this makes IO processing simple for MUSE.
- Support for bad blocks.
- No more (ab)use of FUSE ops such as FUSE_FSYNC.
- Major code cleanup.

This series can also be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/rw/misc.git muse_v3

Richard Weinberger (8):
fuse: Export fuse_simple_request
fuse: Export IO helpers
fuse: Make cuse_parse_one a common helper
mtd: Add MTD_MUSE flag
mtd: Allow passing a custom cmdline to cmdline line parser
fuse: Add MUSE specific defines FUSE interface
fuse: Implement MUSE - MTD in userspace
MAINTAINERS: Add entry for MUSE

 Documentation/ABI/testing/sysfs-class-mtd |    8 +
 MAINTAINERS                               |    7 +
 drivers/mtd/parsers/cmdlinepart.c         |   73 +-
 fs/fuse/Kconfig                           |   15 +
 fs/fuse/Makefile                          |    2 +
 fs/fuse/cuse.c                            |   58 +-
 fs/fuse/dev.c                             |    1 +
 fs/fuse/file.c                            |   16 +-
 fs/fuse/fuse_i.h                          |   18 +
 fs/fuse/helper.c                          |   70 ++
 fs/fuse/muse.c                            | 1086 +++++++++++++++++++++
 include/linux/mtd/partitions.h            |    2 +
 include/uapi/linux/fuse.h                 |   76 ++
 include/uapi/mtd/mtd-abi.h                |    1 +
 14 files changed, 1346 insertions(+), 87 deletions(-)
 create mode 100644 fs/fuse/helper.c
 create mode 100644 fs/fuse/muse.c

--
2.26.2

Signature · 6 lines
Thanks,
//richard

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
maintainer
#11 lore raw
Quoted 2 lines · Richard Weinberger

*friendly FUSE maintainer ping* :-)

Seems like MTD folks are happy, so I'll review and merge when I get the time.

Thanks,
Miklos

maintainer
#12 lore raw
In reply to Richard Weinberger
Quoted 22 lines · Richard Weinberger

I'm happy to announce the first non-RFC version of this patch set. Over the xmas holidays I found some time to experiment with various userspace implementations of MTDs and gave the kernel side more fine-tuning.

Rationale:
----------

When working with flash devices a common task is emulating them to run various tests or inspect dumps from real hardware. To achieve that we have plenty of emulators in the MTD subsystem: mtdram, block2mtd, nandsim.

Each of them implements an ad-hoc MTD and have various drawbacks. Over the last years some developers tried to extend them but these attempts often got rejected because they added just more adhoc feature instead of addressing overall problems.

MUSE is a novel approach to address the need of advanced MTD emulators. Advanced means in this context supporting different (vendor specific) image formats, different ways for fault injection (fuzzing) and recoding/replaying IOs to emulate power cuts.

Quoted 5 lines

The core goal of MUSE is having the complexity on the userspace side and only a small MTD driver in kernelspace.
While playing with different approaches I realized that FUSE offers everything we need. So MUSE is a little like CUSE except that it does not implement a bare character device but an MTD.

Looks fine.

I do wonder if MUSE should go to drivers/mtd/ instead. Long term
goal would be move CUSE to drivers/char and move the transport part of fuse into net/fuse leaving only the actual filesystems (fuse and virtiofs) under fs/.

But for now just moving the minimal interface needed for MUSE into a separate header (<net/fuse.h>) would work, I guess.

Do you think that would make sense?

Quoted 10 lines

Notes:
------

- OOB support is currently limited. Currently MUSE has no support for processing in- and out-band in the same MTD operation. It is good enough to make JFFS2 happy. This limitation is because FUSE has no support more than one variable length buffer in a FUSE request.
At least I didn’t find a good way to pass more than one buffer to a request. Maybe FUSE folks can correct me. :-)

If you look at fuse_do_ioctl() it does variable length input and output at the same time. I guess you need something similar to that.

Thanks,
Miklos

author maintainer
#13 lore raw

Miklos,

----- Ursprüngliche Mail -----

Quoted 7 lines
Quoted 5 lines

The core goal of MUSE is having the complexity on the userspace side and only a small MTD driver in kernelspace.
While playing with different approaches I realized that FUSE offers everything we need. So MUSE is a little like CUSE except that it does not implement a bare character device but an MTD.

Looks fine.

I'm glad to hear that!

Quoted 9 lines

I do wonder if MUSE should go to drivers/mtd/ instead. Long term
goal would be move CUSE to drivers/char and move the transport part of fuse into net/fuse leaving only the actual filesystems (fuse and virtiofs) under fs/.

But for now just moving the minimal interface needed for MUSE into a separate header (<net/fuse.h>) would work, I guess.

Do you think that would make sense?

Yes, I'm all for having MUSE in drivers/mtd/.

I placed MUSE initially in fs/fuse/ because CUSE was already there and muse.c includes fuse_i.h. So tried to be as little invasive as possible.

Quoted 11 lines
Quoted 10 lines

Notes:
------

- OOB support is currently limited. Currently MUSE has no support for processing in- and out-band in the same MTD operation. It is good enough to make JFFS2 happy. This limitation is because FUSE has no support more than one variable length buffer in a FUSE request.
At least I didn’t find a good way to pass more than one buffer to a request. Maybe FUSE folks can correct me. :-)

Quoted 2 lines

If you look at fuse_do_ioctl() it does variable length input and output at the same time. I guess you need something similar to that.

I'll dig into this!

Thanks,
//richard

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

#14 lore raw

Hi guys,

a bit OT probably: is there any chance for you to also implement mmap() for CUSE? That would be much appreciated.

Thanks

Quoted 39 lines · Richard Weinberger

Miklos,

----- Ursprüngliche Mail -----

Quoted 7 lines
Quoted 5 lines

The core goal of MUSE is having the complexity on the userspace side and only a small MTD driver in kernelspace.
While playing with different approaches I realized that FUSE offers everything we need. So MUSE is a little like CUSE except that it does not implement a bare character device but an MTD.

Looks fine.

I'm glad to hear that!

Quoted 9 lines

I do wonder if MUSE should go to drivers/mtd/ instead. Long term
goal would be move CUSE to drivers/char and move the transport part of fuse into net/fuse leaving only the actual filesystems (fuse and virtiofs) under fs/.

But for now just moving the minimal interface needed for MUSE into a separate header (<net/fuse.h>) would work, I guess.

Do you think that would make sense?

Yes, I'm all for having MUSE in drivers/mtd/.

I placed MUSE initially in fs/fuse/ because CUSE was already there and muse.c includes fuse_i.h. So tried to be as little invasive as possible.

Quoted 11 lines
Quoted 10 lines

Notes:
------

- OOB support is currently limited. Currently MUSE has no support for processing in- and out-band in the same MTD operation. It is good enough to make JFFS2 happy. This limitation is because FUSE has no support more than one variable length buffer in a FUSE request.
At least I didn’t find a good way to pass more than one buffer to a request. Maybe FUSE folks can correct me. :-)

Quoted 9 lines
Quoted 2 lines

If you look at fuse_do_ioctl() it does variable length input and output at the same time. I guess you need something similar to that.

I'll dig into this!

Thanks,
//richard

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

maintainer
#15 lore raw
Quoted 5 lines · Luca Risolia

Hi guys,

a bit OT probably: is there any chance for you to also implement mmap() for CUSE? That would be much appreciated.

That's an old one.

No, I don't have plans, but patches are welcome, of course.

Thanks,
Miklos

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

author maintainer
#16 lore raw
In reply to Luca Risolia
Quoted 2 lines

a bit OT probably: is there any chance for you to also implement mmap() for CUSE? That would be much appreciated.

What exactly do you have in mind? I wonder about the use case.
mmap() between a FUSE server and a client is more or less shared memory in userspace.

Thanks,
//richard

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

#17 lore raw
Quoted 1 line · Richard Weinberger

I wonder about the use case.

for example, many existing video applications use mmap() to map the device memory to userspace memory. Adding support for mmap() to CUSE would allow these apps to work without any modifications with CUSE-based
device drivers other than kernel drivers.

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

author maintainer
#18 lore raw

----- Ursprüngliche Mail -----

Quoted 4 lines

for example, many existing video applications use mmap() to map the device memory to userspace memory. Adding support for mmap() to CUSE would allow these apps to work without any modifications with CUSE-based
device drivers other than kernel drivers.

So you want to access device memory via CUSE?
We have plenty of mechanisms in Linux to allow userspace accessing device memory. E.g. /dev/mem, UIO, VFIO.

A simple (but ugly!) approach would be redirecting mmap() requests on CUSE devices to /dev/mem. hmm?

Thanks,
//richard

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

#19 lore raw
Quoted 2 lines

A simple (but ugly!) approach would be redirecting mmap() requests on CUSE devices to /dev/mem. hmm?

what requests are you talking about given that at the moment the CUSE client interface (cuse_lowlevel_ops) does not expose mmap?

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

author maintainer
#20 lore raw

----- Ursprüngliche Mail -----

Quoted 6 lines
Quoted 3 lines

A simple (but ugly!) approach would be redirecting mmap() requests on CUSE devices to /dev/mem.
hmm?

what requests are you talking about given that at the moment the CUSE client interface (cuse_lowlevel_ops) does not expose mmap?

The mmap() call itself. Of course you need to touch code. Maybe just cuse_lowlevel.c, maybe kernel too.

Thanks,
//richard

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

#21 lore raw
Quoted 2 lines · Richard Weinberger

The mmap() call itself. Of course you need to touch code. Maybe just cuse_lowlevel.c, maybe kernel too.

A patch had been submitted some years ago, more than once, asking for inclusion in the kernel, but facts are that at that time nobody in the FUSE group considered it. So much work and time lost, unfortunately.

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

author maintainer
#22 lore raw

----- Ursprüngliche Mail -----

Quoted 7 lines · Richard Weinberger
Quoted 2 lines

The mmap() call itself. Of course you need to touch code. Maybe just cuse_lowlevel.c, maybe kernel too.

A patch had been submitted some years ago, more than once, asking for inclusion in the kernel, but facts are that at that time nobody in the FUSE group considered it. So much work and time lost, unfortunately.

Well, I think having a generic mmap() for CUSE is hard to achieve.

Thanks,
//richard

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

#23 lore raw
Quoted 1 line · Richard Weinberger

Well, I think having a generic mmap() for CUSE is hard to achieve.

Hard or not it did work for what I can tell you. I was not the original author but I certainly contributed with testing that patch. Just to be clear, by "not considered" I meant both the patch and the request were completely ignored with no answers at all, silence in other words.

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

maintainer
#24 lore raw
Quoted 8 lines · Luca Risolia
Quoted 1 line · Richard Weinberger

Well, I think having a generic mmap() for CUSE is hard to achieve.

Hard or not it did work for what I can tell you. I was not the original author but I certainly contributed with testing that patch. Just to be clear, by "not considered" I meant both the patch and the request were completely ignored with no answers at all, silence in other words.

I don't have any bad feelings about CUSE mmap, it was definitely not a
personal thing. But it also wasn't something that many people were
requesting, and the silence was probably at about the time that I was
taking a leave from paid maintainership. So a number of factors.

Patches are still welcome, if it's something that is used in practice (e.g. by Android) that's a plus point.

Thanks,
Miklos

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

author maintainer
#25 lore raw
In reply to Richard Weinberger

Miklos,

----- Ursprüngliche Mail -----

Quoted 8 lines
Quoted 8 lines

I do wonder if MUSE should go to drivers/mtd/ instead. Long term
goal would be move CUSE to drivers/char and move the transport part of fuse into net/fuse leaving only the actual filesystems (fuse and virtiofs) under fs/.

But for now just moving the minimal interface needed for MUSE into a separate header (<net/fuse.h>) would work, I guess.

Quoted 7 lines
Quoted 1 line

Do you think that would make sense?

Yes, I'm all for having MUSE in drivers/mtd/.

I placed MUSE initially in fs/fuse/ because CUSE was already there and muse.c includes
fuse_i.h. So tried to be as little invasive as possible.

I did a quick patch series which moves CUSE into drivers/char/

https://git.kernel.org/pub/scm/linux/kernel/git/rw/misc.git/log/?h=fs_fuse_split

Does this more or less what you had in mind?
If so, I'd submit these patches, rebase MUSE on them and do a v4 soon.

Thanks,
//richard

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

maintainer
#26 lore raw
Quoted 20 lines · Richard Weinberger

Miklos,

----- Ursprüngliche Mail -----

Quoted 8 lines
Quoted 8 lines

I do wonder if MUSE should go to drivers/mtd/ instead. Long term
goal would be move CUSE to drivers/char and move the transport part of fuse into net/fuse leaving only the actual filesystems (fuse and virtiofs) under fs/.

But for now just moving the minimal interface needed for MUSE into a separate header (<net/fuse.h>) would work, I guess.

Quoted 7 lines
Quoted 1 line

Do you think that would make sense?

Yes, I'm all for having MUSE in drivers/mtd/.

I placed MUSE initially in fs/fuse/ because CUSE was already there and muse.c includes
fuse_i.h. So tried to be as little invasive as possible.

Quoted 5 lines

I did a quick patch series which moves CUSE into drivers/char/

https://git.kernel.org/pub/scm/linux/kernel/git/rw/misc.git/log/?h=fs_fuse_split

Does this more or less what you had in mind?

Just moving the whole internal header file is not nice. I did a mechanical public/private separation of the interface based on what
CUSE uses. Incremental patch attached.

But this is just a start. From the big structures still left in <net/fuse.h> CUSE only uses the following fields:

fc: .minor, max_read, max_write, rcu, release, initialized, num_waiting
fm: .fc
ff: .fm
fud: .fc

Dealing with the last 3 is trivial: create and alloc function for the fm, and create accessor functions for the accessed fields.

Dealing with fc properly is probably a bit more involved, but does not seem to be too compex at first glance.

Do you want to take a stab at cleaning this up further?

Thanks,
Miklos

commit 6bc38f7550ccc8c18194ee42194e334c53890afc

Author: Miklos Szeredi <[email protected]>
Date:   Wed Feb 10 10:59:40 2021 +0100

separate fuse_i.h from <net/fuse.h>

drivers/char/cuse.c +1 -0
index 02e382b9863b..c329de20180b 100644
@@ -35,6 +35,7 @@
 #define pr_fmt(fmt) "CUSE: " fmt
 
 #include <linux/fuse.h>
+#include <linux/mm.h>
 #include <linux/cdev.h>
 #include <linux/device.h>
 #include <linux/file.h>
fs/fuse/acl.c +2 -2
index 008241c4c403..f529075a2ce8 100644
@@ -6,11 +6,11 @@
  * See the file COPYING.
  */
 
+#include "fuse_i.h"
+
 #include <linux/posix_acl.h>
 #include <linux/posix_acl_xattr.h>
 
-#include <net/fuse.h>
-
 struct posix_acl *fuse_get_acl(struct inode *inode, int type)
 {
 	struct fuse_conn *fc = get_fuse_conn(inode);
fs/fuse/control.c +2 -2
index 39d71ef076dc..cc7e94d73c6c 100644
@@ -6,12 +6,12 @@
   See the file COPYING.
 */
 
+#include "fuse_i.h"
+
 #include <linux/init.h>
 #include <linux/module.h>
 #include <linux/fs_context.h>
 
-#include <net/fuse.h>
-
 #define FUSE_CTL_SUPER_MAGIC 0x65735543
 
 /*
fs/fuse/dax.c +2 -2
index d222bef6e622..ff99ab2a3c43 100644
@@ -4,6 +4,8 @@
  * Copyright (C) 2020 Red Hat, Inc.
  */
 
+#include "fuse_i.h"
+
 #include <linux/delay.h>
 #include <linux/dax.h>
 #include <linux/uio.h>
@@ -11,8 +13,6 @@
 #include <linux/iomap.h>
 #include <linux/interval_tree.h>
 
-#include <net/fuse.h>
-
 /*
  * Default memory range size.  A power of 2 so it agrees with common FUSE_INIT
  * map_alignment values 4KB and 64KB.
fs/fuse/dev.c +2 -2
index f2e87baa2f59..588f8d1240aa 100644
@@ -6,6 +6,8 @@
   See the file COPYING.
 */
 
+#include "fuse_i.h"
+
 #include <linux/init.h>
 #include <linux/module.h>
 #include <linux/poll.h>
@@ -20,8 +22,6 @@
 #include <linux/splice.h>
 #include <linux/sched.h>
 
-#include <net/fuse.h>
-
 MODULE_ALIAS_MISCDEV(FUSE_MINOR);
 MODULE_ALIAS("devname:fuse");
 
fs/fuse/dir.c +2 -2
index 924c473a577b..78f9f209078c 100644
@@ -6,6 +6,8 @@
   See the file COPYING.
 */
 
+#include "fuse_i.h"
+
 #include <linux/pagemap.h>
 #include <linux/file.h>
 #include <linux/fs_context.h>
@@ -16,8 +18,6 @@
 #include <linux/iversion.h>
 #include <linux/posix_acl.h>
 
-#include <net/fuse.h>
-
 static void fuse_advise_use_readdirplus(struct inode *dir)
 {
 	struct fuse_inode *fi = get_fuse_inode(dir);
fs/fuse/file.c +2 -2
index ca49f86fb22d..8cccecb55fb8 100644
@@ -6,6 +6,8 @@
   See the file COPYING.
 */
 
+#include "fuse_i.h"
+
 #include <linux/pagemap.h>
 #include <linux/slab.h>
 #include <linux/kernel.h>
@@ -18,8 +20,6 @@
 #include <linux/uio.h>
 #include <linux/fs.h>
 
-#include <net/fuse.h>
-
 static struct page **fuse_pages_alloc(unsigned int npages, gfp_t flags,
 				      struct fuse_page_desc **desc)
 {
fs/fuse/fuse_i.h new file +657 -0

657 lines not on this page · raw message

fs/fuse/inode.c +2 -2
index 8efee00a2a1a..b0e18b470e91 100644
@@ -6,6 +6,8 @@
   See the file COPYING.
 */
 
+#include "fuse_i.h"
+
 #include <linux/pagemap.h>
 #include <linux/slab.h>
 #include <linux/file.h>
@@ -22,8 +24,6 @@
 #include <linux/posix_acl.h>
 #include <linux/pid_namespace.h>
 
-#include <net/fuse.h>
-
 MODULE_AUTHOR("Miklos Szeredi <[email protected]>");
 MODULE_DESCRIPTION("Filesystem in Userspace");
 MODULE_LICENSE("GPL");
fs/fuse/readdir.c +1 -2
index a6e8660e40ef..3441ffa740f3 100644
@@ -7,13 +7,12 @@
 */
 
 
+#include "fuse_i.h"
 #include <linux/iversion.h>
 #include <linux/posix_acl.h>
 #include <linux/pagemap.h>
 #include <linux/highmem.h>
 
-#include <net/fuse.h>
-
 static bool fuse_use_readdirplus(struct inode *dir, struct dir_context *ctx)
 {
 	struct fuse_conn *fc = get_fuse_conn(dir);
fs/fuse/virtio_fs.c +1 -2
index 57cc3fe3e07b..8868ac31a3c0 100644
@@ -16,8 +16,7 @@
 #include <linux/fs_parser.h>
 #include <linux/highmem.h>
 #include <linux/uio.h>
-
-#include <net/fuse.h>
+#include "fuse_i.h"
 
 /* List of virtio-fs device instances and a lock for the list. Also provides
  * mutual exclusion in device removal and mounting path
fs/fuse/xattr.c +2 -2
index 46a2919e53ca..cdea18de94f7 100644
@@ -6,11 +6,11 @@
  * See the file COPYING.
  */
 
+#include "fuse_i.h"
+
 #include <linux/xattr.h>
 #include <linux/posix_acl_xattr.h>
 
-#include <net/fuse.h>
-
 int fuse_setxattr(struct inode *inode, const char *name, const void *value,
 		  size_t size, int flags)
 {
include/net/fuse.h +5 -641

716 lines not on this page · raw message

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

#27 lore raw
Quoted 9 lines · Miklos Szeredi
Quoted 1 line

Does this more or less what you had in mind?

Just moving the whole internal header file is not nice. I did a mechanical public/private separation of the interface based on what
CUSE uses. Incremental patch attached.

But this is just a start. From the big structures still left in <net/fuse.h> CUSE only uses the following fields:

Quoted 7 lines

fc: .minor, max_read, max_write, rcu, release, initialized, num_waiting
fm: .fc
ff: .fm
fud: .fc

Dealing with the last 3 is trivial: create and alloc function for the fm, and create accessor functions for the accessed fields.

Ah, ok. So the goal is that <net/fuse.h> provides the bare minimum such that CUSE and MUSE can reside outside of fs/fuse?

Quoted 4 lines

Dealing with fc properly is probably a bit more involved, but does not seem to be too compex at first glance.

Do you want to take a stab at cleaning this up further?

Yes. I guess for MUSE the interface needs little adaptations as well. But I won't be able to do this for the 5.12 merge window.

Signature · 6 lines
Thanks,
//richard

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
maintainer
#28 lore raw
In reply to Miklos Szeredi
Quoted 8 lines · Miklos Szeredi

But this is just a start. From the big structures still left in <net/fuse.h> CUSE only uses the following fields:

fc: .minor, max_read, max_write, rcu, release, initialized, num_waiting
fm: .fc
ff: .fm
fud: .fc

Quoted 7 lines

Dealing with the last 3 is trivial: create and alloc function for the fm, and create accessor functions for the accessed fields.

Dealing with fc properly is probably a bit more involved, but does not seem to be too compex at first glance.

Do you want to take a stab at cleaning this up further?

On second thought, I'll finish this off, since I know the internal API better.

Thanks,
Miklos

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

maintainer
#29 lore raw
Quoted 14 lines · Miklos Szeredi
Quoted 11 lines · Miklos Szeredi

But this is just a start. From the big structures still left in <net/fuse.h> CUSE only uses the following fields:

fc: .minor, max_read, max_write, rcu, release, initialized, num_waiting
fm: .fc
ff: .fm
fud: .fc

Dealing with the last 3 is trivial: create and alloc function for the fm, and create accessor functions for the accessed fields.

Quoted 7 lines
Quoted 4 lines

Dealing with fc properly is probably a bit more involved, but does not seem to be too compex at first glance.

Do you want to take a stab at cleaning this up further?

On second thought, I'll finish this off, since I know the internal API better.

Pushed to

git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/fuse.git#fs_fuse_split

There's still room for improvement, but I guess this can wait after MUSE integration.

Thanks,
Miklos

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

maintainer
#30 lore raw
Quoted 7 lines · Miklos Szeredi

Pushed to

git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/fuse.git#fs_fuse_split

There's still room for improvement, but I guess this can wait after MUSE integration.

Hi Richard,

Have you had a chance of looking at this?

Thanks,
Miklos

author maintainer
#31 lore raw
In reply to Miklos Szeredi

Miklos,

----- Ursprüngliche Mail -----

Quoted 2 lines

If you look at fuse_do_ioctl() it does variable length input and output at the same time. I guess you need something similar to that.

I'm not sure whether I understand correctly.

In MUSE one use case would be attaching two distinct (variable length) buffers to a single FUSE request, in both directions.
If I read fuse_do_ioctl() correctly, it attaches always a single buffer per request but does multiple requests.

In MUSE we cold go the same path and issue up to two requests. One for in-band and optionally a second one for the out-of-band data. Hmmm?

Thanks,
//richard

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

maintainer
#32 lore raw
Quoted 7 lines · Richard Weinberger

Miklos,

----- Ursprüngliche Mail -----

Quoted 2 lines

If you look at fuse_do_ioctl() it does variable length input and output at the same time. I guess you need something similar to that.

Quoted 6 lines

I'm not sure whether I understand correctly.

In MUSE one use case would be attaching two distinct (variable length) buffers to a single FUSE request, in both directions.
If I read fuse_do_ioctl() correctly, it attaches always a single buffer per request but does multiple requests.

Right.

Quoted 3 lines

In MUSE we cold go the same path and issue up to two requests. One for in-band and optionally a second one for the out-of-band data. Hmmm?

Does in-band and OOB data need to be handled together? If so, then two requests is not a good option.

Thanks,
Miklos

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

#33 lore raw
Quoted 5 lines · Miklos Szeredi
Quoted 4 lines

In MUSE one use case would be attaching two distinct (variable length) buffers to a single FUSE request, in both directions.
If I read fuse_do_ioctl() correctly, it attaches always a single buffer per request but does multiple requests.

Quoted 8 lines

Right.

Quoted 3 lines

In MUSE we cold go the same path and issue up to two requests. One for in-band and optionally a second one for the out-of-band data. Hmmm?

Does in-band and OOB data need to be handled together? If so, then two requests is not a good option.

They can be handled separately. All I need to figure who to abstract this nicely in libfuse.

Signature · 6 lines
Thanks,
//richard

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
maintainer
#34 lore raw
In reply to Miklos Szeredi

Hi Miklos,

Miklos Szeredi <[email protected]> wrote on Wed, 10 Feb 2021 11:16:45 +0100:

Quoted 15 lines · Richard Weinberger
Quoted 7 lines

Miklos,

----- Ursprüngliche Mail -----

Quoted 2 lines

If you look at fuse_do_ioctl() it does variable length input and output at the same time. I guess you need something similar to that.

Quoted 6 lines

I'm not sure whether I understand correctly.

In MUSE one use case would be attaching two distinct (variable length) buffers to a single FUSE request, in both directions.
If I read fuse_do_ioctl() correctly, it attaches always a single buffer per request but does multiple requests.

Quoted 7 lines

Right.

Quoted 3 lines

In MUSE we cold go the same path and issue up to two requests. One for in-band and optionally a second one for the out-of-band data. Hmmm?

Does in-band and OOB data need to be handled together?

Short answer: yes.

Quoted 1 line

If so, then two requests is not a good option.

More detailed answer:

There is a type of MTD device (NAND devices) which are composed, for each page, of X in-band bytes plus Y out-of-band metadata bytes.

Accessing either the in-band data, or the out-of-band data, or both at the same time are all valid use cases.

* Read operation details:
From a hardware point of view, the out-of-band data is (almost) always retrieved when the in-band data is read because it contains meta-data used to correct eventual bitflips. In this case, if both areas are requested, it is highly non-efficient to do two requests, that's why the MTD core allows to do both at the same time.
* Write operation details:
Even worse, in the write case, you *must* write both at the same time. It is physically impossible to do one after the other (still with actual hardware, of course).

That is why it is preferable that MUSE will be able to access both in a single request.

Thanks,
Miquèl

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

author maintainer
#35 lore raw

Miquel,

----- Ursprüngliche Mail -----

Quoted 25 lines
Quoted 1 line

Does in-band and OOB data need to be handled together?

Short answer: yes.

Quoted 1 line

If so, then two requests is not a good option.

More detailed answer:

There is a type of MTD device (NAND devices) which are composed, for each page, of X in-band bytes plus Y out-of-band metadata bytes.

Accessing either the in-band data, or the out-of-band data, or both at the same time are all valid use cases.

* Read operation details:
From a hardware point of view, the out-of-band data is (almost) always retrieved when the in-band data is read because it contains meta-data used to correct eventual bitflips. In this case, if both areas are requested, it is highly non-efficient to do two requests, that's why the MTD core allows to do both at the same time.
* Write operation details:
Even worse, in the write case, you *must* write both at the same time. It is physically impossible to do one after the other (still with actual hardware, of course).

Quoted 2 lines

That is why it is preferable that MUSE will be able to access both in a single request.

By single request we meant FUSE op-codes. The NAND simulator in Userspace will see just one call. My plan is to abstract it in libfuse.

Thanks,
//richard

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

maintainer
#36 lore raw

Hi Richard,

Richard Weinberger <[email protected]> wrote on Wed, 10 Feb 2021 12:23:53 +0100 (CET):

Quoted 28 lines

Miquel,

----- Ursprüngliche Mail -----

Quoted 25 lines
Quoted 1 line

Does in-band and OOB data need to be handled together?

Short answer: yes.

Quoted 1 line

If so, then two requests is not a good option.

More detailed answer:

There is a type of MTD device (NAND devices) which are composed, for each page, of X in-band bytes plus Y out-of-band metadata bytes.

Accessing either the in-band data, or the out-of-band data, or both at the same time are all valid use cases.

* Read operation details:
From a hardware point of view, the out-of-band data is (almost) always retrieved when the in-band data is read because it contains meta-data used to correct eventual bitflips. In this case, if both areas are requested, it is highly non-efficient to do two requests, that's why the MTD core allows to do both at the same time.
* Write operation details:
Even worse, in the write case, you *must* write both at the same time. It is physically impossible to do one after the other (still with actual hardware, of course).

Quoted 5 lines
Quoted 2 lines

That is why it is preferable that MUSE will be able to access both in a single request.

By single request we meant FUSE op-codes. The NAND simulator in Userspace will see just one call. My plan is to abstract it in libfuse.

If libfuse abstracts it, as long as MTD only sees a single request I'm fine :)

Thanks,
Miquèl

author maintainer
#37 lore raw

----- Ursprüngliche Mail -----

Quoted 5 lines
Quoted 2 lines

By single request we meant FUSE op-codes. The NAND simulator in Userspace will see just one call. My plan is to abstract it in libfuse.

If libfuse abstracts it, as long as MTD only sees a single request I'm fine :)

:-)

I'll prototype that in the next few weeks. Let's see whether my plans are doable to not.

Thanks,
//richard

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/