Skip to contentSkip to conversation

platform/x86/amd/hsmp: ACPI/platform HSMP concurrency and lifecycle hardening

PATCH Superseded Muralidhara M K 1 participant 1 message Jul 7 x86 platform drivers

v3 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v3 cover platform/x86/amd/hsmp: ACPI/platform HSMP concurrency and lifecycle hardening

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.

It sits on top of the ACPI mailbox-parsing and data-plane readiness cleanups (base commit ff7836fa, "Gate the data plane on a fully initialized socket").

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.
2. Map the metric-table DRAM explicitly with ioremap() and unmap it from the driver teardown paths, so the mapping is no longer pinned to a per-socket devres scope and the ACPI side can coordinate its release.
3. Serialize per-socket metric-table reads with a mutex so two concurrent metrics_bin readers cannot have one trigger a fresh firmware fill while the other is mid-copy and return a torn snapshot. The mutex is initialized on both the platform and ACPI probe paths in this same patch so no bisection point reads metrics_bin through an uninitialized lock.
4. Replace the global is_probed flag with refcounted ACPI socket ownership (a probe-mutex-guarded counter) and run a coordinated release on the last unbind: deregister /dev/hsmp, unmap the metric DRAM, destroy the per-socket mutexes and free the socket array. Also drop a stale metric-table mapping before remapping on rebind, and stop parenting the shared /dev/hsmp to a per-socket device.
5. Add hsmp_sock_rwsem so the lock-free data plane (hsmp_send_message() and its MMIO access) is drained and kept out while a socket is torn down; wire both the platform and ACPI teardown paths into it, nested inside the ACPI probe mutex.

Testing:
- Each patch builds individually with no new warnings; the series is bisectable.
- checkpatch.pl --strict --codespell is clean on every patch.

Changes since v2:
- Split the old "Add explicit metric DRAM mapping and per-socket mutexes" patch into two single-purpose patches: the ioremap()/unmap mapping change (patch 2) and the per-socket read-serialization mutex (patch 3).
- Replaced the struct kref ACPI socket refcount with a simpler counter guarded by the existing probe mutex, and folded the coordinated release, the stale-metric-mapping-on-rebind fix and the /dev/hsmp parent fix into that one patch (patch 4).
- Decoupled the metric-table unmap (hsmp_unmap_metric_tbls()) from the mutex teardown (hsmp_destroy_metric_read_locks()) so each helper does exactly one thing.
- Wired the ACPI metric-read mutex init/destroy in the same patch that introduces the mutex, closing a bisection window where an ACPI metrics_bin read could lock an uninitialized mutex.
- Reordered the series so all hsmp_sock_rwsem writers (platform and ACPI teardown) land together in the final patch.

v2: https://lore.kernel.org/platform-driver-x86/[email protected]/T/#t

Muralidhara M K (5):
platform/x86/amd/hsmp: Serialize ACPI HSMP is_probed with a probe
mutex
platform/x86/amd/hsmp: Map the metric table with ioremap() and unmap
it explicitly
platform/x86/amd/hsmp: Serialize per-socket metric table reads with a
mutex
platform/x86/amd/hsmp: ACPI HSMP refcounted sockets and coordinated
release
platform/x86/amd/hsmp: Serialize the data plane against socket
teardown

 drivers/platform/x86/amd/hsmp/acpi.c | 130 ++++++++++++++++++++++++---
 drivers/platform/x86/amd/hsmp/hsmp.c | 118 +++++++++++++++++++++++-
 drivers/platform/x86/amd/hsmp/hsmp.h |  16 +++-
 drivers/platform/x86/amd/hsmp/plat.c |  42 ++++++++-
 4 files changed, 286 insertions(+), 20 deletions(-)

base-commit: ff7836fa850c2f815bc219f1e48f6ec8699f4ae7

Signature · 1 line
2.34.1