[PATCH rdma-core 2/2] Enforce is_global if GRH required

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Artemy Kovalyov <artemyko@xxxxxxxxxxxx>

When IBV_PORT_GRH_REQUIRED port capability flag is set, the applications
must create all AH with GRH configured. This patch enforces the above
requirement for providers which implement the ibv_create_ah() verb in
user space, for others the kernel enforces that.

Signed-off-by: Artemy Kovalyov <artemyko@xxxxxxxxxxxx>
Signed-off-by: Yishai Hadas <yishaih@xxxxxxxxxxxx>
---
 providers/mlx4/verbs.c  | 4 ++++
 providers/mlx5/mlx5.c   | 5 ++++-
 providers/mlx5/mlx5.h   | 1 +
 providers/mlx5/verbs.c  | 6 +++++-
 providers/mthca/verbs.c | 8 ++++++++
 5 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/providers/mlx4/verbs.c b/providers/mlx4/verbs.c
index 495f84e..7f0c0ab 100644
--- a/providers/mlx4/verbs.c
+++ b/providers/mlx4/verbs.c
@@ -1328,6 +1328,10 @@ struct ibv_ah *mlx4_create_ah(struct ibv_pd *pd, struct ibv_ah_attr *attr)
 	if (query_port_cache(pd->context, attr->port_num, &port_attr))
 		return NULL;
 
+	if (port_attr.port_cap_flags & IBV_PORT_GRH_REQUIRED &&
+	    !attr->is_global)
+		return NULL;
+
 	ah = malloc(sizeof *ah);
 	if (!ah)
 		return NULL;
diff --git a/providers/mlx5/mlx5.c b/providers/mlx5/mlx5.c
index 5590241..5079dcd 100644
--- a/providers/mlx5/mlx5.c
+++ b/providers/mlx5/mlx5.c
@@ -1176,8 +1176,11 @@ static struct verbs_context *mlx5_alloc_context(struct ibv_device *ibdev,
 
 	for (j = 0; j < min(MLX5_MAX_PORTS_NUM, context->num_ports); ++j) {
 		memset(&port_attr, 0, sizeof(port_attr));
-		if (!mlx5_query_port(&v_ctx->context, j + 1, &port_attr))
+		if (!mlx5_query_port(&v_ctx->context, j + 1, &port_attr)) {
 			context->cached_link_layer[j] = port_attr.link_layer;
+			context->cached_port_flags[j] =
+				port_attr.port_cap_flags;
+		}
 	}
 
 	return v_ctx;
diff --git a/providers/mlx5/mlx5.h b/providers/mlx5/mlx5.h
index d3f0829..546d3a6 100644
--- a/providers/mlx5/mlx5.h
+++ b/providers/mlx5/mlx5.h
@@ -269,6 +269,7 @@ struct mlx5_context {
 	struct list_head                hugetlb_list;
 	int				cqe_version;
 	uint8_t				cached_link_layer[MLX5_MAX_PORTS_NUM];
+	uint32_t			cached_port_flags[MLX5_MAX_PORTS_NUM];
 	unsigned int			cached_device_cap_flags;
 	enum ibv_atomic_cap		atomic_cap;
 	struct {
diff --git a/providers/mlx5/verbs.c b/providers/mlx5/verbs.c
index 6ed2c35..70c6af9 100644
--- a/providers/mlx5/verbs.c
+++ b/providers/mlx5/verbs.c
@@ -2211,6 +2211,7 @@ struct ibv_ah *mlx5_create_ah(struct ibv_pd *pd, struct ibv_ah_attr *attr)
 	__be32 tmp;
 	uint8_t grh;
 	int is_eth;
+	int grh_req;
 
 	if (attr->port_num < 1 || attr->port_num > ctx->num_ports)
 		return NULL;
@@ -2218,14 +2219,17 @@ struct ibv_ah *mlx5_create_ah(struct ibv_pd *pd, struct ibv_ah_attr *attr)
 	if (ctx->cached_link_layer[attr->port_num - 1]) {
 		is_eth = ctx->cached_link_layer[attr->port_num - 1] ==
 			IBV_LINK_LAYER_ETHERNET;
+		grh_req = ctx->cached_port_flags[attr->port_num - 1] &
+			IBV_PORT_GRH_REQUIRED;
 	} else {
 		if (ibv_query_port(pd->context, attr->port_num, &port_attr))
 			return NULL;
 
 		is_eth = (port_attr.link_layer == IBV_LINK_LAYER_ETHERNET);
+		grh_req = (port_attr.port_cap_flags & IBV_PORT_GRH_REQUIRED);
 	}
 
-	if (unlikely((!attr->is_global) && is_eth)) {
+	if (unlikely((!attr->is_global) && (is_eth || grh_req))) {
 		errno = EINVAL;
 		return NULL;
 	}
diff --git a/providers/mthca/verbs.c b/providers/mthca/verbs.c
index ebe804a..014733f 100644
--- a/providers/mthca/verbs.c
+++ b/providers/mthca/verbs.c
@@ -709,6 +709,14 @@ int mthca_destroy_qp(struct ibv_qp *qp)
 struct ibv_ah *mthca_create_ah(struct ibv_pd *pd, struct ibv_ah_attr *attr)
 {
 	struct mthca_ah *ah;
+	struct ibv_port_attr port_attr;
+
+	if (mthca_query_port(pd->context, attr->port_num, &port_attr))
+		return NULL;
+
+	if (port_attr.port_cap_flags & IBV_PORT_GRH_REQUIRED &&
+	    !attr->is_global)
+		return NULL;
 
 	ah = malloc(sizeof *ah);
 	if (!ah)
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Yosemite Photos]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux