AI Trajectory


Trajectory: (Expand/Collapse All)
Seq Timestamp Type Name Duration
0/0 2026/08/26 19:21 flow patch-triage
0m Args:
null

Results:
{
  "EnableConfigs": null,
  "FocusSymbols": [],
  "KMSANReasoning": "",
  "NeedsKMSAN": false,
  "Reasoning": "The patch only modifies the user-space libbpf library and adds selftests in the tools/ directory. It does not make any functional changes to the kernel code itself that can be fuzzed.",
  "WorthFuzzing": false
}

1/1 2026/08/26 19:21 action read-patch-diff
0m Args:
null

Results:
{
  "PatchDiff": "commit e7e392857bccbf5726ffd4974ca9066a26bf4162\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate:   Wed Aug 26 19:21:34 2026 +0000\n\n    syz-cluster: applied patch under review\n\ndiff --git a/tools/lib/bpf/bpf_helpers.h b/tools/lib/bpf/bpf_helpers.h\nindex 9d160b5b9c0ee..52978f0e04539 100644\n--- a/tools/lib/bpf/bpf_helpers.h\n+++ b/tools/lib/bpf/bpf_helpers.h\n@@ -218,6 +218,11 @@ enum libbpf_tristate {\n #define __arg_untrusted __attribute((btf_decl_tag(\"arg:untrusted\")))\n #define __arg_arena __attribute((btf_decl_tag(\"arg:arena\")))\n \n+/* Mark a BPF program to be loaded dynamically instead of autoloaded,\n+ * equivalent to bpf_program__set_load_type(prog, BPF_PROG_LOAD_TYPE_DYNAMIC).\n+ */\n+#define __load_dynamic __attribute__((btf_decl_tag(\"loadtype:dynamic\")))\n+\n #ifndef ___bpf_concat\n #define ___bpf_concat(a, b) a ## b\n #endif\ndiff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c\nindex b749c01742ee0..5d58dbf25234f 100644\n--- a/tools/lib/bpf/libbpf.c\n+++ b/tools/lib/bpf/libbpf.c\n@@ -494,7 +494,7 @@ struct bpf_program {\n \tstruct bpf_object *obj;\n \n \tint fd;\n-\tbool autoload;\n+\tenum bpf_prog_load_type load_type;\n \tbool autoattach;\n \tbool sym_global;\n \tbool mark_btf_static;\n@@ -725,6 +725,7 @@ struct bpf_object {\n \n \tbool has_subcalls;\n \tbool has_rodata;\n+\tbool has_dynload_progs;\n \n \tstruct bpf_gen *gen_loader;\n \n@@ -872,11 +873,11 @@ bpf_object__init_prog(struct bpf_object *obj, struct bpf_program *prog,\n \t * autoload set to false.\n \t */\n \tif (sec_name[0] == '?') {\n-\t\tprog-\u003eautoload = false;\n+\t\tprog-\u003eload_type = BPF_PROG_LOAD_TYPE_DISABLED;\n \t\t/* from now on forget there was ? in section name */\n \t\tsec_name++;\n \t} else {\n-\t\tprog-\u003eautoload = true;\n+\t\tprog-\u003eload_type = BPF_PROG_LOAD_TYPE_AUTO;\n \t}\n \n \tprog-\u003eautoattach = true;\n@@ -1125,9 +1126,10 @@ static bool is_valid_st_ops_program(struct bpf_object *obj,\n }\n \n /* For each struct_ops program P, referenced from some struct_ops map M,\n- * enable P.autoload if there are Ms for which M.autocreate is true,\n- * disable P.autoload if for all Ms M.autocreate is false.\n- * Don't change P.autoload for programs that are not referenced from any maps.\n+ * set P's load type to BPF_PROG_LOAD_TYPE_AUTO if there are Ms for which\n+ * M.autocreate is true, or to BPF_PROG_LOAD_TYPE_DISABLED if for all Ms\n+ * M.autocreate is false.\n+ * Don't change P's load type for programs that are not referenced from any maps.\n  */\n static int bpf_object_adjust_struct_ops_autoload(struct bpf_object *obj)\n {\n@@ -1163,7 +1165,8 @@ static int bpf_object_adjust_struct_ops_autoload(struct bpf_object *obj)\n \t\t\t}\n \t\t}\n \t\tif (use_cnt)\n-\t\t\tprog-\u003eautoload = should_load;\n+\t\t\tprog-\u003eload_type = should_load ? BPF_PROG_LOAD_TYPE_AUTO\n+\t\t\t\t: BPF_PROG_LOAD_TYPE_DISABLED;\n \t}\n \n \treturn 0;\n@@ -1242,13 +1245,14 @@ static int bpf_map__init_kern_struct_ops(struct bpf_map *map)\n \n \t\t\tif (st_ops-\u003eprogs[i]) {\n \t\t\t\t/* If we had declaratively set struct_ops callback, we need to\n-\t\t\t\t * force its autoload to false, because it doesn't have\n-\t\t\t\t * a chance of succeeding from POV of the current struct_ops map.\n-\t\t\t\t * If this program is still referenced somewhere else, though,\n-\t\t\t\t * then bpf_object_adjust_struct_ops_autoload() will update its\n-\t\t\t\t * autoload accordingly.\n+\t\t\t\t * force its load type to BPF_PROG_LOAD_TYPE_DISABLED, because\n+\t\t\t\t * it doesn't have a chance of succeeding from POV of the\n+\t\t\t\t * current struct_ops map. If this program is still referenced\n+\t\t\t\t * somewhere else, though, then\n+\t\t\t\t * bpf_object_adjust_struct_ops_autoload() will update its\n+\t\t\t\t * load type accordingly.\n \t\t\t\t */\n-\t\t\t\tst_ops-\u003eprogs[i]-\u003eautoload = false;\n+\t\t\t\tst_ops-\u003eprogs[i]-\u003eload_type = BPF_PROG_LOAD_TYPE_DISABLED;\n \t\t\t\tst_ops-\u003eprogs[i] = NULL;\n \t\t\t}\n \n@@ -1287,7 +1291,7 @@ static int bpf_map__init_kern_struct_ops(struct bpf_map *map)\n \t\t\t * if user replaced it with another program or NULL\n \t\t\t */\n \t\t\tif (st_ops-\u003eprogs[i] \u0026\u0026 st_ops-\u003eprogs[i] != prog)\n-\t\t\t\tst_ops-\u003eprogs[i]-\u003eautoload = false;\n+\t\t\t\tst_ops-\u003eprogs[i]-\u003eload_type = BPF_PROG_LOAD_TYPE_DISABLED;\n \n \t\t\t/* Update the value from the shadow type */\n \t\t\tst_ops-\u003eprogs[i] = prog;\n@@ -3600,7 +3604,7 @@ static bool obj_needs_vmlinux_btf(const struct bpf_object *obj)\n \t}\n \n \tbpf_object__for_each_program(prog, obj) {\n-\t\tif (!prog-\u003eautoload)\n+\t\tif (prog-\u003eload_type == BPF_PROG_LOAD_TYPE_DISABLED)\n \t\t\tcontinue;\n \t\tif (prog_needs_vmlinux_btf(prog))\n \t\t\treturn true;\n@@ -6194,7 +6198,7 @@ bpf_object__relocate_core(struct bpf_object *obj, const char *targ_btf_path)\n \t\t\t/* no need to apply CO-RE relocation if the program is\n \t\t\t * not going to be loaded\n \t\t\t */\n-\t\t\tif (!prog-\u003eautoload)\n+\t\t\tif (prog-\u003eload_type == BPF_PROG_LOAD_TYPE_DISABLED)\n \t\t\t\tcontinue;\n \n \t\t\t/* adjust insn_idx from section frame of reference to the local\n@@ -7154,6 +7158,50 @@ static int bpf_prog_assign_exc_cb(struct bpf_object *obj, struct bpf_program *pr\n \treturn 0;\n }\n \n+#define DYNLOAD_DECL_TAG \"loadtype:dynamic\"\n+\n+/*\n+ * Check whether a BPF program is annotated with the DYNLOAD_DECL_TAG BTF\n+ * decl tag, requesting that it be loaded dynamically after the object load.\n+ *\n+ * Returns 1 if the tag is present, 0 if it is not, negative error otherwise.\n+ */\n+static int prog_has_dynload_tag(struct bpf_object *obj, struct bpf_program *prog)\n+{\n+\tint i, n;\n+\n+\tif (!obj-\u003ebtf)\n+\t\treturn 0;\n+\n+\tn = btf__type_cnt(obj-\u003ebtf);\n+\tfor (i = 1; i \u003c n; i++) {\n+\t\tconst struct btf_type *tag_t, *fn_t;\n+\n+\t\ttag_t = btf__type_by_id(obj-\u003ebtf, i);\n+\t\tif (!btf_is_decl_tag(tag_t) || btf_decl_tag(tag_t)-\u003ecomponent_idx != -1)\n+\t\t\tcontinue;\n+\t\tif (strcmp(btf__str_by_offset(obj-\u003ebtf, tag_t-\u003ename_off),\n+\t\t\t   DYNLOAD_DECL_TAG) != 0)\n+\t\t\tcontinue;\n+\n+\t\t/* a decl tag's type field points at the entity it decorates */\n+\t\tfn_t = btf__type_by_id(obj-\u003ebtf, tag_t-\u003etype);\n+\t\tif (!btf_is_func(fn_t) || btf_func_linkage(fn_t) != BTF_FUNC_GLOBAL) {\n+\t\t\tpr_warn(\"prog '%s': \" DYNLOAD_DECL_TAG\n+\t\t\t\t\" decl tag must be applied to a global function\\n\",\n+\t\t\t\tprog-\u003ename);\n+\t\t\treturn -EINVAL;\n+\t\t}\n+\n+\t\tif (strcmp(btf__str_by_offset(obj-\u003ebtf, fn_t-\u003ename_off), prog-\u003ename) != 0)\n+\t\t\tcontinue;   /* tag belongs to a different program */\n+\n+\t\treturn 1;\n+\t}\n+\n+\treturn 0;\n+}\n+\n static struct {\n \tenum bpf_prog_type prog_type;\n \tconst char *ctx_name;\n@@ -7530,7 +7578,7 @@ static int bpf_object__relocate(struct bpf_object *obj, const char *targ_btf_pat\n \t\t */\n \t\tif (prog_is_subprog(obj, prog))\n \t\t\tcontinue;\n-\t\tif (!prog-\u003eautoload)\n+\t\tif (prog-\u003eload_type == BPF_PROG_LOAD_TYPE_DISABLED)\n \t\t\tcontinue;\n \n \t\terr = bpf_object__relocate_calls(obj, prog);\n@@ -7566,7 +7614,7 @@ static int bpf_object__relocate(struct bpf_object *obj, const char *targ_btf_pat\n \t\tprog = \u0026obj-\u003eprograms[i];\n \t\tif (prog_is_subprog(obj, prog))\n \t\t\tcontinue;\n-\t\tif (!prog-\u003eautoload)\n+\t\tif (prog-\u003eload_type == BPF_PROG_LOAD_TYPE_DISABLED)\n \t\t\tcontinue;\n \n \t\t/* Process data relos for main programs */\n@@ -8055,7 +8103,7 @@ static int bpf_object_load_prog(struct bpf_object *obj, struct bpf_program *prog\n \t\t\tlog_buf = prog-\u003elog_buf;\n \t\t\tlog_buf_size = prog-\u003elog_size;\n \t\t\town_log_buf = false;\n-\t\t} else if (obj-\u003elog_buf) {\n+\t\t} else if (obj-\u003elog_buf \u0026\u0026 prog-\u003eload_type != BPF_PROG_LOAD_TYPE_DYNAMIC) {\n \t\t\tlog_buf = obj-\u003elog_buf;\n \t\t\tlog_buf_size = obj-\u003elog_size;\n \t\t\town_log_buf = false;\n@@ -8398,10 +8446,14 @@ bpf_object__load_progs(struct bpf_object *obj, int log_level)\n \t\tprog = \u0026obj-\u003eprograms[i];\n \t\tif (prog_is_subprog(obj, prog))\n \t\t\tcontinue;\n-\t\tif (!prog-\u003eautoload) {\n-\t\t\tpr_debug(\"prog '%s': skipped loading\\n\", prog-\u003ename);\n+\t\tif (prog-\u003eload_type != BPF_PROG_LOAD_TYPE_AUTO) {\n+\t\t\tpr_debug(\"prog '%s': skipped loading, load type is %s\\n\",\n+\t\t\t\t prog-\u003ename,\n+\t\t\t\t prog-\u003eload_type == BPF_PROG_LOAD_TYPE_DYNAMIC ?\n+\t\t\t\t \"dynamic\" : \"disabled\");\n \t\t\tcontinue;\n \t\t}\n+\n \t\tprog-\u003elog_level |= log_level;\n \n \t\tif (obj-\u003egen_loader)\n@@ -8464,6 +8516,22 @@ static int bpf_object_init_progs(struct bpf_object *obj, const struct bpf_object\n \t\t\t\treturn err;\n \t\t\t}\n \t\t}\n+\n+\t\tif (prog_is_subprog(obj, prog))\n+\t\t\tcontinue;\n+\n+\t\terr = prog_has_dynload_tag(obj, prog);\n+\t\tif (err \u003c 0)\n+\t\t\treturn err;\n+\t\tif (err \u003e 0) {\n+\t\t\terr = bpf_program__set_load_type(prog, BPF_PROG_LOAD_TYPE_DYNAMIC);\n+\t\t\tif (err) {\n+\t\t\t\tpr_warn(\"prog '%s': failed to apply \" DYNLOAD_DECL_TAG\n+\t\t\t\t\t\" decl tag: %s\\n\",\n+\t\t\t\t\tprog-\u003ename, errstr(err));\n+\t\t\t\treturn err;\n+\t\t\t}\n+\t\t}\n \t}\n \n \treturn 0;\n@@ -9075,15 +9143,22 @@ static void bpf_object_cleanup_btf(struct bpf_object *obj)\n \tobj-\u003ebtf_modules_loaded = false;\n \tzfree(\u0026obj-\u003ebtf_modules);\n \n-\t/* clean up vmlinux BTF */\n-\tbtf__free(obj-\u003ebtf_vmlinux);\n-\tobj-\u003ebtf_vmlinux = NULL;\n+\t/* The btf_vmlinux data is needed for dynamically loaded programs,\n+\t * so defer freeing it in that case to the end of the object lifetime.\n+\t */\n+\tif (!obj-\u003ehas_dynload_progs) {\n+\t\tbtf__free(obj-\u003ebtf_vmlinux);\n+\t\tobj-\u003ebtf_vmlinux = NULL;\n+\t}\n }\n \n static void bpf_object_post_load_cleanup(struct bpf_object *obj)\n {\n-\t/* clean up fd_array */\n-\tzfree(\u0026obj-\u003efd_array);\n+\t/* The fd array is needed for dynamically loaded programs,\n+\t * so defer freeing it in that case to the end of the object lifetime.\n+\t */\n+\tif (!obj-\u003ehas_dynload_progs || !obj-\u003efd_array_cnt)\n+\t\tzfree(\u0026obj-\u003efd_array);\n \n \t/* clean up BTF */\n \tbpf_object_cleanup_btf(obj);\n@@ -9677,6 +9752,8 @@ void bpf_object__close(struct bpf_object *obj)\n \t\tclose(obj-\u003ejumptable_maps[i].fd);\n \tzfree(\u0026obj-\u003ejumptable_maps);\n \n+\tzfree(\u0026obj-\u003efd_array);\n+\n \tfree(obj);\n }\n \n@@ -9799,16 +9876,15 @@ const char *bpf_program__section_name(const struct bpf_program *prog)\n \n bool bpf_program__autoload(const struct bpf_program *prog)\n {\n-\treturn prog-\u003eautoload;\n+\treturn prog-\u003eload_type == BPF_PROG_LOAD_TYPE_AUTO;\n }\n \n-int bpf_program__set_autoload(struct bpf_program *prog, bool autoload)\n+int bpf_program__set_autoload(struct bpf_program *prog, enum bpf_prog_load_type autoload)\n {\n-\tif (prog-\u003eobj-\u003estate \u003e= OBJ_LOADED)\n+\tif (autoload != BPF_PROG_LOAD_TYPE_AUTO \u0026\u0026 autoload != BPF_PROG_LOAD_TYPE_DISABLED)\n \t\treturn libbpf_err(-EINVAL);\n \n-\tprog-\u003eautoload = autoload;\n-\treturn 0;\n+\treturn bpf_program__set_load_type(prog, autoload);\n }\n \n bool bpf_program__autoattach(const struct bpf_program *prog)\n@@ -15111,7 +15187,7 @@ int bpf_object__attach_skeleton(struct bpf_object_skeleton *s)\n \t\tstruct bpf_program *prog = *prog_skel-\u003eprog;\n \t\tstruct bpf_link **link = prog_skel-\u003elink;\n \n-\t\tif (!prog-\u003eautoload || !prog-\u003eautoattach)\n+\t\tif (prog-\u003eload_type != BPF_PROG_LOAD_TYPE_AUTO || !prog-\u003eautoattach)\n \t\t\tcontinue;\n \n \t\t/* auto-attaching not supported for this program */\n@@ -15221,3 +15297,136 @@ void bpf_object__destroy_skeleton(struct bpf_object_skeleton *s)\n \tfree(s-\u003eprogs);\n \tfree(s);\n }\n+\n+static int bpf_program__set_dynamicload(struct bpf_program *prog)\n+{\n+\tstruct bpf_object *obj;\n+\tconst char *attach_name;\n+\n+\tobj = prog-\u003eobj;\n+\tif (!obj)\n+\t\treturn libbpf_err(-EINVAL);\n+\n+\t/* Dynamically-loaded programs are not supported for gen_loader.\n+\t * This is because bpf_object_load_prog is not called for\n+\t * dynamicload programs, so dynamicload programs are not visible\n+\t * to gen_loader. For this reason, prevent calling\n+\t * bpf_program__set_dynamicload when gen_loader was used to\n+\t * generate a BPF object loader.\n+\t * A gen_loader implementation is being called for programs with\n+\t * load type BPF_PROG_LOAD_TYPE_AUTO and defines its own model for\n+\t * loading BPF programs.\n+\t */\n+\tif (obj-\u003egen_loader)\n+\t\treturn libbpf_err(-ENOTSUP);\n+\n+\tif (prog_is_subprog(obj, prog))\n+\t\treturn libbpf_err(-EINVAL);\n+\n+\tattach_name = strchr(prog-\u003esec_name, '/');\n+\tif (!attach_name || strchr(attach_name, ':')) {\n+\t\t/* Only reject programs that require BTF-based attach target\n+\t\t * resolution (indicated by the SEC_ATTACH_BTF flag). Such\n+\t\t * programs need the section name parsed for the attach target\n+\t\t * function name (after '/') and optionally the module name\n+\t\t * (before ':') for libbpf_find_attach_btf_id.\n+\t\t *\n+\t\t * Programs like SEC(\"classifier\"), SEC(\"socket\"), etc. do\n+\t\t * not require BTF attach resolution and can safely use\n+\t\t * dynamic loading despite having no '/' in their section\n+\t\t * name. The BTF guard in libbpf_prepare_prog_load (checking\n+\t\t * SEC_ATTACH_BTF) is the authoritative check; this is an\n+\t\t * early-reject for programs that would fail there.\n+\t\t */\n+\t\tlong flags = prog-\u003esec_def ?\n+\t\t\t(long)prog-\u003esec_def-\u003ecookie : SEC_ATTACH_BTF;\n+\t\tif ((flags \u0026 SEC_ATTACH_BTF) \u0026\u0026 !prog-\u003eattach_btf_id)\n+\t\t\treturn libbpf_err(-EINVAL);\n+\t}\n+\n+\tobj-\u003ehas_dynload_progs = true;\n+\tprog-\u003eload_type = BPF_PROG_LOAD_TYPE_DYNAMIC;\n+\tprog-\u003eautoattach = false;\n+\n+\treturn 0;\n+}\n+\n+int bpf_program__set_load_type(struct bpf_program *prog, enum bpf_prog_load_type type)\n+{\n+\tif (!prog)\n+\t\treturn libbpf_err(-EINVAL);\n+\n+\tif (prog-\u003eobj-\u003estate \u003e= OBJ_LOADED)\n+\t\treturn libbpf_err(-EINVAL);\n+\n+\tswitch (type) {\n+\tcase BPF_PROG_LOAD_TYPE_DYNAMIC:\n+\t\treturn bpf_program__set_dynamicload(prog);\n+\tcase BPF_PROG_LOAD_TYPE_AUTO:\n+\tcase BPF_PROG_LOAD_TYPE_DISABLED:\n+\t\t/*\n+\t\t * Leaving the dynamic state: set_dynamicload() cleared\n+\t\t * autoattach because dynamically loaded programs are attached\n+\t\t * explicitly. Restore the default for the target load type.\n+\t\t */\n+\t\tif (prog-\u003eload_type == BPF_PROG_LOAD_TYPE_DYNAMIC)\n+\t\t\tprog-\u003eautoattach = true;\n+\t\tprog-\u003eload_type = type;\n+\t\tbreak;\n+\tdefault:\n+\t\treturn libbpf_err(-EINVAL);\n+\t}\n+\n+\treturn 0;\n+}\n+\n+enum bpf_prog_load_type bpf_program__load_type(const struct bpf_program *prog)\n+{\n+\treturn prog-\u003eload_type;\n+}\n+\n+/*\n+ * This function must be called after bpf_object__load_progs.\n+ * Dynamically-loaded program data is initialized on object load.\n+ * Post-load initialization is not supported.\n+ */\n+int\n+bpf_program__load_dynamically(struct bpf_program *prog, int extra_log_level)\n+{\n+\tint err;\n+\tstruct bpf_object *obj;\n+\n+\tobj = prog-\u003eobj;\n+\tif (!obj || obj-\u003estate \u003c OBJ_LOADED)\n+\t\treturn libbpf_err(-EINVAL);\n+\n+\tif (prog_is_subprog(obj, prog) || prog-\u003eload_type != BPF_PROG_LOAD_TYPE_DYNAMIC)\n+\t\treturn libbpf_err(-EINVAL);\n+\n+\tprog-\u003elog_level |= extra_log_level;\n+\n+\terr = bpf_object_load_prog(obj, prog, prog-\u003einsns, prog-\u003einsns_cnt,\n+\t\t\t\t   obj-\u003elicense, obj-\u003ekern_version, \u0026prog-\u003efd);\n+\tif (err) {\n+\t\tpr_warn(\"prog '%s': failed to dynamically load: %d\\n\", prog-\u003ename, err);\n+\t\tprog-\u003elog_level \u0026= ~extra_log_level;\n+\t\treturn err;\n+\t}\n+\n+\tprog-\u003elog_level \u0026= ~extra_log_level;\n+\treturn 0;\n+}\n+\n+int bpf_program__unload_dynamically(struct bpf_program *prog)\n+{\n+\tint err;\n+\n+\tif (!prog || prog-\u003eload_type != BPF_PROG_LOAD_TYPE_DYNAMIC)\n+\t\treturn libbpf_err(-EINVAL);\n+\n+\t/* Close the file descriptor but retain the program's data to\n+\t * support reloading the program if it is required again.\n+\t */\n+\terr = zclose(prog-\u003efd);\n+\treturn err ? libbpf_err(-errno) : 0;\n+}\ndiff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h\nindex b965ad5715403..a56068f0f1122 100644\n--- a/tools/lib/bpf/libbpf.h\n+++ b/tools/lib/bpf/libbpf.h\n@@ -356,6 +356,19 @@ LIBBPF_API int libbpf_attach_type_by_name(const char *name,\n LIBBPF_API int libbpf_find_vmlinux_btf_id(const char *name,\n \t\t\t\t\t  enum bpf_attach_type attach_type);\n \n+/*\n+ * The program load type:\n+ *\n+ * - BPF_PROG_LOAD_TYPE_DISABLED: the program is not loaded.\n+ * - BPF_PROG_LOAD_TYPE_AUTO: the program is autoloaded when the bpf_object is loaded.\n+ * - BPF_PROG_LOAD_TYPE_DYNAMIC: the program is loaded and attached dynamically.\n+ */\n+enum bpf_prog_load_type {\n+\tBPF_PROG_LOAD_TYPE_DISABLED = 0,\n+\tBPF_PROG_LOAD_TYPE_AUTO,\n+\tBPF_PROG_LOAD_TYPE_DYNAMIC,\n+};\n+\n /* Accessors of bpf_program */\n struct bpf_program;\n \n@@ -376,7 +389,18 @@ LIBBPF_API void bpf_program__set_ifindex(struct bpf_program *prog,\n LIBBPF_API const char *bpf_program__name(const struct bpf_program *prog);\n LIBBPF_API const char *bpf_program__section_name(const struct bpf_program *prog);\n LIBBPF_API bool bpf_program__autoload(const struct bpf_program *prog);\n-LIBBPF_API int bpf_program__set_autoload(struct bpf_program *prog, bool autoload);\n+/**\n+ * @brief **bpf_program__set_autoload()** is retained for backwards\n+ * compatibility; **bpf_program__set_load_type()** is the preferred API.\n+ * The enum's numbering (DISABLED=0, AUTO=1, DYNAMIC=2) matches the previous\n+ * bool semantics (false=0, true=1), so existing bool callers keep compiling\n+ * and behaving unchanged. Only BPF_PROG_LOAD_TYPE_AUTO and\n+ * BPF_PROG_LOAD_TYPE_DISABLED are accepted, preserving the original\n+ * autoload on/off meaning; use bpf_program__set_load_type() to set\n+ * BPF_PROG_LOAD_TYPE_DYNAMIC.\n+ */\n+LIBBPF_API int bpf_program__set_autoload(struct bpf_program *prog,\n+\t\t\t\t\t enum bpf_prog_load_type autoload);\n LIBBPF_API bool bpf_program__autoattach(const struct bpf_program *prog);\n LIBBPF_API void bpf_program__set_autoattach(struct bpf_program *prog, bool autoattach);\n \n@@ -2078,6 +2102,12 @@ LIBBPF_API int libbpf_unregister_prog_handler(int handler_id);\n  */\n LIBBPF_API int bpf_program__clone(struct bpf_program *prog, const struct bpf_prog_load_opts *opts);\n \n+LIBBPF_API int bpf_program__set_load_type(struct bpf_program *prog,\n+\t\t\t\t\t  enum bpf_prog_load_type loadtype);\n+LIBBPF_API enum bpf_prog_load_type bpf_program__load_type(const struct bpf_program *prog);\n+LIBBPF_API int bpf_program__load_dynamically(struct bpf_program *prog, int extra_log_level);\n+LIBBPF_API int bpf_program__unload_dynamically(struct bpf_program *prog);\n+\n #ifdef __cplusplus\n } /* extern \"C\" */\n #endif\ndiff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map\nindex 08ab2ea881fb6..74312c95d3287 100644\n--- a/tools/lib/bpf/libbpf.map\n+++ b/tools/lib/bpf/libbpf.map\n@@ -460,6 +460,10 @@ LIBBPF_1.8.0 {\n \tglobal:\n \t\tbpf_program__attach_tracing_multi;\n \t\tbpf_program__clone;\n+\t\tbpf_program__load_dynamically;\n+\t\tbpf_program__load_type;\n+\t\tbpf_program__set_load_type;\n+\t\tbpf_program__unload_dynamically;\n \t\tbtf__find_by_name_kind_own;\n \t\tbtf__new_empty_opts;\n } LIBBPF_1.7.0;\ndiff --git a/tools/testing/selftests/bpf/prog_tests/dynamicload.c b/tools/testing/selftests/bpf/prog_tests/dynamicload.c\nnew file mode 100644\nindex 0000000000000..799c43034ff92\n--- /dev/null\n+++ b/tools/testing/selftests/bpf/prog_tests/dynamicload.c\n@@ -0,0 +1,222 @@\n+// SPDX-License-Identifier: GPL-2.0\n+\n+#include \u003ctest_progs.h\u003e\n+#include \u003ctime.h\u003e\n+#include \"test_dynamicload.skel.h\"\n+\n+/* prog4 is tagged __load_dynamic in the source instead of being set\n+ * imperatively; verify that an explicit bpf_program__set_load_type() call\n+ * before load overrides the tag's declarative default.\n+ */\n+static void dynamicload_verify_override(void)\n+{\n+\tstruct test_dynamicload *skel;\n+\tint err;\n+\n+\tskel = test_dynamicload__open();\n+\tif (!ASSERT_OK_PTR(skel, \"skel_open\"))\n+\t\treturn;\n+\n+\terr = bpf_program__set_load_type(skel-\u003eprogs.prog4, BPF_PROG_LOAD_TYPE_DISABLED);\n+\tif (!ASSERT_OK(err, \"set_load_type_disabled\"))\n+\t\tgoto cleanup;\n+\n+\tif (!ASSERT_EQ(bpf_program__load_type(skel-\u003eprogs.prog4), BPF_PROG_LOAD_TYPE_DISABLED,\n+\t\t       \"prog4_load_type_overridden\"))\n+\t\tgoto cleanup;\n+\n+\t/* keep the other dynamic-load-only programs out of the way of this load */\n+\tbpf_program__set_load_type(skel-\u003eprogs.prog1, BPF_PROG_LOAD_TYPE_DISABLED);\n+\tbpf_program__set_load_type(skel-\u003eprogs.prog3, BPF_PROG_LOAD_TYPE_DISABLED);\n+\n+\terr = test_dynamicload__load(skel);\n+\tif (!ASSERT_OK(err, \"skel_load\"))\n+\t\tgoto cleanup;\n+\n+\t/* prog4 was never loaded, so it cannot be loaded dynamically either */\n+\terr = bpf_program__load_dynamically(skel-\u003eprogs.prog4, 0);\n+\tASSERT_ERR(err, \"load_dynamically_after_override\");\n+\n+cleanup:\n+\ttest_dynamicload__destroy(skel);\n+}\n+\n+void test_dynamicload(void)\n+{\n+\tstruct bpf_link *link;\n+\tstruct test_dynamicload *skel;\n+\tint err;\n+\n+\tskel = test_dynamicload__open();\n+\tif (!ASSERT_OK_PTR(skel, \"skel_open\"))\n+\t\treturn;\n+\n+\t/* the __load_dynamic tag alone, with no imperative call, must set\n+\t * prog4's load type before it is ever touched below\n+\t */\n+\tif (!ASSERT_EQ(bpf_program__load_type(skel-\u003eprogs.prog4), BPF_PROG_LOAD_TYPE_DYNAMIC,\n+\t\t       \"prog4_tag_load_type\"))\n+\t\tgoto cleanup;\n+\tif (!ASSERT_FALSE(bpf_program__autoattach(skel-\u003eprogs.prog4), \"prog4_autoattach\"))\n+\t\tgoto cleanup;\n+\n+\t/* don't load prog1 */\n+\tbpf_program__set_load_type(skel-\u003eprogs.prog1, BPF_PROG_LOAD_TYPE_DISABLED);\n+\n+\t/* prog2 is autoload */\n+\tbpf_program__set_load_type(skel-\u003eprogs.prog2, BPF_PROG_LOAD_TYPE_AUTO);\n+\n+\t/* prog3 is dynamically loaded */\n+\tbpf_program__set_load_type(skel-\u003eprogs.prog3, BPF_PROG_LOAD_TYPE_DYNAMIC);\n+\n+\terr = test_dynamicload__load(skel);\n+\tif (!ASSERT_OK(err, \"skel_load\"))\n+\t\tgoto cleanup;\n+\n+\terr = test_dynamicload__attach(skel);\n+\tif (!ASSERT_OK(err, \"skel_attach\"))\n+\t\tgoto cleanup;\n+\n+\t/* trigger the BPF programs */\n+\tusleep(1);\n+\n+\tASSERT_FALSE(skel-\u003ebss-\u003eprog1_called, \"prog1_called\");\n+\tASSERT_TRUE(skel-\u003ebss-\u003eprog2_called, \"prog2_called\");\n+\tASSERT_FALSE(skel-\u003ebss-\u003eprog3_called, \"prog3_called\");\n+\tASSERT_FALSE(skel-\u003ebss-\u003eprog4_called, \"prog4_called\");\n+\n+\t/* prog1 is disabled for load */\n+\terr = bpf_program__load_dynamically(skel-\u003eprogs.prog1, 0);\n+\tif (!ASSERT_ERR(err, \"load_dynamically_disabled\"))\n+\t\tgoto cleanup;\n+\n+\t/* prog1 is disabled for load */\n+\terr = bpf_program__unload_dynamically(skel-\u003eprogs.prog1);\n+\tif (!ASSERT_ERR(err, \"unload_dynamically_disabled\"))\n+\t\tgoto cleanup;\n+\n+\t/* prog2 is autoload */\n+\terr = bpf_program__load_dynamically(skel-\u003eprogs.prog2, 0);\n+\tif (!ASSERT_ERR(err, \"load_dynamically_autoload\"))\n+\t\tgoto cleanup;\n+\n+\t/* prog2 is autoload */\n+\terr = bpf_program__unload_dynamically(skel-\u003eprogs.prog2);\n+\tif (!ASSERT_ERR(err, \"unload_dynamically_autoload\"))\n+\t\tgoto cleanup;\n+\n+\t/* reset the call flags */\n+\tskel-\u003ebss-\u003eprog2_called = false;\n+\tskel-\u003ebss-\u003eprog3_called = false;\n+\n+\tusleep(1);\n+\n+\tASSERT_FALSE(skel-\u003ebss-\u003eprog1_called, \"prog1_called\");\n+\tASSERT_TRUE(skel-\u003ebss-\u003eprog2_called, \"prog2_called\");\n+\tASSERT_FALSE(skel-\u003ebss-\u003eprog3_called, \"prog3_called\");\n+\n+\t/* load prog3 */\n+\terr = bpf_program__load_dynamically(skel-\u003eprogs.prog3, 0);\n+\tif (!ASSERT_OK(err, \"load_dynamically\"))\n+\t\tgoto cleanup;\n+\n+\t/* attach prog3 */\n+\tlink = bpf_program__attach(skel-\u003eprogs.prog3);\n+\tif (!ASSERT_OK_PTR(link, \"attach\"))\n+\t\tgoto cleanup;\n+\n+\tusleep(1);\n+\n+\tif (!ASSERT_TRUE(skel-\u003ebss-\u003eprog3_called, \"prog3_called\"))\n+\t\tgoto cleanup;\n+\n+\t/* detach prog3 as test_dynamicload__destroy doesn't detach dynamically loaded programs */\n+\terr = bpf_link__destroy(link);\n+\tif (!ASSERT_OK(err, \"link_destroy\"))\n+\t\tgoto cleanup;\n+\n+\t/* reset the call flags after detach */\n+\tskel-\u003ebss-\u003eprog2_called = false;\n+\tskel-\u003ebss-\u003eprog3_called = false;\n+\n+\tusleep(1);\n+\n+\tASSERT_TRUE(skel-\u003ebss-\u003eprog2_called, \"prog2_called\");\n+\tASSERT_FALSE(skel-\u003ebss-\u003eprog3_called, \"prog3_called\");\n+\n+\t/* unload prog3 */\n+\terr = bpf_program__unload_dynamically(skel-\u003eprogs.prog3);\n+\tif (!ASSERT_OK(err, \"unload_dynamically\"))\n+\t\tgoto cleanup;\n+\n+\t/* reload prog3 */\n+\terr = bpf_program__load_dynamically(skel-\u003eprogs.prog3, 0);\n+\tif (!ASSERT_OK(err, \"load_dynamically_reload\"))\n+\t\tgoto cleanup;\n+\n+\t/* reattach prog3 */\n+\tlink = bpf_program__attach(skel-\u003eprogs.prog3);\n+\tif (!ASSERT_OK_PTR(link, \"reattach\"))\n+\t\tgoto cleanup;\n+\n+\tusleep(1);\n+\n+\tif (!ASSERT_TRUE(skel-\u003ebss-\u003eprog3_called, \"prog3_called_reattach\"))\n+\t\tgoto cleanup;\n+\n+\t/* detach prog3 as test_dynamicload__destroy doesn't detach dynamically loaded programs */\n+\terr = bpf_link__destroy(link);\n+\tif (!ASSERT_OK(err, \"link_destroy_reattach\"))\n+\t\tgoto cleanup;\n+\n+\t/* verify regular unload for dynamically loaded program,\n+\t * unload prog3 as a regular program\n+\t */\n+\tbpf_program__unload(skel-\u003eprogs.prog3);\n+\n+\t/* reset the call flags after unload */\n+\tskel-\u003ebss-\u003eprog2_called = false;\n+\tskel-\u003ebss-\u003eprog3_called = false;\n+\n+\tusleep(1);\n+\n+\tASSERT_TRUE(skel-\u003ebss-\u003eprog2_called, \"prog2_called\");\n+\tASSERT_FALSE(skel-\u003ebss-\u003eprog3_called, \"prog3_called\");\n+\n+\t/* reloading prog3 must fail as it was unloaded as a regular program */\n+\terr = bpf_program__load_dynamically(skel-\u003eprogs.prog3, 0);\n+\tASSERT_ERR(err, \"load_dynamically_after_regular_unload\");\n+\n+\t/* run prog4 (declaratively tagged) through the same dynamic\n+\t * load/attach/trigger/detach/unload cycle as prog3\n+\t */\n+\terr = bpf_program__load_dynamically(skel-\u003eprogs.prog4, 0);\n+\tif (!ASSERT_OK(err, \"prog4_load_dynamically\"))\n+\t\tgoto cleanup;\n+\n+\tlink = bpf_program__attach(skel-\u003eprogs.prog4);\n+\tif (!ASSERT_OK_PTR(link, \"prog4_attach\"))\n+\t\tgoto cleanup;\n+\n+\tusleep(1);\n+\n+\tif (!ASSERT_TRUE(skel-\u003ebss-\u003eprog4_called, \"prog4_called\"))\n+\t\tgoto cleanup;\n+\n+\terr = bpf_link__destroy(link);\n+\tif (!ASSERT_OK(err, \"prog4_link_destroy\"))\n+\t\tgoto cleanup;\n+\n+\terr = bpf_program__unload_dynamically(skel-\u003eprogs.prog4);\n+\tASSERT_OK(err, \"prog4_unload_dynamically\");\n+\n+\ttest_dynamicload__destroy(skel);\n+\n+\t/* separate scenario: imperative override of the declarative tag */\n+\tdynamicload_verify_override();\n+\treturn;\n+\n+cleanup:\n+\ttest_dynamicload__destroy(skel);\n+}\n+\ndiff --git a/tools/testing/selftests/bpf/prog_tests/load_type.c b/tools/testing/selftests/bpf/prog_tests/load_type.c\nnew file mode 100644\nindex 0000000000000..fc91f6666c506\n--- /dev/null\n+++ b/tools/testing/selftests/bpf/prog_tests/load_type.c\n@@ -0,0 +1,167 @@\n+// SPDX-License-Identifier: GPL-2.0\n+\n+#include \u003ctest_progs.h\u003e\n+#include \u003ctime.h\u003e\n+#include \"test_load_type.skel.h\"\n+\n+void test_load_type(void)\n+{\n+\tstruct bpf_link *link;\n+\tstruct test_load_type *skel;\n+\tint err;\n+\n+\tskel = test_load_type__open();\n+\tif (!ASSERT_OK_PTR(skel, \"skel_open\"))\n+\t\treturn;\n+\n+\t/* don't load prog1 */\n+\tbpf_program__set_load_type(skel-\u003eprogs.prog1, BPF_PROG_LOAD_TYPE_DISABLED);\n+\n+\t/* load and attach prog2 */\n+\tbpf_program__set_load_type(skel-\u003eprogs.prog2, BPF_PROG_LOAD_TYPE_AUTO);\n+\tif (!ASSERT_TRUE(bpf_program__autoload(skel-\u003eprogs.prog2), \"prog2_autoload\"))\n+\t\tgoto cleanup;\n+\n+\terr = bpf_program__set_load_type(skel-\u003eprogs.prog3, BPF_PROG_LOAD_TYPE_DYNAMIC);\n+\tif (!ASSERT_OK(err, \"set_load_type_dynamic\"))\n+\t\tgoto cleanup;\n+\tif (!ASSERT_EQ(bpf_program__load_type(skel-\u003eprogs.prog3), BPF_PROG_LOAD_TYPE_DYNAMIC,\n+\t\t       \"prog3_load_type\"))\n+\t\tgoto cleanup;\n+\n+\t/* bpf_program__set_autoload() is a thin forwarder to set_load_type(),\n+\t * restricted to AUTO/DISABLED to preserve its original bool on/off\n+\t * meaning; it does change the load type of a program that isn't\n+\t * currently BPF_PROG_LOAD_TYPE_AUTO.\n+\t */\n+\terr = bpf_program__set_autoload(skel-\u003eprogs.prog3, false);\n+\tif (!ASSERT_OK(err, \"set_autoload_false\"))\n+\t\tgoto cleanup;\n+\n+\tif (!ASSERT_EQ(bpf_program__load_type(skel-\u003eprogs.prog3), BPF_PROG_LOAD_TYPE_DISABLED,\n+\t\t       \"prog3_load_type_after_false\"))\n+\t\tgoto cleanup;\n+\n+\terr = bpf_program__set_autoload(skel-\u003eprogs.prog3, true);\n+\tif (!ASSERT_OK(err, \"set_autoload_true\"))\n+\t\tgoto cleanup;\n+\n+\tif (!ASSERT_EQ(bpf_program__load_type(skel-\u003eprogs.prog3), BPF_PROG_LOAD_TYPE_AUTO,\n+\t\t       \"prog3_load_type_after_true\"))\n+\t\tgoto cleanup;\n+\n+\t/* set_autoload() only accepts AUTO/DISABLED, to preserve its original\n+\t * on/off meaning; DYNAMIC must go through set_load_type()\n+\t */\n+\terr = bpf_program__set_autoload(skel-\u003eprogs.prog3, BPF_PROG_LOAD_TYPE_DYNAMIC);\n+\tif (!ASSERT_ERR(err, \"set_autoload_dynamic_rejected\"))\n+\t\tgoto cleanup;\n+\n+\tif (!ASSERT_EQ(bpf_program__load_type(skel-\u003eprogs.prog3), BPF_PROG_LOAD_TYPE_AUTO,\n+\t\t       \"prog3_load_type_unchanged_after_rejected_autoload\"))\n+\t\tgoto cleanup;\n+\n+\terr = bpf_program__set_load_type(skel-\u003eprogs.prog3, BPF_PROG_LOAD_TYPE_DYNAMIC);\n+\tif (!ASSERT_OK(err, \"set_load_type_dynamic_enum\"))\n+\t\tgoto cleanup;\n+\n+\tif (!ASSERT_EQ(bpf_program__load_type(skel-\u003eprogs.prog3), BPF_PROG_LOAD_TYPE_DYNAMIC,\n+\t\t       \"prog3_load_type_after_dynamic_enum\"))\n+\t\tgoto cleanup;\n+\n+\t/* leaving DYNAMIC for AUTO must restore autoattach (regression test for\n+\t * the autoattach residue bug: set_dynamicload() clears autoattach, and\n+\t * nothing used to restore it on exit)\n+\t */\n+\terr = bpf_program__set_load_type(skel-\u003eprogs.prog3, BPF_PROG_LOAD_TYPE_AUTO);\n+\tif (!ASSERT_OK(err, \"set_load_type_auto\"))\n+\t\tgoto cleanup;\n+\n+\tif (!ASSERT_EQ(bpf_program__load_type(skel-\u003eprogs.prog3), BPF_PROG_LOAD_TYPE_AUTO,\n+\t\t       \"prog3_load_type_auto\"))\n+\t\tgoto cleanup;\n+\n+\tif (!ASSERT_TRUE(bpf_program__autoattach(skel-\u003eprogs.prog3), \"prog3_autoattach_restored\"))\n+\t\tgoto cleanup;\n+\n+\t/* the same residue can relay through DISABLED and resurface on a later\n+\t * DISABLED -\u003e AUTO transition, so the fix must cover both exit edges\n+\t */\n+\terr = bpf_program__set_load_type(skel-\u003eprogs.prog3, BPF_PROG_LOAD_TYPE_DYNAMIC);\n+\tif (!ASSERT_OK(err, \"set_load_type_dynamic_again\"))\n+\t\tgoto cleanup;\n+\n+\terr = bpf_program__set_load_type(skel-\u003eprogs.prog3, BPF_PROG_LOAD_TYPE_DISABLED);\n+\tif (!ASSERT_OK(err, \"set_load_type_disabled\"))\n+\t\tgoto cleanup;\n+\n+\terr = bpf_program__set_load_type(skel-\u003eprogs.prog3, BPF_PROG_LOAD_TYPE_AUTO);\n+\tif (!ASSERT_OK(err, \"set_load_type_auto_via_disabled\"))\n+\t\tgoto cleanup;\n+\n+\tif (!ASSERT_TRUE(bpf_program__autoattach(skel-\u003eprogs.prog3),\n+\t\t\t \"prog3_autoattach_restored_via_disabled\"))\n+\t\tgoto cleanup;\n+\n+\t/* an out-of-range load type is rejected */\n+\terr = bpf_program__set_load_type(skel-\u003eprogs.prog3, (enum bpf_prog_load_type)999);\n+\tif (!ASSERT_ERR(err, \"set_load_type_invalid\"))\n+\t\tgoto cleanup;\n+\n+\t/* change the type back to BPF_PROG_LOAD_TYPE_DYNAMIC for the rest of the test */\n+\terr = bpf_program__set_load_type(skel-\u003eprogs.prog3, BPF_PROG_LOAD_TYPE_DYNAMIC);\n+\tif (!ASSERT_OK(err, \"set_load_type_dynamic_final\"))\n+\t\tgoto cleanup;\n+\n+\tif (!ASSERT_EQ(bpf_program__load_type(skel-\u003eprogs.prog3), BPF_PROG_LOAD_TYPE_DYNAMIC,\n+\t\t       \"prog3_load_type_final\"))\n+\t\tgoto cleanup;\n+\n+\terr = test_load_type__load(skel);\n+\tif (!ASSERT_OK(err, \"skel_load\"))\n+\t\tgoto cleanup;\n+\n+\tif (!ASSERT_TRUE(bpf_program__autoattach(skel-\u003eprogs.prog2), \"prog2_autoattach\"))\n+\t\tgoto cleanup;\n+\tif (!ASSERT_FALSE(bpf_program__autoattach(skel-\u003eprogs.prog3), \"prog3_autoattach\"))\n+\t\tgoto cleanup;\n+\n+\t/* loaded program type cannot be changed */\n+\terr = bpf_program__set_load_type(skel-\u003eprogs.prog3, BPF_PROG_LOAD_TYPE_DISABLED);\n+\tASSERT_ERR(err, \"set_load_type_after_load\");\n+\n+\terr = test_load_type__attach(skel);\n+\tif (!ASSERT_OK(err, \"skel_attach\"))\n+\t\tgoto cleanup;\n+\n+\tusleep(1);\n+\n+\tASSERT_FALSE(skel-\u003ebss-\u003eprog1_called, \"prog1_called\");\n+\tASSERT_TRUE(skel-\u003ebss-\u003eprog2_called, \"prog2_called\");\n+\tASSERT_FALSE(skel-\u003ebss-\u003eprog3_called, \"prog3_called\");\n+\n+\terr = bpf_program__load_dynamically(skel-\u003eprogs.prog3, 0);\n+\tif (!ASSERT_OK(err, \"load_dynamically_1\"))\n+\t\tgoto cleanup;\n+\n+\terr = bpf_program__load_dynamically(skel-\u003eprogs.prog3, 0);\n+\tif (!ASSERT_OK(err, \"load_dynamically_2\"))\n+\t\tgoto cleanup;\n+\n+\t/* attach prog3 */\n+\tlink = bpf_program__attach(skel-\u003eprogs.prog3);\n+\tif (!ASSERT_OK_PTR(link, \"attach\"))\n+\t\tgoto cleanup;\n+\n+\tusleep(1);\n+\n+\tif (!ASSERT_TRUE(skel-\u003ebss-\u003eprog3_called, \"prog3_called_again\"))\n+\t\tgoto cleanup;\n+\n+\t/* detach prog3 as test_load_type__destroy doesn't detach dynamically loaded programs */\n+\terr = bpf_link__destroy(link);\n+\tASSERT_OK(err, \"link_destroy\");\n+\n+cleanup:\n+\ttest_load_type__destroy(skel);\n+}\ndiff --git a/tools/testing/selftests/bpf/progs/test_dynamicload.c b/tools/testing/selftests/bpf/progs/test_dynamicload.c\nnew file mode 100644\nindex 0000000000000..6f5a5cb898031\n--- /dev/null\n+++ b/tools/testing/selftests/bpf/progs/test_dynamicload.c\n@@ -0,0 +1,40 @@\n+// SPDX-License-Identifier: GPL-2.0\n+\n+#include \"vmlinux.h\"\n+#include \u003cbpf/bpf_helpers.h\u003e\n+\n+bool prog1_called = false;\n+bool prog2_called = false;\n+bool prog3_called = false;\n+bool prog4_called = false;\n+\n+SEC(\"raw_tp/sys_enter\")\n+int prog1(const void *ctx)\n+{\n+\tprog1_called = true;\n+\treturn 0;\n+}\n+\n+SEC(\"raw_tp/sys_enter\")\n+int prog2(const void *ctx)\n+{\n+\tprog2_called = true;\n+\treturn 0;\n+}\n+\n+SEC(\"raw_tp/sys_enter\")\n+int prog3(const void *ctx)\n+{\n+\tprog3_called = true;\n+\treturn 0;\n+}\n+\n+SEC(\"raw_tp/sys_enter\")\n+__load_dynamic\n+int prog4(const void *ctx)\n+{\n+\tprog4_called = true;\n+\treturn 0;\n+}\n+\n+char _license[] SEC(\"license\") = \"GPL\";\ndiff --git a/tools/testing/selftests/bpf/progs/test_load_type.c b/tools/testing/selftests/bpf/progs/test_load_type.c\nnew file mode 100644\nindex 0000000000000..3d9b81691d7ad\n--- /dev/null\n+++ b/tools/testing/selftests/bpf/progs/test_load_type.c\n@@ -0,0 +1,31 @@\n+// SPDX-License-Identifier: GPL-2.0\n+\n+#include \"vmlinux.h\"\n+#include \u003cbpf/bpf_helpers.h\u003e\n+\n+bool prog1_called = false;\n+bool prog2_called = false;\n+bool prog3_called = false;\n+\n+SEC(\"raw_tp/sys_enter\")\n+int prog1(const void *ctx)\n+{\n+\tprog1_called = true;\n+\treturn 0;\n+}\n+\n+SEC(\"raw_tp/sys_enter\")\n+int prog2(const void *ctx)\n+{\n+\tprog2_called = true;\n+\treturn 0;\n+}\n+\n+SEC(\"raw_tp/sys_enter\")\n+int prog3(const void *ctx)\n+{\n+\tprog3_called = true;\n+\treturn 0;\n+}\n+\n+char _license[] SEC(\"license\") = \"GPL\";\n"
}

2/1 2026/08/26 19:21 agent patch-evaluator
0m Model:
best-expensive

Args:
null

Results:
{
  "EnableConfigs": null,
  "FocusSymbols": [],
  "Reasoning": "The patch only modifies the user-space libbpf library and adds selftests in the tools/ directory. It does not make any functional changes to the kernel code itself that can be fuzzed.",
  "WorthFuzzing": false
}

Instruction:
You are an expert Linux kernel maintainer.
Your job is to review a provided patch series and determine
if it makes functional changes to the kernel that should be fuzzed.

IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on your internal knowledge of the kernel. You must actively
use your code access tools to examine the actual source code and confirm any assumptions.

Return WorthFuzzing=false if the patch only contains:
- Modifications to Documentation/, Kconfig files, or code comments.
- Purely decorative changes, such as logging (e.g., pr_err, printk) or tracepoints.
- Changes to numeric constants or macros that do not functionally alter execution flow.
- Code paths that are impossible to reach in virtualized environments like GCE or QEMU,
  even when utilizing software-emulated hardware (e.g., usb gadget, mac80211_hwsim).
- Code in vendor-specific PCIe switch, SmartNIC, or GPU drivers (e.g., mlxsw, pds_core, qed,
  ionic, amdgpu) that require physical PCIe hardware cards not emulated in standard QEMU.
