由于 Ubuntu22.04 内核版本和gcc版本比较高,在编译dpdk时会报错。
我使用的编译命令是:
make install T=x86_64-native-linuxapp-gcc
主要有以下几个错误:
1.error: this statement may fall through
== Build kernel/linux/igb_uio
CC [M] /root/dpdk-19.11/x86_64-native-linuxapp-gcc/build/kernel/linux/igb_uio/igb_uio.o
/root/dpdk-19.11/x86_64-native-linuxapp-gcc/build/kernel/linux/igb_uio/igb_uio.c: In function ‘igbuio_pci_enable_interrupts’:
/root/dpdk-19.11/x86_64-native-linuxapp-gcc/build/kernel/linux/igb_uio/igb_uio.c:230:20: error: this statement may fall through [-Werror=implicit-fallthrough=]
230 | if (pci_alloc_irq_vectors(udev->pdev, 1, 1, PCI_IRQ_MSIX) == 1) {
| ^
/root/dpdk-19.11/x86_64-native-linuxapp-gcc/build/kernel/linux/igb_uio/igb_uio.c:240:9: note: here
240 | case RTE_INTR_MODE_MSI:
| ^~~~
/root/dpdk-19.11/x86_64-native-linuxapp-gcc/build/kernel/linux/igb_uio/igb_uio.c:250:20: error: this statement may fall through [-Werror=implicit-fallthrough=]
250 | if (pci_alloc_irq_vectors(udev->pdev, 1, 1, PCI_IRQ_MSI) == 1) {
| ^
/root/dpdk-19.11/x86_64-native-linuxapp-gcc/build/kernel/linux/igb_uio/igb_uio.c:259:9: note: here
259 | case RTE_INTR_MODE_LEGACY:
| ^~~~
In file included from ./include/linux/device.h:15,
from /root/dpdk-19.11/x86_64-native-linuxapp-gcc/build/kernel/linux/igb_uio/igb_uio.c:8:
./include/linux/dev_printk.h:148:31: error: this statement may fall through [-Werror=implicit-fallthrough=]
148 | dev_printk_index_wrap(_dev_notice, KERN_NOTICE, dev, dev_fmt(fmt), ##__VA_ARGS__)
| ^
./include/linux/dev_printk.h:110:17: note: in definition of macro ‘dev_printk_index_wrap’
110 | _p_func(dev, fmt, ##__VA_ARGS__); \
| ^~~~~~~
/root/dpdk-19.11/x86_64-native-linuxapp-gcc/build/kernel/linux/igb_uio/igb_uio.c:267:17: note: in expansion of macro ‘dev_notice’
267 | dev_notice(&udev->pdev->dev, "PCI INTX mask not supported\n");
| ^~~~~~~~~~
/root/dpdk-19.11/x86_64-native-linuxapp-gcc/build/kernel/linux/igb_uio/igb_uio.c:269:9: note: here
269 | case RTE_INTR_MODE_NONE:
| ^~~~
cc1: all warnings being treated as errors
解决办法:
修改 x86_64-native-linuxapp-gcc/build/kernel/linux/igb_uio/Makefile 文件,去掉“MODULE_CFLAGS += -Winline -Wall -Werror” -行的 -Werror 编译选项。
2. error: passing argument 1 of ‘get_user_pages_remote’ from incompatible pointer type
== Build kernel/linux/kni
CC [M] /root/dpdk-19.11/x86_64-native-linuxapp-gcc/build/kernel/linux/kni/kni_misc.o
In file included from /root/dpdk-19.11/x86_64-native-linuxapp-gcc/build/kernel/linux/kni/kni_misc.c:22:
/root/dpdk-19.11/kernel/linux/kni/kni_dev.h: In function ‘iova_to_phys’:
/root/dpdk-19.11/kernel/linux/kni/kni_dev.h:104:37: error: passing argument 1 of ‘get_user_pages_remote’ from incompatible pointer type [-Werror=incompatible-pointer-types]
104 | ret = get_user_pages_remote(tsk, tsk->mm, iova, 1,
| ^~~
| |
| struct task_struct *
In file included from ./arch/x86/include/asm/cacheflush.h:5,
from ./include/linux/cacheflush.h:5,
from ./include/linux/highmem.h:8,
from ./include/linux/bvec.h:10,
from ./include/linux/skbuff.h:17,
from ./include/net/net_namespace.h:39,
from ./include/linux/netdevice.h:37,
from /root/dpdk-19.11/x86_64-native-linuxapp-gcc/build/kernel/linux/kni/kni_misc.c:9:
./include/linux/mm.h:1943:46: note: expected ‘struct mm_struct *’ but argument is of type ‘struct task_struct *’
1943 | long get_user_pages_remote(struct mm_struct *mm,
| ~~~~~~~~~~~~~~~~~~^~
解决办法:
修改 kernel/linux/kni/kni_dev.h 文件104行,改成:
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 9, 0)
ret = get_user_pages_remote(tsk->mm, iova, 1,
FOLL_TOUCH, &page, NULL, NULL);
#else
ret = get_user_pages_remote(tsk, tsk->mm, iova, 1,
FOLL_TOUCH, &page, NULL, NULL);
#endif /* >= 5.9.0 */
== Build kernel/linux/kni
CC [M] /root/dpdk-19.11/x86_64-native-linuxapp-gcc/build/kernel/linux/kni/kni_misc.o
/root/dpdk-19.11/x86_64-native-linuxapp-gcc/build/kernel/linux/kni/kni_misc.c: In function ‘kni_ioctl_create’:
/root/dpdk-19.11/x86_64-native-linuxapp-gcc/build/kernel/linux/kni/kni_misc.c:406:17: error: implicit declaration of function ‘random_ether_addr’ [-Werror=implicit-function-declaration]
406 | random_ether_addr(net_dev->dev_addr);
| ^~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
解决办法:
修改 x86_64-native-linuxapp-gcc/build/kernel/linux/kni/kni_misc.c 文件 406行,
将 random_ether_addr 函数修改为 eth_random_addr。
== Build kernel/linux/kni
CC [M] /root/dpdk-19.11/x86_64-native-linuxapp-gcc/build/kernel/linux/kni/kni_misc.o
CC [M] /root/dpdk-19.11/x86_64-native-linuxapp-gcc/build/kernel/linux/kni/kni_net.o
/root/dpdk-19.11/x86_64-native-linuxapp-gcc/build/kernel/linux/kni/kni_net.c:786:27: error: initialization of ‘void (*)(struct net_device *, unsigned int)’ from incompatible pointer type ‘void (*)(struct net_device *)’ [-Werror=incompatible-pointer-types]
786 | .ndo_tx_timeout = kni_net_tx_timeout,
| ^~~~~~~~~~~~~~~~~~
/root/dpdk-19.11/x86_64-native-linuxapp-gcc/build/kernel/linux/kni/kni_net.c:786:27: note: (near initialization for ‘kni_net_netdev_ops.ndo_tx_timeout’)
cc1: all warnings being treated as errors
解决办法:
修改 x86_64-native-linuxapp-gcc/build/kernel/linux/kni/Makefile 文件,MODULE_CFLAGS += -Wall -Werror 这一行追加 -Wno-error=incompatible-pointer-types 编译选项