
hulk inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/ICA1GK -------------------------------- Add kfunc to retrieve content of x86's direct_pages_count[]. Signed-off-by: GONG Ruiqi <gongruiqi1@huawei.com> --- arch/x86/mm/pat/set_memory.c | 7 +++++++ kernel/bpf-rvi/common_kfuncs.c | 14 ++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c index 2d850f6bae70..0231d2b7f569 100644 --- a/arch/x86/mm/pat/set_memory.c +++ b/arch/x86/mm/pat/set_memory.c @@ -122,6 +122,13 @@ void arch_report_meminfo(struct seq_file *m) seq_printf(m, "DirectMap1G: %8lu kB\n", direct_pages_count[PG_LEVEL_1G] << 20); } + +#ifdef CONFIG_BPF_RVI +const unsigned long *x86_get_direct_pages_count(void) +{ + return direct_pages_count; +} +#endif #else static inline void split_page_count(int level) { } #endif diff --git a/kernel/bpf-rvi/common_kfuncs.c b/kernel/bpf-rvi/common_kfuncs.c index 58ec75b06123..b0f33fd0201d 100644 --- a/kernel/bpf-rvi/common_kfuncs.c +++ b/kernel/bpf-rvi/common_kfuncs.c @@ -267,6 +267,19 @@ __bpf_kfunc unsigned long bpf_mem_vmalloc_total(void) return (unsigned long)VMALLOC_TOTAL >> 10; } +#ifdef CONFIG_X86 +const unsigned long *x86_get_direct_pages_count(void); + +__bpf_kfunc void bpf_x86_direct_pages(unsigned long *p) +{ + memcpy(p, x86_get_direct_pages_count(), PG_LEVEL_NUM); +} +#else +__bpf_kfunc void bpf_x86_direct_pages(unsigned long *p) +{ +} +#endif + BTF_SET8_START(bpf_common_kfuncs_ids) BTF_ID_FLAGS(func, bpf_mem_cgroup_from_task, KF_RET_NULL | KF_RCU) BTF_ID_FLAGS(func, bpf_task_active_pid_ns, KF_TRUSTED_ARGS) @@ -295,6 +308,7 @@ BTF_ID_FLAGS(func, bpf_mem_commit_limit) BTF_ID_FLAGS(func, bpf_mem_committed) BTF_ID_FLAGS(func, bpf_mem_vmalloc_used) BTF_ID_FLAGS(func, bpf_mem_vmalloc_total) +BTF_ID_FLAGS(func, bpf_x86_direct_pages, KF_TRUSTED_ARGS) BTF_SET8_END(bpf_common_kfuncs_ids) static const struct btf_kfunc_id_set bpf_common_kfuncs_set = { -- 2.25.1