From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sandipan Das Subject: Re: [PATCH bpf v2 1/6] bpf: support 64-bit offsets for bpf function calls Date: Fri, 18 May 2018 21:47:14 +0530 Message-ID: <1cf14ffa-d8d7-d463-a160-226e2555873d@linux.vnet.ibm.com> References: <20180518125039.6500-1-sandipan@linux.vnet.ibm.com> <20180518125039.6500-2-sandipan@linux.vnet.ibm.com> <242592f3-c2b4-04bb-7a6c-2394ae4fee98@iogearbox.net> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Cc: ast@kernel.org, netdev@vger.kernel.org, naveen.n.rao@linux.vnet.ibm.com, linuxppc-dev@lists.ozlabs.org, jakub.kicinski@netronome.com To: Daniel Borkmann Return-path: Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:56388 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751541AbeERQRY (ORCPT ); Fri, 18 May 2018 12:17:24 -0400 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w4IGE8Ds072020 for ; Fri, 18 May 2018 12:17:23 -0400 Received: from e06smtp12.uk.ibm.com (e06smtp12.uk.ibm.com [195.75.94.108]) by mx0a-001b2d01.pphosted.com with ESMTP id 2j202sp689-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 18 May 2018 12:17:23 -0400 Received: from localhost by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 18 May 2018 17:17:20 +0100 In-Reply-To: <242592f3-c2b4-04bb-7a6c-2394ae4fee98@iogearbox.net> Content-Language: en-US Sender: netdev-owner@vger.kernel.org List-ID: On 05/18/2018 08:45 PM, Daniel Borkmann wrote: > On 05/18/2018 02:50 PM, Sandipan Das wrote: >> The imm field of a bpf instruction is a signed 32-bit integer. >> For JIT bpf-to-bpf function calls, it stores the offset of the >> start address of the callee's JITed image from __bpf_call_base. >> >> For some architectures, such as powerpc64, this offset may be >> as large as 64 bits and cannot be accomodated in the imm field >> without truncation. >> >> We resolve this by: >> >> [1] Additionally using the auxillary data of each function to >> keep a list of start addresses of the JITed images for all >> functions determined by the verifier. >> >> [2] Retaining the subprog id inside the off field of the call >> instructions and using it to index into the list mentioned >> above and lookup the callee's address. >> >> To make sure that the existing JIT compilers continue to work >> without requiring changes, we keep the imm field as it is. >> >> Signed-off-by: Sandipan Das >> --- >> kernel/bpf/verifier.c | 15 ++++++++++++++- >> 1 file changed, 14 insertions(+), 1 deletion(-) >> >> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c >> index a9e4b1372da6..6c56cce9c4e3 100644 >> --- a/kernel/bpf/verifier.c >> +++ b/kernel/bpf/verifier.c >> @@ -5383,11 +5383,24 @@ static int jit_subprogs(struct bpf_verifier_env *env) >> insn->src_reg != BPF_PSEUDO_CALL) >> continue; >> subprog = insn->off; >> - insn->off = 0; >> insn->imm = (u64 (*)(u64, u64, u64, u64, u64)) >> func[subprog]->bpf_func - >> __bpf_call_base; >> } >> + >> + /* we use the aux data to keep a list of the start addresses >> + * of the JITed images for each function in the program >> + * >> + * for some architectures, such as powerpc64, the imm field >> + * might not be large enough to hold the offset of the start >> + * address of the callee's JITed image from __bpf_call_base >> + * >> + * in such cases, we can lookup the start address of a callee >> + * by using its subprog id, available from the off field of >> + * the call instruction, as an index for this list >> + */ >> + func[i]->aux->func = func; >> + func[i]->aux->func_cnt = env->subprog_cnt + 1; > > The target tree you have here is infact bpf, since in bpf-next there was a > cleanup where the + 1 is removed. Just for the record that we need to keep > this in mind for bpf into bpf-next merge since this would otherwise subtly > break. > Sorry about the wrong tag. This series is indeed based off bpf-next. - Sandipan >> } >> for (i = 0; i < env->subprog_cnt; i++) { >> old_bpf_func = func[i]->bpf_func; >> > >