提交 66648b66 编写于 作者: S Shuyi Cheng 提交者: Zheng Zengkai

libbpf: Add "bool skipped" to struct bpf_map

mainline inclusion
from mainline-5.17-rc1
commit 229fae38
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I5EUVD
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=229fae38d0fc0d6ff58d57cbeb1432da55e58d4f

-------------------------------------------------

Fix error: "failed to pin map: Bad file descriptor, path:
/sys/fs/bpf/_rodata_str1_1."

In the old kernel, the global data map will not be created, see [0]. So
we should skip the pinning of the global data map to avoid
bpf_object__pin_maps returning error. Therefore, when the map is not
created, we mark “map->skipped" as true and then check during relocation
and during pinning.

Fixes: 16e0c35c ("libbpf: Load global data maps lazily on legacy kernels")
Signed-off-by: NShuyi Cheng <chengshuyi@linux.alibaba.com>
Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
(cherry picked from commit 229fae38)
Signed-off-by: NWang Yufen <wangyufen@huawei.com>

Conflicts:
	tools/lib/bpf/libbpf.c
Signed-off-by: NWang Yufen <wangyufen@huawei.com>
上级 214ab1b8
......@@ -388,6 +388,7 @@ struct bpf_map {
char *pin_path;
bool pinned;
bool reused;
bool skipped;
};
enum extern_type {
......@@ -5041,8 +5042,10 @@ bpf_object__create_maps(struct bpf_object *obj)
* kernels.
*/
if (bpf_map__is_internal(map) &&
!kernel_supports(obj, FEAT_GLOBAL_DATA))
!kernel_supports(obj, FEAT_GLOBAL_DATA)) {
map->skipped = true;
continue;
}
retried = false;
retry:
......@@ -5671,8 +5674,7 @@ bpf_object__relocate_data(struct bpf_object *obj, struct bpf_program *prog)
} else {
const struct bpf_map *map = &obj->maps[relo->map_idx];
if (bpf_map__is_internal(map) &&
!kernel_supports(obj, FEAT_GLOBAL_DATA)) {
if (map->skipped) {
pr_warn("prog '%s': relo #%d: kernel doesn't support global data\n",
prog->name, i);
return -ENOTSUP;
......@@ -7837,6 +7839,9 @@ int bpf_object__pin_maps(struct bpf_object *obj, const char *path)
char *pin_path = NULL;
char buf[PATH_MAX];
if (map->skipped)
continue;
if (path) {
int len;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册