Skip to contentSkip to conversation

Revert "virtio_pci: Support surprise removal of virtio pci device"

PATCH Li,Rongqing 3 participants 15 messages Aug 22, 2025 – Aug 28, 2025

Subsystems (2)
lore
Share & tools
lore

Li,Rongqing

author Tested-by
#0 lore raw
Quoted 30 lines

This reverts commit 43bb40c5b926 ("virtio_pci: Support surprise removal of virtio pci device").

Virtio drivers and PCI devices have never fully supported true surprise (aka hot unplug) removal. Drivers historically continued processing and waiting for pending I/O and even continued synchronous device reset during surprise removal. Devices have also continued completing I/Os, doing DMA and allowing device reset after surprise removal to support such drivers.

Supporting it correctly would require a new device capability and driver negotiation in the virtio specification to safely stop I/O and free queue memory. Failure to do so either breaks all the existing drivers with call trace listed in the commit or crashes the host on continuing the DMA. Hence, until such specification and devices are invented, restore the previous behavior of treating surprise removal as graceful removal to avoid regressions and maintain system stability same as before the commit 43bb40c5b926 ("virtio_pci: Support surprise removal of virtio pci device").

As explained above, previous analysis of solving this only in driver was incomplete and non-reliable at [1] and at [2]; Hence reverting commit 43bb40c5b926 ("virtio_pci: Support surprise removal of virtio pci device") is still the best stand to restore failures of virtio net and block devices.

[1]
https://lore.kernel.org/virtualization/CY8PR12MB719506CC5613EB100BC6C638
[email protected]/#t
[2]
https://lore.kernel.org/virtualization/[email protected]
om/

Quoted 7 lines
Fixes 43bb40c5b926 ("virtio_pci: Support surprise removal of virtio pci device")
Reported-by [email protected]

Closes:
https://lore.kernel.org/virtualization/c45dd68698cd47238c55fb73ca9b4741@b
aidu.com/

Thanks

-Li

Quoted 25 lines
---
 drivers/virtio/virtio_pci_common.c | 7 -------
 1 file changed, 7 deletions(-)
drivers/virtio/virtio_pci_common.c +0 -8
index d6d79af44569..dba5eb2eaff9 100644
@@ -747,13 +747,6 @@ static void virtio_pci_remove(struct pci_dev *pci_dev)
 	struct virtio_pci_device *vp_dev = pci_get_drvdata(pci_dev);
 	struct device *dev = get_device(&vp_dev->vdev.dev);
 
-	/*
-	 * Device is marked broken on surprise removal so that virtio upper
-	 * layers can abort any ongoing operation.
-	 */
-	if (!pci_device_is_present(pci_dev))
-		virtio_break_device(&vp_dev->vdev);
-
 	pci_disable_sriov(pci_dev);
 
 	unregister_virtio_device(&vp_dev->vdev);
--

2.26.2

#1 lore raw
Quoted 53 lines

From: Li,Rongqing <[email protected]>
Sent: 22 August 2025 03:57 PM

Quoted 10 lines

This reverts commit 43bb40c5b926 ("virtio_pci: Support surprise removal of virtio pci device").

Virtio drivers and PCI devices have never fully supported true surprise (aka hot
unplug) removal. Drivers historically continued processing and waiting for pending I/O and even continued synchronous device reset during surprise removal. Devices have also continued completing I/Os, doing DMA and allowing device reset after surprise removal to support such drivers.

Quoted 2 lines

Supporting it correctly would require a new device capability and driver negotiation in the virtio specification to safely stop I/O and free queue

memory.

Quoted 6 lines

