Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp165597rdb; Thu, 30 Nov 2023 01:07:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IE9hB4O3R8hgdkXcImPN+Kjw78r3l0HxvrNZI4Xz181zDvZw9CsfQnXyvw+G4/GjNaLeKg+ X-Received: by 2002:a05:6a00:8017:b0:6cd:e35f:997f with SMTP id eg23-20020a056a00801700b006cde35f997fmr2145462pfb.6.1701335243422; Thu, 30 Nov 2023 01:07:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701335243; cv=none; d=google.com; s=arc-20160816; b=K/ZJ2rtb2bG9E3Z4B3nHzuWCACZVwoTT2O9j9Z2qK+Qi17+GsUfIyvWxypKN39qKaq fwIFQMIfmWxlfXYtpQEGBNSilGR1NDEXIIVQGXzZNNskoyhyOEIYQriMzltyuVb4eCmx FaEa0MCIiqY5ae4/PvCoQdrSGKYZwO6n8tq1IVdgVFpREqYg+Sz8pnhNG/i2Sak+hvQg EgCjawLzJMWoNQNPoBpfFT7/1H1Ul5eCtIm6vsQcet3kWNbgL9iLIG8NfutOv3Ify5dI SOci4nWRliH9cuwkyPMHUcNL8v40iyidZVdK1NV2SB5/+RbHNEthV7BmEPkH10iLI5/f oSbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=qzc3U7sFDdtHUadGGzprUKVhVLAwC/gLPx8U/sb5Ft4=; fh=Pvfl91Kfo5V34Ak+9kYEL1VMYoC/xUyfU4uvC/bGmYc=; b=Jo2xGvaj5056hF39EbtvI6yd8SYWn3R2N+6Lz6Rt+gIg9HAfBNRA/vYw8/zQILozBA JZ88BKjs2WbsM1/ZsZTOiDA9HpT+O/HH1AJPewBoFfw/BsbdEiUF0eO8Js9jcad7TaEK j4aG7a6788i71JDlwEeh1XmFqqkGealqen9WrOhOR16JsrtbkIP83xIJeZVHHyu25lne RHMTkkGO0ebrMzPnLZPfBJkKs384RV2xck9TR9hlbrJ/viASVzOzzlT/FgCQBJrNivf7 /+KtbHToY2RTrtVibA1oV28+98fxgvBbJo17U6dMizn16NyJIA6hbxT6mbJna0nEzEZy xccg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=N9gY6RXD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id b11-20020a056a00114b00b006cbf67abff9si842267pfm.269.2023.11.30.01.07.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 01:07:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=N9gY6RXD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id D9FF080CF50B; Thu, 30 Nov 2023 01:07:20 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235005AbjK3JHC (ORCPT + 99 others); Thu, 30 Nov 2023 04:07:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229758AbjK3JG7 (ORCPT ); Thu, 30 Nov 2023 04:06:59 -0500 Received: from mail-yb1-xb2c.google.com (mail-yb1-xb2c.google.com [IPv6:2607:f8b0:4864:20::b2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 920D310F9 for ; Thu, 30 Nov 2023 01:07:01 -0800 (PST) Received: by mail-yb1-xb2c.google.com with SMTP id 3f1490d57ef6-dae7cc31151so591538276.3 for ; Thu, 30 Nov 2023 01:07:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1701335221; x=1701940021; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=qzc3U7sFDdtHUadGGzprUKVhVLAwC/gLPx8U/sb5Ft4=; b=N9gY6RXDkWumRhx9vouBV3yMPGyw5jXA5XNERq4YTreF8GmSxntyHyj3hPmREWT/hl nu2C0hSaOUHSpifnj7szzpFC/3+jXfFN4qG/K4h+wm/iRWXOqqqnjRmXiO5XNQegRHma 03UWSvFUFOO6wNcBmeUub42q46ldRWwDyWYWwQ1Z1tWSbwvbiUS5KlHH7spR64ikt8ne iPGoEuMg6Xke9wL5Znb5tr9BXxMFjUUa8/l5UKSkXxwWNQwMrpQDzcTnhT+oOEZ5gyVc cHx/uoccDvP+WzPldhqcvw3Bxj6VJj5o008JBTqD2+iw+Qm7/fVYJJGX/fnkAYPm8vKQ nRWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701335221; x=1701940021; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=qzc3U7sFDdtHUadGGzprUKVhVLAwC/gLPx8U/sb5Ft4=; b=i72PkH8EJZ/RwcDlEHbJYHVy55wixe+eNon11ohJOeBpxfb8jO+HYa7glULVKIVU0n cPOlnw84e5EGqR0YlUt0kQ+EQFaTWh5GxVruP+bq1FFdqy6Y9WmnuJd0f3Rste6BhrFm lMebnSGCWYGOqJHB+gEVSUXZBS7hBF9e+QwO1qZzs3hyGq0MG+TCZ9JAdDhoNfDR/C// +fb4KDOkZaR8iEFW1maD5YKkgt8J+Bt5CSIfqy14VTgVV304ZukWI5neO+dzeoSTGHkc +y5+A/qheVO5iv3AAAOY238sELiMGFq4kcyHqfHGmlTwSk4gP+XW5aHq7I6VPM3bhh0i VuQw== X-Gm-Message-State: AOJu0YwFnaHPtoxcB4Km8Fz4VOoMngRPsxzx7TRaXH3XL1DWZtKJFiGN yE4ARxHr8fWHWImlEq6AlbSzQejwrPWvGu0HQSrt6A== X-Received: by 2002:a25:ce0e:0:b0:db5:4196:8125 with SMTP id x14-20020a25ce0e000000b00db541968125mr311366ybe.17.1701335220510; Thu, 30 Nov 2023 01:07:00 -0800 (PST) MIME-Version: 1.0 References: <20230929130028.GB2825985@pengutronix.de> <20231122112212.GA783262@pengutronix.de> In-Reply-To: <20231122112212.GA783262@pengutronix.de> From: Ulf Hansson Date: Thu, 30 Nov 2023 10:06:24 +0100 Message-ID: Subject: Re: mmc: handling of Under-Voltage Events in eMMC To: Oleksij Rempel Cc: Mark Brown , Yang Yingliang , linux-mmc@vger.kernel.org, kernel@pengutronix.de, Ye Bin , Heiner Kallweit , Matti Vaittinen , Liam Girdwood , Conor Dooley , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Naresh Solanki , zev@bewilderbeest.net, Sebastian Reichel , linux-pm@vger.kernel.org, =?UTF-8?Q?S=C3=B8ren_Andersen?= Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Thu, 30 Nov 2023 01:07:21 -0800 (PST) On Wed, 22 Nov 2023 at 12:22, Oleksij Rempel wrote: > > Hi Ulf, Hi Mark, > > On Tue, Oct 10, 2023 at 04:48:24PM +0200, Ulf Hansson wrote: > > On Fri, 29 Sept 2023 at 15:00, Oleksij Rempel wrote: > > > > > > Hi, > > > > > > I'm working on a project aiming to protect eMMC during power loss. Our > > > hardware setup includes an under-voltage detector, circuits to disable > > > non-critical components, and enough capacitance to allow the CPU to run > > > for 100ms. > > > > > > I've added an interrupt handler to the fixed regulator to emit > > > REGULATOR_EVENT_UNDER_VOLTAGE events, and modified > > > drivers/mmc/host/sdhci.c to receive these events. Currently, the handler > > > only produces debug output. > > > > > > What is the recommended approach for handling under-voltage situations? > > > Should the driver finish ongoing write commands, block new ones, and > > > shut down the eMMC? I'm looking for direction here. > > > > That's indeed a very good question. From a general point of view, I > > think the best we can do is to stop any new I/O requests from being > > managed - and try to complete only the last ongoing one, if any. > > Exactly how to do that can be a bit tricky though. > > > > Beyond that, we should probably try to send the eMMC specific commands > > that allow us to inform the eMMC that it's about to be powered-off. > > Although, I am not sure that we actually will be able to complete > > these operations within 100ms, so maybe it's not really worth trying? > > See mmc_poweroff_notify(), for example. > > Some puzzle parts are now mainline, for example regulator framework > can be configured to detect under-voltage events and execute > hw_protection_shutdown(). So far it worked good enough to complete > mmc_poweroff_notify() withing 100ms window. The problem is, the chance to > execute mmc_poweroff_notify() depends on kernel configuration. If there are too > many drivers and devices, mmc_poweroff_notify() will be not executed in time. Right. I have been monitoring the discussions around the series "[PATCH v1 0/3] introduce priority-based shutdown support", but wanted to give a reply to $subject patch first. I think the point here is not to *always make it*, but rather try our best to improve the situation. > > For now, I workaround it by registering a reboot notifier for mmc shutdown. > It works, because kernel_power_off() is executing all registered reboot > notifiers at first place and there are no other slow reboot notifiers. > But, it seems to be not reliable enough. Probably notifier prioritization > is needed to make it more predictable. I think I need to have a closer look at the code for such an approach, to tell if that would work. My main concern with this, is that we need to make sure the block device queue needs to be flushed or made quiescent (mmc_blk_shutdown()) first, so we don't end up processing I/O requests beyond calling mmc_poweroff_notify(). > > So far, I have two variants to implement it in more predictable way: > variant 1 - forward the under-voltage notification to the mmc framework and > execute mmc_poweroff_notify() or bus shutdown. > variant 2 - use reboot notifier and introduce reboot notifier prioritization. > > Are there other options? What are your preferences? Something along the variant2 seems to make most sense to me, but I will continue to look at your other series in this regard. Kind regards Uffe