Skip to contentSkip to conversation

xen/pciback: don't call pcistub_device_put() under lock

PATCH In review Juergen Gross 2 participants 2 messages Mar 28, 2023 Xen hypervisor interface

lore
Share & tools
lore

Juergen Gross

author maintainer
#0 lore raw

PATCH 1/1 xen/pciback: don't call pcistub_device_put() under lock

pcistub_device_put() shouldn't be called under spinlock, as it can sleep.

For this reason pcistub_device_get_pci_dev() needs to be modified:
instead of always calling pcistub_device_get() just do the call of pcistub_device_get() only if it is really needed. This removes the need to call pcistub_device_put().

---
 drivers/xen/xen-pciback/pci_stub.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/xen/xen-pciback/pci_stub.c +2 -4
index bba527620507..e34b623e4b41 100644
@@ -194,8 +194,6 @@ static struct pci_dev *pcistub_device_get_pci_dev(struct xen_pcibk_device *pdev,
 	struct pci_dev *pci_dev = NULL;
 	unsigned long flags;
 
-	pcistub_device_get(psdev);
-
 	spin_lock_irqsave(&psdev->lock, flags);
 	if (!psdev->pdev) {
 		psdev->pdev = pdev;
@@ -203,8 +201,8 @@ static struct pci_dev *pcistub_device_get_pci_dev(struct xen_pcibk_device *pdev,
 	}
 	spin_unlock_irqrestore(&psdev->lock, flags);
 
-	if (!pci_dev)
-		pcistub_device_put(psdev);
+	if (pci_dev)
+		pcistub_device_get(psdev);
 
 	return pci_dev;
 }
Signature · 1 line
2.35.3
reviewer Reviewed-by on v1 1/1
#1 lore raw

On 28.03.23 11:45, Juergen Gross wrote:

Hello Juergen

Quoted 11 lines

pcistub_device_put() shouldn't be called under spinlock, as it can sleep.

For this reason pcistub_device_get_pci_dev() needs to be modified:
instead of always calling pcistub_device_get() just do the call of pcistub_device_get() only if it is really needed. This removes the need to call pcistub_device_put().

Quoted 28 lines
---
  drivers/xen/xen-pciback/pci_stub.c | 6 ++----
  1 file changed, 2 insertions(+), 4 deletions(-)
drivers/xen/xen-pciback/pci_stub.c +2 -4
index bba527620507..e34b623e4b41 100644
@@ -194,8 +194,6 @@ static struct pci_dev *pcistub_device_get_pci_dev(struct xen_pcibk_device *pdev,
  	struct pci_dev *pci_dev = NULL;
  	unsigned long flags;
 
-	pcistub_device_get(psdev);
-
  	spin_lock_irqsave(&psdev->lock, flags);
  	if (!psdev->pdev) {
  		psdev->pdev = pdev;
@@ -203,8 +201,8 @@ static struct pci_dev *pcistub_device_get_pci_dev(struct xen_pcibk_device *pdev,
  	}
  	spin_unlock_irqrestore(&psdev->lock, flags);
 
-	if (!pci_dev)
-		pcistub_device_put(psdev);
+	if (pci_dev)
+		pcistub_device_get(psdev);
 
  	return pci_dev;
  }