* [PATCH bpf-next v2] bpf: support doubleword alignment in bpf_jit_binary_alloc
@ 2019-11-15 12:37 Ilya Leoshkevich
2019-11-15 22:29 ` Daniel Borkmann
0 siblings, 1 reply; 2+ messages in thread
From: Ilya Leoshkevich @ 2019-11-15 12:37 UTC (permalink / raw)
To: Daniel Borkmann, Alexei Starovoitov
Cc: bpf, Heiko Carstens, Vasily Gorbik, Ilya Leoshkevich
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.
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
v1 -> v2: Simply bump alignment to 8, don't try to be too generic.
include/linux/filter.h | 6 ++++--
kernel/bpf/core.c | 4 ++++
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/include/linux/filter.h b/include/linux/filter.h
index 7a6f8f6f1da4..ad80e9c6111c 100644
--- a/include/linux/filter.h
+++ b/include/linux/filter.h
@@ -515,10 +515,12 @@ struct sock_fprog_kern {
struct sock_filter *filter;
};
+/* Some arches need doubleword alignment for their instructions and/or data */
+#define BPF_IMAGE_ALIGNMENT 8
+
struct bpf_binary_header {
u32 pages;
- /* Some arches need word alignment for their instructions */
- u8 image[] __aligned(4);
+ u8 image[] __aligned(BPF_IMAGE_ALIGNMENT);
};
struct bpf_prog {
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index c1fde0303280..99693f3c4e99 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -31,6 +31,7 @@
#include <linux/rcupdate.h>
#include <linux/perf_event.h>
#include <linux/extable.h>
+#include <linux/log2.h>
#include <asm/unaligned.h>
/* Registers */
@@ -815,6 +816,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.
--
2.23.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH bpf-next v2] bpf: support doubleword alignment in bpf_jit_binary_alloc
2019-11-15 12:37 [PATCH bpf-next v2] bpf: support doubleword alignment in bpf_jit_binary_alloc Ilya Leoshkevich
@ 2019-11-15 22:29 ` Daniel Borkmann
0 siblings, 0 replies; 2+ messages in thread
From: Daniel Borkmann @ 2019-11-15 22:29 UTC (permalink / raw)
To: Ilya Leoshkevich, Alexei Starovoitov; +Cc: bpf, Heiko Carstens, Vasily Gorbik
On 11/15/19 1:37 PM, Ilya Leoshkevich wrote:
> 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.
>
> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Applied, thanks!
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-11-15 22:29 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-11-15 12:37 [PATCH bpf-next v2] bpf: support doubleword alignment in bpf_jit_binary_alloc Ilya Leoshkevich
2019-11-15 22:29 ` Daniel Borkmann
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.