浏览代码

nfp: bpf: flag jump destination to guide insn combine optimizations

NFP eBPF offload JIT engine is doing some instruction combine based
optimizations which however must not be safe if the combined sequences
are across basic block boarders.

Currently, there are post checks during fixing jump destinations. If the
jump destination is found to be eBPF insn that has been combined into
another one, then JIT engine will raise error and abort.

This is not optimal. The JIT engine ought to disable the optimization on
such cross-bb-border sequences instead of abort.

As there is no control flow information in eBPF infrastructure that we
can't do basic block based optimizations, this patch extends the existing
jump destination record pass to also flag the jump destination, then in
instruction combine passes we could skip the optimizations if insns in the
sequence are jump targets.

Suggested-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Jiong Wang <jiong.wang@netronome.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Jiong Wang 7 年之前
父节点
当前提交
a09d5c52c4
共有 2 个文件被更改,包括 5 次插入0 次删除
  1. 4 0
      drivers/net/ethernet/netronome/nfp/bpf/main.h
  2. 1 0
      drivers/net/ethernet/netronome/nfp/bpf/offload.c

+ 4 - 0
drivers/net/ethernet/netronome/nfp/bpf/main.h

@@ -89,6 +89,8 @@ typedef int (*instr_cb_t)(struct nfp_prog *, struct nfp_insn_meta *);
 #define nfp_meta_next(meta)	list_next_entry(meta, l)
 #define nfp_meta_next(meta)	list_next_entry(meta, l)
 #define nfp_meta_prev(meta)	list_prev_entry(meta, l)
 #define nfp_meta_prev(meta)	list_prev_entry(meta, l)
 
 
+#define FLAG_INSN_IS_JUMP_DST	BIT(0)
+
 /**
 /**
  * struct nfp_insn_meta - BPF instruction wrapper
  * struct nfp_insn_meta - BPF instruction wrapper
  * @insn: BPF instruction
  * @insn: BPF instruction
@@ -97,6 +99,7 @@ typedef int (*instr_cb_t)(struct nfp_prog *, struct nfp_insn_meta *);
  * @jmp_dst: destination info for jump instructions
  * @jmp_dst: destination info for jump instructions
  * @off: index of first generated machine instruction (in nfp_prog.prog)
  * @off: index of first generated machine instruction (in nfp_prog.prog)
  * @n: eBPF instruction number
  * @n: eBPF instruction number
+ * @flags: eBPF instruction extra optimization flags
  * @skip: skip this instruction (optimized out)
  * @skip: skip this instruction (optimized out)
  * @double_cb: callback for second part of the instruction
  * @double_cb: callback for second part of the instruction
  * @l: link on nfp_prog->insns list
  * @l: link on nfp_prog->insns list
@@ -112,6 +115,7 @@ struct nfp_insn_meta {
 	};
 	};
 	unsigned int off;
 	unsigned int off;
 	unsigned short n;
 	unsigned short n;
+	unsigned short flags;
 	bool skip;
 	bool skip;
 	instr_cb_t double_cb;
 	instr_cb_t double_cb;
 
 

+ 1 - 0
drivers/net/ethernet/netronome/nfp/bpf/offload.c

@@ -83,6 +83,7 @@ nfp_prog_prepare(struct nfp_prog *nfp_prog, const struct bpf_insn *prog,
 						     cnt);
 						     cnt);
 
 
 			meta->jmp_dst = dst_meta;
 			meta->jmp_dst = dst_meta;
+			dst_meta->flags |= FLAG_INSN_IS_JUMP_DST;
 		}
 		}
 	}
 	}