public inbox for linux-hyperv@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] PCI: hv: Fix double ida_free in hv_pci_probe error path
@ 2026-04-03 12:09 Sahil Chandna
  2026-04-03 17:16 ` Saurabh Singh Sengar
  2026-04-04  2:42 ` Manivannan Sadhasivam
  0 siblings, 2 replies; 4+ messages in thread
From: Sahil Chandna @ 2026-04-03 12:09 UTC (permalink / raw)
  To: kys, haiyangz, wei.liu, decui, longli, lpieralisi, kwilczynski,
	mani, robh, bhelgaas, dan.j.williams, mhklinux, linux-hyperv,
	linux-pci, linux-kernel

If hv_pci_probe() fails after storing the domain number in
hbus->bridge->domain_nr, there is a call to free this domain_nr via
pci_bus_release_emul_domain_nr(), however, during cleanup, the bridge
release callback pci_release_host_bridge_dev() also frees the domain_nr
causing ida_free to be called on same ID twice and triggering following
warning:

  ida_free called for id=28971 which is not allocated.
  WARNING: lib/idr.c:594 at ida_free+0xdf/0x160, CPU#0: kworker/0:2/198
  Call Trace:
   pci_bus_release_emul_domain_nr+0x17/0x20
   pci_release_host_bridge_dev+0x4b/0x60
   device_release+0x3b/0xa0
   kobject_put+0x8e/0x220
   devm_pci_alloc_host_bridge_release+0xe/0x20
   devres_release_all+0x9a/0xd0
   device_unbind_cleanup+0x12/0xa0
   really_probe+0x1c5/0x3f0
   vmbus_add_channel_work+0x135/0x1a0

Fix this by letting pci core handle the free domain_nr and remove
the explicit free called in pci-hyperv driver.

Fixes: bcce8c74f1ce ("PCI: Enable host bridge emulation for PCI_DOMAINS_GENERIC platforms")
Signed-off-by: Sahil Chandna <sahilchandna@linux.microsoft.com>
---
 drivers/pci/controller/pci-hyperv.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c
index 2c7a406b4ba8..5616ad5d2a8f 100644
--- a/drivers/pci/controller/pci-hyperv.c
+++ b/drivers/pci/controller/pci-hyperv.c
@@ -3778,7 +3778,7 @@ static int hv_pci_probe(struct hv_device *hdev,
 					   hbus->bridge->domain_nr);
 	if (!hbus->wq) {
 		ret = -ENOMEM;
-		goto free_dom;
+		goto free_bus;
 	}

 	hdev->channel->next_request_id_callback = vmbus_next_request_id;
