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 C01E8A00BE; Thu, 10 Feb 2022 20:45:16 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9030B40140; Thu, 10 Feb 2022 20:45:16 +0100 (CET) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by mails.dpdk.org (Postfix) with ESMTP id 38E544013F; Thu, 10 Feb 2022 20:45:14 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1644522314; x=1676058314; h=from:to:cc:subject:date:message-id; bh=I65+QPndgUOYVqEbcYs/E1Ir4icfDNLibenzySQY9iY=; b=V/eNWdzMRNkQ+QA8VSehMxvYGhmPAT/lbtKyHvbzM0g8CL833JF1a09h fzGaAXEf2EDaGvYkCqQTDBMsWeU5KL7zZEWUNTaayLILizIr4tvByXco0 NMcP7TmIExNlovG3jDS616uKL6Nmy4iDX4oNiZzuXiEmwS2e1AcfckDv4 oi0tvFbdBmiNSL3G4cMZ50f6mm4GutAGg7SevVxvvFmOEA4b1I8hUJAhV FLHOHRQ8l9FVY11Jd9EeYukHQGuD/MFb3RIgp9q6uogrfrpfY5+6cPqN7 vQWzFZsDudm/8VKBbjTzNoQCY/RHiWUFoqmt2PGMkRXQ3HPwDiL6bqxXP Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10254"; a="233136605" X-IronPort-AV: E=Sophos;i="5.88,359,1635231600"; d="scan'208";a="233136605" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Feb 2022 11:45:10 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,359,1635231600"; d="scan'208";a="602150635" Received: from silpixa00400573.ir.intel.com (HELO silpixa00400573.ger.corp.intel.com) ([10.237.223.107]) by fmsmga004.fm.intel.com with ESMTP; 10 Feb 2022 11:45:08 -0800 From: Cristian Dumitrescu To: dev@dpdk.org Cc: Harshad Narayane , Kamalakannan R , Venkata Suresh Kumar P , stable@dpdk.org Subject: [PATCH] pipeline: fix table state memory allocation Date: Thu, 10 Feb 2022 19:45:08 +0000 Message-Id: <20220210194508.58650-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 The regular tables, selector tables and learner tables are all sharing the table state array. The locations in this array were computed incorrectly, leading to memory corruption issues. Signed-off-by: Cristian Dumitrescu Signed-off-by: Harshad Narayane Signed-off-by: Kamalakannan R Signed-off-by: Venkata Suresh Kumar P Fixes: 4f59d3726147 ("pipeline: support learner tables") Cc: stable@dpdk.org --- lib/pipeline/rte_swx_ctl.c | 28 +++++++++++++++++----------- lib/pipeline/rte_swx_pipeline.c | 2 +- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/lib/pipeline/rte_swx_ctl.c b/lib/pipeline/rte_swx_ctl.c index 8e29d58cec..f52ccffd75 100644 --- a/lib/pipeline/rte_swx_ctl.c +++ b/lib/pipeline/rte_swx_ctl.c @@ -1021,15 +1021,16 @@ learner_action_data_size_get(struct rte_swx_ctl_pipeline *ctl, struct learner *l static void table_state_free(struct rte_swx_ctl_pipeline *ctl) { - uint32_t i; + uint32_t table_base_index, selector_base_index, learner_base_index, i; if (!ctl->ts_next) return; /* For each table, free its table state. */ + table_base_index = 0; for (i = 0; i < ctl->info.n_tables; i++) { struct table *table = &ctl->tables[i]; - struct rte_swx_table_state *ts = &ctl->ts_next[i]; + struct rte_swx_table_state *ts = &ctl->ts_next[table_base_index + i]; /* Default action data. */ free(ts->default_action_data); @@ -1040,8 +1041,9 @@ table_state_free(struct rte_swx_ctl_pipeline *ctl) } /* For each selector table, free its table state. */ + selector_base_index = ctl->info.n_tables; for (i = 0; i < ctl->info.n_selectors; i++) { - struct rte_swx_table_state *ts = &ctl->ts_next[i]; + struct rte_swx_table_state *ts = &ctl->ts_next[selector_base_index + i]; /* Table object. */ if (ts->obj) @@ -1049,8 +1051,9 @@ table_state_free(struct rte_swx_ctl_pipeline *ctl) } /* For each learner table, free its table state. */ + learner_base_index = ctl->info.n_tables + ctl->info.n_selectors; for (i = 0; i < ctl->info.n_learners; i++) { - struct rte_swx_table_state *ts = &ctl->ts_next[i]; + struct rte_swx_table_state *ts = &ctl->ts_next[learner_base_index + i]; /* Default action data. */ free(ts->default_action_data); @@ -1063,10 +1066,10 @@ table_state_free(struct rte_swx_ctl_pipeline *ctl) static int table_state_create(struct rte_swx_ctl_pipeline *ctl) { + uint32_t table_base_index, selector_base_index, learner_base_index, i; int status = 0; - uint32_t i; - ctl->ts_next = calloc(ctl->info.n_tables + ctl->info.n_selectors, + ctl->ts_next = calloc(ctl->info.n_tables + ctl->info.n_selectors + ctl->info.n_learners, sizeof(struct rte_swx_table_state)); if (!ctl->ts_next) { status = -ENOMEM; @@ -1074,10 +1077,11 @@ table_state_create(struct rte_swx_ctl_pipeline *ctl) } /* Tables. */ + table_base_index = 0; for (i = 0; i < ctl->info.n_tables; i++) { struct table *table = &ctl->tables[i]; - struct rte_swx_table_state *ts = &ctl->ts[i]; - struct rte_swx_table_state *ts_next = &ctl->ts_next[i]; + struct rte_swx_table_state *ts = &ctl->ts[table_base_index + i]; + struct rte_swx_table_state *ts_next = &ctl->ts_next[table_base_index + i]; /* Table object. */ if (!table->is_stub && table->ops.add) { @@ -1110,9 +1114,10 @@ table_state_create(struct rte_swx_ctl_pipeline *ctl) } /* Selector tables. */ + selector_base_index = ctl->info.n_tables; for (i = 0; i < ctl->info.n_selectors; i++) { struct selector *s = &ctl->selectors[i]; - struct rte_swx_table_state *ts_next = &ctl->ts_next[ctl->info.n_tables + i]; + struct rte_swx_table_state *ts_next = &ctl->ts_next[selector_base_index + i]; /* Table object. */ ts_next->obj = rte_swx_table_selector_create(&s->params, NULL, ctl->numa_node); @@ -1123,10 +1128,11 @@ table_state_create(struct rte_swx_ctl_pipeline *ctl) } /* Learner tables. */ + learner_base_index = ctl->info.n_tables + ctl->info.n_selectors; for (i = 0; i < ctl->info.n_learners; i++) { struct learner *l = &ctl->learners[i]; - struct rte_swx_table_state *ts = &ctl->ts[i]; - struct rte_swx_table_state *ts_next = &ctl->ts_next[i]; + struct rte_swx_table_state *ts = &ctl->ts[learner_base_index + i]; + struct rte_swx_table_state *ts_next = &ctl->ts_next[learner_base_index + i]; /* Table object: duplicate from the current table state. */ ts_next->obj = ts->obj; diff --git a/lib/pipeline/rte_swx_pipeline.c b/lib/pipeline/rte_swx_pipeline.c index eb54ccaeda..868010303c 100644 --- a/lib/pipeline/rte_swx_pipeline.c +++ b/lib/pipeline/rte_swx_pipeline.c @@ -8566,7 +8566,7 @@ table_state_build(struct rte_swx_pipeline *p) struct selector *s; struct learner *l; - p->table_state = calloc(p->n_tables + p->n_selectors, + p->table_state = calloc(p->n_tables + p->n_selectors + p->n_learners, sizeof(struct rte_swx_table_state)); CHECK(p->table_state, ENOMEM); -- 2.17.1