Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ebpf: migrate bpf_prog's flags to bitfield

As we need to add further flags to the bpf_prog structure, lets migrate
both bools to a bitfield representation. The size of the base structure
(excluding insns) remains unchanged at 40 bytes.

Add also tags for the kmemchecker, so that it doesn't throw false
positives. Even in case gcc would generate suboptimal code, it's not
being accessed in performance critical paths.

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Alexei Starovoitov <ast@plumgrid.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Daniel Borkmann and committed by
David S. Miller
a91263d5 bd8762be

+18 -12
+1 -1
arch/arm/net/bpf_jit_32.c
··· 1047 1047 1048 1048 set_memory_ro((unsigned long)header, header->pages); 1049 1049 fp->bpf_func = (void *)ctx.target; 1050 - fp->jited = true; 1050 + fp->jited = 1; 1051 1051 out: 1052 1052 kfree(ctx.offsets); 1053 1053 return;
+1 -1
arch/arm64/net/bpf_jit_comp.c
··· 744 744 745 745 set_memory_ro((unsigned long)header, header->pages); 746 746 prog->bpf_func = (void *)ctx.image; 747 - prog->jited = true; 747 + prog->jited = 1; 748 748 out: 749 749 kfree(ctx.offset); 750 750 }
+1 -1
arch/mips/net/bpf_jit.c
··· 1251 1251 bpf_jit_dump(fp->len, alloc_size, 2, ctx.target); 1252 1252 1253 1253 fp->bpf_func = (void *)ctx.target; 1254 - fp->jited = true; 1254 + fp->jited = 1; 1255 1255 1256 1256 out: 1257 1257 kfree(ctx.offsets);
+1 -1
arch/powerpc/net/bpf_jit_comp.c
··· 679 679 ((u64 *)image)[1] = local_paca->kernel_toc; 680 680 #endif 681 681 fp->bpf_func = (void *)image; 682 - fp->jited = true; 682 + fp->jited = 1; 683 683 } 684 684 out: 685 685 kfree(addrs);
+1 -1
arch/s390/net/bpf_jit_comp.c
··· 1310 1310 if (jit.prg_buf) { 1311 1311 set_memory_ro((unsigned long)header, header->pages); 1312 1312 fp->bpf_func = (void *) jit.prg_buf; 1313 - fp->jited = true; 1313 + fp->jited = 1; 1314 1314 } 1315 1315 free_addrs: 1316 1316 kfree(jit.addrs);
+1 -1
arch/sparc/net/bpf_jit_comp.c
··· 812 812 if (image) { 813 813 bpf_flush_icache(image, image + proglen); 814 814 fp->bpf_func = (void *)image; 815 - fp->jited = true; 815 + fp->jited = 1; 816 816 } 817 817 out: 818 818 kfree(addrs);
+1 -1
arch/x86/net/bpf_jit_comp.c
··· 1109 1109 bpf_flush_icache(header, image + proglen); 1110 1110 set_memory_ro((unsigned long)header, header->pages); 1111 1111 prog->bpf_func = (void *)image; 1112 - prog->jited = true; 1112 + prog->jited = 1; 1113 1113 } 1114 1114 out: 1115 1115 kfree(addrs);
+4 -2
include/linux/filter.h
··· 326 326 327 327 struct bpf_prog { 328 328 u16 pages; /* Number of allocated pages */ 329 - bool jited; /* Is our filter JIT'ed? */ 330 - bool gpl_compatible; /* Is our filter GPL compatible? */ 329 + kmemcheck_bitfield_begin(meta); 330 + u16 jited:1, /* Is our filter JIT'ed? */ 331 + gpl_compatible:1; /* Is filter GPL compatible? */ 332 + kmemcheck_bitfield_end(meta); 331 333 u32 len; /* Number of filter blocks */ 332 334 enum bpf_prog_type type; /* Type of BPF program */ 333 335 struct bpf_prog_aux *aux; /* Auxiliary fields */
+4
kernel/bpf/core.c
··· 82 82 if (fp == NULL) 83 83 return NULL; 84 84 85 + kmemcheck_annotate_bitfield(fp, meta); 86 + 85 87 aux = kzalloc(sizeof(*aux), GFP_KERNEL | gfp_extra_flags); 86 88 if (aux == NULL) { 87 89 vfree(fp); ··· 112 110 113 111 fp = __vmalloc(size, gfp_flags, PAGE_KERNEL); 114 112 if (fp != NULL) { 113 + kmemcheck_annotate_bitfield(fp, meta); 114 + 115 115 memcpy(fp, fp_old, fp_old->pages * PAGE_SIZE); 116 116 fp->pages = size / PAGE_SIZE; 117 117
+2 -2
kernel/bpf/syscall.c
··· 553 553 goto free_prog; 554 554 555 555 prog->orig_prog = NULL; 556 - prog->jited = false; 556 + prog->jited = 0; 557 557 558 558 atomic_set(&prog->aux->refcnt, 1); 559 - prog->gpl_compatible = is_gpl; 559 + prog->gpl_compatible = is_gpl ? 1 : 0; 560 560 561 561 /* find program type: socket_filter vs tracing_filter */ 562 562 err = find_prog_type(type, prog);
+1 -1
net/core/filter.c
··· 1001 1001 int err; 1002 1002 1003 1003 fp->bpf_func = NULL; 1004 - fp->jited = false; 1004 + fp->jited = 0; 1005 1005 1006 1006 err = bpf_check_classic(fp->insns, fp->len); 1007 1007 if (err) {