Skip to contentSkip to conversation

PCI: hv: Probe vPCI buses asynchronously

PATCH Applied Naman Jain 5 participants 9 messages Sep 7 – Sep 23

Subsystems (4)
lore
Share & tools
lore

Naman Jain

author
#0 lore raw

PATCH 1/1 PCI: hv: Probe vPCI buses asynchronously

On Hyper-V guests each virtual PCI bus is enumerated by its own hv_pci_probe() call. The probe performs several synchronous host request/response exchanges while negotiating the protocol, querying bus relations, entering D0, and reporting allocated resources. These waits are latency-bound rather than CPU-bound.

hv_pci registers as an ordinary VMBus driver, so driver_register() walks matching vPCI buses and probes them sequentially while the driver's initcall runs. On guests that expose several devices, each through its own vPCI bus, this serialization adds the host round-trip latencies to device initialization.

Each bus is described by its own struct hv_pcibus_device, so independent buses can be probed concurrently. Request asynchronous probing via PROBE_PREFER_ASYNCHRONOUS, causing the driver core to schedule matching buses for asynchronous probe work.

On an Azure Standard_L32s_v3 guest with five vPCI targets (four NVMe controllers and one Mellanox VF), Linux 7.2.3 was tested with one warm-up and three measured boots per variant. The median interval from the first hv_pci_probe() entry to the last return decreased from 2847.968 ms to 2786.709 ms, a 61.259 ms (2.15%) improvement.

---

Previous discussion around this change:
https://lore.kernel.org/all/[email protected]/

Skipping removal of pci_rescan_remove_lock, due to possible synchronization problems associated with this lock removal. Also, with my current setup, I was not able to see much improvements with this change, so keeping it for later. Asynchronous probing change is not dependent on this.

---
 drivers/pci/controller/pci-hyperv.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/pci/controller/pci-hyperv.c +3 -0
index 89816a2bd7cd3..056d379b3cee4 100644
@@ -4155,6 +4155,9 @@ static struct hv_driver hv_pci_drv = {
 	.remove		= hv_pci_remove,
 	.suspend	= hv_pci_suspend,
 	.resume		= hv_pci_resume,
+	.driver = {
+		.probe_type = PROBE_PREFER_ASYNCHRONOUS,
+	},
 };
 
 static void __exit exit_hv_pci_drv(void)
Signature · 1 line
2.43.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

Pre-existing issues:
- [Critical] VMBus transaction mappings are not removed when wait_for_response() aborts early, leading to stack or heap Use-After-Free (UAF) upon delayed host completion.
- [High] Memory leak of child PCI devices (struct hv_pci_dev / hpdev) on the error paths of hv_pci_probe().
- [High] Workqueue leaked on hv_pci_remove() if hv_pci_resume() previously failed.
--

commit acbe68fb0b4a7fd692c44acd0bc27c2e48b030db
Author: Naman Jain <[email protected]>

PCI: hv: Probe vPCI buses asynchronously

On Hyper-V guests each virtual PCI bus is enumerated by its own hv_pci_probe() call. The probe performs several synchronous host request/response exchanges while negotiating the protocol, querying bus relations, entering D0, and reporting allocated resources.

