Commit 48357091 authored by Leon Romanovsky's avatar Leon Romanovsky

RDMA/mlx5: Don't fake udata for kernel path

Kernel paths must not set udata and provide NULL pointer,
instead of faking zeroed udata struct.
Signed-off-by: default avatarLeon Romanovsky <leonro@mellanox.com>
parent da9ee9d8
...@@ -815,6 +815,7 @@ static int mlx5_ib_query_device(struct ib_device *ibdev, ...@@ -815,6 +815,7 @@ static int mlx5_ib_query_device(struct ib_device *ibdev,
struct ib_device_attr *props, struct ib_device_attr *props,
struct ib_udata *uhw) struct ib_udata *uhw)
{ {
size_t uhw_outlen = (uhw) ? uhw->outlen : 0;
struct mlx5_ib_dev *dev = to_mdev(ibdev); struct mlx5_ib_dev *dev = to_mdev(ibdev);
struct mlx5_core_dev *mdev = dev->mdev; struct mlx5_core_dev *mdev = dev->mdev;
int err = -ENOMEM; int err = -ENOMEM;
...@@ -828,12 +829,12 @@ static int mlx5_ib_query_device(struct ib_device *ibdev, ...@@ -828,12 +829,12 @@ static int mlx5_ib_query_device(struct ib_device *ibdev,
u64 max_tso; u64 max_tso;
resp_len = sizeof(resp.comp_mask) + sizeof(resp.response_length); resp_len = sizeof(resp.comp_mask) + sizeof(resp.response_length);
if (uhw->outlen && uhw->outlen < resp_len) if (uhw_outlen && uhw_outlen < resp_len)
return -EINVAL; return -EINVAL;
resp.response_length = resp_len; resp.response_length = resp_len;
if (uhw->inlen && !ib_is_udata_cleared(uhw, 0, uhw->inlen)) if (uhw && uhw->inlen && !ib_is_udata_cleared(uhw, 0, uhw->inlen))
return -EINVAL; return -EINVAL;
memset(props, 0, sizeof(*props)); memset(props, 0, sizeof(*props));
...@@ -897,7 +898,7 @@ static int mlx5_ib_query_device(struct ib_device *ibdev, ...@@ -897,7 +898,7 @@ static int mlx5_ib_query_device(struct ib_device *ibdev,
props->raw_packet_caps |= props->raw_packet_caps |=
IB_RAW_PACKET_CAP_CVLAN_STRIPPING; IB_RAW_PACKET_CAP_CVLAN_STRIPPING;
if (field_avail(typeof(resp), tso_caps, uhw->outlen)) { if (field_avail(typeof(resp), tso_caps, uhw_outlen)) {
max_tso = MLX5_CAP_ETH(mdev, max_lso_cap); max_tso = MLX5_CAP_ETH(mdev, max_lso_cap);
if (max_tso) { if (max_tso) {
resp.tso_caps.max_tso = 1 << max_tso; resp.tso_caps.max_tso = 1 << max_tso;
...@@ -907,7 +908,7 @@ static int mlx5_ib_query_device(struct ib_device *ibdev, ...@@ -907,7 +908,7 @@ static int mlx5_ib_query_device(struct ib_device *ibdev,
} }
} }
if (field_avail(typeof(resp), rss_caps, uhw->outlen)) { if (field_avail(typeof(resp), rss_caps, uhw_outlen)) {
resp.rss_caps.rx_hash_function = resp.rss_caps.rx_hash_function =
MLX5_RX_HASH_FUNC_TOEPLITZ; MLX5_RX_HASH_FUNC_TOEPLITZ;
resp.rss_caps.rx_hash_fields_mask = resp.rss_caps.rx_hash_fields_mask =
...@@ -927,9 +928,9 @@ static int mlx5_ib_query_device(struct ib_device *ibdev, ...@@ -927,9 +928,9 @@ static int mlx5_ib_query_device(struct ib_device *ibdev,
resp.response_length += sizeof(resp.rss_caps); resp.response_length += sizeof(resp.rss_caps);
} }
} else { } else {
if (field_avail(typeof(resp), tso_caps, uhw->outlen)) if (field_avail(typeof(resp), tso_caps, uhw_outlen))
resp.response_length += sizeof(resp.tso_caps); resp.response_length += sizeof(resp.tso_caps);
if (field_avail(typeof(resp), rss_caps, uhw->outlen)) if (field_avail(typeof(resp), rss_caps, uhw_outlen))
resp.response_length += sizeof(resp.rss_caps); resp.response_length += sizeof(resp.rss_caps);
} }
...@@ -1054,7 +1055,7 @@ static int mlx5_ib_query_device(struct ib_device *ibdev, ...@@ -1054,7 +1055,7 @@ static int mlx5_ib_query_device(struct ib_device *ibdev,
MLX5_MAX_CQ_PERIOD; MLX5_MAX_CQ_PERIOD;
} }
if (field_avail(typeof(resp), cqe_comp_caps, uhw->outlen)) { if (field_avail(typeof(resp), cqe_comp_caps, uhw_outlen)) {
resp.response_length += sizeof(resp.cqe_comp_caps); resp.response_length += sizeof(resp.cqe_comp_caps);
if (MLX5_CAP_GEN(dev->mdev, cqe_compression)) { if (MLX5_CAP_GEN(dev->mdev, cqe_compression)) {
...@@ -1072,7 +1073,7 @@ static int mlx5_ib_query_device(struct ib_device *ibdev, ...@@ -1072,7 +1073,7 @@ static int mlx5_ib_query_device(struct ib_device *ibdev,
} }
} }
if (field_avail(typeof(resp), packet_pacing_caps, uhw->outlen) && if (field_avail(typeof(resp), packet_pacing_caps, uhw_outlen) &&
raw_support) { raw_support) {
if (MLX5_CAP_QOS(mdev, packet_pacing) && if (MLX5_CAP_QOS(mdev, packet_pacing) &&
MLX5_CAP_GEN(mdev, qos)) { MLX5_CAP_GEN(mdev, qos)) {
...@@ -1091,7 +1092,7 @@ static int mlx5_ib_query_device(struct ib_device *ibdev, ...@@ -1091,7 +1092,7 @@ static int mlx5_ib_query_device(struct ib_device *ibdev,
} }
if (field_avail(typeof(resp), mlx5_ib_support_multi_pkt_send_wqes, if (field_avail(typeof(resp), mlx5_ib_support_multi_pkt_send_wqes,
uhw->outlen)) { uhw_outlen)) {
if (MLX5_CAP_ETH(mdev, multi_pkt_send_wqe)) if (MLX5_CAP_ETH(mdev, multi_pkt_send_wqe))
resp.mlx5_ib_support_multi_pkt_send_wqes = resp.mlx5_ib_support_multi_pkt_send_wqes =
MLX5_IB_ALLOW_MPW; MLX5_IB_ALLOW_MPW;
...@@ -1104,7 +1105,7 @@ static int mlx5_ib_query_device(struct ib_device *ibdev, ...@@ -1104,7 +1105,7 @@ static int mlx5_ib_query_device(struct ib_device *ibdev,
sizeof(resp.mlx5_ib_support_multi_pkt_send_wqes); sizeof(resp.mlx5_ib_support_multi_pkt_send_wqes);
} }
if (field_avail(typeof(resp), flags, uhw->outlen)) { if (field_avail(typeof(resp), flags, uhw_outlen)) {
resp.response_length += sizeof(resp.flags); resp.response_length += sizeof(resp.flags);
if (MLX5_CAP_GEN(mdev, cqe_compression_128)) if (MLX5_CAP_GEN(mdev, cqe_compression_128))
...@@ -1120,8 +1121,7 @@ static int mlx5_ib_query_device(struct ib_device *ibdev, ...@@ -1120,8 +1121,7 @@ static int mlx5_ib_query_device(struct ib_device *ibdev,
resp.flags |= MLX5_IB_QUERY_DEV_RESP_FLAGS_SCAT2CQE_DCT; resp.flags |= MLX5_IB_QUERY_DEV_RESP_FLAGS_SCAT2CQE_DCT;
} }
if (field_avail(typeof(resp), sw_parsing_caps, if (field_avail(typeof(resp), sw_parsing_caps, uhw_outlen)) {
uhw->outlen)) {
resp.response_length += sizeof(resp.sw_parsing_caps); resp.response_length += sizeof(resp.sw_parsing_caps);
if (MLX5_CAP_ETH(mdev, swp)) { if (MLX5_CAP_ETH(mdev, swp)) {
resp.sw_parsing_caps.sw_parsing_offloads |= resp.sw_parsing_caps.sw_parsing_offloads |=
...@@ -1141,7 +1141,7 @@ static int mlx5_ib_query_device(struct ib_device *ibdev, ...@@ -1141,7 +1141,7 @@ static int mlx5_ib_query_device(struct ib_device *ibdev,
} }
} }
if (field_avail(typeof(resp), striding_rq_caps, uhw->outlen) && if (field_avail(typeof(resp), striding_rq_caps, uhw_outlen) &&
raw_support) { raw_support) {
resp.response_length += sizeof(resp.striding_rq_caps); resp.response_length += sizeof(resp.striding_rq_caps);
if (MLX5_CAP_GEN(mdev, striding_rq)) { if (MLX5_CAP_GEN(mdev, striding_rq)) {
...@@ -1164,8 +1164,7 @@ static int mlx5_ib_query_device(struct ib_device *ibdev, ...@@ -1164,8 +1164,7 @@ static int mlx5_ib_query_device(struct ib_device *ibdev,
} }
} }
if (field_avail(typeof(resp), tunnel_offloads_caps, if (field_avail(typeof(resp), tunnel_offloads_caps, uhw_outlen)) {
uhw->outlen)) {
resp.response_length += sizeof(resp.tunnel_offloads_caps); resp.response_length += sizeof(resp.tunnel_offloads_caps);
if (MLX5_CAP_ETH(mdev, tunnel_stateless_vxlan)) if (MLX5_CAP_ETH(mdev, tunnel_stateless_vxlan))
resp.tunnel_offloads_caps |= resp.tunnel_offloads_caps |=
...@@ -1186,7 +1185,7 @@ static int mlx5_ib_query_device(struct ib_device *ibdev, ...@@ -1186,7 +1185,7 @@ static int mlx5_ib_query_device(struct ib_device *ibdev,
MLX5_IB_TUNNELED_OFFLOADS_MPLS_UDP; MLX5_IB_TUNNELED_OFFLOADS_MPLS_UDP;
} }
if (uhw->outlen) { if (uhw_outlen) {
err = ib_copy_to_udata(uhw, &resp, resp.response_length); err = ib_copy_to_udata(uhw, &resp, resp.response_length);
if (err) if (err)
...@@ -4771,7 +4770,6 @@ static int __get_port_caps(struct mlx5_ib_dev *dev, u8 port) ...@@ -4771,7 +4770,6 @@ static int __get_port_caps(struct mlx5_ib_dev *dev, u8 port)
struct ib_device_attr *dprops = NULL; struct ib_device_attr *dprops = NULL;
struct ib_port_attr *pprops = NULL; struct ib_port_attr *pprops = NULL;
int err = -ENOMEM; int err = -ENOMEM;
struct ib_udata uhw = {.inlen = 0, .outlen = 0};
pprops = kzalloc(sizeof(*pprops), GFP_KERNEL); pprops = kzalloc(sizeof(*pprops), GFP_KERNEL);
if (!pprops) if (!pprops)
...@@ -4781,7 +4779,7 @@ static int __get_port_caps(struct mlx5_ib_dev *dev, u8 port) ...@@ -4781,7 +4779,7 @@ static int __get_port_caps(struct mlx5_ib_dev *dev, u8 port)
if (!dprops) if (!dprops)
goto out; goto out;
err = mlx5_ib_query_device(&dev->ib_dev, dprops, &uhw); err = mlx5_ib_query_device(&dev->ib_dev, dprops, NULL);
if (err) { if (err) {
mlx5_ib_warn(dev, "query_device failed %d\n", err); mlx5_ib_warn(dev, "query_device failed %d\n", err);
goto out; goto out;
......
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