Skip to contentSkip to conversation

vdpa/mlx5: Support creating resources with uid == 0

PATCH In review Eli Cohen 3 participants 4 messages May 31, 2021 – Jun 1, 2021

Subsystems (4)
lore
Share & tools
lore

Eli Cohen

author
#0 lore raw

PATCH 1/2 vdpa/mlx5: Support creating resources with uid == 0

Currently all resources must be created with uid != 0 which is essential when userspace processes are allocating virtquueue resources. Since this is a kernel implementation, it is perfectly legal to open resources with uid == 0.

In case firmware supports, avoid allocating user context.

---
v0 --> v1:
Fix typo and modify phrasing

 drivers/vdpa/mlx5/core/resources.c | 6 ++++++
 include/linux/mlx5/mlx5_ifc.h      | 4 +++-
 2 files changed, 9 insertions(+), 1 deletion(-)
drivers/vdpa/mlx5/core/resources.c +6 -0
index 6521cbd0f5c2..836ab9ef0fa6 100644
@@ -54,6 +54,9 @@ static int create_uctx(struct mlx5_vdpa_dev *mvdev, u16 *uid)
 	void *in;
 	int err;
 
+	if (MLX5_CAP_GEN(mvdev->mdev, umem_uid_0))
+		return 0;
+
 	/* 0 means not supported */
 	if (!MLX5_CAP_GEN(mvdev->mdev, log_max_uctx))
 		return -EOPNOTSUPP;
@@ -79,6 +82,9 @@ static void destroy_uctx(struct mlx5_vdpa_dev *mvdev, u32 uid)
 	u32 out[MLX5_ST_SZ_DW(destroy_uctx_out)] = {};
 	u32 in[MLX5_ST_SZ_DW(destroy_uctx_in)] = {};
 
+	if (!uid)
+		return;
+
 	MLX5_SET(destroy_uctx_in, in, opcode, MLX5_CMD_OP_DESTROY_UCTX);
 	MLX5_SET(destroy_uctx_in, in, uid, uid);
 
