// SPDX-License-Identifier: GPL-2.0
+#include <unistd.h>
 #include <test_progs.h>
 #include <network_helpers.h>
+#include "tailcall_poke.skel.h"
+
 
 /* test_tailcall_1 checks basic functionality by patching multiple locations
  * in a single program for a single tail call slot with nop->jmp, jmp->nop
        bpf_object__close(tgt_obj);
 }
 
+#define JMP_TABLE "/sys/fs/bpf/jmp_table"
+
+static int poke_thread_exit;
+
+static void *poke_update(void *arg)
+{
+       __u32 zero = 0, prog1_fd, prog2_fd, map_fd;
+       struct tailcall_poke *call = arg;
+
+       map_fd = bpf_map__fd(call->maps.jmp_table);
+       prog1_fd = bpf_program__fd(call->progs.call1);
+       prog2_fd = bpf_program__fd(call->progs.call2);
+
+       while (!poke_thread_exit) {
+               bpf_map_update_elem(map_fd, &zero, &prog1_fd, BPF_ANY);
+               bpf_map_update_elem(map_fd, &zero, &prog2_fd, BPF_ANY);
+       }
+
+       return NULL;
+}
+
+/*
+ * We are trying to hit prog array update during another program load
+ * that shares the same prog array map.
+ *
+ * For that we share the jmp_table map between two skeleton instances
+ * by pinning the jmp_table to same path. Then first skeleton instance
+ * periodically updates jmp_table in 'poke update' thread while we load
+ * the second skeleton instance in the main thread.
+ */
+static void test_tailcall_poke(void)
+{
+       struct tailcall_poke *call, *test;
+       int err, cnt = 10;
+       pthread_t thread;
+
+       unlink(JMP_TABLE);
+
+       call = tailcall_poke__open_and_load();
+       if (!ASSERT_OK_PTR(call, "tailcall_poke__open"))
+               return;
+
+       err = bpf_map__pin(call->maps.jmp_table, JMP_TABLE);
+       if (!ASSERT_OK(err, "bpf_map__pin"))
+               goto out;
+
+       err = pthread_create(&thread, NULL, poke_update, call);
+       if (!ASSERT_OK(err, "new toggler"))
+               goto out;
+
+       while (cnt--) {
+               test = tailcall_poke__open();
+               if (!ASSERT_OK_PTR(test, "tailcall_poke__open"))
+                       break;
+
+               err = bpf_map__set_pin_path(test->maps.jmp_table, JMP_TABLE);
+               if (!ASSERT_OK(err, "bpf_map__pin")) {
+                       tailcall_poke__destroy(test);
+                       break;
+               }
+
+               bpf_program__set_autoload(test->progs.test, true);
+               bpf_program__set_autoload(test->progs.call1, false);
+               bpf_program__set_autoload(test->progs.call2, false);
+
+               err = tailcall_poke__load(test);
+               tailcall_poke__destroy(test);
+               if (!ASSERT_OK(err, "tailcall_poke__load"))
+                       break;
+       }
+
+       poke_thread_exit = 1;
+       ASSERT_OK(pthread_join(thread, NULL), "pthread_join");
+
+out:
+       bpf_map__unpin(call->maps.jmp_table, JMP_TABLE);
+       tailcall_poke__destroy(call);
+}
+
 void test_tailcalls(void)
 {
        if (test__start_subtest("tailcall_1"))
                test_tailcall_bpf2bpf_fentry_fexit();
        if (test__start_subtest("tailcall_bpf2bpf_fentry_entry"))
                test_tailcall_bpf2bpf_fentry_entry();
+       if (test__start_subtest("tailcall_poke"))
+               test_tailcall_poke();
 }
 
--- /dev/null
+// SPDX-License-Identifier: GPL-2.0
+#include <linux/bpf.h>
+#include <bpf/bpf_helpers.h>
+#include <bpf/bpf_tracing.h>
+
+char _license[] SEC("license") = "GPL";
+
+struct {
+       __uint(type, BPF_MAP_TYPE_PROG_ARRAY);
+       __uint(max_entries, 1);
+       __uint(key_size, sizeof(__u32));
+       __uint(value_size, sizeof(__u32));
+} jmp_table SEC(".maps");
+
+SEC("?fentry/bpf_fentry_test1")
+int BPF_PROG(test, int a)
+{
+       bpf_tail_call_static(ctx, &jmp_table, 0);
+       return 0;
+}
+
+SEC("fentry/bpf_fentry_test1")
+int BPF_PROG(call1, int a)
+{
+       return 0;
+}
+
+SEC("fentry/bpf_fentry_test1")
+int BPF_PROG(call2, int a)
+{
+       return 0;
+}