proc: allow to mark /proc files permanent outside of fs/proc/
Subsystems (2)
PATCH 1/1 proc: allow to mark /proc files permanent outside of fs/proc/
From 06e2ff406942fef65b9c397a7f44478dd4b61451 Mon Sep 17 00:00:00 2001
From: Alexey Dobriyan <[email protected]>
Date: Sat, 5 Apr 2025 14:50:10 +0300
Subject: [PATCH 1/1] proc: allow to mark /proc files permanent outside of
fs/proc/
From: Mateusz Guzik <[email protected]>
Add proc_make_permanent() function to mark PDE as permanent to speed up open/read/close (one alloc/free and lock/unlock less).
Enable it for built-in code and for compiled-in modules. This function becomes nop magically in modular code.
Use it on /proc/filesystems to add a user.
Note, note, note!
If built-in code creates and deletes PDEs dynamically (not in init hook), then proc_make_permanent() must not be used.
It is intended for simple code:
static int __init xxx_module_init(void)
{
g_pde = proc_create_single();
proc_make_permanent(g_pde);
return 0;
}
static void __exit xxx_module_exit(void)
{
remove_proc_entry(g_pde);
}If module is built-in then exit hook never executed and PDE is permanent so it is OK to mark it as such.
If module is module then rmmod will yank PDE, but proc_make_permanent() is nop and core /proc code will do everything right.
[[email protected]: unexport function (usual exporting is a bug)] [[email protected]: rewrite changelog]
--- fs/filesystems.c | 4 +++- fs/proc/generic.c | 12 ++++++++++++ fs/proc/internal.h | 3 +++ include/linux/proc_fs.h | 10 ++++++++++ 4 files changed, 28 insertions(+), 1 deletion(-)
fs/filesystems.c +3 -1
@@ -252,7 +252,9 @@ static int filesystems_proc_show(struct seq_file *m, void *v)static int __init proc_filesystems_init (void ) { -proc_create_single ("filesystems" ,0 ,NULL , filesystems_proc_show); +struct proc_dir_entry *pde = +proc_create_single ("filesystems" ,0 ,NULL , filesystems_proc_show); +proc_make_permanent (pde);return 0 ; }module_init (proc_filesystems_init);
fs/proc/generic.c +12 -0
@@ -826,3 +826,15 @@ ssize_t proc_simple_write(struct file *f, const char __user *ubuf, size_t size,kfree (buf);return ret ==0 ? size : ret; } + +/* +* Not exported to modules: +* modules' /proc files aren't permanent because modules aren't permanent. +*/ +void impl_proc_make_permanent (struct proc_dir_entry *pde); +void impl_proc_make_permanent (struct proc_dir_entry *pde) +{ +if (pde) { +pde_make_permanent (pde); + } +}
fs/proc/internal.h +3 -0
@@ -80,8 +80,11 @@ static inline bool pde_is_permanent(const struct proc_dir_entry *pde)return pde->flags &PROC_ENTRY_PERMANENT ; } +/* This is for builtin code, not even for modules which are compiled in. */ static inline void pde_make_permanent (struct proc_dir_entry *pde) { +/* Ensure magic flag does something. */ +static_assert (PROC_ENTRY_PERMANENT !=0 ); pde->flags |=PROC_ENTRY_PERMANENT ; }
include/linux/proc_fs.h +10 -0
@@ -247,4 +247,14 @@ static inline struct pid_namespace *proc_pid_ns(struct super_block *sb)bool proc_ns_file (const struct file *file); +static inline void proc_make_permanent (struct proc_dir_entry *pde) +{ +/* Don't give matches to modules. */ +#if definedCONFIG_PROC_FS && !definedMODULE +/* This mess is created by defining "struct proc_dir_entry" elsewhere. */ +void impl_proc_make_permanent (struct proc_dir_entry *pde); +impl_proc_make_permanent (pde); +#endif +} +#endif /* _LINUX_PROC_FS_H */
Signature · 1 line
2.47.0
Quoted 113 lines · Alexey Dobriyan
From
06e2ff406942fef65b9c397a7f44478dd4b61451Mon Sep 17 00:00:00 2001
From: Alexey Dobriyan <[email protected]>
Date: Sat, 5 Apr 2025 14:50:10 +0300
Subject: [PATCH 1/1] proc: allow to mark /proc files permanent outside of
fs/proc/From: Mateusz Guzik <[email protected]>
Add
proc_make_permanent()function to mark PDE as permanent to speed up open/read/close (one alloc/free and lock/unlock less).Enable it for built-in code and for compiled-in modules. This function becomes nop magically in modular code.
Use it on
/proc/filesystemsto add a user.Note, note, note!
If built-in code creates and deletes PDEs dynamically (not in init hook), then
proc_make_permanent()must not be used.It is intended for simple code:
static int __init xxx_module_init(void) { g_pde = proc_create_single(); proc_make_permanent(g_pde); return 0; } static void __exit xxx_module_exit(void) { remove_proc_entry(g_pde); }If module is built-in then exit hook never executed and PDE is permanent so it is OK to mark it as such.
If module is module then rmmod will yank PDE, but
proc_make_permanent()is nop and core /proc code will do everything right.[[email protected]: unexport function (usual exporting is a bug)] [[email protected]: rewrite changelog]
Signed-off-by Mateusz Guzik <[email protected]>Signed-off-by Alexey Dobriyan <[email protected]>--- fs/filesystems.c | 4 +++- fs/proc/generic.c | 12 ++++++++++++ fs/proc/internal.h | 3 +++ include/linux/proc_fs.h | 10 ++++++++++ 4 files changed, 28 insertions(+), 1 deletion(-)fs/filesystems.c +3
-1@@ -252,7 +252,9 @@ static int filesystems_proc_show(struct seq_file *m, void *v)static int __init proc_filesystems_init (void ) { -proc_create_single ("filesystems" ,0 ,NULL , filesystems_proc_show); +struct proc_dir_entry *pde = +proc_create_single ("filesystems" ,0 ,NULL , filesystems_proc_show); +proc_make_permanent (pde);return 0 ; }module_init (proc_filesystems_init);fs/proc/generic.c +12
-0@@ -826,3 +826,15 @@ ssize_t proc_simple_write(struct file *f, const char __user *ubuf, size_t size,kfree (buf);return ret ==0 ? size : ret; } + +/* +* Not exported to modules: +* modules' /proc files aren't permanent because modules aren't permanent. +*/ +void impl_proc_make_permanent (struct proc_dir_entry *pde); +void impl_proc_make_permanent (struct proc_dir_entry *pde) +{ +if (pde) { +pde_make_permanent (pde); + } +}fs/proc/internal.h +3
-0@@ -80,8 +80,11 @@ static inline bool pde_is_permanent(const struct proc_dir_entry *pde)return pde->flags &PROC_ENTRY_PERMANENT ; } +/* This is for builtin code, not even for modules which are compiled in. */ static inline void pde_make_permanent (struct proc_dir_entry *pde) { +/* Ensure magic flag does something. */ +static_assert (PROC_ENTRY_PERMANENT !=0 ); pde->flags |=PROC_ENTRY_PERMANENT ; }include/linux/proc_fs.h +1
-0@@ -247,4 +247,14 @@ static inline struct pid_namespace *proc_pid_ns(struct super_block *sb)bool proc_ns_file (const struct file *file); +static inline void proc_make_permanent (struct proc_dir_entry *pde)
include/linux/proc_fs.h static inline struct pid_namespace *proc_pid_ns(struct super_block *sb) · line 260
Quoted 10 lines
include/linux/proc_fs.h +9
-0+{ +/* Don't give matches to modules. */ +#if definedCONFIG_PROC_FS && !definedMODULE +/* This mess is created by defining "struct proc_dir_entry" elsewhere. */ +void impl_proc_make_permanent (struct proc_dir_entry *pde); +impl_proc_make_permanent (pde); +#endif +} +#endif /* _LINUX_PROC_FS_H */
This diff should not be changing /proc/filesystems, that's for the other patch to do.
So I think this patch is all you and my name needs to be dropped from it, along with marking /proc/filesystems as permanent.
Given that you kept the name (proc_make_permanent), the fs/filesystems.c side of things is identical so my first patch can be just swapped for this one.
Alternatively I can resend the patchset with this (augmented as described above).
Signature · 1 line
Mateusz Guzik <mjguzik gmail.com>
Quoted 10 lines · On Wed, 9 Apr 2025 22:20:13 +0300 Alexey Dobriyan <[email protected]> wrote:
Quoted 1 line
From
06e2ff406942fef65b9c397a7f44478dd4b61451Mon Sep 17 00:00:00 2001From: Alexey Dobriyan <[email protected]>
Date: Sat, 5 Apr 2025 14:50:10 +0300
Subject: [PATCH 1/1] proc: allow to mark /proc files permanent outside of
fs/proc/From: Mateusz Guzik <[email protected]>
Add
proc_make_permanent()function to mark PDE as permanent to speed up open/read/close (one alloc/free and lock/unlock less).
When proposing a speedup it is preferable to provide some benchmarking results to help others understand the magnitude of that speedup.
fs/filesystems.c static int filesystems_proc_show(struct seq_file *m, void *v) · line 256
Quoted 12 lines
...
index
58b9067b2391..81dcd0ddadb6100644fs/filesystems.c +2
-1@@ -252,7 +252,9 @@ static int filesystems_proc_show(struct seq_file *m, void *v)static int __init proc_filesystems_init (void ) { -proc_create_single ("filesystems" ,0 ,NULL , filesystems_proc_show); +struct proc_dir_entry *pde = +proc_create_single ("filesystems" ,0 ,NULL , filesystems_proc_show);
To avoid the 80-column nasties, this is more pleasing:
struct proc_dir_entry *pde;
pde = proc_create_single("filesystems", 0, NULL, filesystems_proc_show);Quoted 9 lines
fs/filesystems.c +1
-0+proc_make_permanent (pde);return 0 ; }module_init (proc_filesystems_init);fs/proc/generic.c +0
-0
fs/proc/generic.c ssize_t proc_simple_write(struct file *f, const char __user *ubuf, size_t size, · line 834
Quoted 9 lines
fs/proc/generic.c +6
-0@@ -826,3 +826,15 @@ ssize_t proc_simple_write(struct file *f, const char __user *ubuf, size_t size,kfree (buf);return ret ==0 ? size : ret; } + +/* +* Not exported to modules: +* modules' /proc files aren't permanent because modules aren't permanent. +*/ +void impl_proc_make_permanent (struct proc_dir_entry *pde);
This declaration is unneeded, isn't it?
fs/proc/generic.c ssize_t proc_simple_write(struct file *f, const char __user *ubuf, size_t size, · line 839
Quoted 5 lines
fs/proc/generic.c +5
-0+void impl_proc_make_permanent (struct proc_dir_entry *pde) +{ +if (pde) { +pde_make_permanent (pde); + }
Please let's be running checkpatch more often?
Quoted 6 lines
fs/proc/generic.c +1
-0+}fs/proc/internal.h +0
-0
fs/proc/internal.h static inline bool pde_is_permanent(const struct proc_dir_entry *pde) · line 87
Quoted 8 lines
fs/proc/internal.h +3
-0@@ -80,8 +80,11 @@ static inline bool pde_is_permanent(const struct proc_dir_entry *pde)return pde->flags &PROC_ENTRY_PERMANENT ; } +/* This is for builtin code, not even for modules which are compiled in. */ static inline void pde_make_permanent (struct proc_dir_entry *pde) { +/* Ensure magic flag does something. */ +static_assert (PROC_ENTRY_PERMANENT !=0 );
Looks odd. What is this doing? The comment does a poor job of explaining this!
Quoted 8 lines
fs/proc/internal.h +0
-0pde->flags |=PROC_ENTRY_PERMANENT ; }include/linux/proc_fs.h +0
-0
include/linux/proc_fs.h static inline struct pid_namespace *proc_pid_ns(struct super_block *sb) · line 252
Quoted 6 lines
include/linux/proc_fs.h +3
-0@@ -247,4 +247,14 @@ static inline struct pid_namespace *proc_pid_ns(struct super_block *sb)bool proc_ns_file (const struct file *file); +static inline void proc_make_permanent (struct proc_dir_entry *pde) +{ +/* Don't give matches to modules. */
This comment is also mysterious (to me). Please expand upon it.
include/linux/proc_fs.h static inline struct pid_namespace *proc_pid_ns(struct super_block *sb) · line 254
Quoted 2 lines
include/linux/proc_fs.h +2
-0+#if definedCONFIG_PROC_FS && !definedMODULE +/* This mess is created by defining "struct proc_dir_entry" elsewhere. */
Also mysterious.
include/linux/proc_fs.h static inline struct pid_namespace *proc_pid_ns(struct super_block *sb) · line 255
Quoted 1 line
include/linux/proc_fs.h +1
-0+void impl_proc_make_permanent (struct proc_dir_entry *pde);
Forward-declaring a function within a function in this manner is quite unusual. Let's be conventional, please.
Quoted 7 lines
include/linux/proc_fs.h +4
-0+impl_proc_make_permanent (pde); +#endif +} +#endif /* _LINUX_PROC_FS_H */ Signature · 1 line
2.47.0
Quoted 9 lines · Andrew Morton
Quoted 6 lines · On Wed, 9 Apr 2025 22:20:13 +0300 Alexey Dobriyan <[email protected]> wrote:
Quoted 1 line
From
06e2ff406942fef65b9c397a7f44478dd4b61451Mon Sep 17 00:00:00 2001From: Alexey Dobriyan <[email protected]>
Date: Sat, 5 Apr 2025 14:50:10 +0300
Subject: [PATCH 1/1] proc: allow to mark /proc files permanent outside of
fs/proc/
Quoted 8 lines
Quoted 4 lines
From: Mateusz Guzik <[email protected]>
Add
proc_make_permanent()function to mark PDE as permanent to speed up open/read/close (one alloc/free and lock/unlock less).When proposing a speedup it is preferable to provide some benchmarking results to help others understand the magnitude of that speedup.
It's all in the original submission:
https://lore.kernel.org/linux-fsdevel/[email protected]/
Signature · 1 line
Mateusz Guzik <mjguzik gmail.com>
Quoted 23 lines · Andrew Morton
Quoted 10 lines · On Wed, 9 Apr 2025 22:20:13 +0300 Alexey Dobriyan <[email protected]> wrote:
Quoted 1 line
From
06e2ff406942fef65b9c397a7f44478dd4b61451Mon Sep 17 00:00:00 2001From: Alexey Dobriyan <[email protected]>
Date: Sat, 5 Apr 2025 14:50:10 +0300
Subject: [PATCH 1/1] proc: allow to mark /proc files permanent outside of
fs/proc/From: Mateusz Guzik <[email protected]>
Add
proc_make_permanent()function to mark PDE as permanent to speed up open/read/close (one alloc/free and lock/unlock less).When proposing a speedup it is preferable to provide some benchmarking results to help others understand the magnitude of that speedup.
Quoted 7 lines
...
index
58b9067b2391..81dcd0ddadb6100644fs/filesystems.c +0
-0@@ -252,7 +252,9 @@ static int filesystems_proc_show(struct seq_file *m, void *v)
Quoted 7 lines
fs/filesystems.c static int filesystems_proc_show(struct seq_file *m, void *v) · line 256
Quoted 5 lines
fs/filesystems.c +2
-1static int __init proc_filesystems_init (void ) { -proc_create_single ("filesystems" ,0 ,NULL , filesystems_proc_show); +struct proc_dir_entry *pde = +proc_create_single ("filesystems" ,0 ,NULL , filesystems_proc_show);To avoid the 80-column nasties, this is more pleasing:
It is inferior style, see below. BTW, how the kernel is still on 80 columns?
Quoted 17 lines
struct proc_dir_entry *pde; pde = proc_create_single("filesystems", 0, NULL, filesystems_proc_show);Quoted 12 lines
fs/filesystems.c +1
-0+proc_make_permanent (pde);return 0 ; }module_init (proc_filesystems_init);fs/proc/generic.c +0
-0@@ -826,3 +826,15 @@ ssize_t proc_simple_write(struct file *f, const char __user *ubuf, size_t size,kfree (buf);return ret ==0 ? size : ret; }
Quoted 8 lines
fs/proc/generic.c ssize_t proc_simple_write(struct file *f, const char __user *ubuf, size_t size, · line 834
Quoted 6 lines
fs/proc/generic.c +6
-0+ +/* +* Not exported to modules: +* modules' /proc files aren't permanent because modules aren't permanent. +*/ +void impl_proc_make_permanent (struct proc_dir_entry *pde);This declaration is unneeded, isn't it?
It is necessary, but I need to make a comment, yes.
Quoted 7 lines
fs/proc/generic.c ssize_t proc_simple_write(struct file *f, const char __user *ubuf, size_t size, · line 839
Quoted 5 lines
fs/proc/generic.c +5
-0+void impl_proc_make_permanent (struct proc_dir_entry *pde) +{ +if (pde) { +pde_make_permanent (pde); + }Please let's be running checkpatch more often?
No! I'd rather change kernel coding style.
Quoted 37 lines
fs/proc/internal.h static inline bool pde_is_permanent(const struct proc_dir_entry *pde) · line 87
Quoted 11 lines
fs/proc/internal.h +3
-0@@ -80,8 +80,11 @@ static inline bool pde_is_permanent(const struct proc_dir_entry *pde)return pde->flags &PROC_ENTRY_PERMANENT ; } +/* This is for builtin code, not even for modules which are compiled in. */ static inline void pde_make_permanent (struct proc_dir_entry *pde) { +/* Ensure magic flag does something. */ +static_assert (PROC_ENTRY_PERMANENT !=0 );Looks odd. What is this doing? The comment does a poor job of explaining this!
Quoted 8 lines
fs/proc/internal.h +0
-0pde->flags |=PROC_ENTRY_PERMANENT ; }include/linux/proc_fs.h +0
-0include/linux/proc_fs.h static inline struct pid_namespace *proc_pid_ns(struct super_block *sb) · line 252
Quoted 6 lines
include/linux/proc_fs.h +3
-0@@ -247,4 +247,14 @@ static inline struct pid_namespace *proc_pid_ns(struct super_block *sb)bool proc_ns_file (const struct file *file); +static inline void proc_make_permanent (struct proc_dir_entry *pde) +{ +/* Don't give matches to modules. */ This comment is also mysterious (to me). Please expand upon it.
include/linux/proc_fs.h static inline struct pid_namespace *proc_pid_ns(struct super_block *sb) · line 254
Quoted 2 lines
include/linux/proc_fs.h +2
-0+#if definedCONFIG_PROC_FS && !definedMODULE +/* This mess is created by defining "struct proc_dir_entry" elsewhere. */ Also mysterious.
Quoted 8 lines
include/linux/proc_fs.h static inline struct pid_namespace *proc_pid_ns(struct super_block *sb) · line 255
Quoted 1 line
include/linux/proc_fs.h +1
-0+void impl_proc_make_permanent (struct proc_dir_entry *pde);Forward-declaring a function within a function in this manner is quite unusual. Let's be conventional, please.
include/linux/proc_fs.h static inline struct pid_namespace *proc_pid_ns(struct super_block *sb) · line 258
Quoted 3 lines
include/linux/proc_fs.h +3
-0+impl_proc_make_permanent (pde); +#endif +}
This patch tries to create semi-exported interface which does nothing if module built as module is using it it but does something it built-in or module built-in does. This is why all complications and prorotypes.
But let me change coding style first.
Hi. This fell through the cracks.
Can you please resubmit your patch with my name dropped from it? It's basically all you.
Alternatively perhaps Christian will be happy to do the edits?
After this is sorted out I'll resend my thing altering how the content of the file is generated.
Quoted 126 lines · Alexey Dobriyan
From
06e2ff406942fef65b9c397a7f44478dd4b61451Mon Sep 17 00:00:00 2001
From: Alexey Dobriyan <[email protected]>
Date: Sat, 5 Apr 2025 14:50:10 +0300
Subject: [PATCH 1/1] proc: allow to mark /proc files permanent outside of
fs/proc/From: Mateusz Guzik <[email protected]>
Add
proc_make_permanent()function to mark PDE as permanent to speed up open/read/close (one alloc/free and lock/unlock less).Enable it for built-in code and for compiled-in modules. This function becomes nop magically in modular code.
Use it on
/proc/filesystemsto add a user.Note, note, note!
If built-in code creates and deletes PDEs dynamically (not in init hook), then
proc_make_permanent()must not be used.It is intended for simple code:
static int __init xxx_module_init(void) { g_pde = proc_create_single(); proc_make_permanent(g_pde); return 0; } static void __exit xxx_module_exit(void) { remove_proc_entry(g_pde); }If module is built-in then exit hook never executed and PDE is permanent so it is OK to mark it as such.
If module is module then rmmod will yank PDE, but
proc_make_permanent()is nop and core /proc code will do everything right.[[email protected]: unexport function (usual exporting is a bug)] [[email protected]: rewrite changelog]
Signed-off-by Mateusz Guzik <[email protected]>Signed-off-by Alexey Dobriyan <[email protected]>--- fs/filesystems.c | 4 +++- fs/proc/generic.c | 12 ++++++++++++ fs/proc/internal.h | 3 +++ include/linux/proc_fs.h | 10 ++++++++++ 4 files changed, 28 insertions(+), 1 deletion(-)fs/filesystems.c +3
-1@@ -252,7 +252,9 @@ static int filesystems_proc_show(struct seq_file *m, void *v)static int __init proc_filesystems_init (void ) { -proc_create_single ("filesystems" ,0 ,NULL , filesystems_proc_show); +struct proc_dir_entry *pde = +proc_create_single ("filesystems" ,0 ,NULL , filesystems_proc_show); +proc_make_permanent (pde);return 0 ; }module_init (proc_filesystems_init);fs/proc/generic.c +12
-0@@ -826,3 +826,15 @@ ssize_t proc_simple_write(struct file *f, const char __user *ubuf, size_t size,kfree (buf);return ret ==0 ? size : ret; } + +/* +* Not exported to modules: +* modules' /proc files aren't permanent because modules aren't permanent. +*/ +void impl_proc_make_permanent (struct proc_dir_entry *pde); +void impl_proc_make_permanent (struct proc_dir_entry *pde) +{ +if (pde) { +pde_make_permanent (pde); + } +}fs/proc/internal.h +3
-0@@ -80,8 +80,11 @@ static inline bool pde_is_permanent(const struct proc_dir_entry *pde)return pde->flags &PROC_ENTRY_PERMANENT ; } +/* This is for builtin code, not even for modules which are compiled in. */ static inline void pde_make_permanent (struct proc_dir_entry *pde) { +/* Ensure magic flag does something. */ +static_assert (PROC_ENTRY_PERMANENT !=0 ); pde->flags |=PROC_ENTRY_PERMANENT ; }include/linux/proc_fs.h +10
-1@@ -247,4 +247,14 @@ static inline struct pid_namespace *proc_pid_ns(struct super_block *sb)bool proc_ns_file (const struct file *file); +static inline void proc_make_permanent (struct proc_dir_entry *pde) +{ +/* Don't give matches to modules. */ +#if definedCONFIG_PROC_FS && !definedMODULE +/* This mess is created by defining "struct proc_dir_entry" elsewhere. */ +void impl_proc_make_permanent (struct proc_dir_entry *pde); +impl_proc_make_permanent (pde); +#endif +} +#endif /* _LINUX_PROC_FS_H */ --2.47.0