net/kni: initialize rte_kni_conf to 0 before using it
PATCH 1/1 net/kni: initialize rte_kni_conf to 0 before using it
When kni driver calls eth_kni_start to start device, some fields such as min_mtu and max_mtu of rte_kni_conf are not initialized. It will cause kni_ioctl_create create a kni netdevice with a random min_mtu and max_mtu value. This is unexpected and in some time we could not change the kni device mtu with ip link command.
--- drivers/net/kni/rte_eth_kni.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/kni/rte_eth_kni.c +1 -0
@@ -128,6 +128,7 @@ eth_kni_start(struct rte_eth_dev *dev)const char *name = dev->device->name +4 ;/* remove net_ */ mb_pool = internals->rx_queues[0 ].mb_pool; +memset (&conf,0 ,sizeof (conf));strlcpy (conf.name, name,RTE_KNI_NAMESIZE ); conf.force_bind =0 ; conf.group_id = port_id;
Signature · 1 line
2.27.0
Quoted 6 lines · Harold Huang
When kni driver calls
eth_kni_startto start device, some fields such asmin_mtuandmax_mtuofrte_kni_confare not initialized. It will causekni_ioctl_createcreate a kni netdevice with a randommin_mtuandmax_mtuvalue. This is unexpected and in some time we could not change the kni device mtu with ip link command.
Agree on the problem and the solution, thanks for the fix.
Quoted 11 lines
Fixes ff1e35fb5f8 ("kni: calculate MTU from mbuf size")Signed-off-by Harold Huang <[email protected]>--- drivers/net/kni/rte_eth_kni.c | 1 + 1 file changed, 1 insertion(+)drivers/net/kni/rte_eth_kni.c +0
-0
drivers/net/kni/rte_eth_kni.c eth_kni_start(struct rte_eth_dev *dev) · line 131
Quoted 4 lines
drivers/net/kni/rte_eth_kni.c +1
-0@@ -128,6 +128,7 @@ eth_kni_start(struct rte_eth_dev *dev)const char *name = dev->device->name +4 ;/* remove net_ */ mb_pool = internals->rx_queues[0 ].mb_pool; +memset (&conf,0 ,sizeof (conf));
Can you prefer initialize to zero, instead of 'memset', I think it is more clear that way:
- struct rte_kni_conf conf;
+ struct rte_kni_conf conf = { 0 };
Quoted 3 lines
drivers/net/kni/rte_eth_kni.c +0
-0strlcpy (conf.name, name,RTE_KNI_NAMESIZE ); conf.force_bind =0 ; conf.group_id = port_id;
Quoted 24 lines · Ferruh Yigit
Quoted 6 lines · Harold Huang
When kni driver calls
eth_kni_startto start device, some fields such asmin_mtuandmax_mtuofrte_kni_confare not initialized. It will causekni_ioctl_createcreate a kni netdevice with a randommin_mtuandmax_mtuvalue. This is unexpected and in some time we could not change the kni device mtu with ip link command.Agree on the problem and the solution, thanks for the fix.
Quoted 13 lines
Fixes ff1e35fb5f8 ("kni: calculate MTU from mbuf size")Signed-off-by Harold Huang <[email protected]>--- drivers/net/kni/rte_eth_kni.c | 1 + 1 file changed, 1 insertion(+)drivers/net/kni/rte_eth_kni.c +0
-0@@ -128,6 +128,7 @@ eth_kni_start(struct rte_eth_dev *dev)const char *name = dev->device->name +4 ;/* remove net_ */
Quoted 5 lines
drivers/net/kni/rte_eth_kni.c eth_kni_start(struct rte_eth_dev *dev) · line 131
Quoted 2 lines
drivers/net/kni/rte_eth_kni.c +1
-0mb_pool = internals->rx_queues[0 ].mb_pool; +memset (&conf,0 ,sizeof (conf));Can you prefer initialize to zero, instead of 'memset', I think it is more clear that way:
Thanks. Sounds good, fix it.
Quoted 8 lines
- struct
rte_kni_confconf;
+ structrte_kni_confconf = { 0 };Quoted 3 lines
drivers/net/kni/rte_eth_kni.c +0
-0strlcpy (conf.name, name,RTE_KNI_NAMESIZE ); conf.force_bind =0 ; conf.group_id = port_id;
PATCH 1/1 net/kni: initialize rte_kni_conf to 0 before using it
In reply to Harold HuangWhen kni driver calls eth_kni_start to start device, some fields such as min_mtu and max_mtu of rte_kni_conf are not initialized. It will cause kni_ioctl_create create a kni netdevice with a random min_mtu and max_mtu value. This is unexpected and sometimes we could not change the kni device mtu with ip link command.
--- drivers/net/kni/rte_eth_kni.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/kni/rte_eth_kni.c +1 -1
@@ -124,7 +124,7 @@ eth_kni_start(struct rte_eth_dev *dev)struct pmd_internals *internals = dev->data->dev_private;uint16_t port_id = dev->data->port_id;struct rte_mempool *mb_pool; -struct rte_kni_conf conf; +struct rte_kni_conf conf = {0 };const char *name = dev->device->name +4 ;/* remove net_ */ mb_pool = internals->rx_queues[0 ].mb_pool;
Signature · 1 line
2.27.0
Quoted 9 lines · Harold Huang
When kni driver calls
eth_kni_startto start device, some fields such asmin_mtuandmax_mtuofrte_kni_confare not initialized. It will causekni_ioctl_createcreate a kni netdevice with a randommin_mtuandmax_mtuvalue. This is unexpected and sometimes we could not change the kni device mtu with ip link command.Fixes ff1e35fb5f83 ("kni: calculate MTU from mbuf size")Signed-off-by Harold Huang <[email protected]>
Applied to dpdk-next-net/main, thanks.
Quoted 18 lines · Harold Huang
When kni driver calls
eth_kni_startto start device, some fields such asmin_mtuandmax_mtuofrte_kni_confare not initialized. It will causekni_ioctl_createcreate a kni netdevice with a randommin_mtuandmax_mtuvalue. This is unexpected and sometimes we could not change the kni device mtu with ip link command.Fixes ff1e35fb5f83 ("kni: calculate MTU from mbuf size")Signed-off-by Harold Huang <[email protected]>--- drivers/net/kni/rte_eth_kni.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/kni/rte_eth_kni.c +0
-0
drivers/net/kni/rte_eth_kni.c eth_kni_start(struct rte_eth_dev *dev) · line 127
Quoted 5 lines
drivers/net/kni/rte_eth_kni.c +1
-1@@ -124,7 +124,7 @@ eth_kni_start(struct rte_eth_dev *dev)struct pmd_internals *internals = dev->data->dev_private;uint16_t port_id = dev->data->port_id;struct rte_mempool *mb_pool; -struct rte_kni_conf conf; +struct rte_kni_conf conf = {0 };
This is causing build error [1], updated in next-net [2] to fix.
Normally '{ 0 }' should be universal zero-initializer, but I guess it fails because of old compiler version:
gcc 4.8.5 "cc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)"
[1]
FAILED: drivers/a715181@@tmp_rte_net_kni@sta/net_kni_rte_eth_kni.c.o ../drivers/net/kni/rte_eth_kni.c: In function 'eth_kni_start':../drivers/net/kni/rte_eth_kni.c:127:9:
error: missing braces around initializer [-Werror=missing-braces]
struct rte_kni_conf conf = { 0 };
^[2]
struct rte_kni_conf conf = {{0}};
Quoted 3 lines
drivers/net/kni/rte_eth_kni.c +0
-0const char *name = dev->device->name +4 ;/* remove net_ */ mb_pool = internals->rx_queues[0 ].mb_pool;