All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexei Starovoitov <ast@plumgrid.com>
To: David Laight <David.Laight@aculab.com>
Cc: Chema Gonzalez <chema@google.com>,
	"David S. Miller" <davem@davemloft.net>,
	Ingo Molnar <mingo@kernel.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Daniel Borkmann <dborkman@redhat.com>,
	Eric Dumazet <edumazet@google.com>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Arnaldo Carvalho de Melo <acme@infradead.org>,
	Jiri Olsa <jolsa@redhat.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Kees Cook <keescook@chromium.org>,
	Linux API <linux-api@vger.kernel.org>,
	Network Development <netdev@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH RFC net-next 08/14] bpf: add eBPF verifier
Date: Thu, 3 Jul 2014 10:41:10 -0700	[thread overview]
Message-ID: <CAMEtUuzfU6APGmWrCXVR-18P531vSAEOaC=x8wtyr+4yegTq3w@mail.gmail.com> (raw)
In-Reply-To: <063D6719AE5E284EB5DD2968C1650D6D1726BF1A@AcuExch.aculab.com>

On Thu, Jul 3, 2014 at 2:13 AM, David Laight <David.Laight@aculab.com> wrote:
> From: Alexei Starovoitov
>> >> +#define _(OP) ({ int ret = OP; if (ret < 0) return ret; })
>> > +1 to removing the _ macro. If you want to avoid the 3 lines (is there
>> > anything in the style guide against "if ((err=OP) < 0) ..." ?), at
>>
>> assignment and function call inside 'if' ? I don't like such style.
>>
>> > least use some meaningful macro name (DO_AND_CHECK, or something like
>> > that).
>
> It would have to be RETURN_IF_NEGATIVE().
> But even then it is skipped by searches for 'return'.

try s/\<_\>/RETURN_IF_NEGATIVE/ and see how ugly it looks…

>> Try replacing _ with any other name and see how bad it will look.
>> I tried with MACRO_NAME and with 'if (err) goto' and with 'if (err) return',
>> before I converged on _ macro.
>> I think it's a hidden gem of this patch.
>
> No, it is one of those things that 'seems like a good idea at the time',
> but causes grief much later on.

Disagree. The _ macro in this code has been around for
almost 2 years and survived all sorts of changes all over the verifier.
The macro proved to be very effective in reducing code noise.

> Have you considered saving the error code into 'env' and making most of
> the functions return if an error is set?
> Then the calling code need not check the result of every function call.

that won't work, since err = check1(); err = check2(); if (err) is just wrong,
then err |= check1(); err |= check2() is even worse.
Even if it was possible, continuing verification and printing multiple
errors is too confusing for users. While writing programs and
dealing with verifier rejects we found that the first error is more than
enough to go back and analyze what's wrong with C source.
Notice that verifier prints full verification trace. Without it it was very
hard to understand why particular register at some point has
invalid type.

  reply	other threads:[~2014-07-03 17:41 UTC|newest]

Thread overview: 108+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-28  0:05 [PATCH RFC net-next 00/14] BPF syscall, maps, verifier, samples Alexei Starovoitov
2014-06-28  0:05 ` [PATCH RFC net-next 01/14] net: filter: split filter.c into two files Alexei Starovoitov
2014-07-02  4:23   ` Namhyung Kim
2014-07-02  4:23     ` Namhyung Kim
2014-07-02  5:35     ` Alexei Starovoitov
2014-07-02  5:35       ` Alexei Starovoitov
2014-06-28  0:05 ` [PATCH RFC net-next 02/14] net: filter: split filter.h and expose eBPF to user space Alexei Starovoitov
2014-06-28  0:05 ` [PATCH RFC net-next 03/14] bpf: introduce syscall(BPF, ...) and BPF maps Alexei Starovoitov
2014-06-28  0:16   ` Andy Lutomirski
2014-06-28  5:55     ` Alexei Starovoitov
2014-06-28  6:25       ` Andy Lutomirski
2014-06-28  6:25         ` Andy Lutomirski
2014-06-28  6:43         ` Alexei Starovoitov
2014-06-28  6:43           ` Alexei Starovoitov
2014-06-28 15:34           ` Andy Lutomirski
2014-06-28 15:34             ` Andy Lutomirski
2014-06-28 20:49             ` Alexei Starovoitov
2014-06-28 20:49               ` Alexei Starovoitov
2014-06-29  1:52               ` Andy Lutomirski
2014-06-29  1:52                 ` Andy Lutomirski
2014-06-29  6:36                 ` Alexei Starovoitov
2014-06-29  6:36                   ` Alexei Starovoitov
2014-06-30 22:09                   ` Andy Lutomirski
2014-06-30 22:09                     ` Andy Lutomirski
2014-07-01  5:47                     ` Alexei Starovoitov
2014-07-01 15:11                       ` Andy Lutomirski
2014-07-01 15:11                         ` Andy Lutomirski
2014-07-02  5:33                         ` Alexei Starovoitov
2014-07-02  5:33                           ` Alexei Starovoitov
2014-07-03  1:43                           ` Andy Lutomirski
2014-07-03  1:43                             ` Andy Lutomirski
2014-07-03  2:29                             ` Alexei Starovoitov
2014-07-04 15:17                               ` Andy Lutomirski
2014-07-04 15:17                                 ` Andy Lutomirski
2014-07-05 21:59                                 ` Alexei Starovoitov
2014-06-28  0:05 ` [PATCH RFC net-next 04/14] bpf: update MAINTAINERS entry Alexei Starovoitov
2014-06-28  0:18   ` Joe Perches
2014-06-28  5:59     ` Alexei Starovoitov
2014-06-28  5:59       ` Alexei Starovoitov
2014-06-28  0:05 ` [PATCH RFC net-next 05/14] bpf: add lookup/update/delete/iterate methods to BPF maps Alexei Starovoitov
2014-06-28  0:05 ` [PATCH RFC net-next 06/14] bpf: add hashtable type of " Alexei Starovoitov
2014-06-28  0:05 ` [PATCH RFC net-next 07/14] bpf: expand BPF syscall with program load/unload Alexei Starovoitov
2014-06-28  0:19   ` Andy Lutomirski
2014-06-28  0:19     ` Andy Lutomirski
2014-06-28  6:12     ` Alexei Starovoitov
2014-06-28  6:28       ` Andy Lutomirski
2014-06-28  7:26         ` Alexei Starovoitov
2014-06-28  7:26           ` Alexei Starovoitov
2014-06-28 15:21           ` Greg KH
2014-06-28 15:21             ` Greg KH
2014-06-28 15:35             ` Andy Lutomirski
2014-06-30 20:39               ` Alexei Starovoitov
2014-06-30 10:06       ` David Laight
2014-06-30 10:06         ` David Laight
2014-06-28  0:06 ` [PATCH RFC net-next 08/14] bpf: add eBPF verifier Alexei Starovoitov
2014-06-28 16:01   ` Andy Lutomirski
2014-06-28 16:01     ` Andy Lutomirski
2014-06-28 20:25     ` Alexei Starovoitov
2014-06-28 20:25       ` Alexei Starovoitov
2014-06-29  1:58       ` Andy Lutomirski
2014-06-29  6:20         ` Alexei Starovoitov
2014-06-29  6:20           ` Alexei Starovoitov
2014-07-01  8:05   ` Daniel Borkmann
2014-07-01  8:05     ` Daniel Borkmann
2014-07-01 20:04     ` Alexei Starovoitov
2014-07-01 20:04       ` Alexei Starovoitov
2014-07-02  8:11       ` David Laight
2014-07-02  8:11         ` David Laight
2014-07-02 22:43         ` Alexei Starovoitov
2014-07-02 22:43           ` Alexei Starovoitov
2014-07-02  5:05   ` Namhyung Kim
2014-07-02  5:05     ` Namhyung Kim
2014-07-02  5:57     ` Alexei Starovoitov
2014-07-02 22:22   ` Chema Gonzalez
2014-07-02 23:04     ` Alexei Starovoitov
2014-07-02 23:04       ` Alexei Starovoitov
2014-07-02 23:35       ` Chema Gonzalez
2014-07-03  0:01         ` Alexei Starovoitov
2014-07-03  0:01           ` Alexei Starovoitov
2014-07-03  9:13       ` David Laight
2014-07-03  9:13         ` David Laight
2014-07-03 17:41         ` Alexei Starovoitov [this message]
2014-06-28  0:06 ` [PATCH RFC net-next 09/14] bpf: allow eBPF programs to use maps Alexei Starovoitov
2014-06-28  0:06   ` Alexei Starovoitov
2014-06-28  0:06 ` [PATCH RFC net-next 10/14] net: sock: allow eBPF programs to be attached to sockets Alexei Starovoitov
2014-06-28  0:06 ` [PATCH RFC net-next 11/14] tracing: allow eBPF programs to be attached to events Alexei Starovoitov
2014-07-01  8:30   ` Daniel Borkmann
2014-07-01  8:30     ` Daniel Borkmann
2014-07-01 20:06     ` Alexei Starovoitov
2014-07-01 20:06       ` Alexei Starovoitov
2014-07-02  5:32   ` Namhyung Kim
2014-07-02  5:32     ` Namhyung Kim
2014-07-02  6:14     ` Alexei Starovoitov
2014-07-02  6:14       ` Alexei Starovoitov
2014-07-02  6:39       ` Namhyung Kim
2014-07-02  7:29         ` Alexei Starovoitov
2014-06-28  0:06 ` [PATCH RFC net-next 12/14] samples: bpf: add mini eBPF library to manipulate maps and programs Alexei Starovoitov
2014-06-28  0:06 ` [PATCH RFC net-next 13/14] samples: bpf: example of stateful socket filtering Alexei Starovoitov
2014-06-28  0:21   ` Andy Lutomirski
2014-06-28  6:21     ` Alexei Starovoitov
2014-06-28  6:21       ` Alexei Starovoitov
2014-06-28  0:06 ` [PATCH RFC net-next 14/14] samples: bpf: example of tracing filters with eBPF Alexei Starovoitov
2014-06-30 23:09 ` [PATCH RFC net-next 00/14] BPF syscall, maps, verifier, samples Kees Cook
2014-06-30 23:09   ` Kees Cook
2014-07-01  7:18   ` Daniel Borkmann
2014-07-01  7:18     ` Daniel Borkmann
2014-07-02 16:39     ` Kees Cook
2014-07-02 16:39       ` Kees Cook

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='CAMEtUuzfU6APGmWrCXVR-18P531vSAEOaC=x8wtyr+4yegTq3w@mail.gmail.com' \
    --to=ast@plumgrid.com \
    --cc=David.Laight@aculab.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=chema@google.com \
    --cc=davem@davemloft.net \
    --cc=dborkman@redhat.com \
    --cc=edumazet@google.com \
    --cc=hpa@zytor.com \
    --cc=jolsa@redhat.com \
    --cc=keescook@chromium.org \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    /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 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.