Netdev List
 help / color / mirror / Atom feed
From: Jakub Kicinski <jakub.kicinski@netronome.com>
To: netdev@vger.kernel.org
Cc: oss-drivers@netronome.com, Jakub Kicinski <jakub.kicinski@netronome.com>
Subject: [PATCH net-next 2/9] nfp: bpf: refactor nfp_bpf_check_ptr()
Date: Mon, 23 Oct 2017 11:58:07 -0700	[thread overview]
Message-ID: <20171023185814.4797-3-jakub.kicinski@netronome.com> (raw)
In-Reply-To: <20171023185814.4797-1-jakub.kicinski@netronome.com>

nfp_bpf_check_ptr() mostly looks at the pointer register.
Add a temporary variable to shorten the code.

While at it make sure we print error messages if translation
fails to help users identify the problem (to be carried in
ext_ack in due course).

Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com>
---
 drivers/net/ethernet/netronome/nfp/bpf/verifier.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/netronome/nfp/bpf/verifier.c b/drivers/net/ethernet/netronome/nfp/bpf/verifier.c
index e361c0e3b788..4d2ed84a82e0 100644
--- a/drivers/net/ethernet/netronome/nfp/bpf/verifier.c
+++ b/drivers/net/ethernet/netronome/nfp/bpf/verifier.c
@@ -113,17 +113,23 @@ nfp_bpf_check_exit(struct nfp_prog *nfp_prog,
 
 static int
 nfp_bpf_check_ptr(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta,
-		  const struct bpf_verifier_env *env, u8 reg)
+		  const struct bpf_verifier_env *env, u8 reg_no)
 {
-	if (env->cur_state.regs[reg].type != PTR_TO_CTX &&
-	    env->cur_state.regs[reg].type != PTR_TO_PACKET)
+	const struct bpf_reg_state *reg = &env->cur_state.regs[reg_no];
+
+	if (reg->type != PTR_TO_CTX &&
+	    reg->type != PTR_TO_PACKET) {
+		pr_info("unsupported ptr type: %d\n", reg->type);
 		return -EINVAL;
+	}
 
-	if (meta->ptr.type != NOT_INIT &&
-	    meta->ptr.type != env->cur_state.regs[reg].type)
+	if (meta->ptr.type != NOT_INIT && meta->ptr.type != reg->type) {
+		pr_info("ptr type changed for instruction %d -> %d\n",
+			meta->ptr.type, reg->type);
 		return -EINVAL;
+	}
 
-	meta->ptr = env->cur_state.regs[reg];
+	meta->ptr = *reg;
 
 	return 0;
 }
-- 
2.14.1

  parent reply	other threads:[~2017-10-23 18:58 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-23 18:58 [PATCH net-next 0/9] nfp: bpf: stack support in offload Jakub Kicinski
2017-10-23 18:58 ` [PATCH net-next 1/9] nfp: bpf: add helper for emitting nops Jakub Kicinski
2017-10-23 18:58 ` Jakub Kicinski [this message]
2017-10-23 18:58 ` [PATCH net-next 3/9] nfp: bpf: add stack write support Jakub Kicinski
2017-10-23 18:58 ` [PATCH net-next 4/9] nfp: bpf: add stack read support Jakub Kicinski
2017-10-23 18:58 ` [PATCH net-next 5/9] nfp: bpf: optimize the RMW for stack accesses Jakub Kicinski
2017-10-23 18:58 ` [PATCH net-next 6/9] nfp: bpf: allow stack accesses via modified stack registers Jakub Kicinski
2017-10-23 18:58 ` [PATCH net-next 7/9] nfp: bpf: support accessing the stack beyond 64 bytes Jakub Kicinski
2017-10-23 18:58 ` [PATCH net-next 8/9] nfp: bpf: support stack accesses via non-constant pointers Jakub Kicinski
2017-10-23 18:58 ` [PATCH net-next 9/9] nfp: bpf: optimize mov64 a little Jakub Kicinski
2017-10-24  8:39 ` [PATCH net-next 0/9] nfp: bpf: stack support in offload David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171023185814.4797-3-jakub.kicinski@netronome.com \
    --to=jakub.kicinski@netronome.com \
    --cc=netdev@vger.kernel.org \
    --cc=oss-drivers@netronome.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox