* [PATCH v3 1/5] platform/x86/amd/hsmp: Serialize ACPI HSMP is_probed with a probe mutex
@ 2026-07-07 5:16 Muralidhara M K
2026-07-07 11:40 ` Ilpo Järvinen
0 siblings, 1 reply; 3+ messages in thread
From: Muralidhara M K @ 2026-07-07 5:16 UTC (permalink / raw)
To: ilpo.jarvinen
Cc: platform-driver-x86, linux-kernel, muthusamy.ramalingam,
Muralidhara M K
Add hsmp_acpi_probe_mutex and hold it across ACPI probe, remove, and
init_acpi() so concurrent platform probes cannot race the global is_probed
handshake or the one-time socket allocation. Use lockdep_assert_held() in
init_acpi() to catch incorrect locking under lockdep.
Signed-off-by: Muralidhara M K <muralidhara.mk@amd.com>
---
drivers/platform/x86/amd/hsmp/acpi.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/drivers/platform/x86/amd/hsmp/acpi.c b/drivers/platform/x86/amd/hsmp/acpi.c
index 72f68cef1297..206eb7897b61 100644
--- a/drivers/platform/x86/amd/hsmp/acpi.c
+++ b/drivers/platform/x86/amd/hsmp/acpi.c
@@ -18,8 +18,11 @@
#include <linux/device.h>
#include <linux/dev_printk.h>
#include <linux/ioport.h>
+#include <linux/cleanup.h>
+#include <linux/lockdep.h>
#include <linux/kstrtox.h>
#include <linux/module.h>
+#include <linux/mutex.h>
#include <linux/platform_device.h>
#include <linux/string.h>
#include <linux/sysfs.h>
@@ -39,6 +42,8 @@
static struct hsmp_plat_device *hsmp_pdev;
+static DEFINE_MUTEX(hsmp_acpi_probe_mutex);
+
struct hsmp_sys_attr {
struct device_attribute dattr;
u32 msg_id;
@@ -482,11 +487,17 @@ static ssize_t hsmp_freq_limit_source_show(struct device *dev, struct device_att
return len;
}
+/**
+ * init_acpi() - Parse ACPI mailbox resources for one socket and validate HSMP.
+ * @dev: ACPI companion device for this socket.
+ */
static int init_acpi(struct device *dev)
{
u16 sock_ind;
int ret;
+ lockdep_assert_held(&hsmp_acpi_probe_mutex);
+
ret = hsmp_get_uid(dev, &sock_ind);
if (ret)
return ret;
@@ -607,6 +618,8 @@ static int hsmp_acpi_probe(struct platform_device *pdev)
if (!hsmp_pdev)
return -ENOMEM;
+ guard(mutex)(&hsmp_acpi_probe_mutex);
+
if (!hsmp_pdev->is_probed) {
hsmp_pdev->num_sockets = topology_max_packages();
if (!hsmp_pdev->num_sockets) {
@@ -642,6 +655,7 @@ static int hsmp_acpi_probe(struct platform_device *pdev)
static void hsmp_acpi_remove(struct platform_device *pdev)
{
+ mutex_lock(&hsmp_acpi_probe_mutex);
/*
* We register only one misc_device even on multi-socket system.
* So, deregister should happen only once.
@@ -650,6 +664,7 @@ static void hsmp_acpi_remove(struct platform_device *pdev)
hsmp_misc_deregister();
hsmp_pdev->is_probed = false;
}
+ mutex_unlock(&hsmp_acpi_probe_mutex);
}
static struct platform_driver amd_hsmp_driver = {
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH v3 1/5] platform/x86/amd/hsmp: Serialize ACPI HSMP is_probed with a probe mutex
2026-07-07 5:16 [PATCH v3 1/5] platform/x86/amd/hsmp: Serialize ACPI HSMP is_probed with a probe mutex Muralidhara M K
@ 2026-07-07 11:40 ` Ilpo Järvinen
0 siblings, 0 replies; 3+ messages in thread
From: Ilpo Järvinen @ 2026-07-07 11:40 UTC (permalink / raw)
To: Muralidhara M K; +Cc: platform-driver-x86, LKML, muthusamy.ramalingam
On Tue, 7 Jul 2026, Muralidhara M K wrote:
> Add hsmp_acpi_probe_mutex and hold it across ACPI probe, remove, and
> init_acpi() so concurrent platform probes cannot race the global is_probed
> handshake or the one-time socket allocation. Use lockdep_assert_held() in
> init_acpi() to catch incorrect locking under lockdep.
>
> Signed-off-by: Muralidhara M K <muralidhara.mk@amd.com>
> ---
> drivers/platform/x86/amd/hsmp/acpi.c | 15 +++++++++++++++
> 1 file changed, 15 insertions(+)
>
> diff --git a/drivers/platform/x86/amd/hsmp/acpi.c b/drivers/platform/x86/amd/hsmp/acpi.c
> index 72f68cef1297..206eb7897b61 100644
> --- a/drivers/platform/x86/amd/hsmp/acpi.c
> +++ b/drivers/platform/x86/amd/hsmp/acpi.c
> @@ -18,8 +18,11 @@
> #include <linux/device.h>
> #include <linux/dev_printk.h>
> #include <linux/ioport.h>
> +#include <linux/cleanup.h>
> +#include <linux/lockdep.h>
> #include <linux/kstrtox.h>
> #include <linux/module.h>
> +#include <linux/mutex.h>
> #include <linux/platform_device.h>
> #include <linux/string.h>
> #include <linux/sysfs.h>
> @@ -39,6 +42,8 @@
>
> static struct hsmp_plat_device *hsmp_pdev;
>
> +static DEFINE_MUTEX(hsmp_acpi_probe_mutex);
> +
> struct hsmp_sys_attr {
> struct device_attribute dattr;
> u32 msg_id;
> @@ -482,11 +487,17 @@ static ssize_t hsmp_freq_limit_source_show(struct device *dev, struct device_att
> return len;
> }
>
> +/**
> + * init_acpi() - Parse ACPI mailbox resources for one socket and validate HSMP.
> + * @dev: ACPI companion device for this socket.
> + */
> static int init_acpi(struct device *dev)
> {
> u16 sock_ind;
> int ret;
>
> + lockdep_assert_held(&hsmp_acpi_probe_mutex);
> +
> ret = hsmp_get_uid(dev, &sock_ind);
> if (ret)
> return ret;
> @@ -607,6 +618,8 @@ static int hsmp_acpi_probe(struct platform_device *pdev)
> if (!hsmp_pdev)
> return -ENOMEM;
>
> + guard(mutex)(&hsmp_acpi_probe_mutex);
> +
> if (!hsmp_pdev->is_probed) {
> hsmp_pdev->num_sockets = topology_max_packages();
> if (!hsmp_pdev->num_sockets) {
> @@ -642,6 +655,7 @@ static int hsmp_acpi_probe(struct platform_device *pdev)
>
> static void hsmp_acpi_remove(struct platform_device *pdev)
> {
> + mutex_lock(&hsmp_acpi_probe_mutex);
Any particular reason why this too doesn't use guard()?
> /*
> * We register only one misc_device even on multi-socket system.
> * So, deregister should happen only once.
> @@ -650,6 +664,7 @@ static void hsmp_acpi_remove(struct platform_device *pdev)
> hsmp_misc_deregister();
> hsmp_pdev->is_probed = false;
> }
> + mutex_unlock(&hsmp_acpi_probe_mutex);
> }
>
> static struct platform_driver amd_hsmp_driver = {
>
--
i.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH v3 0/5] platform/x86/amd/hsmp: ACPI/platform HSMP concurrency and lifecycle hardening
@ 2026-07-06 14:21 Muralidhara M K
2026-07-06 14:21 ` [PATCH v3 1/5] platform/x86/amd/hsmp: Serialize ACPI HSMP is_probed with a probe mutex Muralidhara M K
0 siblings, 1 reply; 3+ messages in thread
From: Muralidhara M K @ 2026-07-06 14:21 UTC (permalink / raw)
To: ilpo.jarvinen; +Cc: platform-driver-x86, linux-kernel, Muralidhara M K
This series hardens the AMD HSMP ACPI and platform drivers against
probe/remove concurrency, use-after-free of the per-socket state, and
resource leaks across unbind/rebind cycles.
On multi-socket systems several ACPI platform devices are probed and
removed independently while a single /dev/hsmp (and the hwmon sysfs
attributes) drive a lock-free data plane. The existing code raced the
global is_probed handshake and the one-time socket allocation, freed the
socket array from under in-flight hsmp_send_message() callers, and leaked
metric-table mappings on rebind.
The patches, in order:
1. Serialize ACPI probe/remove/init_acpi() with a dedicated mutex so
the is_probed handshake and the one-time socket allocation cannot
race across per-socket platform devices.
2. Map the metric-table DRAM explicitly and add per-socket mutexes.
3. Add hsmp_sock_rwsem so the lock-free data plane is drained and kept
out while a socket is torn down; wire the non-ACPI platform path
into it.
4. Refcount the ACPI socket platform devices with struct kref and run a
coordinated release on the final put (deregister /dev/hsmp, unmap
metric DRAM, free the socket array); clear the per-socket dev under
the teardown write lock on both remove and probe failure.
5. Drop any stale metric-table mapping before remapping on rebind.
Testing:
- Each patch builds individually (W=1) with no new warnings; the series
is bisectable.
- checkpatch.pl --strict is clean on every patch.
Changes since v2:
- This revision covers only the five ACPI/platform probe, teardown, and
lifecycle patches. The ACPI UID / _DSD mailbox validation and the
sock->dev readiness-gate changes from v2 are accepted in maintainer branch.
- Reworded the teardown rwsem comments in "Serialize the data plane
against socket teardown" so they describe the drain contract in terms
of a generic teardown path (a teardown path takes the write side)
rather than attributing it to the ACPI path, which is wired into the
drain in the following patch.
v2: https://patch.msgid.link/20260625123337.886435-1-muralidhara.mk@amd.com
Muralidhara M K (5):
platform/x86/amd/hsmp: Serialize ACPI HSMP is_probed with a probe
mutex
platform/x86/amd/hsmp: Add explicit metric DRAM mapping and per-socket
mutexes
platform/x86/amd/hsmp: Serialize the data plane against socket
teardown
platform/x86/amd/hsmp: ACPI HSMP refcounted sockets and coordinated
release
platform/x86/amd/hsmp: Drop stale metric table mapping on rebind
drivers/platform/x86/amd/hsmp/acpi.c | 147 ++++++++++++++++++++++++---
drivers/platform/x86/amd/hsmp/hsmp.c | 112 ++++++++++++++++++--
drivers/platform/x86/amd/hsmp/hsmp.h | 11 +-
drivers/platform/x86/amd/hsmp/plat.c | 39 ++++++-
4 files changed, 285 insertions(+), 24 deletions(-)
base-commit: ff7836fa850c2f815bc219f1e48f6ec8699f4ae7
--
2.34.1
^ permalink raw reply [flat|nested] 3+ messages in thread* [PATCH v3 1/5] platform/x86/amd/hsmp: Serialize ACPI HSMP is_probed with a probe mutex
2026-07-06 14:21 [PATCH v3 0/5] platform/x86/amd/hsmp: ACPI/platform HSMP concurrency and lifecycle hardening Muralidhara M K
@ 2026-07-06 14:21 ` Muralidhara M K
0 siblings, 0 replies; 3+ messages in thread
From: Muralidhara M K @ 2026-07-06 14:21 UTC (permalink / raw)
To: ilpo.jarvinen; +Cc: platform-driver-x86, linux-kernel, Muralidhara M K
Add hsmp_acpi_probe_mutex and hold it across ACPI probe, remove, and
init_acpi() so concurrent platform probes cannot race the global is_probed
handshake or the one-time socket allocation. Use lockdep_assert_held() in
init_acpi() to catch incorrect locking under lockdep.
Signed-off-by: Muralidhara M K <muralidhara.mk@amd.com>
---
drivers/platform/x86/amd/hsmp/acpi.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/drivers/platform/x86/amd/hsmp/acpi.c b/drivers/platform/x86/amd/hsmp/acpi.c
index 72f68cef1297..206eb7897b61 100644
--- a/drivers/platform/x86/amd/hsmp/acpi.c
+++ b/drivers/platform/x86/amd/hsmp/acpi.c
@@ -18,8 +18,11 @@
#include <linux/device.h>
#include <linux/dev_printk.h>
#include <linux/ioport.h>
+#include <linux/cleanup.h>
+#include <linux/lockdep.h>
#include <linux/kstrtox.h>
#include <linux/module.h>
+#include <linux/mutex.h>
#include <linux/platform_device.h>
#include <linux/string.h>
#include <linux/sysfs.h>
@@ -39,6 +42,8 @@
static struct hsmp_plat_device *hsmp_pdev;
+static DEFINE_MUTEX(hsmp_acpi_probe_mutex);
+
struct hsmp_sys_attr {
struct device_attribute dattr;
u32 msg_id;
@@ -482,11 +487,17 @@ static ssize_t hsmp_freq_limit_source_show(struct device *dev, struct device_att
return len;
}
+/**
+ * init_acpi() - Parse ACPI mailbox resources for one socket and validate HSMP.
+ * @dev: ACPI companion device for this socket.
+ */
static int init_acpi(struct device *dev)
{
u16 sock_ind;
int ret;
+ lockdep_assert_held(&hsmp_acpi_probe_mutex);
+
ret = hsmp_get_uid(dev, &sock_ind);
if (ret)
return ret;
@@ -607,6 +618,8 @@ static int hsmp_acpi_probe(struct platform_device *pdev)
if (!hsmp_pdev)
return -ENOMEM;
+ guard(mutex)(&hsmp_acpi_probe_mutex);
+
if (!hsmp_pdev->is_probed) {
hsmp_pdev->num_sockets = topology_max_packages();
if (!hsmp_pdev->num_sockets) {
@@ -642,6 +655,7 @@ static int hsmp_acpi_probe(struct platform_device *pdev)
static void hsmp_acpi_remove(struct platform_device *pdev)
{
+ mutex_lock(&hsmp_acpi_probe_mutex);
/*
* We register only one misc_device even on multi-socket system.
* So, deregister should happen only once.
@@ -650,6 +664,7 @@ static void hsmp_acpi_remove(struct platform_device *pdev)
hsmp_misc_deregister();
hsmp_pdev->is_probed = false;
}
+ mutex_unlock(&hsmp_acpi_probe_mutex);
}
static struct platform_driver amd_hsmp_driver = {
base-commit: ff7836fa850c2f815bc219f1e48f6ec8699f4ae7
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-07-07 11:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-07 5:16 [PATCH v3 1/5] platform/x86/amd/hsmp: Serialize ACPI HSMP is_probed with a probe mutex Muralidhara M K
2026-07-07 11:40 ` Ilpo Järvinen
-- strict thread matches above, loose matches on Subject: below --
2026-07-06 14:21 [PATCH v3 0/5] platform/x86/amd/hsmp: ACPI/platform HSMP concurrency and lifecycle hardening Muralidhara M K
2026-07-06 14:21 ` [PATCH v3 1/5] platform/x86/amd/hsmp: Serialize ACPI HSMP is_probed with a probe mutex Muralidhara M K
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox