From: Suma Hegde <Suma.Hegde@amd.com>
To: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Cc: platform-driver-x86@vger.kernel.org,
Hans de Goede <hdegoede@redhat.com>,
Naveen Krishna Chatradhi <naveenkrishna.chatradhi@amd.com>
Subject: Re: [PATCH v2 4/4] platform/x86/amd/hsmp: Ensure initialization of the sock struct in hsmp_send_message()
Date: Sat, 2 Aug 2025 18:01:28 +0530 [thread overview]
Message-ID: <534f7096-8ecb-490e-9aca-ee4ecde44e17@amd.com> (raw)
In-Reply-To: <dd58fb6a-021c-4467-9873-7832e2185ca2@amd.com>
Hi Ilpo,
On 7/24/2025 2:50 PM, Suma Hegde wrote:
> Caution: This message originated from an External Source. Use proper
> caution when opening attachments, clicking links, or responding.
>
>
> Hi Ilpo,
>
>
> On 7/23/2025 12:40 PM, Ilpo Järvinen wrote:
>> Caution: This message originated from an External Source. Use proper
>> caution when opening attachments, clicking links, or responding.
>>
>>
>> On Wed, 23 Jul 2025, Suma Hegde wrote:
>>
>>> If all sockets are not probed, invoking hsmp_send_message() might
>>> result in
>>> unexpected behavior due to accessing an uninitialized socket structure.
>>>
>>> The initialization of the sock structure can be confirmed if sock->dev
>>> is initialized.
>>>
>>> Signed-off-by: Suma Hegde <suma.hegde@amd.com>
>>> Reviewed-by: Naveen Krishna Chatradhi <naveenkrishna.chatradhi@amd.com>
>>> ---
>>> Changes since v1:
>>> New patch to address the partial probe/removal issue.
>>>
>>> drivers/platform/x86/amd/hsmp/acpi.c | 4 ++++
>>> drivers/platform/x86/amd/hsmp/hsmp.c | 3 +++
>>> 2 files changed, 7 insertions(+)
>>>
>>> diff --git a/drivers/platform/x86/amd/hsmp/acpi.c
>>> b/drivers/platform/x86/amd/hsmp/acpi.c
>>> index 15c4cedc2759..a2d91d4a3e02 100644
>>> --- a/drivers/platform/x86/amd/hsmp/acpi.c
>>> +++ b/drivers/platform/x86/amd/hsmp/acpi.c
>>> @@ -617,6 +617,10 @@ static int hsmp_acpi_probe(struct
>>> platform_device *pdev)
>>>
>>> static void hsmp_acpi_remove(struct platform_device *pdev)
>>> {
>>> + struct hsmp_socket *sock = dev_get_drvdata(&pdev->dev);
>>> +
>>> + sock->dev = NULL;
>>> +
>>> guard(mutex)(&hsmp_lock);
>>> /*
>>> * We register only one misc_device even on multi-socket system.
>>> diff --git a/drivers/platform/x86/amd/hsmp/hsmp.c
>>> b/drivers/platform/x86/amd/hsmp/hsmp.c
>>> index e05d824045d6..a4420db42781 100644
>>> --- a/drivers/platform/x86/amd/hsmp/hsmp.c
>>> +++ b/drivers/platform/x86/amd/hsmp/hsmp.c
>>> @@ -219,6 +219,9 @@ int hsmp_send_message(struct hsmp_message *msg)
>>> return -ENODEV;
>>> sock = &hsmp_pdev.sock[msg->sock_ind];
>>>
>>> + if (!sock->dev)
>>> + return -ENODEV;
>>> +
>>> ret = down_interruptible(&sock->hsmp_sem);
>>> if (ret < 0)
>>> return ret;
>> This is still racy. AFAICT, nothing prevents assigning NULL into
>> sock->dev
>> because of remove while hsmp_send_message() is running and that can
>> result
>> in dereferencing NULL.
>
> Could you please suggest on how to resolve this issue?
>
>
I will relocate hsmp_fops to acpi.c and plat.c from hsmp.c.
Consequently, the module reference
count for hsmp_acpi should be incremented when the device file is opened.
Does this solution address the issue adequately? Is it acceptable?
>> --
>> i.
>
>
> Thanks and Regards,
>
> Suma
>
>
next prev parent reply other threads:[~2025-08-02 12:31 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-23 5:12 [PATCH v2 0/4] platform/x86/amd/hsmp: Fix potential issues during async probing of ACPI driver Suma Hegde
2025-07-23 5:12 ` [PATCH v2 1/4] platform/x86/amd/hsmp: Use mutex to synchronize ACPI based probe Suma Hegde
2025-08-19 8:23 ` Ilpo Järvinen
2025-07-23 5:12 ` [PATCH v2 2/4] platform/x86/amd/hsmp: Add reference counter to track ACPI probe and removal Suma Hegde
2025-07-23 7:17 ` Ilpo Järvinen
2025-07-23 5:12 ` [PATCH v2 3/4] platform/x86/amd/hsmp: Move initialization of num_sockets to hsmp_common_init() Suma Hegde
2025-07-23 5:12 ` [PATCH v2 4/4] platform/x86/amd/hsmp: Ensure initialization of the sock struct in hsmp_send_message() Suma Hegde
2025-07-23 7:10 ` Ilpo Järvinen
2025-07-24 9:20 ` Suma Hegde
2025-08-02 12:31 ` Suma Hegde [this message]
2025-08-19 8:21 ` Ilpo Järvinen
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=534f7096-8ecb-490e-9aca-ee4ecde44e17@amd.com \
--to=suma.hegde@amd.com \
--cc=hdegoede@redhat.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=naveenkrishna.chatradhi@amd.com \
--cc=platform-driver-x86@vger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.