Skip to contentSkip to conversation

mmc: Add pstore backend for crash dump storage on eMMC

PATCH Superseded Kamal Dasu 3 participants 10 messages Mar 19 – Apr 10

Subsystems (2)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Kamal Dasu

author
#0 lore raw

v3 cover mmc: Add pstore backend for crash dump storage on eMMC

This series adds mmcpstore, a pstore backend driver that enables persistent storage of kernel crash logs on eMMC devices. When the kernel panics, pstore captures the kmsg dump and writes it directly to a dedicated MMC partition using polled I/O with interrupts disabled.

Changes since v2 (RFC):
- Rebased onto v7.0-rc — no longer reverts any existing MMC core or SDHCI changes (v1/v2 accidentally reverted recent upstream commits due to being based on an older tree)
- Removed all erase/bitmap tracking logic — MMC/eMMC is managed flash and does not need erase-before-write; the pstore_zone framework handles zone management internally
- Uses standard MMC core request path (mmc_start_request) instead of hand-building mmc_request structs; panic-context I/O is handled through proper mmc_host_ops callbacks rather than ad-hoc code in the driver
- Added panic-context ops to mmc_host_ops and sdhci_ops for clean separation of panic and normal I/O paths
- Fixed deadlocks caused by spinlock contention during panic (lockless mmc_panic_claim_host using WRITE_ONCE)
- Fixed data corruption in pstore recovery (zlib_inflate failures) by letting the normal sdhci_request() path run instead of a custom panic request handler
- Added PM suspend/resume support with eMMC re-initialization
- Supports module loading or builtin loading of the driver
- Added MAINTAINERS entry
- Split into 4-patch series for reviewability

The series is structured as follows:

Patch 1 adds panic-context operations to struct mmc_host_ops and a lockless mmc_panic_claim_host() for use during kernel panic when other CPUs are stopped and may hold locks.

Patch 2 implements these panic-context operations in the SDHCI host controller driver: draining in-flight requests, polling for completion, and making the command retry path panic-safe.

Patch 3 adds mmc_blk_get_card_by_name() helper to look up an mmc_card from a block device name, used by the mmcpstore module path for card discovery.

Patch 4 adds the mmcpstore driver itself, which registers with the pstore_blk framework and handles panic writes, PM suspend/resume, and dual-path registration (direct probe hook for builtin, mmc_blk_get_card_by_name() for module). Also adds probe/remove hooks in block.c and declarations in block.h for the builtin path.

Tested on Broadcom STB platforms (ARM64) with SDHCI controllers, verified panic dump recovery across multiple panic/reboot cycles with kmsg, pmsg, and console pstore.

Previous submissions and related work:
RFC v1: https://lore.kernel.org/linux-mmc/[email protected]/
RFC v2: https://lore.kernel.org/linux-mmc/[email protected]/
Marvell MMC pstore attempt (2020):

    https://lore.kernel.org/linux-mmc/[email protected]/

pstore/blk documentation:
https://www.kernel.org/doc/html/latest/admin-guide/pstore-blk.html

Kamal Dasu (4):
mmc: core: Add panic-context host operations for pstore backends
mmc: sdhci: Implement panic-context write support
mmc: block: Add helper to look up mmc_card by device name
mmc: core: Add MMC pstore backend driver

 MAINTAINERS                  |    6 +
 drivers/mmc/core/Kconfig     |   12 +
 drivers/mmc/core/Makefile    |    1 +
 drivers/mmc/core/block.c     |   56 ++
 drivers/mmc/core/block.h     |   18 +
 drivers/mmc/core/core.c      |   23 +
 drivers/mmc/core/mmcpstore.c | 1512 ++++++++++++++++++++++++++++++++++
 drivers/mmc/host/sdhci.c     |  164 +++-
 drivers/mmc/host/sdhci.h     |    6 +
 include/linux/mmc/host.h     |   12 +
 10 files changed, 1806 insertions(+), 4 deletions(-)
 create mode 100644 drivers/mmc/core/mmcpstore.c
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v3 1/4 mmc: core: Add panic-context host operations for pstore backends

Add three new optional callbacks to struct mmc_host_ops for panic-safe MMC I/O:

- panic_prepare: drain in-flight requests and prepare for polled I/O
- panic_poll_completion: poll for request completion without interrupts
- panic_complete: restore normal host state after panic I/O

Add mmc_panic_claim_host() which uses WRITE_ONCE() to claim the host without taking the spin lock, since during panic other CPUs are stopped and may hold the lock.

---
 drivers/mmc/core/core.c  | 23 +++++++++++++++++++++++
 include/linux/mmc/host.h | 12 ++++++++++++
 2 files changed, 35 insertions(+)
drivers/mmc/core/core.c +23 -0
index 860378bea557..5326b246b4f2 100644
@@ -860,6 +860,29 @@ void mmc_release_host(struct mmc_host *host)
 }
 EXPORT_SYMBOL(mmc_release_host);
 
+/**
+ *	mmc_panic_claim_host - force-claim a host in panic context
+ *	@host: mmc host to claim
+ *
+ *	Force-claims the MMC host without locking. During kernel panic
+ *	other CPUs are stopped and may be holding mmc_host->lock (e.g.
+ *	inside __mmc_claim_host or mmc_release_host). Unlike sdhci_host->lock
+ *	which is freed by the hardware drain+reset, mmc_host->lock has no
+ *	hardware counterpart, so we must bypass it with WRITE_ONCE.
+ */
+void mmc_panic_claim_host(struct mmc_host *host)
+{
+	if (!host)
+		return;
+
+	WRITE_ONCE(host->claimed, 1);
+	host->claimer = &host->default_ctx;
+	host->claimer->task = current;
+	WRITE_ONCE(host->claim_cnt, 1);
+	WRITE_ONCE(host->ongoing_mrq, NULL);
+}
+EXPORT_SYMBOL(mmc_panic_claim_host);
+
 /*
  * This is a helper function, which fetches a runtime pm reference for the
  * card device and also claims the host.
include/linux/mmc/host.h +12 -0
index ba84f02c2a10..cd44b62d29cb 100644
@@ -272,6 +272,16 @@ struct mmc_host_ops {
 	 * negative errno in case of a failure or zero for success.
 	 */
 	int	(*uhs2_control)(struct mmc_host *host, enum sd_uhs2_operation op);
