[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <5dcc65d33bdfa_14082b1d9b77e5b4eb@john-XPS-13-9370.notmuch>
Date: Wed, 13 Nov 2019 12:21:39 -0800
From: John Fastabend <john.fastabend@...il.com>
To: Andrii Nakryiko <andriin@...com>, bpf@...r.kernel.org,
netdev@...r.kernel.org, ast@...com, daniel@...earbox.net
Cc: andrii.nakryiko@...il.com, kernel-team@...com,
Andrii Nakryiko <andriin@...com>
Subject: RE: [PATCH v3 bpf-next 2/3] libbpf: make global data internal arrays
mmap()-able, if possible
Andrii Nakryiko wrote:
> Add detection of BPF_F_MMAPABLE flag support for arrays and add it as an extra
> flag to internal global data maps, if supported by kernel. This allows users
> to memory-map global data and use it without BPF map operations, greatly
> simplifying user experience.
>
> Acked-by: Song Liu <songliubraving@...com>
> Signed-off-by: Andrii Nakryiko <andriin@...com>
> ---
[...]
> /*
> @@ -856,8 +858,6 @@ bpf_object__init_internal_map(struct bpf_object *obj, enum libbpf_map_type type,
> pr_warn("failed to alloc map name\n");
> return -ENOMEM;
> }
> - pr_debug("map '%s' (global data): at sec_idx %d, offset %zu.\n",
> - map_name, map->sec_idx, map->sec_offset);
>
> def = &map->def;
> def->type = BPF_MAP_TYPE_ARRAY;
> @@ -865,6 +865,12 @@ bpf_object__init_internal_map(struct bpf_object *obj, enum libbpf_map_type type,
> def->value_size = data->d_size;
> def->max_entries = 1;
> def->map_flags = type == LIBBPF_MAP_RODATA ? BPF_F_RDONLY_PROG : 0;
> + if (obj->caps.array_mmap)
> + def->map_flags |= BPF_F_MMAPABLE;
> +
> + pr_debug("map '%s' (global data): at sec_idx %d, offset %zu, flags %x.\n",
> + map_name, map->sec_idx, map->sec_offset, def->map_flags);
> +
> if (data_buff) {
> *data_buff = malloc(data->d_size);
> if (!*data_buff) {
> @@ -2160,6 +2166,27 @@ static int bpf_object__probe_btf_datasec(struct bpf_object *obj)
> return 0;
> }
I was a bit concerned we should fall back to making the call without the
BPF_F_MMAPABLE flag set if it fails but did a quick walk through the call
path and it seems like it shouldn't fail except if vmalloc/vzalloc failures
so seems fine.
Acked-by: John Fastabend <john.fastabend@...il.com>
Powered by blists - more mailing lists