- Driver .remove, .shutdown, or pci_unregister_driver teardown callbacks (e.g., igb_remove)
  that are executed only during PCI hot-unplug or sysfs driver unbind operations.

If it modifies reachable core kernel logic, drivers, or architectures, use your code search
tools to verify the code can be executed, then return WorthFuzzing=true.

When returning WorthFuzzing=true, you MUST ALSO:
1. Extract any specific kernel functions that should be heavily fuzzed into FocusSymbols.
   Avoid listing generic hot-path functions to prevent skewed test distributions.
   Prefer non-static, non-inlined API entrypoint functions over internal static helper functions
   (which are inlined by the compiler and do not have distinct symbol addresses).
2. Identify any specific CONFIG_ options required to properly test this new/modified feature.
   Go and look into the Kconfig files and check for ifdefs around the code, do not make assumptions.
   Also check "depends on" lines in Kconfig to include any non-standard parent subsystem configs
   needed for Kbuild to compile the code statically into vmlinux. List them in the EnableConfigs
   output array, and DO NOT add a 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4").
Prefer calling several tools at the same time to save round-trips.


Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.

Prompt:
For your convenience, here is the diff of the changes:
commit e7e392857bccbf5726ffd4974ca9066a26bf4162
Author: syz-cluster <triage@syzkaller.com>
Date:   Wed Aug 26 19:21:34 2026 +0000

    syz-cluster: applied patch under review

diff --git a/tools/lib/bpf/bpf_helpers.h b/tools/lib/bpf/bpf_helpers.h
index 9d160b5b9c0ee..52978f0e04539 100644
--- a/tools/lib/bpf/bpf_helpers.h
+++ b/tools/lib/bpf/bpf_helpers.h
@@ -218,6 +218,11 @@ enum libbpf_tristate {
 #define __arg_untrusted __attribute((btf_decl_tag("arg:untrusted")))
 #define __arg_arena __attribute((btf_decl_tag("arg:arena")))
 
+/* Mark a BPF program to be loaded dynamically instead of autoloaded,
+ * equivalent to bpf_program__set_load_type(prog, BPF_PROG_LOAD_TYPE_DYNAMIC).
+ */
+#define __load_dynamic __attribute__((btf_decl_tag("loadtype:dynamic")))
+
 #ifndef ___bpf_concat
 #define ___bpf_concat(a, b) a ## b
 #endif
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index b749c01742ee0..5d58dbf25234f 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -494,7 +494,7 @@ struct bpf_program {
 	struct bpf_object *obj;
 
 	int fd;
-	bool autoload;
+	enum bpf_prog_load_type load_type;
 	bool autoattach;
 	bool sym_global;
 	bool mark_btf_static;
@@ -725,6 +725,7 @@ struct bpf_object {
 
 	bool has_subcalls;
 	bool has_rodata;
+	bool has_dynload_progs;
 
 	struct bpf_gen *gen_loader;
 
@@ -872,11 +873,11 @@ bpf_object__init_prog(struct bpf_object *obj, struct bpf_program *prog,
 	 * autoload set to false.
 	 */
 	if (sec_name[0] == '?') {
-		prog->autoload = false;
+		prog->load_type = BPF_PROG_LOAD_TYPE_DISABLED;
 		/* from now on forget there was ? in section name */
 		sec_name++;
 	} else {
-		prog->autoload = true;
+		prog->load_type = BPF_PROG_LOAD_TYPE_AUTO;
 	}
 
 	prog->autoattach = true;
@@ -1125,9 +1126,10 @@ static bool is_valid_st_ops_program(struct bpf_object *obj,
 }
 
 /* For each struct_ops program P, referenced from some struct_ops map M,
- * enable P.autoload if there are Ms for which M.autocreate is true,
- * disable P.autoload if for all Ms M.autocreate is false.
- * Don't change P.autoload for programs that are not referenced from any maps.
+ * set P's load type to BPF_PROG_LOAD_TYPE_AUTO if there are Ms for which
+ * M.autocreate is true, or to BPF_PROG_LOAD_TYPE_DISABLED if for all Ms
+ * M.autocreate is false.
+ * Don't change P's load type for programs that are not referenced from any maps.
  */
 static int bpf_object_adjust_struct_ops_autoload(struct bpf_object *obj)
 {
@@ -1163,7 +1165,8 @@ static int bpf_object_adjust_struct_ops_autoload(struct bpf_object *obj)
 			}
 		}
 		if (use_cnt)
-			prog->autoload = should_load;
+			prog->load_type = should_load ? BPF_PROG_LOAD_TYPE_AUTO
+				: BPF_PROG_LOAD_TYPE_DISABLED;
 	}
 
 	return 0;
@@ -1242,13 +1245,14 @@ static int bpf_map__init_kern_struct_ops(struct bpf_map *map)
 
 			if (st_ops->progs[i]) {
 				/* If we had declaratively set struct_ops callback, we need to
-				 * force its autoload to false, because it doesn't have
-				 * a chance of succeeding from POV of the current struct_ops map.
-				 * If this program is still referenced somewhere else, though,
-				 * then bpf_object_adjust_struct_ops_autoload() will update its
-				 * autoload accordingly.
+				 * force its load type to BPF_PROG_LOAD_TYPE_DISABLED, because
+				 * it doesn't have a chance of succeeding from POV of the
+				 * current struct_ops map. If this program is still referenced
+				 * somewhere else, though, then
+				 * bpf_object_adjust_struct_ops_autoload() will update its
+				 * load type accordingly.
 				 */
-				st_ops->progs[i]->autoload = false;
+				st_ops->progs[i]->load_type = BPF_PROG_LOAD_TYPE_DISABLED;
 				st_ops->progs[i] = NULL;
 			}
 
@@ -1287,7 +1291,7 @@ static int bpf_map__init_kern_struct_ops(struct bpf_map *map)
 			 * if user replaced it with another program or NULL
 			 */
 			if (st_ops->progs[i] && st_ops->progs[i] != prog)
-				st_ops->progs[i]->autoload = false;
+				st_ops->progs[i]->load_type = BPF_PROG_LOAD_TYPE_DISABLED;
 
 			/* Update the value from the shadow type */
 			st_ops->progs[i] = prog;
@@ -3600,7 +3604,7 @@ static bool obj_needs_vmlinux_btf(const struct bpf_object *obj)
 	}
 
 	bpf_object__for_each_program(prog, obj) {
-		if (!prog->autoload)
+		if (prog->load_type == BPF_PROG_LOAD_TYPE_DISABLED)
 			continue;
 		if (prog_needs_vmlinux_btf(prog))
 			return true;
@@ -6194,7 +6198,7 @@ bpf_object__relocate_core(struct bpf_object *obj, const char *targ_btf_path)
 			/* no need to apply CO-RE relocation if the program is
 			 * not going to be loaded
 			 */
-			if (!prog->autoload)
+			if (prog->load_type == BPF_PROG_LOAD_TYPE_DISABLED)
 				continue;
 
 			/* adjust insn_idx from section frame of reference to the local
@@ -7154,6 +7158,50 @@ static int bpf_prog_assign_exc_cb(struct bpf_object *obj, struct bpf_program *pr
 	return 0;
 }
 
+#define DYNLOAD_DECL_TAG "loadtype:dynamic"
+
+/*
+ * Check whether a BPF program is annotated with the DYNLOAD_DECL_TAG BTF
+ * decl tag, requesting that it be loaded dynamically after the object load.
+ *
+ * Returns 1 if the tag is present, 0 if it is not, negative error otherwise.
+ */
+static int prog_has_dynload_tag(struct bpf_object *obj, struct bpf_program *prog)
+{
+	int i, n;
+
+	if (!obj->btf)
+		return 0;
+
+	n = btf__type_cnt(obj->btf);
+	for (i = 1; i < n; i++) {
+		const struct btf_type *tag_t, *fn_t;
+
+		tag_t = btf__type_by_id(obj->btf, i);
+		if (!btf_is_decl_tag(tag_t) || btf_decl_tag(tag_t)->component_idx != -1)
+			continue;
+		if (strcmp(btf__str_by_offset(obj->btf, tag_t->name_off),
+			   DYNLOAD_DECL_TAG) != 0)
+			continue;
+
+		/* a decl tag's type field points at the entity it decorates */
+		fn_t = btf__type_by_id(obj->btf, tag_t->type);
+		if (!btf_is_func(fn_t) || btf_func_linkage(fn_t) != BTF_FUNC_GLOBAL) {
+			pr_warn("prog '%s': " DYNLOAD_DECL_TAG
+				" decl tag must be applied to a global function\n",
+				prog->name);
+			return -EINVAL;
+		}
+
+		if (strcmp(btf__str_by_offset(obj->btf, fn_t->name_off), prog->name) != 0)
+			continue;   /* tag belongs to a different program */
+
+		return 1;
+	}
+
+	return 0;
+}
+
 static struct {
 	enum bpf_prog_type prog_type;
 	const char *ctx_name;
@@ -7530,7 +7578,7 @@ static int bpf_object__relocate(struct bpf_object *obj, const char *targ_btf_pat
 		 */
 		if (prog_is_subprog(obj, prog))
 			continue;
-		if (!prog->autoload)
+		if (prog->load_type == BPF_PROG_LOAD_TYPE_DISABLED)
 			continue;
 
 		err = bpf_object__relocate_calls(obj, prog);
@@ -7566,7 +7614,7 @@ static int bpf_object__relocate(struct bpf_object *obj, const char *targ_btf_pat
 		prog = &obj->programs[i];
 		if (prog_is_subprog(obj, prog))
 			continue;
-		if (!prog->autoload)
+		if (prog->load_type == BPF_PROG_LOAD_TYPE_DISABLED)
 			continue;
 
 		/* Process data relos for main programs */
@@ -8055,7 +8103,7 @@ static int bpf_object_load_prog(struct bpf_object *obj, struct bpf_program *prog
 			log_buf = prog->log_buf;
 			log_buf_size = prog->log_size;
 			own_log_buf = false;
-		} else if (obj->log_buf) {
+		} else if (obj->log_buf && prog->load_type != BPF_PROG_LOAD_TYPE_DYNAMIC) {
 			log_buf = obj->log_buf;
 			log_buf_size = obj->log_size;
 			own_log_buf = false;
@@ -8398,10 +8446,14 @@ bpf_object__load_progs(struct bpf_object *obj, int log_level)
 		prog = &obj->programs[i];
 		if (prog_is_subprog(obj, prog))
 			continue;
-		if (!prog->autoload) {
-			pr_debug("prog '%s': skipped loading\n", prog->name);
+		if (prog->load_type != BPF_PROG_LOAD_TYPE_AUTO) {
+			pr_debug("prog '%s': skipped loading, load type is %s\n",
+				 prog->name,
+				 prog->load_type == BPF_PROG_LOAD_TYPE_DYNAMIC ?
+				 "dynamic" : "disabled");
 			continue;
 		}
+
 		prog->log_level |= log_level;
 
 		if (obj->gen_loader)
@@ -8464,6 +8516,22 @@ static int bpf_object_init_progs(struct bpf_object *obj, const struct bpf_object
 				return err;
 			}
 		}
+
+		if (prog_is_subprog(obj, prog))
+			continue;
+
+		err = prog_has_dynload_tag(obj, prog);
+		if (err < 0)
+			return err;
+		if (err > 0) {
+			err = bpf_program__set_load_type(prog, BPF_PROG_LOAD_TYPE_DYNAMIC);
+			if (err) {
+				pr_warn("prog '%s': failed to apply " DYNLOAD_DECL_TAG
+					" decl tag: %s\n",
+					prog->name, errstr(err));
+				return err;
+			}
+		}
 	}
 
 	return 0;
@@ -9075,15 +9143,22 @@ static void bpf_object_cleanup_btf(struct bpf_object *obj)
 	obj->btf_modules_loaded = false;
 	zfree(&obj->btf_modules);
 
-	/* clean up vmlinux BTF */
-	btf__free(obj->btf_vmlinux);
-	obj->btf_vmlinux = NULL;
+	/* The btf_vmlinux data is needed for dynamically loaded programs,
+	 * so defer freeing it in that case to the end of the object lifetime.
+	 */
+	if (!obj->has_dynload_progs) {
+		btf__free(obj->btf_vmlinux);
+		obj->btf_vmlinux = NULL;
+	}
 }
 
 static void bpf_object_post_load_cleanup(struct bpf_object *obj)
 {
-	/* clean up fd_array */
-	zfree(&obj->fd_array);
+	/* The fd array is needed for dynamically loaded programs,
+	 * so defer freeing it in that case to the end of the object lifetime.
+	 */
+	if (!obj->has_dynload_progs || !obj->fd_array_cnt)
+		zfree(&obj->fd_array);
 
 	/* clean up BTF */
 	bpf_object_cleanup_btf(obj);
@@ -9677,6 +9752,8 @@ void bpf_object__close(struct bpf_object *obj)
 		close(obj->jumptable_maps[i].fd);
 	zfree(&obj->jumptable_maps);
 
+	zfree(&obj->fd_array);
+
 	free(obj);
 }
 
@@ -9799,16 +9876,15 @@ const char *bpf_program__section_name(const struct bpf_program *prog)
 
 bool bpf_program__autoload(const struct bpf_program *prog)
 {
-	return prog->autoload;
+	return prog->load_type == BPF_PROG_LOAD_TYPE_AUTO;
 }
 
-int bpf_program__set_autoload(struct bpf_program *prog, bool autoload)
+int bpf_program__set_autoload(struct bpf_program *prog, enum bpf_prog_load_type autoload)
 {
-	if (prog->obj->state >= OBJ_LOADED)
+	if (autoload != BPF_PROG_LOAD_TYPE_AUTO && autoload != BPF_PROG_LOAD_TYPE_DISABLED)
 		return libbpf_err(-EINVAL);
 
-	prog->autoload = autoload;
-	return 0;
+	return bpf_program__set_load_type(prog, autoload);
 }
 
 bool bpf_program__autoattach(const struct bpf_program *prog)
@@ -15111,7 +15187,7 @@ int bpf_object__attach_skeleton(struct bpf_object_skeleton *s)
 		struct bpf_program *prog = *prog_skel->prog;
 		struct bpf_link **link = prog_skel->link;
 
-		if (!prog->autoload || !prog->autoattach)
+		if (prog->load_type != BPF_PROG_LOAD_TYPE_AUTO || !prog->autoattach)
 			continue;
 
 		/* auto-attaching not supported for this program */
@@ -15221,3 +15297,136 @@ void bpf_object__destroy_skeleton(struct bpf_object_skeleton *s)
 	free(s->progs);
 	free(s);
 }
+
+static int bpf_program__set_dynamicload(struct bpf_program *prog)
+{
+	struct bpf_object *obj;
+	const char *attach_name;
+
+	obj = prog->obj;
+	if (!obj)
+		return libbpf_err(-EINVAL);
+
+	/* Dynamically-loaded programs are not supported for gen_loader.
+	 * This is because bpf_object_load_prog is not called for
+	 * dynamicload programs, so dynamicload programs are not visible
+	 * to gen_loader. For this reason, prevent calling
+	 * bpf_program__set_dynamicload when gen_loader was used to
+	 * generate a BPF object loader.
+	 * A gen_loader implementation is being called for programs with
+	 * load type BPF_PROG_LOAD_TYPE_AUTO and defines its own model for
+	 * loading BPF programs.
+	 */
+	if (obj->gen_loader)
+		return libbpf_err(-ENOTSUP);
+
+	if (prog_is_subprog(obj, prog))
+		return libbpf_err(-EINVAL);
+
+	attach_name = strchr(prog->sec_name, '/');
+	if (!attach_name || strchr(attach_name, ':')) {
+		/* Only reject programs that require BTF-based attach target
+		 * resolution (indicated by the SEC_ATTACH_BTF flag). Such
+		 * programs need the section name parsed for the attach target
+		 * function name (after '/') and optionally the module name
+		 * (before ':') for libbpf_find_attach_btf_id.
+		 *
+		 * Programs like SEC("classifier"), SEC("socket"), etc. do
+		 * not require BTF attach resolution and can safely use
+		 * dynamic loading despite having no '/' in their section
+		 * name. The BTF guard in libbpf_prepare_prog_load (checking
+		 * SEC_ATTACH_BTF) is the authoritative check; this is an
+		 * early-reject for programs that would fail there.
+		 */
+		long flags = prog->sec_def ?
+			(long)prog->sec_def->cookie : SEC_ATTACH_BTF;
+		if ((flags & SEC_ATTACH_BTF) && !prog->attach_btf_id)
+			return libbpf_err(-EINVAL);
+	}
+
+	obj->has_dynload_progs = true;
+	prog->load_type = BPF_PROG_LOAD_TYPE_DYNAMIC;
+	prog->autoattach = false;
+
+	return 0;
+}
+
+int bpf_program__set_load_type(struct bpf_program *prog, enum bpf_prog_load_type type)
+{
+	if (!prog)
+		return libbpf_err(-EINVAL);
+
+	if (prog->obj->state >= OBJ_LOADED)
+		return libbpf_err(-EINVAL);
+
+	switch (type) {
+	case BPF_PROG_LOAD_TYPE_DYNAMIC:
+		return bpf_program__set_dynamicload(prog);
+	case BPF_PROG_LOAD_TYPE_AUTO:
+	case BPF_PROG_LOAD_TYPE_DISABLED:
+		/*
+		 * Leaving the dynamic state: set_dynamicload() cleared
+		 * autoattach because dynamically loaded programs are attached
+		 * explicitly. Restore the default for the target load type.
+		 */
+		if (prog->load_type == BPF_PROG_LOAD_TYPE_DYNAMIC)
+			prog->autoattach = true;
+		prog->load_type = type;
+		break;
+	default:
+		return libbpf_err(-EINVAL);
+	}
+
+	return 0;
+}
+
+enum bpf_prog_load_type bpf_program__load_type(const struct bpf_program *prog)
+{
+	return prog->load_type;
+}
+
+/*
+ * This function must be called after bpf_object__load_progs.
+ * Dynamically-loaded program data is initialized on object load.
+ * Post-load initialization is not supported.
+ */
+int
+bpf_program__load_dynamically(struct bpf_program *prog, int extra_log_level)
+{
+	int err;
+	struct bpf_object *obj;
+
+	obj = prog->obj;
+	if (!obj || obj->state < OBJ_LOADED)
+		return libbpf_err(-EINVAL);
+
+	if (prog_is_subprog(obj, prog) || prog->load_type != BPF_PROG_LOAD_TYPE_DYNAMIC)
+		return libbpf_err(-EINVAL);
+
+	prog->log_level |= extra_log_level;
+
+	err = bpf_object_load_prog(obj, prog, prog->insns, prog->insns_cnt,
+				   obj->license, obj->kern_version, &prog->fd);
+	if (err) {
+		pr_warn("prog '%s': failed to dynamically load: %d\n", prog->name, err);
+		prog->log_level &= ~extra_log_level;
+		return err;
+	}
+
+	prog->log_level &= ~extra_log_level;
+	return 0;
+}
+
+int bpf_program__unload_dynamically(struct bpf_program *prog)
+{
+	int err;
+
+	if (!prog || prog->load_type != BPF_PROG_LOAD_TYPE_DYNAMIC)
+		return libbpf_err(-EINVAL);
+
+	/* Close the file descriptor but retain the program's data to
+	 * support reloading the program if it is required again.
+	 */
+	err = zclose(prog->fd);
+	return err ? libbpf_err(-errno) : 0;
+}
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index b965ad5715403..a56068f0f1122 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -356,6 +356,19 @@ LIBBPF_API int libbpf_attach_type_by_name(const char *name,
 LIBBPF_API int libbpf_find_vmlinux_btf_id(const char *name,
 					  enum bpf_attach_type attach_type);
 
+/*
+ * The program load type:
+ *
+ * - BPF_PROG_LOAD_TYPE_DISABLED: the program is not loaded.
+ * - BPF_PROG_LOAD_TYPE_AUTO: the program is autoloaded when the bpf_object is loaded.
+ * - BPF_PROG_LOAD_TYPE_DYNAMIC: the program is loaded and attached dynamically.
+ */
+enum bpf_prog_load_type {
+	BPF_PROG_LOAD_TYPE_DISABLED = 0,
+	BPF_PROG_LOAD_TYPE_AUTO,
+	BPF_PROG_LOAD_TYPE_DYNAMIC,
+};
+
 /* Accessors of bpf_program */
 struct bpf_program;
 
@@ -376,7 +389,18 @@ LIBBPF_API void bpf_program__set_ifindex(struct bpf_program *prog,
 LIBBPF_API const char *bpf_program__name(const struct bpf_program *prog);
 LIBBPF_API const char *bpf_program__section_name(const struct bpf_program *prog);
 LIBBPF_API bool bpf_program__autoload(const struct bpf_program *prog);
-LIBBPF_API int bpf_program__set_autoload(struct bpf_program *prog, bool autoload);
+/**
+ * @brief **bpf_program__set_autoload()** is retained for backwards
+ * compatibility; **bpf_program__set_load_type()** is the preferred API.
+ * The enum's numbering (DISABLED=0, AUTO=1, DYNAMIC=2) matches the previous
+ * bool semantics (false=0, true=1), so existing bool callers keep compiling
+ * and behaving unchanged. Only BPF_PROG_LOAD_TYPE_AUTO and
+ * BPF_PROG_LOAD_TYPE_DISABLED are accepted, preserving the original
+ * autoload on/off meaning; use bpf_program__set_load_type() to set
+ * BPF_PROG_LOAD_TYPE_DYNAMIC.
+ */
+LIBBPF_API int bpf_program__set_autoload(struct bpf_program *prog,
+					 enum bpf_prog_load_type autoload);
 LIBBPF_API bool bpf_program__autoattach(const struct bpf_program *prog);
 LIBBPF_API void bpf_program__set_autoattach(struct bpf_program *prog, bool autoattach);
 
@@ -2078,6 +2102,12 @@ LIBBPF_API int libbpf_unregister_prog_handler(int handler_id);
  */
 LIBBPF_API int bpf_program__clone(struct bpf_program *prog, const struct bpf_prog_load_opts *opts);
 
+LIBBPF_API int bpf_program__set_load_type(struct bpf_program *prog,
+					  enum bpf_prog_load_type loadtype);
+LIBBPF_API enum bpf_prog_load_type bpf_program__load_type(const struct bpf_program *prog);
+LIBBPF_API int bpf_program__load_dynamically(struct bpf_program *prog, int extra_log_level);
+LIBBPF_API int bpf_program__unload_dynamically(struct bpf_program *prog);
+
 #ifdef __cplusplus
 } /* extern "C" */
 #endif
diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map
index 08ab2ea881fb6..74312c95d3287 100644
--- a/tools/lib/bpf/libbpf.map
+++ b/tools/lib/bpf/libbpf.map
@@ -460,6 +460,10 @@ LIBBPF_1.8.0 {
 	global:
 		bpf_program__attach_tracing_multi;
 		bpf_program__clone;
+		bpf_program__load_dynamically;
+		bpf_program__load_type;
+		bpf_program__set_load_type;
+		bpf_program__unload_dynamically;
 		btf__find_by_name_kind_own;
 		btf__new_empty_opts;
 } LIBBPF_1.7.0;
diff --git a/tools/testing/selftests/bpf/prog_tests/dynamicload.c b/tools/testing/selftests/bpf/prog_tests/dynamicload.c
new file mode 100644
index 0000000000000..799c43034ff92
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/dynamicload.c
@@ -0,0 +1,222 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <test_progs.h>
+#include <time.h>
+#include "test_dynamicload.skel.h"
+
+/* prog4 is tagged __load_dynamic in the source instead of being set
+ * imperatively; verify that an explicit bpf_program__set_load_type() call
+ * before load overrides the tag's declarative default.
+ */
+static void dynamicload_verify_override(void)
+{
+	struct test_dynamicload *skel;
+	int err;
+
+	skel = test_dynamicload__open();
+	if (!ASSERT_OK_PTR(skel, "skel_open"))
+		return;
+
+	err = bpf_program__set_load_type(skel->progs.prog4, BPF_PROG_LOAD_TYPE_DISABLED);
+	if (!ASSERT_OK(err, "set_load_type_disabled"))
+		goto cleanup;
+
+	if (!ASSERT_EQ(bpf_program__load_type(skel->progs.prog4), BPF_PROG_LOAD_TYPE_DISABLED,
+		       "prog4_load_type_overridden"))
+		goto cleanup;
+
+	/* keep the other dynamic-load-only programs out of the way of this load */
+	bpf_program__set_load_type(skel->progs.prog1, BPF_PROG_LOAD_TYPE_DISABLED);
+	bpf_program__set_load_type(skel->progs.prog3, BPF_PROG_LOAD_TYPE_DISABLED);
+
+	err = test_dynamicload__load(skel);
+	if (!ASSERT_OK(err, "skel_load"))
+		goto cleanup;
+
+	/* prog4 was never loaded, so it cannot be loaded dynamically either */
+	err = bpf_program__load_dynamically(skel->progs.prog4, 0);
+	ASSERT_ERR(err, "load_dynamically_after_override");
+
+cleanup:
+	test_dynamicload__destroy(skel);
+}
+
+void test_dynamicload(void)
+{
+	struct bpf_link *link;
+	struct test_dynamicload *skel;
+	int err;
+
+	skel = test_dynamicload__open();
+	if (!ASSERT_OK_PTR(skel, "skel_open"))
+		return;
+
+	/* the __load_dynamic tag alone, with no imperative call, must set
+	 * prog4's load type before it is ever touched below
+	 */
+	if (!ASSERT_EQ(bpf_program__load_type(skel->progs.prog4), BPF_PROG_LOAD_TYPE_DYNAMIC,
+		       "prog4_tag_load_type"))
+		goto cleanup;
+	if (!ASSERT_FALSE(bpf_program__autoattach(skel->progs.prog4), "prog4_autoattach"))
+		goto cleanup;
+
+	/* don't load prog1 */
+	bpf_program__set_load_type(skel->progs.prog1, BPF_PROG_LOAD_TYPE_DISABLED);
+
+	/* prog2 is autoload */
+	bpf_program__set_load_type(skel->progs.prog2, BPF_PROG_LOAD_TYPE_AUTO);
+
+	/* prog3 is dynamically loaded */
+	bpf_program__set_load_type(skel->progs.prog3, BPF_PROG_LOAD_TYPE_DYNAMIC);
+
+	err = test_dynamicload__load(skel);
+	if (!ASSERT_OK(err, "skel_load"))
+		goto cleanup;
+
+	err = test_dynamicload__attach(skel);
+	if (!ASSERT_OK(err, "skel_attach"))
+		goto cleanup;
+
+	/* trigger the BPF programs */
+	usleep(1);
+
+	ASSERT_FALSE(skel->bss->prog1_called, "prog1_called");
+	ASSERT_TRUE(skel->bss->prog2_called, "prog2_called");
+	ASSERT_FALSE(skel->bss->prog3_called, "prog3_called");
+	ASSERT_FALSE(skel->bss->prog4_called, "prog4_called");
+
+	/* prog1 is disabled for load */
+	err = bpf_program__load_dynamically(skel->progs.prog1, 0);
+	if (!ASSERT_ERR(err, "load_dynamically_disabled"))
+		goto cleanup;
+
+	/* prog1 is disabled for load */
+	err = bpf_program__unload_dynamically(skel->progs.prog1);
+	if (!ASSERT_ERR(err, "unload_dynamically_disabled"))
+		goto cleanup;
+
+	/* prog2 is autoload */
+	err = bpf_program__load_dynamically(skel->progs.prog2, 0);
+	if (!ASSERT_ERR(err, "load_dynamically_autoload"))
+		goto cleanup;
+
+	/* prog2 is autoload */
+	err = bpf_program__unload_dynamically(skel->progs.prog2);
+	if (!ASSERT_ERR(err, "unload_dynamically_autoload"))
+		goto cleanup;
+
+	/* reset the call flags */
+	skel->bss->prog2_called = false;
+	skel->bss->prog3_called = false;
+
+	usleep(1);
+
+	ASSERT_FALSE(skel->bss->prog1_called, "prog1_called");
+	ASSERT_TRUE(skel->bss->prog2_called, "prog2_called");
+	ASSERT_FALSE(skel->bss->prog3_called, "prog3_called");
+
+	/* load prog3 */
+	err = bpf_program__load_dynamically(skel->progs.prog3, 0);
+	if (!ASSERT_OK(err, "load_dynamically"))
+		goto cleanup;
+
+	/* attach prog3 */
+	link = bpf_program__attach(skel->progs.prog3);
+	if (!ASSERT_OK_PTR(link, "attach"))
+		goto cleanup;
+
+	usleep(1);
+
+	if (!ASSERT_TRUE(skel->bss->prog3_called, "prog3_called"))
+		goto cleanup;
+
+	/* detach prog3 as test_dynamicload__destroy doesn't detach dynamically loaded programs */
+	err = bpf_link__destroy(link);
+	if (!ASSERT_OK(err, "link_destroy"))
+		goto cleanup;
+
+	/* reset the call flags after detach */
+	skel->bss->prog2_called = false;
+	skel->bss->prog3_called = false;
+
+	usleep(1);
+
+	ASSERT_TRUE(skel->bss->prog2_called, "prog2_called");
+	ASSERT_FALSE(skel->bss->prog3_called, "prog3_called");
+
+	/* unload prog3 */
+	err = bpf_program__unload_dynamically(skel->progs.prog3);
+	if (!ASSERT_OK(err, "unload_dynamically"))
+		goto cleanup;
+
+	/* reload prog3 */
+	err = bpf_program__load_dynamically(skel->progs.prog3, 0);
+	if (!ASSERT_OK(err, "load_dynamically_reload"))
+		goto cleanup;
+
+	/* reattach prog3 */
+	link = bpf_program__attach(skel->progs.prog3);
+	if (!ASSERT_OK_PTR(link, "reattach"))
+		goto cleanup;
+
+	usleep(1);
+
+	if (!ASSERT_TRUE(skel->bss->prog3_called, "prog3_called_reattach"))
+		goto cleanup;
+
+	/* detach prog3 as test_dynamicload__destroy doesn't detach dynamically loaded programs */
+	err = bpf_link__destroy(link);
+	if (!ASSERT_OK(err, "link_destroy_reattach"))
+		goto cleanup;
+
+	/* verify regular unload for dynamically loaded program,
+	 * unload prog3 as a regular program
+	 */
+	bpf_program__unload(skel->progs.prog3);
+
+	/* reset the call flags after unload */
+	skel->bss->prog2_called = false;
+	skel->bss->prog3_called = false;
+
+	usleep(1);
+
+	ASSERT_TRUE(skel->bss->prog2_called, "prog2_called");
+	ASSERT_FALSE(skel->bss->prog3_called, "prog3_called");
+
+	/* reloading prog3 must fail as it was unloaded as a regular program */
+	err = bpf_program__load_dynamically(skel->progs.prog3, 0);
+	ASSERT_ERR(err, "load_dynamically_after_regular_unload");
+
+	/* run prog4 (declaratively tagged) through the same dynamic
+	 * load/attach/trigger/detach/unload cycle as prog3
+	 */
+	err = bpf_program__load_dynamically(skel->progs.prog4, 0);
+	if (!ASSERT_OK(err, "prog4_load_dynamically"))
+		goto cleanup;
+
+	link = bpf_program__attach(skel->progs.prog4);
+	if (!ASSERT_OK_PTR(link, "prog4_attach"))
+		goto cleanup;
+
+	usleep(1);
+
+	if (!ASSERT_TRUE(skel->bss->prog4_called, "prog4_called"))
+		goto cleanup;
+
+	err = bpf_link__destroy(link);
+	if (!ASSERT_OK(err, "prog4_link_destroy"))
+		goto cleanup;
+
+	err = bpf_program__unload_dynamically(skel->progs.prog4);
+	ASSERT_OK(err, "prog4_unload_dynamically");
+
+	test_dynamicload__destroy(skel);
+
+	/* separate scenario: imperative override of the declarative tag */
+	dynamicload_verify_override();
+	return;
+
+cleanup:
+	test_dynamicload__destroy(skel);
+}
+
diff --git a/tools/testing/selftests/bpf/prog_tests/load_type.c b/tools/testing/selftests/bpf/prog_tests/load_type.c
new file mode 100644
index 0000000000000..fc91f6666c506
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/load_type.c
@@ -0,0 +1,167 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <test_progs.h>
+#include <time.h>
+#include "test_load_type.skel.h"
+
+void test_load_type(void)
+{
+	struct bpf_link *link;
+	struct test_load_type *skel;
+	int err;
+
+	skel = test_load_type__open();
+	if (!ASSERT_OK_PTR(skel, "skel_open"))
+		return;
+
+	/* don't load prog1 */
+	bpf_program__set_load_type(skel->progs.prog1, BPF_PROG_LOAD_TYPE_DISABLED);
+
+	/* load and attach prog2 */
+	bpf_program__set_load_type(skel->progs.prog2, BPF_PROG_LOAD_TYPE_AUTO);
+	if (!ASSERT_TRUE(bpf_program__autoload(skel->progs.prog2), "prog2_autoload"))
+		goto cleanup;
+
+	err = bpf_program__set_load_type(skel->progs.prog3, BPF_PROG_LOAD_TYPE_DYNAMIC);
+	if (!ASSERT_OK(err, "set_load_type_dynamic"))
+		goto cleanup;
+	if (!ASSERT_EQ(bpf_program__load_type(skel->progs.prog3), BPF_PROG_LOAD_TYPE_DYNAMIC,
+		       "prog3_load_type"))
+		goto cleanup;
+
+	/* bpf_program__set_autoload() is a thin forwarder to set_load_type(),
+	 * restricted to AUTO/DISABLED to preserve its original bool on/off
+	 * meaning; it does change the load type of a program that isn't
+	 * currently BPF_PROG_LOAD_TYPE_AUTO.
+	 */
+	err = bpf_program__set_autoload(skel->progs.prog3, false);
+	if (!ASSERT_OK(err, "set_autoload_false"))
+		goto cleanup;
+
+	if (!ASSERT_EQ(bpf_program__load_type(skel->progs.prog3), BPF_PROG_LOAD_TYPE_DISABLED,
+		       "prog3_load_type_after_false"))
+		goto cleanup;
+
+	err = bpf_program__set_autoload(skel->progs.prog3, true);
+	if (!ASSERT_OK(err, "set_autoload_true"))
+		goto cleanup;
+
+	if (!ASSERT_EQ(bpf_program__load_type(skel->progs.prog3), BPF_PROG_LOAD_TYPE_AUTO,
+		       "prog3_load_type_after_true"))
+		goto cleanup;
+
+	/* set_autoload() only accepts AUTO/DISABLED, to preserve its original
+	 * on/off meaning; DYNAMIC must go through set_load_type()
+	 */
+	err = bpf_program__set_autoload(skel->progs.prog3, BPF_PROG_LOAD_TYPE_DYNAMIC);
+	if (!ASSERT_ERR(err, "set_autoload_dynamic_rejected"))
+		goto cleanup;
+
+	if (!ASSERT_EQ(bpf_program__load_type(skel->progs.prog3), BPF_PROG_LOAD_TYPE_AUTO,
+		       "prog3_load_type_unchanged_after_rejected_autoload"))
+		goto cleanup;
+
+	err = bpf_program__set_load_type(skel->progs.prog3, BPF_PROG_LOAD_TYPE_DYNAMIC);
+	if (!ASSERT_OK(err, "set_load_type_dynamic_enum"))
+		goto cleanup;
+
+	if (!ASSERT_EQ(bpf_program__load_type(skel->progs.prog3), BPF_PROG_LOAD_TYPE_DYNAMIC,
+		       "prog3_load_type_after_dynamic_enum"))
+		goto cleanup;
+
+	/* leaving DYNAMIC for AUTO must restore autoattach (regression test for
+	 * the autoattach residue bug: set_dynamicload() clears autoattach, and
+	 * nothing used to restore it on exit)
+	 */
+	err = bpf_program__set_load_type(skel->progs.prog3, BPF_PROG_LOAD_TYPE_AUTO);
+	if (!ASSERT_OK(err, "set_load_type_auto"))
+		goto cleanup;
+
+	if (!ASSERT_EQ(bpf_program__load_type(skel->progs.prog3), BPF_PROG_LOAD_TYPE_AUTO,
+		       "prog3_load_type_auto"))
+		goto cleanup;
+
+	if (!ASSERT_TRUE(bpf_program__autoattach(skel->progs.prog3), "prog3_autoattach_restored"))
+		goto cleanup;
+
+	/* the same residue can relay through DISABLED and resurface on a later
+	 * DISABLED -> AUTO transition, so the fix must cover both exit edges
+	 */
+	err = bpf_program__set_load_type(skel->progs.prog3, BPF_PROG_LOAD_TYPE_DYNAMIC);
+	if (!ASSERT_OK(err, "set_load_type_dynamic_again"))
+		goto cleanup;
+
+	err = bpf_program__set_load_type(skel->progs.prog3, BPF_PROG_LOAD_TYPE_DISABLED);
+	if (!ASSERT_OK(err, "set_load_type_disabled"))
+		goto cleanup;
+
+	err = bpf_program__set_load_type(skel->progs.prog3, BPF_PROG_LOAD_TYPE_AUTO);
+	if (!ASSERT_OK(err, "set_load_type_auto_via_disabled"))
+		goto cleanup;
+
+	if (!ASSERT_TRUE(bpf_program__autoattach(skel->progs.prog3),
+			 "prog3_autoattach_restored_via_disabled"))
+		goto cleanup;
+
+	/* an out-of-range load type is rejected */
+	err = bpf_program__set_load_type(skel->progs.prog3, (enum bpf_prog_load_type)999);
+	if (!ASSERT_ERR(err, "set_load_type_invalid"))
+		goto cleanup;
+
+	/* change the type back to BPF_PROG_LOAD_TYPE_DYNAMIC for the rest of the test */
+	err = bpf_program__set_load_type(skel->progs.prog3, BPF_PROG_LOAD_TYPE_DYNAMIC);
+	if (!ASSERT_OK(err, "set_load_type_dynamic_final"))
+		goto cleanup;
+
+	if (!ASSERT_EQ(bpf_program__load_type(skel->progs.prog3), BPF_PROG_LOAD_TYPE_DYNAMIC,
+		       "prog3_load_type_final"))
+		goto cleanup;
+
+	err = test_load_type__load(skel);
+	if (!ASSERT_OK(err, "skel_load"))
+		goto cleanup;
+
+	if (!ASSERT_TRUE(bpf_program__autoattach(skel->progs.prog2), "prog2_autoattach"))
+		goto cleanup;
+	if (!ASSERT_FALSE(bpf_program__autoattach(skel->progs.prog3), "prog3_autoattach"))
+		goto cleanup;
+
+	/* loaded program type cannot be changed */
+	err = bpf_program__set_load_type(skel->progs.prog3, BPF_PROG_LOAD_TYPE_DISABLED);
+	ASSERT_ERR(err, "set_load_type_after_load");
+
+	err = test_load_type__attach(skel);
+	if (!ASSERT_OK(err, "skel_attach"))
+		goto cleanup;
+
+	usleep(1);
+
+	ASSERT_FALSE(skel->bss->prog1_called, "prog1_called");
+	ASSERT_TRUE(skel->bss->prog2_called, "prog2_called");
+	ASSERT_FALSE(skel->bss->prog3_called, "prog3_called");
+
+	err = bpf_program__load_dynamically(skel->progs.prog3, 0);
+	if (!ASSERT_OK(err, "load_dynamically_1"))
+		goto cleanup;
+
+	err = bpf_program__load_dynamically(skel->progs.prog3, 0);
+	if (!ASSERT_OK(err, "load_dynamically_2"))
+		goto cleanup;
+
+	/* attach prog3 */
+	link = bpf_program__attach(skel->progs.prog3);
+	if (!ASSERT_OK_PTR(link, "attach"))
+		goto cleanup;
+
+	usleep(1);
+
+	if (!ASSERT_TRUE(skel->bss->prog3_called, "prog3_called_again"))
+		goto cleanup;
+
+	/* detach prog3 as test_load_type__destroy doesn't detach dynamically loaded programs */
+	err = bpf_link__destroy(link);
+	ASSERT_OK(err, "link_destroy");
+
+cleanup:
+	test_load_type__destroy(skel);
+}
diff --git a/tools/testing/selftests/bpf/progs/test_dynamicload.c b/tools/testing/selftests/bpf/progs/test_dynamicload.c
new file mode 100644
index 0000000000000..6f5a5cb898031
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/test_dynamicload.c
@@ -0,0 +1,40 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include "vmlinux.h"
+#include <bpf/bpf_helpers.h>
+
+bool prog1_called = false;
+bool prog2_called = false;
+bool prog3_called = false;
+bool prog4_called = false;
+
+SEC("raw_tp/sys_enter")
+int prog1(const void *ctx)
+{
+	prog1_called = true;
+	return 0;
+}
+
+SEC("raw_tp/sys_enter")
+int prog2(const void *ctx)
+{
+	prog2_called = true;
+	return 0;
+}
+
+SEC("raw_tp/sys_enter")
+int prog3(const void *ctx)
+{
+	prog3_called = true;
+	return 0;
+}
+
+SEC("raw_tp/sys_enter")
+__load_dynamic
+int prog4(const void *ctx)
+{
+	prog4_called = true;
+	return 0;
+}
+
+char _license[] SEC("license") = "GPL";
diff --git a/tools/testing/selftests/bpf/progs/test_load_type.c b/tools/testing/selftests/bpf/progs/test_load_type.c
new file mode 100644
index 0000000000000..3d9b81691d7ad
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/test_load_type.c
@@ -0,0 +1,31 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include "vmlinux.h"
+#include <bpf/bpf_helpers.h>
+
+bool prog1_called = false;
+bool prog2_called = false;
+bool prog3_called = false;
+
+SEC("raw_tp/sys_enter")
+int prog1(const void *ctx)
+{
+	prog1_called = true;
+	return 0;
+}
+
+SEC("raw_tp/sys_enter")
+int prog2(const void *ctx)
+{
+	prog2_called = true;
+	return 0;
+}
+
+SEC("raw_tp/sys_enter")
+int prog3(const void *ctx)
+{
+	prog3_called = true;
+	return 0;
+}
+
+char _license[] SEC("license") = "GPL";

3/2 2026/08/26 19:21 llm patch-evaluator
0m Model:
gemini-3.1-pro-preview

Args:
null

Results:
null

Tokens:
							input: 14719
							output: 73
							thoughts: 910
						

Thoughts:
**Patch Evaluation: Not Worth Fuzzing**

Okay, let's break this down. We have a patch series to evaluate. My immediate focus is whether this impacts the kernel code that syzkaller would target for fuzzing. The patch touches several files: `tools/lib/bpf/libbpf.c`, `tools/lib/bpf/bpf_helpers.h`, `tools/lib/bpf/libbpf.h`, and related map and test files within `tools/testing/selftests/bpf/`. My gut reaction is that this *should* be a no-go for fuzzing, since it's all in the `tools/` directory – and specifically the libbpf user-space library.

The prompt explicitly states what constitutes changes that *wouldn't* warrant fuzzing, and this seems to align. It's user-space code; syzkaller's primary focus is the kernel, specifically targeting syscall interfaces. I need to make sure this user-space code isn't somehow influencing kernel execution directly (beyond normal syscall-based interaction), but I don't see anything inherently that would.

My thought process is this: does this change potentially *expose* new kernel bugs via an updated library or syscall, or does the changed library do something that's only indirectly related to the kernel, or something that is normally excluded? No, from this analysis, it is all `tools/`. Libbpf *uses* syscalls, sure, but the patch itself is just modifying the user-space side. My conclusion is that even if the new code could cause kernel issues, it will not directly affect the kernel for fuzzing.

Let me double-check the diff paths, just to be absolutely certain. Okay, double-checked. Nothing is outside of `tools/`. That's it, then.

So, I'm confident in saying `WorthFuzzing=false`. The patch is solely within the user-space libbpf library and related tests. It doesn't modify any kernel logic, drivers, or architectures that syzkaller would directly fuzz.



4/2 2026/08/26 19:21 tool set-results
0m Args:
{
  "EnableConfigs": [],
  "FocusSymbols": [],
  "Reasoning": "The patch only modifies the user-space libbpf library and adds selftests in the tools/ directory. It does not make any functional changes to the kernel code itself that can be fuzzed.",
  "WorthFuzzing": false
}

Results:
{
  "EnableConfigs": null,
  "FocusSymbols": [],
  "Reasoning": "The patch only modifies the user-space libbpf library and adds selftests in the tools/ directory. It does not make any functional changes to the kernel code itself that can be fuzzed.",
  "WorthFuzzing": false
}

5/1 2026/08/26 19:21 action If
0m Args:
{
  "WorthFuzzing": false
}

Results:
null

LLM Calls Summary:
Total Calls Total Tokens Avg Tokens Total Duration (Seconds) Avg Duration (Seconds)
Tool Calls Summary:
Total Calls Total Duration (Seconds) Avg Duration (Seconds)