On 10/18/23 8:03 PM, Song Liu wrote:
[...]
@@ -1040,6 +1038,38 @@ arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *image, void *image
return -ENOTSUPP;
}
+void * __weak arch_alloc_bpf_trampoline(int size)
+{
+ void *image;
+
+ WARN_ON_ONCE(size > PAGE_SIZE || size <= 0);
non-blocking / can be follow-up, but why not:
if (WARN_ON_ONCE(size > PAGE_SIZE || size <= 0))
return NULL
size could also be u32, then you don't need size <= 0 check ?
+ image = bpf_jit_alloc_exec(PAGE_SIZE);
+ if (image)
+ set_vm_flush_reset_perms(image);
+ return image;
+}
+
+void __weak arch_free_bpf_trampoline(void *image, int size)
+{
+ /* bpf_jit_free_exec doesn't need "size", but
+ * bpf_prog_pack_free() needs it.
+ */
+ bpf_jit_free_exec(image);
+}
+
+void __weak arch_protect_bpf_trampoline(void *image, int size)
+{
+ WARN_ON_ONCE(size > PAGE_SIZE || size <= 0);
+ set_memory_rox((long)image, 1);
+}
+
+void __weak arch_unprotect_bpf_trampoline(void *image, int size)
+{
+ WARN_ON_ONCE(size > PAGE_SIZE || size <= 0);
+ set_memory_nx((long)image, 1);
+ set_memory_rw((long)image, 1);
+}
+
static int __init init_trampolines(void)
{
int i;