From: Lukas Wunner <lukas@wunner.de>
To: Stuart Hayes <stuart.w.hayes@gmail.com>
Cc: Bjorn Helgaas <helgaas@kernel.org>,
linux-pci@vger.kernel.org, Keith Busch <kbusch@kernel.org>,
kw@linux.com, pavel@ucw.cz
Subject: Re: [PATCH v3] Add support for PCIe SSD status LED management
Date: Sat, 14 Aug 2021 08:23:28 +0200 [thread overview]
Message-ID: <20210814062328.GA25723@wunner.de> (raw)
In-Reply-To: <20210813213653.3760-1-stuart.w.hayes@gmail.com>
On Fri, Aug 13, 2021 at 05:36:53PM -0400, Stuart Hayes wrote:
> +struct mutex drive_status_dev_list_lock;
> +struct list_head drive_status_dev_list;
Should be declared static.
> +const guid_t pcie_ssd_leds_dsm_guid =
> + GUID_INIT(0x5d524d9d, 0xfff9, 0x4d4b,
> + 0x8c, 0xb7, 0x74, 0x7e, 0xd5, 0x1e, 0x19, 0x4d);
Same.
> +struct drive_status_led_ops dsm_drive_status_led_ops = {
> + .get_supported_states = get_supported_states_dsm,
> + .get_current_states = get_current_states_dsm,
> + .set_current_states = set_current_states_dsm,
> +};
Same.
> +static void probe_pdev(struct pci_dev *pdev)
> +{
> + /*
> + * This is only supported on PCIe storage devices and PCIe ports
> + */
> + if (pdev->class != PCI_CLASS_STORAGE_EXPRESS &&
> + pdev->class != PCI_CLASS_BRIDGE_PCI)
> + return;
> + if (pdev_has_dsm(pdev))
> + add_drive_status_dev(pdev, &dsm_drive_status_led_ops);
> +}
Why is &dsm_drive_status_led_ops passed to add_drive_status_dev()?
It's always the same argument.
> +static int __init ssd_leds_init(void)
> +{
> + mutex_init(&drive_status_dev_list_lock);
> + INIT_LIST_HEAD(&drive_status_dev_list);
> +
> + bus_register_notifier(&pci_bus_type, &ssd_leds_pci_bus_nb);
> + initial_scan_for_leds();
> + return 0;
> +}
There's a concurrency issue here: initial_scan_for_leds() uses
bus_for_each_dev(), which walks the bus's klist_devices. When a
device is added (e.g. hotplugged), that device gets added to the
tail of klist_devices. (See call to klist_add_tail() in
bus_add_device().)
It is thus possible that probe_pdev() is run concurrently for the
same device, once by the notifier and once by initial_scan_for_leds().
The problem is that add_drive_status_dev() only checks at the top
of the function whether the device has already been added to
drive_status_dev_list. It goes on to instantiate the LED
and only then adds the device to drive_status_dev_list.
It's thus possible that the same LED is instantiated twice
which might confuse users.
Thanks,
Lukas
next prev parent reply other threads:[~2021-08-14 6:23 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-13 21:36 [PATCH v3] Add support for PCIe SSD status LED management Stuart Hayes
2021-08-14 6:23 ` Lukas Wunner [this message]
2021-10-04 17:41 ` stuart hayes
2021-10-05 4:41 ` Williams, Dan J
2021-08-18 7:05 ` Pavel Machek
2021-10-04 18:04 ` stuart hayes
2021-10-05 5:14 ` Williams, Dan J
2021-10-06 2:42 ` stuart hayes
2021-10-06 20:15 ` Dan Williams
2021-10-07 8:24 ` Pavel Machek
2021-10-07 11:32 ` Tkaczyk, Mariusz
2021-11-02 16:23 ` stuart hayes
2021-11-06 2:52 ` Dan Williams
2021-11-07 14:40 ` James Bottomley
2021-11-12 0:56 ` Krzysztof Wilczyński
2021-11-25 22:13 ` Bjorn Helgaas
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=20210814062328.GA25723@wunner.de \
--to=lukas@wunner.de \
--cc=helgaas@kernel.org \
--cc=kbusch@kernel.org \
--cc=kw@linux.com \
--cc=linux-pci@vger.kernel.org \
--cc=pavel@ucw.cz \
--cc=stuart.w.hayes@gmail.com \
/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 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).