From patchwork Mon Jul 16 14:57:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anatoly Burakov X-Patchwork-Id: 43114 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 87D4623C; Mon, 16 Jul 2018 16:57:24 +0200 (CEST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 4045416E; Mon, 16 Jul 2018 16:57:22 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Jul 2018 07:57:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,361,1526367600"; d="scan'208";a="73183180" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga001.jf.intel.com with ESMTP; 16 Jul 2018 07:57:20 -0700 Received: from sivswdev01.ir.intel.com (sivswdev01.ir.intel.com [10.237.217.45]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id w6GEvJFf014117; Mon, 16 Jul 2018 15:57:19 +0100 Received: from sivswdev01.ir.intel.com (localhost [127.0.0.1]) by sivswdev01.ir.intel.com with ESMTP id w6GEvJKd023234; Mon, 16 Jul 2018 15:57:19 +0100 Received: (from aburakov@localhost) by sivswdev01.ir.intel.com with LOCAL id w6GEvJnb023230; Mon, 16 Jul 2018 15:57:19 +0100 From: Anatoly Burakov To: dev@dpdk.org Cc: thomas@monjalon.net, lei.a.yao@intel.com, dariuszx.stojaczyk@intel.com, stable@dpdk.org Date: Mon, 16 Jul 2018 15:57:19 +0100 Message-Id: <1e4e38f022da0d791b454b8d9cddce61b479b7ad.1531752592.git.anatoly.burakov@intel.com> X-Mailer: git-send-email 1.7.0.7 Subject: [dpdk-dev] [PATCH] mem: fix alignment of requested virtual areas 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" The original code did not align any addresses that were requested as page-aligned, but were different because addr_is_hint was set. Below fix by Dariusz has introduced an issue where all unaligned addresses were left as unaligned. This patch is a partial revert of commit 7fa7216ed48d ("mem: fix alignment of requested virtual areas") and implements a proper fix for this issue, by asking for alignment in all but the following two cases: 1) page size is equal to system page size, or 2) we got an aligned requested address, and will not accept a different one This ensures that alignment is performed in all cases, except for those we can guarantee that the address will not need alignment. Fixes: b7cc54187ea4 ("mem: move virtual area function in common directory") Fixes: 7fa7216ed48d ("mem: fix alignment of requested virtual areas") Cc: dariuszx.stojaczyk@intel.com Cc: stable@dpdk.org Signed-off-by: Anatoly Burakov Tested-by: Lei Yao Acked-by: Dariusz Stojaczyk --- lib/librte_eal/common/eal_common_memory.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/librte_eal/common/eal_common_memory.c b/lib/librte_eal/common/eal_common_memory.c index 659cc08f6..fbfb1b055 100644 --- a/lib/librte_eal/common/eal_common_memory.c +++ b/lib/librte_eal/common/eal_common_memory.c @@ -66,14 +66,17 @@ eal_get_virtual_area(void *requested_addr, size_t *size, addr_is_hint = true; } - /* if requested address is not aligned by page size, or if requested - * address is NULL, add page size to requested length as we may get an - * address that's aligned by system page size, which can be smaller than - * our requested page size. additionally, we shouldn't try to align if - * system page size is the same as requested page size. + /* we don't need alignment of resulting pointer in the following cases: + * + * 1. page size is equal to system size + * 2. we have a requested address, and it is page-aligned, and we will + * be discarding the address if we get a different one. + * + * for all other cases, alignment is potentially necessary. */ no_align = (requested_addr != NULL && - ((uintptr_t)requested_addr & (page_sz - 1))) || + requested_addr == RTE_PTR_ALIGN(requested_addr, page_sz) && + !addr_is_hint) || page_sz == system_page_sz; do {