DPDK patches and discussions
 help / color / mirror / Atom feed
From: Bruce Richardson <bruce.richardson@intel.com>
To: dev@dpdk.org
Cc: kevin.laatz@intel.com,
	Bruce Richardson <bruce.richardson@intel.com>,
	Jiayu Hu <jiayu.hu@intel.com>
Subject: [dpdk-dev] [PATCH 1/2] raw/ioat: fix ring space checks
Date: Wed, 12 May 2021 14:49:59 +0000	[thread overview]
Message-ID: <20210512145000.249215-1-bruce.richardson@intel.com> (raw)

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")

Reported-by: Jiayu Hu <jiayu.hu@intel.com>
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 drivers/raw/ioat/rte_idxd_rawdev_fns.h | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/raw/ioat/rte_idxd_rawdev_fns.h b/drivers/raw/ioat/rte_idxd_rawdev_fns.h
index 862e0eb41..6ed67d77e 100644
--- a/drivers/raw/ioat/rte_idxd_rawdev_fns.h
+++ b/drivers/raw/ioat/rte_idxd_rawdev_fns.h
@@ -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 */
-- 
2.30.2


             reply	other threads:[~2021-05-12 14:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-12 14:49 Bruce Richardson [this message]
2021-05-12 14:50 ` [dpdk-dev] [PATCH 2/2] raw/ioat: remove special case for no status reporting Bruce Richardson
2021-05-12 16:11   ` Laatz, Kevin
2021-05-12 18:49     ` Thomas Monjalon
2021-05-12 16:11 ` [dpdk-dev] [PATCH 1/2] raw/ioat: fix ring space checks Laatz, Kevin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210512145000.249215-1-bruce.richardson@intel.com \
    --to=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --cc=jiayu.hu@intel.com \
    --cc=kevin.laatz@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).