From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id D8FBE11A2 for ; Sat, 19 Dec 2015 23:40:14 +0100 (CET) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP; 19 Dec 2015 14:40:13 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,451,1444719600"; d="scan'208";a="844938970" Received: from mlomano-mobl1.ger.corp.intel.com (HELO dverbeir-MOBL2.ger.corp.intel.com) ([10.252.24.149]) by orsmga001.jf.intel.com with ESMTP; 19 Dec 2015 14:40:12 -0800 From: David Verbeiren To: dev@dpdk.org, david.verbeiren@intel.com Date: Sat, 19 Dec 2015 23:39:32 +0100 Message-Id: <1450564772-20000-1-git-send-email-david.verbeiren@intel.com> X-Mailer: git-send-email 2.6.3.windows.1 Subject: [dpdk-dev] [PATCH] ivshmem: avoid infinite loop when concatenating adjacent segments 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: Sat, 19 Dec 2015 22:40:15 -0000 This patch aligns the logic used to check for the presence of adjacent segments in has_adjacent_segments() with the logic used in cleanup_segments() when actually deciding to concatenate or not a pair of segments. This fixes an infinite loop that happened when segments where adjacent in their physical or virtual addresses but not in their ioremap addresses: has_adjacent_segments() reported the presence of adjacent segments while cleanup_segments() was not considering them for concatenation, resulting in an infinite loop since the result of has_adjacent_segments() is used in the decision to continue looping in cleanup_segments(). Signed-off-by: David Verbeiren --- lib/librte_eal/linuxapp/eal/eal_ivshmem.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/librte_eal/linuxapp/eal/eal_ivshmem.c b/lib/librte_eal/linuxapp/eal/eal_ivshmem.c index 589019b..086cafb 100644 --- a/lib/librte_eal/linuxapp/eal/eal_ivshmem.c +++ b/lib/librte_eal/linuxapp/eal/eal_ivshmem.c @@ -254,17 +254,18 @@ adjacent(const struct rte_memzone * mz1, const struct rte_memzone * mz2) static int has_adjacent_segments(struct ivshmem_segment * ms, int len) { - int i, j, a; + int i, j; for (i = 0; i < len; i++) for (j = i + 1; j < len; j++) { - a = adjacent(&ms[i].entry.mz, &ms[j].entry.mz); - - /* check if segments are adjacent virtually and/or physically but - * not ioremap (since that would indicate that they are from - * different PCI devices and thus don't need to be concatenated. + + /* check if segments are adjacent virtually and physically. + * They must also be adjacent in ioremap since disjoint + * ioremap segments would be from different PCI devices and + * thus don't need to be concatenated. This is the logic + * used in cleanup_segments() and must be in sync. */ - if ((a & (VIRT|PHYS)) > 0 && (a & IOREMAP) == 0) + if (adjacent(&ms[i].entry.mz, &ms[j].entry.mz) == FULL) return 1; } return 0; -- 1.9.1