Skip to contentSkip to conversation

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

PATCH In review Parav Pandit 2 participants 5 messages Apr 8, 2025 – Apr 16, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Revert "virtio_pci: Support surprise removal of virtio pci device"

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

The cited commit introduced a fix that marks the device as broken during surprise removal. However, this approach causes uncompleted I/O requests on virtio-blk device. The presence of uncompleted I/O requests prevents the successful removal of virtio-blk devices.

This fix allows devices that simulate a surprise removal but actually remove gracefully to continue working as before.

For surprise removals, a better solution will be preferred in the future.

Fixes 43bb40c5b926 ("virtio_pci: Support surprise removal of virtio pci device")
Reported-by [email protected]
---
 drivers/virtio/virtio_pci_common.c | 7 -------
 1 file changed, 7 deletions(-)
drivers/virtio/virtio_pci_common.c +0 -7
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);
Signature · 1 line
2.26.2
#1 lore raw
Quoted 11 lines · Parav Pandit

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

The cited commit introduced a fix that marks the device as broken during surprise removal. However, this approach causes uncompleted I/O requests on virtio-blk device. The presence of uncompleted I/O requests prevents the successful removal of virtio-blk devices.

This fix allows devices that simulate a surprise removal but actually remove gracefully to continue working as before.

For surprise removals, a better solution will be preferred in the future.

Sorry I'm not breaking one thing to fix another.
Device is gone so no new requests will be completed. Why not complete all unfinished requests, for example?

Come up with a proper fix pls.

Quoted 33 lines
Fixes 43bb40c5b926 ("virtio_pci: Support surprise removal of virtio pci device")
Reported-by [email protected]
---
 drivers/virtio/virtio_pci_common.c | 7 -------
 1 file changed, 7 deletions(-)
drivers/virtio/virtio_pci_common.c +0 -7
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);
Signature · 1 line
2.26.2
#2 lore raw

Hi Michael,

Quoted 15 lines

From: Michael S. Tsirkin <[email protected]>
Sent: Wednesday, April 9, 2025 1:45 AM

Quoted 1 line · Parav Pandit

This reverts commit 43bb40c5b926 ("virtio_pci: Support surprise removal of

virtio pci device").

Quoted 9 lines

The cited commit introduced a fix that marks the device as broken during surprise removal. However, this approach causes uncompleted I/O requests on virtio-blk device. The presence of uncompleted I/O requests prevents the successful removal of virtio-blk devices.

This fix allows devices that simulate a surprise removal but actually remove gracefully to continue working as before.

Quoted 8 lines
Quoted 1 line

For surprise removals, a better solution will be preferred in the future.

Sorry I'm not breaking one thing to fix another.
Device is gone so no new requests will be completed. Why not complete all unfinished requests, for example?

Come up with a proper fix pls.

I would also like to have a proper fix that can be backportable.
However, an attempt [1] had race.
To overcome the race, a different approach also tried, however the block layer was stuck even if all requests in virtio-blk driver layer was completed like you suggested.

It appeared that supporting uncompleted requests won't be so straightforward to backport.

Hence, the request is to revert and restore the previous behavior.
This at least improves the case where the OS thinks that surprise removal occurred, but the device eventually completes the IO. And hence, virtio block driver successfully unloads.
And virtio-net also does not experience the mentioned crash.

[1] https://lore.kernel.org/all/[email protected]/

Quoted 38 lines

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

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

pci device")

Closes:
https://lore.kernel.org/virtualization/c45dd68698cd47238c55fb73ca9b474
[email protected]/

---
 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

#3 lore raw
Quoted 29 lines · Parav Pandit

Hi Michael,

Quoted 15 lines

From: Michael S. Tsirkin <[email protected]>
Sent: Wednesday, April 9, 2025 1:45 AM

Quoted 1 line · Parav Pandit

This reverts commit 43bb40c5b926 ("virtio_pci: Support surprise removal of

virtio pci device").

Quoted 9 lines

The cited commit introduced a fix that marks the device as broken during surprise removal. However, this approach causes uncompleted I/O requests on virtio-blk device. The presence of uncompleted I/O requests prevents the successful removal of virtio-blk devices.

This fix allows devices that simulate a surprise removal but actually remove gracefully to continue working as before.

Quoted 8 lines
Quoted 1 line

For surprise removals, a better solution will be preferred in the future.

Sorry I'm not breaking one thing to fix another.
Device is gone so no new requests will be completed. Why not complete all unfinished requests, for example?

Come up with a proper fix pls.

I would also like to have a proper fix that can be backportable.
However, an attempt [1] had race.
To overcome the race, a different approach also tried, however the block layer was stuck even if all requests in virtio-blk driver layer was completed like you suggested.

Quoted 8 lines

It appeared that supporting uncompleted requests won't be so straightforward to backport.

Hence, the request is to revert and restore the previous behavior.
This at least improves the case where the OS thinks that surprise removal occurred, but the device eventually completes the IO. And hence, virtio block driver successfully unloads.
And virtio-net also does not experience the mentioned crash.

[1] https://lore.kernel.org/all/[email protected]/

Parav this is a commit from 2021. I am not reverting it "because it seems to help". We'll never make progress like this.
You will have to debug and fix it properly. Sorry.

Once we have a fix, we will worry about backports and stuff, this is how we do kernel development here.

Quoted 38 lines
Quoted 38 lines

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

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

pci device")

Closes:
https://lore.kernel.org/virtualization/c45dd68698cd47238c55fb73ca9b474
[email protected]/

---
 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

#4 lore raw
Quoted 50 lines

From: Michael S. Tsirkin <[email protected]>
Sent: Wednesday, April 9, 2025 9:32 PM

Quoted 24 lines · Parav Pandit

Hi Michael,

Quoted 22 lines

From: Michael S. Tsirkin <[email protected]>
Sent: Wednesday, April 9, 2025 1:45 AM

Quoted 2 lines · Parav Pandit

This reverts commit 43bb40c5b926 ("virtio_pci: Support surprise removal of

virtio pci device").

Quoted 10 lines

The cited commit introduced a fix that marks the device as broken during surprise removal. However, this approach causes uncompleted I/O requests on virtio-blk device. The presence of uncompleted I/O requests prevents the successful removal of virtio-blk devices.

This fix allows devices that simulate a surprise removal but actually remove gracefully to continue working as before.

For surprise removals, a better solution will be preferred in the future.

Sorry I'm not breaking one thing to fix another. Device is gone so no new requests will be completed. Why not complete all unfinished requests, for example?

Quoted 5 lines
Quoted 2 lines

Come up with a proper fix pls.

I would also like to have a proper fix that can be backportable. However, an attempt [1] had race.
To overcome the race, a different approach also tried, however the block

layer was stuck even if all requests in virtio-blk driver layer was completed like you suggested.

Quoted 2 lines

It appeared that supporting uncompleted requests won't be so

straightforward to backport.

Quoted 3 lines

Hence, the request is to revert and restore the previous behavior. This at least improves the case where the OS thinks that surprise removal

occurred, but the device eventually completes the IO.

Quoted 5 lines

And hence, virtio block driver successfully unloads. And virtio-net also does not experience the mentioned crash.

[1]
https://lore.kernel.org/all/[email protected]/

Quoted 6 lines

Parav this is a commit from 2021. I am not reverting it "because it seems to help". We'll never make progress like this.
You will have to debug and fix it properly. Sorry.

Once we have a fix, we will worry about backports and stuff, this is how we do kernel development here.

Ok. I will post the candidate patch. Will likely need help to fix it. Will ask Stefano. Thanks.