* [PATCH 0/2] powerpc/bpf: DIV64 instruction fix
@ 2019-06-12 18:51 Naveen N. Rao
2019-06-12 18:51 ` [PATCH 1/2] bpf: fix div64 overflow tests to properly detect errors Naveen N. Rao
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Naveen N. Rao @ 2019-06-12 18:51 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann; +Cc: bpf, netdev, linuxppc-dev
The first patch updates DIV64 overflow tests to properly detect error
conditions. The second patch fixes powerpc64 JIT to generate the proper
unsigned division instruction for BPF_ALU64.
- Naveen
Naveen N. Rao (2):
bpf: fix div64 overflow tests to properly detect errors
powerpc/bpf: use unsigned division instruction for 64-bit operations
arch/powerpc/include/asm/ppc-opcode.h | 1 +
arch/powerpc/net/bpf_jit.h | 2 +-
arch/powerpc/net/bpf_jit_comp64.c | 8 ++++----
.../testing/selftests/bpf/verifier/div_overflow.c | 14 ++++++++++----
4 files changed, 16 insertions(+), 9 deletions(-)
--
2.21.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] bpf: fix div64 overflow tests to properly detect errors
2019-06-12 18:51 [PATCH 0/2] powerpc/bpf: DIV64 instruction fix Naveen N. Rao
@ 2019-06-12 18:51 ` Naveen N. Rao
2019-06-12 18:51 ` [PATCH 2/2] powerpc/bpf: use unsigned division instruction for 64-bit operations Naveen N. Rao
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Naveen N. Rao @ 2019-06-12 18:51 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann; +Cc: bpf, netdev, linuxppc-dev
If the result of the division is LLONG_MIN, current tests do not detect
the error since the return value is truncated to a 32-bit value and ends
up being 0.
Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
---
.../testing/selftests/bpf/verifier/div_overflow.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/tools/testing/selftests/bpf/verifier/div_overflow.c b/tools/testing/selftests/bpf/verifier/div_overflow.c
index bd3f38dbe796..acab4f00819f 100644
--- a/tools/testing/selftests/bpf/verifier/div_overflow.c
+++ b/tools/testing/selftests/bpf/verifier/div_overflow.c
@@ -29,8 +29,11 @@
"DIV64 overflow, check 1",
.insns = {
BPF_MOV64_IMM(BPF_REG_1, -1),
- BPF_LD_IMM64(BPF_REG_0, LLONG_MIN),
- BPF_ALU64_REG(BPF_DIV, BPF_REG_0, BPF_REG_1),
+ BPF_LD_IMM64(BPF_REG_2, LLONG_MIN),
+ BPF_ALU64_REG(BPF_DIV, BPF_REG_2, BPF_REG_1),
+ BPF_MOV32_IMM(BPF_REG_0, 0),
+ BPF_JMP_REG(BPF_JEQ, BPF_REG_0, BPF_REG_2, 1),
+ BPF_MOV32_IMM(BPF_REG_0, 1),
BPF_EXIT_INSN(),
},
.prog_type = BPF_PROG_TYPE_SCHED_CLS,
@@ -40,8 +43,11 @@
{
"DIV64 overflow, check 2",
.insns = {
- BPF_LD_IMM64(BPF_REG_0, LLONG_MIN),
- BPF_ALU64_IMM(BPF_DIV, BPF_REG_0, -1),
+ BPF_LD_IMM64(BPF_REG_1, LLONG_MIN),
+ BPF_ALU64_IMM(BPF_DIV, BPF_REG_1, -1),
+ BPF_MOV32_IMM(BPF_REG_0, 0),
+ BPF_JMP_REG(BPF_JEQ, BPF_REG_0, BPF_REG_1, 1),
+ BPF_MOV32_IMM(BPF_REG_0, 1),
BPF_EXIT_INSN(),
},
.prog_type = BPF_PROG_TYPE_SCHED_CLS,
--
2.21.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] powerpc/bpf: use unsigned division instruction for 64-bit operations
2019-06-12 18:51 [PATCH 0/2] powerpc/bpf: DIV64 instruction fix Naveen N. Rao
2019-06-12 18:51 ` [PATCH 1/2] bpf: fix div64 overflow tests to properly detect errors Naveen N. Rao
@ 2019-06-12 18:51 ` Naveen N. Rao
2019-06-13 5:06 ` [PATCH 0/2] powerpc/bpf: DIV64 instruction fix Sandipan Das
2019-06-13 21:11 ` Daniel Borkmann
3 siblings, 0 replies; 5+ messages in thread
From: Naveen N. Rao @ 2019-06-12 18:51 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann; +Cc: bpf, netdev, linuxppc-dev
BPF_ALU64 div/mod operations are currently using signed division, unlike
BPF_ALU32 operations. Fix the same. DIV64 and MOD64 overflow tests pass
with this fix.
Fixes: 156d0e290e969c ("powerpc/ebpf/jit: Implement JIT compiler for extended BPF")
Cc: stable@vger.kernel.org # v4.8+
Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
---
arch/powerpc/include/asm/ppc-opcode.h | 1 +
arch/powerpc/net/bpf_jit.h | 2 +-
arch/powerpc/net/bpf_jit_comp64.c | 8 ++++----
3 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/arch/powerpc/include/asm/ppc-opcode.h b/arch/powerpc/include/asm/ppc-opcode.h
index 23f7ed796f38..49d65cd08ee0 100644
--- a/arch/powerpc/include/asm/ppc-opcode.h
+++ b/arch/powerpc/include/asm/ppc-opcode.h
@@ -342,6 +342,7 @@
#define PPC_INST_MADDLD 0x10000033
#define PPC_INST_DIVWU 0x7c000396
#define PPC_INST_DIVD 0x7c0003d2
+#define PPC_INST_DIVDU 0x7c000392
#define PPC_INST_RLWINM 0x54000000
#define PPC_INST_RLWINM_DOT 0x54000001
#define PPC_INST_RLWIMI 0x50000000
diff --git a/arch/powerpc/net/bpf_jit.h b/arch/powerpc/net/bpf_jit.h
index dcac37745b05..1e932898d430 100644
--- a/arch/powerpc/net/bpf_jit.h
+++ b/arch/powerpc/net/bpf_jit.h
@@ -116,7 +116,7 @@
___PPC_RA(a) | IMM_L(i))
#define PPC_DIVWU(d, a, b) EMIT(PPC_INST_DIVWU | ___PPC_RT(d) | \
___PPC_RA(a) | ___PPC_RB(b))
-#define PPC_DIVD(d, a, b) EMIT(PPC_INST_DIVD | ___PPC_RT(d) | \
+#define PPC_DIVDU(d, a, b) EMIT(PPC_INST_DIVDU | ___PPC_RT(d) | \
___PPC_RA(a) | ___PPC_RB(b))
#define PPC_AND(d, a, b) EMIT(PPC_INST_AND | ___PPC_RA(d) | \
___PPC_RS(a) | ___PPC_RB(b))
diff --git a/arch/powerpc/net/bpf_jit_comp64.c b/arch/powerpc/net/bpf_jit_comp64.c
index 0ebd946f178b..b0fa4723d6fb 100644
--- a/arch/powerpc/net/bpf_jit_comp64.c
+++ b/arch/powerpc/net/bpf_jit_comp64.c
@@ -399,12 +399,12 @@ static int bpf_jit_build_body(struct bpf_prog *fp, u32 *image,
case BPF_ALU64 | BPF_DIV | BPF_X: /* dst /= src */
case BPF_ALU64 | BPF_MOD | BPF_X: /* dst %= src */
if (BPF_OP(code) == BPF_MOD) {
- PPC_DIVD(b2p[TMP_REG_1], dst_reg, src_reg);
+ PPC_DIVDU(b2p[TMP_REG_1], dst_reg, src_reg);
PPC_MULD(b2p[TMP_REG_1], src_reg,
b2p[TMP_REG_1]);
PPC_SUB(dst_reg, dst_reg, b2p[TMP_REG_1]);
} else
- PPC_DIVD(dst_reg, dst_reg, src_reg);
+ PPC_DIVDU(dst_reg, dst_reg, src_reg);
break;
case BPF_ALU | BPF_MOD | BPF_K: /* (u32) dst %= (u32) imm */
case BPF_ALU | BPF_DIV | BPF_K: /* (u32) dst /= (u32) imm */
@@ -432,7 +432,7 @@ static int bpf_jit_build_body(struct bpf_prog *fp, u32 *image,
break;
case BPF_ALU64:
if (BPF_OP(code) == BPF_MOD) {
- PPC_DIVD(b2p[TMP_REG_2], dst_reg,
+ PPC_DIVDU(b2p[TMP_REG_2], dst_reg,
b2p[TMP_REG_1]);
PPC_MULD(b2p[TMP_REG_1],
b2p[TMP_REG_1],
@@ -440,7 +440,7 @@ static int bpf_jit_build_body(struct bpf_prog *fp, u32 *image,
PPC_SUB(dst_reg, dst_reg,
b2p[TMP_REG_1]);
} else
- PPC_DIVD(dst_reg, dst_reg,
+ PPC_DIVDU(dst_reg, dst_reg,
b2p[TMP_REG_1]);
break;
}
--
2.21.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 0/2] powerpc/bpf: DIV64 instruction fix
2019-06-12 18:51 [PATCH 0/2] powerpc/bpf: DIV64 instruction fix Naveen N. Rao
2019-06-12 18:51 ` [PATCH 1/2] bpf: fix div64 overflow tests to properly detect errors Naveen N. Rao
2019-06-12 18:51 ` [PATCH 2/2] powerpc/bpf: use unsigned division instruction for 64-bit operations Naveen N. Rao
@ 2019-06-13 5:06 ` Sandipan Das
2019-06-13 21:11 ` Daniel Borkmann
3 siblings, 0 replies; 5+ messages in thread
From: Sandipan Das @ 2019-06-13 5:06 UTC (permalink / raw)
To: Naveen N. Rao
Cc: Alexei Starovoitov, Daniel Borkmann, netdev, bpf, linuxppc-dev
On 13/06/19 12:21 AM, Naveen N. Rao wrote:
> The first patch updates DIV64 overflow tests to properly detect error
> conditions. The second patch fixes powerpc64 JIT to generate the proper
> unsigned division instruction for BPF_ALU64.
>
> - Naveen
>
> Naveen N. Rao (2):
> bpf: fix div64 overflow tests to properly detect errors
> powerpc/bpf: use unsigned division instruction for 64-bit operations
>
> arch/powerpc/include/asm/ppc-opcode.h | 1 +
> arch/powerpc/net/bpf_jit.h | 2 +-
> arch/powerpc/net/bpf_jit_comp64.c | 8 ++++----
> .../testing/selftests/bpf/verifier/div_overflow.c | 14 ++++++++++----
> 4 files changed, 16 insertions(+), 9 deletions(-)
>
For the series
Acked-by: Sandipan Das <sandipan@linux.ibm.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 0/2] powerpc/bpf: DIV64 instruction fix
2019-06-12 18:51 [PATCH 0/2] powerpc/bpf: DIV64 instruction fix Naveen N. Rao
` (2 preceding siblings ...)
2019-06-13 5:06 ` [PATCH 0/2] powerpc/bpf: DIV64 instruction fix Sandipan Das
@ 2019-06-13 21:11 ` Daniel Borkmann
3 siblings, 0 replies; 5+ messages in thread
From: Daniel Borkmann @ 2019-06-13 21:11 UTC (permalink / raw)
To: Naveen N. Rao, Alexei Starovoitov; +Cc: bpf, netdev, linuxppc-dev
On 06/12/2019 08:51 PM, Naveen N. Rao wrote:
> The first patch updates DIV64 overflow tests to properly detect error
> conditions. The second patch fixes powerpc64 JIT to generate the proper
> unsigned division instruction for BPF_ALU64.
>
> - Naveen
>
> Naveen N. Rao (2):
> bpf: fix div64 overflow tests to properly detect errors
> powerpc/bpf: use unsigned division instruction for 64-bit operations
>
> arch/powerpc/include/asm/ppc-opcode.h | 1 +
> arch/powerpc/net/bpf_jit.h | 2 +-
> arch/powerpc/net/bpf_jit_comp64.c | 8 ++++----
> .../testing/selftests/bpf/verifier/div_overflow.c | 14 ++++++++++----
> 4 files changed, 16 insertions(+), 9 deletions(-)
>
LGTM, applied to bpf, thanks!
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-06-13 21:11 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-12 18:51 [PATCH 0/2] powerpc/bpf: DIV64 instruction fix Naveen N. Rao
2019-06-12 18:51 ` [PATCH 1/2] bpf: fix div64 overflow tests to properly detect errors Naveen N. Rao
2019-06-12 18:51 ` [PATCH 2/2] powerpc/bpf: use unsigned division instruction for 64-bit operations Naveen N. Rao
2019-06-13 5:06 ` [PATCH 0/2] powerpc/bpf: DIV64 instruction fix Sandipan Das
2019-06-13 21:11 ` Daniel Borkmann
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).