PCI: hv: warn when wait_for_response() waits indefinitely
Subsystems (4)
PATCH v2 1/1 PCI: hv: warn when wait_for_response() waits indefinitely
A guest can wait indefinitely in wait_for_response() for the host to send either a rescind message or a packet completion. If the host does not send either, the guest can remain blocked with no diagnostic indicating a reason.
This was observed during a guest kernel upgrade in which the host-side application handling the PCI channel faulted, causing the guest to never receive the completion request.
Add a warning in wait_for_response() when the wait exceeds a timeout so that such a hang is visible in the guest's kernel log and can be correlated with host-side state.
---
Changes since v1:
- Removed periodic warning to one time warning in 2 minutes
- Include vmbus relid and stuck PCI msg.
Link to v1: https://lore.kernel.org/all/[email protected]/
--- drivers/pci/controller/pci-hyperv.c | 48 +++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 10 deletions(-)
drivers/pci/controller/pci-hyperv.c +38 -10
@@ -1040,19 +1040,40 @@ static void put_pcichild(struct hv_pci_dev *hpdev)/* * There is no good way to get notified from vmbus_onoffer_rescind(), -* so let's use polling here, since this is not a hot path. +* so let's use polling here, since this is not a hot path. If +* wait_for_response() has been polling for PCI_RESPONSE_HANG_TIMEOUT_SEC +* without either a rescind or completion, add a warning. */ +#define PCI_RESPONSE_HANG_TIMEOUT_SEC 120 +static int wait_for_response (struct hv_device *hdev, -struct completion *comp) +struct completion *comp, +const char *msg_type) { +unsigned long delay =secs_to_jiffies (PCI_RESPONSE_HANG_TIMEOUT_SEC ); +u64 timeout =get_jiffies_64 () + delay; +bool warned = false; +while (true) {if (hdev->channel->rescind) {dev_warn_once (&hdev->device,"The device is gone.\n" );return -ENODEV ; } -if (wait_for_completion_timeout (comp,HZ /10 )) +if (wait_for_completion_timeout (comp,HZ /10 )) { +if (warned) +dev_warn (&hdev->device, +"Late %s completion arrived.\n" , msg_type);break ; + } + +if (!warned &&time_after64 (get_jiffies_64 (), timeout)) { +dev_err (&hdev->device, +"%s stuck waiting for response, relid = %u\n" , + msg_type, hdev->channel->offermsg.child_relid); + + warned = true; + } }return 0 ;
@@ -1518,7 +1539,8 @@ static int hv_read_config_block(struct pci_dev *pdev, void *buf,if (ret)return ret; - ret =wait_for_response (hbus->hdev, &comp_pkt.comp_pkt.host_event); + ret =wait_for_response (hbus->hdev, &comp_pkt.comp_pkt.host_event, +"PCI_READ_BLOCK" );if (ret)return ret;
@@ -1607,7 +1629,8 @@ static int hv_write_config_block(struct pci_dev *pdev, void *buf,if (ret)return ret; - ret =wait_for_response (hbus->hdev, &comp_pkt.host_event); + ret =wait_for_response (hbus->hdev, &comp_pkt.host_event, +"PCI_WRITE_BLOCK" );if (ret)return ret;
@@ -2624,7 +2647,8 @@ static struct hv_pci_dev *new_pcichild_device(struct hv_pcibus_device *hbus,if (ret) goto error; -if (wait_for_response (hbus->hdev, &comp_pkt.host_event)) +if (wait_for_response (hbus->hdev, &comp_pkt.host_event, +"PCI_QUERY_RESOURCE_REQUIREMENTS" )) goto error; hpdev->desc = *desc;
@@ -3256,7 +3280,8 @@ static int hv_pci_protocol_negotiation(struct hv_device *hdev, (unsigned long )pkt,VM_PKT_DATA_INBAND , VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);if (!ret) - ret =wait_for_response (hdev, &comp_pkt.host_event); + ret =wait_for_response (hdev, &comp_pkt.host_event, +"PCI_QUERY_PROTOCOL_VERSION" );if (ret) { dev_err(&hdev->device,
@@ -3476,7 +3501,8 @@ static int hv_pci_enter_d0(struct hv_device *hdev) (unsigned long )pkt,VM_PKT_DATA_INBAND , VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);if (!ret) - ret =wait_for_response (hdev, &comp_pkt.host_event); + ret =wait_for_response (hdev, &comp_pkt.host_event, +"PCI_BUS_D0ENTRY" );if (ret) goto exit;
@@ -3553,7 +3579,8 @@ static int hv_pci_query_relations(struct hv_device *hdev) ret =vmbus_sendpacket (hdev->channel, &message,sizeof (message),0 ,VM_PKT_DATA_INBAND ,0 );if (!ret) - ret =wait_for_response (hdev, &comp); + ret =wait_for_response (hdev, &comp, +"PCI_QUERY_BUS_RELATIONS" );/* * In the case of fast device addition/removal, it's possible that
@@ -3644,7 +3671,8 @@ static int hv_send_resources_allocated(struct hv_device *hdev)VM_PKT_DATA_INBAND , VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);if (!ret) - ret =wait_for_response (hdev, &comp_pkt.host_event); + ret =wait_for_response (hdev, &comp_pkt.host_event, +"PCI_RESOURCE_ASSIGNED" );if (ret)break ;
--
2.53.0
[email protected]
AI reviewSashiko has reviewed this patch and found no issues. It looks great!
Quoted 11 lines
A guest can wait indefinitely in
wait_for_response()for the host to send either a rescind message or a packet completion. If the host does not send either, the guest can remain blocked with no diagnostic indicating a reason.
This was observed during a guest kernel upgrade in which the host-side application handling the PCI channel faulted, causing the guest to never receive the completion request.
Add a warning inwait_for_response()when the wait exceeds a timeout so that such a hang is visible in the guest's kernel log and can be correlated with host-side state.
Quoted 4 lines
Suggested-by Hamza Mahfooz <[email protected]>Suggested-by Naman Jain <[email protected]>Suggested-by Michael Kelley <[email protected]>Signed-off-by Sahil Chandna <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 11 lines · Sahil Chandna
A guest can wait indefinitely in
wait_for_response()for the host to send either a rescind message or a packet completion. If the host does not send either, the guest can remain blocked with no diagnostic indicating a reason.
This was observed during a guest kernel upgrade in which the host-side application handling the PCI channel faulted, causing the guest to never receive the completion request.
Add a warning inwait_for_response()when the wait exceeds a timeout so that such a hang is visible in the guest's kernel log and can be correlated with host-side state.
Quoted 3 lines
Suggested-by Hamza Mahfooz <[email protected]>Suggested-by Naman Jain <[email protected]>Suggested-by Michael Kelley <[email protected]>
These two tags can be omitted IMO.
Quoted 59 lines
Signed-off-by Sahil Chandna <[email protected]>---
Changes since v1:
- Removed periodic warning to one time warning in 2 minutes
- Include vmbus relid and stuck PCI msg.
Link to v1: https://lore.kernel.org/all/[email protected]/--- drivers/pci/controller/pci-hyperv.c | 48 +++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 10 deletions(-)drivers/pci/controller/pci-hyperv.c +24
-3@@ -1040,19 +1040,40 @@ static void put_pcichild(struct hv_pci_dev *hpdev)/* * There is no good way to get notified from vmbus_onoffer_rescind(), -* so let's use polling here, since this is not a hot path. +* so let's use polling here, since this is not a hot path. If +* wait_for_response() has been polling for PCI_RESPONSE_HANG_TIMEOUT_SEC +* without either a rescind or completion, add a warning. */ +#define PCI_RESPONSE_HANG_TIMEOUT_SEC 120 +static int wait_for_response (struct hv_device *hdev, -struct completion *comp) +struct completion *comp, +const char *msg_type) { +unsigned long delay =secs_to_jiffies (PCI_RESPONSE_HANG_TIMEOUT_SEC ); +u64 timeout =get_jiffies_64 () + delay; +bool warned = false; +while (true) {if (hdev->channel->rescind) {dev_warn_once (&hdev->device,"The device is gone.\n" );return -ENODEV ; } -if (wait_for_completion_timeout (comp,HZ /10 )) +if (wait_for_completion_timeout (comp,HZ /10 )) { +if (warned) +dev_warn (&hdev->device, +"Late %s completion arrived.\n" , msg_type);break ; + } + +if (!warned &&time_after64 (get_jiffies_64 (), timeout)) { +dev_err (&hdev->device, +"%s stuck waiting for response, relid = %u\n" , + msg_type, hdev->channel->offermsg.child_relid); + + warned = true; + } }return 0 ;
drivers/pci/controller/pci-hyperv.c static int hv_read_config_block(struct pci_dev *pdev, void *buf, · line 1543
Quoted 6 lines
drivers/pci/controller/pci-hyperv.c +2
-1@@ -1518,7 +1539,8 @@ static int hv_read_config_block(struct pci_dev *pdev, void *buf,if (ret)return ret; - ret =wait_for_response (hbus->hdev, &comp_pkt.comp_pkt.host_event); + ret =wait_for_response (hbus->hdev, &comp_pkt.comp_pkt.host_event, +"PCI_READ_BLOCK" );
Instead of hard-coding this msg type two times everywhere, would it be better to simply pass corresponding variable.message_type.type?
Quoted 54 lines
drivers/pci/controller/pci-hyperv.c +10
-5if (ret)return ret;@@ -1607,7 +1629,8 @@ static int hv_write_config_block(struct pci_dev *pdev, void *buf,if (ret)return ret; - ret =wait_for_response (hbus->hdev, &comp_pkt.host_event); + ret =wait_for_response (hbus->hdev, &comp_pkt.host_event, +"PCI_WRITE_BLOCK" );if (ret)return ret;@@ -2624,7 +2647,8 @@ static struct hv_pci_dev *new_pcichild_device(struct hv_pcibus_device *hbus,if (ret) goto error; -if (wait_for_response (hbus->hdev, &comp_pkt.host_event)) +if (wait_for_response (hbus->hdev, &comp_pkt.host_event, +"PCI_QUERY_RESOURCE_REQUIREMENTS" )) goto error; hpdev->desc = *desc;@@ -3256,7 +3280,8 @@ static int hv_pci_protocol_negotiation(struct hv_device *hdev, (unsigned long )pkt,VM_PKT_DATA_INBAND , VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);if (!ret) - ret =wait_for_response (hdev, &comp_pkt.host_event); + ret =wait_for_response (hdev, &comp_pkt.host_event, +"PCI_QUERY_PROTOCOL_VERSION" );if (ret) { dev_err(&hdev->device,@@ -3476,7 +3501,8 @@ static int hv_pci_enter_d0(struct hv_device *hdev) (unsigned long )pkt,VM_PKT_DATA_INBAND , VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);if (!ret) - ret =wait_for_response (hdev, &comp_pkt.host_event); + ret =wait_for_response (hdev, &comp_pkt.host_event, +"PCI_BUS_D0ENTRY" );if (ret) goto exit;@@ -3553,7 +3579,8 @@ static int hv_pci_query_relations(struct hv_device *hdev) ret =vmbus_sendpacket (hdev->channel, &message,sizeof (message),0 ,VM_PKT_DATA_INBAND ,0 );if (!ret) - ret =wait_for_response (hdev, &comp); + ret =wait_for_response (hdev, &comp, +"PCI_QUERY_BUS_RELATIONS" );/* * In the case of fast device addition/removal, it's possible that
drivers/pci/controller/pci-hyperv.c static int hv_send_resources_allocated(struct hv_device *hdev) · line 3675
Quoted 6 lines
drivers/pci/controller/pci-hyperv.c +2
-1@@ -3644,7 +3671,8 @@ static int hv_send_resources_allocated(struct hv_device *hdev)VM_PKT_DATA_INBAND , VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);if (!ret) - ret =wait_for_response (hdev, &comp_pkt.host_event); + ret =wait_for_response (hdev, &comp_pkt.host_event, +"PCI_RESOURCE_ASSIGNED" );
There is an if-else condition before this, which can lead to message type be one of PCI_RESOURCES_ASSIGNED or PCI_RESOURCES_ASSIGNED2. Hard-coding it this way will miss PCI_RESOURCES_ASSIGNED2.
Quoted 5 lines
drivers/pci/controller/pci-hyperv.c +0
-1if (ret)break ; --2.53.0
Regards,
Naman
Quoted 86 lines · Naman Jain
Quoted 11 lines · Sahil Chandna
A guest can wait indefinitely in
wait_for_response()for the host to send either a rescind message or a packet completion. If the host does not send either, the guest can remain blocked with no diagnostic indicating a reason.
This was observed during a guest kernel upgrade in which the host-side application handling the PCI channel faulted, causing the guest to never receive the completion request.
Add a warning inwait_for_response()when the wait exceeds a timeout so that such a hang is visible in the guest's kernel log and can be correlated with host-side state.Quoted 3 lines
Suggested-by Hamza Mahfooz <[email protected]>Suggested-by Naman Jain <[email protected]>Suggested-by Michael Kelley <[email protected]>These two tags can be omitted IMO.
Quoted 66 lines
Signed-off-by Sahil Chandna <[email protected]>---
Changes since v1:
- Removed periodic warning to one time warning in 2 minutes
- Include vmbus relid and stuck PCI msg.
Link to v1: https://lore.kernel.org/all/20260825051850.2438816-1- [email protected]/
---
drivers/pci/controller/pci-hyperv.c| 48 +++++++++++++++++++++++------1 file changed, 38 insertions(+), 10 deletions(-)drivers/pci/controller/pci-hyperv.c +2
-1@@ -1040,19 +1040,40 @@ static void put_pcichild(struct hv_pci_dev *hpdev) /** There is no good way to get notified from vmbus_onoffer_rescind(), -* so let's use polling here, since this is not a hot path. +* so let's use polling here, since this is not a hot path. If +* wait_for_response() has been polling for
PCI_RESPONSE_HANG_TIMEOUT_SEC
+ * without either a rescind or completion, add a warning. */drivers/pci/controller/pci-hyperv.c +2
-0+#define PCI_RESPONSE_HANG_TIMEOUT_SEC 120 +static int wait_for_response(struct
hv_device*hdev,
- struct completion *comp)
+ struct completion *comp,
+ const char*msg_type)
{
+ unsigned long delay =secs_to_jiffies(PCI_RESPONSE_HANG_TIMEOUT_SEC);
+ u64 timeout =get_jiffies_64()+ delay;
+ bool warned = false;
+
while (true) {
if (hdev->channel->rescind) {dev_warn_once(&hdev->device, "The device is gone.\n"); return-ENODEV;
}- if (
wait_for_completion_timeout(comp, HZ / 10)) + if (wait_for_completion_timeout(comp, HZ / 10)) { + if (warned)
+ dev_warn(&hdev->device,
+ "Late %s completion arrived.\n",msg_type); break;
+ }drivers/pci/controller/pci-hyperv.c +8
-0+ + if (!warned && time_after64(get_jiffies_64(), timeout)) { + dev_err(&hdev->device, + "%s stuck waiting for response, relid = %u\n", + msg_type, hdev->channel->offermsg.child_relid); + + warned = true; + }}
return 0;
drivers/pci/controller/pci-hyperv.c +0
-0@@ -1518,7 +1539,8 @@ static int hv_read_config_block(struct pci_dev *pdev, void *buf, if (ret) return ret;
Quoted 5 lines
drivers/pci/controller/pci-hyperv.c static int hv_read_config_block(struct pci_dev *pdev, void *buf, · line 1543
Quoted 3 lines
drivers/pci/controller/pci-hyperv.c +2
-1- ret = wait_for_response(hbus->hdev, &comp_pkt.comp_pkt.host_event); + ret = wait_for_response(hbus->hdev, &comp_pkt.comp_pkt.host_event, + "PCI_READ_BLOCK");Instead of hard-coding this msg type two times everywhere, would it be better to simply pass corresponding variable.message_type.type?
You can ignore this, as you may have wanted to print actual name instead of enum value.
Regards,
Naman
From: Sahil Chandna <[email protected]> Sent: Wednesday, September 2, 2026 4:59 AM
Quoted 30 lines
A guest can wait indefinitely in
wait_for_response()for the host to send either a rescind message or a packet completion. If the host does not send either, the guest can remain blocked with no diagnostic indicating a reason.
This was observed during a guest kernel upgrade in which the host-side application handling the PCI channel faulted, causing the guest to never receive the completion request.
Add a warning inwait_for_response()when the wait exceeds a timeout so that such a hang is visible in the guest's kernel log and can be correlated with host-side state.Suggested-by Hamza Mahfooz <[email protected]>Suggested-by Naman Jain <[email protected]>Suggested-by Michael Kelley <[email protected]>Signed-off-by Sahil Chandna <[email protected]>---
Changes since v1:
- Removed periodic warning to one time warning in 2 minutes
- Include vmbus relid and stuck PCI msg.
Link to v1: https://lore.kernel.org/all/[email protected]/--- drivers/pci/controller/pci-hyperv.c | 48 +++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 10 deletions(-)drivers/pci/controller/pci-hyperv.c +0
-0
drivers/pci/controller/pci-hyperv.c static void put_pcichild(struct hv_pci_dev *hpdev) · line 1047
Quoted 9 lines
drivers/pci/controller/pci-hyperv.c +4
-1@@ -1040,19 +1040,40 @@ static void put_pcichild(struct hv_pci_dev *hpdev)/* * There is no good way to get notified from vmbus_onoffer_rescind(), -* so let's use polling here, since this is not a hot path. +* so let's use polling here, since this is not a hot path. If +* wait_for_response() has been polling for PCI_RESPONSE_HANG_TIMEOUT_SEC +* without either a rescind or completion, add a warning. */ +#define PCI_RESPONSE_HANG_TIMEOUT_SEC 120
This all looks good to me and it should work as written. But the code seems more complex than it needs to be. There are two timers running in parallel -- the 100 millisecond timer in wait_for_completion_timeout(), and the larger 120 second timeout for printing the "stuck waiting" message. A simpler approach would be to count iterations through the "while(true)" loop. Print the "stuck warning" message when the count is exactly 1200. Print the "late completion" message if the completion occurs and count is > 1200. Then there's no need to manipulate jiffies and the "warned" flag isn't needed. Make the loop counter 64-bit so overflow isn't an issue.
Arguably this suggested approach is a little too clever, but it seems clear enough to be easily understood.
Michael
Quoted 109 lines
drivers/pci/controller/pci-hyperv.c +26
-5+static int wait_for_response (struct hv_device *hdev, -struct completion *comp) +struct completion *comp, +const char *msg_type) { +unsigned long delay =secs_to_jiffies (PCI_RESPONSE_HANG_TIMEOUT_SEC ); +u64 timeout =get_jiffies_64 () + delay; +bool warned = false; +while (true) {if (hdev->channel->rescind) {dev_warn_once (&hdev->device,"The device is gone.\n" );return -ENODEV ; } -if (wait_for_completion_timeout (comp,HZ /10 )) +if (wait_for_completion_timeout (comp,HZ /10 )) { +if (warned) +dev_warn (&hdev->device, +"Late %s completion arrived.\n" , msg_type);break ; + } + +if (!warned &&time_after64 (get_jiffies_64 (), timeout)) { +dev_err (&hdev->device, +"%s stuck waiting for response, relid = %u\n" , + msg_type, hdev->channel->offermsg.child_relid); + + warned = true; + } }return 0 ;@@ -1518,7 +1539,8 @@ static int hv_read_config_block(struct pci_dev *pdev, void *buf,if (ret)return ret; - ret =wait_for_response (hbus->hdev, &comp_pkt.comp_pkt.host_event); + ret =wait_for_response (hbus->hdev, &comp_pkt.comp_pkt.host_event, +"PCI_READ_BLOCK" );if (ret)return ret;@@ -1607,7 +1629,8 @@ static int hv_write_config_block(struct pci_dev *pdev, void *buf,if (ret)return ret; - ret =wait_for_response (hbus->hdev, &comp_pkt.host_event); + ret =wait_for_response (hbus->hdev, &comp_pkt.host_event, +"PCI_WRITE_BLOCK" );if (ret)return ret;@@ -2624,7 +2647,8 @@ static struct hv_pci_dev *new_pcichild_device(struct hv_pcibus_device *hbus, if (ret) goto error; -if (wait_for_response (hbus->hdev, &comp_pkt.host_event)) +if (wait_for_response (hbus->hdev, &comp_pkt.host_event, +"PCI_QUERY_RESOURCE_REQUIREMENTS" )) goto error;drivers/pci/controller/pci-hyperv.c +2
-1hpdev->desc = *desc;@@ -3256,7 +3280,8 @@ static int hv_pci_protocol_negotiation(struct hv_device *hdev, (unsigned long )pkt,VM_PKT_DATA_INBAND , VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);if (!ret) - ret =wait_for_response (hdev, &comp_pkt.host_event); + ret =wait_for_response (hdev, &comp_pkt.host_event, +"PCI_QUERY_PROTOCOL_VERSION" );if (ret) {drivers/pci/controller/pci-hyperv.c +6
-4dev_err(&hdev->device,@@ -3476,7 +3501,8 @@ static int hv_pci_enter_d0(struct hv_device *hdev) (unsigned long )pkt,VM_PKT_DATA_INBAND , VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);if (!ret) - ret =wait_for_response (hdev, &comp_pkt.host_event); + ret =wait_for_response (hdev, &comp_pkt.host_event, +"PCI_BUS_D0ENTRY" );if (ret) goto exit;@@ -3553,7 +3579,8 @@ static int hv_pci_query_relations(struct hv_device *hdev) ret =vmbus_sendpacket (hdev->channel, &message,sizeof (message),0 ,VM_PKT_DATA_INBAND ,0 );if (!ret) - ret =wait_for_response (hdev, &comp); + ret =wait_for_response (hdev, &comp, +"PCI_QUERY_BUS_RELATIONS" );/* * In the case of fast device addition/removal, it's possible that @@ -3644,7 +3671,8 @@ static int hv_send_resources_allocated(struct hv_device *hdev)VM_PKT_DATA_INBAND , VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);if (!ret) - ret =wait_for_response (hdev, &comp_pkt.host_event); + ret =wait_for_response (hdev, &comp_pkt.host_event, +"PCI_RESOURCE_ASSIGNED" );if (ret)break ; --2.53.0
Quoted 51 lines · Michael Kelley
From: Sahil Chandna <[email protected]> Sent: Wednesday, September 2, 2026 4:59 AM
Quoted 30 lines
A guest can wait indefinitely in
wait_for_response()for the host to send either a rescind message or a packet completion. If the host does not send either, the guest can remain blocked with no diagnostic indicating a reason.
This was observed during a guest kernel upgrade in which the host-side application handling the PCI channel faulted, causing the guest to never receive the completion request.
Add a warning inwait_for_response()when the wait exceeds a timeout so that such a hang is visible in the guest's kernel log and can be correlated with host-side state.Suggested-by Hamza Mahfooz <[email protected]>Suggested-by Naman Jain <[email protected]>Suggested-by Michael Kelley <[email protected]>Signed-off-by Sahil Chandna <[email protected]>---
Changes since v1:
- Removed periodic warning to one time warning in 2 minutes
- Include vmbus relid and stuck PCI msg.
Link to v1: https://lore.kernel.org/all/[email protected]/--- drivers/pci/controller/pci-hyperv.c | 48 +++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 10 deletions(-)drivers/pci/controller/pci-hyperv.c +0
-0drivers/pci/controller/pci-hyperv.c static void put_pcichild(struct hv_pci_dev *hpdev) · line 1047
Quoted 9 lines
drivers/pci/controller/pci-hyperv.c +4
-1@@ -1040,19 +1040,40 @@ static void put_pcichild(struct hv_pci_dev *hpdev)/* * There is no good way to get notified from vmbus_onoffer_rescind(), -* so let's use polling here, since this is not a hot path. +* so let's use polling here, since this is not a hot path. If +* wait_for_response() has been polling for PCI_RESPONSE_HANG_TIMEOUT_SEC +* without either a rescind or completion, add a warning. */ +#define PCI_RESPONSE_HANG_TIMEOUT_SEC 120This all looks good to me and it should work as written. But the code seems more complex than it needs to be. There are two timers running in parallel -- the 100 millisecond timer in
wait_for_completion_timeout(), and the larger 120 second timeout for printing the "stuck waiting" message. A simpler approach would be to count iterations through the "while(true)" loop. Print the "stuck warning" message when the count is exactly 1200. Print the "late completion" message if the completion occurs and count is > 1200. Then there's no need to manipulate jiffies and the "warned" flag isn't needed. Make the loop counter 64-bit so overflow isn't an issue.
Quoted 5 lines
Arguably this suggested approach is a little too clever, but it seems clear enough to be easily understood.
Michael
Thanks for reviewing. Sure, this makes sense.I will share proposed implementation in v3
Regards,
Sahil
Quoted 109 lines
Quoted 109 lines
drivers/pci/controller/pci-hyperv.c +26
-5+static int wait_for_response (struct hv_device *hdev, -struct completion *comp) +struct completion *comp, +const char *msg_type) { +unsigned long delay =secs_to_jiffies (PCI_RESPONSE_HANG_TIMEOUT_SEC ); +u64 timeout =get_jiffies_64 () + delay; +bool warned = false; +while (true) {if (hdev->channel->rescind) {dev_warn_once (&hdev->device,"The device is gone.\n" );return -ENODEV ; } -if (wait_for_completion_timeout (comp,HZ /10 )) +if (wait_for_completion_timeout (comp,HZ /10 )) { +if (warned) +dev_warn (&hdev->device, +"Late %s completion arrived.\n" , msg_type);break ; + } + +if (!warned &&time_after64 (get_jiffies_64 (), timeout)) { +dev_err (&hdev->device, +"%s stuck waiting for response, relid = %u\n" , + msg_type, hdev->channel->offermsg.child_relid); + + warned = true; + } }return 0 ;@@ -1518,7 +1539,8 @@ static int hv_read_config_block(struct pci_dev *pdev, void *buf,if (ret)return ret; - ret =wait_for_response (hbus->hdev, &comp_pkt.comp_pkt.host_event); + ret =wait_for_response (hbus->hdev, &comp_pkt.comp_pkt.host_event, +"PCI_READ_BLOCK" );if (ret)return ret;@@ -1607,7 +1629,8 @@ static int hv_write_config_block(struct pci_dev *pdev, void *buf,if (ret)return ret; - ret =wait_for_response (hbus->hdev, &comp_pkt.host_event); + ret =wait_for_response (hbus->hdev, &comp_pkt.host_event, +"PCI_WRITE_BLOCK" );if (ret)return ret;@@ -2624,7 +2647,8 @@ static struct hv_pci_dev *new_pcichild_device(struct hv_pcibus_device *hbus, if (ret) goto error; -if (wait_for_response (hbus->hdev, &comp_pkt.host_event)) +if (wait_for_response (hbus->hdev, &comp_pkt.host_event, +"PCI_QUERY_RESOURCE_REQUIREMENTS" )) goto error;drivers/pci/controller/pci-hyperv.c +2
-1hpdev->desc = *desc;@@ -3256,7 +3280,8 @@ static int hv_pci_protocol_negotiation(struct hv_device *hdev, (unsigned long )pkt,VM_PKT_DATA_INBAND , VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);if (!ret) - ret =wait_for_response (hdev, &comp_pkt.host_event); + ret =wait_for_response (hdev, &comp_pkt.host_event, +"PCI_QUERY_PROTOCOL_VERSION" );if (ret) {drivers/pci/controller/pci-hyperv.c +6
-4dev_err(&hdev->device,@@ -3476,7 +3501,8 @@ static int hv_pci_enter_d0(struct hv_device *hdev) (unsigned long )pkt,VM_PKT_DATA_INBAND , VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);if (!ret) - ret =wait_for_response (hdev, &comp_pkt.host_event); + ret =wait_for_response (hdev, &comp_pkt.host_event, +"PCI_BUS_D0ENTRY" );if (ret) goto exit;@@ -3553,7 +3579,8 @@ static int hv_pci_query_relations(struct hv_device *hdev) ret =vmbus_sendpacket (hdev->channel, &message,sizeof (message),0 ,VM_PKT_DATA_INBAND ,0 );if (!ret) - ret =wait_for_response (hdev, &comp); + ret =wait_for_response (hdev, &comp, +"PCI_QUERY_BUS_RELATIONS" );/* * In the case of fast device addition/removal, it's possible that @@ -3644,7 +3671,8 @@ static int hv_send_resources_allocated(struct hv_device *hdev)VM_PKT_DATA_INBAND , VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);if (!ret) - ret =wait_for_response (hdev, &comp_pkt.host_event); + ret =wait_for_response (hdev, &comp_pkt.host_event, +"PCI_RESOURCE_ASSIGNED" );if (ret)break ; --2.53.0