From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f227.google.com (mail-pf1-f227.google.com [209.85.210.227]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9653A26AC3 for ; Wed, 22 Apr 2026 20:51:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.227 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776891094; cv=none; b=TMjEvruaqRDQzLWDLR3ODzvmWcQD3y/ADtJleTY9ZNzqewio2jBsNhOHahycD4NHj9cqZ4mf+8Ky/h0CRmKdKOjGd1nd7H82WErTI7v/9Z5Q+sxYavCiuKe+2aBPxDWSjHeO9LR72S/zNN/8XQ2HuXYTK9c4lh5iybMBewdzA9Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776891094; c=relaxed/simple; bh=lZgUmf+snJtgn2iqyKzz2f7jkJ/tF6tuXosxy/AYwQI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TyqGQl9jzw7cb1iyqvDvMolUa4cwU9lYlqPG+yd9dgulhKV/05m3KezD+TS0al93/nYApejhuujHy1QPl2gLG4oyKGqFVY6CxnUsvOsxdkU760BW4bVT1w8T+FBzJ3uoZAZSH/lRCa2ZDF61WkNcJDzmH2EwQzCPwaDupnXEJbs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=broadcom.com; spf=fail smtp.mailfrom=broadcom.com; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b=QI7PqKzL; arc=none smtp.client-ip=209.85.210.227 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=broadcom.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=broadcom.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="QI7PqKzL" Received: by mail-pf1-f227.google.com with SMTP id d2e1a72fcca58-82f69a286dbso4596178b3a.2 for ; Wed, 22 Apr 2026 13:51:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776891093; x=1777495893; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=vduSvXKe+L7+c8UihFrzYyBr/PDlgqMu0Lyao+9fcwg=; b=JujjmQnamkNz1uTPUgbG6p5TlUXscajsl2I2hB0Lmz0IHibSr+UPo8NaTaky2H3boC fLHZ4zx0inDcyNzC/iT5sgZXqf7iLP473qXT3dt9rVIAE3PWSoATtCNKwPMkwO8gqLHY Nz1dNq3bn0LZzUx9qiIe+5wltqhMZ7nFlJUXzV1mO9gwqhlITlWObSRJUZu6ID+IMwZm wfur4fvsAWKZlFjej8Vqh6smTWd/DVOWFtvWms0bxRMJUlbHyKOgX++deJ3fSGmtdQDv Z7iK2x6e8FafZRvr4+3cH1gVKQLIbfLHLEZfElLQAwCmxEkCwtulN1azof8Cy/lxjzD7 KKvQ== X-Forwarded-Encrypted: i=1; AFNElJ9bDAWmqR4cgQvfqpEeGUwEyodVVwNZATuVP9fLh9cmXNFWEBwMcIGHw0rDmb99sq5EsxEmbF18g9AEKIc=@vger.kernel.org X-Gm-Message-State: AOJu0YzR5/K5YUXcekxOAVn8qxEmrbA0y8/CrpxLeJJOnK7aqQBrtDEL gO1sSrXne9Iyiz5p/AoL6x9E8Wps3pCZ6De6aJ+NNY8JZfLILrTQG/cvr5PfQy6cslJmktovb2m vFt79mc4FNMhgo2k1FGXgea2O9OAxWn4bnTmUEqL4K1kA64nYArXLloBO+fw0MdCRiopjOpG9MF w52NnkMeGu/OHsqpZSy5xyuMVGcsDqHMOKMDfUMN18pFwkvPYDXoKVo/3cTrH/fcubALMcbzQ47 weer9CWOIg1src6 X-Gm-Gg: AeBDieskVkiEuaDUp3sPg3rihMoOeAZBBqfsvn02UAMYUt27GkebCQa/VctLGUQI1h5 aDIAClYNj8drpq5gT0YnUWLRfRAXy332dBMK60G77HBdGCS2rcRuu3yHrSc9mZ/+GN1b+M/dQcp AWOlHBJqaxKFeNONf24fxUUzzP38XpuTEW4BdHlsSHVbxHTM0mucwANDMYNrXuDYaZLF0NpLx0k 5sLZnjsOkDvIOeS7wzqo08A0PM72xGeNrgbGYqOChcU02QTXd8qZBEMAHm5vR1FX0dehvUo6I9p msBgS7KWJLeFaGV4Jt4yMDgX1vM6bhvY2TCcbW7WT7/X7IDtJuBkMdFNjCyvquWH4F+BNr0M7HE knXxBhtG7mCoFatNrdihaKImz6gU5wXJTKU0UjFnq4EPOw9APKt/GeAD8Stru68dkvTQZubn7MQ JKJecTCX1uR/2EWV/+kaL0/xXPtvBFX9zHCu8TqfRd/AQqMZPETDY1rzzH27+jcPZb X-Received: by 2002:a05:6a00:929b:b0:82f:5051:f022 with SMTP id d2e1a72fcca58-82f8c8c7bc4mr25925691b3a.32.1776891092796; Wed, 22 Apr 2026 13:51:32 -0700 (PDT) Received: from smtp-us-east1-p01-i01-si01.dlp.protect.broadcom.com (address-144-49-247-21.dlp.protect.broadcom.com. [144.49.247.21]) by smtp-relay.gmail.com with ESMTPS id d2e1a72fcca58-82f8e966da4sm1369108b3a.1.2026.04.22.13.51.32 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Apr 2026 13:51:32 -0700 (PDT) X-Relaying-Domain: broadcom.com X-CFilter-Loop: Reflected Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-8aca6420fe3so73349996d6.0 for ; Wed, 22 Apr 2026 13:51:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1776891092; x=1777495892; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vduSvXKe+L7+c8UihFrzYyBr/PDlgqMu0Lyao+9fcwg=; b=QI7PqKzLWzAuNkIfzZJiec0NHheMU8OjtfQAjgiobcJBMl2qYP8y69mELAJGE/R2uN Fqszy0FMxhewwMmPgjrEjNPBHqBuu/wuzI9YU/upPQcPCxzyFD8xijBB2OSXWx1TTnr1 mDs+qFopodb2x+9cTnuXXJuJEIW7pLvV6fsq8= X-Forwarded-Encrypted: i=1; AFNElJ9/aUgxyW0c/Z2hlW8F9BtFh5m/37/dB77x4tVcw+UukmIJW/9uu0fX8dwhg0q8aAXaLjr1WvG4VX+eCRU=@vger.kernel.org X-Received: by 2002:a05:6214:478c:b0:8ac:b402:9af1 with SMTP id 6a1803df08f44-8b02814c824mr349683146d6.47.1776891091748; Wed, 22 Apr 2026 13:51:31 -0700 (PDT) X-Received: by 2002:a05:6214:478c:b0:8ac:b402:9af1 with SMTP id 6a1803df08f44-8b02814c824mr349682806d6.47.1776891091255; Wed, 22 Apr 2026 13:51:31 -0700 (PDT) Received: from mail.broadcom.net ([192.19.144.250]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8b02ae88d5fsm171453486d6.39.2026.04.22.13.51.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Apr 2026 13:51:30 -0700 (PDT) From: Kamal Dasu To: Ulf Hansson Cc: Adrian Hunter , Kees Cook , Tony Luck , "Guilherme G . Piccoli" , Florian Fainelli , Arend van Spriel , William Zhang , bcm-kernel-feedback-list@broadcom.com, linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, Kamal Dasu Subject: [PATCH v5 1/4] mmc: core: Add panic-context host operations for pstore backends Date: Wed, 22 Apr 2026 16:50:50 -0400 Message-Id: <20260422205053.3392395-2-kamal.dasu@broadcom.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260422205053.3392395-1-kamal.dasu@broadcom.com> References: <20260422205053.3392395-1-kamal.dasu@broadcom.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-DetectorID-Processed: b00c1d49-9d2e-4205-b15f-d015386d3d5e 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. Signed-off-by: Kamal Dasu --- drivers/mmc/core/core.c | 54 ++++++++++++++++++++++++++++++++++++++++ include/linux/mmc/host.h | 12 +++++++++ 2 files changed, 66 insertions(+) diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index 29e80e5f928e..076bd4eb2878 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -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. diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h index ba84f02c2a10..cd44b62d29cb 100644 --- a/include/linux/mmc/host.h +++ b/include/linux/mmc/host.h @@ -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 */ -- 2.34.1