Re: [PATCH v1 1/1] mmc: core: Handle undervoltage events and register regulator notifiers

From: Oleksij Rempel
Date: Thu Feb 13 2025 - 06:10:40 EST


On Thu, Feb 13, 2025 at 10:14:00AM +0000, Avri Altman wrote:
> > Extend the MMC core to handle undervoltage events by implementing
> > infrastructure to notify the MMC bus about voltage drops.
> >
> > Background & Decision at LPC24:
> >
> > This solution was proposed and refined during LPC24 in the talk "Graceful
> > Under Pressure: Prioritizing Shutdown to Protect Your Data in Embedded
> > Systems" which aimed to address how Linux should handle power fluctuations
> > in embedded devices to prevent data corruption or storage damage.
> >
> > At the time, multiple possible solutions were considered:
> >
> > 1. Triggering a system-wide suspend or shutdown: when undervoltage is
> > detected, with device-specific prioritization to ensure critical
> > components shut down first.
> > - This approach was disliked by Greg Kroah-Hartman, as it introduced
> > complexity and was not suitable for all use cases.
> >
> > 2. Notifying relevant devices through the regulator framework: to allow
> > graceful per-device handling.
> > - This approach was agreed upon as the most acceptable: by participants
> > in the discussion, including Greg Kroah-Hartman, Mark Brown,
> > and Rafael J. Wysocki.
> > - This patch implements that decision by integrating undervoltage
> > handling into the MMC subsystem.
> >
> > This patch was tested on iMX8MP based system with SDHCI controller.
> Has it been considered, to rely on user-space and not the kernel to handle
> those extreme conditions?
> E.g. a pollable sysfs that would be monitored by select(), poll(), etc.
> As Android might use?

Yes, the advantage of solving this in the kernel is:

- The regulator framework already provides all the necessary components,
including event support.
- The MMC framework already supports regulators, making the implementation
straightforward.
- This approach works even if userspace is not ready at boot time.

On the other hand, you are right that a userspace implementation would offer
more flexibility. However, I believe this can be built as an extension of the
current implementation. The regulator framework supports Netlink notifications
to userspace, eliminating the need for sysfs polling. The MMC framework would
also require a sysfs interface to force a quick shutdown - if such an interface
does not already exist - and a filter for regulator notifications to ignore
undervoltage events when they are handled in userspace.

Best Regards,
Oleksij
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |