From: Jiong Wang <jiong.wang@netronome.com>
To: ast@kernel.org, daniel@iogearbox.net
Cc: netdev@vger.kernel.org, oss-drivers@netronome.com,
Jiong Wang <jiong.wang@netronome.com>
Subject: [PATCH bpf-next v2 07/16] bpf: JIT blinds support JMP32
Date: Mon, 21 Jan 2019 08:15:44 -0500 [thread overview]
Message-ID: <1548076553-31268-8-git-send-email-jiong.wang@netronome.com> (raw)
In-Reply-To: <1548076553-31268-1-git-send-email-jiong.wang@netronome.com>
This patch adds JIT blinds support for JMP32.
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Jiong Wang <jiong.wang@netronome.com>
---
include/linux/filter.h | 20 ++++++++++++++++++++
kernel/bpf/core.c | 21 +++++++++++++++++++++
2 files changed, 41 insertions(+)
diff --git a/include/linux/filter.h b/include/linux/filter.h
index ad106d8..248dbc5 100644
--- a/include/linux/filter.h
+++ b/include/linux/filter.h
@@ -277,6 +277,26 @@ struct sock_reuseport;
.off = OFF, \
.imm = IMM })
+/* Like BPF_JMP_REG, but with 32-bit wide operands for comparison. */
+
+#define BPF_JMP32_REG(OP, DST, SRC, OFF) \
+ ((struct bpf_insn) { \
+ .code = BPF_JMP32 | BPF_OP(OP) | BPF_X, \
+ .dst_reg = DST, \
+ .src_reg = SRC, \
+ .off = OFF, \
+ .imm = 0 })
+
+/* Like BPF_JMP_IMM, but with 32-bit wide operands for comparison. */
+
+#define BPF_JMP32_IMM(OP, DST, IMM, OFF) \
+ ((struct bpf_insn) { \
+ .code = BPF_JMP32 | BPF_OP(OP) | BPF_K, \
+ .dst_reg = DST, \
+ .src_reg = 0, \
+ .off = OFF, \
+ .imm = IMM })
+
/* Unconditional jumps, goto pc + off16 */
#define BPF_JMP_A(OFF) \
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 199612e..84a8b25 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -935,6 +935,27 @@ static int bpf_jit_blind_insn(const struct bpf_insn *from,
*to++ = BPF_JMP_REG(from->code, from->dst_reg, BPF_REG_AX, off);
break;
+ case BPF_JMP32 | BPF_JEQ | BPF_K:
+ case BPF_JMP32 | BPF_JNE | BPF_K:
+ case BPF_JMP32 | BPF_JGT | BPF_K:
+ case BPF_JMP32 | BPF_JLT | BPF_K:
+ case BPF_JMP32 | BPF_JGE | BPF_K:
+ case BPF_JMP32 | BPF_JLE | BPF_K:
+ case BPF_JMP32 | BPF_JSGT | BPF_K:
+ case BPF_JMP32 | BPF_JSLT | BPF_K:
+ case BPF_JMP32 | BPF_JSGE | BPF_K:
+ case BPF_JMP32 | BPF_JSLE | BPF_K:
+ case BPF_JMP32 | BPF_JSET | BPF_K:
+ /* Accommodate for extra offset in case of a backjump. */
+ off = from->off;
+ if (off < 0)
+ off -= 2;
+ *to++ = BPF_ALU32_IMM(BPF_MOV, BPF_REG_AX, imm_rnd ^ from->imm);
+ *to++ = BPF_ALU32_IMM(BPF_XOR, BPF_REG_AX, imm_rnd);
+ *to++ = BPF_JMP32_REG(from->code, from->dst_reg, BPF_REG_AX,
+ off);
+ break;
+
case BPF_LD | BPF_IMM | BPF_DW:
*to++ = BPF_ALU64_IMM(BPF_MOV, BPF_REG_AX, imm_rnd ^ aux[1].imm);
*to++ = BPF_ALU64_IMM(BPF_XOR, BPF_REG_AX, imm_rnd);
--
2.7.4
next prev parent reply other threads:[~2019-01-21 13:16 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-21 13:15 [PATCH bpf-next v2 00/16] bpf: propose new jmp32 instructions Jiong Wang
2019-01-21 13:15 ` [PATCH bpf-next v2 01/16] bpf: allocate 0x06 to new eBPF instruction class JMP32 Jiong Wang
2019-01-21 13:15 ` [PATCH bpf-next v2 02/16] bpf: refactor verifier min/max code for condition jump Jiong Wang
2019-01-21 13:15 ` [PATCH bpf-next v2 03/16] bpf: verifier support JMP32 Jiong Wang
2019-01-21 13:15 ` [PATCH bpf-next v2 04/16] bpf: disassembler " Jiong Wang
2019-01-21 13:15 ` [PATCH bpf-next v2 05/16] tools: bpftool: teach cfg code about JMP32 Jiong Wang
2019-01-21 13:15 ` [PATCH bpf-next v2 06/16] bpf: interpreter support for JMP32 Jiong Wang
2019-01-21 13:15 ` Jiong Wang [this message]
2019-01-21 13:15 ` [PATCH bpf-next v2 08/16] bpf: functional and min/max reasoning unit tests " Jiong Wang
2019-01-23 14:29 ` Jiong Wang
2019-01-21 13:15 ` [PATCH bpf-next v2 09/16] x86_64: bpf: implement jitting of JMP32 Jiong Wang
2019-01-21 13:15 ` [PATCH bpf-next v2 10/16] x32: " Jiong Wang
2019-01-21 13:15 ` [PATCH bpf-next v2 11/16] arm64: " Jiong Wang
2019-01-21 13:15 ` [PATCH bpf-next v2 12/16] arm: " Jiong Wang
2019-01-21 13:15 ` [PATCH bpf-next v2 13/16] ppc: " Jiong Wang
2019-01-24 4:58 ` Sandipan Das
2019-01-24 9:53 ` Jiong Wang
2019-01-21 13:15 ` [PATCH bpf-next v2 14/16] s390: " Jiong Wang
2019-01-21 13:15 ` [PATCH bpf-next v2 15/16] nfp: " Jiong Wang
2019-01-21 13:15 ` [PATCH bpf-next v2 16/16] selftests: bpf: makefile support sub-register code-gen test mode Jiong Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1548076553-31268-8-git-send-email-jiong.wang@netronome.com \
--to=jiong.wang@netronome.com \
--cc=ast@kernel.org \
--cc=daniel@iogearbox.net \
--cc=netdev@vger.kernel.org \
--cc=oss-drivers@netronome.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).