Re: [PATCH v3 1/5] platform/x86/amd/hsmp: Serialize ACPI HSMP is_probed with a probe mutex

From: Ilpo Järvinen

Date: Tue Jul 07 2026 - 07:42:08 EST


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@xxxxxxx>
> ---
> 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.