Message ID | 1469198030-8664-1-git-send-email-michalx.k.jastrzebski@intel.com (mailing list archive) |
---|---|
State | Accepted, archived |
Headers |
Return-Path: <dev-bounces@dpdk.org> X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 6D5723777; Fri, 22 Jul 2016 16:34:15 +0200 (CEST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id D96F6DE3 for <dev@dpdk.org>; Fri, 22 Jul 2016 16:34:13 +0200 (CEST) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga103.fm.intel.com with ESMTP; 22 Jul 2016 07:34:13 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.28,405,1464678000"; d="scan'208"; a="1022019627" Received: from mschlewx-mobl1.ger.corp.intel.com (HELO Sent) ([10.104.17.205]) by orsmga002.jf.intel.com with SMTP; 22 Jul 2016 07:34:09 -0700 Received: by Sent (sSMTP sendmail emulation); Fri, 22 Jul 2016 16:34:09 +0200 From: Michal Jastrzebski <michalx.k.jastrzebski@intel.com> To: bruce.richardson@intel.com Cc: dev@dpdk.org, michalx.kobylinski@intel.com, sergio.gonzalez.monroy@intel.com, david.marchand@6wind.com, thomas.monjalon@6wind.com Date: Fri, 22 Jul 2016 16:33:50 +0200 Message-Id: <1469198030-8664-1-git-send-email-michalx.k.jastrzebski@intel.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1469024689-1076-1-git-send-email-michalx.k.jastrzebski@intel.com> References: <1469024689-1076-1-git-send-email-michalx.k.jastrzebski@intel.com> Subject: [dpdk-dev] [PATCH v2] 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 <dev.dpdk.org> List-Unsubscribe: <http://dpdk.org/ml/options/dev>, <mailto:dev-request@dpdk.org?subject=unsubscribe> List-Archive: <http://dpdk.org/ml/archives/dev/> List-Post: <mailto:dev@dpdk.org> List-Help: <mailto:dev-request@dpdk.org?subject=help> List-Subscribe: <http://dpdk.org/ml/listinfo/dev>, <mailto:dev-request@dpdk.org?subject=subscribe> Errors-To: dev-bounces@dpdk.org Sender: "dev" <dev-bounces@dpdk.org> |
Commit Message
Michal Jastrzebski
July 22, 2016, 2:33 p.m. UTC
v2:
-moved close(fd) just after read.
-when read() from fd we expect 8 bytes, so PFN_MASK_SIZE macro
was introduced instead sizeof(uint64_t).
-removed errno print when read returns less than 8 bytes
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 <michalx.k.jastrzebski@intel.com>
---
lib/librte_eal/linuxapp/eal/eal_memory.c | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
Comments
2016-07-22 16:33, Michal Jastrzebski: > v2: > -moved close(fd) just after read. > -when read() from fd we expect 8 bytes, so PFN_MASK_SIZE macro > was introduced instead sizeof(uint64_t). > -removed errno print when read returns less than 8 bytes Looks better. Note: this changelog should be below --- to avoid appearing in the commit. > 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. Better title to explain the issue: mem: fix check of physical address retrieval > +#define PFN_MASK_SIZE 8 > + > #ifdef RTE_LIBRTE_XEN_DOM0 > int rte_xen_dom0_supported(void) > { > @@ -158,7 +160,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,10 +211,19 @@ rte_mem_virt2phy(const void *virtaddr) > close(fd); > return RTE_BAD_PHYS_ADDR; > } > - if (read(fd, &page, sizeof(uint64_t)) < 0) { > + > + retval = read(fd, &page, sizeof(uint64_t)); We could use PFN_MASK_SIZE here > + close(fd); > + if (retval < 0) { > RTE_LOG(ERR, EAL, "%s(): cannot read /proc/self/pagemap: %s\n", > __func__, strerror(errno)); > - close(fd); > + useless whitespace > + return RTE_BAD_PHYS_ADDR; > + } else if (retval != PFN_MASK_SIZE) { > + RTE_LOG(ERR, EAL, "%s(): read %d bytes from /proc/self/pagemap " > + "but expected %d:\n", > + __func__, retval, PFN_MASK_SIZE); > + useless whitespace > return RTE_BAD_PHYS_ADDR; > } > > @@ -222,7 +233,7 @@ rte_mem_virt2phy(const void *virtaddr) > */ > physaddr = ((page & 0x7fffffffffffffULL) * page_size) > + ((unsigned long)virtaddr % page_size); > - close(fd); > + > return physaddr; > } If you and Sergio agree, I can make the minor changes before applying.
On 22/07/2016 16:24, Thomas Monjalon wrote: > 2016-07-22 16:33, Michal Jastrzebski: >> v2: >> -moved close(fd) just after read. >> -when read() from fd we expect 8 bytes, so PFN_MASK_SIZE macro >> was introduced instead sizeof(uint64_t). >> -removed errno print when read returns less than 8 bytes > Looks better. > Note: this changelog should be below --- to avoid appearing in > the commit. > >> 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. > Better title to explain the issue: > mem: fix check of physical address retrieval > >> +#define PFN_MASK_SIZE 8 >> + >> #ifdef RTE_LIBRTE_XEN_DOM0 >> int rte_xen_dom0_supported(void) >> { >> @@ -158,7 +160,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,10 +211,19 @@ rte_mem_virt2phy(const void *virtaddr) >> close(fd); >> return RTE_BAD_PHYS_ADDR; >> } >> - if (read(fd, &page, sizeof(uint64_t)) < 0) { >> + >> + retval = read(fd, &page, sizeof(uint64_t)); > We could use PFN_MASK_SIZE here > >> + close(fd); >> + if (retval < 0) { >> RTE_LOG(ERR, EAL, "%s(): cannot read /proc/self/pagemap: %s\n", >> __func__, strerror(errno)); >> - close(fd); >> + > useless whitespace > >> + return RTE_BAD_PHYS_ADDR; >> + } else if (retval != PFN_MASK_SIZE) { >> + RTE_LOG(ERR, EAL, "%s(): read %d bytes from /proc/self/pagemap " >> + "but expected %d:\n", >> + __func__, retval, PFN_MASK_SIZE); >> + > useless whitespace > >> return RTE_BAD_PHYS_ADDR; >> } >> >> @@ -222,7 +233,7 @@ rte_mem_virt2phy(const void *virtaddr) >> */ >> physaddr = ((page & 0x7fffffffffffffULL) * page_size) >> + ((unsigned long)virtaddr % page_size); >> - close(fd); >> + >> return physaddr; >> } > If you and Sergio agree, I can make the minor changes before applying. Go for it! Sergio
2016-07-22 17:02, Sergio Gonzalez Monroy: > On 22/07/2016 16:24, Thomas Monjalon wrote: > > 2016-07-22 16:33, Michal Jastrzebski: > >> v2: > >> -moved close(fd) just after read. > >> -when read() from fd we expect 8 bytes, so PFN_MASK_SIZE macro > >> was introduced instead sizeof(uint64_t). > >> -removed errno print when read returns less than 8 bytes > > Looks better. [...] > > Better title to explain the issue: > > mem: fix check of physical address retrieval [...] > >> + retval = read(fd, &page, sizeof(uint64_t)); > > We could use PFN_MASK_SIZE here [...] > > useless whitespace [...] > > If you and Sergio agree, I can make the minor changes before applying. > > Go for it! Applied with above changes, thanks
> -----Original Message----- > From: Thomas Monjalon [mailto:thomas.monjalon@6wind.com] > Sent: Friday, July 22, 2016 5:25 PM > To: Jastrzebski, MichalX K <michalx.k.jastrzebski@intel.com> > Cc: Richardson, Bruce <bruce.richardson@intel.com>; dev@dpdk.org; > Kobylinski, MichalX <michalx.kobylinski@intel.com>; Gonzalez Monroy, > Sergio <sergio.gonzalez.monroy@intel.com>; david.marchand@6wind.com > Subject: Re: [PATCH v2] eal: fix check number of bytes from read function > > 2016-07-22 16:33, Michal Jastrzebski: > > v2: > > -moved close(fd) just after read. > > -when read() from fd we expect 8 bytes, so PFN_MASK_SIZE macro > > was introduced instead sizeof(uint64_t). > > -removed errno print when read returns less than 8 bytes > > Looks better. > Note: this changelog should be below --- to avoid appearing in > the commit. > > > 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. > > Better title to explain the issue: > mem: fix check of physical address retrieval > > > +#define PFN_MASK_SIZE 8 > > + > > #ifdef RTE_LIBRTE_XEN_DOM0 > > int rte_xen_dom0_supported(void) > > { > > @@ -158,7 +160,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,10 +211,19 @@ rte_mem_virt2phy(const void *virtaddr) > > close(fd); > > return RTE_BAD_PHYS_ADDR; > > } > > - if (read(fd, &page, sizeof(uint64_t)) < 0) { > > + > > + retval = read(fd, &page, sizeof(uint64_t)); > > We could use PFN_MASK_SIZE here > > > + close(fd); > > + if (retval < 0) { > > RTE_LOG(ERR, EAL, "%s(): cannot read /proc/self/pagemap: > %s\n", > > __func__, strerror(errno)); > > - close(fd); > > + > > useless whitespace > > > + return RTE_BAD_PHYS_ADDR; > > + } else if (retval != PFN_MASK_SIZE) { > > + RTE_LOG(ERR, EAL, "%s(): read %d bytes from > /proc/self/pagemap " > > + "but expected %d:\n", > > + __func__, retval, PFN_MASK_SIZE); > > + > > useless whitespace > > > return RTE_BAD_PHYS_ADDR; > > } > > > > @@ -222,7 +233,7 @@ rte_mem_virt2phy(const void *virtaddr) > > */ > > physaddr = ((page & 0x7fffffffffffffULL) * page_size) > > + ((unsigned long)virtaddr % page_size); > > - close(fd); > > + > > return physaddr; > > } > > If you and Sergio agree, I can make the minor changes before applying. Thanks Thomas. Please apply.
diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c index 42a29fa..e20a38c 100644 --- a/lib/librte_eal/linuxapp/eal/eal_memory.c +++ b/lib/librte_eal/linuxapp/eal/eal_memory.c @@ -99,6 +99,8 @@ #include "eal_filesystem.h" #include "eal_hugepages.h" +#define PFN_MASK_SIZE 8 + #ifdef RTE_LIBRTE_XEN_DOM0 int rte_xen_dom0_supported(void) { @@ -158,7 +160,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,10 +211,19 @@ rte_mem_virt2phy(const void *virtaddr) close(fd); return RTE_BAD_PHYS_ADDR; } - if (read(fd, &page, sizeof(uint64_t)) < 0) { + + retval = read(fd, &page, sizeof(uint64_t)); + close(fd); + 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 != PFN_MASK_SIZE) { + RTE_LOG(ERR, EAL, "%s(): read %d bytes from /proc/self/pagemap " + "but expected %d:\n", + __func__, retval, PFN_MASK_SIZE); + return RTE_BAD_PHYS_ADDR; } @@ -222,7 +233,7 @@ rte_mem_virt2phy(const void *virtaddr) */ physaddr = ((page & 0x7fffffffffffffULL) * page_size) + ((unsigned long)virtaddr % page_size); - close(fd); + return physaddr; }