Re: [Bpf] [PATCH bpf-next v2] bpf, docs: Improve English readability
Alexei Starovoitov <alexei.starovoitov@gmail.com> Thu, 06 July 2023 23:14 UTC
Return-Path: <alexei.starovoitov@gmail.com>
X-Original-To: bpf@ietfa.amsl.com
Delivered-To: bpf@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id AFC72C151091 for <bpf@ietfa.amsl.com>; Thu, 6 Jul 2023 16:14:18 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -7.096
X-Spam-Level:
X-Spam-Status: No, score=-7.096 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_HI=-5, RCVD_IN_ZEN_BLOCKED_OPENDNS=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_DBL_BLOCKED_OPENDNS=0.001, URIBL_ZEN_BLOCKED_OPENDNS=0.001] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com
Received: from mail.ietf.org ([50.223.129.194]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id EQAiqeCrIpY8 for <bpf@ietfa.amsl.com>; Thu, 6 Jul 2023 16:14:18 -0700 (PDT)
Received: from mail-lj1-x22c.google.com (mail-lj1-x22c.google.com [IPv6:2a00:1450:4864:20::22c]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 00151C151082 for <bpf@ietf.org>; Thu, 6 Jul 2023 16:14:17 -0700 (PDT)
Received: by mail-lj1-x22c.google.com with SMTP id 38308e7fff4ca-2b6a16254a4so18822931fa.0 for <bpf@ietf.org>; Thu, 06 Jul 2023 16:14:17 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688685256; x=1691277256; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=VxB9JuP2WVlEJH2kCW8mIXA6VO88USDyMaG1Y1/Q4t0=; b=ZTtCgYCNyojtR5MN7KzcFTTTRUw1P/qNmoRXNugD+XCeL1WTgCoaTrZ0R1X3CiTumy EXt2OpQIVARrMkkxVYicQO2ulKiRrXdJoyM4eYLjL+3+ZhS/TJij8EA8NCY2NS/5Y7+Q tc7yYF2F1hT+58gEt0EW5ZGe+R18tf+7qbD0MXkQ6AO4d6lK1I4o61sA8wLt7uEhOSa5 oU3aHhUSHnYea5Nz5TV0HS0Wnd1TGhjSqaPOXb5ZrLU2+okyuC50JXHxhgg5FORuDJzl 9bKbFdRSOeSmcqyh7dhc9SlBjr6SEhOanGpWRs4J+AO7dViO4UVh83tsyXx8ZiCB/DgZ rmTQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688685256; x=1691277256; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VxB9JuP2WVlEJH2kCW8mIXA6VO88USDyMaG1Y1/Q4t0=; b=Rbq8FCLvpYQzeqEQdgzO3/ajmbzI4zYbIW0rjhkt5fAJESvQbzx9ACwH1EVsKGmqOK AkpVqT5FK1JY29547k3PPp5FzY0Tdyviu0S///H3qdFJGDUKrBmf6M5/cswSq/UNU3HP 92V/kgo5xJOUegNw3zjHrtKfeUv5Z7scHg1t2nXN7q/cLUwl3vxT8gyXgvir3GCURMiv ztHJ61RSxaut8rT+GEdTJ09MvWkP756AQufTMeJRJOCdRWy0mbW/xQly4tj8vusZgHRq L+T63GezyvngwCTfp2wGWShF+0N4zc6tQRKRjFmpoEJQcR+SaAvUOEbbimM6zEgpI7gt uAHQ==
X-Gm-Message-State: ABy/qLaa2JW33CSPmog7/djA0OkZCxrBjvadkt2YRofr+2xgH2M0L8or xPQuq14EiGtbDM2NXdLi7tbi6dhf9pAXdQ1T1kE=
X-Google-Smtp-Source: APBJJlHfcS/fXyytdaBG/ynEG/P+T19cxdqgrZHur5B4fd47ojEFQUBcT126qdjL0lxRPTW+R9bgTgILOb5ktXJV9gU=
X-Received: by 2002:a2e:9104:0:b0:2b6:cdfb:d06a with SMTP id m4-20020a2e9104000000b002b6cdfbd06amr2426704ljg.22.1688685255508; Thu, 06 Jul 2023 16:14:15 -0700 (PDT)
MIME-Version: 1.0
References: <20230706160537.1309-1-dthaler1968@googlemail.com> <20230706204159.7tzacql7wdk3yszc@macbook-pro-8.dhcp.thefacebook.com> <PH7PR21MB3878EA22602A94F1C308CF33A32CA@PH7PR21MB3878.namprd21.prod.outlook.com>
In-Reply-To: <PH7PR21MB3878EA22602A94F1C308CF33A32CA@PH7PR21MB3878.namprd21.prod.outlook.com>
From: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Date: Thu, 06 Jul 2023 16:14:04 -0700
Message-ID: <CAADnVQ+gLnsOVj9s4zpAP6+U6nFHYm6GVZ1FteRac=ZaJvpfDg@mail.gmail.com>
To: Dave Thaler <dthaler@microsoft.com>, "Jose E. Marchesi" <jose.marchesi@oracle.com>
Cc: Dave Thaler <dthaler1968@googlemail.com>, "bpf@vger.kernel.org" <bpf@vger.kernel.org>, "bpf@ietf.org" <bpf@ietf.org>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Archived-At: <https://mailarchive.ietf.org/arch/msg/bpf/-NrwjA_6EHQ8y83cMZZGzbT8-wc>
Subject: Re: [Bpf] [PATCH bpf-next v2] bpf, docs: Improve English readability
X-BeenThere: bpf@ietf.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: Discussion of BPF/eBPF standardization efforts within the IETF <bpf.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/bpf>, <mailto:bpf-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/bpf/>
List-Post: <mailto:bpf@ietf.org>
List-Help: <mailto:bpf-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/bpf>, <mailto:bpf-request@ietf.org?subject=subscribe>
X-List-Received-Date: Thu, 06 Jul 2023 23:14:18 -0000
On Thu, Jul 6, 2023 at 3:04 PM Dave Thaler <dthaler@microsoft.com> wrote: > > > -----Original Message----- > > From: Alexei Starovoitov <alexei.starovoitov@gmail.com> > > Sent: Thursday, July 6, 2023 1:42 PM > > To: Dave Thaler <dthaler1968@googlemail.com> > > Cc: bpf@vger.kernel.org; bpf@ietf.org; Dave Thaler > > <dthaler@microsoft.com> > > Subject: Re: [PATCH bpf-next v2] bpf, docs: Improve English readability > > > > On Thu, Jul 06, 2023 at 04:05:37PM +0000, Dave Thaler wrote: > > > From: Dave Thaler <dthaler@microsoft.com> > > > > > > Signed-off-by: Dave Thaler <dthaler@microsoft.com> > > > -- > > > V1 -> V2: addressed comments from Alexei > > > --- > > > Documentation/bpf/instruction-set.rst | 59 ++++++++++++++++++++------- > > > Documentation/bpf/linux-notes.rst | 5 +++ > > > 2 files changed, 50 insertions(+), 14 deletions(-) > > > > > > diff --git a/Documentation/bpf/instruction-set.rst > > > b/Documentation/bpf/instruction-set.rst > > > index 751e657973f..740989f4c1e 100644 > > > --- a/Documentation/bpf/instruction-set.rst > > > +++ b/Documentation/bpf/instruction-set.rst > > > @@ -7,6 +7,9 @@ eBPF Instruction Set Specification, v1.0 > > > > > > This document specifies version 1.0 of the eBPF instruction set. > > > > > > +The eBPF instruction set consists of eleven 64 bit registers, a > > > +program counter, and an implementation-specific amount (e.g., 512 bytes) > > of stack space. > > > + > > > Documentation conventions > > > ========================= > > > > > > @@ -27,12 +30,24 @@ The eBPF calling convention is defined as: > > > * R6 - R9: callee saved registers that function calls will preserve > > > * R10: read-only frame pointer to access stack > > > > > > -R0 - R5 are scratch registers and eBPF programs needs to spill/fill > > > them if -necessary across calls. > > > +Registers R0 - R5 are caller-saved registers, meaning the BPF program > > > +needs to either spill them to the BPF stack or move them to callee > > > +saved registers if these arguments are to be reused across multiple > > > +function calls. Spilling means that the value in the register is > > > +moved to the BPF stack. The reverse operation of moving the variable > > from the BPF stack to the register is called filling. > > > +The reason for spilling/filling is due to the limited number of registers. > > > > imo this extended explanation goes too far. > > It's also not entirely correct. We could have an ISA with limited number of > > registers where every register is callee saved. A bit absurd, but possible. > > Or went with SPARC style register windows. > > At https://lore.kernel.org/bpf/20220930221624.mqjrzmdxc6etkadm@macbook-pro-4.dhcp.thefacebook.com/ you said about the above > "I like above clarification though." That was on "30 Sep 2022". I like to change my mind often enough to confuse everyone :) > I think it's important for interoperability to define which registers are caller-saved > and which are not, so a compiler (or even verifier) can be used for multiple runtimes. but it really doesn't belong in the ISA doc. We've discussed it at length. We need the psABI doc. ISA doc is a description of instructions and _not_ how they shape into functions and programs. More below. > > > > + > > > +Upon entering execution of an eBPF program, registers R1 - R5 > > > +initially can contain the input arguments for the program (similar to the > > argc/argv pair for a typical C program). > > > > argc/argv is only for main(). We don't have main() concept in BPF ISA. > > argc/argv is also not a property of ISA. > > That's why it's "similar to". I think the analogy helps understanding for new readers. argc is a K&R C thing. Not even a calling convention. That sentence is a combination of analogies from different areas. argc could be interpreted that the first argument is a count and a second argument is an array. See the confusion it might cause? > > > > +The actual number of registers used, and their meaning, is defined by > > > +the program type; for example, a networking program might have an > > > +argument that includes network packet data and/or metadata. > > > > that makes things even more confusing. > > > > tbh none of the above changes make the doc easier to read. > > The program type defines the number and meaning of any arguments passed > to the program. In the ISA that means the number of registered used to > pass inputs, and their contents. Not at all. ISA is an instruction set only and this doc is for ISA. What different program types should accept belongs in a different doc. And it's not a psABI doc. More below. > > > > Instruction encoding > > > ==================== > > > > > > +An eBPF program is a sequence of instructions. > > > > Kinda true, but it opens the door for plenty of bike shedding. > > Is it contiguous sequence? what about subprograms? > > Is BPF program a one function or multiple functions? > > The term "subprogram" is not currently part of the > instruction-set.rst doc. "Program-local functions" > are, and the text says they're part of the same BPF program. > Hence the doc already says a BPF program can have multiple > functions. Yes. It's a mess, but we must not make it worse. instruction-set.rst is for instructions. Definition of BPF program belongs to a different doc. > > etc. > > Just not worth it. > > This is ISA doc. > > > > > + > > > eBPF has two instruction encodings: > > > > > > * the basic instruction encoding, which uses 64 bits to encode an > > > instruction @@ -74,7 +89,7 @@ For example:: > > > 07 1 0 00 00 11 22 33 44 r1 += 0x11223344 // big > > > > > > Note that most instructions do not use all of the fields. > > > -Unused fields shall be cleared to zero. > > > +Unused fields must be set to zero. > > > > How is this better? > > It uses the language common in RFCs. > > > > As discussed below in `64-bit immediate instructions`_, a 64-bit > > > immediate instruction uses a 64-bit immediate value that is constructed as > > follows. > > > @@ -103,7 +118,9 @@ instruction are reserved and shall be cleared to > > zero. > > > Instruction classes > > > ------------------- > > > > > > -The three LSB bits of the 'opcode' field store the instruction class: > > > +The encoding of the 'opcode' field varies and can be determined from > > > +the three least significant bits (LSB) of the 'opcode' field which > > > +holds the "instruction class", as follows: > > > > same question. Don't see an improvement in wording. > > 1. The acronym LSB was not defined and does not have an asterisk by it in > the https://www.rfc-editor.org/materials/abbrev.expansion.txt list. > > 2. "LSB bits" is redundant. > > 3. Putting "instruction class" in quotes is common when defining by use > the first time. ok. fair enough. > > linux-notes.rst is not in the ISA doc. The ISA doc says the value is implementation > defined. linux-notes.rst says what Linux does for things the ISA doc leaves up > to the implementation. I see no value in "Linux currently supports 512 bytes of stack space" sentence. It's too ambiguous to be useful. instruction-set.rst is a description of ISA. We should remove things from it that don't belong instead of doubling down on the current mess. we need the psABI doc that will not be standardized as Jose recommended. That doc will describe recommended calling convention, argument promotion, stack usage, relocation, function/subprogram definition, etc psABI probably should include BTF.ext description, but I'm open to alternatives. BPF program types supported by the kernel is a 3rd document. There we can explain that XDP prog takes a single ctx argument and it's a pointer to ... Such info is linux specific. Based on ISA and psABI one can come up with different program/map types and semantics of their arguments while being fully compliant with ISA and psABI docs. Such doc can start its journey in linux-notes.rst and then split, if necessary.
- [Bpf] [PATCH bpf-next v2] bpf, docs: Improve Engl… Dave Thaler
- Re: [Bpf] [PATCH bpf-next v2] bpf, docs: Improve … Alexei Starovoitov
- Re: [Bpf] [PATCH bpf-next v2] bpf, docs: Improve … Dave Thaler
- Re: [Bpf] [PATCH bpf-next v2] bpf, docs: Improve … Alexei Starovoitov