pstore: directly mapped regions
Subsystems (7)
cover pstore: directly mapped regions
Hello,
This series comes as an RFC proposed solution to enhance pstore and devcoredump with the following functionality:
It is interesting to mark specific memory regions in the kernel as core areas, such that in the even of a cataclysmic event like panic, deadlock, hardware fault, those areas can be retrieved by an external agent, that can be JTAG, firmware, additional debug processor, etc.
Even though pstore panic handlers attempt to copy data into the persistent storage, this is not always working, because the kernel could be in a deadlock, have irqs disabled, panic handler could crash itself, or even some memory areas could be corrupted badly enough that the recovery mechanism doesn't work.
This patch series attempts to solve this by reusing existing infrastructure in pstore and devcoredump, and provide a copy-free possibility to have core kernel data exposed for creating debug information like a coredump or list of binary elements with data.
How this works:
Drivers and key kernel infrastructure, like for example the dmesg buffer (ftrace buffer is still work in progress and not in the series), would register themselves into pstore, with a simple function call taking a name, a pointer to the area and size.
That would be all, and the patch labeled "EXAMPLE" shows a driver doing exactly that, registering it's own dev struct with string markers that can help identifying the data later once it's being retrieved. Further, pstore and pstore/zone would keep track of all registered areas inside the intermediary back-end. There would not be any copy of the data.
Pstore would require a new type of back-end, named directly mapped (because there is no copy, and each zone directly maps the incoming buffer). If this back-end is available, then pstore further calls the back-end to register the area.
The back-end itself is then free to do whatever it wishes with the received area. It can (possibly) do a copy to store data, it can have a timer to check the area every x time periods, or store the pointers inside a table of contents (which is what the qcom smem is doing).
The qcom smem driver registers itself into pstore as a new type of back-end called shared memory. It's very similar with the pstore/blk but much simplified, to cope with just a shared memory storage. The areas metadata are stored in a shared memory that is being managed by the qcom_smem driver. It's called shared memory because it's being shared between the main processor running the kernel and additional secondary remote processors running firmware.
In this qcom smem backend case, the firmware runs when there is a panic event, of watchdog timeout, and uses the table of contents to retrieve useful kernel debug data.
The advantages of this proposed idea are: no kernel panic handler intervention. Everything is being marked and prepared ahead of time, before there is an actual crash. There is no overhead associated, simply the areas are being marked and metadata created, no buffers associated, no memory areas reserved for it. Memory areas being marked, there is no possibility of getting older useless data, that was copied before the actual events leading to a crash would occur, so the data would be the real actual data the kernel was working on.
Of course, this would not work if there is no external agent to parse the areas and get the useful data. However as the hardware becomes more and more advanced, in the cases where this is available, kernel debugging had no way of using this advantage. As the hardware evolves, so is the kernel.
There is another aspect to underline: the directly mapped zones change the semantics of pstore using them. Pstore relies on user being able to read the data from a previous kernel run once the system has rebooted. This is not valid with the directly mapped zones unless the JTAG/firmware would copy this data into a persistent area and make it available upon reboot (which is not impossible).
I would like to thank everyone reviewing and chiping in on the series.
The back-end implementation for qcom_smem is based on the minidump patch series and driver written by Mukesh Ojha, thanks:
https://lore.kernel.org/lkml/[email protected]/
Eugen
Eugen Hristev (10):
pstore/zone: move pstore_device_info into zone header pstore/smem: add new pstore/smem type of pstore pstore/zone: introduce directly mapped zones
qcom: smem: add pstore smem backend
pstore: implement core area registration
qcom: smem: enable smem pstore backend
printk: export symbols for buffer address and length functions
pstore: register kmsg into directly mapped zones if available
devcoredump: add devcd_{un}register_core_area API
rng: qcom_rng: EXAMPLE: registering dev structure
drivers/base/devcoredump.c | 13 ++ drivers/crypto/qcom-rng.c | 11 ++ drivers/soc/qcom/Kconfig | 9 + drivers/soc/qcom/Makefile | 6 +- drivers/soc/qcom/smem.c | 10 ++ drivers/soc/qcom/smem_md.c | 306 +++++++++++++++++++++++++++++++++ drivers/soc/qcom/smem_pstore.c | 112 ++++++++++++ fs/pstore/Kconfig | 13 ++ fs/pstore/Makefile | 3 + fs/pstore/platform.c | 84 +++++++++ fs/pstore/smem.c | 115 +++++++++++++ fs/pstore/zone.c | 122 +++++++++++-- include/linux/devcoredump.h | 3 + include/linux/pstore.h | 20 +++ include/linux/pstore_blk.h | 14 -- include/linux/pstore_smem.h | 9 + include/linux/pstore_zone.h | 17 ++ include/linux/soc/qcom/smem.h | 43 +++++ kernel/printk/printk.c | 2 + 19 files changed, 885 insertions(+), 27 deletions(-) create mode 100644 drivers/soc/qcom/smem_md.c create mode 100644 drivers/soc/qcom/smem_pstore.c create mode 100644 fs/pstore/smem.c create mode 100644 include/linux/pstore_smem.h
Signature · 1 line
2.43.0
RFC PATCH 1/10 pstore/zone: move pstore_device_info into zone header
Struct pstore_device_info is used in pstore/zone, and it's not really connected to anything related to pstore/blk. To further improve on the pstore zone and allow other types of drivers to connect, it is logical to have this struct into pstore_zone.h file.
--- include/linux/pstore_blk.h | 14 -------------- include/linux/pstore_zone.h | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 14 deletions(-)
include/linux/pstore_blk.h +0 -14
@@ -7,20 +7,6 @@#include <linux/pstore.h> #include <linux/pstore_zone.h> -/** -* struct pstore_device_info - back-end pstore/blk driver structure. -* -* @flags: Refer to macro starting with PSTORE_FLAGS defined in -* linux/pstore.h. It means what front-ends this device support. -* Zero means all backends for compatible. -* @zone: The struct pstore_zone_info details. -* -*/ -struct pstore_device_info { -unsigned int flags; -struct pstore_zone_info zone; -}; -int register_pstore_device (struct pstore_device_info *dev);void unregister_pstore_device (struct pstore_device_info *dev);
include/linux/pstore_zone.h +14 -0
@@ -54,6 +54,20 @@ struct pstore_zone_info {pstore_zone_write_op panic_write; }; +/** +* struct pstore_device_info - back-end pstore device driver structure. +* +* @flags: Refer to macro starting with PSTORE_FLAGS defined in +* linux/pstore.h. It means what front-ends this device support. +* Zero means all backends for compatible. +* @zone: The struct pstore_zone_info details. +* +*/ +struct pstore_device_info { +unsigned int flags; +struct pstore_zone_info zone; +}; +extern int register_pstore_zone (struct pstore_zone_info *info);extern void unregister_pstore_zone (struct pstore_zone_info *info);
Signature · 1 line
2.43.0
RFC PATCH 2/10 pstore/smem: add new pstore/smem type of pstore
In reply to Eugen HristevAdd shared memory type of pstore.
--- fs/pstore/Kconfig | 13 ++++ fs/pstore/Makefile | 3 + fs/pstore/smem.c | 115 ++++++++++++++++++++++++++++++++++++ include/linux/pstore_smem.h | 9 +++ 4 files changed, 140 insertions(+) create mode 100644 fs/pstore/smem.c create mode 100644 include/linux/pstore_smem.h
fs/pstore/Kconfig +13 -0
@@ -81,6 +81,19 @@ config PSTORE_RAM For more information, see Documentation/admin-guide/ramoops.rst. +config PSTORE_SMEM + tristate "Log panic/oops to a shared memory buffer" + depends on PSTORE + select PSTORE_ZONE + help + This enables panic and oops messages to be logged to memory + that is shared between different hardware blocks in the system. + This shared memory can be a static ram, a part of dynamic RAM, + a dedicated cache or memory area specific for crash dumps, + or even a memory on an attached device. + + if unsure, say N. + config PSTORE_ZONE tristate depends on PSTORE
fs/pstore/Makefile +3 -0
@@ -18,3 +18,6 @@ obj-$(CONFIG_PSTORE_ZONE) += pstore_zone.o pstore_blk-objs += blk.o obj-$(CONFIG_PSTORE_BLK) += pstore_blk.o + +pstore_smem-objs += smem.o +obj-$(CONFIG_PSTORE_SMEM) += pstore_smem.o
fs/pstore/smem.c new file +115 -0
115 lines not on this page · raw message
include/linux/pstore_smem.h new file +9 -0
@@ -0,0 +1,9 @@ +#ifndef PSTORE_SMEM_H +#define PSTORE_SMEM_H + +#include <linux/pstore_zone.h> + +int register_pstore_smem_device (struct pstore_device_info *dev); +void unregister_pstore_smem_device (struct pstore_device_info *dev); + +#endif
Signature · 1 line
2.43.0
RFC PATCH 3/10 pstore/zone: introduce directly mapped zones
In reply to Eugen HristevDirectly mapped zones have a different semantic from usual pstore zones. Such zones use a pointer to data in their buffer struct, instead of keeping the buffer locally.
The data pointer and size is then passed to the backend for further use. Having a different semantics, backends supporting only these do not offer read/write ops, and only new register_dmr and unregister_dmr ops. Ofcourse, a backend could support both classic zones and directly mapped. Directly mapped zones have the advantage of not being passed through in the event of a crashed, but rather at registration time.
--- fs/pstore/platform.c | 1 + fs/pstore/smem.c | 6 ++--- fs/pstore/zone.c | 45 ++++++++++++++++++++++++++++--------- include/linux/pstore.h | 4 ++++ include/linux/pstore_zone.h | 3 +++ 5 files changed, 45 insertions(+), 14 deletions(-)
fs/pstore/platform.c +1 -0
@@ -51,6 +51,7 @@ static const char * const pstore_type_names[] = {"powerpc-common" ,"pmsg" ,"powerpc-opal" , + "directly-mapped", };static int pstore_new_entry;
fs/pstore/smem.c +3 -3
@@ -36,15 +36,15 @@ static int __register_pstore_device(struct pstore_device_info *dev)pr_err ("NULL device info\n" );return -EINVAL ; } -if (!dev->zone.total_size) { +if (!dev->zone.total_size && !dev->zone.dmapped_cnt) {pr_err ("zero sized device\n" );return -EINVAL ; } -if (!dev->zone.read) { +if (!dev->zone.read && !dev->zone.dmapped_cnt) {pr_err ("no read handler for device\n" );return -EINVAL ; } -if (!dev->zone.write) { +if (!dev->zone.write && !dev->zone.dmapped_cnt) {pr_err ("no write handler for device\n" );return -EINVAL ; }
fs/pstore/zone.c +34 -11
129 lines not on this page · raw message
include/linux/pstore.h +4 -0
@@ -39,6 +39,7 @@ enum pstore_type_id {PSTORE_TYPE_PMSG =7 ,PSTORE_TYPE_PPC_OPAL =8 , +PSTORE_TYPE_DMAPPED =9 ,/* End of the list */ PSTORE_TYPE_MAX };
@@ -199,6 +200,8 @@ struct pstore_info {int (*write_user)(struct pstore_record *record,const char __user *buf);int (*erase)(struct pstore_record *record); +int (*register_dmr)(struct pstore_record *record); +int (*unregister_dmr)(struct pstore_record *record); };/* Supported frontends */
@@ -206,6 +209,7 @@ struct pstore_info {#define PSTORE_FLAGS_CONSOLE BIT(1)#define PSTORE_FLAGS_FTRACE BIT(2)#define PSTORE_FLAGS_PMSG BIT(3) +#define PSTORE_FLAGS_DMAPPED BIT(4)extern int pstore_register (struct pstore_info *);extern void pstore_unregister (struct pstore_info *);
include/linux/pstore_zone.h +3 -0
@@ -48,10 +48,13 @@ struct pstore_zone_info {unsigned long pmsg_size;unsigned long console_size;unsigned long ftrace_size; +unsigned long dmapped_cnt;pstore_zone_read_op read;pstore_zone_write_op write;pstore_zone_erase_op erase;pstore_zone_write_op panic_write; +int (*register_dmr)(char *,int ,void *,size_t ); +int (*unregister_dmr)(void *,size_t ); };/**
Signature · 1 line
2.43.0
kernel test robot
build botRe: [RFC][PATCH 03/10] pstore/zone: introduce directly mapped zones
kernel test robot noticed the following build warnings:
Hi Eugen,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build warnings:
[auto build test WARNING on kees/for-next/pstore]
[also build test WARNING on kees/for-next/kspp driver-core/driver-core-testing driver-core/driver-core-next driver-core/driver-core-linus herbert-cryptodev-2.6/master herbert-crypto-2.6/master linus/master v6.14-rc3 next-20250217] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Eugen-Hristev/pstore-zone-move-pstore_device_info-into-zone-header/20250217-182615 base: https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git for-next/pstore patch link: https://lore.kernel.org/r/20250217101706.2104498-4-eugen.hristev%40linaro.org patch subject: [RFC][PATCH 03/10] pstore/zone: introduce directly mapped zones config: i386-buildonly-randconfig-001-20250218 (https://download.01.org/0day-ci/archive/20250218/[email protected]/config) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250218/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> fs/pstore/zone.c:141: warning: Function parameter or struct member 'dmszs' not described in 'psz_context' >> fs/pstore/zone.c:141: warning: Function parameter or struct member 'dmapped_max_cnt' not described in 'psz_context'
vim +141 fs/pstore/zone.c
d26c3321fe18dc7 WeiXiong Liao 2020-03-25 88
d26c3321fe18dc7 WeiXiong Liao 2020-03-25 89 /**
d26c3321fe18dc7 WeiXiong Liao 2020-03-25 90 * struct psz_context - all about running state of pstore/zone
d26c3321fe18dc7 WeiXiong Liao 2020-03-25 91 *
d26c3321fe18dc7 WeiXiong Liao 2020-03-25 92 * @kpszs: kmsg dump storage zones
0dc068265a1c592 WeiXiong Liao 2020-03-25 93 * @ppsz: pmsg storage zone
cc9c4d1b5597167 WeiXiong Liao 2020-03-25 94 * @cpsz: console storage zone
34327e9fd213414 WeiXiong Liao 2020-03-25 95 * @fpszs: ftrace storage zones
d26c3321fe18dc7 WeiXiong Liao 2020-03-25 96 * @kmsg_max_cnt: max count of @kpszs
d26c3321fe18dc7 WeiXiong Liao 2020-03-25 97 * @kmsg_read_cnt: counter of total read kmsg dumps
d26c3321fe18dc7 WeiXiong Liao 2020-03-25 98 * @kmsg_write_cnt: counter of total kmsg dump writes
0dc068265a1c592 WeiXiong Liao 2020-03-25 99 * @pmsg_read_cnt: counter of total read pmsg zone
cc9c4d1b5597167 WeiXiong Liao 2020-03-25 100 * @console_read_cnt: counter of total read console zone
34327e9fd213414 WeiXiong Liao 2020-03-25 101 * @ftrace_max_cnt: max count of @fpszs
34327e9fd213414 WeiXiong Liao 2020-03-25 102 * @ftrace_read_cnt: counter of max read ftrace zone
d26c3321fe18dc7 WeiXiong Liao 2020-03-25 103 * @oops_counter: counter of oops dumps
d26c3321fe18dc7 WeiXiong Liao 2020-03-25 104 * @panic_counter: counter of panic dumps
d26c3321fe18dc7 WeiXiong Liao 2020-03-25 105 * @recovered: whether finished recovering data from storage
d26c3321fe18dc7 WeiXiong Liao 2020-03-25 106 * @on_panic: whether panic is happening
d26c3321fe18dc7 WeiXiong Liao 2020-03-25 107 * @pstore_zone_info_lock: lock to @pstore_zone_info
d26c3321fe18dc7 WeiXiong Liao 2020-03-25 108 * @pstore_zone_info: information from backend
d26c3321fe18dc7 WeiXiong Liao 2020-03-25 109 * @pstore: structure for pstore
d26c3321fe18dc7 WeiXiong Liao 2020-03-25 110 */
d26c3321fe18dc7 WeiXiong Liao 2020-03-25 111 struct psz_context {
d26c3321fe18dc7 WeiXiong Liao 2020-03-25 112 struct pstore_zone **kpszs;
0dc068265a1c592 WeiXiong Liao 2020-03-25 113 struct pstore_zone *ppsz;
cc9c4d1b5597167 WeiXiong Liao 2020-03-25 114 struct pstore_zone *cpsz;
34327e9fd213414 WeiXiong Liao 2020-03-25 115 struct pstore_zone **fpszs;
da841d31ac7ea7b Eugen Hristev 2025-02-17 116 struct pstore_zone **dmszs;
d26c3321fe18dc7 WeiXiong Liao 2020-03-25 117 unsigned int kmsg_max_cnt;
d26c3321fe18dc7 WeiXiong Liao 2020-03-25 118 unsigned int kmsg_read_cnt;
d26c3321fe18dc7 WeiXiong Liao 2020-03-25 119 unsigned int kmsg_write_cnt;
0dc068265a1c592 WeiXiong Liao 2020-03-25 120 unsigned int pmsg_read_cnt;
cc9c4d1b5597167 WeiXiong Liao 2020-03-25 121 unsigned int console_read_cnt;
34327e9fd213414 WeiXiong Liao 2020-03-25 122 unsigned int ftrace_max_cnt;
34327e9fd213414 WeiXiong Liao 2020-03-25 123 unsigned int ftrace_read_cnt;
da841d31ac7ea7b Eugen Hristev 2025-02-17 124 unsigned int dmapped_max_cnt;
d26c3321fe18dc7 WeiXiong Liao 2020-03-25 125 /*
d26c3321fe18dc7 WeiXiong Liao 2020-03-25 126 * These counters should be calculated during recovery.
d26c3321fe18dc7 WeiXiong Liao 2020-03-25 127 * It records the oops/panic times after crashes rather than boots.
d26c3321fe18dc7 WeiXiong Liao 2020-03-25 128 */
d26c3321fe18dc7 WeiXiong Liao 2020-03-25 129 unsigned int oops_counter;
d26c3321fe18dc7 WeiXiong Liao 2020-03-25 130 unsigned int panic_counter;
d26c3321fe18dc7 WeiXiong Liao 2020-03-25 131 atomic_t recovered;
d26c3321fe18dc7 WeiXiong Liao 2020-03-25 132 atomic_t on_panic;
d26c3321fe18dc7 WeiXiong Liao 2020-03-25 133
d26c3321fe18dc7 WeiXiong Liao 2020-03-25 134 /*
d26c3321fe18dc7 WeiXiong Liao 2020-03-25 135 * pstore_zone_info_lock protects this entire structure during calls
d26c3321fe18dc7 WeiXiong Liao 2020-03-25 136 * to register_pstore_zone()/unregister_pstore_zone().
d26c3321fe18dc7 WeiXiong Liao 2020-03-25 137 */
d26c3321fe18dc7 WeiXiong Liao 2020-03-25 138 struct mutex pstore_zone_info_lock;
d26c3321fe18dc7 WeiXiong Liao 2020-03-25 139 struct pstore_zone_info *pstore_zone_info;
d26c3321fe18dc7 WeiXiong Liao 2020-03-25 140 struct pstore_info pstore;d26c3321fe18dc7 WeiXiong Liao 2020-03-25 @141 };d26c3321fe18dc7 WeiXiong Liao 2020-03-25 142 static struct psz_context pstore_zone_cxt; d26c3321fe18dc7 WeiXiong Liao 2020-03-25 143
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
RFC PATCH 4/10 qcom: smem: add pstore smem backend
In reply to Eugen HristevAdd support for pstore smem backend in the qcom smem driver. This backend resorts to minidump regions behind the scenes.
--- drivers/soc/qcom/Kconfig | 9 + drivers/soc/qcom/Makefile | 6 +- drivers/soc/qcom/smem_md.c | 306 +++++++++++++++++++++++++++++++++ drivers/soc/qcom/smem_pstore.c | 112 ++++++++++++ include/linux/soc/qcom/smem.h | 43 +++++ 5 files changed, 474 insertions(+), 2 deletions(-) create mode 100644 drivers/soc/qcom/smem_md.c create mode 100644 drivers/soc/qcom/smem_pstore.c
drivers/soc/qcom/Kconfig +9 -0
@@ -180,6 +180,15 @@ config QCOM_SMEM The driver provides an interface to items in a heap shared among all processors in a Qualcomm platform. +config QCOM_SMEM_PSTORE + bool "Qualcomm Shared Memory(SMEM) Pstore backend" + depends on QCOM_SMEM + select PSTORE + select PSTORE_SMEM + help + Say y here to enable the shared memory driver to register itself + as a pstore backend. + config QCOM_SMD_RPM tristate "Qualcomm Resource Power Manager (RPM) over SMD" depends on ARCH_QCOM || COMPILE_TEST
drivers/soc/qcom/Makefile +4 -2
@@ -23,8 +23,10 @@ obj-$(CONFIG_QCOM_RPMH) += qcom_rpmh.o qcom_rpmh-y += rpmh-rsc.o qcom_rpmh-y += rpmh.o obj-$(CONFIG_QCOM_SMD_RPM) += rpm-proc.o smd-rpm.o -obj-$(CONFIG_QCOM_SMEM) += smem.o -obj-$(CONFIG_QCOM_SMEM_STATE) += smem_state.o +obj-$(CONFIG_QCOM_SMEM) += qcom_smem.o +qcom_smem-y += smem.o +qcom_smem-$(CONFIG_QCOM_SMEM_PSTORE) += smem_pstore.o smem_md.o +obj-$(CONFIG_QCOM_SMEM_STATE) += smem_state.o CFLAGS_smp2p.o := -I$(src) obj-$(CONFIG_QCOM_SMP2P) += smp2p.o obj-$(CONFIG_QCOM_SMSM) += smsm.o
drivers/soc/qcom/smem_md.c new file +306 -0
306 lines not on this page · raw message
drivers/soc/qcom/smem_pstore.c new file +112 -0
112 lines not on this page · raw message
include/linux/soc/qcom/smem.h +43 -0
47 lines not on this page · raw message
Signature · 1 line
2.43.0
RFC PATCH 5/10 pstore: implement core area registration
In reply to Eugen HristevImplement core area registration mechanism. Implement directly mapped zone corespoding to core areas.
--- fs/pstore/platform.c | 67 ++++++++++++++++++++++++++++++++++++ fs/pstore/zone.c | 77 ++++++++++++++++++++++++++++++++++++++++++ include/linux/pstore.h | 16 +++++++++ 3 files changed, 160 insertions(+)
fs/pstore/platform.c +67 -0
@@ -68,6 +68,7 @@ static DECLARE_WORK(pstore_work, pstore_dowork);* the filesystem mount/unmount routines. */ static DEFINE_MUTEX (psinfo_lock); +static DEFINE_MUTEX (ps_dmr_lock);struct pstore_info *psinfo;static char *backend;
@@ -99,6 +100,12 @@ MODULE_PARM_DESC(kmsg_bytes, "amount of kernel log to snapshot (in bytes)");static void *compress_workspace; +static LIST_HEAD (rec_list); +struct rec_list_t { +struct pstore_record rec; +struct list_head list; +}; +/* * Compression is only used for dmesg output, which consists of low-entropy * ASCII text, and so we can assume worst-case 60%.
@@ -271,6 +278,66 @@ void pstore_record_init(struct pstore_record *record, record->time =ns_to_timespec64 (ktime_get_real_fast_ns ()); } +int pstore_register_core_area (const char *handle,void *area,size_t size) +{ +struct rec_list_t *rec_element =kzalloc (sizeof (*rec_element),GFP_KERNEL ); +struct pstore_record *record = &rec_element->rec; +int ret; + +if (!psinfo || !psinfo->register_dmr) { +pr_err ("No pstore available ! Bailing out.\n" ); +return -EAGAIN ; + } + +pstore_record_init (record, psinfo); + record->type =PSTORE_TYPE_DMAPPED ; + record->buf = area; + record->size = size; + +if (handle) { + record->priv =kmalloc (8 ,GFP_KERNEL ); +strncpy (record->priv, handle,8 ); + } + +mutex_lock (&ps_dmr_lock); + + ret = psinfo->register_dmr (record); +if (!ret) +list_add (&rec_element->list, &rec_list); + +mutex_unlock (&ps_dmr_lock); +return ret; +} +EXPORT_SYMBOL_GPL (pstore_register_core_area); + +int pstore_unregister_core_area (const char *handle,void *area,size_t size) +{ +struct rec_list_t *rec_element, *tmp; +int ret; + +if (!psinfo || !psinfo->unregister_dmr) +return -EAGAIN ; + +mutex_lock (&ps_dmr_lock); +list_for_each_entry_safe (rec_element, tmp, &rec_list, list) { +struct pstore_record *record; + + record = &rec_element->rec; + +if (record->buf == area) { + ret = psinfo->unregister_dmr (record); +list_del (&rec_element->list); +mutex_unlock (&ps_dmr_lock); +return 0 ; + } + } + +mutex_unlock (&ps_dmr_lock); +return 0 ; + +} +EXPORT_SYMBOL_GPL (pstore_unregister_core_area); +/* * callback from kmsg_dump. Save as much as we can (up to kmsg_bytes) from the * end of the buffer.
fs/pstore/zone.c +77 -0
101 lines not on this page · raw message
include/linux/pstore.h +16 -0
@@ -290,4 +290,20 @@ pstore_ftrace_write_timestamp(struct pstore_ftrace_record *rec, u64 val) }#endif +#ifdef CONFIG_PSTORE +int pstore_register_core_area (const char *handle,void *area,size_t size); +int pstore_unregister_core_area (const char *handle,void *area,size_t size); +#else +static inline int pstore_register_core_area (const char *handle,void *area, +size_t size) +{ +return 0 ; +} +static inline int pstore_unregister_core_area (const char *handle,void *area, +size_t size) +{ +return 0 ; +} +#endif +#endif /*_LINUX_PSTORE_H*/
Signature · 1 line
2.43.0
kernel test robot
build botRe: [RFC][PATCH 05/10] pstore: implement core area registration
kernel test robot noticed the following build warnings:
Hi Eugen,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build warnings:
[auto build test WARNING on kees/for-next/pstore]
[also build test WARNING on kees/for-next/kspp driver-core/driver-core-testing driver-core/driver-core-next driver-core/driver-core-linus herbert-cryptodev-2.6/master herbert-crypto-2.6/master linus/master v6.14-rc3 next-20250217] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Eugen-Hristev/pstore-zone-move-pstore_device_info-into-zone-header/20250217-182615 base: https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git for-next/pstore patch link: https://lore.kernel.org/r/20250217101706.2104498-6-eugen.hristev%40linaro.org patch subject: [RFC][PATCH 05/10] pstore: implement core area registration config: i386-buildonly-randconfig-001-20250218 (https://download.01.org/0day-ci/archive/20250218/[email protected]/config) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250218/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
fs/pstore/platform.c: In function 'pstore_unregister_core_area':
>> fs/pstore/platform.c:316:13: warning: variable 'ret' set but not used [-Wunused-but-set-variable]
316 | int ret;
| ^~~
--
>> fs/pstore/zone.c:40: warning: Function parameter or struct member 'data_ptr' not described in 'psz_buffer' fs/pstore/zone.c:142: warning: Function parameter or struct member 'dmszs' not described in 'psz_context' fs/pstore/zone.c:142: warning: Function parameter or struct member 'dmapped_max_cnt' not described in 'psz_context'
vim +/ret +316 fs/pstore/platform.c
312
313 int pstore_unregister_core_area(const char *handle, void *area, size_t size)
314 {
315 struct rec_list_t *rec_element, *tmp;
> 316 int ret;
317
318 if (!psinfo || !psinfo->unregister_dmr)
319 return -EAGAIN;
320
321 mutex_lock(&ps_dmr_lock);
322 list_for_each_entry_safe(rec_element, tmp, &rec_list, list) {
323 struct pstore_record *record;
324
325 record = &rec_element->rec;
326
327 if (record->buf == area) {
328 ret = psinfo->unregister_dmr(record);
329 list_del(&rec_element->list);
330 mutex_unlock(&ps_dmr_lock);
331 return 0;
332 }
333 }
334
335 mutex_unlock(&ps_dmr_lock);
336 return 0;
337
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [RFC][PATCH 05/10] pstore: implement core area registration
In reply to Eugen Hristevkernel test robot noticed the following build warnings:
Hi Eugen,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build warnings:
[auto build test WARNING on kees/for-next/pstore]
[also build test WARNING on kees/for-next/kspp driver-core/driver-core-testing driver-core/driver-core-next driver-core/driver-core-linus herbert-cryptodev-2.6/master herbert-crypto-2.6/master linus/master v6.14-rc3 next-20250217] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Eugen-Hristev/pstore-zone-move-pstore_device_info-into-zone-header/20250217-182615 base: https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git for-next/pstore patch link: https://lore.kernel.org/r/20250217101706.2104498-6-eugen.hristev%40linaro.org patch subject: [RFC][PATCH 05/10] pstore: implement core area registration config: arm-randconfig-002-20250218 (https://download.01.org/0day-ci/archive/20250218/[email protected]/config) compiler: arm-linux-gnueabi-gcc (GCC) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250218/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
fs/pstore/platform.c: In function 'pstore_unregister_core_area':
fs/pstore/platform.c:316:13: warning: variable 'ret' set but not used [-Wunused-but-set-variable]
316 | int ret;
| ^~~
fs/pstore/platform.c: In function 'pstore_register_core_area':
>> fs/pstore/platform.c:299:17: warning: 'strncpy' specified bound 8 equals destination size [-Wstringop-truncation]
299 | strncpy(record->priv, handle, 8);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~vim +/strncpy +299 fs/pstore/platform.c
280
281 int pstore_register_core_area(const char *handle, void *area, size_t size)
282 {
283 struct rec_list_t *rec_element = kzalloc(sizeof (*rec_element), GFP_KERNEL);
284 struct pstore_record *record = &rec_element->rec;
285 int ret;
286
287 if (!psinfo || !psinfo->register_dmr) {
288 pr_err("No pstore available ! Bailing out.\n");
289 return -EAGAIN;
290 }
291
292 pstore_record_init(record, psinfo);
293 record->type = PSTORE_TYPE_DMAPPED;
294 record->buf = area;
295 record->size = size;
296
297 if (handle) {
298 record->priv = kmalloc(8, GFP_KERNEL);
> 299 strncpy(record->priv, handle, 8);
300 }
301
302 mutex_lock(&ps_dmr_lock);
303
304 ret = psinfo->register_dmr(record);
305 if (!ret)
306 list_add(&rec_element->list, &rec_list);
307
308 mutex_unlock(&ps_dmr_lock);
309 return ret;
310 }
311 EXPORT_SYMBOL_GPL(pstore_register_core_area);
312
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
RFC PATCH 6/10 qcom: smem: enable smem pstore backend
In reply to Eugen HristevEnable smem pstore backend that registers regions into the minidump table.
--- drivers/soc/qcom/smem.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/soc/qcom/smem.c +10 -0
@@ -1236,11 +1236,21 @@ static int qcom_smem_probe(struct platform_device *pdev)if (IS_ERR (smem->socinfo))dev_dbg (&pdev->dev,"failed to register socinfo device\n" ); + ret =qcom_smem_md_init (&pdev->dev); +if (ret) +dev_info (&pdev->dev,"smem minidump backend init failed\n" ); + + ret =qcom_register_pstore_smem (&pdev->dev); +if (ret) +dev_info (&pdev->dev,"smem pstore backend registration failed\n" ); +return 0 ; }static void qcom_smem_remove (struct platform_device *pdev) { +qcom_unregister_pstore_smem (); +platform_device_unregister (__smem->socinfo);hwspin_lock_free (__smem->hwlock);
Signature · 1 line
2.43.0
RFC PATCH 7/10 printk: export symbols for buffer address and length functions
In reply to Eugen Hristevlog_buf_addr_get() and log_buf_len_get() can be reused in another module, export the symbols.
--- kernel/printk/printk.c | 2 ++ 1 file changed, 2 insertions(+)
kernel/printk/printk.c +2 -0
@@ -588,12 +588,14 @@ char *log_buf_addr_get(void) {return log_buf; } +EXPORT_SYMBOL_GPL (log_buf_addr_get);/* Return log buffer size */ u32 log_buf_len_get (void ) {return log_buf_len; } +EXPORT_SYMBOL_GPL (log_buf_len_get);/* * Define how much of the log buffer we could take at maximum. The value
Signature · 1 line
2.43.0
Re: [RFC][PATCH 07/10] printk: export symbols for buffer address and length functions
Quoted 2 lines · Eugen Hristev
log_buf_addr_get()andlog_buf_len_get()can be reused in another module, export the symbols.
Err, no way.
Sergey Senozhatsky
reviewerRe: [RFC][PATCH 07/10] printk: export symbols for buffer address and length functions
Quoted 5 lines · Christoph Hellwig
Quoted 2 lines · Eugen Hristev
log_buf_addr_get()andlog_buf_len_get()can be reused in another module, export the symbols.Err, no way.
Yeah I think we've been there before [1]
Re: [RFC][PATCH 07/10] printk: export symbols for buffer address and length functions
Quoted 10 lines · Sergey Senozhatsky
Quoted 5 lines · Christoph Hellwig
Quoted 2 lines · Eugen Hristev
log_buf_addr_get()andlog_buf_len_get()can be reused in another module, export the symbols.Err, no way.
Yeah I think we've been there before [1]
Okay... in the line of the purpose of this patch series, I would like to be able to have the dmesg ready to be retrieved out of the kernel in case the kernel becomes unusable (due to various reasons as described in the cover letter). However to know exactly 'where' is the buffer stored I would need some way to point to it.
Do you have any other suggestion on how to do this ? Using the kmsg_dump() API works only if the kernel/CPU can run code.
Thanks for looking into the patches,
Eugen
RFC PATCH 8/10 pstore: register kmsg into directly mapped zones if available
In reply to Eugen HristevIf dmapped zones are available, register the log buffer into one zone.
--- fs/pstore/platform.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
fs/pstore/platform.c +16 -0
@@ -452,11 +452,22 @@ static void pstore_register_kmsg(void)kmsg_dump_register (&pstore_dumper); } +static int pstore_register_kmsg_dmapped (void ) +{ +return pstore_register_core_area ("dmesg" ,log_buf_addr_get (), +log_buf_len_get ()); +} +static void pstore_unregister_kmsg (void ) {kmsg_dump_unregister (&pstore_dumper); } +static int pstore_unregister_kmsg_dmapped (void ) +{ +return pstore_unregister_core_area ("dmesg" ,log_buf_addr_get (), +log_buf_len_get ()); +}#ifdef CONFIG_PSTORE_CONSOLE static void pstore_console_write (struct console *con,const char *s,unsigned c) {
@@ -582,6 +593,9 @@ int pstore_register(struct pstore_info *psi) pstore_dumper.max_reason = psinfo->max_reason;pstore_register_kmsg (); } +if (psi->flags &PSTORE_FLAGS_DMAPPED ) +if (pstore_register_kmsg_dmapped ()) +pr_warn ("Registering kmsg as dmapped failed.\n" );if (psi->flags &PSTORE_FLAGS_CONSOLE )pstore_register_console ();if (psi->flags &PSTORE_FLAGS_FTRACE )
@@ -628,6 +642,8 @@ void pstore_unregister(struct pstore_info *psi)pstore_unregister_console ();if (psi->flags &PSTORE_FLAGS_DMESG )pstore_unregister_kmsg (); +if (psi->flags &PSTORE_FLAGS_DMAPPED ) +pstore_unregister_kmsg_dmapped ();/* Stop timer and make sure all work has finished. */ del_timer_sync (&pstore_timer);
Signature · 1 line
2.43.0
RFC PATCH 9/10 devcoredump: add devcd_{un}register_core_area API
In reply to Eugen HristevAdd API for registering device core area for saving into pstore.
--- drivers/base/devcoredump.c | 13 +++++++++++++ include/linux/devcoredump.h | 3 +++ 2 files changed, 16 insertions(+)
drivers/base/devcoredump.c +13 -0
@@ -9,6 +9,7 @@#include <linux/device.h> #include <linux/devcoredump.h> #include <linux/list.h> +#include <linux/pstore.h> #include <linux/slab.h> #include <linux/fs.h> #include <linux/workqueue.h>
@@ -76,6 +77,18 @@ static struct devcd_entry *dev_to_devcd(struct device *dev) return container_of(dev, struct devcd_entry, devcd_dev); } +int devcd_register_core_area (struct device *dev,void *area,size_t size) +{ +return pstore_register_core_area (dev->driver->name, area, size); +} +EXPORT_SYMBOL_GPL (devcd_register_core_area); + +int devcd_unregister_core_area (struct device *dev,void *area,size_t size) +{ +return pstore_unregister_core_area (dev->driver->name, area, size); +} +EXPORT_SYMBOL_GPL (devcd_unregister_core_area); +static void devcd_dev_release (struct device *dev) {struct devcd_entry *devcd =dev_to_devcd (dev);
include/linux/devcoredump.h +3 -0
@@ -69,6 +69,9 @@ void dev_coredumpsg(struct device *dev, struct scatterlist *table, size_t datalen, gfp_t gfp);void dev_coredump_put (struct device *dev); + +int devcd_register_core_area (struct device *,void *,size_t ); +int devcd_unregister_core_area (struct device *,void *,size_t );#else static inline void dev_coredumpv (struct device *dev,void *data,size_t datalen,gfp_t gfp)
Signature · 1 line
2.43.0
RFC PATCH 10/10 rng: qcom_rng: EXAMPLE: registering dev structure
In reply to Eugen HristevProof of concept on how devcd register core area works.
--- drivers/crypto/qcom-rng.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/crypto/qcom-rng.c +11 -0
@@ -7,6 +7,7 @@#include <linux/acpi.h> #include <linux/clk.h> #include <linux/crypto.h> +#include <linux/devcoredump.h> #include <linux/hw_random.h> #include <linux/io.h> #include <linux/iopoll.h>
@@ -32,11 +33,13 @@#define QCOM_TRNG_QUALITY 1024struct qcom_rng { +char start[10 ];struct mutex lock;void __iomem *base;struct clk *clk;struct hwrng hwrng;struct qcom_rng_match_data *match_data; +char end[10 ]; };struct qcom_rng_ctx {
@@ -192,6 +195,10 @@ static int qcom_rng_probe(struct platform_device *pdev)if (IS_ERR (rng->base))return PTR_ERR (rng->base); +/* Setting some markers to easily recognize them afterwards */ +strcpy (rng->start,"MD_RNG_ST" ); +strcpy (rng->end,"MD_RNG_en" ); + rng->clk =devm_clk_get_optional (&pdev->dev,"core" );if (IS_ERR (rng->clk))return PTR_ERR (rng->clk);
@@ -218,6 +225,8 @@ static int qcom_rng_probe(struct platform_device *pdev) } } +devcd_register_core_area (&pdev->dev, rng,sizeof (*rng)); +return ret; fail:crypto_unregister_rng (&qcom_rng_alg);
@@ -228,6 +237,8 @@ static void qcom_rng_remove(struct platform_device *pdev) {crypto_unregister_rng (&qcom_rng_alg); +devcd_unregister_core_area (&pdev->dev, qcom_rng_dev, +sizeof (*qcom_rng_dev)); qcom_rng_dev =NULL ; }
Signature · 1 line
2.43.0
Johannes Berg
maintainerQuoted 2 lines · Eugen Hristev
This series comes as an RFC proposed solution to enhance pstore and devcoredump with the following functionality:
...
Quoted 2 lines
This patch series attempts to solve this by reusing existing infrastructure in pstore and devcoredump, and provide a copy-free
...
You mention devcoredump multiple times, but it almost seems like you don't even know what devcoredump does? I don't see how there's any relation at all, and the code added to it seems to have no relation to the actual functionality of devcoredump either?
johannes
Quoted 10 lines · Johannes Berg
Quoted 2 lines · Eugen Hristev
This series comes as an RFC proposed solution to enhance pstore and devcoredump with the following functionality:
...
Quoted 2 lines
This patch series attempts to solve this by reusing existing infrastructure in pstore and devcoredump, and provide a copy-free
Quoted 6 lines
...
You mention devcoredump multiple times, but it almost seems like you don't even know what devcoredump does? I don't see how there's any relation at all, and the code added to it seems to have no relation to the actual functionality of devcoredump either?
At this moment going through devcoredump is not something that impacts the idea of the implementation.
The whole reason of going through it (because things work without it as well), is to see whether this has any kind of impact or not, and if there is any kind of fit/reason of going through it. Devcoredump is involved because the whole core registration is similar to a core area that devcoredump could use.
For example, would it be interesting to have a handler going through all devices, and have the dump areas already registered ? Meaning, when there is a request to generate a core dump, one could directly dump this area instead of calling back the driver, and provide that to the userspace instead of the driver calling the dev_coredumpv by its own.
Quoted 2 lines
johannes
Johannes Berg
maintainerQuoted 3 lines · Eugen Hristev
At this moment going through devcoredump is not something that impacts the idea of the implementation.
Yeah. I don't think it _should_ go through it at all.
Quoted 3 lines
The whole reason of going through it (because things work without it as well), is to see whether this has any kind of impact or not, and if there is any kind of fit/reason of going through it.
So it's just a trial balloon?
Quoted 2 lines
Devcoredump is involved because the whole core registration is similar to a core area that devcoredump could use.
Yeah but ...
Quoted 6 lines
For example, would it be interesting to have a handler going through all devices, and have the dump areas already registered ? Meaning, when there is a request to generate a core dump, one could directly dump this area instead of calling back the driver, and provide that to the userspace instead of the driver calling the
dev_coredumpvby its own.
I'll be blunt ... so you _really_ haven't understood devcoredump then?
It's really not doing this. It's not meant to do this... It's intended to dump data from inside the device when the device crashes.
Please remove devcoredump involvement from this series.
johannes
Quoted 5 lines · Johannes Berg
Quoted 3 lines · Eugen Hristev
At this moment going through devcoredump is not something that impacts the idea of the implementation.
Quoted 7 lines
Yeah. I don't think it _should_ go through it at all.
Quoted 3 lines
The whole reason of going through it (because things work without it as well), is to see whether this has any kind of impact or not, and if there is any kind of fit/reason of going through it.
So it's just a trial balloon?
Yes, that's why it's marked as an RFC.
Quoted 13 lines
Quoted 3 lines
Devcoredump is involved because the whole core registration is similar to a core area that devcoredump could use.
Yeah but ...
Quoted 6 lines
For example, would it be interesting to have a handler going through all devices, and have the dump areas already registered ? Meaning, when there is a request to generate a core dump, one could directly dump this area instead of calling back the driver, and provide that to the userspace instead of the driver calling the
dev_coredumpvby its own.
Quoted 6 lines
I'll be blunt ... so you _really_ haven't understood devcoredump then?
It's really not doing this. It's not meant to do this... It's intended to dump data from inside the device when the device crashes.
Please remove devcoredump involvement from this series.
Thank you for your feedback.
Quoted 2 lines
johannes
Johannes Berg
maintainerQuoted 9 lines · Eugen Hristev
Quoted 7 lines · Johannes Berg
Quoted 3 lines · Eugen Hristev
At this moment going through devcoredump is not something that impacts the idea of the implementation.
Yeah. I don't think it _should_ go through it at all.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
The whole reason of going through it (because things work without it as well), is to see whether this has any kind of impact or not, and if there is any kind of fit/reason of going through it.
So it's just a trial balloon?
Yes, that's why it's marked as an RFC.
(IMHO) that doesn't make it acceptable to just randomly go modify code you don't understand the purpose of, certainly not without actually stating such. But anyway, I'll leave it at that.
johannes