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

Started by Jason Wang on May 31, 2021 · 2 messages from 1 author · Last reply May 31, 2021

open the first message on its own page

Message details and related content
在 2021/5/30 下午3:54, Eli Cohen 写道:
Currently all resources must be created with uid != 0 which is essential
userspace processes allocating virtquueue resources. Since this is a
kernel implementation, it is perfectly legal to open resources with
uid == 0.

In case frimware supports, avoid allocating user context.

Typo "frimware".

Otherwise.

Acked-by: Jason Wang <redacted>

(I don't see any code to check the firmware capability, is this intended?)

Thanks

quoted hunk
Signed-off-by: Eli Cohen <redacted>
---
  drivers/vdpa/mlx5/core/resources.c | 6 ++++++
  include/linux/mlx5/mlx5_ifc.h      | 4 +++-
  2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/drivers/vdpa/mlx5/core/resources.c b/drivers/vdpa/mlx5/core/resources.c
index 6521cbd0f5c2..836ab9ef0fa6 100644
--- a/drivers/vdpa/mlx5/core/resources.c
+++ b/drivers/vdpa/mlx5/core/resources.c
@@ -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);
  
diff --git a/include/linux/mlx5/mlx5_ifc.h b/include/linux/mlx5/mlx5_ifc.h
index 9c68b2da14c6..606d2aeacad4 100644
--- a/include/linux/mlx5/mlx5_ifc.h
+++ b/include/linux/mlx5/mlx5_ifc.h
@@ -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];

6 more quoted lines

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Message details and related content
在 2021/5/31 上午11:02, Jason Wang 写道:
在 2021/5/30 下午3:54, Eli Cohen 写道:
quoted
Currently all resources must be created with uid != 0 which is essential
userspace processes allocating virtquueue resources. Since this is a
kernel implementation, it is perfectly legal to open resources with
uid == 0.

In case frimware supports, avoid allocating user context.

Typo "frimware".

Otherwise.

Acked-by: Jason Wang <redacted>

(I don't see any code to check the firmware capability, is this intended?)

Speak too fast. I see the MLX5_CAP_GEN(), so it's fine.

Thanks

Thanks

quoted
Signed-off-by: Eli Cohen <redacted>
---
  drivers/vdpa/mlx5/core/resources.c | 6 ++++++
  include/linux/mlx5/mlx5_ifc.h      | 4 +++-
  2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/drivers/vdpa/mlx5/core/resources.c b/drivers/vdpa/mlx5/core/resources.c
index 6521cbd0f5c2..836ab9ef0fa6 100644
--- a/drivers/vdpa/mlx5/core/resources.c
+++ b/drivers/vdpa/mlx5/core/resources.c
@@ -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);
  diff --git a/include/linux/mlx5/mlx5_ifc.h b/include/linux/mlx5/mlx5_ifc.h
index 9c68b2da14c6..606d2aeacad4 100644
--- a/include/linux/mlx5/mlx5_ifc.h
+++ b/include/linux/mlx5/mlx5_ifc.h
@@ -1487,7 +1487,9 @@ struct mlx5_ifc_cmd_hca_cap_bits {
      u8         uar_4k[0x1];
      u8         reserved_at_241[0x9];
      u8         uar_sz[0x6];

6 more quoted lines

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help