linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/3] tmpfs: Casefold fixes
@ 2024-11-01 16:42 André Almeida
  2024-11-01 16:42 ` [PATCH v2 1/3] libfs: Fix kernel-doc warning in generic_ci_validate_strict_name André Almeida
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: André Almeida @ 2024-11-01 16:42 UTC (permalink / raw)
  To: Hugh Dickins, Andrew Morton, Alexander Viro, Christian Brauner,
	Jan Kara, krisman, Stephen Rothwell, Nathan Chancellor
  Cc: linux-mm, linux-kernel, linux-fsdevel, kernel-dev,
	Theodore Ts'o, André Almeida

After casefold support for tmpfs was merged into vfs tree, two warnings
were reported and I also found a small fix in the code.

Thanks Nathan Chancellor and Stephen Rothwell!

Changelog:
- Fixed ifdef guard for tmpfs_sysfs_init()
v1: https://lore.kernel.org/lkml/20241101013741.295792-1-andrealmeid@igalia.com/

André Almeida (3):
  libfs: Fix kernel-doc warning in generic_ci_validate_strict_name
  tmpfs: Fix type for sysfs' casefold attribute
  tmpfs: Initialize sysfs during tmpfs init

 include/linux/fs.h |  10 ++---
 mm/shmem.c         | 105 +++++++++++++++++++++++++++++----------------
 2 files changed, 73 insertions(+), 42 deletions(-)

-- 
2.47.0



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 1/3] libfs: Fix kernel-doc warning in generic_ci_validate_strict_name
  2024-11-01 16:42 [PATCH v2 0/3] tmpfs: Casefold fixes André Almeida
@ 2024-11-01 16:42 ` André Almeida
  2024-11-01 16:42 ` [PATCH v2 2/3] tmpfs: Fix type for sysfs' casefold attribute André Almeida
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: André Almeida @ 2024-11-01 16:42 UTC (permalink / raw)
  To: Hugh Dickins, Andrew Morton, Alexander Viro, Christian Brauner,
	Jan Kara, krisman, Stephen Rothwell, Nathan Chancellor
  Cc: linux-mm, linux-kernel, linux-fsdevel, kernel-dev,
	Theodore Ts'o, André Almeida

Fix the indentation of the return values from
generic_ci_validate_strict_name() to properly render the comment and to
address a `make htmldocs` warning:

Documentation/filesystems/api-summary:14: include/linux/fs.h:3504:
WARNING: Bullet list ends without a blank line; unexpected unindent.

Fixes: 0e152beb5aa1 ("libfs: Create the helper function generic_ci_validate_strict_name()")
Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
Closes: https://lore.kernel.org/lkml/20241030162435.05425f60@canb.auug.org.au/
Signed-off-by: André Almeida <andrealmeid@igalia.com>
---
 include/linux/fs.h | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/include/linux/fs.h b/include/linux/fs.h
index 3b279f60e48f..b562a161e2ee 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -3499,12 +3499,12 @@ int generic_ci_d_compare(const struct dentry *dentry, unsigned int len,
  * @name: name of the new file
  *
  * Return:
- * * True if the filename is suitable for this directory. It can be
- * true if a given name is not suitable for a strict encoding
- * directory, but the directory being used isn't strict
+ * * True: if the filename is suitable for this directory. It can be
+ *   true if a given name is not suitable for a strict encoding
+ *   directory, but the directory being used isn't strict
  * * False if the filename isn't suitable for this directory. This only
- * happens when a directory is casefolded and the filesystem is strict
- * about its encoding.
+ *   happens when a directory is casefolded and the filesystem is strict
+ *   about its encoding.
  */
 static inline bool generic_ci_validate_strict_name(struct inode *dir, struct qstr *name)
 {
-- 
2.47.0



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 2/3] tmpfs: Fix type for sysfs' casefold attribute
  2024-11-01 16:42 [PATCH v2 0/3] tmpfs: Casefold fixes André Almeida
  2024-11-01 16:42 ` [PATCH v2 1/3] libfs: Fix kernel-doc warning in generic_ci_validate_strict_name André Almeida
