From: Shamir Rabinovitch <shamir.rabinovitch@xxxxxxxxxx> Copy mlx4 ib_pd to user-space. Signed-off-by: Shamir Rabinovitch <shamir.rabinovitch@xxxxxxxxxx> Signed-off-by: Shamir Rabinovitch <srabinov7@xxxxxxxxx> --- drivers/infiniband/hw/mlx4/main.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/infiniband/hw/mlx4/main.c b/drivers/infiniband/hw/mlx4/main.c index 8790101facb7..8adc569ce4fd 100644 --- a/drivers/infiniband/hw/mlx4/main.c +++ b/drivers/infiniband/hw/mlx4/main.c @@ -1178,6 +1178,13 @@ static int mlx4_ib_mmap(struct ib_ucontext *context, struct vm_area_struct *vma) } } +static int mlx4_ib_clone_pd(struct ib_udata *udata, struct ib_pd *ibpd) +{ + struct mlx4_ib_pd *pd = to_mpd(ibpd); + + return udata ? ib_copy_to_udata(udata, &pd->pdn, sizeof(__u32)) : 0; +} + static int mlx4_ib_alloc_pd(struct ib_pd *ibpd, struct ib_udata *udata) { struct mlx4_ib_pd *pd = to_mpd(ibpd); @@ -1188,10 +1195,12 @@ static int mlx4_ib_alloc_pd(struct ib_pd *ibpd, struct ib_udata *udata) if (err) return err; - if (udata && ib_copy_to_udata(udata, &pd->pdn, sizeof(__u32))) { + err = mlx4_ib_clone_pd(udata, ibpd); + if (err) { mlx4_pd_free(to_mdev(ibdev)->dev, pd->pdn); return -EFAULT; } + return 0; } @@ -2564,6 +2573,9 @@ static const struct ib_device_ops mlx4_ib_dev_ops = { .rereg_user_mr = mlx4_ib_rereg_user_mr, .resize_cq = mlx4_ib_resize_cq, + /* Object sharing callbacks */ + .clone_ib_pd = mlx4_ib_clone_pd, + INIT_RDMA_OBJ_SIZE(ib_ah, mlx4_ib_ah, ibah), INIT_RDMA_OBJ_SIZE(ib_cq, mlx4_ib_cq, ibcq), INIT_RDMA_OBJ_SIZE(ib_pd, mlx4_ib_pd, ibpd), -- 2.20.1