+
+	/*
+	 * Optional panic-context ops for pstore backends that write to MMC
+	 * during kernel panic with interrupts disabled.
+	 */
+	int	(*panic_prepare)(struct mmc_host *host);
+	bool	(*panic_poll_completion)(struct mmc_host *host,
+					 struct mmc_request *mrq);
+	void	(*panic_complete)(struct mmc_host *host,
+				  struct mmc_request *mrq);
 };
 
 struct mmc_cqe_ops {
@@ -758,4 +768,6 @@ int mmc_send_abort_tuning(struct mmc_host *host, u32 opcode);
 int mmc_get_ext_csd(struct mmc_card *card, u8 **new_ext_csd);
 int mmc_read_tuning(struct mmc_host *host, unsigned int blksz, unsigned int blocks);
 
+void mmc_panic_claim_host(struct mmc_host *host);
+
 #endif /* LINUX_MMC_HOST_H */
Signature · 1 line
2.34.1
author
#2 lore raw

PATCH v3 2/4 mmc: sdhci: Implement panic-context write support

In reply to Kamal Dasu

Implement the panic-context host operations for SDHCI controllers:

sdhci_panic_prepare(): Reset the controller, drain any pending requests by polling Present State, and clear interrupt status to start from a known-good state.

sdhci_panic_poll_completion(): Poll for command and data completion using register reads instead of waiting for interrupts.

sdhci_panic_complete(): Clear interrupt status and restore the host to normal operation after panic I/O.

Make sdhci_send_command_retry() panic-safe by using mdelay() instead of usleep_range() when oops_in_progress is set, and suppress WARN output during panic.

Add oops_in_progress guards to sdhci_timeout_timer() and sdhci_timeout_data_timer() to prevent spurious timeout handling during panic writes.

---
 drivers/mmc/host/sdhci.c | 164 ++++++++++++++++++++++++++++++++++++++-
 drivers/mmc/host/sdhci.h |   6 ++
 2 files changed, 166 insertions(+), 4 deletions(-)
drivers/mmc/host/sdhci.c +160 -4
index ac7e11f37af7..311ab361ee32 100644
@@ -15,6 +15,7 @@
 #include <linux/ktime.h>
 #include <linux/highmem.h>
 #include <linux/io.h>
+#include <linux/iopoll.h>
 #include <linux/module.h>
 #include <linux/dma-mapping.h>
 #include <linux/slab.h>
@@ -1765,17 +1766,22 @@ static bool sdhci_send_command_retry(struct sdhci_host *host,
 
 	while (!sdhci_send_command(host, cmd)) {
 		if (!timeout--) {
-			pr_err("%s: Controller never released inhibit bit(s).\n",
-			       mmc_hostname(host->mmc));
+			if (!oops_in_progress) {
+				pr_err("%s: Controller never released inhibit bit(s).\n",
+				       mmc_hostname(host->mmc));
+				sdhci_dumpregs(host);
+			}
 			sdhci_err_stats_inc(host, CTRL_TIMEOUT);
-			sdhci_dumpregs(host);
 			cmd->error = -EIO;
 			return false;
 		}
 
 		spin_unlock_irqrestore(&host->lock, flags);
 
-		usleep_range(1000, 1250);
+		if (unlikely(oops_in_progress))
+			mdelay(1);
+		else
+			usleep_range(1000, 1250);
 
 		present = host->mmc->ops->get_cd(host->mmc);
 
@@ -3076,6 +3082,147 @@ static void sdhci_card_event(struct mmc_host *mmc)
 	spin_unlock_irqrestore(&host->lock, flags);
 }
 
+/*
+ * Panic-context operations for pstore backends.
+ * These run with interrupts disabled and other CPUs stopped.
+ */
+
+#define SDHCI_PANIC_POLL_ITERATIONS	2000
+#define SDHCI_PANIC_POLL_DELAY_US	500
+#define SDHCI_PANIC_MIN_POLL_COUNT	300
+#define SDHCI_PANIC_RESET_TIMEOUT_US	100000
+#define SDHCI_PANIC_DRAIN_TIMEOUT_US	100000
+
+/**
+ * sdhci_panic_prepare - Prepare SDHCI controller for panic-context I/O
+ *
+ * Called during kernel panic. Drains any in-flight request, resets the
+ * CMD and DATA lines, then clears software state under spinlock.
+ * The drain + reset ensures no stopped CPU is still inside sdhci_irq
+ * holding host->lock by the time we take it.
+ */
+int sdhci_panic_prepare(struct mmc_host *mmc)
+{
+	struct sdhci_host *host = mmc_priv(mmc);
+	unsigned long flags;
+	u32 present;
+	u8 val;
+	int ret;
+
+	/*
+	 * If the controller has a request in flight, give it a short
+	 * bounded time to finish. The CMD/DATA reset below will
+	 * force-abort anything that doesn't complete in time.
+	 */
+	present = sdhci_readl(host, SDHCI_PRESENT_STATE);
+	if (present & (SDHCI_CMD_INHIBIT | SDHCI_DATA_INHIBIT)) {
+		readl_poll_timeout_atomic(host->ioaddr + SDHCI_PRESENT_STATE,
+					  present,
+					  !(present & (SDHCI_CMD_INHIBIT |
+						       SDHCI_DATA_INHIBIT)),
+					  10, SDHCI_PANIC_DRAIN_TIMEOUT_US);
+	}
+
+	sdhci_writeb(host, SDHCI_RESET_CMD | SDHCI_RESET_DATA,
+		     SDHCI_SOFTWARE_RESET);
+
+	ret = readb_poll_timeout_atomic(host->ioaddr + SDHCI_SOFTWARE_RESET,
+					val, !(val & (SDHCI_RESET_CMD | SDHCI_RESET_DATA)),
+					10, SDHCI_PANIC_RESET_TIMEOUT_US);
+
+	spin_lock_irqsave(&host->lock, flags);
+	host->cmd = NULL;
+	host->data = NULL;
+	host->data_cmd = NULL;
+	host->mrqs_done[0] = NULL;
+	host->mrqs_done[1] = NULL;
+	spin_unlock_irqrestore(&host->lock, flags);
+
+	if (host->ops && host->ops->panic_prepare)
+		host->ops->panic_prepare(host);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(sdhci_panic_prepare);
+
+/**
+ * sdhci_panic_poll_completion - Poll SDHCI registers for request completion
+ *
+ * Checks interrupt status and present state registers to determine if a
+ * request has completed. Used during panic when interrupts are disabled.
+ */
+bool sdhci_panic_poll_completion(struct mmc_host *mmc, struct mmc_request *mrq)
+{
+	struct sdhci_host *host = mmc_priv(mmc);
+	unsigned int poll_count;
+	u32 int_status, present;
+
+	for (poll_count = 0; poll_count < SDHCI_PANIC_POLL_ITERATIONS;
+	     poll_count++) {
+		cpu_relax();
+		udelay(SDHCI_PANIC_POLL_DELAY_US);
+
+		int_status = sdhci_readl(host, SDHCI_INT_STATUS);
+
+		if (int_status & SDHCI_INT_ERROR) {
+			if (mrq->cmd)
+				mrq->cmd->error = -EIO;
+			if (mrq->data)
+				mrq->data->error = -EIO;
+			sdhci_writel(host, int_status, SDHCI_INT_STATUS);
+			return true;
+		}
+
+		if (int_status & SDHCI_INT_RESPONSE)
+			sdhci_writel(host, SDHCI_INT_RESPONSE,
+				     SDHCI_INT_STATUS);
+
+		if (int_status & SDHCI_INT_DATA_END)
+			sdhci_writel(host, SDHCI_INT_DATA_END,
+				     SDHCI_INT_STATUS);
+
+		/*
+		 * Use the same completion heuristic as the working v5
+		 * implementation: after a minimum number of poll
+		 * iterations, treat the request as complete when the
+		 * DATA_INHIBIT bit clears (controller is idle).
+		 */
+		if (poll_count >= SDHCI_PANIC_MIN_POLL_COUNT) {
+			present = sdhci_readl(host, SDHCI_PRESENT_STATE);
+			if (!(present & SDHCI_DATA_INHIBIT))
+				return true;
+		}
+	}
+
+	if (mrq->cmd)
+		mrq->cmd->error = -ETIMEDOUT;
+	if (mrq->data)
+		mrq->data->error = -ETIMEDOUT;
+	return false;
+}
+EXPORT_SYMBOL_GPL(sdhci_panic_poll_completion);
+
+/**
+ * sdhci_panic_complete - Clean up SDHCI state after a panic-context request
+ *
+ * Clears host software state under spinlock so the next panic request
+ * starts clean.
+ */
+void sdhci_panic_complete(struct mmc_host *mmc, struct mmc_request *mrq)
+{
+	struct sdhci_host *host = mmc_priv(mmc);
+	unsigned long flags;
+
+	spin_lock_irqsave(&host->lock, flags);
+	host->cmd = NULL;
+	host->data = NULL;
+	host->data_cmd = NULL;
+	host->mrqs_done[0] = NULL;
+	host->mrqs_done[1] = NULL;
+	spin_unlock_irqrestore(&host->lock, flags);
+}
+EXPORT_SYMBOL_GPL(sdhci_panic_complete);
+
 static const struct mmc_host_ops sdhci_ops = {
 	.request	= sdhci_request,
 	.post_req	= sdhci_post_req,
@@ -3091,6 +3238,9 @@ static const struct mmc_host_ops sdhci_ops = {
 	.execute_tuning			= sdhci_execute_tuning,
 	.card_event			= sdhci_card_event,
 	.card_busy	= sdhci_card_busy,
+	.panic_prepare			= sdhci_panic_prepare,
+	.panic_poll_completion		= sdhci_panic_poll_completion,
+	.panic_complete			= sdhci_panic_complete,
 };
 
 /*****************************************************************************\
@@ -3242,6 +3392,9 @@ static void sdhci_timeout_timer(struct timer_list *t)
 
 	host = timer_container_of(host, t, timer);
 
+	if (oops_in_progress)
+		return;
+
 	spin_lock_irqsave(&host->lock, flags);
 
 	if (host->cmd && !sdhci_data_line_cmd(host->cmd)) {
@@ -3264,6 +3417,9 @@ static void sdhci_timeout_data_timer(struct timer_list *t)
 
 	host = timer_container_of(host, t, data_timer);
 
+	if (oops_in_progress)
+		return;
+
 	spin_lock_irqsave(&host->lock, flags);
 
 	if (host->data || host->data_cmd ||
drivers/mmc/host/sdhci.h +6 -0
index b6a571d866fa..396eca56439f 100644
@@ -724,6 +724,7 @@ struct sdhci_ops {
 	void    (*dump_vendor_regs)(struct sdhci_host *host);
 	void	(*dump_uhs2_regs)(struct sdhci_host *host);
 	void    (*uhs2_pre_detect_init)(struct sdhci_host *host);
+	void	(*panic_prepare)(struct sdhci_host *host);
 };
 
 #ifdef CONFIG_MMC_SDHCI_IO_ACCESSORS
@@ -906,6 +907,11 @@ void sdhci_switch_external_dma(struct sdhci_host *host, bool en);
 void sdhci_set_data_timeout_irq(struct sdhci_host *host, bool enable);
 void __sdhci_set_timeout(struct sdhci_host *host, struct mmc_command *cmd);
 
+int sdhci_panic_prepare(struct mmc_host *mmc);
+bool sdhci_panic_poll_completion(struct mmc_host *mmc,
+				 struct mmc_request *mrq);
+void sdhci_panic_complete(struct mmc_host *mmc, struct mmc_request *mrq);
+
 #if defined(CONFIG_DYNAMIC_DEBUG) || \
 	(defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
 #define SDHCI_DBG_ANYWAY 0
Signature · 1 line
2.34.1
#3 lore raw

Re: [PATCH v3 2/4] mmc: sdhci: Implement panic-context write support

kernel test robot noticed the following build warnings:

Hi Kamal,

kernel test robot noticed the following build warnings:

[auto build test WARNING on linus/master]
[also build test WARNING on v7.0-rc4 next-20260319]
[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/Kamal-Dasu/mmc-core-Add-panic-context-host-operations-for-pstore-backends/20260320-064639
base:   linus/master
patch link:    https://lore.kernel.org/r/20260319185705.1516950-3-kamal.dasu%40broadcom.com
patch subject: [PATCH v3 2/4] mmc: sdhci: Implement panic-context write support
config: x86_64-rhel-9.4 (https://download.01.org/0day-ci/archive/20260320/[email protected]/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260320/[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 >>):

>> Warning: drivers/mmc/host/sdhci.c:3104 function parameter 'mmc' not described in 'sdhci_panic_prepare'
>> Warning: drivers/mmc/host/sdhci.c:3154 function parameter 'mmc' not described in 'sdhci_panic_poll_completion'
>> Warning: drivers/mmc/host/sdhci.c:3154 function parameter 'mrq' not described in 'sdhci_panic_poll_completion'
>> Warning: drivers/mmc/host/sdhci.c:3211 function parameter 'mmc' not described in 'sdhci_panic_complete'
>> Warning: drivers/mmc/host/sdhci.c:3211 function parameter 'mrq' not described in 'sdhci_panic_complete'
>> Warning: drivers/mmc/host/sdhci.c:3104 function parameter 'mmc' not described in 'sdhci_panic_prepare'
>> Warning: drivers/mmc/host/sdhci.c:3154 function parameter 'mmc' not described in 'sdhci_panic_poll_completion'
>> Warning: drivers/mmc/host/sdhci.c:3154 function parameter 'mrq' not described in 'sdhci_panic_poll_completion'
>> Warning: drivers/mmc/host/sdhci.c:3211 function parameter 'mmc' not described in 'sdhci_panic_complete'
>> Warning: drivers/mmc/host/sdhci.c:3211 function parameter 'mrq' not described in 'sdhci_panic_complete'
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#4 lore raw

Re: [PATCH v3 2/4] mmc: sdhci: Implement panic-context write support

In reply to Kamal Dasu
kernel test robot noticed the following build warnings:

Hi Kamal,

kernel test robot noticed the following build warnings:

[auto build test WARNING on linus/master]
[also build test WARNING on v7.0-rc4 next-20260319]
[cannot apply to ulf-hansson-mmc-mirror/next]
[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/Kamal-Dasu/mmc-core-Add-panic-context-host-operations-for-pstore-backends/20260320-064639
base:   linus/master
patch link:    https://lore.kernel.org/r/20260319185705.1516950-3-kamal.dasu%40broadcom.com
patch subject: [PATCH v3 2/4] mmc: sdhci: Implement panic-context write support
config: i386-randconfig-r134-20260320 (https://download.01.org/0day-ci/archive/20260320/[email protected]/config)
compiler: gcc-13 (Debian 13.3.0-16) 13.3.0
sparse: v0.6.5-rc1
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260320/[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 >>):

>> Warning: drivers/mmc/host/sdhci.c:3104 function parameter 'mmc' not described in 'sdhci_panic_prepare'
>> Warning: drivers/mmc/host/sdhci.c:3154 function parameter 'mmc' not described in 'sdhci_panic_poll_completion'
>> Warning: drivers/mmc/host/sdhci.c:3154 function parameter 'mrq' not described in 'sdhci_panic_poll_completion'
>> Warning: drivers/mmc/host/sdhci.c:3211 function parameter 'mmc' not described in 'sdhci_panic_complete'
>> Warning: drivers/mmc/host/sdhci.c:3211 function parameter 'mrq' not described in 'sdhci_panic_complete'
>> Warning: drivers/mmc/host/sdhci.c:3104 function parameter 'mmc' not described in 'sdhci_panic_prepare'
>> Warning: drivers/mmc/host/sdhci.c:3154 function parameter 'mmc' not described in 'sdhci_panic_poll_completion'
>> Warning: drivers/mmc/host/sdhci.c:3154 function parameter 'mrq' not described in 'sdhci_panic_poll_completion'
>> Warning: drivers/mmc/host/sdhci.c:3211 function parameter 'mmc' not described in 'sdhci_panic_complete'
>> Warning: drivers/mmc/host/sdhci.c:3211 function parameter 'mrq' not described in 'sdhci_panic_complete'
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
author
#5 lore raw

PATCH v3 3/4 mmc: block: Add helper to look up mmc_card by device name

In reply to Kamal Dasu

Add mmc_blk_get_card_by_name() which resolves an MMC block device name (e.g., "mmcblk1") to its associated struct mmc_card by opening the block device and traversing gendisk to the mmc_blk_data private data.

This is needed by the mmcpstore backend driver to find the card associated with a given pstore_blk block device path. When mmcpstore is built as a module, the eMMC card is already probed by the time the module loads, so the helper can look it up directly.

---
 drivers/mmc/core/block.c | 54 ++++++++++++++++++++++++++++++++++++++++
 drivers/mmc/core/block.h |  4 +++
 2 files changed, 58 insertions(+)
drivers/mmc/core/block.c +54 -0
index 05ee76cb0a08..91e3a778d5b2 100644
@@ -3441,6 +3441,60 @@ static void __exit mmc_blk_exit(void)
 	bus_unregister(&mmc_rpmb_bus_type);
 }
 
+/**
+ * mmc_blk_get_card_by_name - Get mmc_card from device name
+ * @device_name: Name of the MMC device (e.g., "mmcblk1")
+ *
+ * Resolves an MMC block device name to its associated struct mmc_card.
+ * Used by the mmcpstore backend driver (when built as a module) to find
+ * the card associated with a given pstore_blk block device path.
+ *
+ * Returns: mmc_card pointer on success, NULL on failure
+ */
+struct mmc_card *mmc_blk_get_card_by_name(const char *device_name)
+{
+	struct file *bdev_file;
+	struct block_device *bdev;
+	struct gendisk *disk;
+	struct mmc_blk_data *md;
+	struct mmc_card *card = NULL;
+	char dev_path[32];
+
+	if (!device_name)
+		return NULL;
+
+	snprintf(dev_path, sizeof(dev_path), "/dev/%s", device_name);
+
+	bdev_file = bdev_file_open_by_path(dev_path, BLK_OPEN_READ, NULL, NULL);
+	if (IS_ERR(bdev_file)) {
+		pr_debug("mmc_blk: Failed to open block device %s: %ld\n",
+			 dev_path, PTR_ERR(bdev_file));
+		return NULL;
+	}
+	bdev = file_bdev(bdev_file);
+
+	disk = bdev->bd_disk;
+	if (!disk) {
+		pr_err("mmc_blk: No gendisk found for %s\n", dev_path);
+		goto out_put_bdev;
+	}
+
+	md = disk->private_data;
+	if (!md) {
+		pr_debug("mmc_blk: No mmc_blk_data found for %s\n", dev_path);
+		goto out_put_bdev;
+	}
+
+	card = md->queue.card;
+	if (!card)
+		pr_err("mmc_blk: No mmc_card found for %s\n", dev_path);
+
+out_put_bdev:
+	fput(bdev_file);
+	return card;
+}
+EXPORT_SYMBOL_GPL(mmc_blk_get_card_by_name);
+
 module_init(mmc_blk_init);
 module_exit(mmc_blk_exit);
 
drivers/mmc/core/block.h +4 -0
index 31153f656f41..08798c56dcce 100644
@@ -17,4 +17,8 @@ struct work_struct;
 
 void mmc_blk_mq_complete_work(struct work_struct *work);
 
+/* MMC block device helper for mmcpstore */
+struct mmc_card;
+struct mmc_card *mmc_blk_get_card_by_name(const char *device_name);
+
 #endif
Signature · 1 line
2.34.1
author
#6 lore raw

PATCH v3 4/4 mmc: core: Add MMC pstore backend driver

In reply to Kamal Dasu

Add mmcpstore, a pstore backend driver that provides persistent storage for kernel crash logs and other pstore data on eMMC devices. The driver registers with the pstore_blk framework and performs direct MMC writes during kernel panic using the panic-context host operations.

Key features:
- Panic-safe writes using polled I/O with interrupts disabled
- Sector offset and count parameters for flexible partition usage
- Support for both module and builtin configurations
- PM suspend/resume support with eMMC hardware re-initialization
- Dual-path registration: direct probe callback when builtin, mmc_blk_get_card_by_name() lookup when loaded as module
- Console pstore support via atomic context detection: when called from printk's atomic console path, returns -EBUSY so pstore_zone defers the write to its workqueue. Console logging works but is not recommended when kmsg is enabled, as it generates constant flash writes for every kernel log message.

When CONFIG_MMC_PSTORE=y, mmc_blk_probe() calls mmcpstore_card_add() directly. When CONFIG_MMC_PSTORE=m, the module init uses mmc_blk_get_card_by_name() to look up the already-probed eMMC card. The IS_BUILTIN() guard in block.h ensures no cross-module symbol dependency.

Required kernel config:
CONFIG_PSTORE=y
CONFIG_PSTORE_BLK=m (or =y)
CONFIG_MMC_PSTORE=m (or =y)
CONFIG_PSTORE_PMSG=y (optional, for pmsg support) CONFIG_PSTORE_COMPRESS=y (optional, for compressed kmsg dumps) CONFIG_PSTORE_CONSOLE=y (optional, console log capture)

Module loading examples:

Basic usage with a dedicated eMMC partition:
modprobe pstore_blk blkdev=/dev/mmcblk1p5 kmsg_size=64 pmsg_size=32 modprobe mmcpstore

With console log capture:

    modprobe pstore_blk blkdev=/dev/mmcblk1p5 kmsg_size=64 pmsg_size=32 \
      console_size=32
    modprobe mmcpstore

Using a subset of sectors within a partition:
modprobe pstore_blk blkdev=/dev/mmcblk1p5 kmsg_size=64 pmsg_size=32 modprobe mmcpstore sector_offset=512 sector_count=512

Builtin configuration (kernel command line):

    pstore_blk.blkdev=/dev/mmcblk1p5 pstore_blk.kmsg_size=64 \
      pstore_blk.pmsg_size=32

Verify stored pstore data after a panic reboot:
mount -t pstore pstore /sys/fs/pstore
ls /sys/fs/pstore/
cat /sys/fs/pstore/dmesg-pstore_blk-0
cat /sys/fs/pstore/pmsg-pstore_blk-0

Module parameters:
sector_offset Starting sector within partition (default: 0)
sector_count Number of sectors to use (default: entire partition)

Tested with ARM and ARM64 builds on Broadcom STB platforms with SDHCI controllers.

---
 MAINTAINERS                  |    6 +
 drivers/mmc/core/Kconfig     |   12 +
 drivers/mmc/core/Makefile    |    1 +
 drivers/mmc/core/block.c     |    2 +
 drivers/mmc/core/block.h     |   14 +
 drivers/mmc/core/mmcpstore.c | 1519 ++++++++++++++++++++++++++++++++++
 6 files changed, 1554 insertions(+)
 create mode 100644 drivers/mmc/core/mmcpstore.c
MAINTAINERS +6 -0
index 96ea84948d76..2f8470c3c480 100644
@@ -18087,6 +18087,12 @@ F:	drivers/mmc/
 F:	include/linux/mmc/
 F:	include/uapi/linux/mmc/
 
+MULTIMEDIA CARD (MMC) PSTORE BACKEND
+M:	Kamal Dasu <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/mmc/core/mmcpstore.c
+
 MULTIPLEXER SUBSYSTEM
 M:	Peter Rosin <[email protected]>
 S:	Odd Fixes
drivers/mmc/core/Kconfig +12 -0
index 14d2ecbb04d3..961c76f4b6c7 100644
@@ -23,6 +23,18 @@ config PWRSEQ_SD8787
 	  This driver can also be built as a module. If so, the module
 	  will be called pwrseq_sd8787.
 
+config MMC_PSTORE
+	tristate "MMC pstore backend support"
+	depends on MMC_BLOCK
+	select PSTORE_BLK
+	help
+	  This option enables MMC devices to be used as pstore backends.
+	  This allows kernel crash logs and other pstore data to be stored
+	  on MMC/SD storage devices for post-mortem analysis.
+
+	  If you want to store kernel crash logs on MMC devices, say Y.
+
+
 config PWRSEQ_SIMPLE
 	tristate "Simple HW reset support for MMC"
 	default y
drivers/mmc/core/Makefile +1 -0
index 15b067e8b0d1..6b7bbfd2adbe 100644
@@ -19,3 +19,4 @@ mmc_block-objs			:= block.o queue.o
 obj-$(CONFIG_MMC_TEST)		+= mmc_test.o
 obj-$(CONFIG_SDIO_UART)		+= sdio_uart.o
 mmc_core-$(CONFIG_MMC_CRYPTO)	+= crypto.o
+obj-$(CONFIG_MMC_PSTORE)	+= mmcpstore.o
drivers/mmc/core/block.c +2 -0
index 91e3a778d5b2..c4db0d96139b 100644
@@ -3305,6 +3305,7 @@ static int mmc_blk_probe(struct mmc_card *card)
 	}
 
 	mmc_blk_rpmb_add(card);
+	mmcpstore_card_add(card, md->disk);
 
 	return 0;
 
@@ -3320,6 +3321,7 @@ static void mmc_blk_remove(struct mmc_card *card)
 {
 	struct mmc_blk_data *md = dev_get_drvdata(&card->dev);
 
+	mmcpstore_card_remove(card);
 	mmc_blk_remove_debugfs(card, md);
 	mmc_blk_remove_parts(card, md);
 	pm_runtime_get_sync(&card->dev);
drivers/mmc/core/block.h +14 -0
index 08798c56dcce..cb58c1366c1d 100644
@@ -19,6 +19,20 @@ void mmc_blk_mq_complete_work(struct work_struct *work);
 
 /* MMC block device helper for mmcpstore */
 struct mmc_card;
+struct gendisk;
 struct mmc_card *mmc_blk_get_card_by_name(const char *device_name);
 
+/*
+ * Builtin mmcpstore: called directly from mmc_blk_probe/remove.
+ * Module mmcpstore: stubs — module uses mmc_blk_get_card_by_name() instead.
+ */
+#if IS_BUILTIN(CONFIG_MMC_PSTORE)
+void mmcpstore_card_add(struct mmc_card *card, struct gendisk *disk);
+void mmcpstore_card_remove(struct mmc_card *card);
+#else
+static inline void mmcpstore_card_add(struct mmc_card *card,
+				      struct gendisk *disk) {}
+static inline void mmcpstore_card_remove(struct mmc_card *card) {}
+#endif
+
 #endif
drivers/mmc/core/mmcpstore.c new file +1519 -0

1,519 lines not on this page · raw message

Signature · 1 line
2.34.1
#7 lore raw

Re: [PATCH v3 4/4] mmc: core: Add MMC pstore backend driver

Quoted 4 lines · Kamal Dasu

Add mmcpstore, a pstore backend driver that provides persistent storage for kernel crash logs and other pstore data on eMMC devices. The driver registers with the pstore_blk framework and performs direct MMC writes during kernel panic using the panic-context host operations.

I'm glad to see another pstore_zone user! I can't speak to the MMC bits, but the interface to pstore looks correct to me on a first pass examination.

Thanks for picking this up again!

Signature · 1 line
Kees Cook
#8 lore raw

Re: [PATCH v3 4/4] mmc: core: Add MMC pstore backend driver

In reply to Kamal Dasu
kernel test robot noticed the following build warnings:

Hi Kamal,

kernel test robot noticed the following build warnings:

[auto build test WARNING on linus/master]
[also build test WARNING on v7.0-rc4 next-20260319]
[cannot apply to ulf-hansson-mmc-mirror/next]
[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/Kamal-Dasu/mmc-core-Add-panic-context-host-operations-for-pstore-backends/20260320-064639
base:   linus/master
patch link:    https://lore.kernel.org/r/20260319185705.1516950-5-kamal.dasu%40broadcom.com
patch subject: [PATCH v3 4/4] mmc: core: Add MMC pstore backend driver
config: m68k-allyesconfig (https://download.01.org/0day-ci/archive/20260320/[email protected]/config)
compiler: m68k-linux-gcc (GCC) 15.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260320/[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 >>):

drivers/mmc/core/mmcpstore.c: In function 'mmcpstore_register_for_card':

>> drivers/mmc/core/mmcpstore.c:1016:23: warning: variable 'offset_bytes' set but not used [-Wunused-but-set-variable]
    1016 |         unsigned long offset_bytes;
         |                       ^~~~~~~~~~~~
--
>> Warning: drivers/mmc/core/mmcpstore.c:250 function parameter 'sect_offset' not described in 'mmcpstore_do_request_internal'
>> Warning: drivers/mmc/core/mmcpstore.c:573 expecting prototype for mmcpstore_read(). Prototype was for mmcpstore_read_zone() instead
>> Warning: drivers/mmc/core/mmcpstore.c:1248 function parameter 'disk' not described in 'mmcpstore_card_add'
>> Warning: drivers/mmc/core/mmcpstore.c:250 function parameter 'sect_offset' not described in 'mmcpstore_do_request_internal'
>> Warning: drivers/mmc/core/mmcpstore.c:1248 function parameter 'disk' not described in 'mmcpstore_card_add'

vim +/offset_bytes +1016 drivers/mmc/core/mmcpstore.c

998
999 /**
1000 * mmcpstore_register_for_card - Register pstore for specific MMC card
1001 * @card: MMC card to register pstore for
1002 * @dev_name_param: Device path (e.g., "/dev/mmcblk1p5")
1003 * @disk: gendisk for the card (non-NULL for builtin path, NULL for module)
1004 *
1005 * Returns: 0 on success, negative error on failure
1006 */
1007 static int mmcpstore_register_for_card(struct mmc_card *card,
1008 const char *dev_name_param,
1009 struct gendisk *disk)
1010 {
1011 struct mmcpstore_context *cxt;
1012 struct pstore_blk_config conf;
1013 struct file *bdev_file;
1014 struct block_device *bdev;
1015 sector_t partition_sectors;

> 1016		unsigned long offset_bytes;

1017 unsigned long required_size;
1018 unsigned long kmsg_records;
1019 int ret;
1020
1021 /*
1022 * Open the block device to get partition start sector and size.
1023 * When called from mmc_blk_probe() (builtin path), /dev/ may not
1024 * be mounted yet, so use the gendisk + partition number to look
1025 * up the dev_t directly.
1026 */
1027 if (disk) {
1028 int partno = mmcpstore_extract_partno(dev_name_param);
1029 dev_t devt;
1030
1031 if (partno < 0) {
1032 pr_warn("Cannot parse partition from %s\n",
1033 dev_name_param);
1034 return -EINVAL;
1035 }
1036 devt = part_devt(disk, partno);
1037 if (!devt) {
1038 pr_warn("Partition %d not found on %s\n",
1039 partno, disk->disk_name);
1040 return -ENODEV;
1041 }
1042 bdev_file = bdev_file_open_by_dev(devt, BLK_OPEN_READ,
1043 NULL, NULL);
1044 } else {
1045 bdev_file = bdev_file_open_by_path(dev_name_param,
1046 BLK_OPEN_READ, NULL, NULL);
1047 }
1048 if (IS_ERR(bdev_file)) {
1049 ret = PTR_ERR(bdev_file);
1050 pr_warn("Failed to open device %s: %d\n", dev_name_param, ret);
1051 return ret;
1052 }
1053 bdev = file_bdev(bdev_file);
1054
1055 cxt = mmcpstore_ctx;
1056 if (!cxt) {
1057 pr_err("No context available\n");
1058 fput(bdev_file);
1059 return -ENODEV;
1060 }
1061
1062 /* pre-allocated buffer for alignment handling */
1063 cxt->buffer_size = MMC_PSTORE_MAX_BUFFER_SIZE;
1064 cxt->buffer = kmalloc(cxt->buffer_size, GFP_KERNEL);
1065 if (!cxt->buffer) {
1066 pr_err("Failed to allocate %zu bytes for pstore buffer\n",
1067 cxt->buffer_size);
1068 fput(bdev_file);
1069 return -ENOMEM;
1070 }
1071
1072 if (!(card->host->caps & MMC_CAP_NONREMOVABLE)) {
1073 dev_err(&card->dev, "MMC pstore only supports non-removable cards (eMMC)\n");
1074 dev_err(&card->dev, "This card is removable and not suitable for pstore\n");
1075 ret = -EOPNOTSUPP;
1076 goto err_free;
1077 }
1078
1079 /* Initialize context */
1080 cxt->card = card;
1081 strscpy(cxt->card_name, dev_name_param, sizeof(cxt->card_name));
1082 cxt->start_sect = bdev->bd_start_sect;
1083 cxt->size = bdev_nr_bytes(bdev);
1084
1085 /* Apply user-specified sector offset and count within the partition */
1086 if (part_sect_ofs > 0 || part_sect_cnt > 0) {
1087 if ((part_sect_ofs > 0 && part_sect_cnt == 0) ||
1088 (part_sect_ofs == 0 && part_sect_cnt > 0)) {
1089 dev_err(&card->dev, "sector_offset and sector_count must be specified\n");
1090 ret = -EINVAL;
1091 goto err_free;
1092 }
1093
1094 /* Validate offset and count */
1095 partition_sectors = cxt->size >> 9;
1096 offset_bytes = part_sect_ofs * MMC_PSTORE_SECTOR_SIZE;
1097
1098 if (part_sect_ofs >= partition_sectors) {
1099 dev_err(&card->dev, "Sector offset %lu >= partition size %llu sectors\n",
1100 part_sect_ofs, partition_sectors);
1101 ret = -EINVAL;
1102 goto err_free;
1103 }
1104
1105 if (part_sect_ofs + part_sect_cnt > partition_sectors) {
1106 dev_err(&card->dev, "Sector range %lu-%lu exceeds partition size %llu sectors\n",
1107 part_sect_ofs,
1108 part_sect_ofs + part_sect_cnt - 1,
1109 partition_sectors);
1110 ret = -EINVAL;
1111 goto err_free;
1112 }
1113
1114 cxt->start_sect += part_sect_ofs;
1115 cxt->size = part_sect_cnt * MMC_PSTORE_SECTOR_SIZE;
1116
1117 pr_info("Pstore will use: sectors %lu-%lu (%llu bytes total)\n",
1118 part_sect_ofs, part_sect_ofs + part_sect_cnt - 1,
1119 cxt->size);
1120 }
1121
1122 fput(bdev_file);
1123
1124 /* Configure pstore */
1125 memset(&conf, 0, sizeof(conf));
1126 strscpy(conf.device, dev_name_param, sizeof(conf.device));
1127 conf.max_reason = KMSG_DUMP_PANIC;
1128
1129 /* Fetch pstore configuration including sizes from module parameters */
1130 ret = pstore_blk_get_config(&conf);
1131 if (ret != 0) {
1132 pr_err("Failed to get pstore block config: %d\n", ret);
1133 goto err_free;
1134 }
1135
1136 /* Validate size requirements */
1137 ret = mmcpstore_calculate_sizes(cxt, &conf, &required_size,
1138 &kmsg_records);
1139 if (ret)
1140 goto err_free;
1141
1142 pr_debug("Pstore requirements: kmsg=%lu KB, pmsg=%lu KB, console=%lu KB, ftrace=%lu KB\n",
1143 MMC_PSTORE_BYTES_TO_KB(conf.kmsg_size),
1144 MMC_PSTORE_BYTES_TO_KB(conf.pmsg_size),
1145 MMC_PSTORE_BYTES_TO_KB(conf.console_size),
1146 MMC_PSTORE_BYTES_TO_KB(conf.ftrace_size));
1147 pr_debug("Pstore capacity: ~%lu kmsg records possible (%lu KB each, varies with compression)\n",
1148 kmsg_records, MMC_PSTORE_BYTES_TO_KB(conf.kmsg_size));
1149
1150 /* Set up pstore device info */
1151 cxt->dev.flags = 0; /* Support all backends */
1152 if (conf.kmsg_size > 0)
1153 cxt->dev.flags |= PSTORE_FLAGS_DMESG;
1154 if (conf.pmsg_size > 0)
1155 cxt->dev.flags |= PSTORE_FLAGS_PMSG;
1156 if (conf.console_size > 0)
1157 cxt->dev.flags |= PSTORE_FLAGS_CONSOLE;
1158 if (conf.ftrace_size > 0)
1159 cxt->dev.flags |= PSTORE_FLAGS_FTRACE;
1160
1161 /* Set up zone structure for pstore/zone API */
1162 cxt->dev.zone.read = mmcpstore_read_zone;
1163 cxt->dev.zone.write = mmcpstore_write;
1164 cxt->dev.zone.panic_write = mmcpstore_panic_write;
1165 cxt->dev.zone.total_size = cxt->size;
1166 cxt->dev.zone.kmsg_size = conf.kmsg_size;
1167 cxt->dev.zone.pmsg_size = conf.pmsg_size;
1168 cxt->dev.zone.console_size = conf.console_size;
1169 cxt->dev.zone.ftrace_size = conf.ftrace_size;
1170 cxt->dev.zone.max_reason = conf.max_reason;
1171 cxt->dev.zone.name = "mmcpstore";
1172 cxt->dev.zone.owner = THIS_MODULE;
1173
1174 mutex_init(&cxt->lock);
1175
1176 /*
1177 * Set state to READY before registration because register_pstore_device()
1178 * triggers pstore_zone recovery which calls our read callback, and the
1179 * read callback requires state == READY to proceed.
1180 */
1181 mutex_lock(&mmcpstore_global_lock);
1182 cxt->state = MMCPSTORE_STATE_READY;
1183 mutex_unlock(&mmcpstore_global_lock);
1184
1185 ret = register_pstore_device(&cxt->dev);
1186 if (ret) {
1187 dev_err(&card->dev, "Failed to register pstore device: %d\n",
1188 ret);
1189 mutex_lock(&mmcpstore_global_lock);
1190 cxt->state = MMCPSTORE_STATE_UNINITIALIZED;
1191 mutex_unlock(&mmcpstore_global_lock);
1192 goto err_free;
1193 }
1194
1195 dev_info(&card->dev, "MMC pstore backend registered successfully\n");
1196 dev_info(&card->dev, "Device: %s, Size: %llu bytes (%llu KB)\n",
1197 dev_name_param, cxt->size, MMC_PSTORE_BYTES_TO_KB(cxt->size));
1198 dev_info(&card->dev, "Start sector: %llu, Sector count: %llu\n",
1199 cxt->start_sect, cxt->size / MMC_PSTORE_SECTOR_SIZE);
1200 dev_info(&card->dev, "Pstore components: kmsg=%lu KB, pmsg=%lu KB, console=%lu KB, ftrace=%lu KB\n",
1201 MMC_PSTORE_BYTES_TO_KB(conf.kmsg_size),
1202 MMC_PSTORE_BYTES_TO_KB(conf.pmsg_size),
1203 MMC_PSTORE_BYTES_TO_KB(conf.console_size),
1204 MMC_PSTORE_BYTES_TO_KB(conf.ftrace_size));
1205
1206 return 0;
1207
1208 err_free:
1209 kfree(cxt->buffer);
1210 /* Don't free cxt here - it's the global context */
1211 return ret;
1212 }
1213

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
author
#9 lore raw

Re: [PATCH v3 4/4] mmc: core: Add MMC pstore backend driver

Quoted 42 lines · kernel test robot

Hi Kamal,

kernel test robot noticed the following build warnings:

[auto build test WARNING on linus/master]
[also build test WARNING on v7.0-rc4 next-20260319]
[cannot apply to ulf-hansson-mmc-mirror/next]
[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/Kamal-Dasu/mmc-core-Add-panic-context-host-operations-for-pstore-backends/20260320-064639
base: linus/master
patch link:
https://lore.kernel.org/r/20260319185705.1516950-5-kamal.dasu%40broadcom.com
patch subject: [PATCH v3 4/4] mmc: core: Add MMC pstore backend driver
config: m68k-allyesconfig (
https://download.01.org/0day-ci/archive/20260320/[email protected]/config
)
compiler: m68k-linux-gcc (GCC) 15.2.0
reproduce (this is a W=1 build): (
https://download.01.org/0day-ci/archive/20260320/[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 >>):

drivers/mmc/core/mmcpstore.c: In function 'mmcpstore_register_for_card':

Quoted 1 line
Quoted 1 line

drivers/mmc/core/mmcpstore.c:1016:23: warning: variable 'offset_bytes'

set but not used [-Wunused-but-set-variable]

    1016 |         unsigned long offset_bytes;
         |                       ^~~~~~~~~~~~

--

Quoted 1 line
Quoted 1 line

Warning: drivers/mmc/core/mmcpstore.c:250 function parameter

'sect_offset' not described in 'mmcpstore_do_request_internal'

Quoted 10 lines
Quoted 1 line
Quoted 1 line

Warning: drivers/mmc/core/mmcpstore.c:573 expecting prototype for

mmcpstore_read(). Prototype was for mmcpstore_read_zone() instead

Quoted 1 line
Quoted 1 line

Warning: drivers/mmc/core/mmcpstore.c:1248 function parameter 'disk'

not described in 'mmcpstore_card_add'

Quoted 1 line
Quoted 1 line

Warning: drivers/mmc/core/mmcpstore.c:250 function parameter

'sect_offset' not described in 'mmcpstore_do_request_internal'

Quoted 1 line
Quoted 1 line

Warning: drivers/mmc/core/mmcpstore.c:1248 function parameter 'disk'

not described in 'mmcpstore_card_add'

Fixed all warnings and sent a v4 version a couple of weeks back. Please review the v4 changes.

Quoted 251 lines

vim +/offset_bytes +1016 drivers/mmc/core/mmcpstore.c

   998
   999  /**
  1000   * mmcpstore_register_for_card - Register pstore for specific MMC
card
  1001   * @card: MMC card to register pstore for
  1002   * @dev_name_param: Device path (e.g., "/dev/mmcblk1p5")
  1003   * @disk: gendisk for the card (non-NULL for builtin path, NULL
for module)
  1004   *
  1005   * Returns: 0 on success, negative error on failure
  1006   */
  1007  static int mmcpstore_register_for_card(struct mmc_card *card,
  1008                                         const char *dev_name_param,
  1009                                         struct gendisk *disk)
  1010  {
  1011          struct mmcpstore_context *cxt;
  1012          struct pstore_blk_config conf;
  1013          struct file *bdev_file;
  1014          struct block_device *bdev;
  1015          sector_t partition_sectors;
> 1016          unsigned long offset_bytes;
  1017          unsigned long required_size;
  1018          unsigned long kmsg_records;
  1019          int ret;

1020
1021 /*
1022 * Open the block device to get partition start sector and
size.
1023 * When called from mmc_blk_probe() (builtin path), /dev/
may not
1024 * be mounted yet, so use the gendisk + partition number
to look
1025 * up the dev_t directly.
1026 */
1027 if (disk) {
1028 int partno =
mmcpstore_extract_partno(dev_name_param);
1029 dev_t devt;
1030
1031 if (partno < 0) {
1032 pr_warn("Cannot parse partition from %s\n",
1033 dev_name_param);
1034 return -EINVAL;

  1035                  }
  1036                  devt = part_devt(disk, partno);
  1037                  if (!devt) {

1038 pr_warn("Partition %d not found on %s\n",
1039 partno, disk->disk_name);
1040 return -ENODEV;
1041 }
1042 bdev_file = bdev_file_open_by_dev(devt,
BLK_OPEN_READ,
1043 NULL, NULL);
1044 } else {
1045 bdev_file = bdev_file_open_by_path(dev_name_param,
1046 BLK_OPEN_READ,
NULL, NULL);
1047 }
1048 if (IS_ERR(bdev_file)) {
1049 ret = PTR_ERR(bdev_file);
1050 pr_warn("Failed to open device %s: %d\n",
dev_name_param, ret);
1051 return ret;
1052 }
1053 bdev = file_bdev(bdev_file);
1054
1055 cxt = mmcpstore_ctx;
1056 if (!cxt) {

  1057                  pr_err("No context available\n");
  1058                  fput(bdev_file);
  1059                  return -ENODEV;
  1060          }
  1061
  1062          /* pre-allocated buffer for alignment handling */
  1063          cxt->buffer_size = MMC_PSTORE_MAX_BUFFER_SIZE;
  1064          cxt->buffer = kmalloc(cxt->buffer_size, GFP_KERNEL);
  1065          if (!cxt->buffer) {

1066 pr_err("Failed to allocate %zu bytes for pstore
buffer\n",
1067 cxt->buffer_size);
1068 fput(bdev_file);
1069 return -ENOMEM;
1070 }
1071
1072 if (!(card->host->caps & MMC_CAP_NONREMOVABLE)) {
1073 dev_err(&card->dev, "MMC pstore only supports
non-removable cards (eMMC)\n");
1074 dev_err(&card->dev, "This card is removable and
not suitable for pstore\n");
1075 ret = -EOPNOTSUPP;
1076 goto err_free;
1077 }
1078

  1079          /* Initialize context */
  1080          cxt->card = card;
  1081          strscpy(cxt->card_name, dev_name_param,

sizeof(cxt->card_name));
1082 cxt->start_sect = bdev->bd_start_sect;
1083 cxt->size = bdev_nr_bytes(bdev);
1084
1085 /* Apply user-specified sector offset and count within the
partition */
1086 if (part_sect_ofs > 0 || part_sect_cnt > 0) {
1087 if ((part_sect_ofs > 0 && part_sect_cnt == 0) ||
1088 (part_sect_ofs == 0 && part_sect_cnt > 0)) {
1089 dev_err(&card->dev, "sector_offset and
sector_count must be specified\n");
1090 ret = -EINVAL;
1091 goto err_free;
1092 }
1093

  1094                  /* Validate offset and count */
  1095                  partition_sectors = cxt->size >> 9;
  1096                  offset_bytes = part_sect_ofs *

MMC_PSTORE_SECTOR_SIZE;
1097
1098 if (part_sect_ofs >= partition_sectors) {
1099 dev_err(&card->dev, "Sector offset %lu >=
partition size %llu sectors\n",
1100 part_sect_ofs, partition_sectors);
1101 ret = -EINVAL;
1102 goto err_free;
1103 }
1104
1105 if (part_sect_ofs + part_sect_cnt >
partition_sectors) {
1106 dev_err(&card->dev, "Sector range %lu-%lu
exceeds partition size %llu sectors\n",

  1107                                  part_sect_ofs,
  1108                                  part_sect_ofs + part_sect_cnt - 1,
  1109                                  partition_sectors);

1110 ret = -EINVAL;
1111 goto err_free;
1112 }
1113
1114 cxt->start_sect += part_sect_ofs;
1115 cxt->size = part_sect_cnt * MMC_PSTORE_SECTOR_SIZE;
1116
1117 pr_info("Pstore will use: sectors %lu-%lu (%llu
bytes total)\n",
1118 part_sect_ofs, part_sect_ofs +
part_sect_cnt - 1,
1119 cxt->size);
1120 }
1121
1122 fput(bdev_file);
1123

  1124          /* Configure pstore */
  1125          memset(&conf, 0, sizeof(conf));
  1126          strscpy(conf.device, dev_name_param, sizeof(conf.device));
  1127          conf.max_reason = KMSG_DUMP_PANIC;

1128
1129 /* Fetch pstore configuration including sizes from module
parameters */
1130 ret = pstore_blk_get_config(&conf);
1131 if (ret != 0) {
1132 pr_err("Failed to get pstore block config: %d\n",
ret);
1133 goto err_free;
1134 }
1135
1136 /* Validate size requirements */
1137 ret = mmcpstore_calculate_sizes(cxt, &conf, &required_size,
1138 &kmsg_records);
1139 if (ret)
1140 goto err_free;
1141
1142 pr_debug("Pstore requirements: kmsg=%lu KB, pmsg=%lu KB,
console=%lu KB, ftrace=%lu KB\n",

  1143                  MMC_PSTORE_BYTES_TO_KB(conf.kmsg_size),
  1144                  MMC_PSTORE_BYTES_TO_KB(conf.pmsg_size),
  1145                  MMC_PSTORE_BYTES_TO_KB(conf.console_size),
  1146                  MMC_PSTORE_BYTES_TO_KB(conf.ftrace_size));

1147 pr_debug("Pstore capacity: ~%lu kmsg records possible (%lu
KB each, varies with compression)\n",
1148 kmsg_records,
MMC_PSTORE_BYTES_TO_KB(conf.kmsg_size));
1149

  1150          /* Set up pstore device info */
  1151          cxt->dev.flags = 0; /* Support all backends */
  1152          if (conf.kmsg_size > 0)
  1153                  cxt->dev.flags |= PSTORE_FLAGS_DMESG;
  1154          if (conf.pmsg_size > 0)
  1155                  cxt->dev.flags |= PSTORE_FLAGS_PMSG;
  1156          if (conf.console_size > 0)
  1157                  cxt->dev.flags |= PSTORE_FLAGS_CONSOLE;
  1158          if (conf.ftrace_size > 0)
  1159                  cxt->dev.flags |= PSTORE_FLAGS_FTRACE;
  1160
  1161          /* Set up zone structure for pstore/zone API */
  1162          cxt->dev.zone.read = mmcpstore_read_zone;
  1163          cxt->dev.zone.write = mmcpstore_write;
  1164          cxt->dev.zone.panic_write = mmcpstore_panic_write;
  1165          cxt->dev.zone.total_size = cxt->size;
  1166          cxt->dev.zone.kmsg_size = conf.kmsg_size;
  1167          cxt->dev.zone.pmsg_size = conf.pmsg_size;
  1168          cxt->dev.zone.console_size = conf.console_size;
  1169          cxt->dev.zone.ftrace_size = conf.ftrace_size;
  1170          cxt->dev.zone.max_reason = conf.max_reason;
  1171          cxt->dev.zone.name = "mmcpstore";
  1172          cxt->dev.zone.owner = THIS_MODULE;

1173
1174 mutex_init(&cxt->lock);
1175
1176 /*
1177 * Set state to READY before registration because
register_pstore_device()
1178 * triggers pstore_zone recovery which calls our read
callback, and the
1179 * read callback requires state == READY to proceed.
1180 */

  1181          mutex_lock(&mmcpstore_global_lock);
  1182          cxt->state = MMCPSTORE_STATE_READY;
  1183          mutex_unlock(&mmcpstore_global_lock);

1184
1185 ret = register_pstore_device(&cxt->dev);
1186 if (ret) {
1187 dev_err(&card->dev, "Failed to register pstore
device: %d\n",
1188 ret);

  1189                  mutex_lock(&mmcpstore_global_lock);
  1190                  cxt->state = MMCPSTORE_STATE_UNINITIALIZED;
  1191                  mutex_unlock(&mmcpstore_global_lock);
  1192                  goto err_free;

1193 }
1194
1195 dev_info(&card->dev, "MMC pstore backend registered
successfully\n");
1196 dev_info(&card->dev, "Device: %s, Size: %llu bytes (%llu
KB)\n",
1197 dev_name_param, cxt->size,
MMC_PSTORE_BYTES_TO_KB(cxt->size));
1198 dev_info(&card->dev, "Start sector: %llu, Sector count:
%llu\n",
1199 cxt->start_sect, cxt->size /
MMC_PSTORE_SECTOR_SIZE);
1200 dev_info(&card->dev, "Pstore components: kmsg=%lu KB,
pmsg=%lu KB, console=%lu KB, ftrace=%lu KB\n",

  1201                   MMC_PSTORE_BYTES_TO_KB(conf.kmsg_size),
  1202                   MMC_PSTORE_BYTES_TO_KB(conf.pmsg_size),
  1203                   MMC_PSTORE_BYTES_TO_KB(conf.console_size),
  1204                   MMC_PSTORE_BYTES_TO_KB(conf.ftrace_size));
  1205
  1206          return 0;
  1207
  1208  err_free:
  1209          kfree(cxt->buffer);
  1210          /* Don't free cxt here - it's the global context */
  1211          return ret;
Quoted 4 lines

1212 }
1213

Thanks
Kamal

Quoted 4 lines

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki