Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp3861411ybf; Tue, 3 Mar 2020 14:27:22 -0800 (PST) X-Google-Smtp-Source: ADFU+vueAyu8IUDs3n9BCYmhT9Vu6//2Ew6Skm/+3CIwXLvsgnqeRMpQeX2zd4cQsiSS5ia68tBf X-Received: by 2002:aca:dc8b:: with SMTP id t133mr556312oig.98.1583274442552; Tue, 03 Mar 2020 14:27:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583274442; cv=none; d=google.com; s=arc-20160816; b=y8RHGc0u6o4kaX4sTzWKcDjpfhps4iN57yDAnEpGwoB0YLZuMxRDQELXKC1pWZDJxi QTN1DRkBBbquzJskjUHrKPSCR+ab8nhfqMHdKJZ3qgYJ5Ge6PZkLySzE8Q7ulgppomNX XXnJ4osXLDHhB4wt0zLKnUSS77xd53IMQ1K9+SFmHtQYZcwjaPOk76yWyBnmM0JhvWQg 4lbV+7Ib6SwTj0AuYSWza3SIzr+DLJ1lM6+5J3Cf3xJnuwxuNnXDo+SAr1Tp4HWUsLbV 6SYZ7tDX9ORQSrJMBVzLSIx66oyunZaNpHSZai7PGhnvQ9PJdPyl2n6tECg0POrb91Po FS9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=wagrVCzS/XTiayLok4nktlIE6b9GM+kU+mOoA/5BUNQ=; b=TE7QSoBw0SQW53EB8RAOvJnTpPYU3nuZKuQWQ/XQCehgE1hW+ExAhMPxn3jSQXTtrK PQazbsrgm6A5o5Rfg8iEAqhdrAJ146g9a5J/DYeLqiCW78GLOk66VV0LA/OfR+cFhnvk LwP2WrXOCrBfpUHxMZC+UXFnEdPBx9XPWjHWCUqaznEzIj9Ut52J2LNpGLE1kWmDT+Bv ficC7D0O49nlzCeM7IjJRAtQo/A9TD3QLsg9N74KWEWBNe53G+q/Oji0lj9UDKIpenab ITLz1lfTY2xElGKTY5xCzArNC0u+tPVK2enLVf3+N0xSM3yh1jB1UFM1h6x7XrVH0MmR LHfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Imebv53X; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h136si80712oib.141.2020.03.03.14.27.10; Tue, 03 Mar 2020 14:27:22 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Imebv53X; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727913AbgCCW0W (ORCPT + 99 others); Tue, 3 Mar 2020 17:26:22 -0500 Received: from mail-qk1-f196.google.com ([209.85.222.196]:38074 "EHLO mail-qk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727769AbgCCW0W (ORCPT ); Tue, 3 Mar 2020 17:26:22 -0500 Received: by mail-qk1-f196.google.com with SMTP id h22so5142407qke.5; Tue, 03 Mar 2020 14:26:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=wagrVCzS/XTiayLok4nktlIE6b9GM+kU+mOoA/5BUNQ=; b=Imebv53X2yi2WO2vBjXJnc2vvyk3l9qMBZXaUJaOUOgVd0pHdwWbRO8ViUIGKuFEya k3cBuospCwoqTF8lPuQofzal2lkaGUwsaw96sH1TrytGrqawdqkvDq2op7vcPso25yq2 iZi3BsykiP20586JqH3pd3J+M5kx/F39T0F2Ef6RpPyvGQnwFEYFeTF2i0TfnwlgBz7O 3uUutbiMzQc9XD4rZmBXqfTuWctktVmS+kssFTpj+n7FuBzvkXGZhUOiDun2ND+/VVCr b4vnW/SVEMNvgqMN50J/CfTUcFMTnIdaC/TpVcnCK/J5jBUwQZjkNTOZaAMr+zmaoOS9 OxsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=wagrVCzS/XTiayLok4nktlIE6b9GM+kU+mOoA/5BUNQ=; b=eBLJZ4dgXs08JOqjGf8GmdBHDIpV/p+89HgXRxTZReC5QP8fGayuaABmNAlp60d/ex CIVznFW6DWkNX20mGgzx6Ht8OjueSoau1YIiqnxmCdPWZRA56NA2OU2Rz+NBt1Sb7X+z Y9CkBPpOeKlpTKr5+0DvJUgtVm2SbzFtHE1Z+ktOURuQPRTBRJYdQ8zTDCa4nEmXQHfR QQ38kCwfQFPRlDem315QcxUbQvrCbSAUQsWTbf7Z5nipYRjeZzU1+VzpuIIZTItJ0ogT Ki641z1+y8D1/ngFn1TmvvHU0pEI6IwxxzAQeufjwXm27wJ/4RmC+XAGvsf16HleTgQj rxJg== X-Gm-Message-State: ANhLgQ16hO1Jl4bGguS6Q640LzEaBds4m0GrSb4CAB7vnEP6KGUYScbG +wOW64ABfrZoeGuI/J+ARbHhHjG/4RUeOuBpcFM= X-Received: by 2002:a05:620a:99d:: with SMTP id x29mr231581qkx.39.1583274380969; Tue, 03 Mar 2020 14:26:20 -0800 (PST) MIME-Version: 1.0 References: <20200303140950.6355-1-kpsingh@chromium.org> <20200303140950.6355-3-kpsingh@chromium.org> In-Reply-To: <20200303140950.6355-3-kpsingh@chromium.org> From: Andrii Nakryiko Date: Tue, 3 Mar 2020 14:26:09 -0800 Message-ID: Subject: Re: [PATCH bpf-next 2/7] bpf: JIT helpers for fmod_ret progs To: KP Singh Cc: open list , bpf , Alexei Starovoitov , Daniel Borkmann , Paul Turner , Florent Revest , Brendan Jackman Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 3, 2020 at 6:13 AM KP Singh wrote: > > From: KP Singh > > * Split the invoke_bpf program to prepare for special handling of > fmod_ret programs introduced in a subsequent patch. > * Move the definition of emit_cond_near_jump and emit_nops as they are > needed for fmod_ret. > * Refactor branch target alignment into its own function > align16_branch_target. > > Signed-off-by: KP Singh > --- > arch/x86/net/bpf_jit_comp.c | 158 ++++++++++++++++++++---------------- > 1 file changed, 90 insertions(+), 68 deletions(-) > > diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c > index 15c7d28bc05c..475e354c2e88 100644 > --- a/arch/x86/net/bpf_jit_comp.c > +++ b/arch/x86/net/bpf_jit_comp.c > @@ -1361,35 +1361,100 @@ static void restore_regs(const struct btf_func_model *m, u8 **prog, int nr_args, > -(stack_size - i * 8)); > } > [...] > + > +/* From Intel 64 and IA-32 Architectures Optimization > + * Reference Manual, 3.4.1.4 Code Alignment, Assembly/Compiler > + * Coding Rule 11: All branch targets should be 16-byte > + * aligned. > + */ > +static void align16_branch_target(u8 **pprog) > +{ > + u8 *target, *prog = *pprog; > + > + target = PTR_ALIGN(prog, 16); > + if (target != prog) > + emit_nops(&prog, target - prog); > + if (target != prog) > + pr_err("calcultion error\n"); this wasn't in the original code, do you feel like it's more important to check this and print error? also typo: calculation error, but then it's a bit brief and uninformative message. So I don't know, maybe just drop it? > +} > + > +static int emit_cond_near_jump(u8 **pprog, void *func, void *ip, u8 jmp_cond) > +{ > + u8 *prog = *pprog; > + int cnt = 0; > + s64 offset; > + > + offset = func - (ip + 2 + 4); > + if (!is_simm32(offset)) { > + pr_err("Target %p is out of range\n", func); > + return -EINVAL; > + } > + EMIT2_off32(0x0F, jmp_cond + 0x10, offset); > + *pprog = prog; > + return 0; > +} > + [...]