vdpa/ifcvf: Time out and report device reset failure
Subsystems (2)
RFC PATCH 1/1 vdpa/ifcvf: Time out and report device reset failure
ifcvf_reset() writes 0 to device_status and polls it without a bound, and ifcvf_vdpa_reset() always returns 0. A device that does not finish the reset, or one that was surprise-removed and reads back 0xff, keeps the caller in the reset path forever.
Bound the poll with readx_poll_timeout() and return -ETIMEDOUT from .reset, so that callers such as VHOST_VDPA_SET_STATUS(0) see the failure instead of hanging. Stop right away with -ENODEV once the device reads back all ones and is no longer present, as there is nothing left to wait for.
---
RFC for two reasons:
- The spec gives no bound for a reset; 10 seconds follows octeon_ep's OCTEP_HW_TIMEOUT.
- vhost_vdpa_release() ignores a reset failure and still tears the mappings down, so on close a timeout turns a hang into teardown while the device may still be active. That needs a separate fix in vhost-vdpa.
Compile-tested only (x86_64 defconfig + IFCVF, W=1).
drivers/vdpa/ifcvf/ifcvf_base.c | 24 +++++++++++++++++++++--- drivers/vdpa/ifcvf/ifcvf_base.h | 3 ++- drivers/vdpa/ifcvf/ifcvf_main.c | 4 +--- 3 files changed, 24 insertions(+), 7 deletions(-)
drivers/vdpa/ifcvf/ifcvf_base.c +21 -3
@@ -8,6 +8,8 @@* */ +#include <linux/iopoll.h> +#include "ifcvf_base.h" u16 ifcvf_set_vq_vector (struct ifcvf_hw *hw,u16 qid,int vector)
@@ -201,11 +203,27 @@ void ifcvf_set_status(struct ifcvf_hw *hw, u8 status)vp_iowrite8 (status, &hw->common_cfg->device_status); } -void ifcvf_reset (struct ifcvf_hw *hw) +static bool ifcvf_reset_done (struct ifcvf_hw *hw,u8 status) { +/* A surprise-removed device reads back all ones and never resets */ +return !status || (status ==0xff && !pci_device_is_present (hw->pdev)); +} + +int ifcvf_reset (struct ifcvf_hw *hw) +{ +u8 status; +int ret; +ifcvf_set_status (hw,0 ); -while (ifcvf_get_status (hw)) -msleep (1 ); + ret =readx_poll_timeout (ifcvf_get_status, hw, status, +ifcvf_reset_done (hw, status), +1000 ,IFCVF_RESET_TIMEOUT_US ); +if (ret) { +IFCVF_ERR (hw->pdev,"timed out waiting for device reset\n" ); +return ret; + } + +return status ? -ENODEV :0 ; }u64 ifcvf_get_hw_features (struct ifcvf_hw *hw)
drivers/vdpa/ifcvf/ifcvf_base.h +2 -1
@@ -29,6 +29,7 @@#define IFCVF_LM_BAR 4#define IFCVF_MIN_VQ_SIZE 64 +#define IFCVF_RESET_TIMEOUT_US (10 * USEC_PER_SEC)#define IFCVF_ERR (pdev, fmt, ...) dev_err(&pdev->dev, fmt, ##__VA_ARGS__)#define IFCVF_DBG (pdev, fmt, ...) dev_dbg(&pdev->dev, fmt, ##__VA_ARGS__)
@@ -112,7 +113,7 @@ void ifcvf_write_dev_config(struct ifcvf_hw *hw, u64 offset, const void *src, int length);u8 ifcvf_get_status (struct ifcvf_hw *hw);void ifcvf_set_status (struct ifcvf_hw *hw,u8 status); -void ifcvf_reset (struct ifcvf_hw *hw); +int ifcvf_reset (struct ifcvf_hw *hw);u64 ifcvf_get_dev_features (struct ifcvf_hw *hw);u64 ifcvf_get_hw_features (struct ifcvf_hw *hw);int ifcvf_verify_min_features (struct ifcvf_hw *hw,u64 features);
drivers/vdpa/ifcvf/ifcvf_main.c +1 -3
@@ -444,9 +444,7 @@ static int ifcvf_vdpa_reset(struct vdpa_device *vdpa_dev)if (status &VIRTIO_CONFIG_S_DRIVER_OK )ifcvf_free_irq (vf); -ifcvf_reset (vf); - -return 0 ; +return ifcvf_reset (vf); }static u16 ifcvf_vdpa_get_vq_num_max (struct vdpa_device *vdpa_dev)
base-commit: 551c722f40809618230001baccf219193e22fc5a
Signature · 1 line
2.43.0
[email protected]
AI reviewSashiko has reviewed this patch and found no issues. It looks great!
Quoted 5 lines
ifcvf_reset()writes 0 todevice_statusand polls it without a bound, andifcvf_vdpa_reset()always returns 0. A device that does not finish the reset, or one that was surprise-removed and reads back0xff, keeps the caller in the reset path forever.
Quoted 8 lines
Bound the poll with
readx_poll_timeout()and return-ETIMEDOUTfrom .reset, so that callers such asVHOST_VDPA_SET_STATUS(0)see the failure instead of hanging. Stop right away with-ENODEVonce the device reads back all ones and is no longer present, as there is nothing left to wait for.Fixes 386a26208524 ("vDPA/ifcvf: synchronize irqs in the reset routine")Signed-off-by Yuho Choi <[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
Michael S. Tsirkin
maintainerQuoted 8 lines · Yuho Choi
ifcvf_reset()writes 0 todevice_statusand polls it without a bound, andifcvf_vdpa_reset()always returns 0. A device that does not finish the reset, or one that was surprise-removed and reads back0xff, keeps the caller in the reset path forever.Bound the poll with
readx_poll_timeout()and return-ETIMEDOUTfrom .reset, so that callers such asVHOST_VDPA_SET_STATUS(0)see the failure instead of hanging.
No one handles reset errors. You can not timeout this.
Quoted 6 lines
Stop right away with
-ENODEVonce the device reads
back all ones and is no longer present, as there is nothing left to wait for.Fixes 386a26208524 ("vDPA/ifcvf: synchronize irqs in the reset routine")Signed-off-by Yuho Choi <[email protected]>
Use standard is present APIs not "all ones" hacks.
Quoted 100 lines
---
RFC for two reasons:
- The spec gives no bound for a reset; 10 seconds follows octeon_ep'sOCTEP_HW_TIMEOUT.
-vhost_vdpa_release()ignores a reset failure and still tears the mappings down, so on close a timeout turns a hang into teardown while the device may still be active. That needs a separate fix in vhost-vdpa.Compile-tested only (
x86_64defconfig + IFCVF, W=1).drivers/vdpa/ifcvf/ifcvf_base.c | 24 +++++++++++++++++++++--- drivers/vdpa/ifcvf/ifcvf_base.h | 3 ++- drivers/vdpa/ifcvf/ifcvf_main.c | 4 +--- 3 files changed, 24 insertions(+), 7 deletions(-)drivers/vdpa/ifcvf/ifcvf_base.c +21
-3@@ -8,6 +8,8 @@* */ +#include <linux/iopoll.h> +#include "ifcvf_base.h" u16 ifcvf_set_vq_vector (struct ifcvf_hw *hw,u16 qid,int vector)@@ -201,11 +203,27 @@ void ifcvf_set_status(struct ifcvf_hw *hw, u8 status)vp_iowrite8 (status, &hw->common_cfg->device_status); } -void ifcvf_reset (struct ifcvf_hw *hw) +static bool ifcvf_reset_done (struct ifcvf_hw *hw,u8 status) { +/* A surprise-removed device reads back all ones and never resets */ +return !status || (status ==0xff && !pci_device_is_present (hw->pdev)); +} + +int ifcvf_reset (struct ifcvf_hw *hw) +{ +u8 status; +int ret; +ifcvf_set_status (hw,0 ); -while (ifcvf_get_status (hw)) -msleep (1 ); + ret =readx_poll_timeout (ifcvf_get_status, hw, status, +ifcvf_reset_done (hw, status), +1000 ,IFCVF_RESET_TIMEOUT_US ); +if (ret) { +IFCVF_ERR (hw->pdev,"timed out waiting for device reset\n" ); +return ret; + } + +return status ? -ENODEV :0 ; }u64 ifcvf_get_hw_features (struct ifcvf_hw *hw)drivers/vdpa/ifcvf/ifcvf_base.h +2
-1@@ -29,6 +29,7 @@#define IFCVF_LM_BAR 4#define IFCVF_MIN_VQ_SIZE 64 +#define IFCVF_RESET_TIMEOUT_US (10 * USEC_PER_SEC)#define IFCVF_ERR (pdev, fmt, ...) dev_err(&pdev->dev, fmt, ##__VA_ARGS__)#define IFCVF_DBG (pdev, fmt, ...) dev_dbg(&pdev->dev, fmt, ##__VA_ARGS__)@@ -112,7 +113,7 @@ void ifcvf_write_dev_config(struct ifcvf_hw *hw, u64 offset, const void *src, int length);u8 ifcvf_get_status (struct ifcvf_hw *hw);void ifcvf_set_status (struct ifcvf_hw *hw,u8 status); -void ifcvf_reset (struct ifcvf_hw *hw); +int ifcvf_reset (struct ifcvf_hw *hw);u64 ifcvf_get_dev_features (struct ifcvf_hw *hw);u64 ifcvf_get_hw_features (struct ifcvf_hw *hw);int ifcvf_verify_min_features (struct ifcvf_hw *hw,u64 features);drivers/vdpa/ifcvf/ifcvf_main.c +1
-3@@ -444,9 +444,7 @@ static int ifcvf_vdpa_reset(struct vdpa_device *vdpa_dev)if (status &VIRTIO_CONFIG_S_DRIVER_OK )ifcvf_free_irq (vf); -ifcvf_reset (vf); - -return 0 ; +return ifcvf_reset (vf); }static u16 ifcvf_vdpa_get_vq_num_max (struct vdpa_device *vdpa_dev)base-commit:
551c722f40809618230001baccf219193e22fc5aSignature · 1 line
2.43.0
Thanks for the review.
Quoted 2 lines · Michael S. Tsirkin
No one handles reset errors. You can not timeout this.
Agreed, returning early lets callers free memory the device may still DMA into.
For a device that is present but never completes the reset, would it be acceptable to fence it instead: pci_clear_master() after a bounded wait, and pci_set_master() only once a later reset completes? .reset would then always return with the device quiet, so caller can keep ignoring the result.
Quoted 1 line
Use standard is present APIs not "all ones" hacks.
Will do, v2 will use the present APIs.
Thanks,
Yuho