Blob Blame History Raw
From: Gary Lin <glin@suse.com>
Subject: kabi: implement map_lookup_elem_sys_only in another way 
Patch-mainline: never, KABI fix
References: bsc#1083647

The upstream fix(*) introduces a new member, map_lookup_elem_sys_only,
to 'struct bpf_map_ops' and breaks KABI.

Since the only user of map_lookup_elem_sys_only is lru hash, this patch
renames htab_lru_map_lookup_elem_sys() and makes it public for
kernel/bpf/syscall.c.

(*) c6110222c6f49ea68169f353565eb865488a8619
    patches.fixes/bpf-add-map_lookup_elem_sys_only-for-lookups-from-sy.patch

Signed-off-by: Gary Lin <glin@suse.com>

---
 include/linux/bpf.h  |    1 -
 kernel/bpf/hashtab.c |    3 +--
 kernel/bpf/hashtab.h |   16 ++++++++++++++++
 kernel/bpf/syscall.c |    6 ++++--
 4 files changed, 21 insertions(+), 5 deletions(-)

--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -25,7 +25,6 @@ struct bpf_map_ops {
 	void (*map_release)(struct bpf_map *map, struct file *map_file);
 	void (*map_free)(struct bpf_map *map);
 	int (*map_get_next_key)(struct bpf_map *map, void *key, void *next_key);
-	void *(*map_lookup_elem_sys_only)(struct bpf_map *map, void *key);
 
 	/* funcs callable from userspace and from eBPF programs */
 	void *(*map_lookup_elem)(struct bpf_map *map, void *key);
--- a/kernel/bpf/hashtab.c
+++ b/kernel/bpf/hashtab.c
@@ -512,7 +512,7 @@ static void *htab_lru_map_lookup_elem(st
 	return __htab_lru_map_lookup_elem(map, key, true);
 }
 
-static void *htab_lru_map_lookup_elem_sys(struct bpf_map *map, void *key)
+void *suse_htab_lru_map_lookup_elem_sys(struct bpf_map *map, void *key)
 {
 	return __htab_lru_map_lookup_elem(map, key, false);
 }
@@ -1166,7 +1166,6 @@ const struct bpf_map_ops htab_lru_map_op
 	.map_free = htab_map_free,
 	.map_get_next_key = htab_map_get_next_key,
 	.map_lookup_elem = htab_lru_map_lookup_elem,
-	.map_lookup_elem_sys_only = htab_lru_map_lookup_elem_sys,
 	.map_update_elem = htab_lru_map_update_elem,
 	.map_delete_elem = htab_lru_map_delete_elem,
 	.map_gen_lookup = htab_lru_map_gen_lookup,
--- /dev/null
+++ b/kernel/bpf/hashtab.h
@@ -0,0 +1,16 @@
+/* Copyright (c) 2019 SUSE, https://www.suse.com/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ */
+
+#include <linux/bpf.h>
+
+/* Add this function to avoid adding an extra member to bpf_map_ops */
+void *suse_htab_lru_map_lookup_elem_sys(struct bpf_map *map, void *key);
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -24,6 +24,8 @@
 #include <linux/kernel.h>
 #include <linux/idr.h>
 
+#include "hashtab.h"
+
 #define IS_FD_ARRAY(map) ((map)->map_type == BPF_MAP_TYPE_PROG_ARRAY || \
 			   (map)->map_type == BPF_MAP_TYPE_PERF_EVENT_ARRAY || \
 			   (map)->map_type == BPF_MAP_TYPE_CGROUP_ARRAY || \
@@ -488,8 +490,8 @@ static int map_lookup_elem(union bpf_att
 		err = bpf_fd_htab_map_lookup_elem(map, key, value);
 	} else {
 		rcu_read_lock();
-		if (map->ops->map_lookup_elem_sys_only)
-			ptr = map->ops->map_lookup_elem_sys_only(map, key);
+		if (map->map_type == BPF_MAP_TYPE_LRU_HASH)
+			ptr = suse_htab_lru_map_lookup_elem_sys(map, key);
 		else
 			ptr = map->ops->map_lookup_elem(map, key);
 		if (ptr)