From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 7CA4A2BD9 for ; Fri, 22 Jul 2016 16:38:39 +0200 (CEST) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP; 22 Jul 2016 07:38:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.28,405,1464678000"; d="scan'208";a="143830989" Received: from irsmsx102.ger.corp.intel.com ([163.33.3.155]) by fmsmga004.fm.intel.com with ESMTP; 22 Jul 2016 07:38:26 -0700 Received: from irsmsx109.ger.corp.intel.com ([169.254.13.24]) by IRSMSX102.ger.corp.intel.com ([169.254.2.123]) with mapi id 14.03.0248.002; Fri, 22 Jul 2016 15:38:09 +0100 From: "Jastrzebski, MichalX K" To: "Gonzalez Monroy, Sergio" , "Richardson, Bruce" CC: "dev@dpdk.org" , "Kobylinski, MichalX" , "david.marchand@6wind.com" Thread-Topic: [PATCH] eal: fix check number of bytes from read function Thread-Index: AQHR411rWKJvmkYRukiO3ENzmqiIO6AkhkWg Date: Fri, 22 Jul 2016 14:38:08 +0000 Message-ID: <60ABE07DBB3A454EB7FAD707B4BB158213AC7FAA@IRSMSX109.ger.corp.intel.com> References: <1469024689-1076-1-git-send-email-michalx.k.jastrzebski@intel.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [163.33.239.181] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH] eal: fix check number of bytes from read function X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Jul 2016 14:38:40 -0000 > -----Original Message----- > From: Gonzalez Monroy, Sergio > Sent: Thursday, July 21, 2016 4:37 PM > To: Jastrzebski, MichalX K ; Richardson, > Bruce > Cc: dev@dpdk.org; Kobylinski, MichalX ; > david.marchand@6wind.com > Subject: Re: [PATCH] eal: fix check number of bytes from read function >=20 > On 20/07/2016 15:24, Michal Jastrzebski wrote: > > In rte_mem_virt2phy: Value returned from a function and indicating the > > number of bytes was ignored. This could cause a wrong pfn (page frame > > number) mask read from pagemap file. > > When read returns less than the number of sizeof(uint64_t) bytes, > > function rte_mem_virt2phy returns error. > > > > Coverity issue: 13212 > > Fixes: 40b966a211ab ("ivshmem: library changes for mmaping using > > ivshmem"). > > > > Signed-off-by: Michal Jastrzebski > > --- > > lib/librte_eal/linuxapp/eal/eal_memory.c | 12 ++++++++++-- > > 1 file changed, 10 insertions(+), 2 deletions(-) > > > > diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c > b/lib/librte_eal/linuxapp/eal/eal_memory.c > > index 42a29fa..05769fb 100644 > > --- a/lib/librte_eal/linuxapp/eal/eal_memory.c > > +++ b/lib/librte_eal/linuxapp/eal/eal_memory.c > > @@ -158,7 +158,7 @@ rte_mem_lock_page(const void *virt) > > phys_addr_t > > rte_mem_virt2phy(const void *virtaddr) > > { > > - int fd; > > + int fd, retval; > > uint64_t page, physaddr; > > unsigned long virt_pfn; > > int page_size; > > @@ -209,11 +209,19 @@ rte_mem_virt2phy(const void *virtaddr) > > close(fd); > > return RTE_BAD_PHYS_ADDR; > > } > > - if (read(fd, &page, sizeof(uint64_t)) < 0) { > > + > > + retval =3D read(fd, &page, sizeof(uint64_t)); > > + if (retval < 0) { > > RTE_LOG(ERR, EAL, "%s(): cannot read /proc/self/pagemap: > %s\n", > > __func__, strerror(errno)); > > close(fd); > > return RTE_BAD_PHYS_ADDR; > > + } else if (retval >=3D 0 && retval < (int)sizeof(uint64_t)) { >=20 > Just a couple of nits, retval >=3D 0 it's already implicit, no need to do > that check. >=20 > > + RTE_LOG(ERR, EAL, "%s(): read %d bytes from > /proc/self/pagemap " > > + "but expected %d: %s\n", > > + __func__, retval, (int)sizeof(uint64_t), > strerror(errno)); > > + close(fd); >=20 > Another nit, we could just close(fd) right after read, regardless of > read being success or error as > we close(fd) also on success just before exiting the function. >=20 > Other than that: >=20 > Acked-by: Sergio Gonzalez Monroy >=20 > > + return RTE_BAD_PHYS_ADDR; > > } > > > > /* Thanks Sergio, I have sent v2 with the changes that You suggest Michal.