All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next 0/2] nfp: bpf: rename ALU_OP_NEG and support BPF_NEG
@ 2017-11-01 17:38 Jakub Kicinski
  2017-11-01 17:38 ` [PATCH net-next 1/2] nfp: bpf: rename ALU_OP_NEG to ALU_OP_NOT Jakub Kicinski
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Jakub Kicinski @ 2017-11-01 17:38 UTC (permalink / raw)
  To: netdev; +Cc: oss-drivers, Jakub Kicinski

Jiong says:

  Compilers are starting to use BPF_NEG, for example LLVM. However, NFP
does not support JITing it. This patch set adds this. Unit test is added
as well.

  Meanwhile, the current NFP_ALU_NEG is actually doing bitwise NOT (one's
complement) operation, so the name is misleading. This patch set corrects
this.


Jiong Wang (2):
  nfp: bpf: rename ALU_OP_NEG to ALU_OP_NOT
  nfp: bpf: support [BPF_ALU | BPF_ALU64] | BPF_NEG

 drivers/net/ethernet/netronome/nfp/bpf/jit.c | 26 +++++++++++++++++++++++++-
 drivers/net/ethernet/netronome/nfp/nfp_asm.h |  2 +-
 2 files changed, 26 insertions(+), 2 deletions(-)

-- 
2.14.1

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH net-next 1/2] nfp: bpf: rename ALU_OP_NEG to ALU_OP_NOT
  2017-11-01 17:38 [PATCH net-next 0/2] nfp: bpf: rename ALU_OP_NEG and support BPF_NEG Jakub Kicinski
@ 2017-11-01 17:38 ` Jakub Kicinski
  2017-11-01 17:38 ` [PATCH net-next 2/2] nfp: bpf: support [BPF_ALU | BPF_ALU64] | BPF_NEG Jakub Kicinski
  2017-11-02  7:47 ` [PATCH net-next 0/2] nfp: bpf: rename ALU_OP_NEG and support BPF_NEG David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: Jakub Kicinski @ 2017-11-01 17:38 UTC (permalink / raw)
  To: netdev; +Cc: oss-drivers, Jiong Wang

From: Jiong Wang <jiong.wang@netronome.com>

The current ALU_OP_NEG is Op encoding 0x4 for NPF ALU instruction. It is
actually performing "~B" operation which is bitwise NOT.

The using naming ALU_OP_NEG is misleading as NEG is -B which is not the
same as ~B.

Signed-off-by: Jiong Wang <jiong.wang@netronome.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
---
 drivers/net/ethernet/netronome/nfp/bpf/jit.c | 2 +-
 drivers/net/ethernet/netronome/nfp/nfp_asm.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/netronome/nfp/bpf/jit.c b/drivers/net/ethernet/netronome/nfp/bpf/jit.c
index e7eeb7a07f81..369173100fcf 100644
--- a/drivers/net/ethernet/netronome/nfp/bpf/jit.c
+++ b/drivers/net/ethernet/netronome/nfp/bpf/jit.c
@@ -944,7 +944,7 @@ wrp_alu_imm(struct nfp_prog *nfp_prog, u8 dst, enum alu_op alu_op, u32 imm)
 	if (alu_op == ALU_OP_XOR) {
 		if (!~imm)
 			emit_alu(nfp_prog, reg_both(dst), reg_none(),
-				 ALU_OP_NEG, reg_b(dst));
+				 ALU_OP_NOT, reg_b(dst));
 		if (!imm || !~imm)
 			return;
 	}
diff --git a/drivers/net/ethernet/netronome/nfp/nfp_asm.h b/drivers/net/ethernet/netronome/nfp/nfp_asm.h
index f4d1df3a1925..74d0c11ab2f9 100644
--- a/drivers/net/ethernet/netronome/nfp/nfp_asm.h
+++ b/drivers/net/ethernet/netronome/nfp/nfp_asm.h
@@ -174,7 +174,7 @@ enum shf_sc {
 enum alu_op {
 	ALU_OP_NONE	= 0x00,
 	ALU_OP_ADD	= 0x01,
-	ALU_OP_NEG	= 0x04,
+	ALU_OP_NOT	= 0x04,
 	ALU_OP_AND	= 0x08,
 	ALU_OP_SUB_C	= 0x0d,
 	ALU_OP_ADD_C	= 0x11,
-- 
2.14.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH net-next 2/2] nfp: bpf: support [BPF_ALU | BPF_ALU64] | BPF_NEG
  2017-11-01 17:38 [PATCH net-next 0/2] nfp: bpf: rename ALU_OP_NEG and support BPF_NEG Jakub Kicinski
  2017-11-01 17:38 ` [PATCH net-next 1/2] nfp: bpf: rename ALU_OP_NEG to ALU_OP_NOT Jakub Kicinski
@ 2017-11-01 17:38 ` Jakub Kicinski
  2017-11-02  7:47 ` [PATCH net-next 0/2] nfp: bpf: rename ALU_OP_NEG and support BPF_NEG David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: Jakub Kicinski @ 2017-11-01 17:38 UTC (permalink / raw)
  To: netdev; +Cc: oss-drivers, Jiong Wang

From: Jiong Wang <jiong.wang@netronome.com>

This patch supports BPF_NEG under both BPF_ALU64 and BPF_ALU. LLVM recently
starts to generate it.

NOTE: BPF_NEG takes single operand which is an register and serve as both
input and output.

Signed-off-by: Jiong Wang <jiong.wang@netronome.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
---
 drivers/net/ethernet/netronome/nfp/bpf/jit.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/drivers/net/ethernet/netronome/nfp/bpf/jit.c b/drivers/net/ethernet/netronome/nfp/bpf/jit.c
index 369173100fcf..2609a2487100 100644
--- a/drivers/net/ethernet/netronome/nfp/bpf/jit.c
+++ b/drivers/net/ethernet/netronome/nfp/bpf/jit.c
@@ -1218,6 +1218,18 @@ static int sub_imm64(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta)
 	return 0;
 }
 
+static int neg_reg64(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta)
+{
+	const struct bpf_insn *insn = &meta->insn;
+
+	emit_alu(nfp_prog, reg_both(insn->dst_reg * 2), reg_imm(0),
+		 ALU_OP_SUB, reg_b(insn->dst_reg * 2));
+	emit_alu(nfp_prog, reg_both(insn->dst_reg * 2 + 1), reg_imm(0),
+		 ALU_OP_SUB_C, reg_b(insn->dst_reg * 2 + 1));
+
+	return 0;
+}
+
 static int shl_imm64(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta)
 {
 	const struct bpf_insn *insn = &meta->insn;
@@ -1338,6 +1350,16 @@ static int sub_imm(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta)
 	return wrp_alu32_imm(nfp_prog, meta, ALU_OP_SUB, !meta->insn.imm);
 }
 
+static int neg_reg(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta)
+{
+	u8 dst = meta->insn.dst_reg * 2;
+
+	emit_alu(nfp_prog, reg_both(dst), reg_imm(0), ALU_OP_SUB, reg_b(dst));
+	wrp_immed(nfp_prog, reg_both(meta->insn.dst_reg * 2 + 1), 0);
+
+	return 0;
+}
+
 static int shl_imm(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta)
 {
 	const struct bpf_insn *insn = &meta->insn;
@@ -1847,6 +1869,7 @@ static const instr_cb_t instr_cb[256] = {
 	[BPF_ALU64 | BPF_ADD | BPF_K] =	add_imm64,
 	[BPF_ALU64 | BPF_SUB | BPF_X] =	sub_reg64,
 	[BPF_ALU64 | BPF_SUB | BPF_K] =	sub_imm64,
+	[BPF_ALU64 | BPF_NEG] =		neg_reg64,
 	[BPF_ALU64 | BPF_LSH | BPF_K] =	shl_imm64,
 	[BPF_ALU64 | BPF_RSH | BPF_K] =	shr_imm64,
 	[BPF_ALU | BPF_MOV | BPF_X] =	mov_reg,
@@ -1861,6 +1884,7 @@ static const instr_cb_t instr_cb[256] = {
 	[BPF_ALU | BPF_ADD | BPF_K] =	add_imm,
 	[BPF_ALU | BPF_SUB | BPF_X] =	sub_reg,
 	[BPF_ALU | BPF_SUB | BPF_K] =	sub_imm,
+	[BPF_ALU | BPF_NEG] =		neg_reg,
 	[BPF_ALU | BPF_LSH | BPF_K] =	shl_imm,
 	[BPF_ALU | BPF_END | BPF_X] =	end_reg32,
 	[BPF_LD | BPF_IMM | BPF_DW] =	imm_ld8,
-- 
2.14.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next 0/2] nfp: bpf: rename ALU_OP_NEG and support BPF_NEG
  2017-11-01 17:38 [PATCH net-next 0/2] nfp: bpf: rename ALU_OP_NEG and support BPF_NEG Jakub Kicinski
  2017-11-01 17:38 ` [PATCH net-next 1/2] nfp: bpf: rename ALU_OP_NEG to ALU_OP_NOT Jakub Kicinski
  2017-11-01 17:38 ` [PATCH net-next 2/2] nfp: bpf: support [BPF_ALU | BPF_ALU64] | BPF_NEG Jakub Kicinski
@ 2017-11-02  7:47 ` David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2017-11-02  7:47 UTC (permalink / raw)
  To: jakub.kicinski; +Cc: netdev, oss-drivers

From: Jakub Kicinski <jakub.kicinski@netronome.com>
Date: Wed,  1 Nov 2017 10:38:23 -0700

> Jiong says:
> 
>   Compilers are starting to use BPF_NEG, for example LLVM. However, NFP
> does not support JITing it. This patch set adds this. Unit test is added
> as well.
> 
>   Meanwhile, the current NFP_ALU_NEG is actually doing bitwise NOT (one's
> complement) operation, so the name is misleading. This patch set corrects
> this.

Series applied, thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-11-02  7:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-01 17:38 [PATCH net-next 0/2] nfp: bpf: rename ALU_OP_NEG and support BPF_NEG Jakub Kicinski
2017-11-01 17:38 ` [PATCH net-next 1/2] nfp: bpf: rename ALU_OP_NEG to ALU_OP_NOT Jakub Kicinski
2017-11-01 17:38 ` [PATCH net-next 2/2] nfp: bpf: support [BPF_ALU | BPF_ALU64] | BPF_NEG Jakub Kicinski
2017-11-02  7:47 ` [PATCH net-next 0/2] nfp: bpf: rename ALU_OP_NEG and support BPF_NEG David Miller

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.