Skip to contentSkip to conversation

providers/rxe: Replace '%' with '&' in check_qp_queue_full()

PATCH RESEND Superseded Xiao Yang 3 participants 9 messages Jan 11, 2022 – Jan 18, 2022 InfiniBand

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Xiao Yang

author
#0 lore raw

PATCH RESEND 1/1 providers/rxe: Replace '%' with '&' in check_qp_queue_full()

The expression "cons == ((qp->cur_index + 1) % q->index_mask)" mistakenly assumes the queue is full when the number of entires is equal to "maximum - 1" (maximum is correct).

For example:
If cons and qp->cur_index are 0 and q->index_mask is 1, check_qp_queue_full() reports ENOSPC.

Fixes 1a894ca10105 ("Providers/rxe: Implement ibv_create_qp_ex verb")
---
 providers/rxe/rxe_queue.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
providers/rxe/rxe_queue.h +1 -1
index 6de8140c..708e76ac 100644
@@ -205,7 +205,7 @@ static inline int check_qp_queue_full(struct rxe_qp *qp)
 	if (qp->err)
 		goto err;
 
-	if (cons == ((qp->cur_index + 1) % q->index_mask))
+	if (cons == ((qp->cur_index + 1) & q->index_mask))
 		qp->err = ENOSPC;
 err:
 	return qp->err;
Signature · 1 line
2.25.1
#1 lore raw
Quoted 30 lines

-----Original Message-----
From: Xiao Yang <[email protected]>
Sent: Tuesday, January 11, 2022 7:54 AM
To: [email protected]; [email protected]
Cc: [email protected]; Xiao Yang <[email protected]>
Subject: [PATCH rdma-core RESEND] providers/rxe: Replace '%' with '&' in check_qp_queue_full()

The expression "cons == ((qp->cur_index + 1) % q->index_mask)" mistakenly assumes the queue is full when the number of entires is equal to "maximum
- 1"
(maximum is correct).

For example:
If cons and qp->cur_index are 0 and q->index_mask is 1, check_qp_queue_full() reports ENOSPC.

Fixes 1a894ca10105 ("Providers/rxe: Implement ibv_create_qp_ex verb")
---
 providers/rxe/rxe_queue.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
providers/rxe/rxe_queue.h index renamed from providers/rxe/rxe_queue.h +0 -0

6de8140c..708e76ac 100644

providers/rxe/rxe_queue.h static inline int check_qp_queue_full(struct rxe_qp · line 209

Quoted 6 lines
providers/rxe/rxe_queue.h +1 -1
@@ -205,7 +205,7 @@ static inline int check_qp_queue_full(struct rxe_qp
 *qp)
 	if (qp->err)
 		goto err;
 
-	if (cons == ((qp->cur_index + 1) % q->index_mask))
+	if (cons == ((qp->cur_index + 1) & q->index_mask))

Are you sure that index_mask would always be aligned with 2^X?

Quoted 7 lines
providers/rxe/rxe_queue.h +0 -0
 		qp->err = ENOSPC;
 err:

return qp->err;
--
2.25.1

#2 lore raw
Quoted 33 lines · Devesh Sharma
Quoted 33 lines

-----Original Message-----
From: Xiao Yang<[email protected]>
Sent: Tuesday, January 11, 2022 7:54 AM
To: [email protected]; [email protected]
Cc: [email protected]; Xiao Yang<[email protected]>
Subject: [PATCH rdma-core RESEND] providers/rxe: Replace '%' with '&' in check_qp_queue_full()

The expression "cons == ((qp->cur_index + 1) % q->index_mask)" mistakenly assumes the queue is full when the number of entires is equal to "maximum
- 1"
(maximum is correct).

For example:
If cons and qp->cur_index are 0 and q->index_mask is 1, check_qp_queue_full() reports ENOSPC.

Fixes 1a894ca10105 ("Providers/rxe: Implement ibv_create_qp_ex verb")
---
  providers/rxe/rxe_queue.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
providers/rxe/rxe_queue.h index renamed from providers/rxe/rxe_queue.h +0 -0

6de8140c..708e76ac 100644

providers/rxe/rxe_queue.h +0 -0
@@ -205,7 +205,7 @@ static inline int check_qp_queue_full(struct rxe_qp
 *qp)
  	if (qp->err)
  		goto err;
 
Quoted 3 lines

providers/rxe/rxe_queue.h static inline int check_qp_queue_full(struct rxe_qp · line 209

Quoted 2 lines
providers/rxe/rxe_queue.h +1 -1
-	if (cons == ((qp->cur_index + 1) % q->index_mask))
+	if (cons == ((qp->cur_index + 1)&  q->index_mask))

Are you sure that index_mask would always be aligned with 2^X?

Hi Deves,

I think it is. index_mask is alwasy set to 2^X -1 in kernel:
----------------------------------------------------------------
struct rxe_queue *rxe_queue_init(struct rxe_dev *rxe, int *num_elem,
unsigned int elem_size, enum queue_type type)

{
     ...
     num_slots = *num_elem + 1;
     num_slots = roundup_pow_of_two(num_slots);
     q->index_mask = num_slots - 1;
     ...
}

----------------------------------------------------------------

Best Regards,
Xiao Yang

Quoted 7 lines
Quoted 7 lines
providers/rxe/rxe_queue.h +0 -0
  		qp->err = ENOSPC;
  err:

return qp->err;
--
2.25.1

Reviewed-by
#3 lore raw
Quoted 48 lines

-----Original Message-----
From: [email protected] <[email protected]>
Sent: Tuesday, January 11, 2022 2:41 PM
To: Devesh Sharma <[email protected]>
Cc: [email protected]; [email protected]; [email protected]
Subject: [External] : Re: [PATCH rdma-core RESEND] providers/rxe: Replace '%' with '&' in check_qp_queue_full()

Quoted 37 lines · Devesh Sharma
Quoted 37 lines

-----Original Message-----
From: Xiao Yang<[email protected]>
Sent: Tuesday, January 11, 2022 7:54 AM
To: [email protected]; [email protected]
Cc: [email protected]; Xiao Yang<[email protected]>
Subject: [PATCH rdma-core RESEND] providers/rxe: Replace '%' with '&' in
check_qp_queue_full()

The expression "cons == ((qp->cur_index + 1) % q->index_mask)" mistakenly assumes the queue is full when the number of entires is equal to "maximum
- 1"
(maximum is correct).

For example:
If cons and qp->cur_index are 0 and q->index_mask is 1, check_qp_queue_full() reports ENOSPC.

Fixes 1a894ca10105 ("Providers/rxe: Implement ibv_create_qp_ex

verb")

---
  providers/rxe/rxe_queue.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
providers/rxe/rxe_queue.h +0 -0
index 6de8140c..708e76ac 100644
@@ -205,7 +205,7 @@ static inline int check_qp_queue_full(struct

rxe_qp
*qp)
if (qp->err)
goto err;

Quoted 6 lines
Quoted 3 lines

providers/rxe/rxe_queue.h

Quoted 2 lines
providers/rxe/rxe_queue.h +1 -1
-	if (cons == ((qp->cur_index + 1) % q->index_mask))
+	if (cons == ((qp->cur_index + 1)&  q->index_mask))

Are you sure that index_mask would always be aligned with 2^X?

Hi Deves,

I think it is. index_mask is alwasy set to 2^X -1 in kernel:

Cool looks good, other than comments from Leon.

Quoted 20 lines

----------------------------------------------------------------
struct rxe_queue *rxe_queue_init(struct rxe_dev *rxe, int *num_elem,

                         unsigned int elem_size, enum queue_type type) {
     ...
     num_slots = *num_elem + 1;
     num_slots = roundup_pow_of_two(num_slots);
     q->index_mask = num_slots - 1;
     ...
}

----------------------------------------------------------------

Best Regards,
Xiao Yang

Quoted 7 lines
Quoted 7 lines

qp->err = ENOSPC;
err:
return qp->err;
--
2.25.1

#4 lore raw
In reply to Xiao Yang
Quoted 19 lines · Xiao Yang

The expression "cons == ((qp->cur_index + 1) % q->index_mask)" mistakenly assumes the queue is full when the number of entires is equal to "maximum - 1" (maximum is correct).

For example:
If cons and qp->cur_index are 0 and q->index_mask is 1, check_qp_queue_full() reports ENOSPC.

Fixes 1a894ca10105 ("Providers/rxe: Implement ibv_create_qp_ex verb")
---
 providers/rxe/rxe_queue.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
providers/rxe/rxe_queue.h +0 -0
index 6de8140c..708e76ac 100644

providers/rxe/rxe_queue.h static inline int check_qp_queue_full(struct rxe_qp *qp) · line 208

Quoted 5 lines
providers/rxe/rxe_queue.h +1 -1
@@ -205,7 +205,7 @@ static inline int check_qp_queue_full(struct rxe_qp *qp)
 	if (qp->err)
 		goto err;
 
-	if (cons == ((qp->cur_index + 1) % q->index_mask))
+	if (cons == ((qp->cur_index + 1) & q->index_mask))

Please reuse queue_full().

Thanks

Quoted 8 lines
providers/rxe/rxe_queue.h +0 -0
 		qp->err = ENOSPC;
 err:
 	return qp->err;
Signature · 1 line
2.25.1
#5 lore raw
Quoted 23 lines · Leon Romanovsky
Quoted 22 lines · Xiao Yang

The expression "cons == ((qp->cur_index + 1) % q->index_mask)" mistakenly assumes the queue is full when the number of entires is equal to "maximum - 1" (maximum is correct).

For example:
If cons and qp->cur_index are 0 and q->index_mask is 1, check_qp_queue_full() reports ENOSPC.

Fixes 1a894ca10105 ("Providers/rxe: Implement ibv_create_qp_ex verb")
---
  providers/rxe/rxe_queue.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
providers/rxe/rxe_queue.h +0 -0
index 6de8140c..708e76ac 100644
@@ -205,7 +205,7 @@ static inline int check_qp_queue_full(struct rxe_qp *qp)
  	if (qp->err)
  		goto err;
 
Quoted 3 lines

providers/rxe/rxe_queue.h static inline int check_qp_queue_full(struct rxe_qp *qp) · line 208

Quoted 2 lines
providers/rxe/rxe_queue.h +1 -1
-	if (cons == ((qp->cur_index + 1) % q->index_mask))
+	if (cons == ((qp->cur_index + 1)&  q->index_mask))

Please reuse queue_full().

Hi Leon,

qp->cur_index and qp->err are introduced for new ibv_wr_* APIs and I am not sure if check_qp_queue_full() can be replaced with queue_full().

Bob, do you have any suggestion?

Best Regards,
Xiao Yang

Quoted 10 lines

Thanks

Quoted 8 lines
providers/rxe/rxe_queue.h +0 -0
  		qp->err = ENOSPC;
  err:
  	return qp->err;
Signature · 1 line
2.25.1
#6 lore raw
Quoted 27 lines · On Tue, Jan 11, 2022 at 09:19:46AM +0000, [email protected] wrote:
Quoted 23 lines · Leon Romanovsky
Quoted 22 lines · Xiao Yang

The expression "cons == ((qp->cur_index + 1) % q->index_mask)" mistakenly assumes the queue is full when the number of entires is equal to "maximum - 1" (maximum is correct).

For example:
If cons and qp->cur_index are 0 and q->index_mask is 1, check_qp_queue_full() reports ENOSPC.

Fixes 1a894ca10105 ("Providers/rxe: Implement ibv_create_qp_ex verb")
---
  providers/rxe/rxe_queue.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
providers/rxe/rxe_queue.h +0 -0
index 6de8140c..708e76ac 100644
@@ -205,7 +205,7 @@ static inline int check_qp_queue_full(struct rxe_qp *qp)
  	if (qp->err)
  		goto err;
 
Quoted 3 lines

providers/rxe/rxe_queue.h static inline int check_qp_queue_full(struct rxe_qp *qp) · line 208

Quoted 2 lines
providers/rxe/rxe_queue.h +1 -1
-	if (cons == ((qp->cur_index + 1) % q->index_mask))
+	if (cons == ((qp->cur_index + 1)&  q->index_mask))

Please reuse queue_full().

Quoted 6 lines

Hi Leon,

qp->cur_index and qp->err are introduced for new ibv_wr_* APIs and I am not sure if check_qp_queue_full() can be replaced with queue_full().

Bob, do you have any suggestion?

providers/rxe/rxe_queue.h +1 -4
index 6de8140c..83eb4a5f 100644
@@ -198,14 +198,11 @@ static inline void advance_qp_cur_index(struct rxe_qp *qp)
 static inline int check_qp_queue_full(struct rxe_qp *qp)
 {
        struct rxe_queue_buf *q = qp->sq.queue;
-       uint32_t cons;
-
-       cons = atomic_load_explicit(consumer(q), memory_order_acquire);
 
        if (qp->err)
                goto err;
 
-       if (cons == ((qp->cur_index + 1) % q->index_mask))
+       if (queue_full(q))
                qp->err = ENOSPC;
 err:
        return qp->err;

(END)

Quoted 13 lines

Best Regards,
Xiao Yang

Quoted 10 lines

Thanks

Quoted 8 lines
providers/rxe/rxe_queue.h +0 -0
  		qp->err = ENOSPC;
  err:
  	return qp->err;
Signature · 1 line
2.25.1
#7 lore raw
Quoted 55 lines · Leon Romanovsky
Quoted 33 lines · On Tue, Jan 11, 2022 at 09:19:46AM +0000, [email protected] wrote:
Quoted 23 lines · Leon Romanovsky
Quoted 22 lines · Xiao Yang

The expression "cons == ((qp->cur_index + 1) % q->index_mask)" mistakenly assumes the queue is full when the number of entires is equal to "maximum - 1" (maximum is correct).

For example:
If cons and qp->cur_index are 0 and q->index_mask is 1, check_qp_queue_full() reports ENOSPC.

Fixes 1a894ca10105 ("Providers/rxe: Implement ibv_create_qp_ex verb")
---
   providers/rxe/rxe_queue.h | 2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
providers/rxe/rxe_queue.h +0 -0
index 6de8140c..708e76ac 100644
@@ -205,7 +205,7 @@ static inline int check_qp_queue_full(struct rxe_qp *qp)
   	if (qp->err)
   		goto err;
 
Quoted 3 lines

providers/rxe/rxe_queue.h static inline int check_qp_queue_full(struct rxe_qp *qp) · line 208

Quoted 2 lines
providers/rxe/rxe_queue.h +1 -1
-	if (cons == ((qp->cur_index + 1) % q->index_mask))
+	if (cons == ((qp->cur_index + 1)&   q->index_mask))

Please reuse queue_full().

Hi Leon,

qp->cur_index and qp->err are introduced for new ibv_wr_* APIs and I am not sure if check_qp_queue_full() can be replaced with queue_full().

Bob, do you have any suggestion?

providers/rxe/rxe_queue.h +1 -4
index 6de8140c..83eb4a5f 100644
@@ -198,14 +198,11 @@ static inline void advance_qp_cur_index(struct rxe_qp *qp)
  static inline int check_qp_queue_full(struct rxe_qp *qp)
  {
         struct rxe_queue_buf *q = qp->sq.queue;
-       uint32_t cons;
-
-       cons = atomic_load_explicit(consumer(q), memory_order_acquire);
 
         if (qp->err)
                 goto err;
 
-       if (cons == ((qp->cur_index + 1) % q->index_mask))
+       if (queue_full(q))
                 qp->err = ENOSPC;
  err:
         return qp->err;
Quoted 2 lines

(END)

Hi Leon,

This change using q->producer_index makes qp->cur_index unused. According to commit 1a894ca10105, qp->cur_index and related functions (advance_qp_cur_index() , check_qp_queue_full()) are introduced for ibv_wr_* APIs on purpose.
I am not sure if we can replace qp->cur_index with q->producer_index directly. I think we need Bob to confirm it.
By the way, could we just fix the issue here?

Best Regards,
Xiao Yang

Quoted 12 lines
Quoted 12 lines

Best Regards,
Xiao Yang

Quoted 10 lines

Thanks

Quoted 8 lines
providers/rxe/rxe_queue.h +0 -0
   		qp->err = ENOSPC;
   err:
   	return qp->err;
Signature · 1 line
2.25.1
#8 lore raw
In reply to Xiao Yang
Quoted 7 lines · Xiao Yang

The expression "cons == ((qp->cur_index + 1) % q->index_mask)" mistakenly assumes the queue is full when the number of entires is equal to "maximum - 1" (maximum is correct).

For example:
If cons and qp->cur_index are 0 and q->index_mask is 1, check_qp_queue_full() reports ENOSPC.wrote

Hi Bob,

I think the commit message also misled you.

The expression "cons == ((qp->cur_index + 1) % q->index_mask)" mistakenly
assumes the queue is full when we create an empty two-slots queue (i.e. cur_index = 0 and cons = 0)

Best Regards,
Xiao Yang