Received: by 10.223.176.5 with SMTP id f5csp2850144wra; Mon, 29 Jan 2018 05:08:24 -0800 (PST) X-Google-Smtp-Source: AH8x225pW8EbpE3WP201c9p90W/BIp9qZgrm5HJ7WJ5lORWc1aWbmuyuQsDk7vO1MHPRaZZQMBdz X-Received: by 10.98.15.27 with SMTP id x27mr27355156pfi.197.1517231304470; Mon, 29 Jan 2018 05:08:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517231304; cv=none; d=google.com; s=arc-20160816; b=GYH3dhDoDfEWJXLHPlFs+h7/JwjC79LTUoSsLTh+Ng/4NiX+O/iFIczpMC0XvdGYDw DdUaw3UA6YJLkV9BtEyxxRdR+U0Osq7gJgZFZwg8wUW7liin4V+9rjB6wDIqnnp+Vsb3 UeTJq2G38kS4I6ue/q3XgZD0TyAU19LKdVkeqXry+q2+qryqL+eqfpSqYZD75CdG/+sA M/QSDGCbwQwriN6mNp9NfAiXuPa0QF1ZDL2aYsPy9MTQi6TtSz6WtV+TbWB/3ytz6Tfy 2b5hct4hL+sVfordjg93MaBjpKX6Q7Ql1zHAjaL6gNCV2q66RjrSu03PxytDiVLjJyP0 CTDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=K+/bT2xR4hTL09SKqbWg6P9vVShz9Txd2nOOKlnSGCg=; b=itJkUoafLnNEUKaH8qU/EDUPhfJ+A7W9XK4R5vrSVb1l9cdCor5wD4qojCSC0mI+cu o38QBIma/GTPsI+IbBExjg5EAu+5Ijuj96rulFpcPcc4CCjISlvSwh97aPWJoifodH2Z 7TaujpWC2AGvuJr/k75Wvsu55oLBDGzs9VTJCSgMYQ2SKfNUc7irbFG+CkI17lqxAY1B +PhNcp5gkgfBIbLZhlyTCEVRMd4tXw+jSziSAI8Ycbd1b5FTE49/5UEztn5uBMXCSJzm XWcSDsMkCpsdrZx7kdyTvM7qdhFHK//G3stj7ZByNSOBgXGZTxP9Yhou3JTtPZCbiYc9 rhpg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h187si7449192pgc.531.2018.01.29.05.08.09; Mon, 29 Jan 2018 05:08:24 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752000AbeA2NHK (ORCPT + 99 others); Mon, 29 Jan 2018 08:07:10 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:42490 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751778AbeA2NHH (ORCPT ); Mon, 29 Jan 2018 08:07:07 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 10B7D2FB6; Mon, 29 Jan 2018 13:06:51 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , Alexei Starovoitov , Daniel Borkmann , "David S. Miller" Subject: [PATCH 4.9 59/66] x86: bpf_jit: small optimization in emit_bpf_tail_call() Date: Mon, 29 Jan 2018 13:57:23 +0100 Message-Id: <20180129123842.996759510@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180129123839.842860149@linuxfoundation.org> References: <20180129123839.842860149@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 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 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eric Dumazet [ upstream commit 84ccac6e7854ebbfb56d2fc6d5bef9be49bb304c ] Saves 4 bytes replacing following instructions : lea rax, [rsi + rdx * 8 + offsetof(...)] mov rax, qword ptr [rax] cmp rax, 0 by : mov rax, [rsi + rdx * 8 + offsetof(...)] test rax, rax Signed-off-by: Eric Dumazet Cc: Alexei Starovoitov Cc: Daniel Borkmann Acked-by: Daniel Borkmann Acked-by: Alexei Starovoitov Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- arch/x86/net/bpf_jit_comp.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) --- a/arch/x86/net/bpf_jit_comp.c +++ b/arch/x86/net/bpf_jit_comp.c @@ -281,7 +281,7 @@ static void emit_bpf_tail_call(u8 **ppro EMIT4(0x48, 0x8B, 0x46, /* mov rax, qword ptr [rsi + 16] */ offsetof(struct bpf_array, map.max_entries)); EMIT3(0x48, 0x39, 0xD0); /* cmp rax, rdx */ -#define OFFSET1 47 /* number of bytes to jump */ +#define OFFSET1 43 /* number of bytes to jump */ EMIT2(X86_JBE, OFFSET1); /* jbe out */ label1 = cnt; @@ -290,21 +290,20 @@ static void emit_bpf_tail_call(u8 **ppro */ EMIT2_off32(0x8B, 0x85, -STACKSIZE + 36); /* mov eax, dword ptr [rbp - 516] */ EMIT3(0x83, 0xF8, MAX_TAIL_CALL_CNT); /* cmp eax, MAX_TAIL_CALL_CNT */ -#define OFFSET2 36 +#define OFFSET2 32 EMIT2(X86_JA, OFFSET2); /* ja out */ label2 = cnt; EMIT3(0x83, 0xC0, 0x01); /* add eax, 1 */ EMIT2_off32(0x89, 0x85, -STACKSIZE + 36); /* mov dword ptr [rbp - 516], eax */ /* prog = array->ptrs[index]; */ - EMIT4_off32(0x48, 0x8D, 0x84, 0xD6, /* lea rax, [rsi + rdx * 8 + offsetof(...)] */ + EMIT4_off32(0x48, 0x8B, 0x84, 0xD6, /* mov rax, [rsi + rdx * 8 + offsetof(...)] */ offsetof(struct bpf_array, ptrs)); - EMIT3(0x48, 0x8B, 0x00); /* mov rax, qword ptr [rax] */ /* if (prog == NULL) * goto out; */ - EMIT4(0x48, 0x83, 0xF8, 0x00); /* cmp rax, 0 */ + EMIT3(0x48, 0x85, 0xC0); /* test rax,rax */ #define OFFSET3 10 EMIT2(X86_JE, OFFSET3); /* je out */ label3 = cnt;