When NUMA support is disabled, mbuf pools are created on
SOCKET_ID_ANY but port->socket_id is still set to 0 (or
--socket-num). Pool lookup is by name, and the name embeds the
socket id the pool was created with, so every lookup that does not
go through the one workaround in start_port() misses:

- the per-lcore pool assignment in init_config() leaves
  fwd_lcores[]->mbp NULL, so "testpmd --no-numa
  --forward-mode=txonly" crashes with a NULL dereference in
  pkt_burst_transmit();
- the per-segment and multi-mempool lookups in rx_queue_setup()
  fall back to the first pool, so buffer split fails when a later
  segment needs a larger mbuf
  (e.g. --mbuf-size=314,978 --rxpkts=186,978);
- the interactive "port <id> rxq|txq <id> setup" command cannot
  find a pool.

The --socket-num option is also ignored for pool allocation since
the offending commit.

Fix this at the source instead of adding another workaround at a
lookup site: make port->socket_id hold the same socket id the
pools are created and named with. Add uma_socket_id() returning
the pool socket key used when NUMA support is disabled
(--socket-num if given, otherwise SOCKET_ID_ANY) and use it for
pool creation, port->socket_id and the per-lcore pool fallback.
The workaround in start_port() is then unnecessary.

Passing SOCKET_ID_ANY to rte_eth_rx/tx_queue_setup() is allowed by
the ethdev API and matches the cross-NUMA intent of the offending
commit.

Fixes: 835fd4893a31 ("app/testpmd: support cross-NUMA allocations")
Cc: [email protected]

Reported-by: Maayan Kashani <[email protected]>
Signed-off-by: Stephen Hemminger <[email protected]>
---
 app/test-pmd/testpmd.c | 27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)

diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index fcd8a90967..b5dca03047 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -1729,6 +1729,17 @@ init_config_port_offloads(portid_t pid, uint32_t 
socket_id)
        }
 }
 
+/*
+ * Socket id that mbuf pools are created (and named) with when NUMA
+ * support is disabled: --socket-num if given, otherwise SOCKET_ID_ANY.
+ */
+static unsigned int
+uma_socket_id(void)
+{
+       return socket_num == UMA_NO_CONFIG ?
+              (unsigned int)SOCKET_ID_ANY : socket_num;
+}
+
 static void
 init_config(void)
 {
@@ -1778,8 +1789,7 @@ init_config(void)
                                        socket_id = socket_ids[0];
                        }
                } else {
-                       socket_id = (socket_num == UMA_NO_CONFIG) ?
-                                   0 : socket_num;
+                       socket_id = uma_socket_id();
                }
                /* Apply default TxRx configuration for all ports */
                init_config_port_offloads(pid, socket_id);
@@ -1823,7 +1833,7 @@ init_config(void)
                        mempools[i] = mbuf_pool_create
                                        (mbuf_data_size[i],
                                         nb_mbuf_per_pool,
-                                        SOCKET_ID_ANY, i);
+                                        uma_socket_id(), i);
                }
        }
 
@@ -1841,7 +1851,8 @@ init_config(void)
                        rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]));
 
                if (mbp == NULL)
-                       mbp = mbuf_pool_find_first(0);
+                       mbp = mbuf_pool_find_first(numa_support ?
+                               0 : uma_socket_id());
                fwd_lcores[lc_id]->mbp = mbp;
 #ifdef RTE_LIB_GSO
                /* initialize GSO context */
@@ -1920,10 +1931,7 @@ init_fwd_streams(void)
                        }
                }
                else {
-                       if (socket_num == UMA_NO_CONFIG)
-                               port->socket_id = 0;
-                       else
-                               port->socket_id = socket_num;
+                       port->socket_id = uma_socket_id();
                }
        }
 
@@ -3153,8 +3161,7 @@ start_port(portid_t pid)
                                } else {
                                        struct rte_mempool *mp =
                                                mbuf_pool_find_first
-                                                       ((numa_support ? 
port->socket_id :
-                                                       (unsigned 
int)SOCKET_ID_ANY));
+                                                       (port->socket_id);
                                        if (mp == NULL) {
                                                fprintf(stderr,
                                                        "Failed to setup RX 
queue: No mempool allocation on the socket %d\n",
-- 
2.53.0

Reply via email to