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=-5.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, 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 31CB4C54E4A for ; Thu, 7 May 2020 20:19:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1691C20870 for ; Thu, 7 May 2020 20:19:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728590AbgEGUTm (ORCPT ); Thu, 7 May 2020 16:19:42 -0400 Received: from www62.your-server.de ([213.133.104.62]:33822 "EHLO www62.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726320AbgEGUTl (ORCPT ); Thu, 7 May 2020 16:19:41 -0400 Received: from sslproxy05.your-server.de ([78.46.172.2]) by www62.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1jWmzZ-0000uo-43; Thu, 07 May 2020 22:19:37 +0200 Received: from [178.195.186.98] (helo=pc-9.home) by sslproxy05.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jWmzY-000Pq5-CQ; Thu, 07 May 2020 22:19:36 +0200 Subject: Re: [RFC PATCH bpf-next 2/3] bpf, arm64: Optimize AND,OR,XOR,JSET BPF_K using arm64 logical immediates To: Luke Nelson , bpf@vger.kernel.org Cc: Luke Nelson , Xi Wang , Catalin Marinas , Will Deacon , Alexei Starovoitov , Zi Shen Lim , Martin KaFai Lau , Song Liu , Yonghong Song , Andrii Nakryiko , John Fastabend , KP Singh , Mark Rutland , Enrico Weigelt , Alexios Zavras , Thomas Gleixner , Marc Zyngier , Christoffer Dall , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, clang-built-linux@googlegroups.com References: <20200507010504.26352-1-luke.r.nels@gmail.com> <20200507010504.26352-3-luke.r.nels@gmail.com> From: Daniel Borkmann Message-ID: <2b05950b-5f7a-e5e7-81fe-27703c3ef77f@iogearbox.net> Date: Thu, 7 May 2020 22:19:35 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: <20200507010504.26352-3-luke.r.nels@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Authenticated-Sender: daniel@iogearbox.net X-Virus-Scanned: Clear (ClamAV 0.102.2/25805/Thu May 7 14:14:46 2020) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On 5/7/20 3:05 AM, Luke Nelson wrote: > The current code for BPF_{AND,OR,XOR,JSET} BPF_K loads the immediate to > a temporary register before use. > > This patch changes the code to avoid using a temporary register > when the BPF immediate is encodable using an arm64 logical immediate > instruction. If the encoding fails (due to the immediate not being > encodable), it falls back to using a temporary register. > > Example of generated code for BPF_ALU32_IMM(BPF_AND, R0, 0x80000001): > > without optimization: > > 24: mov w10, #0x8000ffff > 28: movk w10, #0x1 > 2c: and w7, w7, w10 > > with optimization: > > 24: and w7, w7, #0x80000001 > > Since the encoding process is quite complex, the JIT reuses existing > functionality in arch/arm64/kernel/insn.c for encoding logical immediates > rather than duplicate it in the JIT. > > Co-developed-by: Xi Wang > Signed-off-by: Xi Wang > Signed-off-by: Luke Nelson Great find, thanks! Given Will wanted to queue them: Acked-by: Daniel Borkmann