LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] acpi: scan: Fix a possible data race in acpi_scan_hotplug_enabled
@ 2018-05-08  3:08 Jia-Ju Bai
  2018-05-08 20:17 ` Rafael J. Wysocki
  0 siblings, 1 reply; 4+ messages in thread
From: Jia-Ju Bai @ 2018-05-08  3:08 UTC (permalink / raw)
  To: rjw, lenb; +Cc: linux-acpi, linux-kernel, Jia-Ju Bai

The write operation to "hotplug->enabled" is protected by
the lock on line 1760, but the read operation to
this data on line 1755 is not protected by the lock.
Thus, there may exist a data race for "hotplug->enabled".

To fix this data race, the read operation to "hotplug->enabled" is 
also protected by the lock.

Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
---
 drivers/acpi/scan.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 970dd87d347c..e21d7b0f7179 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -1752,11 +1752,13 @@ static struct acpi_scan_handler *acpi_scan_match_handler(const char *idstr,
 
 void acpi_scan_hotplug_enabled(struct acpi_hotplug_profile *hotplug, bool val)
 {
-	if (!!hotplug->enabled == !!val)
-		return;
-
 	mutex_lock(&acpi_scan_lock);
 
+	if (!!hotplug->enabled == !!val) {
+		mutex_unlock(&acpi_scan_lock);
+		return;
+	}
+
 	hotplug->enabled = val;
 
 	mutex_unlock(&acpi_scan_lock);
-- 
2.17.0

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] acpi: scan: Fix a possible data race in acpi_scan_hotplug_enabled
  2018-05-08  3:08 [PATCH] acpi: scan: Fix a possible data race in acpi_scan_hotplug_enabled Jia-Ju Bai
@ 2018-05-08 20:17 ` Rafael J. Wysocki
  2018-05-09  3:17   ` Jia-Ju Bai
  0 siblings, 1 reply; 4+ messages in thread
From: Rafael J. Wysocki @ 2018-05-08 20:17 UTC (permalink / raw)
  To: Jia-Ju Bai
  Cc: Rafael J. Wysocki, Len Brown, ACPI Devel Maling List,
	Linux Kernel Mailing List

On Tue, May 8, 2018 at 5:08 AM, Jia-Ju Bai <baijiaju1990@gmail.com> wrote:
> The write operation to "hotplug->enabled" is protected by
> the lock on line 1760, but the read operation to
> this data on line 1755 is not protected by the lock.
> Thus, there may exist a data race for "hotplug->enabled".

Either it does exist, or it doesn't.

If it exists, it needs to be fixed.  If it doesn't exist, nothing
needs to be done.

Which is the case?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] acpi: scan: Fix a possible data race in acpi_scan_hotplug_enabled
  2018-05-08 20:17 ` Rafael J. Wysocki
@ 2018-05-09  3:17   ` Jia-Ju Bai
  2018-05-09  7:53     ` Rafael J. Wysocki
  0 siblings, 1 reply; 4+ messages in thread
From: Jia-Ju Bai @ 2018-05-09  3:17 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Rafael J. Wysocki, Len Brown, ACPI Devel Maling List,
	Linux Kernel Mailing List



On 2018/5/9 4:17, Rafael J. Wysocki wrote:
> On Tue, May 8, 2018 at 5:08 AM, Jia-Ju Bai <baijiaju1990@gmail.com> wrote:
>> The write operation to "hotplug->enabled" is protected by
>> the lock on line 1760, but the read operation to
>> this data on line 1755 is not protected by the lock.
>> Thus, there may exist a data race for "hotplug->enabled".
> Either it does exist, or it doesn't.
>
> If it exists, it needs to be fixed.  If it doesn't exist, nothing
> needs to be done.
>
> Which is the case?

I only read the code and find this possible data race.
It is not found in real driver execution.
I am not sure of it, so I use "may" and "possible" here.


Best wishes,
Jia-Ju Bai

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] acpi: scan: Fix a possible data race in acpi_scan_hotplug_enabled
  2018-05-09  3:17   ` Jia-Ju Bai
@ 2018-05-09  7:53     ` Rafael J. Wysocki
  0 siblings, 0 replies; 4+ messages in thread
From: Rafael J. Wysocki @ 2018-05-09  7:53 UTC (permalink / raw)
  To: Jia-Ju Bai
  Cc: Rafael J. Wysocki, Rafael J. Wysocki, Len Brown,
	ACPI Devel Maling List, Linux Kernel Mailing List

On Wed, May 9, 2018 at 5:17 AM, Jia-Ju Bai <baijiaju1990@gmail.com> wrote:
>
>
> On 2018/5/9 4:17, Rafael J. Wysocki wrote:
>>
>> On Tue, May 8, 2018 at 5:08 AM, Jia-Ju Bai <baijiaju1990@gmail.com> wrote:
>>>
>>> The write operation to "hotplug->enabled" is protected by
>>> the lock on line 1760, but the read operation to
>>> this data on line 1755 is not protected by the lock.
>>> Thus, there may exist a data race for "hotplug->enabled".
>>
>> Either it does exist, or it doesn't.
>>
>> If it exists, it needs to be fixed.  If it doesn't exist, nothing
>> needs to be done.
>>
>> Which is the case?
>
>
> I only read the code and find this possible data race.
> It is not found in real driver execution.
> I am not sure of it, so I use "may" and "possible" here.

It looks like you are not actually sure what you are doing then.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-05-09  7:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-08  3:08 [PATCH] acpi: scan: Fix a possible data race in acpi_scan_hotplug_enabled Jia-Ju Bai
2018-05-08 20:17 ` Rafael J. Wysocki
2018-05-09  3:17   ` Jia-Ju Bai
2018-05-09  7:53     ` Rafael J. Wysocki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).