git: a30f71704efe - main - mlx5ib: Add support for parsing udata in mlx5_ib_create_flow().
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 10 Feb 2022 10:18:35 UTC
The branch main has been updated by hselasky: URL: https://cgit.FreeBSD.org/src/commit/?id=a30f71704efeea06c158bc0a625e37d5a12ffbd5 commit a30f71704efeea06c158bc0a625e37d5a12ffbd5 Author: Hans Petter Selasky <hselasky@FreeBSD.org> AuthorDate: 2022-02-10 10:13:36 +0000 Commit: Hans Petter Selasky <hselasky@FreeBSD.org> CommitDate: 2022-02-10 10:17:42 +0000 mlx5ib: Add support for parsing udata in mlx5_ib_create_flow(). Backport from Linux 5.17 (drivers/infiniband/hw/mlx5/fs.c) This fixes creating flow rules from user-space after the kernel space update based on Linux 5.7-rc1 . Sponsored by: NVIDIA Networking --- sys/dev/mlx5/mlx5_ib/mlx5_ib_main.c | 87 ++++++++++++++++++++++++++--------- sys/ofed/include/uapi/rdma/mlx5-abi.h | 22 +++++++++ 2 files changed, 87 insertions(+), 22 deletions(-) diff --git a/sys/dev/mlx5/mlx5_ib/mlx5_ib_main.c b/sys/dev/mlx5/mlx5_ib/mlx5_ib_main.c index 70a7fcd758de..65767483652f 100644 --- a/sys/dev/mlx5/mlx5_ib/mlx5_ib_main.c +++ b/sys/dev/mlx5/mlx5_ib/mlx5_ib_main.c @@ -2317,6 +2317,7 @@ static struct mlx5_ib_flow_handler *create_sniffer_rule(struct mlx5_ib_dev *dev, int err; static const struct ib_flow_attr flow_attr = { .num_of_specs = 0, + .type = IB_FLOW_ATTR_SNIFFER, .size = sizeof(flow_attr) }; @@ -2355,20 +2356,55 @@ static struct ib_flow *mlx5_ib_create_flow(struct ib_qp *qp, struct mlx5_flow_destination *dst = NULL; struct mlx5_ib_flow_prio *ft_prio_tx = NULL; struct mlx5_ib_flow_prio *ft_prio; + struct mlx5_ib_create_flow *ucmd = NULL, ucmd_hdr; + size_t min_ucmd_sz, required_ucmd_sz; int err; - if (flow_attr->priority > MLX5_IB_FLOW_LAST_PRIO) - return ERR_PTR(-ENOSPC); + if (udata && udata->inlen) { + min_ucmd_sz = offsetofend(struct mlx5_ib_create_flow, reserved); + if (udata->inlen < min_ucmd_sz) + return ERR_PTR(-EOPNOTSUPP); - if (domain != IB_FLOW_DOMAIN_USER || - udata != NULL || - flow_attr->port > MLX5_CAP_GEN(dev->mdev, num_ports) || - (flow_attr->flags & ~IB_FLOW_ATTR_FLAGS_DONT_TRAP)) - return ERR_PTR(-EINVAL); + err = ib_copy_from_udata(&ucmd_hdr, udata, min_ucmd_sz); + if (err) + return ERR_PTR(err); + + /* currently supports only one counters data */ + if (ucmd_hdr.ncounters_data > 1) + return ERR_PTR(-EINVAL); + + required_ucmd_sz = min_ucmd_sz + + sizeof(struct mlx5_ib_flow_counters_data) * + ucmd_hdr.ncounters_data; + if (udata->inlen > required_ucmd_sz && + !ib_is_udata_cleared(udata, required_ucmd_sz, + udata->inlen - required_ucmd_sz)) + return ERR_PTR(-EOPNOTSUPP); + + ucmd = kzalloc(required_ucmd_sz, GFP_KERNEL); + if (!ucmd) + return ERR_PTR(-ENOMEM); + + err = ib_copy_from_udata(ucmd, udata, required_ucmd_sz); + if (err) + goto free_ucmd; + } + + if (flow_attr->priority > MLX5_IB_FLOW_LAST_PRIO) { + err = -ENOMEM; + goto free_ucmd; + } + + if (flow_attr->flags & ~IB_FLOW_ATTR_FLAGS_DONT_TRAP) { + err = -EINVAL; + goto free_ucmd; + } dst = kzalloc(sizeof(*dst), GFP_KERNEL); - if (!dst) - return ERR_PTR(-ENOMEM); + if (!dst) { + err = -ENOMEM; + goto free_ucmd; + } mutex_lock(&dev->flow_db.lock); @@ -2392,21 +2428,26 @@ static struct ib_flow *mlx5_ib_create_flow(struct ib_qp *qp, else dst->tir_num = mqp->raw_packet_qp.rq.tirn; - if (flow_attr->type == IB_FLOW_ATTR_NORMAL) { - if (flow_attr->flags & IB_FLOW_ATTR_FLAGS_DONT_TRAP) { - handler = create_dont_trap_rule(dev, ft_prio, - flow_attr, dst); + switch (flow_attr->type) { + case IB_FLOW_ATTR_NORMAL: + if (mqp->flags & IB_QP_CREATE_SOURCE_QPN) { + err = -EOPNOTSUPP; + goto destroy_ft; + } + if (flow_attr->flags & IB_FLOW_ATTR_FLAGS_DONT_TRAP) { + handler = create_dont_trap_rule(dev, ft_prio, flow_attr, dst); } else { - handler = create_flow_rule(dev, ft_prio, flow_attr, - dst); + handler = create_flow_rule(dev, ft_prio, flow_attr, dst); } - } else if (flow_attr->type == IB_FLOW_ATTR_ALL_DEFAULT || - flow_attr->type == IB_FLOW_ATTR_MC_DEFAULT) { - handler = create_leftovers_rule(dev, ft_prio, flow_attr, - dst); - } else if (flow_attr->type == IB_FLOW_ATTR_SNIFFER) { + break; + case IB_FLOW_ATTR_ALL_DEFAULT: + case IB_FLOW_ATTR_MC_DEFAULT: + handler = create_leftovers_rule(dev, ft_prio, flow_attr, dst); + break; + case IB_FLOW_ATTR_SNIFFER: handler = create_sniffer_rule(dev, ft_prio, ft_prio_tx, dst); - } else { + break; + default: err = -EINVAL; goto destroy_ft; } @@ -2419,6 +2460,7 @@ static struct ib_flow *mlx5_ib_create_flow(struct ib_qp *qp, mutex_unlock(&dev->flow_db.lock); kfree(dst); + kfree(ucmd); return &handler->ibflow; @@ -2429,7 +2471,8 @@ destroy_ft: unlock: mutex_unlock(&dev->flow_db.lock); kfree(dst); - kfree(handler); +free_ucmd: + kfree(ucmd); return ERR_PTR(err); } diff --git a/sys/ofed/include/uapi/rdma/mlx5-abi.h b/sys/ofed/include/uapi/rdma/mlx5-abi.h index efa7712b79ec..313265467a26 100644 --- a/sys/ofed/include/uapi/rdma/mlx5-abi.h +++ b/sys/ofed/include/uapi/rdma/mlx5-abi.h @@ -299,4 +299,26 @@ enum { MLX5_IB_CLOCK_INFO_V1 = 0, }; +struct mlx5_ib_flow_counters_desc { + __u32 description; + __u32 index; +}; + +struct mlx5_ib_flow_counters_data { + RDMA_UAPI_PTR(struct mlx5_ib_flow_counters_desc *, counters_data); + __u32 ncounters; + __u32 reserved; +}; + +struct mlx5_ib_create_flow { + __u32 ncounters_data; + __u32 reserved; + /* + * Following are counters data based on ncounters_data, each + * entry in the data[] should match a corresponding counter object + * that was pointed by a counters spec upon the flow creation + */ + struct mlx5_ib_flow_counters_data data[]; +}; + #endif /* MLX5_ABI_USER_H */