提交 10c4d614 编写于 作者: M Markos Chandras 提交者: Ralf Baechle

MIPS: bpf: Fix is_range() semantics

is_range() was meant to check whether the number is within
the s16 range or not. However the return values and consumers expected
the exact opposite. We fix that by inverting the logic in the function
to return 'true' for < s16 and 'false' for > s16.
Signed-off-by: NMarkos Chandras <markos.chandras@imgtec.com>
Reported-by: NAlexei Starovoitov <ast@plumgrid.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: Daniel Borkmann <dborkman@redhat.com>
Cc: Alexei Starovoitov <ast@plumgrid.com>
Cc: netdev@vger.kernel.org
Cc: linux-mips@linux-mips.org
Patchwork: https://patchwork.linux-mips.org/patch/7131/Signed-off-by: NRalf Baechle <ralf@linux-mips.org>
上级 78b95b66
...@@ -166,9 +166,7 @@ do { \ ...@@ -166,9 +166,7 @@ do { \
/* Determine if immediate is within the 16-bit signed range */ /* Determine if immediate is within the 16-bit signed range */
static inline bool is_range16(s32 imm) static inline bool is_range16(s32 imm)
{ {
if (imm >= SBIT(15) || imm < -SBIT(15)) return !(imm >= SBIT(15) || imm < -SBIT(15));
return true;
return false;
} }
static inline void emit_addu(unsigned int dst, unsigned int src1, static inline void emit_addu(unsigned int dst, unsigned int src1,
...@@ -187,7 +185,7 @@ static inline void emit_load_imm(unsigned int dst, u32 imm, struct jit_ctx *ctx) ...@@ -187,7 +185,7 @@ static inline void emit_load_imm(unsigned int dst, u32 imm, struct jit_ctx *ctx)
{ {
if (ctx->target != NULL) { if (ctx->target != NULL) {
/* addiu can only handle s16 */ /* addiu can only handle s16 */
if (is_range16(imm)) { if (!is_range16(imm)) {
u32 *p = &ctx->target[ctx->idx]; u32 *p = &ctx->target[ctx->idx];
uasm_i_lui(&p, r_tmp_imm, (s32)imm >> 16); uasm_i_lui(&p, r_tmp_imm, (s32)imm >> 16);
p = &ctx->target[ctx->idx + 1]; p = &ctx->target[ctx->idx + 1];
...@@ -199,7 +197,7 @@ static inline void emit_load_imm(unsigned int dst, u32 imm, struct jit_ctx *ctx) ...@@ -199,7 +197,7 @@ static inline void emit_load_imm(unsigned int dst, u32 imm, struct jit_ctx *ctx)
} }
ctx->idx++; ctx->idx++;
if (is_range16(imm)) if (!is_range16(imm))
ctx->idx++; ctx->idx++;
} }
...@@ -240,7 +238,7 @@ static inline void emit_daddiu(unsigned int dst, unsigned int src, ...@@ -240,7 +238,7 @@ static inline void emit_daddiu(unsigned int dst, unsigned int src,
static inline void emit_addiu(unsigned int dst, unsigned int src, static inline void emit_addiu(unsigned int dst, unsigned int src,
u32 imm, struct jit_ctx *ctx) u32 imm, struct jit_ctx *ctx)
{ {
if (is_range16(imm)) { if (!is_range16(imm)) {
emit_load_imm(r_tmp, imm, ctx); emit_load_imm(r_tmp, imm, ctx);
emit_addu(dst, r_tmp, src, ctx); emit_addu(dst, r_tmp, src, ctx);
} else { } else {
...@@ -347,7 +345,7 @@ static inline void emit_sltiu(unsigned dst, unsigned int src, ...@@ -347,7 +345,7 @@ static inline void emit_sltiu(unsigned dst, unsigned int src,
unsigned int imm, struct jit_ctx *ctx) unsigned int imm, struct jit_ctx *ctx)
{ {
/* 16 bit immediate */ /* 16 bit immediate */
if (is_range16((s32)imm)) { if (!is_range16((s32)imm)) {
emit_load_imm(r_tmp, imm, ctx); emit_load_imm(r_tmp, imm, ctx);
emit_sltu(dst, src, r_tmp, ctx); emit_sltu(dst, src, r_tmp, ctx);
} else { } else {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册