From: "Pratik R. Sampat" <prsampat@amd.com>
To: <mcgrof@kernel.org>, <russ.weight@linux.dev>, <dakr@kernel.org>,
<ashish.kalra@amd.com>, <thomas.lendacky@amd.com>,
<herbert@gondor.apana.org.au>, <davem@davemloft.net>
Cc: <linux-crypto@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<gregkh@linuxfoundation.org>, <rafael@kernel.org>,
<chao.gao@intel.com>, <aik@amd.com>, <tycho@kernel.org>,
<nikunj@amd.com>, <michael.roth@amd.com>, <shansinha@google.com>,
<prsampat@amd.com>
Subject: [Patch v2 1/7] firmware_loader: Stop pinning modules on registration
Date: Fri, 18 Sep 2026 16:40:55 +0000 [thread overview]
Message-ID: <685e3707522394f212d62ff9f1bf64c5e0cb8a23.1789749016.git.prsampat@amd.com> (raw)
In-Reply-To: <cover.1789749016.git.prsampat@amd.com>
From: Dan Williams <djbw@kernel.org>
The module reference counting can result in callers pinning themselves in a
circular loop. The module reference counting is unnecessary.
firmware_upload_unregister() must be able to guarantee that all ops are
idle at return.
All ops are either called from sysfs or the workqueue, so unregister sysfs
to stop submissions, cancel any started transfers, flush cancelled
transfers, and then release the device.
This also solves a theoretical race of new submissions starting between
flush_work() and device_unregister(). The module reference was not
protecting against that race.
Cc: Luis Chamberlain <mcgrof@kernel.org>
Cc: Russ Weight <russ.weight@linux.dev>
Cc: Danilo Krummrich <dakr@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Reported-by: Chao Gao <chao.gao@intel.com>
Tested-by: Chao Gao <chao.gao@intel.com>
Closes: https://sashiko.dev/#/patchset/20260326084448.29947-1-chao.gao%40intel.com?patch=10705
Fixes: 97730bbb242c ("firmware_loader: Add firmware-upload support")
Signed-off-by: Dan Williams <djbw@kernel.org>
Signed-off-by: Pratik R. Sampat <prsampat@amd.com>
---
drivers/base/firmware_loader/sysfs_upload.c | 31 ++++++++++-----------
1 file changed, 14 insertions(+), 17 deletions(-)
diff --git a/drivers/base/firmware_loader/sysfs_upload.c b/drivers/base/firmware_loader/sysfs_upload.c
index efc33294212f..6f2123538682 100644
--- a/drivers/base/firmware_loader/sysfs_upload.c
+++ b/drivers/base/firmware_loader/sysfs_upload.c
@@ -312,14 +312,9 @@ firmware_upload_register(struct module *module, struct device *parent,
return ERR_PTR(-EINVAL);
}
- if (!try_module_get(module))
- return ERR_PTR(-EFAULT);
-
fw_upload = kzalloc_obj(*fw_upload);
- if (!fw_upload) {
- ret = -ENOMEM;
- goto exit_module_put;
- }
+ if (!fw_upload)
+ return ERR_PTR(-ENOMEM);
fw_upload_priv = kzalloc_obj(*fw_upload_priv);
if (!fw_upload_priv) {
@@ -361,7 +356,7 @@ firmware_upload_register(struct module *module, struct device *parent,
if (ret) {
dev_err(fw_dev, "%s: device_register failed\n", __func__);
put_device(fw_dev);
- goto exit_module_put;
+ return ERR_PTR(ret);
}
return fw_upload;
@@ -372,9 +367,6 @@ firmware_upload_register(struct module *module, struct device *parent,
free_fw_upload:
kfree(fw_upload);
-exit_module_put:
- module_put(module);
-
return ERR_PTR(ret);
}
EXPORT_SYMBOL_GPL(firmware_upload_register);
@@ -386,23 +378,28 @@ EXPORT_SYMBOL_GPL(firmware_upload_register);
void firmware_upload_unregister(struct fw_upload *fw_upload)
{
struct fw_sysfs *fw_sysfs = fw_upload->priv;
+ struct device *parent = fw_sysfs->dev.parent;
struct fw_upload_priv *fw_upload_priv = fw_sysfs->fw_upload_priv;
- struct module *module = fw_upload_priv->module;
+
+ /* hold a parent reference while child is unregistered */
+ get_device(parent);
+
+ /* shutdown the sysfs interface to block new requests */
+ device_del(&fw_sysfs->dev);
mutex_lock(&fw_upload_priv->lock);
if (fw_upload_priv->progress == FW_UPLOAD_PROG_IDLE) {
mutex_unlock(&fw_upload_priv->lock);
- goto unregister;
+ goto release;
}
fw_upload_priv->ops->cancel(fw_upload);
mutex_unlock(&fw_upload_priv->lock);
+release:
/* Ensure lower-level device-driver is finished */
flush_work(&fw_upload_priv->work);
-
-unregister:
- device_unregister(&fw_sysfs->dev);
- module_put(module);
+ put_device(&fw_sysfs->dev);
+ put_device(parent);
}
EXPORT_SYMBOL_GPL(firmware_upload_unregister);
--
2.43.0
next prev parent reply other threads:[~2026-09-18 16:41 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-18 16:40 [Patch v2 0/7] Implement SNP live firmware update support Pratik R. Sampat
2026-09-18 16:40 ` Pratik R. Sampat [this message]
2026-09-18 16:40 ` [Patch v2 2/7] firmware_loader: Stop pinning parent device per workqueue invocation Pratik R. Sampat
2026-09-18 16:40 ` [Patch v2 3/7] treewide: firmware_loader: Drop the unused @module argument Pratik R. Sampat
2026-09-18 16:40 ` [Patch v2 4/7] crypto: ccp - Factor out the release of the SEV firmware buffers Pratik R. Sampat
2026-09-18 16:40 ` [Patch v2 5/7] crypto: ccp - Allow SNP platform data to be queried after SNP INIT Pratik R. Sampat
2026-09-18 16:41 ` [Patch v2 6/7] crypto/ccp: Register with fw_uploader and always fail Pratik R. Sampat
2026-09-18 16:41 ` [Patch v2 7/7] crypto/ccp: Implement SNP Download Firmware EX Pratik R. Sampat
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=685e3707522394f212d62ff9f1bf64c5e0cb8a23.1789749016.git.prsampat@amd.com \
--to=prsampat@amd.com \
--cc=aik@amd.com \
--cc=ashish.kalra@amd.com \
--cc=chao.gao@intel.com \
--cc=dakr@kernel.org \
--cc=davem@davemloft.net \
--cc=gregkh@linuxfoundation.org \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mcgrof@kernel.org \
--cc=michael.roth@amd.com \
--cc=nikunj@amd.com \
--cc=rafael@kernel.org \
--cc=russ.weight@linux.dev \
--cc=shansinha@google.com \
--cc=thomas.lendacky@amd.com \
--cc=tycho@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®