aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQuentin Monnet <quentin.monnet@netronome.com>2018-01-10 07:26:07 -0500
committerDaniel Borkmann <daniel@iogearbox.net>2018-01-10 07:49:36 -0500
commitff627e3d07a07f7ed1105f459ee9586d4be7818e (patch)
treebd26e78addbbd2c5afb46e8d4a37e5924a114580
parent430e68d10baf55e4c40d4dd1de8201c1caf5dddd (diff)
nfp: bpf: reuse verifier log for debug messages
Now that `bpf_verifier_log_write()` is exported from the verifier and makes it possible to reuse the verifier log to print messages to the standard output, use this instead of the kernel logs in the nfp driver for printing error messages occurring at verification time. Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com> Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
-rw-r--r--drivers/net/ethernet/netronome/nfp/bpf/verifier.c30
1 files changed, 16 insertions, 14 deletions
diff --git a/drivers/net/ethernet/netronome/nfp/bpf/verifier.c b/drivers/net/ethernet/netronome/nfp/bpf/verifier.c
index d8870c2f11f3..7890d95d4018 100644
--- a/drivers/net/ethernet/netronome/nfp/bpf/verifier.c
+++ b/drivers/net/ethernet/netronome/nfp/bpf/verifier.c
@@ -31,8 +31,6 @@
31 * SOFTWARE. 31 * SOFTWARE.
32 */ 32 */
33 33
34#define pr_fmt(fmt) "NFP net bpf: " fmt
35
36#include <linux/bpf.h> 34#include <linux/bpf.h>
37#include <linux/bpf_verifier.h> 35#include <linux/bpf_verifier.h>
38#include <linux/kernel.h> 36#include <linux/kernel.h>
@@ -41,6 +39,9 @@
41#include "fw.h" 39#include "fw.h"
42#include "main.h" 40#include "main.h"
43 41
42#define pr_vlog(env, fmt, ...) \
43 bpf_verifier_log_write(env, "[nfp] " fmt, ##__VA_ARGS__)
44
44struct nfp_insn_meta * 45struct nfp_insn_meta *
45nfp_bpf_goto_meta(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta, 46nfp_bpf_goto_meta(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta,
46 unsigned int insn_idx, unsigned int n_insns) 47 unsigned int insn_idx, unsigned int n_insns)
@@ -116,18 +117,18 @@ nfp_bpf_check_call(struct nfp_prog *nfp_prog, struct bpf_verifier_env *env,
116 switch (func_id) { 117 switch (func_id) {
117 case BPF_FUNC_xdp_adjust_head: 118 case BPF_FUNC_xdp_adjust_head:
118 if (!bpf->adjust_head.off_max) { 119 if (!bpf->adjust_head.off_max) {
119 pr_warn("adjust_head not supported by FW\n"); 120 pr_vlog(env, "adjust_head not supported by FW\n");
120 return -EOPNOTSUPP; 121 return -EOPNOTSUPP;
121 } 122 }
122 if (!(bpf->adjust_head.flags & NFP_BPF_ADJUST_HEAD_NO_META)) { 123 if (!(bpf->adjust_head.flags & NFP_BPF_ADJUST_HEAD_NO_META)) {
123 pr_warn("adjust_head: FW requires shifting metadata, not supported by the driver\n"); 124 pr_vlog(env, "adjust_head: FW requires shifting metadata, not supported by the driver\n");
124 return -EOPNOTSUPP; 125 return -EOPNOTSUPP;
125 } 126 }
126 127
127 nfp_record_adjust_head(bpf, nfp_prog, meta, reg2); 128 nfp_record_adjust_head(bpf, nfp_prog, meta, reg2);
128 break; 129 break;
129 default: 130 default:
130 pr_warn("unsupported function id: %d\n", func_id); 131 pr_vlog(env, "unsupported function id: %d\n", func_id);
131 return -EOPNOTSUPP; 132 return -EOPNOTSUPP;
132 } 133 }
133 134
@@ -150,7 +151,7 @@ nfp_bpf_check_exit(struct nfp_prog *nfp_prog,
150 char tn_buf[48]; 151 char tn_buf[48];
151 152
152 tnum_strn(tn_buf, sizeof(tn_buf), reg0->var_off); 153 tnum_strn(tn_buf, sizeof(tn_buf), reg0->var_off);
153 pr_info("unsupported exit state: %d, var_off: %s\n", 154 pr_vlog(env, "unsupported exit state: %d, var_off: %s\n",
154 reg0->type, tn_buf); 155 reg0->type, tn_buf);
155 return -EINVAL; 156 return -EINVAL;
156 } 157 }
@@ -160,7 +161,7 @@ nfp_bpf_check_exit(struct nfp_prog *nfp_prog,
160 imm <= TC_ACT_REDIRECT && 161 imm <= TC_ACT_REDIRECT &&
161 imm != TC_ACT_SHOT && imm != TC_ACT_STOLEN && 162 imm != TC_ACT_SHOT && imm != TC_ACT_STOLEN &&
162 imm != TC_ACT_QUEUED) { 163 imm != TC_ACT_QUEUED) {
163 pr_info("unsupported exit state: %d, imm: %llx\n", 164 pr_vlog(env, "unsupported exit state: %d, imm: %llx\n",
164 reg0->type, imm); 165 reg0->type, imm);
165 return -EINVAL; 166 return -EINVAL;
166 } 167 }
@@ -171,12 +172,13 @@ nfp_bpf_check_exit(struct nfp_prog *nfp_prog,
171static int 172static int
172nfp_bpf_check_stack_access(struct nfp_prog *nfp_prog, 173nfp_bpf_check_stack_access(struct nfp_prog *nfp_prog,
173 struct nfp_insn_meta *meta, 174 struct nfp_insn_meta *meta,
174 const struct bpf_reg_state *reg) 175 const struct bpf_reg_state *reg,
176 struct bpf_verifier_env *env)
175{ 177{
176 s32 old_off, new_off; 178 s32 old_off, new_off;
177 179
178 if (!tnum_is_const(reg->var_off)) { 180 if (!tnum_is_const(reg->var_off)) {
179 pr_info("variable ptr stack access\n"); 181 pr_vlog(env, "variable ptr stack access\n");
180 return -EINVAL; 182 return -EINVAL;
181 } 183 }
182 184
@@ -194,7 +196,7 @@ nfp_bpf_check_stack_access(struct nfp_prog *nfp_prog,
194 if (old_off % 4 == new_off % 4) 196 if (old_off % 4 == new_off % 4)
195 return 0; 197 return 0;
196 198
197 pr_info("stack access changed location was:%d is:%d\n", 199 pr_vlog(env, "stack access changed location was:%d is:%d\n",
198 old_off, new_off); 200 old_off, new_off);
199 return -EINVAL; 201 return -EINVAL;
200} 202}
@@ -209,18 +211,18 @@ nfp_bpf_check_ptr(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta,
209 if (reg->type != PTR_TO_CTX && 211 if (reg->type != PTR_TO_CTX &&
210 reg->type != PTR_TO_STACK && 212 reg->type != PTR_TO_STACK &&
211 reg->type != PTR_TO_PACKET) { 213 reg->type != PTR_TO_PACKET) {
212 pr_info("unsupported ptr type: %d\n", reg->type); 214 pr_vlog(env, "unsupported ptr type: %d\n", reg->type);
213 return -EINVAL; 215 return -EINVAL;
214 } 216 }
215 217
216 if (reg->type == PTR_TO_STACK) { 218 if (reg->type == PTR_TO_STACK) {
217 err = nfp_bpf_check_stack_access(nfp_prog, meta, reg); 219 err = nfp_bpf_check_stack_access(nfp_prog, meta, reg, env);
218 if (err) 220 if (err)
219 return err; 221 return err;
220 } 222 }
221 223
222 if (meta->ptr.type != NOT_INIT && meta->ptr.type != reg->type) { 224 if (meta->ptr.type != NOT_INIT && meta->ptr.type != reg->type) {
223 pr_info("ptr type changed for instruction %d -> %d\n", 225 pr_vlog(env, "ptr type changed for instruction %d -> %d\n",
224 meta->ptr.type, reg->type); 226 meta->ptr.type, reg->type);
225 return -EINVAL; 227 return -EINVAL;
226 } 228 }
@@ -241,7 +243,7 @@ nfp_verify_insn(struct bpf_verifier_env *env, int insn_idx, int prev_insn_idx)
241 243
242 if (meta->insn.src_reg >= MAX_BPF_REG || 244 if (meta->insn.src_reg >= MAX_BPF_REG ||
243 meta->insn.dst_reg >= MAX_BPF_REG) { 245 meta->insn.dst_reg >= MAX_BPF_REG) {
244 pr_err("program uses extended registers - jit hardening?\n"); 246 pr_vlog(env, "program uses extended registers - jit hardening?\n");
245 return -EINVAL; 247 return -EINVAL;
246 } 248 }
247 249