include/linux/mlx5/mlx5_ifc.h +3 -1
index 9c68b2da14c6..606d2aeacad4 100644
@@ -1487,7 +1487,9 @@ struct mlx5_ifc_cmd_hca_cap_bits {
 	u8         uar_4k[0x1];
 	u8         reserved_at_241[0x9];
 	u8         uar_sz[0x6];
-	u8         reserved_at_250[0x8];
+	u8         reserved_at_248[0x2];
+	u8         umem_uid_0[0x1];
+	u8         reserved_at_250[0x5];
 	u8         log_pg_sz[0x8];
 
 	u8         bf[0x1];
Signature · 1 line
2.31.1
#1 lore raw
Quoted 11 lines · Eli Cohen

Currently all resources must be created with uid != 0 which is essential when userspace processes are allocating virtquueue resources. Since this is a kernel implementation, it is perfectly legal to open resources with uid == 0.

In case firmware supports, avoid allocating user context.

---
v0 --> v1:
Fix typo and modify phrasing

threading's broken now

Quoted 45 lines
 drivers/vdpa/mlx5/core/resources.c | 6 ++++++
 include/linux/mlx5/mlx5_ifc.h      | 4 +++-
 2 files changed, 9 insertions(+), 1 deletion(-)
drivers/vdpa/mlx5/core/resources.c +6 -0
index 6521cbd0f5c2..836ab9ef0fa6 100644
@@ -54,6 +54,9 @@ static int create_uctx(struct mlx5_vdpa_dev *mvdev, u16 *uid)
 	void *in;
 	int err;
 
+	if (MLX5_CAP_GEN(mvdev->mdev, umem_uid_0))
+		return 0;
+
 	/* 0 means not supported */
 	if (!MLX5_CAP_GEN(mvdev->mdev, log_max_uctx))
 		return -EOPNOTSUPP;
@@ -79,6 +82,9 @@ static void destroy_uctx(struct mlx5_vdpa_dev *mvdev, u32 uid)
 	u32 out[MLX5_ST_SZ_DW(destroy_uctx_out)] = {};
 	u32 in[MLX5_ST_SZ_DW(destroy_uctx_in)] = {};
 
+	if (!uid)
+		return;
+
 	MLX5_SET(destroy_uctx_in, in, opcode, MLX5_CMD_OP_DESTROY_UCTX);
 	MLX5_SET(destroy_uctx_in, in, uid, uid);
 
include/linux/mlx5/mlx5_ifc.h +3 -1
index 9c68b2da14c6..606d2aeacad4 100644
@@ -1487,7 +1487,9 @@ struct mlx5_ifc_cmd_hca_cap_bits {
 	u8         uar_4k[0x1];
 	u8         reserved_at_241[0x9];
 	u8         uar_sz[0x6];
-	u8         reserved_at_250[0x8];
+	u8         reserved_at_248[0x2];
+	u8         umem_uid_0[0x1];
+	u8         reserved_at_250[0x5];
 	u8         log_pg_sz[0x8];
 
 	u8         bf[0x1];
Signature · 1 line
2.31.1
Acked-by on v1 1/2
#3 lore raw
In reply to Eli Cohen
Quoted 8 lines · Eli Cohen

Currently all resources must be created with uid != 0 which is essential when userspace processes are allocating virtquueue resources. Since this is a kernel implementation, it is perfectly legal to open resources with uid == 0.

In case firmware supports, avoid allocating user context.

Quoted 47 lines

---
v0 --> v1:
Fix typo and modify phrasing

  drivers/vdpa/mlx5/core/resources.c | 6 ++++++
  include/linux/mlx5/mlx5_ifc.h      | 4 +++-
  2 files changed, 9 insertions(+), 1 deletion(-)
drivers/vdpa/mlx5/core/resources.c +6 -0
index 6521cbd0f5c2..836ab9ef0fa6 100644
@@ -54,6 +54,9 @@ static int create_uctx(struct mlx5_vdpa_dev *mvdev, u16 *uid)
  	void *in;
  	int err;
 
+	if (MLX5_CAP_GEN(mvdev->mdev, umem_uid_0))
+		return 0;
+
  	/* 0 means not supported */
  	if (!MLX5_CAP_GEN(mvdev->mdev, log_max_uctx))
  		return -EOPNOTSUPP;
@@ -79,6 +82,9 @@ static void destroy_uctx(struct mlx5_vdpa_dev *mvdev, u32 uid)
  	u32 out[MLX5_ST_SZ_DW(destroy_uctx_out)] = {};
  	u32 in[MLX5_ST_SZ_DW(destroy_uctx_in)] = {};
 
+	if (!uid)
+		return;
+
  	MLX5_SET(destroy_uctx_in, in, opcode, MLX5_CMD_OP_DESTROY_UCTX);
  	MLX5_SET(destroy_uctx_in, in, uid, uid);
 
include/linux/mlx5/mlx5_ifc.h +3 -1
index 9c68b2da14c6..606d2aeacad4 100644
@@ -1487,7 +1487,9 @@ struct mlx5_ifc_cmd_hca_cap_bits {
  	u8         uar_4k[0x1];
  	u8         reserved_at_241[0x9];
  	u8         uar_sz[0x6];
-	u8         reserved_at_250[0x8];
+	u8         reserved_at_248[0x2];
+	u8         umem_uid_0[0x1];
+	u8         reserved_at_250[0x5];
  	u8         log_pg_sz[0x8];
 
  	u8         bf[0x1];
author
#2 lore raw
In reply to Michael S. Tsirkin
Quoted 6 lines · Michael S. Tsirkin
Quoted 5 lines · Eli Cohen

Currently all resources must be created with uid != 0 which is essential when userspace processes are allocating virtquueue resources. Since this is a kernel implementation, it is perfectly legal to open resources with uid == 0.

Quoted 8 lines
Quoted 6 lines

In case firmware supports, avoid allocating user context.

---
v0 --> v1:
Fix typo and modify phrasing

threading's broken now

Sorry about this, will repost again.

Quoted 47 lines
Quoted 46 lines
 drivers/vdpa/mlx5/core/resources.c | 6 ++++++
 include/linux/mlx5/mlx5_ifc.h      | 4 +++-
 2 files changed, 9 insertions(+), 1 deletion(-)
drivers/vdpa/mlx5/core/resources.c +6 -0
index 6521cbd0f5c2..836ab9ef0fa6 100644
@@ -54,6 +54,9 @@ static int create_uctx(struct mlx5_vdpa_dev *mvdev, u16 *uid)
 	void *in;
 	int err;
 
+	if (MLX5_CAP_GEN(mvdev->mdev, umem_uid_0))
+		return 0;
+
 	/* 0 means not supported */
 	if (!MLX5_CAP_GEN(mvdev->mdev, log_max_uctx))
 		return -EOPNOTSUPP;
@@ -79,6 +82,9 @@ static void destroy_uctx(struct mlx5_vdpa_dev *mvdev, u32 uid)
 	u32 out[MLX5_ST_SZ_DW(destroy_uctx_out)] = {};
 	u32 in[MLX5_ST_SZ_DW(destroy_uctx_in)] = {};
 
+	if (!uid)
+		return;
+
 	MLX5_SET(destroy_uctx_in, in, opcode, MLX5_CMD_OP_DESTROY_UCTX);
 	MLX5_SET(destroy_uctx_in, in, uid, uid);
 
include/linux/mlx5/mlx5_ifc.h +3 -1
index 9c68b2da14c6..606d2aeacad4 100644
@@ -1487,7 +1487,9 @@ struct mlx5_ifc_cmd_hca_cap_bits {
 	u8         uar_4k[0x1];
 	u8         reserved_at_241[0x9];
 	u8         uar_sz[0x6];
-	u8         reserved_at_250[0x8];
+	u8         reserved_at_248[0x2];
+	u8         umem_uid_0[0x1];
+	u8         reserved_at_250[0x5];
 	u8         log_pg_sz[0x8];
 
 	u8         bf[0x1];
Signature · 1 line
2.31.1