All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xen/pciback: don't call pcistub_device_put() under lock
@ 2023-03-28  8:45 Juergen Gross
  2023-03-28 11:46 ` Oleksandr Tyshchenko
  0 siblings, 1 reply; 2+ messages in thread
From: Juergen Gross @ 2023-03-28  8:45 UTC (permalink / raw)
  To: linux-kernel
  Cc: Juergen Gross, Stefano Stabellini, Oleksandr Tyshchenko,
	xen-devel, Dan Carpenter

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

Reported-by: Dan Carpenter <error27@gmail.com>
Link: https://lore.kernel.org/lkml/Y+JUIl64UDmdkboh@kadam/
Signed-off-by: Juergen Gross <jgross@suse.com>
---
 drivers/xen/xen-pciback/pci_stub.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/xen/xen-pciback/pci_stub.c b/drivers/xen/xen-pciback/pci_stub.c
index bba527620507..e34b623e4b41 100644
--- a/drivers/xen/xen-pciback/pci_stub.c
+++ b/drivers/xen/xen-pciback/pci_stub.c
@@ -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;
 }
-- 
2.35.3


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

* Re: [PATCH] xen/pciback: don't call pcistub_device_put() under lock
  2023-03-28  8:45 [PATCH] xen/pciback: don't call pcistub_device_put() under lock Juergen Gross
@ 2023-03-28 11:46 ` Oleksandr Tyshchenko
  0 siblings, 0 replies; 2+ messages in thread
From: Oleksandr Tyshchenko @ 2023-03-28 11:46 UTC (permalink / raw)
  To: Juergen Gross; +Cc: Stefano Stabellini, xen-devel, Dan Carpenter, linux-kernel



On 28.03.23 11:45, Juergen Gross wrote:

Hello Juergen

> 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().
> 
> Reported-by: Dan Carpenter <error27@gmail.com>
> Link: https://urldefense.com/v3/__https://lore.kernel.org/lkml/Y*JUIl64UDmdkboh@kadam/__;Kw!!GF_29dbcQIUBPA!wO4HR1jCrDMOfB1Ih2qEZs2jnqcieZUZnc6cPwh7Ta8hiLRKwS1Gs-1tmQP-NuEYoz9LhYWI8aFazIwIa8Lh$ [lore[.]kernel[.]org]
> Signed-off-by: Juergen Gross <jgross@suse.com>


Reviewed-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>

> ---
>   drivers/xen/xen-pciback/pci_stub.c | 6 ++----
>   1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/xen/xen-pciback/pci_stub.c b/drivers/xen/xen-pciback/pci_stub.c
> index bba527620507..e34b623e4b41 100644
> --- a/drivers/xen/xen-pciback/pci_stub.c
> +++ b/drivers/xen/xen-pciback/pci_stub.c
> @@ -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;
>   }

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

end of thread, other threads:[~2023-03-28 11:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-28  8:45 [PATCH] xen/pciback: don't call pcistub_device_put() under lock Juergen Gross
2023-03-28 11:46 ` Oleksandr Tyshchenko

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.