Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp3161079pxb; Tue, 12 Jan 2021 07:46:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJwqV/m3I/G9lpt5vNWipOCa3I96xIxl++Xnu4a4jHcfn9NQsIFyn5IZW2RFFIWHvyvFQtEf X-Received: by 2002:a17:906:af99:: with SMTP id mj25mr3807699ejb.414.1610466404246; Tue, 12 Jan 2021 07:46:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610466404; cv=none; d=google.com; s=arc-20160816; b=aM4QPNE2F1Ai+yNeEfie04EmB0gVkUJEY0pwnbufBAQ6PgzkF6Aec1/ChM1DO8F/rv z43RkPU/FHzUly/Le3ho/rIHA2jBCBTudcC4QR5qnr8A9a1CaUauegF3XR7+/DNmVM5R UegacC2e2KQboNHDVstPJdgLtY0VGzSJHa5AON2sMA+YtflKvCxmCyYYVH/ln7KqS30F QcT4RPr1eaQahASWXRZKhnMwZ5SaxIOkVdHv2nSgfOI3hFu/ciOWFw91a7fA9B8q7Sow ti8VNhX8oZqbfH8AfuaWl1KsJ54Ajkm9GehEfpPlIQZmKGAYbIeiJzrii3/TiVs/BhLh 8kTQ== 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=oW3at7tYerofWpFJJa0IT/4f63HRcTZEokqKQUOM8Tc=; b=qmbf4pR4mJUuAkNtlznrTxf22NYhPegkYGKP8tgmGypglWf26qmRxlPf/ThUuGbCJg ih8BLPA+Q+EFMfrXRPKC6U4AzqubD2EB3OPnK6JM0H+r7U9b+6GLJQhlW5LZYPTIKkhn yOWQP6Feha3vEpdYo+bH7FoaxbL1DjlvSyZooOM7x7Cf4D/zXV1tcxs9TKQyrqbLE8q8 C5f5x4Vp4daUIIHmlJnhEuHAVyx/qztgnb9suKOW1UGEIzDdoM5REcgtEQUeOcvacYDg Brn2Y9jTLd8JmXvbuGxQ/IoAUahTEyzJiZFmGT34iDlerVqtU6WCvah5qA1Y2b+izkmJ A0pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=pp1KxffC; 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 p10si1321361eji.254.2021.01.12.07.46.19; Tue, 12 Jan 2021 07:46:44 -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=pp1KxffC; 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 S2405237AbhALPoU (ORCPT + 99 others); Tue, 12 Jan 2021 10:44:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405170AbhALPoR (ORCPT ); Tue, 12 Jan 2021 10:44:17 -0500 Received: from mail-wr1-x44a.google.com (mail-wr1-x44a.google.com [IPv6:2a00:1450:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87611C061381 for ; Tue, 12 Jan 2021 07:43:04 -0800 (PST) Received: by mail-wr1-x44a.google.com with SMTP id u3so1305471wri.19 for ; Tue, 12 Jan 2021 07:43:04 -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=oW3at7tYerofWpFJJa0IT/4f63HRcTZEokqKQUOM8Tc=; b=pp1KxffCDPqB9jIy9tx75GpgmaQQZyM9ktvJ18nRXiTSgY7iOlYcn/aLrbZzWn9QhQ J/ttqRDHk0CFmqUEVoF/OXmko556O047ZO0EVK9glyXSWKTuMLlQorx/q78jwJ26WHz5 a7jiDA1y0IMP/vKZh3ImwFFrYjN6o0PMJNeb8vxYLINl4WR9fhirFJVJGDDNgxeup7e6 HVVxQtkxslABlElQVoeaJ1axZjXe/0P/VA9WuMgcEdzcWAkcSmy4OFclaKppnT6Ai+CT YVbBl66fxFfNzgLvWFVTaGDa32TvibyRjWcgAK7xh5hWThS5AFcwo53DS0PmFOExlBUJ Hclw== 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=oW3at7tYerofWpFJJa0IT/4f63HRcTZEokqKQUOM8Tc=; b=Z2nYPOOERVPyC181R8M8w4asU0DBtppJJxOG818WIAOH5zA5G2m0JLK1az+tDHZmmn 3Ywo+znQu4T+wUCY50GSeOom09eRk4gNZijR/9EM79KjU1aswxZ5fXzDHKea6lIZPYI1 a8WdHHBejawU+SYJUiAPKFvMbsMnLhRX/3h2rvXeuBvQeBlPt6dvSJ36cavXV2h+xHQz 3ewDZeOwbLotKw51fookdAiT5rSBlSJ6EoYgIY7Yc/qhyQRyfq+YT2iBMIx25rjTqVMj Exzd9K9eOJoiUUnuRTm6REn11VMSHvwqJ/oscHuIZsUJce0NZa8KrJ7MWylNFrCVH9LY 0p5Q== X-Gm-Message-State: AOAM530KYYbPwuey3aMFpnHY372GHvzxtSUCy/AegUx+Wofx9qcwaREx fLe6I5w0UJy/eHLyEf6jff1mUIXotJnaUA== 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:e4c5:: with SMTP id b188mr3649502wmh.78.1610466183095; Tue, 12 Jan 2021 07:43:03 -0800 (PST) Date: Tue, 12 Jan 2021 15:42:35 +0000 In-Reply-To: <20210112154235.2192781-1-jackmanb@google.com> Message-Id: <20210112154235.2192781-12-jackmanb@google.com> Mime-Version: 1.0 References: <20210112154235.2192781-1-jackmanb@google.com> X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7-goog Subject: [PATCH bpf-next v6 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, "=?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?=" , John Fastabend , Yonghong Song , 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. Acked-by: Yonghong Song Signed-off-by: Brendan Jackman --- Documentation/networking/filter.rst | 31 +++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/Documentation/networking/filter.rst b/Documentation/networking/filter.rst index 1583d59d806d..f6d8f90e9a56 100644 --- a/Documentation/networking/filter.rst +++ b/Documentation/networking/filter.rst @@ -1053,8 +1053,39 @@ 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 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. +Except ``BPF_ADD`` _without_ ``BPF_FETCH`` (for legacy reasons), all 4 byte +atomic operations require alu32 mode. Clang enables this mode by default in +architecture v3 (``-mcpu=v3``). For older versions it can be enabled with +``-Xclang -target-feature -Xclang +alu32``. + You may encounter BPF_XADD - this is a legacy name for BPF_ATOMIC, referring to the exclusive-add operation encoded when the immediate field is zero. -- 2.30.0.284.gd98b1dd5eaa7-goog