@ 2024-11-01 16:42 ` André Almeida
  2024-11-01 16:42 ` [PATCH v2 3/3] tmpfs: Initialize sysfs during tmpfs init André Almeida
  2024-11-06 10:23 ` [PATCH v2 0/3] tmpfs: Casefold fixes Christian Brauner
  3 siblings, 0 replies; 5+ messages in thread
From: André Almeida @ 2024-11-01 16:42 UTC (permalink / raw)
  To: Hugh Dickins, Andrew Morton, Alexander Viro, Christian Brauner,
	Jan Kara, krisman, Stephen Rothwell, Nathan Chancellor
  Cc: linux-mm, linux-kernel, linux-fsdevel, kernel-dev,
	Theodore Ts'o, André Almeida

DEVICE_STRING_ATTR_RO should be only used by device drivers since it
relies on `struct device` to use device_show_string() function. Using
this with non device code led to a kCFI violation:

> cat /sys/fs/tmpfs/features/casefold
[   70.558496] CFI failure at kobj_attr_show+0x2c/0x4c (target: device_show_string+0x0/0x38; expected type: 0xc527b809)

Like the other filesystems, fix this by manually declaring the attribute
using kobj_attribute() and writing a proper show() function.

Also, leave macros for anyone that need to expand tmpfs sysfs' with
more attributes.

Fixes: 5132f08bd332 ("tmpfs: Expose filesystem features via sysfs")
Reported-by: Nathan Chancellor <nathan@kernel.org>
Closes: https://lore.kernel.org/lkml/20241031051822.GA2947788@thelio-3990X/
Signed-off-by: André Almeida <andrealmeid@igalia.com>
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Tested-by: Nathan Chancellor <nathan@kernel.org>
---
 mm/shmem.c | 29 +++++++++++++++++++++++++++--
 1 file changed, 27 insertions(+), 2 deletions(-)

diff --git a/mm/shmem.c b/mm/shmem.c
index b86f526a1cb1..6038e1d11987 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -5548,13 +5548,38 @@ struct page *shmem_read_mapping_page_gfp(struct address_space *mapping,
 EXPORT_SYMBOL_GPL(shmem_read_mapping_page_gfp);
 
 #if defined(CONFIG_SYSFS) && defined(CONFIG_TMPFS)
+
+#define __INIT_KOBJ_ATTR(_name, _mode, _show, _store)			\
+{									\
+	.attr	= { .name = __stringify(_name), .mode = _mode },	\
+	.show	= _show,						\
+	.store	= _store,						\
+}
+
+#define TMPFS_ATTR_W(_name, _store)				\
+	static struct kobj_attribute tmpfs_attr_##_name =	\
+			__INIT_KOBJ_ATTR(_name, 0200, NULL, _store)
+
+#define TMPFS_ATTR_RW(_name, _show, _store)			\
+	static struct kobj_attribute tmpfs_attr_##_name =	\
+			__INIT_KOBJ_ATTR(_name, 0644, _show, _store)
+
+#define TMPFS_ATTR_RO(_name, _show)				\
+	static struct kobj_attribute tmpfs_attr_##_name =	\
+			__INIT_KOBJ_ATTR(_name, 0444, _show, NULL)
+
 #if IS_ENABLED(CONFIG_UNICODE)
-static DEVICE_STRING_ATTR_RO(casefold, 0444, "supported");
+static ssize_t casefold_show(struct kobject *kobj, struct kobj_attribute *a,
+			char *buf)
+{
+		return sysfs_emit(buf, "supported\n");
+}
+TMPFS_ATTR_RO(casefold, casefold_show);
 #endif
 
 static struct attribute *tmpfs_attributes[] = {
 #if IS_ENABLED(CONFIG_UNICODE)
-	&dev_attr_casefold.attr.attr,
+	&tmpfs_attr_casefold.attr,
 #endif
 	NULL
 };
-- 
2.47.0



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 3/3] tmpfs: Initialize sysfs during tmpfs init
  2024-11-01 16:42 [PATCH v2 0/3] tmpfs: Casefold fixes André Almeida
  2024-11-01 16:42 ` [PATCH v2 1/3] libfs: Fix kernel-doc warning in generic_ci_validate_strict_name André Almeida
  2024-11-01 16:42 ` [PATCH v2 2/3] tmpfs: Fix type for sysfs' casefold attribute André Almeida
@ 2024-11-01 16:42 ` André Almeida
  2024-11-06 10:23 ` [PATCH v2 0/3] tmpfs: Casefold fixes Christian Brauner
  3 siblings, 0 replies; 5+ messages in thread
From: André Almeida @ 2024-11-01 16:42 UTC (permalink / raw)
  To: Hugh Dickins, Andrew Morton, Alexander Viro, Christian Brauner,
	Jan Kara, krisman, Stephen Rothwell, Nathan Chancellor
  Cc: linux-mm, linux-kernel, linux-fsdevel, kernel-dev,
	Theodore Ts'o, André Almeida

Instead of using fs_initcall(), initialize sysfs with the rest of the
filesystem. This is the right way to do it because otherwise any error
during tmpfs_sysfs_init() would get silently ignored. It's also useful
if tmpfs' sysfs ever need to display runtime information.

Signed-off-by: André Almeida <andrealmeid@igalia.com>
---
Changes from v1:
- Fixed ifdef guard for tmpfs_sysfs_init()
---
 mm/shmem.c | 130 ++++++++++++++++++++++++++++-------------------------
 1 file changed, 68 insertions(+), 62 deletions(-)

diff --git a/mm/shmem.c b/mm/shmem.c
index 6038e1d11987..a5355cf9443c 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -5126,6 +5126,66 @@ static struct file_system_type shmem_fs_type = {
 	.fs_flags	= FS_USERNS_MOUNT | FS_ALLOW_IDMAP | FS_MGTIME,
 };
 
+#if defined(CONFIG_SYSFS) && defined(CONFIG_TMPFS)
+
+#define __INIT_KOBJ_ATTR(_name, _mode, _show, _store)			\
+{									\
+	.attr	= { .name = __stringify(_name), .mode = _mode },	\
+	.show	= _show,						\
+	.store	= _store,						\
+}
+
+#define TMPFS_ATTR_W(_name, _store)				\
+	static struct kobj_attribute tmpfs_attr_##_name =	\
+			__INIT_KOBJ_ATTR(_name, 0200, NULL, _store)
+
+#define TMPFS_ATTR_RW(_name, _show, _store)			\
+	static struct kobj_attribute tmpfs_attr_##_name =	\
+			__INIT_KOBJ_ATTR(_name, 0644, _show, _store)
+
+#define TMPFS_ATTR_RO(_name, _show)				\
+	static struct kobj_attribute tmpfs_attr_##_name =	\
+			__INIT_KOBJ_ATTR(_name, 0444, _show, NULL)
+
+#if IS_ENABLED(CONFIG_UNICODE)
+static ssize_t casefold_show(struct kobject *kobj, struct kobj_attribute *a,
+			char *buf)
+{
+		return sysfs_emit(buf, "supported\n");
+}
+TMPFS_ATTR_RO(casefold, casefold_show);
+#endif
+
+static struct attribute *tmpfs_attributes[] = {
+#if IS_ENABLED(CONFIG_UNICODE)
+	&tmpfs_attr_casefold.attr,
+#endif
+	NULL
+};
+
+static const struct attribute_group tmpfs_attribute_group = {
+	.attrs = tmpfs_attributes,
+	.name = "features"
+};
+
+static struct kobject *tmpfs_kobj;
+
+static int __init tmpfs_sysfs_init(void)
+{
+	int ret;
+
+	tmpfs_kobj = kobject_create_and_add("tmpfs", fs_kobj);
+	if (!tmpfs_kobj)
+		return -ENOMEM;
+
+	ret = sysfs_create_group(tmpfs_kobj, &tmpfs_attribute_group);
+	if (ret)
+		kobject_put(tmpfs_kobj);
+
+	return ret;
+}
+#endif /* CONFIG_SYSFS && CONFIG_TMPFS */
+
 void __init shmem_init(void)
 {
 	int error;
@@ -5149,6 +5209,14 @@ void __init shmem_init(void)
 		goto out1;
 	}
 
+#if defined(CONFIG_SYSFS) && defined(CONFIG_TMPFS)
+	error = tmpfs_sysfs_init();
+	if (error) {
+		pr_err("Could not init tmpfs sysfs\n");
+		goto out1;
+	}
+#endif
+
 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
 	if (has_transparent_hugepage() && shmem_huge > SHMEM_HUGE_DENY)
 		SHMEM_SB(shm_mnt->mnt_sb)->huge = shmem_huge;
@@ -5546,65 +5614,3 @@ struct page *shmem_read_mapping_page_gfp(struct address_space *mapping,
 	return page;
 }
 EXPORT_SYMBOL_GPL(shmem_read_mapping_page_gfp);
-
-#if defined(CONFIG_SYSFS) && defined(CONFIG_TMPFS)
-
-#define __INIT_KOBJ_ATTR(_name, _mode, _show, _store)			\
-{									\
-	.attr	= { .name = __stringify(_name), .mode = _mode },	\
-	.show	= _show,						\
-	.store	= _store,						\
-}
-
-#define TMPFS_ATTR_W(_name, _store)				\
-	static struct kobj_attribute tmpfs_attr_##_name =	\
-			__INIT_KOBJ_ATTR(_name, 0200, NULL, _store)
-
-#define TMPFS_ATTR_RW(_name, _show, _store)			\
-	static struct kobj_attribute tmpfs_attr_##_name =	\
-			__INIT_KOBJ_ATTR(_name, 0644, _show, _store)
-
-#define TMPFS_ATTR_RO(_name, _show)				\
-	static struct kobj_attribute tmpfs_attr_##_name =	\
-			__INIT_KOBJ_ATTR(_name, 0444, _show, NULL)
-
-#if IS_ENABLED(CONFIG_UNICODE)
-static ssize_t casefold_show(struct kobject *kobj, struct kobj_attribute *a,
-			char *buf)
-{
-		return sysfs_emit(buf, "supported\n");
-}
-TMPFS_ATTR_RO(casefold, casefold_show);
-#endif
-
-static struct attribute *tmpfs_attributes[] = {
-#if IS_ENABLED(CONFIG_UNICODE)
-	&tmpfs_attr_casefold.attr,
-#endif
-	NULL
-};
-
-static const struct attribute_group tmpfs_attribute_group = {
-	.attrs = tmpfs_attributes,
-	.name = "features"
-};
-
-static struct kobject *tmpfs_kobj;
-
-static int __init tmpfs_sysfs_init(void)
-{
-	int ret;
-
-	tmpfs_kobj = kobject_create_and_add("tmpfs", fs_kobj);
-	if (!tmpfs_kobj)
-		return -ENOMEM;
-
-	ret = sysfs_create_group(tmpfs_kobj, &tmpfs_attribute_group);
-	if (ret)
-		kobject_put(tmpfs_kobj);
-
-	return ret;
-}
-
-fs_initcall(tmpfs_sysfs_init);
-#endif /* CONFIG_SYSFS && CONFIG_TMPFS */
-- 
2.47.0



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 0/3] tmpfs: Casefold fixes
  2024-11-01 16:42 [PATCH v2 0/3] tmpfs: Casefold fixes André Almeida
                   ` (2 preceding siblings ...)
  2024-11-01 16:42 ` [PATCH v2 3/3] tmpfs: Initialize sysfs during tmpfs init André Almeida
@ 2024-11-06 10:23 ` Christian Brauner
  3 siblings, 0 replies; 5+ messages in thread