@@ -3874,8 +3874,6 @@ static int hv_pci_probe(struct hv_device *hdev,
 	vmbus_close(hdev->channel);
 destroy_wq:
 	destroy_workqueue(hbus->wq);
-free_dom:
-	pci_bus_release_emul_domain_nr(hbus->bridge->domain_nr);
 free_bus:
 	kfree(hbus);
 	return ret;
--
2.53.0


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

* Re: [PATCH] PCI: hv: Fix double ida_free in hv_pci_probe error path
  2026-04-03 12:09 [PATCH] PCI: hv: Fix double ida_free in hv_pci_probe error path Sahil Chandna
@ 2026-04-03 17:16 ` Saurabh Singh Sengar
  2026-04-04  2:42 ` Manivannan Sadhasivam
  1 sibling, 0 replies; 4+ messages in thread
From: Saurabh Singh Sengar @ 2026-04-03 17:16 UTC (permalink / raw)
  To: Sahil Chandna
  Cc: kys, haiyangz, wei.liu, decui, longli, lpieralisi, kwilczynski,
	mani, robh, bhelgaas, dan.j.williams, mhklinux, linux-hyperv,
	linux-pci, linux-kernel

On Fri, Apr 03, 2026 at 05:09:29AM -0700, Sahil Chandna wrote:
> If hv_pci_probe() fails after storing the domain number in
> hbus->bridge->domain_nr, there is a call to free this domain_nr via
> pci_bus_release_emul_domain_nr(), however, during cleanup, the bridge
> release callback pci_release_host_bridge_dev() also frees the domain_nr
> causing ida_free to be called on same ID twice and triggering following
> warning:
> 
>   ida_free called for id=28971 which is not allocated.
>   WARNING: lib/idr.c:594 at ida_free+0xdf/0x160, CPU#0: kworker/0:2/198
>   Call Trace:
>    pci_bus_release_emul_domain_nr+0x17/0x20
>    pci_release_host_bridge_dev+0x4b/0x60
>    device_release+0x3b/0xa0
>    kobject_put+0x8e/0x220
>    devm_pci_alloc_host_bridge_release+0xe/0x20
>    devres_release_all+0x9a/0xd0
>    device_unbind_cleanup+0x12/0xa0
>    really_probe+0x1c5/0x3f0
>    vmbus_add_channel_work+0x135/0x1a0
> 
> Fix this by letting pci core handle the free domain_nr and remove
> the explicit free called in pci-hyperv driver.
> 
> Fixes: bcce8c74f1ce ("PCI: Enable host bridge emulation for PCI_DOMAINS_GENERIC platforms")
> Signed-off-by: Sahil Chandna <sahilchandna@linux.microsoft.com>
> ---
>  drivers/pci/controller/pci-hyperv.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c
> index 2c7a406b4ba8..5616ad5d2a8f 100644
> --- a/drivers/pci/controller/pci-hyperv.c
> +++ b/drivers/pci/controller/pci-hyperv.c
> @@ -3778,7 +3778,7 @@ static int hv_pci_probe(struct hv_device *hdev,
>  					   hbus->bridge->domain_nr);
>  	if (!hbus->wq) {
>  		ret = -ENOMEM;
> -		goto free_dom;
> +		goto free_bus;
>  	}
> 
>  	hdev->channel->next_request_id_callback = vmbus_next_request_id;
> @@ -3874,8 +3874,6 @@ static int hv_pci_probe(struct hv_device *hdev,
>  	vmbus_close(hdev->channel);
>  destroy_wq:
>  	destroy_workqueue(hbus->wq);
> -free_dom:
> -	pci_bus_release_emul_domain_nr(hbus->bridge->domain_nr);
>  free_bus:
>  	kfree(hbus);
>  	return ret;
> --
> 2.53.0
> 

LGTM,
Reviewed-by: Saurabh Sengar <ssengar@linux.microsoft.com>

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

* Re: [PATCH] PCI: hv: Fix double ida_free in hv_pci_probe error path
  2026-04-03 12:09 [PATCH] PCI: hv: Fix double ida_free in hv_pci_probe error path Sahil Chandna
  2026-04-03 17:16 ` Saurabh Singh Sengar
@ 2026-04-04  2:42 ` Manivannan Sadhasivam
  2026-04-04  5:19   ` Wei Liu
  1 sibling, 1 reply; 4+ messages in thread
From: Manivannan Sadhasivam @ 2026-04-04  2:42 UTC (permalink / raw)
  To: Sahil Chandna
  Cc: kys, haiyangz, wei.liu, decui, longli, lpieralisi, kwilczynski,
	robh, bhelgaas, dan.j.williams, mhklinux, linux-hyperv, linux-pci,
	linux-kernel

On Fri, Apr 03, 2026 at 05:09:29AM -0700, Sahil Chandna wrote:
> If hv_pci_probe() fails after storing the domain number in
> hbus->bridge->domain_nr, there is a call to free this domain_nr via
> pci_bus_release_emul_domain_nr(), however, during cleanup, the bridge
> release callback pci_release_host_bridge_dev() also frees the domain_nr
> causing ida_free to be called on same ID twice and triggering following
> warning:
> 
>   ida_free called for id=28971 which is not allocated.
>   WARNING: lib/idr.c:594 at ida_free+0xdf/0x160, CPU#0: kworker/0:2/198
>   Call Trace:
>    pci_bus_release_emul_domain_nr+0x17/0x20
>    pci_release_host_bridge_dev+0x4b/0x60
>    device_release+0x3b/0xa0
>    kobject_put+0x8e/0x220
>    devm_pci_alloc_host_bridge_release+0xe/0x20
>    devres_release_all+0x9a/0xd0
>    device_unbind_cleanup+0x12/0xa0
>    really_probe+0x1c5/0x3f0
>    vmbus_add_channel_work+0x135/0x1a0
> 
> Fix this by letting pci core handle the free domain_nr and remove
> the explicit free called in pci-hyperv driver.
> 
> Fixes: bcce8c74f1ce ("PCI: Enable host bridge emulation for PCI_DOMAINS_GENERIC platforms")
> Signed-off-by: Sahil Chandna <sahilchandna@linux.microsoft.com>

Reviewed-by: Manivannan Sadhasivam <mani@kernel.org>

Wei: I see that you've taken previous hyperv patches. So feel free to take this
one also.

We will be proactive from next release onwards ;)

- Mani

> ---
>  drivers/pci/controller/pci-hyperv.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c
> index 2c7a406b4ba8..5616ad5d2a8f 100644
> --- a/drivers/pci/controller/pci-hyperv.c
> +++ b/drivers/pci/controller/pci-hyperv.c
> @@ -3778,7 +3778,7 @@ static int hv_pci_probe(struct hv_device *hdev,
>  					   hbus->bridge->domain_nr);
>  	if (!hbus->wq) {
>  		ret = -ENOMEM;
> -		goto free_dom;
> +		goto free_bus;
>  	}
> 
>  	hdev->channel->next_request_id_callback = vmbus_next_request_id;
> @@ -3874,8 +3874,6 @@ static int hv_pci_probe(struct hv_device *hdev,
>  	vmbus_close(hdev->channel);
>  destroy_wq:
>  	destroy_workqueue(hbus->wq);
> -free_dom:
> -	pci_bus_release_emul_domain_nr(hbus->bridge->domain_nr);
>  free_bus:
>  	kfree(hbus);
>  	return ret;
> --
> 2.53.0
> 

-- 
மணிவண்ணன் சதாசிவம்

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

* Re: [PATCH] PCI: hv: Fix double ida_free in hv_pci_probe error path
  2026-04-04  2:42 ` Manivannan Sadhasivam
@ 2026-04-04  5:19   ` Wei Liu
  0 siblings, 0 replies; 4+ messages in thread
From: Wei Liu @ 2026-04-04  5:19 UTC (permalink / raw)
  To: Manivannan Sadhasivam
  Cc: Sahil Chandna, kys, haiyangz, wei.liu, decui, longli, lpieralisi,
	kwilczynski, robh, bhelgaas, dan.j.williams, mhklinux,
	linux-hyperv, linux-pci, linux-kernel

On Sat, Apr 04, 2026 at 08:12:36AM +0530, Manivannan Sadhasivam wrote:
> On Fri, Apr 03, 2026 at 05:09:29AM -0700, Sahil Chandna wrote:
> > If hv_pci_probe() fails after storing the domain number in
> > hbus->bridge->domain_nr, there is a call to free this domain_nr via
> > pci_bus_release_emul_domain_nr(), however, during cleanup, the bridge
> > release callback pci_release_host_bridge_dev() also frees the domain_nr
> > causing ida_free to be called on same ID twice and triggering following
> > warning:
> > 
> >   ida_free called for id=28971 which is not allocated.
> >   WARNING: lib/idr.c:594 at ida_free+0xdf/0x160, CPU#0: kworker/0:2/198
> >   Call Trace:
> >    pci_bus_release_emul_domain_nr+0x17/0x20
> >    pci_release_host_bridge_dev+0x4b/0x60
> >    device_release+0x3b/0xa0
> >    kobject_put+0x8e/0x220
> >    devm_pci_alloc_host_bridge_release+0xe/0x20
> >    devres_release_all+0x9a/0xd0
> >    device_unbind_cleanup+0x12/0xa0
> >    really_probe+0x1c5/0x3f0
> >    vmbus_add_channel_work+0x135/0x1a0
> > 
> > Fix this by letting pci core handle the free domain_nr and remove
> > the explicit free called in pci-hyperv driver.
> > 
> > Fixes: bcce8c74f1ce ("PCI: Enable host bridge emulation for PCI_DOMAINS_GENERIC platforms")
> > Signed-off-by: Sahil Chandna <sahilchandna@linux.microsoft.com>
> 
> Reviewed-by: Manivannan Sadhasivam <mani@kernel.org>
> 
> Wei: I see that you've taken previous hyperv patches. So feel free to take this
> one also.

Sure. I will pick this up.

Wei

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

end of thread, other threads:[~2026-04-04  5:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-03 12:09 [PATCH] PCI: hv: Fix double ida_free in hv_pci_probe error path Sahil Chandna
2026-04-03 17:16 ` Saurabh Singh Sengar
2026-04-04  2:42 ` Manivannan Sadhasivam
2026-04-04  5:19   ` Wei Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox