Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756304AbbEUQRU (ORCPT ); Thu, 21 May 2015 12:17:20 -0400 Received: from www62.your-server.de ([213.133.104.62]:40457 "EHLO www62.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754744AbbEUQRS (ORCPT ); Thu, 21 May 2015 12:17:18 -0400 Message-ID: <555E0503.8010302@iogearbox.net> Date: Thu, 21 May 2015 18:17:07 +0200 From: Daniel Borkmann User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: Alexei Starovoitov CC: "David S. Miller" , Ingo Molnar , Michael Holzheu , Zi Shen Lim , linux-api@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH net-next 1/4] bpf: allow bpf programs to tail-call other bpf programs References: <1432079946-9878-1-git-send-email-ast@plumgrid.com> <1432079946-9878-2-git-send-email-ast@plumgrid.com> In-Reply-To: <1432079946-9878-2-git-send-email-ast@plumgrid.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Authenticated-Sender: daniel@iogearbox.net Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1339 Lines: 38 On 05/20/2015 01:59 AM, Alexei Starovoitov wrote: > introduce bpf_tail_call(ctx, &jmp_table, index) helper function > which can be used from BPF programs like: > int bpf_prog(struct pt_regs *ctx) > { > ... > bpf_tail_call(ctx, &jmp_table, index); > ... > } > that is roughly equivalent to: > int bpf_prog(struct pt_regs *ctx) > { > ... > if (jmp_table[index]) > return (*jmp_table[index])(ctx); > ... > } > The important detail that it's not a normal call, but a tail call. > The kernel stack is precious, so this helper reuses the current > stack frame and jumps into another BPF program without adding > extra call frame. > It's trivially done in interpreter and a bit trickier in JITs. > In case of x64 JIT the bigger part of generated assembler prologue > is common for all programs, so it is simply skipped while jumping. > Other JITs can do similar prologue-skipping optimization or > do stack unwind before jumping into the next program. > ... > Signed-off-by: Alexei Starovoitov LGTM, thanks! Acked-by: Daniel Borkmann -- 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/