fix segment fault when parse args
Subsystems (3)
cover fix segment fault when parse args
The rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
It may leads to segment fault when parse args with 'only key', this patchset fixes rest of them.
Chengwen Feng (5):
app/pdump: fix segment fault when parse args
net/memif: fix segment fault when parse devargs
net/pcap: fix segment fault when parse devargs
net/ring: fix segment fault when parse devargs
net/sfc: fix segment fault when parse devargs
app/pdump/main.c | 12 ++++++++++++ drivers/net/memif/rte_eth_memif.c | 30 ++++++++++++++++++++++++++++++ drivers/net/pcap/pcap_ethdev.c | 13 +++++++++++-- drivers/net/ring/rte_eth_ring.c | 6 ++++++ drivers/net/sfc/sfc.c | 3 +++ drivers/net/sfc/sfc_ev.c | 3 +++ drivers/net/sfc/sfc_kvargs.c | 6 ++++++ 7 files changed, 71 insertions(+), 2 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/5 app/pdump: fix segment fault when parse args
The rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse --pdump args with 'only keys' (e.g. 'port,queue=*').
--- app/pdump/main.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
app/pdump/main.c +12 -0
@@ -170,6 +170,9 @@ parse_device_id(const char *key __rte_unused, const char *value, {struct pdump_tuples *pt = extra_args; +if (value ==NULL || extra_args ==NULL ) +return -EINVAL ; + pt->device_id =strdup (value); pt->dump_by_type =DEVICE_ID ;
@@ -182,6 +185,9 @@ parse_queue(const char *key __rte_unused, const char *value, void *extra_args)unsigned long n;struct pdump_tuples *pt = extra_args; +if (value ==NULL || extra_args ==NULL ) +return -EINVAL ; +if (!strcmp (value,"*" )) pt->queue =RTE_PDUMP_ALL_QUEUES ;else {
@@ -197,6 +203,9 @@ parse_rxtxdev(const char *key, const char *value, void *extra_args)struct pdump_tuples *pt = extra_args; +if (value ==NULL || extra_args ==NULL ) +return -EINVAL ; +if (!strcmp (key,PDUMP_RX_DEV_ARG )) {strlcpy (pt->rx_dev, value,sizeof (pt->rx_dev));/* identify the tx stream type for pcap vdev */
@@ -220,6 +229,9 @@ parse_uint_value(const char *key, const char *value, void *extra_args)char *end;int ret =0 ; +if (value ==NULL || extra_args ==NULL ) +return -EINVAL ; + errno =0 ; v = extra_args; t =strtoul (value, &end,10 );
Signature · 1 line
2.17.1
Re: [PATCH 1/5] app/pdump: fix segment fault when parse args
Quoted 11 lines · Chengwen Feng
The
rte_kvargs_process()was used to parse KV pairs, it also supports to parse 'only keys' (e.g.socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.This patch fixes segment fault when parse --pdump args with 'only keys' (e.g. 'port,queue=*').
Fixes caa7028276b8 ("app/pdump: add tool for packet capturing")Signed-off-by Chengwen Feng <[email protected]>
Hi Chengwen,
Thanks for the fix, +1 to patch.
Quoted 9 lines
--- app/pdump/main.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)app/pdump/main.c +0
-0
app/pdump/main.c parse_device_id(const char *key __rte_unused, const char *value, · line 175
Quoted 6 lines
app/pdump/main.c +3
-0@@ -170,6 +170,9 @@ parse_device_id(const char *key __rte_unused, const char *value, {struct pdump_tuples *pt = extra_args; +if (value ==NULL || extra_args ==NULL ) +return -EINVAL ; +
Do we need to check 'extra_args'?
It is not something changes in the runtime, functions provides this callback is local to this file and in control, also if 'extra_args' is not provided correctly it will crash immediately so easy to detect it.
But +1 to check 'value', since that depends what user provided and need to verify user input.
Same comment for all set.
PATCH 2/5 net/memif: fix segment fault when parse devargs
In reply to Chengwen FengThe rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/net/memif/rte_eth_memif.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
drivers/net/memif/rte_eth_memif.c +30 -0
@@ -1720,6 +1720,9 @@ memif_set_role(const char *key __rte_unused, const char *value, {enum memif_role_t *role = (enum memif_role_t *)extra_args; +if (value ==NULL || extra_args ==NULL ) +return -EINVAL ; +if (strstr (value,"server" ) !=NULL ) { *role =MEMIF_ROLE_SERVER ; }else if (strstr (value,"client" ) !=NULL ) {
@@ -1742,6 +1745,9 @@ memif_set_zc(const char *key __rte_unused, const char *value, void *extra_args) {uint32_t *flags = (uint32_t *)extra_args; +if (value ==NULL || extra_args ==NULL ) +return -EINVAL ; +if (strstr (value,"yes" ) !=NULL ) {if (!rte_mcfg_get_single_file_segments ()) {MIF_LOG (ERR ,"Zero-copy doesn't support multi-file segments." );
@@ -1762,6 +1768,9 @@ memif_set_id(const char *key __rte_unused, const char *value, void *extra_args) {memif_interface_id_t *id = (memif_interface_id_t *)extra_args; +if (value ==NULL || extra_args ==NULL ) +return -EINVAL ; +/* even if parsing fails, 0 is a valid id */ *id =strtoul (value,NULL ,10 );return 0 ;
@@ -1773,6 +1782,9 @@ memif_set_bs(const char *key __rte_unused, const char *value, void *extra_args)unsigned long tmp;uint16_t *pkt_buffer_size = (uint16_t *)extra_args; +if (value ==NULL || extra_args ==NULL ) +return -EINVAL ; + tmp =strtoul (value,NULL ,10 );if (tmp ==0 || tmp >0xFFFF ) {MIF_LOG (ERR ,"Invalid buffer size: %s." , value);
@@ -1789,6 +1801,9 @@ memif_set_rs(const char *key __rte_unused, const char *value, void *extra_args)memif_log2_ring_size_t *log2_ring_size = (memif_log2_ring_size_t *)extra_args; +if (value ==NULL || extra_args ==NULL ) +return -EINVAL ; + tmp =strtoul (value,NULL ,10 );if (tmp ==0 || tmp >ETH_MEMIF_MAX_LOG2_RING_SIZE ) { MIF_LOG(ERR, "Invalid ring size: %s (max %u).",
@@ -1840,6 +1855,9 @@ memif_set_socket_filename(const char *key __rte_unused, const char *value, {const char **socket_filename = (const char **)extra_args; +if (value ==NULL || extra_args ==NULL ) +return -EINVAL ; + *socket_filename = value;return 0 ; }
@@ -1849,6 +1867,9 @@ memif_set_is_socket_abstract(const char *key __rte_unused, const char *value, vo {uint32_t *flags = (uint32_t *)extra_args; +if (value ==NULL || extra_args ==NULL ) +return -EINVAL ; +if (strstr (value,"yes" ) !=NULL ) { *flags |=ETH_MEMIF_FLAG_SOCKET_ABSTRACT ; }else if (strstr (value,"no" ) !=NULL ) {
@@ -1870,6 +1891,9 @@ memif_set_owner(const char *key, const char *value, void *extra_args)char *end =NULL ;uint32_t *id = (uint32_t *)extra_args; +if (value ==NULL || extra_args ==NULL ) +return -EINVAL ; + val =strtoul (value, &end,10 );if (*value =='\0' || *end !='\0' ) {MIF_LOG (ERR ,"Failed to parse %s: %s." , key, value);
@@ -1889,6 +1913,9 @@ memif_set_mac(const char *key __rte_unused, const char *value, void *extra_args) {struct rte_ether_addr *ether_addr = (struct rte_ether_addr *)extra_args; +if (value ==NULL || extra_args ==NULL ) +return -EINVAL ; +if (rte_ether_unformat_addr (value, ether_addr) <0 )MIF_LOG (WARNING ,"Failed to parse mac '%s'." , value);return 0 ;
@@ -1899,6 +1926,9 @@ memif_set_secret(const char *key __rte_unused, const char *value, void *extra_ar {const char **secret = (const char **)extra_args; +if (value ==NULL || extra_args ==NULL ) +return -EINVAL ; + *secret = value;return 0 ; }
Signature · 1 line
2.17.1
Re: [PATCH 2/5] net/memif: fix segment fault when parse devargs
Quoted 11 lines · Chengwen Feng
The
rte_kvargs_process()was used to parse KV pairs, it also supports to parse 'only keys' (e.g.socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.This patch fixes segment fault when parse input args with 'only keys'.
Fixes 09c7e63a71f9 ("net/memif: introduce memory interface PMD")Fixes 2f865ed07bb6 ("net/memif: use abstract socket address")Signed-off-by Chengwen Feng <[email protected]>
<...>
drivers/net/memif/rte_eth_memif.c memif_set_mac(const char *key __rte_unused, const char *value, void *extra_args) · line 1920
Quoted 9 lines
drivers/net/memif/rte_eth_memif.c +3
-0@@ -1889,6 +1913,9 @@ memif_set_mac(const char *key __rte_unused, const char *value, void *extra_args) {struct rte_ether_addr *ether_addr = (struct rte_ether_addr *)extra_args; +if (value ==NULL || extra_args ==NULL ) +return -EINVAL ; +if (rte_ether_unformat_addr (value, ether_addr) <0 )MIF_LOG (WARNING ,"Failed to parse mac '%s'." , value);
Not related to the patch, but to record it,
it seems public 'rte_ether_unformat_addr()' API is missing parameter verification, we need to fix it.
PATCH 3/5 net/pcap: fix segment fault when parse devargs
In reply to Chengwen FengThe rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/net/pcap/pcap_ethdev.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/net/pcap/pcap_ethdev.c +11 -2
@@ -1034,6 +1034,9 @@ open_rx_pcap(const char *key, const char *value, void *extra_args)struct pmd_devargs *rx = extra_args;pcap_t *pcap =NULL ; +if (value ==NULL || extra_args ==NULL ) +return -EINVAL ; +if (open_single_rx_pcap (pcap_filename, &pcap) <0 )return -1 ;
@@ -1056,6 +1059,9 @@ open_tx_pcap(const char *key, const char *value, void *extra_args)struct pmd_devargs *dumpers = extra_args;pcap_dumper_t *dumper; +if (value ==NULL || extra_args ==NULL ) +return -EINVAL ; +if (open_single_tx_pcap (pcap_filename, &dumper) <0 )return -1 ;
@@ -1077,6 +1083,9 @@ open_rx_tx_iface(const char *key, const char *value, void *extra_args)struct pmd_devargs *tx = extra_args;pcap_t *pcap =NULL ; +if (value ==NULL || extra_args ==NULL ) +return -EINVAL ; +if (open_single_iface (iface, &pcap) <0 )return -1 ;
@@ -1163,7 +1172,7 @@ static int select_phy_mac(const char *key __rte_unused, const char *value, void *extra_args) { - if (extra_args) { +if (value !=NULL && extra_args !=NULL ) {const int phy_mac =atoi (value);int *enable_phy_mac = extra_args;
@@ -1177,7 +1186,7 @@ static int get_infinite_rx_arg(const char *key __rte_unused, const char *value, void *extra_args) { - if (extra_args) { +if (value !=NULL && extra_args !=NULL ) {const int infinite_rx =atoi (value);int *enable_infinite_rx = extra_args;
Signature · 1 line
2.17.1
Re: [PATCH 3/5] net/pcap: fix segment fault when parse devargs
Quoted 4 lines · Chengwen Feng
The
rte_kvargs_process()was used to parse KV pairs, it also supports to parse 'only keys' (e.g.socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
Quoted 8 lines
This patch fixes segment fault when parse input args with 'only keys'.
Fixes 4c173302c307 ("pcap: add new driver")Fixes 53bf48403409 ("net/pcap: capture only ingress packets from Rx iface")Fixes c9507cd0cada ("net/pcap: support physical interface MAC address")Fixes a3f5252e5cbd ("net/pcap: enable infinitely Rx a pcap file")
Can you please check following callbacks too:rx_iface_args_process()open_tx_iface()
PATCH 4/5 net/ring: fix segment fault when parse devargs
In reply to Chengwen FengThe rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/net/ring/rte_eth_ring.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/net/ring/rte_eth_ring.c +6 -0
@@ -562,6 +562,9 @@ static int parse_kvlist(const char *key __rte_unused,char *node;char *end; +if (value ==NULL || data ==NULL ) +return -EINVAL ; + name =strdup (value); ret = -EINVAL ;
@@ -630,6 +633,9 @@ parse_internal_args(const char *key __rte_unused, const char *value,void *args;int ret, n; +if (value ==NULL ) +return -EINVAL ; +/* make sure 'value' is valid pointer length */ if (strnlen (value,ETH_RING_INTERNAL_ARG_MAX_LEN ) >=ETH_RING_INTERNAL_ARG_MAX_LEN ) {
Signature · 1 line
2.17.1
PATCH 5/5 net/sfc: fix segment fault when parse devargs
In reply to Chengwen FengThe rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/net/sfc/sfc.c | 3 +++ drivers/net/sfc/sfc_ev.c | 3 +++ drivers/net/sfc/sfc_kvargs.c | 6 ++++++ 3 files changed, 12 insertions(+)
drivers/net/sfc/sfc.c +3 -0
@@ -1108,6 +1108,9 @@ sfc_kvarg_fv_variant_handler(__rte_unused const char *key, {uint32_t *value = opaque; +if (value_str ==NULL || opaque ==NULL ) +return -EINVAL ; +if (strcasecmp (value_str,SFC_KVARG_FW_VARIANT_DONT_CARE ) ==0 ) *value =EFX_FW_VARIANT_DONT_CARE ;else if (strcasecmp (value_str,SFC_KVARG_FW_VARIANT_FULL_FEATURED ) ==0 )
drivers/net/sfc/sfc_ev.c +3 -0
@@ -955,6 +955,9 @@ sfc_kvarg_perf_profile_handler(__rte_unused const char *key, {uint32_t *value = opaque; +if (value_str ==NULL || opaque ==NULL ) +return -EINVAL ; +if (strcasecmp (value_str,SFC_KVARG_PERF_PROFILE_THROUGHPUT ) ==0 ) *value =EFX_EVQ_FLAGS_TYPE_THROUGHPUT ;else if (strcasecmp (value_str,SFC_KVARG_PERF_PROFILE_LOW_LATENCY ) ==0 )
drivers/net/sfc/sfc_kvargs.c +6 -0
@@ -85,6 +85,9 @@ sfc_kvarg_bool_handler(__rte_unused const char *key, };bool *value = opaque; +if (!key || !opaque) +return -EINVAL ; +if (sfc_kvarg_match_value (value_str, true_strs,RTE_DIM (true_strs))) *value = true;
@@ -120,6 +123,9 @@ int sfc_kvarg_string_handler(__rte_unused const char *key, const char *value_str, void *opaque) { + if (value_str == NULL || opaque == NULL) + return -EINVAL; + *(const char **)opaque = value_str;return 0 ;
Signature · 1 line
2.17.1
Re: [PATCH 5/5] net/sfc: fix segment fault when parse devargs
Quoted 13 lines · Chengwen Feng
The
rte_kvargs_process()was used to parse KV pairs, it also supports to parse 'only keys' (e.g.socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.This patch fixes segment fault when parse input args with 'only keys'.
Fixes 9e7fc8b8f3be ("net/sfc: add device parameter to choose FW variant")Fixes c22d3c508e0c ("net/sfc: support parameter to choose performance profile")Fixes 63d588ff2692 ("net/sfc: libefx-based driver stub")Fixes df1bfde4ff0d ("net/sfc: factor out libefx-based Rx datapath")Signed-off-by Chengwen Feng <[email protected]>
<...>
drivers/net/sfc/sfc_kvargs.c sfc_kvarg_bool_handler(__rte_unused const char *key, · line 89
Quoted 9 lines
index
783cb43ae6..f77c4af345100644drivers/net/sfc/sfc_kvargs.c +2
-0@@ -85,6 +85,9 @@ sfc_kvarg_bool_handler(__rte_unused const char *key, };bool *value = opaque; +if (!key || !opaque) +return -EINVAL ;
s/key/value_str/ ?
And better to be consistent with compression syntax, !ptr vs `ptr == NULL"
Quoted 7 lines · Chengwen Feng
The
rte_kvargs_process()was used to parse KV pairs, it also supports to parse 'only keys' (e.g.socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.It may leads to segment fault when parse args with 'only key', this patchset fixes rest of them.
Quoted 6 lines
Chengwen Feng (5):
app/pdump: fix segment fault when parse args
net/memif: fix segment fault when parse devargs
net/pcap: fix segment fault when parse devargs
net/ring: fix segment fault when parse devargs
net/sfc: fix segment fault when parse devargs
Hi Chengwen,
Did you scan all rte_kvargs_process() instances?
And if there would be a way to tell kvargs that a value is expected (or not) this checks could be done in kvargs layer, I think this also can be to look at.
Quoted 15 lines · Ferruh Yigit
Quoted 7 lines · Chengwen Feng
The
rte_kvargs_process()was used to parse KV pairs, it also supports to parse 'only keys' (e.g.socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.It may leads to segment fault when parse args with 'only key', this patchset fixes rest of them.
Quoted 6 lines
Chengwen Feng (5):
app/pdump: fix segment fault when parse args
net/memif: fix segment fault when parse devargs
net/pcap: fix segment fault when parse devargs
net/ring: fix segment fault when parse devargs
net/sfc: fix segment fault when parse devargs
Quoted 3 lines
Hi Chengwen,
Did you scan all
rte_kvargs_process()instances?
No, I was just looking at the modules I was concerned about. I looked at it briefly, and some modules had the same problem.
Quoted 5 lines
And if there would be a way to tell kvargs that a value is expected (or not) this checks could be done in kvargs layer, I think this also can be to look at.
Yes, the way to tell kvargs may lead to a lot of modifys and also break ABI.
I also think about just set value = "" when only exist key, It could perfectly solve the above segment scene. But it also break the API's behavior.
Or continue fix the exist code (about 10+ place more),
for new invoking, because the 'arg_handler_t' already well documented (52ab17efdecf935792ee1d0cb749c0dbd536c083), they'll take the initiative to prevent this.
Hope for more advise for the next.
Quoted 2 lines
.
Quoted 25 lines · fengchengwen
Quoted 15 lines · Ferruh Yigit
Quoted 7 lines · Chengwen Feng
The
rte_kvargs_process()was used to parse KV pairs, it also supports to parse 'only keys' (e.g.socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.It may leads to segment fault when parse args with 'only key', this patchset fixes rest of them.
Quoted 6 lines
Chengwen Feng (5):
app/pdump: fix segment fault when parse args
net/memif: fix segment fault when parse devargs
net/pcap: fix segment fault when parse devargs
net/ring: fix segment fault when parse devargs
net/sfc: fix segment fault when parse devargsQuoted 3 lines
Hi Chengwen,
Did you scan all
rte_kvargs_process()instances?No, I was just looking at the modules I was concerned about. I looked at it briefly, and some modules had the same problem.
Quoted 2 lines
Quoted 8 lines
Quoted 3 lines
And if there would be a way to tell kvargs that a value is expected (or not) this checks could be done in kvargs layer, I think this also can be to look at.
Yes, the way to tell kvargs may lead to a lot of modifys and also break ABI.
I also think about just set value = "" when only exist key, It could perfectly solve the above segment scene. But it also break the API's behavior.
What about having a new API, like rte_kvargs_process_extended(),
That gets an additional flag as parameter, which may have values like following to indicate if key expects a value or not:
ARG_MAY_HAVE_VALUE --> "key=value" OR 'key' ARG_WITH_VALUE --> "key=value" ARG_NO_VALUE --> 'key'
Default flag can be 'ARG_MAY_HAVE_VALUE' and it becomes same as rte_kvargs_process().
This way instead of adding checks, relevant usage can be replaced by rte_kvargs_process_extended(), this requires similar amount of change but code will be more clean I think.
Do you think does this work?
Quoted 10 lines
Or continue fix the exist code (about 10+ place more),
for new invoking, because the 'arg_handler_t' already well documented (52ab17efdecf935792ee1d0cb749c0dbd536c083), they'll take the initiative to prevent this.Hope for more advise for the next.
Quoted 2 lines
.
Quoted 43 lines · Ferruh Yigit
Quoted 25 lines · fengchengwen
Quoted 15 lines · Ferruh Yigit
Quoted 7 lines · Chengwen Feng
The
rte_kvargs_process()was used to parse KV pairs, it also supports to parse 'only keys' (e.g.socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.It may leads to segment fault when parse args with 'only key', this patchset fixes rest of them.
Quoted 6 lines
Chengwen Feng (5):
app/pdump: fix segment fault when parse args
net/memif: fix segment fault when parse devargs
net/pcap: fix segment fault when parse devargs
net/ring: fix segment fault when parse devargs
net/sfc: fix segment fault when parse devargsQuoted 3 lines
Hi Chengwen,
Did you scan all
rte_kvargs_process()instances?No, I was just looking at the modules I was concerned about. I looked at it briefly, and some modules had the same problem.
Quoted 2 lines
Quoted 8 lines
Quoted 3 lines
And if there would be a way to tell kvargs that a value is expected (or not) this checks could be done in kvargs layer, I think this also can be to look at.
Yes, the way to tell kvargs may lead to a lot of modifys and also break ABI.
I also think about just set value = "" when only exist key, It could perfectly solve the above segment scene. But it also break the API's behavior.What about having a new API, like
rte_kvargs_process_extended(),That gets an additional flag as parameter, which may have values like following to indicate if key expects a value or not:
ARG_MAY_HAVE_VALUE --> "key=value" OR 'key' ARG_WITH_VALUE --> "key=value" ARG_NO_VALUE --> 'key'
Quoted 8 lines
Default flag can be '
ARG_MAY_HAVE_VALUE' and it becomes same asrte_kvargs_process().This way instead of adding checks, relevant usage can be replaced by
rte_kvargs_process_extended(), this requires similar amount of change but code will be more clean I think.Do you think does this work?
Yes, it can work.
But I think the introduction of new API adds some complexity. And a good API definition could more simpler.
Quoted 15 lines
Quoted 12 lines
Or continue fix the exist code (about 10+ place more),
for new invoking, because the 'arg_handler_t' already well documented (52ab17efdecf935792ee1d0cb749c0dbd536c083), they'll take the initiative to prevent this.Hope for more advise for the next.
Quoted 2 lines
.
.
Quoted 51 lines · fengchengwen
Quoted 50 lines · Ferruh Yigit
Quoted 25 lines · fengchengwen
Quoted 15 lines · Ferruh Yigit
Quoted 7 lines · Chengwen Feng
The
rte_kvargs_process()was used to parse KV pairs, it also supports to parse 'only keys' (e.g.socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.It may leads to segment fault when parse args with 'only key', this patchset fixes rest of them.
Quoted 6 lines
Chengwen Feng (5):
app/pdump: fix segment fault when parse args
net/memif: fix segment fault when parse devargs
net/pcap: fix segment fault when parse devargs
net/ring: fix segment fault when parse devargs
net/sfc: fix segment fault when parse devargsQuoted 3 lines
Hi Chengwen,
Did you scan all
rte_kvargs_process()instances?No, I was just looking at the modules I was concerned about. I looked at it briefly, and some modules had the same problem.
Quoted 2 lines
Quoted 8 lines
Quoted 3 lines
And if there would be a way to tell kvargs that a value is expected (or not) this checks could be done in kvargs layer, I think this also can be to look at.
Yes, the way to tell kvargs may lead to a lot of modifys and also break ABI.
I also think about just set value = "" when only exist key, It could perfectly solve the above segment scene. But it also break the API's behavior.What about having a new API, like
rte_kvargs_process_extended(),That gets an additional flag as parameter, which may have values like following to indicate if key expects a value or not:
ARG_MAY_HAVE_VALUE --> "key=value" OR 'key' ARG_WITH_VALUE --> "key=value" ARG_NO_VALUE --> 'key'Default flag can be '
ARG_MAY_HAVE_VALUE' and it becomes same asrte_kvargs_process().This way instead of adding checks, relevant usage can be replaced by
rte_kvargs_process_extended(), this requires similar amount of change but code will be more clean I think.
Quoted 7 lines
Quoted 1 line
Do you think does this work?
Yes, it can work.
But I think the introduction of new API adds some complexity. And a good API definition could more simpler.
Other option is changing existing API, but that may be widely used and changing it impacts applications, I don't think it worth.
Of course we can live with as it is and add checks to the callback functions, although I still believe a new 'process()' API is better idea.
Quoted 15 lines
Quoted 15 lines
Quoted 12 lines
Or continue fix the exist code (about 10+ place more),
for new invoking, because the 'arg_handler_t' already well documented (52ab17efdecf935792ee1d0cb749c0dbd536c083), they'll take the initiative to prevent this.Hope for more advise for the next.
Quoted 2 lines
.
.
22/03/2023 09:53, Ferruh Yigit:
Quoted 54 lines · fengchengwen
Quoted 53 lines · Ferruh Yigit
Quoted 51 lines · fengchengwen
Quoted 25 lines · Ferruh Yigit
Quoted 15 lines · Chengwen Feng
Quoted 7 lines
The
rte_kvargs_process()was used to parse KV pairs, it also supports to parse 'only keys' (e.g.socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.It may leads to segment fault when parse args with 'only key', this patchset fixes rest of them.
Quoted 6 lines
Chengwen Feng (5):
app/pdump: fix segment fault when parse args
net/memif: fix segment fault when parse devargs
net/pcap: fix segment fault when parse devargs
net/ring: fix segment fault when parse devargs
net/sfc: fix segment fault when parse devargsQuoted 3 lines
Hi Chengwen,
Did you scan all
rte_kvargs_process()instances?No, I was just looking at the modules I was concerned about. I looked at it briefly, and some modules had the same problem.
Quoted 2 lines
Quoted 8 lines
Quoted 3 lines
And if there would be a way to tell kvargs that a value is expected (or not) this checks could be done in kvargs layer, I think this also can be to look at.
Yes, the way to tell kvargs may lead to a lot of modifys and also break ABI.
I also think about just set value = "" when only exist key, It could perfectly solve the above segment scene. But it also break the API's behavior.What about having a new API, like
rte_kvargs_process_extended(),That gets an additional flag as parameter, which may have values like following to indicate if key expects a value or not:
ARG_MAY_HAVE_VALUE --> "key=value" OR 'key' ARG_WITH_VALUE --> "key=value" ARG_NO_VALUE --> 'key'Default flag can be '
ARG_MAY_HAVE_VALUE' and it becomes same asrte_kvargs_process().This way instead of adding checks, relevant usage can be replaced by
rte_kvargs_process_extended(), this requires similar amount of change but code will be more clean I think.Do you think does this work?
Quoted 8 lines
Quoted 5 lines
Yes, it can work.
But I think the introduction of new API adds some complexity. And a good API definition could more simpler.
Other option is changing existing API, but that may be widely used and changing it impacts applications, I don't think it worth.
I've planned a change in kvargs API 5 years ago and never did it:
From doc/guides/rel_notes/deprecation.rst:
"
* kvargs: The function ``rte_kvargs_process`` will get a new parameter for returning key match count. It will ease handling of no-match case.
"
Quoted 2 lines
Of course we can live with as it is and add checks to the callback functions, although I still believe a new '
process()' API is better idea.
Quoted 64 lines · Thomas Monjalon
22/03/2023 09:53, Ferruh Yigit:
Quoted 54 lines · fengchengwen
Quoted 53 lines · Ferruh Yigit
Quoted 51 lines · fengchengwen
Quoted 25 lines · Ferruh Yigit
Quoted 15 lines · Chengwen Feng
Quoted 7 lines
The
rte_kvargs_process()was used to parse KV pairs, it also supports to parse 'only keys' (e.g.socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.It may leads to segment fault when parse args with 'only key', this patchset fixes rest of them.
Quoted 6 lines
Chengwen Feng (5):
app/pdump: fix segment fault when parse args
net/memif: fix segment fault when parse devargs
net/pcap: fix segment fault when parse devargs
net/ring: fix segment fault when parse devargs
net/sfc: fix segment fault when parse devargsQuoted 3 lines
Hi Chengwen,
Did you scan all
rte_kvargs_process()instances?No, I was just looking at the modules I was concerned about. I looked at it briefly, and some modules had the same problem.
Quoted 2 lines
Quoted 8 lines
Quoted 3 lines
And if there would be a way to tell kvargs that a value is expected (or not) this checks could be done in kvargs layer, I think this also can be to look at.
Yes, the way to tell kvargs may lead to a lot of modifys and also break ABI.
I also think about just set value = "" when only exist key, It could perfectly solve the above segment scene. But it also break the API's behavior.What about having a new API, like
rte_kvargs_process_extended(),That gets an additional flag as parameter, which may have values like following to indicate if key expects a value or not:
ARG_MAY_HAVE_VALUE --> "key=value" OR 'key' ARG_WITH_VALUE --> "key=value" ARG_NO_VALUE --> 'key'Default flag can be '
ARG_MAY_HAVE_VALUE' and it becomes same asrte_kvargs_process().This way instead of adding checks, relevant usage can be replaced by
rte_kvargs_process_extended(), this requires similar amount of change but code will be more clean I think.Do you think does this work?
Quoted 8 lines
Quoted 5 lines
Yes, it can work.
But I think the introduction of new API adds some complexity. And a good API definition could more simpler.
Other option is changing existing API, but that may be widely used and changing it impacts applications, I don't think it worth.
Quoted 6 lines
I've planned a change in kvargs API 5 years ago and never did it:
Quoted 1 line
From
doc/guides/rel_notes/deprecation.rst:"
* kvargs: The function ``rte_kvargs_process`` will get a new parameter for returning key match count. It will ease handling of no-match case.
"
I think it's okay to add extra parameter for rte_kvargs_process. But it will break ABI.
Also I notice patchset was deferred in patchwork.
Does it mean that the new version can't accept until the 23.11 release cycle ?
Quoted 8 lines
Quoted 3 lines
Of course we can live with as it is and add checks to the callback functions, although I still believe a new '
process()' API is better idea..
23/03/2023 12:58, fengchengwen:
Quoted 72 lines · Thomas Monjalon
Quoted 64 lines
22/03/2023 09:53, Ferruh Yigit:
Quoted 54 lines · fengchengwen
Quoted 53 lines · Ferruh Yigit
Quoted 51 lines · fengchengwen
Quoted 25 lines · Ferruh Yigit
Quoted 15 lines · Chengwen Feng
Quoted 7 lines
The
rte_kvargs_process()was used to parse KV pairs, it also supports to parse 'only keys' (e.g.socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.It may leads to segment fault when parse args with 'only key', this patchset fixes rest of them.
Quoted 6 lines
Chengwen Feng (5):
app/pdump: fix segment fault when parse args
net/memif: fix segment fault when parse devargs
net/pcap: fix segment fault when parse devargs
net/ring: fix segment fault when parse devargs
net/sfc: fix segment fault when parse devargsQuoted 3 lines
Hi Chengwen,
Did you scan all
rte_kvargs_process()instances?No, I was just looking at the modules I was concerned about. I looked at it briefly, and some modules had the same problem.
Quoted 2 lines
Quoted 8 lines
Quoted 3 lines
And if there would be a way to tell kvargs that a value is expected (or not) this checks could be done in kvargs layer, I think this also can be to look at.
Yes, the way to tell kvargs may lead to a lot of modifys and also break ABI.
I also think about just set value = "" when only exist key, It could perfectly solve the above segment scene. But it also break the API's behavior.What about having a new API, like
rte_kvargs_process_extended(),That gets an additional flag as parameter, which may have values like following to indicate if key expects a value or not:
ARG_MAY_HAVE_VALUE --> "key=value" OR 'key' ARG_WITH_VALUE --> "key=value" ARG_NO_VALUE --> 'key'Default flag can be '
ARG_MAY_HAVE_VALUE' and it becomes same asrte_kvargs_process().This way instead of adding checks, relevant usage can be replaced by
rte_kvargs_process_extended(), this requires similar amount of change but code will be more clean I think.Do you think does this work?
Quoted 8 lines
Quoted 5 lines
Yes, it can work.
But I think the introduction of new API adds some complexity. And a good API definition could more simpler.
Other option is changing existing API, but that may be widely used and changing it impacts applications, I don't think it worth.
Quoted 6 lines
I've planned a change in kvargs API 5 years ago and never did it:
Quoted 1 line
From
doc/guides/rel_notes/deprecation.rst:"
* kvargs: The function ``rte_kvargs_process`` will get a new parameter for returning key match count. It will ease handling of no-match case.
"
Quoted 5 lines
I think it's okay to add extra parameter for
rte_kvargs_process. But it will break ABI.
Also I notice patchset was deferred in patchwork.Does it mean that the new version can't accept until the 23.11 release cycle ?
It is a bit too late to take a decision in 23.03 cycle.
Let's continue this discussion.
We can either have some fixes in 23.07 or have an ABI breaking change in 23.11.
v2 cover fix segment fault when parse args
In reply to Chengwen FengThe rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
It may leads to segment fault when parse args with 'only key', this patchset fixes rest of them.
Chengwen Feng (44):
app/pdump: fix segment fault when parse args
ethdev: fix segment fault when parse args net/memif: fix segment fault when parse devargs net/pcap: fix segment fault when parse devargs net/ring: fix segment fault when parse devargs net/sfc: fix segment fault when parse devargs net/af_xdp: fix segment fault when parse devargs net/ark: fix segment fault when parse devargs net/cnxk: fix segment fault when parse devargs net/cxgbe: fix segment fault when parse devargs net/dpaa2: fix segment fault when parse devargs net/ena: fix segment fault when parse devargs net/enic: fix segment fault when parse devargs net/fm10k: fix segment fault when parse devargs net/i40e: fix segment fault when parse devargs net/iavf: fix segment fault when parse devargs net/ice: fix segment fault when parse devargs net/idpf: fix segment fault when parse devargs net/ionic: fix segment fault when parse devargs net/mana: fix segment fault when parse devargs net/mlx4: fix segment fault when parse devargs net/mvneta: fix segment fault when parse devargs net/mvpp2: fix segment fault when parse devargs net/netvsc: fix segment fault when parse devargs net/octeontx: fix segment fault when parse devargs net/pfe: fix segment fault when parse devargs net/qede: fix segment fault when parse devargs baseband/la12xx: fix segment fault when parse devargs bus/pci: fix segment fault when parse args common/mlx5: fix segment fault when parse devargs crypto/cnxk: fix segment fault when parse devargs crypto/dpaa_sec: fix segment fault when parse devargs crypto/dpaa2_sec: fix segment fault when parse devargs crypto/mvsam: fix segment fault when parse devargs crypto/scheduler: fix segment fault when parse devargs dma/dpaa2: fix segment fault when parse devargs event/cnxk: fix segment fault when parse devargs event/dlb2: fix segment fault when parse devargs event/dpaa: fix segment fault when parse devargs event/octeontx: fix segment fault when parse devargs event/opdl: fix segment fault when parse devargs event/sw: fix segment fault when parse devargs mempool/cnxk: fix segment fault when parse devargs raw/cnxk_gpio: fix segment fault when parse devargs
---
v2: according Ferruh's comments:
fix all 'rte_kvargs_process()' bug instances.
only judge value validation.
app/pdump/main.c | 12 ++++++ drivers/baseband/la12xx/bbdev_la12xx.c | 3 ++ drivers/bus/pci/pci_params.c | 2 + drivers/common/mlx5/mlx5_common.c | 5 +++ drivers/crypto/cnxk/cnxk_cryptodev_devargs.c | 3 ++ drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c | 2 + drivers/crypto/dpaa_sec/dpaa_sec.c | 3 ++ drivers/crypto/mvsam/rte_mrvl_pmd.c | 6 +++ drivers/crypto/scheduler/scheduler_pmd.c | 21 +++++++++++ drivers/dma/dpaa2/dpaa2_qdma.c | 3 ++ drivers/event/cnxk/cnxk_eventdev.c | 6 +++ drivers/event/cnxk/cnxk_eventdev.h | 6 +++ drivers/event/cnxk/cnxk_tim_evdev.c | 6 +++ drivers/event/dlb2/dlb2.c | 5 ++- drivers/event/dpaa/dpaa_eventdev.c | 3 ++ drivers/event/octeontx/ssovf_evdev.c | 2 + drivers/event/opdl/opdl_evdev.c | 9 +++++ drivers/event/sw/sw_evdev.c | 12 ++++++ drivers/mempool/cnxk/cnxk_mempool.c | 3 ++ drivers/net/af_xdp/rte_eth_af_xdp.c | 12 ++++++ drivers/net/ark/ark_ethdev.c | 3 ++ drivers/net/cnxk/cnxk_ethdev_devargs.c | 39 ++++++++++++++++++++ drivers/net/cnxk/cnxk_ethdev_sec.c | 12 ++++++ drivers/net/cxgbe/cxgbe_main.c | 3 ++ drivers/net/dpaa2/dpaa2_ethdev.c | 3 ++ drivers/net/ena/ena_ethdev.c | 6 +++ drivers/net/enic/enic_ethdev.c | 6 +++ drivers/net/fm10k/fm10k_ethdev.c | 3 ++ drivers/net/i40e/i40e_ethdev.c | 15 ++++++++ drivers/net/iavf/iavf_ethdev.c | 6 +++ drivers/net/ice/ice_dcf_ethdev.c | 6 +++ drivers/net/ice/ice_ethdev.c | 6 +++ drivers/net/idpf/idpf_ethdev.c | 6 +++ drivers/net/ionic/ionic_dev_pci.c | 3 ++ drivers/net/mana/mana.c | 3 ++ drivers/net/memif/rte_eth_memif.c | 30 +++++++++++++++ drivers/net/mlx4/mlx4.c | 3 ++ drivers/net/mvneta/mvneta_ethdev.c | 3 ++ drivers/net/mvpp2/mrvl_ethdev.c | 3 ++ drivers/net/mvpp2/mrvl_qos.c | 6 ++- drivers/net/netvsc/hn_ethdev.c | 3 ++ drivers/net/octeontx/octeontx_ethdev.c | 3 ++ drivers/net/pcap/pcap_ethdev.c | 18 ++++++++- drivers/net/pfe/pfe_ethdev.c | 3 ++ drivers/net/qede/qede_ethdev.c | 3 ++ drivers/net/ring/rte_eth_ring.c | 6 +++ drivers/net/sfc/sfc.c | 3 ++ drivers/net/sfc/sfc_ev.c | 3 ++ drivers/net/sfc/sfc_kvargs.c | 6 +++ drivers/raw/cnxk_gpio/cnxk_gpio.c | 6 +++ lib/ethdev/rte_class_eth.c | 6 +++ 51 files changed, 345 insertions(+), 4 deletions(-)
Signature · 1 line
2.17.1
PATCH v2 1/44 app/pdump: fix segment fault when parse args
The rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse --pdump args with 'only keys' (e.g. 'port,queue=*').
--- app/pdump/main.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
app/pdump/main.c +12 -0
@@ -170,6 +170,9 @@ parse_device_id(const char *key __rte_unused, const char *value, {struct pdump_tuples *pt = extra_args; +if (value ==NULL ) +return -EINVAL ; + pt->device_id =strdup (value); pt->dump_by_type =DEVICE_ID ;
@@ -182,6 +185,9 @@ parse_queue(const char *key __rte_unused, const char *value, void *extra_args)unsigned long n;struct pdump_tuples *pt = extra_args; +if (value ==NULL ) +return -EINVAL ; +if (!strcmp (value,"*" )) pt->queue =RTE_PDUMP_ALL_QUEUES ;else {
@@ -197,6 +203,9 @@ parse_rxtxdev(const char *key, const char *value, void *extra_args)struct pdump_tuples *pt = extra_args; +if (value ==NULL ) +return -EINVAL ; +if (!strcmp (key,PDUMP_RX_DEV_ARG )) {strlcpy (pt->rx_dev, value,sizeof (pt->rx_dev));/* identify the tx stream type for pcap vdev */
@@ -220,6 +229,9 @@ parse_uint_value(const char *key, const char *value, void *extra_args)char *end;int ret =0 ; +if (value ==NULL ) +return -EINVAL ; + errno =0 ; v = extra_args; t =strtoul (value, &end,10 );
Signature · 1 line
2.17.1
PATCH v2 2/44 ethdev: fix segment fault when parse args
In reply to Chengwen FengThe rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse args with 'only keys' (e.g. 'mac,representor').
--- lib/ethdev/rte_class_eth.c | 6 ++++++ 1 file changed, 6 insertions(+)
lib/ethdev/rte_class_eth.c +6 -0
@@ -46,6 +46,9 @@ eth_mac_cmp(const char *key __rte_unused,struct rte_eth_dev_info dev_info;uint32_t index; +if (value ==NULL ) +return -EINVAL ; +/* Parse devargs MAC address. */ if (rte_ether_unformat_addr (value, &mac) <0 )return -1 ;/* invalid devargs value */
@@ -72,6 +75,9 @@ eth_representor_cmp(const char *key __rte_unused,if ((data->dev_flags &RTE_ETH_DEV_REPRESENTOR ) ==0 )return -1 ;/* not a representor port */ +if (value ==NULL ) +return -EINVAL ; +/* Parse devargs representor values. */ values =strdup (value);if (values ==NULL )
Signature · 1 line
2.17.1
Re: [PATCH v2 02/44] ethdev: fix segment fault when parse args
Quoted 4 lines · Chengwen Feng
The
rte_kvargs_process()was used to parse KV pairs, it also supports to parse 'only keys' (e.g.socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
Quoted 8 lines
This patch fixes segment fault when parse args with 'only keys' (e.g. 'mac,representor').
Fixes c10cdce180a6 ("ethdev: support MAC address as iterator filter")Fixes a7d3c6271d55 ("ethdev: support representor id as iterator filter")Signed-off-by Chengwen Feng <[email protected]>
PATCH v2 3/44 net/memif: fix segment fault when parse devargs
In reply to Chengwen FengThe rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/net/memif/rte_eth_memif.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
drivers/net/memif/rte_eth_memif.c +30 -0
@@ -1720,6 +1720,9 @@ memif_set_role(const char *key __rte_unused, const char *value, {enum memif_role_t *role = (enum memif_role_t *)extra_args; +if (value ==NULL ) +return -EINVAL ; +if (strstr (value,"server" ) !=NULL ) { *role =MEMIF_ROLE_SERVER ; }else if (strstr (value,"client" ) !=NULL ) {
@@ -1742,6 +1745,9 @@ memif_set_zc(const char *key __rte_unused, const char *value, void *extra_args) {uint32_t *flags = (uint32_t *)extra_args; +if (value ==NULL ) +return -EINVAL ; +if (strstr (value,"yes" ) !=NULL ) {if (!rte_mcfg_get_single_file_segments ()) {MIF_LOG (ERR ,"Zero-copy doesn't support multi-file segments." );
@@ -1762,6 +1768,9 @@ memif_set_id(const char *key __rte_unused, const char *value, void *extra_args) {memif_interface_id_t *id = (memif_interface_id_t *)extra_args; +if (value ==NULL ) +return -EINVAL ; +/* even if parsing fails, 0 is a valid id */ *id =strtoul (value,NULL ,10 );return 0 ;
@@ -1773,6 +1782,9 @@ memif_set_bs(const char *key __rte_unused, const char *value, void *extra_args)unsigned long tmp;uint16_t *pkt_buffer_size = (uint16_t *)extra_args; +if (value ==NULL ) +return -EINVAL ; + tmp =strtoul (value,NULL ,10 );if (tmp ==0 || tmp >0xFFFF ) {MIF_LOG (ERR ,"Invalid buffer size: %s." , value);
@@ -1789,6 +1801,9 @@ memif_set_rs(const char *key __rte_unused, const char *value, void *extra_args)memif_log2_ring_size_t *log2_ring_size = (memif_log2_ring_size_t *)extra_args; +if (value ==NULL ) +return -EINVAL ; + tmp =strtoul (value,NULL ,10 );if (tmp ==0 || tmp >ETH_MEMIF_MAX_LOG2_RING_SIZE ) { MIF_LOG(ERR, "Invalid ring size: %s (max %u).",
@@ -1840,6 +1855,9 @@ memif_set_socket_filename(const char *key __rte_unused, const char *value, {const char **socket_filename = (const char **)extra_args; +if (value ==NULL ) +return -EINVAL ; + *socket_filename = value;return 0 ; }
@@ -1849,6 +1867,9 @@ memif_set_is_socket_abstract(const char *key __rte_unused, const char *value, vo {uint32_t *flags = (uint32_t *)extra_args; +if (value ==NULL ) +return -EINVAL ; +if (strstr (value,"yes" ) !=NULL ) { *flags |=ETH_MEMIF_FLAG_SOCKET_ABSTRACT ; }else if (strstr (value,"no" ) !=NULL ) {
@@ -1870,6 +1891,9 @@ memif_set_owner(const char *key, const char *value, void *extra_args)char *end =NULL ;uint32_t *id = (uint32_t *)extra_args; +if (value ==NULL ) +return -EINVAL ; + val =strtoul (value, &end,10 );if (*value =='\0' || *end !='\0' ) {MIF_LOG (ERR ,"Failed to parse %s: %s." , key, value);
@@ -1889,6 +1913,9 @@ memif_set_mac(const char *key __rte_unused, const char *value, void *extra_args) {struct rte_ether_addr *ether_addr = (struct rte_ether_addr *)extra_args; +if (value ==NULL ) +return -EINVAL ; +if (rte_ether_unformat_addr (value, ether_addr) <0 )MIF_LOG (WARNING ,"Failed to parse mac '%s'." , value);return 0 ;
@@ -1899,6 +1926,9 @@ memif_set_secret(const char *key __rte_unused, const char *value, void *extra_ar {const char **secret = (const char **)extra_args; +if (value ==NULL ) +return -EINVAL ; + *secret = value;return 0 ; }
Signature · 1 line
2.17.1
PATCH v2 4/44 net/pcap: fix segment fault when parse devargs
In reply to Chengwen FengThe rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/net/pcap/pcap_ethdev.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
drivers/net/pcap/pcap_ethdev.c +16 -2
@@ -1034,6 +1034,9 @@ open_rx_pcap(const char *key, const char *value, void *extra_args)struct pmd_devargs *rx = extra_args;pcap_t *pcap =NULL ; +if (value ==NULL ) +return -EINVAL ; +if (open_single_rx_pcap (pcap_filename, &pcap) <0 )return -1 ;
@@ -1056,6 +1059,9 @@ open_tx_pcap(const char *key, const char *value, void *extra_args)struct pmd_devargs *dumpers = extra_args;pcap_dumper_t *dumper; +if (value ==NULL ) +return -EINVAL ; +if (open_single_tx_pcap (pcap_filename, &dumper) <0 )return -1 ;
@@ -1077,6 +1083,9 @@ open_rx_tx_iface(const char *key, const char *value, void *extra_args)struct pmd_devargs *tx = extra_args;pcap_t *pcap =NULL ; +if (value ==NULL ) +return -EINVAL ; +if (open_single_iface (iface, &pcap) <0 )return -1 ;
@@ -1143,6 +1152,9 @@ open_rx_iface(const char *key, const char *value, void *extra_args)static inline int rx_iface_args_process (const char *key,const char *value,void *extra_args) { +if (value ==NULL ) +return -EINVAL ; +if (strcmp (key,ETH_PCAP_RX_IFACE_ARG ) ==0 ||strcmp (key,ETH_PCAP_RX_IFACE_IN_ARG ) ==0 )return open_rx_iface (key, value, extra_args);
@@ -1156,6 +1168,8 @@ rx_iface_args_process(const char *key, const char *value, void *extra_args)static int open_tx_iface (const char *key,const char *value,void *extra_args) { +if (value ==NULL ) +return -EINVAL ;return open_iface (key, value, extra_args); }
@@ -1163,7 +1177,7 @@ static int select_phy_mac(const char *key __rte_unused, const char *value, void *extra_args) { - if (extra_args) { +if (value !=NULL && extra_args !=NULL ) {const int phy_mac =atoi (value);int *enable_phy_mac = extra_args;
@@ -1177,7 +1191,7 @@ static int get_infinite_rx_arg(const char *key __rte_unused, const char *value, void *extra_args) { - if (extra_args) { +if (value !=NULL && extra_args !=NULL ) {const int infinite_rx =atoi (value);int *enable_infinite_rx = extra_args;
Signature · 1 line
2.17.1
Re: [PATCH v2 04/44] net/pcap: fix segment fault when parse devargs
Quoted 6 lines · On Mon, 20 Mar 2023 09:20:30 +0000 Chengwen Feng <[email protected]>…
The
rte_kvargs_process()was used to parse KV pairs, it also supports to parse 'only keys' (e.g.socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.This patch fixes segment fault when parse input args with 'only keys'.
Quoted 7 lines
Fixes 4c173302c307 ("pcap: add new driver")Fixes 53bf48403409 ("net/pcap: capture only ingress packets from Rx iface")Fixes c9507cd0cada ("net/pcap: support physical interface MAC address")Fixes a3f5252e5cbd ("net/pcap: enable infinitely Rx a pcap file")Signed-off-by Chengwen Feng <[email protected]>
PATCH v2 5/44 net/ring: fix segment fault when parse devargs
In reply to Chengwen FengThe rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/net/ring/rte_eth_ring.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/net/ring/rte_eth_ring.c +6 -0
@@ -562,6 +562,9 @@ static int parse_kvlist(const char *key __rte_unused,char *node;char *end; +if (value ==NULL ) +return -EINVAL ; + name =strdup (value); ret = -EINVAL ;
@@ -630,6 +633,9 @@ parse_internal_args(const char *key __rte_unused, const char *value,void *args;int ret, n; +if (value ==NULL ) +return -EINVAL ; +/* make sure 'value' is valid pointer length */ if (strnlen (value,ETH_RING_INTERNAL_ARG_MAX_LEN ) >=ETH_RING_INTERNAL_ARG_MAX_LEN ) {
Signature · 1 line
2.17.1
PATCH v2 6/44 net/sfc: fix segment fault when parse devargs
In reply to Chengwen FengThe rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/net/sfc/sfc.c | 3 +++ drivers/net/sfc/sfc_ev.c | 3 +++ drivers/net/sfc/sfc_kvargs.c | 6 ++++++ 3 files changed, 12 insertions(+)
drivers/net/sfc/sfc.c +3 -0
@@ -1108,6 +1108,9 @@ sfc_kvarg_fv_variant_handler(__rte_unused const char *key, {uint32_t *value = opaque; +if (value_str ==NULL ) +return -EINVAL ; +if (strcasecmp (value_str,SFC_KVARG_FW_VARIANT_DONT_CARE ) ==0 ) *value =EFX_FW_VARIANT_DONT_CARE ;else if (strcasecmp (value_str,SFC_KVARG_FW_VARIANT_FULL_FEATURED ) ==0 )
drivers/net/sfc/sfc_ev.c +3 -0
@@ -955,6 +955,9 @@ sfc_kvarg_perf_profile_handler(__rte_unused const char *key, {uint32_t *value = opaque; +if (value_str ==NULL ) +return -EINVAL ; +if (strcasecmp (value_str,SFC_KVARG_PERF_PROFILE_THROUGHPUT ) ==0 ) *value =EFX_EVQ_FLAGS_TYPE_THROUGHPUT ;else if (strcasecmp (value_str,SFC_KVARG_PERF_PROFILE_LOW_LATENCY ) ==0 )
drivers/net/sfc/sfc_kvargs.c +6 -0
@@ -85,6 +85,9 @@ sfc_kvarg_bool_handler(__rte_unused const char *key, };bool *value = opaque; +if (value_str ==NULL ) +return -EINVAL ; +if (sfc_kvarg_match_value (value_str, true_strs,RTE_DIM (true_strs))) *value = true;
@@ -120,6 +123,9 @@ int sfc_kvarg_string_handler(__rte_unused const char *key, const char *value_str, void *opaque) { + if (value_str == NULL) + return -EINVAL; + *(const char **)opaque = value_str;return 0 ;
Signature · 1 line
2.17.1
Re: [PATCH v2 06/44] net/sfc: fix segment fault when parse devargs
Quoted 6 lines · Chengwen Feng
The
rte_kvargs_process()was used to parse KV pairs, it also supports to parse 'only keys' (e.g.socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.This patch fixes segment fault when parse input args with 'only keys'.
Quoted 7 lines
Fixes 9e7fc8b8f3be ("net/sfc: add device parameter to choose FW variant")Fixes c22d3c508e0c ("net/sfc: support parameter to choose performance profile")Fixes 63d588ff2692 ("net/sfc: libefx-based driver stub")Fixes df1bfde4ff0d ("net/sfc: factor out libefx-based Rx datapath")Signed-off-by Chengwen Feng <[email protected]>
PATCH v2 7/44 net/af_xdp: fix segment fault when parse devargs
In reply to Chengwen FengThe rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/net/af_xdp/rte_eth_af_xdp.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/net/af_xdp/rte_eth_af_xdp.c +12 -0
@@ -1897,6 +1897,9 @@ parse_budget_arg(const char *key __rte_unused,int *i = (int *)extra_args;char *end; +if (value ==NULL ) +return -EINVAL ; + *i =strtol (value, &end,10 );if (*i <0 || *i >UINT16_MAX ) { AF_XDP_LOG(ERR, "Invalid busy_budget %i, must be >= 0 and <= %u\n",
@@ -1915,6 +1918,9 @@ parse_integer_arg(const char *key __rte_unused,int *i = (int *)extra_args;char *end; +if (value ==NULL ) +return -EINVAL ; + *i =strtol (value, &end,10 );if (*i <0 ) {AF_XDP_LOG (ERR ,"Argument has to be positive.\n" );
@@ -1931,6 +1937,9 @@ parse_name_arg(const char *key __rte_unused, {char *name = extra_args; +if (value ==NULL ) +return -EINVAL ; +if (strnlen (value,IFNAMSIZ ) >IFNAMSIZ -1 ) {AF_XDP_LOG (ERR ,"Invalid name %s, should be less than %u bytes.\n" , value,IFNAMSIZ );
@@ -1949,6 +1958,9 @@ parse_prog_arg(const char *key __rte_unused, {char *path = extra_args; +if (value ==NULL ) +return -EINVAL ; +if (strnlen (value,PATH_MAX ) ==PATH_MAX ) {AF_XDP_LOG (ERR ,"Invalid path %s, should be less than %u bytes.\n" , value,PATH_MAX );
Signature · 1 line
2.17.1
PATCH v2 8/44 net/ark: fix segment fault when parse devargs
In reply to Chengwen FengThe rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/net/ark/ark_ethdev.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/ark/ark_ethdev.c +3 -0
@@ -898,6 +898,9 @@ process_pktdir_arg(const char *key, const char *value,struct ark_adapter *ark = (struct ark_adapter *)extra_args; +if (value ==NULL ) +return -EINVAL ; + ark->pkt_dir_v =strtol (value,NULL ,16 );ARK_PMD_LOG (DEBUG ,"pkt_dir_v = 0x%x\n" , ark->pkt_dir_v);return 0 ;
Signature · 1 line
2.17.1
PATCH v2 9/44 net/cnxk: fix segment fault when parse devargs
In reply to Chengwen FengThe rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/net/cnxk/cnxk_ethdev_devargs.c | 39 ++++++++++++++++++++++++++ drivers/net/cnxk/cnxk_ethdev_sec.c | 12 ++++++++ 2 files changed, 51 insertions(+)
drivers/net/cnxk/cnxk_ethdev_devargs.c +39 -0
@@ -25,6 +25,9 @@ parse_outb_nb_desc(const char *key, const char *value, void *extra_args)RTE_SET_USED (key);uint32_t val; +if (value ==NULL ) +return -EINVAL ; + val =atoi (value); *(uint16_t *)extra_args = val;
@@ -38,6 +41,9 @@ parse_outb_nb_crypto_qs(const char *key, const char *value, void *extra_args)RTE_SET_USED (key);uint32_t val; +if (value ==NULL ) +return -EINVAL ; + val =atoi (value);if (val <1 || val >64 )
@@ -54,6 +60,9 @@ parse_ipsec_in_spi_range(const char *key, const char *value, void *extra_args)RTE_SET_USED (key);uint32_t val; +if (value ==NULL ) +return -EINVAL ; + errno =0 ; val =strtoul (value,NULL ,0 );if (errno)
@@ -70,6 +79,9 @@ parse_ipsec_out_max_sa(const char *key, const char *value, void *extra_args)RTE_SET_USED (key);uint32_t val; +if (value ==NULL ) +return -EINVAL ; + errno =0 ; val =strtoul (value,NULL ,0 );if (errno)
@@ -86,6 +98,9 @@ parse_flow_max_priority(const char *key, const char *value, void *extra_args)RTE_SET_USED (key);uint16_t val; +if (value ==NULL ) +return -EINVAL ; + val =atoi (value);/* Limit the max priority to 32 */
@@ -103,6 +118,9 @@ parse_flow_prealloc_size(const char *key, const char *value, void *extra_args)RTE_SET_USED (key);uint16_t val; +if (value ==NULL ) +return -EINVAL ; + val =atoi (value);/* Limit the prealloc size to 32 */
@@ -120,6 +138,9 @@ parse_reta_size(const char *key, const char *value, void *extra_args)RTE_SET_USED (key);uint32_t val; +if (value ==NULL ) +return -EINVAL ; + val =atoi (value);if (val <=RTE_ETH_RSS_RETA_SIZE_64 )
@@ -144,6 +165,9 @@ parse_pre_l2_hdr_info(const char *key, const char *value, void *extra_args)char *tok1 =NULL , *tok2 =NULL ;uint16_t off, off_mask, dir; +if (value ==NULL ) +return -EINVAL ; +RTE_SET_USED (key); off =strtol (value, &tok1,16 ); tok1++;
@@ -164,6 +188,9 @@ parse_flag(const char *key, const char *value, void *extra_args) {RTE_SET_USED (key); +if (value ==NULL ) +return -EINVAL ; + *(uint16_t *)extra_args =atoi (value);return 0 ;
@@ -175,6 +202,9 @@ parse_sqb_count(const char *key, const char *value, void *extra_args)RTE_SET_USED (key);uint32_t val; +if (value ==NULL ) +return -EINVAL ; + val =atoi (value); *(uint16_t *)extra_args = val;
@@ -188,6 +218,9 @@ parse_meta_bufsize(const char *key, const char *value, void *extra_args)RTE_SET_USED (key);uint32_t val; +if (value ==NULL ) +return -EINVAL ; + errno =0 ; val =strtoul (value,NULL ,0 );if (errno)
@@ -203,6 +236,9 @@ parse_switch_header_type(const char *key, const char *value, void *extra_args) {RTE_SET_USED (key); +if (value ==NULL ) +return -EINVAL ; +if (strcmp (value,"higig2" ) ==0 ) *(uint16_t *)extra_args =ROC_PRIV_FLAGS_HIGIG ;
@@ -231,6 +267,9 @@ parse_sdp_channel_mask(const char *key, const char *value, void *extra_args)uint16_t chan =0 , mask =0 ;char *next =0 ; +if (value ==NULL ) +return -EINVAL ; +/* next will point to the separator '/' */ chan =strtol (value, &next,16 ); mask =strtol (++next,0 ,16 );
drivers/net/cnxk/cnxk_ethdev_sec.c +12 -0
@@ -133,6 +133,9 @@ parse_max_ipsec_rules(const char *key, const char *value, void *extra_args)RTE_SET_USED (key);uint32_t val; +if (value ==NULL ) +return -EINVAL ; + val =atoi (value);if (val <1 || val >4095 )
@@ -248,6 +251,9 @@ parse_val_u32(const char *key, const char *value, void *extra_args)RTE_SET_USED (key);uint32_t val; +if (value ==NULL ) +return -EINVAL ; + errno =0 ; val =strtoul (value,NULL ,0 );if (errno)
@@ -264,6 +270,9 @@ parse_selftest(const char *key, const char *value, void *extra_args)RTE_SET_USED (key);uint32_t val; +if (value ==NULL ) +return -EINVAL ; + val =atoi (value); *(uint8_t *)extra_args = !!(val ==1 );
@@ -277,6 +286,9 @@ parse_inl_cpt_channel(const char *key, const char *value, void *extra_args)uint16_t chan =0 , mask =0 ;char *next =0 ; +if (value ==NULL ) +return -EINVAL ; +/* next will point to the separator '/' */ chan =strtol (value, &next,16 ); mask =strtol (++next,0 ,16 );
Signature · 1 line
2.17.1
PATCH v2 10/44 net/cxgbe: fix segment fault when parse devargs
In reply to Chengwen FengThe rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/net/cxgbe/cxgbe_main.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/cxgbe/cxgbe_main.c +3 -0
@@ -746,6 +746,9 @@ void cxgbe_print_port_info(struct adapter *adap)static int check_devargs_handler (const char *key,const char *value,void *p) { +if (value ==NULL ) +return -EINVAL ; +if (!strncmp (key,CXGBE_DEVARG_CMN_KEEP_OVLAN ,strlen (key)) || !strncmp (key,CXGBE_DEVARG_CMN_TX_MODE_LATENCY ,strlen (key)) || !strncmp (key,CXGBE_DEVARG_VF_FORCE_LINK_UP ,strlen (key))) {
Signature · 1 line
2.17.1
PATCH v2 11/44 net/dpaa2: fix segment fault when parse devargs
In reply to Chengwen FengThe rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/net/dpaa2/dpaa2_ethdev.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/dpaa2/dpaa2_ethdev.c +3 -0
@@ -2545,6 +2545,9 @@ static int check_devargs_handler(__rte_unused const char *key, const char *value, __rte_unused void *opaque) { + if (value == NULL) + return -EINVAL; +if (strcmp (value,"1" ))return -1 ;
Signature · 1 line
2.17.1
PATCH v2 12/44 net/ena: fix segment fault when parse devargs
In reply to Chengwen FengThe rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/net/ena/ena_ethdev.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/net/ena/ena_ethdev.c +6 -0
@@ -3444,6 +3444,9 @@ static int ena_process_uint_devarg(const char *key,char *str_end;uint64_t uint_value; +if (value ==NULL ) +return -EINVAL ; + uint_value =strtoull (value, &str_end,10 );if (value == str_end) { PMD_INIT_LOG(ERR,
@@ -3482,6 +3485,9 @@ static int ena_process_bool_devarg(const char *key,struct ena_adapter *adapter = opaque;bool bool_value; +if (value ==NULL ) +return -EINVAL ; +/* Parse the value. */ if (strcmp (value,"1" ) ==0 ) { bool_value = true;
Signature · 1 line
2.17.1
PATCH v2 13/44 net/enic: fix segment fault when parse devargs
In reply to Chengwen FengThe rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/net/enic/enic_ethdev.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/net/enic/enic_ethdev.c +6 -0
@@ -1148,6 +1148,9 @@ static int enic_parse_zero_one(const char *key,struct enic *enic;bool b; +if (value ==NULL ) +return -EINVAL ; + enic = (struct enic *)opaque;if (strcmp (value,"0" ) ==0 ) { b = false;
@@ -1173,6 +1176,9 @@ static int enic_parse_ig_vlan_rewrite(__rte_unused const char *key, {struct enic *enic; +if (value ==NULL ) +return -EINVAL ; + enic = (struct enic *)opaque;if (strcmp (value,"trunk" ) ==0 ) {/* Trunk mode: always tag */
Signature · 1 line
2.17.1
Re: [PATCH v2 13/44] net/enic: fix segment fault when parse devargs
From: Chengwen Feng <[email protected]>
Date: Monday, March 20, 2023 at 2:28 AM
To: [email protected] <[email protected]>, [email protected] <[email protected]>, John Daley (johndale) <[email protected]>, Hyong Youb Kim (hyonkim) <[email protected]>
Cc: [email protected] <[email protected]>
Subject: [PATCH v2 13/44] net/enic: fix segment fault when parse devargs
The rte_kvargs_process() was used to parse KV pairs, it also supports
to parse 'only keys' (e.g. socket_id) type. And the callback function
parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/net/enic/enic_ethdev.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/net/enic/enic_ethdev.c +6 -0
@@ -1148,6 +1148,9 @@ static int enic_parse_zero_one(const char *key,struct enic *enic;bool b; +if (value ==NULL ) +return -EINVAL ; + enic = (struct enic *)opaque;if (strcmp (value,"0" ) ==0 ) { b = false;
@@ -1173,6 +1176,9 @@ static int enic_parse_ig_vlan_rewrite(__rte_unused const char *key, {struct enic *enic; +if (value ==NULL ) +return -EINVAL ; + enic = (struct enic *)opaque;if (strcmp (value,"trunk" ) ==0 ) {/* Trunk mode: always tag */
--
2.17.1
PATCH v2 14/44 net/fm10k: fix segment fault when parse devargs
In reply to Chengwen FengThe rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/net/fm10k/fm10k_ethdev.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/fm10k/fm10k_ethdev.c +3 -0
@@ -2873,6 +2873,9 @@ static const struct eth_dev_ops fm10k_eth_dev_ops = { static int ftag_check_handler(__rte_unused const char *key, const char *value, __rte_unused void *opaque) { +if (value ==NULL ) +return -EINVAL ; +if (strcmp (value,"1" ))return -1 ;
Signature · 1 line
2.17.1
PATCH v2 15/44 net/i40e: fix segment fault when parse devargs
In reply to Chengwen FengThe rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/net/i40e/i40e_ethdev.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
drivers/net/i40e/i40e_ethdev.c +15 -0
@@ -829,6 +829,9 @@ floating_veb_list_handler(__rte_unused const char *key,int min, max;bool *vf_floating_veb = opaque; +if (floating_veb_value ==NULL ) +return -EINVAL ; +while (isblank (*floating_veb_value)) floating_veb_value++;
@@ -921,6 +924,9 @@ i40e_check_floating_handler(__rte_unused const char *key, const char *value, __rte_unused void *opaque) { + if (value == NULL) + return -EINVAL; +if (strcmp (value,"1" ))return -1 ;
@@ -1258,6 +1264,9 @@ i40e_parse_multi_drv_handler(__rte_unused const char *key, pf = (struct i40e_pf *)opaque; +if (value ==NULL ) +return -EINVAL ; + errno =0 ; support_multi_driver =strtoul (value, &end,10 );if (errno !=0 || end == value || *end !=0 ) {
@@ -1347,6 +1356,9 @@ read_vf_msg_config(__rte_unused const char *key, {struct i40e_vf_msg_cfg *cfg = opaque; +if (value ==NULL ) +return -EINVAL ; +if (sscanf (value,"%u@%u:%u" , &cfg->max_msg, &cfg->period, &cfg->ignore_second) !=3 ) {memset (cfg,0 ,sizeof (*cfg));
@@ -4693,6 +4705,9 @@ static int i40e_pf_parse_vf_queue_number_handler(const char *key, pf = (struct i40e_pf *)opaque;RTE_SET_USED (key); +if (value ==NULL ) +return -EINVAL ; + errno =0 ; num =strtoul (value, &end,0 );if (errno !=0 || end == value || *end !=0 ) {
Signature · 1 line
2.17.1
PATCH v2 16/44 net/iavf: fix segment fault when parse devargs
In reply to Chengwen FengThe rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/net/iavf/iavf_ethdev.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/net/iavf/iavf_ethdev.c +6 -0
@@ -2185,6 +2185,9 @@ parse_u16(__rte_unused const char *key, const char *value, void *args)u16 *num = (u16 *)args;u16 tmp; +if (value ==NULL ) +return -EINVAL ; + errno =0 ; tmp =strtoull (value,NULL ,10 );if (errno || !tmp) {
@@ -2815,6 +2818,9 @@ static int iavf_dcf_cap_check_handler(__rte_unused const char *key, const char *value, __rte_unused void *opaque) { + if (value == NULL) + return -EINVAL; +if (strcmp (value,"dcf" ))return -1 ;
Signature · 1 line
2.17.1
PATCH v2 17/44 net/ice: fix segment fault when parse devargs
In reply to Chengwen FengThe rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/net/ice/ice_dcf_ethdev.c | 6 ++++++ drivers/net/ice/ice_ethdev.c | 6 ++++++ 2 files changed, 12 insertions(+)
drivers/net/ice/ice_dcf_ethdev.c +6 -0
@@ -1933,6 +1933,9 @@ static int ice_dcf_engine_disabled_handler(__rte_unused const char *key, const char *value, __rte_unused void *opaque) { + if (value == NULL) + return -EINVAL; +if (strcmp (value,"off" ))return -1 ;
@@ -1943,6 +1946,9 @@ static int ice_dcf_cap_check_handler(__rte_unused const char *key, const char *value, __rte_unused void *opaque) { + if (value == NULL) + return -EINVAL; +if (strcmp (value,"dcf" ))return -1 ;
drivers/net/ice/ice_ethdev.c +6 -0
@@ -1887,6 +1887,9 @@ parse_bool(const char *key, const char *value, void *args)char *end;int num; +if (value ==NULL ) +return -EINVAL ; + num =strtoul (value, &end,10 );if (num !=0 && num !=1 ) {
@@ -1906,6 +1909,9 @@ parse_u64(const char *key, const char *value, void *args)u64 *num = (u64 *)args;u64 tmp; +if (value ==NULL ) +return -EINVAL ; + errno =0 ; tmp =strtoull (value,NULL ,16 );if (errno) {
Signature · 1 line
2.17.1
PATCH v2 18/44 net/idpf: fix segment fault when parse devargs
In reply to Chengwen FengThe rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/net/idpf/idpf_ethdev.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/net/idpf/idpf_ethdev.c +6 -0
@@ -903,6 +903,9 @@ parse_vport(const char *key, const char *value, void *args)struct idpf_devargs *devargs = args;const char *pos = value; +if (value ==NULL ) +return -EINVAL ; + devargs->req_vport_nb =0 ;if (*pos =='[' )
@@ -936,6 +939,9 @@ parse_bool(const char *key, const char *value, void *args)char *end;int num; +if (value ==NULL ) +return -EINVAL ; + errno =0 ; num =strtoul (value, &end,10 );
Signature · 1 line
2.17.1
PATCH v2 19/44 net/ionic: fix segment fault when parse devargs
In reply to Chengwen FengThe rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/net/ionic/ionic_dev_pci.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/ionic/ionic_dev_pci.c +3 -0
@@ -103,6 +103,9 @@ ionic_pci_devarg_cmb(const char *key __rte_unused, const char *val, void *arg) {struct ionic_adapter *adapter = arg; +if (val ==NULL ) +return -EINVAL ; +if (!strcmp (val,"1" )) {IONIC_PRINT (NOTICE ,"%s enabled" ,PMD_IONIC_CMB_KVARG ); adapter->q_in_cmb = true;
Signature · 1 line
2.17.1
PATCH v2 20/44 net/mana: fix segment fault when parse devargs
In reply to Chengwen FengThe rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/net/mana/mana.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/mana/mana.c +3 -0
@@ -750,6 +750,9 @@ mana_arg_parse_callback(const char *key, const char *val, void *private)return 1 ; } +if (val ==NULL ) +return -EINVAL ; + ret =rte_ether_unformat_addr (val, &conf->mac_array[conf->index]);if (ret) {DRV_LOG (ERR ,"Invalid MAC address %s" , val);
Signature · 1 line
2.17.1
RE: [PATCH v2 20/44] net/mana: fix segment fault when parse devargs
Quoted 6 lines
Subject: [PATCH v2 20/44] net/mana: fix segment fault when parse devargs
The
rte_kvargs_process()was used to parse KV pairs, it also supports to parse 'only keys' (e.g.socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
Quoted 6 lines
This patch fixes segment fault when parse input args with 'only keys'.
Fixes 517ed6e2d590 ("net/mana: add basic driver with build environment")Signed-off-by Chengwen Feng <[email protected]>
Quoted 21 lines
--- drivers/net/mana/mana.c | 3 +++ 1 file changed, 3 insertions(+)drivers/net/mana/mana.c index renamed from drivers/net/mana/mana.c +0
-0
8a782c0d63..9c097c02ba100644drivers/net/mana/mana.c +3
-0@@ -750,6 +750,9 @@ mana_arg_parse_callback(const char *key, const char *val, void *private)return 1 ; } +if (val ==NULL ) +return -EINVAL ; + ret =rte_ether_unformat_addr (val, &conf->mac_array[conf->index]);if (ret) {
DRV_LOG(ERR, "Invalid MAC address %s", val);
--
2.17.1
PATCH v2 21/44 net/mlx4: fix segment fault when parse devargs
In reply to Chengwen FengThe rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/net/mlx4/mlx4.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/mlx4/mlx4.c +3 -0
@@ -521,6 +521,9 @@ mlx4_arg_parse(const char *key, const char *val, struct mlx4_conf *conf) {unsigned long tmp; +if (val ==NULL ) +return -EINVAL ; + errno =0 ; tmp =strtoul (val,NULL ,0 );if (errno) {
Signature · 1 line
2.17.1
PATCH v2 22/44 net/mvneta: fix segment fault when parse devargs
In reply to Chengwen FengThe rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/net/mvneta/mvneta_ethdev.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/mvneta/mvneta_ethdev.c +3 -0
@@ -91,6 +91,9 @@ mvneta_ifnames_get(const char *key __rte_unused, const char *value, {struct mvneta_ifnames *ifnames = extra_args; +if (value ==NULL ) +return -EINVAL ; + ifnames->names[ifnames->idx++] = value;return 0 ;
Signature · 1 line
2.17.1
RE: [EXT] [PATCH v2 22/44] net/mvneta: fix segment fault when parse devargs
-----Original Message-----
From: Chengwen Feng <[email protected]>
Sent: Monday, 20 March 2023 11:21
To: [email protected]; [email protected]; Zyta Szpak <[email protected]>; Liron Himi <[email protected]>; Dmitri Epshtein <[email protected]>; Natalie Samsonov <[email protected]>; Andrzej Ostruszka <[email protected]>; Yelena Krivosheev <[email protected]>
Cc: [email protected]
Subject: [EXT] [PATCH v2 22/44] net/mvneta: fix segment fault when parse devargs
External Email
----------------------------------------------------------------------
The rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/net/mvneta/mvneta_ethdev.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/mvneta/mvneta_ethdev.c +3 -1
@@ -91,6 +91,9 @@ mvneta_ifnames_get(const char *key __rte_unused, const char *value, {struct mvneta_ifnames *ifnames = extra_args; +if (value ==NULL ) +return -EINVAL ; + ifnames->names[ifnames->idx++] = value;return 0 ; --
2.17.1
PATCH v2 23/44 net/mvpp2: fix segment fault when parse devargs
In reply to Chengwen FengThe rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/net/mvpp2/mrvl_ethdev.c | 3 +++ drivers/net/mvpp2/mrvl_qos.c | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-)
drivers/net/mvpp2/mrvl_ethdev.c +3 -0
@@ -3180,6 +3180,9 @@ mrvl_get_ifnames(const char *key __rte_unused, const char *value, {struct mrvl_ifnames *ifnames = extra_args; +if (value ==NULL ) +return -EINVAL ; + ifnames->names[ifnames->idx++] = value;return 0 ;
drivers/net/mvpp2/mrvl_qos.c +5 -1
@@ -656,12 +656,16 @@ int mrvl_get_cfg(const char *key __rte_unused, const char *path, void *extra_args) { struct mrvl_cfg **cfg = extra_args; -struct rte_cfgfile *file =rte_cfgfile_load (path,0 ); +struct rte_cfgfile *file;uint32_t val;int n, i, ret;const char *entry;char sec_name[32 ]; +if (path ==NULL ) +return -EINVAL ; + + file =rte_cfgfile_load (path,0 );if (file ==NULL ) {MRVL_LOG (ERR ,"Cannot load configuration %s\n" , path);return -1 ;
Signature · 1 line
2.17.1
RE: [EXT] [PATCH v2 23/44] net/mvpp2: fix segment fault when parse devargs
-----Original Message-----
From: Chengwen Feng <[email protected]>
Sent: Monday, 20 March 2023 11:21
To: [email protected]; [email protected]; Liron Himi <[email protected]>; Tomasz Duszynski <[email protected]>; Jacek Siuda <[email protected]>
Cc: [email protected]
Subject: [EXT] [PATCH v2 23/44] net/mvpp2: fix segment fault when parse devargs
External Email
----------------------------------------------------------------------
The rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/net/mvpp2/mrvl_ethdev.c | 3 +++ drivers/net/mvpp2/mrvl_qos.c | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-)
drivers/net/mvpp2/mrvl_ethdev.c +3 -0
@@ -3180,6 +3180,9 @@ mrvl_get_ifnames(const char *key __rte_unused, const char *value, {struct mrvl_ifnames *ifnames = extra_args; +if (value ==NULL ) +return -EINVAL ; + ifnames->names[ifnames->idx++] = value;return 0 ;
drivers/net/mvpp2/mrvl_qos.c +5 -2
@@ -656,12 +656,16 @@ int mrvl_get_cfg(const char *key __rte_unused, const char *path, void *extra_args) { struct mrvl_cfg **cfg = extra_args; -struct rte_cfgfile *file =rte_cfgfile_load (path,0 ); +struct rte_cfgfile *file;uint32_t val;int n, i, ret;const char *entry;char sec_name[32 ]; +if (path ==NULL ) +return -EINVAL ; + + file =rte_cfgfile_load (path,0 );if (file ==NULL ) {MRVL_LOG (ERR ,"Cannot load configuration %s\n" , path);return -1 ; --
2.17.1
PATCH v2 24/44 net/netvsc: fix segment fault when parse devargs
In reply to Chengwen FengThe rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/net/netvsc/hn_ethdev.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/netvsc/hn_ethdev.c +3 -0
@@ -157,6 +157,9 @@ static int hn_set_parameter(const char *key, const char *value, void *opaque)char *endp =NULL ;unsigned long v; +if (value ==NULL ) +return -EINVAL ; + v =strtoul (value, &endp,0 );if (*value =='\0' || *endp !='\0' ) {PMD_DRV_LOG (ERR ,"invalid parameter %s=%s" , key, value);
Signature · 1 line
2.17.1
RE: [PATCH v2 24/44] net/netvsc: fix segment fault when parse devargs
Quoted 6 lines
Subject: [PATCH v2 24/44] net/netvsc: fix segment fault when parse devargs
The
rte_kvargs_process()was used to parse KV pairs, it also supports to parse 'only keys' (e.g.socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
Quoted 6 lines
This patch fixes segment fault when parse input args with 'only keys'.
Fixes a25d39a3eb69 ("net/netvsc: allow tuning latency with devargs")Signed-off-by Chengwen Feng <[email protected]>
Thank you.
Quoted 21 lines
--- drivers/net/netvsc/hn_ethdev.c | 3 +++ 1 file changed, 3 insertions(+)drivers/net/netvsc/hn_ethdev.c +3
-0@@ -157,6 +157,9 @@ static int hn_set_parameter(const char *key, const char *value, void *opaque) char *endp = NULL;unsigned long v; +if (value ==NULL ) +return -EINVAL ; + v =strtoul (value, &endp,0 );if (*value =='\0' || *endp !='\0' ) {
PMD_DRV_LOG(ERR, "invalid parameter %s=%s", key, value);
--
2.17.1
Re: [PATCH v2 24/44] net/netvsc: fix segment fault when parse devargs
In reply to Chengwen FengQuoted 10 lines · On Mon, 20 Mar 2023 09:20:50 +0000 Chengwen Feng <[email protected]>…
The
rte_kvargs_process()was used to parse KV pairs, it also supports to parse 'only keys' (e.g.socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.This patch fixes segment fault when parse input args with 'only keys'.
Fixes a25d39a3eb69 ("net/netvsc: allow tuning latency with devargs")Signed-off-by Chengwen Feng <[email protected]>
PATCH v2 25/44 net/octeontx: fix segment fault when parse devargs
In reply to Chengwen FengThe rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/net/octeontx/octeontx_ethdev.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/octeontx/octeontx_ethdev.c +3 -0
@@ -70,6 +70,9 @@ parse_integer_arg(const char *key __rte_unused, {int *i = (int *)extra_args; +if (value ==NULL ) +return -EINVAL ; + *i =atoi (value);if (*i <0 ) {octeontx_log_err ("argument has to be positive." );
Signature · 1 line
2.17.1
RE: [EXT] [PATCH v2 25/44] net/octeontx: fix segment fault when parse devargs
Hi,
Thanks for fixing the seg fault.
Thanks
Harman
Quoted 44 lines
-----Original Message-----
From: Chengwen Feng <[email protected]>
Sent: Monday, March 20, 2023 2:51 PM
To: [email protected]; [email protected]; Harman Kalra <[email protected]>; Santosh Shukla <[email protected]>; Jerin Jacob <[email protected]>
Cc: [email protected]
Subject: [EXT] [PATCH v2 25/44] net/octeontx: fix segment fault when parse devargsExternal Email
----------------------------------------------------------------------
Therte_kvargs_process()was used to parse KV pairs, it also supports to parse 'only keys' (e.g.socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.This patch fixes segment fault when parse input args with 'only keys'.
Fixes f7be70e5130e ("net/octeontx: add net device probe and remove")Signed-off-by Chengwen Feng <[email protected]>--- drivers/net/octeontx/octeontx_ethdev.c | 3 +++ 1 file changed, 3 insertions(+)drivers/net/octeontx/octeontx_ethdev.c +3
-1@@ -70,6 +70,9 @@ parse_integer_arg(const char *key __rte_unused, {int *i = (int *)extra_args; +if (value ==NULL ) +return -EINVAL ; + *i =atoi (value);if (*i <0 ) {octeontx_log_err ("argument has to be positive." ); --2.17.1
PATCH v2 26/44 net/pfe: fix segment fault when parse devargs
In reply to Chengwen FengThe rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/net/pfe/pfe_ethdev.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/pfe/pfe_ethdev.c +3 -0
@@ -888,6 +888,9 @@ parse_integer_arg(const char *key __rte_unused,char *end; errno =0 ; +if (value ==NULL ) +return -EINVAL ; + i =strtol (value, &end,10 );if (*end !=0 || errno !=0 || i <0 || i >1 ) {PFE_PMD_ERR ("Supported Port IDS are 0 and 1" );
Signature · 1 line
2.17.1
PATCH v2 27/44 net/qede: fix segment fault when parse devargs
In reply to Chengwen FengThe rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/net/qede/qede_ethdev.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/qede/qede_ethdev.c +3 -0
@@ -1211,6 +1211,9 @@ static int qede_args_check(const char *key, const char *val, void *opaque)struct qede_dev *qdev =QEDE_INIT_QDEV (eth_dev);struct ecore_dev *edev =QEDE_INIT_EDEV (qdev); +if (val ==NULL ) +return -EINVAL ; + errno =0 ; tmp =strtoul (val,NULL ,0 );if (errno) {
Signature · 1 line
2.17.1
PATCH v2 28/44 baseband/la12xx: fix segment fault when parse devargs
In reply to Chengwen FengThe rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/baseband/la12xx/bbdev_la12xx.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/baseband/la12xx/bbdev_la12xx.c +3 -0
@@ -936,6 +936,9 @@ parse_integer_arg(const char *key __rte_unused,int i;char *end; +if (value ==NULL ) +return -EINVAL ; + errno =0 ; i =strtol (value, &end,10 );
Signature · 1 line
2.17.1
PATCH v2 29/44 bus/pci: fix segment fault when parse args
In reply to Chengwen FengThe rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/bus/pci/pci_params.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/bus/pci/pci_params.c +2 -0
@@ -34,6 +34,8 @@ pci_addr_kv_cmp(const char *key __rte_unused,struct rte_pci_addr *addr1 = &_addr1;struct rte_pci_addr *addr2 = _addr2; +if (value ==NULL ) +return -EINVAL ;if (rte_pci_addr_parse (value, addr1))return -1 ;return -abs (rte_pci_addr_cmp (addr1, addr2));
Signature · 1 line
2.17.1
PATCH v2 30/44 common/mlx5: fix segment fault when parse devargs
In reply to Chengwen FengThe rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/common/mlx5/mlx5_common.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/common/mlx5/mlx5_common.c +5 -0
@@ -365,6 +365,11 @@ devargs_class_handler(__rte_unused const char *key,char *found;char *refstr =NULL ; +if (class_names ==NULL ) { + *ret = -EINVAL ; +return *ret; + } + *ret =0 ; scratch =strdup (class_names);if (scratch ==NULL ) {
Signature · 1 line
2.17.1
PATCH v2 31/44 crypto/cnxk: fix segment fault when parse devargs
In reply to Chengwen FengThe rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/crypto/cnxk/cnxk_cryptodev_devargs.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/crypto/cnxk/cnxk_cryptodev_devargs.c +3 -0
@@ -16,6 +16,9 @@ parse_max_qps_limit(const char *key, const char *value, void *extra_args)RTE_SET_USED (key);uint32_t val; +if (value ==NULL ) +return -EINVAL ; + val =atoi (value);if (val <CNXK_MAX_QPS_LIMIT_MIN || val >CNXK_MAX_QPS_LIMIT_MAX )
Signature · 1 line
2.17.1
PATCH v2 32/44 crypto/dpaa_sec: fix segment fault when parse devargs
In reply to Chengwen FengThe rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/crypto/dpaa_sec/dpaa_sec.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/crypto/dpaa_sec/dpaa_sec.c +3 -0
@@ -3584,6 +3584,9 @@ static int check_devargs_handler(__rte_unused const char *key, const char *value, __rte_unused void *opaque) { + if (value == NULL) + return -EINVAL; + dpaa_sec_dp_dump =atoi (value);if (dpaa_sec_dp_dump >DPAA_SEC_DP_FULL_DUMP ) { DPAA_SEC_WARN("WARN: DPAA_SEC_DP_DUMP_LEVEL is not "
Signature · 1 line
2.17.1
PATCH v2 33/44 crypto/dpaa2_sec: fix segment fault when parse devargs
In reply to Chengwen FengThe rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c +2 -0
@@ -4242,6 +4242,8 @@ check_devargs_handler(const char *key, const char *value,if (!strcmp (key,"drv_strict_order" )) { priv->en_loose_ordered = false; }else if (!strcmp (key,"drv_dump_mode" )) { +if (value ==NULL ) +return -EINVAL ; dpaa2_sec_dp_dump =atoi (value);if (dpaa2_sec_dp_dump >DPAA2_SEC_DP_FULL_DUMP ) { DPAA2_SEC_WARN("WARN: DPAA2_SEC_DP_DUMP_LEVEL is not "
Signature · 1 line
2.17.1
PATCH v2 34/44 crypto/mvsam: fix segment fault when parse devargs
In reply to Chengwen FengThe rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/crypto/mvsam/rte_mrvl_pmd.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/crypto/mvsam/rte_mrvl_pmd.c +6 -0
@@ -1126,6 +1126,9 @@ parse_integer_arg(const char *key __rte_unused, {int *i = (int *) extra_args; +if (value ==NULL ) +return -EINVAL ; + *i =atoi (value);if (*i <0 ) {MRVL_LOG (ERR ,"Argument has to be positive!" );
@@ -1142,6 +1145,9 @@ parse_name_arg(const char *key __rte_unused, {struct rte_cryptodev_pmd_init_params *params = extra_args; +if (value ==NULL ) +return -EINVAL ; +if (strlen (value) >=RTE_CRYPTODEV_NAME_MAX_LEN -1 ) {MRVL_LOG (ERR ,"Invalid name %s, should be less than %u bytes!" , value,RTE_CRYPTODEV_NAME_MAX_LEN -1 );
Signature · 1 line
2.17.1
RE: [EXT] [PATCH v2 34/44] crypto/mvsam: fix segment fault when parse devargs
-----Original Message-----
From: Chengwen Feng <[email protected]>
Sent: Monday, 20 March 2023 11:21
To: [email protected]; [email protected]; Michael Shamis <[email protected]>; Liron Himi <[email protected]>; Pablo de Lara <[email protected]>; Tomasz Duszynski <[email protected]>
Cc: [email protected]
Subject: [EXT] [PATCH v2 34/44] crypto/mvsam: fix segment fault when parse devargs
External Email
----------------------------------------------------------------------
The rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/crypto/mvsam/rte_mrvl_pmd.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/crypto/mvsam/rte_mrvl_pmd.c +3 -0
@@ -1126,6 +1126,9 @@ parse_integer_arg(const char *key __rte_unused, {int *i = (int *) extra_args; +if (value ==NULL ) +return -EINVAL ; + *i =atoi (value);if (*i <0 ) { MRVL_LOG(ERR, "Argument has to be positive!"); @@ -1142,6 +1145,9 @@ parse_name_arg(const char *key __rte_unused, { struct rte_cryptodev_pmd_init_params *params = extra_args;
+ if (value == NULL)
+ return -EINVAL;
+
if (strlen(value) >= RTE_CRYPTODEV_NAME_MAX_LEN - 1) {
MRVL_LOG(ERR, "Invalid name %s, should be less than %u bytes!",
value, RTE_CRYPTODEV_NAME_MAX_LEN - 1);
--
2.17.1
PATCH v2 35/44 crypto/scheduler: fix segment fault when parse devargs
In reply to Chengwen FengThe rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/crypto/scheduler/scheduler_pmd.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
drivers/crypto/scheduler/scheduler_pmd.c +21 -0
@@ -272,6 +272,9 @@ parse_integer_arg(const char *key __rte_unused, {int *i = (int *) extra_args; +if (value ==NULL ) +return -EINVAL ; + *i =atoi (value);if (*i <0 ) {CR_SCHED_LOG (ERR ,"Argument has to be positive." );
@@ -338,6 +341,9 @@ parse_corelist_arg(const char *key __rte_unused, {struct scheduler_init_params *params = extra_args; +if (value ==NULL ) +return -EINVAL ; + params->nb_wc =0 ;const char *token = value;
@@ -367,6 +373,9 @@ parse_name_arg(const char *key __rte_unused, {struct rte_cryptodev_pmd_init_params *params = extra_args; +if (value ==NULL ) +return -EINVAL ; +if (strlen (value) >=RTE_CRYPTODEV_NAME_MAX_LEN -1 ) { CR_SCHED_LOG(ERR, "Invalid name %s, should be less than " "%u bytes.", value,
@@ -386,6 +395,9 @@ parse_worker_arg(const char *key __rte_unused, {struct scheduler_init_params *param = extra_args; +if (value ==NULL ) +return -EINVAL ; +if (param->nb_workers >=RTE_CRYPTODEV_SCHEDULER_MAX_NB_WORKERS ) {CR_SCHED_LOG (ERR ,"Too many workers." );return -ENOMEM ;
@@ -404,6 +416,9 @@ parse_mode_arg(const char *key __rte_unused,struct scheduler_init_params *param = extra_args;uint32_t i; +if (value ==NULL ) +return -EINVAL ; +for (i =0 ; i <RTE_DIM (scheduler_mode_map); i++) {if (strcmp (value, scheduler_mode_map[i].name) ==0 ) { param->mode = (enum rte_cryptodev_scheduler_mode)
@@ -427,6 +442,9 @@ parse_mode_param_arg(const char *key __rte_unused, {struct scheduler_init_params *param = extra_args; +if (value ==NULL ) +return -EINVAL ; +strlcpy (param->mode_param_str, value,RTE_CRYPTODEV_SCHEDULER_NAME_MAX_LEN );
@@ -440,6 +458,9 @@ parse_ordering_arg(const char *key __rte_unused,struct scheduler_init_params *param = extra_args;uint32_t i; +if (value ==NULL ) +return -EINVAL ; +for (i =0 ; i <RTE_DIM (scheduler_ordering_map); i++) {if (strcmp (value, scheduler_ordering_map[i].name) ==0 ) { param->enable_ordering =
Signature · 1 line
2.17.1
PATCH v2 36/44 dma/dpaa2: fix segment fault when parse devargs
In reply to Chengwen FengThe rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/dma/dpaa2/dpaa2_qdma.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/dma/dpaa2/dpaa2_qdma.c +3 -0
@@ -1169,6 +1169,9 @@ check_devargs_handler(__rte_unused const char *key, const char *value, __rte_unused void *opaque) { + if (value == NULL) + return -EINVAL; +if (strcmp (value,"1" ))return -1 ;
Signature · 1 line
2.17.1
PATCH v2 37/44 event/cnxk: fix segment fault when parse devargs
In reply to Chengwen FengThe rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/event/cnxk/cnxk_eventdev.c | 6 ++++++ drivers/event/cnxk/cnxk_eventdev.h | 6 ++++++ drivers/event/cnxk/cnxk_tim_evdev.c | 6 ++++++ 3 files changed, 18 insertions(+)
drivers/event/cnxk/cnxk_eventdev.c +6 -0
@@ -565,6 +565,9 @@ parse_sso_kvargs_qos_dict(const char *key, const char *value, void *opaque) {RTE_SET_USED (key); +if (value ==NULL ) +return -EINVAL ; +/* Dict format [Qx-TAQ-IAQ][Qz-TAQ-IAQ] use '-' cause ',' isn't allowed. * Everything is expressed in percentages, 0 represents default. */
@@ -578,6 +581,9 @@ parse_sso_kvargs_stash_dict(const char *key, const char *value, void *opaque) {RTE_SET_USED (key); +if (value ==NULL ) +return -EINVAL ; +/* Dict format [Qx|<stash_offset>|<stash_length>] use '|' cause ',' * isn't allowed. */
drivers/event/cnxk/cnxk_eventdev.h +6 -0
@@ -169,6 +169,9 @@ parse_kvargs_flag(const char *key, const char *value, void *opaque) {RTE_SET_USED (key); +if (value ==NULL ) +return -EINVAL ; + *(uint8_t *)opaque = !!atoi (value);return 0 ; }
@@ -178,6 +181,9 @@ parse_kvargs_value(const char *key, const char *value, void *opaque) {RTE_SET_USED (key); +if (value ==NULL ) +return -EINVAL ; + *(uint32_t *)opaque = (uint32_t )atoi (value);return 0 ; }
drivers/event/cnxk/cnxk_tim_evdev.c +6 -0
@@ -490,6 +490,9 @@ cnxk_tim_parse_kvargs_dict(const char *key, const char *value, void *opaque) {RTE_SET_USED (key); +if (value ==NULL ) +return -EINVAL ; +/* Dict format [ring-chunk_sz-disable_npa-enable_stats] use '-' as ',' * isn't allowed. 0 represents default. */
@@ -528,6 +531,9 @@ cnxk_tim_parse_kvargs_dsv(const char *key, const char *value, void *opaque) {RTE_SET_USED (key); +if (value ==NULL ) +return -EINVAL ; +/* DSV format GPIO-PTP-SYNCE-BTS use '-' as ',' * isn't allowed. 0 represents default. */
Signature · 1 line
2.17.1
PATCH v2 38/44 event/dlb2: fix segment fault when parse devargs
In reply to Chengwen FengThe rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/event/dlb2/dlb2.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/event/dlb2/dlb2.c +4 -1
@@ -329,6 +329,9 @@ set_numa_node(const char *key __rte_unused, const char *value, void *opaque)int *socket_id = opaque;int ret; +if (value ==NULL ) +return -EINVAL ; + ret =dlb2_string_to_int (socket_id, value);if (ret <0 )return ret;
@@ -542,7 +545,7 @@ set_cos_bw(const char *key __rte_unused, {struct dlb2_cos_bw *cos_bw = opaque; -if (opaque ==NULL ) { +if (value ==NULL || opaque ==NULL ) {DLB2_LOG_ERR ("NULL pointer\n" );return -EINVAL ; }
Signature · 1 line
2.17.1
RE: [PATCH v2 38/44] event/dlb2: fix segment fault when parse devargs
-----Original Message-----
From: Chengwen Feng <[email protected]>
Sent: Monday, March 20, 2023 2:21 AM
To: [email protected]; [email protected]; McDaniel, Timothy <[email protected]>; Sevincer, Abdullah <[email protected]>
Cc: [email protected]
Subject: [PATCH v2 38/44] event/dlb2: fix segment fault when parse devargs
The rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/event/dlb2/dlb2.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/event/dlb2/dlb2.c +4 -2
@@ -329,6 +329,9 @@ set_numa_node(const char *key __rte_unused, const char *value, void *opaque)int *socket_id = opaque;int ret; +if (value ==NULL ) +return -EINVAL ; + ret =dlb2_string_to_int (socket_id, value);if (ret <0 )return ret;
@@ -542,7 +545,7 @@ set_cos_bw(const char *key __rte_unused, {struct dlb2_cos_bw *cos_bw = opaque; -if (opaque ==NULL ) { +if (value ==NULL || opaque ==NULL ) {DLB2_LOG_ERR ("NULL pointer\n" );return -EINVAL ; } --
2.17.1
PATCH v2 39/44 event/dpaa: fix segment fault when parse devargs
In reply to Chengwen FengThe rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/event/dpaa/dpaa_eventdev.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/event/dpaa/dpaa_eventdev.c +3 -0
@@ -959,6 +959,9 @@ static struct eventdev_ops dpaa_eventdev_ops = { static int flag_check_handler(__rte_unused const char *key, const char *value, __rte_unused void *opaque) { +if (value ==NULL ) +return -EINVAL ; +if (strcmp (value,"1" ))return -1 ;
Signature · 1 line
2.17.1
PATCH v2 40/44 event/octeontx: fix segment fault when parse devargs
In reply to Chengwen FengThe rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/event/octeontx/ssovf_evdev.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/event/octeontx/ssovf_evdev.c +2 -0
@@ -717,6 +717,8 @@ static int ssovf_parsekv(const char *key __rte_unused, const char *value, void *opaque) { int *flag = opaque; +if (value ==NULL ) +return -EINVAL ; *flag = !!atoi (value);return 0 ; }
Signature · 1 line
2.17.1
PATCH v2 41/44 event/opdl: fix segment fault when parse devargs
In reply to Chengwen FengThe rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/event/opdl/opdl_evdev.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/event/opdl/opdl_evdev.c +9 -0
@@ -580,6 +580,8 @@ static int assign_numa_node(const char *key __rte_unused, const char *value, void *opaque) { int *socket_id = opaque; +if (value ==NULL ) +return -EINVAL ; *socket_id =atoi (value);if (*socket_id >=RTE_MAX_NUMA_NODES )return -1 ;
@@ -590,6 +592,10 @@ static int set_do_validation(const char *key __rte_unused, const char *value, void *opaque) { int *do_val = opaque; + +if (value ==NULL ) +return -EINVAL ; + *do_val =atoi (value);if (*do_val !=0 ) *do_val =1 ;
@@ -601,6 +607,9 @@ set_do_test(const char *key __rte_unused, const char *value, void *opaque) {int *do_test = opaque; +if (value ==NULL ) +return -EINVAL ; + *do_test =atoi (value);if (*do_test !=0 )
Signature · 1 line
2.17.1
Re: [PATCH v2 41/44] event/opdl: fix segment fault when parse devargs
Quoted 10 lines · Chengwen Feng
The
rte_kvargs_process()was used to parse KV pairs, it also supports to parse 'only keys' (e.g.socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.This patch fixes segment fault when parse input args with 'only keys'.
Fixes 3c7f3dcfb099 ("event/opdl: add PMD main body and helper function")Signed-off-by Chengwen Feng <[email protected]>
Quoted 41 lines
--- drivers/event/opdl/opdl_evdev.c | 9 +++++++++ 1 file changed, 9 insertions(+)drivers/event/opdl/opdl_evdev.c +9
-0@@ -580,6 +580,8 @@ static int assign_numa_node(const char *key __rte_unused, const char *value, void *opaque) { int *socket_id = opaque; +if (value ==NULL ) +return -EINVAL ; *socket_id =atoi (value);if (*socket_id >=RTE_MAX_NUMA_NODES )return -1 ;@@ -590,6 +592,10 @@ static int set_do_validation(const char *key __rte_unused, const char *value, void *opaque) { int *do_val = opaque; + +if (value ==NULL ) +return -EINVAL ; + *do_val =atoi (value);if (*do_val !=0 ) *do_val =1 ;@@ -601,6 +607,9 @@ set_do_test(const char *key __rte_unused, const char *value, void *opaque) {int *do_test = opaque; +if (value ==NULL ) +return -EINVAL ; + *do_test =atoi (value);if (*do_test !=0 )Signature · 1 line
2.17.1
PATCH v2 42/44 event/sw: fix segment fault when parse devargs
In reply to Chengwen FengThe rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/event/sw/sw_evdev.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/event/sw/sw_evdev.c +12 -0
@@ -875,6 +875,8 @@ static int assign_numa_node(const char *key __rte_unused, const char *value, void *opaque) { int *socket_id = opaque; +if (value ==NULL ) +return -EINVAL ; *socket_id =atoi (value);if (*socket_id >=RTE_MAX_NUMA_NODES )return -1 ;
@@ -885,6 +887,8 @@ static int set_sched_quanta(const char *key __rte_unused, const char *value, void *opaque) { int *quanta = opaque; +if (value ==NULL ) +return -EINVAL ; *quanta =atoi (value);if (*quanta <0 || *quanta >=4096 )return -1 ;
@@ -895,6 +899,8 @@ static int set_credit_quanta(const char *key __rte_unused, const char *value, void *opaque) { int *credit = opaque; +if (value ==NULL ) +return -EINVAL ; *credit =atoi (value);if (*credit <0 || *credit >=128 )return -1 ;
@@ -905,6 +911,8 @@ static int set_deq_burst_sz(const char *key __rte_unused, const char *value, void *opaque) { int *deq_burst_sz = opaque; +if (value ==NULL ) +return -EINVAL ; *deq_burst_sz =atoi (value);if (*deq_burst_sz <0 || *deq_burst_sz >SCHED_DEQUEUE_MAX_BURST_SIZE )return -1 ;
@@ -915,6 +923,8 @@ static int set_min_burst_sz(const char *key __rte_unused, const char *value, void *opaque) { int *min_burst_sz = opaque; +if (value ==NULL ) +return -EINVAL ; *min_burst_sz =atoi (value);if (*min_burst_sz <0 || *min_burst_sz >SCHED_DEQUEUE_MAX_BURST_SIZE )return -1 ;
@@ -925,6 +935,8 @@ static int set_refill_once(const char *key __rte_unused, const char *value, void *opaque) { int *refill_once_per_call = opaque; +if (value ==NULL ) +return -EINVAL ; *refill_once_per_call =atoi (value);if (*refill_once_per_call <0 || *refill_once_per_call >1 )return -1 ;
Signature · 1 line
2.17.1
RE: [PATCH v2 42/44] event/sw: fix segment fault when parse devargs
Quoted 14 lines
-----Original Message-----
From: Chengwen Feng <[email protected]>
Sent: Monday, March 20, 2023 9:21 AM
To: [email protected]; [email protected]; Van Haaren, Harry <[email protected]>; Richardson, Bruce <[email protected]>; Jerin Jacob <[email protected]>; Nicolau, Radu <[email protected]>
Cc: [email protected]
Subject: [PATCH v2 42/44] event/sw: fix segment fault when parse devargsThe
rte_kvargs_process()was used to parse KV pairs, it also supports to parse 'only keys' (e.g.socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
Quoted 7 lines
This patch fixes segment fault when parse input args with 'only keys'.
Fixes aaa4a221da26 ("event/sw: add new software-only eventdev driver")Fixes 70207f35e21f ("event/sw: improve performance")Signed-off-by Chengwen Feng <[email protected]>
PATCH v2 43/44 mempool/cnxk: fix segment fault when parse devargs
In reply to Chengwen FengThe rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/mempool/cnxk/cnxk_mempool.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/mempool/cnxk/cnxk_mempool.c +3 -0
@@ -36,6 +36,9 @@ parse_max_pools_handler(const char *key, const char *value, void *extra_args)RTE_SET_USED (key);uint32_t val; +if (value ==NULL ) +return -EINVAL ; + val =rte_align32pow2 (atoi (value));if (val <npa_aura_size_to_u32 (NPA_AURA_SZ_128 )) val =128 ;
Signature · 1 line
2.17.1
PATCH v2 44/44 raw/cnxk_gpio: fix segment fault when parse devargs
In reply to Chengwen FengThe rte_kvargs_process() was used to parse KV pairs, it also supports to parse 'only keys' (e.g. socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.
This patch fixes segment fault when parse input args with 'only keys'.
--- drivers/raw/cnxk_gpio/cnxk_gpio.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/raw/cnxk_gpio/cnxk_gpio.c +6 -0
@@ -67,6 +67,9 @@ cnxk_gpio_parse_arg_gpiochip(const char *key __rte_unused, const char *value, {long val; +if (value ==NULL ) +return -EINVAL ; + errno =0 ; val =strtol (value,NULL ,10 );if (errno)
@@ -81,6 +84,9 @@ static int cnxk_gpio_parse_arg_allowlist(const char *key __rte_unused, const char *value, void *extra_args __rte_unused) { + if (value == NULL) + return -EINVAL; + allowlist =strdup (value);if (!allowlist)return -ENOMEM ;
Signature · 1 line
2.17.1
Hi Thomas, Ferruh,
This patch-set get almost 30% ack by PMD's maintainer. Could it be applied? and squeeze the patch-set is okay.
Another thread talk about a change in kvargs API, we could discuss here.
My opinion:
1) the below PMD has the bug, but there are also many PMD take care of only key situation. I think it mainly because the API definition is not detailed, but this hole was already fill by commit: 52ab17efdec.
2) the rte_kvargs_get API, I think we could refine it definition, because it can't identify invalid keys and only-keys (both of them return NULL), and I suggest add one extra parameter:
const char *rte_kvargs_get(const struct rte_kvargs *kvlist, const char *key, bool *key_exist);
Thanks.
Quoted 111 lines · Chengwen Feng
The
rte_kvargs_process()was used to parse KV pairs, it also supports to parse 'only keys' (e.g.socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.It may leads to segment fault when parse args with 'only key', this patchset fixes rest of them.
Chengwen Feng (44):
app/pdump: fix segment fault when parse args
ethdev: fix segment fault when parse args net/memif: fix segment fault when parse devargs net/pcap: fix segment fault when parse devargs net/ring: fix segment fault when parse devargs net/sfc: fix segment fault when parse devargsnet/af_xdp: fix segment fault when parse devargs net/ark: fix segment fault when parse devargs net/cnxk: fix segment fault when parse devargs net/cxgbe: fix segment fault when parse devargs net/dpaa2: fix segment fault when parse devargs net/ena: fix segment fault when parse devargs net/enic: fix segment fault when parse devargs net/fm10k: fix segment fault when parse devargs net/i40e: fix segment fault when parse devargs net/iavf: fix segment fault when parse devargs net/ice: fix segment fault when parse devargs net/idpf: fix segment fault when parse devargs net/ionic: fix segment fault when parse devargs net/mana: fix segment fault when parse devargs net/mlx4: fix segment fault when parse devargs net/mvneta: fix segment fault when parse devargs net/mvpp2: fix segment fault when parse devargs net/netvsc: fix segment fault when parse devargs net/octeontx: fix segment fault when parse devargs net/pfe: fix segment fault when parse devargs net/qede: fix segment fault when parse devargs baseband/la12xx: fix segment fault when parse devargs bus/pci: fix segment fault when parse args common/mlx5: fix segment fault when parse devargscrypto/cnxk: fix segment fault when parse devargscrypto/dpaa_sec: fix segment fault when parse devargscrypto/dpaa2_sec: fix segment fault when parse devargscrypto/mvsam: fix segment fault when parse devargscrypto/scheduler: fix segment fault when parse devargs dma/dpaa2: fix segment fault when parse devargs event/cnxk: fix segment fault when parse devargs event/dlb2: fix segment fault when parse devargs event/dpaa: fix segment fault when parse devargs event/octeontx: fix segment fault when parse devargs event/opdl: fix segment fault when parse devargs event/sw: fix segment fault when parse devargs mempool/cnxk: fix segment fault when parse devargs raw/cnxk_gpio: fix segment fault when parse devargs---
v2: according Ferruh's comments:
fix all 'rte_kvargs_process()' bug instances.
only judge value validation.app/pdump/main.c | 12 ++++++ drivers/baseband/la12xx/bbdev_la12xx.c | 3 ++ drivers/bus/pci/pci_params.c | 2 + drivers/common/mlx5/mlx5_common.c | 5 +++ drivers/crypto/cnxk/cnxk_cryptodev_devargs.c | 3 ++ drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c | 2 + drivers/crypto/dpaa_sec/dpaa_sec.c | 3 ++ drivers/crypto/mvsam/rte_mrvl_pmd.c | 6 +++ drivers/crypto/scheduler/scheduler_pmd.c | 21 +++++++++++ drivers/dma/dpaa2/dpaa2_qdma.c | 3 ++ drivers/event/cnxk/cnxk_eventdev.c | 6 +++ drivers/event/cnxk/cnxk_eventdev.h | 6 +++ drivers/event/cnxk/cnxk_tim_evdev.c | 6 +++ drivers/event/dlb2/dlb2.c | 5 ++- drivers/event/dpaa/dpaa_eventdev.c | 3 ++ drivers/event/octeontx/ssovf_evdev.c | 2 + drivers/event/opdl/opdl_evdev.c | 9 +++++ drivers/event/sw/sw_evdev.c | 12 ++++++ drivers/mempool/cnxk/cnxk_mempool.c | 3 ++ drivers/net/af_xdp/rte_eth_af_xdp.c | 12 ++++++ drivers/net/ark/ark_ethdev.c | 3 ++ drivers/net/cnxk/cnxk_ethdev_devargs.c | 39 ++++++++++++++++++++ drivers/net/cnxk/cnxk_ethdev_sec.c | 12 ++++++ drivers/net/cxgbe/cxgbe_main.c | 3 ++ drivers/net/dpaa2/dpaa2_ethdev.c | 3 ++ drivers/net/ena/ena_ethdev.c | 6 +++ drivers/net/enic/enic_ethdev.c | 6 +++ drivers/net/fm10k/fm10k_ethdev.c | 3 ++ drivers/net/i40e/i40e_ethdev.c | 15 ++++++++ drivers/net/iavf/iavf_ethdev.c | 6 +++ drivers/net/ice/ice_dcf_ethdev.c | 6 +++ drivers/net/ice/ice_ethdev.c | 6 +++ drivers/net/idpf/idpf_ethdev.c | 6 +++ drivers/net/ionic/ionic_dev_pci.c | 3 ++ drivers/net/mana/mana.c | 3 ++ drivers/net/memif/rte_eth_memif.c | 30 +++++++++++++++ drivers/net/mlx4/mlx4.c | 3 ++ drivers/net/mvneta/mvneta_ethdev.c | 3 ++ drivers/net/mvpp2/mrvl_ethdev.c | 3 ++ drivers/net/mvpp2/mrvl_qos.c | 6 ++- drivers/net/netvsc/hn_ethdev.c | 3 ++ drivers/net/octeontx/octeontx_ethdev.c | 3 ++ drivers/net/pcap/pcap_ethdev.c | 18 ++++++++- drivers/net/pfe/pfe_ethdev.c | 3 ++ drivers/net/qede/qede_ethdev.c | 3 ++ drivers/net/ring/rte_eth_ring.c | 6 +++ drivers/net/sfc/sfc.c | 3 ++ drivers/net/sfc/sfc_ev.c | 3 ++ drivers/net/sfc/sfc_kvargs.c | 6 +++ drivers/raw/cnxk_gpio/cnxk_gpio.c | 6 +++ lib/ethdev/rte_class_eth.c | 6 +++ 51 files changed, 345 insertions(+), 4 deletions(-)
Quoted 5 lines · fengchengwen
Hi Thomas, Ferruh,
This patch-set get almost 30% ack by PMD's maintainer. Could it be applied? and squeeze the patch-set is okay.
Hi Chengwen,
The patch is trivial and safe on its own, so for me having enough ack or not is not what blocks the set.
As we discussed before, instead of adding NULL checks to the callbacks, it is better to handle this in the kvargs API level, that discussion is holding this patchset back.
According result of discussion we may prefer to not merge this patch at all.
Quoted 5 lines
Another thread talk about a change in kvargs API, we could discuss here.
My opinion:
1) the below PMD has the bug, but there are also many PMD take care of only key situation. I think it mainly because the API definition is not detailed, but this hole was already fill by commit:52ab17efdec.
Ack
Quoted 4 lines
2) the
rte_kvargs_getAPI, I think we could refine it definition, because it can't identify invalid keys and only-keys (both of them return NULL), and I suggest add one extra parameter:
const char *rte_kvargs_get(const structrte_kvargs*kvlist, const char *key, bool*key_exist);
I am not clear why to update rte_kvargs_get(), and how to benefit from this update.
My suggestion was to update kvargs API to let user of API define if 'key' should have a 'value' or not, similar to done in getopt() API.
One option can be to update rte_kvargs_parse() API to recognize a special char in "const char *const valid_keys[]" to know if value expected or not, and API can do internal checks based on this information.
To reduce the impact of change, no special char in the valid_keys string may mean key expects a value (I think this is the most common case), and in this case if "value == NULL" API can return an error.
But if there is a special char at the end, lets say '-', key doesn't need a value and having "value == NULL" is accepted.
Again this is similar to ':' char in the getopt() API, but meaning is reverse.
Above is just an option, there can be another solution by to updating rte_kvargs_process() API, only this may be more disruptive.
Any other solution is welcomed.
Quoted 114 lines
Thanks.
Quoted 111 lines · Chengwen Feng
The
rte_kvargs_process()was used to parse KV pairs, it also supports to parse 'only keys' (e.g.socket_id) type. And the callback function parameter 'value' is NULL when parsed 'only keys'.It may leads to segment fault when parse args with 'only key', this patchset fixes rest of them.
Chengwen Feng (44):
app/pdump: fix segment fault when parse args
ethdev: fix segment fault when parse args net/memif: fix segment fault when parse devargs net/pcap: fix segment fault when parse devargs net/ring: fix segment fault when parse devargs net/sfc: fix segment fault when parse devargsnet/af_xdp: fix segment fault when parse devargs net/ark: fix segment fault when parse devargs net/cnxk: fix segment fault when parse devargs net/cxgbe: fix segment fault when parse devargs net/dpaa2: fix segment fault when parse devargs net/ena: fix segment fault when parse devargs net/enic: fix segment fault when parse devargs net/fm10k: fix segment fault when parse devargs net/i40e: fix segment fault when parse devargs net/iavf: fix segment fault when parse devargs net/ice: fix segment fault when parse devargs net/idpf: fix segment fault when parse devargs net/ionic: fix segment fault when parse devargs net/mana: fix segment fault when parse devargs net/mlx4: fix segment fault when parse devargs net/mvneta: fix segment fault when parse devargs net/mvpp2: fix segment fault when parse devargs net/netvsc: fix segment fault when parse devargs net/octeontx: fix segment fault when parse devargs net/pfe: fix segment fault when parse devargs net/qede: fix segment fault when parse devargs baseband/la12xx: fix segment fault when parse devargs bus/pci: fix segment fault when parse args common/mlx5: fix segment fault when parse devargscrypto/cnxk: fix segment fault when parse devargscrypto/dpaa_sec: fix segment fault when parse devargscrypto/dpaa2_sec: fix segment fault when parse devargscrypto/mvsam: fix segment fault when parse devargscrypto/scheduler: fix segment fault when parse devargs dma/dpaa2: fix segment fault when parse devargs event/cnxk: fix segment fault when parse devargs event/dlb2: fix segment fault when parse devargs event/dpaa: fix segment fault when parse devargs event/octeontx: fix segment fault when parse devargs event/opdl: fix segment fault when parse devargs event/sw: fix segment fault when parse devargs mempool/cnxk: fix segment fault when parse devargs raw/cnxk_gpio: fix segment fault when parse devargs---
v2: according Ferruh's comments:
fix all 'rte_kvargs_process()' bug instances.
only judge value validation.app/pdump/main.c | 12 ++++++ drivers/baseband/la12xx/bbdev_la12xx.c | 3 ++ drivers/bus/pci/pci_params.c | 2 + drivers/common/mlx5/mlx5_common.c | 5 +++ drivers/crypto/cnxk/cnxk_cryptodev_devargs.c | 3 ++ drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c | 2 + drivers/crypto/dpaa_sec/dpaa_sec.c | 3 ++ drivers/crypto/mvsam/rte_mrvl_pmd.c | 6 +++ drivers/crypto/scheduler/scheduler_pmd.c | 21 +++++++++++ drivers/dma/dpaa2/dpaa2_qdma.c | 3 ++ drivers/event/cnxk/cnxk_eventdev.c | 6 +++ drivers/event/cnxk/cnxk_eventdev.h | 6 +++ drivers/event/cnxk/cnxk_tim_evdev.c | 6 +++ drivers/event/dlb2/dlb2.c | 5 ++- drivers/event/dpaa/dpaa_eventdev.c | 3 ++ drivers/event/octeontx/ssovf_evdev.c | 2 + drivers/event/opdl/opdl_evdev.c | 9 +++++ drivers/event/sw/sw_evdev.c | 12 ++++++ drivers/mempool/cnxk/cnxk_mempool.c | 3 ++ drivers/net/af_xdp/rte_eth_af_xdp.c | 12 ++++++ drivers/net/ark/ark_ethdev.c | 3 ++ drivers/net/cnxk/cnxk_ethdev_devargs.c | 39 ++++++++++++++++++++ drivers/net/cnxk/cnxk_ethdev_sec.c | 12 ++++++ drivers/net/cxgbe/cxgbe_main.c | 3 ++ drivers/net/dpaa2/dpaa2_ethdev.c | 3 ++ drivers/net/ena/ena_ethdev.c | 6 +++ drivers/net/enic/enic_ethdev.c | 6 +++ drivers/net/fm10k/fm10k_ethdev.c | 3 ++ drivers/net/i40e/i40e_ethdev.c | 15 ++++++++ drivers/net/iavf/iavf_ethdev.c | 6 +++ drivers/net/ice/ice_dcf_ethdev.c | 6 +++ drivers/net/ice/ice_ethdev.c | 6 +++ drivers/net/idpf/idpf_ethdev.c | 6 +++ drivers/net/ionic/ionic_dev_pci.c | 3 ++ drivers/net/mana/mana.c | 3 ++ drivers/net/memif/rte_eth_memif.c | 30 +++++++++++++++ drivers/net/mlx4/mlx4.c | 3 ++ drivers/net/mvneta/mvneta_ethdev.c | 3 ++ drivers/net/mvpp2/mrvl_ethdev.c | 3 ++ drivers/net/mvpp2/mrvl_qos.c | 6 ++- drivers/net/netvsc/hn_ethdev.c | 3 ++ drivers/net/octeontx/octeontx_ethdev.c | 3 ++ drivers/net/pcap/pcap_ethdev.c | 18 ++++++++- drivers/net/pfe/pfe_ethdev.c | 3 ++ drivers/net/qede/qede_ethdev.c | 3 ++ drivers/net/ring/rte_eth_ring.c | 6 +++ drivers/net/sfc/sfc.c | 3 ++ drivers/net/sfc/sfc_ev.c | 3 ++ drivers/net/sfc/sfc_kvargs.c | 6 +++ drivers/raw/cnxk_gpio/cnxk_gpio.c | 6 +++ lib/ethdev/rte_class_eth.c | 6 +++ 51 files changed, 345 insertions(+), 4 deletions(-)
Quoted 17 lines · On Mon, 17 Apr 2023 17:37:46 +0100 Ferruh Yigit <[email protected]> wrote:
From: Ferruh Yigit <[email protected]>
To: fengchengwen <[email protected]>, [email protected]
Cc: [email protected]
Subject: Re: [PATCH v2 00/44] fix segment fault when parse args
Date: Mon, 17 Apr 2023 17:37:46 +0100
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.10.0Quoted 5 lines · fengchengwen
Hi Thomas, Ferruh,
This patch-set get almost 30% ack by PMD's maintainer. Could it be applied? and squeeze the patch-set is okay.
Hi Chengwen,
Quoted 8 lines
The patch is trivial and safe on its own, so for me having enough ack or not is not what blocks the set.
As we discussed before, instead of adding NULL checks to the callbacks, it is better to handle this in the kvargs API level, that discussion is holding this patchset back.
According result of discussion we may prefer to not merge this patch at all.
Agree. Hitting so many places, and not sure that all of them are covered, is an indicator it should be solved at higher level.
RFC 1/1 kvargs: don't pass parse handler a NULL pointer
In reply to Chengwen FengThere is class of problems in current DPDK where rte_kvargs is used a key/value pair is passed without an associated value. Currently, this can cause a NULL dereference in the rte_kvargs_process handler.
--- lib/kvargs/rte_kvargs.c | 3 +++ lib/kvargs/rte_kvargs.h | 3 +++ 2 files changed, 6 insertions(+)
lib/kvargs/rte_kvargs.c +3 -0
@@ -185,6 +185,9 @@ rte_kvargs_process(const struct rte_kvargs *kvlist,for (i =0 ; i < kvlist->count; i++) { pair = &kvlist->pairs[i];if (key_match ==NULL ||strcmp (pair->key, key_match) ==0 ) { +if (pair->value ==NULL ) +return -1 ; +if ((*handler)(pair->key, pair->value, opaque_arg) <0 )return -1 ; }
lib/kvargs/rte_kvargs.h +3 -0
@@ -178,6 +178,9 @@ const char *rte_kvargs_get_with_value(const struct rte_kvargs *kvlist,* handler function with the for a given arg_name passing the value on the * dictionary for that key and a given extra argument. * +* If no value was specified with the given key, then this +* function will return -1 and the handlere will not be called. +* * @param kvlist * The rte_kvargs structure. No error if NULL. * @param key_match
Signature · 1 line
2.41.0
Re: [RFC] kvargs: don't pass parse handler a NULL pointer
There are a few only-key situation which use rte_kvargs_process to process, If we make this change, the above case will fail.
Actually I locally make similar change plus a new API (rte_kvargs_process_opt), this new API will cover key/value and only-key match, while rte_kvargs_process make restrict only work for key/value match.
I didn't send the patches because it too late for adding this new API due to already RC1.
/**
* Call a handler function for each key/value or only-key matching the key *
* For each key/value or only-key association that matches the given key, calls
* the handler function with the for a given arg_name passing the value on the
* dictionary for that key and a given extra argument.
*
* @param kvlist
* The rte_kvargs structure. No error if NULL.
* @param key_match
* The key on which the handler should be called, or NULL to process handler
* on all associations
* @param handler
* The function to call for each matching key
* @param opaque_arg
* A pointer passed unchanged to the handler
*
* @return
* - 0 on success
* - Negative on error
*/
int rte_kvargs_process_opt(const struct rte_kvargs *kvlist,
const char *key_match, arg_handler_t handler, void *opaque_arg);
Quoted 41 lines · Stephen Hemminger
There is class of problems in current DPDK where
rte_kvargsis used a key/value pair is passed without an associated value. Currently, this can cause a NULL dereference in therte_kvargs_processhandler.Reported-by Chengwen Feng <[email protected]>Signed-off-by Stephen Hemminger <[email protected]>--- lib/kvargs/rte_kvargs.c | 3 +++ lib/kvargs/rte_kvargs.h | 3 +++ 2 files changed, 6 insertions(+)lib/kvargs/rte_kvargs.c +3
-0@@ -185,6 +185,9 @@ rte_kvargs_process(const struct rte_kvargs *kvlist,for (i =0 ; i < kvlist->count; i++) { pair = &kvlist->pairs[i];if (key_match ==NULL ||strcmp (pair->key, key_match) ==0 ) { +if (pair->value ==NULL ) +return -1 ; +if ((*handler)(pair->key, pair->value, opaque_arg) <0 )return -1 ; }lib/kvargs/rte_kvargs.h +3
-0@@ -178,6 +178,9 @@ const char *rte_kvargs_get_with_value(const struct rte_kvargs *kvlist,* handler function with the for a given arg_name passing the value on the * dictionary for that key and a given extra argument. * +* If no value was specified with the given key, then this +* function will return -1 and the handlere will not be called. +* * @param kvlist * The rte_kvargs structure. No error if NULL. * @param key_match
v3 cover fix segment fault when parse args
In reply to Chengwen FengThe rte_kvargs_process() was used to parse key-value (e.g. socket_id=0), it also supports to parse only-key (e.g. socket_id). But many drivers's callback can only handle key-value, it will segment fault if handles only-key. so the patchset [1] was introduced.
Because the patchset [1] modified too much drivers, therefore:
1) A new API rte_kvargs_process_opt() was introduced, it inherits the function of rte_kvargs_process() which could parse both key-value and only-key.
2) Constraint the rte_kvargs_process() can only parse key-value.
This patchset also include one bugfix for kvargs of mvneta driver.
[1] https://patches.dpdk.org/project/dpdk/patch/[email protected]/
Chengwen Feng (5):
kvargs: add one new process API
net/af_packet: use new API to parse kvargs
net/sfc: use new API to parse kvargs
net/tap: use new API to parse kvargs
net/mvneta: fix possible out-of-bounds write
drivers/common/sfc_efx/sfc_efx.c | 4 ++-- drivers/net/af_packet/rte_eth_af_packet.c | 4 ++-- drivers/net/mvneta/mvneta_ethdev.c | 3 +++ drivers/net/sfc/sfc_kvargs.c | 2 +- drivers/net/tap/rte_eth_tap.c | 26 ++++++++++---------- lib/kvargs/rte_kvargs.c | 29 ++++++++++++++++++++++- lib/kvargs/rte_kvargs.h | 28 ++++++++++++++++++++++ lib/kvargs/version.map | 3 +++ 8 files changed, 80 insertions(+), 19 deletions(-)
Signature · 1 line
2.17.1
PATCH v3 1/5 kvargs: add one new process API
The rte_kvargs_process() was used to parse key-value (e.g. socket_id=0), it also supports to parse only-key (e.g. socket_id). But many drivers's callback can only handle key-value, it will segment fault if handles only-key. so the patchset [1] was introduced.
Because the patchset [1] modified too much drivers, therefore:
1) A new API rte_kvargs_process_opt() was introduced, it inherits the function of rte_kvargs_process() which could parse both key-value and only-key.
2) Constraint the rte_kvargs_process() can only parse key-value.
[1] https://patches.dpdk.org/project/dpdk/patch/[email protected]/
--- lib/kvargs/rte_kvargs.c | 29 ++++++++++++++++++++++++++++- lib/kvargs/rte_kvargs.h | 28 ++++++++++++++++++++++++++++ lib/kvargs/version.map | 3 +++ 3 files changed, 59 insertions(+), 1 deletion(-)
lib/kvargs/rte_kvargs.c +28 -1
@@ -168,7 +168,7 @@ rte_kvargs_count(const struct rte_kvargs *kvlist, const char *key_match) }/* -* For each matching key, call the given handler function. +* For each matching key in key/value, call the given handler function. */ int rte_kvargs_process(const struct rte_kvargs *kvlist,
@@ -179,6 +179,33 @@ rte_kvargs_process(const struct rte_kvargs *kvlist,const struct rte_kvargs_pair *pair;unsigned i; +if (kvlist ==NULL ) +return 0 ; + +for (i =0 ; i < kvlist->count; i++) { + pair = &kvlist->pairs[i]; +if (pair->value ==NULL ) +continue ; +if (key_match ==NULL ||strcmp (pair->key, key_match) ==0 ) { +if ((*handler)(pair->key, pair->value, opaque_arg) <0 ) +return -1 ; + } + } +return 0 ; +} + +/* +* For each matching key in key/value or only-key, call the given handler function. +*/ +int +rte_kvargs_process_opt (const struct rte_kvargs *kvlist, +const char *key_match, +arg_handler_t handler, +void *opaque_arg) +{ +const struct rte_kvargs_pair *pair; +unsigned int i; +if (kvlist ==NULL )return 0 ;
lib/kvargs/rte_kvargs.h +28 -0
@@ -195,6 +195,34 @@ const char *rte_kvargs_get_with_value(const struct rte_kvargs *kvlist,int rte_kvargs_process (const struct rte_kvargs *kvlist,const char *key_match,arg_handler_t handler,void *opaque_arg); +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Call a handler function for each key/value or only-key matching the key +* +* For each key/value or only-key association that matches the given key, calls +* the handler function with the for a given arg_name passing the value on the +* dictionary for that key and a given extra argument. +* +* @param kvlist +* The rte_kvargs structure. No error if NULL. +* @param key_match +* The key on which the handler should be called, or NULL to process handler +* on all associations +* @param handler +* The function to call for each matching key +* @param opaque_arg +* A pointer passed unchanged to the handler +* +* @return +* - 0 on success +* - Negative on error +*/ +__rte_experimental +int rte_kvargs_process_opt(const struct rte_kvargs *kvlist, +const char *key_match,arg_handler_t handler,void *opaque_arg); +/** * Count the number of associations matching the given key *
lib/kvargs/version.map +3 -0
@@ -16,4 +16,7 @@ EXPERIMENTAL { # added in 21.11 rte_kvargs_get_with_value; + + # added in 23.11 + rte_kvargs_process_opt; };
Signature · 1 line
2.17.1
Re: [PATCH v3 1/5] kvargs: add one new process API
Quoted 11 lines · Chengwen Feng
The
rte_kvargs_process()was used to parse key-value (e.g. socket_id=0), it also supports to parse only-key (e.g.socket_id). But many drivers's callback can only handle key-value, it will segment fault if handles only-key. so the patchset [1] was introduced.Because the patchset [1] modified too much drivers, therefore:
1) A new APIrte_kvargs_process_opt()was introduced, it inherits the function ofrte_kvargs_process()which could parse both key-value and only-key.
2) Constraint therte_kvargs_process()can only parse key-value.
Hi Chengwen,
This works, but behavior change in 'rte_kvargs_process()' can hit some exiting users who handles both "key=value" and "key" cases.
Other option is to keep 'rte_kvargs_process()' behavior same but add a new API like 'rte_kvargs_process_safe()' that checks "value == NULL" case, but this requires more existing code to change and in this option existing users doesn't get the benefit of the NULL check by default.
Assuming number of the users that use 'rte_kvargs_process()' for "key=value" is majority, OK to continue with your change, but please document this in the release notes to highlight.
Quoted 23 lines
[1] https://patches.dpdk.org/project/dpdk/patch/[email protected]/
Signed-off-by Chengwen Feng <[email protected]>--- lib/kvargs/rte_kvargs.c | 29 ++++++++++++++++++++++++++++- lib/kvargs/rte_kvargs.h | 28 ++++++++++++++++++++++++++++ lib/kvargs/version.map | 3 +++ 3 files changed, 59 insertions(+), 1 deletion(-)lib/kvargs/rte_kvargs.c +1
-1@@ -168,7 +168,7 @@ rte_kvargs_count(const struct rte_kvargs *kvlist, const char *key_match) }/* -* For each matching key, call the given handler function. +* For each matching key in key/value, call the given handler function. */ int rte_kvargs_process(const struct rte_kvargs *kvlist,
lib/kvargs/rte_kvargs.c rte_kvargs_process(const struct rte_kvargs *kvlist, · line 184
Quoted 6 lines
lib/kvargs/rte_kvargs.c +3
-0@@ -179,6 +179,33 @@ rte_kvargs_process(const struct rte_kvargs *kvlist,const struct rte_kvargs_pair *pair;unsigned i; +if (kvlist ==NULL ) +return 0 ; +
I think it should return error here, ignoring arg silently with success can cause trouble in the application. If error returned, at least application can know argument not provided as it should be (value is missing).
lib/kvargs/rte_kvargs.c rte_kvargs_process(const struct rte_kvargs *kvlist, · line 196
Quoted 12 lines
lib/kvargs/rte_kvargs.c +12
-0+for (i =0 ; i < kvlist->count; i++) { + pair = &kvlist->pairs[i]; +if (pair->value ==NULL ) +continue ; +if (key_match ==NULL ||strcmp (pair->key, key_match) ==0 ) { +if ((*handler)(pair->key, pair->value, opaque_arg) <0 ) +return -1 ; + } + } +return 0 ; +} +
'rte_kvargs_process()' & 'rte_kvargs_process_opt()' implementations are very similar, to reduce duplication what about create 'rte_kvargs_process_common()' static function and both use this common with different parameter?
Quoted 20 lines
lib/kvargs/rte_kvargs.c +12
-0+/* +* For each matching key in key/value or only-key, call the given handler function. +*/ +int +rte_kvargs_process_opt (const struct rte_kvargs *kvlist, +const char *key_match, +arg_handler_t handler, +void *opaque_arg) +{ +const struct rte_kvargs_pair *pair; +unsigned int i; +if (kvlist ==NULL )return 0 ;lib/kvargs/rte_kvargs.h +0
-0
lib/kvargs/rte_kvargs.h const char *rte_kvargs_get_with_value(const struct rte_kvargs *kvlist, · line 204
Quoted 10 lines
lib/kvargs/rte_kvargs.h +6
-0@@ -195,6 +195,34 @@ const char *rte_kvargs_get_with_value(const struct rte_kvargs *kvlist,int rte_kvargs_process (const struct rte_kvargs *kvlist,const char *key_match,arg_handler_t handler,void *opaque_arg); +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Call a handler function for each key/value or only-key matching the key +*
In API documentation, the difference between 'rte_kvargs_process_opt()' & 'rte_kvargs_process()' is, 'rte_kvargs_process()' doesn't have "or only-key", this is easy to miss.
Can you please add more not to 'rte_kvargs_process()' saying on "only-key" case it returns error?
Quoted 13 lines
lib/kvargs/rte_kvargs.h +13
-0+* For each key/value or only-key association that matches the given key, calls +* the handler function with the for a given arg_name passing the value on the +* dictionary for that key and a given extra argument. +* +* @param kvlist +* The rte_kvargs structure. No error if NULL. +* @param key_match +* The key on which the handler should be called, or NULL to process handler +* on all associations +* @param handler +* The function to call for each matching key +* @param opaque_arg +* A pointer passed unchanged to the handler
lib/kvargs/rte_kvargs.h const char *rte_kvargs_get_with_value(const struct rte_kvargs *kvlist,
Quoted 10 lines
lib/kvargs/rte_kvargs.h +9
-0+* +* @return +* - 0 on success +* - Negative on error +*/ +__rte_experimental +int rte_kvargs_process_opt(const struct rte_kvargs *kvlist, +const char *key_match,arg_handler_t handler,void *opaque_arg); +
I am not sure about the API name, 'rte_kvargs_process_opt()', what is 'opt' here, "optional"?
What about 'rte_kvargs_process_unsafe()', not quite strong on this too but not able to come with better one, please feel free to try other alternatives.
Quoted 15 lines
lib/kvargs/rte_kvargs.h +0
-0/** * Count the number of associations matching the given key *
lib/kvargs/version.map +3
-0@@ -16,4 +16,7 @@ EXPERIMENTAL { # added in 21.11 rte_kvargs_get_with_value; + + # added in 23.11 + rte_kvargs_process_opt; };
Re: [PATCH v3 1/5] kvargs: add one new process API
Hi Ferruh,
Quoted 24 lines · Ferruh Yigit
Quoted 11 lines · Chengwen Feng
The
rte_kvargs_process()was used to parse key-value (e.g. socket_id=0), it also supports to parse only-key (e.g.socket_id). But many drivers's callback can only handle key-value, it will segment fault if handles only-key. so the patchset [1] was introduced.Because the patchset [1] modified too much drivers, therefore:
1) A new APIrte_kvargs_process_opt()was introduced, it inherits the function ofrte_kvargs_process()which could parse both key-value and only-key.
2) Constraint therte_kvargs_process()can only parse key-value.Hi Chengwen,
This works, but behavior change in '
rte_kvargs_process()' can hit some exiting users who handles both "key=value" and "key" cases.Other option is to keep '
rte_kvargs_process()' behavior same but add a new API like 'rte_kvargs_process_safe()' that checks "value == NULL" case, but this requires more existing code to change and in this option existing users doesn't get the benefit of the NULL check by default.
Quoted 3 lines
Assuming number of the users that use '
rte_kvargs_process()' for "key=value" is majority, OK to continue with your change, but please document this in the release notes to highlight.
Thanks, already fix in v4
Quoted 29 lines
Quoted 29 lines
[1] https://patches.dpdk.org/project/dpdk/patch/[email protected]/
Signed-off-by Chengwen Feng <[email protected]>--- lib/kvargs/rte_kvargs.c | 29 ++++++++++++++++++++++++++++- lib/kvargs/rte_kvargs.h | 28 ++++++++++++++++++++++++++++ lib/kvargs/version.map | 3 +++ 3 files changed, 59 insertions(+), 1 deletion(-)lib/kvargs/rte_kvargs.c +1
-1@@ -168,7 +168,7 @@ rte_kvargs_count(const struct rte_kvargs *kvlist, const char *key_match) }/* -* For each matching key, call the given handler function. +* For each matching key in key/value, call the given handler function. */ int rte_kvargs_process(const struct rte_kvargs *kvlist,@@ -179,6 +179,33 @@ rte_kvargs_process(const struct rte_kvargs *kvlist,const struct rte_kvargs_pair *pair;unsigned i;
Quoted 8 lines
lib/kvargs/rte_kvargs.c rte_kvargs_process(const struct rte_kvargs *kvlist, · line 184
Quoted 3 lines
lib/kvargs/rte_kvargs.c +3
-0+if (kvlist ==NULL ) +return 0 ; +I think it should return error here, ignoring arg silently with success can cause trouble in the application. If error returned, at least application can know argument not provided as it should be (value is missing).
fix in v4.
Quoted 11 lines
Quoted 11 lines
lib/kvargs/rte_kvargs.c +9
-0+for (i =0 ; i < kvlist->count; i++) { + pair = &kvlist->pairs[i]; +if (pair->value ==NULL ) +continue ; +if (key_match ==NULL ||strcmp (pair->key, key_match) ==0 ) { +if ((*handler)(pair->key, pair->value, opaque_arg) <0 ) +return -1 ; + } + }
Quoted 8 lines
lib/kvargs/rte_kvargs.c rte_kvargs_process(const struct rte_kvargs *kvlist, · line 196
Quoted 3 lines
lib/kvargs/rte_kvargs.c +3
-0+return 0 ; +} +'
rte_kvargs_process()' & 'rte_kvargs_process_opt()' implementations are very similar, to reduce duplication what about create 'rte_kvargs_process_common()' static function and both use this common with different parameter?
nice catch, fix in v4.
Quoted 25 lines
Quoted 25 lines
lib/kvargs/rte_kvargs.c +12
-0+/* +* For each matching key in key/value or only-key, call the given handler function. +*/ +int +rte_kvargs_process_opt (const struct rte_kvargs *kvlist, +const char *key_match, +arg_handler_t handler, +void *opaque_arg) +{ +const struct rte_kvargs_pair *pair; +unsigned int i; +if (kvlist ==NULL )return 0 ;lib/kvargs/rte_kvargs.h +0
-0@@ -195,6 +195,34 @@ const char *rte_kvargs_get_with_value(const struct rte_kvargs *kvlist,int rte_kvargs_process (const struct rte_kvargs *kvlist,const char *key_match,arg_handler_t handler,void *opaque_arg);
Quoted 13 lines
lib/kvargs/rte_kvargs.h const char *rte_kvargs_get_with_value(const struct rte_kvargs *kvlist,
Quoted 7 lines
lib/kvargs/rte_kvargs.h +6
-0+/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Call a handler function for each key/value or only-key matching the key +* In API documentation, the difference between '
rte_kvargs_process_opt()' & 'rte_kvargs_process()' is, 'rte_kvargs_process()' doesn't have "or only-key", this is easy to miss.
Can you please add more not to 'rte_kvargs_process()' saying on "only-key" case it returns error?
add one @note in v4.
Quoted 20 lines
Quoted 20 lines
lib/kvargs/rte_kvargs.h +18
-0+* For each key/value or only-key association that matches the given key, calls +* the handler function with the for a given arg_name passing the value on the +* dictionary for that key and a given extra argument. +* +* @param kvlist +* The rte_kvargs structure. No error if NULL. +* @param key_match +* The key on which the handler should be called, or NULL to process handler +* on all associations +* @param handler +* The function to call for each matching key +* @param opaque_arg +* A pointer passed unchanged to the handler +* +* @return +* - 0 on success +* - Negative on error +*/
Quoted 8 lines
lib/kvargs/rte_kvargs.h const char *rte_kvargs_get_with_value(const struct rte_kvargs *kvlist,
Quoted 5 lines
lib/kvargs/rte_kvargs.h +4
-0+__rte_experimental +int rte_kvargs_process_opt(const struct rte_kvargs *kvlist, +const char *key_match,arg_handler_t handler,void *opaque_arg); +I am not sure about the API name, '
rte_kvargs_process_opt()', what is 'opt' here, "optional"?
Yes, it mean optional of value is valid or NULL.
Quoted 3 lines
What about '
rte_kvargs_process_unsafe()', not quite strong on this too but not able to come with better one, please feel free to try other alternatives.
also have no better name, so keep the same with v3.
Thanks
Chengwen
Quoted 20 lines
Quoted 10 lines
lib/kvargs/rte_kvargs.h +0
-0/** * Count the number of associations matching the given key *
lib/kvargs/version.map +0
-0lib/kvargs/version.map EXPERIMENTAL { · line 22
Quoted 7 lines
lib/kvargs/version.map +3
-0@@ -16,4 +16,7 @@ EXPERIMENTAL { # added in 21.11 rte_kvargs_get_with_value; + + # added in 23.11 + rte_kvargs_process_opt; };.
PATCH v3 2/5 net/af_packet: use new API to parse kvargs
In reply to Chengwen FengThis driver don't care about the 'iface' value, it should use rte_kvargs_process_opt() instead of rte_kvargs_process() to parse.
--- drivers/net/af_packet/rte_eth_af_packet.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/af_packet/rte_eth_af_packet.c +2 -2
@@ -1096,8 +1096,8 @@ rte_pmd_af_packet_probe(struct rte_vdev_device *dev)*/ if (rte_kvargs_count (kvlist,ETH_AF_PACKET_IFACE_ARG ) ==1 ) { - ret =rte_kvargs_process (kvlist,ETH_AF_PACKET_IFACE_ARG , - &open_packet_iface, &sockfd); + ret =rte_kvargs_process_opt (kvlist,ETH_AF_PACKET_IFACE_ARG , + &open_packet_iface, &sockfd);if (ret <0 ) goto exit; }
Signature · 1 line
2.17.1
Re: [PATCH v3 2/5] net/af_packet: use new API to parse kvargs
Quoted 13 lines · Chengwen Feng
This driver don't care about the 'iface' value, it should use
rte_kvargs_process_opt()instead ofrte_kvargs_process()to parse.Signed-off-by Chengwen Feng <[email protected]>--- drivers/net/af_packet/rte_eth_af_packet.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/net/af_packet/rte_eth_af_packet.c +0
-0
drivers/net/af_packet/rte_eth_af_packet.c rte_pmd_af_packet_probe(struct rte_vdev_device *dev) · line 1103
Quoted 10 lines
drivers/net/af_packet/rte_eth_af_packet.c +2
-2@@ -1096,8 +1096,8 @@ rte_pmd_af_packet_probe(struct rte_vdev_device *dev)*/ if (rte_kvargs_count (kvlist,ETH_AF_PACKET_IFACE_ARG ) ==1 ) { - ret =rte_kvargs_process (kvlist,ETH_AF_PACKET_IFACE_ARG , - &open_packet_iface, &sockfd); + ret =rte_kvargs_process_opt (kvlist,ETH_AF_PACKET_IFACE_ARG , + &open_packet_iface, &sockfd);if (ret <0 ) goto exit; }
lets not update this driver, I think it is using kvargs unconventionally, 'iface' requires argument but driver parses it directly from kvargs.
We can fix kvargs usage more properly instead of this change, I am taking a mental note for this.
Re: [PATCH v3 2/5] net/af_packet: use new API to parse kvargs
Hi Ferruh,
Quoted 29 lines · Ferruh Yigit
Quoted 13 lines · Chengwen Feng
This driver don't care about the 'iface' value, it should use
rte_kvargs_process_opt()instead ofrte_kvargs_process()to parse.Signed-off-by Chengwen Feng <[email protected]>--- drivers/net/af_packet/rte_eth_af_packet.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/net/af_packet/rte_eth_af_packet.c +0
-0drivers/net/af_packet/rte_eth_af_packet.c rte_pmd_af_packet_probe(struct rte_vdev_device *dev) · line 1103
Quoted 10 lines
drivers/net/af_packet/rte_eth_af_packet.c +2
-2@@ -1096,8 +1096,8 @@ rte_pmd_af_packet_probe(struct rte_vdev_device *dev)*/ if (rte_kvargs_count (kvlist,ETH_AF_PACKET_IFACE_ARG ) ==1 ) { - ret =rte_kvargs_process (kvlist,ETH_AF_PACKET_IFACE_ARG , - &open_packet_iface, &sockfd); + ret =rte_kvargs_process_opt (kvlist,ETH_AF_PACKET_IFACE_ARG , + &open_packet_iface, &sockfd);if (ret <0 ) goto exit; }lets not update this driver, I think it is using kvargs unconventionally, 'iface' requires argument but driver parses it directly from kvargs.
Quoted 2 lines
We can fix kvargs usage more properly instead of this change, I am taking a mental note for this.
got, it was droped from v4.
Thanks
Chengwen
Quoted 2 lines
.
PATCH v3 3/5 net/sfc: use new API to parse kvargs
In reply to Chengwen FengThe sfc_kvargs_process() and sfc_efx_dev_class_get() function could handle both key=value and only-key, so they should use rte_kvargs_process_opt() instead of rte_kvargs_process() to parse.
--- drivers/common/sfc_efx/sfc_efx.c | 4 ++-- drivers/net/sfc/sfc_kvargs.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/common/sfc_efx/sfc_efx.c +2 -2
@@ -52,8 +52,8 @@ sfc_efx_dev_class_get(struct rte_devargs *devargs)return dev_class;if (rte_kvargs_count (kvargs,RTE_DEVARGS_KEY_CLASS ) !=0 ) { -rte_kvargs_process (kvargs,RTE_DEVARGS_KEY_CLASS , - sfc_efx_kvarg_dev_class_handler, &dev_class); +rte_kvargs_process_opt (kvargs,RTE_DEVARGS_KEY_CLASS , + sfc_efx_kvarg_dev_class_handler, &dev_class); }rte_kvargs_free (kvargs);
drivers/net/sfc/sfc_kvargs.c +1 -1
@@ -70,7 +70,7 @@ sfc_kvargs_process(struct sfc_adapter *sa, const char *key_match,if (sa->kvargs ==NULL )return 0 ; -return -rte_kvargs_process (sa->kvargs, key_match, handler, opaque_arg); +return -rte_kvargs_process_opt (sa->kvargs, key_match, handler, opaque_arg); }int
Signature · 1 line
2.17.1
Re: [PATCH v3 3/5] net/sfc: use new API to parse kvargs
Quoted 30 lines · Chengwen Feng
The
sfc_kvargs_process()andsfc_efx_dev_class_get()function could handle both key=value and only-key, so they should userte_kvargs_process_opt()instead ofrte_kvargs_process()to parse.Signed-off-by Chengwen Feng <[email protected]>--- drivers/common/sfc_efx/sfc_efx.c | 4 ++-- drivers/net/sfc/sfc_kvargs.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)drivers/common/sfc_efx/sfc_efx.c +2
-2@@ -52,8 +52,8 @@ sfc_efx_dev_class_get(struct rte_devargs *devargs)return dev_class;if (rte_kvargs_count (kvargs,RTE_DEVARGS_KEY_CLASS ) !=0 ) { -rte_kvargs_process (kvargs,RTE_DEVARGS_KEY_CLASS , - sfc_efx_kvarg_dev_class_handler, &dev_class); +rte_kvargs_process_opt (kvargs,RTE_DEVARGS_KEY_CLASS , + sfc_efx_kvarg_dev_class_handler, &dev_class); }rte_kvargs_free (kvargs);drivers/net/sfc/sfc_kvargs.c +0
-0
drivers/net/sfc/sfc_kvargs.c sfc_kvargs_process(struct sfc_adapter *sa, const char *key_match, · line 76
Quoted 8 lines
drivers/net/sfc/sfc_kvargs.c +1
-1@@ -70,7 +70,7 @@ sfc_kvargs_process(struct sfc_adapter *sa, const char *key_match,if (sa->kvargs ==NULL )return 0 ; -return -rte_kvargs_process (sa->kvargs, key_match, handler, opaque_arg); +return -rte_kvargs_process_opt (sa->kvargs, key_match, handler, opaque_arg); }int
looks good to me
PATCH v3 4/5 net/tap: use new API to parse kvargs
In reply to Chengwen FengThis driver could handles both key=value and only-key kvargs, so it should use rte_kvargs_process_opt() instead of rte_kvargs_process() to parse.
--- drivers/net/tap/rte_eth_tap.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
drivers/net/tap/rte_eth_tap.c +13 -13
@@ -2342,7 +2342,7 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev) kvlist =rte_kvargs_parse (params, valid_arguments);if (kvlist) {if (rte_kvargs_count (kvlist,ETH_TAP_IFACE_ARG ) ==1 ) { - ret =rte_kvargs_process (kvlist, + ret =rte_kvargs_process_opt (kvlist,ETH_TAP_IFACE_ARG , &set_interface_name, tun_name);
@@ -2546,28 +2546,28 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev) kvlist =rte_kvargs_parse (params, valid_arguments);if (kvlist) {if (rte_kvargs_count (kvlist,ETH_TAP_IFACE_ARG ) ==1 ) { - ret =rte_kvargs_process (kvlist, -ETH_TAP_IFACE_ARG , - &set_interface_name, - tap_name); + ret =rte_kvargs_process_opt (kvlist, +ETH_TAP_IFACE_ARG , + &set_interface_name, + tap_name);if (ret ==-1 ) goto leave; }if (rte_kvargs_count (kvlist,ETH_TAP_REMOTE_ARG ) ==1 ) { - ret =rte_kvargs_process (kvlist, -ETH_TAP_REMOTE_ARG , - &set_remote_iface, - remote_iface); + ret =rte_kvargs_process_opt (kvlist, +ETH_TAP_REMOTE_ARG , + &set_remote_iface, + remote_iface);if (ret ==-1 ) goto leave; }if (rte_kvargs_count (kvlist,ETH_TAP_MAC_ARG ) ==1 ) { - ret =rte_kvargs_process (kvlist, -ETH_TAP_MAC_ARG , - &set_mac_type, - &user_mac); + ret =rte_kvargs_process_opt (kvlist, +ETH_TAP_MAC_ARG , + &set_mac_type, + &user_mac);if (ret ==-1 ) goto leave; }
Signature · 1 line
2.17.1
Re: [PATCH v3 4/5] net/tap: use new API to parse kvargs
Quoted 38 lines · Chengwen Feng
This driver could handles both key=value and only-key kvargs, so it should use
rte_kvargs_process_opt()instead ofrte_kvargs_process()to parse.Signed-off-by Chengwen Feng <[email protected]>--- drivers/net/tap/rte_eth_tap.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)drivers/net/tap/rte_eth_tap.c +5
-5@@ -2342,7 +2342,7 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev) kvlist =rte_kvargs_parse (params, valid_arguments);if (kvlist) {if (rte_kvargs_count (kvlist,ETH_TAP_IFACE_ARG ) ==1 ) { - ret =rte_kvargs_process (kvlist, + ret =rte_kvargs_process_opt (kvlist,ETH_TAP_IFACE_ARG , &set_interface_name, tun_name);@@ -2546,28 +2546,28 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev) kvlist =rte_kvargs_parse (params, valid_arguments);if (kvlist) {if (rte_kvargs_count (kvlist,ETH_TAP_IFACE_ARG ) ==1 ) { - ret =rte_kvargs_process (kvlist, -ETH_TAP_IFACE_ARG , - &set_interface_name, - tap_name); + ret =rte_kvargs_process_opt (kvlist, +ETH_TAP_IFACE_ARG , + &set_interface_name, + tap_name);if (ret ==-1 ) goto leave; }
drivers/net/tap/rte_eth_tap.c rte_pmd_tap_probe(struct rte_vdev_device *dev) · line 2562
Quoted 10 lines
drivers/net/tap/rte_eth_tap.c +4
-4if (rte_kvargs_count (kvlist,ETH_TAP_REMOTE_ARG ) ==1 ) { - ret =rte_kvargs_process (kvlist, -ETH_TAP_REMOTE_ARG , - &set_remote_iface, - remote_iface); + ret =rte_kvargs_process_opt (kvlist, +ETH_TAP_REMOTE_ARG , + &set_remote_iface, + remote_iface);
As far as I can see, "remote" arg without value is not valid, but driver handles this case as if "remote" arg is not provided at all. I think it is reasonable to keep using 'rte_kvargs_process()', and fail if 'value' is not provided.
drivers/net/tap/rte_eth_tap.c rte_pmd_tap_probe(struct rte_vdev_device *dev) · line 2570
Quoted 13 lines
drivers/net/tap/rte_eth_tap.c +4
-4if (ret ==-1 ) goto leave; }if (rte_kvargs_count (kvlist,ETH_TAP_MAC_ARG ) ==1 ) { - ret =rte_kvargs_process (kvlist, -ETH_TAP_MAC_ARG , - &set_mac_type, - &user_mac); + ret =rte_kvargs_process_opt (kvlist, +ETH_TAP_MAC_ARG , + &set_mac_type, + &user_mac);
same here, 'rte_kvargs_process()' can be used, there is no point to give "mac" keyword without value, that is same as not providing "mac" keyword at all, so this can fail to notify user either provide a mac or remove the argument.
I think current logic is to handle "value==null" case, otherwise this is not a valid usecase.
Quoted 3 lines
drivers/net/tap/rte_eth_tap.c +0
-0if (ret ==-1 ) goto leave;}
Re: [PATCH v3 4/5] net/tap: use new API to parse kvargs
Hi Ferruh,
Thanks for deepin, both fix in v4.
Quoted 84 lines · Ferruh Yigit
Quoted 38 lines · Chengwen Feng
This driver could handles both key=value and only-key kvargs, so it should use
rte_kvargs_process_opt()instead ofrte_kvargs_process()to parse.Signed-off-by Chengwen Feng <[email protected]>--- drivers/net/tap/rte_eth_tap.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)drivers/net/tap/rte_eth_tap.c +5
-5@@ -2342,7 +2342,7 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev) kvlist =rte_kvargs_parse (params, valid_arguments);if (kvlist) {if (rte_kvargs_count (kvlist,ETH_TAP_IFACE_ARG ) ==1 ) { - ret =rte_kvargs_process (kvlist, + ret =rte_kvargs_process_opt (kvlist,ETH_TAP_IFACE_ARG , &set_interface_name, tun_name);@@ -2546,28 +2546,28 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev) kvlist =rte_kvargs_parse (params, valid_arguments);if (kvlist) {if (rte_kvargs_count (kvlist,ETH_TAP_IFACE_ARG ) ==1 ) { - ret =rte_kvargs_process (kvlist, -ETH_TAP_IFACE_ARG , - &set_interface_name, - tap_name); + ret =rte_kvargs_process_opt (kvlist, +ETH_TAP_IFACE_ARG , + &set_interface_name, + tap_name);if (ret ==-1 ) goto leave; }drivers/net/tap/rte_eth_tap.c rte_pmd_tap_probe(struct rte_vdev_device *dev) · line 2562
Quoted 10 lines
drivers/net/tap/rte_eth_tap.c +4
-4if (rte_kvargs_count (kvlist,ETH_TAP_REMOTE_ARG ) ==1 ) { - ret =rte_kvargs_process (kvlist, -ETH_TAP_REMOTE_ARG , - &set_remote_iface, - remote_iface); + ret =rte_kvargs_process_opt (kvlist, +ETH_TAP_REMOTE_ARG , + &set_remote_iface, + remote_iface);As far as I can see, "remote" arg without value is not valid, but driver handles this case as if "remote" arg is not provided at all. I think it is reasonable to keep using '
rte_kvargs_process()', and fail if 'value' is not provided.drivers/net/tap/rte_eth_tap.c rte_pmd_tap_probe(struct rte_vdev_device *dev) · line 2570
Quoted 13 lines
drivers/net/tap/rte_eth_tap.c +4
-4if (ret ==-1 ) goto leave; }if (rte_kvargs_count (kvlist,ETH_TAP_MAC_ARG ) ==1 ) { - ret =rte_kvargs_process (kvlist, -ETH_TAP_MAC_ARG , - &set_mac_type, - &user_mac); + ret =rte_kvargs_process_opt (kvlist, +ETH_TAP_MAC_ARG , + &set_mac_type, + &user_mac);same here, '
rte_kvargs_process()' can be used, there is no point to give "mac" keyword without value, that is same as not providing "mac" keyword at all, so this can fail to notify user either provide a mac or remove the argument.I think current logic is to handle "value==null" case, otherwise this is not a valid usecase.
Quoted 3 lines
drivers/net/tap/rte_eth_tap.c +0
-0if (ret ==-1 ) goto leave;}
.
PATCH v3 5/5 net/mvneta: fix possible out-of-bounds write
In reply to Chengwen FengThe mvneta_ifnames_get() function will save 'iface' value to ifnames, it will out-of-bounds write if passed many iface pairs (e.g. 'iface=xxx,iface=xxx,...').
--- drivers/net/mvneta/mvneta_ethdev.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/mvneta/mvneta_ethdev.c +3 -0
@@ -91,6 +91,9 @@ mvneta_ifnames_get(const char *key __rte_unused, const char *value, {struct mvneta_ifnames *ifnames = extra_args; +if (ifnames->idx >=NETA_NUM_ETH_PPIO ) +return -EINVAL ; + ifnames->names[ifnames->idx++] = value;return 0 ;
Signature · 1 line
2.17.1
Re: [PATCH v3 5/5] net/mvneta: fix possible out-of-bounds write
Quoted 9 lines · Chengwen Feng
The
mvneta_ifnames_get()function will save 'iface' value to ifnames, it will out-of-bounds write if passed many iface pairs (e.g. 'iface=xxx,iface=xxx,...').Fixes 4ccc8d770d3b ("net/mvneta: add PMD skeleton")Signed-off-by Chengwen Feng <[email protected]>
Quoted 13 lines · Chengwen Feng
The
rte_kvargs_process()was used to parse key-value (e.g. socket_id=0), it also supports to parse only-key (e.g.socket_id). But many drivers's callback can only handle key-value, it will segment fault if handles only-key. so the patchset [1] was introduced.Because the patchset [1] modified too much drivers, therefore:
1) A new APIrte_kvargs_process_opt()was introduced, it inherits the function ofrte_kvargs_process()which could parse both key-value and only-key.
2) Constraint therte_kvargs_process()can only parse key-value.This patchset also include one bugfix for kvargs of mvneta driver.
Quoted 9 lines
[1] https://patches.dpdk.org/project/dpdk/patch/[email protected]/
Chengwen Feng (5):
kvargs: add one new process API
net/af_packet: use new API to parse kvargs
net/sfc: use new API to parse kvargs
net/tap: use new API to parse kvargs
net/mvneta: fix possible out-of-bounds write
Hi Chengwen,
I checked the driver code updates above, but it is hard to know if there are more missing, each requires investigating one by one. Perhaps it can be easier to trace back from your original patch [1] and update the ones that doesn't need "value == NULL" check, I assume this is what you did.
Hi Ferruh,
Quoted 24 lines · Ferruh Yigit
Quoted 13 lines · Chengwen Feng
The
rte_kvargs_process()was used to parse key-value (e.g. socket_id=0), it also supports to parse only-key (e.g.socket_id). But many drivers's callback can only handle key-value, it will segment fault if handles only-key. so the patchset [1] was introduced.Because the patchset [1] modified too much drivers, therefore:
1) A new APIrte_kvargs_process_opt()was introduced, it inherits the function ofrte_kvargs_process()which could parse both key-value and only-key.
2) Constraint therte_kvargs_process()can only parse key-value.This patchset also include one bugfix for kvargs of mvneta driver.
Quoted 9 lines
[1] https://patches.dpdk.org/project/dpdk/patch/[email protected]/
Chengwen Feng (5):
kvargs: add one new process API
net/af_packet: use new API to parse kvargs
net/sfc: use new API to parse kvargs
net/tap: use new API to parse kvargs
net/mvneta: fix possible out-of-bounds write
Quoted 7 lines
Hi Chengwen,
I checked the driver code updates above, but it is hard to know if there are more missing, each requires investigating one by one. Perhaps it can be easier to trace back from your original patch [1] and update the ones that doesn't need "value == NULL" check, I assume this is what you did.
There are 51 files modified in v2 [1], there will about 80 rte_kvargs_process() invoke in current git (stats by command [2]).
Exclude kvargs lib and it's test and part comment, there are 30 file was not in v2:
drivers/baseband/null/bbdev_null.c ---already treat NULL value as a error drivers/baseband/turbo_sw/bbdev_turbo_software.c ---already treat NULL value as a error drivers/bus/ifpga/ifpga_bus.c ---already treat NULL value as a error drivers/common/nfp/nfp_common_pci.c ---could handle NULL value drivers/common/sfc_efx/sfc_efx.c ---could handle NULL value drivers/dma/skeleton/skeleton_dmadev.c ---already treat NULL value as a error drivers/ml/cnxk/cn10k_ml_dev.c ---part treat NULL value as a error, other segment fault when with NULL value drivers/ml/cnxk/mvtvm_ml_dev.c ---segment fault when with NULL value drivers/net/af_packet/rte_eth_af_packet.c ---don't care about value, suggested don't change in v3's comment drivers/net/bnxt/bnxt_ethdev.c ---already treat NULL value as a error drivers/net/bonding/rte_eth_bond_pmd.c ---already treat NULL value as a error drivers/net/cpfl/cpfl_ethdev.c ---segment fault when with NULL value drivers/net/failsafe/failsafe_args.c ---already treat NULL value as a error drivers/net/hns3/hns3_common.c ---already treat NULL value as a error drivers/net/ixgbe/ixgbe_ethdev.c ---already treat NULL value as a error drivers/net/null/rte_eth_null.c ---already treat NULL value as a error drivers/net/softnic/rte_eth_softnic.c ---already treat NULL value as a error drivers/net/tap/rte_eth_tap.c ---could handle NULL value drivers/net/txgbe/txgbe_ethdev.c ---already treat NULL value as a error drivers/net/vhost/rte_eth_vhost.c ---already treat NULL value as a error drivers/net/virtio/virtio_ethdev.c ---already treat NULL value as a error drivers/net/virtio/virtio_pci_ethdev.c ---already treat NULL value as a error drivers/net/virtio/virtio_user_ethdev.c ---already treat NULL value as a error drivers/raw/ifpga/ifpga_rawdev.c ---already treat NULL value as a error drivers/raw/skeleton/skeleton_rawdev.c ---already treat NULL value as a error drivers/vdpa/ifc/ifcvf_vdpa.c ---already treat NULL value as a error drivers/vdpa/sfc/sfc_vdpa_filter.c ---already treat NULL value as a error lib/compressdev/rte_compressdev_pmd.c ---already treat NULL value as a error lib/cryptodev/cryptodev_pmd.c ---already treat NULL value as a error lib/ethdev/rte_ethdev_telemetry.c ---already treat NULL value as a error
so we should only process three drivers: common/nfp, sfc, tap, and these are what v4 doing.
[1] https://patches.dpdk.org/project/dpdk/patch/[email protected]/
[2] grep -rn "rte_kvargs_process(" | cut -d ":" -f 1 | sort | uniq -c | wc -l
Thanks
Chengwen
Quoted 3 lines
.
v4 cover fix segment fault when parse args
In reply to Chengwen FengThe rte_kvargs_process() was used to parse key-value (e.g. socket_id=0), it also supports to parse only-key (e.g. socket_id). But many drivers's callback can only handle key-value, it will segment fault if handles only-key. so the patchset [1] was introduced.
Because the patchset [1] modified too much drivers, therefore:
1) A new API rte_kvargs_process_opt() was introduced, it inherits the function of rte_kvargs_process() which could parse both key-value and only-key.
2) Constraint the rte_kvargs_process() can only parse key-value.
This patchset also include one bugfix for kvargs of mvneta driver.
[1] https://patches.dpdk.org/project/dpdk/patch/[email protected]/
Chengwen Feng (5):
kvargs: add one new process API
net/sfc: use new API to parse kvargs
net/tap: use new API to parse kvargs
common/nfp: use new API to parse kvargs
net/mvneta: fix possible out-of-bounds write
---
v4: refine API's define and impl which address Ferruh's comments.
add common/nfp change commit.
v3: introduce new API instead of modify too many drivers which address
Ferruh's comments.
doc/guides/rel_notes/release_23_11.rst | 13 ++++++++ drivers/common/nfp/nfp_common_pci.c | 4 +-- drivers/common/sfc_efx/sfc_efx.c | 4 +-- drivers/net/mvneta/mvneta_ethdev.c | 3 ++ drivers/net/sfc/sfc_kvargs.c | 2 +- drivers/net/tap/rte_eth_tap.c | 10 +++--- lib/kvargs/rte_kvargs.c | 43 ++++++++++++++++++++------ lib/kvargs/rte_kvargs.h | 37 ++++++++++++++++++++-- lib/kvargs/version.map | 3 ++ 9 files changed, 97 insertions(+), 22 deletions(-)
Signature · 1 line
2.17.1
PATCH v4 1/5 kvargs: add one new process API
The rte_kvargs_process() was used to handle key=value (e.g. socket_id=0), it also supports to handle only-key (e.g. socket_id). But many drivers's callback can only handle key=value, it will segment fault if handles only-key. so the patchset [1] was introduced.
Because the patchset [1] modified too much drivers, therefore:
1) A new API rte_kvargs_process_opt() was introduced, it inherits the function of rte_kvargs_process() which could handle both key=value and only-key cases.
2) Constraint the rte_kvargs_process() can only handle key=value cases, it will return -1 when handle only-key case (that is the matched key's value is NULL).
This patch also make sure the rte_kvargs_process_opt() and rte_kvargs_process() API both return -1 when the kvlist parameter is NULL.
[1] https://patches.dpdk.org/project/dpdk/patch/[email protected]/
--- doc/guides/rel_notes/release_23_11.rst | 13 ++++++++ lib/kvargs/rte_kvargs.c | 43 ++++++++++++++++++++------ lib/kvargs/rte_kvargs.h | 37 ++++++++++++++++++++-- lib/kvargs/version.map | 3 ++ 4 files changed, 84 insertions(+), 12 deletions(-)
doc/guides/rel_notes/release_23_11.rst +13 -0
@@ -137,6 +137,19 @@ New Features a group's miss actions, which are the actions to be performed on packets that didn't match any of the flow rules in the group. +* **Updated kvargs process API.** + + * Introduced rte_kvargs_process_opt() API, which inherits the function + of rte_kvargs_process() and could handle both key=value and only-key + cases. + + * Constraint rte_kvargs_process() API can only handle key=value cases, + it will return -1 when handle only-key case (that is the matched key's + value is NULL). + + * Make sure rte_kvargs_process_opt() and rte_kvargs_process() API both + return -1 when the kvlist parameter is NULL. + * **Updated Amazon ena (Elastic Network Adapter) net driver.** * Upgraded ENA HAL to latest version.
lib/kvargs/rte_kvargs.c +34 -9
65 lines not on this page · raw message
lib/kvargs/rte_kvargs.h +34 -3
@@ -172,14 +172,17 @@ const char *rte_kvargs_get_with_value(const struct rte_kvargs *kvlist, const char *key, const char *value);/** -* Call a handler function for each key/value matching the key +* Call a handler function for each key=value matching the key * -* For each key/value association that matches the given key, calls the +* For each key=value association that matches the given key, calls the * handler function with the for a given arg_name passing the value on the * dictionary for that key and a given extra argument. * +* @note Compared to @see rte_kvargs_process_opt, this API will return -1 +* when handle only-key case (that is the matched key's value is NULL). +* * @param kvlist -* The rte_kvargs structure. No error if NULL. +* The rte_kvargs structure. * @param key_match * The key on which the handler should be called, or NULL to process handler * on all associations
@@ -195,6 +198,34 @@ const char *rte_kvargs_get_with_value(const struct rte_kvargs *kvlist,int rte_kvargs_process (const struct rte_kvargs *kvlist,const char *key_match,arg_handler_t handler,void *opaque_arg); +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Call a handler function for each key=value or only-key matching the key +* +* For each key=value or only-key association that matches the given key, calls +* the handler function with the for a given arg_name passing the value on the +* dictionary for that key and a given extra argument. +* +* @param kvlist +* The rte_kvargs structure. +* @param key_match +* The key on which the handler should be called, or NULL to process handler +* on all associations +* @param handler +* The function to call for each matching key +* @param opaque_arg +* A pointer passed unchanged to the handler +* +* @return +* - 0 on success +* - Negative on error +*/ +__rte_experimental +int rte_kvargs_process_opt(const struct rte_kvargs *kvlist, +const char *key_match,arg_handler_t handler,void *opaque_arg); +/** * Count the number of associations matching the given key *
lib/kvargs/version.map +3 -0
@@ -16,4 +16,7 @@ EXPERIMENTAL { # added in 21.11 rte_kvargs_get_with_value; + + # added in 23.11 + rte_kvargs_process_opt; };
Signature · 1 line
2.17.1
Re: [PATCH v4 1/5] kvargs: add one new process API
doc/guides/rel_notes/release_23_11.rst New Features · line 149
Quoted 10 lines · On Sun, 5 Nov 2023 05:45:35 +0000 Chengwen Feng <[email protected]> wrote:
doc/guides/rel_notes/release_23_11.rst +10
-0+* **Updated kvargs process API.** + + * Introduced rte_kvargs_process_opt() API, which inherits the function + of rte_kvargs_process() and could handle both key=value and only-key + cases. + + * Constraint rte_kvargs_process() API can only handle key=value cases, + it will return -1 when handle only-key case (that is the matched key's + value is NULL). +
Looks good but may I suggest some alternatives.
Since this is an API and ABI change as was not announced, maybe a little late in the process for this release. And since unlikely to go in 23.11 need to do something better in 24.03.
What about changing the args to rte_kvargs_process() to add an additional default value. Most callers don't have a default (use key-value) but the ones that take only-key would pass the default value.
Then use ABI versioning to add the new arg and you would not have to introduce a new function. And add a legacy API version that does what current code does.
All the drivers in DPDK would get the new API/ABI but any customer apps using rte_kvargs_process() would get the old version.
Re: [PATCH v4 1/5] kvargs: add one new process API
Hi Stephen,
Quoted 16 lines · Stephen Hemminger
doc/guides/rel_notes/release_23_11.rst New Features · line 149
Quoted 10 lines · On Sun, 5 Nov 2023 05:45:35 +0000 Chengwen Feng <[email protected]> wrote:
doc/guides/rel_notes/release_23_11.rst +10
-0+* **Updated kvargs process API.** + + * Introduced rte_kvargs_process_opt() API, which inherits the function + of rte_kvargs_process() and could handle both key=value and only-key + cases. + + * Constraint rte_kvargs_process() API can only handle key=value cases, + it will return -1 when handle only-key case (that is the matched key's + value is NULL). +Looks good but may I suggest some alternatives.
Quoted 7 lines
Since this is an API and ABI change as was not announced, maybe a little late in the process for this release. And since unlikely to go in 23.11 need to do something better in 24.03.
What about changing the args to
rte_kvargs_process()to add an additional default value. Most callers don't have a default (use key-value) but the ones that take only-key would pass the default value.
The API definition changed, it may need modify most drivers.
Although it's a little late, better continue current.
Thanks
Chengwen
Quoted 10 lines
Then use ABI versioning to add the new arg and you would not have to introduce a new function. And add a legacy API version that does what current code does.
All the drivers in DPDK would get the new API/ABI but any customer apps using
rte_kvargs_process()would get the old version..
Re: [PATCH v4 1/5] kvargs: add one new process API
Quoted 12 lines · On Mon, 6 Nov 2023 15:13:35 +0800 fengchengwen <[email protected]> wrote:
Quoted 11 lines
Quoted 1 line
+
Looks good but may I suggest some alternatives.
Since this is an API and ABI change as was not announced, maybe a little late in the process for this release. And since unlikely to go in 23.11 need to do something better in 24.03.
What about changing the args to
rte_kvargs_process()to add an additional default value. Most callers don't have a default (use key-value) but the ones that take only-key would pass the default value.
Quoted 6 lines
The API definition changed, it may need modify most drivers.
Although it's a little late, better continue current.
Thanks
Chengwen
Looking ahead, I would like to replace all of EAL args and KVargs processing with something more like the python parseargs library. The API is cleaner and incorporating the help with arg parsing is a real benefit. Thomas also suggested integrating help in the arg parsing.
Something like: https://github.com/cofyc/argparse
Re: [PATCH v4 1/5] kvargs: add one new process API
Hi Stephen,
Quoted 22 lines · Stephen Hemminger
Quoted 12 lines · On Mon, 6 Nov 2023 15:13:35 +0800 fengchengwen <[email protected]> wrote:
Quoted 11 lines
Quoted 1 line
+
Looks good but may I suggest some alternatives.
Since this is an API and ABI change as was not announced, maybe a little late in the process for this release. And since unlikely to go in 23.11 need to do something better in 24.03.
What about changing the args to
rte_kvargs_process()to add an additional default value. Most callers don't have a default (use key-value) but the ones that take only-key would pass the default value.Quoted 6 lines
The API definition changed, it may need modify most drivers.
Although it's a little late, better continue current.
Thanks
Chengwen
Quoted 6 lines
Looking ahead, I would like to replace all of EAL args and KVargs processing with something more like the python parseargs library. The API is cleaner and incorporating the help with arg parsing is a real benefit. Thomas also suggested integrating help in the arg parsing.
Something like: https://github.com/cofyc/argparse
The argparse is great, especial it integrate help in the arg parsing, which could help for parse args.
I will propose a argparse library RFC later, and we could both work on it.
As for this commit, I think it has difference: the KV pair was not separated by spaces,
So for: dpdk-testpmd -a 0000:7d:00.0,a=1,b=2,c=3 --file-prefix=feng
We could parse 'a' has value: 0000:7d:00.0,a=1,b=2,c=3
'file-prefix' has value: feng
by argparse.
and then use kvargs to parse a=1,b=2,c=3.
Thanks
Chengwen
Quoted 3 lines
.
PATCH v4 2/5 net/sfc: use new API to parse kvargs
In reply to Chengwen FengThe sfc_kvargs_process() and sfc_efx_dev_class_get() function could handle both key=value and only-key, so they should use rte_kvargs_process_opt() instead of rte_kvargs_process() to parse.
--- drivers/common/sfc_efx/sfc_efx.c | 4 ++-- drivers/net/sfc/sfc_kvargs.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/common/sfc_efx/sfc_efx.c +2 -2
@@ -52,8 +52,8 @@ sfc_efx_dev_class_get(struct rte_devargs *devargs)return dev_class;if (rte_kvargs_count (kvargs,RTE_DEVARGS_KEY_CLASS ) !=0 ) { -rte_kvargs_process (kvargs,RTE_DEVARGS_KEY_CLASS , - sfc_efx_kvarg_dev_class_handler, &dev_class); +rte_kvargs_process_opt (kvargs,RTE_DEVARGS_KEY_CLASS , + sfc_efx_kvarg_dev_class_handler, &dev_class); }rte_kvargs_free (kvargs);
drivers/net/sfc/sfc_kvargs.c +1 -1
@@ -70,7 +70,7 @@ sfc_kvargs_process(struct sfc_adapter *sa, const char *key_match,if (sa->kvargs ==NULL )return 0 ; -return -rte_kvargs_process (sa->kvargs, key_match, handler, opaque_arg); +return -rte_kvargs_process_opt (sa->kvargs, key_match, handler, opaque_arg); }int
Signature · 1 line
2.17.1
PATCH v4 3/5 net/tap: use new API to parse kvargs
In reply to Chengwen FengSome kvargs could be key=value or only-key, it should use rte_kvargs_process_opt() instead of rte_kvargs_process() to handle these kvargs.
--- drivers/net/tap/rte_eth_tap.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/net/tap/rte_eth_tap.c +5 -5
@@ -2292,7 +2292,7 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev) kvlist =rte_kvargs_parse (params, valid_arguments);if (kvlist) {if (rte_kvargs_count (kvlist,ETH_TAP_IFACE_ARG ) ==1 ) { - ret =rte_kvargs_process (kvlist, + ret =rte_kvargs_process_opt (kvlist,ETH_TAP_IFACE_ARG , &set_interface_name, tun_name);
@@ -2496,10 +2496,10 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev) kvlist =rte_kvargs_parse (params, valid_arguments);if (kvlist) {if (rte_kvargs_count (kvlist,ETH_TAP_IFACE_ARG ) ==1 ) { - ret =rte_kvargs_process (kvlist, -ETH_TAP_IFACE_ARG , - &set_interface_name, - tap_name); + ret =rte_kvargs_process_opt (kvlist, +ETH_TAP_IFACE_ARG , + &set_interface_name, + tap_name);if (ret ==-1 ) goto leave; }
Signature · 1 line
2.17.1
PATCH v4 4/5 common/nfp: use new API to parse kvargs
In reply to Chengwen FengThe nfp_parse_class_options() function could handle both key=value and only-key, so it should use rte_kvargs_process_opt() instead of rte_kvargs_process() to parse.
--- drivers/common/nfp/nfp_common_pci.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/common/nfp/nfp_common_pci.c +2 -2
@@ -171,8 +171,8 @@ nfp_parse_class_options(const struct rte_devargs *devargs)return dev_class;if (rte_kvargs_count (kvargs,RTE_DEVARGS_KEY_CLASS ) !=0 ) { -rte_kvargs_process (kvargs,RTE_DEVARGS_KEY_CLASS , - nfp_kvarg_dev_class_handler, &dev_class); +rte_kvargs_process_opt (kvargs,RTE_DEVARGS_KEY_CLASS , + nfp_kvarg_dev_class_handler, &dev_class); }rte_kvargs_free (kvargs);
Signature · 1 line
2.17.1
Re: [PATCH v4 4/5] common/nfp: use new API to parse kvargs
drivers/common/nfp/nfp_common_pci.c nfp_parse_class_options(const struct rte_devargs *devargs) · line 176
Quoted 6 lines · On Sun, 5 Nov 2023 05:45:38 +0000 Chengwen Feng <[email protected]> wrote:
drivers/common/nfp/nfp_common_pci.c +2
-2if (rte_kvargs_count (kvargs,RTE_DEVARGS_KEY_CLASS ) !=0 ) { -rte_kvargs_process (kvargs,RTE_DEVARGS_KEY_CLASS , - nfp_kvarg_dev_class_handler, &dev_class); +rte_kvargs_process_opt (kvargs,RTE_DEVARGS_KEY_CLASS , + nfp_kvarg_dev_class_handler, &dev_class); }
Since kvargs_process() already does a scan, the kvargs_count() cause an extra pass.
Re: [PATCH v4 4/5] common/nfp: use new API to parse kvargs
Hi Stephen,
Quoted 11 lines · Stephen Hemminger
drivers/common/nfp/nfp_common_pci.c nfp_parse_class_options(const struct rte_devargs *devargs) · line 176
Quoted 6 lines · On Sun, 5 Nov 2023 05:45:38 +0000 Chengwen Feng <[email protected]> wrote:
drivers/common/nfp/nfp_common_pci.c +2
-2if (rte_kvargs_count (kvargs,RTE_DEVARGS_KEY_CLASS ) !=0 ) { -rte_kvargs_process (kvargs,RTE_DEVARGS_KEY_CLASS , - nfp_kvarg_dev_class_handler, &dev_class); +rte_kvargs_process_opt (kvargs,RTE_DEVARGS_KEY_CLASS , + nfp_kvarg_dev_class_handler, &dev_class); }Since
kvargs_process()already does a scan, thekvargs_count()cause an extra pass.
will fix in v5
Thanks
Chengwen
Quoted 3 lines
.
PATCH v4 5/5 net/mvneta: fix possible out-of-bounds write
In reply to Chengwen FengThe mvneta_ifnames_get() function will save 'iface' value to ifnames, it will out-of-bounds write if passed many iface pairs (e.g. 'iface=xxx,iface=xxx,...').
--- drivers/net/mvneta/mvneta_ethdev.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/mvneta/mvneta_ethdev.c +3 -0
@@ -91,6 +91,9 @@ mvneta_ifnames_get(const char *key __rte_unused, const char *value, {struct mvneta_ifnames *ifnames = extra_args; +if (ifnames->idx >=NETA_NUM_ETH_PPIO ) +return -EINVAL ; + ifnames->names[ifnames->idx++] = value;return 0 ;
Signature · 1 line
2.17.1
v5 cover fix segment fault when parse args
In reply to Chengwen FengThe rte_kvargs_process() was used to parse key-value (e.g. socket_id=0), it also supports to parse only-key (e.g. socket_id). But many drivers's callback can only handle key-value, it will segment fault if handles only-key. so the patchset [1] was introduced.
Because the patchset [1] modified too much drivers, therefore:
1) A new API rte_kvargs_process_opt() was introduced, it inherits the function of rte_kvargs_process() which could parse both key-value and only-key.
2) Constraint the rte_kvargs_process() can only parse key-value.
This patchset also include one bugfix for kvargs of mvneta driver.
[1] https://patches.dpdk.org/project/dpdk/patch/[email protected]/
Chengwen Feng (5):
kvargs: add one new process API
net/sfc: use new API to parse kvargs
net/tap: use new API to parse kvargs
common/nfp: use new API to parse kvargs
net/mvneta: fix possible out-of-bounds write
---
v5: remove redundant of rte_kvargs_count of 4/5 commit which address
Stephen's comment.
v4: refine API's define and impl which address Ferruh's comments.
add common/nfp change commit.
v3: introduce new API instead of modify too many drivers which address
Ferruh's comments.
doc/guides/rel_notes/release_23_11.rst | 13 ++++++++ drivers/common/nfp/nfp_common_pci.c | 6 ++-- drivers/common/sfc_efx/sfc_efx.c | 4 +-- drivers/net/mvneta/mvneta_ethdev.c | 3 ++ drivers/net/sfc/sfc_kvargs.c | 2 +- drivers/net/tap/rte_eth_tap.c | 10 +++--- lib/kvargs/rte_kvargs.c | 43 ++++++++++++++++++++------ lib/kvargs/rte_kvargs.h | 37 ++++++++++++++++++++-- lib/kvargs/version.map | 3 ++ 9 files changed, 97 insertions(+), 24 deletions(-)
Signature · 1 line
2.17.1
PATCH v5 1/5 kvargs: add one new process API
The rte_kvargs_process() was used to handle key=value (e.g. socket_id=0), it also supports to handle only-key (e.g. socket_id). But many drivers's callback can only handle key=value, it will segment fault if handles only-key. so the patchset [1] was introduced.
Because the patchset [1] modified too much drivers, therefore:
1) A new API rte_kvargs_process_opt() was introduced, it inherits the function of rte_kvargs_process() which could handle both key=value and only-key cases.
2) Constraint the rte_kvargs_process() can only handle key=value cases, it will return -1 when handle only-key case (that is the matched key's value is NULL).
This patch also make sure the rte_kvargs_process_opt() and rte_kvargs_process() API both return -1 when the kvlist parameter is NULL.
[1] https://patches.dpdk.org/project/dpdk/patch/[email protected]/
--- doc/guides/rel_notes/release_23_11.rst | 13 ++++++++ lib/kvargs/rte_kvargs.c | 43 ++++++++++++++++++++------ lib/kvargs/rte_kvargs.h | 37 ++++++++++++++++++++-- lib/kvargs/version.map | 3 ++ 4 files changed, 84 insertions(+), 12 deletions(-)
doc/guides/rel_notes/release_23_11.rst +13 -0
@@ -142,6 +142,19 @@ New Features a group's miss actions, which are the actions to be performed on packets that didn't match any of the flow rules in the group. +* **Updated kvargs process API.** + + * Introduced rte_kvargs_process_opt() API, which inherits the function + of rte_kvargs_process() and could handle both key=value and only-key + cases. + + * Constraint rte_kvargs_process() API can only handle key=value cases, + it will return -1 when handle only-key case (that is the matched key's + value is NULL). + + * Make sure rte_kvargs_process_opt() and rte_kvargs_process() API both + return -1 when the kvlist parameter is NULL. + * **Updated Amazon ena (Elastic Network Adapter) net driver.** * Upgraded ENA HAL to latest version.
lib/kvargs/rte_kvargs.c +34 -9
65 lines not on this page · raw message
lib/kvargs/rte_kvargs.h +34 -3
@@ -172,14 +172,17 @@ const char *rte_kvargs_get_with_value(const struct rte_kvargs *kvlist, const char *key, const char *value);/** -* Call a handler function for each key/value matching the key +* Call a handler function for each key=value matching the key * -* For each key/value association that matches the given key, calls the +* For each key=value association that matches the given key, calls the * handler function with the for a given arg_name passing the value on the * dictionary for that key and a given extra argument. * +* @note Compared to @see rte_kvargs_process_opt, this API will return -1 +* when handle only-key case (that is the matched key's value is NULL). +* * @param kvlist -* The rte_kvargs structure. No error if NULL. +* The rte_kvargs structure. * @param key_match * The key on which the handler should be called, or NULL to process handler * on all associations
@@ -195,6 +198,34 @@ const char *rte_kvargs_get_with_value(const struct rte_kvargs *kvlist,int rte_kvargs_process (const struct rte_kvargs *kvlist,const char *key_match,arg_handler_t handler,void *opaque_arg); +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Call a handler function for each key=value or only-key matching the key +* +* For each key=value or only-key association that matches the given key, calls +* the handler function with the for a given arg_name passing the value on the +* dictionary for that key and a given extra argument. +* +* @param kvlist +* The rte_kvargs structure. +* @param key_match +* The key on which the handler should be called, or NULL to process handler +* on all associations +* @param handler +* The function to call for each matching key +* @param opaque_arg +* A pointer passed unchanged to the handler +* +* @return +* - 0 on success +* - Negative on error +*/ +__rte_experimental +int rte_kvargs_process_opt(const struct rte_kvargs *kvlist, +const char *key_match,arg_handler_t handler,void *opaque_arg); +/** * Count the number of associations matching the given key *
lib/kvargs/version.map +3 -0
@@ -16,4 +16,7 @@ EXPERIMENTAL { # added in 21.11 rte_kvargs_get_with_value; + + # added in 23.11 + rte_kvargs_process_opt; };
Signature · 1 line
2.17.1
PATCH v5 2/5 net/sfc: use new API to parse kvargs
In reply to Chengwen FengThe sfc_kvargs_process() and sfc_efx_dev_class_get() function could handle both key=value and only-key, so they should use rte_kvargs_process_opt() instead of rte_kvargs_process() to parse.
--- drivers/common/sfc_efx/sfc_efx.c | 4 ++-- drivers/net/sfc/sfc_kvargs.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/common/sfc_efx/sfc_efx.c +2 -2
@@ -52,8 +52,8 @@ sfc_efx_dev_class_get(struct rte_devargs *devargs)return dev_class;if (rte_kvargs_count (kvargs,RTE_DEVARGS_KEY_CLASS ) !=0 ) { -rte_kvargs_process (kvargs,RTE_DEVARGS_KEY_CLASS , - sfc_efx_kvarg_dev_class_handler, &dev_class); +rte_kvargs_process_opt (kvargs,RTE_DEVARGS_KEY_CLASS , + sfc_efx_kvarg_dev_class_handler, &dev_class); }rte_kvargs_free (kvargs);
drivers/net/sfc/sfc_kvargs.c +1 -1
@@ -70,7 +70,7 @@ sfc_kvargs_process(struct sfc_adapter *sa, const char *key_match,if (sa->kvargs ==NULL )return 0 ; -return -rte_kvargs_process (sa->kvargs, key_match, handler, opaque_arg); +return -rte_kvargs_process_opt (sa->kvargs, key_match, handler, opaque_arg); }int
Signature · 1 line
2.17.1
Re: [PATCH v5 2/5] net/sfc: use new API to parse kvargs
Quoted 15 lines · Chengwen Feng
The
sfc_kvargs_process()andsfc_efx_dev_class_get()function could handle both key=value and only-key, so they should userte_kvargs_process_opt()instead ofrte_kvargs_process()to parse.Signed-off-by Chengwen Feng <[email protected]>--- drivers/common/sfc_efx/sfc_efx.c | 4 ++-- drivers/net/sfc/sfc_kvargs.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)drivers/common/sfc_efx/sfc_efx.c +0
-0
drivers/common/sfc_efx/sfc_efx.c sfc_efx_dev_class_get(struct rte_devargs *devargs) · line 56
Quoted 7 lines
drivers/common/sfc_efx/sfc_efx.c +2
-2@@ -52,8 +52,8 @@ sfc_efx_dev_class_get(struct rte_devargs *devargs)return dev_class;if (rte_kvargs_count (kvargs,RTE_DEVARGS_KEY_CLASS ) !=0 ) { -rte_kvargs_process (kvargs,RTE_DEVARGS_KEY_CLASS , - sfc_efx_kvarg_dev_class_handler, &dev_class); +rte_kvargs_process_opt (kvargs,RTE_DEVARGS_KEY_CLASS , + sfc_efx_kvarg_dev_class_handler, &dev_class);
LGTM from code point of view, but I'm not sure that I understand the idea behind handling NULL value in sfc_efx_kvarg_dev_class_handler().
drivers/net/sfc/sfc_kvargs.c sfc_kvargs_process(struct sfc_adapter *sa, const char *key_match, · line 73
Quoted 13 lines
drivers/common/sfc_efx/sfc_efx.c +0
-0}rte_kvargs_free (kvargs);drivers/net/sfc/sfc_kvargs.c +1
-1@@ -70,7 +70,7 @@ sfc_kvargs_process(struct sfc_adapter *sa, const char *key_match,if (sa->kvargs ==NULL )return 0 ; -return -rte_kvargs_process (sa->kvargs, key_match, handler, opaque_arg); +return -rte_kvargs_process_opt (sa->kvargs, key_match, handler, opaque_arg);
It looks wrong to me since many handlers do not handle NULL string gracefully. As I understand some handlers where fixed to avoid crash and correct fix would be to keep rte_kvargs_process() and remove
unnecessary checks for NULL string value.
Quoted 3 lines
drivers/net/sfc/sfc_kvargs.c +0
-0}int
Re: [PATCH v5 2/5] net/sfc: use new API to parse kvargs
Hi Andrew,
Quoted 28 lines · Andrew Rybchenko
Quoted 15 lines · Chengwen Feng
The
sfc_kvargs_process()andsfc_efx_dev_class_get()function could handle both key=value and only-key, so they should userte_kvargs_process_opt()instead ofrte_kvargs_process()to parse.Signed-off-by Chengwen Feng <[email protected]>---
drivers/common/sfc_efx/sfc_efx.c| 4 ++--
drivers/net/sfc/sfc_kvargs.c | 2 +-2 files changed, 3 insertions(+), 3 deletions(-)drivers/common/sfc_efx/sfc_efx.c +0
-0drivers/common/sfc_efx/sfc_efx.c sfc_efx_dev_class_get(struct rte_devargs *devargs) · line 55
Quoted 6 lines
drivers/common/sfc_efx/sfc_efx.c +2
-2@@ -52,8 +52,8 @@ sfc_efx_dev_class_get(struct rte_devargs *devargs) return dev_class; if (rte_kvargs_count(kvargs, RTE_DEVARGS_KEY_CLASS) != 0) { - rte_kvargs_process(kvargs, RTE_DEVARGS_KEY_CLASS, - sfc_efx_kvarg_dev_class_handler, &dev_class); + rte_kvargs_process_opt(kvargs, RTE_DEVARGS_KEY_CLASS, + sfc_efx_kvarg_dev_class_handler, &dev_class);LGTM from code point of view, but I'm not sure that I understand the idea behind handling NULL value in
sfc_efx_kvarg_dev_class_handler().Cc Vijay
Quoted 15 lines
drivers/net/sfc/sfc_kvargs.c sfc_kvargs_process(struct sfc_adapter *sa, const char *key_match, · line 73
Quoted 11 lines
drivers/common/sfc_efx/sfc_efx.c +0
-0} rte_kvargs_free(kvargs);drivers/net/sfc/sfc_kvargs.c +1
-0@@ -70,7 +70,7 @@ sfc_kvargs_process(struct sfc_adapter *sa, const char *key_match, if (sa->kvargs == NULL) return 0; - return -rte_kvargs_process(sa->kvargs, key_match, handler, opaque_arg); + return -rte_kvargs_process_opt(sa->kvargs, key_match, handler, opaque_arg);It looks wrong to me since many handlers do not handle NULL string gracefully. As I understand some handlers where fixed to avoid crash and correct fix would be to keep
rte_kvargs_process()and remove
unnecessary checks for NULL string value.
The scope is large, I suggest creates a new patchset later which remove unnecessary checks for NULL string value.
Quoted 5 lines
Quoted 3 lines
drivers/net/sfc/sfc_kvargs.c +0
-0}int
.
Andrew Rybchenko
NAKRe: [PATCH v5 2/5] net/sfc: use new API to parse kvargs
Quoted 47 lines · fengchengwen
Hi Andrew,
Quoted 28 lines · Andrew Rybchenko
Quoted 15 lines · Chengwen Feng
The
sfc_kvargs_process()andsfc_efx_dev_class_get()function could handle both key=value and only-key, so they should userte_kvargs_process_opt()instead ofrte_kvargs_process()to parse.Signed-off-by Chengwen Feng <[email protected]>--- drivers/common/sfc_efx/sfc_efx.c | 4 ++-- drivers/net/sfc/sfc_kvargs.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)drivers/common/sfc_efx/sfc_efx.c +0
-0drivers/common/sfc_efx/sfc_efx.c sfc_efx_dev_class_get(struct rte_devargs *devargs) · line 55
Quoted 6 lines
drivers/common/sfc_efx/sfc_efx.c +2
-2@@ -52,8 +52,8 @@ sfc_efx_dev_class_get(struct rte_devargs *devargs) return dev_class; if (rte_kvargs_count(kvargs, RTE_DEVARGS_KEY_CLASS) != 0) { - rte_kvargs_process(kvargs, RTE_DEVARGS_KEY_CLASS, - sfc_efx_kvarg_dev_class_handler, &dev_class); + rte_kvargs_process_opt(kvargs, RTE_DEVARGS_KEY_CLASS, + sfc_efx_kvarg_dev_class_handler, &dev_class);LGTM from code point of view, but I'm not sure that I understand the idea behind handling NULL value in
sfc_efx_kvarg_dev_class_handler().Cc VijayQuoted 15 lines
drivers/net/sfc/sfc_kvargs.c sfc_kvargs_process(struct sfc_adapter *sa, const char *key_match, · line 73
Quoted 11 lines
drivers/common/sfc_efx/sfc_efx.c +0
-0} rte_kvargs_free(kvargs);drivers/net/sfc/sfc_kvargs.c +1
-0@@ -70,7 +70,7 @@ sfc_kvargs_process(struct sfc_adapter *sa, const char *key_match, if (sa->kvargs == NULL) return 0; - return -rte_kvargs_process(sa->kvargs, key_match, handler, opaque_arg); + return -rte_kvargs_process_opt(sa->kvargs, key_match, handler, opaque_arg);It looks wrong to me since many handlers do not handle NULL string gracefully. As I understand some handlers where fixed to avoid crash and correct fix would be to keep
rte_kvargs_process()and remove
unnecessary checks for NULL string value.
Quoted 1 line
The scope is large, I suggest creates a new patchset later which remove unnecessary checks for NULL string value.
I just want to highlight that it will not make this patch correct. So,
Nack
Quoted 6 lines
Quoted 6 lines
drivers/net/sfc/sfc_kvargs.c sfc_kvargs_process(struct sfc_adapter *sa, const char *key_match, · line 75
Quoted 4 lines
drivers/net/sfc/sfc_kvargs.c +0
-0} int.
PATCH v5 3/5 net/tap: use new API to parse kvargs
In reply to Chengwen FengSome kvargs could be key=value or only-key, it should use rte_kvargs_process_opt() instead of rte_kvargs_process() to handle these kvargs.
--- drivers/net/tap/rte_eth_tap.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/net/tap/rte_eth_tap.c +5 -5
@@ -2292,7 +2292,7 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev) kvlist =rte_kvargs_parse (params, valid_arguments);if (kvlist) {if (rte_kvargs_count (kvlist,ETH_TAP_IFACE_ARG ) ==1 ) { - ret =rte_kvargs_process (kvlist, + ret =rte_kvargs_process_opt (kvlist,ETH_TAP_IFACE_ARG , &set_interface_name, tun_name);
@@ -2496,10 +2496,10 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev) kvlist =rte_kvargs_parse (params, valid_arguments);if (kvlist) {if (rte_kvargs_count (kvlist,ETH_TAP_IFACE_ARG ) ==1 ) { - ret =rte_kvargs_process (kvlist, -ETH_TAP_IFACE_ARG , - &set_interface_name, - tap_name); + ret =rte_kvargs_process_opt (kvlist, +ETH_TAP_IFACE_ARG , + &set_interface_name, + tap_name);if (ret ==-1 ) goto leave; }
Signature · 1 line
2.17.1
PATCH v5 4/5 common/nfp: use new API to parse kvargs
In reply to Chengwen FengThe nfp_parse_class_options() function could handle both key=value and only-key, so it should use rte_kvargs_process_opt() instead of rte_kvargs_process() to parse.
--- drivers/common/nfp/nfp_common_pci.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/common/nfp/nfp_common_pci.c +2 -4
@@ -170,10 +170,8 @@ nfp_parse_class_options(const struct rte_devargs *devargs)if (kvargs ==NULL )return dev_class; -if (rte_kvargs_count (kvargs,RTE_DEVARGS_KEY_CLASS ) !=0 ) { -rte_kvargs_process (kvargs,RTE_DEVARGS_KEY_CLASS , - nfp_kvarg_dev_class_handler, &dev_class); - } +rte_kvargs_process_opt (kvargs,RTE_DEVARGS_KEY_CLASS , + nfp_kvarg_dev_class_handler, &dev_class);rte_kvargs_free (kvargs);
Signature · 1 line
2.17.1
PATCH v5 5/5 net/mvneta: fix possible out-of-bounds write
In reply to Chengwen FengThe mvneta_ifnames_get() function will save 'iface' value to ifnames, it will out-of-bounds write if passed many iface pairs (e.g. 'iface=xxx,iface=xxx,...').
--- drivers/net/mvneta/mvneta_ethdev.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/mvneta/mvneta_ethdev.c +3 -0
@@ -91,6 +91,9 @@ mvneta_ifnames_get(const char *key __rte_unused, const char *value, {struct mvneta_ifnames *ifnames = extra_args; +if (ifnames->idx >=NETA_NUM_ETH_PPIO ) +return -EINVAL ; + ifnames->names[ifnames->idx++] = value;return 0 ;
Signature · 1 line
2.17.1
Re: [PATCH v5 5/5] net/mvneta: fix possible out-of-bounds write
Quoted 27 lines · Chengwen Feng
The
mvneta_ifnames_get()function will save 'iface' value to ifnames, it will out-of-bounds write if passed many iface pairs (e.g. 'iface=xxx,iface=xxx,...').Fixes 4ccc8d770d3b ("net/mvneta: add PMD skeleton")Signed-off-by Chengwen Feng <[email protected]>Acked-by Ferruh Yigit <[email protected]>--- drivers/net/mvneta/mvneta_ethdev.c | 3 +++ 1 file changed, 3 insertions(+)drivers/net/mvneta/mvneta_ethdev.c +3
-0@@ -91,6 +91,9 @@ mvneta_ifnames_get(const char *key __rte_unused, const char *value, {struct mvneta_ifnames *ifnames = extra_args; +if (ifnames->idx >=NETA_NUM_ETH_PPIO ) +return -EINVAL ; + ifnames->names[ifnames->idx++] = value;return 0 ;
Quoted 13 lines · On Mon, 6 Nov 2023 07:31:19 +0000 Chengwen Feng <[email protected]> wrote:
The
rte_kvargs_process()was used to parse key-value (e.g. socket_id=0), it also supports to parse only-key (e.g.socket_id). But many drivers's callback can only handle key-value, it will segment fault if handles only-key. so the patchset [1] was introduced.Because the patchset [1] modified too much drivers, therefore:
1) A new APIrte_kvargs_process_opt()was introduced, it inherits the function ofrte_kvargs_process()which could parse both key-value and only-key.
2) Constraint therte_kvargs_process()can only parse key-value.This patchset also include one bugfix for kvargs of mvneta driver.
Quoted 8 lines
[1] https://patches.dpdk.org/project/dpdk/patch/[email protected]/
Chengwen Feng (5):
kvargs: add one new process API
net/sfc: use new API to parse kvargs
net/tap: use new API to parse kvargs
common/nfp: use new API to parse kvargs
net/mvneta: fix possible out-of-bounds write
Not sure why the patchset never got more attention.
Yes it is a real bug, and this looks like a reasonable way to address it.
It does need to be rebased to current 24.11 tree to have a chance, and would be good to add more documentation to the API and remove cases in drivers that have unnecessary NULL checks after this. But those changes can be follow ups.
Also the mvneta patch probably should be sent as separate it does not depend on anything here.
Bottom line resubmit it, and I will ack the new version.
Hi Stephen,
Quoted 28 lines · Stephen Hemminger
Quoted 13 lines · On Mon, 6 Nov 2023 07:31:19 +0000 Chengwen Feng <[email protected]> wrote:
The
rte_kvargs_process()was used to parse key-value (e.g. socket_id=0), it also supports to parse only-key (e.g.socket_id). But many drivers's callback can only handle key-value, it will segment fault if handles only-key. so the patchset [1] was introduced.Because the patchset [1] modified too much drivers, therefore:
1) A new APIrte_kvargs_process_opt()was introduced, it inherits the function ofrte_kvargs_process()which could parse both key-value and only-key.
2) Constraint therte_kvargs_process()can only parse key-value.This patchset also include one bugfix for kvargs of mvneta driver.
Quoted 8 lines
[1] https://patches.dpdk.org/project/dpdk/patch/[email protected]/
Chengwen Feng (5):
kvargs: add one new process API
net/sfc: use new API to parse kvargs
net/tap: use new API to parse kvargs
common/nfp: use new API to parse kvargs
net/mvneta: fix possible out-of-bounds writeNot sure why the patchset never got more attention.
Yes it is a real bug, and this looks like a reasonable way to address it.
Quoted 7 lines
It does need to be rebased to current 24.11 tree to have a chance, and would be good to add more documentation to the API and remove cases in drivers that have unnecessary NULL checks after this. But those changes can be follow ups.
Also the mvneta patch probably should be sent as separate it does not depend on anything here.
Done
Quoted 2 lines
Bottom line resubmit it, and I will ack the new version.
Already sent v6, please take a review
Thanks
v6 cover fix segment fault when parse args
In reply to Chengwen FengThe rte_kvargs_process() was used to parse key-value (e.g. socket_id=0), it also supports to parse only-key (e.g. socket_id). But many drivers's callback can only handle key-value, it will segment fault if handles only-key. so the patchset [1] was introduced.
Because the patchset [1] modified too much drivers, therefore:
1) A new API rte_kvargs_process_opt() was introduced, it inherits the function of rte_kvargs_process() which could parse both key-value and only-key.
2) Constraint the rte_kvargs_process() can only parse key-value.
[1] https://patches.dpdk.org/project/dpdk/patch/[email protected]/
Chengwen Feng (4):
kvargs: add one new process API
net/sfc: use new API to parse kvargs
net/tap: use new API to parse kvargs
common/nfp: use new API to parse kvargs
---
v6: rebase to 24.11, refine net/sfc modification, make mvneta as an
independent commit which address Stephen's comment.
v5: remove redundant of rte_kvargs_count of 4/5 commit which address
Stephen's comment.
v4: refine API's define and impl which address Ferruh's comments.
add common/nfp change commit.
v3: introduce new API instead of modify too many drivers which address
Ferruh's comments.
doc/guides/rel_notes/release_24_11.rst | 13 ++++++++ drivers/common/nfp/nfp_common_pci.c | 6 ++-- drivers/common/sfc_efx/sfc_efx.c | 3 -- drivers/net/sfc/sfc_ethdev.c | 12 +++---- drivers/net/sfc/sfc_kvargs.c | 12 ++++++- drivers/net/sfc/sfc_kvargs.h | 2 ++ drivers/net/tap/rte_eth_tap.c | 10 +++--- lib/kvargs/rte_kvargs.c | 43 ++++++++++++++++++++------ lib/kvargs/rte_kvargs.h | 39 +++++++++++++++++++++-- lib/kvargs/version.map | 7 +++++ 10 files changed, 116 insertions(+), 31 deletions(-)
Signature · 1 line
2.17.1
PATCH v6 1/4 kvargs: add one new process API
The rte_kvargs_process() was used to handle key=value (e.g. socket_id=0), it also supports to handle only-key (e.g. socket_id). But many drivers's callback can only handle key=value, it will segment fault if handles only-key. so the patchset [1] was introduced.
Because the patchset [1] modified too much drivers, therefore:
1) A new API rte_kvargs_process_opt() was introduced, it inherits the function of rte_kvargs_process() which could handle both key=value and only-key cases.
2) Constraint the rte_kvargs_process() can only handle key=value cases, it will return -1 when handle only-key case (that is the matched key's value is NULL).
This patch also make sure the rte_kvargs_process_opt() and rte_kvargs_process() API both return -1 when the kvlist parameter is NULL.
[1] https://patches.dpdk.org/project/dpdk/patch/[email protected]/
--- doc/guides/rel_notes/release_24_11.rst | 13 ++++++++ lib/kvargs/rte_kvargs.c | 43 ++++++++++++++++++++------ lib/kvargs/rte_kvargs.h | 39 +++++++++++++++++++++-- lib/kvargs/version.map | 7 +++++ 4 files changed, 90 insertions(+), 12 deletions(-)
doc/guides/rel_notes/release_24_11.rst +13 -0
@@ -96,6 +96,19 @@ API Changes Also, make sure to start the actual text at the margin. ======================================================= +* **Updated kvargs process API.** + + * Introduced rte_kvargs_process_opt() API, which inherits the function + of rte_kvargs_process() and could handle both key=value and only-key + cases. + + * Constraint rte_kvargs_process() API can only handle key=value cases, + it will return -1 when handle only-key case (that is the matched key's + value is NULL). + + * Make sure rte_kvargs_process_opt() and rte_kvargs_process() API both + return -1 when the kvlist parameter is NULL. + ABI Changes -----------
lib/kvargs/rte_kvargs.c +34 -9
65 lines not on this page · raw message
lib/kvargs/rte_kvargs.h +36 -3
@@ -6,6 +6,8 @@#ifndef _RTE_KVARGS_H_#define _RTE_KVARGS_H_ +#include <rte_compat.h> +/** * @file * RTE Argument parsing
@@ -166,14 +168,17 @@ const char *rte_kvargs_get_with_value(const struct rte_kvargs *kvlist, const char *key, const char *value);/** -* Call a handler function for each key/value matching the key +* Call a handler function for each key=value matching the key * -* For each key/value association that matches the given key, calls the +* For each key=value association that matches the given key, calls the * handler function with the for a given arg_name passing the value on the * dictionary for that key and a given extra argument. * +* @note Compared to @see rte_kvargs_process_opt, this API will return -1 +* when handle only-key case (that is the matched key's value is NULL). +* * @param kvlist -* The rte_kvargs structure. No error if NULL. +* The rte_kvargs structure. * @param key_match * The key on which the handler should be called, or NULL to process handler * on all associations
@@ -189,6 +194,34 @@ const char *rte_kvargs_get_with_value(const struct rte_kvargs *kvlist,int rte_kvargs_process (const struct rte_kvargs *kvlist,const char *key_match,arg_handler_t handler,void *opaque_arg); +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Call a handler function for each key=value or only-key matching the key +* +* For each key=value or only-key association that matches the given key, calls +* the handler function with the for a given arg_name passing the value on the +* dictionary for that key and a given extra argument. +* +* @param kvlist +* The rte_kvargs structure. +* @param key_match +* The key on which the handler should be called, or NULL to process handler +* on all associations +* @param handler +* The function to call for each matching key +* @param opaque_arg +* A pointer passed unchanged to the handler +* +* @return +* - 0 on success +* - Negative on error +*/ +__rte_experimental +int rte_kvargs_process_opt(const struct rte_kvargs *kvlist, +const char *key_match,arg_handler_t handler,void *opaque_arg); +/** * Count the number of associations matching the given key *
lib/kvargs/version.map +7 -0
@@ -11,3 +11,10 @@ DPDK_25 { local: *; }; + +EXPERIMENTAL { + global: + + # added in 24.11 + rte_kvargs_process_opt; +};
Signature · 1 line
2.17.1
Re: [PATCH v6 1/4] kvargs: add one new process API
Quoted 13 lines · Chengwen Feng
The
rte_kvargs_process()was used to handle key=value (e.g. socket_id=0), it also supports to handle only-key (e.g.socket_id). But many drivers's callback can only handle key=value, it will segment fault if handles only-key. so the patchset [1] was introduced.Because the patchset [1] modified too much drivers, therefore:
1) A new APIrte_kvargs_process_opt()was introduced, it inherits the function ofrte_kvargs_process()which could handle both key=value and only-key cases.
2) Constraint therte_kvargs_process()can only handle key=value cases, it will return -1 when handle only-key case (that is the matched key's value is NULL).
Quoted 9 lines
This patch also make sure the
rte_kvargs_process_opt()andrte_kvargs_process()API both return -1 when the kvlist parameter is NULL.[1] https://patches.dpdk.org/project/dpdk/patch/20230320092110.37295-1-
[email protected]/Signed-off-by Chengwen Feng <[email protected]>
PATCH v6 2/4 net/sfc: use new API to parse kvargs
In reply to Chengwen FengAdd sfc_kvargs_process_opt() function to handle only-key case, and remove redundancy NULL judgement of value because the rte_kvargs_process (which invoked in sfc_kvargs_process()) will handle it.
--- drivers/common/sfc_efx/sfc_efx.c | 3 --- drivers/net/sfc/sfc_ethdev.c | 12 ++++++------ drivers/net/sfc/sfc_kvargs.c | 12 +++++++++++- drivers/net/sfc/sfc_kvargs.h | 2 ++ 4 files changed, 19 insertions(+), 10 deletions(-)
drivers/common/sfc_efx/sfc_efx.c +0 -3
@@ -23,9 +23,6 @@ sfc_efx_kvarg_dev_class_handler(__rte_unused const char *key, {enum sfc_efx_dev_class *dev_class = opaque; -if (class_str ==NULL ) -return *dev_class; -if (strcmp (class_str,"vdpa" ) ==0 ) { *dev_class =SFC_EFX_DEV_CLASS_VDPA ; }else if (strcmp (class_str,"net" ) ==0 ) {
drivers/net/sfc/sfc_ethdev.c +6 -6
@@ -2835,8 +2835,8 @@ sfc_eth_dev_set_ops(struct rte_eth_dev *dev)if (encp->enc_rx_es_super_buffer_supported) avail_caps |=SFC_DP_HW_FW_CAP_RX_ES_SUPER_BUFFER ; - rc =sfc_kvargs_process (sa,SFC_KVARG_RX_DATAPATH , - sfc_kvarg_string_handler, &rx_name); + rc =sfc_kvargs_process_opt (sa,SFC_KVARG_RX_DATAPATH , + sfc_kvarg_string_handler, &rx_name);if (rc !=0 ) goto fail_kvarg_rx_datapath;
@@ -2878,8 +2878,8 @@ sfc_eth_dev_set_ops(struct rte_eth_dev *dev)sfc_notice (sa,"use %s Rx datapath" , sas->dp_rx_name); - rc =sfc_kvargs_process (sa,SFC_KVARG_TX_DATAPATH , - sfc_kvarg_string_handler, &tx_name); + rc =sfc_kvargs_process_opt (sa,SFC_KVARG_TX_DATAPATH , + sfc_kvarg_string_handler, &tx_name);if (rc !=0 ) goto fail_kvarg_tx_datapath;
@@ -3073,8 +3073,8 @@ sfc_parse_switch_mode(struct sfc_adapter *sa, bool has_representors)sfc_log_init (sa,"entry" ); - rc =sfc_kvargs_process (sa,SFC_KVARG_SWITCH_MODE , - sfc_kvarg_string_handler, &switch_mode); + rc =sfc_kvargs_process_opt (sa,SFC_KVARG_SWITCH_MODE , + sfc_kvarg_string_handler, &switch_mode);if (rc !=0 ) goto fail_kvargs;
drivers/net/sfc/sfc_kvargs.c +11 -1
@@ -73,6 +73,16 @@ sfc_kvargs_process(struct sfc_adapter *sa, const char *key_match,return -rte_kvargs_process (sa->kvargs, key_match, handler, opaque_arg); } +int +sfc_kvargs_process_opt (struct sfc_adapter *sa,const char *key_match, +arg_handler_t handler,void *opaque_arg) +{ +if (sa->kvargs ==NULL ) +return 0 ; + +return -rte_kvargs_process_opt (sa->kvargs, key_match, handler, opaque_arg); +} +int sfc_kvarg_bool_handler(__rte_unused const char *key,const char *value_str,void *opaque)
@@ -104,7 +114,7 @@ sfc_kvarg_long_handler(__rte_unused const char *key,long value;char *endptr; -if (!value_str || !opaque) +if (!opaque)return -EINVAL ; value =strtol (value_str, &endptr,0 );
drivers/net/sfc/sfc_kvargs.h +2 -0
@@ -83,6 +83,8 @@ void sfc_kvargs_cleanup(struct sfc_adapter *sa);int sfc_kvargs_process (struct sfc_adapter *sa,const char *key_match,arg_handler_t handler,void *opaque_arg); +int sfc_kvargs_process_opt (struct sfc_adapter *sa,const char *key_match, +arg_handler_t handler,void *opaque_arg);int sfc_kvarg_bool_handler (const char *key,const char *value_str,void *opaque);
Signature · 1 line
2.17.1
PATCH v6 3/4 net/tap: use new API to parse kvargs
In reply to Chengwen FengSome kvargs could be key=value or only-key, it should use rte_kvargs_process_opt() instead of rte_kvargs_process() to handle these kvargs.
--- drivers/net/tap/rte_eth_tap.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/net/tap/rte_eth_tap.c +5 -5
@@ -2291,7 +2291,7 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev) kvlist =rte_kvargs_parse (params, valid_arguments);if (kvlist) {if (rte_kvargs_count (kvlist,ETH_TAP_IFACE_ARG ) ==1 ) { - ret =rte_kvargs_process (kvlist, + ret =rte_kvargs_process_opt (kvlist,ETH_TAP_IFACE_ARG , &set_interface_name, tun_name);
@@ -2487,10 +2487,10 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev) kvlist =rte_kvargs_parse (params, valid_arguments);if (kvlist) {if (rte_kvargs_count (kvlist,ETH_TAP_IFACE_ARG ) ==1 ) { - ret =rte_kvargs_process (kvlist, -ETH_TAP_IFACE_ARG , - &set_interface_name, - tap_name); + ret =rte_kvargs_process_opt (kvlist, +ETH_TAP_IFACE_ARG , + &set_interface_name, + tap_name);if (ret ==-1 ) goto leave; }
Signature · 1 line
2.17.1
PATCH v6 4/4 common/nfp: use new API to parse kvargs
In reply to Chengwen FengThe nfp_parse_class_options() function could handle both key=value and only-key, so it should use rte_kvargs_process_opt() instead of rte_kvargs_process() to parse.
--- drivers/common/nfp/nfp_common_pci.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/common/nfp/nfp_common_pci.c +2 -4
@@ -170,10 +170,8 @@ nfp_parse_class_options(const struct rte_devargs *devargs)if (kvargs ==NULL )return dev_class; -if (rte_kvargs_count (kvargs,RTE_DEVARGS_KEY_CLASS ) !=0 ) { -rte_kvargs_process (kvargs,RTE_DEVARGS_KEY_CLASS , - nfp_kvarg_dev_class_handler, &dev_class); - } +rte_kvargs_process_opt (kvargs,RTE_DEVARGS_KEY_CLASS , + nfp_kvarg_dev_class_handler, &dev_class);rte_kvargs_free (kvargs);
Signature · 1 line
2.17.1
RE: [PATCH v6 4/4] common/nfp: use new API to parse kvargs
Quoted 39 lines
-----Original Message-----
From: Chengwen Feng <[email protected]>
Sent: Wednesday, October 9, 2024 12:51 PM
To: [email protected]; [email protected]; Chaoyong He <[email protected]>
Cc: [email protected]; [email protected]
Subject: [PATCH v6 4/4] common/nfp: use new API to parse kvargsThe
nfp_parse_class_options()function could handle both key=value and only-key, so it should userte_kvargs_process_opt()instead ofrte_kvargs_process()to parse.Signed-off-by Chengwen Feng <[email protected]>--- drivers/common/nfp/nfp_common_pci.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)drivers/common/nfp/nfp_common_pci.c +2
-5@@ -170,10 +170,8 @@ nfp_parse_class_options(const struct rte_devargs *devargs)if (kvargs ==NULL )return dev_class; -if (rte_kvargs_count (kvargs,RTE_DEVARGS_KEY_CLASS ) !=0 ) { -rte_kvargs_process (kvargs,RTE_DEVARGS_KEY_CLASS , - nfp_kvarg_dev_class_handler, &dev_class); - } +rte_kvargs_process_opt (kvargs,RTE_DEVARGS_KEY_CLASS , + nfp_kvarg_dev_class_handler, &dev_class);rte_kvargs_free (kvargs); --
Quoted 1 line
2.17.1
Looks good to me.
Quoted 12 lines · Chengwen Feng
The
rte_kvargs_process()was used to parse key-value (e.g. socket_id=0), it also supports to parse only-key (e.g.socket_id). But many drivers's callback can only handle key-value, it will segment fault if handles only-key. so the patchset [1] was introduced.Because the patchset [1] modified too much drivers, therefore:
1) A new APIrte_kvargs_process_opt()was introduced, it inherits the function ofrte_kvargs_process()which could parse both key-value and only-key.
2) Constraint therte_kvargs_process()can only parse key-value.
Quoted 7 lines
[1] https://patches.dpdk.org/project/dpdk/patch/[email protected]/
Chengwen Feng (4):
kvargs: add one new process API
net/sfc: use new API to parse kvargs
net/tap: use new API to parse kvargs
common/nfp: use new API to parse kvargs
I see Stephen wanted to have a look on the series, but rc1 is close, and I decided to merge it with following comments.
I marked the new API as stable from the go.
The reason being that it provides the "legacy" behavior of previous rte_kvargs_process function, and as such, some users may have been relying on it.
If you think this is wrong, please submit a followup patch.
I was surprised of the change in behavior wrt to a NULL kvlist input parameter mixed in the change.
But I left it as is. Idem, a followup patch may be sent.
Series applied, thanks for fixing this old issue Chengwen.
Signature · 1 line
David Marchand
Quoted 21 lines · David Marchand
Quoted 12 lines · Chengwen Feng
The
rte_kvargs_process()was used to parse key-value (e.g. socket_id=0), it also supports to parse only-key (e.g.socket_id). But many drivers's callback can only handle key-value, it will segment fault if handles only-key. so the patchset [1] was introduced.Because the patchset [1] modified too much drivers, therefore:
1) A new APIrte_kvargs_process_opt()was introduced, it inherits the function ofrte_kvargs_process()which could parse both key-value and only-key.
2) Constraint therte_kvargs_process()can only parse key-value.Quoted 7 lines
[1] https://patches.dpdk.org/project/dpdk/patch/[email protected]/
Chengwen Feng (4):
kvargs: add one new process API
net/sfc: use new API to parse kvargs
net/tap: use new API to parse kvargs
common/nfp: use new API to parse kvargs
Quoted 8 lines
I see Stephen wanted to have a look on the series, but rc1 is close, and I decided to merge it with following comments.
I marked the new API as stable from the go.
The reason being that it provides the "legacy" behavior of previousrte_kvargs_processfunction, and as such, some users may have been relying on it.
If you think this is wrong, please submit a followup patch.
I just reviewed the merged commit, it's OK.
Quoted 7 lines
I was surprised of the change in behavior wrt to a NULL kvlist input parameter mixed in the change.
But I left it as is. Idem, a followup patch may be sent.Series applied, thanks for fixing this old issue Chengwen.
Thanks David