kni: cleanups and improvements
cover kni: cleanups and improvements
Going over using KNI with netvsc, saw lots of remove for improvment (deleting code).
This is still mostly "putting lipstick on a pig" all users would be better off using virtio_user rather than KNI.
Stephen Hemminger (9):
kni: don't need stubs for rx_mode or ioctl
kni: use netdev_alloc_skb
kni: drop unused field
kni: don't keep stats in kni_net
kni: drop unused group_id and device_id
kni: drop unused status element
kni: use proper type for kni fifo's
kni: return -EFAULT if copy_from_user fails
doc: update KNI documentation
.../sample_app_ug/kernel_nic_interface.rst | 18 ++--- kernel/linux/kni/kni_dev.h | 21 ++--- kernel/linux/kni/kni_misc.c | 17 ++-- kernel/linux/kni/kni_net.c | 79 +++++-------------- 4 files changed, 38 insertions(+), 97 deletions(-)
Signature · 1 line
2.20.1
PATCH 1/9 kni: don't need stubs for rx_mode or ioctl
The netdev subsystem already handles case where
network sevice does not support ioctl.
If device has no rx_mode hook it is not called.
--- kernel/linux/kni/kni_net.c | 19 ------------------- 1 file changed, 19 deletions(-)
kernel/linux/kni/kni_net.c +0 -19
@@ -593,23 +593,6 @@ kni_net_tx_timeout(struct net_device *dev)netif_wake_queue (dev); } -/* -* Ioctl commands -*/ -static int -kni_net_ioctl (struct net_device *dev,struct ifreq *rq,int cmd) -{ -pr_debug ("kni_net_ioctl group:%d cmd:%d\n" , - ((struct kni_dev *)netdev_priv (dev))->group_id, cmd); - -return -EOPNOTSUPP ; -} - -static void -kni_net_set_rx_mode (struct net_device *dev) -{ -} -static int kni_net_change_mtu (struct net_device *dev,int new_mtu) {
@@ -758,8 +741,6 @@ static const struct net_device_ops kni_net_netdev_ops = { .ndo_change_rx_flags = kni_net_set_promiscusity, .ndo_start_xmit = kni_net_tx, .ndo_change_mtu = kni_net_change_mtu, - .ndo_do_ioctl = kni_net_ioctl, - .ndo_set_rx_mode = kni_net_set_rx_mode, .ndo_get_stats = kni_net_stats, .ndo_tx_timeout = kni_net_tx_timeout, .ndo_set_mac_address = kni_net_set_mac,
Signature · 1 line
2.20.1
PATCH 2/9 kni: use netdev_alloc_skb
In reply to Stephen Hemmingernetdev_alloc_skb is optimized to any alignment or setup of skb->dev that is required. The kernel has chosen to not pad packets on x86 (for many years), because it is faster.
--- kernel/linux/kni/kni_net.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-)
kernel/linux/kni/kni_net.c +3 -14
@@ -340,16 +340,13 @@ kni_net_rx_normal(struct kni_dev *kni) data_kva =kva2data_kva (kva); kni->va[i] =pa2va (kni->pa[i], kva); - skb =dev_alloc_skb (len +2 ); + skb =netdev_alloc_skb (dev, len +2 );if (!skb) {/* Update statistics */ kni->stats.rx_dropped++;continue ; } -/* Align IP on 16B boundary */ -skb_reserve (skb,2 ); -if (kva->nb_segs ==1 ) {memcpy (skb_put (skb, len), data_kva, len); }else {
@@ -368,7 +365,6 @@ kni_net_rx_normal(struct kni_dev *kni) } } - skb->dev = dev; skb->protocol =eth_type_trans (skb, dev); skb->ip_summed =CHECKSUM_UNNECESSARY ;
@@ -512,26 +508,20 @@ kni_net_rx_lo_fifo_skb(struct kni_dev *kni) data_kva =kva2data_kva (kva); kni->va[i] =pa2va (kni->pa[i], kva); - skb =dev_alloc_skb (len +2 ); + skb =netdev_alloc_skb (dev, len +2 );if (skb) { -/* Align IP on 16B boundary */ -skb_reserve (skb,2 );memcpy (skb_put (skb, len), data_kva, len); - skb->dev = dev; skb->ip_summed =CHECKSUM_UNNECESSARY ;dev_kfree_skb (skb); }/* Simulate real usage, allocate/copy skb twice */ - skb =dev_alloc_skb (len +2 ); + skb =netdev_alloc_skb (dev, len +2 );if (skb ==NULL ) { kni->stats.rx_dropped++;continue ; } -/* Align IP on 16B boundary */ -skb_reserve (skb,2 ); -if (kva->nb_segs ==1 ) {memcpy (skb_put (skb, len), data_kva, len); }else {
@@ -550,7 +540,6 @@ kni_net_rx_lo_fifo_skb(struct kni_dev *kni) } } - skb->dev = dev; skb->ip_summed =CHECKSUM_UNNECESSARY ; kni->stats.rx_bytes += len;
Signature · 1 line
2.20.1
PATCH 3/9 kni: drop unused field
In reply to Stephen HemmingerThe kni net structure only exists in driver no API/ABI.
--- kernel/linux/kni/kni_dev.h | 3 --- 1 file changed, 3 deletions(-)
kernel/linux/kni/kni_dev.h +0 -3
@@ -83,9 +83,6 @@ struct kni_dev {/* mbuf size */ uint32_t mbuf_size; -/* synchro for request processing */ -unsigned long synchro; -/* buffers */ void *pa[MBUF_BURST_SZ ];void *va[MBUF_BURST_SZ ];
Signature · 1 line
2.20.1
PATCH 4/9 kni: don't keep stats in kni_net
In reply to Stephen HemmingerSince kernel 2.6.28 the network subsystem has provided dev->stats for devices to use statistics handling and is the default if no ndo_get_stats is provided.
This allow allows for 64 bit (rather than just 32 bit) statistics with KNI.
--- kernel/linux/kni/kni_dev.h | 1 - kernel/linux/kni/kni_net.c | 43 +++++++++++++------------------------- 2 files changed, 15 insertions(+), 29 deletions(-)
kernel/linux/kni/kni_dev.h +0 -1
@@ -39,7 +39,6 @@ struct kni_dev {/* kni list */ struct list_head list; -struct net_device_stats stats;int status;uint16_t group_id;/* Group ID of a group of KNI devices */ uint32_t core_id;/* Core ID to bind */
kernel/linux/kni/kni_net.c +15 -28
118 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH 5/9 kni: drop unused group_id and device_id
In reply to Stephen HemmingerKni devices no longer are restricted to PCI and device_id in kni_dev is no longer used.
The group_id is set but never used.
The fields do need to stay in the ABI (dev_info) but kernel can ignore them.
--- kernel/linux/kni/kni_dev.h | 4 ---- kernel/linux/kni/kni_misc.c | 1 - 2 files changed, 5 deletions(-)
kernel/linux/kni/kni_dev.h +0 -4
@@ -40,7 +40,6 @@ struct kni_dev {struct list_head list;int status; -uint16_t group_id;/* Group ID of a group of KNI devices */ uint32_t core_id;/* Core ID to bind */ char name[RTE_KNI_NAMESIZE ];/* Network device name */ struct task_struct *pthread;
@@ -49,9 +48,6 @@ struct kni_dev {wait_queue_head_t wq;struct mutex sync_lock; -/* PCI device id */ -uint16_t device_id; -/* kni device */ struct net_device *net_dev;
kernel/linux/kni/kni_misc.c +0 -1
@@ -346,7 +346,6 @@ kni_ioctl_create(struct net *net, uint32_t ioctl_num, kni =netdev_priv (net_dev); kni->net_dev = net_dev; - kni->group_id = dev_info.group_id; kni->core_id = dev_info.core_id;strncpy (kni->name, dev_info.name,RTE_KNI_NAMESIZE );
Signature · 1 line
2.20.1
PATCH 6/9 kni: drop unused status element
In reply to Stephen HemmingerYet another ethtool leftover.
--- kernel/linux/kni/kni_dev.h | 1 - 1 file changed, 1 deletion(-)
kernel/linux/kni/kni_dev.h +0 -1
@@ -39,7 +39,6 @@ struct kni_dev {/* kni list */ struct list_head list; -int status;uint32_t core_id;/* Core ID to bind */ char name[RTE_KNI_NAMESIZE ];/* Network device name */ struct task_struct *pthread;
Signature · 1 line
2.20.1
PATCH 7/9 kni: use proper type for kni fifo's
In reply to Stephen HemmingerUsing void * instead of proper type is unsafe practice.
--- kernel/linux/kni/kni_dev.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
kernel/linux/kni/kni_dev.h +6 -6
@@ -51,22 +51,22 @@ struct kni_dev {struct net_device *net_dev;/* queue for packets to be sent out */ -void *tx_q; +struct rte_kni_fifo *tx_q;/* queue for the packets received */ -void *rx_q; +struct rte_kni_fifo *rx_q;/* queue for the allocated mbufs those can be used to save sk buffs */ -void *alloc_q; +struct rte_kni_fifo *alloc_q;/* free queue for the mbufs to be freed */ -void *free_q; +struct rte_kni_fifo *free_q;/* request queue */ -void *req_q; +struct rte_kni_fifo *req_q;/* response queue */ -void *resp_q; +struct rte_kni_fifo *resp_q;void *sync_kva;void *sync_va;
Signature · 1 line
2.20.1
PATCH 8/9 kni: return -EFAULT if copy_from_user fails
In reply to Stephen HemmingerThe correct thing to return if user gives a bad data is to return -EFAULT. Logging is also discouraged because it could be used as a DoS attack.
--- kernel/linux/kni/kni_misc.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-)
kernel/linux/kni/kni_misc.c +5 -11
@@ -301,11 +301,8 @@ kni_ioctl_create(struct net *net, uint32_t ioctl_num,return -EINVAL ;/* Copy kni info from user space */ - ret =copy_from_user (&dev_info, (void *)ioctl_param,sizeof (dev_info)); -if (ret) { -pr_err ("copy_from_user in kni_ioctl_create" ); -return -EIO ; - } +if (copy_from_user (&dev_info, (void *)ioctl_param,sizeof (dev_info))) +return -EFAULT ;/* Check if name is zero-ended */ if (strnlen (dev_info.name,sizeof (dev_info.name)) ==sizeof (dev_info.name)) {
@@ -433,15 +430,12 @@ kni_ioctl_release(struct net *net, uint32_t ioctl_num,if (_IOC_SIZE (ioctl_num) >sizeof (dev_info))return -EINVAL ; - ret =copy_from_user (&dev_info, (void *)ioctl_param,sizeof (dev_info)); -if (ret) { -pr_err ("copy_from_user in kni_ioctl_release" ); -return -EIO ; - } +if (copy_from_user (&dev_info, (void *)ioctl_param,sizeof (dev_info))) +return -EFAULT ;/* Release the network device according to its name */ if (strlen (dev_info.name) ==0 ) -return ret; +return -EINVAL ;down_write (&knet->kni_list_lock);list_for_each_entry_safe (dev, n, &knet->kni_list_head, list) {
Signature · 1 line
2.20.1
PATCH 9/9 doc: update KNI documentation
In reply to Stephen HemmingerMake the KNI documentation reflect modern kernel networking. Ifconfig has been superseded by iproute2 for 15 years. Iproute2 is well maintained, supports current feature set.
Ethtool is no longer supported by KNI.
Tshark is a better replacement for tcpdump.
--- .../sample_app_ug/kernel_nic_interface.rst | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
doc/guides/sample_app_ug/kernel_nic_interface.rst +9 -9
@@ -21,14 +21,14 @@ The FIFO queues contain pointers to data packets in the DPDK. This: * Provides a faster mechanism to interface with the kernel net stack and eliminates system calls -* Facilitates the DPDK using standard Linux* userspace net tools (tcpdump, ftp, and so on) +* Facilitates the DPDK using standard Linux* userspace net tools (tshark, rsync, and so on) * Eliminate the copy_to_user and copy_from_user operations on packets. The Kernel NIC Interface sample application is a simple example that demonstrates the use of the DPDK to create a path for packets to go through the Linux* kernel. This is done by creating one or more kernel net devices for each of the DPDK ports. -The application allows the use of standard Linux tools (ethtool, ifconfig, tcpdump) with the DPDK ports and +The application allows the use of standard Linux tools (iproute, tshark) with the DPDK ports and also the exchange of packets between the DPDK application and the Linux* kernel. The Kernel NIC Interface sample application requires that the
@@ -220,13 +220,13 @@ Enable KNI interface and assign an IP address: .. code-block:: console - # ifconfig vEth0_0 192.168.0.1 + # ip addr add dev vEth0_0 192.168.0.1 Show KNI interface configuration and statistics: .. code-block:: console - # ifconfig vEth0_0 + # ip -s -d addr show vEth0_0 The user can also check and reset the packet statistics inside the ``kni`` application by sending the app the USR1 and USR2 signals:
@@ -234,16 +234,16 @@ application by sending the app the USR1 and USR2 signals: .. code-block:: console # Print statistics - # kill -SIGUSR1 `pidof kni` + # pkill -USR1 kni # Zero statistics - # kill -SIGUSR2 `pidof kni` + # pkill -USR2 kni Dump network traffic: .. code-block:: console - # tcpdump -i vEth0_0 + # tshark -n -i vEth0_0 The normal Linux commands can also be used to change the MAC address and MTU size used by the physical NIC which corresponds to the KNI interface.
@@ -254,13 +254,13 @@ Change the MAC address: .. code-block:: console - # ifconfig vEth0_0 hw ether 0C:01:02:03:04:08 + # ip link set dev vEth0_0 lladdr 0C:01:02:03:04:08 Change the MTU size: .. code-block:: console - # ifconfig vEth0_0 mtu 1450 + # ip link set dev vEth0_0 mtu 1450 When the ``kni`` application is closed, all the KNI interfaces are deleted from the Linux kernel.
Signature · 1 line
2.20.1
Re: [dpdk-dev] [PATCH 2/9] kni: use netdev_alloc_skb
In reply to Stephen Hemmingerkernel/linux/kni/kni_net.c kni_net_rx_normal(struct kni_dev *kni) · line 343
Quoted 7 lines · On Fri, 7 Jun 2019 17:19:56 -0700 Stephen Hemminger…
+++
b/kernel/linux/kni/kni_net.ckernel/linux/kni/kni_net.c +1
-1@@ -340,16 +340,13 @@ kni_net_rx_normal(struct kni_dev *kni) data_kva =kva2data_kva (kva); kni->va[i] =pa2va (kni->pa[i], kva); - skb =dev_alloc_skb (len +2 ); + skb =netdev_alloc_skb (dev, len +2 );
The +2 is no longer needed. will update in next version