IB/mlx5: Set uid as part of XRCD commands
authorYishai Hadas <yishaih@mellanox.com>
Thu, 20 Sep 2018 18:39:31 +0000 (21:39 +0300)
committerJason Gunthorpe <jgg@mellanox.com>
Tue, 25 Sep 2018 20:06:04 +0000 (14:06 -0600)
Set uid as part of XRCD commands so that the firmware can manage the
XRCD object in a secured way.

That will enable using an XRCD that was created by verbs application
to be used by the DEVX flow in case the uid is equal.

Signed-off-by: Yishai Hadas <yishaih@mellanox.com>
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
drivers/infiniband/hw/mlx5/cmd.c
drivers/infiniband/hw/mlx5/cmd.h
drivers/infiniband/hw/mlx5/mlx5_ib.h
drivers/infiniband/hw/mlx5/qp.c

index 6862b03dbdec1b90c004275c7821329f76ce598a..2a530e9f99e6537a9a87225fd74dc2d4dafca28c 100644 (file)
@@ -271,3 +271,28 @@ int mlx5_cmd_detach_mcg(struct mlx5_core_dev *dev, union ib_gid *mgid,
        memcpy(gid, mgid, sizeof(*mgid));
        return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
 }
+
+int mlx5_cmd_xrcd_alloc(struct mlx5_core_dev *dev, u32 *xrcdn, u16 uid)
+{
+       u32 out[MLX5_ST_SZ_DW(alloc_xrcd_out)] = {};
+       u32 in[MLX5_ST_SZ_DW(alloc_xrcd_in)]   = {};
+       int err;
+
+       MLX5_SET(alloc_xrcd_in, in, opcode, MLX5_CMD_OP_ALLOC_XRCD);
+       MLX5_SET(alloc_xrcd_in, in, uid, uid);
+       err = mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
+       if (!err)
+               *xrcdn = MLX5_GET(alloc_xrcd_out, out, xrcd);
+       return err;
+}
+
+int mlx5_cmd_xrcd_dealloc(struct mlx5_core_dev *dev, u32 xrcdn, u16 uid)
+{
+       u32 out[MLX5_ST_SZ_DW(dealloc_xrcd_out)] = {};
+       u32 in[MLX5_ST_SZ_DW(dealloc_xrcd_in)]   = {};
+
+       MLX5_SET(dealloc_xrcd_in, in, opcode, MLX5_CMD_OP_DEALLOC_XRCD);
+       MLX5_SET(dealloc_xrcd_in, in, xrcd, xrcdn);
+       MLX5_SET(dealloc_xrcd_in, in, uid, uid);
+       return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
+}
index 742452e4be7eab8023a0dee5f40d7f3ca16f0ca4..12fe63005d11535a817b77ac3214cb4680204b88 100644 (file)
@@ -55,4 +55,6 @@ int mlx5_cmd_attach_mcg(struct mlx5_core_dev *dev, union ib_gid *mgid,
                        u32 qpn, u16 uid);
 int mlx5_cmd_detach_mcg(struct mlx5_core_dev *dev, union ib_gid *mgid,
                        u32 qpn, u16 uid);
+int mlx5_cmd_xrcd_alloc(struct mlx5_core_dev *dev, u32 *xrcdn, u16 uid);
+int mlx5_cmd_xrcd_dealloc(struct mlx5_core_dev *dev, u32 xrcdn, u16 uid);
 #endif /* MLX5_IB_CMD_H */
index 43eddd452a6825fb8a47d757df309954bb1e60e8..94cf83bd171681754e309b34e4d11a5cdc342479 100644 (file)
@@ -539,6 +539,7 @@ struct mlx5_ib_srq {
 struct mlx5_ib_xrcd {
        struct ib_xrcd          ibxrcd;
        u32                     xrcdn;
+       u16                     uid;
 };
 
 enum mlx5_ib_mtt_access_flags {
index 5dc5869692eba141238e316e0aaa6a7d9f3db1b4..a0cb260a271f1172e83865222673286ad3449d2d 100644 (file)
@@ -5280,6 +5280,7 @@ struct ib_xrcd *mlx5_ib_alloc_xrcd(struct ib_device *ibdev,
        struct mlx5_ib_dev *dev = to_mdev(ibdev);
        struct mlx5_ib_xrcd *xrcd;
        int err;
+       u16 uid;
 
        if (!MLX5_CAP_GEN(dev->mdev, xrc))
                return ERR_PTR(-ENOSYS);
@@ -5288,12 +5289,14 @@ struct ib_xrcd *mlx5_ib_alloc_xrcd(struct ib_device *ibdev,
        if (!xrcd)
                return ERR_PTR(-ENOMEM);
 
-       err = mlx5_core_xrcd_alloc(dev->mdev, &xrcd->xrcdn);
+       uid = context ? to_mucontext(context)->devx_uid : 0;
+       err = mlx5_cmd_xrcd_alloc(dev->mdev, &xrcd->xrcdn, uid);
        if (err) {
                kfree(xrcd);
                return ERR_PTR(-ENOMEM);
        }
 
+       xrcd->uid = uid;
        return &xrcd->ibxrcd;
 }
 
@@ -5301,9 +5304,10 @@ int mlx5_ib_dealloc_xrcd(struct ib_xrcd *xrcd)
 {
        struct mlx5_ib_dev *dev = to_mdev(xrcd->device);
        u32 xrcdn = to_mxrcd(xrcd)->xrcdn;
+       u16 uid =  to_mxrcd(xrcd)->uid;
        int err;
 
-       err = mlx5_core_xrcd_dealloc(dev->mdev, xrcdn);
+       err = mlx5_cmd_xrcd_dealloc(dev->mdev, xrcdn, uid);
        if (err)
                mlx5_ib_warn(dev, "failed to dealloc xrcdn 0x%x\n", xrcdn);