From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <tomaszx.kulasek@intel.com>
Received: from mga04.intel.com (mga04.intel.com [192.55.52.120])
 by dpdk.org (Postfix) with ESMTP id 9036C2B96
 for <dev@dpdk.org>; Tue, 26 Apr 2016 17:48:12 +0200 (CEST)
Received: from fmsmga002.fm.intel.com ([10.253.24.26])
 by fmsmga104.fm.intel.com with ESMTP; 26 Apr 2016 08:48:11 -0700
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.24,537,1455004800"; d="scan'208";a="966904067"
Received: from unknown (HELO Sent) ([10.217.248.44])
 by fmsmga002.fm.intel.com with SMTP; 26 Apr 2016 08:48:07 -0700
Received: by Sent (sSMTP sendmail emulation); Tue, 26 Apr 2016 17:48:06 +0200
From: Tomasz Kulasek <tomaszx.kulasek@intel.com>
To: ian.betts@intel.com
Cc: dev@dpdk.org
Date: Tue, 26 Apr 2016 17:47:56 +0200
Message-Id: <1461685676-7084-1-git-send-email-tomaszx.kulasek@intel.com>
X-Mailer: git-send-email 2.1.4
Subject: [dpdk-dev] [PATCH] examples/performance-thread: fix segfault with
	in gcc 5.x
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>
X-List-Received-Date: Tue, 26 Apr 2016 15:48:13 -0000

It seems that with gcc >5.x and -O2/-O3 optimization breaks packet grouping
algorithm in l3fwd-thread application causing segfault.

When last packet pointer "lp" and "pnum->u64" buffer points the same
memory buffer, high optimization can cause unpredictable results. It seems
that assignment of precalculated group sizes may interfere with
initialization of new group size when lp points value inside current group
and didn't should be changed.

With gcc >5.x and optimization we cannot be sure which assignment will be
done first, so the group size can be counted incorrectly causing segfault.

This patch eliminates intersection of assignment of initial group size
(lp[0] = 1) and precalculated group sizes when gptbl[v].idx < 4.

Fixes: d48415e1fee3 ("examples/performance-thread: add l3fwd-thread app")

Signed-off-by: Tomasz Kulasek <tomaszx.kulasek@intel.com>
---
 examples/performance-thread/l3fwd-thread/main.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/examples/performance-thread/l3fwd-thread/main.c b/examples/performance-thread/l3fwd-thread/main.c
index 15c0a4d..3417fd5 100644
--- a/examples/performance-thread/l3fwd-thread/main.c
+++ b/examples/performance-thread/l3fwd-thread/main.c
@@ -1658,9 +1658,9 @@ port_groupx4(uint16_t pn[FWDSTEP + 1], uint16_t *lp, __m128i dp1, __m128i dp2)
 
 	/* if dest port value has changed. */
 	if (v != GRPMSK) {
-		lp = pnum->u16 + gptbl[v].idx;
-		lp[0] = 1;
 		pnum->u64 = gptbl[v].pnum;
+		pnum->u16[FWDSTEP] = 1;
+		lp = pnum->u16 + gptbl[v].idx;
 	}
 
 	return lp;
-- 
1.7.9.5