From b55886e8bf9176ea358905231d2b3a98ae2820e5 Mon Sep 17 00:00:00 2001 From: Ren Zhijie Date: Thu, 1 Dec 2022 18:23:14 +0800 Subject: [PATCH 1/2] sched: programmable: fix build error of bpf_topology MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I645C7 CVE: NA -------------------------------- make ARCH="arm64" CROSS_COMPILE="aarch64-linux-gnu-", gcc complained as follow: In file included from ./arch/arm64/include/asm/topology.h:17:0, from ./arch/arm64/include/asm/numa.h:5, from ./arch/arm64/include/asm/mmzone.h:7, from ./include/linux/mmzone.h:1025, from ./include/linux/gfp.h:6, from ./include/linux/umh.h:4, from ./include/linux/kmod.h:9, from ./include/linux/module.h:16, from ./include/linux/bpf.h:20, from kernel/sched/bpf_topology.c:15: kernel/sched/bpf_topology.c: In function ‘bpf_update_cpu_topology’: ./include/linux/arch_topology.h:64:62: error: ‘struct bpf_cpu_topology’ has no member named ‘package_id’; did you mean ‘package_cpus’? #define topology_physical_package_id(cpu) (cpu_topology[cpu].package_id) kernel/sched/bpf_topology.c:57:20: warning: ‘bpf_cpu_topology_ids’ defined but not used [-Wunused-variable] BTF_ID_LIST_SINGLE(bpf_cpu_topology_ids, struct, bpf_cpu_topology) To fix this error, change local variable cpu_topology to bpf_cpu_topology and delete the definition of bpf_cpu_topology_ids. Fixes: f333bd6882e7 ("sched: programmable: Add helper function for...") Signed-off-by: Ren Zhijie Signed-off-by: Hui Tang --- kernel/sched/bpf_topology.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/kernel/sched/bpf_topology.c b/kernel/sched/bpf_topology.c index a843aebd0c14..69541dc6a983 100644 --- a/kernel/sched/bpf_topology.c +++ b/kernel/sched/bpf_topology.c @@ -20,20 +20,20 @@ #include #include -static void bpf_update_cpu_topology(struct bpf_cpu_topology *cpu_topology, int cpu) +static void bpf_update_cpu_topology(struct bpf_cpu_topology *bpf_cpu_topology, int cpu) { - cpu_topology->cpu = cpu; - cpu_topology->core_id = topology_core_id(cpu); - cpu_topology->cluster_id = topology_cluster_id(cpu); - cpu_topology->die_id = topology_die_id(cpu); - cpu_topology->physical_package_id = topology_physical_package_id(cpu); - cpu_topology->numa_node = cpu_to_node(cpu); - cpumask_copy(&cpu_topology->thread_siblings, topology_sibling_cpumask(cpu)); - cpumask_copy(&cpu_topology->core_siblings, topology_core_cpumask(cpu)); - cpumask_copy(&cpu_topology->cluster_cpus, topology_cluster_cpumask(cpu)); - cpumask_copy(&cpu_topology->die_cpus, topology_die_cpumask(cpu)); - cpumask_copy(&cpu_topology->package_cpus, topology_core_cpumask(cpu)); - cpumask_copy(&cpu_topology->node_cpu_lists, cpumask_of_node(cpu_to_node(cpu))); + bpf_cpu_topology->cpu = cpu; + bpf_cpu_topology->core_id = topology_core_id(cpu); + bpf_cpu_topology->cluster_id = topology_cluster_id(cpu); + bpf_cpu_topology->die_id = topology_die_id(cpu); + bpf_cpu_topology->physical_package_id = topology_physical_package_id(cpu); + bpf_cpu_topology->numa_node = cpu_to_node(cpu); + cpumask_copy(&bpf_cpu_topology->thread_siblings, topology_sibling_cpumask(cpu)); + cpumask_copy(&bpf_cpu_topology->core_siblings, topology_core_cpumask(cpu)); + cpumask_copy(&bpf_cpu_topology->cluster_cpus, topology_cluster_cpumask(cpu)); + cpumask_copy(&bpf_cpu_topology->die_cpus, topology_die_cpumask(cpu)); + cpumask_copy(&bpf_cpu_topology->package_cpus, topology_core_cpumask(cpu)); + cpumask_copy(&bpf_cpu_topology->node_cpu_lists, cpumask_of_node(cpu_to_node(cpu))); } BPF_CALL_1(bpf_init_cpu_topology, struct bpf_map *, map) @@ -54,8 +54,6 @@ BPF_CALL_1(bpf_init_cpu_topology, struct bpf_map *, map) return 0; } -BTF_ID_LIST_SINGLE(bpf_cpu_topology_ids, struct, bpf_cpu_topology) - const struct bpf_func_proto bpf_init_cpu_topology_proto = { .func = bpf_init_cpu_topology, .gpl_only = false, -- Gitee From 6d1c9cd32496d1bb227c229bd1518ba7b9a047bb Mon Sep 17 00:00:00 2001 From: Hui Tang Date: Thu, 1 Dec 2022 19:53:31 +0800 Subject: [PATCH 2/2] sched: programmable: Fix build error for nr_cpus_ids MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I645C7 CVE: NA -------------------------------- When !CONFIG_SMP && CONFIG_BPF_SCHED, it will build error, as follows: ./include/linux/cpumask.h:37:33: error: expected identifier or ‘(’ before numeric constant 37 | #define nr_cpu_ids 1U | ^~ ./include/linux/bpf_topology.h:39:22: note: in expansion of macro ‘nr_cpu_ids’ 39 | unsigned int nr_cpu_ids; | ^~~~~~~~~~ kernel/sched/bpf_topology.c: In function ‘____bpf_get_cpumask_info’: ./include/linux/cpumask.h:37:33: error: expected identifier before numeric constant 37 | #define nr_cpu_ids 1U | ^~ kernel/sched/bpf_topology.c:75:15: note: in expansion of macro ‘nr_cpu_ids’ 75 | cpus->nr_cpu_ids = nr_cpu_ids; Fixes: f333bd6882e7 ("sched: programmable: Add helper function for...") Signed-off-by: Hui Tang --- include/linux/bpf_topology.h | 2 +- kernel/sched/bpf_topology.c | 2 +- tools/lib/bpf/libbpf_sched.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/linux/bpf_topology.h b/include/linux/bpf_topology.h index 0c7ee492edde..b2c6d621821d 100644 --- a/include/linux/bpf_topology.h +++ b/include/linux/bpf_topology.h @@ -36,7 +36,7 @@ struct bpf_cpumask_info { unsigned int nums_possible_cpus; unsigned int nums_active_cpus; unsigned int nums_isolate_cpus; - unsigned int nr_cpu_ids; + unsigned int bpf_nr_cpu_ids; unsigned int bpf_nr_cpumask_bits; struct cpumask cpu_possible_cpumask; struct cpumask cpu_active_cpumask; diff --git a/kernel/sched/bpf_topology.c b/kernel/sched/bpf_topology.c index 69541dc6a983..ce6cb8277246 100644 --- a/kernel/sched/bpf_topology.c +++ b/kernel/sched/bpf_topology.c @@ -72,7 +72,7 @@ BPF_CALL_2(bpf_get_cpumask_info, struct bpf_map *, map, struct bpf_cpumask_info cpus->nums_possible_cpus = num_possible_cpus(); cpus->nums_active_cpus = num_active_cpus(); cpus->nums_isolate_cpus = cpumask_weight(&cpus->cpu_isolate_cpumask); - cpus->nr_cpu_ids = nr_cpu_ids; + cpus->bpf_nr_cpu_ids = nr_cpu_ids; cpus->bpf_nr_cpumask_bits = nr_cpumask_bits; return 0; diff --git a/tools/lib/bpf/libbpf_sched.h b/tools/lib/bpf/libbpf_sched.h index b2008ff6bb25..04b43c145fcd 100644 --- a/tools/lib/bpf/libbpf_sched.h +++ b/tools/lib/bpf/libbpf_sched.h @@ -310,7 +310,7 @@ static __always_inline int libbpf_nr_cpus_ids(void) return -1; bpf_get_cpumask_info(&map_cpumask_info, cpus); - return getVal(cpus->nr_cpu_ids); + return getVal(cpus->bpf_nr_cpu_ids); } static __always_inline int libbpf_nr_cpumask_bits(void) -- Gitee