drivers/pci/controller/pci-hyperv.c static struct hv_driver hv_pci_drv = { · line 4161

Quoted 12 lines
drivers/pci/controller/pci-hyperv.c +3 -0
index 89816a2bd7cd3..056d379b3cee4 100644
@@ -4155,6 +4155,9 @@ static struct hv_driver hv_pci_drv = {
 	.remove		= hv_pci_remove,
 	.suspend	= hv_pci_suspend,
 	.resume		= hv_pci_resume,
+	.driver = {
+		.probe_type = PROBE_PREFER_ASYNCHRONOUS,
+	},
 };

[Severity: High]
This is a pre-existing issue, but I noticed a potential memory leak of child PCI device structures (struct hv_pci_dev) in the error paths of hv_pci_probe() in drivers/pci/controller/pci-hyperv.c.

If hv_pci_enter_d0() fails, the error path jumps directly to release_state_lock:

    ret = hv_pci_enter_d0(hdev);
    if (ret)
        goto release_state_lock;

This completely skips hv_pci_bus_exit(), which is responsible for unlinking and freeing the children.

Additionally, if an error occurs earlier and it jumps to exit_d0, it calls hv_pci_bus_exit() but skips freeing the devices:

exit_d0:

    (void) hv_pci_bus_exit(hdev, true);
release_state_lock:
    mutex_unlock(&hbus->state_lock);

The keep_devs=true argument explicitly skips freeing the children.

In both situations, the hbus structure is subsequently freed, leaving the previously populated hbus->children list permanently leaked. Could these error paths be adjusted to ensure child devices are properly freed?

[Severity: High]
This is a pre-existing issue, but could a workqueue be leaked in hv_pci_remove() if hv_pci_resume() had previously failed?

In drivers/pci/controller/pci-hyperv.c:hv_pci_resume(), hbus->state is initially set to hv_pcibus_init. If a subsequent operation fails, the function returns an error without restoring the state.

Later, when the device is removed, hv_pci_remove() checks the state before destroying the workqueue:

    if (hbus->state == hv_pcibus_installed) {
        tasklet_disable(&hdev->channel->callback_event);
        hbus->state = hv_pcibus_removing;
        tasklet_enable(&hdev->channel->callback_event);
        destroy_workqueue(hbus->wq);
        hbus->wq = NULL;
        ...

Since the state was left as hv_pcibus_init, this block is bypassed, and the workqueue is leaked when hbus is later freed. Does this state check need to be modified to ensure the workqueue is always destroyed on removal?

[Severity: Critical]
This is a pre-existing issue, but can VMBus transaction mappings be left dangling when wait_for_response() aborts early, leading to a Use-After-Free upon delayed host completion?

In drivers/pci/controller/pci-hyperv.c, several functions allocate a struct pci_packet on the stack or heap, pass it to the VMBus requestor, and then wait for a response. For example, in new_pcichild_device():

    if (wait_for_response(hbus->hdev, &comp_pkt.host_event))
        goto error;

Or in hv_pci_enter_d0():

    ret = wait_for_response(hdev, &comp_pkt.host_event);
    if (ret)
        goto exit;

Similar early returns occur in hv_read_config_block() and hv_write_config_block().

If wait_for_response() aborts immediately (e.g. returning -ENODEV due to a channel rescind), the caller returns and destroys its stack frame or frees the heap allocation.

However, the transaction ID mapping remains in the VMBus requestor. If the host sends a completion packet just after this, the hv_pci_onchannelcallback() tasklet will retrieve the dangling pointer and execute its completion_func, corrupting the stack or heap.

Should these functions use vmbus_request_addr_match() to remove the mapping on failure, similar to how hv_pci_bus_exit() handles it?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
author
#2 lore raw
Quoted 8 lines · On 9/7/2026 11:32 AM, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

Pre-existing issues:
- [Critical] VMBus transaction mappings are not removed when wait_for_response() aborts early, leading to stack or heap Use-After-Free (UAF) upon delayed host completion.
- [High] Memory leak of child PCI devices (struct hv_pci_dev / hpdev) on the error paths of hv_pci_probe().
- [High] Workqueue leaked on hv_pci_remove() if hv_pci_resume() previously failed.
--

All of the issues reported by Sashiko are pre-existing and unrelated to my patch. No action required.

Regards,
Naman

Quoted 108 lines

commit acbe68fb0b4a7fd692c44acd0bc27c2e48b030db
Author: Naman Jain <[email protected]>

PCI: hv: Probe vPCI buses asynchronously

On Hyper-V guests each virtual PCI bus is enumerated by its own hv_pci_probe() call. The probe performs several synchronous host request/response exchanges while negotiating the protocol, querying bus relations, entering D0, and reporting allocated resources.

drivers/pci/controller/pci-hyperv.c static struct hv_driver hv_pci_drv = { · line 4161

Quoted 12 lines
drivers/pci/controller/pci-hyperv.c +3 -0
index 89816a2bd7cd3..056d379b3cee4 100644
@@ -4155,6 +4155,9 @@ static struct hv_driver hv_pci_drv = {
  	.remove		= hv_pci_remove,
  	.suspend	= hv_pci_suspend,
  	.resume		= hv_pci_resume,
+	.driver = {
+		.probe_type = PROBE_PREFER_ASYNCHRONOUS,
+	},
  };

[Severity: High]
This is a pre-existing issue, but I noticed a potential memory leak of child PCI device structures (struct hv_pci_dev) in the error paths of hv_pci_probe() in drivers/pci/controller/pci-hyperv.c.

If hv_pci_enter_d0() fails, the error path jumps directly to release_state_lock:

     ret = hv_pci_enter_d0(hdev);
     if (ret)
         goto release_state_lock;

This completely skips hv_pci_bus_exit(), which is responsible for unlinking and freeing the children.

Additionally, if an error occurs earlier and it jumps to exit_d0, it calls hv_pci_bus_exit() but skips freeing the devices:

exit_d0:

     (void) hv_pci_bus_exit(hdev, true);
release_state_lock:
     mutex_unlock(&hbus->state_lock);

The keep_devs=true argument explicitly skips freeing the children.

In both situations, the hbus structure is subsequently freed, leaving the previously populated hbus->children list permanently leaked. Could these error paths be adjusted to ensure child devices are properly freed?

[Severity: High]
This is a pre-existing issue, but could a workqueue be leaked in hv_pci_remove() if hv_pci_resume() had previously failed?

In drivers/pci/controller/pci-hyperv.c:hv_pci_resume(), hbus->state is initially set to hv_pcibus_init. If a subsequent operation fails, the function returns an error without restoring the state.

Later, when the device is removed, hv_pci_remove() checks the state before destroying the workqueue:

     if (hbus->state == hv_pcibus_installed) {
         tasklet_disable(&hdev->channel->callback_event);
         hbus->state = hv_pcibus_removing;
         tasklet_enable(&hdev->channel->callback_event);
         destroy_workqueue(hbus->wq);
         hbus->wq = NULL;
         ...

Since the state was left as hv_pcibus_init, this block is bypassed, and the workqueue is leaked when hbus is later freed. Does this state check need to be modified to ensure the workqueue is always destroyed on removal?

[Severity: Critical]
This is a pre-existing issue, but can VMBus transaction mappings be left dangling when wait_for_response() aborts early, leading to a Use-After-Free upon delayed host completion?

In drivers/pci/controller/pci-hyperv.c, several functions allocate a struct pci_packet on the stack or heap, pass it to the VMBus requestor, and then wait for a response. For example, in new_pcichild_device():

     if (wait_for_response(hbus->hdev, &comp_pkt.host_event))
         goto error;

Or in hv_pci_enter_d0():

     ret = wait_for_response(hdev, &comp_pkt.host_event);
     if (ret)
         goto exit;

Similar early returns occur in hv_read_config_block() and hv_write_config_block().

If wait_for_response() aborts immediately (e.g. returning -ENODEV due to a channel rescind), the caller returns and destroys its stack frame or frees the heap allocation.

However, the transaction ID mapping remains in the VMBus requestor. If the host sends a completion packet just after this, the hv_pci_onchannelcallback() tasklet will retrieve the dangling pointer and execute its completion_func, corrupting the stack or heap.

Should these functions use vmbus_request_addr_match() to remove the mapping on failure, similar to how hv_pci_bus_exit() handles it?

Reviewed-by on v1 1/1
#3 lore raw
In reply to Naman Jain
Quoted 46 lines · Naman Jain

On Hyper-V guests each virtual PCI bus is enumerated by its own hv_pci_probe() call. The probe performs several synchronous host request/response exchanges while negotiating the protocol, querying bus relations, entering D0, and reporting allocated resources. These waits are latency-bound rather than CPU-bound.

hv_pci registers as an ordinary VMBus driver, so driver_register() walks matching vPCI buses and probes them sequentially while the driver's initcall runs. On guests that expose several devices, each through its own vPCI bus, this serialization adds the host round-trip latencies to device initialization.

Each bus is described by its own struct hv_pcibus_device, so independent buses can be probed concurrently. Request asynchronous probing via PROBE_PREFER_ASYNCHRONOUS, causing the driver core to schedule matching buses for asynchronous probe work.

On an Azure Standard_L32s_v3 guest with five vPCI targets (four NVMe controllers and one Mellanox VF), Linux 7.2.3 was tested with one warm-up and three measured boots per variant. The median interval from the first hv_pci_probe() entry to the last return decreased from 2847.968 ms to 2786.709 ms, a 61.259 ms (2.15%) improvement.

---

Previous discussion around this change:
https://lore.kernel.org/all/[email protected]/

Skipping removal of pci_rescan_remove_lock, due to possible synchronization problems associated with this lock removal. Also, with my current setup, I was not able to see much improvements with this change, so keeping it for later. Asynchronous probing change is not dependent on this.

---
 drivers/pci/controller/pci-hyperv.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/pci/controller/pci-hyperv.c +0 -0
index 89816a2bd7cd3..056d379b3cee4 100644

drivers/pci/controller/pci-hyperv.c static struct hv_driver hv_pci_drv = { · line 4163

Quoted 9 lines
drivers/pci/controller/pci-hyperv.c +3 -0
@@ -4155,6 +4155,9 @@ static struct hv_driver hv_pci_drv = {
 	.remove		= hv_pci_remove,
 	.suspend	= hv_pci_suspend,
 	.resume		= hv_pci_resume,
+	.driver = {
+		.probe_type = PROBE_PREFER_ASYNCHRONOUS,
+	},
 };
 
 static void __exit exit_hv_pci_drv(void)

LGTM.

Regards,
Sahil

maintainer Applied
#4 lore raw
Quoted 55 lines · Sahil Chandna
Quoted 54 lines · Naman Jain

On Hyper-V guests each virtual PCI bus is enumerated by its own hv_pci_probe() call. The probe performs several synchronous host request/response exchanges while negotiating the protocol, querying bus relations, entering D0, and reporting allocated resources. These waits are latency-bound rather than CPU-bound.

hv_pci registers as an ordinary VMBus driver, so driver_register() walks matching vPCI buses and probes them sequentially while the driver's initcall runs. On guests that expose several devices, each through its own vPCI bus, this serialization adds the host round-trip latencies to device initialization.

Each bus is described by its own struct hv_pcibus_device, so independent buses can be probed concurrently. Request asynchronous probing via PROBE_PREFER_ASYNCHRONOUS, causing the driver core to schedule matching buses for asynchronous probe work.

On an Azure Standard_L32s_v3 guest with five vPCI targets (four NVMe controllers and one Mellanox VF), Linux 7.2.3 was tested with one warm-up and three measured boots per variant. The median interval from the first hv_pci_probe() entry to the last return decreased from 2847.968 ms to 2786.709 ms, a 61.259 ms (2.15%) improvement.

---

Previous discussion around this change:
https://lore.kernel.org/all/[email protected]/

Skipping removal of pci_rescan_remove_lock, due to possible synchronization problems associated with this lock removal. Also, with my current setup, I was not able to see much improvements with this change, so keeping it for later. Asynchronous probing change is not dependent on this.

---
 drivers/pci/controller/pci-hyperv.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/pci/controller/pci-hyperv.c +3 -0
index 89816a2bd7cd3..056d379b3cee4 100644
@@ -4155,6 +4155,9 @@ static struct hv_driver hv_pci_drv = {
 	.remove		= hv_pci_remove,
 	.suspend	= hv_pci_suspend,
 	.resume		= hv_pci_resume,
+	.driver = {
+		.probe_type = PROBE_PREFER_ASYNCHRONOUS,
+	},
 };
 
Quoted 3 lines

drivers/pci/controller/pci-hyperv.c static struct hv_driver hv_pci_drv = { · line 4163

Quoted 1 line
drivers/pci/controller/pci-hyperv.c +0 -0
 static void __exit exit_hv_pci_drv(void)

LGTM.

Applied. Thanks.

#5 lore raw
In reply to Naman Jain

From: Naman Jain <[email protected]> Sent: Sunday, September 6, 2026 10:48 PM

Quoted 18 lines

On Hyper-V guests each virtual PCI bus is enumerated by its own hv_pci_probe() call. The probe performs several synchronous host request/response exchanges while negotiating the protocol, querying bus relations, entering D0, and reporting allocated resources. These waits are latency-bound rather than CPU-bound.

hv_pci registers as an ordinary VMBus driver, so driver_register() walks matching vPCI buses and probes them sequentially while the driver's initcall runs. On guests that expose several devices, each through its own vPCI bus, this serialization adds the host round-trip latencies to device initialization.

Each bus is described by its own struct hv_pcibus_device, so independent buses can be probed concurrently. Request asynchronous probing via PROBE_PREFER_ASYNCHRONOUS, causing the driver core to schedule matching buses for asynchronous probe work.

Quoted 5 lines

On an Azure Standard_L32s_v3 guest with five vPCI targets (four NVMe controllers and one Mellanox VF), Linux 7.2.3 was tested with one warm-up and three measured boots per variant. The median interval from the first hv_pci_probe() entry to the last return decreased from 2847.968 ms to 2786.709 ms, a 61.259 ms (2.15%) improvement.

The elapsed time improvement is rather disappointing given the complexity of the probing sequence and the number of interactions with the Hyper-V host. Do you have any insight into why there isn't a larger reduction? Is something mostly serializing the work even though PROBE_PREFER_ASYNCHRONOUS is specified?

Michael

Quoted 36 lines

---

Previous discussion around this change:
https://lore.kernel.org/all/[email protected]/

Skipping removal of pci_rescan_remove_lock, due to possible synchronization problems associated with this lock removal. Also, with my current setup, I was not able to see much improvements with this change, so keeping it for later. Asynchronous probing change is not dependent on this.

---
 drivers/pci/controller/pci-hyperv.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/pci/controller/pci-hyperv.c +3 -1
index 89816a2bd7cd3..056d379b3cee4 100644
@@ -4155,6 +4155,9 @@ static struct hv_driver hv_pci_drv = {
 	.remove		= hv_pci_remove,
 	.suspend	= hv_pci_suspend,
 	.resume		= hv_pci_resume,
+	.driver = {
+		.probe_type = PROBE_PREFER_ASYNCHRONOUS,
+	},
 };
 
 static void __exit exit_hv_pci_drv(void)
--

2.43.0

author
#6 lore raw
Quoted 25 lines · Michael Kelley

From: Naman Jain <[email protected]> Sent: Sunday, September 6, 2026 10:48 PM

Quoted 18 lines

On Hyper-V guests each virtual PCI bus is enumerated by its own hv_pci_probe() call. The probe performs several synchronous host request/response exchanges while negotiating the protocol, querying bus relations, entering D0, and reporting allocated resources. These waits are latency-bound rather than CPU-bound.

hv_pci registers as an ordinary VMBus driver, so driver_register() walks matching vPCI buses and probes them sequentially while the driver's initcall runs. On guests that expose several devices, each through its own vPCI bus, this serialization adds the host round-trip latencies to device initialization.

Each bus is described by its own struct hv_pcibus_device, so independent buses can be probed concurrently. Request asynchronous probing via PROBE_PREFER_ASYNCHRONOUS, causing the driver core to schedule matching buses for asynchronous probe work.

Quoted 5 lines

On an Azure Standard_L32s_v3 guest with five vPCI targets (four NVMe controllers and one Mellanox VF), Linux 7.2.3 was tested with one warm-up and three measured boots per variant. The median interval from the first hv_pci_probe() entry to the last return decreased from 2847.968 ms to 2786.709 ms, a 61.259 ms (2.15%) improvement.

Quoted 8 lines

The elapsed time improvement is rather disappointing given the complexity of the probing sequence and the number of interactions with the Hyper-V host. Do you have any insight into why there isn't a larger reduction? Is something mostly serializing the work even though PROBE_PREFER_ASYNCHRONOUS is specified?

Michael

I can see these reasons for not seeing great improvements:
1. Timing of device offers from the host is beyond the control of guest and the Hyper-V host may also be serializing the requests from the host.
2. Shared locks that needs to be handled separately:
* hyperv_mmio_lock during VMBus MMIO allocation.
* pci_rescan_remove_lock during PCI resource assignment and device
addition.

I digged more into it, and it is indeed because of late offers from Hyper-V. I was considering the start of first probe to the last return, for time calculations.

For the 4 PCI devices on my setup whose offers were delivered together, the performance improvement was about 24%. However with the last offer coming late for MLX PCI device, overall improvement in time was lesser in terms of percentage.

Dexuan had removed pci_rescan_remove_lock in his previous upstream attempt, but I ommitted it intentionally this time because from AI review, I saw a potential race condition that we would introduce if we remove it. Secondly, I did not observe any benefits of removing this lock. But I am going to revisit it again.

Regards,
Naman

Quoted 37 lines
Quoted 36 lines

---

Previous discussion around this change:
https://lore.kernel.org/all/[email protected]/

Skipping removal of pci_rescan_remove_lock, due to possible synchronization problems associated with this lock removal. Also, with my current setup, I was not able to see much improvements with this change, so keeping it for later. Asynchronous probing change is not dependent on this.

---
  drivers/pci/controller/pci-hyperv.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/pci/controller/pci-hyperv.c +3 -1
index 89816a2bd7cd3..056d379b3cee4 100644
@@ -4155,6 +4155,9 @@ static struct hv_driver hv_pci_drv = {
  	.remove		= hv_pci_remove,
  	.suspend	= hv_pci_suspend,
  	.resume		= hv_pci_resume,
+	.driver = {
+		.probe_type = PROBE_PREFER_ASYNCHRONOUS,
+	},
  };
 
  static void __exit exit_hv_pci_drv(void)
--

2.43.0

#7 lore raw

From: Naman Jain <[email protected]> Sent: Tuesday, September 22, 2026 2:09 AM

Quoted 33 lines · Michael Kelley
Quoted 31 lines

From: Naman Jain <[email protected]> Sent: Sunday, September 6, 2026 10:48 PM

Quoted 18 lines

On Hyper-V guests each virtual PCI bus is enumerated by its own hv_pci_probe() call. The probe performs several synchronous host request/response exchanges while negotiating the protocol, querying bus relations, entering D0, and reporting allocated resources. These waits are latency-bound rather than CPU-bound.

hv_pci registers as an ordinary VMBus driver, so driver_register() walks matching vPCI buses and probes them sequentially while the driver's initcall runs. On guests that expose several devices, each through its own vPCI bus, this serialization adds the host round-trip latencies to device initialization.

Each bus is described by its own struct hv_pcibus_device, so independent buses can be probed concurrently. Request asynchronous probing via PROBE_PREFER_ASYNCHRONOUS, causing the driver core to schedule matching buses for asynchronous probe work.

Quoted 5 lines

On an Azure Standard_L32s_v3 guest with five vPCI targets (four NVMe controllers and one Mellanox VF), Linux 7.2.3 was tested with one warm-up and three measured boots per variant. The median interval from the first hv_pci_probe() entry to the last return decreased from 2847.968 ms to 2786.709 ms, a 61.259 ms (2.15%) improvement.

The elapsed time improvement is rather disappointing given the complexity of the probing sequence and the number of interactions with the Hyper-V host. Do you have any insight into why there isn't a larger reduction? Is something mostly serializing the work even though PROBE_PREFER_ASYNCHRONOUS is specified?

Quoted 6 lines
Quoted 2 lines

Michael

I can see these reasons for not seeing great improvements:
1. Timing of device offers from the host is beyond the control of guest and the Hyper-V host may also be serializing the requests from the host.

Ah, right. This is probably the key factor.

Quoted 2 lines

2. Shared locks that needs to be handled separately:
* hyperv_mmio_lock during VMBus MMIO allocation.

This probably has minimal impact. While there's a decent amount of code protected by the lock, I don't think there's any interaction with the host (even via traps), so it should run quickly.

Quoted 2 lines

* pci_rescan_remove_lock during PCI resource assignment and device
addition.

OK. I don’t know about this one.

Quoted 10 lines

I digged more into it, and it is indeed because of late offers from Hyper-V. I was considering the start of first probe to the last return, for time calculations.

For the 4 PCI devices on my setup whose offers were delivered together, the performance improvement was about 24%. However with the last offer coming late for MLX PCI device, overall improvement in time was lesser in terms of percentage.

For traditional configs where the VF NIC is paired with a netvsc instance, the host doesn't offer the VF NIC to the guest until the corresponding netvsc instance has been probed and the netvsc driver has told the host it will accept a VF NIC. In these cases, the Mellanox or MANA VF NIC device is always "late" and probably shouldn't be included when determining the speed-up of doing hv_pci probing asynchronously.

Quoted 6 lines

Dexuan had removed pci_rescan_remove_lock in his previous upstream attempt, but I ommitted it intentionally this time because from AI review, I saw a potential race condition that we would introduce if we remove it. Secondly, I did not observe any benefits of removing this lock. But I am going to revisit it again.

Thanks for the discussion. Using PROBE_PREFER_ASYNCHRONOUS is still a good thing to use, but the benefit will accrue the most when there are a significant number of NVMe devices and when Hyper-V is quick about offering them. As I described above, it will be harder to get parallelism with the VF NIC.

Michael

author
#8 lore raw
Quoted 81 lines · Michael Kelley

From: Naman Jain <[email protected]> Sent: Tuesday, September 22, 2026 2:09 AM

Quoted 33 lines · Michael Kelley
Quoted 31 lines

From: Naman Jain <[email protected]> Sent: Sunday, September 6, 2026 10:48 PM

Quoted 18 lines

On Hyper-V guests each virtual PCI bus is enumerated by its own hv_pci_probe() call. The probe performs several synchronous host request/response exchanges while negotiating the protocol, querying bus relations, entering D0, and reporting allocated resources. These waits are latency-bound rather than CPU-bound.

hv_pci registers as an ordinary VMBus driver, so driver_register() walks matching vPCI buses and probes them sequentially while the driver's initcall runs. On guests that expose several devices, each through its own vPCI bus, this serialization adds the host round-trip latencies to device initialization.

Each bus is described by its own struct hv_pcibus_device, so independent buses can be probed concurrently. Request asynchronous probing via PROBE_PREFER_ASYNCHRONOUS, causing the driver core to schedule matching buses for asynchronous probe work.

Quoted 5 lines

On an Azure Standard_L32s_v3 guest with five vPCI targets (four NVMe controllers and one Mellanox VF), Linux 7.2.3 was tested with one warm-up and three measured boots per variant. The median interval from the first hv_pci_probe() entry to the last return decreased from 2847.968 ms to 2786.709 ms, a 61.259 ms (2.15%) improvement.

The elapsed time improvement is rather disappointing given the complexity of the probing sequence and the number of interactions with the Hyper-V host. Do you have any insight into why there isn't a larger reduction? Is something mostly serializing the work even though PROBE_PREFER_ASYNCHRONOUS is specified?

Quoted 6 lines
Quoted 2 lines

Michael

I can see these reasons for not seeing great improvements:
1. Timing of device offers from the host is beyond the control of guest and the Hyper-V host may also be serializing the requests from the host.

Ah, right. This is probably the key factor.

Quoted 2 lines

2. Shared locks that needs to be handled separately:
* hyperv_mmio_lock during VMBus MMIO allocation.

This probably has minimal impact. While there's a decent amount of code protected by the lock, I don't think there's any interaction with the host (even via traps), so it should run quickly.

Quoted 2 lines

* pci_rescan_remove_lock during PCI resource assignment and device
addition.

OK. I don’t know about this one.

Quoted 10 lines

I digged more into it, and it is indeed because of late offers from Hyper-V. I was considering the start of first probe to the last return, for time calculations.

For the 4 PCI devices on my setup whose offers were delivered together, the performance improvement was about 24%. However with the last offer coming late for MLX PCI device, overall improvement in time was lesser in terms of percentage.

For traditional configs where the VF NIC is paired with a netvsc instance, the host doesn't offer the VF NIC to the guest until the corresponding netvsc instance has been probed and the netvsc driver has told the host it will accept a VF NIC. In these cases, the Mellanox or MANA VF NIC device is always "late" and probably shouldn't be included when determining the speed-up of doing hv_pci probing asynchronously.

Quoted 6 lines

Dexuan had removed pci_rescan_remove_lock in his previous upstream attempt, but I ommitted it intentionally this time because from AI review, I saw a potential race condition that we would introduce if we remove it. Secondly, I did not observe any benefits of removing this lock. But I am going to revisit it again.

Quoted 7 lines

Thanks for the discussion. Using PROBE_PREFER_ASYNCHRONOUS is still a good thing to use, but the benefit will accrue the most when there are a significant number of NVMe devices and when Hyper-V is quick about offering them. As I described above, it will be harder to get parallelism with the VF NIC.

Michael

Thanks Michael, this makes sense now. I'm glad that you asked.

Regards,
Naman