From 2ca1ef1b7079ed6766ce3190df974384d475b2ff Mon Sep 17 00:00:00 2001 From: bitcoffee Date: Tue, 7 Mar 2023 17:01:21 +0800 Subject: [PATCH] Kmesh: fix node clean failed in rb tree When deleteing a red-black tree, do not use the rb_erase interface. This inerface will cause the red-black tree to be rebalanced. As a result, nodes are lost during deletion. The correct approach would be to use the subsequent output node and directly release and leave the root node pointer empty. Signed-off-by: bitcoffee --- ...esh-fix-node-clean-failed-in-rb-tree.patch | 57 +++++++++++++++++++ Kmesh.spec | 6 +- 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 0003-Kmesh-fix-node-clean-failed-in-rb-tree.patch diff --git a/0003-Kmesh-fix-node-clean-failed-in-rb-tree.patch b/0003-Kmesh-fix-node-clean-failed-in-rb-tree.patch new file mode 100644 index 0000000..cb9cc34 --- /dev/null +++ b/0003-Kmesh-fix-node-clean-failed-in-rb-tree.patch @@ -0,0 +1,57 @@ +From 437d126ec9fe1af935adc8bd61b8adc943a1e6c1 Mon Sep 17 00:00:00 2001 +From: bitcoffee +Date: Tue, 7 Mar 2023 14:53:56 +0800 +Subject: [PATCH] Kmesh: fix node clean failed in rb tree + +When deleteing a red-black tree, do not use the rb_erase interface. +This inerface will cause the red-black tree to be rebalanced. As a +result, nodes are lost during deletion. The correct approach would +be to use the subsequent output node and directly release and leave +the root node pointer empty. + +Signed-off-by: bitcoffee +--- + kernel/ko_src/kmesh/kmesh_parse_protocol_data.c | 8 +++++--- + 1 file changed, 5 insertions(+), 3 deletions(-) + +diff --git a/kernel/ko_src/kmesh/kmesh_parse_protocol_data.c b/kernel/ko_src/kmesh/kmesh_parse_protocol_data.c +index 0d91a07..f4dd6d3 100644 +--- a/kernel/ko_src/kmesh/kmesh_parse_protocol_data.c ++++ b/kernel/ko_src/kmesh/kmesh_parse_protocol_data.c +@@ -98,16 +98,15 @@ static void kmesh_protocol_clean_all(struct rb_root *kmesh_data_root) + struct kmesh_data_node* n = NULL; + if (!kmesh_data_root) + return; +- rbtree_postorder_for_each_entry_safe(data, n, kmesh_data_root, node) { +- rb_erase(&data->node, kmesh_data_root); ++ rbtree_postorder_for_each_entry_safe(data, n, kmesh_data_root, node) + delete_kmesh_data_node(&data); +- } + } + + void kmesh_protocol_data_clean_all(void) + { + struct rb_root *kmesh_data_root = per_cpu_ptr(g_kmesh_data_root, raw_smp_processor_id()); + kmesh_protocol_clean_all(kmesh_data_root); ++ kmesh_data_root->rb_node = NULL; + } + + void kmesh_protocol_data_clean_allcpu(void) +@@ -155,6 +154,8 @@ int __init proto_common_init(void) + get_protocol_element_func = get_protocol_element_impl; + /* add protocol list */ + g_kmesh_data_root = alloc_percpu(struct rb_root); ++ if (!g_kmesh_data_root) ++ return -ENOMEM; + + return 0; + } +@@ -164,4 +165,5 @@ void __exit proto_common_exit(void) + parse_protocol_func = NULL; + get_protocol_element_func = NULL; + kmesh_protocol_data_clean_allcpu(); ++ free_percpu(g_kmesh_data_root); + } +-- +2.39.1 + diff --git a/Kmesh.spec b/Kmesh.spec index 8d2c61e..a16c64e 100644 --- a/Kmesh.spec +++ b/Kmesh.spec @@ -2,7 +2,7 @@ Name: Kmesh Version: 0.2.0 -Release: 2 +Release: 3 Summary: %{name} is a eBPF-based service mesh kernel solution License: Mulan PSL v2 URL: https://gitee.com/openeuler/%{name} @@ -22,6 +22,7 @@ Requires: libboundscheck Patch0001: 0001-fix-makefile-not-found-pc-file.patch Patch0002: 0002-fix-ubuf-not-use-sockops-and-tcp-state.patch +Patch0003: 0003-Kmesh-fix-node-clean-failed-in-rb-tree.patch %description %{name} is a eBPF-based service mesh kernel solution. @@ -102,6 +103,9 @@ rm -rf %{buildroot} %attr(0550,root,root) /usr/bin/kmesh-stop-post.sh %changelog +* Tue Mar 07 2023 liuxin - 0.2.0-3 +- fix kmesh clean node data failed + * Fri Mar 03 2023 liuxin - 0.2.0-2 - fix ubuf skip sockops and incorrect tcp state occur crash -- Gitee