diff mbox series

[v2,3/4] dma/idxd: fix wrap-around in burst capacity calculation

Message ID 20220111134105.1007191-4-bruce.richardson@intel.com (mailing list archive)
State Accepted
Delegated to: Thomas Monjalon
Headers show
Series fixes for dma/idxd | expand

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Bruce Richardson Jan. 11, 2022, 1:41 p.m. UTC
The burst capacity calculation code assumes that the write and read
(i.e. ids_returned) values both wrap at the ring-size, but the read
value instead wraps as UINT16_MAX. Therefore, instead of just adding
ring-size to the write value in case the read is greater, we need to
just always mask the result to ensure a correct, in-range, value.

Fixes: 9459de4edc99 ("dma/idxd: add burst capacity")
Cc: kevin.laatz@intel.com
Cc: stable@dpdk.org

Reported-by: Sunil Pai G <sunil.pai.g@intel.com>
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 drivers/dma/idxd/idxd_common.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

Comments

Pai G, Sunil Jan. 11, 2022, 1:45 p.m. UTC | #1
Tested-by: Sunil Pai G <sunil.pai.g@intel.com>

<snipped>

Thanks and regards,
Sunil
Kevin Laatz Jan. 11, 2022, 4:50 p.m. UTC | #2
On 11/01/2022 13:41, Bruce Richardson wrote:
> The burst capacity calculation code assumes that the write and read
> (i.e. ids_returned) values both wrap at the ring-size, but the read
> value instead wraps as UINT16_MAX. Therefore, instead of just adding
> ring-size to the write value in case the read is greater, we need to
> just always mask the result to ensure a correct, in-range, value.
>
> Fixes: 9459de4edc99 ("dma/idxd: add burst capacity")
> Cc: kevin.laatz@intel.com
> Cc: stable@dpdk.org
>
> Reported-by: Sunil Pai G <sunil.pai.g@intel.com>
> Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
> ---
>   drivers/dma/idxd/idxd_common.c | 6 ++----
>   1 file changed, 2 insertions(+), 4 deletions(-)
>

Acked-by: Kevin Laatz <kevin.laatz@intel.com>
diff mbox series

Patch

diff --git a/drivers/dma/idxd/idxd_common.c b/drivers/dma/idxd/idxd_common.c
index 4442d1cbbd..ea6413cc7a 100644
--- a/drivers/dma/idxd/idxd_common.c
+++ b/drivers/dma/idxd/idxd_common.c
@@ -480,10 +480,8 @@  idxd_burst_capacity(const void *dev_private, uint16_t vchan __rte_unused)
 			idxd->batch_idx_write + 1 == idxd->batch_idx_read)
 		return 0;
 
-	/* For descriptors, check for wrap-around on write but not read */
-	if (idxd->ids_returned > write_idx)
-		write_idx += idxd->desc_ring_mask + 1;
-	used_space = write_idx - idxd->ids_returned;
+	/* Subtract and mask to get in correct range */
+	used_space = (write_idx - idxd->ids_returned) & idxd->desc_ring_mask;
 
 	const int ret = RTE_MIN((idxd->desc_ring_mask - used_space),
 			(idxd->max_batch_size - idxd->batch_size));