mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-09 21:59:12 -04:00
BACKPORT: 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. Change-Id: Iee3d04012d22d54adb739c627fc7b9c31262dbc7 Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Link: https://lore.kernel.org/bpf/20191115123722.58462-1-iii@linux.ibm.com
This commit is contained in:
parent
626fc04169
commit
6839e235e4
2 changed files with 8 additions and 2 deletions
|
|
@ -535,13 +535,15 @@ struct sock_fprog_kern {
|
|||
|
||||
#define BPF_BINARY_HEADER_MAGIC 0x05de0e82
|
||||
|
||||
/* Some arches need doubleword alignment for their instructions and/or data */
|
||||
#define BPF_IMAGE_ALIGNMENT 8
|
||||
|
||||
struct bpf_binary_header {
|
||||
#ifdef CONFIG_CFI_CLANG
|
||||
u32 magic;
|
||||
#endif
|
||||
u32 pages;
|
||||
/* Some arches need word alignment for their instructions */
|
||||
u8 image[] __aligned(4);
|
||||
u8 image[] __aligned(BPF_IMAGE_ALIGNMENT);
|
||||
};
|
||||
|
||||
struct bpf_prog {
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@
|
|||
#include <linux/rcupdate.h>
|
||||
#include <linux/perf_event.h>
|
||||
#include <linux/extable.h>
|
||||
#include <linux/log2.h>
|
||||
#include <linux/nospec.h>
|
||||
|
||||
#include <asm/barrier.h>
|
||||
|
|
@ -834,6 +835,9 @@ bpf_jit_binary_alloc(unsigned int proglen, u8 **image_ptr,
|
|||
struct bpf_binary_header *hdr;
|
||||
u32 size, hole, start, pages;
|
||||
|
||||
WARN_ON_ONCE(!is_power_of_2(alignment) ||
|
||||
alignment > BPF_IMAGE_ALIGNMENT);
|
||||
|
||||
/* Most of BPF filters are really small, but if some of them
|
||||
* fill a page, allow at least 128 extra bytes to insert a
|
||||
* random section of illegal instructions.
|
||||
|
|
|
|||
Loading…
Reference in a new issue