mmc: Add pstore backend for crash dump storage on eMMC
v5 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 v4 (addresses Ulf Hansson's feedback on the v4 panic host path, linux-mmc):
- mmc_panic_claim_host(): log claimed, runtime suspend, and ongoing_mrq before claim; always call panic_prepare() when implemented so the host can drain or gracefully terminate in-flight requests, then force-claim. Vendor controllers may supply their own panic_prepare for platform-specific cases (1/4).
- SDHCI: reference panic_prepare implementation; longer drain/reset timeouts; document panic helper return values in kernel-doc (2/4).
- mmcpstore: single prepare/claim path; panic_complete() after panic_poll_completion() on panic writes (4/4).
Changes since v3:
- Fixed kernel-doc warnings reported by kernel test robot:
- Added missing @param descriptions for sdhci_panic_prepare(), sdhci_panic_poll_completion(), sdhci_panic_complete() (patch 2)
- Added missing @sect_offset param doc for mmcpstore_do_request_internal() (patch 4)
- Fixed kernel-doc function name mismatch: mmcpstore_read() -> mmcpstore_read_zone() (patch 4)
- Added missing @disk param doc for mmcpstore_card_add() (patch 4)
- Removed unused 'offset_bytes' variable in mmcpstore_register_for_card() (patch 4)
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. Host drivers may replace panic_prepare with vendor-specific code where needed.
Patch 2 implements the SDHCI reference panic_prepare (graceful termination of in-flight work, then polled completion paths); other MMC host drivers use the same mmc_host_ops hooks with their own panic_prepare where the hardware differs.
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; also tested with concurrent I/O stress before panic.
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]/
v3: https://lore.kernel.org/linux-mmc/[email protected]/
v4: linux-mmc (same thread as v3; superseded by this v5)
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 | 54 ++ drivers/mmc/core/mmcpstore.c | 1511 ++++++++++++++++++++++++++++++++++ drivers/mmc/host/sdhci.c | 173 +++- drivers/mmc/host/sdhci.h | 6 + include/linux/mmc/host.h | 12 + 10 files changed, 1845 insertions(+), 4 deletions(-) create mode 100644 drivers/mmc/core/mmcpstore.c
Signature · 1 line
2.34.1
PATCH v5 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 | 54 ++++++++++++++++++++++++++++++++++++++++ include/linux/mmc/host.h | 12 +++++++++ 2 files changed, 66 insertions(+)
drivers/mmc/core/core.c +54 -0
@@ -861,6 +861,60 @@ 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. +* +* This function first checks the current host state (claimed/suspended/ongoing), +* then calls panic_prepare() to let the controller driver safely drain any +* in-flight hardware requests and handle runtime PM suspend state. After +* panic_prepare() returns, the host is forcefully claimed for panic I/O. +*/ +void mmc_panic_claim_host (struct mmc_host *host) +{ +bool claimed; +bool suspended; +struct mmc_request *ongoing; + +if (!host) +return ; + +/* Check current state for visibility into what we're dealing with */ + claimed =READ_ONCE (host->claimed); + suspended =pm_runtime_suspended (&host->class_dev); + ongoing =READ_ONCE (host->ongoing_mrq); + +if (claimed || suspended || ongoing) { +pr_info ("mmc_panic_claim: host state: claimed=%d suspended=%d ongoing_mrq=%p\n" , + claimed, suspended, ongoing); + } + +/* Always call panic_prepare to drain/reset hardware, regardless of claimed state. +* This ensures the controller is in a safe state for panic I/O even if the +* host was already claimed (which shouldn't happen, but we handle it safely). +*/ +if (host->ops && host->ops->panic_prepare) { +int ret = host->ops->panic_prepare (host); + +if (ret) +pr_warn ("mmc_panic_claim: panic_prepare failed: %d\n" , ret); + } + +/* Force-claim the host. Safe because all other CPUs are stopped. */ +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
@@ -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
PATCH v5 2/4 mmc: sdhci: Implement panic-context write support
In reply to Kamal DasuImplement 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 | 173 ++++++++++++++++++++++++++++++++++++++- drivers/mmc/host/sdhci.h | 6 ++ 2 files changed, 175 insertions(+), 4 deletions(-)
drivers/mmc/host/sdhci.c +169 -4
@@ -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,156 @@ 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 500000 +#define SDHCI_PANIC_DRAIN_TIMEOUT_US 500000 + +/** +* sdhci_panic_prepare - Prepare SDHCI controller for panic-context I/O +* @mmc: MMC host structure +* +* 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. +* +* Return: 0 on success, -ETIMEDOUT if hardware reset timed out. +*/ +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 +* @mmc: MMC host structure +* @mrq: MMC request being polled for completion +* +* Checks interrupt status and present state registers to determine if a +* request has completed. Used during panic when interrupts are disabled. +* +* Return: true if request has completed (with or without error), false if still in progress. +*/ +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 +* @mmc: MMC host structure +* @mrq: MMC request that has completed +* +* 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 +3247,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 +3401,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 +3426,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
@@ -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
PATCH v5 3/4 mmc: block: Add helper to look up mmc_card by device name
In reply to Kamal DasuAdd 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
@@ -3381,6 +3381,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
@@ -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
PATCH v5 4/4 mmc: core: Add MMC pstore backend driver
In reply to Kamal DasuAdd 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 | 1511 ++++++++++++++++++++++++++++++++++ 6 files changed, 1546 insertions(+) create mode 100644 drivers/mmc/core/mmcpstore.c
MAINTAINERS +6 -0
@@ -18235,6 +18235,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
@@ -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
@@ -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
@@ -3247,6 +3247,7 @@ static int mmc_blk_probe(struct mmc_card *card) }mmc_blk_rpmb_add (card); +mmcpstore_card_add (card, md->disk);return 0 ;
@@ -3262,6 +3263,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
@@ -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 +1511 -0
1,511 lines not on this page · raw message
Signature · 1 line
2.34.1
Ulf,
I'm sending a gentle reminder regarding the v5 patch series for mmcpstore.
This version addresses your previous feedback on the v4 panic host path and includes several key stability improvements:
- Implements a lockless mmc_panic_claim_host using WRITE_ONCE to avoid deadlocks during panic.
- Adds panic_prepare to the host ops to ensure in-flight requests are drained and runtime PM states are handled before panic writes.
- Uses standard MMC core request paths with polling-based completion for robust I/O during a crash.
- Includes full PM suspend/resume support with eMMC re-initialization.
The series has been tested thoroughly on Broadcom STB platforms (ARM64), verifying reliable recovery of kmsg, pmsg, and console logs across multiple panic cycles.
Please let me know if you need any further information or if there are additional changes required for acceptance.
Thanks
Kamal
Quoted 116 lines · Kamal Dasu
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 v4 (addresses Ulf Hansson's feedback on the v4 panic host path, linux-mmc):
-mmc_panic_claim_host(): log claimed, runtime suspend, andongoing_mrqbefore claim; always callpanic_prepare()when implemented so the host can drain or gracefully terminate in-flight requests, then force-claim. Vendor controllers may supply their ownpanic_preparefor platform-specific cases (1/4).
- SDHCI: referencepanic_prepareimplementation; longer drain/reset timeouts; document panic helper return values in kernel-doc (2/4).
- mmcpstore: single prepare/claim path;panic_complete()afterpanic_poll_completion()on panic writes (4/4).Changes since v3:
- Fixed kernel-doc warnings reported by kernel test robot:
- Added missing @param descriptions forsdhci_panic_prepare(),sdhci_panic_poll_completion(),sdhci_panic_complete()(patch 2)
- Added missing @sect_offset param doc formmcpstore_do_request_internal()(patch 4)
- Fixed kernel-doc function name mismatch:mmcpstore_read()->mmcpstore_read_zone()(patch 4)
- Added missing @disk param doc formmcpstore_card_add()(patch 4)
- Removed unused 'offset_bytes' variable inmmcpstore_register_for_card()(patch 4)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; thepstore_zoneframework handles zone management internally
- Uses standard MMC core request path (mmc_start_request) instead of hand-buildingmmc_requeststructs; panic-context I/O is handled through propermmc_host_opscallbacks rather than ad-hoc code in the driver
- Added panic-context ops tommc_host_opsandsdhci_opsfor clean separation of panic and normal I/O paths
- Fixed deadlocks caused by spinlock contention during panic (locklessmmc_panic_claim_hostusingWRITE_ONCE)
- Fixed data corruption in pstore recovery (zlib_inflatefailures) by letting the normalsdhci_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
- AddedMAINTAINERSentry
- Split into 4-patch series for reviewabilityThe series is structured as follows:
Patch 1 adds panic-context operations to struct
mmc_host_opsand a locklessmmc_panic_claim_host()for use during kernel panic when other CPUs are stopped and may hold locks. Host drivers may replacepanic_preparewith vendor-specific code where needed.Patch 2 implements the SDHCI reference
panic_prepare(graceful termination of in-flight work, then polled completion paths); other MMC host drivers use the samemmc_host_opshooks with their ownpanic_preparewhere the hardware differs.Patch 3 adds
mmc_blk_get_card_by_name()helper to look up anmmc_cardfrom 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_blkframework 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 inblock.cand declarations inblock.hfor 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; also tested with concurrent I/O stress before panic.
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]/
v3:
https://lore.kernel.org/linux-mmc/[email protected]/
v4: linux-mmc (same thread as v3; superseded by this v5) 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.htmlKamal 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 upmmc_cardby device name
mmc: core: Add MMC pstore backend driverMAINTAINERS | 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 | 54 ++ drivers/mmc/core/mmcpstore.c | 1511 ++++++++++++++++++++++++++++++++++ drivers/mmc/host/sdhci.c | 173 +++- drivers/mmc/host/sdhci.h | 6 + include/linux/mmc/host.h | 12 + 10 files changed, 1845 insertions(+), 4 deletions(-) create mode 100644 drivers/mmc/core/mmcpstore.c--
2.34.1
Quoted 118 lines · Kamal Dasu
Quoted 113 lines · Kamal Dasu
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 v4 (addresses Ulf Hansson's feedback on the v4 panic host path, linux-mmc):
-mmc_panic_claim_host(): log claimed, runtime suspend, andongoing_mrqbefore claim; always callpanic_prepare()when implemented so the host can drain or gracefully terminate in-flight requests, then force-claim. Vendor controllers may supply their ownpanic_preparefor platform-specific cases (1/4).
- SDHCI: referencepanic_prepareimplementation; longer drain/reset timeouts; document panic helper return values in kernel-doc (2/4).
- mmcpstore: single prepare/claim path;panic_complete()afterpanic_poll_completion()on panic writes (4/4).Changes since v3:
- Fixed kernel-doc warnings reported by kernel test robot:
- Added missing @param descriptions forsdhci_panic_prepare(),sdhci_panic_poll_completion(),sdhci_panic_complete()(patch 2)
- Added missing @sect_offset param doc formmcpstore_do_request_internal()(patch 4)
- Fixed kernel-doc function name mismatch:mmcpstore_read()->mmcpstore_read_zone()(patch 4)
- Added missing @disk param doc formmcpstore_card_add()(patch 4)
- Removed unused 'offset_bytes' variable inmmcpstore_register_for_card()(patch 4)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; thepstore_zoneframework handles zone management internally
- Uses standard MMC core request path (mmc_start_request) instead of hand-buildingmmc_requeststructs; panic-context I/O is handled through propermmc_host_opscallbacks rather than ad-hoc code in the driver
- Added panic-context ops tommc_host_opsandsdhci_opsfor clean separation of panic and normal I/O paths
- Fixed deadlocks caused by spinlock contention during panic (locklessmmc_panic_claim_hostusingWRITE_ONCE)
- Fixed data corruption in pstore recovery (zlib_inflatefailures) by letting the normalsdhci_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
- AddedMAINTAINERSentry
- Split into 4-patch series for reviewabilityThe series is structured as follows:
Patch 1 adds panic-context operations to struct
mmc_host_opsand a locklessmmc_panic_claim_host()for use during kernel panic when other CPUs are stopped and may hold locks. Host drivers may replacepanic_preparewith vendor-specific code where needed.Patch 2 implements the SDHCI reference
panic_prepare(graceful termination of in-flight work, then polled completion paths); other MMC host drivers use the samemmc_host_opshooks with their ownpanic_preparewhere the hardware differs.Patch 3 adds
mmc_blk_get_card_by_name()helper to look up anmmc_cardfrom 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_blkframework 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 inblock.cand declarations inblock.hfor 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; also tested with concurrent I/O stress before panic.
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]/
v3:
https://lore.kernel.org/linux-mmc/[email protected]/
v4: linux-mmc (same thread as v3; superseded by this v5) 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.htmlKamal 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 upmmc_cardby device name
mmc: core: Add MMC pstore backend driverMAINTAINERS | 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 | 54 ++ drivers/mmc/core/mmcpstore.c | 1511 ++++++++++++++++++++++++++++++++++ drivers/mmc/host/sdhci.c | 173 +++- drivers/mmc/host/sdhci.h | 6 + include/linux/mmc/host.h | 12 + 10 files changed, 1845 insertions(+), 4 deletions(-) create mode 100644 drivers/mmc/core/mmcpstore.c
Quoted 4 lines
Quoted 3 lines
--
2.34.1
Ulf,
I'm resending a gentle reminder regarding the v5 patch series for mmcpstore.
This version addresses your previous feedback on the v4 panic host path and includes several key stability improvements:
- Implements a lockless mmc_panic_claim_host using WRITE_ONCE to avoid deadlocks during panic.
- Adds panic_prepare to the host ops to ensure in-flight requests are drained and runtime PM states are handled before panic writes.
- Uses standard MMC core request paths with polling-based completion for robust I/O during a crash.
- Includes full PM suspend/resume support with eMMC re-initialization.
The series has been tested thoroughly on Broadcom STB platforms (ARM64), verifying reliable recovery of kmsg, pmsg, and console logs across multiple panic cycles.
Please let me know if you need any further information or if there are additional changes required for acceptance.
Thanks
Kamal
Hi Ulf,
Quoted 154 lines · Kamal Dasu
On Wed, Jun 10, 2026 at 12:53 PM Kamal Dasu <[email protected] <mailto:[email protected]>> wrote:
On Wed, Apr 22, 2026 at 4:51 PM Kamal Dasu <[email protected] <mailto:[email protected]>> wrote:
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 v4 (addresses Ulf Hansson's feedback on the v4 panic host path, linux-mmc):
-mmc_panic_claim_host(): log claimed, runtime suspend, andongoing_mrqbefore claim; always callpanic_prepare()when implemented so the host can drain or gracefully terminate in-flight requests, then force-claim. Vendor controllers may supply their ownpanic_preparefor platform-specific cases (1/4).
- SDHCI: referencepanic_prepareimplementation; longer drain/reset timeouts; document panic helper return values in kernel-doc
(2/4).
- mmcpstore: single prepare/claim path;panic_complete()afterpanic_poll_completion()on panic writes (4/4).Changes since v3:
- Fixed kernel-doc warnings reported by kernel test robot:
- Added missing @param descriptions forsdhci_panic_prepare(),sdhci_panic_poll_completion(),sdhci_panic_complete()(patch 2)
- Added missing @sect_offset param doc formmcpstore_do_request_internal()(patch 4)
- Fixed kernel-doc function name mismatch:mmcpstore_read()->mmcpstore_read_zone()(patch 4)
- Added missing @disk param doc formmcpstore_card_add()
(patch 4)
- Removed unused 'offset_bytes' variable inmmcpstore_register_for_card()(patch 4)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; thepstore_zoneframework handles zone management internally
- Uses standard MMC core request path (mmc_start_request) instead of hand-buildingmmc_requeststructs; panic-context I/O is handled through propermmc_host_opscallbacks rather than ad-hoc code in the driver
- Added panic-context ops tommc_host_opsandsdhci_opsfor clean separation of panic and normal I/O paths
- Fixed deadlocks caused by spinlock contention during panic (locklessmmc_panic_claim_hostusingWRITE_ONCE)
- Fixed data corruption in pstore recovery (zlib_inflatefailures) by letting the normalsdhci_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
- AddedMAINTAINERSentry
- Split into 4-patch series for reviewabilityThe series is structured as follows:
Patch 1 adds panic-context operations to struct
mmc_host_opsand a locklessmmc_panic_claim_host()for use during kernel panic when other CPUs are stopped and may hold locks. Host drivers may replacepanic_preparewith vendor-specific code where needed.Patch 2 implements the SDHCI reference
panic_prepare(graceful termination of in-flight work, then polled completion paths); other MMC host drivers use the samemmc_host_opshooks with their ownpanic_preparewhere the hardware differs.Patch 3 adds
mmc_blk_get_card_by_name()helper to look up anmmc_cardfrom 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_blkframework 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 inblock.cand declarations inblock.hfor 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; also tested with concurrent I/O stress before panic.
Previous submissions and related work:
RFC v1: https://lore.kernel.org/linux-
mmc/[email protected]/ <https://
lore.kernel.org/linux-mmc/20221216212738.7928-1- [email protected]/>
RFC v2: https://lore.kernel.org/linux-
mmc/[email protected]/ <https://
lore.kernel.org/linux-mmc/20221222185948.12717-1- [email protected]/>
v3: https://lore.kernel.org/linux-
mmc/[email protected]/ <https://
lore.kernel.org/linux-mmc/20260319185705.1516950-1- [email protected]/>
v4: linux-mmc (same thread as v3; superseded by this v5) Marvell MMC pstore attempt (2020):
https://lore.kernel.org/linux-mmc/20201207115753.21728-1-
[email protected]/ <https://lore.kernel.org/linux-
mmc/[email protected]/>
pstore/blk documentation:
https://www.kernel.org/doc/html/latest/admin-guide/pstore-
blk.html <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 upmmc_cardby device name
mmc: core: Add MMC pstore backend driverMAINTAINERS | 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 | 54 ++
drivers/mmc/core/mmcpstore.c| 1511 ++++++++++++++++++++++++++
++++++++
drivers/mmc/host/sdhci.c | 173 +++- drivers/mmc/host/sdhci.h | 6 + include/linux/mmc/host.h | 12 +
10 files changed, 1845 insertions(+), 4 deletions(-) create mode 100644drivers/mmc/core/mmcpstore.c--
2.34.1Ulf,
I'm resending a gentle reminder regarding the v5 patch series for mmcpstore.
This version addresses your previous feedback on the v4 panic host path and includes several key stability improvements:
- Implements a lockless
mmc_panic_claim_hostusingWRITE_ONCEto avoid deadlocks during panic.
- Addspanic_prepareto the host ops to ensure in-flight requests are drained and runtime PM states are handled before panic writes.
- Uses standard MMC core request paths with polling-based completion for robust I/O during a crash.
- Includes full PM suspend/resume support with eMMC re-initialization.
Quoted 3 lines
The series has been tested thoroughly on Broadcom STB platforms (ARM64), verifying reliable recovery of kmsg, pmsg, and console logs across multiple panic cycles.
Please let me know if you need any further information or if there are additional changes required for acceptance.
Is there anything we could do here to move this forward? We have large number of devices in the field that make use of that feature and we would really like for this to be included upstream and usable by others as well.
Thanks!
Signature · 1 line
Florian
Adrian Hunter
maintainerQuoted 153 lines · Florian Fainelli
Hi Ulf,
Quoted 150 lines · Kamal Dasu
On Wed, Jun 10, 2026 at 12:53 PM Kamal Dasu <[email protected] <mailto:[email protected]>> wrote:
On Wed, Apr 22, 2026 at 4:51 PM Kamal Dasu <[email protected] <mailto:[email protected]>> wrote:
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 v4 (addresses Ulf Hansson's feedback on the v4 panic host path, linux-mmc):
-mmc_panic_claim_host(): log claimed, runtime suspend, andongoing_mrqbefore claim; always callpanic_prepare()when implemented so the host can drain or gracefully terminate in-flight requests, then force-claim. Vendor controllers may supply their ownpanic_preparefor platform-specific cases (1/4).
- SDHCI: referencepanic_prepareimplementation; longer drain/reset timeouts; document panic helper return values in kernel-doc (2/4).
- mmcpstore: single prepare/claim path;panic_complete()afterpanic_poll_completion()on panic writes (4/4).Changes since v3:
- Fixed kernel-doc warnings reported by kernel test robot:
- Added missing @param descriptions forsdhci_panic_prepare(),sdhci_panic_poll_completion(),sdhci_panic_complete()(patch 2)
- Added missing @sect_offset param doc formmcpstore_do_request_internal()(patch 4)
- Fixed kernel-doc function name mismatch:mmcpstore_read()->mmcpstore_read_zone()(patch 4)
- Added missing @disk param doc formmcpstore_card_add()(patch 4)
- Removed unused 'offset_bytes' variable inmmcpstore_register_for_card()(patch 4)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; thepstore_zoneframework handles zone management internally
- Uses standard MMC core request path (mmc_start_request) instead of hand-buildingmmc_requeststructs; panic-context I/O is handled through propermmc_host_opscallbacks rather than ad-hoc code in the driver
- Added panic-context ops tommc_host_opsandsdhci_opsfor clean separation of panic and normal I/O paths
- Fixed deadlocks caused by spinlock contention during panic (locklessmmc_panic_claim_hostusingWRITE_ONCE)
- Fixed data corruption in pstore recovery (zlib_inflatefailures) by letting the normalsdhci_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
- AddedMAINTAINERSentry
- Split into 4-patch series for reviewabilityThe series is structured as follows:
Patch 1 adds panic-context operations to struct
mmc_host_opsand a locklessmmc_panic_claim_host()for use during kernel panic when other CPUs are stopped and may hold locks. Host drivers may replacepanic_preparewith vendor-specific code where needed.Patch 2 implements the SDHCI reference
panic_prepare(graceful termination of in-flight work, then polled completion paths); other MMC host drivers use the samemmc_host_opshooks with their ownpanic_preparewhere the hardware differs.Patch 3 adds
mmc_blk_get_card_by_name()helper to look up anmmc_cardfrom 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_blkframework 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 inblock.cand declarations inblock.hfor 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; also tested with concurrent I/O stress before panic.
Previous submissions and related work:
RFC v1: https://lore.kernel.org/linux-
mmc/[email protected]/ <https://
lore.kernel.org/linux-mmc/20221216212738.7928-1- [email protected]/>
RFC v2: https://lore.kernel.org/linux-
mmc/[email protected]/ <https://
lore.kernel.org/linux-mmc/20221222185948.12717-1- [email protected]/>
v3: https://lore.kernel.org/linux-
mmc/[email protected]/ <https://
lore.kernel.org/linux-mmc/20260319185705.1516950-1- [email protected]/>
v4: linux-mmc (same thread as v3; superseded by this v5) Marvell MMC pstore attempt (2020):
https://lore.kernel.org/linux-mmc/20201207115753.21728-1-
[email protected]/ <https://lore.kernel.org/linux-
mmc/[email protected]/> pstore/blk documentation:
https://www.kernel.org/doc/html/latest/admin-guide/pstore-
blk.html <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 upmmc_cardby device name
mmc: core: Add MMC pstore backend driverMAINTAINERS | 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 | 54 ++ drivers/mmc/core/mmcpstore.c | 1511 ++++++++++++++++++++++++++ ++++++++ drivers/mmc/host/sdhci.c | 173 +++- drivers/mmc/host/sdhci.h | 6 + include/linux/mmc/host.h | 12 + 10 files changed, 1845 insertions(+), 4 deletions(-)create mode 100644
drivers/mmc/core/mmcpstore.c-- 2.34.1
Ulf,
I'm resending a gentle reminder regarding the v5 patch series for mmcpstore.
This version addresses your previous feedback on the v4 panic host path and includes several key stability improvements:
- Implements a lockless
mmc_panic_claim_hostusingWRITE_ONCEto avoid deadlocks during panic.
- Addspanic_prepareto the host ops to ensure in-flight requests are drained and runtime PM states are handled before panic writes.
- Uses standard MMC core request paths with polling-based completion for robust I/O during a crash.
- Includes full PM suspend/resume support with eMMC re-initialization.
Quoted 7 lines
Quoted 3 lines
The series has been tested thoroughly on Broadcom STB platforms (ARM64), verifying reliable recovery of kmsg, pmsg, and console logs across multiple panic cycles.
Please let me know if you need any further information or if there are additional changes required for acceptance.
Is there anything we could do here to move this forward? We have large number of devices in the field that make use of that feature and we would really like for this to be included upstream and usable by others as well.
Thanks!
Perhaps start by describing the problem. pstore_blk already supports block devices including mmc block devices, right? Have you any information on how well that works in practice? Is a dedicated mmc pstore back end really needed?
What are the generic requirements for a pstore backend? How do they map to requirements for mmc?
How are big obstacles handled like:
- the device is in use
- the device is runtime suspended
- the controller is runtime suspended
- a runtime power management transition is underway
- a system power management transition is underway
- reset or recovery is in progress
- the panic originates in the mmc subsystem
- switching emmc partitions
- device tuning / re-tuning
- maybe other things?
Is it so that in some cases the pstore back end needs to leave the mmc system in an operational state? Whereas in a panic/oops it could leave it broken?
Quoted 159 lines · Adrian Hunter
Quoted 157 lines · Florian Fainelli
Hi Ulf,
Quoted 153 lines · Kamal Dasu
On Wed, Jun 10, 2026 at 12:53 PM Kamal Dasu <[email protected] <mailto:[email protected]>> wrote:
On Wed, Apr 22, 2026 at 4:51 PM Kamal Dasu <[email protected] <mailto:[email protected]>> wrote:
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 v4 (addresses Ulf Hansson's feedback on the v4 panic host path, linux-mmc):
-mmc_panic_claim_host(): log claimed, runtime suspend, andongoing_mrqbefore claim; always callpanic_prepare()when implemented so the host can drain or gracefully terminate in-flight requests, then force-claim. Vendor controllers may supply their ownpanic_preparefor platform-specific cases (1/4).
- SDHCI: referencepanic_prepareimplementation; longer drain/reset timeouts; document panic helper return values in kernel-doc
(2/4).
- mmcpstore: single prepare/claim path;panic_complete()afterpanic_poll_completion()on panic writes (4/4).Changes since v3:
- Fixed kernel-doc warnings reported by kernel test robot:
- Added missing @param descriptions forsdhci_panic_prepare(),sdhci_panic_poll_completion(),sdhci_panic_complete()(patch 2)
- Added missing @sect_offset param doc formmcpstore_do_request_internal()(patch 4)
- Fixed kernel-doc function name mismatch:mmcpstore_read()->mmcpstore_read_zone()(patch 4)
- Added missing @disk param doc formmcpstore_card_add()
(patch 4)
- Removed unused 'offset_bytes' variable inmmcpstore_register_for_card()(patch 4)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; thepstore_zoneframework handles zone management internally
- Uses standard MMC core request path (mmc_start_request) instead of hand-buildingmmc_requeststructs; panic-context I/O is handled through propermmc_host_opscallbacks rather than ad-hoc code in the driver
- Added panic-context ops tommc_host_opsandsdhci_opsfor clean separation of panic and normal I/O paths
- Fixed deadlocks caused by spinlock contention during panic (locklessmmc_panic_claim_hostusingWRITE_ONCE)
- Fixed data corruption in pstore recovery (zlib_inflatefailures) by letting the normalsdhci_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
- AddedMAINTAINERSentry
- Split into 4-patch series for reviewabilityThe series is structured as follows:
Patch 1 adds panic-context operations to struct
mmc_host_opsand a locklessmmc_panic_claim_host()for use during kernel panic when other CPUs are stopped and may hold locks. Host drivers may replacepanic_preparewith vendor-specific code where needed.Patch 2 implements the SDHCI reference
panic_prepare(graceful termination of in-flight work, then polled completion paths); other MMC host drivers use the samemmc_host_opshooks with their ownpanic_preparewhere the hardware differs.Patch 3 adds
mmc_blk_get_card_by_name()helper to look up anmmc_cardfrom 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_blkframework 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 inblock.cand declarations inblock.hfor 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; also tested with concurrent I/O stress before panic.
Previous submissions and related work:
RFC v1: https://lore.kernel.org/linux-
mmc/[email protected]/ <https://
lore.kernel.org/linux-mmc/20221216212738.7928-1- [email protected]/>
RFC v2: https://lore.kernel.org/linux-
mmc/[email protected]/ <https://
lore.kernel.org/linux-mmc/20221222185948.12717-1- [email protected]/>
v3: https://lore.kernel.org/linux-
mmc/[email protected]/ <https://
lore.kernel.org/linux-mmc/20260319185705.1516950-1- [email protected]/>
v4: linux-mmc (same thread as v3; superseded by this v5) Marvell MMC pstore attempt (2020):
https://lore.kernel.org/linux-mmc/20201207115753.21728-1-
[email protected]/ <https://lore.kernel.org/linux-
mmc/[email protected]/>
pstore/blk documentation:
https://www.kernel.org/doc/html/latest/admin-guide/pstore-
blk.html <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 upmmc_cardby 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| 54 ++
drivers/mmc/core/mmcpstore.c| 1511 ++++++++++++++++++++++++++
++++++++
drivers/mmc/host/sdhci.c| 173 +++-
drivers/mmc/host/sdhci.h| 6 +
include/linux/mmc/host.h| 12 +
10 files changed, 1845 insertions(+), 4 deletions(-) create mode 100644drivers/mmc/core/mmcpstore.c-- 2.34.1
Ulf,
I'm resending a gentle reminder regarding the v5 patch series for mmcpstore.
This version addresses your previous feedback on the v4 panic host path and includes several key stability improvements:
- Implements a lockless
mmc_panic_claim_hostusingWRITE_ONCEto avoid deadlocks during panic.
- Addspanic_prepareto the host ops to ensure in-flight requests are drained and runtime PM states are handled before panic writes.
- Uses standard MMC core request paths with polling-based completion for robust I/O during a crash.
- Includes full PM suspend/resume support with eMMC re-initialization.The series has been tested thoroughly on Broadcom STB platforms (ARM64), verifying reliable recovery of kmsg, pmsg, and console logs across multiple panic cycles.
Please let me know if you need any further information or if there are additional changes required for acceptance.
Quoted 9 lines
Quoted 3 lines
Is there anything we could do here to move this forward? We have large number of devices in the field that make use of that feature and we would really like for this to be included upstream and usable by others as well.
Thanks!
Perhaps start by describing the problem.
pstore_blkalready supports block devices including mmc block devices, right? Have you any information on how well that works in practice? Is a dedicated mmc pstore back end really needed?
pstore must write kmsg to eMMC from inside panic() -- IRQs and preemption already disabled, other CPUs stopped -- and complete without sleeping, blocking on a lock, or waiting on an interrupt. It lets you attach one (blkdev=/dev/mmcblk0pN). Attaching isn't the same as working during a panic.
Not at all for an actual panic. Its own code says so on attach:
"attached %s (...) (no dedicated panic_write!)" (fs/pstore/blk.c:312). Its write path also returns -EBUSY whenever irqs_disabled() -- always true once panic() has run -- and no panic_write is registered, so pstore's panic dispatch has nothing to call.
"Is a dedicated mmc backend really needed? "
Yes. pstore-blk.rst already documents that panic capture requires a dedicated, polled, lock-free panic_write; mtdpstore is the existing in-tree backend doing that for flash. This is the same pattern applied to MMC.
Quoted 3 lines
What are the generic requirements for a pstore backend? How do they map to requirements for mmc?
panic_write must run synchronously, one CPU, IRQs/preempt already off, complete-or-fail before returning: no sleep, no blocking lock, no allocation, no interrupt-driven completion. That rules out mmc_claim_host() (sleeps), mmc_wait_for_req()/mmc_wait_for_cmd() (wait_for_completion -> schedule()), and blk-mq/mmc_queue (IRQ + workqueue driven). The panic path instead builds raw mmc commands and polls host registers directly for completion.
Quoted 2 lines
How are big obstacles handled like:
- the device is in use
force-claimed via WRITE_ONCE (host
lock not taken); in-flight command is drained with a bounded poll (500ms) then aborted via software reset, not gracefully finished.
Quoted 1 line
- the device is runtime suspended
detected (pm_runtime_suspended()) and
logged; nothing resumes power before the write is attempted.
Quoted 1 line
- the controller is runtime suspended
same -- detected, not acted on.
Runtime PM transition underway: no check beyond that same read.
Quoted 1 line
- a runtime power management transition is underway
no check beyond that same read.
Quoted 1 line
- a system power management transition is underway
A PM notifier blocks read/write during PM_SUSPEND_PREPARE and re-inits the card viapm_runtime_get_sync() on PM_POST_SUSPEND -- but this notifier is entirely separate from, and not consulted by, the panic write path.
Quoted 1 line
- reset or recovery is in progress
no interaction with mmc_hw_reset() or CQE recovery anywhere in the panic path.
Quoted 1 line
- the panic originates in the mmc subsystem
mmc_host->lock is bypassed entirely (WRITE_ONCE, no lock taken) for exactly this reason.sdhci_host->lock is not treated the same way -- it's taken with a plain spin_lock_irqsave(), no trylock, no bypass.
Quoted 1 line
- switching emmc partitions
the panic path can switch to its own target partition (raw CMD6 + busy poll). The previously-active
partition is saved (original_part_config) but never read back or restored anywhere in the file.
Quoted 1 line
- device tuning / re-tuning
mmc_start_request(), called directly by the panic path, unconditionally calls mmc_retune(), which if host->retune_now is set calls into mmc_execute_tuning() ->mmc_wait_for_req() -> wait_for_completion() -> schedule(). Nothing checks or clears retune_now beforehand.
Quoted 2 lines
- maybe other things?
None of the above interact with each other either
e.g.a partition switch and a runtime-suspended controller occurring together are each handled (or not) independently, not as a combined case.
Quoted 4 lines
Is it so that in some cases the pstore back end needs to leave the mmc system in an operational state? Whereas in a panic/oops it could leave it broken?
Nothing in the code releases the forced claim, re-initializes the card, or restores state after a panic write. It does two bounded delays and returns, leaving host->claimed forced, CQE off if disabled, and the card on whichever partition was last selected. The The implicit assumption is that a reboot follows eventually.
Thanks
Kamal