Skip to contentSkip to conversation

Expose encoding information of volumes

PATCH In review Gabriel Krisman Bertazi 5 participants 16 messages Sep 28 – Sep 29

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

cover Expose encoding information of volumes

Daniel Tang reported [1] some inconsistencies in detecting filesystem casefold support on shmem. The problem is that we don't expose the casefold arguments in /proc/mounts for shmem, requiring you to probe the the filesystem to discover it. More interestingly, it can be a problem for programs that use /proc/mounts to remount filesystems, making them to remount "case-sensitively'. This apparently is a real use case in linux utils, according to my favorite LLM. shmem is fixed by patch 1.

This made me go look at how other casefolding filesystems expose this information and found it to be very inconsistent. f2fs is the only one doing it properly over /sys/fs/<vol>/encoding. Ext4 and ovl don't have nice ways to expose it, so the remaining patches replicate the f2fs interface for them.

I considered a /sys/fs interface for shmem as wel. It makes sense. But since shmem is the only filesystem where casefolding is a mount option, it also makes sense for it to appear in /proc/mounts. Considering it doesn't have /sys/fs at the moment, it does fell like overkill to add it just for this file.

ovl also doesn't have a /sys/fs/ entry. But in its case, casefold is derived from the lower/upper directories, so it cannot not be set in /proc/mounts. For this reason, I ended up plumbling /sys/fs/overlay and wiring the encoding file just like ext4 and f2fs.

[1] https://lore.kernel.org/linux-fsdevel/5193732.31r3eYUQgx@daniel-desktop3/#

---
Cc: Christian Brauner <[email protected]>
Cc: Jan Kara <[email protected]>
Cc: "Theodore Ts'o" <[email protected]>
Cc: Hugh Dickins <[email protected]>
Cc: Daniel Tang <[email protected]>
Cc: [email protected]
Cc: Miklos Szeredi <[email protected]>
Cc: Amir Goldstein <[email protected]>
CC: [email protected]
CC: [email protected]

Gabriel Krisman Bertazi (4):
shmem: Report casefold setting in mount options
ext4: Expose the filesystem encoding through sysfs
ovl: Add /sys/fs/overlay plumbing
ovl: Expose the filesystem encoding through sysfs

 Documentation/ABI/testing/sysfs-fs-ext4    |  21 ++++
 Documentation/ABI/testing/sysfs-fs-overlay |  13 +++
 MAINTAINERS                                |   1 +
 fs/ext4/sysfs.c                            |  29 ++++++
 fs/overlayfs/Makefile                      |   2 +-
 fs/overlayfs/overlayfs.h                   |   5 +
 fs/overlayfs/ovl_entry.h                   |   7 ++
 fs/overlayfs/super.c                       |  26 ++++-
 fs/overlayfs/sysfs.c                       | 116 +++++++++++++++++++++
 mm/shmem.c                                 |  11 ++
 10 files changed, 227 insertions(+), 4 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-fs-overlay
 create mode 100644 fs/overlayfs/sysfs.c
Signature · 1 line
2.55.0
#1 lore raw

PATCH 1/4 shmem: Report casefold setting in mount options

For shmem, casefolding is a mount option. Report the current encoding and casefolding flags in /proc/mounts, so userspace can easily check if casefolding is supported withour relying on parsing dmesg or trying to set +F.

---
 mm/shmem.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
mm/shmem.c +11 -0
index 897fa2b61346..2b93fcbf5127 100644
@@ -4916,6 +4916,17 @@ static int shmem_show_options(struct seq_file *seq, struct dentry *root)
 	if (sbinfo->qlimits.grpquota_ihardlimit)
 		seq_printf(seq, ",grpquota_inode_hardlimit=%lld",
 			   sbinfo->qlimits.grpquota_ihardlimit);
+#endif
+#if IS_ENABLED(CONFIG_UNICODE)
+	if (root->d_sb->s_encoding) {
+		unsigned int version = root->d_sb->s_encoding->version;
+
+		seq_printf(seq, ",casefold=utf8-%u.%u.%u",
+			   unicode_major(version), unicode_minor(version),
+			   unicode_rev(version));
+		if (sb_has_strict_encoding(root->d_sb))
+			seq_puts(seq, ",strict_encoding");
+	}
 #endif
 	return 0;
 }
Signature · 1 line
2.55.0
#2 lore raw

Re: [PATCH 1/4] shmem: Report casefold setting in mount options

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 9 lines

For shmem, casefolding is a mount option. Report the current encoding and casefolding flags in /proc/mounts, so userspace can easily check if casefolding is supported withour relying on parsing dmesg or trying to set +F.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Tested-by on v1 1/4
#3 lore raw

Re: [PATCH 1/4] shmem: Report casefold setting in mount options

In reply to Gabriel Krisman Bertazi
Quoted 2 lines · Gabriel Krisman Bertazi

For shmem, casefolding is a mount option. Report the current encoding and casefolding flags in /proc/mounts

This works for me, on 90ddfbd19636 (akpm/mm-unstable), x86_64, CONFIG_UNICODE=y:

  # mount -t tmpfs -o casefold tmpfs /t
  # grep /t /proc/mounts
  tmpfs /t tmpfs rw,relatime,casefold=utf8-12.1.0 0 0

Heads-up on one side effect, since mount(8) builds its remount options from /proc/mounts: once casefold= is listed there, it gets passed back on every remount.

  # mount -t tmpfs -o casefold tmpfs /t
  [  527.593309] tmpfs: Using encoding : utf8-12.1.0
  # mount -o remount,size=64M /t
  [  527.595716] tmpfs: Using encoding : utf8-12.1.0

That second line is shmem_parse_opt_casefold() running on a remount that only asked to change size. It calls utf8_load() each time, and nothing frees the result - shmem_reconfigure() doesn't look at ctx->encoding and shmem_free_fc() doesn't unload it. 50000 such remounts grew kmalloc-32 by ~50000 objects; a tmpfs without casefold stays flat.

The leak predates this patch - you can trigger it by passing casefold= on a remount by hand - so I sent the fix as a separate patch:

https://lore.kernel.org/all/ba38f80f629fd093c77f3a49fdab7b71ee7bbc5f.1790687276.git.med08elkadiri@gmail.com/

#4 lore raw

Re: [PATCH 1/4] shmem: Report casefold setting in mount options

Quoted 4 lines · Mohammed EL Kadiri
Quoted 2 lines · Gabriel Krisman Bertazi

For shmem, casefolding is a mount option. Report the current encoding and casefolding flags in /proc/mounts

Quoted 8 lines

This works for me, on 90ddfbd19636 (akpm/mm-unstable), x86_64, CONFIG_UNICODE=y:

  # mount -t tmpfs -o casefold tmpfs /t
  # grep /t /proc/mounts
  tmpfs /t tmpfs rw,relatime,casefold=utf8-12.1.0 0 0

Thanks!

Quoted 9 lines

Heads-up on one side effect, since mount(8) builds its remount options from /proc/mounts: once casefold= is listed there, it gets passed back on every remount.

  # mount -t tmpfs -o casefold tmpfs /t
  [  527.593309] tmpfs: Using encoding : utf8-12.1.0
  # mount -o remount,size=64M /t
  [  527.595716] tmpfs: Using encoding : utf8-12.1.0

This is desired behavior, IMO. You should not lose casefold during a remount, at risk of botching your data/splitting unrelated files. Also this is the reason why I didn't expose it directly in /proc/mounts for ovl, it would be easier but break the remount.

Quoted 10 lines

That second line is shmem_parse_opt_casefold() running on a remount that only asked to change size. It calls utf8_load() each time, and nothing frees the result - shmem_reconfigure() doesn't look at ctx->encoding and shmem_free_fc() doesn't unload it. 50000 such remounts grew kmalloc-32 by ~50000 objects; a tmpfs without casefold stays flat.

The leak predates this patch - you can trigger it by passing casefold= on a remount by hand - so I sent the fix as a separate patch:

https://lore.kernel.org/all/ba38f80f629fd093c77f3a49fdab7b71ee7bbc5f.1790687276.git.med08elkadiri@gmail.com/

Thanks for reporting and fixing this. feel free to cc me on further unicode stuff. Will review it right now.

Thanks,

Signature · 1 line
Gabriel Krisman Bertazi
#5 lore raw

PATCH 2/4 ext4: Expose the filesystem encoding through sysfs

In reply to Gabriel Krisman Bertazi

Daniel Tang pointed out that shmem doesn't list casefold as a mount option, even when it is mounted casefolded. While fixing it, I noticed f2fs actually already provides that information via sysfs, but ext4 doesn't. This patch reproduces the same interface in ext4 to have feature parity, so users don't need to rely on parsing dmesg or trying +F on a temporary directory just to check for support.

