kni: rework rte_kni_update_link using ioctl
PATCH 1/1 kni: rework rte_kni_update_link using ioctl
Current implementation doesn't allow us to update KNI carrier if the interface is not yet UP in kernel. It means that we can't use it in the same thread which is processing rte_kni_ops.config_network_if, which is very convenient, because it allows us to have correct carrier status of the interface right after we enabled it and we don't have to use any additional thread to track link status.
--- kernel/linux/kni/compat.h | 4 -- kernel/linux/kni/kni_misc.c | 47 +++++++++++++++++++ kernel/linux/kni/kni_net.c | 15 ------ .../linux/eal/include/rte_kni_common.h | 6 +++ lib/librte_kni/rte_kni.c | 28 +++-------- lib/librte_kni/rte_kni.h | 3 +- 6 files changed, 60 insertions(+), 43 deletions(-)
kernel/linux/kni/compat.h +0 -4
@@ -61,10 +61,6 @@#define kni_sock_map_fd (s) sock_map_fd(s, 0)#endif -#if LINUX_VERSION_CODE >=KERNEL_VERSION (3 ,9 ,0 ) -#define HAVE_CHANGE_CARRIER_CB -#endif -#if LINUX_VERSION_CODE <KERNEL_VERSION (3 ,14 ,0 )#define ether_addr_copy (dst, src) memcpy(dst, src, ETH_ALEN)#endif
kernel/linux/kni/kni_misc.c +47 -0
59 lines not on this page · raw message
kernel/linux/kni/kni_net.c +0 -15
@@ -706,18 +706,6 @@ kni_net_set_mac(struct net_device *netdev, void *p)return (ret ==0 ? req.result : ret); } -#ifdef HAVE_CHANGE_CARRIER_CB -static int -kni_net_change_carrier (struct net_device *dev,bool new_carrier) -{ -if (new_carrier) -netif_carrier_on (dev); -else -netif_carrier_off (dev); -return 0 ; -} -#endif -static const struct header_ops kni_net_header_ops = { .create = kni_net_header, .parse = eth_header_parse,
@@ -736,9 +724,6 @@ static const struct net_device_ops kni_net_netdev_ops = { .ndo_change_mtu = kni_net_change_mtu, .ndo_tx_timeout = kni_net_tx_timeout, .ndo_set_mac_address = kni_net_set_mac, -#ifdef HAVE_CHANGE_CARRIER_CB - .ndo_change_carrier = kni_net_change_carrier, -#endif }; static void kni_get_drvinfo(struct net_device *dev,
lib/librte_eal/linux/eal/include/rte_kni_common.h +6 -0
@@ -125,10 +125,16 @@ struct rte_kni_device_info { uint8_t mac_addr[6]; }; +struct rte_kni_link_info { +char name[RTE_KNI_NAMESIZE ]; +unsigned int linkup; +}; +#define KNI_DEVICE "kni"#define RTE_KNI_IOCTL_TEST _IOWR(0, 1, int)#define RTE_KNI_IOCTL_CREATE _IOWR(0, 2, struct rte_kni_device_info)#define RTE_KNI_IOCTL_RELEASE _IOWR(0, 3, struct rte_kni_device_info) +#define RTE_KNI_IOCTL_LINK _IOWR(0, 4, struct rte_kni_link_info)#endif /* _RTE_KNI_COMMON_H_ */
lib/librte_kni/rte_kni.c +6 -22
@@ -738,36 +738,20 @@ rte_kni_update_link(struct rte_kni *kni, unsigned int linkup)const char *new_carrier;int old_linkup;int fd, ret; +struct rte_kni_link_info link_info;if (kni ==NULL )return -1 ; -snprintf (path,sizeof (path),"/sys/devices/virtual/net/%s/carrier" , - kni->name); +snprintf (link_info.name,RTE_KNI_NAMESIZE ,"%s" , kni->name); + link_info.linkup = linkup; - fd =open (path,O_RDWR ); -if (fd ==-1 ) { -RTE_LOG (ERR ,KNI ,"Failed to open file: %s.\n" , path); +if (ioctl (kni_fd,RTE_KNI_IOCTL_LINK , &link_info) <0 ) { +RTE_LOG (ERR ,KNI ,"Fail to update KNI link\n" );return -1 ; } - ret =read (fd, old_carrier,2 ); -if (ret <1 ) { -close (fd); -return -1 ; - } - old_linkup = (old_carrier[0 ] =='1' ); - - new_carrier = linkup ?"1" :"0" ; - ret =write (fd, new_carrier,1 ); -if (ret <1 ) { -RTE_LOG (ERR ,KNI ,"Failed to write file: %s.\n" , path); -close (fd); -return -1 ; - } - -close (fd); -return old_linkup; +return 0 ; }void
lib/librte_kni/rte_kni.h +1 -2
@@ -247,9 +247,8 @@ int rte_kni_unregister_handlers(struct rte_kni *kni);* > 0 for linkup. * * @return +* On success: 0 * On failure: -1 -* Previous link state == linkdown: 0 -* Previous link state == linkup: 1 */ __rte_experimental int
Signature · 1 line
2.23.0
PATCH v2 1/1 kni: rework rte_kni_update_link using ioctl
Current implementation doesn't allow us to update KNI carrier if the interface is not yet UP in kernel. It means that we can't use it in the same thread which is processing rte_kni_ops.config_network_if, which is very convenient, because it allows us to have correct carrier status of the interface right after we enabled it and we don't have to use any additional thread to track link status.
---
v2: fix checkpatch warnings
kernel/linux/kni/compat.h | 4 -- kernel/linux/kni/kni_misc.c | 42 +++++++++++++++++++ kernel/linux/kni/kni_net.c | 15 ------- .../linux/eal/include/rte_kni_common.h | 6 +++ lib/librte_kni/rte_kni.c | 28 +++---------- lib/librte_kni/rte_kni.h | 3 +- 6 files changed, 55 insertions(+), 43 deletions(-)
kernel/linux/kni/compat.h +0 -4
@@ -61,10 +61,6 @@#define kni_sock_map_fd (s) sock_map_fd(s, 0)#endif -#if LINUX_VERSION_CODE >=KERNEL_VERSION (3 ,9 ,0 ) -#define HAVE_CHANGE_CARRIER_CB -#endif -#if LINUX_VERSION_CODE <KERNEL_VERSION (3 ,14 ,0 )#define ether_addr_copy (dst, src) memcpy(dst, src, ETH_ALEN)#endif
kernel/linux/kni/kni_misc.c +42 -0
54 lines not on this page · raw message
kernel/linux/kni/kni_net.c +0 -15
@@ -706,18 +706,6 @@ kni_net_set_mac(struct net_device *netdev, void *p)return (ret ==0 ? req.result : ret); } -#ifdef HAVE_CHANGE_CARRIER_CB -static int -kni_net_change_carrier (struct net_device *dev,bool new_carrier) -{ -if (new_carrier) -netif_carrier_on (dev); -else -netif_carrier_off (dev); -return 0 ; -} -#endif -static const struct header_ops kni_net_header_ops = { .create = kni_net_header, .parse = eth_header_parse,
@@ -736,9 +724,6 @@ static const struct net_device_ops kni_net_netdev_ops = { .ndo_change_mtu = kni_net_change_mtu, .ndo_tx_timeout = kni_net_tx_timeout, .ndo_set_mac_address = kni_net_set_mac, -#ifdef HAVE_CHANGE_CARRIER_CB - .ndo_change_carrier = kni_net_change_carrier, -#endif }; static void kni_get_drvinfo(struct net_device *dev,
lib/librte_eal/linux/eal/include/rte_kni_common.h +6 -0
@@ -125,10 +125,16 @@ struct rte_kni_device_info { uint8_t mac_addr[6]; }; +struct rte_kni_link_info { +char name[RTE_KNI_NAMESIZE ]; +unsigned int linkup; +}; +#define KNI_DEVICE "kni"#define RTE_KNI_IOCTL_TEST _IOWR(0, 1, int)#define RTE_KNI_IOCTL_CREATE _IOWR(0, 2, struct rte_kni_device_info)#define RTE_KNI_IOCTL_RELEASE _IOWR(0, 3, struct rte_kni_device_info) +#define RTE_KNI_IOCTL_LINK _IOWR(0, 4, struct rte_kni_link_info)#endif /* _RTE_KNI_COMMON_H_ */
lib/librte_kni/rte_kni.c +6 -22
@@ -738,36 +738,20 @@ rte_kni_update_link(struct rte_kni *kni, unsigned int linkup)const char *new_carrier;int old_linkup;int fd, ret; +struct rte_kni_link_info link_info;if (kni ==NULL )return -1 ; -snprintf (path,sizeof (path),"/sys/devices/virtual/net/%s/carrier" , - kni->name); +snprintf (link_info.name,RTE_KNI_NAMESIZE ,"%s" , kni->name); + link_info.linkup = linkup; - fd =open (path,O_RDWR ); -if (fd ==-1 ) { -RTE_LOG (ERR ,KNI ,"Failed to open file: %s.\n" , path); +if (ioctl (kni_fd,RTE_KNI_IOCTL_LINK , &link_info) <0 ) { +RTE_LOG (ERR ,KNI ,"Fail to update KNI link\n" );return -1 ; } - ret =read (fd, old_carrier,2 ); -if (ret <1 ) { -close (fd); -return -1 ; - } - old_linkup = (old_carrier[0 ] =='1' ); - - new_carrier = linkup ?"1" :"0" ; - ret =write (fd, new_carrier,1 ); -if (ret <1 ) { -RTE_LOG (ERR ,KNI ,"Failed to write file: %s.\n" , path); -close (fd); -return -1 ; - } - -close (fd); -return old_linkup; +return 0 ; }void
lib/librte_kni/rte_kni.h +1 -2
@@ -247,9 +247,8 @@ int rte_kni_unregister_handlers(struct rte_kni *kni);* > 0 for linkup. * * @return +* On success: 0 * On failure: -1 -* Previous link state == linkdown: 0 -* Previous link state == linkup: 1 */ __rte_experimental int
Signature · 1 line
2.23.0
lib/librte_kni/rte_kni.c rte_kni_update_link(struct rte_kni *kni, unsigned int linkup)
Quoted 153 lines · Igor Ryzhov
Current implementation doesn't allow us to update KNI carrier if the interface is not yet UP in kernel. It means that we can't use it in the same thread which is processing rte_kni_ops.config_network_if, which is very convenient, because it allows us to have correct carrier status of the interface right after we enabled it and we don't have to use any additional thread to track link status.
Signed-off-by Igor Ryzhov <[email protected]>---
v2: fix checkpatch warningskernel/linux/kni/compat.h | 4 -- kernel/linux/kni/kni_misc.c | 42 +++++++++++++++++++ kernel/linux/kni/kni_net.c | 15 ------- .../linux/eal/include/rte_kni_common.h | 6 +++ lib/librte_kni/rte_kni.c | 28 +++---------- lib/librte_kni/rte_kni.h | 3 +- 6 files changed, 55 insertions(+), 43 deletions(-)kernel/linux/kni/compat.h +0
-4@@ -61,10 +61,6 @@#define kni_sock_map_fd (s) sock_map_fd(s, 0)#endif -#if LINUX_VERSION_CODE >=KERNEL_VERSION (3 ,9 ,0 ) -#define HAVE_CHANGE_CARRIER_CB -#endif -#if LINUX_VERSION_CODE <KERNEL_VERSION (3 ,14 ,0 )#define ether_addr_copy (dst, src) memcpy(dst, src, ETH_ALEN)#endif kernel/linux/kni/kni_misc.c +42
-0@@ -462,6 +462,45 @@ kni_ioctl_release(struct net *net, uint32_t ioctl_num,return ret; } +static int +kni_ioctl_link (struct net *net,uint32_t ioctl_num, +unsigned long ioctl_param) +{ +struct kni_net *knet =net_generic (net, kni_net_id); +int ret = -EINVAL ; +struct kni_dev *dev, *n; +struct rte_kni_link_info link_info; +struct net_device *netdev; + +if (_IOC_SIZE (ioctl_num) >sizeof (link_info)) +return -EINVAL ; + +if (copy_from_user (&link_info, (void *)ioctl_param,sizeof (link_info))) +return -EFAULT ; + +if (strlen (link_info.name) ==0 ) +return -EINVAL ; + +down_read (&knet->kni_list_lock); +list_for_each_entry_safe (dev, n, &knet->kni_list_head, list) { +if (strncmp (dev->name, link_info.name,RTE_KNI_NAMESIZE ) !=0 ) +continue ; + + netdev = dev->net_dev; + +if (link_info.linkup) +netif_carrier_on (netdev); +else +netif_carrier_off (netdev); + + ret =0 ; +break ; + } +up_read (&knet->kni_list_lock); + +return ret; +} +static int kni_ioctl (struct inode *inode,uint32_t ioctl_num,unsigned long ioctl_param) {@@ -483,6 +522,9 @@ kni_ioctl(struct inode *inode, uint32_t ioctl_num, unsigned long ioctl_param)case _IOC_NR (RTE_KNI_IOCTL_RELEASE ): ret =kni_ioctl_release (net, ioctl_num, ioctl_param);break ; +case _IOC_NR (RTE_KNI_IOCTL_LINK ): + ret =kni_ioctl_link (net, ioctl_num, ioctl_param); +break ;default :pr_debug ("IOCTL default\n" );break ;kernel/linux/kni/kni_net.c +0
-15@@ -706,18 +706,6 @@ kni_net_set_mac(struct net_device *netdev, void *p)return (ret ==0 ? req.result : ret); } -#ifdef HAVE_CHANGE_CARRIER_CB -static int -kni_net_change_carrier (struct net_device *dev,bool new_carrier) -{ -if (new_carrier) -netif_carrier_on (dev); -else -netif_carrier_off (dev); -return 0 ; -} -#endif -static const struct header_ops kni_net_header_ops = { .create = kni_net_header, .parse = eth_header_parse,@@ -736,9 +724,6 @@ static const struct net_device_ops kni_net_netdev_ops = { .ndo_change_mtu = kni_net_change_mtu, .ndo_tx_timeout = kni_net_tx_timeout, .ndo_set_mac_address = kni_net_set_mac, -#ifdef HAVE_CHANGE_CARRIER_CB - .ndo_change_carrier = kni_net_change_carrier, -#endif }; static void kni_get_drvinfo(struct net_device *dev,lib/librte_eal/linux/eal/include/rte_kni_common.h +6
-0@@ -125,10 +125,16 @@ struct rte_kni_device_info { uint8_t mac_addr[6]; }; +struct rte_kni_link_info { +char name[RTE_KNI_NAMESIZE ]; +unsigned int linkup; +}; +#define KNI_DEVICE "kni"#define RTE_KNI_IOCTL_TEST _IOWR(0, 1, int)#define RTE_KNI_IOCTL_CREATE _IOWR(0, 2, struct rte_kni_device_info)#define RTE_KNI_IOCTL_RELEASE _IOWR(0, 3, struct rte_kni_device_info) +#define RTE_KNI_IOCTL_LINK _IOWR(0, 4, struct rte_kni_link_info)#endif /* _RTE_KNI_COMMON_H_ */ lib/librte_kni/rte_kni.c +0
-0@@ -738,36 +738,20 @@ rte_kni_update_link(struct rte_kni *kni, unsigned int linkup)
You'vbe dropped a lot of code from here, but no the corresponding variables. This will trigger lots of warnings. Please build with all warnings and fix them.
Quoted 57 lines
lib/librte_kni/rte_kni.c +6
-22const char *new_carrier;int old_linkup;int fd, ret; +struct rte_kni_link_info link_info;if (kni ==NULL )return -1 ; -snprintf (path,sizeof (path),"/sys/devices/virtual/net/%s/carrier" , - kni->name); +snprintf (link_info.name,RTE_KNI_NAMESIZE ,"%s" , kni->name); + link_info.linkup = linkup; - fd =open (path,O_RDWR ); -if (fd ==-1 ) { -RTE_LOG (ERR ,KNI ,"Failed to open file: %s.\n" , path); +if (ioctl (kni_fd,RTE_KNI_IOCTL_LINK , &link_info) <0 ) { +RTE_LOG (ERR ,KNI ,"Fail to update KNI link\n" );return -1 ; } - ret =read (fd, old_carrier,2 ); -if (ret <1 ) { -close (fd); -return -1 ; - } - old_linkup = (old_carrier[0 ] =='1' ); - - new_carrier = linkup ?"1" :"0" ; - ret =write (fd, new_carrier,1 ); -if (ret <1 ) { -RTE_LOG (ERR ,KNI ,"Failed to write file: %s.\n" , path); -close (fd); -return -1 ; - } - -close (fd); -return old_linkup; +return 0 ; }void lib/librte_kni/rte_kni.h +1
-2@@ -247,9 +247,8 @@ int rte_kni_unregister_handlers(struct rte_kni *kni);* > 0 for linkup. * * @return +* On success: 0 * On failure: -1 -* Previous link state == linkdown: 0 -* Previous link state == linkup: 1 */ __rte_experimental int
Sure, my bad, sorry. Will send v3.
Quoted 226 lines · Aaron Conole
kernel/linux/kni/kni_misc.c kni_ioctl_release(struct net *net, uint32_t
Quoted 39 lines · Igor Ryzhov
Current implementation doesn't allow us to update KNI carrier if the interface is not yet UP in kernel. It means that we can't use it in the same thread which is processing rte_kni_ops.config_network_if, which is very convenient, because it allows us to have correct carrier status of the interface right after we enabled it and we don't have to use any additional thread to track link status.
Signed-off-by Igor Ryzhov <[email protected]>---
v2: fix checkpatch warningskernel/linux/kni/compat.h | 4 -- kernel/linux/kni/kni_misc.c | 42 +++++++++++++++++++ kernel/linux/kni/kni_net.c | 15 ------- .../linux/eal/include/rte_kni_common.h | 6 +++ lib/librte_kni/rte_kni.c | 28 +++---------- lib/librte_kni/rte_kni.h | 3 +- 6 files changed, 55 insertions(+), 43 deletions(-)kernel/linux/kni/compat.h +0
-4@@ -61,10 +61,6 @@#define kni_sock_map_fd (s) sock_map_fd(s, 0)#endif -#if LINUX_VERSION_CODE >=KERNEL_VERSION (3 ,9 ,0 ) -#define HAVE_CHANGE_CARRIER_CB -#endif -#if LINUX_VERSION_CODE <KERNEL_VERSION (3 ,14 ,0 )#define ether_addr_copy (dst, src) memcpy(dst, src, ETH_ALEN)#endif kernel/linux/kni/kni_misc.c +0
-0@@ -462,6 +462,45 @@ kni_ioctl_release(struct net *net, uint32_t
ioctl_num,Quoted 7 lines
kernel/linux/kni/kni_misc.c +4
-0return ret; } +static int +kni_ioctl_link (struct net *net,uint32_t ioctl_num, +unsigned long ioctl_param) +{kernel/linux/kni/kni_misc.c kni_ioctl_release(struct net *net, uint32_t ioctl_num,
Quoted 10 lines
kernel/linux/kni/kni_misc.c +10
-0+struct kni_net *knet =net_generic (net, kni_net_id); +int ret = -EINVAL ; +struct kni_dev *dev, *n; +struct rte_kni_link_info link_info; +struct net_device *netdev; + +if (_IOC_SIZE (ioctl_num) >sizeof (link_info)) +return -EINVAL ; + + if (copy_from_user(&link_info, (void *)ioctl_param,
sizeof(link_info)))kernel/linux/kni/kni_misc.c kni_ioctl_release(struct net *net, uint32_t ioctl_num,
Quoted 8 lines
kernel/linux/kni/kni_misc.c +8
-0+return -EFAULT ; + +if (strlen (link_info.name) ==0 ) +return -EINVAL ; + +down_read (&knet->kni_list_lock); +list_for_each_entry_safe (dev, n, &knet->kni_list_head, list) { + if (strncmp(dev->name, link_info.name, RTE_KNI_NAMESIZE)!= 0)
Quoted 9 lines
kernel/linux/kni/kni_misc.c +9
-0+continue ; + + netdev = dev->net_dev; + +if (link_info.linkup) +netif_carrier_on (netdev); +else +netif_carrier_off (netdev); +kernel/linux/kni/kni_misc.c kni_ioctl_release(struct net *net, uint32_t ioctl_num,
Quoted 10 lines
kernel/linux/kni/kni_misc.c +8
-0+ ret =0 ; +break ; + } +up_read (&knet->kni_list_lock); + +return ret; +} +static int kni_ioctl(struct inode *inode, uint32_t ioctl_num, unsigned long
ioctl_param)kernel/linux/kni/kni_misc.c kni_ioctl(struct inode *inode, uint32_t ioctl_num,
Quoted 2 lines
kernel/linux/kni/kni_misc.c +0
-0{@@ -483,6 +522,9 @@ kni_ioctl(struct inode *inode, uint32_t ioctl_num,unsigned long
ioctl_param)kernel/linux/kni/kni_net.c static const struct net_device_ops
Quoted 33 lines
kernel/linux/kni/kni_misc.c +3
-0case _IOC_NR (RTE_KNI_IOCTL_RELEASE ): ret =kni_ioctl_release (net, ioctl_num, ioctl_param);break ; +case _IOC_NR (RTE_KNI_IOCTL_LINK ): + ret =kni_ioctl_link (net, ioctl_num, ioctl_param); +break ;default :pr_debug ("IOCTL default\n" );break ;kernel/linux/kni/kni_net.c +0
-12@@ -706,18 +706,6 @@ kni_net_set_mac(struct net_device *netdev, void *p)return (ret ==0 ? req.result : ret); } -#ifdef HAVE_CHANGE_CARRIER_CB -static int -kni_net_change_carrier (struct net_device *dev,bool new_carrier) -{ -if (new_carrier) -netif_carrier_on (dev); -else -netif_carrier_off (dev); -return 0 ; -} -#endif -static const struct header_ops kni_net_header_ops = { .create = kni_net_header, .parse = eth_header_parse,@@ -736,9 +724,6 @@ static const struct net_device_ops
kni_net_netdev_ops= {Review
Quoted 10 lines
kernel/linux/kni/kni_net.c +0
-3.ndo_change_mtu = kni_net_change_mtu, .ndo_tx_timeout = kni_net_tx_timeout, .ndo_set_mac_address = kni_net_set_mac, -#ifdef HAVE_CHANGE_CARRIER_CB - .ndo_change_carrier = kni_net_change_carrier, -#endif }; static void kni_get_drvinfo(struct net_device *dev,(quoted diff) +0
-0
b/lib/librte_eal/linux/eal/include/rte_kni_common.hlib/librte_kni/rte_kni.c rte_kni_update_link(struct rte_kni *kni, unsigned
Quoted 25 lines
index
70992d835..07a10dd93100644lib/librte_eal/linux/eal/include/rte_kni_common.h +6
-0@@ -125,10 +125,16 @@ struct rte_kni_device_info { uint8_t mac_addr[6]; }; +struct rte_kni_link_info { +char name[RTE_KNI_NAMESIZE ]; +unsigned int linkup; +}; +#define KNI_DEVICE "kni"#define RTE_KNI_IOCTL_TEST _IOWR(0, 1, int)#define RTE_KNI_IOCTL_CREATE _IOWR(0, 2, struct rte_kni_device_info)#define RTE_KNI_IOCTL_RELEASE _IOWR(0, 3, struct rte_kni_device_info) +#define RTE_KNI_IOCTL_LINK _IOWR(0, 4, struct rte_kni_link_info)#endif /* _RTE_KNI_COMMON_H_ */ lib/librte_kni/rte_kni.c +0
-0@@ -738,36 +738,20 @@ rte_kni_update_link(struct rte_kni *kni, unsignedint linkup)
You'vbe dropped a lot of code from here, but no the corresponding variables. This will trigger lots of warnings. Please build with all warnings and fix them.
Quoted 57 lines
lib/librte_kni/rte_kni.c +6
-22const char *new_carrier;int old_linkup;int fd, ret; +struct rte_kni_link_info link_info;if (kni ==NULL )return -1 ; -snprintf (path,sizeof (path),"/sys/devices/virtual/net/%s/carrier" , - kni->name); +snprintf (link_info.name,RTE_KNI_NAMESIZE ,"%s" , kni->name); + link_info.linkup = linkup; - fd =open (path,O_RDWR ); -if (fd ==-1 ) { -RTE_LOG (ERR ,KNI ,"Failed to open file: %s.\n" , path); +if (ioctl (kni_fd,RTE_KNI_IOCTL_LINK , &link_info) <0 ) { +RTE_LOG (ERR ,KNI ,"Fail to update KNI link\n" );return -1 ; } - ret =read (fd, old_carrier,2 ); -if (ret <1 ) { -close (fd); -return -1 ; - } - old_linkup = (old_carrier[0 ] =='1' ); - - new_carrier = linkup ?"1" :"0" ; - ret =write (fd, new_carrier,1 ); -if (ret <1 ) { -RTE_LOG (ERR ,KNI ,"Failed to write file: %s.\n" , path); -close (fd); -return -1 ; - } - -close (fd); -return old_linkup; +return 0 ; }void lib/librte_kni/rte_kni.h +1
-2@@ -247,9 +247,8 @@ int rte_kni_unregister_handlers(struct rte_kni *kni);* > 0 for linkup. * * @return +* On success: 0 * On failure: -1 -* Previous link state == linkdown: 0 -* Previous link state == linkup: 1 */ __rte_experimental int
PATCH v3 1/1 kni: rework rte_kni_update_link using ioctl
In reply to Igor RyzhovCurrent implementation doesn't allow us to update KNI carrier if the interface is not yet UP in kernel. It means that we can't use it in the same thread which is processing rte_kni_ops.config_network_if, which is very convenient, because it allows us to have correct carrier status of the interface right after we enabled it and we don't have to use any additional thread to track link status.
---
v3: remove unused variables
v2: fix checkpatch warnings
kernel/linux/kni/compat.h | 4 -- kernel/linux/kni/kni_misc.c | 42 +++++++++++++++++++ kernel/linux/kni/kni_net.c | 15 ------- .../linux/eal/include/rte_kni_common.h | 6 +++ lib/librte_kni/rte_kni.c | 33 +++------------ lib/librte_kni/rte_kni.h | 3 +- 6 files changed, 55 insertions(+), 48 deletions(-)
kernel/linux/kni/compat.h +0 -4
@@ -61,10 +61,6 @@#define kni_sock_map_fd (s) sock_map_fd(s, 0)#endif -#if LINUX_VERSION_CODE >=KERNEL_VERSION (3 ,9 ,0 ) -#define HAVE_CHANGE_CARRIER_CB -#endif -#if LINUX_VERSION_CODE <KERNEL_VERSION (3 ,14 ,0 )#define ether_addr_copy (dst, src) memcpy(dst, src, ETH_ALEN)#endif
kernel/linux/kni/kni_misc.c +42 -0
54 lines not on this page · raw message
kernel/linux/kni/kni_net.c +0 -15
@@ -706,18 +706,6 @@ kni_net_set_mac(struct net_device *netdev, void *p)return (ret ==0 ? req.result : ret); } -#ifdef HAVE_CHANGE_CARRIER_CB -static int -kni_net_change_carrier (struct net_device *dev,bool new_carrier) -{ -if (new_carrier) -netif_carrier_on (dev); -else -netif_carrier_off (dev); -return 0 ; -} -#endif -static const struct header_ops kni_net_header_ops = { .create = kni_net_header, .parse = eth_header_parse,
@@ -736,9 +724,6 @@ static const struct net_device_ops kni_net_netdev_ops = { .ndo_change_mtu = kni_net_change_mtu, .ndo_tx_timeout = kni_net_tx_timeout, .ndo_set_mac_address = kni_net_set_mac, -#ifdef HAVE_CHANGE_CARRIER_CB - .ndo_change_carrier = kni_net_change_carrier, -#endif }; static void kni_get_drvinfo(struct net_device *dev,
lib/librte_eal/linux/eal/include/rte_kni_common.h +6 -0
@@ -125,10 +125,16 @@ struct rte_kni_device_info { uint8_t mac_addr[6]; }; +struct rte_kni_link_info { +char name[RTE_KNI_NAMESIZE ]; +unsigned int linkup; +}; +#define KNI_DEVICE "kni"#define RTE_KNI_IOCTL_TEST _IOWR(0, 1, int)#define RTE_KNI_IOCTL_CREATE _IOWR(0, 2, struct rte_kni_device_info)#define RTE_KNI_IOCTL_RELEASE _IOWR(0, 3, struct rte_kni_device_info) +#define RTE_KNI_IOCTL_LINK _IOWR(0, 4, struct rte_kni_link_info)#endif /* _RTE_KNI_COMMON_H_ */
lib/librte_kni/rte_kni.c +6 -27
@@ -733,41 +733,20 @@ rte_kni_unregister_handlers(struct rte_kni *kni)int rte_kni_update_link (struct rte_kni *kni,unsigned int linkup) { -char path[64 ]; -char old_carrier[2 ]; -const char *new_carrier; -int old_linkup; -int fd, ret; +struct rte_kni_link_info link_info;if (kni ==NULL )return -1 ; -snprintf (path,sizeof (path),"/sys/devices/virtual/net/%s/carrier" , - kni->name); +snprintf (link_info.name,RTE_KNI_NAMESIZE ,"%s" , kni->name); + link_info.linkup = linkup; - fd =open (path,O_RDWR ); -if (fd ==-1 ) { -RTE_LOG (ERR ,KNI ,"Failed to open file: %s.\n" , path); +if (ioctl (kni_fd,RTE_KNI_IOCTL_LINK , &link_info) <0 ) { +RTE_LOG (ERR ,KNI ,"Fail to update KNI link\n" );return -1 ; } - ret =read (fd, old_carrier,2 ); -if (ret <1 ) { -close (fd); -return -1 ; - } - old_linkup = (old_carrier[0 ] =='1' ); - - new_carrier = linkup ?"1" :"0" ; - ret =write (fd, new_carrier,1 ); -if (ret <1 ) { -RTE_LOG (ERR ,KNI ,"Failed to write file: %s.\n" , path); -close (fd); -return -1 ; - } - -close (fd); -return old_linkup; +return 0 ; }void
lib/librte_kni/rte_kni.h +1 -2
@@ -247,9 +247,8 @@ int rte_kni_unregister_handlers(struct rte_kni *kni);* > 0 for linkup. * * @return +* On success: 0 * On failure: -1 -* Previous link state == linkdown: 0 -* Previous link state == linkup: 1 */ __rte_experimental int
Signature · 1 line
2.23.0
Quoted 6 lines · Igor Ryzhov
Current implementation doesn't allow us to update KNI carrier if the interface is not yet UP in kernel. It means that we can't use it in the same thread which is processing rte_kni_ops.config_network_if, which is very convenient, because it allows us to have correct carrier status of the interface right after we enabled it and we don't have to use any additional thread to track link status.
Hi Igor,
The existing thread tracks the link status of the physical device and reflects the changes to the kni netdev, but the "struct rte_kni_ops" (rte_kni_ops.config_network_if) works other way around, it captures (some) requests to kni netdev and reflects them to the underlying physical device. Even 'rte_kni_update_link()' updated to use ioctl, the thread still looks required and this patch doesn't really changes that part.
Also I am reluctant to extend the KNI ioctl interface when there is a generic way to do that work.
What is the use case of updating kni netdev carrier status when the interface is down?
Quoted 2 lines
Signed-off-by Igor Ryzhov <[email protected]>
<...>
Quoted 17 lines · Ferruh Yigit
Quoted 6 lines · Igor Ryzhov
Current implementation doesn't allow us to update KNI carrier if the interface is not yet UP in kernel. It means that we can't use it in the same thread which is processing rte_kni_ops.config_network_if, which is very convenient, because it allows us to have correct carrier status of the interface right after we enabled it and we don't have to use any additional thread to track link status.
Hi Igor,
The existing thread tracks the link status of the physical device and reflects the changes to the kni netdev, but the "struct
rte_kni_ops" (rte_kni_ops.config_network_if) works other way around, it captures (some) requests to kni netdev and reflects them to the underlying physical device. Even 'rte_kni_update_link()' updated to use ioctl, the thread still looks required and this patch doesn't really changes that part.
Quoted 5 lines
Also I am reluctant to extend the KNI ioctl interface when there is a generic way to do that work.
What is the use case of updating kni netdev carrier status when the interface is down?
btw, if the problem is status of the interface being 'no-carrier' by default, this can be changed by "carrier=on" parameter of the kni kernel module:
"insmod ./build/kmod/rte_kni.ko carrier=on"
Quoted 6 lines
Quoted 3 lines
Signed-off-by Igor Ryzhov <[email protected]><...>
My original patch to add this feature was basically the same thing as
this: setting the link status via a KNI ioctl. That method was rejected after _much_ discussion and we eventually settled on the currently implementation.
My original patch was here: Message-Id: <[email protected]>
If you search for KNI and [email protected] in the DPDK devel list you should be able to suss out the whole discussion that lead to the current implementation.
thanks
dan
Quoted 36 lines · Ferruh Yigit
Quoted 17 lines · Ferruh Yigit
Quoted 6 lines · Igor Ryzhov
Current implementation doesn't allow us to update KNI carrier if the interface is not yet UP in kernel. It means that we can't use it in the same thread which is processing rte_kni_ops.config_network_if, which is very convenient, because it allows us to have correct carrier status of the interface right after we enabled it and we don't have to use any additional thread to track link status.
Hi Igor,
The existing thread tracks the link status of the physical device and reflects the changes to the kni netdev, but the "struct
rte_kni_ops" (rte_kni_ops.config_network_if) works other way around, it captures (some) requests to kni netdev and reflects them to the underlying physical device. Even 'rte_kni_update_link()' updated to use ioctl, the thread still looks required and this patch doesn't really changes that part.Quoted 5 lines
Also I am reluctant to extend the KNI ioctl interface when there is a generic way to do that work.
What is the use case of updating kni netdev carrier status when the interface is down?
btw, if the problem is status of the interface being 'no-carrier' by default, this can be changed by "carrier=on" parameter of the kni kernel module:
"insmod./build/kmod/rte_kni.kocarrier=on"Quoted 6 lines
Quoted 3 lines
Signed-off-by Igor Ryzhov <[email protected]><...>
Here's another link to the thread where this was discussed last year.. Igor was actually on this thread as well...
https://mails.dpdk.org/archives/dev/2018-August/110383.html
Quoted 44 lines · Dan Gora
My original patch to add this feature was basically the same thing as
this: setting the link status via a KNI ioctl. That method was rejected after _much_ discussion and we eventually settled on the currently implementation.My original patch was here: Message-Id: <[email protected]>
If you search for KNI and [email protected] in the DPDK devel list you should be able to suss out the whole discussion that lead to the current implementation.
thanks
danQuoted 28 lines · Ferruh Yigit
Quoted 17 lines · Ferruh Yigit
Quoted 6 lines · Igor Ryzhov
Current implementation doesn't allow us to update KNI carrier if the interface is not yet UP in kernel. It means that we can't use it in the same thread which is processing rte_kni_ops.config_network_if, which is very convenient, because it allows us to have correct carrier status of the interface right after we enabled it and we don't have to use any additional thread to track link status.
Hi Igor,
The existing thread tracks the link status of the physical device and reflects the changes to the kni netdev, but the "struct
rte_kni_ops" (rte_kni_ops.config_network_if) works other way around, it captures (some) requests to kni netdev and reflects them to the underlying physical device. Even 'rte_kni_update_link()' updated to use ioctl, the thread still looks required and this patch doesn't really changes that part.Quoted 5 lines
Also I am reluctant to extend the KNI ioctl interface when there is a generic way to do that work.
What is the use case of updating kni netdev carrier status when the interface is down?
btw, if the problem is status of the interface being 'no-carrier' by default, this can be changed by "carrier=on" parameter of the kni kernel module:
"insmod./build/kmod/rte_kni.kocarrier=on"
Hi Ferruh, Dan,
Sure, I remember last year discussion but now I see the problem in current implementation.
Ferruh, here is an example:
We have a thread in the application that processes KNI commands from the kernel.
It receives config_network_if command to set interface up, calls rte_eth_dev_start, and here is the problem.
We cannot call current rte_kni_update_link from here as the interface is not yet up in the kernel,
as we didn't send a response for config_network_if yet. So we need to send a response first and only
after that, we can use rte_kni_update_link. Actually, we don't even know the exact time between we
send a response and the moment when the kernel receives it and the interface becomes up.
We always have a dependency on the interface state in the kernel. With ioctl approach, we don't
have such dependency - we can call rte_kni_update_link whenever we want, even when the interface is
down in the kernel. As I explained, it's common when processing config_network_if to set interface up.
Igor
Quoted 63 lines · Dan Gora
Here's another link to the thread where this was discussed last year.. Igor was actually on this thread as well...
https://mails.dpdk.org/archives/dev/2018-August/110383.html
Quoted 7 lines · Dan Gora
My original patch to add this feature was basically the same thing as
this: setting the link status via a KNI ioctl. That method was rejected after _much_ discussion and we eventually settled on the currently implementation.My original patch was here: Message-Id: <
Quoted 9 lines
If you search for KNI and [email protected] in the DPDK devel list you should be able to suss out the whole discussion that lead to the current implementation.
thanks
danOn Mon, Oct 14, 2019 at 1:17 PM Ferruh Yigit <[email protected]>
Quoted 5 lines · wrote:
Quoted 5 lines · Ferruh Yigit
Quoted 3 lines · Igor Ryzhov
Quoted 2 lines
Current implementation doesn't allow us to update KNI carrier if the interface is not yet UP in kernel. It means that we can't use it in
the
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
same thread which is processing rte_kni_ops.config_network_if,
which is
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
very convenient, because it allows us to have correct carrier status of the interface right after we enabled it and we don't have to use
any
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
additional thread to track link status.
Hi Igor,
The existing thread tracks the link status of the physical device
and reflects
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
the changes to the kni netdev, but the "struct
rte_kni_ops" (rte_kni_ops.config_network_if) works other way around, it captures(some)
Quoted 1 line
Quoted 1 line
Quoted 1 line
requests to kni netdev and reflects them to the underlying physical
device.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Even '
rte_kni_update_link()' updated to use ioctl, the thread stilllooks
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
required and this patch doesn't really changes that part.
Also I am reluctant to extend the KNI ioctl interface when there is
a generic
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
way to do that work.
What is the use case of updating kni netdev carrier status when the
interface is
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
down?
btw, if the problem is status of the interface being 'no-carrier' by
default,
Quoted 2 lines
Quoted 2 lines
this can be changed by "carrier=on" parameter of the kni kernel module:
"insmod./build/kmod/rte_kni.kocarrier=on"
Quoted 17 lines · Igor Ryzhov
Hi Ferruh, Dan,
Sure, I remember last year discussion but now I see the problem in current implementation.
Ferruh, here is an example:
We have a thread in the application that processes KNI commands from the kernel.
It receivesconfig_network_ifcommand to set interface up, callsrte_eth_dev_start, and here is the problem.
We cannot call currentrte_kni_update_linkfrom here as the interface is not yet up in the kernel,
as we didn't send a response forconfig_network_ifyet. So we need to send a response first and only
after that, we can userte_kni_update_link. Actually, we don't even know the exact time between we
Quoted 9 lines
send a response and the moment when the kernel receives it and the interface becomes up.
We always have a dependency on the interface state in the kernel. With ioctl approach, we don't
have such dependency - we can callrte_kni_update_linkwhenever we want, even when the interface is
down in the kernel. As I explained, it's common when processingconfig_network_ifto set interface up.
Hi Igor,
I agree with the mentioned problem. When the KNI interface is down, not able to update the link carrier status is not convenient.
For a physical interface this may make sense, since interface won't be used by the OS, no need to power on the PHY and trace the carrier status. But for the intention of the original link set feature, it requires to be able to update the carrier status independent from the interface up/down status.
Overall, also agree to not introduce a new ioctl and use existing interface, but for this case existing interface doesn't exactly fit to the intended use case and I am OK have the ioctl.
Can you please send a new version rebasing latest head, we can continue on that one?
Thanks,
ferruh
Quoted 67 lines
Igor
Quoted 63 lines · Dan Gora
Here's another link to the thread where this was discussed last year.. Igor was actually on this thread as well...
https://mails.dpdk.org/archives/dev/2018-August/110383.html
Quoted 7 lines · Dan Gora
My original patch to add this feature was basically the same thing as
this: setting the link status via a KNI ioctl. That method was rejected after _much_ discussion and we eventually settled on the currently implementation.My original patch was here: Message-Id: <
Quoted 9 lines
If you search for KNI and [email protected] in the DPDK devel list you should be able to suss out the whole discussion that lead to the current implementation.
thanks
danOn Mon, Oct 14, 2019 at 1:17 PM Ferruh Yigit <[email protected]>
Quoted 5 lines · wrote:
Quoted 5 lines · Ferruh Yigit
Quoted 3 lines · Igor Ryzhov
Quoted 2 lines
Current implementation doesn't allow us to update KNI carrier if the interface is not yet UP in kernel. It means that we can't use it in
the
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
same thread which is processing rte_kni_ops.config_network_if,
which is
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
very convenient, because it allows us to have correct carrier status of the interface right after we enabled it and we don't have to use
any
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
additional thread to track link status.
Hi Igor,
The existing thread tracks the link status of the physical device
and reflects
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
the changes to the kni netdev, but the "struct
rte_kni_ops" (rte_kni_ops.config_network_if) works other way around, it captures(some)
Quoted 1 line
Quoted 1 line
Quoted 1 line
requests to kni netdev and reflects them to the underlying physical
device.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Even '
rte_kni_update_link()' updated to use ioctl, the thread stilllooks
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
required and this patch doesn't really changes that part.
Also I am reluctant to extend the KNI ioctl interface when there is
a generic
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
way to do that work.
What is the use case of updating kni netdev carrier status when the
interface is
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
down?
btw, if the problem is status of the interface being 'no-carrier' by
default,
Quoted 2 lines
Quoted 2 lines
this can be changed by "carrier=on" parameter of the kni kernel module:
"insmod./build/kmod/rte_kni.kocarrier=on"
Thanks Ferruh,
I'll send an update later this week.
I also want to add a "Suggested-by: Dan Gora <[email protected]>" as it was his idea.
Dan, please let me know if you don't want this tag to be added.
Thanks,
Igor
Quoted 127 lines · Ferruh Yigit
Quoted 3 lines · Igor Ryzhov
Hi Ferruh, Dan,
Sure, I remember last year discussion but now I see the problem in
current
Quoted 11 lines
implementation.
Ferruh, here is an example:
We have a thread in the application that processes KNI commands from the kernel.
It receivesconfig_network_ifcommand to set interface up, callsrte_eth_dev_start, and here is the problem.
We cannot call currentrte_kni_update_linkfrom here as the interface is not yet up in the kernel,
as we didn't send a response forconfig_network_ifyet. So we need tosend
Quoted 12 lines
a response first and only
after that, we can userte_kni_update_link. Actually, we don't even know the exact time between we
send a response and the moment when the kernel receives it and the interface becomes up.
We always have a dependency on the interface state in the kernel. With ioctl approach, we don't
have such dependency - we can callrte_kni_update_linkwhenever we want, even when the interface is
down in the kernel. As I explained, it's common when processingconfig_network_ifto set interface up.Hi Igor,
I agree with the mentioned problem. When the KNI interface is down, not able to
update the link carrier status is not convenient.For a physical interface this may make sense, since interface won't be used by
the OS, no need to power on the PHY and trace the carrier status. But for the
intention of the original link set feature, it requires to be able to update the
carrier status independent from the interface up/down status.Overall, also agree to not introduce a new ioctl and use existing interface, but
for this case existing interface doesn't exactly fit to the intended use case
and I am OK have the ioctl.Can you please send a new version rebasing latest head, we can continue on that one?
Thanks,
ferruhQuoted 65 lines
Igor
Quoted 61 lines · Dan Gora
Here's another link to the thread where this was discussed last year.. Igor was actually on this thread as well...
https://mails.dpdk.org/archives/dev/2018-August/110383.html
Quoted 7 lines · Dan Gora
My original patch to add this feature was basically the same thing as
this: setting the link status via a KNI ioctl. That method was rejected after _much_ discussion and we eventually settled on the currently implementation.My original patch was here: Message-Id: <
Quoted 9 lines
If you search for KNI and [email protected] in the DPDK devel list you should be able to suss out the whole discussion that lead to the current implementation.
thanks
danOn Mon, Oct 14, 2019 at 1:17 PM Ferruh Yigit <[email protected]>
Quoted 5 lines · wrote:
Quoted 5 lines · Ferruh Yigit
Quoted 3 lines · Igor Ryzhov
Quoted 2 lines
Current implementation doesn't allow us to update KNI carrier if the interface is not yet UP in kernel. It means that we can't use it in
the
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
same thread which is processing rte_kni_ops.config_network_if,
which is
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
very convenient, because it allows us to have correct carrier status of the interface right after we enabled it and we don't have to use
any
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
additional thread to track link status.
Hi Igor,
The existing thread tracks the link status of the physical device
and reflects
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
the changes to the kni netdev, but the "struct
rte_kni_ops" (rte_kni_ops.config_network_if) works other way around, it captures(some)
Quoted 1 line
Quoted 1 line
Quoted 1 line
requests to kni netdev and reflects them to the underlying physical
device.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Even '
rte_kni_update_link()' updated to use ioctl, the thread stilllooks
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
required and this patch doesn't really changes that part.
Also I am reluctant to extend the KNI ioctl interface when there is
a generic
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
way to do that work.
What is the use case of updating kni netdev carrier status when the
interface is
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
down?
btw, if the problem is status of the interface being 'no-carrier' by
default,
Quoted 1 line
Quoted 1 line
this can be changed by "carrier=on" parameter of the kni kernel
module:
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
Quoted 1 line
"insmod
./build/kmod/rte_kni.kocarrier=on"
PATCH v4 1/2 kni: rework rte_kni_update_link using ioctl
In reply to Igor RyzhovCurrent implementation doesn't allow us to update KNI carrier if the interface is not yet UP in kernel. It means that we can't use it in the same thread which is processing rte_kni_ops.config_network_if, which is very convenient, because it allows us to have correct carrier status of the interface right after we enabled it and we don't have to use any additional thread to track link status.
Propagating speed/duplex/autoneg to the kernel module also allows us to implement ethtool_ops.get_link_ksettings callback.
--- app/test/test_kni.c | 32 ++++++++++--------------- examples/kni/main.c | 2 +- kernel/linux/kni/compat.h | 4 ---- kernel/linux/kni/kni_dev.h | 5 ++++ kernel/linux/kni/kni_misc.c | 47 +++++++++++++++++++++++++++++++++++++ kernel/linux/kni/kni_net.c | 15 ------------ lib/kni/rte_kni.c | 38 ++++++++---------------------- lib/kni/rte_kni.h | 10 ++++---- lib/kni/rte_kni_common.h | 9 +++++++ 9 files changed, 89 insertions(+), 73 deletions(-)
app/test/test_kni.c +13 -19
@@ -125,6 +125,7 @@ kni_change_mtu(uint16_t port_id, unsigned int new_mtu)static int test_kni_link_change (void ) { +struct rte_eth_link link;int ret;int pid;
@@ -135,42 +136,35 @@ test_kni_link_change(void) }if (pid ==0 ) { + link.link_speed =ETH_SPEED_NUM_10G ; + link.link_duplex =ETH_LINK_FULL_DUPLEX ; + link.link_autoneg =ETH_LINK_AUTONEG ; +printf ("Starting KNI Link status change tests.\n" ); if (system(IFCONFIG TEST_KNI_PORT" up") == -1) { ret =-1 ; goto error; } - ret =rte_kni_update_link (test_kni_ctx,1 ); + link.link_status =ETH_LINK_UP ; + ret =rte_kni_update_link (test_kni_ctx, &link);if (ret <0 ) {printf ("Failed to change link state to Up ret=%d.\n" , ret); goto error; }rte_delay_ms (1000 ); -printf ("KNI: Set LINKUP, previous state=%d\n" , ret); - - ret =rte_kni_update_link (test_kni_ctx,0 ); -if (ret !=1 ) { -printf ( -"Failed! Previous link state should be 1, returned %d.\n" , - ret); - goto error; - } -rte_delay_ms (1000 ); -printf ("KNI: Set LINKDOWN, previous state=%d\n" , ret); +printf ("KNI: Set LINKUP\n" ); - ret =rte_kni_update_link (test_kni_ctx,1 ); -if (ret !=0 ) { -printf ( -"Failed! Previous link state should be 0, returned %d.\n" , + link.link_status =ETH_LINK_DOWN ; + ret =rte_kni_update_link (test_kni_ctx, &link); +if (ret <0 ) { +printf ("Failed to change link state to Down ret=%d.\n" , ret); goto error; } -printf ("KNI: Set LINKUP, previous state=%d\n" , ret); - - ret =0 ;rte_delay_ms (1000 ); +printf ("KNI: Set LINKDOWN\n" ); error: if (system(IFCONFIG TEST_KNI_PORT" down") == -1)
examples/kni/main.c +1 -1
@@ -755,7 +755,7 @@ monitor_all_ports_link_status(void *arg) }for (i =0 ; i < p[portid]->nb_kni; i++) { prev =rte_kni_update_link (p[portid]->kni[i], - link.link_status); + &link);log_link_state (p[portid]->kni[i], prev, &link); } }
kernel/linux/kni/compat.h +0 -4
@@ -61,10 +61,6 @@#define kni_sock_map_fd (s) sock_map_fd(s, 0)#endif -#if LINUX_VERSION_CODE >=KERNEL_VERSION (3 ,9 ,0 ) -#define HAVE_CHANGE_CARRIER_CB -#endif -#if LINUX_VERSION_CODE <KERNEL_VERSION (3 ,14 ,0 )#define ether_addr_copy (dst, src) memcpy(dst, src, ETH_ALEN)#endif
kernel/linux/kni/kni_dev.h +5 -0
@@ -88,6 +88,11 @@ struct kni_dev {void *alloc_va[MBUF_BURST_SZ ];struct task_struct *usr_tsk; + +/* correct when netif_carrier_ok */ +uint32_t speed; +uint8_t duplex; +uint8_t autoneg; };#ifdef HAVE_IOVA_TO_KVA_MAPPING_SUPPORT
kernel/linux/kni/kni_misc.c +47 -0
59 lines not on this page · raw message
kernel/linux/kni/kni_net.c +0 -15
@@ -778,18 +778,6 @@ kni_net_set_mac(struct net_device *netdev, void *p)return (ret ==0 ? req.result : ret); } -#ifdef HAVE_CHANGE_CARRIER_CB -static int -kni_net_change_carrier (struct net_device *dev,bool new_carrier) -{ -if (new_carrier) -netif_carrier_on (dev); -else -netif_carrier_off (dev); -return 0 ; -} -#endif -static const struct header_ops kni_net_header_ops = { .create = kni_net_header, .parse = eth_header_parse,
@@ -808,9 +796,6 @@ static const struct net_device_ops kni_net_netdev_ops = { .ndo_change_mtu = kni_net_change_mtu, .ndo_tx_timeout = kni_net_tx_timeout, .ndo_set_mac_address = kni_net_set_mac, -#ifdef HAVE_CHANGE_CARRIER_CB - .ndo_change_carrier = kni_net_change_carrier, -#endif }; static void kni_get_drvinfo(struct net_device *dev,
lib/kni/rte_kni.c +10 -28
@@ -784,43 +784,25 @@ rte_kni_unregister_handlers(struct rte_kni *kni) }int -rte_kni_update_link (struct rte_kni *kni,unsigned int linkup) +rte_kni_update_link (struct rte_kni *kni,struct rte_eth_link *link) { -char path[64 ]; -char old_carrier[2 ]; -const char *new_carrier; -int old_linkup; -int fd, ret; +struct rte_kni_link_info link_info;if (kni ==NULL )return -1 ; -snprintf (path,sizeof (path),"/sys/devices/virtual/net/%s/carrier" , - kni->name); +snprintf (link_info.name,RTE_KNI_NAMESIZE ,"%s" , kni->name); + link_info.speed = link->link_speed; + link_info.duplex = link->link_duplex; + link_info.autoneg = link->link_autoneg; + link_info.status = link->link_status; - fd =open (path,O_RDWR ); -if (fd ==-1 ) { -RTE_LOG (ERR ,KNI ,"Failed to open file: %s.\n" , path); +if (ioctl (kni_fd,RTE_KNI_IOCTL_LINK , &link_info) <0 ) { +RTE_LOG (ERR ,KNI ,"Fail to update KNI link\n" );return -1 ; } - ret =read (fd, old_carrier,2 ); -if (ret <1 ) { -close (fd); -return -1 ; - } - old_linkup = (old_carrier[0 ] =='1' ); - - new_carrier = linkup ?"1" :"0" ; - ret =write (fd, new_carrier,1 ); -if (ret <1 ) { -RTE_LOG (ERR ,KNI ,"Failed to write file: %s.\n" , path); -close (fd); -return -1 ; - } - -close (fd); -return old_linkup; +return 0 ; }void
lib/kni/rte_kni.h +4 -6
@@ -21,6 +21,7 @@#include <rte_memory.h> #include <rte_mempool.h> #include <rte_ether.h> +#include <rte_ethdev.h> #include <rte_kni_common.h>
@@ -245,18 +246,15 @@ int rte_kni_unregister_handlers(struct rte_kni *kni);* @param kni * pointer to struct rte_kni. * @param linkup -* New link state: -* 0 for linkdown. -* > 0 for linkup. +* new link state, speed, duplex, autoneg. * * @return +* On success: 0 * On failure: -1 -* Previous link state == linkdown: 0 -* Previous link state == linkup: 1 */ __rte_experimental int -rte_kni_update_link (struct rte_kni *kni,unsigned int linkup); +rte_kni_update_link (struct rte_kni *kni,struct rte_eth_link *link);/** * Close KNI device.
lib/kni/rte_kni_common.h +9 -0
@@ -130,10 +130,19 @@ struct rte_kni_device_info { uint8_t iova_mode; }; +struct rte_kni_link_info { +char name[RTE_KNI_NAMESIZE ]; +unsigned int speed; +unsigned char duplex; +unsigned char autoneg; +unsigned char status; +}; +#define KNI_DEVICE "kni"#define RTE_KNI_IOCTL_TEST _IOWR(0, 1, int)#define RTE_KNI_IOCTL_CREATE _IOWR(0, 2, struct rte_kni_device_info)#define RTE_KNI_IOCTL_RELEASE _IOWR(0, 3, struct rte_kni_device_info) +#define RTE_KNI_IOCTL_LINK _IOWR(0, 4, struct rte_kni_link_info)#endif /* _RTE_KNI_COMMON_H_ */
Signature · 1 line
2.32.0
PATCH v4 2/2 kni: implement basic get_link_ksettings callback
--- kernel/linux/kni/kni_net.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
kernel/linux/kni/kni_net.c +25 -0
@@ -805,9 +805,34 @@ static void kni_get_drvinfo(struct net_device *dev,strlcpy (info->driver,"kni" ,sizeof (info->driver)); } +#ifdef ETHTOOL_GLINKSETTINGS +static int kni_get_link_ksettings (struct net_device *dev, +struct ethtool_link_ksettings *settings) +{ +struct kni_dev *kni =netdev_priv (dev); + + settings->base.port =PORT_OTHER ; + +if (netif_carrier_ok (dev)) { + settings->base.speed = kni->speed; + settings->base.duplex = kni->duplex; + settings->base.autoneg = kni->autoneg; + }else { + settings->base.speed =SPEED_UNKNOWN ; + settings->base.duplex =DUPLEX_UNKNOWN ; + settings->base.autoneg =AUTONEG_ENABLE ; + } + +return 0 ; +} +#endif +static const struct ethtool_ops kni_net_ethtool_ops = { .get_drvinfo = kni_get_drvinfo, .get_link = ethtool_op_get_link, +#ifdef ETHTOOL_GLINKSETTINGS + .get_link_ksettings = kni_get_link_ksettings, +#endif };void
Signature · 1 line
2.32.0
Quoted 73 lines · Igor Ryzhov
Current implementation doesn't allow us to update KNI carrier if the interface is not yet UP in kernel. It means that we can't use it in the same thread which is processing rte_kni_ops.config_network_if, which is very convenient, because it allows us to have correct carrier status of the interface right after we enabled it and we don't have to use any additional thread to track link status.
Propagating speed/duplex/autoneg to the kernel module also allows us to implement ethtool_ops.get_link_ksettings callback.
Suggested-by Dan Gora <[email protected]>Signed-off-by Igor Ryzhov <[email protected]>--- app/test/test_kni.c | 32 ++++++++++--------------- examples/kni/main.c | 2 +- kernel/linux/kni/compat.h | 4 ---- kernel/linux/kni/kni_dev.h | 5 ++++ kernel/linux/kni/kni_misc.c | 47 +++++++++++++++++++++++++++++++++++++ kernel/linux/kni/kni_net.c | 15 ------------ lib/kni/rte_kni.c | 38 ++++++++---------------------- lib/kni/rte_kni.h | 10 ++++---- lib/kni/rte_kni_common.h | 9 +++++++ 9 files changed, 89 insertions(+), 73 deletions(-)app/test/test_kni.c +8
-13@@ -125,6 +125,7 @@ kni_change_mtu(uint16_t port_id, unsigned int new_mtu)static int test_kni_link_change (void ) { +struct rte_eth_link link;int ret;int pid;@@ -135,42 +136,35 @@ test_kni_link_change(void) }if (pid ==0 ) { + link.link_speed =ETH_SPEED_NUM_10G ; + link.link_duplex =ETH_LINK_FULL_DUPLEX ; + link.link_autoneg =ETH_LINK_AUTONEG ; +printf ("Starting KNI Link status change tests.\n" ); if (system(IFCONFIG TEST_KNI_PORT" up") == -1) { ret =-1 ; goto error; } - ret =rte_kni_update_link (test_kni_ctx,1 ); + link.link_status =ETH_LINK_UP ; + ret =rte_kni_update_link (test_kni_ctx, &link);if (ret <0 ) {printf ("Failed to change link state to Up ret=%d.\n" , ret); goto error; }rte_delay_ms (1000 ); -printf ("KNI: Set LINKUP, previous state=%d\n" , ret); - - ret =rte_kni_update_link (test_kni_ctx,0 ); -if (ret !=1 ) { -printf ( -"Failed! Previous link state should be 1, returned %d.\n" , - ret); - goto error; - } -rte_delay_ms (1000 ); -printf ("KNI: Set LINKDOWN, previous state=%d\n" , ret); +printf ("KNI: Set LINKUP\n" ); - ret =rte_kni_update_link (test_kni_ctx,1 );
app/test/test_kni.c test_kni_link_change(void) · line 165
Quoted 10 lines
app/test/test_kni.c +4
-3-if (ret !=0 ) { -printf ( -"Failed! Previous link state should be 0, returned %d.\n" , + link.link_status =ETH_LINK_DOWN ; + ret =rte_kni_update_link (test_kni_ctx, &link); +if (ret <0 ) { +printf ("Failed to change link state to Down ret=%d.\n" , ret); goto error; }
Is there a way to verify the link status of the KNI interface, to double check setting link status succedded?
Quoted 141 lines
app/test/test_kni.c +1
-3-printf ("KNI: Set LINKUP, previous state=%d\n" , ret); - - ret =0 ;rte_delay_ms (1000 ); +printf ("KNI: Set LINKDOWN\n" ); error: if (system(IFCONFIG TEST_KNI_PORT" down") == -1)examples/kni/main.c +1
-1@@ -755,7 +755,7 @@ monitor_all_ports_link_status(void *arg) }for (i =0 ; i < p[portid]->nb_kni; i++) { prev =rte_kni_update_link (p[portid]->kni[i], - link.link_status); + &link);log_link_state (p[portid]->kni[i], prev, &link); } }kernel/linux/kni/compat.h +0
-4@@ -61,10 +61,6 @@#define kni_sock_map_fd (s) sock_map_fd(s, 0)#endif -#if LINUX_VERSION_CODE >=KERNEL_VERSION (3 ,9 ,0 ) -#define HAVE_CHANGE_CARRIER_CB -#endif -#if LINUX_VERSION_CODE <KERNEL_VERSION (3 ,14 ,0 )#define ether_addr_copy (dst, src) memcpy(dst, src, ETH_ALEN)#endif kernel/linux/kni/kni_dev.h +5
-0@@ -88,6 +88,11 @@ struct kni_dev {void *alloc_va[MBUF_BURST_SZ ];struct task_struct *usr_tsk; + +/* correct when netif_carrier_ok */ +uint32_t speed; +uint8_t duplex; +uint8_t autoneg; };#ifdef HAVE_IOVA_TO_KVA_MAPPING_SUPPORT kernel/linux/kni/kni_misc.c +47
-0@@ -481,6 +481,50 @@ kni_ioctl_release(struct net *net, uint32_t ioctl_num,return ret; } +static int +kni_ioctl_link (struct net *net,uint32_t ioctl_num, +unsigned long ioctl_param) +{ +struct kni_net *knet =net_generic (net, kni_net_id); +int ret = -EINVAL ; +struct kni_dev *dev, *n; +struct rte_kni_link_info link_info; +struct net_device *netdev; + +if (_IOC_SIZE (ioctl_num) >sizeof (link_info)) +return -EINVAL ; + +if (copy_from_user (&link_info, (void *)ioctl_param,sizeof (link_info))) +return -EFAULT ; + +if (strlen (link_info.name) ==0 ) +return -EINVAL ; + +down_read (&knet->kni_list_lock); +list_for_each_entry_safe (dev, n, &knet->kni_list_head, list) { +if (strncmp (dev->name, link_info.name,RTE_KNI_NAMESIZE ) !=0 ) +continue ; + + netdev = dev->net_dev; + +if (link_info.status) { +netif_carrier_on (netdev); + + dev->speed = link_info.speed; + dev->duplex = link_info.duplex; + dev->autoneg = link_info.autoneg; + }else { +netif_carrier_off (netdev); + } + + ret =0 ; +break ; + } +up_read (&knet->kni_list_lock); + +return ret; +} +static int kni_ioctl (struct inode *inode,uint32_t ioctl_num,unsigned long ioctl_param) {@@ -502,6 +546,9 @@ kni_ioctl(struct inode *inode, uint32_t ioctl_num, unsigned long ioctl_param)case _IOC_NR (RTE_KNI_IOCTL_RELEASE ): ret =kni_ioctl_release (net, ioctl_num, ioctl_param);break ; +case _IOC_NR (RTE_KNI_IOCTL_LINK ): + ret =kni_ioctl_link (net, ioctl_num, ioctl_param); +break ;default :pr_debug ("IOCTL default\n" );break ;kernel/linux/kni/kni_net.c +0
-12@@ -778,18 +778,6 @@ kni_net_set_mac(struct net_device *netdev, void *p)return (ret ==0 ? req.result : ret); } -#ifdef HAVE_CHANGE_CARRIER_CB -static int -kni_net_change_carrier (struct net_device *dev,bool new_carrier) -{ -if (new_carrier) -netif_carrier_on (dev); -else -netif_carrier_off (dev); -return 0 ; -} -#endif -static const struct header_ops kni_net_header_ops = { .create = kni_net_header, .parse = eth_header_parse,
kernel/linux/kni/kni_net.c static const struct net_device_ops kni_net_netdev_ops = { · line 813
Quoted 6 lines
kernel/linux/kni/kni_net.c +0
-3@@ -808,9 +796,6 @@ static const struct net_device_ops kni_net_netdev_ops = { .ndo_change_mtu = kni_net_change_mtu, .ndo_tx_timeout = kni_net_tx_timeout, .ndo_set_mac_address = kni_net_set_mac, -#ifdef HAVE_CHANGE_CARRIER_CB - .ndo_change_carrier = kni_net_change_carrier, -#endif
What do you think keeping the 'carrier' interface? Even the API not using it, it can be useful, what do you think?
Quoted 49 lines
kernel/linux/kni/kni_net.c +0
-0}; static void kni_get_drvinfo(struct net_device *dev,lib/kni/rte_kni.c +9
-20@@ -784,43 +784,25 @@ rte_kni_unregister_handlers(struct rte_kni *kni) }int -rte_kni_update_link (struct rte_kni *kni,unsigned int linkup) +rte_kni_update_link (struct rte_kni *kni,struct rte_eth_link *link) { -char path[64 ]; -char old_carrier[2 ]; -const char *new_carrier; -int old_linkup; -int fd, ret; +struct rte_kni_link_info link_info;if (kni ==NULL )return -1 ; -snprintf (path,sizeof (path),"/sys/devices/virtual/net/%s/carrier" , - kni->name); +snprintf (link_info.name,RTE_KNI_NAMESIZE ,"%s" , kni->name); + link_info.speed = link->link_speed; + link_info.duplex = link->link_duplex; + link_info.autoneg = link->link_autoneg; + link_info.status = link->link_status; - fd =open (path,O_RDWR ); -if (fd ==-1 ) { -RTE_LOG (ERR ,KNI ,"Failed to open file: %s.\n" , path); +if (ioctl (kni_fd,RTE_KNI_IOCTL_LINK , &link_info) <0 ) { +RTE_LOG (ERR ,KNI ,"Fail to update KNI link\n" );return -1 ; } - ret =read (fd, old_carrier,2 ); -if (ret <1 ) { -close (fd); -return -1 ; - } - old_linkup = (old_carrier[0 ] =='1' ); - - new_carrier = linkup ?"1" :"0" ; - ret =write (fd, new_carrier,1 );
lib/kni/rte_kni.c rte_kni_unregister_handlers(struct rte_kni *kni) · line 806
Quoted 10 lines
lib/kni/rte_kni.c +1
-8-if (ret <1 ) { -RTE_LOG (ERR ,KNI ,"Failed to write file: %s.\n" , path); -close (fd); -return -1 ; - } - -close (fd); -return old_linkup; +return 0 ; }
Can you please add new API to KNI PMD too? To set the link up when port started.
Quoted 19 lines
lib/kni/rte_kni.c +0
-0void lib/kni/rte_kni.h +1
-1@@ -21,6 +21,7 @@#include <rte_memory.h> #include <rte_mempool.h> #include <rte_ether.h> +#include <rte_ethdev.h> #include <rte_kni_common.h> @@ -245,18 +246,15 @@ int rte_kni_unregister_handlers(struct rte_kni *kni);* @param kni * pointer to struct rte_kni. * @param linkup -* New link state:
lib/kni/rte_kni.h int rte_kni_unregister_handlers(struct rte_kni *kni); · line 254
Quoted 10 lines
lib/kni/rte_kni.h +2
-4-* 0 for linkdown. -* > 0 for linkup. +* new link state, speed, duplex, autoneg. * * @return +* On success: 0 * On failure: -1 -* Previous link state == linkdown: 0 -* Previous link state == linkup: 1 */
This was useful to detect the change in the status and log according. With current change KNI example will keep logging the link state.
Also in the KNI sample it periodically reads the link status from the device and applies it to the kni device, with current implementation it will keep updating the link status. Can we add a logic in the KNI sample so that update the KNI interface only if physical device link status changed?
Quoted 12 lines
lib/kni/rte_kni.h +1
-1__rte_experimental int -rte_kni_update_link (struct rte_kni *kni,unsigned int linkup); +rte_kni_update_link (struct rte_kni *kni,struct rte_eth_link *link);/** * Close KNI device. lib/kni/rte_kni_common.h +0
-0
lib/kni/rte_kni_common.h struct rte_kni_device_info { · line 139
Quoted 10 lines
lib/kni/rte_kni_common.h +7
-0@@ -130,10 +130,19 @@ struct rte_kni_device_info {uint8_t iova_mode; }; +struct rte_kni_link_info { +char name[RTE_KNI_NAMESIZE ]; +unsigned int speed; +unsigned char duplex; +unsigned char autoneg; +unsigned char status; +};
Should we prefer fixed size storage types "uint32_t speed" or "unsigned int", did you select current ones explicitly?
Quoted 10 lines
lib/kni/rte_kni_common.h +2
-0+#define KNI_DEVICE "kni"#define RTE_KNI_IOCTL_TEST _IOWR(0, 1, int)#define RTE_KNI_IOCTL_CREATE _IOWR(0, 2, struct rte_kni_device_info)#define RTE_KNI_IOCTL_RELEASE _IOWR(0, 3, struct rte_kni_device_info) +#define RTE_KNI_IOCTL_LINK _IOWR(0, 4, struct rte_kni_link_info)#endif /* _RTE_KNI_COMMON_H_ */
Hi Ferruh,
Thanks for the review. My comments inline. I'll send a new version later this week.
Quoted 83 lines · Ferruh Yigit
app/test/test_kni.c kni_change_mtu(uint16_t port_id, unsigned int
Quoted 29 lines · Igor Ryzhov
Current implementation doesn't allow us to update KNI carrier if the interface is not yet UP in kernel. It means that we can't use it in the same thread which is processing rte_kni_ops.config_network_if, which is very convenient, because it allows us to have correct carrier status of the interface right after we enabled it and we don't have to use any additional thread to track link status.
Propagating speed/duplex/autoneg to the kernel module also allows us to implement ethtool_ops.get_link_ksettings callback.
Suggested-by Dan Gora <[email protected]>Signed-off-by Igor Ryzhov <[email protected]>--- app/test/test_kni.c | 32 ++++++++++--------------- examples/kni/main.c | 2 +- kernel/linux/kni/compat.h | 4 ---- kernel/linux/kni/kni_dev.h | 5 ++++ kernel/linux/kni/kni_misc.c | 47 +++++++++++++++++++++++++++++++++++++ kernel/linux/kni/kni_net.c | 15 ------------ lib/kni/rte_kni.c | 38 ++++++++---------------------- lib/kni/rte_kni.h | 10 ++++---- lib/kni/rte_kni_common.h | 9 +++++++ 9 files changed, 89 insertions(+), 73 deletions(-)app/test/test_kni.c +0
-0@@ -125,6 +125,7 @@ kni_change_mtu(uint16_t port_id, unsigned int
new_mtu)Quoted 16 lines
app/test/test_kni.c +5
-0static int test_kni_link_change (void ) { +struct rte_eth_link link;int ret;int pid;@@ -135,42 +136,35 @@ test_kni_link_change(void) }if (pid ==0 ) { + link.link_speed =ETH_SPEED_NUM_10G ; + link.link_duplex =ETH_LINK_FULL_DUPLEX ; + link.link_autoneg =ETH_LINK_AUTONEG ; +printf ("Starting KNI Link status change tests.\n" );app/test/test_kni.c test_kni_link_change(void) · line 152
Quoted 10 lines
app/test/test_kni.c +2
-1if (system(IFCONFIG TEST_KNI_PORT" up") == -1) { ret =-1 ; goto error; } - ret =rte_kni_update_link (test_kni_ctx,1 ); + link.link_status =ETH_LINK_UP ; + ret =rte_kni_update_link (test_kni_ctx, &link);if (ret <0 ) { printf("Failed to change link state to Upret=%d.\n",
Quoted 15 lines
app/test/test_kni.c +0
-11ret); goto error; }rte_delay_ms (1000 ); -printf ("KNI: Set LINKUP, previous state=%d\n" , ret); - - ret =rte_kni_update_link (test_kni_ctx,0 ); -if (ret !=1 ) { -printf ( -"Failed! Previous link state should be 1, returned %d.\n" , - ret); - goto error; - } -rte_delay_ms (1000 ); -printf ("KNI: Set LINKDOWN, previous state=%d\n" , ret);app/test/test_kni.c test_kni_link_change(void)
Quoted 10 lines
app/test/test_kni.c +5
-4+printf ("KNI: Set LINKUP\n" ); - ret =rte_kni_update_link (test_kni_ctx,1 ); -if (ret !=0 ) { - printf( - "Failed! Previous link state should be 0, returned %d.\n", + link.link_status =ETH_LINK_DOWN ; + ret =rte_kni_update_link (test_kni_ctx, &link); +if (ret <0 ) { + printf("Failed to change link state to Down
Quoted 9 lines
ret=%d.\n",
app/test/test_kni.c test_kni_link_change(void) · line 155
Quoted 3 lines
app/test/test_kni.c +0
-0ret); goto error; }Is there a way to verify the link status of the KNI interface, to double check
setting link status succedded?
Yes, we can still read from the carrier file to check the current status. I'll add this to the test.
Quoted 150 lines
Quoted 14 lines
app/test/test_kni.c +1
-3-printf ("KNI: Set LINKUP, previous state=%d\n" , ret); - - ret =0 ;rte_delay_ms (1000 ); +printf ("KNI: Set LINKDOWN\n" ); error: if (system(IFCONFIG TEST_KNI_PORT" down") == -1)examples/kni/main.c +0
-0examples/kni/main.c monitor_all_ports_link_status(void *arg) · line 757
Quoted 3 lines
examples/kni/main.c +0
-0@@ -755,7 +755,7 @@ monitor_all_ports_link_status(void *arg) }for (i =0 ; i < p[portid]->nb_kni; i++) { prev =rte_kni_update_link(p[portid]->kni[i],
examples/kni/main.c monitor_all_ports_link_status(void *arg)
Quoted 3 lines
examples/kni/main.c +1
-1- link.link_status); + &link); log_link_state(p[portid]->kni[i], prev,&link);
kernel/linux/kni/kni_misc.c kni_ioctl_release(struct net *net, uint32_t
Quoted 38 lines
examples/kni/main.c +0
-0} }kernel/linux/kni/compat.h +0
-4@@ -61,10 +61,6 @@#define kni_sock_map_fd (s) sock_map_fd(s, 0)#endif -#if LINUX_VERSION_CODE >=KERNEL_VERSION (3 ,9 ,0 ) -#define HAVE_CHANGE_CARRIER_CB -#endif -#if LINUX_VERSION_CODE <KERNEL_VERSION (3 ,14 ,0 )#define ether_addr_copy (dst, src) memcpy(dst, src, ETH_ALEN)#endif kernel/linux/kni/kni_dev.h +5
-0@@ -88,6 +88,11 @@ struct kni_dev {void *alloc_va[MBUF_BURST_SZ ];struct task_struct *usr_tsk; + +/* correct when netif_carrier_ok */ +uint32_t speed; +uint8_t duplex; +uint8_t autoneg; };#ifdef HAVE_IOVA_TO_KVA_MAPPING_SUPPORT kernel/linux/kni/kni_misc.c +0
-0@@ -481,6 +481,50 @@ kni_ioctl_release(struct net *net, uint32_t
ioctl_num,Quoted 7 lines
kernel/linux/kni/kni_misc.c +4
-0return ret; } +static int +kni_ioctl_link (struct net *net,uint32_t ioctl_num, +unsigned long ioctl_param) +{kernel/linux/kni/kni_misc.c kni_ioctl_release(struct net *net, uint32_t ioctl_num,
Quoted 10 lines
kernel/linux/kni/kni_misc.c +10
-0+struct kni_net *knet =net_generic (net, kni_net_id); +int ret = -EINVAL ; +struct kni_dev *dev, *n; +struct rte_kni_link_info link_info; +struct net_device *netdev; + +if (_IOC_SIZE (ioctl_num) >sizeof (link_info)) +return -EINVAL ; + + if (copy_from_user(&link_info, (void *)ioctl_param,
sizeof(link_info)))kernel/linux/kni/kni_misc.c kni_ioctl_release(struct net *net, uint32_t ioctl_num,
Quoted 8 lines
kernel/linux/kni/kni_misc.c +8
-0+return -EFAULT ; + +if (strlen (link_info.name) ==0 ) +return -EINVAL ; + +down_read (&knet->kni_list_lock); +list_for_each_entry_safe (dev, n, &knet->kni_list_head, list) { + if (strncmp(dev->name, link_info.name, RTE_KNI_NAMESIZE)!= 0)
Quoted 14 lines
kernel/linux/kni/kni_misc.c +14
-0+continue ; + + netdev = dev->net_dev; + +if (link_info.status) { +netif_carrier_on (netdev); + + dev->speed = link_info.speed; + dev->duplex = link_info.duplex; + dev->autoneg = link_info.autoneg; + }else { +netif_carrier_off (netdev); + } +kernel/linux/kni/kni_misc.c kni_ioctl_release(struct net *net, uint32_t ioctl_num,
Quoted 10 lines
kernel/linux/kni/kni_misc.c +8
-0+ ret =0 ; +break ; + } +up_read (&knet->kni_list_lock); + +return ret; +} +static int kni_ioctl(struct inode *inode, uint32_t ioctl_num, unsigned long
ioctl_param)kernel/linux/kni/kni_misc.c kni_ioctl(struct inode *inode, uint32_t ioctl_num,
Quoted 2 lines
kernel/linux/kni/kni_misc.c +0
-0{@@ -502,6 +546,9 @@ kni_ioctl(struct inode *inode, uint32_t ioctl_num,unsigned long
ioctl_param)kernel/linux/kni/kni_net.c static const struct net_device_ops
Quoted 33 lines
kernel/linux/kni/kni_misc.c +3
-0case _IOC_NR (RTE_KNI_IOCTL_RELEASE ): ret =kni_ioctl_release (net, ioctl_num, ioctl_param);break ; +case _IOC_NR (RTE_KNI_IOCTL_LINK ): + ret =kni_ioctl_link (net, ioctl_num, ioctl_param); +break ;default :pr_debug ("IOCTL default\n" );break ;kernel/linux/kni/kni_net.c +0
-12@@ -778,18 +778,6 @@ kni_net_set_mac(struct net_device *netdev, void *p)return (ret ==0 ? req.result : ret); } -#ifdef HAVE_CHANGE_CARRIER_CB -static int -kni_net_change_carrier (struct net_device *dev,bool new_carrier) -{ -if (new_carrier) -netif_carrier_on (dev); -else -netif_carrier_off (dev); -return 0 ; -} -#endif -static const struct header_ops kni_net_header_ops = { .create = kni_net_header, .parse = eth_header_parse,@@ -808,9 +796,6 @@ static const struct net_device_ops
kni_net_netdev_ops= {
Quoted 11 lines
kernel/linux/kni/kni_net.c static const struct net_device_ops kni_net_netdev_ops = { · line 813
Quoted 6 lines
kernel/linux/kni/kni_net.c +0
-3.ndo_change_mtu = kni_net_change_mtu, .ndo_tx_timeout = kni_net_tx_timeout, .ndo_set_mac_address = kni_net_set_mac, -#ifdef HAVE_CHANGE_CARRIER_CB - .ndo_change_carrier = kni_net_change_carrier, -#endif What do you think keeping the 'carrier' interface? Even the API not using it, it
can be useful, what do you think?
We can keep it, but if people continue to write to the carrier file instead of using the API,
then speed/duplex/autoneg values will have unspecified values. We can reflect this in
the docs.
Quoted 55 lines
Quoted 55 lines
kernel/linux/kni/kni_net.c +0
-0}; static void kni_get_drvinfo(struct net_device *dev,lib/kni/rte_kni.c +9
-25@@ -784,43 +784,25 @@ rte_kni_unregister_handlers(struct rte_kni *kni) }int -rte_kni_update_link (struct rte_kni *kni,unsigned int linkup) +rte_kni_update_link (struct rte_kni *kni,struct rte_eth_link *link) { -char path[64 ]; -char old_carrier[2 ]; -const char *new_carrier; -int old_linkup; -int fd, ret; +struct rte_kni_link_info link_info;if (kni ==NULL )return -1 ; -snprintf (path,sizeof (path),"/sys/devices/virtual/net/%s/carrier" , - kni->name); +snprintf (link_info.name,RTE_KNI_NAMESIZE ,"%s" , kni->name); + link_info.speed = link->link_speed; + link_info.duplex = link->link_duplex; + link_info.autoneg = link->link_autoneg; + link_info.status = link->link_status; - fd =open (path,O_RDWR ); -if (fd ==-1 ) { -RTE_LOG (ERR ,KNI ,"Failed to open file: %s.\n" , path); +if (ioctl (kni_fd,RTE_KNI_IOCTL_LINK , &link_info) <0 ) { +RTE_LOG (ERR ,KNI ,"Fail to update KNI link\n" );return -1 ; } - ret =read (fd, old_carrier,2 ); -if (ret <1 ) { -close (fd); -return -1 ; - } - old_linkup = (old_carrier[0 ] =='1' ); - - new_carrier = linkup ?"1" :"0" ; - ret =write (fd, new_carrier,1 ); -if (ret <1 ) { -RTE_LOG (ERR ,KNI ,"Failed to write file: %s.\n" , path); -close (fd); -return -1 ; - }
Quoted 9 lines
lib/kni/rte_kni.c rte_kni_unregister_handlers(struct rte_kni *kni) · line 806
Quoted 5 lines
lib/kni/rte_kni.c +1
-3- -close (fd); -return old_linkup; +return 0 ; }Can you please add new API to KNI PMD too? To set the link up when port started.
I'll check KNI PMD and update.
Quoted 35 lines
lib/kni/rte_kni.h int rte_kni_unregister_handlers(struct rte_kni
Quoted 16 lines
lib/kni/rte_kni.c +0
-0void lib/kni/rte_kni.h +1
-0@@ -21,6 +21,7 @@#include <rte_memory.h> #include <rte_mempool.h> #include <rte_ether.h> +#include <rte_ethdev.h> #include <rte_kni_common.h> @@ -245,18 +246,15 @@ int rte_kni_unregister_handlers(struct rte_kni*kni);
Quoted 4 lines
lib/kni/rte_kni.h +0
-1* @param kni * pointer to struct rte_kni. * @param linkup -* New link state: lib/kni/rte_kni.h int rte_kni_unregister_handlers(struct rte_kni *kni); · line 254
Quoted 10 lines
lib/kni/rte_kni.h +2
-4-* 0 for linkdown. -* > 0 for linkup. +* new link state, speed, duplex, autoneg. * * @return +* On success: 0 * On failure: -1 -* Previous link state == linkdown: 0 -* Previous link state == linkup: 1 */ This was useful to detect the change in the status and log according. With current change KNI example will keep logging the link state.
Quoted 8 lines
Also in the KNI sample it periodically reads the link status from the device and
applies it to the kni device, with current implementation it will keep updating
the link status. Can we add a logic in the KNI sample so that update the KNI
interface only if physical device link status changed?
We can still read from the carrier file and return the old state if it's really needed.
I'll check the KNI sample code and try to find the best solution.
Quoted 16 lines
Quoted 16 lines
lib/kni/rte_kni.h +1
-1__rte_experimental int -rte_kni_update_link (struct rte_kni *kni,unsigned int linkup); +rte_kni_update_link (struct rte_kni *kni,struct rte_eth_link *link);/** * Close KNI device. lib/kni/rte_kni_common.h +0
-0@@ -130,10 +130,19 @@ struct rte_kni_device_info {uint8_t iova_mode; };
Quoted 12 lines
lib/kni/rte_kni_common.h struct rte_kni_device_info { · line 139
Quoted 7 lines
lib/kni/rte_kni_common.h +7
-0+struct rte_kni_link_info { +char name[RTE_KNI_NAMESIZE ]; +unsigned int speed; +unsigned char duplex; +unsigned char autoneg; +unsigned char status; +};Should we prefer fixed size storage types "
uint32_tspeed" or "unsigned int",
did you select current ones explicitly?
Sure, I'll update. Not sure why I chose it initially, it was a long time ago :)
Quoted 13 lines
Quoted 11 lines
lib/kni/rte_kni_common.h +2
-0+#define KNI_DEVICE "kni"#define RTE_KNI_IOCTL_TEST _IOWR(0, 1, int)#define RTE_KNI_IOCTL_CREATE _IOWR(0, 2, struct rte_kni_device_info)#define RTE_KNI_IOCTL_RELEASE _IOWR(0, 3, struct rte_kni_device_info) +#define RTE_KNI_IOCTL_LINK _IOWR(0, 4, struct rte_kni_link_info)#endif /* _RTE_KNI_COMMON_H_ */
PATCH v5 1/3 kni: rework rte_kni_update_link using ioctl
In reply to Igor RyzhovCurrent implementation doesn't allow us to update KNI carrier if the interface is not yet UP in kernel. It means that we can't use it in the same thread which is processing rte_kni_ops.config_network_if, which is very convenient, because it allows us to have correct carrier status of the interface right after we enabled it and we don't have to use any additional thread to track link status.
Propagating speed/duplex/autoneg to the kernel module also allows us to implement ethtool_ops.get_link_ksettings callback.
--- app/test/test_kni.c | 62 +++++++++++++++++++++++++++---------- examples/kni/main.c | 8 +++-- kernel/linux/kni/kni_dev.h | 5 +++ kernel/linux/kni/kni_misc.c | 47 ++++++++++++++++++++++++++++ lib/kni/rte_kni.c | 38 ++++++----------------- lib/kni/rte_kni.h | 12 +++---- lib/kni/rte_kni_common.h | 9 ++++++ 7 files changed, 126 insertions(+), 55 deletions(-)
app/test/test_kni.c +45 -17
@@ -122,9 +122,32 @@ kni_change_mtu(uint16_t port_id, unsigned int new_mtu)return 0 ; } +static int +kni_get_carrier (const char *name) +{ +FILE *fd; +char path[128 ]; +int carrier; + +snprintf (path,sizeof (path),"/sys/devices/virtual/net/%s/carrier" , + name); + fd =fopen (path,"r" ); +if (fd ==NULL ) +return -1 ; + +if (fscanf (fd,"%d" , &carrier) !=1 ) +return -1 ; + +fclose (fd); + +return carrier; +} +static int test_kni_link_change (void ) { +struct rte_eth_link link; +int carrier;int ret;int pid;
@@ -135,42 +158,47 @@ test_kni_link_change(void) }if (pid ==0 ) { + link.link_speed =ETH_SPEED_NUM_10G ; + link.link_duplex =ETH_LINK_FULL_DUPLEX ; + link.link_autoneg =ETH_LINK_AUTONEG ; +printf ("Starting KNI Link status change tests.\n" ); if (system(IFCONFIG TEST_KNI_PORT" up") == -1) { ret =-1 ; goto error; } - ret =rte_kni_update_link (test_kni_ctx,1 ); + link.link_status =ETH_LINK_UP ; + ret =rte_kni_update_link (test_kni_ctx, &link);if (ret <0 ) {printf ("Failed to change link state to Up ret=%d.\n" , ret); goto error; }rte_delay_ms (1000 ); -printf ("KNI: Set LINKUP, previous state=%d\n" , ret); - - ret =rte_kni_update_link (test_kni_ctx,0 ); -if (ret !=1 ) { -printf ( -"Failed! Previous link state should be 1, returned %d.\n" , - ret); + carrier =kni_get_carrier (TEST_KNI_PORT ); +if (carrier !=1 ) { +printf ("Carrier did not change to Up in kernel.\n" ); + ret =-1 ; goto error; } -rte_delay_ms (1000 ); -printf ("KNI: Set LINKDOWN, previous state=%d\n" , ret); +printf ("KNI: Set LINKUP\n" ); - ret =rte_kni_update_link (test_kni_ctx,1 ); -if (ret !=0 ) { -printf ( -"Failed! Previous link state should be 0, returned %d.\n" , + link.link_status =ETH_LINK_DOWN ; + ret =rte_kni_update_link (test_kni_ctx, &link); +if (ret <0 ) { +printf ("Failed to change link state to Down ret=%d.\n" , ret); goto error; } -printf ("KNI: Set LINKUP, previous state=%d\n" , ret); - - ret =0 ;rte_delay_ms (1000 ); + carrier =kni_get_carrier (TEST_KNI_PORT ); +if (carrier !=0 ) { +printf ("Carrier did not change to Down in kernel.\n" ); + ret =-1 ; + goto error; + } +printf ("KNI: Set LINKDOWN\n" ); error: if (system(IFCONFIG TEST_KNI_PORT" down") == -1)
examples/kni/main.c +5 -3
@@ -85,6 +85,7 @@ struct kni_port_params {unsigned lcore_tx;/* lcore ID for TX */ uint32_t nb_lcore_k;/* Number of lcores for KNI multi kernel threads */ uint32_t nb_kni;/* Number of KNI devices to be created */ +uint8_t link_status;/* Current link status of the port */ unsigned lcore_k[KNI_MAX_KTHREAD ];/* lcore ID list for kthreads */ struct rte_kni *kni[KNI_MAX_KTHREAD ];/* KNI context pointers */ } __rte_cache_aligned;
@@ -720,7 +721,7 @@ log_link_state(struct rte_kni *kni, int prev, struct rte_eth_link *link)rte_eth_link_to_str (link_status_text,sizeof (link_status_text), link);if (prev != link->link_status) -RTE_LOG (INFO ,APP ,"%s NIC %s" , +RTE_LOG (INFO ,APP ,"%s NIC %s\n" ,rte_kni_get_name (kni), link_status_text); }
@@ -754,9 +755,10 @@ monitor_all_ports_link_status(void *arg)continue ; }for (i =0 ; i < p[portid]->nb_kni; i++) { - prev =rte_kni_update_link (p[portid]->kni[i], - link.link_status); +rte_kni_update_link (p[portid]->kni[i], &link); + prev = p[portid]->link_status;log_link_state (p[portid]->kni[i], prev, &link); + p[portid]->link_status = link.link_status; } } }
kernel/linux/kni/kni_dev.h +5 -0
@@ -88,6 +88,11 @@ struct kni_dev {void *alloc_va[MBUF_BURST_SZ ];struct task_struct *usr_tsk; + +/* correct when netif_carrier_ok */ +uint32_t speed; +uint8_t duplex; +uint8_t autoneg; };#ifdef HAVE_IOVA_TO_KVA_MAPPING_SUPPORT
kernel/linux/kni/kni_misc.c +47 -0
59 lines not on this page · raw message
lib/kni/rte_kni.c +10 -28
@@ -784,43 +784,25 @@ rte_kni_unregister_handlers(struct rte_kni *kni) }int -rte_kni_update_link (struct rte_kni *kni,unsigned int linkup) +rte_kni_update_link (struct rte_kni *kni,struct rte_eth_link *link) { -char path[64 ]; -char old_carrier[2 ]; -const char *new_carrier; -int old_linkup; -int fd, ret; +struct rte_kni_link_info link_info;if (kni ==NULL )return -1 ; -snprintf (path,sizeof (path),"/sys/devices/virtual/net/%s/carrier" , - kni->name); +snprintf (link_info.name,RTE_KNI_NAMESIZE ,"%s" , kni->name); + link_info.speed = link->link_speed; + link_info.duplex = link->link_duplex; + link_info.autoneg = link->link_autoneg; + link_info.status = link->link_status; - fd =open (path,O_RDWR ); -if (fd ==-1 ) { -RTE_LOG (ERR ,KNI ,"Failed to open file: %s.\n" , path); +if (ioctl (kni_fd,RTE_KNI_IOCTL_LINK , &link_info) <0 ) { +RTE_LOG (ERR ,KNI ,"Fail to update KNI link\n" );return -1 ; } - ret =read (fd, old_carrier,2 ); -if (ret <1 ) { -close (fd); -return -1 ; - } - old_linkup = (old_carrier[0 ] =='1' ); - - new_carrier = linkup ?"1" :"0" ; - ret =write (fd, new_carrier,1 ); -if (ret <1 ) { -RTE_LOG (ERR ,KNI ,"Failed to write file: %s.\n" , path); -close (fd); -return -1 ; - } - -close (fd); -return old_linkup; +return 0 ; }void
lib/kni/rte_kni.h +5 -7
@@ -21,6 +21,7 @@#include <rte_memory.h> #include <rte_mempool.h> #include <rte_ether.h> +#include <rte_ethdev.h> #include <rte_kni_common.h>
@@ -244,19 +245,16 @@ int rte_kni_unregister_handlers(struct rte_kni *kni);* * @param kni * pointer to struct rte_kni. -* @param linkup -* New link state: -* 0 for linkdown. -* > 0 for linkup. +* @param link +* new link state, speed, duplex, autoneg. * * @return +* On success: 0 * On failure: -1 -* Previous link state == linkdown: 0 -* Previous link state == linkup: 1 */ __rte_experimental int -rte_kni_update_link (struct rte_kni *kni,unsigned int linkup); +rte_kni_update_link (struct rte_kni *kni,struct rte_eth_link *link);/** * Close KNI device.
lib/kni/rte_kni_common.h +9 -0
@@ -130,10 +130,19 @@ struct rte_kni_device_info { uint8_t iova_mode; }; +struct rte_kni_link_info { +char name[RTE_KNI_NAMESIZE ]; +uint32_t speed; +uint8_t duplex; +uint8_t autoneg; +uint8_t status; +}; +#define KNI_DEVICE "kni"#define RTE_KNI_IOCTL_TEST _IOWR(0, 1, int)#define RTE_KNI_IOCTL_CREATE _IOWR(0, 2, struct rte_kni_device_info)#define RTE_KNI_IOCTL_RELEASE _IOWR(0, 3, struct rte_kni_device_info) +#define RTE_KNI_IOCTL_LINK _IOWR(0, 4, struct rte_kni_link_info)#endif /* _RTE_KNI_COMMON_H_ */
Signature · 1 line
2.33.0
PATCH v5 2/3 kni: implement basic get_link_ksettings callback
It allows inspecting link parameters using ethtool.
--- kernel/linux/kni/kni_net.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
kernel/linux/kni/kni_net.c +25 -0
@@ -820,9 +820,34 @@ static void kni_get_drvinfo(struct net_device *dev,strlcpy (info->driver,"kni" ,sizeof (info->driver)); } +#ifdef ETHTOOL_GLINKSETTINGS +static int kni_get_link_ksettings (struct net_device *dev, +struct ethtool_link_ksettings *settings) +{ +struct kni_dev *kni =netdev_priv (dev); + + settings->base.port =PORT_OTHER ; + +if (netif_carrier_ok (dev)) { + settings->base.speed = kni->speed; + settings->base.duplex = kni->duplex; + settings->base.autoneg = kni->autoneg; + }else { + settings->base.speed =SPEED_UNKNOWN ; + settings->base.duplex =DUPLEX_UNKNOWN ; + settings->base.autoneg =AUTONEG_ENABLE ; + } + +return 0 ; +} +#endif +static const struct ethtool_ops kni_net_ethtool_ops = { .get_drvinfo = kni_get_drvinfo, .get_link = ethtool_op_get_link, +#ifdef ETHTOOL_GLINKSETTINGS + .get_link_ksettings = kni_get_link_ksettings, +#endif };void
Signature · 1 line
2.33.0
PATCH v5 3/3 app/test: fix return value of test_kni_link_change
In reply to Igor RyzhovIf the child process returns -1, WEXITSTATUS converts to 255 because it takes only 8 least significant bits. As a result, the test is not considered failed when it should.
--- app/test/test_kni.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
app/test/test_kni.c +1 -1
@@ -214,7 +214,7 @@ test_kni_link_change(void) p_ret =waitpid (pid, &status,WNOHANG );if (p_ret !=0 ) {if (WIFEXITED (status)) -return WEXITSTATUS (status); +return WEXITSTATUS (status) ?-1 :0 ;return -1 ; }rte_delay_ms (10 );
Signature · 1 line
2.33.0
Quoted 35 lines · On Thu, 26 Aug 2021 18:19:09 +0300 Igor Ryzhov <[email protected]> wrote:
kernel/linux/kni/kni_misc.c +34
-0+static int +kni_ioctl_link (struct net *net,uint32_t ioctl_num, +unsigned long ioctl_param) +{ +struct kni_net *knet =net_generic (net, kni_net_id); +int ret = -EINVAL ; +struct kni_dev *dev, *n; +struct rte_kni_link_info link_info; +struct net_device *netdev; + +if (_IOC_SIZE (ioctl_num) >sizeof (link_info)) +return -EINVAL ; + +if (copy_from_user (&link_info, (void *)ioctl_param,sizeof (link_info))) +return -EFAULT ; + +if (strlen (link_info.name) ==0 ) +return -EINVAL ; + +down_read (&knet->kni_list_lock); +list_for_each_entry_safe (dev, n, &knet->kni_list_head, list) { +if (strncmp (dev->name, link_info.name,RTE_KNI_NAMESIZE ) !=0 ) +continue ; + + netdev = dev->net_dev; + +if (link_info.status) { +netif_carrier_on (netdev); + + dev->speed = link_info.speed; + dev->duplex = link_info.duplex; + dev->autoneg = link_info.autoneg; + }else { +netif_carrier_off (netdev);
kernel/linux/kni/kni_misc.c kni_ioctl_release(struct net *net, uint32_t ioctl_num, · line 527
Quoted 10 lines
kernel/linux/kni/kni_misc.c +10
-0+ } + + ret =0 ; +break ; + } +up_read (&knet->kni_list_lock); + +return ret; +} +
You need to be using the RTNL mutex in KNI here (and probably elsewhere). The use of semaphore for list lock should also be replaced by a mutex.
The KNI driver was written long ago and was never reviewed by people knowledgeable about kernel networking. That is one reason IMHO KNI should not be used in production systems.
Could you please clarify where exactly do I need to use rtnl lock? From what I understand, netif_carrier_on/off can be called without the lock.
Quoted 59 lines · Stephen Hemminger
Quoted 5 lines · On Thu, 26 Aug 2021 18:19:09 +0300 Igor Ryzhov <[email protected]> wrote:
kernel/linux/kni/kni_misc.c +4
-0+static int +kni_ioctl_link (struct net *net,uint32_t ioctl_num, +unsigned long ioctl_param) +{kernel/linux/kni/kni_misc.c kni_ioctl_release(struct net *net, uint32_t ioctl_num,
Quoted 10 lines
kernel/linux/kni/kni_misc.c +10
-0+struct kni_net *knet =net_generic (net, kni_net_id); +int ret = -EINVAL ; +struct kni_dev *dev, *n; +struct rte_kni_link_info link_info; +struct net_device *netdev; + +if (_IOC_SIZE (ioctl_num) >sizeof (link_info)) +return -EINVAL ; + + if (copy_from_user(&link_info, (void *)ioctl_param,
sizeof(link_info)))kernel/linux/kni/kni_misc.c kni_ioctl_release(struct net *net, uint32_t ioctl_num,
Quoted 8 lines
kernel/linux/kni/kni_misc.c +8
-0+return -EFAULT ; + +if (strlen (link_info.name) ==0 ) +return -EINVAL ; + +down_read (&knet->kni_list_lock); +list_for_each_entry_safe (dev, n, &knet->kni_list_head, list) { + if (strncmp(dev->name, link_info.name, RTE_KNI_NAMESIZE)!= 0)
Quoted 12 lines
kernel/linux/kni/kni_misc.c +12
-0+continue ; + + netdev = dev->net_dev; + +if (link_info.status) { +netif_carrier_on (netdev); + + dev->speed = link_info.speed; + dev->duplex = link_info.duplex; + dev->autoneg = link_info.autoneg; + }else { +netif_carrier_off (netdev);kernel/linux/kni/kni_misc.c kni_ioctl_release(struct net *net, uint32_t ioctl_num, · line 527
Quoted 10 lines
kernel/linux/kni/kni_misc.c +10
-0+ } + + ret =0 ; +break ; + } +up_read (&knet->kni_list_lock); + +return ret; +} +You need to be using the RTNL mutex in KNI here (and probably elsewhere). The use of semaphore for list lock should also be replaced by a mutex.
The KNI driver was written long ago and was never reviewed by people knowledgeable about kernel networking. That is one reason IMHO KNI should not be used in production systems.
Quoted 2 lines · On Thu, 26 Aug 2021 20:46:47 +0300 Igor Ryzhov <[email protected]> wrote:
Could you please clarify where exactly do I need to use rtnl lock? From what I understand, netif_carrier_on/off can be called without the lock.
Just a basic concern. The new stuff looks ok.
If you follow what current upstream virtio is doing, it should be safe.
See drivers/net/virtio/virtio_net.c, looks like more is needed?
Do you call ethtool_validate_speed() and ethtool_validate_duplex()?
Also, in virtio the driver does stop/wakeup of tx queues on carrier change.
Quoted 11 lines · Stephen Hemminger
Quoted 2 lines · On Thu, 26 Aug 2021 20:46:47 +0300 Igor Ryzhov <[email protected]> wrote:
Could you please clarify where exactly do I need to use rtnl lock? From what I understand, netif_carrier_on/off can be called without the
lock.
Just a basic concern. The new stuff looks ok.
If you follow what current upstream virtio is doing, it should be safe.See
drivers/net/virtio/virtio_net.c, looks like more is needed?
Thanks for the suggestion, I looked at it.
Quoted 2 lines
Do you call
ethtool_validate_speed()andethtool_validate_duplex()?
The problem with those functions is that they are only available since kernel version 4.6 and currently we have to also support 4.4. I don't think we need to introduce more compatibility code, as nothing really bad happens if the developer provides some invalued values. The worst thing is that ethtool will show weird speed or unknown duplex.
Quoted 3 lines
Also, in virtio the driver does stop/wakeup of tx queues on carrier change.
This can be added for sure, but this improvement is not actually related to my patch. We don't currently stop kernel's tx queue when the link is down and I don't change that behavior. The code change is trivial but I'll need to
find some time to test that everything works fine, so let's consider it a separate thing, please.
PATCH v6 1/3 kni: rework rte_kni_update_link using ioctl
In reply to Igor RyzhovCurrent implementation doesn't allow us to update KNI carrier if the interface is not yet UP in kernel. It means that we can't use it in the same thread which is processing rte_kni_ops.config_network_if, which is very convenient, because it allows us to have correct carrier status of the interface right after we enabled it and we don't have to use any additional thread to track link status.
Propagating speed/duplex/autoneg to the kernel module also allows us to implement ethtool_ops.get_link_ksettings callback.
--- app/test/test_kni.c | 62 +++++++++++++++++++++++++++---------- examples/kni/main.c | 8 +++-- kernel/linux/kni/kni_dev.h | 5 +++ kernel/linux/kni/kni_misc.c | 47 ++++++++++++++++++++++++++++ lib/kni/rte_kni.c | 41 ++++++------------------ lib/kni/rte_kni.h | 12 +++---- lib/kni/rte_kni_common.h | 9 ++++++ 7 files changed, 126 insertions(+), 58 deletions(-)
app/test/test_kni.c +45 -17
@@ -122,9 +122,32 @@ kni_change_mtu(uint16_t port_id, unsigned int new_mtu)return 0 ; } +static int +kni_get_carrier (const char *name) +{ +FILE *fd; +char path[128 ]; +int carrier; + +snprintf (path,sizeof (path),"/sys/devices/virtual/net/%s/carrier" , + name); + fd =fopen (path,"r" ); +if (fd ==NULL ) +return -1 ; + +if (fscanf (fd,"%d" , &carrier) !=1 ) +return -1 ; + +fclose (fd); + +return carrier; +} +static int test_kni_link_change (void ) { +struct rte_eth_link link; +int carrier;int ret;int pid;
@@ -135,42 +158,47 @@ test_kni_link_change(void) }if (pid ==0 ) { + link.link_speed =ETH_SPEED_NUM_10G ; + link.link_duplex =ETH_LINK_FULL_DUPLEX ; + link.link_autoneg =ETH_LINK_AUTONEG ; +printf ("Starting KNI Link status change tests.\n" ); if (system(IFCONFIG TEST_KNI_PORT" up") == -1) { ret =-1 ; goto error; } - ret =rte_kni_update_link (test_kni_ctx,1 ); + link.link_status =ETH_LINK_UP ; + ret =rte_kni_update_link (test_kni_ctx, &link);if (ret <0 ) {printf ("Failed to change link state to Up ret=%d.\n" , ret); goto error; }rte_delay_ms (1000 ); -printf ("KNI: Set LINKUP, previous state=%d\n" , ret); - - ret =rte_kni_update_link (test_kni_ctx,0 ); -if (ret !=1 ) { -printf ( -"Failed! Previous link state should be 1, returned %d.\n" , - ret); + carrier =kni_get_carrier (TEST_KNI_PORT ); +if (carrier !=1 ) { +printf ("Carrier did not change to Up in kernel.\n" ); + ret =-1 ; goto error; } -rte_delay_ms (1000 ); -printf ("KNI: Set LINKDOWN, previous state=%d\n" , ret); +printf ("KNI: Set LINKUP\n" ); - ret =rte_kni_update_link (test_kni_ctx,1 ); -if (ret !=0 ) { -printf ( -"Failed! Previous link state should be 0, returned %d.\n" , + link.link_status =ETH_LINK_DOWN ; + ret =rte_kni_update_link (test_kni_ctx, &link); +if (ret <0 ) { +printf ("Failed to change link state to Down ret=%d.\n" , ret); goto error; } -printf ("KNI: Set LINKUP, previous state=%d\n" , ret); - - ret =0 ;rte_delay_ms (1000 ); + carrier =kni_get_carrier (TEST_KNI_PORT ); +if (carrier !=0 ) { +printf ("Carrier did not change to Down in kernel.\n" ); + ret =-1 ; + goto error; + } +printf ("KNI: Set LINKDOWN\n" ); error: if (system(IFCONFIG TEST_KNI_PORT" down") == -1)
examples/kni/main.c +5 -3
@@ -85,6 +85,7 @@ struct kni_port_params {unsigned lcore_tx;/* lcore ID for TX */ uint32_t nb_lcore_k;/* Number of lcores for KNI multi kernel threads */ uint32_t nb_kni;/* Number of KNI devices to be created */ +uint8_t link_status;/* Current link status of the port */ unsigned lcore_k[KNI_MAX_KTHREAD ];/* lcore ID list for kthreads */ struct rte_kni *kni[KNI_MAX_KTHREAD ];/* KNI context pointers */ } __rte_cache_aligned;
@@ -720,7 +721,7 @@ log_link_state(struct rte_kni *kni, int prev, struct rte_eth_link *link)rte_eth_link_to_str (link_status_text,sizeof (link_status_text), link);if (prev != link->link_status) -RTE_LOG (INFO ,APP ,"%s NIC %s" , +RTE_LOG (INFO ,APP ,"%s NIC %s\n" ,rte_kni_get_name (kni), link_status_text); }
@@ -754,9 +755,10 @@ monitor_all_ports_link_status(void *arg)continue ; }for (i =0 ; i < p[portid]->nb_kni; i++) { - prev =rte_kni_update_link (p[portid]->kni[i], - link.link_status); +rte_kni_update_link (p[portid]->kni[i], &link); + prev = p[portid]->link_status;log_link_state (p[portid]->kni[i], prev, &link); + p[portid]->link_status = link.link_status; } } }
kernel/linux/kni/kni_dev.h +5 -0
@@ -88,6 +88,11 @@ struct kni_dev {void *alloc_va[MBUF_BURST_SZ ];struct task_struct *usr_tsk; + +/* correct when netif_carrier_ok */ +uint32_t speed; +uint8_t duplex; +uint8_t autoneg; };#ifdef HAVE_IOVA_TO_KVA_MAPPING_SUPPORT
kernel/linux/kni/kni_misc.c +47 -0
59 lines not on this page · raw message
lib/kni/rte_kni.c +10 -31
56 lines not on this page · raw message
lib/kni/rte_kni.h +5 -7
@@ -21,6 +21,7 @@#include <rte_memory.h> #include <rte_mempool.h> #include <rte_ether.h> +#include <rte_ethdev.h> #include <rte_kni_common.h>
@@ -244,19 +245,16 @@ int rte_kni_unregister_handlers(struct rte_kni *kni);* * @param kni * pointer to struct rte_kni. -* @param linkup -* New link state: -* 0 for linkdown. -* > 0 for linkup. +* @param link +* new link state, speed, duplex, autoneg. * * @return +* On success: 0 * On failure: -1 -* Previous link state == linkdown: 0 -* Previous link state == linkup: 1 */ __rte_experimental int -rte_kni_update_link (struct rte_kni *kni,unsigned int linkup); +rte_kni_update_link (struct rte_kni *kni,struct rte_eth_link *link);/** * Close KNI device.
lib/kni/rte_kni_common.h +9 -0
@@ -130,10 +130,19 @@ struct rte_kni_device_info { uint8_t iova_mode; }; +struct rte_kni_link_info { +char name[RTE_KNI_NAMESIZE ]; +uint32_t speed; +uint8_t duplex; +uint8_t autoneg; +uint8_t status; +}; +#define KNI_DEVICE "kni"#define RTE_KNI_IOCTL_TEST _IOWR(0, 1, int)#define RTE_KNI_IOCTL_CREATE _IOWR(0, 2, struct rte_kni_device_info)#define RTE_KNI_IOCTL_RELEASE _IOWR(0, 3, struct rte_kni_device_info) +#define RTE_KNI_IOCTL_LINK _IOWR(0, 4, struct rte_kni_link_info)#endif /* _RTE_KNI_COMMON_H_ */
Signature · 1 line
2.33.0
PATCH v6 2/3 kni: implement basic get_link_ksettings callback
It allows inspecting link parameters using ethtool.
--- kernel/linux/kni/kni_net.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
kernel/linux/kni/kni_net.c +25 -0
@@ -820,9 +820,34 @@ static void kni_get_drvinfo(struct net_device *dev,strlcpy (info->driver,"kni" ,sizeof (info->driver)); } +#ifdef ETHTOOL_GLINKSETTINGS +static int kni_get_link_ksettings (struct net_device *dev, +struct ethtool_link_ksettings *settings) +{ +struct kni_dev *kni =netdev_priv (dev); + + settings->base.port =PORT_OTHER ; + +if (netif_carrier_ok (dev)) { + settings->base.speed = kni->speed; + settings->base.duplex = kni->duplex; + settings->base.autoneg = kni->autoneg; + }else { + settings->base.speed =SPEED_UNKNOWN ; + settings->base.duplex =DUPLEX_UNKNOWN ; + settings->base.autoneg =AUTONEG_ENABLE ; + } + +return 0 ; +} +#endif +static const struct ethtool_ops kni_net_ethtool_ops = { .get_drvinfo = kni_get_drvinfo, .get_link = ethtool_op_get_link, +#ifdef ETHTOOL_GLINKSETTINGS + .get_link_ksettings = kni_get_link_ksettings, +#endif };void
Signature · 1 line
2.33.0
PATCH v6 3/3 app/test: fix return value of test_kni_link_change
In reply to Igor RyzhovIf the child process returns -1, WEXITSTATUS converts to 255 because it takes only 8 least significant bits. As a result, the test is not considered failed when it should.
--- app/test/test_kni.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
app/test/test_kni.c +1 -1
@@ -214,7 +214,7 @@ test_kni_link_change(void) p_ret =waitpid (pid, &status,WNOHANG );if (p_ret !=0 ) {if (WIFEXITED (status)) -return WEXITSTATUS (status); +return WEXITSTATUS (status) ?-1 :0 ;return -1 ; }rte_delay_ms (10 );
Signature · 1 line
2.33.0
Quoted 7 lines · On Mon, 30 Aug 2021 17:27:29 +0300 Igor Ryzhov <[email protected]> wrote:
Current implementation doesn't allow us to update KNI carrier if the interface is not yet UP in kernel. It means that we can't use it in the same thread which is processing rte_kni_ops.config_network_if, which is very convenient, because it allows us to have correct carrier status of the interface right after we enabled it and we don't have to use any additional thread to track link status.
Quoted 5 lines
Propagating speed/duplex/autoneg to the kernel module also allows us to implement ethtool_ops.get_link_ksettings callback.
Suggested-by Dan Gora <[email protected]>Signed-off-by Igor Ryzhov <[email protected]>
Marking this patch as rejected because KNI is marked as deprecated and this goes into the "won't fix" category.
The link handling in KNI was always a botch. It violated the kernel locking (see calling usermode helper with RTNL held); and was fundamentally flawed. That was one of the reasons KNI never made it upstream and was marked deprecated.