| From 0be71b0d57b67ed92fa7dd36ee318500f63a5af3 Mon Sep 17 00:00:00 2001 |
| From: Sasha Levin <sashal@kernel.org> |
| Date: Mon, 15 May 2023 13:08:48 +0000 |
| Subject: bpf: Remove bpf trampoline selector |
| |
| From: Yafang Shao <laoar.shao@gmail.com> |
| |
| [ Upstream commit 47e79cbeea4b3891ad476047f4c68543eb51c8e0 ] |
| |
| After commit e21aa341785c ("bpf: Fix fexit trampoline."), the selector is only |
| used to indicate how many times the bpf trampoline image are updated and been |
| displayed in the trampoline ksym name. After the trampoline is freed, the |
| selector will start from 0 again. So the selector is a useless value to the |
| user. We can remove it. |
| |
| If the user want to check whether the bpf trampoline image has been updated |
| or not, the user can compare the address. Each time the trampoline image is |
| updated, the address will change consequently. Jiri also pointed out another |
| issue that perf is still using the old name "bpf_trampoline_%lu", so this |
| change can fix the issue in perf. |
| |
| Fixes: e21aa341785c ("bpf: Fix fexit trampoline.") |
| Signed-off-by: Yafang Shao <laoar.shao@gmail.com> |
| Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> |
| Acked-by: Song Liu <song@kernel.org> |
| Cc: Jiri Olsa <olsajiri@gmail.com> |
| Link: https://lore.kernel.org/bpf/ZFvOOlrmHiY9AgXE@krava |
| Link: https://lore.kernel.org/bpf/20230515130849.57502-3-laoar.shao@gmail.com |
| Signed-off-by: Sasha Levin <sashal@kernel.org> |
| --- |
| include/linux/bpf.h | 1 - |
| kernel/bpf/trampoline.c | 11 ++++------- |
| 2 files changed, 4 insertions(+), 8 deletions(-) |
| |
| diff --git a/include/linux/bpf.h b/include/linux/bpf.h |
| index 5bd6ac04773aa..18397e54bac18 100644 |
| --- a/include/linux/bpf.h |
| +++ b/include/linux/bpf.h |
| @@ -1082,7 +1082,6 @@ struct bpf_trampoline { |
| int progs_cnt[BPF_TRAMP_MAX]; |
| /* Executable image of trampoline */ |
| struct bpf_tramp_image *cur_image; |
| - u64 selector; |
| struct module *mod; |
| }; |
| |
| diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c |
| index d0ed7d6f5eec5..213d9b3cb06ad 100644 |
| --- a/kernel/bpf/trampoline.c |
| +++ b/kernel/bpf/trampoline.c |
| @@ -372,7 +372,7 @@ static void bpf_tramp_image_put(struct bpf_tramp_image *im) |
| call_rcu_tasks_trace(&im->rcu, __bpf_tramp_image_put_rcu_tasks); |
| } |
| |
| -static struct bpf_tramp_image *bpf_tramp_image_alloc(u64 key, u32 idx) |
| +static struct bpf_tramp_image *bpf_tramp_image_alloc(u64 key) |
| { |
| struct bpf_tramp_image *im; |
| struct bpf_ksym *ksym; |
| @@ -399,7 +399,7 @@ static struct bpf_tramp_image *bpf_tramp_image_alloc(u64 key, u32 idx) |
| |
| ksym = &im->ksym; |
| INIT_LIST_HEAD_RCU(&ksym->lnode); |
| - snprintf(ksym->name, KSYM_NAME_LEN, "bpf_trampoline_%llu_%u", key, idx); |
| + snprintf(ksym->name, KSYM_NAME_LEN, "bpf_trampoline_%llu", key); |
| bpf_image_ksym_add(image, ksym); |
| return im; |
| |
| @@ -429,11 +429,10 @@ static int bpf_trampoline_update(struct bpf_trampoline *tr, bool lock_direct_mut |
| err = unregister_fentry(tr, tr->cur_image->image); |
| bpf_tramp_image_put(tr->cur_image); |
| tr->cur_image = NULL; |
| - tr->selector = 0; |
| goto out; |
| } |
| |
| - im = bpf_tramp_image_alloc(tr->key, tr->selector); |
| + im = bpf_tramp_image_alloc(tr->key); |
| if (IS_ERR(im)) { |
| err = PTR_ERR(im); |
| goto out; |
| @@ -470,8 +469,7 @@ static int bpf_trampoline_update(struct bpf_trampoline *tr, bool lock_direct_mut |
| |
| set_memory_rox((long)im->image, 1); |
| |
| - WARN_ON(tr->cur_image && tr->selector == 0); |
| - WARN_ON(!tr->cur_image && tr->selector); |
| + WARN_ON(tr->cur_image && total == 0); |
| if (tr->cur_image) |
| /* progs already running at this address */ |
| err = modify_fentry(tr, tr->cur_image->image, im->image, lock_direct_mutex); |
| @@ -501,7 +499,6 @@ static int bpf_trampoline_update(struct bpf_trampoline *tr, bool lock_direct_mut |
| if (tr->cur_image) |
| bpf_tramp_image_put(tr->cur_image); |
| tr->cur_image = im; |
| - tr->selector++; |
| out: |
| /* If any error happens, restore previous flags */ |
| if (err) |
| -- |
| 2.39.2 |
| |