From patchwork Mon Jan 3 18:35:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12702732 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E49CC4332F for ; Mon, 3 Jan 2022 18:36:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233666AbiACSgO (ORCPT ); Mon, 3 Jan 2022 13:36:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235842AbiACSgK (ORCPT ); Mon, 3 Jan 2022 13:36:10 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86C0DC061785; Mon, 3 Jan 2022 10:36:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=qs5t1JYPABDfY8UHpgPdePHyWxVleAN0r9HqvFjtxPY=; b=LPCFd7r08dh9uh2iLCGerVaKlW RT+tRZDnDjZznd7jcy3/FrHNeB79QQ8AnXl2Z2q2g6fTKLdr6CDV0UbdPNaU+3s8YwG3JpM0boQkv 9DEUvjHAna0NQ1znEbDhTV5Crs/V3S0EecE7SMAG4DEHFp9aRzN+e65SDVC/COd1nc13Ouipud6tC danyqcp2RvNOjUp23Rxc8rGboaVATSElZZnUws5mUbep7FrOXhrt8WsfOOc5aXJ6rDCPoK78zquUo VI7j9GU+O8Oz2ZAXznaiJyL17KQs4UWHJp/duKNCs2aCakJ90WENPTEoI4D8rKyCuyvnVcV6D5utU TI3C1Cow==; Received: from [2001:4bb8:184:3f95:b8f7:97d6:6b53:b9be] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1n4SBf-009qRX-PS; Mon, 03 Jan 2022 18:36:04 +0000 From: Christoph Hellwig To: Jonathan Corbet , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , linux-doc@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH 1/6] bpf, docs: Add a setion to explain the basic instruction encoding Date: Mon, 3 Jan 2022 19:35:51 +0100 Message-Id: <20220103183556.41040-2-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220103183556.41040-1-hch@lst.de> References: <20220103183556.41040-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net The eBPF instruction set document does not currently document the basic instruction encoding. Add a section to do that. Signed-off-by: Christoph Hellwig --- Documentation/bpf/instruction-set.rst | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Documentation/bpf/instruction-set.rst b/Documentation/bpf/instruction-set.rst index 1af51143ff9f6..80f42984b5942 100644 --- a/Documentation/bpf/instruction-set.rst +++ b/Documentation/bpf/instruction-set.rst @@ -19,8 +19,22 @@ The eBPF calling convention is defined as: R0 - R5 are scratch registers and eBPF programs needs to spill/fill them if necessary across calls. +Instruction encoding +==================== + +eBPF uses 64-bit instructions with the following encoding: + + ============= ======= =============== ==================== ============ + 32 bits (MSB) 16 bits 4 bits 4 bits 8 bits (LSB) + ============= ======= =============== ==================== ============ + immediate offset source register destination register opcode + ============= ======= =============== ==================== ============ + +Note that most instructions do not use all of the fields. +Unused fields shall be cleared to zero. + Instruction classes -=================== +------------------- The three LSB bits of the 'opcode' field store the instruction class: From patchwork Mon Jan 3 18:35:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12702733 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 10649C43219 for ; Mon, 3 Jan 2022 18:36:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235745AbiACSgQ (ORCPT ); Mon, 3 Jan 2022 13:36:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233753AbiACSgL (ORCPT ); Mon, 3 Jan 2022 13:36:11 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA282C061792; Mon, 3 Jan 2022 10:36:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=7+pxu6cDD4g2E8lG+K1S7eqbHuoDNUuSCiRxnDV66sg=; b=MqA3Hqi4WE303YbcKTI4usg9TS M4FJ98wRqebNFJlP1onyD495XPZhh2ddIv5RwcK7yPGotXDJkfc5APn/6F1ytF1BKSgIvk8hk2gI7 I0ByNfV/TjdWPjTmocznGnoXp5yR18s4skUTDVl0W1pyD/daS1Xa/AGI//7G8APSGYsTaOwAJlkSU GTJ+slZcojF7G23bTmb49LzXLB4uJuNGfjdGuHv56SU8A9vj+O96OZwe5mWxQRqAitZZd1SDSOyvG vfWB6CNO+2vOSrx5EbTpitLfSgWAT6BgIxSKrsC2hGP2QmO1zU145YgYaw1mj06MlRCJgZLU+/OAo oEZoHM+Q==; Received: from [2001:4bb8:184:3f95:b8f7:97d6:6b53:b9be] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1n4SBi-009qRr-IN; Mon, 03 Jan 2022 18:36:07 +0000 From: Christoph Hellwig To: Jonathan Corbet , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , linux-doc@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH 2/6] bpf, docs: Add subsections for ALU and JMP instructions Date: Mon, 3 Jan 2022 19:35:52 +0100 Message-Id: <20220103183556.41040-3-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220103183556.41040-1-hch@lst.de> References: <20220103183556.41040-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Add a little more stucture to the ALU/JMP documentation with sections and improve the example text. Signed-off-by: Christoph Hellwig --- Documentation/bpf/instruction-set.rst | 52 ++++++++++++++++----------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/Documentation/bpf/instruction-set.rst b/Documentation/bpf/instruction-set.rst index 80f42984b5942..03bf3c6c55771 100644 --- a/Documentation/bpf/instruction-set.rst +++ b/Documentation/bpf/instruction-set.rst @@ -74,7 +74,13 @@ The 4th bit encodes the source operand: The four MSB bits store the operation code. -For class BPF_ALU or BPF_ALU64: + +Arithmetic instructions +----------------------- + +BPF_ALU uses 32-bit wide operands while BPF_ALU64 uses 64-bit wide operands for +otherwise identical operations. +The code field encodes the operation as below: ======== ===== ========================= code value description @@ -95,7 +101,29 @@ For class BPF_ALU or BPF_ALU64: BPF_END 0xd0 endianness conversion ======== ===== ========================= -For class BPF_JMP or BPF_JMP32: +BPF_ADD | BPF_X | BPF_ALU means:: + + dst_reg = (u32) dst_reg + (u32) src_reg; + +BPF_ADD | BPF_X | BPF_ALU64 means:: + + dst_reg = dst_reg + src_reg + +BPF_XOR | BPF_K | BPF_ALU means:: + + src_reg = (u32) src_reg ^ (u32) imm32 + +BPF_XOR | BPF_K | BPF_ALU64 means:: + + src_reg = src_reg ^ imm32 + + +Jump instructions +----------------- + +BPF_JMP32 uses 32-bit wide operands while BPF_JMP uses 64-bit wide operands for +otherwise identical operations. +The code field encodes the operation as below: ======== ===== ========================= code value description @@ -116,24 +144,8 @@ For class BPF_JMP or BPF_JMP32: BPF_JSLE 0xd0 signed '<=' ======== ===== ========================= -So BPF_ADD | BPF_X | BPF_ALU means:: - - dst_reg = (u32) dst_reg + (u32) src_reg; - -Similarly, BPF_XOR | BPF_K | BPF_ALU means:: - - src_reg = (u32) src_reg ^ (u32) imm32 - -eBPF is using BPF_MOV | BPF_X | BPF_ALU to represent A = B moves. BPF_ALU64 -is used to mean exactly the same operations as BPF_ALU, but with 64-bit wide -operands instead. So BPF_ADD | BPF_X | BPF_ALU64 means 64-bit addition, i.e.:: - - dst_reg = dst_reg + src_reg - -BPF_JMP | BPF_EXIT means function exit only. The eBPF program needs to store -the return value into register R0 before doing a BPF_EXIT. Class 6 is used as -BPF_JMP32 to mean exactly the same operations as BPF_JMP, but with 32-bit wide -operands for the comparisons instead. +The eBPF program needs to store the return value into register R0 before doing a +BPF_EXIT. Load and store instructions From patchwork Mon Jan 3 18:35:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12702734 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 81783C4332F for ; Mon, 3 Jan 2022 18:36:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235874AbiACSgR (ORCPT ); Mon, 3 Jan 2022 13:36:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235825AbiACSgN (ORCPT ); Mon, 3 Jan 2022 13:36:13 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1458C061799; Mon, 3 Jan 2022 10:36:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=dkBtKqpQqy6FnXC+2071cnCfXFMaEXuDdAHnYiHoYDg=; b=e5AdriocHOagnC/Eihbz09ZKkt XdK4/K8wZN/umkcRnPF8zeqN/fACqB+gMLjOWcJ/9xMrL6xo9I0+k+QvpFLCSKnn6/nZsVZsb/FuX XA6iOYX8ine9/je/8KuhTUmbnIsjdRzRhIE1bUK8VKfJPLmQeCPIvm7EAGSTcazXKX5B93gfhIRYo tSzBALnesvisyQXjM70UQ5+F0zj005Gdk6qJFeNvRXZpVsrXKhTrcJtv7TSEkANI9/NRe7pzGHdg9 D+ZUydXf34XNwIcJOaWBWnQT7Ol5jZ20RJHgI1Pq+tY+DBOLuTdZIG18wR7QN/ivbLtthayhK6HtH Ua/ZUrQw==; Received: from [2001:4bb8:184:3f95:b8f7:97d6:6b53:b9be] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1n4SBl-009qSE-9c; Mon, 03 Jan 2022 18:36:09 +0000 From: Christoph Hellwig To: Jonathan Corbet , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , linux-doc@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH 3/6] bpf, docs: Document the opcode classes Date: Mon, 3 Jan 2022 19:35:53 +0100 Message-Id: <20220103183556.41040-4-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220103183556.41040-1-hch@lst.de> References: <20220103183556.41040-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Add a description for each opcode class. Signed-off-by: Christoph Hellwig --- Documentation/bpf/instruction-set.rst | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Documentation/bpf/instruction-set.rst b/Documentation/bpf/instruction-set.rst index 03bf3c6c55771..2987cbb07f7f6 100644 --- a/Documentation/bpf/instruction-set.rst +++ b/Documentation/bpf/instruction-set.rst @@ -38,18 +38,18 @@ Instruction classes The three LSB bits of the 'opcode' field store the instruction class: - ========= ===== - class value - ========= ===== - BPF_LD 0x00 - BPF_LDX 0x01 - BPF_ST 0x02 - BPF_STX 0x03 - BPF_ALU 0x04 - BPF_JMP 0x05 - BPF_JMP32 0x06 - BPF_ALU64 0x07 - ========= ===== + ========= ===== =============================== + class value description + ========= ===== =============================== + BPF_LD 0x00 non-standard load operations + BPF_LDX 0x01 load into register operations + BPF_ST 0x02 store from immediate operations + BPF_STX 0x03 store from register operations + BPF_ALU 0x04 32-bit arithmetic operations + BPF_JMP 0x05 64-bit jump operations + BPF_JMP32 0x06 32-bit jump operations + BPF_ALU64 0x07 64-bit arithmetic operations + ========= ===== =============================== Arithmetic and jump instructions ================================ From patchwork Mon Jan 3 18:35:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12702735 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4A619C433F5 for ; Mon, 3 Jan 2022 18:36:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235814AbiACSg0 (ORCPT ); Mon, 3 Jan 2022 13:36:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235811AbiACSgR (ORCPT ); Mon, 3 Jan 2022 13:36:17 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BA8AC061784; Mon, 3 Jan 2022 10:36:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=budVXNBVPihdySFLw09Mck8of6+GoN4AceRFnzdYfvE=; b=R+P34GJCnHZqHiggcv0j5uXpww Jbf/SSP6SQROuncqB/ajpqBkPlYR/Yx6E45Xfe/KgH9tvBjTraMDBLJwn7pdXJonXqQ8/cTs9u8YI hPcr7JY6kRxVEX5SGGPxViliIMfZXm4DVf8QJL2iPhHxvu6ik/ky6dmmUKuw0js1xTkX7BktUfE/e xFtLyraAO2T/yRwvmGKcpzfHP495cRlxTQ2O6077uRGqUk7B8CT+IV+/wygJepY+Dbu2BVZ+dvS4J /d+ZJaZDtqwCRpvOy5k/NboLdH5MCsv7PYAoaa/6mvFBpD75x+fejDY3GS+g5+ICyUUzcjKoNSKQu xqPjPpCw==; Received: from [2001:4bb8:184:3f95:b8f7:97d6:6b53:b9be] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1n4SBn-009qSl-Te; Mon, 03 Jan 2022 18:36:12 +0000 From: Christoph Hellwig To: Jonathan Corbet , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , linux-doc@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH 4/6] bpf, docs: Fully document the ALU opcodes Date: Mon, 3 Jan 2022 19:35:54 +0100 Message-Id: <20220103183556.41040-5-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220103183556.41040-1-hch@lst.de> References: <20220103183556.41040-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Add pseudo-code to document all the different BPF_ALU / BPF_ALU64 opcodes. Signed-off-by: Christoph Hellwig --- Documentation/bpf/instruction-set.rst | 30 +++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/Documentation/bpf/instruction-set.rst b/Documentation/bpf/instruction-set.rst index 2987cbb07f7f6..efba4d1931853 100644 --- a/Documentation/bpf/instruction-set.rst +++ b/Documentation/bpf/instruction-set.rst @@ -82,24 +82,24 @@ BPF_ALU uses 32-bit wide operands while BPF_ALU64 uses 64-bit wide operands for otherwise identical operations. The code field encodes the operation as below: - ======== ===== ========================= + ======== ===== ========================== code value description - ======== ===== ========================= - BPF_ADD 0x00 - BPF_SUB 0x10 - BPF_MUL 0x20 - BPF_DIV 0x30 - BPF_OR 0x40 - BPF_AND 0x50 - BPF_LSH 0x60 - BPF_RSH 0x70 - BPF_NEG 0x80 - BPF_MOD 0x90 - BPF_XOR 0xa0 - BPF_MOV 0xb0 mov reg to reg + ======== ===== ========================== + BPF_ADD 0x00 dst += src + BPF_SUB 0x10 dst -= src + BPF_MUL 0x20 dst \*= src + BPF_DIV 0x30 dst /= src + BPF_OR 0x40 dst \|= src + BPF_AND 0x50 dst &= src + BPF_LSH 0x60 dst <<= src + BPF_RSH 0x70 dst >>= src + BPF_NEG 0x80 dst = ~src + BPF_MOD 0x90 dst %= src + BPF_XOR 0xa0 dst ^= src + BPF_MOV 0xb0 dst = src BPF_ARSH 0xc0 sign extending shift right BPF_END 0xd0 endianness conversion - ======== ===== ========================= + ======== ===== ========================== BPF_ADD | BPF_X | BPF_ALU means:: From patchwork Mon Jan 3 18:35:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12702736 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 48516C4332F for ; Mon, 3 Jan 2022 18:36:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235725AbiACSgb (ORCPT ); Mon, 3 Jan 2022 13:36:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235861AbiACSgT (ORCPT ); Mon, 3 Jan 2022 13:36:19 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 732DBC061799; Mon, 3 Jan 2022 10:36:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=YothgiYWmU2Bn16pVq6rc9tCxo9MCVxckYP/8PpXRT0=; b=BygqRBDY8OUsgOVKOeQ4iiDbkp k5Vg261sr2p70bvs9PSFAJzKEyhe9S+6LYxApLj1/ANP5lUPBUQcqOCAD7Tk/5xJWsPK79zcKtHb1 ZCCcgNDVXhLRMXAm4XogxokTfRRUfyhTE1pNGqwY6NB8Kh0li4dXLIy3jOIzvIvCkqIz0t0ukHu1+ XJe1rFOhvZ0CxOowWI6b3lfQMNMu7quTyMFMKvkZ5wFfcwsx51yZC80LjW1ea+fBNNYKjBR+F99nb IKsBQhMfAxcyCF/zqLHBbiW9BxOuKlMEhu6PZ4k1GcRHDbZBN7lTMzKzTLi3h5BQmUIEjB5zhAleo drbVfKqw==; Received: from [2001:4bb8:184:3f95:b8f7:97d6:6b53:b9be] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1n4SBq-009qTm-MG; Mon, 03 Jan 2022 18:36:15 +0000 From: Christoph Hellwig To: Jonathan Corbet , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , linux-doc@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH 5/6] bpf, docs: Fully document the JMP opcodes Date: Mon, 3 Jan 2022 19:35:55 +0100 Message-Id: <20220103183556.41040-6-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220103183556.41040-1-hch@lst.de> References: <20220103183556.41040-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Add pseudo-code to document all the different BPF_JMP / BPF_JMP64 opcodes. Signed-off-by: Christoph Hellwig --- Documentation/bpf/instruction-set.rst | 34 +++++++++++++-------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/Documentation/bpf/instruction-set.rst b/Documentation/bpf/instruction-set.rst index efba4d1931853..88e8d6a9195cd 100644 --- a/Documentation/bpf/instruction-set.rst +++ b/Documentation/bpf/instruction-set.rst @@ -125,24 +125,24 @@ BPF_JMP32 uses 32-bit wide operands while BPF_JMP uses 64-bit wide operands for otherwise identical operations. The code field encodes the operation as below: - ======== ===== ========================= - code value description - ======== ===== ========================= - BPF_JA 0x00 BPF_JMP only - BPF_JEQ 0x10 - BPF_JGT 0x20 - BPF_JGE 0x30 - BPF_JSET 0x40 - BPF_JNE 0x50 jump '!=' - BPF_JSGT 0x60 signed '>' - BPF_JSGE 0x70 signed '>=' + ======== ===== ========================= ============ + code value description notes + ======== ===== ========================= ============ + BPF_JA 0x00 PC += off BPF_JMP only + BPF_JEQ 0x10 PC += off if dst == src + BPF_JGT 0x20 PC += off if dst > src unsigned + BPF_JGE 0x30 PC += off if dst >= src unsigned + BPF_JSET 0x40 PC += off if dst & src + BPF_JNE 0x50 PC += off if dst != src + BPF_JSGT 0x60 PC += off if dst > src signed + BPF_JSGE 0x70 PC += off if dst >= src signed BPF_CALL 0x80 function call - BPF_EXIT 0x90 function return - BPF_JLT 0xa0 unsigned '<' - BPF_JLE 0xb0 unsigned '<=' - BPF_JSLT 0xc0 signed '<' - BPF_JSLE 0xd0 signed '<=' - ======== ===== ========================= + BPF_EXIT 0x90 function / program return BPF_JMP only + BPF_JLT 0xa0 PC += off if dst < src unsigned + BPF_JLE 0xb0 PC += off if dst <= src unsigned + BPF_JSLT 0xc0 PC += off if dst < src signed + BPF_JSLE 0xd0 PC += off if dst <= src signed + ======== ===== ========================= ============ The eBPF program needs to store the return value into register R0 before doing a BPF_EXIT. From patchwork Mon Jan 3 18:35:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12702737 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75069C433F5 for ; Mon, 3 Jan 2022 18:36:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235911AbiACSgf (ORCPT ); Mon, 3 Jan 2022 13:36:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235919AbiACSg3 (ORCPT ); Mon, 3 Jan 2022 13:36:29 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8C43C061394; Mon, 3 Jan 2022 10:36:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=bq5JLgDM3t8BkrOTMe1SQwbqoVsrqTMzIyC33K4R1uk=; b=oBkEjgAqF7FRXTYDvwnv1mpZzB DCxEujsulSn/6eHyj43SIeTXqIWRJHc+Oo89mSx9+Sa4aNiJ1bfNIsPq+pUTSbfF9SH/GRIzpwGtI gBD4eEGSuMpYffuAvFK7T4tclIOqvqx7i5tvwjh9lMp+UM2bEVtgGfhM4UORkx1snnFV8cipq4XG4 YbuPaYUW2+KM3T+waONpNi0LnkmALB9dG6gEAiG6JjT9pjMavTB3p06YCuD6nGLa+BXnsBw2PROeM KKv0+YJZHZS54YAbaGjb4oV2hF1q0ZcwAcU0FOAwwMuNpX36Ec2nUXRFlV9LBdy7eG/SG7bYnV+Vu 5SgD96gA==; Received: from [2001:4bb8:184:3f95:b8f7:97d6:6b53:b9be] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1n4SBt-009qUs-Gv; Mon, 03 Jan 2022 18:36:18 +0000 From: Christoph Hellwig To: Jonathan Corbet , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , linux-doc@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH 6/6] bpf, docs: Fully document the JMP mode modifiers Date: Mon, 3 Jan 2022 19:35:56 +0100 Message-Id: <20220103183556.41040-7-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220103183556.41040-1-hch@lst.de> References: <20220103183556.41040-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Add a description for all the modifiers. Signed-off-by: Christoph Hellwig --- Documentation/bpf/instruction-set.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Documentation/bpf/instruction-set.rst b/Documentation/bpf/instruction-set.rst index 88e8d6a9195cd..3704836fe6df6 100644 --- a/Documentation/bpf/instruction-set.rst +++ b/Documentation/bpf/instruction-set.rst @@ -173,15 +173,15 @@ The size modifier is one of: The mode modifier is one of: - ============= ===== ===================== + ============= ===== ==================================== mode modifier value description - ============= ===== ===================== + ============= ===== ==================================== BPF_IMM 0x00 used for 64-bit mov - BPF_ABS 0x20 - BPF_IND 0x40 - BPF_MEM 0x60 + BPF_ABS 0x20 legacy BPF packet access + BPF_IND 0x40 legacy BPF packet access + BPF_MEM 0x60 all normal load and store operations BPF_ATOMIC 0xc0 atomic operations - ============= ===== ===================== + ============= ===== ==================================== BPF_MEM | | BPF_STX means::