From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 99457A04B1; Wed, 26 Aug 2020 17:21:00 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id C89EA1C1FB; Wed, 26 Aug 2020 17:15:42 +0200 (CEST) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id BA5641C0B4 for ; Wed, 26 Aug 2020 17:15:14 +0200 (CEST) IronPort-SDR: vwLolyuiCbep1jV1AomJ8WN0x8mTNHj0nBZNbHzDYBgoSUK8OQ7JlglzPBi6Kcsp3cFylgXLdA uyFwvIU8aKSg== X-IronPort-AV: E=McAfee;i="6000,8403,9725"; a="153879583" X-IronPort-AV: E=Sophos;i="5.76,356,1592895600"; d="scan'208";a="153879583" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Aug 2020 08:15:13 -0700 IronPort-SDR: hhK69dFNKUgTIX/vhxC/7s22D3YEp57oQaRs3B7v0mOZLdwArxBjnXgHyUqpP+I4XieYVdEAGP LoRLgetaYI4g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,356,1592895600"; d="scan'208";a="444081419" Received: from silpixa00400573.ir.intel.com (HELO silpixa00400573.ger.corp.intel.com) ([10.237.223.107]) by orsmga004.jf.intel.com with ESMTP; 26 Aug 2020 08:15:13 -0700 From: Cristian Dumitrescu To: dev@dpdk.org Date: Wed, 26 Aug 2020 16:14:31 +0100 Message-Id: <20200826151445.51500-27-cristian.dumitrescu@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200826151445.51500-1-cristian.dumitrescu@intel.com> References: <20200826151445.51500-1-cristian.dumitrescu@intel.com> Subject: [dpdk-dev] [PATCH 26/40] pipeline: add instruction verifier 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" Instruction verifier. Executes at instruction translation time during pipeline build, i.e. initialization instead of run-time. Signed-off-by: Cristian Dumitrescu --- lib/librte_pipeline/rte_swx_pipeline.c | 51 ++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/lib/librte_pipeline/rte_swx_pipeline.c b/lib/librte_pipeline/rte_swx_pipeline.c index 4eb1f4228..0016e0f0a 100644 --- a/lib/librte_pipeline/rte_swx_pipeline.c +++ b/lib/librte_pipeline/rte_swx_pipeline.c @@ -5653,6 +5653,53 @@ instr_jmp_resolve(struct instruction *instructions, return 0; } +static int +instr_verify(struct rte_swx_pipeline *p __rte_unused, + struct action *a, + struct instruction *instr, + struct instruction_data *data __rte_unused, + uint32_t n_instructions) +{ + if (!a) { + enum instruction_type type; + uint32_t i; + + /* Check that the first instruction is rx. */ + CHECK(instr[0].type == INSTR_RX, EINVAL); + + /* Check that there is at least one tx instruction. */ + for (i = 0; i < n_instructions; i++) { + type = instr[i].type; + + if (instr[i].type == INSTR_TX) + break; + } + CHECK(i < n_instructions, EINVAL); + + /* Check that the last instruction is either tx or unconditional + * jump. + */ + type = instr[n_instructions - 1].type; + CHECK((type == INSTR_TX) || (type == INSTR_JMP), EINVAL); + } + + if (a) { + enum instruction_type type; + uint32_t i; + + /* Check that there is at least one return or tx instruction. */ + for (i = 0; i < n_instructions; i++) { + type = instr[i].type; + + if ((type == INSTR_RETURN) || (type == INSTR_TX)) + break; + } + CHECK(i < n_instructions, EINVAL); + } + + return 0; +} + static int instruction_config(struct rte_swx_pipeline *p, struct action *a, @@ -5701,6 +5748,10 @@ instruction_config(struct rte_swx_pipeline *p, if (err) goto error; + err = instr_verify(p, a, instr, data, n_instructions); + if (err) + goto error; + err = instr_jmp_resolve(instr, data, n_instructions); if (err) goto error; -- 2.17.1