vdpa: allow vdpa dev_del management operation to return failure
Subsystems (5)
PATCH 1/1 vdpa: allow vdpa dev_del management operation to return failure
Currently, the vdpa_nl_cmd_dev_del_set_doit() implementation allows returning a value to depict the operation status but the return type of dev_del() callback is void. So, any error while deleting the vdpa device in the vdpa parent driver can't be returned to the management layer.
This patch changes the return type of dev_del() callback to int to allow returning an error code in case of failure.
--- drivers/vdpa/ifcvf/ifcvf_main.c | 3 ++- drivers/vdpa/mlx5/net/mlx5_vnet.c | 3 ++- drivers/vdpa/vdpa.c | 11 ++++++++--- drivers/vdpa/vdpa_sim/vdpa_sim_blk.c | 3 ++- drivers/vdpa/vdpa_sim/vdpa_sim_net.c | 3 ++- drivers/vdpa/vdpa_user/vduse_dev.c | 3 ++- include/linux/vdpa.h | 5 +++-- 7 files changed, 21 insertions(+), 10 deletions(-)
drivers/vdpa/ifcvf/ifcvf_main.c +2 -1
@@ -800,13 +800,14 @@ static int ifcvf_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,return ret; } -static void ifcvf_vdpa_dev_del (struct vdpa_mgmt_dev *mdev,struct vdpa_device *dev) +static int ifcvf_vdpa_dev_del (struct vdpa_mgmt_dev *mdev,struct vdpa_device *dev) {struct ifcvf_vdpa_mgmt_dev *ifcvf_mgmt_dev; ifcvf_mgmt_dev = container_of(mdev, struct ifcvf_vdpa_mgmt_dev, mdev);_vdpa_unregister_device (dev); ifcvf_mgmt_dev->adapter =NULL ; +return 0 ; }static const struct vdpa_mgmtdev_ops ifcvf_vdpa_mgmt_dev_ops = {
drivers/vdpa/mlx5/net/mlx5_vnet.c +2 -1
@@ -2775,7 +2775,7 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,return err; } -static void mlx5_vdpa_dev_del (struct vdpa_mgmt_dev *v_mdev,struct vdpa_device *dev) +static int mlx5_vdpa_dev_del (struct vdpa_mgmt_dev *v_mdev,struct vdpa_device *dev) { struct mlx5_vdpa_mgmtdev *mgtdev = container_of(v_mdev, struct mlx5_vdpa_mgmtdev, mgtdev);struct mlx5_vdpa_dev *mvdev =to_mvdev (dev);
@@ -2788,6 +2788,7 @@ static void mlx5_vdpa_dev_del(struct vdpa_mgmt_dev *v_mdev, struct vdpa_device *destroy_workqueue (wq);_vdpa_unregister_device (dev); mgtdev->ndev =NULL ; +return 0 ; }static const struct vdpa_mgmtdev_ops mdev_ops = {
drivers/vdpa/vdpa.c +8 -3
@@ -363,10 +363,11 @@ static int vdpa_match_remove(struct device *dev, void *data) { struct vdpa_device *vdev = container_of(dev, struct vdpa_device, dev);struct vdpa_mgmt_dev *mdev = vdev->mdev; +int err =0 ;if (mdev == data) - mdev->ops->dev_del (mdev, vdev); -return 0 ; + err = mdev->ops->dev_del (mdev, vdev); +return err; }void vdpa_mgmtdev_unregister (struct vdpa_mgmt_dev *mdev)
@@ -673,7 +674,11 @@ static int vdpa_nl_cmd_dev_del_set_doit(struct sk_buff *skb, struct genl_info *i goto mdev_err; } mdev = vdev->mdev; - mdev->ops->dev_del (mdev, vdev); + err = mdev->ops->dev_del (mdev, vdev); +if (err) { +NL_SET_ERR_MSG_MOD (info->extack,"ops->dev_del failed" ); + goto dev_err; + } mdev_err:put_device (dev); dev_err:
drivers/vdpa/vdpa_sim/vdpa_sim_blk.c +2 -1
@@ -280,12 +280,13 @@ static int vdpasim_blk_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,return ret; } -static void vdpasim_blk_dev_del (struct vdpa_mgmt_dev *mdev, +static int vdpasim_blk_dev_del (struct vdpa_mgmt_dev *mdev,struct vdpa_device *dev) { struct vdpasim *simdev = container_of(dev, struct vdpasim, vdpa);_vdpa_unregister_device (&simdev->vdpa); +return 0 ; }static const struct vdpa_mgmtdev_ops vdpasim_blk_mgmtdev_ops = {
drivers/vdpa/vdpa_sim/vdpa_sim_net.c +2 -1
@@ -167,12 +167,13 @@ static int vdpasim_net_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,return ret; } -static void vdpasim_net_dev_del (struct vdpa_mgmt_dev *mdev, +static int vdpasim_net_dev_del (struct vdpa_mgmt_dev *mdev,struct vdpa_device *dev) { struct vdpasim *simdev = container_of(dev, struct vdpasim, vdpa);_vdpa_unregister_device (&simdev->vdpa); +return 0 ; }static const struct vdpa_mgmtdev_ops vdpasim_net_mgmtdev_ops = {
drivers/vdpa/vdpa_user/vduse_dev.c +2 -1
@@ -1540,9 +1540,10 @@ static int vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,return 0 ; } -static void vdpa_dev_del (struct vdpa_mgmt_dev *mdev,struct vdpa_device *dev) +static int vdpa_dev_del (struct vdpa_mgmt_dev *mdev,struct vdpa_device *dev) {_vdpa_unregister_device (dev); +return 0 ; }static const struct vdpa_mgmtdev_ops vdpa_dev_mgmtdev_ops = {
include/linux/vdpa.h +3 -2
@@ -443,12 +443,13 @@ void vdpa_set_status(struct vdpa_device *vdev, u8 status);* @mdev: parent device to use for device removal * @dev: vdpa device to remove * Driver need to remove the specified device by calling -* _vdpa_unregister_device(). +* _vdpa_unregister_device(). Driver must return 0 +* on success or appropriate error code in failure case. */ struct vdpa_mgmtdev_ops {int (*dev_add)(struct vdpa_mgmt_dev *mdev,const char *name,const struct vdpa_dev_set_config *config); -void (*dev_del)(struct vdpa_mgmt_dev *mdev,struct vdpa_device *dev); +int (*dev_del)(struct vdpa_mgmt_dev *mdev,struct vdpa_device *dev); };/**
Signature · 1 line
2.30.1
Quoted 18 lines
From: Gautam Dawar <[email protected]>
Sent: Friday, June 3, 2022 1:34 PM
To: [email protected]
Cc: [email protected]; [email protected]; Gautam Dawar <[email protected]>; Michael S. Tsirkin <[email protected]>; Jason Wang <[email protected]>; Zhu Lingshan <[email protected]>; Xie Yongji <[email protected]>; Eli Cohen <[email protected]>; Parav Pandit <[email protected]>; Si-Wei Liu <[email protected]>; Stefano Garzarella <[email protected]>; Wan Jiabing <[email protected]>; Dan Carpenter <[email protected]>; [email protected]; [email protected]
Subject: [PATCH] vdpa: allow vdpadev_delmanagement operation to return failureCurrently, the
vdpa_nl_cmd_dev_del_set_doit()implementation allows returning a value to depict the operation status but the return type ofdev_del()callback is void. So, any error while deleting the vdpa device in the vdpa parent driver can't be returned to the management layer.
This patch changes the return type ofdev_del()callback to int to allow returning an error code in case of failure.
Quoted 2 lines
Signed-off-by Gautam Dawar <[email protected]>---
This patch is not changing anything except for planning on some future device returning error upon delete. Until that happens I don't see much reason for making this change.
Quoted 157 lines
drivers/vdpa/ifcvf/ifcvf_main.c | 3 ++- drivers/vdpa/mlx5/net/mlx5_vnet.c | 3 ++- drivers/vdpa/vdpa.c | 11 ++++++++--- drivers/vdpa/vdpa_sim/vdpa_sim_blk.c | 3 ++- drivers/vdpa/vdpa_sim/vdpa_sim_net.c | 3 ++- drivers/vdpa/vdpa_user/vduse_dev.c | 3 ++- include/linux/vdpa.h | 5 +++-- 7 files changed, 21 insertions(+), 10 deletions(-)drivers/vdpa/ifcvf/ifcvf_main.c +2
-1@@ -800,13 +800,14 @@ static int ifcvf_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,return ret; } -static void ifcvf_vdpa_dev_del (struct vdpa_mgmt_dev *mdev,struct vdpa_device *dev) +static int ifcvf_vdpa_dev_del (struct vdpa_mgmt_dev *mdev,struct vdpa_device *dev) {struct ifcvf_vdpa_mgmt_dev *ifcvf_mgmt_dev; ifcvf_mgmt_dev = container_of(mdev, struct ifcvf_vdpa_mgmt_dev, mdev);_vdpa_unregister_device (dev); ifcvf_mgmt_dev->adapter =NULL ; +return 0 ; }static const struct vdpa_mgmtdev_ops ifcvf_vdpa_mgmt_dev_ops = {drivers/vdpa/mlx5/net/mlx5_vnet.c +2
-1@@ -2775,7 +2775,7 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,return err; } -static void mlx5_vdpa_dev_del (struct vdpa_mgmt_dev *v_mdev,struct vdpa_device *dev) +static int mlx5_vdpa_dev_del (struct vdpa_mgmt_dev *v_mdev,struct vdpa_device *dev) { struct mlx5_vdpa_mgmtdev *mgtdev = container_of(v_mdev, struct mlx5_vdpa_mgmtdev, mgtdev);struct mlx5_vdpa_dev *mvdev =to_mvdev (dev);@@ -2788,6 +2788,7 @@ static void mlx5_vdpa_dev_del(struct vdpa_mgmt_dev *v_mdev, struct vdpa_device *destroy_workqueue (wq);_vdpa_unregister_device (dev); mgtdev->ndev =NULL ; +return 0 ; }static const struct vdpa_mgmtdev_ops mdev_ops = {drivers/vdpa/vdpa.c +8
-3@@ -363,10 +363,11 @@ static int vdpa_match_remove(struct device *dev, void *data) { struct vdpa_device *vdev = container_of(dev, struct vdpa_device, dev);struct vdpa_mgmt_dev *mdev = vdev->mdev; +int err =0 ;if (mdev == data) - mdev->ops->dev_del (mdev, vdev); -return 0 ; + err = mdev->ops->dev_del (mdev, vdev); +return err; }void vdpa_mgmtdev_unregister (struct vdpa_mgmt_dev *mdev)@@ -673,7 +674,11 @@ static int vdpa_nl_cmd_dev_del_set_doit(struct sk_buff *skb, struct genl_info *i goto mdev_err; } mdev = vdev->mdev; - mdev->ops->dev_del (mdev, vdev); + err = mdev->ops->dev_del (mdev, vdev); +if (err) { +NL_SET_ERR_MSG_MOD (info->extack,"ops->dev_del failed" ); + goto dev_err; + } mdev_err:put_device (dev); dev_err:drivers/vdpa/vdpa_sim/vdpa_sim_blk.c +2
-1@@ -280,12 +280,13 @@ static int vdpasim_blk_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,return ret; } -static void vdpasim_blk_dev_del (struct vdpa_mgmt_dev *mdev, +static int vdpasim_blk_dev_del (struct vdpa_mgmt_dev *mdev,struct vdpa_device *dev) { struct vdpasim *simdev = container_of(dev, struct vdpasim, vdpa);_vdpa_unregister_device (&simdev->vdpa); +return 0 ; }static const struct vdpa_mgmtdev_ops vdpasim_blk_mgmtdev_ops = {drivers/vdpa/vdpa_sim/vdpa_sim_net.c +2
-1@@ -167,12 +167,13 @@ static int vdpasim_net_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,return ret; } -static void vdpasim_net_dev_del (struct vdpa_mgmt_dev *mdev, +static int vdpasim_net_dev_del (struct vdpa_mgmt_dev *mdev,struct vdpa_device *dev) { struct vdpasim *simdev = container_of(dev, struct vdpasim, vdpa);_vdpa_unregister_device (&simdev->vdpa); +return 0 ; }static const struct vdpa_mgmtdev_ops vdpasim_net_mgmtdev_ops = {drivers/vdpa/vdpa_user/vduse_dev.c +2
-1@@ -1540,9 +1540,10 @@ static int vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,return 0 ; } -static void vdpa_dev_del (struct vdpa_mgmt_dev *mdev,struct vdpa_device *dev) +static int vdpa_dev_del (struct vdpa_mgmt_dev *mdev,struct vdpa_device *dev) {_vdpa_unregister_device (dev); +return 0 ; }static const struct vdpa_mgmtdev_ops vdpa_dev_mgmtdev_ops = {include/linux/vdpa.h +3
-3@@ -443,12 +443,13 @@ void vdpa_set_status(struct vdpa_device *vdev, u8 status);* @mdev: parent device to use for device removal * @dev: vdpa device to remove * Driver need to remove the specified device by calling -* _vdpa_unregister_device(). +* _vdpa_unregister_device(). Driver must return 0 +* on success or appropriate error code in failure case. */ struct vdpa_mgmtdev_ops {int (*dev_add)(struct vdpa_mgmt_dev *mdev,const char *name,const struct vdpa_dev_set_config *config); -void (*dev_del)(struct vdpa_mgmt_dev *mdev,struct vdpa_device *dev); +int (*dev_del)(struct vdpa_mgmt_dev *mdev,struct vdpa_device *dev); };/** -- 2.30.1
Hi Gautam:
Quoted 6 lines · Gautam Dawar
Currently, the
vdpa_nl_cmd_dev_del_set_doit()implementation allows returning a value to depict the operation status but the return type ofdev_del()callback is void. So, any error while deleting the vdpa device in the vdpa parent driver can't be returned to the management layer.
I wonder under which cognition we can hit an error in dev_del()?
Thanks
Quoted 161 lines
This patch changes the return type of
dev_del()callback to int to allow returning an error code in case of failure.Signed-off-by Gautam Dawar <[email protected]>--- drivers/vdpa/ifcvf/ifcvf_main.c | 3 ++- drivers/vdpa/mlx5/net/mlx5_vnet.c | 3 ++- drivers/vdpa/vdpa.c | 11 ++++++++--- drivers/vdpa/vdpa_sim/vdpa_sim_blk.c | 3 ++- drivers/vdpa/vdpa_sim/vdpa_sim_net.c | 3 ++- drivers/vdpa/vdpa_user/vduse_dev.c | 3 ++- include/linux/vdpa.h | 5 +++-- 7 files changed, 21 insertions(+), 10 deletions(-)drivers/vdpa/ifcvf/ifcvf_main.c +2
-1@@ -800,13 +800,14 @@ static int ifcvf_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,return ret; } -static void ifcvf_vdpa_dev_del (struct vdpa_mgmt_dev *mdev,struct vdpa_device *dev) +static int ifcvf_vdpa_dev_del (struct vdpa_mgmt_dev *mdev,struct vdpa_device *dev) {struct ifcvf_vdpa_mgmt_dev *ifcvf_mgmt_dev; ifcvf_mgmt_dev = container_of(mdev, struct ifcvf_vdpa_mgmt_dev, mdev);_vdpa_unregister_device (dev); ifcvf_mgmt_dev->adapter =NULL ; +return 0 ; }static const struct vdpa_mgmtdev_ops ifcvf_vdpa_mgmt_dev_ops = {drivers/vdpa/mlx5/net/mlx5_vnet.c +2
-1@@ -2775,7 +2775,7 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,return err; } -static void mlx5_vdpa_dev_del (struct vdpa_mgmt_dev *v_mdev,struct vdpa_device *dev) +static int mlx5_vdpa_dev_del (struct vdpa_mgmt_dev *v_mdev,struct vdpa_device *dev) { struct mlx5_vdpa_mgmtdev *mgtdev = container_of(v_mdev, struct mlx5_vdpa_mgmtdev, mgtdev);struct mlx5_vdpa_dev *mvdev =to_mvdev (dev);@@ -2788,6 +2788,7 @@ static void mlx5_vdpa_dev_del(struct vdpa_mgmt_dev *v_mdev, struct vdpa_device *destroy_workqueue (wq);_vdpa_unregister_device (dev); mgtdev->ndev =NULL ; +return 0 ; }static const struct vdpa_mgmtdev_ops mdev_ops = {drivers/vdpa/vdpa.c +8
-3@@ -363,10 +363,11 @@ static int vdpa_match_remove(struct device *dev, void *data) { struct vdpa_device *vdev = container_of(dev, struct vdpa_device, dev);struct vdpa_mgmt_dev *mdev = vdev->mdev; +int err =0 ;if (mdev == data) - mdev->ops->dev_del (mdev, vdev); -return 0 ; + err = mdev->ops->dev_del (mdev, vdev); +return err; }void vdpa_mgmtdev_unregister (struct vdpa_mgmt_dev *mdev)@@ -673,7 +674,11 @@ static int vdpa_nl_cmd_dev_del_set_doit(struct sk_buff *skb, struct genl_info *i goto mdev_err; } mdev = vdev->mdev; - mdev->ops->dev_del (mdev, vdev); + err = mdev->ops->dev_del (mdev, vdev); +if (err) { +NL_SET_ERR_MSG_MOD (info->extack,"ops->dev_del failed" ); + goto dev_err; + } mdev_err:put_device (dev); dev_err:drivers/vdpa/vdpa_sim/vdpa_sim_blk.c +2
-1@@ -280,12 +280,13 @@ static int vdpasim_blk_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,return ret; } -static void vdpasim_blk_dev_del (struct vdpa_mgmt_dev *mdev, +static int vdpasim_blk_dev_del (struct vdpa_mgmt_dev *mdev,struct vdpa_device *dev) { struct vdpasim *simdev = container_of(dev, struct vdpasim, vdpa);_vdpa_unregister_device (&simdev->vdpa); +return 0 ; }static const struct vdpa_mgmtdev_ops vdpasim_blk_mgmtdev_ops = {drivers/vdpa/vdpa_sim/vdpa_sim_net.c +2
-1@@ -167,12 +167,13 @@ static int vdpasim_net_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,return ret; } -static void vdpasim_net_dev_del (struct vdpa_mgmt_dev *mdev, +static int vdpasim_net_dev_del (struct vdpa_mgmt_dev *mdev,struct vdpa_device *dev) { struct vdpasim *simdev = container_of(dev, struct vdpasim, vdpa);_vdpa_unregister_device (&simdev->vdpa); +return 0 ; }static const struct vdpa_mgmtdev_ops vdpasim_net_mgmtdev_ops = {drivers/vdpa/vdpa_user/vduse_dev.c +2
-1@@ -1540,9 +1540,10 @@ static int vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,return 0 ; } -static void vdpa_dev_del (struct vdpa_mgmt_dev *mdev,struct vdpa_device *dev) +static int vdpa_dev_del (struct vdpa_mgmt_dev *mdev,struct vdpa_device *dev) {_vdpa_unregister_device (dev); +return 0 ; }static const struct vdpa_mgmtdev_ops vdpa_dev_mgmtdev_ops = {include/linux/vdpa.h +3
-3@@ -443,12 +443,13 @@ void vdpa_set_status(struct vdpa_device *vdev, u8 status);* @mdev: parent device to use for device removal * @dev: vdpa device to remove * Driver need to remove the specified device by calling -* _vdpa_unregister_device(). +* _vdpa_unregister_device(). Driver must return 0 +* on success or appropriate error code in failure case. */ struct vdpa_mgmtdev_ops {int (*dev_add)(struct vdpa_mgmt_dev *mdev,const char *name,const struct vdpa_dev_set_config *config); -void (*dev_del)(struct vdpa_mgmt_dev *mdev,struct vdpa_device *dev); +int (*dev_del)(struct vdpa_mgmt_dev *mdev,struct vdpa_device *dev); };/** --
Quoted 2 lines
2.30.1
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
[AMD Official Use Only - General]
Hi Gautam:
[GD>>] Hi Jason,
Quoted 6 lines · Gautam Dawar
Currently, the
vdpa_nl_cmd_dev_del_set_doit()implementation allows returning a value to depict the operation status but the return type ofdev_del()callback is void. So, any error while deleting the vdpa device in the vdpa parent driver can't be returned to the management layer.
I wonder under which cognition we can hit an error in dev_del()?
[GD>>] In the AMD-Xilinx vDPA driver, on receiving vdpa device deletion request, I try to identify if the vdpa device is in use by any virtio-net driver (through any vdpa bus driver) by looking at the vdpa device status value. In case the vdpa device status is >= VIRTIO_CONFIG_S_DRIVER, -EBUSY is returned. This is to avoid side-effects as noted in https://bugzilla.kernel.org/show_bug.cgi?id=213179 caused by deleting the vdpa device when it is being used.
Quoted 1 line
Thanks
Quoted 175 lines
This patch changes the return type of
dev_del()callback to int to allow returning an error code in case of failure.Signed-off-by Gautam Dawar <[email protected]>--- drivers/vdpa/ifcvf/ifcvf_main.c | 3 ++- drivers/vdpa/mlx5/net/mlx5_vnet.c | 3 ++- drivers/vdpa/vdpa.c | 11 ++++++++--- drivers/vdpa/vdpa_sim/vdpa_sim_blk.c | 3 ++- drivers/vdpa/vdpa_sim/vdpa_sim_net.c | 3 ++- drivers/vdpa/vdpa_user/vduse_dev.c | 3 ++- include/linux/vdpa.h | 5 +++-- 7 files changed, 21 insertions(+), 10 deletions(-)(quoted diff) +0
-0
b/drivers/vdpa/ifcvf/ifcvf_main.cindex4366320fb68d..6a967935478b100644drivers/vdpa/ifcvf/ifcvf_main.c +3
-2@@ -800,13 +800,14 @@ static int ifcvf_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,return ret; } -static void ifcvf_vdpa_dev_del (struct vdpa_mgmt_dev *mdev,struct vdpa_device *dev) +static int ifcvf_vdpa_dev_del (struct vdpa_mgmt_dev *mdev,struct +vdpa_device *dev) {struct ifcvf_vdpa_mgmt_dev *ifcvf_mgmt_dev; ifcvf_mgmt_dev = container_of(mdev, struct ifcvf_vdpa_mgmt_dev, mdev);_vdpa_unregister_device (dev); ifcvf_mgmt_dev->adapter =NULL ; +return 0 ; }static const struct vdpa_mgmtdev_ops ifcvf_vdpa_mgmt_dev_ops = { diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c
b/drivers/vdpa/mlx5/net/mlx5_vnet.c
indexe0de44000d92..b06204c2f3e8100644drivers/vdpa/mlx5/net/mlx5_vnet.c +4
-1@@ -2775,7 +2775,7 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,return err; } -static void mlx5_vdpa_dev_del (struct vdpa_mgmt_dev *v_mdev,struct vdpa_device *dev) +static int mlx5_vdpa_dev_del (struct vdpa_mgmt_dev *v_mdev,struct +vdpa_device *dev) { struct mlx5_vdpa_mgmtdev *mgtdev = container_of(v_mdev, struct mlx5_vdpa_mgmtdev, mgtdev); struct mlx5_vdpa_dev *mvdev = to_mvdev(dev); @@ -2788,6 +2788,7 @@ static void mlx5_vdpa_dev_del(struct vdpa_mgmt_dev *v_mdev, struct vdpa_device * destroy_workqueue(wq);_vdpa_unregister_device (dev); mgtdev->ndev =NULL ; +return 0 ; } static const struct vdpa_mgmtdev_ops mdev_ops = { diff --git
a/drivers/vdpa/vdpa.cb/drivers/vdpa/vdpa.cindex2b75c00b1005..65dc8bf2f37f100644drivers/vdpa/vdpa.c +9
-3@@ -363,10 +363,11 @@ static int vdpa_match_remove(struct device *dev, void *data) { struct vdpa_device *vdev = container_of(dev, struct vdpa_device, dev);struct vdpa_mgmt_dev *mdev = vdev->mdev; +int err =0 ;if (mdev == data) - mdev->ops->dev_del (mdev, vdev); -return 0 ; + err = mdev->ops->dev_del (mdev, vdev); +return err; } void vdpa_mgmtdev_unregister(struct vdpa_mgmt_dev *mdev) @@ -673,7 +674,11 @@ static int vdpa_nl_cmd_dev_del_set_doit(struct sk_buff *skb, struct genl_info *i goto mdev_err; } mdev = vdev->mdev; - mdev->ops->dev_del (mdev, vdev); + err = mdev->ops->dev_del (mdev, vdev); +if (err) { +NL_SET_ERR_MSG_MOD (info->extack,"ops->dev_del failed" ); + goto dev_err; + } mdev_err:put_device (dev); dev_err:drivers/vdpa/vdpa_sim/vdpa_sim_blk.c +2
-2@@ -280,12 +280,13 @@ static int vdpasim_blk_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,return ret; } -static void vdpasim_blk_dev_del (struct vdpa_mgmt_dev *mdev, +static int vdpasim_blk_dev_del (struct vdpa_mgmt_dev *mdev,struct vdpa_device *dev) { struct vdpasim *simdev = container_of(dev, struct vdpasim, vdpa);_vdpa_unregister_device (&simdev->vdpa); +return 0 ; }static const struct vdpa_mgmtdev_ops vdpasim_blk_mgmtdev_ops = { diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim_net.c
b/drivers/vdpa/vdpa_sim/vdpa_sim_net.c
indexd5324f6fd8c7..9e5a5ad34e65100644drivers/vdpa/vdpa_sim/vdpa_sim_net.c +2
-2@@ -167,12 +167,13 @@ static int vdpasim_net_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,return ret; } -static void vdpasim_net_dev_del (struct vdpa_mgmt_dev *mdev, +static int vdpasim_net_dev_del (struct vdpa_mgmt_dev *mdev,struct vdpa_device *dev) { struct vdpasim *simdev = container_of(dev, struct vdpasim, vdpa);_vdpa_unregister_device (&simdev->vdpa); +return 0 ; }static const struct vdpa_mgmtdev_ops vdpasim_net_mgmtdev_ops = { diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c
b/drivers/vdpa/vdpa_user/vduse_dev.c
indexf85d1a08ed87..33ff45e70ff7100644drivers/vdpa/vdpa_user/vduse_dev.c +3
-2@@ -1540,9 +1540,10 @@ static int vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,return 0 ; } -static void vdpa_dev_del (struct vdpa_mgmt_dev *mdev,struct vdpa_device *dev) +static int vdpa_dev_del (struct vdpa_mgmt_dev *mdev,struct +vdpa_device *dev) {_vdpa_unregister_device (dev); +return 0 ; }static const struct vdpa_mgmtdev_ops vdpa_dev_mgmtdev_ops = { diff --git a/include/linux/vdpa.h b/include/linux/vdpa.h index
8943a209202e..e547c9dfdfce100644include/linux/vdpa.h +4
-3@@ -443,12 +443,13 @@ void vdpa_set_status(struct vdpa_device *vdev, u8 status);* @mdev: parent device to use for device removal * @dev: vdpa device to remove * Driver need to remove the specified device by calling -* _vdpa_unregister_device(). +* _vdpa_unregister_device(). Driver must return 0 +* on success or appropriate error code in failure case. */ struct vdpa_mgmtdev_ops {int (*dev_add)(struct vdpa_mgmt_dev *mdev,const char *name,const struct vdpa_dev_set_config *config); -void (*dev_del)(struct vdpa_mgmt_dev *mdev,struct vdpa_device *dev); +int (*dev_del)(struct vdpa_mgmt_dev *mdev,struct vdpa_device + *dev); };/** -- 2.30.1
Quoted 30 lines
From: Dawar, Gautam <[email protected]>
Sent: Wednesday, June 8, 2022 6:30 AM
To: Jason Wang <[email protected]>
Cc: netdev <[email protected]>; linux-net-drivers (AMD-Xilinx) <linux- [email protected]>; Anand, Harpreet <[email protected]>; Michael S. Tsirkin <[email protected]>; Zhu Lingshan <[email protected]>; Xie Yongji <[email protected]>; Eli Cohen <[email protected]>; Parav Pandit <[email protected]>; Si-Wei Liu <si- [email protected]>; Stefano Garzarella <[email protected]>; Wan Jiabing <[email protected]>; Dan Carpenter <[email protected]>; virtualization <[email protected] foundation.org>; linux-kernel <[email protected]>
Subject: RE: [PATCH] vdpa: allow vdpadev_delmanagement operation to return failure[AMD Official Use Only - General]
Hi Gautam:
[GD>>] Hi Jason,Quoted 6 lines · Gautam Dawar
Currently, the
vdpa_nl_cmd_dev_del_set_doit()implementation allows returning a value to depict the operation status but the return type ofdev_del()callback is void. So, any error while deleting the vdpa device in the vdpa parent driver can't be returned to the management layer.
Quoted 10 lines
I wonder under which cognition we can hit an error in
dev_del()? [GD>>] In the AMD-Xilinx vDPA driver, on receiving vdpa device deletion request, I try to identify if the vdpa device is in use by any virtio-net driver (through any vdpa bus driver) by looking at the vdpa device status value. In case the vdpa device status is >=VIRTIO_CONFIG_S_DRIVER,-EBUSYis returned.
This is to avoid side-effects as noted in
https://bugzilla.kernel.org/show_bug.cgi?id=213179 caused by deleting the vdpa device when it is being used.Quoted 1 line
User should be able to delete the device anytime.
Upper layers who are unable to perform teardown sequence should be fixed.
_______________________________________________
Virtualization mailing list [email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Quoted 41 lines · Parav Pandit
Quoted 31 lines
From: Dawar, Gautam <[email protected]>
Sent: Wednesday, June 8, 2022 6:30 AM
To: Jason Wang <[email protected]>
Cc: netdev <[email protected]>; linux-net-drivers (AMD-Xilinx) <linux- [email protected]>; Anand, Harpreet <[email protected]>; Michael S. Tsirkin <[email protected]>; Zhu Lingshan <[email protected]>; Xie Yongji <[email protected]>; Eli Cohen <[email protected]>; Parav Pandit <[email protected]>; Si-Wei Liu <si- [email protected]>; Stefano Garzarella <[email protected]>; Wan Jiabing <[email protected]>; Dan Carpenter <[email protected]>; virtualization <[email protected] foundation.org>; linux-kernel <[email protected]>
Subject: RE: [PATCH] vdpa: allow vdpadev_delmanagement operation to return failure[AMD Official Use Only - General]
Hi Gautam:
[GD>>] Hi Jason,Quoted 6 lines · Gautam Dawar
Currently, the
vdpa_nl_cmd_dev_del_set_doit()implementation allows returning a value to depict the operation status but the return type ofdev_del()callback is void. So, any error while deleting the vdpa device in the vdpa parent driver can't be returned to the management layer.Quoted 10 lines
I wonder under which cognition we can hit an error in
dev_del()? [GD>>] In the AMD-Xilinx vDPA driver, on receiving vdpa device deletion request, I try to identify if the vdpa device is in use by any virtio-net driver (through any vdpa bus driver) by looking at the vdpa device status value. In case the vdpa device status is >=VIRTIO_CONFIG_S_DRIVER,-EBUSYis returned.
This is to avoid side-effects as noted in
https://bugzilla.kernel.org/show_bug.cgi?id=213179 caused by deleting the vdpa device when it is being used.Quoted 1 line
Quoted 1 line
User should be able to delete the device anytime.
It requires a poll event to user space and then Qemu can release the vhost-vDPA device. This is how VFIO works. We probably need to implement something like this.
But notice that, at the worst case, usersapce may not respond to this event, so there's nothing more kenrel can do execpt for waiting.
We need to consider something different. I used to have an idea to make vhost-vdpa couple with vDPA loosely with SRCU/RCU. We might consider implementing that.
Quoted 1 line
Upper layers who are unable to perform teardown sequence should be fixed.
I think we probably don't need to bother with failing the dev_del(). We can consider to fix/workaround the waiting first.
Thanks
Quoted 4 lines
From: Jason Wang <[email protected]>
Sent: Thursday, June 9, 2022 3:19 AM
[..]
Quoted 10 lines
Quoted 5 lines
Quoted 4 lines
This is to avoid side-effects as noted in
https://bugzilla.kernel.org/show_bug.cgi?id=213179 caused by deleting the vdpa device when it is being used.Quoted 1 line
User should be able to delete the device anytime.
It requires a poll event to user space and then Qemu can release the vhost- vDPA device. This is how VFIO works. We probably need to implement something like this.
Yes, I remember hang with either vfio or vfio-mdev.
Quoted 7 lines
But notice that, at the worst case, usersapce may not respond to this event, so there's nothing more kenrel can do execpt for waiting.
We need to consider something different. I used to have an idea to make vhost-vdpa couple with vDPA loosely with SRCU/RCU. We might consider implementing that.
Right. It needs a different solution. As you described, vhost-vdpa cannot rely on the user space involvement in freeing. Rdma uverbs does that for device removal cases to detach the user space ioctl() context with low level device.
Quoted 6 lines
Quoted 1 line
Upper layers who are unable to perform teardown sequence should be
fixed.
I think we probably don't need to bother with failing the
dev_del(). We can consider to fix/workaround the waiting first.
Lets fix it as you hinted with S/RCU.
We don’t need to add UAPI for the fix.
UAPI anyway doesn’t work, when driver/system level event occurs such as device fatal error, sriov disablement, sf removal and more. Vhost-vdpa should be able to detach it from the underlying device.