Failure to do so either breaks all the existing drivers with call trace listed in the commit or crashes the host on continuing the DMA. Hence, until such specification and devices are invented, restore the previous behavior of treating surprise removal as graceful removal to avoid regressions and maintain system stability same as before the commit 43bb40c5b926 ("virtio_pci: Support surprise removal of virtio pci

device").

Quoted 6 lines

As explained above, previous analysis of solving this only in driver was incomplete and non-reliable at [1] and at [2]; Hence reverting commit
43bb40c5b926 ("virtio_pci: Support surprise removal of virtio pci device") is still the best stand to restore failures of virtio net and block

devices.

Quoted 3 lines

[1]

https://lore.kernel.org/virtualization/CY8PR12MB719506CC5613EB100BC6C6

Quoted 7 lines

38 [email protected]/#t
[2]
https://lore.kernel.org/virtualization/20250602024358.57114-1-parav@nv
idia.c
om/

Fixes 43bb40c5b926 ("virtio_pci: Support surprise removal of virtio
Quoted 8 lines

pci device")

Closes:
https://lore.kernel.org/virtualization/c45dd68698cd47238c55fb73ca9b474
1@b
aidu.com/

Quoted 6 lines

Thanks

-Li

Multiple users are blocked to have this fix in stable kernel. Thanks a lot Li for the quick test.

Quoted 27 lines

drivers/virtio/virtio_pci_common.c static void virtio_pci_remove(struct pci_dev

Quoted 11 lines
---
 drivers/virtio/virtio_pci_common.c | 7 -------
 1 file changed, 7 deletions(-)
drivers/virtio/virtio_pci_common.c +0 -0
index d6d79af44569..dba5eb2eaff9 100644
@@ -747,13 +747,6 @@ static void virtio_pci_remove(struct pci_dev

*pci_dev)

Quoted 15 lines
drivers/virtio/virtio_pci_common.c +0 -8
 	struct virtio_pci_device *vp_dev = pci_get_drvdata(pci_dev);
 	struct device *dev = get_device(&vp_dev->vdev.dev);
 
-	/*
-	 * Device is marked broken on surprise removal so that virtio upper
-	 * layers can abort any ongoing operation.
-	 */
-	if (!pci_device_is_present(pci_dev))
-		virtio_break_device(&vp_dev->vdev);
-
 	pci_disable_sriov(pci_dev);
 
 	unregister_virtio_device(&vp_dev->vdev);
--

2.26.2

#2 lore raw
Quoted 53 lines · Parav Pandit
Quoted 53 lines

From: Li,Rongqing <[email protected]>
Sent: 22 August 2025 03:57 PM

Quoted 10 lines

This reverts commit 43bb40c5b926 ("virtio_pci: Support surprise removal of virtio pci device").

Virtio drivers and PCI devices have never fully supported true surprise (aka hot
unplug) removal. Drivers historically continued processing and waiting for pending I/O and even continued synchronous device reset during surprise removal. Devices have also continued completing I/Os, doing DMA and allowing device reset after surprise removal to support such drivers.

Quoted 2 lines

Supporting it correctly would require a new device capability and driver negotiation in the virtio specification to safely stop I/O and free queue

memory.

Quoted 6 lines

Failure to do so either breaks all the existing drivers with call trace listed in the commit or crashes the host on continuing the DMA. Hence, until such specification and devices are invented, restore the previous behavior of treating surprise removal as graceful removal to avoid regressions and maintain system stability same as before the commit 43bb40c5b926 ("virtio_pci: Support surprise removal of virtio pci

device").

Quoted 6 lines

As explained above, previous analysis of solving this only in driver was incomplete and non-reliable at [1] and at [2]; Hence reverting commit
43bb40c5b926 ("virtio_pci: Support surprise removal of virtio pci device") is still the best stand to restore failures of virtio net and block

devices.

Quoted 3 lines

[1]

https://lore.kernel.org/virtualization/CY8PR12MB719506CC5613EB100BC6C6

Quoted 15 lines

38 [email protected]/#t
[2]
https://lore.kernel.org/virtualization/20250602024358.57114-1-parav@nv
idia.c
om/

Fixes 43bb40c5b926 ("virtio_pci: Support surprise removal of virtio

pci device")

Closes:
https://lore.kernel.org/virtualization/c45dd68698cd47238c55fb73ca9b474
1@b
aidu.com/

Quoted 7 lines
Quoted 6 lines

Thanks

-Li

Multiple users are blocked to have this fix in stable kernel.

what are these users doing that is blocked by this fix?

Signature · 1 line
MST
#3 lore raw
Quoted 68 lines

From: Michael S. Tsirkin <[email protected]>
Sent: 22 August 2025 06:35 PM

Quoted 7 lines · Parav Pandit
Quoted 7 lines

From: Li,Rongqing <[email protected]>
Sent: 22 August 2025 03:57 PM

Quoted 3 lines

This reverts commit 43bb40c5b926 ("virtio_pci: Support surprise removal of virtio pci device").

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Virtio drivers and PCI devices have never fully supported true surprise (aka hot
unplug) removal. Drivers historically continued processing and waiting for pending I/O and even continued synchronous device reset during surprise removal. Devices have also continued completing I/Os, doing DMA and allowing device reset after surprise

removal to support such drivers.

Quoted 48 lines
Quoted 48 lines
Quoted 4 lines

Supporting it correctly would require a new device capability and driver negotiation in the virtio specification to safely stop I/O and free queue

memory.

Quoted 7 lines

Failure to do so either breaks all the existing drivers with call trace listed in the commit or crashes the host on continuing the DMA. Hence, until such specification and devices are invented, restore the previous behavior of treating surprise removal as graceful removal to avoid regressions and maintain system stability same as before the commit 43bb40c5b926 ("virtio_pci: Support surprise removal of virtio pci

device").

Quoted 7 lines

As explained above, previous analysis of solving this only in driver was incomplete and non-reliable at [1] and at [2]; Hence reverting commit
43bb40c5b926 ("virtio_pci: Support surprise removal of virtio pci device") is still the best stand to restore failures of virtio net and block

devices.

Quoted 3 lines

[1]

https://lore.kernel.org/virtualization/CY8PR12MB719506CC5613EB100BC6
C6

Quoted 9 lines

38 [email protected]/#t
[2]
https://lore.kernel.org/virtualization/20250602024358.57114-1-para
v@nv
idia.c
om/

Fixes 43bb40c5b926 ("virtio_pci: Support surprise removal of

virtio pci device")

Quoted 8 lines

Closes:
https://lore.kernel.org/virtualization/c45dd68698cd47238c55fb73ca9
b474
1@b
aidu.com/

Quoted 8 lines
Quoted 5 lines
Quoted 4 lines

Thanks

-Li

Multiple users are blocked to have this fix in stable kernel.

what are these users doing that is blocked by this fix?

Not sure I understand the question. Let me try to answer.
They are unable to dynamically add/remove the virtio net, block, fs devices in their systems. Users have their networking applications running over NS network and database and file system through these devices. Some of them keep reverting the patch. Some are unable to.
They are in search of stable kernel.

Did I understand your question?

Quoted 2 lines

--
MST

#4 lore raw
Quoted 76 lines · Parav Pandit
Quoted 68 lines

From: Michael S. Tsirkin <[email protected]>
Sent: 22 August 2025 06:35 PM

Quoted 7 lines · Parav Pandit
Quoted 7 lines

From: Li,Rongqing <[email protected]>
Sent: 22 August 2025 03:57 PM

Quoted 3 lines

This reverts commit 43bb40c5b926 ("virtio_pci: Support surprise removal of virtio pci device").

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Virtio drivers and PCI devices have never fully supported true surprise (aka hot
unplug) removal. Drivers historically continued processing and waiting for pending I/O and even continued synchronous device reset during surprise removal. Devices have also continued completing I/Os, doing DMA and allowing device reset after surprise

removal to support such drivers.

Quoted 48 lines
Quoted 48 lines
Quoted 4 lines

Supporting it correctly would require a new device capability and driver negotiation in the virtio specification to safely stop I/O and free queue

memory.

Quoted 7 lines

Failure to do so either breaks all the existing drivers with call trace listed in the commit or crashes the host on continuing the DMA. Hence, until such specification and devices are invented, restore the previous behavior of treating surprise removal as graceful removal to avoid regressions and maintain system stability same as before the commit 43bb40c5b926 ("virtio_pci: Support surprise removal of virtio pci

device").

Quoted 7 lines

As explained above, previous analysis of solving this only in driver was incomplete and non-reliable at [1] and at [2]; Hence reverting commit
43bb40c5b926 ("virtio_pci: Support surprise removal of virtio pci device") is still the best stand to restore failures of virtio net and block

devices.

Quoted 3 lines

[1]

https://lore.kernel.org/virtualization/CY8PR12MB719506CC5613EB100BC6
C6

Quoted 9 lines

38 [email protected]/#t
[2]
https://lore.kernel.org/virtualization/20250602024358.57114-1-para
v@nv
idia.c
om/

Fixes 43bb40c5b926 ("virtio_pci: Support surprise removal of

virtio pci device")

Quoted 8 lines

Closes:
https://lore.kernel.org/virtualization/c45dd68698cd47238c55fb73ca9
b474
1@b
aidu.com/

Quoted 8 lines
Quoted 5 lines
Quoted 4 lines

Thanks

-Li

Multiple users are blocked to have this fix in stable kernel.

what are these users doing that is blocked by this fix?

Quoted 8 lines

Not sure I understand the question. Let me try to answer.
They are unable to dynamically add/remove the virtio net, block, fs devices in their systems. Users have their networking applications running over NS network and database and file system through these devices. Some of them keep reverting the patch. Some are unable to.
They are in search of stable kernel.

Did I understand your question?

Not really, sorry.

Does the system or does it not have a mechanical interlock?

If it does, how does a user run into surprise removal issues without the ability to remove the device?

If it does not, and a user pull out the working device, how does your patch help?

Signature · 1 line
MST
#5 lore raw
Quoted 96 lines

From: Michael S. Tsirkin <[email protected]>
Sent: 22 August 2025 07:32 PM

Quoted 20 lines · Parav Pandit
Quoted 20 lines

From: Michael S. Tsirkin <[email protected]>
Sent: 22 August 2025 06:35 PM

Quoted 14 lines · Parav Pandit
Quoted 14 lines

From: Li,Rongqing <[email protected]>
Sent: 22 August 2025 03:57 PM

Quoted 10 lines

This reverts commit 43bb40c5b926 ("virtio_pci: Support surprise removal of virtio pci device").

Virtio drivers and PCI devices have never fully supported true surprise (aka hot
unplug) removal. Drivers historically continued processing and waiting for pending I/O and even continued synchronous device reset during surprise removal. Devices have also continued completing I/Os, doing DMA and allowing device reset after surprise

Quoted 8 lines
Quoted 8 lines

removal to support such drivers.

Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

Supporting it correctly would require a new device capability and driver negotiation in the virtio specification to safely stop I/O and free queue

memory.

Quoted 2 lines

Failure to do so either breaks all the existing drivers with call trace listed in the commit or crashes the host on continuing the

DMA.

Quoted 47 lines
Quoted 47 lines
Quoted 47 lines
Quoted 47 lines
Quoted 5 lines

Hence, until such specification and devices are invented, restore the previous behavior of treating surprise removal as graceful removal to avoid regressions and maintain system stability same as before the commit 43bb40c5b926 ("virtio_pci:
Support surprise removal of virtio pci

device").

Quoted 8 lines

As explained above, previous analysis of solving this only in driver was incomplete and non-reliable at [1] and at [2]; Hence reverting commit
43bb40c5b926 ("virtio_pci: Support surprise removal of virtio pci
device") is still the best stand to restore failures of virtio net and block

devices.

Quoted 3 lines

[1]

https://lore.kernel.org/virtualization/CY8PR12MB719506CC5613EB10
0BC6
C6

Quoted 12 lines

38 [email protected]/#t
[2]
https://lore.kernel.org/virtualization/20250602024358.57114-1-
para
v@nv
idia.c
om/

Fixes 43bb40c5b926 ("virtio_pci: Support surprise removal of

virtio pci device")

Quoted 7 lines

Closes:
https://lore.kernel.org/virtualization/c45dd68698cd47238c55fb7
3ca9
b474
1@b
aidu.com/

Thanks

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 2 lines

-Li

Multiple users are blocked to have this fix in stable kernel.

what are these users doing that is blocked by this fix?

Not sure I understand the question. Let me try to answer.
They are unable to dynamically add/remove the virtio net, block, fs devices in

their systems.

Quoted 1 line

Users have their networking applications running over NS network and

database and file system through these devices.

Quoted 3 lines

Some of them keep reverting the patch. Some are unable to. They are in search of stable kernel.

Quoted 7 lines
Quoted 2 lines

Did I understand your question?

Not really, sorry.

Does the system or does it not have a mechanical interlock?

It is modern system beyond mechanical interlock but has the ability for surprise removal.

Quoted 3 lines

If it does, how does a user run into surprise removal issues without the ability to remove the device?

User has the ability to surprise removal a device from the slot via the slot's pci registers.
Yet the device is capable enough to fulfil the needs of broken drivers which are waiting for the pending requests to arrive.

Quoted 3 lines

If it does not, and a user pull out the working device, how does your patch help?

A driver must tell that it will not follow broken ancient behaviour and at that point device would stop its ancient backward compatibility mode.

Quoted 2 lines

--
MST

#6 lore raw
Quoted 96 lines · Parav Pandit
Quoted 96 lines

From: Michael S. Tsirkin <[email protected]>
Sent: 22 August 2025 07:32 PM

Quoted 20 lines · Parav Pandit
Quoted 20 lines

From: Michael S. Tsirkin <[email protected]>
Sent: 22 August 2025 06:35 PM

Quoted 14 lines · Parav Pandit
Quoted 14 lines

From: Li,Rongqing <[email protected]>
Sent: 22 August 2025 03:57 PM

Quoted 10 lines

This reverts commit 43bb40c5b926 ("virtio_pci: Support surprise removal of virtio pci device").

Virtio drivers and PCI devices have never fully supported true surprise (aka hot
unplug) removal. Drivers historically continued processing and waiting for pending I/O and even continued synchronous device reset during surprise removal. Devices have also continued completing I/Os, doing DMA and allowing device reset after surprise

Quoted 8 lines
Quoted 8 lines

removal to support such drivers.

Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

Supporting it correctly would require a new device capability and driver negotiation in the virtio specification to safely stop I/O and free queue

memory.

Quoted 2 lines

Failure to do so either breaks all the existing drivers with call trace listed in the commit or crashes the host on continuing the

DMA.

Quoted 47 lines
Quoted 47 lines
Quoted 47 lines
Quoted 47 lines
Quoted 5 lines

Hence, until such specification and devices are invented, restore the previous behavior of treating surprise removal as graceful removal to avoid regressions and maintain system stability same as before the commit 43bb40c5b926 ("virtio_pci:
Support surprise removal of virtio pci

device").

Quoted 8 lines

As explained above, previous analysis of solving this only in driver was incomplete and non-reliable at [1] and at [2]; Hence reverting commit
43bb40c5b926 ("virtio_pci: Support surprise removal of virtio pci
device") is still the best stand to restore failures of virtio net and block

devices.

Quoted 3 lines

[1]

https://lore.kernel.org/virtualization/CY8PR12MB719506CC5613EB10
0BC6
C6

Quoted 12 lines

38 [email protected]/#t
[2]
https://lore.kernel.org/virtualization/20250602024358.57114-1-
para
v@nv
idia.c
om/

Fixes 43bb40c5b926 ("virtio_pci: Support surprise removal of

virtio pci device")

Quoted 7 lines

Closes:
https://lore.kernel.org/virtualization/c45dd68698cd47238c55fb7
3ca9
b474
1@b
aidu.com/

Thanks

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 2 lines

-Li

Multiple users are blocked to have this fix in stable kernel.

what are these users doing that is blocked by this fix?

Not sure I understand the question. Let me try to answer.
They are unable to dynamically add/remove the virtio net, block, fs devices in

their systems.

Quoted 1 line

Users have their networking applications running over NS network and

database and file system through these devices.

Quoted 3 lines

Some of them keep reverting the patch. Some are unable to. They are in search of stable kernel.

Quoted 8 lines
Quoted 7 lines
Quoted 2 lines

Did I understand your question?

Not really, sorry.

Does the system or does it not have a mechanical interlock?

It is modern system beyond mechanical interlock but has the ability for surprise removal.

I am not sure what does "beyond" mean. I guess that it does not have it?

Quoted 4 lines
Quoted 3 lines

If it does, how does a user run into surprise removal issues without the ability to remove the device?

User has the ability to surprise removal a device from the slot via the slot's pci registers.

I don't know what this means. Surprise removal is done by removing the device. Not via pci registers.

Quoted 1 line

Yet the device is capable enough to fulfil the needs of broken drivers which are waiting for the pending requests to arrive.

I don't know what this means. A removed device can not do anything at all.

Quoted 4 lines
Quoted 3 lines

If it does not, and a user pull out the working device, how does your patch help?

A driver must tell that it will not follow broken ancient behaviour and at that point device would stop its ancient backward compatibility mode.

I don't know what is "ancient backward compatibility mode".

Quoted 2 lines
Quoted 2 lines

--
MST

#7 lore raw
Quoted 111 lines

From: Michael S. Tsirkin <[email protected]>
Sent: 24 August 2025 08:00 PM

Quoted 32 lines · Parav Pandit
Quoted 32 lines

From: Michael S. Tsirkin <[email protected]>
Sent: 22 August 2025 07:32 PM

Quoted 26 lines · Parav Pandit
Quoted 26 lines

From: Michael S. Tsirkin <[email protected]>
Sent: 22 August 2025 06:35 PM

Quoted 7 lines · Parav Pandit
Quoted 7 lines

From: Li,Rongqing <[email protected]>
Sent: 22 August 2025 03:57 PM

Quoted 3 lines

This reverts commit 43bb40c5b926 ("virtio_pci: Support surprise removal of virtio pci device").

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Virtio drivers and PCI devices have never fully supported true surprise (aka hot
unplug) removal. Drivers historically continued processing and waiting for pending I/O and even continued synchronous device reset during surprise removal. Devices have also continued completing I/Os, doing DMA and allowing device reset after surprise

removal to support such drivers.

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

Supporting it correctly would require a new device capability and driver negotiation in the virtio specification to safely stop I/O and free queue

memory.

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Failure to do so either breaks all the existing drivers with call trace listed in the commit or crashes the host on continuing the

DMA.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Hence, until such specification and devices are invented, restore the previous behavior of treating surprise removal as graceful removal to avoid regressions and maintain system stability same as before the commit 43bb40c5b926

("virtio_pci:

Quoted 65 lines
Quoted 65 lines
Quoted 48 lines
Quoted 48 lines
Quoted 48 lines
Quoted 48 lines
Quoted 1 line

Support surprise removal of virtio pci

device").

Quoted 8 lines

As explained above, previous analysis of solving this only in driver was incomplete and non-reliable at [1] and at [2]; Hence reverting commit
43bb40c5b926 ("virtio_pci: Support surprise removal of virtio pci
device") is still the best stand to restore failures of virtio net and block

devices.

Quoted 3 lines

[1]

https://lore.kernel.org/virtualization/CY8PR12MB719506CC5613
EB10
0BC6
C6

Quoted 13 lines

38 [email protected]/#t
[2]
https://lore.kernel.org/virtualization/20250602024358.5711
4-1-
para
v@nv
idia.c
om/

Fixes 43bb40c5b926 ("virtio_pci: Support surprise removal

of virtio pci device")

Quoted 8 lines

Closes:
https://lore.kernel.org/virtualization/c45dd68698cd47238c5
5fb7
3ca9
b474
1@b
aidu.com/

Thanks

-Li

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Multiple users are blocked to have this fix in stable kernel.

what are these users doing that is blocked by this fix?

Not sure I understand the question. Let me try to answer. They are unable to dynamically add/remove the virtio net, block, fs devices in

their systems.

Quoted 2 lines

Users have their networking applications running over NS network and

database and file system through these devices.

Quoted 5 lines

Some of them keep reverting the patch. Some are unable to. They are in search of stable kernel.

Did I understand your question?

Quoted 9 lines
Quoted 5 lines
Quoted 4 lines

Not really, sorry.

Does the system or does it not have a mechanical interlock?

It is modern system beyond mechanical interlock but has the ability for

surprise removal.

I am not sure what does "beyond" mean. I guess that it does not have it?

Right.

Quoted 8 lines
Quoted 4 lines
Quoted 3 lines

If it does, how does a user run into surprise removal issues without the ability to remove the device?

User has the ability to surprise removal a device from the slot via the slot's

pci registers.

I don't know what this means. Surprise removal is done by removing the device. Not via pci registers.

They are many ways to surprise remove a device from a slot.
Slots are capable to detect the device removal and when that occurs, the pcie switch/bridge updates the slot registers for the downstream port and indicate to the sw. Some slots are physical in nature. Some are virtual slots in the pcie switch/bridge.
End result is, sw gets to know this sw PCIe registers in switch/bridge/port level.

Quoted 6 lines
Quoted 2 lines

Yet the device is capable enough to fulfil the needs of broken drivers which

are waiting for the pending requests to arrive.

I don't know what this means. A removed device can not do anything at all.

If this was really physically removed, yes.
but in virtual system, the device is still present on the slot until it gets indication from the OS.

Quoted 10 lines
Quoted 4 lines
Quoted 3 lines

If it does not, and a user pull out the working device, how does your patch help?

A driver must tell that it will not follow broken ancient behaviour and at that

point device would stop its ancient backward compatibility mode.

I don't know what is "ancient backward compatibility mode".

Let me explain.
Sadly, CSPs virtio pci device implementation is done such a way that, it works with ancient Linux kernel which does not have commit 43bb40c5b9265. Commit 43bb40c5b9265 was partial in nature.
Hence request to revert and do proper implementation like you mentioned using extra callback and/or with spec extension.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

--
MST

#8 lore raw
Quoted 4 lines · Parav Pandit
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

If it does not, and a user pull out the working device, how does your patch help?

A driver must tell that it will not follow broken ancient behaviour and at that

Quoted 8 lines
Quoted 6 lines

point device would stop its ancient backward compatibility mode.

I don't know what is "ancient backward compatibility mode".

Let me explain.
Sadly, CSPs virtio pci device implementation is done such a way that, it works with ancient Linux kernel which does not have commit 43bb40c5b9265.

OK we are getting new information here.

So let me summarize. There's a virtual system that pretends, to the guest, that device was removed by surprise removal, but actually device is there and is still doing DMA.
Is that a fair summary?

Signature · 1 line
MST
#9 lore raw
Quoted 15 lines · Michael S. Tsirkin
Quoted 4 lines · Parav Pandit
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

If it does not, and a user pull out the working device, how does your patch help?

A driver must tell that it will not follow broken ancient behaviour and at that

Quoted 8 lines
Quoted 6 lines

point device would stop its ancient backward compatibility mode.

I don't know what is "ancient backward compatibility mode".

Let me explain.
Sadly, CSPs virtio pci device implementation is done such a way that, it works with ancient Linux kernel which does not have commit 43bb40c5b9265.

Quoted 6 lines

OK we are getting new information here.

So let me summarize. There's a virtual system that pretends, to the guest, that device was removed by surprise removal, but actually device is there and is still doing DMA.
Is that a fair summary?

If that is the case, the thing to do would be to try and detect the fake removal and then work with device as usual - device not doing DMA after removal is pretty fundamental, after all.

For example, how about reading device control+status?

If we get all ones device has been removed
If we get 0 in bus master: device has been removed but re-inserted Anything else is a fake removal

Hmm?

Quoted 2 lines
Signature · 1 line
MST
#10 lore raw
Quoted 15 lines

From: Michael S. Tsirkin <[email protected]>
Sent: 27 August 2025 04:19 PM

Quoted 10 lines · Michael S. Tsirkin
Quoted 9 lines · Parav Pandit
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines

If it does not, and a user pull out the working device, how does your patch help?

A driver must tell that it will not follow broken ancient behaviour and at that

point device would stop its ancient backward compatibility mode.

Quoted 15 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

I don't know what is "ancient backward compatibility mode".

Let me explain.
Sadly, CSPs virtio pci device implementation is done such a way that, it

works with ancient Linux kernel which does not have commit 43bb40c5b9265.

Quoted 8 lines

OK we are getting new information here.

So let me summarize. There's a virtual system that pretends, to the guest, that device was removed by surprise removal, but actually device is there and is still doing DMA.
Is that a fair summary?

Yes.

Quoted 4 lines

If that is the case, the thing to do would be to try and detect the fake removal and then work with device as usual - device not doing DMA after removal is pretty fundamental, after all.

The issue is: one can build the device to stop the DMA.
There is no predictable combination for the driver and device that can work for the user. For example,
Device that stops the dma will not work before the commit 43bb40c5b9265.
Device that continues the dma will not work with whatever new implementation done in future kernels.

Hence the capability negotiation would be needed so that device can stop the DMA, config interrupts etc.

Quoted 2 lines

For example, how about reading device control+status?

Most platforms read 0xffff on non-existing device, but not sure if this the standard or well defined.

Quoted 3 lines

If we get all ones device has been removed If we get 0 in bus master: device has been removed but re-inserted Anything else is a fake removal

Bus master check may pass, right returning all 1s, even if the device is removed, isn't it?

Quoted 7 lines

Hmm?

Quoted 2 lines

--
MST

#11 lore raw
Quoted 36 lines · Parav Pandit
Quoted 15 lines

From: Michael S. Tsirkin <[email protected]>
Sent: 27 August 2025 04:19 PM

Quoted 10 lines · Michael S. Tsirkin
Quoted 9 lines · Parav Pandit
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines

If it does not, and a user pull out the working device, how does your patch help?

A driver must tell that it will not follow broken ancient behaviour and at that

point device would stop its ancient backward compatibility mode.

Quoted 15 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

I don't know what is "ancient backward compatibility mode".

Let me explain.
Sadly, CSPs virtio pci device implementation is done such a way that, it

works with ancient Linux kernel which does not have commit 43bb40c5b9265.

Quoted 8 lines

OK we are getting new information here.

So let me summarize. There's a virtual system that pretends, to the guest, that device was removed by surprise removal, but actually device is there and is still doing DMA.
Is that a fair summary?

Yes.

Quoted 4 lines

If that is the case, the thing to do would be to try and detect the fake removal and then work with device as usual - device not doing DMA after removal is pretty fundamental, after all.

Quoted 7 lines

The issue is: one can build the device to stop the DMA.
There is no predictable combination for the driver and device that can work for the user. For example,
Device that stops the dma will not work before the commit 43bb40c5b9265.
Device that continues the dma will not work with whatever new implementation done in future kernels.

Hence the capability negotiation would be needed so that device can stop the DMA, config interrupts etc.

So this is a broken implementation at the pci level. We really can't fix removal for this device at all, except by fixing the device. Whatever works, works by chance. Feature negotiation in spec is not the way to fix that, but some work arounds in the driver to skip the device are acceptable, mostly to not bother with it.

Pls document exactly how this pci looks. Does it have an id we can use to detect it?

Quoted 3 lines
Quoted 2 lines

For example, how about reading device control+status?

Most platforms read 0xffff on non-existing device, but not sure if this the standard or well defined.

IIRC it's in the pci spec as a note.

Quoted 4 lines
Quoted 3 lines

If we get all ones device has been removed If we get 0 in bus master: device has been removed but re-inserted Anything else is a fake removal

Bus master check may pass, right returning all 1s, even if the device is removed, isn't it?

So we check all ones 1st, only check bus master if not all ones?

Quoted 7 lines
Quoted 7 lines

Hmm?

Quoted 2 lines

--
MST

#12 lore raw
Quoted 49 lines

From: Michael S. Tsirkin <[email protected]>
Sent: 28 August 2025 12:04 PM

Quoted 31 lines · Parav Pandit
Quoted 15 lines

From: Michael S. Tsirkin <[email protected]>
Sent: 27 August 2025 04:19 PM

Quoted 10 lines · Michael S. Tsirkin
Quoted 9 lines · Parav Pandit
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines

If it does not, and a user pull out the working device, how does your patch help?

A driver must tell that it will not follow broken ancient behaviour and at that

point device would stop its ancient backward compatibility mode.

Quoted 16 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

I don't know what is "ancient backward compatibility mode".

Let me explain.
Sadly, CSPs virtio pci device implementation is done such a way that, it

works with ancient Linux kernel which does not have commit 43bb40c5b9265.

Quoted 8 lines

OK we are getting new information here.

So let me summarize. There's a virtual system that pretends, to the guest, that device was removed by surprise removal, but actually device is there and is still doing DMA.
Is that a fair summary?

Quoted 8 lines

Yes.

Quoted 4 lines

If that is the case, the thing to do would be to try and detect the fake removal and then work with device as usual - device not doing DMA after removal is pretty fundamental, after all.

The issue is: one can build the device to stop the DMA.
There is no predictable combination for the driver and device that can work

for the user.

Quoted 3 lines

For example,
Device that stops the dma will not work before the commit 43bb40c5b9265. Device that continues the dma will not work with whatever new

Quoted 7 lines

implementation done in future kernels.

Quoted 2 lines

Hence the capability negotiation would be needed so that device can stop the

DMA, config interrupts etc.

So this is a broken implementation at the pci level. We really can't fix removal for this device at all, except by fixing the device.

The device to be told how to behave with/without commit 43bb40c5b9265. Not sure what you mean by 'fix the device'.

Users are running stable kernel that has commit 43bb40c5b9265 and its broken setup for them.

Quoted 5 lines

Whatever works, works by
chance. Feature negotiation in spec is not the way to fix that, but some work arounds in the driver to skip the device are acceptable, mostly to not bother with it.

Why not?
It sounds like we need feature bit like VERSION_1 or ORDER_PLATFORM.

To _fix_ a stable kernel, if you have a suggestion, please suggest.

Quoted 3 lines

Pls document exactly how this pci looks. Does it have an id we can use to detect it?

CSPs have different device and vendor id for vnet, blk vfs. Is that what you mean by id?

Quoted 7 lines
Quoted 3 lines
Quoted 2 lines

For example, how about reading device control+status?

Most platforms read 0xffff on non-existing device, but not sure if this the

standard or well defined.

IIRC it's in the pci spec as a note.

Checking.

Quoted 10 lines
Quoted 5 lines
Quoted 4 lines

If we get all ones device has been removed If we get 0 in bus
master: device has been removed but re-inserted Anything else is a fake removal

Bus master check may pass, right returning all 1s, even if the device is

removed, isn't it?

So we check all ones 1st, only check bus master if not all ones?

Pci subsystem typically checks the vendor and device ids, and if its not all 1s, its safe enough check.

How about a fix something like this:

drivers/virtio/virtio_pci_common.c +5 -1
@@ -746,12 +746,16 @@ static void virtio_pci_remove(struct pci_dev *pci_dev)
 {
        struct virtio_pci_device *vp_dev = pci_get_drvdata(pci_dev);
        struct device *dev = get_device(&vp_dev->vdev.dev);
+       u32 v;
 
        /*
         * Device is marked broken on surprise removal so that virtio upper
         * layers can abort any ongoing operation.
+        * Make sure that device is truly removed by directly interacting
+        * with the device (and not just depend on the slot registers).
         */
-       if (!pci_device_is_present(pci_dev))
+       if (!pci_device_is_present(pci_dev) &&
+           !pci_bus_read_dev_vendor_id(pci_dev->bus, pci_dev->devfn, &v, 0))
                virtio_break_device(&vp_dev->vdev);
 

So if the device is still there, it let it go through its usual cleanup flow.
And post this fix, a proper implementation with callback etc that you described can be implemented.

#13 lore raw
Quoted 61 lines · Parav Pandit
Quoted 49 lines

From: Michael S. Tsirkin <[email protected]>
Sent: 28 August 2025 12:04 PM

Quoted 31 lines · Parav Pandit
Quoted 15 lines

From: Michael S. Tsirkin <[email protected]>
Sent: 27 August 2025 04:19 PM

Quoted 10 lines · Michael S. Tsirkin
Quoted 9 lines · Parav Pandit
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines

If it does not, and a user pull out the working device, how does your patch help?

A driver must tell that it will not follow broken ancient behaviour and at that

point device would stop its ancient backward compatibility mode.

Quoted 16 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

I don't know what is "ancient backward compatibility mode".

Let me explain.
Sadly, CSPs virtio pci device implementation is done such a way that, it

works with ancient Linux kernel which does not have commit 43bb40c5b9265.

Quoted 8 lines

OK we are getting new information here.

So let me summarize. There's a virtual system that pretends, to the guest, that device was removed by surprise removal, but actually device is there and is still doing DMA.
Is that a fair summary?

Quoted 8 lines

Yes.

Quoted 4 lines

If that is the case, the thing to do would be to try and detect the fake removal and then work with device as usual - device not doing DMA after removal is pretty fundamental, after all.

The issue is: one can build the device to stop the DMA.
There is no predictable combination for the driver and device that can work

for the user.

Quoted 3 lines

For example,
Device that stops the dma will not work before the commit 43bb40c5b9265. Device that continues the dma will not work with whatever new

Quoted 7 lines

implementation done in future kernels.

Quoted 2 lines

Hence the capability negotiation would be needed so that device can stop the

DMA, config interrupts etc.

So this is a broken implementation at the pci level. We really can't fix removal for this device at all, except by fixing the device.

The device to be told how to behave with/without commit 43bb40c5b9265. Not sure what you mean by 'fix the device'.

Users are running stable kernel that has commit 43bb40c5b9265 and its broken setup for them.

Quoted 7 lines
Quoted 5 lines

Whatever works, works by
chance. Feature negotiation in spec is not the way to fix that, but some work arounds in the driver to skip the device are acceptable, mostly to not bother with it.

Why not?
It sounds like we need feature bit like VERSION_1 or ORDER_PLATFORM.

Because the device is out of spec (PCI spec which virtio references).

Besides the bug is not in the device, it's in the pci emulation.

Quoted 7 lines

To _fix_ a stable kernel, if you have a suggestion, please suggest.

Quoted 3 lines

Pls document exactly how this pci looks. Does it have an id we can use to detect it?

CSPs have different device and vendor id for vnet, blk vfs. Is that what you mean by id?

vendor id is one way, yes. maybe a revision check, too.

Quoted 42 lines
Quoted 7 lines
Quoted 3 lines
Quoted 2 lines

For example, how about reading device control+status?

Most platforms read 0xffff on non-existing device, but not sure if this the

standard or well defined.

IIRC it's in the pci spec as a note.

Checking.

Quoted 10 lines
Quoted 5 lines
Quoted 4 lines

If we get all ones device has been removed If we get 0 in bus
master: device has been removed but re-inserted Anything else is a fake removal

Bus master check may pass, right returning all 1s, even if the device is

removed, isn't it?

So we check all ones 1st, only check bus master if not all ones?

Pci subsystem typically checks the vendor and device ids, and if its not all 1s, its safe enough check.

How about a fix something like this:

drivers/virtio/virtio_pci_common.c +5 -1
@@ -746,12 +746,16 @@ static void virtio_pci_remove(struct pci_dev *pci_dev)
 {
        struct virtio_pci_device *vp_dev = pci_get_drvdata(pci_dev);
        struct device *dev = get_device(&vp_dev->vdev.dev);
+       u32 v;
 
        /*
         * Device is marked broken on surprise removal so that virtio upper
         * layers can abort any ongoing operation.
+        * Make sure that device is truly removed by directly interacting
+        * with the device (and not just depend on the slot registers).
         */
-       if (!pci_device_is_present(pci_dev))
+       if (!pci_device_is_present(pci_dev) &&
+           !pci_bus_read_dev_vendor_id(pci_dev->bus, pci_dev->devfn, &v, 0))
                virtio_break_device(&vp_dev->vdev);
 
Quoted 2 lines

So if the device is still there, it let it go through its usual cleanup flow.
And post this fix, a proper implementation with callback etc that you described can be implemented.

I don't have a big problem with this, but I don't understand the scenario now again. report_error_detected relies on dev->error_state and bus read. error_state is set on AER reporting an error. This is not what you described.

Does the patch actually solve the problem for you?

Also can we limit this to a specific vendor id, or something like that?

I also still like the idea of reading dev control and status, since it always bothered me that there's a theoretical chance that device is re-inserted and bus read will succeed. Or maybe I'm imagining it.

Signature · 1 line
MST
#14 lore raw
Quoted 87 lines

From: Michael S. Tsirkin <[email protected]>
Sent: 28 August 2025 02:53 PM

Quoted 43 lines · Parav Pandit
Quoted 43 lines

From: Michael S. Tsirkin <[email protected]>
Sent: 28 August 2025 12:04 PM

Quoted 37 lines · Parav Pandit
Quoted 15 lines

From: Michael S. Tsirkin <[email protected]>
Sent: 27 August 2025 04:19 PM

Quoted 10 lines · Michael S. Tsirkin
Quoted 9 lines · Parav Pandit
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines

If it does not, and a user pull out the working
device, how does your patch help?

A driver must tell that it will not follow broken
ancient behaviour and at that

point device would stop its ancient backward compatibility mode.

Quoted 16 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

I don't know what is "ancient backward compatibility mode".

Let me explain.
Sadly, CSPs virtio pci device implementation is done such a way that, it

works with ancient Linux kernel which does not have commit 43bb40c5b9265.

Quoted 8 lines

OK we are getting new information here.

So let me summarize. There's a virtual system that pretends, to the guest, that device was removed by surprise removal, but actually device is there and is still doing DMA.
Is that a fair summary?

Yes.

Quoted 4 lines

If that is the case, the thing to do would be to try and detect the fake removal and then work with device as usual - device not doing DMA after removal is pretty fundamental, after all.

Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

The issue is: one can build the device to stop the DMA. There is no predictable combination for the driver and device that can work

for the user.

Quoted 2 lines

For example,
Device that stops the dma will not work before the commit

43bb40c5b9265.

Quoted 5 lines
Quoted 5 lines
Quoted 1 line

Device that continues the dma will not work with whatever new

implementation done in future kernels.

Quoted 3 lines

Hence the capability negotiation would be needed so that device can stop the

Quoted 8 lines
Quoted 4 lines

DMA, config interrupts etc.

So this is a broken implementation at the pci level. We really can't fix removal for this device at all, except by fixing the device.

The device to be told how to behave with/without commit 43bb40c5b9265. Not sure what you mean by 'fix the device'.

Users are running stable kernel that has commit 43bb40c5b9265 and its

broken setup for them.

Quoted 8 lines
Quoted 6 lines

Whatever works, works by
chance. Feature negotiation in spec is not the way to fix that, but some work arounds in the driver to skip the device are acceptable, mostly to not bother with it.

Why not?
It sounds like we need feature bit like VERSION_1 or ORDER_PLATFORM.

Because the device is out of spec (PCI spec which virtio references).

Besides the bug is not in the device, it's in the pci emulation.

Quoted 2 lines

To _fix_ a stable kernel, if you have a suggestion, please suggest.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Pls document exactly how this pci looks. Does it have an id we can use to detect it?

CSPs have different device and vendor id for vnet, blk vfs. Is that what you mean by id?

vendor id is one way, yes. maybe a revision check, too.

Vendor and device id are as defined in virtio spec as ID 0x1AF4 and respective device id.

Quoted 46 lines
Quoted 14 lines
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

For example, how about reading device control+status?

Most platforms read 0xffff on non-existing device, but not sure if this the

standard or well defined.

IIRC it's in the pci spec as a note.

Checking.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

If we get all ones device has been removed If we get 0 in bus
master: device has been removed but re-inserted Anything else is a fake removal

Quoted 8 lines
Quoted 7 lines
Quoted 2 lines

Bus master check may pass, right returning all 1s, even if the device is

removed, isn't it?

So we check all ones 1st, only check bus master if not all ones?

Pci subsystem typically checks the vendor and device ids, and if its not all 1s,

its safe enough check.

Quoted 23 lines

How about a fix something like this:

drivers/virtio/virtio_pci_common.c +6 -1
@@ -746,12 +746,16 @@ static void virtio_pci_remove(struct pci_dev
 *pci_dev)  {
        struct virtio_pci_device *vp_dev = pci_get_drvdata(pci_dev);
        struct device *dev = get_device(&vp_dev->vdev.dev);
+       u32 v;
 
        /*
         * Device is marked broken on surprise removal so that virtio upper
         * layers can abort any ongoing operation.
+        * Make sure that device is truly removed by directly interacting
+        * with the device (and not just depend on the slot registers).
         */
-       if (!pci_device_is_present(pci_dev))
+       if (!pci_device_is_present(pci_dev) &&
+           !pci_bus_read_dev_vendor_id(pci_dev->bus, pci_dev->devfn,
+ &v, 0))
                virtio_break_device(&vp_dev->vdev);
 
Quoted 9 lines
Quoted 2 lines

So if the device is still there, it let it go through its usual cleanup flow. And post this fix, a proper implementation with callback etc that you

described can be implemented.

I don't have a big problem with this, but I don't understand the scenario now again. report_error_detected relies on dev->error_state and bus read. error_state is set on AER reporting an error. This is not what you described.

When pci device is virtually removed from the slot error_state is updated using,

pci_dev_set_disconnected()
pci_dev_set_io_state()

Quoted 2 lines

Does the patch actually solve the problem for you?

It should. I am going to check if this approach looks fine to you. Please let me know.

Quoted 2 lines

Also can we limit this to a specific vendor id, or something like that?

Its spec defined 0x1AF4.

Quoted 5 lines

I also still like the idea of reading dev control and status, since it always bothered me that there's a theoretical chance that device is re-inserted and bus read will succeed. Or maybe I'm imagining it.

Re-insertion cannot happen in same slot until the previous slot is properly cleaned up and bus number is not released.
User may still attempt to plug in in same (virtual) or physical slot, but it will get different bus assigned as the previous one is not recycled yet because cleanup didnt finish yet.

Quoted 3 lines

--
MST