linux-hyperv.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [bug report] PCI: hv: Fix a race condition when removing the device
@ 2021-08-23 15:21 Dan Carpenter
  2021-08-24  7:23 ` Long Li
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2021-08-23 15:21 UTC (permalink / raw)
  To: longli; +Cc: linux-hyperv

Hello Long Li,

The patch 94d22763207a: "PCI: hv: Fix a race condition when removing
the device" from May 12, 2021, leads to the following
Smatch static checker warning:

	drivers/pci/controller/pci-hyperv.c:3294 hv_pci_bus_exit()
	warn: sleeping in atomic context

drivers/pci/controller/pci-hyperv.c
    3287 
    3288 	if (!keep_devs) {
    3289 		/* Delete any children which might still exist. */
    3290 		spin_lock_irqsave(&hbus->device_list_lock, flags);
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This takes a spinlock.

    3291 		list_for_each_entry_safe(hpdev, tmp, &hbus->children, list_entry) {
    3292 			list_del(&hpdev->list_entry);
    3293 			if (hpdev->pci_slot)
--> 3294 				pci_destroy_slot(hpdev->pci_slot);
                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The pci_destroy_slot() function takes a mutex and you can't take a mutex
when you're holding a spinlock because it can sleep.

    3295 			/* For the two refs got in new_pcichild_device() */
    3296 			put_pcichild(hpdev);
    3297 			put_pcichild(hpdev);
    3298 		}
    3299 		spin_unlock_irqrestore(&hbus->device_list_lock, flags);
    3300 	}
    3301 
    3302 	ret = hv_send_resources_released(hdev);
    3303 	if (ret) {
    3304 		dev_err(&hdev->device,

regards,
dan carpenter

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

* RE: [bug report] PCI: hv: Fix a race condition when removing the device
  2021-08-23 15:21 [bug report] PCI: hv: Fix a race condition when removing the device Dan Carpenter
@ 2021-08-24  7:23 ` Long Li
  0 siblings, 0 replies; 2+ messages in thread
From: Long Li @ 2021-08-24  7:23 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: linux-hyperv

> Subject: [bug report] PCI: hv: Fix a race condition when removing the device
> 
> Hello Long Li,
> 
> The patch 94d22763207a: "PCI: hv: Fix a race condition when removing the
> device" from May 12, 2021, leads to the following Smatch static checker
> warning:
> 
> 	drivers/pci/controller/pci-hyperv.c:3294 hv_pci_bus_exit()
> 	warn: sleeping in atomic context
> 
> drivers/pci/controller/pci-hyperv.c
>     3287
>     3288 	if (!keep_devs) {
>     3289 		/* Delete any children which might still exist. */
>     3290 		spin_lock_irqsave(&hbus->device_list_lock, flags);
>                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> This takes a spinlock.
> 
>     3291 		list_for_each_entry_safe(hpdev, tmp, &hbus->children,
> list_entry) {
>     3292 			list_del(&hpdev->list_entry);
>     3293 			if (hpdev->pci_slot)
> --> 3294 				pci_destroy_slot(hpdev->pci_slot);
>                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The
> pci_destroy_slot() function takes a mutex and you can't take a mutex when
> you're holding a spinlock because it can sleep.
> 
>     3295 			/* For the two refs got in new_pcichild_device() */
>     3296 			put_pcichild(hpdev);
>     3297 			put_pcichild(hpdev);
>     3298 		}
>     3299 		spin_unlock_irqrestore(&hbus->device_list_lock, flags);
>     3300 	}
>     3301
>     3302 	ret = hv_send_resources_released(hdev);
>     3303 	if (ret) {
>     3304 		dev_err(&hdev->device,
> 
> regards,
> dan carpenter

Thank you, Dan. I have submitted a patch to fix this.

Long

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

end of thread, other threads:[~2021-08-24  7:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-23 15:21 [bug report] PCI: hv: Fix a race condition when removing the device Dan Carpenter
2021-08-24  7:23 ` Long Li

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).