History

bpf: Support doubleword alignment in bpf_jit_binary_alloc

Currently passing alignment greater than 4 to bpf_jit_binary_alloc does not work: in such cases it silently aligns only to 4 bytes. On s390, in order to load a constant from memory in a large (>512k) BPF program, one must use lgrl instruction, whose memory operand must be aligned on an 8-byte boundary. This patch makes it possible to request 8-byte alignment from bpf_jit_binary_alloc, and also makes it issue a warning when an unsupported alignment is requested.

Ilya Leoshkevich committed 7 years ago

Commit b7b3fc81 parent e47a1792 files · +8 −2Browse files

Unified · Split

2 files
  1. include/linux/filter.h +4 −2
  2. kernel/bpf/core.c +4 −0
include/linux/filter.h+4−2
@@ -515,10 +515,12 @@ struct sock_fprog_kern { · 514 unmodified lines
515 struct sock_filter *filter;515 struct sock_filter *filter;
516};516};
517 517
518/* Some arches need doubleword alignment for their instructions and/or data */
519#define BPF_IMAGE_ALIGNMENT 8
520
518struct bpf_binary_header {521struct bpf_binary_header {
519 u32 pages;522 u32 pages;
520 /* Some arches need word alignment for their instructions */523 u8 image[] __aligned(BPF_IMAGE_ALIGNMENT);
521 u8 image[] __aligned(4);
522};524};
523 525
524struct bpf_prog {526struct bpf_prog {
kernel/bpf/core.c+4−0
@@ -31,6 +31,7 @@ · 30 unmodified lines
31#include <linux/rcupdate.h>31#include <linux/rcupdate.h>
32#include <linux/perf_event.h>32#include <linux/perf_event.h>
33#include <linux/extable.h>33#include <linux/extable.h>
34#include <linux/log2.h>
34#include <asm/unaligned.h>35#include <asm/unaligned.h>
35 36
36/* Registers */37/* Registers */
@@ -815,6 +816,9 @@ bpf_jit_binary_alloc(unsigned int proglen, u8 **image_ptr, · 778 unmodified lines
815 struct bpf_binary_header *hdr;816 struct bpf_binary_header *hdr;
816 u32 size, hole, start, pages;817 u32 size, hole, start, pages;
817 818
819 WARN_ON_ONCE(!is_power_of_2(alignment) ||
820 alignment > BPF_IMAGE_ALIGNMENT);
821
818 /* Most of BPF filters are really small, but if some of them822 /* Most of BPF filters are really small, but if some of them
819 * fill a page, allow at least 128 extra bytes to insert a823 * fill a page, allow at least 128 extra bytes to insert a
820 * random section of illegal instructions.824 * random section of illegal instructions.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t