From: Eugen Hristev <eugen.hristev@linaro.org>
To: linux-arm-msm@vger.kernel.org, linux-hardening@vger.kernel.org,
kees@kernel.org
Cc: linux-kernel@vger.kernel.org, johannes@sipsolutions.net,
gregkh@linuxfoundation.org, rafael@kernel.org, dakr@kernel.org,
andersson@kernel.org, konradybcio@kernel.org,
tony.luck@intel.com, gpiccoli@igalia.com, pmladek@suse.com,
rostedt@goodmis.org, john.ogness@linutronix.de,
senozhatsky@chromium.org, quic_mojha@quicinc.com,
linux-arm-kernel@lists.infradead.org, kernel@quicinc.com,
Eugen Hristev <eugen.hristev@linaro.org>
Subject: [RFC][PATCH 02/10] pstore/smem: add new pstore/smem type of pstore
Date: Mon, 17 Feb 2025 12:16:58 +0200 [thread overview]
Message-ID: <20250217101706.2104498-3-eugen.hristev@linaro.org> (raw)
In-Reply-To: <20250217101706.2104498-1-eugen.hristev@linaro.org>
Add shared memory type of pstore.
Signed-off-by: Eugen Hristev <eugen.hristev@linaro.org>
---
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
diff --git a/fs/pstore/Kconfig b/fs/pstore/Kconfig
index 3acc38600cd1..84f87edf9b8f 100644
--- a/fs/pstore/Kconfig
+++ b/fs/pstore/Kconfig
@@ -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
diff --git a/fs/pstore/Makefile b/fs/pstore/Makefile
index c270467aeece..f2a314ca03a0 100644
--- a/fs/pstore/Makefile
+++ b/fs/pstore/Makefile
@@ -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
diff --git a/fs/pstore/smem.c b/fs/pstore/smem.c
new file mode 100644
index 000000000000..9eedd7df5446
--- /dev/null
+++ b/fs/pstore/smem.c
@@ -0,0 +1,115 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Implements pstore backend driver for shared memory devices,
+ * using the pstore/zone API.
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/blkdev.h>
+#include <linux/string.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/platform_device.h>
+#include <linux/pstore_smem.h>
+#include <linux/fs.h>
+#include <linux/file.h>
+#include <linux/init_syscalls.h>
+#include <linux/mount.h>
+
+/*
+ * All globals must only be accessed under the pstore_smem_lock
+ * during the register/unregister functions.
+ */
+static DEFINE_MUTEX(pstore_smem_lock);
+static struct pstore_device_info *pstore_device_info;
+
+static int __register_pstore_device(struct pstore_device_info *dev)
+{
+ int ret;
+
+ lockdep_assert_held(&pstore_smem_lock);
+
+ if (!dev) {
+ pr_err("NULL device info\n");
+ return -EINVAL;
+ }
+ if (!dev->zone.total_size) {
+ pr_err("zero sized device\n");
+ return -EINVAL;
+ }
+ if (!dev->zone.read) {
+ pr_err("no read handler for device\n");
+ return -EINVAL;
+ }
+ if (!dev->zone.write) {
+ pr_err("no write handler for device\n");
+ return -EINVAL;
+ }
+
+ /* someone already registered before */
+ if (pstore_device_info)
+ return -EBUSY;
+
+ /* zero means not limit on which backends to attempt to store. */
+ if (!dev->flags)
+ dev->flags = UINT_MAX;
+
+ /* Initialize required zone ownership details. */
+ dev->zone.name = KBUILD_MODNAME;
+ dev->zone.owner = THIS_MODULE;
+
+ ret = register_pstore_zone(&dev->zone);
+ if (ret == 0)
+ pstore_device_info = dev;
+
+ return ret;
+}
+/**
+ * register_pstore_smem_device() - register smem device to pstore
+ *
+ * @dev: smem device information
+ *
+ * Return:
+ * * 0 - OK
+ * * Others - some error.
+ */
+int register_pstore_smem_device(struct pstore_device_info *dev)
+{
+ int ret;
+
+ mutex_lock(&pstore_smem_lock);
+ ret = __register_pstore_device(dev);
+ mutex_unlock(&pstore_smem_lock);
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(register_pstore_smem_device);
+
+static void __unregister_pstore_device(struct pstore_device_info *dev)
+{
+ lockdep_assert_held(&pstore_smem_lock);
+ if (pstore_device_info && pstore_device_info == dev) {
+ unregister_pstore_zone(&dev->zone);
+ pstore_device_info = NULL;
+ }
+}
+
+/**
+ * unregister_pstore_smem_device() - unregister smem device from pstore
+ *
+ * @dev: smem device information
+ */
+void unregister_pstore_smem_device(struct pstore_device_info *dev)
+{
+ mutex_lock(&pstore_smem_lock);
+ __unregister_pstore_device(dev);
+ mutex_unlock(&pstore_smem_lock);
+}
+EXPORT_SYMBOL_GPL(unregister_pstore_smem_device);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Eugen Hristev <eugen.hristev@linaro.org>");
+MODULE_DESCRIPTION("pstore backend for smem devices");
diff --git a/include/linux/pstore_smem.h b/include/linux/pstore_smem.h
new file mode 100644
index 000000000000..f0ad23e117c4
--- /dev/null
+++ b/include/linux/pstore_smem.h
@@ -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
--
2.43.0
next prev parent reply other threads:[~2025-02-17 10:17 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-17 10:16 [RFC][PATCH 00/10] pstore: directly mapped regions Eugen Hristev
2025-02-17 10:16 ` [RFC][PATCH 01/10] pstore/zone: move pstore_device_info into zone header Eugen Hristev
2025-02-17 10:16 ` Eugen Hristev [this message]
2025-02-17 10:16 ` [RFC][PATCH 03/10] pstore/zone: introduce directly mapped zones Eugen Hristev
2025-02-17 10:17 ` [RFC][PATCH 04/10] qcom: smem: add pstore smem backend Eugen Hristev
2025-02-17 10:17 ` [RFC][PATCH 05/10] pstore: implement core area registration Eugen Hristev
2025-02-17 10:17 ` [RFC][PATCH 06/10] qcom: smem: enable smem pstore backend Eugen Hristev
2025-02-17 10:17 ` [RFC][PATCH 07/10] printk: export symbols for buffer address and length functions Eugen Hristev
2025-02-18 8:26 ` Christoph Hellwig
2025-02-18 8:58 ` Sergey Senozhatsky
2025-02-18 9:11 ` Eugen Hristev
2025-02-17 10:17 ` [RFC][PATCH 08/10] pstore: register kmsg into directly mapped zones if available Eugen Hristev
2025-02-17 10:17 ` [RFC][PATCH 09/10] devcoredump: add devcd_{un}register_core_area API Eugen Hristev
2025-02-17 10:17 ` [RFC][PATCH 10/10] rng: qcom_rng: EXAMPLE: registering dev structure Eugen Hristev
2025-02-17 10:23 ` [RFC][PATCH 00/10] pstore: directly mapped regions Johannes Berg
2025-02-17 10:44 ` Eugen Hristev
2025-02-17 11:19 ` Johannes Berg
2025-02-17 11:39 ` Eugen Hristev
2025-02-17 11:43 ` Johannes Berg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250217101706.2104498-3-eugen.hristev@linaro.org \
--to=eugen.hristev@linaro.org \
--cc=andersson@kernel.org \
--cc=dakr@kernel.org \
--cc=gpiccoli@igalia.com \
--cc=gregkh@linuxfoundation.org \
--cc=johannes@sipsolutions.net \
--cc=john.ogness@linutronix.de \
--cc=kees@kernel.org \
--cc=kernel@quicinc.com \
--cc=konradybcio@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pmladek@suse.com \
--cc=quic_mojha@quicinc.com \
--cc=rafael@kernel.org \
--cc=rostedt@goodmis.org \
--cc=senozhatsky@chromium.org \
--cc=tony.luck@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox