Skip to contentSkip to conversation

raw/ioat: fix ring space checks

PATCH In review Bruce Richardson 3 participants 5 messages May 12, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 raw/ioat: fix ring space checks

When enqueuing a descriptor, when checking that there is at least one slot free for the current descriptor and a later batch descriptor, we need to test for both two free and one free, in case the last write was a batch descriptor which is allowed to use the "spare" slot.

Similarly, when computing the free space in the ring to return to the user, we need to take account of the same condition, so that we do not return a "-1" ring space value, by blindly subtracting "2".

Fixes 245efe544d8e ("raw/ioat: report status of completed jobs")
---
 drivers/raw/ioat/rte_idxd_rawdev_fns.h | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/raw/ioat/rte_idxd_rawdev_fns.h +7 -3
index 862e0eb41..6ed67d77e 100644
@@ -132,7 +132,7 @@ __idxd_burst_capacity(int dev_id)
 	struct rte_idxd_rawdev *idxd =
 			(struct rte_idxd_rawdev *)rte_rawdevs[dev_id].dev_private;
 	uint16_t write_idx = idxd->batch_start + idxd->batch_size;
-	uint16_t used_space;
+	uint16_t used_space, free_space;
 
 	/* Check for space in the batch ring */
 	if ((idxd->batch_idx_read == 0 && idxd->batch_idx_write == idxd->max_batches) ||
@@ -147,7 +147,10 @@ __idxd_burst_capacity(int dev_id)
 	/* Return amount of free space in the descriptor ring
 	 * subtract 1 for space for batch descriptor and 1 for possible null desc
 	 */
-	return idxd->desc_ring_mask - used_space - 2;
+	free_space = idxd->desc_ring_mask - used_space;
+	if (free_space < 2)
+		return 0;
+	return free_space - 2;
 }
 
 static __rte_always_inline rte_iova_t
@@ -174,7 +177,8 @@ __idxd_write_desc(int dev_id,
 			idxd->batch_idx_write + 1 == idxd->batch_idx_read)
 		goto failed;
 	/* for descriptor ring, we always need a slot for batch completion */
-	if (((write_idx + 2) & mask) == idxd->hdls_read)
+	if (((write_idx + 2) & mask) == idxd->hdls_read ||
+			((write_idx + 1) & mask) == idxd->hdls_read)
 		goto failed;
 
 	/* write desc and handle. Note, descriptors don't wrap */
Signature · 1 line
2.30.2
#1 lore raw

PATCH 2/2 raw/ioat: remove special case for no status reporting

The special fast-path for returning completed descriptors without reporting status or user-handles returns the number of completed ring slots used, rather than the number of actual user-submitted jobs. This means that the counts returned are too high, as the batch descriptor slots would be included in the total. Therefore remove this special case, and use the normal status-processing path so that the returned count is correct in all cases.

Fixes 245efe544d8e ("raw/ioat: report status of completed jobs")
---
 drivers/raw/ioat/rte_idxd_rawdev_fns.h | 9 ---------
 1 file changed, 9 deletions(-)
drivers/raw/ioat/rte_idxd_rawdev_fns.h +0 -9
index 6ed67d77e..6c5334cb3 100644
@@ -343,14 +343,6 @@ __idxd_completed_ops(int dev_id, uint8_t max_ops, uint32_t *status, uint8_t *num
 			idxd->batch_idx_read = 0;
 	}
 
-	if (idxd->cfg.hdls_disable && status == NULL) {
-		n = (idxd->hdls_avail < idxd->hdls_read) ?
-				(idxd->hdls_avail + idxd->desc_ring_mask + 1 - idxd->hdls_read) :
-				(idxd->hdls_avail - idxd->hdls_read);
-		idxd->hdls_read = idxd->hdls_avail;
-		goto out;
-	}
-
 	n = 0;
 	h_idx = idxd->hdls_read;
 	while (h_idx != idxd->hdls_avail) {
@@ -386,7 +378,6 @@ __idxd_completed_ops(int dev_id, uint8_t max_ops, uint32_t *status, uint8_t *num
 	}
 	idxd->hdls_read = h_idx;
 
-out:
 	idxd->xstats.completed += n;
 	return n;
 }
Signature · 1 line
2.30.2
Acked-by on v1 2/2
#2 lore raw

Re: [dpdk-dev] [PATCH 2/2] raw/ioat: remove special case for no status reporting

Quoted 13 lines

The special fast-path for returning completed descriptors without reporting status or user-handles returns the number of completed ring slots used, rather than the number of actual user-submitted jobs. This means that the counts returned are too high, as the batch descriptor slots would be included in the total. Therefore remove this special case, and use the normal status-processing path so that the returned count is correct in all cases.

Fixes 245efe544d8e ("raw/ioat: report status of completed jobs")

---

<...>

#3 lore raw

Re: [dpdk-dev] [PATCH 2/2] raw/ioat: remove special case for no status reporting

Quoted 8 lines
Quoted 8 lines

The special fast-path for returning completed descriptors without reporting status or user-handles returns the number of completed ring slots used, rather than the number of actual user-submitted jobs. This means that the counts returned are too high, as the batch descriptor slots would be included in the total. Therefore remove this special case, and use the normal status-processing path so that the returned count is correct in all cases.

Quoted 6 lines
Quoted 4 lines
Fixes 245efe544d8e ("raw/ioat: report status of completed jobs")

Series applied, thanks

Acked-by on v1 1/2
#4 lore raw
In reply to Bruce Richardson
Quoted 14 lines

When enqueuing a descriptor, when checking that there is at least one slot free for the current descriptor and a later batch descriptor, we need to test for both two free and one free, in case the last write was a batch descriptor which is allowed to use the "spare" slot.

Similarly, when computing the free space in the ring to return to the user, we need to take account of the same condition, so that we do not return a "-1" ring space value, by blindly subtracting "2".

Fixes 245efe544d8e ("raw/ioat: report status of completed jobs")

---

<...>