[Bpf] Re: [PATCH bpf-next] docs/bpf: Document some special sdiv/smod operations
Dave Thaler <dthaler1968@googlemail.com> Tue, 01 October 2024 19:55 UTC
Return-Path: <dthaler1968@googlemail.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 1493EC151068 for <bpf@ietfa.amsl.com>; Tue, 1 Oct 2024 12:55:22 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.854
X-Spam-Level:
X-Spam-Status: No, score=-1.854 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_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_BLOCKED=0.001, 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=googlemail.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 b5yi9arXfnMm for <bpf@ietfa.amsl.com>; Tue, 1 Oct 2024 12:55:18 -0700 (PDT)
Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (P-256) server-digest SHA256) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id C18EFC14F703 for <bpf@ietf.org>; Tue, 1 Oct 2024 12:54:33 -0700 (PDT)
Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-20b7259be6fso32075145ad.0 for <bpf@ietf.org>; Tue, 01 Oct 2024 12:54:33 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20230601; t=1727812473; x=1728417273; darn=ietf.org; h=content-language:thread-index:content-transfer-encoding :mime-version:message-id:date:subject:in-reply-to:references:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=TuGoJk9ECvqTkdhRfL58HMyKOI+yVlMGcPqLYre0Ahc=; b=TFxWIYw7MBEFjnQre+n5GFIGmrZNq0GU4lQzxhO85MDBe+5jp+u2w1FiqAupnOosy/ B68ozLzIjQWt4LEonoSC54EIAGP6zPbPpc/DDIC8bNLFQyV2zWzK628Wc2o+bSdDqiGd KOinqlnWxQcnd3QbTYWke67P29n3p/a3f6tz8CRVYUtwDJHOduyqxcWFa/lgCAaDtZxN RF1dTjc9xuTk5/+2Bb/eSP7kmw9i9IzlCPvNXn0Wbz7EYMYFIxj3ri0/DwxkKG5nMMei 1UbKgeMzHJ5aW8PAPgx/pXP1TKjje6+XILSQZsfq0lpR4FZd5EWG6TsxpBIzymHFwpyd wUtg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727812473; x=1728417273; h=content-language:thread-index:content-transfer-encoding :mime-version:message-id:date:subject:in-reply-to:references:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=TuGoJk9ECvqTkdhRfL58HMyKOI+yVlMGcPqLYre0Ahc=; b=AfYTmcFEeZzA++HKEe7vfIk3aEasxVkVoMbH3cn366Rv5CDmrnSIpNcWsg/MKzWB3o fCVcBw8wfANLDwUMeTmuGfUxBCgqqG06K/FSb5G8DQF0aia57Ud8Dm1rQD70x8tXedcU HTeOOBDO9khxnuztgI8QkwMRBUdYzGum1RRVDIcl4AMsFKLuFQ0Ui2v6Xk79PycfjOpu KgJOQVI9Z3Ur1ss7OE7g6pau27B3k/UiOHnrJRSca35LtOAtyuE+VGj3+v3vXgaKMOqH b8kEsYWN5ewtQWlYVtcQXkyyx5WdsY5Gcd0GYXVMIl6Dwm+N+hfiJXnk3cgzstMj7zxP 3CUQ==
X-Forwarded-Encrypted: i=1; AJvYcCW4cpTgp83EgAQKbwxr/dbxKUwg1kGooO624sNM8rrPEz9a12vdHMGaU9wD3H+DbdRBKXU=@ietf.org
X-Gm-Message-State: AOJu0YxQMq5C3JLFfuko4YFXy98U26LyEbzGC5ODdWbYRC7cYx4Ro1W1 QW2ah32jM2mW66Q9+zJhR3AZ0Pum/UOcDDA90F3tThNj8n7M2u6i
X-Google-Smtp-Source: AGHT+IFVhbB/nL9ZYL1sIb+zR/pBa2OyC8tXDQL0EL3nGOyvlR4VqOEyMLN/BUeXrKLcnwyn+SiONw==
X-Received: by 2002:a17:903:1103:b0:20b:9078:707b with SMTP id d9443c01a7336-20bc5a10233mr8891435ad.30.1727812473077; Tue, 01 Oct 2024 12:54:33 -0700 (PDT)
Received: from ArmidaleLaptop ([2601:600:877f:ae0f:f8cf:32cf:647d:b56e]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20b37d89297sm73751755ad.71.2024.10.01.12.54.31 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Oct 2024 12:54:32 -0700 (PDT)
From: Dave Thaler <dthaler1968@googlemail.com>
X-Google-Original-From: "Dave Thaler" <dthaler1968@gmail.com>
To: 'Yonghong Song' <yonghong.song@linux.dev>, 'Alexei Starovoitov' <alexei.starovoitov@gmail.com>, bpf@ietf.org
References: <20240927033904.2702474-1-yonghong.song@linux.dev> <CAADnVQJZLRnT3J31CLB85by=SmC2UY1pmUZX0kkyePtVdTdy9A@mail.gmail.com> <e93729b5-199f-4809-84f5-7efdf7c8aaf3@linux.dev>
In-Reply-To: <e93729b5-199f-4809-84f5-7efdf7c8aaf3@linux.dev>
Date: Tue, 01 Oct 2024 12:54:27 -0700
Message-ID: <181301db143b$ba6fd9c0$2f4f8d40$@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Mailer: Microsoft Outlook 16.0
Thread-Index: AQKzqMffW8FFfWCd3ulEKsb+gfc3egGOkjXjAfqQ6mmwpNlrgA==
Content-Language: en-us
Message-ID-Hash: YWEJP3KQ2OXTQKMEEI4H7RCXD5VLGSAU
X-Message-ID-Hash: YWEJP3KQ2OXTQKMEEI4H7RCXD5VLGSAU
X-MailFrom: dthaler1968@googlemail.com
X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header
CC: 'bpf' <bpf@vger.kernel.org>, 'Alexei Starovoitov' <ast@kernel.org>, 'Andrii Nakryiko' <andrii@kernel.org>, 'Daniel Borkmann' <daniel@iogearbox.net>, 'Martin KaFai Lau' <martin.lau@kernel.org>
X-Mailman-Version: 3.3.9rc4
Precedence: list
Subject: [Bpf] Re: [PATCH bpf-next] docs/bpf: Document some special sdiv/smod operations
List-Id: Discussion of BPF/eBPF standardization efforts within the IETF <bpf.ietf.org>
Archived-At: <https://mailarchive.ietf.org/arch/msg/bpf/RIsU3BSetPq3LrX7rc4qFb4bEJw>
List-Archive: <https://mailarchive.ietf.org/arch/browse/bpf>
List-Help: <mailto:bpf-request@ietf.org?subject=help>
List-Owner: <mailto:bpf-owner@ietf.org>
List-Post: <mailto:bpf@ietf.org>
List-Subscribe: <mailto:bpf-join@ietf.org>
List-Unsubscribe: <mailto:bpf-leave@ietf.org>
Yonghong Song <yonghong.song@linux.dev> wrote: > On 9/30/24 6:50 PM, Alexei Starovoitov wrote: > > On Thu, Sep 26, 2024 at 8:39 PM Yonghong Song <yonghong.song@linux.dev> > wrote: > >> Patch [1] fixed possible kernel crash due to specific sdiv/smod > >> operations in bpf program. The following are related operations and > >> the expected results of those operations: > >> - LLONG_MIN/-1 = LLONG_MIN > >> - INT_MIN/-1 = INT_MIN > >> - LLONG_MIN%-1 = 0 > >> - INT_MIN%-1 = 0 > >> > >> Those operations are replaced with codes which won't cause kernel > >> crash. This patch documents what operations may cause exception and > >> what replacement operations are. > >> > >> [1] > >> https://lore.kernel.org/all/20240913150326.1187788-1-yonghong.song@li > >> nux.dev/ > >> > >> Signed-off-by: Yonghong Song <yonghong.song@linux.dev> > >> --- > >> .../bpf/standardization/instruction-set.rst | 25 +++++++++++++++---- > >> 1 file changed, 20 insertions(+), 5 deletions(-) > >> > >> diff --git a/Documentation/bpf/standardization/instruction-set.rst > >> b/Documentation/bpf/standardization/instruction-set.rst > >> index ab820d565052..d150c1d7ad3b 100644 > >> --- a/Documentation/bpf/standardization/instruction-set.rst > >> +++ b/Documentation/bpf/standardization/instruction-set.rst > >> @@ -347,11 +347,26 @@ register. > >> ===== ===== ======= > >> ========================================================== > >> > >> Underflow and overflow are allowed during arithmetic operations, > >> meaning -the 64-bit or 32-bit value will wrap. If BPF program > >> execution would -result in division by zero, the destination register is instead set > to zero. > >> -If execution would result in modulo by zero, for ``ALU64`` the value of > >> -the destination register is unchanged whereas for ``ALU`` the upper > >> -32 bits of the destination register are zeroed. > >> +the 64-bit or 32-bit value will wrap. There are also a few > >> +arithmetic operations which may cause exception for certain > >> +architectures. Since crashing the kernel is not an option, those operations are > replaced with alternative operations. > >> + > >> +.. table:: Arithmetic operations with possible exceptions > >> + > >> + ===== ========== ============================= > ========================== > >> + name class original replacement > >> + ===== ========== ============================= > ========================== > >> + DIV ALU64/ALU dst /= 0 dst = 0 > >> + SDIV ALU64/ALU dst s/= 0 dst = 0 > >> + MOD ALU64 dst %= 0 dst = dst (no replacement) > >> + MOD ALU dst %= 0 dst = (u32)dst > >> + SMOD ALU64 dst s%= 0 dst = dst (no replacement) > >> + SMOD ALU dst s%= 0 dst = (u32)dst All of the above are already covered in existing Table 5 and in my opinion don't need to be repeated. That is, the "original" is not what Table 5 has, so just introduces confusion in the document in my opinion. > >> + SDIV ALU64 dst s/= -1 (dst = LLONG_MIN) dst = LLONG_MIN > >> + SDIV ALU dst s/= -1 (dst = INT_MIN) dst = (u32)INT_MIN > >> + SMOD ALU64 dst s%= -1 (dst = LLONG_MIN) dst = 0 > >> + SMOD ALU dst s%= -1 (dst = INT_MIN) dst = 0 The above four are the new ones and I'd prefer a solution that modifies existing table 5. E.g. table 5 has now for SMOD: dst = (src != 0) ? (dst s% src) : dst and could have something like this: dst = (src == 0) ? dst : ((src == -1 && dst == INT_MIN) ? 0 : (dst s% src)) > > This is a great addition to the doc, but this file is currently being > > used as a base for IETF standard which is in its final "edit" stage > > which may require few patches, so we cannot land any changes to > > instruction-set.rst not related to standardization until RFC number is > > issued and it becomes immutable. After that the same > > instruction-set.rst file can be reused for future revisions on the > > standard. > > Hopefully the draft will clear the final hurdle in a couple weeks. > > Until then: > > pw-bot: cr > > Sure. No problem. Will resubmit once the RFC number is issued. I'm adding bpf@ietf.org to the To line since all changes in the standardization directory should include that mailing list. The WG should discuss whether any changes should be done via a new RFC that obsoletes the first one, or as RFCs that Update and just describe deltas (additions, etc.). There are precedents both ways and I don't have a strong preference, but I have a weak preference for delta-based ones since they're shorter and are less likely to re-open discussion on previously resolved issues, thus often saving the WG time. Also FYI to Linux kernel folks: With WG and AD approval, it's also possible (but not ideal) to take changes at AUTH48. That'd be up to the chairs and AD to decide though, and normally that's just for purely editorial clarifications, e.g., to confusion called out by the RFC editor pass. Dave
- [Bpf] Re: [PATCH bpf-next] docs/bpf: Document som… Dave Thaler
- [Bpf] Re: [PATCH bpf-next] docs/bpf: Document som… Alexei Starovoitov
- [Bpf] Re: [PATCH bpf-next] docs/bpf: Document som… Dave Thaler
- [Bpf] Re: [PATCH bpf-next] docs/bpf: Document som… Alexei Starovoitov
- [Bpf] Re: [PATCH bpf-next] docs/bpf: Document som… Dave Thaler
- [Bpf] Re: [PATCH bpf-next] docs/bpf: Document som… Yonghong Song
- [Bpf] Re: [PATCH bpf-next] docs/bpf: Document som… Alexei Starovoitov
- [Bpf] Re: [PATCH bpf-next] docs/bpf: Document som… Yonghong Song