Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759424AbaGCRlP (ORCPT ); Thu, 3 Jul 2014 13:41:15 -0400 Received: from mail-we0-f172.google.com ([74.125.82.172]:52701 "EHLO mail-we0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758872AbaGCRlM convert rfc822-to-8bit (ORCPT ); Thu, 3 Jul 2014 13:41:12 -0400 MIME-Version: 1.0 In-Reply-To: <063D6719AE5E284EB5DD2968C1650D6D1726BF1A@AcuExch.aculab.com> References: <1403913966-4927-1-git-send-email-ast@plumgrid.com> <1403913966-4927-9-git-send-email-ast@plumgrid.com> <063D6719AE5E284EB5DD2968C1650D6D1726BF1A@AcuExch.aculab.com> Date: Thu, 3 Jul 2014 10:41:10 -0700 Message-ID: Subject: Re: [PATCH RFC net-next 08/14] bpf: add eBPF verifier From: Alexei Starovoitov To: David Laight Cc: Chema Gonzalez , "David S. Miller" , Ingo Molnar , Linus Torvalds , Steven Rostedt , Daniel Borkmann , Eric Dumazet , Peter Zijlstra , Arnaldo Carvalho de Melo , Jiri Olsa , Thomas Gleixner , "H. Peter Anvin" , Andrew Morton , Kees Cook , Linux API , Network Development , LKML Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 3, 2014 at 2:13 AM, David Laight 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. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/