* Re: [dpdk-dev] [PATCH v2] kni: rework rte_kni_update_link using ioctl
2019-09-24 19:33 ` [dpdk-dev] [PATCH v2] " Igor Ryzhov
@ 2019-09-24 20:37 ` Aaron Conole
2019-09-25 9:00 ` Igor Ryzhov
2019-09-25 9:36 ` [dpdk-dev] [PATCH v3] " Igor Ryzhov
2021-07-04 16:06 ` [dpdk-dev] [PATCH v4 1/2] " Igor Ryzhov
2 siblings, 1 reply; 27+ messages in thread
From: Aaron Conole @ 2019-09-24 20:37 UTC (permalink / raw)
To: Igor Ryzhov; +Cc: dev
Igor Ryzhov <iryzhov@nfware.com> writes:
> 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 <iryzhov@nfware.com>
> ---
> 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(-)
>
> diff --git a/kernel/linux/kni/compat.h b/kernel/linux/kni/compat.h
> index fe0ee55e7..e0a491bcd 100644
> --- a/kernel/linux/kni/compat.h
> +++ b/kernel/linux/kni/compat.h
> @@ -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
> diff --git a/kernel/linux/kni/kni_misc.c b/kernel/linux/kni/kni_misc.c
> index aeb275329..9bcba68c8 100644
> --- a/kernel/linux/kni/kni_misc.c
> +++ b/kernel/linux/kni/kni_misc.c
> @@ -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;
> diff --git a/kernel/linux/kni/kni_net.c b/kernel/linux/kni/kni_net.c
> index 7bd3a9f1e..cd852eea3 100644
> --- a/kernel/linux/kni/kni_net.c
> +++ b/kernel/linux/kni/kni_net.c
> @@ -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,
> diff --git a/lib/librte_eal/linux/eal/include/rte_kni_common.h b/lib/librte_eal/linux/eal/include/rte_kni_common.h
> index 70992d835..07a10dd93 100644
> --- a/lib/librte_eal/linux/eal/include/rte_kni_common.h
> +++ b/lib/librte_eal/linux/eal/include/rte_kni_common.h
> @@ -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_ */
> diff --git a/lib/librte_kni/rte_kni.c b/lib/librte_kni/rte_kni.c
> index 521db27c4..bdea03d5c 100644
> --- a/lib/librte_kni/rte_kni.c
> +++ b/lib/librte_kni/rte_kni.c
> @@ -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.
> 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
> diff --git a/lib/librte_kni/rte_kni.h b/lib/librte_kni/rte_kni.h
> index b22446fa7..7e1cce1e0 100644
> --- a/lib/librte_kni/rte_kni.h
> +++ b/lib/librte_kni/rte_kni.h
> @@ -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
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [dpdk-dev] [PATCH v2] kni: rework rte_kni_update_link using ioctl
2019-09-24 20:37 ` Aaron Conole
@ 2019-09-25 9:00 ` Igor Ryzhov
0 siblings, 0 replies; 27+ messages in thread
From: Igor Ryzhov @ 2019-09-25 9:00 UTC (permalink / raw)
To: Aaron Conole; +Cc: dev
Sure, my bad, sorry. Will send v3.
On Tue, Sep 24, 2019 at 11:37 PM Aaron Conole <aconole@redhat.com> wrote:
> Igor Ryzhov <iryzhov@nfware.com> writes:
>
> > 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 <iryzhov@nfware.com>
> > ---
> > 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(-)
> >
> > diff --git a/kernel/linux/kni/compat.h b/kernel/linux/kni/compat.h
> > index fe0ee55e7..e0a491bcd 100644
> > --- a/kernel/linux/kni/compat.h
> > +++ b/kernel/linux/kni/compat.h
> > @@ -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
> > diff --git a/kernel/linux/kni/kni_misc.c b/kernel/linux/kni/kni_misc.c
> > index aeb275329..9bcba68c8 100644
> > --- a/kernel/linux/kni/kni_misc.c
> > +++ b/kernel/linux/kni/kni_misc.c
> > @@ -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;
> > diff --git a/kernel/linux/kni/kni_net.c b/kernel/linux/kni/kni_net.c
> > index 7bd3a9f1e..cd852eea3 100644
> > --- a/kernel/linux/kni/kni_net.c
> > +++ b/kernel/linux/kni/kni_net.c
> > @@ -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,
> > diff --git a/lib/librte_eal/linux/eal/include/rte_kni_common.h
> b/lib/librte_eal/linux/eal/include/rte_kni_common.h
> > index 70992d835..07a10dd93 100644
> > --- a/lib/librte_eal/linux/eal/include/rte_kni_common.h
> > +++ b/lib/librte_eal/linux/eal/include/rte_kni_common.h
> > @@ -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_ */
> > diff --git a/lib/librte_kni/rte_kni.c b/lib/librte_kni/rte_kni.c
> > index 521db27c4..bdea03d5c 100644
> > --- a/lib/librte_kni/rte_kni.c
> > +++ b/lib/librte_kni/rte_kni.c
> > @@ -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.
>
> > 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
> > diff --git a/lib/librte_kni/rte_kni.h b/lib/librte_kni/rte_kni.h
> > index b22446fa7..7e1cce1e0 100644
> > --- a/lib/librte_kni/rte_kni.h
> > +++ b/lib/librte_kni/rte_kni.h
> > @@ -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
>
^ permalink raw reply [flat|nested] 27+ messages in thread
* [dpdk-dev] [PATCH v3] kni: rework rte_kni_update_link using ioctl
2019-09-24 19:33 ` [dpdk-dev] [PATCH v2] " Igor Ryzhov
2019-09-24 20:37 ` Aaron Conole
@ 2019-09-25 9:36 ` Igor Ryzhov
2019-10-14 16:10 ` Ferruh Yigit
2021-07-04 16:06 ` [dpdk-dev] [PATCH v4 1/2] " Igor Ryzhov
2 siblings, 1 reply; 27+ messages in thread
From: Igor Ryzhov @ 2019-09-25 9:36 UTC (permalink / raw)
To: dev; +Cc: aconole
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 <iryzhov@nfware.com>
---
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(-)
diff --git a/kernel/linux/kni/compat.h b/kernel/linux/kni/compat.h
index fe0ee55e7..e0a491bcd 100644
--- a/kernel/linux/kni/compat.h
+++ b/kernel/linux/kni/compat.h
@@ -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
diff --git a/kernel/linux/kni/kni_misc.c b/kernel/linux/kni/kni_misc.c
index aeb275329..9bcba68c8 100644
--- a/kernel/linux/kni/kni_misc.c
+++ b/kernel/linux/kni/kni_misc.c
@@ -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;
diff --git a/kernel/linux/kni/kni_net.c b/kernel/linux/kni/kni_net.c
index 7bd3a9f1e..cd852eea3 100644
--- a/kernel/linux/kni/kni_net.c
+++ b/kernel/linux/kni/kni_net.c
@@ -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,
diff --git a/lib/librte_eal/linux/eal/include/rte_kni_common.h b/lib/librte_eal/linux/eal/include/rte_kni_common.h
index 70992d835..07a10dd93 100644
--- a/lib/librte_eal/linux/eal/include/rte_kni_common.h
+++ b/lib/librte_eal/linux/eal/include/rte_kni_common.h
@@ -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_ */
diff --git a/lib/librte_kni/rte_kni.c b/lib/librte_kni/rte_kni.c
index 521db27c4..f80b97e2f 100644
--- a/lib/librte_kni/rte_kni.c
+++ b/lib/librte_kni/rte_kni.c
@@ -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
diff --git a/lib/librte_kni/rte_kni.h b/lib/librte_kni/rte_kni.h
index b22446fa7..7e1cce1e0 100644
--- a/lib/librte_kni/rte_kni.h
+++ b/lib/librte_kni/rte_kni.h
@@ -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
--
2.23.0
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [dpdk-dev] [PATCH v3] kni: rework rte_kni_update_link using ioctl
2019-09-25 9:36 ` [dpdk-dev] [PATCH v3] " Igor Ryzhov
@ 2019-10-14 16:10 ` Ferruh Yigit
2019-10-14 16:17 ` Ferruh Yigit
0 siblings, 1 reply; 27+ messages in thread
From: Ferruh Yigit @ 2019-10-14 16:10 UTC (permalink / raw)
To: Igor Ryzhov, dev; +Cc: aconole, Dan Gora
On 9/25/2019 10:36 AM, Igor Ryzhov 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.
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?
>
> Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
<...>
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [dpdk-dev] [PATCH v3] kni: rework rte_kni_update_link using ioctl
2019-10-14 16:10 ` Ferruh Yigit
@ 2019-10-14 16:17 ` Ferruh Yigit
2019-10-14 19:01 ` Dan Gora
0 siblings, 1 reply; 27+ messages in thread
From: Ferruh Yigit @ 2019-10-14 16:17 UTC (permalink / raw)
To: Igor Ryzhov, dev; +Cc: aconole, Dan Gora
On 10/14/2019 5:10 PM, Ferruh Yigit wrote:
> On 9/25/2019 10:36 AM, Igor Ryzhov 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.
>
> 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?
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"
>
>>
>> Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
>
> <...>
>
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [dpdk-dev] [PATCH v3] kni: rework rte_kni_update_link using ioctl
2019-10-14 16:17 ` Ferruh Yigit
@ 2019-10-14 19:01 ` Dan Gora
2019-10-14 20:55 ` Dan Gora
0 siblings, 1 reply; 27+ messages in thread
From: Dan Gora @ 2019-10-14 19:01 UTC (permalink / raw)
To: Ferruh Yigit; +Cc: Igor Ryzhov, dev, aconole
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: <20180628225548.21885-1-dg@adax.com>
If you search for KNI and dg@adax.com in the DPDK devel list you
should be able to suss out the whole discussion that lead to the
current implementation.
thanks
dan
On Mon, Oct 14, 2019 at 1:17 PM Ferruh Yigit <ferruh.yigit@intel.com> wrote:
>
> On 10/14/2019 5:10 PM, Ferruh Yigit wrote:
> > On 9/25/2019 10:36 AM, Igor Ryzhov 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.
> >
> > 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?
>
> 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"
>
> >
> >>
> >> Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
> >
> > <...>
> >
>
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [dpdk-dev] [PATCH v3] kni: rework rte_kni_update_link using ioctl
2019-10-14 19:01 ` Dan Gora
@ 2019-10-14 20:55 ` Dan Gora
2019-10-27 20:16 ` Igor Ryzhov
0 siblings, 1 reply; 27+ messages in thread
From: Dan Gora @ 2019-10-14 20:55 UTC (permalink / raw)
To: Ferruh Yigit; +Cc: Igor Ryzhov, dev, aconole
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
On Mon, Oct 14, 2019 at 4:01 PM Dan Gora <dg@adax.com> wrote:
>
> 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: <20180628225548.21885-1-dg@adax.com>
>
> If you search for KNI and dg@adax.com in the DPDK devel list you
> should be able to suss out the whole discussion that lead to the
> current implementation.
>
> thanks
> dan
>
> On Mon, Oct 14, 2019 at 1:17 PM Ferruh Yigit <ferruh.yigit@intel.com> wrote:
> >
> > On 10/14/2019 5:10 PM, Ferruh Yigit wrote:
> > > On 9/25/2019 10:36 AM, Igor Ryzhov 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.
> > >
> > > 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?
> >
> > 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"
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [dpdk-dev] [PATCH v3] kni: rework rte_kni_update_link using ioctl
2019-10-14 20:55 ` Dan Gora
@ 2019-10-27 20:16 ` Igor Ryzhov
2021-06-28 12:55 ` Ferruh Yigit
0 siblings, 1 reply; 27+ messages in thread
From: Igor Ryzhov @ 2019-10-27 20:16 UTC (permalink / raw)
To: Dan Gora; +Cc: Ferruh Yigit, dev, Aaron Conole
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
On Mon, Oct 14, 2019 at 11:56 PM Dan Gora <dg@adax.com> wrote:
> 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
>
> On Mon, Oct 14, 2019 at 4:01 PM Dan Gora <dg@adax.com> wrote:
> >
> > 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: <
> 20180628225548.21885-1-dg@adax.com>
> >
> > If you search for KNI and dg@adax.com in the DPDK devel list you
> > should be able to suss out the whole discussion that lead to the
> > current implementation.
> >
> > thanks
> > dan
> >
> > On Mon, Oct 14, 2019 at 1:17 PM Ferruh Yigit <ferruh.yigit@intel.com>
> wrote:
> > >
> > > On 10/14/2019 5:10 PM, Ferruh Yigit wrote:
> > > > On 9/25/2019 10:36 AM, Igor Ryzhov 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.
> > > >
> > > > 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?
> > >
> > > 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"
>
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [dpdk-dev] [PATCH v3] kni: rework rte_kni_update_link using ioctl
2019-10-27 20:16 ` Igor Ryzhov
@ 2021-06-28 12:55 ` Ferruh Yigit
2021-06-28 13:16 ` Igor Ryzhov
0 siblings, 1 reply; 27+ messages in thread
From: Ferruh Yigit @ 2021-06-28 12:55 UTC (permalink / raw)
To: Igor Ryzhov, Dan Gora; +Cc: dev, Aaron Conole, Stephen Hemminger
On 10/27/2019 8:16 PM, Igor Ryzhov wrote:
> 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.
>
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
> Igor
>
> On Mon, Oct 14, 2019 at 11:56 PM Dan Gora <dg@adax.com> wrote:
>
>> 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
>>
>> On Mon, Oct 14, 2019 at 4:01 PM Dan Gora <dg@adax.com> wrote:
>>>
>>> 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: <
>> 20180628225548.21885-1-dg@adax.com>
>>>
>>> If you search for KNI and dg@adax.com in the DPDK devel list you
>>> should be able to suss out the whole discussion that lead to the
>>> current implementation.
>>>
>>> thanks
>>> dan
>>>
>>> On Mon, Oct 14, 2019 at 1:17 PM Ferruh Yigit <ferruh.yigit@intel.com>
>> wrote:
>>>>
>>>> On 10/14/2019 5:10 PM, Ferruh Yigit wrote:
>>>>> On 9/25/2019 10:36 AM, Igor Ryzhov 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.
>>>>>
>>>>> 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?
>>>>
>>>> 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"
>>
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [dpdk-dev] [PATCH v3] kni: rework rte_kni_update_link using ioctl
2021-06-28 12:55 ` Ferruh Yigit
@ 2021-06-28 13:16 ` Igor Ryzhov
0 siblings, 0 replies; 27+ messages in thread
From: Igor Ryzhov @ 2021-06-28 13:16 UTC (permalink / raw)
To: Ferruh Yigit; +Cc: Dan Gora, dev, Aaron Conole, Stephen Hemminger
Thanks Ferruh,
I'll send an update later this week.
I also want to add a "Suggested-by: Dan Gora <dg@adax.com>" as it was his
idea.
Dan, please let me know if you don't want this tag to be added.
Thanks,
Igor
On Mon, Jun 28, 2021 at 3:55 PM Ferruh Yigit <ferruh.yigit@intel.com> wrote:
> On 10/27/2019 8:16 PM, Igor Ryzhov wrote:
> > 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.
> >
>
> 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
>
>
> > Igor
> >
> > On Mon, Oct 14, 2019 at 11:56 PM Dan Gora <dg@adax.com> wrote:
> >
> >> 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
> >>
> >> On Mon, Oct 14, 2019 at 4:01 PM Dan Gora <dg@adax.com> wrote:
> >>>
> >>> 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: <
> >> 20180628225548.21885-1-dg@adax.com>
> >>>
> >>> If you search for KNI and dg@adax.com in the DPDK devel list you
> >>> should be able to suss out the whole discussion that lead to the
> >>> current implementation.
> >>>
> >>> thanks
> >>> dan
> >>>
> >>> On Mon, Oct 14, 2019 at 1:17 PM Ferruh Yigit <ferruh.yigit@intel.com>
> >> wrote:
> >>>>
> >>>> On 10/14/2019 5:10 PM, Ferruh Yigit wrote:
> >>>>> On 9/25/2019 10:36 AM, Igor Ryzhov 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.
> >>>>>
> >>>>> 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?
> >>>>
> >>>> 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"
> >>
>
>
^ permalink raw reply [flat|nested] 27+ messages in thread
* [dpdk-dev] [PATCH v4 1/2] kni: rework rte_kni_update_link using ioctl
2019-09-24 19:33 ` [dpdk-dev] [PATCH v2] " Igor Ryzhov
2019-09-24 20:37 ` Aaron Conole
2019-09-25 9:36 ` [dpdk-dev] [PATCH v3] " Igor Ryzhov
@ 2021-07-04 16:06 ` Igor Ryzhov
2021-07-04 16:06 ` [dpdk-dev] [PATCH v4 2/2] kni: implement basic get_link_ksettings callback Igor Ryzhov
` (2 more replies)
2 siblings, 3 replies; 27+ messages in thread
From: Igor Ryzhov @ 2021-07-04 16:06 UTC (permalink / raw)
To: dev; +Cc: ferruh.yigit, dg
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 <dg@adax.com>
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
---
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(-)
diff --git a/app/test/test_kni.c b/app/test/test_kni.c
index 96733554b6c4..f9300552b3f6 100644
--- a/app/test/test_kni.c
+++ b/app/test/test_kni.c
@@ -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)
diff --git a/examples/kni/main.c b/examples/kni/main.c
index beabb3c848aa..5833037cf1c9 100644
--- a/examples/kni/main.c
+++ b/examples/kni/main.c
@@ -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);
}
}
diff --git a/kernel/linux/kni/compat.h b/kernel/linux/kni/compat.h
index 5f65640d5ed2..995d109c275a 100644
--- a/kernel/linux/kni/compat.h
+++ b/kernel/linux/kni/compat.h
@@ -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
diff --git a/kernel/linux/kni/kni_dev.h b/kernel/linux/kni/kni_dev.h
index c15da311ba25..969108cc30f8 100644
--- a/kernel/linux/kni/kni_dev.h
+++ b/kernel/linux/kni/kni_dev.h
@@ -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
diff --git a/kernel/linux/kni/kni_misc.c b/kernel/linux/kni/kni_misc.c
index 2b464c438113..30ee69661935 100644
--- a/kernel/linux/kni/kni_misc.c
+++ b/kernel/linux/kni/kni_misc.c
@@ -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;
diff --git a/kernel/linux/kni/kni_net.c b/kernel/linux/kni/kni_net.c
index 611719b5ee27..99da8d37dd6b 100644
--- a/kernel/linux/kni/kni_net.c
+++ b/kernel/linux/kni/kni_net.c
@@ -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,
diff --git a/lib/kni/rte_kni.c b/lib/kni/rte_kni.c
index eb24b0d0ae4e..0a7b562abf11 100644
--- a/lib/kni/rte_kni.c
+++ b/lib/kni/rte_kni.c
@@ -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
diff --git a/lib/kni/rte_kni.h b/lib/kni/rte_kni.h
index b0eaf4610416..ab5990fd210d 100644
--- a/lib/kni/rte_kni.h
+++ b/lib/kni/rte_kni.h
@@ -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.
diff --git a/lib/kni/rte_kni_common.h b/lib/kni/rte_kni_common.h
index b547ea550171..35a1620e0bd2 100644
--- a/lib/kni/rte_kni_common.h
+++ b/lib/kni/rte_kni_common.h
@@ -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_ */
--
2.32.0
^ permalink raw reply [flat|nested] 27+ messages in thread
* [dpdk-dev] [PATCH v4 2/2] kni: implement basic get_link_ksettings callback
2021-07-04 16:06 ` [dpdk-dev] [PATCH v4 1/2] " Igor Ryzhov
@ 2021-07-04 16:06 ` Igor Ryzhov
2021-07-05 11:58 ` [dpdk-dev] [PATCH v4 1/2] kni: rework rte_kni_update_link using ioctl Ferruh Yigit
2021-08-26 15:19 ` [dpdk-dev] [PATCH v5 1/3] " Igor Ryzhov
2 siblings, 0 replies; 27+ messages in thread
From: Igor Ryzhov @ 2021-07-04 16:06 UTC (permalink / raw)
To: dev; +Cc: ferruh.yigit, dg
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
---
kernel/linux/kni/kni_net.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/kernel/linux/kni/kni_net.c b/kernel/linux/kni/kni_net.c
index 99da8d37dd6b..84357bec1341 100644
--- a/kernel/linux/kni/kni_net.c
+++ b/kernel/linux/kni/kni_net.c
@@ -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
--
2.32.0
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [dpdk-dev] [PATCH v4 1/2] kni: rework rte_kni_update_link using ioctl
2021-07-04 16:06 ` [dpdk-dev] [PATCH v4 1/2] " Igor Ryzhov
2021-07-04 16:06 ` [dpdk-dev] [PATCH v4 2/2] kni: implement basic get_link_ksettings callback Igor Ryzhov
@ 2021-07-05 11:58 ` Ferruh Yigit
2021-07-06 9:14 ` Igor Ryzhov
2021-08-26 15:19 ` [dpdk-dev] [PATCH v5 1/3] " Igor Ryzhov
2 siblings, 1 reply; 27+ messages in thread
From: Ferruh Yigit @ 2021-07-05 11:58 UTC (permalink / raw)
To: Igor Ryzhov, dev; +Cc: dg
On 7/4/2021 6:06 PM, Igor Ryzhov 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.
>
> Propagating speed/duplex/autoneg to the kernel module also allows us to
> implement ethtool_ops.get_link_ksettings callback.
>
> Suggested-by: Dan Gora <dg@adax.com>
> Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
> ---
> 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(-)
>
> diff --git a/app/test/test_kni.c b/app/test/test_kni.c
> index 96733554b6c4..f9300552b3f6 100644
> --- a/app/test/test_kni.c
> +++ b/app/test/test_kni.c
> @@ -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;
> }
Is there a way to verify the link status of the KNI interface, to double check
setting link status succedded?
> - 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)
> diff --git a/examples/kni/main.c b/examples/kni/main.c
> index beabb3c848aa..5833037cf1c9 100644
> --- a/examples/kni/main.c
> +++ b/examples/kni/main.c
> @@ -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);
> }
> }
> diff --git a/kernel/linux/kni/compat.h b/kernel/linux/kni/compat.h
> index 5f65640d5ed2..995d109c275a 100644
> --- a/kernel/linux/kni/compat.h
> +++ b/kernel/linux/kni/compat.h
> @@ -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
> diff --git a/kernel/linux/kni/kni_dev.h b/kernel/linux/kni/kni_dev.h
> index c15da311ba25..969108cc30f8 100644
> --- a/kernel/linux/kni/kni_dev.h
> +++ b/kernel/linux/kni/kni_dev.h
> @@ -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
> diff --git a/kernel/linux/kni/kni_misc.c b/kernel/linux/kni/kni_misc.c
> index 2b464c438113..30ee69661935 100644
> --- a/kernel/linux/kni/kni_misc.c
> +++ b/kernel/linux/kni/kni_misc.c
> @@ -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;
> diff --git a/kernel/linux/kni/kni_net.c b/kernel/linux/kni/kni_net.c
> index 611719b5ee27..99da8d37dd6b 100644
> --- a/kernel/linux/kni/kni_net.c
> +++ b/kernel/linux/kni/kni_net.c
> @@ -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
What do you think keeping the 'carrier' interface? Even the API not using it, it
can be useful, what do you think?
> };
>
> static void kni_get_drvinfo(struct net_device *dev,
> diff --git a/lib/kni/rte_kni.c b/lib/kni/rte_kni.c
> index eb24b0d0ae4e..0a7b562abf11 100644
> --- a/lib/kni/rte_kni.c
> +++ b/lib/kni/rte_kni.c
> @@ -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;
> }
Can you please add new API to KNI PMD too? To set the link up when port started.
>
> void
> diff --git a/lib/kni/rte_kni.h b/lib/kni/rte_kni.h
> index b0eaf4610416..ab5990fd210d 100644
> --- a/lib/kni/rte_kni.h
> +++ b/lib/kni/rte_kni.h
> @@ -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
> */
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?
> __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.
> diff --git a/lib/kni/rte_kni_common.h b/lib/kni/rte_kni_common.h
> index b547ea550171..35a1620e0bd2 100644
> --- a/lib/kni/rte_kni_common.h
> +++ b/lib/kni/rte_kni_common.h
> @@ -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?
> +
> #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_ */
>
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [dpdk-dev] [PATCH v4 1/2] kni: rework rte_kni_update_link using ioctl
2021-07-05 11:58 ` [dpdk-dev] [PATCH v4 1/2] kni: rework rte_kni_update_link using ioctl Ferruh Yigit
@ 2021-07-06 9:14 ` Igor Ryzhov
0 siblings, 0 replies; 27+ messages in thread
From: Igor Ryzhov @ 2021-07-06 9:14 UTC (permalink / raw)
To: Ferruh Yigit; +Cc: dev, Dan Gora
Hi Ferruh,
Thanks for the review. My comments inline. I'll send a new version later
this week.
On Mon, Jul 5, 2021 at 2:58 PM Ferruh Yigit <ferruh.yigit@intel.com> wrote:
> On 7/4/2021 6:06 PM, Igor Ryzhov 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.
> >
> > Propagating speed/duplex/autoneg to the kernel module also allows us to
> > implement ethtool_ops.get_link_ksettings callback.
> >
> > Suggested-by: Dan Gora <dg@adax.com>
> > Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
> > ---
> > 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(-)
> >
> > diff --git a/app/test/test_kni.c b/app/test/test_kni.c
> > index 96733554b6c4..f9300552b3f6 100644
> > --- a/app/test/test_kni.c
> > +++ b/app/test/test_kni.c
> > @@ -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;
> > }
>
> 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.
>
> > - 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)
> > diff --git a/examples/kni/main.c b/examples/kni/main.c
> > index beabb3c848aa..5833037cf1c9 100644
> > --- a/examples/kni/main.c
> > +++ b/examples/kni/main.c
> > @@ -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);
> > }
> > }
> > diff --git a/kernel/linux/kni/compat.h b/kernel/linux/kni/compat.h
> > index 5f65640d5ed2..995d109c275a 100644
> > --- a/kernel/linux/kni/compat.h
> > +++ b/kernel/linux/kni/compat.h
> > @@ -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
> > diff --git a/kernel/linux/kni/kni_dev.h b/kernel/linux/kni/kni_dev.h
> > index c15da311ba25..969108cc30f8 100644
> > --- a/kernel/linux/kni/kni_dev.h
> > +++ b/kernel/linux/kni/kni_dev.h
> > @@ -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
> > diff --git a/kernel/linux/kni/kni_misc.c b/kernel/linux/kni/kni_misc.c
> > index 2b464c438113..30ee69661935 100644
> > --- a/kernel/linux/kni/kni_misc.c
> > +++ b/kernel/linux/kni/kni_misc.c
> > @@ -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;
> > diff --git a/kernel/linux/kni/kni_net.c b/kernel/linux/kni/kni_net.c
> > index 611719b5ee27..99da8d37dd6b 100644
> > --- a/kernel/linux/kni/kni_net.c
> > +++ b/kernel/linux/kni/kni_net.c
> > @@ -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
>
> 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.
>
> > };
> >
> > static void kni_get_drvinfo(struct net_device *dev,
> > diff --git a/lib/kni/rte_kni.c b/lib/kni/rte_kni.c
> > index eb24b0d0ae4e..0a7b562abf11 100644
> > --- a/lib/kni/rte_kni.c
> > +++ b/lib/kni/rte_kni.c
> > @@ -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;
> > }
>
> 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.
>
> >
> > void
> > diff --git a/lib/kni/rte_kni.h b/lib/kni/rte_kni.h
> > index b0eaf4610416..ab5990fd210d 100644
> > --- a/lib/kni/rte_kni.h
> > +++ b/lib/kni/rte_kni.h
> > @@ -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
> > */
>
> 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?
>
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.
>
> > __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.
> > diff --git a/lib/kni/rte_kni_common.h b/lib/kni/rte_kni_common.h
> > index b547ea550171..35a1620e0bd2 100644
> > --- a/lib/kni/rte_kni_common.h
> > +++ b/lib/kni/rte_kni_common.h
> > @@ -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?
>
Sure, I'll update. Not sure why I chose it initially, it was a long time
ago :)
>
> > +
> > #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_ */
> >
>
>
^ permalink raw reply [flat|nested] 27+ messages in thread
* [dpdk-dev] [PATCH v5 1/3] kni: rework rte_kni_update_link using ioctl
2021-07-04 16:06 ` [dpdk-dev] [PATCH v4 1/2] " Igor Ryzhov
2021-07-04 16:06 ` [dpdk-dev] [PATCH v4 2/2] kni: implement basic get_link_ksettings callback Igor Ryzhov
2021-07-05 11:58 ` [dpdk-dev] [PATCH v4 1/2] kni: rework rte_kni_update_link using ioctl Ferruh Yigit
@ 2021-08-26 15:19 ` Igor Ryzhov
2021-08-26 15:19 ` [dpdk-dev] [PATCH v5 2/3] kni: implement basic get_link_ksettings callback Igor Ryzhov
` (3 more replies)
2 siblings, 4 replies; 27+ messages in thread
From: Igor Ryzhov @ 2021-08-26 15:19 UTC (permalink / raw)
To: dev; +Cc: ferruh.yigit, Dan Gora
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 <dg@adax.com>
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
---
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(-)
diff --git a/app/test/test_kni.c b/app/test/test_kni.c
index 96733554b6c4..0df028696f36 100644
--- a/app/test/test_kni.c
+++ b/app/test/test_kni.c
@@ -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)
diff --git a/examples/kni/main.c b/examples/kni/main.c
index beabb3c848aa..aea44beac550 100644
--- a/examples/kni/main.c
+++ b/examples/kni/main.c
@@ -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;
}
}
}
diff --git a/kernel/linux/kni/kni_dev.h b/kernel/linux/kni/kni_dev.h
index c15da311ba25..969108cc30f8 100644
--- a/kernel/linux/kni/kni_dev.h
+++ b/kernel/linux/kni/kni_dev.h
@@ -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
diff --git a/kernel/linux/kni/kni_misc.c b/kernel/linux/kni/kni_misc.c
index 2b464c438113..30ee69661935 100644
--- a/kernel/linux/kni/kni_misc.c
+++ b/kernel/linux/kni/kni_misc.c
@@ -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;
diff --git a/lib/kni/rte_kni.c b/lib/kni/rte_kni.c
index eb24b0d0ae4e..0a7b562abf11 100644
--- a/lib/kni/rte_kni.c
+++ b/lib/kni/rte_kni.c
@@ -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
diff --git a/lib/kni/rte_kni.h b/lib/kni/rte_kni.h
index b0eaf4610416..c891e0e1f9a5 100644
--- a/lib/kni/rte_kni.h
+++ b/lib/kni/rte_kni.h
@@ -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.
diff --git a/lib/kni/rte_kni_common.h b/lib/kni/rte_kni_common.h
index b547ea550171..e27cb3330b35 100644
--- a/lib/kni/rte_kni_common.h
+++ b/lib/kni/rte_kni_common.h
@@ -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_ */
--
2.33.0
^ permalink raw reply [flat|nested] 27+ messages in thread
* [dpdk-dev] [PATCH v5 2/3] kni: implement basic get_link_ksettings callback
2021-08-26 15:19 ` [dpdk-dev] [PATCH v5 1/3] " Igor Ryzhov
@ 2021-08-26 15:19 ` Igor Ryzhov
2021-08-26 15:19 ` [dpdk-dev] [PATCH v5 3/3] app/test: fix return value of test_kni_link_change Igor Ryzhov
` (2 subsequent siblings)
3 siblings, 0 replies; 27+ messages in thread
From: Igor Ryzhov @ 2021-08-26 15:19 UTC (permalink / raw)
To: dev; +Cc: ferruh.yigit
It allows inspecting link parameters using ethtool.
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
---
kernel/linux/kni/kni_net.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/kernel/linux/kni/kni_net.c b/kernel/linux/kni/kni_net.c
index 611719b5ee27..931b9daf104f 100644
--- a/kernel/linux/kni/kni_net.c
+++ b/kernel/linux/kni/kni_net.c
@@ -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
--
2.33.0
^ permalink raw reply [flat|nested] 27+ messages in thread
* [dpdk-dev] [PATCH v5 3/3] app/test: fix return value of test_kni_link_change
2021-08-26 15:19 ` [dpdk-dev] [PATCH v5 1/3] " Igor Ryzhov
2021-08-26 15:19 ` [dpdk-dev] [PATCH v5 2/3] kni: implement basic get_link_ksettings callback Igor Ryzhov
@ 2021-08-26 15:19 ` Igor Ryzhov
2021-08-26 17:15 ` [dpdk-dev] [PATCH v5 1/3] kni: rework rte_kni_update_link using ioctl Stephen Hemminger
2021-08-30 14:27 ` [dpdk-dev] [PATCH v6 " Igor Ryzhov
3 siblings, 0 replies; 27+ messages in thread
From: Igor Ryzhov @ 2021-08-26 15:19 UTC (permalink / raw)
To: dev; +Cc: ferruh.yigit
If 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.
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
---
app/test/test_kni.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/test/test_kni.c b/app/test/test_kni.c
index 0df028696f36..70c81f4af0f4 100644
--- a/app/test/test_kni.c
+++ b/app/test/test_kni.c
@@ -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);
--
2.33.0
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [dpdk-dev] [PATCH v5 1/3] kni: rework rte_kni_update_link using ioctl
2021-08-26 15:19 ` [dpdk-dev] [PATCH v5 1/3] " Igor Ryzhov
2021-08-26 15:19 ` [dpdk-dev] [PATCH v5 2/3] kni: implement basic get_link_ksettings callback Igor Ryzhov
2021-08-26 15:19 ` [dpdk-dev] [PATCH v5 3/3] app/test: fix return value of test_kni_link_change Igor Ryzhov
@ 2021-08-26 17:15 ` Stephen Hemminger
2021-08-26 17:46 ` Igor Ryzhov
2021-08-30 14:27 ` [dpdk-dev] [PATCH v6 " Igor Ryzhov
3 siblings, 1 reply; 27+ messages in thread
From: Stephen Hemminger @ 2021-08-26 17:15 UTC (permalink / raw)
To: Igor Ryzhov; +Cc: dev, ferruh.yigit, Dan Gora
On Thu, 26 Aug 2021 18:19:09 +0300
Igor Ryzhov <iryzhov@nfware.com> wrote:
>
> +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;
> +}
> +
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.
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [dpdk-dev] [PATCH v5 1/3] kni: rework rte_kni_update_link using ioctl
2021-08-26 17:15 ` [dpdk-dev] [PATCH v5 1/3] kni: rework rte_kni_update_link using ioctl Stephen Hemminger
@ 2021-08-26 17:46 ` Igor Ryzhov
2021-08-26 18:06 ` Stephen Hemminger
0 siblings, 1 reply; 27+ messages in thread
From: Igor Ryzhov @ 2021-08-26 17:46 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: dev, Ferruh Yigit, Dan Gora
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.
On Thu, Aug 26, 2021 at 8:15 PM Stephen Hemminger <
stephen@networkplumber.org> wrote:
> On Thu, 26 Aug 2021 18:19:09 +0300
> Igor Ryzhov <iryzhov@nfware.com> wrote:
>
> >
> > +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;
> > +}
> > +
>
> 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.
>
>
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [dpdk-dev] [PATCH v5 1/3] kni: rework rte_kni_update_link using ioctl
2021-08-26 17:46 ` Igor Ryzhov
@ 2021-08-26 18:06 ` Stephen Hemminger
2021-08-30 18:05 ` Igor Ryzhov
0 siblings, 1 reply; 27+ messages in thread
From: Stephen Hemminger @ 2021-08-26 18:06 UTC (permalink / raw)
To: Igor Ryzhov; +Cc: dev, Ferruh Yigit, Dan Gora
On Thu, 26 Aug 2021 20:46:47 +0300
Igor Ryzhov <iryzhov@nfware.com> 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.
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [dpdk-dev] [PATCH v5 1/3] kni: rework rte_kni_update_link using ioctl
2021-08-26 18:06 ` Stephen Hemminger
@ 2021-08-30 18:05 ` Igor Ryzhov
0 siblings, 0 replies; 27+ messages in thread
From: Igor Ryzhov @ 2021-08-30 18:05 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: dev, Ferruh Yigit, Dan Gora
On Thu, Aug 26, 2021 at 9:06 PM Stephen Hemminger <
stephen@networkplumber.org> wrote:
> On Thu, 26 Aug 2021 20:46:47 +0300
> Igor Ryzhov <iryzhov@nfware.com> 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.
> Do you call ethtool_validate_speed() and ethtool_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.
>
> 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.
^ permalink raw reply [flat|nested] 27+ messages in thread
* [dpdk-dev] [PATCH v6 1/3] kni: rework rte_kni_update_link using ioctl
2021-08-26 15:19 ` [dpdk-dev] [PATCH v5 1/3] " Igor Ryzhov
` (2 preceding siblings ...)
2021-08-26 17:15 ` [dpdk-dev] [PATCH v5 1/3] kni: rework rte_kni_update_link using ioctl Stephen Hemminger
@ 2021-08-30 14:27 ` Igor Ryzhov
2021-08-30 14:27 ` [dpdk-dev] [PATCH v6 2/3] kni: implement basic get_link_ksettings callback Igor Ryzhov
` (2 more replies)
3 siblings, 3 replies; 27+ messages in thread
From: Igor Ryzhov @ 2021-08-30 14:27 UTC (permalink / raw)
To: dev; +Cc: ferruh.yigit, Dan Gora
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 <dg@adax.com>
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
---
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(-)
diff --git a/app/test/test_kni.c b/app/test/test_kni.c
index 96733554b6c4..0df028696f36 100644
--- a/app/test/test_kni.c
+++ b/app/test/test_kni.c
@@ -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)
diff --git a/examples/kni/main.c b/examples/kni/main.c
index beabb3c848aa..aea44beac550 100644
--- a/examples/kni/main.c
+++ b/examples/kni/main.c
@@ -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;
}
}
}
diff --git a/kernel/linux/kni/kni_dev.h b/kernel/linux/kni/kni_dev.h
index c15da311ba25..969108cc30f8 100644
--- a/kernel/linux/kni/kni_dev.h
+++ b/kernel/linux/kni/kni_dev.h
@@ -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
diff --git a/kernel/linux/kni/kni_misc.c b/kernel/linux/kni/kni_misc.c
index 2b464c438113..30ee69661935 100644
--- a/kernel/linux/kni/kni_misc.c
+++ b/kernel/linux/kni/kni_misc.c
@@ -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;
diff --git a/lib/kni/rte_kni.c b/lib/kni/rte_kni.c
index d3e236005ed5..0a7b562abf11 100644
--- a/lib/kni/rte_kni.c
+++ b/lib/kni/rte_kni.c
@@ -784,46 +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');
-
- if (old_linkup == (int)linkup)
- goto out;
-
- 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;
- }
-out:
- close(fd);
- return old_linkup;
+ return 0;
}
void
diff --git a/lib/kni/rte_kni.h b/lib/kni/rte_kni.h
index b0eaf4610416..c891e0e1f9a5 100644
--- a/lib/kni/rte_kni.h
+++ b/lib/kni/rte_kni.h
@@ -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.
diff --git a/lib/kni/rte_kni_common.h b/lib/kni/rte_kni_common.h
index b547ea550171..e27cb3330b35 100644
--- a/lib/kni/rte_kni_common.h
+++ b/lib/kni/rte_kni_common.h
@@ -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_ */
--
2.33.0
^ permalink raw reply [flat|nested] 27+ messages in thread
* [dpdk-dev] [PATCH v6 2/3] kni: implement basic get_link_ksettings callback
2021-08-30 14:27 ` [dpdk-dev] [PATCH v6 " Igor Ryzhov
@ 2021-08-30 14:27 ` Igor Ryzhov
2021-08-30 14:27 ` [dpdk-dev] [PATCH v6 3/3] app/test: fix return value of test_kni_link_change Igor Ryzhov
2023-06-29 17:05 ` [dpdk-dev] [PATCH v6 1/3] kni: rework rte_kni_update_link using ioctl Stephen Hemminger
2 siblings, 0 replies; 27+ messages in thread
From: Igor Ryzhov @ 2021-08-30 14:27 UTC (permalink / raw)
To: dev; +Cc: ferruh.yigit
It allows inspecting link parameters using ethtool.
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
---
kernel/linux/kni/kni_net.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/kernel/linux/kni/kni_net.c b/kernel/linux/kni/kni_net.c
index 611719b5ee27..931b9daf104f 100644
--- a/kernel/linux/kni/kni_net.c
+++ b/kernel/linux/kni/kni_net.c
@@ -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
--
2.33.0
^ permalink raw reply [flat|nested] 27+ messages in thread
* [dpdk-dev] [PATCH v6 3/3] app/test: fix return value of test_kni_link_change
2021-08-30 14:27 ` [dpdk-dev] [PATCH v6 " Igor Ryzhov
2021-08-30 14:27 ` [dpdk-dev] [PATCH v6 2/3] kni: implement basic get_link_ksettings callback Igor Ryzhov
@ 2021-08-30 14:27 ` Igor Ryzhov
2023-06-29 17:05 ` [dpdk-dev] [PATCH v6 1/3] kni: rework rte_kni_update_link using ioctl Stephen Hemminger
2 siblings, 0 replies; 27+ messages in thread
From: Igor Ryzhov @ 2021-08-30 14:27 UTC (permalink / raw)
To: dev; +Cc: ferruh.yigit
If 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.
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
---
app/test/test_kni.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/test/test_kni.c b/app/test/test_kni.c
index 0df028696f36..70c81f4af0f4 100644
--- a/app/test/test_kni.c
+++ b/app/test/test_kni.c
@@ -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);
--
2.33.0
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [dpdk-dev] [PATCH v6 1/3] kni: rework rte_kni_update_link using ioctl
2021-08-30 14:27 ` [dpdk-dev] [PATCH v6 " Igor Ryzhov
2021-08-30 14:27 ` [dpdk-dev] [PATCH v6 2/3] kni: implement basic get_link_ksettings callback Igor Ryzhov
2021-08-30 14:27 ` [dpdk-dev] [PATCH v6 3/3] app/test: fix return value of test_kni_link_change Igor Ryzhov
@ 2023-06-29 17:05 ` Stephen Hemminger
2 siblings, 0 replies; 27+ messages in thread
From: Stephen Hemminger @ 2023-06-29 17:05 UTC (permalink / raw)
To: Igor Ryzhov; +Cc: dev, ferruh.yigit, Dan Gora
On Mon, 30 Aug 2021 17:27:29 +0300
Igor Ryzhov <iryzhov@nfware.com> 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.
>
> Propagating speed/duplex/autoneg to the kernel module also allows us to
> implement ethtool_ops.get_link_ksettings callback.
>
> Suggested-by: Dan Gora <dg@adax.com>
> Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
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.
^ permalink raw reply [flat|nested] 27+ messages in thread