Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754576AbbETQ3e (ORCPT ); Wed, 20 May 2015 12:29:34 -0400 Received: from mail-ie0-f169.google.com ([209.85.223.169]:33994 "EHLO mail-ie0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754474AbbETQ33 (ORCPT ); Wed, 20 May 2015 12:29:29 -0400 Message-ID: <555CB668.2090901@plumgrid.com> Date: Wed, 20 May 2015 09:29:28 -0700 From: Alexei Starovoitov User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: Andy Lutomirski CC: "David S. Miller" , Ingo Molnar , Daniel Borkmann , Michael Holzheu , Zi Shen Lim , Linux API , Network Development , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH net-next 2/4] x86: bpf_jit: implement bpf_tail_call() helper References: <1432079946-9878-1-git-send-email-ast@plumgrid.com> <1432079946-9878-3-git-send-email-ast@plumgrid.com> <555BD1E9.5000000@plumgrid.com> In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1606 Lines: 36 On 5/20/15 9:05 AM, Andy Lutomirski wrote: >>> >>> 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). ahh, that's what you were referring to. Yes, there is no alloca(). stack cannot grow and always fixed. That's critical for safety verification. On a JIT side though, x64 has ugly div/mod, so JIT is doing push/pop rax/rdx to compile 'dst_reg /= src_reg' bpf insn. But that doesn't change 'same stack depth' rule at the time of bpf_tail_call. Note, s390 JIT can generate different prologue/epilogue for every program, so it will likely be doing stack unwind and jump. Like I was doing in my tail_call_v2 version of x64 jit: https://git.kernel.org/cgit/linux/kernel/git/ast/bpf.git/diff/arch/x86/net/bpf_jit_comp.c?h=tail_call_v2&id=bfd60c3135c8f010a6497dfc5e7d3070e26ca4d1 In case of interrupt happens sometime during this jumping process it's also fine. no-red-zone business is very dear to my heart :) I always keep it in mind when doing assembler/jit changes. -- 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/