Commit 2c473ae7 authored by Hadar Hen Zion's avatar Hadar Hen Zion Committed by David S. Miller

net/mlx4_core: Disallow releasing VF QPs which have steering rules

VF QPs must not be released when they have steering rules attached to them.

For that end, introduce a reference count field to the QP object in the
SRIOV resource tracker which is incremented/decremented when steering rules
are attached/detached to it. QPs can be released by VF only when their
ref count is zero.
Signed-off-by: default avatarHadar Hen Zion <hadarh@mellanox.com>
Signed-off-by: default avatarOr Gerlitz <ogerlitz@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 1e3f7b32
...@@ -99,6 +99,7 @@ struct res_qp { ...@@ -99,6 +99,7 @@ struct res_qp {
struct list_head mcg_list; struct list_head mcg_list;
spinlock_t mcg_spl; spinlock_t mcg_spl;
int local_qpn; int local_qpn;
atomic_t ref_count;
}; };
enum res_mtt_states { enum res_mtt_states {
...@@ -197,6 +198,7 @@ enum res_fs_rule_states { ...@@ -197,6 +198,7 @@ enum res_fs_rule_states {
struct res_fs_rule { struct res_fs_rule {
struct res_common com; struct res_common com;
int qpn;
}; };
static void *res_tracker_lookup(struct rb_root *root, u64 res_id) static void *res_tracker_lookup(struct rb_root *root, u64 res_id)
...@@ -447,6 +449,7 @@ static struct res_common *alloc_qp_tr(int id) ...@@ -447,6 +449,7 @@ static struct res_common *alloc_qp_tr(int id)
ret->local_qpn = id; ret->local_qpn = id;
INIT_LIST_HEAD(&ret->mcg_list); INIT_LIST_HEAD(&ret->mcg_list);
spin_lock_init(&ret->mcg_spl); spin_lock_init(&ret->mcg_spl);
atomic_set(&ret->ref_count, 0);
return &ret->com; return &ret->com;
} }
...@@ -554,7 +557,7 @@ static struct res_common *alloc_xrcdn_tr(int id) ...@@ -554,7 +557,7 @@ static struct res_common *alloc_xrcdn_tr(int id)
return &ret->com; return &ret->com;
} }
static struct res_common *alloc_fs_rule_tr(u64 id) static struct res_common *alloc_fs_rule_tr(u64 id, int qpn)
{ {
struct res_fs_rule *ret; struct res_fs_rule *ret;
...@@ -564,7 +567,7 @@ static struct res_common *alloc_fs_rule_tr(u64 id) ...@@ -564,7 +567,7 @@ static struct res_common *alloc_fs_rule_tr(u64 id)
ret->com.res_id = id; ret->com.res_id = id;
ret->com.state = RES_FS_RULE_ALLOCATED; ret->com.state = RES_FS_RULE_ALLOCATED;
ret->qpn = qpn;
return &ret->com; return &ret->com;
} }
...@@ -602,7 +605,7 @@ static struct res_common *alloc_tr(u64 id, enum mlx4_resource type, int slave, ...@@ -602,7 +605,7 @@ static struct res_common *alloc_tr(u64 id, enum mlx4_resource type, int slave,
ret = alloc_xrcdn_tr(id); ret = alloc_xrcdn_tr(id);
break; break;
case RES_FS_RULE: case RES_FS_RULE:
ret = alloc_fs_rule_tr(id); ret = alloc_fs_rule_tr(id, extra);
break; break;
default: default:
return NULL; return NULL;
...@@ -671,10 +674,14 @@ static int add_res_range(struct mlx4_dev *dev, int slave, u64 base, int count, ...@@ -671,10 +674,14 @@ static int add_res_range(struct mlx4_dev *dev, int slave, u64 base, int count,
static int remove_qp_ok(struct res_qp *res) static int remove_qp_ok(struct res_qp *res)
{ {
if (res->com.state == RES_QP_BUSY) if (res->com.state == RES_QP_BUSY || atomic_read(&res->ref_count) ||
!list_empty(&res->mcg_list)) {
pr_err("resource tracker: fail to remove qp, state %d, ref_count %d\n",
res->com.state, atomic_read(&res->ref_count));
return -EBUSY; return -EBUSY;
else if (res->com.state != RES_QP_RESERVED) } else if (res->com.state != RES_QP_RESERVED) {
return -EPERM; return -EPERM;
}
return 0; return 0;
} }
...@@ -3124,6 +3131,7 @@ int mlx4_QP_FLOW_STEERING_ATTACH_wrapper(struct mlx4_dev *dev, int slave, ...@@ -3124,6 +3131,7 @@ int mlx4_QP_FLOW_STEERING_ATTACH_wrapper(struct mlx4_dev *dev, int slave,
struct list_head *rlist = &tracker->slave_list[slave].res_list[RES_MAC]; struct list_head *rlist = &tracker->slave_list[slave].res_list[RES_MAC];
int err; int err;
int qpn; int qpn;
struct res_qp *rqp;
struct mlx4_net_trans_rule_hw_ctrl *ctrl; struct mlx4_net_trans_rule_hw_ctrl *ctrl;
struct _rule_hw *rule_header; struct _rule_hw *rule_header;
int header_id; int header_id;
...@@ -3134,7 +3142,7 @@ int mlx4_QP_FLOW_STEERING_ATTACH_wrapper(struct mlx4_dev *dev, int slave, ...@@ -3134,7 +3142,7 @@ int mlx4_QP_FLOW_STEERING_ATTACH_wrapper(struct mlx4_dev *dev, int slave,
ctrl = (struct mlx4_net_trans_rule_hw_ctrl *)inbox->buf; ctrl = (struct mlx4_net_trans_rule_hw_ctrl *)inbox->buf;
qpn = be32_to_cpu(ctrl->qpn) & 0xffffff; qpn = be32_to_cpu(ctrl->qpn) & 0xffffff;
err = get_res(dev, slave, qpn, RES_QP, NULL); err = get_res(dev, slave, qpn, RES_QP, &rqp);
if (err) { if (err) {
pr_err("Steering rule with qpn 0x%x rejected.\n", qpn); pr_err("Steering rule with qpn 0x%x rejected.\n", qpn);
return err; return err;
...@@ -3175,14 +3183,16 @@ int mlx4_QP_FLOW_STEERING_ATTACH_wrapper(struct mlx4_dev *dev, int slave, ...@@ -3175,14 +3183,16 @@ int mlx4_QP_FLOW_STEERING_ATTACH_wrapper(struct mlx4_dev *dev, int slave,
if (err) if (err)
goto err_put; goto err_put;
err = add_res_range(dev, slave, vhcr->out_param, 1, RES_FS_RULE, 0); err = add_res_range(dev, slave, vhcr->out_param, 1, RES_FS_RULE, qpn);
if (err) { if (err) {
mlx4_err(dev, "Fail to add flow steering resources.\n "); mlx4_err(dev, "Fail to add flow steering resources.\n ");
/* detach rule*/ /* detach rule*/
mlx4_cmd(dev, vhcr->out_param, 0, 0, mlx4_cmd(dev, vhcr->out_param, 0, 0,
MLX4_QP_FLOW_STEERING_DETACH, MLX4_CMD_TIME_CLASS_A, MLX4_QP_FLOW_STEERING_DETACH, MLX4_CMD_TIME_CLASS_A,
MLX4_CMD_NATIVE); MLX4_CMD_NATIVE);
goto err_put;
} }
atomic_inc(&rqp->ref_count);
err_put: err_put:
put_res(dev, slave, qpn, RES_QP); put_res(dev, slave, qpn, RES_QP);
return err; return err;
...@@ -3195,20 +3205,35 @@ int mlx4_QP_FLOW_STEERING_DETACH_wrapper(struct mlx4_dev *dev, int slave, ...@@ -3195,20 +3205,35 @@ int mlx4_QP_FLOW_STEERING_DETACH_wrapper(struct mlx4_dev *dev, int slave,
struct mlx4_cmd_info *cmd) struct mlx4_cmd_info *cmd)
{ {
int err; int err;
struct res_qp *rqp;
struct res_fs_rule *rrule;
if (dev->caps.steering_mode != if (dev->caps.steering_mode !=
MLX4_STEERING_MODE_DEVICE_MANAGED) MLX4_STEERING_MODE_DEVICE_MANAGED)
return -EOPNOTSUPP; return -EOPNOTSUPP;
err = get_res(dev, slave, vhcr->in_param, RES_FS_RULE, &rrule);
if (err)
return err;
/* Release the rule form busy state before removal */
put_res(dev, slave, vhcr->in_param, RES_FS_RULE);
err = get_res(dev, slave, rrule->qpn, RES_QP, &rqp);
if (err)
return err;
err = rem_res_range(dev, slave, vhcr->in_param, 1, RES_FS_RULE, 0); err = rem_res_range(dev, slave, vhcr->in_param, 1, RES_FS_RULE, 0);
if (err) { if (err) {
mlx4_err(dev, "Fail to remove flow steering resources.\n "); mlx4_err(dev, "Fail to remove flow steering resources.\n ");
return err; goto out;
} }
err = mlx4_cmd(dev, vhcr->in_param, 0, 0, err = mlx4_cmd(dev, vhcr->in_param, 0, 0,
MLX4_QP_FLOW_STEERING_DETACH, MLX4_CMD_TIME_CLASS_A, MLX4_QP_FLOW_STEERING_DETACH, MLX4_CMD_TIME_CLASS_A,
MLX4_CMD_NATIVE); MLX4_CMD_NATIVE);
if (!err)
atomic_dec(&rqp->ref_count);
out:
put_res(dev, slave, rrule->qpn, RES_QP);
return err; return err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment