From 04eb3718e680e82730426074cd52390902731b96 Mon Sep 17 00:00:00 2001 From: Kshitij Rana Date: Tue, 18 Feb 2025 16:25:15 -0500 Subject: [PATCH 1/5] Support for Ubuntu 22.04 --- bessctl/sugar.py | 6 ++--- build.py | 24 +++++++++++++++++++ core/Makefile | 4 ++-- core/kmod/sn_ethtool.c | 1 + core/modules/l2_forward.cc | 4 ++-- core/utils/exact_match_table.h | 3 +++ deps/linux_5_15.patch | 44 ++++++++++++++++++++++++++++++++++ 7 files changed, 79 insertions(+), 7 deletions(-) create mode 100644 deps/linux_5_15.patch diff --git a/bessctl/sugar.py b/bessctl/sugar.py index 86484d0cd..89d629719 100644 --- a/bessctl/sugar.py +++ b/bessctl/sugar.py @@ -31,7 +31,7 @@ from __future__ import print_function import re import tokenize -import parser +import ast import io ''' @@ -171,8 +171,8 @@ def is_gate_expr(exp, is_ogate): exp_stripped = exp_stripped[:-1].strip() try: - parser.expr('(%s)' % exp_stripped) - parser.expr('%s%s%s' % (prefix, exp, postfix)) + ast.parse('(%s)' % exp_stripped, mode='eval') + ast.parse('%s%s%s' % (prefix, exp, postfix), mode='eval') except SyntaxError: return False else: diff --git a/build.py b/build.py index ff4289523..fcb0981a2 100755 --- a/build.py +++ b/build.py @@ -41,7 +41,26 @@ import subprocess import textwrap import argparse +import platform +from packaging import version +def get_kernel_version(): + try: + kernel_ver = platform.release().split('-')[0] + return kernel_ver + except Exception as e: + print(f"Error getting kernel version: {e}") + return None + +def is_kernel_version_equal(version_to_check): + """ + Check if current kernel version is equal to the specified version + Example: is_kernel_version_equal("5.15.0") + """ + current_version = get_kernel_version() + if current_version: + return version.parse(current_version) == version.parse(version_to_check) + return False def cmd(cmd, quiet=False, shell=False): """ @@ -338,6 +357,11 @@ def build_dpdk(): configure_dpdk() for f in glob.glob('%s/*.patch' % DEPS_DIR): + # skip the kernel 5.15 patch if we are not running kernel 5.15 + is_5_15_patch = "linux_5_15.patch" in f + is_wrong_kernel = not is_kernel_version_equal("5.15.0") + if is_5_15_patch and is_wrong_kernel: + continue print('Applying patch %s' % f) cmd('patch -d %s -N -p1 < %s || true' % (DPDK_DIR, f), shell=True) diff --git a/core/Makefile b/core/Makefile index cff111737..aeb1db46e 100644 --- a/core/Makefile +++ b/core/Makefile @@ -78,9 +78,9 @@ endif # We always want these libraries to be dynamically linked even when the # user requests a static build. -ALWAYS_DYN_LIBS := -lpthread -ldl +ALWAYS_DYN_LIBS := -lpcap -lpthread -ldl -lunwind -lgrpc++ # These libraries are not supported by pkg-config. -ALWAYS_LIBS := -lpcap -lgflags -lnuma +ALWAYS_LIBS := -lgflags -lnuma # If pkg-config is available, we just need a list of the dependecies. PKG_CONFIG_DEPS := libglog protobuf grpc++ libunwind zlib # If pkg-config is not available, we need to list the libs we depend on. diff --git a/core/kmod/sn_ethtool.c b/core/kmod/sn_ethtool.c index 55649a092..22f1f0b65 100644 --- a/core/kmod/sn_ethtool.c +++ b/core/kmod/sn_ethtool.c @@ -31,6 +31,7 @@ #include "sn_common.h" #include "sn_kernel.h" #include "../snbuf_layout.h" +#include #define NUM_STATS_PER_TX_QUEUE (sizeof(struct sn_queue_tx_stats) / sizeof(u64)) #define NUM_STATS_PER_RX_QUEUE (sizeof(struct sn_queue_rx_stats) / sizeof(u64)) diff --git a/core/modules/l2_forward.cc b/core/modules/l2_forward.cc index 546462513..d2c2c60f8 100644 --- a/core/modules/l2_forward.cc +++ b/core/modules/l2_forward.cc @@ -370,7 +370,7 @@ static uint64_t l2_addr_to_u64(char *addr) { static void l2_forward_init_test() { int ret; - struct l2_table l2tbl; + struct l2_table l2tbl = {}; ret = l2_init(&l2tbl, 0, 0); DCHECK_LT(ret, 0); @@ -445,7 +445,7 @@ static void l2_forward_entry_test() { static void l2_forward_flush_test() { int ret; - struct l2_table l2tbl; + struct l2_table l2tbl = {}; uint64_t addr1 = 0x0123456701234567; uint16_t index1 = 0x0123; diff --git a/core/utils/exact_match_table.h b/core/utils/exact_match_table.h index 7c0cfda42..d00bce196 100644 --- a/core/utils/exact_match_table.h +++ b/core/utils/exact_match_table.h @@ -395,6 +395,9 @@ class ExactMatchTable { return MakeError(EINVAL, Format("idx %d is not in [0,%d)", idx, MAX_FIELDS)); } + if (m == nullptr) { + return MakeError(EINVAL, Format("idx %d: module pointer is null", idx)); + } ExactMatchField *f = &fields_[idx]; f->size = field.size; if (f->size < 1 || f->size > MAX_FIELD_SIZE) { diff --git a/deps/linux_5_15.patch b/deps/linux_5_15.patch new file mode 100644 index 000000000..a0e6b1758 --- /dev/null +++ b/deps/linux_5_15.patch @@ -0,0 +1,44 @@ +diff --git a/kernel/linux/igb_uio/igb_uio.c b/kernel/linux/igb_uio/igb_uio.c +index 039f5a5f63..57d0c58ab1 100644 +--- a/kernel/linux/igb_uio/igb_uio.c ++++ b/kernel/linux/igb_uio/igb_uio.c +@@ -236,7 +236,7 @@ igbuio_pci_enable_interrupts(struct rte_uio_pci_dev *udev) + } + #endif + +- /* falls through - to MSI */ ++ fallthrough; + case RTE_INTR_MODE_MSI: + #ifndef HAVE_ALLOC_IRQ_VECTORS + if (pci_enable_msi(udev->pdev) == 0) { +@@ -255,7 +255,7 @@ igbuio_pci_enable_interrupts(struct rte_uio_pci_dev *udev) + break; + } + #endif +- /* falls through - to INTX */ ++ fallthrough; + case RTE_INTR_MODE_LEGACY: + if (pci_intx_mask_supported(udev->pdev)) { + dev_dbg(&udev->pdev->dev, "using INTX"); +@@ -265,7 +265,7 @@ igbuio_pci_enable_interrupts(struct rte_uio_pci_dev *udev) + break; + } + dev_notice(&udev->pdev->dev, "PCI INTX mask not supported\n"); +- /* falls through - to no IRQ */ ++ fallthrough; + case RTE_INTR_MODE_NONE: + udev->mode = RTE_INTR_MODE_NONE; + udev->info.irq = UIO_IRQ_NONE; +diff --git a/kernel/linux/kni/kni_dev.h b/kernel/linux/kni/kni_dev.h +index 5e75c6371f..4f36b23fe7 100644 +--- a/kernel/linux/kni/kni_dev.h ++++ b/kernel/linux/kni/kni_dev.h +@@ -101,7 +101,7 @@ static inline phys_addr_t iova_to_phys(struct task_struct *tsk, + offset = iova & (PAGE_SIZE - 1); + + /* Read one page struct info */ +- ret = get_user_pages_remote(tsk, tsk->mm, iova, 1, ++ ret = get_user_pages_remote(tsk->mm, iova, 1, + FOLL_TOUCH, &page, NULL, NULL); + if (ret < 0) + return 0; From de1a0ebe0dba6a70b9389de7d0c24aa3696071de Mon Sep 17 00:00:00 2001 From: Kshitij Rana Date: Tue, 18 Feb 2025 18:34:10 -0500 Subject: [PATCH 2/5] Updated kernel version check --- build.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/build.py b/build.py index fcb0981a2..4210249ee 100755 --- a/build.py +++ b/build.py @@ -52,14 +52,14 @@ def get_kernel_version(): print(f"Error getting kernel version: {e}") return None -def is_kernel_version_equal(version_to_check): +def is_kernel_version_grtr_eq(version_to_check): """ Check if current kernel version is equal to the specified version Example: is_kernel_version_equal("5.15.0") """ current_version = get_kernel_version() if current_version: - return version.parse(current_version) == version.parse(version_to_check) + return version.parse(current_version) >= version.parse(version_to_check) return False def cmd(cmd, quiet=False, shell=False): @@ -357,9 +357,9 @@ def build_dpdk(): configure_dpdk() for f in glob.glob('%s/*.patch' % DEPS_DIR): - # skip the kernel 5.15 patch if we are not running kernel 5.15 + # skip the kernel 5.15 patch if we running under v5.15 is_5_15_patch = "linux_5_15.patch" in f - is_wrong_kernel = not is_kernel_version_equal("5.15.0") + is_wrong_kernel = not is_kernel_version_grtr_eq("5.15.0") if is_5_15_patch and is_wrong_kernel: continue print('Applying patch %s' % f) From e917b60ea5408f977bc940d422e0966351d55c0a Mon Sep 17 00:00:00 2001 From: Kshitij Rana Date: Tue, 18 Feb 2025 18:53:02 -0500 Subject: [PATCH 3/5] Removed static libraries that are now linked dynamically --- core/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/Makefile b/core/Makefile index aeb1db46e..6829c62aa 100644 --- a/core/Makefile +++ b/core/Makefile @@ -82,9 +82,9 @@ ALWAYS_DYN_LIBS := -lpcap -lpthread -ldl -lunwind -lgrpc++ # These libraries are not supported by pkg-config. ALWAYS_LIBS := -lgflags -lnuma # If pkg-config is available, we just need a list of the dependecies. -PKG_CONFIG_DEPS := libglog protobuf grpc++ libunwind zlib +PKG_CONFIG_DEPS := libglog protobuf # If pkg-config is not available, we need to list the libs we depend on. -NO_PKG_CONFIG_LIBS := -lglog -lgflags -lprotobuf -lgrpc++ -lunwind -lz +NO_PKG_CONFIG_LIBS := -lglog -lgflags -lprotobuf # If pkg-config is not available and we're static linking, we also need # the indirect dependecies. This is annoying, because they may change # in future versions. From 7feb6dc9e7b4369a16a83529cdca8d0a64244327 Mon Sep 17 00:00:00 2001 From: Kshitij Rana Date: Tue, 18 Feb 2025 19:15:25 -0500 Subject: [PATCH 4/5] Removed libunwind shared linking --- core/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/Makefile b/core/Makefile index 6829c62aa..cd227472f 100644 --- a/core/Makefile +++ b/core/Makefile @@ -78,7 +78,7 @@ endif # We always want these libraries to be dynamically linked even when the # user requests a static build. -ALWAYS_DYN_LIBS := -lpcap -lpthread -ldl -lunwind -lgrpc++ +ALWAYS_DYN_LIBS := -lpcap -lpthread -ldl -lgrpc++ # These libraries are not supported by pkg-config. ALWAYS_LIBS := -lgflags -lnuma # If pkg-config is available, we just need a list of the dependecies. From 9a371eb296a4f9a89a84613d75403ed55c5fd7df Mon Sep 17 00:00:00 2001 From: Kshitij Rana Date: Tue, 18 Feb 2025 21:13:11 -0500 Subject: [PATCH 5/5] Updated version of the kernel patch --- build.py | 8 ++++---- deps/{linux_5_15.patch => linux_5_9.patch} | 0 2 files changed, 4 insertions(+), 4 deletions(-) rename deps/{linux_5_15.patch => linux_5_9.patch} (100%) diff --git a/build.py b/build.py index 4210249ee..6f5cc2f85 100755 --- a/build.py +++ b/build.py @@ -357,10 +357,10 @@ def build_dpdk(): configure_dpdk() for f in glob.glob('%s/*.patch' % DEPS_DIR): - # skip the kernel 5.15 patch if we running under v5.15 - is_5_15_patch = "linux_5_15.patch" in f - is_wrong_kernel = not is_kernel_version_grtr_eq("5.15.0") - if is_5_15_patch and is_wrong_kernel: + # skip the kernel 5.9 patch if we running under v5.9 + is_5_9_patch = "linux_5_9.patch" in f + is_wrong_kernel = not is_kernel_version_grtr_eq("5.9.0") + if is_5_9_patch and is_wrong_kernel: continue print('Applying patch %s' % f) cmd('patch -d %s -N -p1 < %s || true' % (DPDK_DIR, f), shell=True) diff --git a/deps/linux_5_15.patch b/deps/linux_5_9.patch similarity index 100% rename from deps/linux_5_15.patch rename to deps/linux_5_9.patch