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=-9.8 required=3.0 tests=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_GIT 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 3BC41C47258 for ; Wed, 6 May 2020 00:03:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 10F1220721 for ; Wed, 6 May 2020 00:03:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=cs.washington.edu header.i=@cs.washington.edu header.b="YYYhuVfw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729809AbgEFADr (ORCPT ); Tue, 5 May 2020 20:03:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729674AbgEFADd (ORCPT ); Tue, 5 May 2020 20:03:33 -0400 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C015C061A0F for ; Tue, 5 May 2020 17:03:33 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id a32so68811pje.5 for ; Tue, 05 May 2020 17:03:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cs.washington.edu; s=goo201206; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=tu4wfIJHIQQHHdr2oULlj2uQlQex1349SVlpEUwQDaA=; b=YYYhuVfwies2v08OAprLyffNxDwOzCKJiip46cwKDTes0snI5kI1fVXAt1v/DbyQbq qqyIuITgLNQFp7znZJSNTLBz31BDZ2NDzwY487Q4RBlX5Avypqf06V/om1/Cwl6WM9/f RqZY+PdRhztp2kb1+kPiL5NQXx0HtDwlCc7LQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=tu4wfIJHIQQHHdr2oULlj2uQlQex1349SVlpEUwQDaA=; b=eeo5RKtySyoB/Jt4M4akJvIgufo9liSiI9wvSdYMsDDUw0MJKXsZ2xG8nkdE9JMWRX 9Hq4buMxyxFwqg0jCRv23XynWTfRLxRtkD4pMeNQYlwF/5028xc3JXlZY8izCrh0L6zU +cPFNJNMWLt+n/HfiUmhyEUu/Si8sLVzqQntYDhKYPqNVP0g5uuJf5IevYc0IhQFP0Iu xvp0VBpWs+ZxJ7tz32jXEzKx1k8vVkkoSwkTDwScSYHxjVPG9+MaYjEKpNh0YqLjoAMD 2Vg8QB0+pSm6eZr0DzjURSaeI6iF2+H/Q295vzqwFyi1W6HTTogeiRkHqb0fQI75hqHV V6cw== X-Gm-Message-State: AGi0PuZLUKcofOZEzgjoWKHgWCZNNkXJlV5nE2oQJHIKT0MeNerNAyBu aI751P2pnQStsEWVBKWmK3sjKw== X-Google-Smtp-Source: APiQypIwBdTOVciQ6JxnzjjE9tj9R8b2rWOeA29u6dvkgY6D7Tjhk6Ie+E/Rg01PCw6tols8N/uxIA== X-Received: by 2002:a17:902:b711:: with SMTP id d17mr5341360pls.333.1588723412695; Tue, 05 May 2020 17:03:32 -0700 (PDT) Received: from localhost.localdomain (c-73-53-94-119.hsd1.wa.comcast.net. [73.53.94.119]) by smtp.gmail.com with ESMTPSA id u3sm133912pfn.217.2020.05.05.17.03.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 May 2020 17:03:32 -0700 (PDT) From: Luke Nelson X-Google-Original-From: Luke Nelson To: bpf@vger.kernel.org Cc: Luke Nelson , Xi Wang , =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , Andrii Nakryiko , John Fastabend , KP Singh , netdev@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next 2/4] bpf, riscv: Optimize FROM_LE using verifier_zext on RV64 Date: Tue, 5 May 2020 17:03:18 -0700 Message-Id: <20200506000320.28965-3-luke.r.nels@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200506000320.28965-1-luke.r.nels@gmail.com> References: <20200506000320.28965-1-luke.r.nels@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch adds two optimizations for BPF_ALU BPF_END BPF_FROM_LE in the RV64 BPF JIT. First, it enables the verifier zero-extension optimization to avoid zero extension when imm == 32. Second, it avoids generating code for imm == 64, since it is equivalent to a no-op. Co-developed-by: Xi Wang Signed-off-by: Xi Wang Signed-off-by: Luke Nelson --- arch/riscv/net/bpf_jit_comp64.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c index e2636902a74e..c3ce9a911b66 100644 --- a/arch/riscv/net/bpf_jit_comp64.c +++ b/arch/riscv/net/bpf_jit_comp64.c @@ -542,13 +542,21 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, struct rv_jit_context *ctx, /* dst = BSWAP##imm(dst) */ case BPF_ALU | BPF_END | BPF_FROM_LE: - { - int shift = 64 - imm; - - emit(rv_slli(rd, rd, shift), ctx); - emit(rv_srli(rd, rd, shift), ctx); + switch (imm) { + case 16: + emit(rv_slli(rd, rd, 48), ctx); + emit(rv_srli(rd, rd, 48), ctx); + break; + case 32: + if (!aux->verifier_zext) + emit_zext_32(rd, ctx); + break; + case 64: + /* Do nothing */ + break; + } break; - } + case BPF_ALU | BPF_END | BPF_FROM_BE: emit(rv_addi(RV_REG_T2, RV_REG_ZERO, 0), ctx); -- 2.17.1 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=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham 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 9CB32C47259 for ; Wed, 6 May 2020 00:03:40 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6F31D21841 for ; Wed, 6 May 2020 00:03:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="kINVCE5q"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=cs.washington.edu header.i=@cs.washington.edu header.b="YYYhuVfw" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6F31D21841 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=cs.washington.edu Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+infradead-linux-riscv=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:MIME-Version: Content-Type:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=tu4wfIJHIQQHHdr2oULlj2uQlQex1349SVlpEUwQDaA=; b=kINVCE5qS08++f dVjCw4Lsktov16xe025pUdeodAqPMab9zf4+nLgvtEY2oSEBIwmDfAhJfwFKafLHd7cUeDw4FEc3h cWGpxMJqzLm6HtIEV7X5nOTNodrHe8gxHBFClDEbWikq7WfUeRfRH+00TeCU6CRyhPH8s38Vu+nXj 3LMIYfvf2ogpZd0Jo49biulmgLixag8HDr6k7HpJGC+5g/9IMXnbQdqPkmnazOPQzr+TL1JO00lm8 /ugkFXQOlTvd0kSMyK7IdFA3VuFlmQ2d5q4PdNHjVEx3f07MJLHA9QY0z/+5M4YF72DpBvNOzAuKA ac/5hnmGKa2ODf3LPt4A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jW7XH-0007mE-Af; Wed, 06 May 2020 00:03:39 +0000 Received: from mail-pj1-x1041.google.com ([2607:f8b0:4864:20::1041]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jW7XB-0007f5-Km for linux-riscv@lists.infradead.org; Wed, 06 May 2020 00:03:35 +0000 Received: by mail-pj1-x1041.google.com with SMTP id e6so4335pjt.4 for ; Tue, 05 May 2020 17:03:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cs.washington.edu; s=goo201206; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=tu4wfIJHIQQHHdr2oULlj2uQlQex1349SVlpEUwQDaA=; b=YYYhuVfwies2v08OAprLyffNxDwOzCKJiip46cwKDTes0snI5kI1fVXAt1v/DbyQbq qqyIuITgLNQFp7znZJSNTLBz31BDZ2NDzwY487Q4RBlX5Avypqf06V/om1/Cwl6WM9/f RqZY+PdRhztp2kb1+kPiL5NQXx0HtDwlCc7LQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=tu4wfIJHIQQHHdr2oULlj2uQlQex1349SVlpEUwQDaA=; b=i5l8L1/KtgeNDKmHhpB5gJ7HWwOiahhsiJgCATiULTFs8CMQcifhpyz7dzAMqzbMXo pwba8m3XPqOVzw40Fn8q2IULrT6JaePjChE2hb6qtNtN79lTNo2WEvl32OEPUMxUV2c9 1BuqoN6NmMIAgCOzhWGOfU4qIwtcKhLTAlk1s1Rer2dvf4m2QC4Gm6mfzxu/Ya6JhuYW opXRkdZ24VRsfE++QB7/p7QDQsCnNlP7FFvJRI+Rx2XdHjdSTjqFWYBNvVvje5f/ShYm b8BfnnWyjHmtVKcc96WwP5E4h8h6qybCqkWc+87BThCyiHsjrB6E3AAXErJjpjsaS/hx 9biQ== X-Gm-Message-State: AGi0PuYWWrIe0uKYA/8PXHWR2WnuY2dVtU2yyqo7D87Y8xQKbuGquMXZ z+Go7LQNqNiA9jzJ7DN5tzwKyg== X-Google-Smtp-Source: APiQypIwBdTOVciQ6JxnzjjE9tj9R8b2rWOeA29u6dvkgY6D7Tjhk6Ie+E/Rg01PCw6tols8N/uxIA== X-Received: by 2002:a17:902:b711:: with SMTP id d17mr5341360pls.333.1588723412695; Tue, 05 May 2020 17:03:32 -0700 (PDT) Received: from localhost.localdomain (c-73-53-94-119.hsd1.wa.comcast.net. [73.53.94.119]) by smtp.gmail.com with ESMTPSA id u3sm133912pfn.217.2020.05.05.17.03.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 May 2020 17:03:32 -0700 (PDT) From: Luke Nelson X-Google-Original-From: Luke Nelson To: bpf@vger.kernel.org Subject: [PATCH bpf-next 2/4] bpf, riscv: Optimize FROM_LE using verifier_zext on RV64 Date: Tue, 5 May 2020 17:03:18 -0700 Message-Id: <20200506000320.28965-3-luke.r.nels@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200506000320.28965-1-luke.r.nels@gmail.com> References: <20200506000320.28965-1-luke.r.nels@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200505_170333_679632_731385A4 X-CRM114-Status: GOOD ( 11.13 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Song Liu , Albert Ou , Daniel Borkmann , Luke Nelson , =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , John Fastabend , Alexei Starovoitov , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Palmer Dabbelt , Paul Walmsley , KP Singh , Yonghong Song , linux-riscv@lists.infradead.org, Andrii Nakryiko , Martin KaFai Lau , Xi Wang Sender: "linux-riscv" Errors-To: linux-riscv-bounces+infradead-linux-riscv=archiver.kernel.org@lists.infradead.org This patch adds two optimizations for BPF_ALU BPF_END BPF_FROM_LE in the RV64 BPF JIT. First, it enables the verifier zero-extension optimization to avoid zero extension when imm == 32. Second, it avoids generating code for imm == 64, since it is equivalent to a no-op. Co-developed-by: Xi Wang Signed-off-by: Xi Wang Signed-off-by: Luke Nelson --- arch/riscv/net/bpf_jit_comp64.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c index e2636902a74e..c3ce9a911b66 100644 --- a/arch/riscv/net/bpf_jit_comp64.c +++ b/arch/riscv/net/bpf_jit_comp64.c @@ -542,13 +542,21 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, struct rv_jit_context *ctx, /* dst = BSWAP##imm(dst) */ case BPF_ALU | BPF_END | BPF_FROM_LE: - { - int shift = 64 - imm; - - emit(rv_slli(rd, rd, shift), ctx); - emit(rv_srli(rd, rd, shift), ctx); + switch (imm) { + case 16: + emit(rv_slli(rd, rd, 48), ctx); + emit(rv_srli(rd, rd, 48), ctx); + break; + case 32: + if (!aux->verifier_zext) + emit_zext_32(rd, ctx); + break; + case 64: + /* Do nothing */ + break; + } break; - } + case BPF_ALU | BPF_END | BPF_FROM_BE: emit(rv_addi(RV_REG_T2, RV_REG_ZERO, 0), ctx); -- 2.17.1