Skip to content

Commit

Permalink
pipeline: fix table state memory allocation
Browse files Browse the repository at this point in the history
[ upstream commit eb3e2c1 ]

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.

Fixes: 4f59d37 ("pipeline: support learner tables")

Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
Signed-off-by: Harshad Narayane <harshad.suresh.narayane@intel.com>
Signed-off-by: Kamalakannan R <kamalakannan.r@intel.com>
Signed-off-by: Venkata Suresh Kumar P <venkata.suresh.kumar.p@intel.com>
  • Loading branch information
cristian-dumitrescu authored and kevintraynor committed Feb 21, 2022
1 parent 1e8aa23 commit adfebc5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
28 changes: 17 additions & 11 deletions lib/pipeline/rte_swx_ctl.c
Expand Up @@ -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);
Expand All @@ -1040,17 +1041,19 @@ 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)
rte_swx_table_selector_free(ts->obj);
}

/* 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);
Expand All @@ -1063,21 +1066,22 @@ 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;
goto error;
}

/* 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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/pipeline/rte_swx_pipeline.c
Expand Up @@ -8531,7 +8531,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);

Expand Down

0 comments on commit adfebc5

Please sign in to comment.