Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp3862257ybf; Tue, 3 Mar 2020 14:28:41 -0800 (PST) X-Google-Smtp-Source: ADFU+vtVf8ugqbnIJ40XS/Qm2NnjhYg3qu6dRJH9jpie7MN+HYI7AT1AcMc7SIlFA5qhKiewnqOK X-Received: by 2002:aca:4fd5:: with SMTP id d204mr539419oib.76.1583274521476; Tue, 03 Mar 2020 14:28:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583274521; cv=none; d=google.com; s=arc-20160816; b=Z/AbPICPyYhbs5uws4xMXdyAuojZP1F+j9e60L+hYtNgXaQmvgySfHUARyRcy0gkka 1+1zIxolJT3+qCqK9kzP08vgJRsfYYc3cMLSJLYdvXWvyA7dAJN6ZHtJxjD1RkubNNlM rqmx3y88ZdIY+3j7mue6SFotvciw6GM3pCesf3y3fjV5p4W7fxX/H3mvHjSm8G7WYxFF kZEKZYFy6Etiv07azUesu5S/PiNagrZON87/W+B/UUEdAytsvfn8xfXYV7MiEWLGEvsl 6H2TzReHRVEbaDv6QseZkTNNisjRF3QQo8VjTvdyfFxT9UE5hgI7vyOuOO4OF50RsRjb HW8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:date:from:dkim-signature; bh=e4V+8aTWhdIlLEzf4Eox/9Ord8vKJnS3U23eYxJI4AQ=; b=n322WcXhMlrjD6eXA5BaY7dMSscOfvaNkOKXsAUXLIoNNnptvm53x3n0eSGciWezqN tw9SLWAwAPYay+fhNKaJ7KPx/aV+8BftTskDMjLjN8993snsTXi0faH8+h7WK57jv5J6 XhsrOvH+Msa7lbauNNZ1267sjPZR0aIl3zgYxrhLjCAR53kctEyZ4/mkjsRR6s0AhY33 RHwCeckbLn1ILSkdffRT0D2h8JNKHAMRhrdT3aoNimd0HR1xYrRZqjsdJ7G6QMIDC8sk ksg9E5lGkKBKvYFP8G0HCyPnHXNrGXS4Ycjd35ijD8kI83uLISz/3E6YdSrz8BjWGeoM 3KuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=KXqGqes3; 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=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b8si66729oib.193.2020.03.03.14.28.29; Tue, 03 Mar 2020 14:28:41 -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=@chromium.org header.s=google header.b=KXqGqes3; 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=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727769AbgCCW2U (ORCPT + 99 others); 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-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; > > +} > > + > > [...]