Commit e0aa5cf5 authored by Alexei Starovoitov's avatar Alexei Starovoitov
Browse files

Merge branch 'unsupported-map-lookup'



Prashant Bhole says:

====================
Currently when map a lookup fails, user space API can not make any
distinction whether given key was not found or lookup is not supported
by particular map.

In this series we modify return value of maps which do not support
lookup. Lookup on such map implementation will return -EOPNOTSUPP.
bpf() syscall with BPF_MAP_LOOKUP_ELEM command will set EOPNOTSUPP
errno. We also handle this error in bpftool to print appropriate
message.

Patch 1: adds handling of BPF_MAP_LOOKUP ELEM command of bpf syscall
such that errno will set to EOPNOTSUPP when map doesn't support lookup

Patch 2: Modifies the return value of map_lookup_elem() to EOPNOTSUPP
for maps which do not support lookup

Patch 3: Splits do_dump() in bpftool/map.c. Element printing code is
moved out into new function dump_map_elem(). This was done in order to
reduce deep indentation and accomodate further changes.

Patch 4: Changes in bpftool to print strerror() message when lookup
error is occured. This will result in appropriate message like
"Operation not supported" when map doesn't support lookup.

Patch 5: test_verifier: change fixup map naming convention as
suggested by Alexei

Patch 6: Added verifier tests to check whether verifier rejects call
to bpf_map_lookup_elem from bpf program. For all map types those
do not support map lookup.
====================

Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parents 8af03d1a 7c85c448
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -449,7 +449,7 @@ static void fd_array_map_free(struct bpf_map *map)


static void *fd_array_map_lookup_elem(struct bpf_map *map, void *key)
static void *fd_array_map_lookup_elem(struct bpf_map *map, void *key)
{
{
	return NULL;
	return ERR_PTR(-EOPNOTSUPP);
}
}


/* only called from syscall */
/* only called from syscall */
+1 −1
Original line number Original line Diff line number Diff line
@@ -2096,7 +2096,7 @@ int sockmap_get_from_fd(const union bpf_attr *attr, int type,


static void *sock_map_lookup(struct bpf_map *map, void *key)
static void *sock_map_lookup(struct bpf_map *map, void *key)
{
{
	return NULL;
	return ERR_PTR(-EOPNOTSUPP);
}
}


static int sock_map_update_elem(struct bpf_map *map,
static int sock_map_update_elem(struct bpf_map *map,
+1 −1
Original line number Original line Diff line number Diff line
@@ -505,7 +505,7 @@ const struct bpf_func_proto bpf_get_stack_proto = {
/* Called from eBPF program */
/* Called from eBPF program */
static void *stack_map_lookup_elem(struct bpf_map *map, void *key)
static void *stack_map_lookup_elem(struct bpf_map *map, void *key)
{
{
	return NULL;
	return ERR_PTR(-EOPNOTSUPP);
}
}


/* Called from syscall */
/* Called from syscall */
+7 −2
Original line number Original line Diff line number Diff line
@@ -719,10 +719,15 @@ static int map_lookup_elem(union bpf_attr *attr)
	} else {
	} else {
		rcu_read_lock();
		rcu_read_lock();
		ptr = map->ops->map_lookup_elem(map, key);
		ptr = map->ops->map_lookup_elem(map, key);
		if (ptr)
		if (IS_ERR(ptr)) {
			err = PTR_ERR(ptr);
		} else if (!ptr) {
			err = -ENOENT;
		} else {
			err = 0;
			memcpy(value, ptr, value_size);
			memcpy(value, ptr, value_size);
		}
		rcu_read_unlock();
		rcu_read_unlock();
		err = ptr ? 0 : -ENOENT;
	}
	}


	if (err)
	if (err)
+1 −1
Original line number Original line Diff line number Diff line
@@ -154,7 +154,7 @@ void __xsk_map_flush(struct bpf_map *map)


static void *xsk_map_lookup_elem(struct bpf_map *map, void *key)
static void *xsk_map_lookup_elem(struct bpf_map *map, void *key)
{
{
	return NULL;
	return ERR_PTR(-EOPNOTSUPP);
}
}


static int xsk_map_update_elem(struct bpf_map *map, void *key, void *value,
static int xsk_map_update_elem(struct bpf_map *map, void *key, void *value,
Loading