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

!14847 bpf: put bpf_link's program when link is safe to be deallocated

parents 5b481526 c92a7a68
Loading
Loading
Loading
Loading
+17 −5
Original line number Diff line number Diff line
@@ -2877,12 +2877,24 @@ void bpf_link_inc(struct bpf_link *link)
	atomic64_inc(&link->refcnt);
}

static void bpf_link_defer_dealloc_rcu_gp(struct rcu_head *rcu)
static void bpf_link_dealloc(struct bpf_link *link)
{
	struct bpf_link *link = container_of(rcu, struct bpf_link, rcu);
	/* now that we know that bpf_link itself can't be reached, put underlying BPF program */
	if (link->prog)
		bpf_prog_put(link->prog);

	/* free bpf_link and its containing memory */
	if (link->ops->dealloc_deferred)
		link->ops->dealloc_deferred(link);
	else
		link->ops->dealloc(link);
}

static void bpf_link_defer_dealloc_rcu_gp(struct rcu_head *rcu)
{
	struct bpf_link *link = container_of(rcu, struct bpf_link, rcu);

	bpf_link_dealloc(link);
}

static void bpf_link_defer_dealloc_mult_rcu_gp(struct rcu_head *rcu)
@@ -2904,7 +2916,6 @@ static void bpf_link_free(struct bpf_link *link)
		sleepable = link->prog->aux->sleepable;
		/* detach BPF program, clean up used resources */
		ops->release(link);
		bpf_prog_put(link->prog);
	}
	if (ops->dealloc_deferred) {
		/* schedule BPF link deallocation; if underlying BPF program
@@ -2915,8 +2926,9 @@ static void bpf_link_free(struct bpf_link *link)
			call_rcu_tasks_trace(&link->rcu, bpf_link_defer_dealloc_mult_rcu_gp);
		else
			call_rcu(&link->rcu, bpf_link_defer_dealloc_rcu_gp);
	} else if (ops->dealloc)
		ops->dealloc(link);
	} else if (ops->dealloc) {
		bpf_link_dealloc(link);
	}
}

static void bpf_link_put_deferred(struct work_struct *work)