---
 Documentation/ABI/testing/sysfs-fs-ext4 | 21 ++++++++++++++++++
 fs/ext4/sysfs.c                         | 29 +++++++++++++++++++++++++
 2 files changed, 50 insertions(+)
Documentation/ABI/testing/sysfs-fs-ext4 +21 -0
index 2edd0a6672d3..8abc5706f459 100644
@@ -116,3 +116,24 @@ Contact:	"Theodore Ts'o" <[email protected]>
 Description:
 		This file is read-only and shows the pid of journal thread in
 		current pid-namespace or 0 if task is unreachable.
+
+What:		/sys/fs/ext4/<disk>/encoding
+Date:		September 2026
+Contact:	"Gabriel Krisman Bertazi" <[email protected]>
+Description:
+		Displays name and version of the encoding set for the
+		filesystem.  If no encoding is set, displays (none)
+
+What:		/sys/fs/ext4/<disk>/encoding_flags
+Date:		September 2026
+Contact:	"Gabriel Krisman Bertazi" <[email protected]>
+Description:
+		This is a read-only entry to show the value of
+		sb.s_encoding_flags, the value is hexadecimal.
+
+		============================     ==========
+		Flag_Name                        Flag_Value
+		============================     ==========
+		SB_ENC_STRICT_MODE_FL            0x00000001
+		SB_ENC_NO_COMPAT_FALLBACK_FL     0x00000002
+		============================     ==========
fs/ext4/sysfs.c +29 -0
index 923b375e017f..bc1c59d67eed 100644
@@ -32,6 +32,8 @@ typedef enum {
 	attr_clusters_in_group,
 	attr_mb_order,
 	attr_feature,
+	attr_encoding,
+	attr_encoding_flags,
 	attr_pointer_pi,
 	attr_pointer_ui,
 	attr_pointer_ul,
@@ -161,6 +163,25 @@ static ssize_t err_report_sec_store(struct ext4_sb_info *sbi,
 	return count;
 }
 
+static ssize_t encoding_show(struct ext4_sb_info *sbi, char *buf)
+{
+#if IS_ENABLED(CONFIG_UNICODE)
+	struct super_block *sb = sbi->s_sb;
+
+	if (ext4_has_feature_casefold(sb))
+		return sysfs_emit(buf, "UTF-8 (%d.%d.%d)\n",
+				  unicode_major(sb->s_encoding->version),
+				  unicode_minor(sb->s_encoding->version),
+				  unicode_rev(sb->s_encoding->version));
+#endif
+	return sysfs_emit(buf, "(none)\n");
+}
+
+static ssize_t encoding_flags_show(struct ext4_sb_info *sbi, char *buf)
+{
+	return sysfs_emit(buf, "%x\n", le16_to_cpu(sbi->s_es->s_encoding_flags));
+}
+
 static ssize_t journal_task_show(struct ext4_sb_info *sbi, char *buf)
 {
 	if (!sbi->s_journal)
@@ -283,6 +304,8 @@ EXT4_RO_ATTR_ES_STRING(last_error_func, s_last_error_func, 32);
 EXT4_ATTR(first_error_time, 0444, first_error_time);
 EXT4_ATTR(last_error_time, 0444, last_error_time);
 EXT4_ATTR(journal_task, 0444, journal_task);
+EXT4_ATTR_FUNC(encoding, 0444);
+EXT4_ATTR_FUNC(encoding_flags, 0444);
 EXT4_RW_ATTR_SBI_UI(mb_prefetch, s_mb_prefetch);
 EXT4_RW_ATTR_SBI_UI(mb_prefetch_limit, s_mb_prefetch_limit);
 EXT4_RW_ATTR_SBI_UL(last_trim_minblks, s_last_trim_minblks);
@@ -333,6 +356,8 @@ static struct attribute *ext4_attrs[] = {
 	ATTR_LIST(first_error_time),
 	ATTR_LIST(last_error_time),
 	ATTR_LIST(journal_task),
+	ATTR_LIST(encoding),
+	ATTR_LIST(encoding_flags),
 #ifdef CONFIG_EXT4_DEBUG
 	ATTR_LIST(simulate_fail),
 #endif
@@ -483,6 +508,10 @@ static ssize_t ext4_attr_show(struct kobject *kobj,
 		return print_tstamp(buf, sbi->s_es, s_last_error_time);
 	case attr_journal_task:
 		return journal_task_show(sbi, buf);
+	case attr_encoding:
+		return encoding_show(sbi, buf);
+	case attr_encoding_flags:
+		return encoding_flags_show(sbi, buf);
 	default:
 		return ext4_generic_attr_show(a, sbi, buf);
 	}
Signature · 1 line
2.55.0
#6 lore raw

Re: [PATCH 2/4] ext4: Expose the filesystem encoding through sysfs

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] ext4: NULL pointer deref in encoding_show() via dynamic casefold --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] ext4: NULL pointer deref in encoding_show() via dynamic casefold --

commit c325498f77eea14582e06218baa713f49fde001a
Author: Gabriel Krisman Bertazi <[email protected]>

ext4: Expose the filesystem encoding through sysfs

This commit introduces new sysfs attributes in ext4 to display the active filesystem encoding and encoding flags. This provides users with a direct interface to check casefold support without relying on dmesg parsing.

Quoted 4 lines
fs/ext4/sysfs.c +0 -0
index 923b375e017fa..bc1c59d67eed8 100644

[ ... ]

Quoted 4 lines
fs/ext4/sysfs.c +0 -0
@@ -161,6 +163,25 @@ static ssize_t err_report_sec_store(struct ext4_sb_info *sbi,
 	return count;
 }
 

fs/ext4/sysfs.c static ssize_t err_report_sec_store(struct ext4_sb_info *sbi, · line 175

Quoted 10 lines
fs/ext4/sysfs.c +10 -0
+static ssize_t encoding_show(struct ext4_sb_info *sbi, char *buf)
+{
+#if IS_ENABLED(CONFIG_UNICODE)
+	struct super_block *sb = sbi->s_sb;
+
+	if (ext4_has_feature_casefold(sb))
+		return sysfs_emit(buf, "UTF-8 (%d.%d.%d)\n",
+				  unicode_major(sb->s_encoding->version),
+				  unicode_minor(sb->s_encoding->version),
+				  unicode_rev(sb->s_encoding->version));

[Severity: High]
Does this introduce a regression where reading the sysfs attribute causes a NULL pointer dereference if casefold is enabled dynamically?

If a privileged user dynamically enables EXT4_FEATURE_INCOMPAT_CASEFOLD on an online filesystem via the EXT4_IOC_SET_TUNE_SB_PARAM ioctl, it updates the in-memory on-disk superblock representation but does not load the unicode map into the VFS superblock:

fs/ext4/ioctl.c:ext4_ioctl_set_tune_sb() {
    ...
    if ((params.set_feature_incompat_mask &
         EXT4_FEATURE_INCOMPAT_CASEFOLD)) {
        enabling_casefold = 1;
    ...
}

In this state, ext4_has_feature_casefold(sb) evaluates to true, but sb->s_encoding remains NULL. If the sysfs attribute is read, encoding_show() will unconditionally dereference sb->s_encoding->version, resulting in a system crash.

Quoted 4 lines
fs/ext4/sysfs.c +4 -0
+#endif
+	return sysfs_emit(buf, "(none)\n");
+}
+

[ ... ]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#7 lore raw

Re: [PATCH 2/4] ext4: Expose the filesystem encoding through sysfs

Quoted 50 lines · [email protected] writes:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] ext4: NULL pointer deref in encoding_show() via dynamic casefold --

commit c325498f77eea14582e06218baa713f49fde001a
Author: Gabriel Krisman Bertazi <[email protected]>

ext4: Expose the filesystem encoding through sysfs

This commit introduces new sysfs attributes in ext4 to display the active filesystem encoding and encoding flags. This provides users with a direct interface to check casefold support without relying on dmesg parsing.

Quoted 4 lines
fs/ext4/sysfs.c +0 -0
index 923b375e017fa..bc1c59d67eed8 100644

[ ... ]

Quoted 4 lines
fs/ext4/sysfs.c +0 -0
@@ -161,6 +163,25 @@ static ssize_t err_report_sec_store(struct ext4_sb_info *sbi,
 	return count;
 }
 

fs/ext4/sysfs.c static ssize_t err_report_sec_store(struct ext4_sb_info *sbi, · line 175

Quoted 10 lines
fs/ext4/sysfs.c +10 -0
+static ssize_t encoding_show(struct ext4_sb_info *sbi, char *buf)
+{
+#if IS_ENABLED(CONFIG_UNICODE)
+	struct super_block *sb = sbi->s_sb;
+
+	if (ext4_has_feature_casefold(sb))
+		return sysfs_emit(buf, "UTF-8 (%d.%d.%d)\n",
+				  unicode_major(sb->s_encoding->version),
+				  unicode_minor(sb->s_encoding->version),
+				  unicode_rev(sb->s_encoding->version));

[Severity: High]
Does this introduce a regression where reading the sysfs attribute causes a NULL pointer dereference if casefold is enabled dynamically?

If a privileged user dynamically enables EXT4_FEATURE_INCOMPAT_CASEFOLD on an online filesystem via the EXT4_IOC_SET_TUNE_SB_PARAM ioctl, it updates the in-memory on-disk superblock representation but does not load the unicode map into the VFS superblock:

fs/ext4/ioctl.c:ext4_ioctl_set_tune_sb() {
    ...
    if ((params.set_feature_incompat_mask &
         EXT4_FEATURE_INCOMPAT_CASEFOLD)) {
        enabling_casefold = 1;
    ...
}
Quoted 4 lines

In this state, ext4_has_feature_casefold(sb) evaluates to true, but sb->s_encoding remains NULL. If the sysfs attribute is read, encoding_show() will unconditionally dereference sb->s_encoding->version, resulting in a system crash.

Uh...

If we flip EXT4_FEATURE_INCOMPAT_CASEFOLD without loading the casefold table, I'm surprised the current code doesn't blow up already. I completely missed the introduction of EXT4_IOC_SET_TUNE_SB_PARAM, so I'm missing context if there is a use case to actually do an online flip of feat_casefold. It seems the ioctl actually can set this bit, but I don't see any provision to load the table. I'm a bit confused now. I can work around it for /sys/fs, but is anyone actually enabling casefold without a remount?

Quoted 9 lines
Quoted 5 lines
fs/ext4/sysfs.c +4 -0
+#endif
+	return sysfs_emit(buf, "(none)\n");
+}
+

[ ... ]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Signature · 1 line
Gabriel Krisman Bertazi
#8 lore raw

PATCH 3/4 ovl: Add /sys/fs/overlay plumbing

In reply to Gabriel Krisman Bertazi

In preparation to expose encoding settings in sysfs, add a subtree for overlayfs under /sys/fs. The only remarkable detail is how we reference the volume. Use major:minor, which is not very human-friendly but it is at least discoverable. I considered uuid, but that would be a problem if mounted with uuid=off.

---
 Documentation/ABI/testing/sysfs-fs-overlay |   6 ++
 MAINTAINERS                                |   1 +
 fs/overlayfs/Makefile                      |   2 +-
 fs/overlayfs/overlayfs.h                   |   5 +
 fs/overlayfs/ovl_entry.h                   |   7 ++
 fs/overlayfs/super.c                       |  26 +++++-
 fs/overlayfs/sysfs.c                       | 101 +++++++++++++++++++++
 7 files changed, 144 insertions(+), 4 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-fs-overlay
 create mode 100644 fs/overlayfs/sysfs.c
Documentation/ABI/testing/sysfs-fs-overlay new file +6 -0
new file mode 100644
index 000000000000..9060c39679ae
@@ -0,0 +1,6 @@
+What:		/sys/fs/overlay/<volume>/
+Date:		September 2026
+Contact:	[email protected]
+Description:
+		A directory is created for every mounted overlayfs instance.
+		<volume> is set to the device major:minor.
MAINTAINERS +1 -0
index c2414447892c..e49f84c4c691 100644
@@ -20586,6 +20586,7 @@ M:	Amir Goldstein <[email protected]>
 L:	[email protected]
 S:	Supported
 T:	git git://git.kernel.org/pub/scm/linux/kernel/git/overlayfs/vfs.git
+F:	Documentation/ABI/testing/sysfs-fs-overlay
 F:	Documentation/filesystems/overlayfs.rst
 F:	fs/overlayfs/
 
fs/overlayfs/Makefile +1 -1
index 5648954f8588..fd4e747820c2 100644
@@ -6,4 +6,4 @@
 obj-$(CONFIG_OVERLAY_FS) += overlay.o
 
 overlay-objs := super.o namei.o util.o inode.o file.o dir.o readdir.o \
-		copy_up.o export.o params.o xattrs.o
+		copy_up.o export.o params.o xattrs.o sysfs.o
fs/overlayfs/overlayfs.h +5 -0
index e0d8c6152e9f..91d3894d9bd2 100644
@@ -939,6 +939,11 @@ extern const struct export_operations ovl_export_fid_operations;
 /* super.c */
 int ovl_fill_super(struct super_block *sb, struct fs_context *fc);
 
+int __init ovl_sysfs_init(void);
+void ovl_sysfs_exit(void);
+int ovl_sysfs_register(struct ovl_fs *ofs);
+void ovl_sysfs_unregister(struct ovl_fs *ofs);
+
 /* Will this overlay be forced to mount/remount ro? */
 static inline bool ovl_force_readonly(struct ovl_fs *ofs)
 {
fs/overlayfs/ovl_entry.h +7 -0
index 80cad4ea96a3..c14253e75826 100644
@@ -5,6 +5,9 @@
  * Copyright (C) 2016 Red Hat, Inc.
  */
 
+#include <linux/completion.h>
+#include <linux/kobject.h>
+
 struct ovl_config {
 	char *upperdir;
 	char *workdir;
@@ -56,6 +59,7 @@ struct ovl_entry {
 
 /* private information held for overlayfs's superblock */
 struct ovl_fs {
+	struct super_block *sb;
 	unsigned int numlayer;
 	/* Number of unique fs among layers including upper fs */
 	unsigned int numfs;
@@ -92,6 +96,9 @@ struct ovl_fs {
 	/* r/o snapshot of upperdir sb's only taken on volatile mounts */
 	errseq_t errseq;
 	bool casefold;
+	struct kobject kobj;
+	struct completion kobj_unregister;
+	bool kobj_registered;
 };
 
 /* Number of lower layers, not including data-only layers */
fs/overlayfs/super.c +23 -3
index bd0a3f9039d2..d195dace135d 100644
@@ -226,8 +226,10 @@ static void ovl_put_super(struct super_block *sb)
 {
 	struct ovl_fs *ofs = OVL_FS(sb);
 
-	if (ofs)
+	if (ofs) {
+		ovl_sysfs_unregister(ofs);
 		ovl_free_fs(ofs);
+	}
 }
 
 /* Sync real dirty inodes in upper filesystem (if it exists) */
@@ -1548,6 +1550,7 @@ int ovl_fill_super(struct super_block *sb, struct fs_context *fc)
 	if (fc->user_ns != current_user_ns())
 		goto out_err;
 
+	ofs->sb = sb;
 	ovl_set_d_op(sb);
 
 	if (!ofs->creator_cred) {
@@ -1559,6 +1562,13 @@ int ovl_fill_super(struct super_block *sb, struct fs_context *fc)
 
 	with_ovl_creds(sb)
 		err = ovl_fill_super_creds(fc, sb);
+	if (err)
+		goto out_err;
+	/*
+	 * ->s_root is now set (by ovl_fill_super_creds), so if
+	 * ovl_sysfs_register fails it will be cleaned by ovl_put_super.
+	 */
+	return ovl_sysfs_register(ofs);
 
 out_err:
 	if (err) {
@@ -1598,10 +1608,19 @@ static int __init ovl_init(void)
 	if (ovl_inode_cachep == NULL)
 		return -ENOMEM;
 
+	err = ovl_sysfs_init();
+	if (err)
+		goto out_destroy_cache;
+
 	err = register_filesystem(&ovl_fs_type);
-	if (!err)
-		return 0;
+	if (err)
+		goto out_sysfs_exit;
+
+	return 0;
 
+out_sysfs_exit:
+	ovl_sysfs_exit();
+out_destroy_cache:
 	kmem_cache_destroy(ovl_inode_cachep);
 
 	return err;
@@ -1610,6 +1629,7 @@ static int __init ovl_init(void)
 static void __exit ovl_exit(void)
 {
 	unregister_filesystem(&ovl_fs_type);
+	ovl_sysfs_exit();
 
 	/*
 	 * Make sure all delayed rcu free inodes are flushed before we
fs/overlayfs/sysfs.c new file +101 -0

101 lines not on this page · raw message

Signature · 1 line
2.55.0
#9 lore raw

Re: [PATCH 3/4] ovl: Add /sys/fs/overlay plumbing

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 8 lines

In preparation to expose encoding settings in sysfs, add a subtree for overlayfs under /sys/fs. The only remarkable detail is how we reference the volume. Use major:minor, which is not very human-friendly but it is at least discoverable. I considered uuid, but that would be a problem if mounted with uuid=off.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
#10 lore raw

PATCH 4/4 ovl: Expose the filesystem encoding through sysfs

In reply to Gabriel Krisman Bertazi

This patch reproduces the same interface from ext4/f2fs to have feature parity, so users don't need to rely on parsing dmesg or trying +F on a temporary directory just to check for support. Note there is no encoding_flags file, as none are supported by ovl.

---
 Documentation/ABI/testing/sysfs-fs-overlay |  7 +++++++
 fs/overlayfs/sysfs.c                       | 15 +++++++++++++++
 2 files changed, 22 insertions(+)
Documentation/ABI/testing/sysfs-fs-overlay +7 -0
index 9060c39679ae..7f3c6403c4f8 100644
@@ -4,3 +4,10 @@ Contact:	[email protected]
 Description:
 		A directory is created for every mounted overlayfs instance.
 		<volume> is set to the device major:minor.
+
+What:		/sys/fs/overlay/<volume>/encoding
+Date:		September 2026
+Contact:	[email protected]
+Description:
+		Displays name and version of the encoding set for the
+		overlay.  If no encoding is set, displays (none)
fs/overlayfs/sysfs.c +15 -0
index be83b57f637c..2144cbb418bc 100644
@@ -22,7 +22,22 @@ struct ovl_sysfs_attr {
 		.show	= ovl_##_name##_show,				\
 	}
 
+static ssize_t ovl_encoding_show(struct ovl_fs *ofs, char *buf)
+{
+	struct unicode_map *um = sb_encoding(ofs->sb);
+
+	if (!um)
+		return sysfs_emit(buf, "(none)\n");
+
+	return sysfs_emit(buf, "UTF-8 (%d.%d.%d)\n",
+			  unicode_major(um->version),
+			  unicode_minor(um->version),
+			  unicode_rev(um->version));
+}
+OVL_SYSFS_ATTR_RO(encoding);
+
 static struct attribute *ovl_sysfs_attrs[] = {
+	&ovl_sysfs_attr_encoding.attr,
 	NULL,
 };
 ATTRIBUTE_GROUPS(ovl_sysfs);
Signature · 1 line
2.55.0
#11 lore raw

Re: [PATCH 4/4] ovl: Expose the filesystem encoding through sysfs

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 7 lines

This patch reproduces the same interface from ext4/f2fs to have feature parity, so users don't need to rely on parsing dmesg or trying +F on a temporary directory just to check for support. Note there is no encoding_flags file, as none are supported by ovl.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
maintainer
#12 lore raw

Re: [PATCH 4/4] ovl: Expose the filesystem encoding through sysfs

In reply to Gabriel Krisman Bertazi
Quoted 6 lines · Gabriel Krisman Bertazi

This patch reproduces the same interface from ext4/f2fs to have feature parity, so users don't need to rely on parsing dmesg or trying +F on a temporary directory just to check for support. Note there is no encoding_flags file, as none are supported by ovl.

Gabriel,

I am not ok with this API.
It is wrong in several ways.
It is not generic, we have already file_getattr() to get casefold status. There was a suggestion by Pali [1] to get the supported xflags - statx style, which can be a way to say if a fs could return FS_XFLAG_CASEFOLD. In Chuck's v2 [2] FILEATTR_CASEFOLD_TYPE was already suggested
as an extension to file_getattr(). I think we can still do that if we include proper versioning in the casefold type.

TBH, I don't think anyone requested this - you only mentioned the need to know if tmpfs was mounted with casefold on and that doesn't mean that etx4/ovl patches are justified, but ext4 can decide for themselves.

The point is that this sysfs is not going to be the standard for all the fs that can return the FS_XFLAG_CASEFOLD, so I see no reason to add this sysfs interface to ovl.

Thanks,
Amir.

[1] https://lore.kernel.org/linux-fsdevel/[email protected]/
[2] https://lore.kernel.org/linux-fsdevel/[email protected]/

#13 lore raw

Re: [PATCH 4/4] ovl: Expose the filesystem encoding through sysfs

Quoted 9 lines · On Tuesday 29 September 2026 16:15:04 Amir Goldstein wrote:
Quoted 6 lines · Gabriel Krisman Bertazi

This patch reproduces the same interface from ext4/f2fs to have feature parity, so users don't need to rely on parsing dmesg or trying +F on a temporary directory just to check for support. Note there is no encoding_flags file, as none are supported by ovl.

Quoted 7 lines

Gabriel,

I am not ok with this API.
It is wrong in several ways.
It is not generic, we have already file_getattr() to get casefold status. There was a suggestion by Pali [1] to get the supported xflags - statx style, which can be a way to say if a fs could return FS_XFLAG_CASEFOLD.

Yea, sorry for that. I have not finished it, I did not have time. But I would like to address this as this is something was was asked more times...

Quoted 18 lines

In Chuck's v2 [2] FILEATTR_CASEFOLD_TYPE was already suggested
as an extension to file_getattr(). I think we can still do that if we include proper versioning in the casefold type.

TBH, I don't think anyone requested this - you only mentioned the need to know if tmpfs was mounted with casefold on and that doesn't mean that etx4/ovl patches are justified, but ext4 can decide for themselves.

The point is that this sysfs is not going to be the standard for all the fs that can return the FS_XFLAG_CASEFOLD, so I see no reason to add this sysfs interface to ovl.

Thanks,
Amir.

[1] https://lore.kernel.org/linux-fsdevel/[email protected]/
[2] https://lore.kernel.org/linux-fsdevel/[email protected]/

#14 lore raw

Re: [PATCH 4/4] ovl: Expose the filesystem encoding through sysfs

Quoted 18 lines · Pali Rohár
Quoted 9 lines · On Tuesday 29 September 2026 16:15:04 Amir Goldstein wrote:
Quoted 6 lines · Gabriel Krisman Bertazi

This patch reproduces the same interface from ext4/f2fs to have feature parity, so users don't need to rely on parsing dmesg or trying +F on a temporary directory just to check for support. Note there is no encoding_flags file, as none are supported by ovl.

Quoted 7 lines

Gabriel,

I am not ok with this API.
It is wrong in several ways.
It is not generic, we have already file_getattr() to get casefold status. There was a suggestion by Pali [1] to get the supported xflags - statx style, which can be a way to say if a fs could return FS_XFLAG_CASEFOLD.

Quoted 3 lines

Yea, sorry for that. I have not finished it, I did not have time. But I would like to address this as this is something was was asked more times...

please cc me when sending it.

Signature · 1 line
Gabriel Krisman Bertazi
#15 lore raw

Re: [PATCH 4/4] ovl: Expose the filesystem encoding through sysfs

In reply to Amir Goldstein
Quoted 11 lines · Amir Goldstein

On Mon, Sep 28, 2026 at 11:32 PM Gabriel Krisman Bertazi <[email protected]> wrote:

I am not ok with this API.
It is wrong in several ways.
It is not generic, we have already file_getattr() to get casefold status. There was a suggestion by Pali [1] to get the supported xflags - statx style, which can be a way to say if a fs could return FS_XFLAG_CASEFOLD. In Chuck's v2 [2] FILEATTR_CASEFOLD_TYPE was already suggested
as an extension to file_getattr(). I think we can still do that if we include proper versioning in the casefold type.

Ok. I'm not fond of the overlay part of this series at all, in particular due to the major:minor design. I was looking for an alternative way to do it and didn't find it, thus /sys/fs.

Quoted 4 lines

TBH, I don't think anyone requested this - you only mentioned the need to know if tmpfs was mounted with casefold on and that doesn't mean that etx4/ovl patches are justified, but ext4 can decide for themselves.

There is a need for a proper probing API when deciding to fallback to userspace casefolding workarounds, and that is not shmem specific at all. I'm sure the Wine folks that right now use ext4/overlayfs will also benefit from a smarter way to fetch the information.

Quoted 3 lines

The point is that this sysfs is not going to be the standard for all the fs that can return the FS_XFLAG_CASEFOLD, so I see no reason to add this sysfs interface to ovl.

Ack. I'll drop patches 3 and 4 and wait on ext4 people to see if they want patch 2 to match f2fs. Will also keep an eye on FS_XFLAG_CASEFOLD.

Quoted 5 lines

Thanks,
Amir.

[1] https://lore.kernel.org/linux-fsdevel/[email protected]/
[2] https://lore.kernel.org/linux-fsdevel/[email protected]/

Signature · 1 line
Gabriel Krisman Bertazi