pstore: add multi-backend suuport
Subsystems (3)
v4 cover pstore: add multi-backend suuport
This is the 4th version of the patch set. In this patchset we aim to add pstore multi-backend support then user can register more than one pstore backend.
Changes in v4:
- Replace all rcu_read_lock with mutex
- Move bif_oops_buf, max_compressed_size and pstore_dumper into pstore_info_list
- add a helper to do "is this name in the list" and a helper to do
"is this backend loaded"
- make comments in pstore_(un)register clearer
- return the max_seen ret or the first negative err in write_pmsg()
- add a /sys/module entry for the list of backends, comma separated
- Link to v3: https://lore.kernel.org/all/[email protected]/
Changes in v3:
- Fix ftrace.c build error
- Link to v2: https://lore.kernel.org/all/[email protected]/
Changes in v2:
- pstore.backend no longer acts as "registered backend", but
"backends eligible for registration".
- drop subdir since it will break user space
- drop tty frontend since I haven't yet devised a satisfactory
implementation strategy
- Link to v1: https://lore.kernel.org/all/[email protected]/
Yuanhe Shu (4):
pstore: add multi-backend support
pstore: add a /sys/module entry for loaded backends
Documentation: adjust pstore backend related document tools/testing: adjust pstore backend related selftest
Documentation/ABI/testing/pstore | 8 +- .../admin-guide/kernel-parameters.txt | 4 +- fs/pstore/ftrace.c | 27 +- fs/pstore/inode.c | 57 +++- fs/pstore/internal.h | 5 +- fs/pstore/platform.c | 274 ++++++++++++------ fs/pstore/pmsg.c | 27 +- include/linux/pstore.h | 23 ++ tools/testing/selftests/pstore/common_tests | 8 +- .../selftests/pstore/pstore_post_reboot_tests | 67 +++-- tools/testing/selftests/pstore/pstore_tests | 2 +- 11 files changed, 358 insertions(+), 144 deletions(-)
Signature · 1 line
2.39.3
PATCH v4 1/4 pstore: add multi-backend support
Currently, pstore supports only one backend open at a time. Specifically, due to the global variable "psinfo", pstore only accepts the first registered backend. If a new backend wants to register later, pstore will simply reject it and return an error. This design forced us to close existing backend in order to use the new ones.
To enable pstore to support multiple backends, "psinfo" is replaced by "psinfo_list", a list that holds multiple "psinfo". If multiple backends are registered with the same frontend, the frontend is reused.
User can specify multiple backends that are allowed to be registered by module parameter "pstore.backend=" separated by commas or "all" to enable all available backends. If no pstore.backend was specified, pstore would accept the first registered backend which is the same as before.
--- fs/pstore/ftrace.c | 27 +++- fs/pstore/inode.c | 19 ++- fs/pstore/internal.h | 4 +- fs/pstore/platform.c | 279 +++++++++++++++++++++++++++-------------- fs/pstore/pmsg.c | 27 +++- include/linux/pstore.h | 23 ++++ 6 files changed, 271 insertions(+), 108 deletions(-)
fs/pstore/ftrace.c +23 -4
@@ -23,10 +23,11 @@/* This doesn't need to be atomic: speed is chosen over correctness here. */ static u64 pstore_ftrace_stamp; -static void notrace pstore_ftrace_call(unsigned long ip, +static void notrace pstore_do_ftrace(unsigned long ip,unsigned long parent_ip,struct ftrace_ops *op, -struct ftrace_regs *fregs) +struct ftrace_regs *fregs, +struct pstore_info *psinfo) {int bit;unsigned long flags;
@@ -57,6 +58,20 @@ static void notrace pstore_ftrace_call(unsigned long ip,ftrace_test_recursion_unlock (bit); } +static void notrace pstore_ftrace_call(unsigned long ip, +unsigned long parent_ip, +struct ftrace_ops *op, +struct ftrace_regs *fregs) +{ +struct pstore_info_list *entry; + +mutex_lock (&psback_lock); +list_for_each_entry (entry, &psback->list_entry, list) +if (entry->psi->flags &PSTORE_FLAGS_FTRACE ) +pstore_do_ftrace (ip, parent_ip, op, fregs, entry->psi); +mutex_unlock (&psback_lock); +} +static struct ftrace_ops pstore_ftrace_ops__read_mostly = { .func = pstore_ftrace_call, };
@@ -131,8 +146,12 @@ MODULE_PARM_DESC(record_ftrace,void pstore_register_ftrace (void ) { -if (!psinfo->write) -return ; +struct pstore_info_list *entry; + +list_for_each_entry (entry, &psback->list_entry, list) +if (entry->psi->flags &PSTORE_FLAGS_FTRACE ) +if (!entry->psi->write) +return ; pstore_ftrace_dir =debugfs_create_dir ("pstore" ,NULL );
fs/pstore/inode.c +13 -6
@@ -285,7 +285,7 @@ static const struct super_operations pstore_ops = { .show_options = pstore_show_options, }; -static struct dentry *psinfo_lock_root (void ) +static struct dentry *psinfo_lock_root (struct pstore_info *psinfo) {struct dentry *root;
@@ -309,7 +309,7 @@ int pstore_put_backend_records(struct pstore_info *psi)struct dentry *root;int rc =0 ; - root =psinfo_lock_root (); + root =psinfo_lock_root (psi);if (!root)return 0 ;
@@ -398,21 +398,22 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record)* when we are re-scanning the backing store looking to add new * error records. */ -void pstore_get_records (int quiet) +void pstore_get_records (struct pstore_info *psi,int quiet) {struct dentry *root; - root =psinfo_lock_root (); + root =psinfo_lock_root (psi);if (!root)return ; -pstore_get_backend_records (psinfo, root, quiet); +pstore_get_backend_records (psi, root, quiet);inode_unlock (d_inode (root)); }static int pstore_fill_super (struct super_block *sb,void *data,int silent) {struct inode *inode; +struct pstore_info_list *entry; sb->s_maxbytes =MAX_LFS_FILESIZE ; sb->s_blocksize =PAGE_SIZE ;
@@ -437,7 +438,13 @@ static int pstore_fill_super(struct super_block *sb, void *data, int silent)scoped_guard (mutex, &pstore_sb_lock) pstore_sb = sb; -pstore_get_records (0 ); +if (!psback) +return 0 ; + +mutex_lock (&psback_lock); +list_for_each_entry (entry, &psback->list_entry, list) +pstore_get_records (entry->psi,0 ); +mutex_unlock (&psback_lock);return 0 ; }
fs/pstore/internal.h +2 -2
@@ -33,10 +33,10 @@ static inline void pstore_register_pmsg(void) {}static inline void pstore_unregister_pmsg (void ) {}#endif -extern struct pstore_info *psinfo; +extern struct pstore_backends *psback;extern void pstore_set_kmsg_bytes (int ); -extern void pstore_get_records (int ); +extern void pstore_get_records (struct pstore_info *psi,int quiet);extern void pstore_get_backend_records (struct pstore_info *psi,struct dentry *root,int quiet);extern int pstore_put_backend_records (struct pstore_info *psi);
fs/pstore/platform.c +185 -94
503 lines not on this page · raw message
fs/pstore/pmsg.c +25 -2
@@ -11,8 +11,9 @@static DEFINE_MUTEX (pmsg_lock); -static ssize_t write_pmsg (struct file *file,const char __user *buf, -size_t count,loff_t *ppos) +static ssize_t do_write_pmsg (struct file *file,const char __user *buf, +size_t count,loff_t *ppos, +struct pstore_info *psinfo) {struct pstore_record record;int ret;
@@ -34,6 +35,28 @@ static ssize_t write_pmsg(struct file *file, const char __user *buf,return ret ? ret : count; } +static ssize_t write_pmsg (struct file *file,const char __user *buf, +size_t count,loff_t *ppos) +{ +int ret, written =0 , err =0 ; +struct pstore_info_list *entry; + +mutex_lock (&psback_lock); +list_for_each_entry (entry, &psback->list_entry, list) { +if (entry->psi->flags &PSTORE_FLAGS_PMSG ) { + ret =do_write_pmsg (file, buf, count, + ppos, entry->psi); +/* Return the first negative value or max_seen ret */ +if (!err && ret <0 ) + err = ret; + written = ret > written ? ret : written; + } + } +mutex_unlock (&psback_lock); + +return err ? err : written; +} +static const struct file_operations pmsg_fops = { .owner =THIS_MODULE , .llseek = noop_llseek,
include/linux/pstore.h +23 -0
@@ -201,6 +201,29 @@ struct pstore_info {int (*erase)(struct pstore_record *record); }; +/* Supported multibackends */ +extern struct mutex psback_lock; + +struct pstore_info_list { +struct pstore_info *psi; +char *big_oops_buf; +size_t max_compressed_size; +struct kmsg_dumper pstore_dumper; +struct list_head list; +}; + +/** +* struct pstore_backends - management of pstore backends +* @front_cnt: count of each enabled frontend +* @list_entry: entry of pstore backend driver information list +* +*/ + +struct pstore_backends { +int front_cnt[PSTORE_TYPE_MAX ]; +struct list_head list_entry; +}; +/* Supported frontends */ #define PSTORE_FLAGS_DMESG BIT(0)#define PSTORE_FLAGS_CONSOLE BIT(1)
Signature · 1 line
2.39.3
PATCH v4 2/4 pstore: add a /sys/module entry for loaded backends
In reply to Yuanhe ShuIntroduce a /sys/module entry for loaded pstore backends which provide users and testcases with a standarized interface to retrieve information on which pstore backends are currently registered.
--- fs/pstore/inode.c | 38 ++++++++++++++++++++++++++++++++++++++ fs/pstore/internal.h | 1 + fs/pstore/platform.c | 9 ++++++++- 3 files changed, 47 insertions(+), 1 deletion(-)
fs/pstore/inode.c +38 -0
@@ -6,6 +6,7 @@*/ #include <linux/module.h> +#include <linux/kobject.h> #include <linux/fs.h> #include <linux/fsnotify.h> #include <linux/pagemap.h>
@@ -491,6 +492,43 @@ int __init pstore_init_fs(void)return err; } +static ssize_t loaded_backend_show (struct kobject *k, +struct kobj_attribute *attr,char *buf) +{ +struct pstore_info_list *entry; +char *old, *loaded_backend =NULL ; + +mutex_lock (&psback_lock); +list_for_each_entry (entry, &psback->list_entry, list) +if (!loaded_backend) + loaded_backend =kstrdup (entry->psi->name,GFP_KERNEL ); +else { + old = loaded_backend; + loaded_backend =kasprintf (GFP_KERNEL ,"%s,%s" , + old, entry->psi->name); +kfree (old); + } +mutex_unlock (&psback_lock); + +return sprintf (buf,"%s\n" , loaded_backend); +} + +static struct kobj_attribute backend_attribute = +__ATTR (loaded_backend,0444 , loaded_backend_show,NULL ); + +int __init pstore_init_entry (void ) +{ +int err =0 ; +struct kobject *pstore_kobj; + + pstore_kobj =kset_find_obj (module_kset,"pstore" ); +if (pstore_kobj) { + err =sysfs_create_file (pstore_kobj, &backend_attribute.attr); +kobject_put (pstore_kobj); + } +return err; +} + void __exit pstore_exit_fs(void) {unregister_filesystem (&pstore_fs_type);
fs/pstore/internal.h +1 -0
@@ -47,6 +47,7 @@ extern void pstore_record_init(struct pstore_record *record,/* Called during pstore init/exit. */ int __init pstore_init_fs (void ); +int __init pstore_init_entry (void ); void __exit pstore_exit_fs(void);#endif
fs/pstore/platform.c +8 -1
@@ -841,7 +841,14 @@ static void pstore_timefunc(struct timer_list *unused)static int __init pstore_init (void ) { -return pstore_init_fs (); +int ret; + + ret =pstore_init_fs (); +if (ret) +return ret; + + ret =pstore_init_entry (); +return ret; }late_initcall (pstore_init);
Signature · 1 line
2.39.3
PATCH v4 3/4 Documentation: adjust pstore backend related document
In reply to Yuanhe ShuPstore now supports multiple backends, adjust related document.
--- Documentation/ABI/testing/pstore | 8 ++++---- Documentation/admin-guide/kernel-parameters.txt | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-)
Documentation/ABI/testing/pstore +4 -4
@@ -41,7 +41,7 @@ Description: Generic interface to platform dependent persistent storage. persistent storage until at least this amount is reached. Default is 10 Kbytes. - Pstore only supports one backend at a time. If multiple - backends are available, the preferred backend may be - set by passing the pstore.backend= argument to the kernel at - boot time. + Pstore supports multiple backends at a time. If multiple + backends are available, the registrable backends may be + set by passing the pstore.backend=argument1,argument2... + or pstore.backend= all to the kernel at boot time.
Documentation/admin-guide/kernel-parameters.txt +3 -1
@@ -4748,7 +4748,9 @@ [HW,MOUSE] Controls Logitech smartscroll autorepeat. 0 = disabled, 1 = enabled (default). - pstore.backend= Specify the name of the pstore backend to use + pstore.backend=backend1,...,backendN + Specify the names of the pstore backends to use + or =all for all available backends pti= [X86-64] Control Page Table Isolation of user and kernel address spaces. Disabling this feature
Signature · 1 line
2.39.3
PATCH v4 4/4 tools/testing: adjust pstore backend related selftest
In reply to Yuanhe ShuPstore now supports multiple backends, the module parameter pstore.backend varies from 'registered backend' to 'backends that are allowed to register' and a new entry /sys/module/pstore/loaded_backend is added to show which pstore backends are loaded at present. Adjust selftests to match the change.
--- tools/testing/selftests/pstore/common_tests | 8 +-- .../selftests/pstore/pstore_post_reboot_tests | 67 ++++++++++--------- tools/testing/selftests/pstore/pstore_tests | 2 +- 3 files changed, 40 insertions(+), 37 deletions(-)
tools/testing/selftests/pstore/common_tests +4 -4
@@ -27,9 +27,9 @@ show_result() { # result_value } check_files_exist() { # type of pstorefs file - if [ -e ${1}-${backend}-0 ]; then + if [ -e ${1}-${2}-0 ]; then prlog "ok" - for f in `ls ${1}-${backend}-*`; do + for f in `ls ${1}-${2}-*`; do prlog -e "\t${f}" done else
@@ -74,9 +74,9 @@ prlog "=== Pstore unit tests (`basename $0`) ===" prlog "UUID="$UUID prlog -n "Checking pstore backend is registered ... " -backend=`cat /sys/module/pstore/parameters/backend` +backends=`cat /sys/module/pstore/loaded_backend` show_result $? -prlog -e "\tbackend=${backend}" +prlog -e "\tbackends=${backends}" prlog -e "\tcmdline=`cat /proc/cmdline`" if [ $rc -ne 0 ]; then exit 1
tools/testing/selftests/pstore/pstore_post_reboot_tests +35 -32
81 lines not on this page · raw message
tools/testing/selftests/pstore/pstore_tests +1 -1
@@ -10,7 +10,7 @@ . ./common_tests prlog -n "Checking pstore console is registered ... " -dmesg | grep -Eq "console \[(pstore|${backend})" +dmesg | grep -Eq "console \[(pstore console)" show_result $? prlog -n "Checking /dev/pmsg0 exists ... "
Signature · 1 line
2.39.3