Skip to content

Commit 5771e30

Browse files
Hou TaoAlexei Starovoitov
authored andcommitted
bpf: Rename __htab_percpu_map_update_elem to htab_map_update_elem_in_place
Rename __htab_percpu_map_update_elem to htab_map_update_elem_in_place, and add a new percpu argument for the helper to support in-place update for both per-cpu htab and htab of maps. Acked-by: Andrii Nakryiko <[email protected]> Signed-off-by: Hou Tao <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent ba2b31b commit 5771e30

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

kernel/bpf/hashtab.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,12 +1258,12 @@ static long htab_lru_map_update_elem(struct bpf_map *map, void *key, void *value
12581258
return ret;
12591259
}
12601260

1261-
static long __htab_percpu_map_update_elem(struct bpf_map *map, void *key,
1261+
static long htab_map_update_elem_in_place(struct bpf_map *map, void *key,
12621262
void *value, u64 map_flags,
1263-
bool onallcpus)
1263+
bool percpu, bool onallcpus)
12641264
{
12651265
struct bpf_htab *htab = container_of(map, struct bpf_htab, map);
1266-
struct htab_elem *l_new = NULL, *l_old;
1266+
struct htab_elem *l_new, *l_old;
12671267
struct hlist_nulls_head *head;
12681268
unsigned long flags;
12691269
struct bucket *b;
@@ -1295,19 +1295,18 @@ static long __htab_percpu_map_update_elem(struct bpf_map *map, void *key,
12951295
goto err;
12961296

12971297
if (l_old) {
1298-
/* per-cpu hash map can update value in-place */
1298+
/* Update value in-place */
12991299
pcpu_copy_value(htab, htab_elem_get_ptr(l_old, key_size),
13001300
value, onallcpus);
13011301
} else {
13021302
l_new = alloc_htab_elem(htab, key, value, key_size,
1303-
hash, true, onallcpus, NULL);
1303+
hash, percpu, onallcpus, NULL);
13041304
if (IS_ERR(l_new)) {
13051305
ret = PTR_ERR(l_new);
13061306
goto err;
13071307
}
13081308
hlist_nulls_add_head_rcu(&l_new->hash_node, head);
13091309
}
1310-
ret = 0;
13111310
err:
13121311
htab_unlock_bucket(b, flags);
13131312
return ret;
@@ -1386,7 +1385,7 @@ static long __htab_lru_percpu_map_update_elem(struct bpf_map *map, void *key,
13861385
static long htab_percpu_map_update_elem(struct bpf_map *map, void *key,
13871386
void *value, u64 map_flags)
13881387
{
1389-
return __htab_percpu_map_update_elem(map, key, value, map_flags, false);
1388+
return htab_map_update_elem_in_place(map, key, value, map_flags, true, false);
13901389
}
13911390

13921391
static long htab_lru_percpu_map_update_elem(struct bpf_map *map, void *key,
@@ -2407,8 +2406,8 @@ int bpf_percpu_hash_update(struct bpf_map *map, void *key, void *value,
24072406
ret = __htab_lru_percpu_map_update_elem(map, key, value,
24082407
map_flags, true);
24092408
else
2410-
ret = __htab_percpu_map_update_elem(map, key, value, map_flags,
2411-
true);
2409+
ret = htab_map_update_elem_in_place(map, key, value, map_flags,
2410+
true, true);
24122411
rcu_read_unlock();
24132412

24142413
return ret;

0 commit comments

Comments
 (0)