From patchwork Tue Jan 15 08:35:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= X-Patchwork-Id: 10764087 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3CBC1139A for ; Tue, 15 Jan 2019 08:35:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2D4E72B502 for ; Tue, 15 Jan 2019 08:35:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1E7462B562; Tue, 15 Jan 2019 08:35:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C2AD22B502 for ; Tue, 15 Jan 2019 08:35:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=VYxu1TFv3BzK18eTvOjzk2DJi6lLPOzVBsR93qnMF8c=; b=LaRSOsoRX++BKj n+6EcvyZYQdyK4hX7wPdOJM+qeJs+AHyyHZWWT2zX48SUt2c/gsOSUI+g5KLhIBvjHucs1JWudk4I +wnXH+HtxiWsGFXS0+Fltu7iwY7XxQfJW9+x13KtpuZq9rLLKTuWjcFXdRqxrhuCjuTbqLTjxwHUV p4AV8oigi4lBDvnTFDY78mF2zpNpbwRbYDb/zcXyial/HreRmqttWDGy6A/9zYVbVDyG/q4+V4c6d fPj7bAmT4ydqxwV7QgARiDy6dg6gPCsG/+oJREvIBp349gq1hV8kyQgE7pfDL3oX+zspT33eAVbKf 4iLdPpgAjqvbfSpIC8qQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gjKCK-0002s8-RF; Tue, 15 Jan 2019 08:35:48 +0000 Received: from mail-lj1-x242.google.com ([2a00:1450:4864:20::242]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gjKCH-0002rb-HL for linux-riscv@lists.infradead.org; Tue, 15 Jan 2019 08:35:46 +0000 Received: by mail-lj1-x242.google.com with SMTP id v1-v6so1603162ljd.0 for ; Tue, 15 Jan 2019 00:35:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=54UCKXD55YHOKubS5JS59AxRACPcjYF8KFxR/pvfPzI=; b=UUo7X7nXPfMIid3V8x1AP+JC4SGOMvIAcMSm8O5K2VG2Tca+bKxtq4TQJ8Ero5bua5 TxLcVMeGwcnbwJd7+8oDF0j4AhqJrsekXZIszbUyGeeZgYiJq+fsChTiYWLwgZ9S6i0c PnyDOKxjmGQ1qos/URa1rJz/XnSfqJbsAeZQFJOdLc7JxD+B5MgDl5jo2AHkAKtYwna8 jirqhOc+DZ2Nzbgb6DdSjAVxzmaA7+y0jBlo57UFqUNVttslsaanAlIiS2GpOJrvUGCO NCaJT1OwfZmLAA9gLYMxBrtnInM5z2FEjp5b5FzUNvrK2cL64ebOt/n7bqjutDm3/0Rh /aHg== 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:mime-version :content-transfer-encoding; bh=54UCKXD55YHOKubS5JS59AxRACPcjYF8KFxR/pvfPzI=; b=DfZpDtH8tOhjLUpS3KWTe7MtfbmgqfamNe6L2of94uQI/gXKoeJyQivlvr+H6Y5xYs 4NHjp8mF2Nw0cFWbwap+FvIq/LAYlB72+T/K/MeKhFTBr90BJYWAIXXXvPs4ySID99kG NeSossusI8CHcwfrUZ7VngoOwqp1JzfyLwz/yI9MHmpl46LiozN9Ysl/YKg7+xcxMTRG MYpan7m3mcBmRRJV7BeKVhiak3jzH/HZutzG1MMIi41tTm5hrGNPA3N9HL1yeDw7zxSo /veY6H6+oHY7uLgsj8C+0W7rZlrus9qhnUKOVoW/nLbZhdjppBzsidGzJB1fiknhr4BY GaYw== X-Gm-Message-State: AJcUukcwLhyaPO7TWvRySNRm10atE3hROrQLWYC1O7vjnZgYxqw9RcsH rUbZCyEkjqyXkzpXxCT248VbagV9cI/PCA== X-Google-Smtp-Source: ALg8bN5JSLwoATDB3fZMXpwQvqny651ZRVa+L8o6zDEpg8IlWloedmWoNdlNk/jqPKb9WaOSzYR4Dw== X-Received: by 2002:a2e:90ca:: with SMTP id o10-v6mr1877605ljg.134.1547541342295; Tue, 15 Jan 2019 00:35:42 -0800 (PST) Received: from btopel-mobl.ger.intel.com ([213.100.199.124]) by smtp.gmail.com with ESMTPSA id e14-v6sm453004ljb.31.2019.01.15.00.35.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 Jan 2019 00:35:41 -0800 (PST) From: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= To: linux-riscv@lists.infradead.org Subject: [RFC PATCH 0/3] RV64G eBPF JIT Date: Tue, 15 Jan 2019 09:35:15 +0100 Message-Id: <20190115083518.10149-1-bjorn.topel@gmail.com> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190115_003545_619098_D943F22E X-CRM114-Status: UNSURE ( 9.57 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , palmer@sifive.com, davidlee@sifive.com, daniel@iogearbox.net, netdev@vger.kernel.org Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Hi! I've been hacking on a RV64G eBPF JIT compiler, and would like some feedback. Codewise, it needs some refactoring. Currently there's a bit too much copy-and-paste going on, and I know some places where I could optimize the code generation a bit (mostly BPF_K type of instructions, dealing with immediates). From a features perspective, two things are missing: * tail calls * "far-branches", i.e. conditional branches that reach beyond 13b. The test_bpf.ko (only tested on 4.20!) passes all tests. I've done all the tests on QEMU (version 3.1.50), so no real hardware. Some questions/observations: * I've added "HAVE_EFFICIENT_UNALIGNED_ACCESS" to arch/riscv/Kconfig. Is this assumption correct? * emit_imm() just relies on lui, adds and shifts. No fancy xori cost optimizations like GCC does. * Suggestions on how to implement the tail call, given that the prologue/epilogue has variable size. I will dig into the details of mips/arm64/x86. :-) Next steps (prior patch proper) is cleaning up the code, add tail calls, and making sure that bpftool disassembly works correctly. All input are welcome. This is my first RISC-V hack, so I sure there are a lot things to improve! Thanks, Björn Björn Töpel (3): riscv: set HAVE_EFFICIENT_UNALIGNED_ACCESS riscv: add build infra for JIT compiler bpf, riscv: added eBPF JIT for RV64G arch/riscv/Kconfig | 2 + arch/riscv/Makefile | 4 + arch/riscv/net/Makefile | 5 + arch/riscv/net/bpf_jit_comp.c | 1612 +++++++++++++++++++++++++++++++++ 4 files changed, 1623 insertions(+) create mode 100644 arch/riscv/net/Makefile create mode 100644 arch/riscv/net/bpf_jit_comp.c