Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp3322941pxu; Tue, 15 Dec 2020 04:24:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJxtHQHHYg5EUJ213RxOx4WxYXUgN5rD6PfefeOF3OeaVWXeDCKEbRwvJt/miA7rWF3IK/ZT X-Received: by 2002:aa7:d74f:: with SMTP id a15mr29706356eds.344.1608035080215; Tue, 15 Dec 2020 04:24:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608035080; cv=none; d=google.com; s=arc-20160816; b=M1excBif8djmqeX/CPTrDxG+GZqa+zD7Zb2B5XhH+PEcDXxjptNNKWt7EwWcw06Gai DDZSbcxlUXwOkZMbKCZ4KFwd7ZG1wEhVA5yfFeluZdDOQGiiT8WVBMI67Ty67Zytywev u+1qiK5iJ1EC5N5cxSm5QfiWoZgvJUE0Uxup6fyhAhvag5yLvOj0A/FrAulyiPim5+Wi 1WmKPWuyC/959xdBvK13lIxsQvlFZo1O4mrBS+A39qIfFY0se8V3UYUM0AQuqJuG7Ajs Iuz8Bre8omO+gIHti59l9U+y6osb3/XbKJqETihWb0WfDfv9DD43+Sby5PUL4Y4IYF14 qR+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:sender:dkim-signature; bh=Bfu1yJn/kcF0Yo8zAQx6cAw+Cz3e6GVA73k+ZlHyjbw=; b=bMhgMf0Vcyvd7ZNziWD3VKE795//AFqnNkb1XaVcIw+aKdKfWVMu0GBVwhTcK0nz50 /4H/GbQFxhkfrpc7MsNYb7IDHmJ5L7jtkJa2xqrmEdK9SOanU4tvS7GbMMkavfF1+Vhf eSmZdpUoAa3oKI49lERlnhWbRRPXokdMyNyB6YYNJ1+0DLRvlXhXUT5wJHvX9Ta9FmDK +vTW2pOEim9X1H6HVFSeQr9EI8C4An/gZQmysuXbC3T9SoN0saIEuETszyyst0VYAkx7 iT/XwA7Fr/BzH860oPUebltHmnDFW1eLD7jNFs2Q8uA8nDA62WTLmYKvgEpuz1iT8g+g jjOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ZYqCWeA1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g10si767299ejp.536.2020.12.15.04.24.16; Tue, 15 Dec 2020 04:24:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ZYqCWeA1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729028AbgLOMUp (ORCPT + 99 others); Tue, 15 Dec 2020 07:20:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729319AbgLOMU3 (ORCPT ); Tue, 15 Dec 2020 07:20:29 -0500 Received: from mail-wm1-x349.google.com (mail-wm1-x349.google.com [IPv6:2a00:1450:4864:20::349]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6B7DC0619D9 for ; Tue, 15 Dec 2020 04:18:49 -0800 (PST) Received: by mail-wm1-x349.google.com with SMTP id b194so1513062wmd.3 for ; Tue, 15 Dec 2020 04:18:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=Bfu1yJn/kcF0Yo8zAQx6cAw+Cz3e6GVA73k+ZlHyjbw=; b=ZYqCWeA16+zZio2g7PNwYJH77/xqbft2wlFuZdsF6W3VdU9IyMjLpGXVsGcvmd/JBj QT8wa2MlmMlpXjr4I1opHpAjTKqrcvS/3xZgc7sP2iqwjeD3QcolwYGvtTRbZBkXxASq /eTxXFwqo080NpRpJs2Ki6Tx3c1fg7dxc+qtFjP78oHmyydgNKV4bS4KFjPhLjYisA++ rVpMqJepERBl0HmEklSuA0UEDaWGVtCBZJWNSFYZq/Htm8LSxLVfGTN6hxa1JEhV2jQb Drjvrucf8vmSq9MNSp9CL3qvlwysxtSTS5AJZoLK7gy7GH5g2PpOIA1Ju3mSmTOdtjOg CzSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Bfu1yJn/kcF0Yo8zAQx6cAw+Cz3e6GVA73k+ZlHyjbw=; b=kVel7UKWt4BDAZ0dxHCn0C13rt4RWmiL2102s80vHKQ4jB5xWjKe9PVpEeHadsL8pu 02yoI3W9pTIlWNq4J+HVbgHKgPKfiTXuxLOlskpJWDZhaq4uwSSrobERf42Tofujz9NG nLiwaK0iDG9LAakaSsDDTfkvS4BX90em3RHTfUfE8u/ysaKlujYWEUBd2R4bFYTPLoDC 1qqfN+Xfo0762MXCjCrqDogWaSdjPL/PCP4DeM6rn7X0CHlCbyzKC3Hqcv9K0Oq87SAk oXR4RpOZy7f4xfZIzlltJgnm/b1IZhqlDJRYbOdF16Gbx5gwEOHKBz/7wYvmdR6Xx+Er 1KSA== X-Gm-Message-State: AOAM5317msZQ95valf30V/pd6Gsg1zCe7dJTgGX2CczqF9MdCiRVXRac 5+LtIUZzvHWv3HvDlR/P7LVHDbjo7mrAhw== Sender: "jackmanb via sendgmr" X-Received: from beeg.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:11db]) (user=jackmanb job=sendgmr) by 2002:a1c:25c2:: with SMTP id l185mr32768635wml.113.1608034728668; Tue, 15 Dec 2020 04:18:48 -0800 (PST) Date: Tue, 15 Dec 2020 12:18:16 +0000 In-Reply-To: <20201215121816.1048557-1-jackmanb@google.com> Message-Id: <20201215121816.1048557-13-jackmanb@google.com> Mime-Version: 1.0 References: <20201215121816.1048557-1-jackmanb@google.com> X-Mailer: git-send-email 2.29.2.684.gfbc64c5ab5-goog Subject: [PATCH bpf-next v5 11/11] bpf: Document new atomic instructions From: Brendan Jackman To: bpf@vger.kernel.org Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , KP Singh , Florent Revest , linux-kernel@vger.kernel.org, Brendan Jackman Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Document new atomic instructions. Signed-off-by: Brendan Jackman --- Documentation/networking/filter.rst | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Documentation/networking/filter.rst b/Documentation/networking/filter.rst index 1583d59d806d..26d508a5e038 100644 --- a/Documentation/networking/filter.rst +++ b/Documentation/networking/filter.rst @@ -1053,6 +1053,32 @@ encoding. .imm = BPF_ADD, .code = BPF_ATOMIC | BPF_W | BPF_STX: lock xadd *(u32 *)(dst_reg + off16) += src_reg .imm = BPF_ADD, .code = BPF_ATOMIC | BPF_DW | BPF_STX: lock xadd *(u64 *)(dst_reg + off16) += src_reg +The basic atomic operations supported (from architecture v4 onwards) are: + + BPF_ADD + BPF_AND + BPF_OR + BPF_XOR + +Each having equivalent semantics with the ``BPF_ADD`` example, that is: the +memory location addresed by ``dst_reg + off`` is atomically modified, with +``src_reg`` as the other operand. If the ``BPF_FETCH`` flag is set in the +immediate, then these operations also overwrite ``src_reg`` with the +value that was in memory before it was modified. + +The more special operations are: + + BPF_XCHG + +This atomically exchanges ``src_reg`` with the value addressed by ``dst_reg + +off``. + + BPF_CMPXCHG + +This atomically compares the value addressed by ``dst_reg + off`` with +``R0``. If they match it is replaced with ``src_reg``, The value that was there +before is loaded back to ``R0``. + Note that 1 and 2 byte atomic operations are not supported. You may encounter BPF_XADD - this is a legacy name for BPF_ATOMIC, referring to -- 2.29.2.684.gfbc64c5ab5-goog