Re: [Bpf] Review of draft-thaler-bpf-isa-01

Alexei Starovoitov <alexei.starovoitov@gmail.com> Wed, 02 August 2023 02:55 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 54028C1519AA for <bpf@ietfa.amsl.com>; Tue, 1 Aug 2023 19:55:35 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -7.105
X-Spam-Level:
X-Spam-Status: No, score=-7.105 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, T_SCC_BODY_TEXT_LINE=-0.01, URIBL_BLOCKED=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 FYB9JPm3MKux for <bpf@ietfa.amsl.com>; Tue, 1 Aug 2023 19:55:31 -0700 (PDT)
Received: from mail-lj1-x234.google.com (mail-lj1-x234.google.com [IPv6:2a00:1450:4864:20::234]) (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 19AE0C151AFE for <bpf@ietf.org>; Tue, 1 Aug 2023 19:55:31 -0700 (PDT)
Received: by mail-lj1-x234.google.com with SMTP id 38308e7fff4ca-2b9e6cc93c6so47344771fa.2 for <bpf@ietf.org>; Tue, 01 Aug 2023 19:55:30 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690944928; x=1691549728; 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=W3KawIIdSZsZuxgabCo6IdJKUkHbfL/F//FMoh+PB+w=; b=YsdBTrSTbcZxqWcZVhQZumdMuDYewrHBF6URjWoGOp+wigQX+n4shOSxlf5t3VoZVQ 2VjLF845hq/DM10BQVjzXhrAVkfOjaPuRR0v/PjkeRY6ZKGLFYKHgqkUrm4XvII14L5d b2J2VmEIMEOGbPEgVj75lO8M5nxI1qQ5VKTW52crU3xx1eFN/IHIYH7k94+kir+YPNID kzRF5Pnq402MuA1AZ/e6ed39Q7jknecVkOrazDo4E7W/SAPNQ/Gj7Hj8RK6tF/IbRjpl P4j8MFWMkw1ry144bfLLZodMswwkjI4Ke5iUuKKkbsCpSRwUwRS15eLanPHWJaStgcQU p3ig==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690944928; x=1691549728; 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=W3KawIIdSZsZuxgabCo6IdJKUkHbfL/F//FMoh+PB+w=; b=YVvkVIxI8VnwWiCZufmORspOWzThQJ0r+AlAg2N80PX+2whFd8ib9p9GSrNbKv26bX 4DQV/HoVGxsznIzHnSUYUaD2ECRlyx66tXPkDTJUSGPefS45VCW2pV9qozOKJl3I9k7X R2/TcYgrZeg8s1CeNoBNFYy85SYMdISiNiWg582hcgoJLmwwXOh0KMy9FOOtb50T6Nm8 6YADy5ZxRLuLeBmOzt51Vva9JOx2jmYfCcVOKjvbNIC15YqDTo70hLxxkLQQNwjN0RaP YrNH9iBNanpLn4JIPcSt0trSkqL+daO0Mw+BfThuOERkAe/twbxxmJrWa+vU7gfLta+X vnJg==
X-Gm-Message-State: ABy/qLaNoTfIWE3SvT9V24WojW8UJM/Qhr13r9wJX9NdxjPsxWQXDfE/ E4EVfcGIg3+HI/SZQa6S55QCDkL54aV7jp03ofo=
X-Google-Smtp-Source: APBJJlFWHBWllQEsFDmzblSk1xOzJc9L/1BTLjjsGWOcJdSOCSZkLqFKUPChM57tbfYnTFoD+2k/w5ehEQvXz7Ot71A=
X-Received: by 2002:a2e:3c0e:0:b0:2b6:cdfb:d06a with SMTP id j14-20020a2e3c0e000000b002b6cdfbd06amr3776757lja.22.1690944928377; Tue, 01 Aug 2023 19:55:28 -0700 (PDT)
MIME-Version: 1.0
References: <CACsn0ckZO+b5bRgMZhOvx+Jn-sa0g8cBD+ug1CJEdtYxSm_hgA@mail.gmail.com> <PH7PR21MB3878D8DCEF24A5F8E52BA59DA303A@PH7PR21MB3878.namprd21.prod.outlook.com> <CAADnVQJ1fKXcsTXdCijwQzf0OVF0md-ATN5RbB3g10geyofNzA@mail.gmail.com> <CACsn0cmf22zEN9AduiRiFnQ7XhY1ABRL=SwAwmmFgxJvVZAOsg@mail.gmail.com> <CAADnVQ+O0CZQ1-5+dBiPWgZig3MVRX92PWPwNCrL7rG+4Xrbag@mail.gmail.com> <CACsn0cmvuGBKd3erDQKugygZfhT-Cu8xYBJ3hCETp6a-1HNbYw@mail.gmail.com>
In-Reply-To: <CACsn0cmvuGBKd3erDQKugygZfhT-Cu8xYBJ3hCETp6a-1HNbYw@mail.gmail.com>
From: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Date: Tue, 01 Aug 2023 19:55:17 -0700
Message-ID: <CAADnVQK8sGGA8dwFDH6bJMWv56_s8gzj0yUY5OvMQKiL6d8YHA@mail.gmail.com>
To: Watson Ladd <watsonbladd@gmail.com>
Cc: Dave Thaler <dthaler@microsoft.com>, "bpf@ietf.org" <bpf@ietf.org>, bpf <bpf@vger.kernel.org>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Archived-At: <https://mailarchive.ietf.org/arch/msg/bpf/gFnwGumOFSpHNef_GYnBGcjzKLs>
Subject: Re: [Bpf] Review of draft-thaler-bpf-isa-01
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: Wed, 02 Aug 2023 02:55:35 -0000

On Tue, Aug 1, 2023 at 7:34 PM Watson Ladd <watsonbladd@gmail.com> wrote:
>
> In reply to a long conversation:
> <snip>
> >
> > Could you please be specific which instruction in table 4 is not obvious?
>
> The question isn't obvious, the question is unambigious, and C is not
> great for this. Maybe with a reference and some text it would get
> better.
> >
> > > >
> > > > > > The good news is I think this is very fixable although tedious.
> > > > > >
> > > > > > The other thornier issues are memory model etc. But the overall structure seems good
> > > > > > and the document overall makes sense.
> > > >
> > > > What do you mean by "memory model" ?
> > > > Do you see a reference to it ? Please be specific.
> > >
> > > No, and that's the problem. Section 5.2 talks about atomic operations.
> > > I'd expect that to be paired with a description of barriers so that
> > > these work, or a big warning about when you need to use them.
> >
> > That's a good suggestion.
> > A warning paragraph that BPF ISA does not have barrier instructions
> > is necessary.
> >
> > > For
> > > clarity I'm pretty unfamiliar with bpf as a technology, and it's
> > > possible that with more knowledge this would make sense. On looking
> > > back on that I don't even know if the memory space is flat, or
> > > segmented: can I access maps through a value set to dst+offset, or
> > > must I always used index? I'm just very confused.
> >
> > flat vs segmented is an orthogonal topic.
> > We definitely need to cover it in the architecture doc.
> > BPF WG charter requires us to produce it as Informational doc eventually.
>
> Huh? If you access memory through specialized descriptors+offsets
> that's very different from arbitrary computations with addresses, even
> if they do trap. A little explanation might orient the reader to
> understand what is going on. As is I thought "ok, it's flat" and then
> saw the maps and really got thrown for a loop.

It's flat.

> >
> > As far as memory model BPF adopts LKMM (Linux Kernel Memory Model).
> > https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p0124r7.html
> >
> > We can add a reference to it from BPF ISA doc, but since
> > there are no barrier instructions at the moment the memory model
> > statement would be premature.
> > The work on "BPF Memory Model" have been ongoing for quite some time.
> > For example see:
> > https://lpc.events/event/11/contributions/941/attachments/859/1667/bpf-memory-model.2020.09.22a.pdf
> >
> > BPF Memory Model is certainly an important topic, but out of scope for ISA.
>
> I expect that an ISA defines the semantics of the instructions. Which
> absolutely includes the memory model.  Now maybe we're envisioning a
> different splitting of this information, but I don't see how it can't
> be at a different level if you want to give the instructions
> semantics.

Please read the links above.
BPF ISA is not going to define TSO, dictate weak ordering or anything
like that. It follows Linux Kernel Memory Model which is closer to
C memory model than to what HW CPUs see as memory model.
It's unlikely that we will ever introduce explicit memory barrier
instructions. More likely they will be kfuncs that will map to smp_mb(),
dma_wmb(), and friends in kernel Documentation/memory-barriers.txt.
Analogies with HW ISAs are not applicable here.