Merge tag 'for-5.15-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux
[linux-2.6-microblaze.git] / kernel / bpf / trampoline.c
index 28a3630..fe1e857 100644 (file)
@@ -172,7 +172,7 @@ static int register_fentry(struct bpf_trampoline *tr, void *new_addr)
 }
 
 static struct bpf_tramp_progs *
-bpf_trampoline_get_progs(const struct bpf_trampoline *tr, int *total)
+bpf_trampoline_get_progs(const struct bpf_trampoline *tr, int *total, bool *ip_arg)
 {
        const struct bpf_prog_aux *aux;
        struct bpf_tramp_progs *tprogs;
@@ -189,8 +189,10 @@ bpf_trampoline_get_progs(const struct bpf_trampoline *tr, int *total)
                *total += tr->progs_cnt[kind];
                progs = tprogs[kind].progs;
 
-               hlist_for_each_entry(aux, &tr->progs_hlist[kind], tramp_hlist)
+               hlist_for_each_entry(aux, &tr->progs_hlist[kind], tramp_hlist) {
+                       *ip_arg |= aux->prog->call_get_func_ip;
                        *progs++ = aux->prog;
+               }
        }
        return tprogs;
 }
@@ -333,9 +335,10 @@ static int bpf_trampoline_update(struct bpf_trampoline *tr)
        struct bpf_tramp_image *im;
        struct bpf_tramp_progs *tprogs;
        u32 flags = BPF_TRAMP_F_RESTORE_REGS;
+       bool ip_arg = false;
        int err, total;
 
-       tprogs = bpf_trampoline_get_progs(tr, &total);
+       tprogs = bpf_trampoline_get_progs(tr, &total, &ip_arg);
        if (IS_ERR(tprogs))
                return PTR_ERR(tprogs);
 
@@ -357,6 +360,9 @@ static int bpf_trampoline_update(struct bpf_trampoline *tr)
            tprogs[BPF_TRAMP_MODIFY_RETURN].nr_progs)
                flags = BPF_TRAMP_F_CALL_ORIG | BPF_TRAMP_F_SKIP_FRAME;
 
+       if (ip_arg)
+               flags |= BPF_TRAMP_F_IP_ARG;
+
        err = arch_prepare_bpf_trampoline(im, im->image, im->image + PAGE_SIZE,
                                          &tr->func.model, flags, tprogs,
                                          tr->func.addr);
@@ -542,7 +548,7 @@ static void notrace inc_misses_counter(struct bpf_prog *prog)
        u64_stats_update_end(&stats->syncp);
 }
 
-/* The logic is similar to BPF_PROG_RUN, but with an explicit
+/* The logic is similar to bpf_prog_run(), but with an explicit
  * rcu_read_lock() and migrate_disable() which are required
  * for the trampoline. The macro is split into
  * call __bpf_prog_enter