From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
stable@dpdk.org, Aman Singh <aman.deep.singh@intel.com>,
Jingjing Wu <jingjing.wu@intel.com>, Wei Dai <wei.dai@intel.com>
Subject: [PATCH] app/testpmd: fix out-of-bound reference in offload config
Date: Thu, 20 Feb 2025 12:44:26 -0800 [thread overview]
Message-ID: <20250220204427.213965-1-stephen@networkplumber.org> (raw)
When configuring offloads, need to check the port id before
indexing into the ports[] array. This can easily be done
by moving the call to oh_dev_conf_get_print_err() to before
the checks for port stopped.
Fixes: c73a9071877a ("app/testpmd: add commands to test new offload API")
Cc: stable@dpdk.org
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
app/test-pmd/cmdline.c | 57 +++++++++++++++++++++++-------------------
1 file changed, 31 insertions(+), 26 deletions(-)
diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index 86d763b66a..d059b65003 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -11627,7 +11627,7 @@ cmd_rx_offload_get_configuration_parsed(
struct cmd_rx_offload_get_configuration_result *res = parsed_result;
struct rte_eth_dev_info dev_info;
portid_t port_id = res->port_id;
- struct rte_port *port = &ports[port_id];
+ struct rte_port *port;
struct rte_eth_conf dev_conf;
uint64_t port_offloads;
uint64_t queue_offloads;
@@ -11635,12 +11635,13 @@ cmd_rx_offload_get_configuration_parsed(
int q;
int ret;
- printf("Rx Offloading Configuration of port %d :\n", port_id);
-
ret = eth_dev_conf_get_print_err(port_id, &dev_conf);
if (ret != 0)
return;
+ port = &ports[port_id];
+ printf("Rx Offloading Configuration of port %d :\n", port_id);
+
port_offloads = dev_conf.rxmode.offloads;
printf(" Port :");
print_rx_offloads(port_offloads);
@@ -11741,12 +11742,17 @@ static void
config_port_rx_offload(portid_t port_id, char *name, bool on)
{
struct rte_eth_dev_info dev_info;
- struct rte_port *port = &ports[port_id];
+ struct rte_port *port;
uint16_t nb_rx_queues;
uint64_t offload;
int q;
int ret;
+ ret = eth_dev_info_get_print_err(port_id, &dev_info);
+ if (ret != 0)
+ return;
+
+ port = &ports[port_id];
if (port->port_status != RTE_PORT_STOPPED) {
fprintf(stderr,
"Error: Can't config offload when Port %d is not stopped\n",
@@ -11754,10 +11760,6 @@ config_port_rx_offload(portid_t port_id, char *name, bool on)
return;
}
- ret = eth_dev_info_get_print_err(port_id, &dev_info);
- if (ret != 0)
- return;
-
if (!strcmp(name, "all")) {
offload = dev_info.rx_offload_capa;
} else {
@@ -11943,10 +11945,15 @@ cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
struct rte_eth_dev_info dev_info;
portid_t port_id = res->port_id;
uint16_t queue_id = res->queue_id;
- struct rte_port *port = &ports[port_id];
+ struct rte_port *port;
uint64_t offload;
int ret;
+ ret = eth_dev_info_get_print_err(port_id, &dev_info);
+ if (ret != 0)
+ return;
+
+ port = &ports[port_id];
if (port->port_status != RTE_PORT_STOPPED) {
fprintf(stderr,
"Error: Can't config offload when Port %d is not stopped\n",
@@ -11954,10 +11961,6 @@ cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
return;
}
- ret = eth_dev_info_get_print_err(port_id, &dev_info);
- if (ret != 0)
- return;
-
if (queue_id >= dev_info.nb_rx_queues) {
fprintf(stderr,
"Error: input queue_id should be 0 ... %d\n",
@@ -12145,7 +12148,7 @@ cmd_tx_offload_get_configuration_parsed(
struct cmd_tx_offload_get_configuration_result *res = parsed_result;
struct rte_eth_dev_info dev_info;
portid_t port_id = res->port_id;
- struct rte_port *port = &ports[port_id];
+ struct rte_port *port;
struct rte_eth_conf dev_conf;
uint64_t port_offloads;
uint64_t queue_offloads;
@@ -12153,12 +12156,12 @@ cmd_tx_offload_get_configuration_parsed(
int q;
int ret;
- printf("Tx Offloading Configuration of port %d :\n", port_id);
-
ret = eth_dev_conf_get_print_err(port_id, &dev_conf);
if (ret != 0)
return;
+ printf("Tx Offloading Configuration of port %d :\n", port_id);
+ port = &ports[port_id];
port_offloads = dev_conf.txmode.offloads;
printf(" Port :");
print_tx_offloads(port_offloads);
@@ -12263,12 +12266,17 @@ static void
config_port_tx_offload(portid_t port_id, char *name, bool on)
{
struct rte_eth_dev_info dev_info;
- struct rte_port *port = &ports[port_id];
+ struct rte_port *port;
uint16_t nb_tx_queues;
uint64_t offload;
int q;
int ret;
+ ret = eth_dev_info_get_print_err(port_id, &dev_info);
+ if (ret != 0)
+ return;
+
+ port = &ports[port_id];
if (port->port_status != RTE_PORT_STOPPED) {
fprintf(stderr,
"Error: Can't config offload when Port %d is not stopped\n",
@@ -12276,10 +12284,6 @@ config_port_tx_offload(portid_t port_id, char *name, bool on)
return;
}
- ret = eth_dev_info_get_print_err(port_id, &dev_info);
- if (ret != 0)
- return;
-
if (!strcmp(name, "all")) {
offload = dev_info.tx_offload_capa;
} else {
@@ -12469,10 +12473,15 @@ cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
struct rte_eth_dev_info dev_info;
portid_t port_id = res->port_id;
uint16_t queue_id = res->queue_id;
- struct rte_port *port = &ports[port_id];
+ struct rte_port *port;
uint64_t offload;
int ret;
+ ret = eth_dev_info_get_print_err(port_id, &dev_info);
+ if (ret != 0)
+ return;
+
+ port = &ports[port_id];
if (port->port_status != RTE_PORT_STOPPED) {
fprintf(stderr,
"Error: Can't config offload when Port %d is not stopped\n",
@@ -12480,10 +12489,6 @@ cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
return;
}
- ret = eth_dev_info_get_print_err(port_id, &dev_info);
- if (ret != 0)
- return;
-
if (queue_id >= dev_info.nb_tx_queues) {
fprintf(stderr,
"Error: input queue_id should be 0 ... %d\n",
--
2.47.2
next reply other threads:[~2025-02-20 20:44 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-20 20:44 Stephen Hemminger [this message]
2025-02-21 1:27 ` lihuisong (C)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250220204427.213965-1-stephen@networkplumber.org \
--to=stephen@networkplumber.org \
--cc=aman.deep.singh@intel.com \
--cc=dev@dpdk.org \
--cc=jingjing.wu@intel.com \
--cc=stable@dpdk.org \
--cc=wei.dai@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).