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 69A05A034F; Tue, 11 Jan 2022 14:42:03 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4F46942709; Tue, 11 Jan 2022 14:42:03 +0100 (CET) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mails.dpdk.org (Postfix) with ESMTP id B3D3341143; Tue, 11 Jan 2022 14:42:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1641908521; x=1673444521; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Km6+KRQAQ5Va+gNSXtAiMWR8aiwowM9k/oDsf/gHcaI=; b=N6k8qv8zP7T95xSvFFLB64XIqkqUygnAZUkx97AJ0rhJOFLax8iZjVuR KpwI/vxTLgBQxiWhzzoEEMr0euHtwTVtp7q2+A7sZyftRpqzNOfZG500v cxINCFcla62ySgzKWNhhZiVTj5qGOghmkQpJsJaddfq/GF4Zshb2msuMQ tMdxrJRTJ0jlEnm7bONwb1YwFO2wexwJEpWeGUPKV08JDg1CtWDrJ3XiV UOfMYAcK8Z1uPaaXu6QAvNQPsUcupTHGswnOu5zi9pbIDcJ7F39g5/1Z3 83+2RHu24ZgngNuaabw1GJ/QrVUL9O3EjrQ5Cb1NwwmvcSKo3RqGj37Xx w==; X-IronPort-AV: E=McAfee;i="6200,9189,10223"; a="223467476" X-IronPort-AV: E=Sophos;i="5.88,279,1635231600"; d="scan'208";a="223467476" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jan 2022 05:41:59 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,279,1635231600"; d="scan'208";a="690997229" Received: from silpixa00399126.ir.intel.com ([10.237.223.86]) by orsmga005.jf.intel.com with ESMTP; 11 Jan 2022 05:41:57 -0800 From: Bruce Richardson To: dev@dpdk.org Cc: Bruce Richardson , kevin.laatz@intel.com, stable@dpdk.org, Sunil Pai G , Conor Walsh , Chengwen Feng Subject: [PATCH v2 3/4] dma/idxd: fix wrap-around in burst capacity calculation Date: Tue, 11 Jan 2022 13:41:04 +0000 Message-Id: <20220111134105.1007191-4-bruce.richardson@intel.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220111134105.1007191-1-bruce.richardson@intel.com> References: <20211220170514.736732-1-bruce.richardson@intel.com> <20220111134105.1007191-1-bruce.richardson@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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 Signed-off-by: Bruce Richardson --- drivers/dma/idxd/idxd_common.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) 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)); -- 2.32.0