From patchwork Wed Jun 24 09:35:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ferruh Yigit X-Patchwork-Id: 72102 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 883F8A0350; Wed, 24 Jun 2020 11:35:30 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 021281D8F8; Wed, 24 Jun 2020 11:35:30 +0200 (CEST) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id 06A7B1D8EE for ; Wed, 24 Jun 2020 11:35:27 +0200 (CEST) IronPort-SDR: IAMppuJ5kAF4RvCoFij8G+0NeRZis6YdtITSD/HfBSIfIlxjtbpwoSzQfToaY3ICSU8h3m56K3 A0So3S80PRUw== X-IronPort-AV: E=McAfee;i="6000,8403,9661"; a="145897249" X-IronPort-AV: E=Sophos;i="5.75,274,1589266800"; d="scan'208";a="145897249" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jun 2020 02:35:23 -0700 IronPort-SDR: ZtfrQkHuVw29JXaVZwPZY18L69TNO7qImm7HcqAR0U7yk4+rmax/KTH2gU1klOeKOkYDafJCdI UbnlykZWisEw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,274,1589266800"; d="scan'208";a="479054428" Received: from silpixa00399752.ir.intel.com (HELO silpixa00399752.ger.corp.intel.com) ([10.237.222.180]) by fmsmga006.fm.intel.com with ESMTP; 24 Jun 2020 02:35:22 -0700 From: Ferruh Yigit To: Thomas Monjalon , Andrew Rybchenko Cc: dev@dpdk.org, Ferruh Yigit , Renata Saiakhova , Anatoly Burakov Date: Wed, 24 Jun 2020 10:35:20 +0100 Message-Id: <20200624093520.2142722-1-ferruh.yigit@intel.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200623164111.1939144-1-ferruh.yigit@intel.com> References: <20200623164111.1939144-1-ferruh.yigit@intel.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v2] ethdev: verify reserved HW ring X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 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" Function 'rte_eth_dma_zone_reserve()' returns an existing memzone based on name match, but other requested attributes are discarded. This may cause driver using a memzone with wrong size or alignment. Verify size, alignment and socket_id for matched memzone, and do not use memzone if any one of the attributes are not justified. It is possible to free the existing memzone and allocate again with the requested attributes but it is better caller do the explicit free. Reported-by: Renata Saiakhova Signed-off-by: Ferruh Yigit Reviewed-by: Andrew Rybchenko --- Cc: Anatoly Burakov v2: * Updated commit log related decision on not doing implicit free * Updated alignment check to make it more explicit --- lib/librte_ethdev/rte_ethdev.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c index 8e10a6fc3..d24db66fb 100644 --- a/lib/librte_ethdev/rte_ethdev.c +++ b/lib/librte_ethdev/rte_ethdev.c @@ -4202,8 +4202,18 @@ rte_eth_dma_zone_reserve(const struct rte_eth_dev *dev, const char *ring_name, } mz = rte_memzone_lookup(z_name); - if (mz) + if (mz) { + if ((socket_id != SOCKET_ID_ANY && socket_id != mz->socket_id) || + size > mz->len || + ((uintptr_t)mz->addr & (align - 1)) != 0) { + RTE_ETHDEV_LOG(ERR, + "memzone %s does not justify the requested attributes\n", + mz->name); + return NULL; + } + return mz; + } return rte_memzone_reserve_aligned(z_name, size, socket_id, RTE_MEMZONE_IOVA_CONTIG, align);