From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f51.google.com (mail-wm0-f51.google.com [74.125.82.51]) by dpdk.org (Postfix) with ESMTP id 924762BE2 for ; Fri, 22 Jul 2016 17:24:53 +0200 (CEST) Received: by mail-wm0-f51.google.com with SMTP id o80so71403805wme.1 for ; Fri, 22 Jul 2016 08:24:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:user-agent:in-reply-to :references:mime-version:content-transfer-encoding; bh=gUbWZ7dF6Jusw8+UkmF9IFLaTTeoOeIJ9ZyjpUGH02g=; b=Y68PkYTG8jXbol6wQ3sxAs2roQ2b4WdnzcS0pi+TxWMn3lTZhNPeeYjVvZm5E24eaH wbNk+k4fcyGIAFScqO32gcBdMCC91Gj0cLQuQWCuXd2x0DZCZsr1ocxsnSQSAMcyeG92 B6OTYhTo8dD3//I6zqrZqQyldRYh9OpnEdLxFvrfhIqtpQMONw2nsCvkz3XotYJdjxNk abLl94+PKAEpI+++Z8YMDdXb7GU8OcjgqmkdeLw3HpUiTdSdbiDMk5xSn19AAtn78IB1 2gWFKx//VQlkhfuu1Z4K6lwpHRXkcr5MzQeySlthy45d4dmGTO8pewZx9YBGZHzY+maU 83Ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:user-agent :in-reply-to:references:mime-version:content-transfer-encoding; bh=gUbWZ7dF6Jusw8+UkmF9IFLaTTeoOeIJ9ZyjpUGH02g=; b=eH9dB48nN2eG8FK9T96DOhgKy4f0/osXo2HCRYqqJN+Hqgwp19FdoTs8oXztl2RRpj skOYg7VKBx6kTY0bgTIJDfx52qMTSyOxAWlnOzyt5I3XUUwZN/5csfV+pNQZGtHMN7QL NbgMDrQPAbZl8ZeBVjqcSzp2bg8Mt0bpXQRFpfJ8AvP9evgf+QGvZIdzLrI54Yr2G1bm vjNDT0nAYKjuKIyW2IqIEaq8+x2uNDcpsJ/ZBj1HfhujRtknnntYZxPL1dz8bsBrEBAC W15Qs3dRzcE7jubM6lBLRmse7CvqlxBzB6jqtGrfKjpB5GZ3LLQMNeT+WNcR0lrF+dY/ whvg== X-Gm-Message-State: ALyK8tIaRCekhYZ1gkm4QzbWzbR/c/hpL6Z5fuhMfkOCNSlAMqpp2Biv00s17DzJv2NRFwJ/ X-Received: by 10.28.186.138 with SMTP id k132mr24662957wmf.65.1469201093359; Fri, 22 Jul 2016 08:24:53 -0700 (PDT) Received: from xps13.localnet (184.203.134.77.rev.sfr.net. [77.134.203.184]) by smtp.gmail.com with ESMTPSA id v10sm1422435wjs.27.2016.07.22.08.24.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Jul 2016 08:24:52 -0700 (PDT) From: Thomas Monjalon To: Michal Jastrzebski Cc: bruce.richardson@intel.com, dev@dpdk.org, michalx.kobylinski@intel.com, sergio.gonzalez.monroy@intel.com, david.marchand@6wind.com Date: Fri, 22 Jul 2016 17:24:51 +0200 Message-ID: <2746518.l5JpmnHLoW@xps13> User-Agent: KMail/4.14.10 (Linux/4.5.4-1-ARCH; KDE/4.14.11; x86_64; ; ) In-Reply-To: <1469198030-8664-1-git-send-email-michalx.k.jastrzebski@intel.com> References: <1469024689-1076-1-git-send-email-michalx.k.jastrzebski@intel.com> <1469198030-8664-1-git-send-email-michalx.k.jastrzebski@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Subject: Re: [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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Jul 2016 15:24:53 -0000 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.