From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 4A5CAA0A0E; Wed, 12 May 2021 16:50:15 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 32CDD4003F; Wed, 12 May 2021 16:50:15 +0200 (CEST) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mails.dpdk.org (Postfix) with ESMTP id 1B6874003E for ; Wed, 12 May 2021 16:50:13 +0200 (CEST) IronPort-SDR: oM5irJY3fNLun03n46s3SRLI/FWfZ0+mLLniZ547cfxl4q+1g2kRwbE1znMpCYhqFo3iWQAGep GWDY5Cp24NaQ== X-IronPort-AV: E=McAfee;i="6200,9189,9982"; a="263650383" X-IronPort-AV: E=Sophos;i="5.82,293,1613462400"; d="scan'208";a="263650383" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 May 2021 07:50:12 -0700 IronPort-SDR: MH/C4F3wJmon6Cm9UcijeWHNq1MiXFTDvQOnrrUyt66lMu5rpv/6Mt1kB9WGOgEZ0QM4v2TsTL XXCaHs/2MYDg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,293,1613462400"; d="scan'208";a="537795895" Received: from silpixa00401026.ir.intel.com ([10.243.23.108]) by fmsmga001.fm.intel.com with ESMTP; 12 May 2021 07:50:11 -0700 From: Bruce Richardson To: dev@dpdk.org Cc: kevin.laatz@intel.com, Bruce Richardson , Jiayu Hu Date: Wed, 12 May 2021 14:49:59 +0000 Message-Id: <20210512145000.249215-1-bruce.richardson@intel.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH 1/2] raw/ioat: fix ring space checks X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 Signed-off-by: Bruce Richardson --- 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