[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220308131056.6732-7-laoar.shao@gmail.com>
Date: Tue, 8 Mar 2022 13:10:53 +0000
From: Yafang Shao <laoar.shao@...il.com>
To: ast@...nel.org, daniel@...earbox.net, andrii@...nel.org,
kafai@...com, songliubraving@...com, yhs@...com,
john.fastabend@...il.com, kpsingh@...nel.org,
akpm@...ux-foundation.org, cl@...ux.com, penberg@...nel.org,
rientjes@...gle.com, iamjoonsoo.kim@....com, vbabka@...e.cz,
hannes@...xchg.org, mhocko@...nel.org, vdavydov.dev@...il.com,
guro@...com
Cc: linux-mm@...ck.org, netdev@...r.kernel.org, bpf@...r.kernel.org,
Yafang Shao <laoar.shao@...il.com>
Subject: [PATCH RFC 6/9] bpf: add a helper to find map by id
A new helper bpf_map_idr_find() is introduced for later use.
Signed-off-by: Yafang Shao <laoar.shao@...il.com>
---
kernel/bpf/syscall.c | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 3b50fcb..68fea3b 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -3474,6 +3474,21 @@ static int bpf_prog_get_fd_by_id(const union bpf_attr *attr)
return fd;
}
+static struct bpf_map *bpf_map_idr_find(unsigned long id)
+{
+ void *map;
+
+ spin_lock_bh(&map_idr_lock);
+ map = idr_find(&map_idr, id);
+ if (map)
+ map = __bpf_map_inc_not_zero(map, true);
+ else
+ map = ERR_PTR(-ENOENT);
+ spin_unlock_bh(&map_idr_lock);
+
+ return map;
+}
+
#define BPF_MAP_GET_FD_BY_ID_LAST_FIELD open_flags
static int bpf_map_get_fd_by_id(const union bpf_attr *attr)
@@ -3494,14 +3509,7 @@ static int bpf_map_get_fd_by_id(const union bpf_attr *attr)
if (f_flags < 0)
return f_flags;
- spin_lock_bh(&map_idr_lock);
- map = idr_find(&map_idr, id);
- if (map)
- map = __bpf_map_inc_not_zero(map, true);
- else
- map = ERR_PTR(-ENOENT);
- spin_unlock_bh(&map_idr_lock);
-
+ map = bpf_map_idr_find(id);
if (IS_ERR(map))
return PTR_ERR(map);
--
1.8.3.1
Powered by blists - more mailing lists