From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.4 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6811EC3F2C6 for ; Tue, 3 Mar 2020 22:28:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 38CD420848 for ; Tue, 3 Mar 2020 22:28:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="KXqGqes3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727847AbgCCW2U (ORCPT ); Tue, 3 Mar 2020 17:28:20 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:37392 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727335AbgCCW2T (ORCPT ); Tue, 3 Mar 2020 17:28:19 -0500 Received: by mail-wr1-f66.google.com with SMTP id q8so6502812wrm.4 for ; Tue, 03 Mar 2020 14:28:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:date:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=e4V+8aTWhdIlLEzf4Eox/9Ord8vKJnS3U23eYxJI4AQ=; b=KXqGqes3H3m8InAE8AGrElj7zAvDMD6xwXVFASzk6WwjuCdFaB4vMPGC2jaTP1ee28 35OsUP23/42wx2xoQArttVKCiXPzhmAaFjJdOSCM1/+hSxiItYlTXPpd12zHHTVpnPQx /hKiRvHeqRGFZ/uA8E+RhYTTuO/5+L3wxwB6c= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=e4V+8aTWhdIlLEzf4Eox/9Ord8vKJnS3U23eYxJI4AQ=; b=CmMc/3atE5e7ydNhNToliqPkli0qmWRhk2mDsbb0X61N8d6rVSG88R/IMCVatZ04SX dQrTRnSOdkKpVDslWltF35BFdDa+L/d19UoL1czkPxx2bTkqEEJPX548kf6eoUhb7l6e rASzxUOgb+nXh9glRgBX4cjP3Y/dMuOhg5rAh5VEcYQLSnYceSvW/hqdr4nG6S76huNH UuzTfzuU/i5Ba4Omf1Bh9fuEBkisZmYfWLQlzaE/CQIqV81hJDmq8PSjiLtSfFTCmM77 v3PJqn267sFx/d5jJziKS+TIs/zpMp6I4W1LCHgEJWclwivXsK0ZuoLZKTnGlIE4nMZz ngYg== X-Gm-Message-State: ANhLgQ2h48NXs20pC4HzQJpK8SD14EM5STFAfv/RAiFwnj6IQI/3y+X8 fGnZAHCYWMC/350GFMkMUDz/2A== X-Google-Smtp-Source: ADFU+vsO7rRWvBSAQDxjBwGmKgf0DoG0NPF8tyeTqymolzH6Fse1dadJP4xsklXMM6Et8L73vKrO0w== X-Received: by 2002:a5d:608b:: with SMTP id w11mr198197wrt.366.1583274495670; Tue, 03 Mar 2020 14:28:15 -0800 (PST) Received: from chromium.org (77-56-209-237.dclient.hispeed.ch. [77.56.209.237]) by smtp.gmail.com with ESMTPSA id n13sm773557wmd.21.2020.03.03.14.28.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Mar 2020 14:28:15 -0800 (PST) From: KP Singh X-Google-Original-From: KP Singh Date: Tue, 3 Mar 2020 23:28:12 +0100 To: Andrii Nakryiko Cc: open list , bpf , Alexei Starovoitov , Daniel Borkmann , Paul Turner , Florent Revest , Brendan Jackman Subject: Re: [PATCH bpf-next 2/7] bpf: JIT helpers for fmod_ret progs Message-ID: <20200303222812.GA5265@chromium.org> References: <20200303140950.6355-1-kpsingh@chromium.org> <20200303140950.6355-3-kpsingh@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03-Mär 14:26, Andrii Nakryiko wrote: > 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? Ah, good catch! this is deinitely not intended to be here. It's a debug artifact and needs to dropped indeed. - KP > > > +} > > + > > +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; > > +} > > + > > [...]