From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id D51CCA00BE; Wed, 27 Apr 2022 23:56:58 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 28175427FE; Wed, 27 Apr 2022 23:56:58 +0200 (CEST) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mails.dpdk.org (Postfix) with ESMTP id 23B4E40E78; Wed, 27 Apr 2022 23:56:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1651096616; x=1682632616; h=from:to:cc:subject:date:message-id; bh=HHByTaJwgp03Ta53fFOybVxZlO2vkmRSkZH/WKOMqLU=; b=Dho4A7Rl1gy/vedn6AJur09zkmDVG8zW3BY+EfDkjDAsrzBHbweoCVhY XfcT7inQDdQCWYthC+xDOoix/bvafVBbPYJofH1+/aQ5D7aHQsXKW/3Kp Io2y706zjL0o4lzOQtFDv9lQsmLBJEIIp7fQwGkvTs5fjrwqzRjpUmqY9 A2v/CLuALxoXaQ8L5wgcRD58b+FX+3i/rPZcEtMdJZ9nWtBJraauWfmbT zY2Kc2o5ESeZgXNjgo3fLKDjrAlM3lui4AULlM1QPp0clDDR63KivUq7h p4DXrA1dv72zfU5t5JolswvH4xwS4OIcaqkV5Hijd7zJKxelZzxywqe4I g==; X-IronPort-AV: E=McAfee;i="6400,9594,10330"; a="246639522" X-IronPort-AV: E=Sophos;i="5.90,294,1643702400"; d="scan'208";a="246639522" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Apr 2022 14:56:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,294,1643702400"; d="scan'208";a="533462095" Received: from silpixa00400573.ir.intel.com (HELO silpixa00400573.ger.corp.intel.com) ([10.237.223.107]) by orsmga006.jf.intel.com with ESMTP; 27 Apr 2022 14:56:53 -0700 From: Cristian Dumitrescu To: dev@dpdk.org Cc: stable@dpdk.org, Venkata Suresh Kumar P , Yogesh Jangra Subject: [PATCH] pipeline: fix emit instruction for invalid headers Date: Wed, 27 Apr 2022 22:56:52 +0100 Message-Id: <20220427215652.49229-1-cristian.dumitrescu@intel.com> X-Mailer: git-send-email 2.17.1 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Fix the emit instruction for the pathological case of all headers to be emitted being invalid. In this case, the for loop was essentially skipped and the last emitted header (or an invalid memory location) getting corrupted by setting its size to 0 through the assignment to ho->n_bytes right after the for loop. Fixes: d60dbdc88a3e ("pipeline: create inline functions for emit instruction") Cc: stable@dpdk.org Signed-off-by: Cristian Dumitrescu Signed-off-by: Venkata Suresh Kumar P Signed-off-by: Yogesh Jangra --- lib/pipeline/rte_swx_pipeline_internal.h | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/pipeline/rte_swx_pipeline_internal.h b/lib/pipeline/rte_swx_pipeline_internal.h index f8a6661f75..dd1d499f57 100644 --- a/lib/pipeline/rte_swx_pipeline_internal.h +++ b/lib/pipeline/rte_swx_pipeline_internal.h @@ -2010,9 +2010,9 @@ __instr_hdr_emit_many_exec(struct rte_swx_pipeline *p __rte_unused, { uint64_t valid_headers = t->valid_headers; uint32_t n_headers_out = t->n_headers_out; - struct header_out_runtime *ho = &t->headers_out[n_headers_out - 1]; + struct header_out_runtime *ho = NULL; uint8_t *ho_ptr = NULL; - uint32_t ho_nbytes = 0, first = 1, i; + uint32_t ho_nbytes = 0, i; for (i = 0; i < n_emit; i++) { uint32_t header_id = ip->io.hdr.header_id[i]; @@ -2024,18 +2024,21 @@ __instr_hdr_emit_many_exec(struct rte_swx_pipeline *p __rte_unused, uint8_t *hi_ptr = t->structs[struct_id]; - if (!MASK64_BIT_GET(valid_headers, header_id)) + if (!MASK64_BIT_GET(valid_headers, header_id)) { + TRACE("[Thread %2u]: emit header %u (invalid)\n", + p->thread_id, + header_id); + continue; + } - TRACE("[Thread %2u]: emit header %u\n", + TRACE("[Thread %2u]: emit header %u (valid)\n", p->thread_id, header_id); /* Headers. */ - if (first) { - first = 0; - - if (!t->n_headers_out) { + if (!ho) { + if (!n_headers_out) { ho = &t->headers_out[0]; ho->ptr0 = hi_ptr0; @@ -2048,6 +2051,8 @@ __instr_hdr_emit_many_exec(struct rte_swx_pipeline *p __rte_unused, continue; } else { + ho = &t->headers_out[n_headers_out - 1]; + ho_ptr = ho->ptr; ho_nbytes = ho->n_bytes; } @@ -2069,7 +2074,8 @@ __instr_hdr_emit_many_exec(struct rte_swx_pipeline *p __rte_unused, } } - ho->n_bytes = ho_nbytes; + if (ho) + ho->n_bytes = ho_nbytes; t->n_headers_out = n_headers_out; } -- 2.17.1