Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp5265089ybf; Wed, 4 Mar 2020 21:02:58 -0800 (PST) X-Google-Smtp-Source: ADFU+vuAwLFNU46m51W536WddZqcZIlfoSTnCBkeEMFUshytqUqk+3j7qDjA7N8zHm2Rk5YYojHq X-Received: by 2002:a05:6830:2006:: with SMTP id e6mr5203991otp.134.1583384578654; Wed, 04 Mar 2020 21:02:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583384578; cv=none; d=google.com; s=arc-20160816; b=yt5ClBN5bgknTCtUompankZ8VMxWFH+hL34f34B0w5GaT3M5w5Bc+sHnKmOTZZ7V6P 9/Ep7lcKGkj/kKEWgC2ediypEvrXuT9+BsPYf8mvmZCgB5ywtRbPOCvNvdikWsVPT88T l7UHxvjO0uyhZ3Zkzlmkj2pMiM0YWvCoDbXxxPWHA/VNVA31ZWx1ivgq1ejMsuWs8c1c MDsj03xJ1aNQv9d9lHToGYB88g52XJWwhIhVKBRSlHYpXZZbqe1PUivAJgWB33af93Qj fBf5aDZ+mlftQTjDBKqv3zVrKQkvvCEVYX/F8DHwfhVFWZDs5Lzh7SDwF1A8pLVPU/kd y8lQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=YpOwyrb2WE/CDlzT3QThQwLnDNsGkooSRHNga96mtQc=; b=Ed8/aRQ61iHrnQfhc70bZP8nk4taTgNUkTr7s1g2R5qwgTo+a6fT544nVRc6uwv6jb t6ou8pPRJRE8XaLIHnA5Gnek5wsR8AvscezPBqQRDEjCFoRhGNceG8CK/KZzIqEns5ix ey2/m4y8xXx6mSLLbzEMy8BLlJfwp4daSYCz52CvXWAV0AXrz31al2UkwV/cr6N5ZsSZ I2MtAf5ToCCqMB8dutch7ZBhnzaCAukhpTWFkFlH4gSv4g8bzFCPYXROfjUu213zkOpf oR5nCA/b2k10ZwwsWQsiV8UZZ8FuHqkGObGdNVGK3y+7L4ZbEHJghvPq3zTKY/IyTlx8 8lCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cs.washington.edu header.s=goo201206 header.b=D4mP+M6u; 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=cs.washington.edu Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j17si2673944otl.278.2020.03.04.21.02.44; Wed, 04 Mar 2020 21:02:58 -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=@cs.washington.edu header.s=goo201206 header.b=D4mP+M6u; 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=cs.washington.edu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725861AbgCEFCR (ORCPT + 99 others); Thu, 5 Mar 2020 00:02:17 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:43361 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725818AbgCEFCR (ORCPT ); Thu, 5 Mar 2020 00:02:17 -0500 Received: by mail-pg1-f194.google.com with SMTP id u12so2126338pgb.10 for ; Wed, 04 Mar 2020 21:02:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cs.washington.edu; s=goo201206; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=YpOwyrb2WE/CDlzT3QThQwLnDNsGkooSRHNga96mtQc=; b=D4mP+M6uKURXP9HP9xpBxfbWTwS2sXLCAH4XXiVTLLBY2AHKEG4zJCDy0WZMfc5Cdf 0vWrb8YgmglaHdbSRbvzwy0Ud+GY5kjFjJG5svoO6WbDsiVnX1N3h3+BPsGpiXZjFXIt IjlL0igv8nG47EYU1nWRvSzj9kcDGs1Mwl6Xc= 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=YpOwyrb2WE/CDlzT3QThQwLnDNsGkooSRHNga96mtQc=; b=N81poZB6/8BZzsacF5/2lQeYU1LI9ykLNot8SNk4uJD8OPrro7WWryQQaP0MCK2JKq HUzdn2DtUvYyG9hcfA1oGucF6O+dpI5O5Wnjy6qm4gsVdx7YnbJ2dnaxjAqmhSjY2axp bL/GhXK9JXgATFEaMZZ6wVzO+eNcgsZ6o2/EyFWwehuA4ZGFBtV017b2ktD2kveNUJ4h EzNQusJuwbbSCoVqrUKlPYk71+O3VStYh6pfB/0t3Ts4woLZxP9OqUMljN2M7U52E+xK LltqS1qm45+UbcAVehUCw8pC9jTQyWRVN67BLmYmHN+blZyvRXNfiHXFwafSHZA6QwRF a/YA== X-Gm-Message-State: ANhLgQ3EYW1km/lqG15tlRueUNTUnf75t2XuKRlwHTIVNN1ogBI0LEew PqMtNzvmRJuG7dE+v3J04g0p1Q== X-Received: by 2002:a63:4a19:: with SMTP id x25mr5914511pga.167.1583384535762; Wed, 04 Mar 2020 21:02:15 -0800 (PST) Received: from ryzen.cs.washington.edu ([2607:4000:200:11:e9fe:faad:3d84:58ea]) by smtp.gmail.com with ESMTPSA id y7sm17820466pfq.15.2020.03.04.21.02.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Mar 2020 21:02:14 -0800 (PST) From: Luke Nelson X-Google-Original-From: Luke Nelson To: bpf@vger.kernel.org Cc: Luke Nelson , Jonathan Corbet , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , Andrii Nakryiko , "David S. Miller" , Jakub Kicinski , Paul Walmsley , Palmer Dabbelt , Albert Ou , =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , Xi Wang , Mauro Carvalho Chehab , Stephen Hemminger , Rob Herring , Greg Kroah-Hartman , Jonathan Cameron , Andy Shevchenko , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-riscv@lists.infradead.org Subject: [PATCH bpf-next v5 0/4] eBPF JIT for RV32G Date: Wed, 4 Mar 2020 21:02:03 -0800 Message-Id: <20200305050207.4159-1-luke.r.nels@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This series adds an eBPF JIT for 32-bit RISC-V (RV32G) to the kernel, adapted from the RV64 JIT and the 32-bit ARM JIT. There are two main changes required for this to work compared to the RV64 JIT. First, eBPF registers are 64-bit, while RV32G registers are 32-bit. BPF registers either map directly to 2 RISC-V registers, or reside in stack scratch space and are saved and restored when used. Second, many 64-bit ALU operations do not trivially map to 32-bit operations. Operations that move bits between high and low words, such as ADD, LSH, MUL, and others must emulate the 64-bit behavior in terms of 32-bit instructions. Supported features: The RV32 JIT supports the same features and instructions as the RV64 JIT, with the following exceptions: - ALU64 DIV/MOD: Requires loops to implement on 32-bit hardware. - BPF_XADD | BPF_DW: There's no 8-byte atomic instruction in RV32. These features are also unsupported on other BPF JITs for 32-bit architectures. Testing: - lib/test_bpf.c test_bpf: Summary: 378 PASSED, 0 FAILED, [349/366 JIT'ed] test_bpf: test_skb_segment: Summary: 2 PASSED, 0 FAILED The tests that are not JITed are all due to use of 64-bit div/mod or 64-bit xadd. - tools/testing/selftests/bpf/test_verifier.c Summary: 1415 PASSED, 122 SKIPPED, 43 FAILED Tested both with and without BPF JIT hardening. This is the same set of tests that pass using the BPF interpreter with the JIT disabled. Running the BPF kernel tests / selftests on riscv32 is non-trivial, to help others reproduce the test results I made a guide here: https://github.com/lukenels/meta-linux-utils/tree/master/rv32-linux Verification and synthesis: We developed the RV32 JIT using our automated verification tool, Serval. We have used Serval in the past to verify patches to the RV64 JIT. We also used Serval to superoptimize the resulting code through program synthesis. You can find the tool and a guide to the approach and results here: https://github.com/uw-unsat/serval-bpf/tree/rv32-jit-v5 Thanks again for all the comments! Changelog: v4 -> v5: * Factored common code (build_body, bpf_int_jit_compile, etc) to bpf_jit_core.c (Björn Töpel). * Moved RV32-specific changes to bpf_jit.h from patch 1 to patch 2 (Björn Töpel). * Removed "_rv32_" from function names in JIT as it is redundant (Björn Töpel). * Added commit message to MAINTAINERS and made sure to keep entries in order (Andy Shevchenko). v3 -> v4: * Added more comments and cleaned up style nits (Björn Töpel). * Factored common code in RV64 and RV32 JITs into a separate header (Song Liu, Björn Töpel). * Added an optimization in the BPF_ALU64 BPF_ADD BPF_X case. * Updated MAINTAINERS and kernel documentation (Björn Töpel). v2 -> v3: * Added support for far jumps / branches similar to RV64 JIT. * Added support for tail calls. * Cleaned up code with more optimizations and comments. * Removed special zero-extension instruction from BPF_ALU64 case (Jiong Wang). v1 -> v2: * Added support for far conditional branches. * Added the zero-extension optimization (Jiong Wang). * Added more optimizations for operations with an immediate operand. Luke Nelson (4): riscv, bpf: factor common RISC-V JIT code riscv, bpf: add RV32G eBPF JIT bpf, doc: add BPF JIT for RV32G to BPF documentation MAINTAINERS: add entry for RV32G BPF JIT Documentation/admin-guide/sysctl/net.rst | 3 +- Documentation/networking/filter.txt | 2 +- MAINTAINERS | 13 +- arch/riscv/Kconfig | 2 +- arch/riscv/net/Makefile | 9 +- arch/riscv/net/bpf_jit.h | 514 +++++++ arch/riscv/net/bpf_jit_comp32.c | 1310 +++++++++++++++++ .../net/{bpf_jit_comp.c => bpf_jit_comp64.c} | 605 +------- arch/riscv/net/bpf_jit_core.c | 166 +++ 9 files changed, 2018 insertions(+), 606 deletions(-) create mode 100644 arch/riscv/net/bpf_jit.h create mode 100644 arch/riscv/net/bpf_jit_comp32.c rename arch/riscv/net/{bpf_jit_comp.c => bpf_jit_comp64.c} (69%) create mode 100644 arch/riscv/net/bpf_jit_core.c Cc: Jonathan Corbet Cc: Alexei Starovoitov Cc: Daniel Borkmann Cc: Martin KaFai Lau Cc: Song Liu Cc: Yonghong Song Cc: Andrii Nakryiko Cc: "David S. Miller" Cc: Jakub Kicinski Cc: Paul Walmsley Cc: Palmer Dabbelt Cc: Albert Ou Cc: "Björn Töpel" Cc: Luke Nelson Cc: Xi Wang Cc: Mauro Carvalho Chehab Cc: Stephen Hemminger Cc: Rob Herring Cc: Greg Kroah-Hartman Cc: Jonathan Cameron Cc: Andy Shevchenko Cc: linux-doc@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: netdev@vger.kernel.org Cc: bpf@vger.kernel.org Cc: linux-riscv@lists.infradead.org -- 2.20.1