Unverified Commit 7cfad214 authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!12816 v2 bpf lts backport

Merge Pull Request from: @ci-robot 
 
PR sync from: Pu Lehui <pulehui@huawei.com>
https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/message/3GOUAB4KQT2WJ4OJZZSCDRAUGINQNC4R/ 
Hou Tao (1):
  bpf: Optimize the free of inner map

Tengda Wu (1):
  Fix kabi breakage in struct bpf_map


-- 
2.34.1
 
https://gitee.com/openeuler/kernel/issues/IAD6H2 
 
Link:https://gitee.com/openeuler/kernel/pulls/12816

 

Reviewed-by: default avatarXu Kuohai <xukuohai@huawei.com>
Signed-off-by: default avatarZhang Peng <zhangpeng362@huawei.com>
parents 327d477f a81cf159
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -302,9 +302,10 @@ struct bpf_map {
	bool bypass_spec_v1;
	bool frozen; /* write-once; write-protected by freeze_mutex */
	bool free_after_mult_rcu_gp;
	KABI_FILL_HOLE(bool free_after_rcu_gp)
	s64 __percpu *elem_count;

	KABI_RESERVE(1)
	KABI_USE(1, atomic64_t sleepable_refcnt)
	KABI_RESERVE(2)
	KABI_RESERVE(3)
	KABI_RESERVE(4)
+4 −0
Original line number Diff line number Diff line
@@ -2677,12 +2677,16 @@ void __bpf_free_used_maps(struct bpf_prog_aux *aux,
			  struct bpf_map **used_maps, u32 len)
{
	struct bpf_map *map;
	bool sleepable;
	u32 i;

	sleepable = aux->sleepable;
	for (i = 0; i < len; i++) {
		map = used_maps[i];
		if (map->ops->map_poke_untrack)
			map->ops->map_poke_untrack(map, aux);
		if (sleepable)
			atomic64_dec(&map->sleepable_refcnt);
		bpf_map_put(map);
	}
}
+9 −5
Original line number Diff line number Diff line
@@ -131,12 +131,16 @@ void bpf_map_fd_put_ptr(struct bpf_map *map, void *ptr, bool need_defer)
{
	struct bpf_map *inner_map = ptr;

	/* The inner map may still be used by both non-sleepable and sleepable
	 * bpf program, so free it after one RCU grace period and one tasks
	 * trace RCU grace period.
	/* Defer the freeing of inner map according to the sleepable attribute
	 * of bpf program which owns the outer map, so unnecessary waiting for
	 * RCU tasks trace grace period can be avoided.
	 */
	if (need_defer)
	if (need_defer) {
		if (atomic64_read(&map->sleepable_refcnt))
			WRITE_ONCE(inner_map->free_after_mult_rcu_gp, true);
		else
			WRITE_ONCE(inner_map->free_after_rcu_gp, true);
	}
	bpf_map_put(inner_map);
}

+8 −0
Original line number Diff line number Diff line
@@ -754,8 +754,11 @@ void bpf_map_put(struct bpf_map *map)
		/* bpf_map_free_id() must be called first */
		bpf_map_free_id(map);

		WARN_ON_ONCE(atomic64_read(&map->sleepable_refcnt));
		if (READ_ONCE(map->free_after_mult_rcu_gp))
			call_rcu_tasks_trace(&map->rcu, bpf_map_free_mult_rcu_gp);
		else if (READ_ONCE(map->free_after_rcu_gp))
			call_rcu(&map->rcu, bpf_map_free_rcu_gp);
		else
			bpf_map_free_in_work(map);
	}
@@ -5400,6 +5403,11 @@ static int bpf_prog_bind_map(union bpf_attr *attr)
		goto out_unlock;
	}

	/* The bpf program will not access the bpf map, but for the sake of
	 * simplicity, increase sleepable_refcnt for sleepable program as well.
	 */
	if (prog->aux->sleepable)
		atomic64_inc(&map->sleepable_refcnt);
	memcpy(used_maps_new, used_maps_old,
	       sizeof(used_maps_old[0]) * prog->aux->used_map_cnt);
	used_maps_new[prog->aux->used_map_cnt] = map;
+3 −1
Original line number Diff line number Diff line
@@ -17741,10 +17741,12 @@ static int resolve_pseudo_ldimm64(struct bpf_verifier_env *env)
				return -E2BIG;
			}
			if (env->prog->aux->sleepable)
				atomic64_inc(&map->sleepable_refcnt);
			/* hold the map. If the program is rejected by verifier,
			 * the map will be released by release_maps() or it
			 * will be used by the valid program until it's unloaded
			 * and all maps are released in free_used_maps()
			 * and all maps are released in bpf_free_used_maps()
			 */
			bpf_map_inc(map);