@@ -2464,11 +2464,24 @@ int mlx5_ib_dealloc_dm(struct ib_dm *ibdm, struct uverbs_attr_bundle *attrs)
return 0;
}
+static int mlx5_ib_clone_pd(struct ib_udata *udata, struct ib_pd *ibpd)
+{
+ struct mlx5_ib_pd *pd = to_mpd(ibpd);
+ struct mlx5_ib_alloc_pd_resp resp;
+ int ret = 0;
+
+ if (udata) {
+ resp.pdn = pd->pdn;
+ ret = ib_copy_to_udata(udata, &resp, sizeof(resp));
+ }
+
+ return ret;
+}
+
static int mlx5_ib_alloc_pd(struct ib_pd *ibpd, struct ib_udata *udata)
{
struct mlx5_ib_pd *pd = to_mpd(ibpd);
struct ib_device *ibdev = ibpd->device;
- struct mlx5_ib_alloc_pd_resp resp;
int err;
u32 out[MLX5_ST_SZ_DW(alloc_pd_out)] = {};
u32 in[MLX5_ST_SZ_DW(alloc_pd_in)] = {};
@@ -2486,12 +2499,11 @@ static int mlx5_ib_alloc_pd(struct ib_pd *ibpd, struct ib_udata *udata)
pd->pdn = MLX5_GET(alloc_pd_out, out, pd);
pd->uid = uid;
- if (udata) {
- resp.pdn = pd->pdn;
- if (ib_copy_to_udata(udata, &resp, sizeof(resp))) {
- mlx5_cmd_dealloc_pd(to_mdev(ibdev)->mdev, pd->pdn, uid);
- return -EFAULT;
- }
+
+ err = mlx5_ib_clone_pd(udata, ibpd);
+ if (err) {
+ mlx5_cmd_dealloc_pd(to_mdev(ibdev)->mdev, pd->pdn, uid);
+ return err;
}
return 0;
@@ -6338,6 +6350,9 @@ static const struct ib_device_ops mlx5_ib_dev_ops = {
.rereg_user_mr = mlx5_ib_rereg_user_mr,
.resize_cq = mlx5_ib_resize_cq,
+ /* Object sharing callbacks */
+ .clone_ib_pd = mlx5_ib_clone_pd,
+
INIT_RDMA_OBJ_SIZE(ib_ah, mlx5_ib_ah, ibah),
INIT_RDMA_OBJ_SIZE(ib_cq, mlx5_ib_cq, ibcq),
INIT_RDMA_OBJ_SIZE(ib_pd, mlx5_ib_pd, ibpd),