From: Christian Brauner @ 2024-11-06 10:23 UTC (permalink / raw)
  To: André Almeida
  Cc: Christian Brauner, linux-mm, linux-kernel, linux-fsdevel,
	kernel-dev, Theodore Ts'o, Hugh Dickins, Andrew Morton,
	Alexander Viro, Jan Kara, krisman, Stephen Rothwell,
	Nathan Chancellor

On Fri, 01 Nov 2024 13:42:48 -0300, André Almeida wrote:
> After casefold support for tmpfs was merged into vfs tree, two warnings
> were reported and I also found a small fix in the code.
> 
> Thanks Nathan Chancellor and Stephen Rothwell!
> 
> Changelog:
> - Fixed ifdef guard for tmpfs_sysfs_init()
> v1: https://lore.kernel.org/lkml/20241101013741.295792-1-andrealmeid@igalia.com/
> 
> [...]

Applied to the vfs.tmpfs branch of the vfs/vfs.git tree.
Patches in the vfs.tmpfs branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.tmpfs

[1/3] libfs: Fix kernel-doc warning in generic_ci_validate_strict_name
      https://git.kernel.org/vfs/vfs/c/33b091c08ed8
[2/3] tmpfs: Fix type for sysfs' casefold attribute
      https://git.kernel.org/vfs/vfs/c/18d2f10f6284
[3/3] tmpfs: Initialize sysfs during tmpfs init
      https://git.kernel.org/vfs/vfs/c/65c481f30896


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-11-06 10:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-01 16:42 [PATCH v2 0/3] tmpfs: Casefold fixes André Almeida
2024-11-01 16:42 ` [PATCH v2 1/3] libfs: Fix kernel-doc warning in generic_ci_validate_strict_name André Almeida
2024-11-01 16:42 ` [PATCH v2 2/3] tmpfs: Fix type for sysfs' casefold attribute André Almeida
2024-11-01 16:42 ` [PATCH v2 3/3] tmpfs: Initialize sysfs during tmpfs init André Almeida
2024-11-06 10:23 ` [PATCH v2 0/3] tmpfs: Casefold fixes Christian Brauner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox