Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754715AbbETQFu (ORCPT ); Wed, 20 May 2015 12:05:50 -0400 Received: from mail-la0-f44.google.com ([209.85.215.44]:33506 "EHLO mail-la0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754067AbbETQFq (ORCPT ); Wed, 20 May 2015 12:05:46 -0400 MIME-Version: 1.0 In-Reply-To: <555BD1E9.5000000@plumgrid.com> References: <1432079946-9878-1-git-send-email-ast@plumgrid.com> <1432079946-9878-3-git-send-email-ast@plumgrid.com> <555BD1E9.5000000@plumgrid.com> From: Andy Lutomirski Date: Wed, 20 May 2015 09:05:24 -0700 Message-ID: Subject: Re: [PATCH net-next 2/4] x86: bpf_jit: implement bpf_tail_call() helper To: Alexei Starovoitov Cc: "David S. Miller" , Ingo Molnar , Daniel Borkmann , Michael Holzheu , Zi Shen Lim , Linux API , Network Development , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1755 Lines: 62 On Tue, May 19, 2015 at 5:14 PM, Alexei Starovoitov wrote: > On 5/19/15 5:11 PM, Andy Lutomirski wrote: >> >> On Tue, May 19, 2015 at 4:59 PM, Alexei Starovoitov >> wrote: >>> >>> bpf_tail_call() arguments: >>> ctx - context pointer >>> jmp_table - one of BPF_MAP_TYPE_PROG_ARRAY maps used as the jump table >>> index - index in the jump table >>> >>> In this implementation x64 JIT bypasses stack unwind and jumps into the >>> callee program after prologue, so the callee program reuses the same >>> stack. >>> >>> The logic can be roughly expressed in C like: >>> >>> u32 tail_call_cnt; >>> >>> void *jumptable[2] = { &&label1, &&label2 }; >>> >>> int bpf_prog1(void *ctx) >>> { >>> label1: >>> ... >>> } >>> >>> int bpf_prog2(void *ctx) >>> { >>> label2: >>> ... >>> } >>> >>> int bpf_prog1(void *ctx) >>> { >>> ... >>> if (tail_call_cnt++ < MAX_TAIL_CALL_CNT) >>> goto *jumptable[index]; ... and pass my 'ctx' to callee ... >>> >>> ... fall through if no entry in jumptable ... >>> } >>> >> >> What causes the stack pointer to be right? Is there some reason that >> the stack pointer is the same no matter where you are in the generated >> code? > > > that's why I said 'it's _roughly_ expressed in C' this way. > Stack pointer doesn't change. It uses the same stack frame. > I think the more relevant point is that (I think) eBPF never changes the stack pointer after the prologue (i.e. the stack depth is truly constant). --Andy -- 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/