Skip to contentSkip to conversation

vmw_pvrdma: Avoid rounding up of sge count to power of 2

PATCH In review Adit Ranadive 3 participants 5 messages Feb 16, 2018 3 messages not in the archive InfiniBand

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vmw_pvrdma: Avoid rounding up of sge count to power of 2

Creation of resources can fail if the rounding up exceeds provider supported values.

Fixes 4c8ed14eb6b7 ("vmw_pvrdma: Add SRQ support")
---
 providers/vmw_pvrdma/qp.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
providers/vmw_pvrdma/qp.c +3 -5
index efcc99b..4b9f897 100644
@@ -113,7 +113,7 @@ struct ibv_srq *pvrdma_create_srq(struct ibv_pd *pd,
 	int ret;
 
 	attr->attr.max_wr = align_next_power2(max_t(uint32_t, 1U, attr->attr.max_wr));
-	attr->attr.max_sge = align_next_power2(max_t(uint32_t, 1U, attr->attr.max_sge));
+	attr->attr.max_sge = max_t(uint32_t, 1U, attr->attr.max_sge);
 
 	srq = malloc(sizeof(*srq));
 	if (!srq)
@@ -216,14 +216,12 @@ struct ibv_qp *pvrdma_create_qp(struct ibv_pd *pd,
 	int ret;
 	int is_srq = !!(attr->srq);
 
-	attr->cap.max_send_sge =
-		align_next_power2(max_t(uint32_t, 1U, attr->cap.max_send_sge));
+	attr->cap.max_send_sge = max_t(uint32_t, 1U, attr->cap.max_send_sge);
 	attr->cap.max_send_wr =
 		align_next_power2(max_t(uint32_t, 1U, attr->cap.max_send_wr));
 
 	if (!is_srq) {
-		attr->cap.max_recv_sge =
-			align_next_power2(max_t(uint32_t, 1U, attr->cap.max_recv_sge));
+		attr->cap.max_recv_sge = max_t(uint32_t, 1U, attr->cap.max_recv_sge);
 		attr->cap.max_recv_wr =
 			align_next_power2(max_t(uint32_t, 1U, attr->cap.max_recv_wr));
 	} else {
Signature · 6 lines
2.7.4

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

A message that is not in the archive (sent off-list or not yet received): 1518741592-12723-1-git-send-email-aditr-pghWNbHTmq7QT0dZR+AlfA@public.gmane.org

#2 lore raw
Quoted 17 lines · Adit Ranadive

Creation of resources can fail if the rounding up exceeds provider supported values.

Fixes 4c8ed14eb6b7 ("vmw_pvrdma: Add SRQ support")
---
 providers/vmw_pvrdma/qp.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
providers/vmw_pvrdma/qp.c +0 -0
index efcc99b..4b9f897 100644

providers/vmw_pvrdma/qp.c struct ibv_srq *pvrdma_create_srq(struct ibv_pd *pd, · line 116

Quoted 5 lines
providers/vmw_pvrdma/qp.c +1 -1
@@ -113,7 +113,7 @@ struct ibv_srq *pvrdma_create_srq(struct ibv_pd *pd,
 	int ret;
 
 	attr->attr.max_wr = align_next_power2(max_t(uint32_t, 1U, attr->attr.max_wr));
-	attr->attr.max_sge = align_next_power2(max_t(uint32_t, 1U, attr->attr.max_sge));
+	attr->attr.max_sge = max_t(uint32_t, 1U, attr->attr.max_sge);

One of two: or your commit message is not correct and you should mention that align_next_power2() is not needed, or your code is incorrect, because user can provide large enough number and this call will fail anyway.

Quoted 27 lines
providers/vmw_pvrdma/qp.c +2 -5
 	srq = malloc(sizeof(*srq));
 	if (!srq)
@@ -216,14 +216,12 @@ struct ibv_qp *pvrdma_create_qp(struct ibv_pd *pd,
 	int ret;
 	int is_srq = !!(attr->srq);
 
-	attr->cap.max_send_sge =
-		align_next_power2(max_t(uint32_t, 1U, attr->cap.max_send_sge));
+	attr->cap.max_send_sge = max_t(uint32_t, 1U, attr->cap.max_send_sge);
 	attr->cap.max_send_wr =
 		align_next_power2(max_t(uint32_t, 1U, attr->cap.max_send_wr));
 
 	if (!is_srq) {
-		attr->cap.max_recv_sge =
-			align_next_power2(max_t(uint32_t, 1U, attr->cap.max_recv_sge));
+		attr->cap.max_recv_sge = max_t(uint32_t, 1U, attr->cap.max_recv_sge);
 		attr->cap.max_recv_wr =
 			align_next_power2(max_t(uint32_t, 1U, attr->cap.max_recv_wr));
 	} else {
--

2.7.4

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

A message that is not in the archive (sent off-list or not yet received): 20180216072216.GK2197-U/[email protected]

#4 lore raw
Quoted 20 lines · Leon Romanovsky
Quoted 19 lines · Adit Ranadive

Creation of resources can fail if the rounding up exceeds provider supported values.

Fixes 4c8ed14eb6b7 ("vmw_pvrdma: Add SRQ support")
---
 providers/vmw_pvrdma/qp.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
providers/vmw_pvrdma/qp.c +0 -0
index efcc99b..4b9f897 100644
@@ -113,7 +113,7 @@ struct ibv_srq *pvrdma_create_srq(struct ibv_pd *pd,
 	int ret;
 
Quoted 8 lines

providers/vmw_pvrdma/qp.c struct ibv_srq *pvrdma_create_srq(struct ibv_pd *pd, · line 116

Quoted 3 lines
providers/vmw_pvrdma/qp.c +1 -1
 	attr->attr.max_wr = align_next_power2(max_t(uint32_t, 1U, attr->attr.max_wr));
-	attr->attr.max_sge = align_next_power2(max_t(uint32_t, 1U, attr->attr.max_sge));
+	attr->attr.max_sge = max_t(uint32_t, 1U, attr->attr.max_sge);

One of two: or your commit message is not correct and you should mention that align_next_power2() is not needed, or your code is incorrect, because user can provide large enough number and this call will fail anyway.

Sorry, that's a terrible commit message. Yeah the align_next_power2 is extraneous. Will send v1 out with updated message.
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#5 lore raw
In reply to a message not in the archive
Quoted 15 lines · Adit Ranadive

Creation of resources can fail if the rounding up exceeds provider supported values.

Fixes 4c8ed14eb6b7 ("vmw_pvrdma: Add SRQ support")
 providers/vmw_pvrdma/qp.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
providers/vmw_pvrdma/qp.c +1 -0
index efcc99b..4b9f897 100644
+++ b/providers/vmw_pvrdma/qp.c

providers/vmw_pvrdma/qp.c struct ibv_srq *pvrdma_create_srq(struct ibv_pd *pd, · line 116

Quoted 5 lines
providers/vmw_pvrdma/qp.c +1 -1
@@ -113,7 +113,7 @@ struct ibv_srq *pvrdma_create_srq(struct ibv_pd *pd,
 	int ret;
 
 	attr->attr.max_wr = align_next_power2(max_t(uint32_t, 1U, attr->attr.max_wr));
-	attr->attr.max_sge = align_next_power2(max_t(uint32_t, 1U, attr->attr.max_sge));
+	attr->attr.max_sge = max_t(uint32_t, 1U, attr->attr.max_sge);

What is with all these max's? If the user provides <= 0 for these values it should be EINVAL, not round up.

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

A message that is not in the archive (sent off-list or not yet received): 20180216161526.GC22739-uk2M96/[email protected]

#7 lore raw
Quoted 18 lines · Jason Gunthorpe
Quoted 17 lines · Adit Ranadive

Creation of resources can fail if the rounding up exceeds provider supported values.

Fixes 4c8ed14eb6b7 ("vmw_pvrdma: Add SRQ support")
 providers/vmw_pvrdma/qp.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
providers/vmw_pvrdma/qp.c +1 -0
index efcc99b..4b9f897 100644
+++ b/providers/vmw_pvrdma/qp.c
@@ -113,7 +113,7 @@ struct ibv_srq *pvrdma_create_srq(struct ibv_pd *pd,
 	int ret;
 
Quoted 6 lines

providers/vmw_pvrdma/qp.c struct ibv_srq *pvrdma_create_srq(struct ibv_pd *pd, · line 116

Quoted 3 lines
providers/vmw_pvrdma/qp.c +1 -1
 	attr->attr.max_wr = align_next_power2(max_t(uint32_t, 1U, attr->attr.max_wr));
-	attr->attr.max_sge = align_next_power2(max_t(uint32_t, 1U, attr->attr.max_sge));
+	attr->attr.max_sge = max_t(uint32_t, 1U, attr->attr.max_sge);

What is with all these max's? If the user provides <= 0 for these values it should be EINVAL, not round up.

SRQ attributes are uint32_t, user can't provide negative values.

680 struct ibv_srq_attr {

 681         uint32_t                max_wr;
 682         uint32_t                max_sge;
 683         uint32_t                srq_limit;

684 };

Thanks

Quoted 6 lines

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