* Re: [PATCH v1 2/3] zinc: Introduce minimal cryptography library
From: Eric Biggers @ 2018-08-01 7:22 UTC (permalink / raw)
To: Jason A. Donenfeld
Cc: linux-crypto, linux-kernel, netdev, davem, Andy Lutomirski,
Greg KH, Samuel Neves, D . J . Bernstein, Tanja Lange,
Jean-Philippe Aumasson, Karthikeyan Bhargavan
[+Cc linux-crypto]
Hi Jason,
Apologies for starting a new thread, but this patch apparently wasn't
Cc'ed to linux-crypto, despite adding over 24000 lines of crypto code.
So much for WireGuard being only 4000 lines :-)
(For anyone else like me who didn't receive the patch, it can be found at
https://patchwork.ozlabs.org/patch/951763/)
I have some preliminary comments below.
On Tue, 31 Jul 2018 21:11:01 +0200, Jason A. Donenfeld wrote:
> [PATCH v1 2/3] zinc: Introduce minimal cryptography library
>
> Zinc stands for "Zinc Is Not crypto/". It's also short, easy to type,
> and plays nicely with the recent trend of naming crypto libraries after
> elements. The guiding principle is "don't overdo it". It's less of a
> library and more of a directory tree for organizing well-curated direct
> implementations of cryptography primitives.
>
> Zinc is a new cryptography API that is much more minimal and lower-level
> than the current one. It intends to complement it and provide a basis
> upon which the current crypto API might build, and perhaps someday Zinc
> may altogether supplant the current crypto API. It is motivated by
> three primary observations in crypto API design:
>
> * Highly composable "cipher modes" and related abstractions from
> 90s cryptographers did not turn out to be as terrific an idea as
> hoped, leading to a host of API misuse problems.
>
> * Most programmers are afraid of crypto code, and so prefer to
> integrate it into libraries in a highly abstracted manner, so as to
> shield themselves from implementation details. Cryptographers, on
> the other hand, prefer simple direct implementations, which they're
> able to verify for high assurance and optimize in accordance with
> their expertise.
>
> * Overly abstracted and flexible cryptography APIs lead to a host of
> dangerous problems and performance issues. The kernel is in the
> business usually not of coming up with new uses of crypto, but
> rather implementing various constructions, which means it essentially
> needs a library of primitives, not a highly abstracted enterprise-ready
> pluggable system, with a few particular exceptions.
>
> This last observation has seen itself play out several times over and
> over again within the kernel:
>
> * The perennial move of actual primitives away from crypto/ and into
> lib/, so that users can actually call these functions directly with
> no overhead and without lots of allocations, function pointers,
> string specifier parsing, and general clunkiness. For example:
> sha256, chacha20, siphash, sha1, and so forth live in lib/ rather
> than in crypto/. Zinc intends to stop the cluttering of lib/ and
> introduce these direct primitives into their proper place, lib/zinc/.
>
> * An abundance of misuse bugs with the present crypto API that have
> been very unpleasant to clean up.
>
> * A hesitance to even use cryptography, because of the overhead and
> headaches involved in accessing the routines.
>
> Zinc goes in a rather different direction. Rather than providing a
> thoroughly designed and abstracted API, Zinc gives you simple functions,
> which implement some primitive, or some particular and specific
> construction of primitives. It is not dynamic in the least, though one
> could imagine implementing a complex dynamic dispatch mechanism (such as
> the current crypto API) on top of these basic functions. After all,
> dynamic dispatch is usually needed for applications with cipher agility,
> such as IPsec, dm-crypt, AF_ALG, and so forth, and the existing crypto
> API will continue to play that role. However, Zinc will provide a non-
> haphazard way of directly utilizing crypto routines in applications
> that do have neither need nor desire for abstraction and dynamic
> dispatch.
>
> It also organizes the implementations in a simple, straight-forward,
> and direct manner, making it enjoyable and intuitive to work on.
> Rather than moving optimized assembly implementations into arch/, it
> keeps them all together in lib/zinc/, making it simple and obvious to
> compare and contrast what's happening. This is, notably, exactly what
> the lib/raid6/ tree does, and that seems to work out rather well. It's
> also the pattern of most successful crypto libraries. Likewise, the
> cascade of architecture-specific functions is done as ifdefs within one
> file, so that it's easy and obvious and clear what's happening, how each
> architecture differs, and how to optimize for shared patterns. This is
> very much preferable to architecture-specific file splitting.
>
> All implementations have been extensively tested and fuzzed, and are
> selected for their quality, trustworthiness, and performance. Wherever
> possible and performant, formally verified implementations are used,
> such as those from HACL* [1] and Fiat-Crypto [2]. The routines also take
> special care to zero out secrets using memzero_explicit (and future work
> is planned to have gcc do this more reliably and performantly with
> compiler plugins). The performance of the selected implementations is
> state-of-the-art and unrivaled. Each implementation also comes with
> extensive self-tests and crafted test vectors, pulled from various
> places such as Wycheproof [9].
>
> Regularity of function signatures is important, so that users can easily
> "guess" the name of the function they want. Though, individual
> primitives are oftentimes not trivially interchangeable, having been
> designed for different things and requiring different parameters and
> semantics, and so the function signatures they provide will directly
> reflect the realities of the primitives' usages, rather than hiding it
> behind (inevitably leaky) abstractions. Also, in contrast to the current
> crypto API, Zinc functions can work on stack buffers, and can be called
> with different keys, without requiring allocations or locking.
>
> SIMD is used automatically when available, though some routines may
> benefit from either having their SIMD disabled for particular
> invocations, or to have the SIMD initialization calls amortized over
> several invocations of the function, and so Zinc provides helpers and
> function signatures enabling that.
>
> More generally, Zinc provides function signatures that allow just what
> is required by the various callers. This isn't to say that users of the
> functions will be permitted to pollute the function semantics with weird
> particular needs, but we are trying very hard not to overdo it, and that
> means looking carefully at what's actually necessary, and doing just that,
> and not much more than that. Remember: practicality and cleanliness rather
> than over-zealous infrastructure.
>
> Zinc provides also an opening for the best implementers in academia to
> contribute their time and effort to the kernel, by being sufficiently
> simple and inviting. In discussing this commit with some of the best and
> brightest over the last few years, there are many who are eager to
> devote rare talent and energy to this effort.
>
> This initial commit adds implementations of the primitives used by WireGuard:
>
> * Curve25519 [3]: formally verified 64-bit C, formally verified 32-bit C,
> x86_64 BMI2, x86_64 ADX, ARM NEON.
>
> * ChaCha20 [4]: generic C, x86_64 SSSE3, x86_64 AVX-2, x86_64 AVX-512F,
> x86_64 AVX-512VL, ARM NEON, ARM64 NEON, MIPS.
>
> * HChaCha20 [5]: generic C, x86_64 SSSE3.
>
> * Poly1305 [6]: generic C, x86_64, x86_64 AVX, x86_64 AVX-2, x86_64
> AVX-512F, ARM NEON, ARM64 NEON, MIPS, MIPS64.
>
> * BLAKE2s [7]: generic C, x86_64 AVX, x86_64 AVX-512VL.
>
> * ChaCha20Poly1305 [8]: generic C construction for both full buffers and
> scatter gather.
>
> * XChaCha20Poly1305 [5]: generic C construction.
>
> Following the merging of this, I expect for first the primitives that
> currently exist in lib/ to work their way into lib/zinc/, after intense
> scrutiny of each implementation, potentially replacing them with either
> formally-verified implementations, or better studied and faster
> state-of-the-art implementations. In a phase after that, I envision that
> certain instances from crypto/ will want to rebase themselves to simply
> be abstracted crypto API wrappers using the lower level Zinc functions.
> This is already what various crypto/ implementations do with the
> existing code in lib/.
>
> Currently Zinc exists as a single un-menued option, CONFIG_ZINC, but as
> this grows we will inevitably want to make that more granular. This will
> happen at the appropriate time, rather than doing so prematurely. There
> also is a CONFIG_ZINC_DEBUG menued option, performing several intense
> tests at startup and enabling various BUG_ONs.
>
> [1] https://github.com/project-everest/hacl-star
> [2] https://github.com/mit-plv/fiat-crypto
> [3] https://cr.yp.to/ecdh.html
> [4] https://cr.yp.to/chacha.html
> [5] https://cr.yp.to/snuffle/xsalsa-20081128.pdf
> [6] https://cr.yp.to/mac.html
> [7] https://blake2.net/
> [8] https://tools.ietf.org/html/rfc8439
> [9] https://github.com/google/wycheproof
>
> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
> Cc: Andy Lutomirski <luto@kernel.org>
> Cc: Greg KH <gregkh@linuxfoundation.org>
> Cc: Samuel Neves <sneves@dei.uc.pt>
> Cc: D. J. Bernstein <djb@cr.yp.to>
> Cc: Tanja Lange <tanja@hyperelliptic.org>
> Cc: Jean-Philippe Aumasson <jeanphilippe.aumasson@gmail.com>
> Cc: Karthikeyan Bhargavan <karthik.bhargavan@gmail.com>
> ---
> MAINTAINERS | 7 +
> include/zinc/blake2s.h | 94 +
> include/zinc/chacha20.h | 46 +
> include/zinc/chacha20poly1305.h | 51 +
> include/zinc/curve25519.h | 25 +
> include/zinc/poly1305.h | 34 +
> include/zinc/simd.h | 60 +
> lib/Kconfig | 21 +
> lib/Makefile | 2 +
> lib/zinc/Makefile | 28 +
> lib/zinc/blake2s/blake2s-x86_64.S | 685 ++++++
> lib/zinc/blake2s/blake2s.c | 292 +++
> lib/zinc/chacha20/chacha20-arm.S | 1471 ++++++++++++
> lib/zinc/chacha20/chacha20-arm64.S | 1940 ++++++++++++++++
> lib/zinc/chacha20/chacha20-mips.S | 474 ++++
> lib/zinc/chacha20/chacha20-x86_64.S | 2630 +++++++++++++++++++++
> lib/zinc/chacha20/chacha20.c | 242 ++
> lib/zinc/chacha20poly1305.c | 286 +++
> lib/zinc/curve25519/curve25519-arm.S | 2110 +++++++++++++++++
> lib/zinc/curve25519/curve25519-arm.h | 14 +
> lib/zinc/curve25519/curve25519-fiat32.h | 838 +++++++
> lib/zinc/curve25519/curve25519-hacl64.h | 751 ++++++
> lib/zinc/curve25519/curve25519-x86_64.h | 2060 +++++++++++++++++
> lib/zinc/curve25519/curve25519.c | 86 +
> lib/zinc/main.c | 36 +
> lib/zinc/poly1305/poly1305-arm.S | 1115 +++++++++
> lib/zinc/poly1305/poly1305-arm64.S | 820 +++++++
> lib/zinc/poly1305/poly1305-mips.S | 417 ++++
> lib/zinc/poly1305/poly1305-mips64.S | 357 +++
> lib/zinc/poly1305/poly1305-x86_64.S | 2790 +++++++++++++++++++++++
> lib/zinc/poly1305/poly1305.c | 377 +++
> lib/zinc/selftest/blake2s.h | 559 +++++
> lib/zinc/selftest/chacha20poly1305.h | 1559 +++++++++++++
> lib/zinc/selftest/curve25519.h | 607 +++++
> lib/zinc/selftest/poly1305.h | 1568 +++++++++++++
> 35 files changed, 24452 insertions(+)
> create mode 100644 include/zinc/blake2s.h
> create mode 100644 include/zinc/chacha20.h
> create mode 100644 include/zinc/chacha20poly1305.h
> create mode 100644 include/zinc/curve25519.h
> create mode 100644 include/zinc/poly1305.h
> create mode 100644 include/zinc/simd.h
> create mode 100644 lib/zinc/Makefile
> create mode 100644 lib/zinc/blake2s/blake2s-x86_64.S
> create mode 100644 lib/zinc/blake2s/blake2s.c
> create mode 100644 lib/zinc/chacha20/chacha20-arm.S
> create mode 100644 lib/zinc/chacha20/chacha20-arm64.S
> create mode 100644 lib/zinc/chacha20/chacha20-mips.S
> create mode 100644 lib/zinc/chacha20/chacha20-x86_64.S
> create mode 100644 lib/zinc/chacha20/chacha20.c
> create mode 100644 lib/zinc/chacha20poly1305.c
> create mode 100644 lib/zinc/curve25519/curve25519-arm.S
> create mode 100644 lib/zinc/curve25519/curve25519-arm.h
> create mode 100644 lib/zinc/curve25519/curve25519-fiat32.h
> create mode 100644 lib/zinc/curve25519/curve25519-hacl64.h
> create mode 100644 lib/zinc/curve25519/curve25519-x86_64.h
> create mode 100644 lib/zinc/curve25519/curve25519.c
> create mode 100644 lib/zinc/main.c
> create mode 100644 lib/zinc/poly1305/poly1305-arm.S
> create mode 100644 lib/zinc/poly1305/poly1305-arm64.S
> create mode 100644 lib/zinc/poly1305/poly1305-mips.S
> create mode 100644 lib/zinc/poly1305/poly1305-mips64.S
> create mode 100644 lib/zinc/poly1305/poly1305-x86_64.S
> create mode 100644 lib/zinc/poly1305/poly1305.c
> create mode 100644 lib/zinc/selftest/blake2s.h
> create mode 100644 lib/zinc/selftest/chacha20poly1305.h
> create mode 100644 lib/zinc/selftest/curve25519.h
> create mode 100644 lib/zinc/selftest/poly1305.h
[...]
In general this is great work, and I'm very excited for WireGuard to be
upstreamed! But for the new crypto code, I think a few things are on
the wrong track, for example treating it is a special library. Even the
name is contradicting itself: Zinc is "not crypto/", yet as you stated
it's intended that the "Zinc" algorithms will be exposed through the
crypto API -- just like how most of the existing crypto code in lib/ is
also exposed through the crypto API. So, I think that what you're doing
isn't actually *that* different from what already exists in some cases;
and pretending that it is very different is just going to cause
problems. Rather, the actual truly new thing seems to be that the
dispatch to architecture specific implementations is done at the lib/
level instead of handled by the crypto API priority numbers.
So, I don't see why you don't just add lib/blake2s/, lib/chacha20/,
lib/poly1305/, etc., without pretending that they all have some special
new "Zinc" thing in common and are part of some holy crusade against the
crypto API.
They could even still go in subdirectory lib/crypto/ -- but just for
logical code organization purposes, as opposed to a special library with
a name that isn't self-explanatory and sounds like some third-party
library rather than first-class kernel code.
CONFIG_ZINC also needs to go. Algorithms will need to be independently
configurable as soon as anything other than WireGuard needs to use any
of them, so you might as well do it right from the start with
CONFIG_BLAKE2, CONFIG_CHACHA20, CONFIG_POLY1305, etc.
I think the above changes would also naturally lead to a much saner
patch series where each algorithm is added by its own patch, rather than
one monster patch that adds many algorithms and 24000 lines of code.
Note that adding all the algorithms in one patch also makes the
description of them conflated, e.g. you wrote that "formally verified"
implementations were used whenever possible, but AFAICS that actually
only applies to the C implementations of Curve25519, and even those have
your copyright statement so presumably you had to change something from
the "formally verified" code :-). Note also that Poly1305
implementations are somewhat error-prone, since there can be overflow
bugs that are extremely rarely hit; see e.g. how OpenSSL's Poly1305 NEON
implementation was initially buggy and had to be fixed:
https://mta.openssl.org/pipermail/openssl-commits/2016-April/006639.html.
Not to mention that C glue code is error-prone, especially with the tons
of #ifdefs. So, I'd strongly prefer that you don't oversell the crypto
code you're adding, e.g. by implying that most of it is formally
verified, as it likely still has bugs, like any other code...
I also want to compare the performance of some of the assembly
implementations you're adding to the existing implementations in the
kernel they duplicate. I'm especially interested in the NEON
implementation of ChaCha20. But adding 11 implementations in one single
patch means there isn't really a chance to comment on them individually.
Also, earlier when I tested OpenSSL's ChaCha NEON implementation on ARM
Cortex-A7 it was actually quite a bit slower than the one in the Linux
kernel written by Ard Biesheuvel... I trust that when claiming the
performance of all implementations you're adding is "state-of-the-art
and unrivaled", you actually compared them to the ones already in the
Linux kernel which you're advocating replacing, right? :-)
Your patch description is also missing any mention of crypto accelerator
hardware. Quite a bit of the complexity in the crypto API, such as
scatterlist support and asynchronous execution, exists because it
supports crypto accelerators. AFAICS your new APIs cannot support
crypto accelerators, as your APIs are synchronous and operate on virtual
addresses. I assume your justification is that "djb algorithms" like
ChaCha and Poly1305 don't need crypto accelerators as they are fast in
software. But you never explicitly stated this and discussed the
tradeoffs. Since this is basically the foundation for the design you've
chosen, it really needs to be addressed.
As for doing the architecture-specific dispatch in lib/ rather than
through the crypto API, there definitely are some arguments in favor of
it. The main problem, though, is that your code is a mess due to all
the #ifdefs, and it will only get worse as people add more
architectures. You may think you already added all the architectures
that matter, but tomorrow people will come and want to add PowerPC,
RISC-V, etc. I really think you should consider splitting up
implementations by architecture; this would *not*, however, preclude the
implementations from still being accessed through a single top-level
"glue" function. For example chacha20() could look like:
void chacha20(struct chacha20_ctx *state, u8 *dst, const u8 *src, u32 len,
bool have_simd)
{
if (chacha20_arch(dst, src, len, state->key, state->counter, have_simd))
goto out;
chacha20_generic(dst, src, len, state->key, state->counter);
out:
state->counter[0] += (len + 63) / 64;
}
So, each architecture would optionally define its own chacha20_arch()
that returns true if the data was processed, or false if not. (The data
wouldn't be processed if, for example, 'have_simd' was false but only
SIMD implementations are available; or if the input was too short for an
SIMD implementation to be faster than the generic one.) Note that this
would make the code much more consistent with the usual Linux kernel
coding style, which strongly prefers calling functions unconditionally
rather than having core logic littered with unmaintainable #ifdefs.
I'd also strongly prefer the patchset to include converting the crypto
API versions of ChaCha20 and Poly1305 over to use your new lib/ code, to
show that it's really possible. You mentioned that it's planned, but if
it's not done right away there will be things that were missed and will
require changes when someone finally does it. IMO it's not acceptable
to add your own completely separate ChaCha20 and Poly1305 just because
you don't like that the existing ones are part of the crypto API. You
need to refactor things properly. I think you'd need to expose the new
code under a cra_driver_name like "chacha20-software" and
"poly1305-software" to reflect that they use the fastest available
implementation of the algorithm on the CPU, e.g. "chacha20-generic",
"chacha20-neon", and "chacha20-simd" would all be replaced by a single
"chacha20-software". Is that what you had in mind?
I'm also wondering about the origin and licensing of some of the
assembly language files. Many have an OpenSSL copyright statement.
But, the OpenSSL license is often thought to be incompatible with GPL,
so using OpenSSL assembly code in the kernel has in the past required
getting special permission from Andy Polyakov (the person who's written
most of OpenSSL's assembly code so holds the copyright on it). As one
example, see arch/arm/crypto/sha256-armv4.pl: the file explicitly states
that Andy has relicensed it under GPLv2. For your new OpenSSL-derived
files, have you gone through and explicitly gotten GPLv2 permission from
Andy / the copyright holders?
Each assembly language file should also explicitly state where it came
from. For example lib/zinc/curve25519/curve25519-arm.S has your
copyright statement and says it's "Based on algorithms from Daniel J.
Bernstein and Peter Schwabe.", but it's not clarified whether the *code*
was written by those other people, as opposed to those people designing
the *algorithms* and then you writing the code; and if you didn't write
it, where you retrieved the file from and when, what license it had
(even if it was "public domain" like some of djb's code, this should be
mentioned for informational purposes), and what changes you made if any.
Oh, and please use 80-character lines like the rest of the kernel, so
that people's eyes don't bleed when reading your code :-)
Thanks for all your hard work on WireGuard!
- Eric
^ permalink raw reply
* [PATCH net-next] NFC: nci: remove redundant variable 'status'
From: YueHaibing @ 2018-08-01 7:20 UTC (permalink / raw)
To: davem, sameo; +Cc: linux-kernel, netdev, YueHaibing
After commit d8cd37ed2fc8 ("NFC: nci: Fix improper management of HCI return code")
variable 'status' is being assigned but never used,
so can be removed. Also make a trival cleanup.
Signed-off-by: YueHaibing <yuehaibing@huawei.com>
---
net/nfc/nci/hci.c | 10 ++--------
1 file changed, 2 insertions(+), 8 deletions(-)
diff --git a/net/nfc/nci/hci.c b/net/nfc/nci/hci.c
index ddfc52a..4debba8 100644
--- a/net/nfc/nci/hci.c
+++ b/net/nfc/nci/hci.c
@@ -370,17 +370,11 @@ static void nci_hci_resp_received(struct nci_dev *ndev, u8 pipe,
u8 result, struct sk_buff *skb)
{
struct nci_conn_info *conn_info;
- u8 status = result;
conn_info = ndev->hci_dev->conn_info;
- if (!conn_info) {
- status = NCI_STATUS_REJECTED;
- goto exit;
- }
-
- conn_info->rx_skb = skb;
+ if (conn_info)
+ conn_info->rx_skb = skb;
-exit:
nci_req_complete(ndev, NCI_STATUS_OK);
}
--
2.7.0
^ permalink raw reply related
* Re: [PATCH] HID: Bluetooth: hidp: buffer overflow in hidp_process_report
From: Marcel Holtmann @ 2018-08-01 7:16 UTC (permalink / raw)
To: Mark Salyzyn
Cc: linux-kernel, Johan Hedberg, David S. Miller, Kees Cook,
Benjamin Tissoires, linux-bluetooth, netdev, security,
kernel-team, Jiri Kosina
In-Reply-To: <20180731220225.159741-1-salyzyn@android.com>
Hi Mark,
> CVE-2018-9363
>
> The buffer length is unsigned at all layers, but gets cast to int and
> checked in hidp_process_report and can lead to a buffer overflow.
> Switch len parameter to unsigned int to resolve issue.
>
> This affects 3.18 and newer kernels.
>
> Signed-off-by: Mark Salyzyn <salyzyn@android.com>
> Fixes: a4b1b5877b514b276f0f31efe02388a9c2836728 ("HID: Bluetooth: hidp: make sure input buffers are big enough")
> Cc: Marcel Holtmann <marcel@holtmann.org>
> Cc: Johan Hedberg <johan.hedberg@gmail.com>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Kees Cook <keescook@chromium.org>
> Cc: Benjamin Tissoires <benjamin.tissoires@redhat.com>
> Cc: linux-bluetooth@vger.kernel.org
> Cc: netdev@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> Cc: security@kernel.org
> Cc: kernel-team@android.com
> ---
> net/bluetooth/hidp/core.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
patch has been applied to bluetooth-next tree.
Regards
Marcel
^ permalink raw reply
* [PATCH net-next] rds: remove redundant variable 'rds_ibdev'
From: YueHaibing @ 2018-08-01 7:14 UTC (permalink / raw)
To: davem, santosh.shilimkar
Cc: linux-kernel, netdev, linux-rdma, rds-devel, YueHaibing
Variable 'rds_ibdev' is being assigned but never used,
so can be removed.
fix this clang warning:
net/rds/ib_send.c:762:24: warning: variable ‘rds_ibdev’ set but not used [-Wunused-but-set-variable]
Signed-off-by: YueHaibing <yuehaibing@huawei.com>
---
net/rds/ib_send.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/net/rds/ib_send.c b/net/rds/ib_send.c
index c4cdfe49..c8dd312 100644
--- a/net/rds/ib_send.c
+++ b/net/rds/ib_send.c
@@ -759,14 +759,11 @@ int rds_ib_xmit_atomic(struct rds_connection *conn, struct rm_atomic_op *op)
struct rds_ib_connection *ic = conn->c_transport_data;
struct rds_ib_send_work *send = NULL;
struct ib_send_wr *failed_wr;
- struct rds_ib_device *rds_ibdev;
u32 pos;
u32 work_alloc;
int ret;
int nr_sig = 0;
- rds_ibdev = ib_get_client_data(ic->i_cm_id->device, &rds_ib_client);
-
work_alloc = rds_ib_ring_alloc(&ic->i_send_ring, 1, &pos);
if (work_alloc != 1) {
rds_ib_stats_inc(s_ib_tx_ring_full);
--
2.7.0
^ permalink raw reply related
* [PATCH net-next] strparser: remove redundant variable 'rd_desc'
From: YueHaibing @ 2018-08-01 7:10 UTC (permalink / raw)
To: davem, doronrk, tom, vakul.garg, davejwatson, ebiggers,
john.fastabend
Cc: linux-kernel, netdev, YueHaibing
Variable 'rd_desc' is being assigned but never used,
so can be removed.
fix this clang warning:
net/strparser/strparser.c:411:20: warning: variable ‘rd_desc’ set but not used [-Wunused-but-set-variable]
Signed-off-by: YueHaibing <yuehaibing@huawei.com>
---
net/strparser/strparser.c | 4 ----
1 file changed, 4 deletions(-)
diff --git a/net/strparser/strparser.c b/net/strparser/strparser.c
index 3a51293..da1a676 100644
--- a/net/strparser/strparser.c
+++ b/net/strparser/strparser.c
@@ -408,8 +408,6 @@ EXPORT_SYMBOL_GPL(strp_data_ready);
static void do_strp_work(struct strparser *strp)
{
- read_descriptor_t rd_desc;
-
/* We need the read lock to synchronize with strp_data_ready. We
* need the socket lock for calling strp_read_sock.
*/
@@ -421,8 +419,6 @@ static void do_strp_work(struct strparser *strp)
if (strp->paused)
goto out;
- rd_desc.arg.data = strp;
-
if (strp_read_sock(strp) == -ENOMEM)
queue_work(strp_wq, &strp->work);
--
2.7.0
^ permalink raw reply related
* Re: [PATCH net-next] xfrm: Make function xfrmi_get_link_net() static
From: Steffen Klassert @ 2018-08-01 5:22 UTC (permalink / raw)
To: Wei Yongjun; +Cc: Lorenzo Colitti, Benedict Wong, netdev, kernel-janitors
In-Reply-To: <1532760588-31129-1-git-send-email-weiyongjun1@huawei.com>
On Sat, Jul 28, 2018 at 06:49:48AM +0000, Wei Yongjun wrote:
> Fixes the following sparse warning:
>
> net/xfrm/xfrm_interface.c:745:12: warning:
> symbol 'xfrmi_get_link_net' was not declared. Should it be static?
>
> Fixes: f203b76d7809 ("xfrm: Add virtual xfrm interfaces")
> Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
Applied, thanks Wei!
^ permalink raw reply
* Re: [PATCH mlx5-next] RDMA/mlx5: Don't use cached IRQ affinity mask
From: Sagi Grimberg @ 2018-08-01 5:12 UTC (permalink / raw)
To: Max Gurtovoy, Jason Gunthorpe
Cc: Steve Wise, 'Leon Romanovsky', 'Doug Ledford',
'RDMA mailing list', 'Saeed Mahameed',
'linux-netdev'
In-Reply-To: <c079b7b4-bff8-8ffe-0be5-e470c86479b4@mellanox.com>
Hi Max,
> Yes, since nvmf is the only user of this function.
> Still waiting for comments on the suggested patch :)
>
Sorry for the late response (but I'm on vacation so I have
an excuse ;))
I'm thinking that we should avoid trying to find an assignment
when stuff like irqbalance daemon is running and changing
the affinitization.
This extension was made to apply optimal affinity assignment
when the device irq affinity is lined up in a vector per
core.
I'm thinking that when we identify this is not the case, we immediately
fallback to the default mapping.
1. when we get a mask, if its weight != 1, we fallback.
2. if a queue was left unmapped, we fallback.
Maybe something like the following:
--
diff --git a/block/blk-mq-rdma.c b/block/blk-mq-rdma.c
index 996167f1de18..1ada6211c55e 100644
--- a/block/blk-mq-rdma.c
+++ b/block/blk-mq-rdma.c
@@ -35,17 +35,26 @@ int blk_mq_rdma_map_queues(struct blk_mq_tag_set *set,
const struct cpumask *mask;
unsigned int queue, cpu;
+ /* reset all CPUs mapping */
+ for_each_possible_cpu(cpu)
+ set->mq_map[cpu] = UINT_MAX;
+
for (queue = 0; queue < set->nr_hw_queues; queue++) {
mask = ib_get_vector_affinity(dev, first_vec + queue);
if (!mask)
goto fallback;
- for_each_cpu(cpu, mask)
- set->mq_map[cpu] = queue;
+ if (cpumask_weight(mask) != 1)
+ goto fallback;
+
+ cpu = cpumask_first(mask);
+ if (set->mq_map[cpu] != UINT_MAX)
+ goto fallback;
+
+ set->mq_map[cpu] = queue;
}
return 0;
-
fallback:
return blk_mq_map_queues(set);
}
^ permalink raw reply related
* [PATCH bpf-next 12/13] docs: net: Fix various minor typos
From: Tobin C. Harding @ 2018-08-01 5:09 UTC (permalink / raw)
To: Daniel Borkmann, Alexei Starovoitov
Cc: Tobin C. Harding, Jonathan Corbet, David S. Miller, linux-doc,
netdev, linux-kernel
In-Reply-To: <20180801050908.29970-1-me@tobin.cc>
There are a few minor typos and grammatical issues. We should however
try to keep the current flavour of the document.
Fix typos and grammar if glaringly required.
Signed-off-by: Tobin C. Harding <me@tobin.cc>
---
Documentation/networking/filter.rst | 65 +++++++++++++++--------------
1 file changed, 33 insertions(+), 32 deletions(-)
diff --git a/Documentation/networking/filter.rst b/Documentation/networking/filter.rst
index 99dfa74fc4f7..b989a6c882b8 100644
--- a/Documentation/networking/filter.rst
+++ b/Documentation/networking/filter.rst
@@ -32,10 +32,10 @@ removing the old one and placing your new one in its place, assuming your
filter has passed the checks, otherwise if it fails the old filter will
remain on that socket.
-SO_LOCK_FILTER option allows to lock the filter attached to a socket. Once
-set, a filter cannot be removed or changed. This allows one process to
+SO_LOCK_FILTER option allows locking of the filter attached to a socket.
+Once set, a filter cannot be removed or changed. This allows one process to
setup a socket, attach a filter, lock it then drop privileges and be
-assured that the filter will be kept until the socket is closed.
+assured that the filter will be kept until the socket is closed.
The biggest user of this construct might be libpcap. Issuing a high-level
filter command like ``tcpdump -i em1 port 22`` passes through the libpcap
@@ -470,7 +470,7 @@ JIT compiler
============
The Linux kernel has a built-in BPF JIT compiler for x86_64, SPARC, PowerPC,
-ARM, ARM64, MIPS and s390 and can be enabled through CONFIG_BPF_JIT. The JIT
+ARM, ARM64, MIPS and s390 which can be enabled through CONFIG_BPF_JIT. The JIT
compiler is transparently invoked for each attached filter from user space
or for internal kernel users if it has been previously enabled by root::
@@ -580,7 +580,7 @@ Internally, for the kernel interpreter, a different instruction set
format with similar underlying principles from BPF described in previous
paragraphs is being used. However, the instruction set format is modelled
closer to the underlying architecture to mimic native instruction sets, so
-that a better performance can be achieved (more details later). This new
+that better performance can be achieved (more details later). This new
ISA is called 'eBPF' or 'internal BPF' interchangeably. (Note: eBPF which
originates from [e]xtended BPF is not the same as BPF extensions! While
eBPF is an ISA, BPF extensions date back to classic BPF's 'overloading'
@@ -655,12 +655,12 @@ Some core changes of the new internal format:
32-bit architectures run 64-bit internal BPF programs via interpreter.
Their JITs may convert BPF programs that only use 32-bit subregisters into
- native instruction set and let the rest being interpreted.
+ native instruction set and let the rest be interpreted.
- Operation is 64-bit, because on 64-bit architectures, pointers are also
- 64-bit wide, and we want to pass 64-bit values in/out of kernel functions,
- so 32-bit eBPF registers would otherwise require to define register-pair
- ABI, thus, there won't be able to use a direct eBPF register to HW register
+ Operation is 64-bit since on 64-bit architectures pointers are also
+ 64-bit wide and we want to pass 64-bit values in/out of kernel functions.
+ 32-bit eBPF registers would otherwise require us to define a register-pair
+ ABI, thus we would not be able to use a direct eBPF register to HW register
mapping and JIT would need to do combine/split/move operations for every
register in and out of the function, which is complex, bug prone and slow.
Another reason is the use of atomic 64-bit counters.
@@ -694,7 +694,7 @@ Some core changes of the new internal format:
situations without performance penalty.
After an in-kernel function call, R1 - R5 are reset to unreadable and R0 has
- a return value of the function. Since R6 - R9 are callee saved, their state
+ the return value of the function. Since R6 - R9 are callee saved, their state
is preserved across the call.
For example, consider three C functions::
@@ -732,7 +732,7 @@ Some core changes of the new internal format:
are currently not supported, but these restrictions can be lifted if necessary
in the future.
- On 64-bit architectures all register map to HW registers one to one. For
+ On 64-bit architectures all registers map to HW registers one to one. For
example, x86_64 JIT compiler can map them as ... ::
R0 - rax
@@ -831,9 +831,10 @@ A program, that is translated internally consists of the following elements::
op:16, jt:8, jf:8, k:32 ==> op:8, dst_reg:4, src_reg:4, off:16, imm:32
-So far 87 internal BPF instructions were implemented. 8-bit ``op`` opcode field
-has room for new instructions. Some of them may use 16/24/32 byte encoding. New
-instructions must be multiple of 8 bytes to preserve backward compatibility.
+So far 87 internal BPF instructions have been implemented. 8-bit ``op``
+opcode field has room for new instructions. Some of them may use 16/24/32
+byte encoding. New instructions must be a multiple of 8 bytes to preserve
+backward compatibility.
Internal BPF is a general purpose RISC instruction set. Not every register and
every instruction are used during translation from original BPF to new format.
@@ -844,11 +845,11 @@ out of registers and would have to resort to spill/fill to stack.
Internal BPF can used as generic assembler for last step performance
optimizations, socket filters and seccomp are using it as assembler. Tracing
-filters may use it as assembler to generate code from kernel. In kernel usage
+filters may use it as assembler to generate code from kernel. In-kernel usage
may not be bounded by security considerations, since generated internal BPF code
-may be optimizing internal code path and not being exposed to the user space.
-Safety of internal BPF can come from a verifier (TBD). In such use cases as
-described, it may be used as safe instruction set.
+may use an optimised internal code path and may not be being exposed to user
+space. Safety of internal BPF can come from a verifier (TBD). In such use cases
+as described, it may be used as safe as the instruction set.
Just like the original BPF, the new format runs within a controlled environment,
is deterministic and the kernel can easily prove that. The safety of the program
@@ -945,7 +946,7 @@ Classic BPF is using BPF_MISC class to represent A = X and X = A moves.
eBPF is using BPF_MOV | BPF_X | BPF_ALU code instead. Since there are no
BPF_MISC operations in eBPF, the class 7 is used as BPF_ALU64 to mean
exactly the same operations as BPF_ALU, but with 64-bit wide operands
-instead. So BPF_ADD | BPF_X | BPF_ALU64 means 64-bit addition, i.e.:
+instead. So BPF_ADD | BPF_X | BPF_ALU64 means 64-bit addition i.e.
dst_reg = dst_reg + src_reg
Classic BPF wastes the whole BPF_RET class to represent a single 'ret'
@@ -1024,8 +1025,8 @@ Where size is one of: BPF_B or BPF_H or BPF_W or BPF_DW. Note that 1 and
2 byte atomic increments are not supported.
eBPF has one 16-byte instruction: BPF_LD | BPF_DW | BPF_IMM which consists
-of two consecutive ``struct bpf_insn`` 8-byte blocks and interpreted as single
-instruction that loads 64-bit immediate value into a dst_reg.
+of two consecutive ``struct bpf_insn`` 8-byte blocks and is interpreted as
+a single instruction that loads 64-bit immediate value into a dst_reg.
Classic BPF has similar instruction: BPF_LD | BPF_W | BPF_IMM which loads
32-bit immediate value into a register.
@@ -1035,8 +1036,8 @@ eBPF verifier
The safety of the eBPF program is determined in two steps.
First step does DAG check to disallow loops and other CFG validation.
-In particular it will detect programs that have unreachable instructions.
-(though classic BPF checker allows them)
+In particular it will detect programs that have unreachable instructions
+(though classic BPF checker allows them).
Second step starts from the first insn and descends all possible paths.
It simulates execution of every insn and observes the state change of
@@ -1107,7 +1108,7 @@ For example::
bpf_ld R0 = *(u32 *)(R10 - 4)
bpf_exit
-is invalid program.
+is an invalid program.
Though R10 is correct read-only register and has type PTR_TO_STACK
and R10 - 4 is within stack bounds, there were no stores into that location.
@@ -1118,13 +1119,13 @@ Allowed function calls are customized with bpf_verifier_ops->get_func_proto()
The eBPF verifier will check that registers match argument constraints.
After the call register R0 will be set to return type of the function.
-Function calls is a main mechanism to extend functionality of eBPF programs.
-Socket filters may let programs to call one set of functions, whereas tracing
-filters may allow completely different set.
+Function calls is an important mechanism to extend functionality of eBPF
+programs. Socket filters may let programs call one set of functions,
+whereas tracing filters may allow a completely different set.
-If a function made accessible to eBPF program, it needs to be thought through
-from safety point of view. The verifier will guarantee that the function is
-called with valid arguments.
+If a function is made accessible to eBPF program, it needs to be thought
+through from a safety point of view. The verifier will guarantee that the
+function is called with valid arguments.
seccomp vs socket filters have different security restrictions for classic BPF.
Seccomp solves this by two stage verifier: classic BPF verifier is followed
@@ -1202,7 +1203,7 @@ checked and found to be non-NULL, all copies can become PTR_TO_MAP_VALUEs.
As well as range-checking, the tracked information is also used for enforcing
alignment of pointer accesses. For instance, on most systems the packet pointer
is 2 bytes after a 4-byte alignment. If a program adds 14 bytes to that to jump
-over the Ethernet header, then reads IHL and addes (IHL * 4), the resulting
+over the Ethernet header, then reads IHL and adds (IHL * 4), the resulting
pointer will have a variable offset known to be 4n+2 for some n, so adding the 2
bytes (NET_IP_ALIGN) gives a 4-byte alignment and so word-sized accesses through
that pointer are safe.
--
2.17.1
^ permalink raw reply related
* [PATCH bpf-next 05/13] docs: net: Fix indentation issues for code snippets
From: Tobin C. Harding @ 2018-08-01 5:09 UTC (permalink / raw)
To: Daniel Borkmann, Alexei Starovoitov
Cc: Tobin C. Harding, Jonathan Corbet, David S. Miller, linux-doc,
netdev, linux-kernel
In-Reply-To: <20180801050908.29970-1-me@tobin.cc>
Recent conversion of filter.txt to RST format did not fix indentation.
Sphinx emits various warnings about indentation. We should prefix all
code snippets with the RST identifier '::' and indent first column of
snippets 2 characters (inline with other docs in RST format).
Fix indentation issues for code snippets (including spaces to tabs when
appropriate).
Signed-off-by: Tobin C. Harding <me@tobin.cc>
---
Documentation/networking/filter.rst | 746 +++++++++++++++-------------
1 file changed, 398 insertions(+), 348 deletions(-)
diff --git a/Documentation/networking/filter.rst b/Documentation/networking/filter.rst
index 19325286780b..916e7ac01576 100644
--- a/Documentation/networking/filter.rst
+++ b/Documentation/networking/filter.rst
@@ -62,38 +62,40 @@ Structure
=========
User space applications include <linux/filter.h> which contains the
-following relevant structures:
+following relevant structures::
-struct sock_filter { /* Filter block */
+ struct sock_filter { /* Filter block */
__u16 code; /* Actual filter code */
__u8 jt; /* Jump true */
__u8 jf; /* Jump false */
__u32 k; /* Generic multiuse field */
-};
+ };
Such a structure is assembled as an array of 4-tuples, that contains
a code, jt, jf and k value. jt and jf are jump offsets and k a generic
value to be used for a provided code.
+::
-struct sock_fprog { /* Required for SO_ATTACH_FILTER. */
+ struct sock_fprog { /* Required for SO_ATTACH_FILTER. */
unsigned short len; /* Number of filter blocks */
struct sock_filter __user *filter;
-};
+ };
For socket filtering, a pointer to this structure (as shown in
follow-up example) is being passed to the kernel through setsockopt(2).
Example
-------
+::
-#include <sys/socket.h>
-#include <sys/types.h>
-#include <arpa/inet.h>
-#include <linux/if_ether.h>
-/* ... */
+ #include <sys/socket.h>
+ #include <sys/types.h>
+ #include <arpa/inet.h>
+ #include <linux/if_ether.h>
+ /* ... */
-/* From the example above: tcpdump -i em1 port 22 -dd */
-struct sock_filter code[] = {
+ /* From the example above: tcpdump -i em1 port 22 -dd */
+ struct sock_filter code[] = {
{ 0x28, 0, 0, 0x0000000c },
{ 0x15, 0, 8, 0x000086dd },
{ 0x30, 0, 0, 0x00000014 },
@@ -118,23 +120,23 @@ struct sock_filter code[] = {
{ 0x15, 0, 1, 0x00000016 },
{ 0x06, 0, 0, 0x0000ffff },
{ 0x06, 0, 0, 0x00000000 },
-};
+ };
-struct sock_fprog bpf = {
+ struct sock_fprog bpf = {
.len = ARRAY_SIZE(code),
.filter = code,
-};
+ };
-sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
-if (sock < 0)
+ sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
+ if (sock < 0)
/* ... bail out ... */
-ret = setsockopt(sock, SOL_SOCKET, SO_ATTACH_FILTER, &bpf, sizeof(bpf));
-if (ret < 0)
+ ret = setsockopt(sock, SOL_SOCKET, SO_ATTACH_FILTER, &bpf, sizeof(bpf));
+ if (ret < 0)
/* ... bail out ... */
-/* ... */
-close(sock);
+ /* ... */
+ close(sock);
The above example code attaches a socket filter for a PF_PACKET socket
in order to let all IPv4/IPv6 packets with port 22 pass. The rest will
@@ -179,17 +181,17 @@ bpf_asm and will be used for further explanations (instead of dealing with
less readable opcodes directly, principles are the same). The syntax is
closely modelled after Steven McCanne's and Van Jacobson's BPF paper.
-The BPF architecture consists of the following basic elements:
+The BPF architecture consists of the following basic elements::
- Element Description
+ Element Description
- A 32 bit wide accumulator
- X 32 bit wide X register
- M[] 16 x 32 bit wide misc registers aka "scratch memory
- store", addressable from 0 to 15
+ A 32 bit wide accumulator
+ X 32 bit wide X register
+ M[] 16 x 32 bit wide misc registers aka "scratch memory
+ store", addressable from 0 to 15
A program, that is translated by bpf_asm into "opcodes" is an array that
-consists of the following elements (as already mentioned):
+consists of the following elements (as already mentioned)::
op:16, jt:8, jf:8, k:32
@@ -202,7 +204,7 @@ ways depending on the given instruction in op.
The instruction set consists of load, store, branch, alu, miscellaneous
and return instructions that are also represented in bpf_asm syntax. This
table lists all bpf_asm instructions available resp. what their underlying
-opcodes as defined in linux/filter.h stand for:
+opcodes as defined in linux/filter.h stand for::
Instruction Addressing mode Description
@@ -245,7 +247,7 @@ opcodes as defined in linux/filter.h stand for:
ret 4, 9 Return
-The next table shows addressing formats from the 2nd column:
+The next table shows addressing formats from the 2nd column::
Addressing mode Syntax Description
@@ -266,7 +268,7 @@ with the class of load instructions by "overloading" the k argument with
a negative offset + a particular extension offset. The result of such BPF
extensions are loaded into A.
-Possible BPF extensions are shown in the following table:
+Possible BPF extensions are shown in the following table::
Extension Description
@@ -290,14 +292,14 @@ Possible BPF extensions are shown in the following table:
These extensions can also be prefixed with '#'.
Examples for low-level BPF:
-** ARP packets:
+** ARP packets::
ldh [12]
jne #0x806, drop
ret #-1
drop: ret #0
-** IPv4 TCP packets:
+** IPv4 TCP packets::
ldh [12]
jne #0x800, drop
@@ -306,14 +308,15 @@ Examples for low-level BPF:
ret #-1
drop: ret #0
-** (Accelerated) VLAN w/ id 10:
+** (Accelerated) VLAN w/ id 10::
ld vlan_tci
jneq #10, drop
ret #-1
drop: ret #0
-** icmp random packet sampling, 1 in 4
+** icmp random packet sampling, 1 in 4::
+
ldh [12]
jne #0x800, drop
ldb [23]
@@ -325,7 +328,7 @@ Examples for low-level BPF:
ret #-1
drop: ret #0
-** SECCOMP filter example:
+** SECCOMP filter example::
ld [4] /* offsetof(struct seccomp_data, arch) */
jne #0xc000003e, bad /* AUDIT_ARCH_X86_64 */
@@ -346,18 +349,18 @@ Examples for low-level BPF:
The above example code can be placed into a file (here called "foo"), and
then be passed to the bpf_asm tool for generating opcodes, output that xt_bpf
and cls_bpf understands and can directly be loaded with. Example with above
-ARP code:
+ARP code::
-$ ./bpf_asm foo
-4,40 0 0 12,21 0 1 2054,6 0 0 4294967295,6 0 0 0,
+ $ ./bpf_asm foo
+ 4,40 0 0 12,21 0 1 2054,6 0 0 4294967295,6 0 0 0,
-In copy and paste C-like output:
+In copy and paste C-like output::
-$ ./bpf_asm -c foo
-{ 0x28, 0, 0, 0x0000000c },
-{ 0x15, 0, 1, 0x00000806 },
-{ 0x06, 0, 0, 0xffffffff },
-{ 0x06, 0, 0, 0000000000 },
+ $ ./bpf_asm -c foo
+ { 0x28, 0, 0, 0x0000000c },
+ { 0x15, 0, 1, 0x00000806 },
+ { 0x06, 0, 0, 0xffffffff },
+ { 0x06, 0, 0, 0000000000 },
In particular, as usage with xt_bpf or cls_bpf can result in more complex BPF
filters that might not be obvious at first, it's good to test filters before
@@ -366,9 +369,9 @@ bpf_dbg under tools/bpf/ in the kernel source directory. This debugger allows
for testing BPF filters against given pcap files, single stepping through the
BPF code on the pcap's packets and to do BPF machine register dumps.
-Starting bpf_dbg is trivial and just requires issuing:
+Starting bpf_dbg is trivial and just requires issuing::
-# ./bpf_dbg
+ # ./bpf_dbg
In case input and output do not equal stdin/stdout, bpf_dbg takes an
alternative stdin source as a first argument, and an alternative stdout
@@ -381,86 +384,87 @@ file "~/.bpf_dbg_init" and the command history is stored in the file
Interaction in bpf_dbg happens through a shell that also has auto-completion
support (follow-up example commands starting with '>' denote bpf_dbg shell).
The usual workflow would be to ...
-
-> load bpf 6,40 0 0 12,21 0 3 2048,48 0 0 23,21 0 1 1,6 0 0 65535,6 0 0 0
- Loads a BPF filter from standard output of bpf_asm, or transformed via
- e.g. `tcpdump -iem1 -ddd port 22 | tr '\n' ','`. Note that for JIT
- debugging (next section), this command creates a temporary socket and
- loads the BPF code into the kernel. Thus, this will also be useful for
- JIT developers.
-
-> load pcap foo.pcap
- Loads standard tcpdump pcap file.
-
-> run [<n>]
-bpf passes:1 fails:9
- Runs through all packets from a pcap to account how many passes and fails
- the filter will generate. A limit of packets to traverse can be given.
-
-> disassemble
-l0: ldh [12]
-l1: jeq #0x800, l2, l5
-l2: ldb [23]
-l3: jeq #0x1, l4, l5
-l4: ret #0xffff
-l5: ret #0
- Prints out BPF code disassembly.
-
-> dump
-/* { op, jt, jf, k }, */
-{ 0x28, 0, 0, 0x0000000c },
-{ 0x15, 0, 3, 0x00000800 },
-{ 0x30, 0, 0, 0x00000017 },
-{ 0x15, 0, 1, 0x00000001 },
-{ 0x06, 0, 0, 0x0000ffff },
-{ 0x06, 0, 0, 0000000000 },
- Prints out C-style BPF code dump.
-
-> breakpoint 0
-breakpoint at: l0: ldh [12]
-> breakpoint 1
-breakpoint at: l1: jeq #0x800, l2, l5
- ...
- Sets breakpoints at particular BPF instructions. Issuing a `run` command
- will walk through the pcap file continuing from the current packet and
- break when a breakpoint is being hit (another `run` will continue from
- the currently active breakpoint executing next instructions):
-
- > run
- -- register dump --
- pc: [0] <-- program counter
- code: [40] jt[0] jf[0] k[12] <-- plain BPF code of current instruction
- curr: l0: ldh [12] <-- disassembly of current instruction
- A: [00000000][0] <-- content of A (hex, decimal)
- X: [00000000][0] <-- content of X (hex, decimal)
- M[0,15]: [00000000][0] <-- folded content of M (hex, decimal)
- -- packet dump -- <-- Current packet from pcap (hex)
- len: 42
- 0: 00 19 cb 55 55 a4 00 14 a4 43 78 69 08 06 00 01
- 16: 08 00 06 04 00 01 00 14 a4 43 78 69 0a 3b 01 26
- 32: 00 00 00 00 00 00 0a 3b 01 01
- (breakpoint)
- >
-
-> breakpoint
-breakpoints: 0 1
- Prints currently set breakpoints.
-
-> step [-<n>, +<n>]
- Performs single stepping through the BPF program from the current pc
- offset. Thus, on each step invocation, above register dump is issued.
- This can go forwards and backwards in time, a plain `step` will break
- on the next BPF instruction, thus +1. (No `run` needs to be issued here.)
-
-> select <n>
- Selects a given packet from the pcap file to continue from. Thus, on
- the next `run` or `step`, the BPF program is being evaluated against
- the user pre-selected packet. Numbering starts just as in Wireshark
- with index 1.
-
-> quit
-#
- Exits bpf_dbg.
+::
+
+ > load bpf 6,40 0 0 12,21 0 3 2048,48 0 0 23,21 0 1 1,6 0 0 65535,6 0 0 0
+ Loads a BPF filter from standard output of bpf_asm, or transformed via
+ e.g. `tcpdump -iem1 -ddd port 22 | tr '\n' ','`. Note that for JIT
+ debugging (next section), this command creates a temporary socket and
+ loads the BPF code into the kernel. Thus, this will also be useful for
+ JIT developers.
+
+ > load pcap foo.pcap
+ Loads standard tcpdump pcap file.
+
+ > run [<n>]
+ bpf passes:1 fails:9
+ Runs through all packets from a pcap to account how many passes and fails
+ the filter will generate. A limit of packets to traverse can be given.
+
+ > disassemble
+ l0: ldh [12]
+ l1: jeq #0x800, l2, l5
+ l2: ldb [23]
+ l3: jeq #0x1, l4, l5
+ l4: ret #0xffff
+ l5: ret #0
+ Prints out BPF code disassembly.
+
+ > dump
+ /* { op, jt, jf, k }, */
+ { 0x28, 0, 0, 0x0000000c },
+ { 0x15, 0, 3, 0x00000800 },
+ { 0x30, 0, 0, 0x00000017 },
+ { 0x15, 0, 1, 0x00000001 },
+ { 0x06, 0, 0, 0x0000ffff },
+ { 0x06, 0, 0, 0000000000 },
+ Prints out C-style BPF code dump.
+
+ > breakpoint 0
+ breakpoint at: l0: ldh [12]
+ > breakpoint 1
+ breakpoint at: l1: jeq #0x800, l2, l5
+ ...
+ Sets breakpoints at particular BPF instructions. Issuing a `run` command
+ will walk through the pcap file continuing from the current packet and
+ break when a breakpoint is being hit (another `run` will continue from
+ the currently active breakpoint executing next instructions):
+
+ > run
+ -- register dump --
+ pc: [0] <-- program counter
+ code: [40] jt[0] jf[0] k[12] <-- plain BPF code of current instruction
+ curr: l0:ldh [12] <-- disassembly of current instruction
+ A: [00000000][0] <-- content of A (hex, decimal)
+ X: [00000000][0] <-- content of X (hex, decimal)
+ M[0,15]: [00000000][0] <-- folded content of M (hex, decimal)
+ -- packet dump -- <-- Current packet from pcap (hex)
+ len: 42
+ 0: 00 19 cb 55 55 a4 00 14 a4 43 78 69 08 06 00 01
+ 16: 08 00 06 04 00 01 00 14 a4 43 78 69 0a 3b 01 26
+ 32: 00 00 00 00 00 00 0a 3b 01 01
+ (breakpoint)
+ >
+
+ > breakpoint
+ breakpoints: 0 1
+ Prints currently set breakpoints.
+
+ > step [-<n>, +<n>]
+ Performs single stepping through the BPF program from the current pc
+ offset. Thus, on each step invocation, above register dump is issued.
+ This can go forwards and backwards in time, a plain `step` will break
+ on the next BPF instruction, thus +1. (No `run` needs to be issued here.)
+
+ > select <n>
+ Selects a given packet from the pcap file to continue from. Thus, on
+ the next `run` or `step`, the BPF program is being evaluated against
+ the user pre-selected packet. Numbering starts just as in Wireshark
+ with index 1.
+
+ > quit
+ #
+ Exits bpf_dbg.
JIT compiler
============
@@ -468,23 +472,23 @@ JIT compiler
The Linux kernel has a built-in BPF JIT compiler for x86_64, SPARC, PowerPC,
ARM, ARM64, MIPS and s390 and can be enabled through CONFIG_BPF_JIT. The JIT
compiler is transparently invoked for each attached filter from user space
-or for internal kernel users if it has been previously enabled by root:
+or for internal kernel users if it has been previously enabled by root::
echo 1 > /proc/sys/net/core/bpf_jit_enable
For JIT developers, doing audits etc, each compile run can output the generated
-opcode image into the kernel log via:
+opcode image into the kernel log via::
echo 2 > /proc/sys/net/core/bpf_jit_enable
-Example output from dmesg:
+Example output from dmesg::
-[ 3389.935842] flen=6 proglen=70 pass=3 image=ffffffffa0069c8f
-[ 3389.935847] JIT code: 00000000: 55 48 89 e5 48 83 ec 60 48 89 5d f8 44 8b 4f 68
-[ 3389.935849] JIT code: 00000010: 44 2b 4f 6c 4c 8b 87 d8 00 00 00 be 0c 00 00 00
-[ 3389.935850] JIT code: 00000020: e8 1d 94 ff e0 3d 00 08 00 00 75 16 be 17 00 00
-[ 3389.935851] JIT code: 00000030: 00 e8 28 94 ff e0 83 f8 01 75 07 b8 ff ff 00 00
-[ 3389.935852] JIT code: 00000040: eb 02 31 c0 c9 c3
+ [ 3389.935842] flen=6 proglen=70 pass=3 image=ffffffffa0069c8f
+ [ 3389.935847] JIT code: 00000000: 55 48 89 e5 48 83 ec 60 48 89 5d f8 44 8b 4f 68
+ [ 3389.935849] JIT code: 00000010: 44 2b 4f 6c 4c 8b 87 d8 00 00 00 be 0c 00 00 00
+ [ 3389.935850] JIT code: 00000020: e8 1d 94 ff e0 3d 00 08 00 00 75 16 be 17 00 00
+ [ 3389.935851] JIT code: 00000030: 00 e8 28 94 ff e0 83 f8 01 75 07 b8 ff ff 00 00
+ [ 3389.935852] JIT code: 00000040: eb 02 31 c0 c9 c3
When CONFIG_BPF_JIT_ALWAYS_ON is enabled, bpf_jit_enable is permanently set to 1 and
setting any other value than that will return in failure. This is even the case for
@@ -493,77 +497,77 @@ is discouraged and introspection through bpftool (under tools/bpf/bpftool/) is t
generally recommended approach instead.
In the kernel source tree under tools/bpf/, there's bpf_jit_disasm for
-generating disassembly out of the kernel log's hexdump:
-
-# ./bpf_jit_disasm
-70 bytes emitted from JIT compiler (pass:3, flen:6)
-ffffffffa0069c8f + <x>:
- 0: push %rbp
- 1: mov %rsp,%rbp
- 4: sub $0x60,%rsp
- 8: mov %rbx,-0x8(%rbp)
- c: mov 0x68(%rdi),%r9d
- 10: sub 0x6c(%rdi),%r9d
- 14: mov 0xd8(%rdi),%r8
- 1b: mov $0xc,%esi
- 20: callq 0xffffffffe0ff9442
- 25: cmp $0x800,%eax
- 2a: jne 0x0000000000000042
- 2c: mov $0x17,%esi
- 31: callq 0xffffffffe0ff945e
- 36: cmp $0x1,%eax
- 39: jne 0x0000000000000042
- 3b: mov $0xffff,%eax
- 40: jmp 0x0000000000000044
- 42: xor %eax,%eax
- 44: leaveq
- 45: retq
+generating disassembly out of the kernel log's hexdump::
+
+ # ./bpf_jit_disasm
+ 70 bytes emitted from JIT compiler (pass:3, flen:6)
+ ffffffffa0069c8f + <x>:
+ 0: push %rbp
+ 1: mov %rsp,%rbp
+ 4: sub $0x60,%rsp
+ 8: mov %rbx,-0x8(%rbp)
+ c: mov 0x68(%rdi),%r9d
+ 10: sub 0x6c(%rdi),%r9d
+ 14: mov 0xd8(%rdi),%r8
+ 1b: mov $0xc,%esi
+ 20: callq 0xffffffffe0ff9442
+ 25: cmp $0x800,%eax
+ 2a: jne 0x0000000000000042
+ 2c: mov $0x17,%esi
+ 31: callq 0xffffffffe0ff945e
+ 36: cmp $0x1,%eax
+ 39: jne 0x0000000000000042
+ 3b: mov $0xffff,%eax
+ 40: jmp 0x0000000000000044
+ 42: xor %eax,%eax
+ 44: leaveq
+ 45: retq
Issuing option `-o` will "annotate" opcodes to resulting assembler
-instructions, which can be very useful for JIT developers:
+instructions, which can be very useful for JIT developers::
-# ./bpf_jit_disasm -o
-70 bytes emitted from JIT compiler (pass:3, flen:6)
-ffffffffa0069c8f + <x>:
- 0: push %rbp
+ # ./bpf_jit_disasm -o
+ 70 bytes emitted from JIT compiler (pass:3, flen:6)
+ ffffffffa0069c8f + <x>:
+ 0: push %rbp
55
- 1: mov %rsp,%rbp
+ 1: mov %rsp,%rbp
48 89 e5
- 4: sub $0x60,%rsp
+ 4: sub $0x60,%rsp
48 83 ec 60
- 8: mov %rbx,-0x8(%rbp)
+ 8: mov %rbx,-0x8(%rbp)
48 89 5d f8
- c: mov 0x68(%rdi),%r9d
+ c: mov 0x68(%rdi),%r9d
44 8b 4f 68
- 10: sub 0x6c(%rdi),%r9d
+ 10: sub 0x6c(%rdi),%r9d
44 2b 4f 6c
- 14: mov 0xd8(%rdi),%r8
+ 14: mov 0xd8(%rdi),%r8
4c 8b 87 d8 00 00 00
- 1b: mov $0xc,%esi
+ 1b: mov $0xc,%esi
be 0c 00 00 00
- 20: callq 0xffffffffe0ff9442
+ 20: callq 0xffffffffe0ff9442
e8 1d 94 ff e0
- 25: cmp $0x800,%eax
+ 25: cmp $0x800,%eax
3d 00 08 00 00
- 2a: jne 0x0000000000000042
+ 2a: jne 0x0000000000000042
75 16
- 2c: mov $0x17,%esi
+ 2c: mov $0x17,%esi
be 17 00 00 00
- 31: callq 0xffffffffe0ff945e
+ 31: callq 0xffffffffe0ff945e
e8 28 94 ff e0
- 36: cmp $0x1,%eax
+ 36: cmp $0x1,%eax
83 f8 01
- 39: jne 0x0000000000000042
+ 39: jne 0x0000000000000042
75 07
- 3b: mov $0xffff,%eax
+ 3b: mov $0xffff,%eax
b8 ff ff 00 00
- 40: jmp 0x0000000000000044
+ 40: jmp 0x0000000000000044
eb 02
- 42: xor %eax,%eax
+ 42: xor %eax,%eax
31 c0
- 44: leaveq
+ 44: leaveq
c9
- 45: retq
+ 45: retq
c3
For BPF JIT developers, bpf_jit_disasm, bpf_asm and bpf_dbg provides a useful
@@ -663,9 +667,18 @@ Some core changes of the new internal format:
- Conditional jt/jf targets replaced with jt/fall-through:
- While the original design has constructs such as "if (cond) jump_true;
- else jump_false;", they are being replaced into alternative constructs like
- "if (cond) jump_true; /* else fall-through */".
+ While the original design has constructs such as::
+
+ if (cond)
+ jump_true;
+ else
+ jump_false;
+
+ they are being replaced into alternative constructs like::
+
+ if (cond)
+ jump_true;
+ /* else fall-through */
- Introduces bpf_call insn and register passing convention for zero overhead
calls from/to other kernel functions:
@@ -684,30 +697,30 @@ Some core changes of the new internal format:
a return value of the function. Since R6 - R9 are callee saved, their state
is preserved across the call.
- For example, consider three C functions:
+ For example, consider three C functions::
- u64 f1() { return (*_f2)(1); }
- u64 f2(u64 a) { return f3(a + 1, a); }
- u64 f3(u64 a, u64 b) { return a - b; }
+ u64 f1() { return (*_f2)(1); }
+ u64 f2(u64 a) { return f3(a + 1, a); }
+ u64 f3(u64 a, u64 b) { return a - b; }
- GCC can compile f1, f3 into x86_64:
+ GCC can compile f1, f3 into x86_64::
- f1:
- movl $1, %edi
- movq _f2(%rip), %rax
- jmp *%rax
- f3:
- movq %rdi, %rax
- subq %rsi, %rax
- ret
+ f1:
+ movl $1, %edi
+ movq _f2(%rip), %rax
+ jmp *%rax
+ f3:
+ movq %rdi, %rax
+ subq %rsi, %rax
+ ret
- Function f2 in eBPF may look like:
+ Function f2 in eBPF may look like::
- f2:
- bpf_mov R2, R1
- bpf_add R1, 1
- bpf_call f3
- bpf_exit
+ f2:
+ bpf_mov R2, R1
+ bpf_add R1, 1
+ bpf_call f3
+ bpf_exit
If f2 is JITed and the pointer stored to '_f2'. The calls f1 -> f2 -> f3 and
returns will be seamless. Without JIT, __bpf_prog_run() interpreter needs to
@@ -720,7 +733,7 @@ Some core changes of the new internal format:
in the future.
On 64-bit architectures all register map to HW registers one to one. For
- example, x86_64 JIT compiler can map them as ...
+ example, x86_64 JIT compiler can map them as ... ::
R0 - rax
R1 - rdi
@@ -737,7 +750,7 @@ Some core changes of the new internal format:
... since x86_64 ABI mandates rdi, rsi, rdx, rcx, r8, r9 for argument passing
and rbx, r12 - r15 are callee saved.
- Then the following internal BPF pseudo-program:
+ Then the following internal BPF pseudo-program::
bpf_mov R6, R1 /* save ctx */
bpf_mov R2, 2
@@ -755,7 +768,7 @@ Some core changes of the new internal format:
bpf_add R0, R7
bpf_exit
- After JIT to x86_64 may look like:
+ After JIT to x86_64 may look like::
push %rbp
mov %rsp,%rbp
@@ -781,11 +794,11 @@ Some core changes of the new internal format:
leaveq
retq
- Which is in this example equivalent in C to:
+ Which is in this example equivalent in C to::
u64 bpf_filter(u64 ctx)
{
- return foo(ctx, 2, 3, 4, 5) + bar(ctx, 6, 7, 8, 9);
+ return foo(ctx, 2, 3, 4, 5) + bar(ctx, 6, 7, 8, 9);
}
In-kernel functions foo() and bar() with prototype: u64 (*)(u64 arg1, u64
@@ -795,7 +808,7 @@ Some core changes of the new internal format:
interpreter. R0-R5 are scratch registers, so eBPF program needs to preserve
them across the calls as defined by calling convention.
- For example the following program is invalid:
+ For example the following program is invalid::
bpf_mov R1, 1
bpf_call foo
@@ -814,7 +827,7 @@ The input context pointer for invoking the interpreter function is generic,
its content is defined by a specific use case. For seccomp register R1 points
to seccomp_data, for converted BPF filters R1 points to a skb.
-A program, that is translated internally consists of the following elements:
+A program, that is translated internally consists of the following elements::
op:16, jt:8, jf:8, k:32 ==> op:8, dst_reg:4, src_reg:4, off:16, imm:32
@@ -849,7 +862,7 @@ eBPF opcode encoding
eBPF is reusing most of the opcode encoding from classic to simplify conversion
of classic BPF to eBPF. For arithmetic and jump instructions the 8-bit 'code'
-field is divided into three parts:
+field is divided into three parts::
+----------------+--------+--------------------+
| 4 bits | 1 bit | 3 bits |
@@ -857,7 +870,7 @@ field is divided into three parts:
+----------------+--------+--------------------+
(MSB) (LSB)
-Three LSB bits store instruction class which is one of:
+Three LSB bits store instruction class which is one of::
Classic BPF classes: eBPF classes:
@@ -871,23 +884,24 @@ Three LSB bits store instruction class which is one of:
BPF_MISC 0x07 BPF_ALU64 0x07
When BPF_CLASS(code) == BPF_ALU or BPF_JMP, 4th bit encodes source operand ...
+::
BPF_K 0x00
BPF_X 0x08
- * in classic BPF, this means:
+in classic BPF, this means::
BPF_SRC(code) == BPF_X - use register X as source operand
BPF_SRC(code) == BPF_K - use 32-bit immediate as source operand
- * in eBPF, this means:
+in eBPF, this means::
BPF_SRC(code) == BPF_X - use 'src_reg' register as source operand
BPF_SRC(code) == BPF_K - use 32-bit immediate as source operand
... and four MSB bits store operation code.
-If BPF_CLASS(code) == BPF_ALU or BPF_ALU64 [ in eBPF ], BPF_OP(code) is one of:
+If BPF_CLASS(code) == BPF_ALU or BPF_ALU64 [ in eBPF ], BPF_OP(code) is one of::
BPF_ADD 0x00
BPF_SUB 0x10
@@ -904,7 +918,7 @@ If BPF_CLASS(code) == BPF_ALU or BPF_ALU64 [ in eBPF ], BPF_OP(code) is one of:
BPF_ARSH 0xc0 /* eBPF only: sign extending shift right */
BPF_END 0xd0 /* eBPF only: endianness conversion */
-If BPF_CLASS(code) == BPF_JMP, BPF_OP(code) is one of:
+If BPF_CLASS(code) == BPF_JMP, BPF_OP(code) is one of::
BPF_JA 0x00
BPF_JEQ 0x10
@@ -941,7 +955,7 @@ in eBPF means function exit only. The eBPF program needs to store return
value into register R0 before doing a BPF_EXIT. Class 6 in eBPF is currently
unused and reserved for future use.
-For load and store instructions the 8-bit 'code' field is divided as:
+For load and store instructions the 8-bit 'code' field is divided as::
+--------+--------+-------------------+
| 3 bits | 2 bits | 3 bits |
@@ -949,21 +963,21 @@ For load and store instructions the 8-bit 'code' field is divided as:
+--------+--------+-------------------+
(MSB) (LSB)
-Size modifier is one of ...
+Size modifier is one of ... ::
BPF_W 0x00 /* word */
BPF_H 0x08 /* half word */
BPF_B 0x10 /* byte */
BPF_DW 0x18 /* eBPF only, double word */
-... which encodes size of load/store operation:
+... which encodes size of load/store operation::
- B - 1 byte
- H - 2 byte
- W - 4 byte
- DW - 8 byte (eBPF only)
+ B - 1 byte
+ H - 2 byte
+ W - 4 byte
+ DW - 8 byte (eBPF only)
-Mode modifier is one of:
+Mode modifier is one of::
BPF_IMM 0x00 /* used for 32-bit mov in classic BPF and 64-bit in eBPF */
BPF_ABS 0x20
@@ -991,20 +1005,20 @@ the interpreter will abort the execution of the program. JIT compilers
therefore must preserve this property. src_reg and imm32 fields are
explicit inputs to these instructions.
-For example:
+For example::
BPF_IND | BPF_W | BPF_LD means:
R0 = ntohl(*(u32 *) (((struct sk_buff *) R6)->data + src_reg + imm32))
and R1 - R5 were scratched.
-Unlike classic BPF instruction set, eBPF has generic load/store operations:
+Unlike classic BPF instruction set, eBPF has generic load/store operations::
-BPF_MEM | <size> | BPF_STX: *(size *) (dst_reg + off) = src_reg
-BPF_MEM | <size> | BPF_ST: *(size *) (dst_reg + off) = imm32
-BPF_MEM | <size> | BPF_LDX: dst_reg = *(size *) (src_reg + off)
-BPF_XADD | BPF_W | BPF_STX: lock xadd *(u32 *)(dst_reg + off16) += src_reg
-BPF_XADD | BPF_DW | BPF_STX: lock xadd *(u64 *)(dst_reg + off16) += src_reg
+ BPF_MEM | <size> | BPF_STX: *(size *) (dst_reg + off) = src_reg
+ BPF_MEM | <size> | BPF_ST: *(size *) (dst_reg + off) = imm32
+ BPF_MEM | <size> | BPF_LDX: dst_reg = *(size *) (src_reg + off)
+ BPF_XADD | BPF_W | BPF_STX: lock xadd *(u32 *)(dst_reg + off16) += src_reg
+ BPF_XADD | BPF_DW | BPF_STX: lock xadd *(u64 *)(dst_reg + off16) += src_reg
Where size is one of: BPF_B or BPF_H or BPF_W or BPF_DW. Note that 1 and
2 byte atomic increments are not supported.
@@ -1037,29 +1051,35 @@ since addition of two valid pointers makes invalid pointer.
(In 'secure' mode verifier will reject any type of pointer arithmetic to make
sure that kernel addresses don't leak to unprivileged users)
-If register was never written to, it's not readable:
+If register was never written to, it's not readable::
+
bpf_mov R0 = R2
bpf_exit
+
will be rejected, since R2 is unreadable at the start of the program.
After kernel function call, R1-R5 are reset to unreadable and
R0 has a return type of the function.
-Since R6-R9 are callee saved, their state is preserved across the call.
+Since R6-R9 are callee saved, their state is preserved across the call. ::
+
bpf_mov R6 = 1
bpf_call foo
bpf_mov R0 = R6
bpf_exit
+
is a correct program. If there was R1 instead of R6, it would have
been rejected.
load/store instructions are allowed only with registers of valid types, which
are PTR_TO_CTX, PTR_TO_MAP, PTR_TO_STACK. They are bounds and alignment checked.
-For example:
+For example::
+
bpf_mov R1 = 1
bpf_mov R2 = 2
bpf_xadd *(u32 *)(R1 + 3) += R2
bpf_exit
+
will be rejected, since R1 doesn't have a valid pointer type at the time of
execution of instruction bpf_xadd.
@@ -1067,8 +1087,10 @@ At the start R1 type is PTR_TO_CTX (a pointer to generic 'struct bpf_context')
A callback is used to customize verifier to restrict eBPF program access to only
certain fields within ctx structure with specified size and alignment.
-For example, the following insn:
+For example, the following insn::
+
bpf_ld R0 = *(u32 *)(R6 + 8)
+
intends to load a word from address R6 + 8 and store it into R0
If R6=PTR_TO_CTX, via is_valid_access() callback the verifier will know
that offset 8 of size 4 bytes can be accessed for reading, otherwise
@@ -1080,9 +1102,11 @@ so it will fail verification, since it's out of bounds.
The verifier will allow eBPF program to read data from stack only after
it wrote into it.
Classic BPF verifier does similar check with M[0-15] memory slots.
-For example:
+For example::
+
bpf_ld R0 = *(u32 *)(R10 - 4)
bpf_exit
+
is invalid program.
Though R10 is correct read-only register and has type PTR_TO_STACK
and R10 - 4 is within stack bounds, there were no stores into that location.
@@ -1118,19 +1142,21 @@ This is done with 'struct bpf_reg_state', defined in include/linux/
bpf_verifier.h, which unifies tracking of scalar and pointer values. Each
register state has a type, which is either NOT_INIT (the register has not been
written to), SCALAR_VALUE (some value which is not usable as a pointer), or a
-pointer type. The types of pointers describe their base, as follows:
+pointer type. The types of pointers describe their base, as follows::
+
PTR_TO_CTX Pointer to bpf_context.
CONST_PTR_TO_MAP Pointer to struct bpf_map. "Const" because arithmetic
- on these pointers is forbidden.
+ on these pointers is forbidden.
PTR_TO_MAP_VALUE Pointer to the value stored in a map element.
PTR_TO_MAP_VALUE_OR_NULL
- Either a pointer to a map value, or NULL; map accesses
- (see section 'eBPF maps', below) return this type,
- which becomes a PTR_TO_MAP_VALUE when checked != NULL.
- Arithmetic on these pointers is forbidden.
+ Either a pointer to a map value, or NULL; map accesses
+ (see section 'eBPF maps', below) return this type,
+ which becomes a PTR_TO_MAP_VALUE when checked != NULL.
+ Arithmetic on these pointers is forbidden.
PTR_TO_STACK Frame pointer.
PTR_TO_PACKET skb->data.
PTR_TO_PACKET_END skb->data + headlen; arithmetic forbidden.
+
However, a pointer may be offset from this base (as a result of pointer
arithmetic), and this is tracked in two parts: the 'fixed offset' and 'variable
offset'. The former is used when an exactly-known value (e.g. an immediate
@@ -1182,14 +1208,15 @@ Direct packet access
====================
In cls_bpf and act_bpf programs the verifier allows direct access to the packet
data via skb->data and skb->data_end pointers.
-Ex:
-1: r4 = *(u32 *)(r1 +80) /* load skb->data_end */
-2: r3 = *(u32 *)(r1 +76) /* load skb->data */
-3: r5 = r3
-4: r5 += 14
-5: if r5 > r4 goto pc+16
-R1=ctx R3=pkt(id=0,off=0,r=14) R4=pkt_end R5=pkt(id=0,off=14,r=14) R10=fp
-6: r0 = *(u16 *)(r3 +12) /* access 12 and 13 bytes of the packet */
+Ex::
+
+ 1: r4 = *(u32 *)(r1 +80) /* load skb->data_end */
+ 2: r3 = *(u32 *)(r1 +76) /* load skb->data */
+ 3: r5 = r3
+ 4: r5 += 14
+ 5: if r5 > r4 goto pc+16
+ R1=ctx R3=pkt(id=0,off=0,r=14) R4=pkt_end R5=pkt(id=0,off=14,r=14) R10=fp
+ 6: r0 = *(u16 *)(r3 +12) /* access 12 and 13 bytes of the packet */
this 2byte load from the packet is safe to do, since the program author
did check 'if (skb->data + 14 > skb->data_end) goto err' at insn #5 which
@@ -1204,23 +1231,25 @@ to the packet data, but constant 14 was added to the register, so
it now points to 'skb->data + 14' and accessible range is [R5, R5 + 14 - 14)
which is zero bytes.
-More complex packet access may look like:
- R0=inv1 R1=ctx R3=pkt(id=0,off=0,r=14) R4=pkt_end R5=pkt(id=0,off=14,r=14) R10=fp
- 6: r0 = *(u8 *)(r3 +7) /* load 7th byte from the packet */
- 7: r4 = *(u8 *)(r3 +12)
- 8: r4 *= 14
- 9: r3 = *(u32 *)(r1 +76) /* load skb->data */
-10: r3 += r4
-11: r2 = r1
-12: r2 <<= 48
-13: r2 >>= 48
-14: r3 += r2
-15: r2 = r3
-16: r2 += 8
-17: r1 = *(u32 *)(r1 +80) /* load skb->data_end */
-18: if r2 > r1 goto pc+2
- R0=inv(id=0,umax_value=255,var_off=(0x0; 0xff)) R1=pkt_end R2=pkt(id=2,off=8,r=8) R3=pkt(id=2,off=0,r=8) R4=inv(id=0,umax_value=3570,var_off=(0x0; 0xfffe)) R5=pkt(id=0,off=14,r=14) R10=fp
-19: r1 = *(u8 *)(r3 +4)
+More complex packet access may look like::
+
+ R0=inv1 R1=ctx R3=pkt(id=0,off=0,r=14) R4=pkt_end R5=pkt(id=0,off=14,r=14) R10=fp
+ 6: r0 = *(u8 *)(r3 +7) /* load 7th byte from the packet */
+ 7: r4 = *(u8 *)(r3 +12)
+ 8: r4 *= 14
+ 9: r3 = *(u32 *)(r1 +76) /* load skb->data */
+ 10: r3 += r4
+ 11: r2 = r1
+ 12: r2 <<= 48
+ 13: r2 >>= 48
+ 14: r3 += r2
+ 15: r2 = r3
+ 16: r2 += 8
+ 17: r1 = *(u32 *)(r1 +80) /* load skb->data_end */
+ 18: if r2 > r1 goto pc+2
+ R0=inv(id=0,umax_value=255,var_off=(0x0; 0xff)) R1=pkt_end R2=pkt(id=2,off=8,r=8) R3=pkt(id=2,off=0,r=8) R4=inv(id=0,umax_value=3570,var_off=(0x0; 0xfffe)) R5=pkt(id=0,off=14,r=14) R10=fp
+ 19: r1 = *(u8 *)(r3 +4)
+
The state of the register R3 is R3=pkt(id=2,off=0,r=8)
id=2 means that two 'r3 += rX' instructions were seen, so r3 points to some
offset within a packet and since the program author did
@@ -1246,7 +1275,8 @@ which calls adjust_ptr_min_max_vals() for adding pointer to scalar (or vice
versa) and adjust_scalar_min_max_vals() for operations on two scalars.
The end result is that bpf program author can access packet directly
-using normal C code as:
+using normal C code as::
+
void *data = (void *)(long)skb->data;
void *data_end = (void *)(long)skb->data_end;
struct eth_hdr *eth = data;
@@ -1254,13 +1284,14 @@ using normal C code as:
struct udphdr *udp = data + sizeof(*eth) + sizeof(*iph);
if (data + sizeof(*eth) + sizeof(*iph) + sizeof(*udp) > data_end)
- return 0;
+ return 0;
if (eth->h_proto != htons(ETH_P_IP))
- return 0;
+ return 0;
if (iph->protocol != IPPROTO_UDP || iph->ihl != 5)
- return 0;
+ return 0;
if (udp->dest == 53 || udp->source == 9)
- ...;
+ ...;
+
which makes such programs easier to write comparing to LD_ABS insn
and significantly faster.
@@ -1271,6 +1302,7 @@ eBPF maps
and userspace.
The maps are accessed from user space via BPF syscall, which has commands:
+
- create a map with given type and attributes
map_fd = bpf(BPF_MAP_CREATE, union bpf_attr *attr, u32 size)
using attr->map_type, attr->key_size, attr->value_size, attr->max_entries
@@ -1327,66 +1359,79 @@ Understanding eBPF verifier messages
The following are few examples of invalid eBPF programs and verifier error
messages as seen in the log:
-Program with unreachable instructions:
-static struct bpf_insn prog[] = {
- BPF_EXIT_INSN(),
- BPF_EXIT_INSN(),
-};
-Error:
- unreachable insn 1
+Program with unreachable instructions::
+
+ static struct bpf_insn prog[] = {
+ BPF_EXIT_INSN(),
+ BPF_EXIT_INSN(),
+ };
+
+ Error:
+ unreachable insn 1
+
+Program that reads uninitialized register::
-Program that reads uninitialized register:
BPF_MOV64_REG(BPF_REG_0, BPF_REG_2),
BPF_EXIT_INSN(),
-Error:
- 0: (bf) r0 = r2
- R2 !read_ok
-Program that doesn't initialize R0 before exiting:
+ Error:
+ 0: (bf) r0 = r2
+ R2 !read_ok
+
+Program that doesn't initialize R0 before exiting::
+
BPF_MOV64_REG(BPF_REG_2, BPF_REG_1),
BPF_EXIT_INSN(),
-Error:
- 0: (bf) r2 = r1
- 1: (95) exit
- R0 !read_ok
-Program that accesses stack out of bounds:
+ Error:
+ 0: (bf) r2 = r1
+ 1: (95) exit
+ R0 !read_ok
+
+Program that accesses stack out of bounds::
+
BPF_ST_MEM(BPF_DW, BPF_REG_10, 8, 0),
BPF_EXIT_INSN(),
-Error:
- 0: (7a) *(u64 *)(r10 +8) = 0
- invalid stack off=8 size=8
-Program that doesn't initialize stack before passing its address into function:
+ Error:
+ 0: (7a) *(u64 *)(r10 +8) = 0
+ invalid stack off=8 size=8
+
+Program that doesn't initialize stack before passing its address into function::
+
BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
BPF_LD_MAP_FD(BPF_REG_1, 0),
BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_map_lookup_elem),
BPF_EXIT_INSN(),
-Error:
- 0: (bf) r2 = r10
- 1: (07) r2 += -8
- 2: (b7) r1 = 0x0
- 3: (85) call 1
- invalid indirect read from stack off -8+0 size 8
-
-Program that uses invalid map_fd=0 while calling to map_lookup_elem() function:
+
+ Error:
+ 0: (bf) r2 = r10
+ 1: (07) r2 += -8
+ 2: (b7) r1 = 0x0
+ 3: (85) call 1
+ invalid indirect read from stack off -8+0 size 8
+
+Program that uses invalid map_fd=0 while calling to map_lookup_elem() function::
+
BPF_ST_MEM(BPF_DW, BPF_REG_10, -8, 0),
BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
BPF_LD_MAP_FD(BPF_REG_1, 0),
BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_map_lookup_elem),
BPF_EXIT_INSN(),
-Error:
- 0: (7a) *(u64 *)(r10 -8) = 0
- 1: (bf) r2 = r10
- 2: (07) r2 += -8
- 3: (b7) r1 = 0x0
- 4: (85) call 1
- fd 0 is not pointing to valid bpf_map
+
+ Error:
+ 0: (7a) *(u64 *)(r10 -8) = 0
+ 1: (bf) r2 = r10
+ 2: (07) r2 += -8
+ 3: (b7) r1 = 0x0
+ 4: (85) call 1
+ fd 0 is not pointing to valid bpf_map
Program that doesn't check return value of map_lookup_elem() before accessing
-map element:
+map element::
+
BPF_ST_MEM(BPF_DW, BPF_REG_10, -8, 0),
BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
@@ -1394,17 +1439,19 @@ map element:
BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_map_lookup_elem),
BPF_ST_MEM(BPF_DW, BPF_REG_0, 0, 0),
BPF_EXIT_INSN(),
-Error:
- 0: (7a) *(u64 *)(r10 -8) = 0
- 1: (bf) r2 = r10
- 2: (07) r2 += -8
- 3: (b7) r1 = 0x0
- 4: (85) call 1
- 5: (7a) *(u64 *)(r0 +0) = 0
- R0 invalid mem access 'map_value_or_null'
+
+ Error:
+ 0: (7a) *(u64 *)(r10 -8) = 0
+ 1: (bf) r2 = r10
+ 2: (07) r2 += -8
+ 3: (b7) r1 = 0x0
+ 4: (85) call 1
+ 5: (7a) *(u64 *)(r0 +0) = 0
+ R0 invalid mem access 'map_value_or_null'
Program that correctly checks map_lookup_elem() returned value for NULL, but
-accesses the memory with incorrect alignment:
+accesses the memory with incorrect alignment::
+
BPF_ST_MEM(BPF_DW, BPF_REG_10, -8, 0),
BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
@@ -1413,20 +1460,22 @@ accesses the memory with incorrect alignment:
BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 1),
BPF_ST_MEM(BPF_DW, BPF_REG_0, 4, 0),
BPF_EXIT_INSN(),
-Error:
- 0: (7a) *(u64 *)(r10 -8) = 0
- 1: (bf) r2 = r10
- 2: (07) r2 += -8
- 3: (b7) r1 = 1
- 4: (85) call 1
- 5: (15) if r0 == 0x0 goto pc+1
- R0=map_ptr R10=fp
- 6: (7a) *(u64 *)(r0 +4) = 0
- misaligned access off 4 size 8
+
+ Error:
+ 0: (7a) *(u64 *)(r10 -8) = 0
+ 1: (bf) r2 = r10
+ 2: (07) r2 += -8
+ 3: (b7) r1 = 1
+ 4: (85) call 1
+ 5: (15) if r0 == 0x0 goto pc+1
+ R0=map_ptr R10=fp
+ 6: (7a) *(u64 *)(r0 +4) = 0
+ misaligned access off 4 size 8
Program that correctly checks map_lookup_elem() returned value for NULL and
accesses memory with correct alignment in one side of 'if' branch, but fails
-to do so in the other side of 'if' branch:
+to do so in the other side of 'if' branch::
+
BPF_ST_MEM(BPF_DW, BPF_REG_10, -8, 0),
BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
@@ -1437,20 +1486,21 @@ to do so in the other side of 'if' branch:
BPF_EXIT_INSN(),
BPF_ST_MEM(BPF_DW, BPF_REG_0, 0, 1),
BPF_EXIT_INSN(),
-Error:
- 0: (7a) *(u64 *)(r10 -8) = 0
- 1: (bf) r2 = r10
- 2: (07) r2 += -8
- 3: (b7) r1 = 1
- 4: (85) call 1
- 5: (15) if r0 == 0x0 goto pc+2
- R0=map_ptr R10=fp
- 6: (7a) *(u64 *)(r0 +0) = 0
- 7: (95) exit
-
- from 5 to 8: R0=imm0 R10=fp
- 8: (7a) *(u64 *)(r0 +0) = 1
- R0 invalid mem access 'imm'
+
+ Error:
+ 0: (7a) *(u64 *)(r10 -8) = 0
+ 1: (bf) r2 = r10
+ 2: (07) r2 += -8
+ 3: (b7) r1 = 1
+ 4: (85) call 1
+ 5: (15) if r0 == 0x0 goto pc+2
+ R0=map_ptr R10=fp
+ 6: (7a) *(u64 *)(r0 +0) = 0
+ 7: (95) exit
+
+ from 5 to 8: R0=imm0 R10=fp
+ 8: (7a) *(u64 *)(r0 +0) = 1
+ R0 invalid mem access 'imm'
Testing
=======
@@ -1458,7 +1508,7 @@ Testing
Next to the BPF toolchain, the kernel also ships a test module that contains
various test cases for classic and internal BPF that can be executed against
the BPF interpreter and JIT compiler. It can be found in lib/test_bpf.c and
-enabled via Kconfig:
+enabled via Kconfig::
CONFIG_TEST_BPF=m
--
2.17.1
^ permalink raw reply related
* [PATCH bpf-next 02/13] docs: Update references to filter.rst
From: Tobin C. Harding @ 2018-08-01 5:08 UTC (permalink / raw)
To: Daniel Borkmann, Alexei Starovoitov
Cc: Tobin C. Harding, Jonathan Corbet, David S. Miller, linux-doc,
netdev, linux-kernel
In-Reply-To: <20180801050908.29970-1-me@tobin.cc>
Documentation/networking/filter.rst was just renamed. In order to use RST
references we need to add a label to filter.rst
Add label and update references from filter.txt to filter.rst
Signed-off-by: Tobin C. Harding <me@tobin.cc>
---
Documentation/bpf/index.rst | 9 ++++-----
Documentation/networking/filter.rst | 2 ++
Documentation/networking/packet_mmap.txt | 2 +-
tools/bpf/bpf_asm.c | 2 +-
tools/bpf/bpf_dbg.c | 2 +-
5 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/Documentation/bpf/index.rst b/Documentation/bpf/index.rst
index 00a8450a602f..192393135c61 100644
--- a/Documentation/bpf/index.rst
+++ b/Documentation/bpf/index.rst
@@ -7,10 +7,10 @@ Filter) facility, with a focus on the extended BPF version (eBPF).
This kernel side documentation is still work in progress. The main
textual documentation is (for historical reasons) described in
-`Documentation/networking/filter.txt`_, which describe both classical
-and extended BPF instruction-set.
-The Cilium project also maintains a `BPF and XDP Reference Guide`_
-that goes into great technical depth about the BPF Architecture.
+:ref:`Documentation/networking/filter.rst <bpf_filter>`, which describe
+both classical and extended BPF instruction-set. The Cilium project also
+maintains a `BPF and XDP Reference Guide`_ that goes into great technical
+depth about the BPF Architecture.
The primary info for the bpf syscall is available in the `man-pages`_
for `bpf(2)`_.
@@ -30,7 +30,6 @@ Two sets of Questions and Answers (Q&A) are maintained.
.. Links:
-.. _Documentation/networking/filter.txt: ../networking/filter.txt
.. _man-pages: https://www.kernel.org/doc/man-pages/
.. _bpf(2): http://man7.org/linux/man-pages/man2/bpf.2.html
.. _BPF and XDP Reference Guide: http://cilium.readthedocs.io/en/latest/bpf/
diff --git a/Documentation/networking/filter.rst b/Documentation/networking/filter.rst
index e6b4ebb2b243..14ce8901c245 100644
--- a/Documentation/networking/filter.rst
+++ b/Documentation/networking/filter.rst
@@ -1,6 +1,8 @@
Linux Socket Filtering aka Berkeley Packet Filter (BPF)
=======================================================
+.. _bpf_filter:
+
Introduction
------------
diff --git a/Documentation/networking/packet_mmap.txt b/Documentation/networking/packet_mmap.txt
index 999eb41da81d..494614573c67 100644
--- a/Documentation/networking/packet_mmap.txt
+++ b/Documentation/networking/packet_mmap.txt
@@ -1051,7 +1051,7 @@ for more information on hardware timestamps.
-------------------------------------------------------------------------------
- Packet sockets work well together with Linux socket filters, thus you also
- might want to have a look at Documentation/networking/filter.txt
+ might want to have a look at Documentation/networking/filter.rst
--------------------------------------------------------------------------------
+ THANKS
diff --git a/tools/bpf/bpf_asm.c b/tools/bpf/bpf_asm.c
index c15aef097b04..5040875735db 100644
--- a/tools/bpf/bpf_asm.c
+++ b/tools/bpf/bpf_asm.c
@@ -10,7 +10,7 @@
*
* How to get into it:
*
- * 1) read Documentation/networking/filter.txt
+ * 1) read Documentation/networking/filter.rst
* 2) Run `bpf_asm [-c] <filter-prog file>` to translate into binary
* blob that is loadable with xt_bpf, cls_bpf et al. Note: -c will
* pretty print a C-like construct.
diff --git a/tools/bpf/bpf_dbg.c b/tools/bpf/bpf_dbg.c
index 61b9aa5d6415..d05d8df0ce3b 100644
--- a/tools/bpf/bpf_dbg.c
+++ b/tools/bpf/bpf_dbg.c
@@ -12,7 +12,7 @@
* for making a verdict when multiple simple BPF programs are combined
* into one in order to prevent parsing same headers multiple times.
*
- * More on how to debug BPF opcodes see Documentation/networking/filter.txt
+ * More on how to debug BPF opcodes see Documentation/networking/filter.rst
* which is the main document on BPF. Mini howto for getting started:
*
* 1) `./bpf_dbg` to enter the shell (shell cmds denoted with '>'):
--
2.17.1
^ permalink raw reply related
* [PATCH] sunrpc: remove redundant variables 'checksumlen','blocksize' and 'data'
From: YueHaibing @ 2018-08-01 6:28 UTC (permalink / raw)
To: davem, trond.myklebust, anna.schumaker, bfields, jlayton,
ebiggers, chuck.lever
Cc: linux-kernel, netdev, linux-nfs, YueHaibing
Variables 'checksumlen','blocksize' and 'data' are being assigned,
but are never used,hence they are redundant and can be removed.
fix fllowing warning:
net/sunrpc/auth_gss/gss_krb5_wrap.c:443:7: warning: variable ‘blocksize’ set but not used [-Wunused-but-set-variable]
net/sunrpc/auth_gss/gss_krb5_crypto.c:376:15: warning: variable ‘checksumlen’ set but not used [-Wunused-but-set-variable]
net/sunrpc/xprtrdma/svc_rdma.c:97:9: warning: variable ‘data’ set but not used [-Wunused-but-set-variable]
Signed-off-by: YueHaibing <yuehaibing@huawei.com>
---
net/sunrpc/auth_gss/gss_krb5_crypto.c | 2 --
net/sunrpc/auth_gss/gss_krb5_wrap.c | 2 --
net/sunrpc/xprtrdma/svc_rdma.c | 2 --
3 files changed, 6 deletions(-)
diff --git a/net/sunrpc/auth_gss/gss_krb5_crypto.c b/net/sunrpc/auth_gss/gss_krb5_crypto.c
index 8654494..84a16fd 100644
--- a/net/sunrpc/auth_gss/gss_krb5_crypto.c
+++ b/net/sunrpc/auth_gss/gss_krb5_crypto.c
@@ -373,7 +373,6 @@ make_checksum_v2(struct krb5_ctx *kctx, char *header, int hdrlen,
struct scatterlist sg[1];
int err = -1;
u8 *checksumdata;
- unsigned int checksumlen;
if (kctx->gk5e->keyed_cksum == 0) {
dprintk("%s: expected keyed hash for %s\n",
@@ -393,7 +392,6 @@ make_checksum_v2(struct krb5_ctx *kctx, char *header, int hdrlen,
tfm = crypto_alloc_ahash(kctx->gk5e->cksum_name, 0, CRYPTO_ALG_ASYNC);
if (IS_ERR(tfm))
goto out_free_cksum;
- checksumlen = crypto_ahash_digestsize(tfm);
req = ahash_request_alloc(tfm, GFP_NOFS);
if (!req)
diff --git a/net/sunrpc/auth_gss/gss_krb5_wrap.c b/net/sunrpc/auth_gss/gss_krb5_wrap.c
index a737c2d..9a1347f 100644
--- a/net/sunrpc/auth_gss/gss_krb5_wrap.c
+++ b/net/sunrpc/auth_gss/gss_krb5_wrap.c
@@ -440,7 +440,6 @@ static u32
gss_wrap_kerberos_v2(struct krb5_ctx *kctx, u32 offset,
struct xdr_buf *buf, struct page **pages)
{
- int blocksize;
u8 *ptr, *plainhdr;
s32 now;
u8 flags = 0x00;
@@ -473,7 +472,6 @@ gss_wrap_kerberos_v2(struct krb5_ctx *kctx, u32 offset,
*ptr++ = 0xff;
be16ptr = (__be16 *)ptr;
- blocksize = crypto_skcipher_blocksize(kctx->acceptor_enc);
*be16ptr++ = 0;
/* "inner" token header always uses 0 for RRC */
*be16ptr++ = 0;
diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
index 357ba90..134bef6a 100644
--- a/net/sunrpc/xprtrdma/svc_rdma.c
+++ b/net/sunrpc/xprtrdma/svc_rdma.c
@@ -94,7 +94,6 @@ static int read_reset_stat(struct ctl_table *table, int write,
atomic_set(stat, 0);
else {
char str_buf[32];
- char *data;
int len = snprintf(str_buf, 32, "%d\n", atomic_read(stat));
if (len >= 32)
return -EFAULT;
@@ -103,7 +102,6 @@ static int read_reset_stat(struct ctl_table *table, int write,
*lenp = 0;
return 0;
}
- data = &str_buf[*ppos];
len -= *ppos;
if (len > *lenp)
len = *lenp;
--
2.7.0
^ permalink raw reply related
* RE: [PATCH 3/3] ptp_qoriq: convert to use module parameters for initialization
From: Y.b. Lu @ 2018-08-01 4:38 UTC (permalink / raw)
To: David Miller
Cc: netdev@vger.kernel.org, Madalin-cristian Bucur,
richardcochran@gmail.com, robh+dt@kernel.org, shawnguo@kernel.org,
devicetree@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
In-Reply-To: <20180730.092545.225621578249887012.davem@davemloft.net>
Hi David,
> -----Original Message-----
> From: David Miller [mailto:davem@davemloft.net]
> Sent: Tuesday, July 31, 2018 12:26 AM
> To: Y.b. Lu <yangbo.lu@nxp.com>
> Cc: netdev@vger.kernel.org; Madalin-cristian Bucur
> <madalin.bucur@nxp.com>; richardcochran@gmail.com; robh+dt@kernel.org;
> shawnguo@kernel.org; devicetree@vger.kernel.org;
> linuxppc-dev@lists.ozlabs.org; linux-arm-kernel@lists.infradead.org;
> linux-kernel@vger.kernel.org
> Subject: Re: [PATCH 3/3] ptp_qoriq: convert to use module parameters for
> initialization
>
> From: Yangbo Lu <yangbo.lu@nxp.com>
> Date: Mon, 30 Jul 2018 18:01:54 +0800
>
> > +static unsigned int cksel = DEFAULT_CKSEL; module_param(cksel, uint,
> > +0644); MODULE_PARM_DESC(cksel, "Select reference clock");
> > +
> > +static unsigned int clk_src;
> > +module_param(clk_src, uint, 0644);
> > +MODULE_PARM_DESC(clk_src, "Reference clock frequency (if clocks
> > +property not provided in dts)");
> > +
> > +static unsigned int tmr_prsc = 2;
> > +module_param(tmr_prsc, uint, 0644);
> > +MODULE_PARM_DESC(tmr_prsc, "Output clock division/prescale factor");
> > +
> > +static unsigned int tmr_fiper1 = 1000000000; module_param(tmr_fiper1,
> > +uint, 0644); MODULE_PARM_DESC(tmr_fiper1, "Desired fixed interval
> > +pulse period (ns)");
> > +
> > +static unsigned int tmr_fiper2 = 100000; module_param(tmr_fiper2,
> > +uint, 0644); MODULE_PARM_DESC(tmr_fiper2, "Desired fixed interval
> > +pulse period (ns)");
>
> Sorry, there is no way I am every applying something like this. Module
> parameters are to be avoided at all costs.
>
> And you don't need it here, you have DTS, please use it.
>
> You are required to support the existing DTS cases, in order to avoid breaking
> things, anyways.
[Y.b. Lu] I get your point. Will drop module_param method.
Thanks a lot for your suggestion.
^ permalink raw reply
* Re: [PATCH 3/3] ptp_qoriq: convert to use module parameters for initialization
From: Richard Cochran @ 2018-08-01 6:15 UTC (permalink / raw)
To: Y.b. Lu
Cc: netdev@vger.kernel.org, Madalin-cristian Bucur, Rob Herring,
Shawn Guo, David S . Miller, devicetree@vger.kernel.org,
linuxppc-dev@lists.ozlabs.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
In-Reply-To: <DB6PR0401MB253643010802739AD55820F3F82D0@DB6PR0401MB2536.eurprd04.prod.outlook.com>
On Wed, Aug 01, 2018 at 04:36:40AM +0000, Y.b. Lu wrote:
> Could I add a function to calculate a set of default register values
> to initialize ptp timer when dts method failed to get required
> properties in driver?
Yes, it would be ideal if the driver can pick correct values
automatically.
However, the frequency on the FIPER outputs can't be configured
automatically, and we don't have an API for the user to choose this.
> I think this will be useful. The ptp timer on new platforms (you may
> see two dts patches in this patchset. Many platforms will be
> affected.) will work without these dts properties. If user want
> specific setting, they can set dts properties.
Sure.
Thanks,
Richard
^ permalink raw reply
* Re: [PATCH] net/tipc: remove redundant variables 'tn' and 'oport'
From: Ying Xue @ 2018-08-01 6:10 UTC (permalink / raw)
To: Colin King, Jon Maloy, David S . Miller, netdev, tipc-discussion
Cc: kernel-janitors, linux-kernel
In-Reply-To: <20180731160137.5850-1-colin.king@canonical.com>
On 08/01/2018 12:01 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Variables 'tn' and 'oport' are being assigned but are never used hence
> they are redundant and can be removed.
>
> Cleans up clang warnings:
> warning: variable 'oport' set but not used [-Wunused-but-set-variable]
> warning: variable 'tn' set but not used [-Wunused-but-set-variable]
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
Acked-by: Ying Xue <ying.xue@windriver.com>
> ---
> net/tipc/socket.c | 5 +----
> 1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/net/tipc/socket.c b/net/tipc/socket.c
> index 3763bedecf5f..c1e93c9515bc 100644
> --- a/net/tipc/socket.c
> +++ b/net/tipc/socket.c
> @@ -411,7 +411,6 @@ static int tipc_sk_sock_err(struct socket *sock, long *timeout)
> static int tipc_sk_create(struct net *net, struct socket *sock,
> int protocol, int kern)
> {
> - struct tipc_net *tn;
> const struct proto_ops *ops;
> struct sock *sk;
> struct tipc_sock *tsk;
> @@ -446,7 +445,6 @@ static int tipc_sk_create(struct net *net, struct socket *sock,
> INIT_LIST_HEAD(&tsk->publications);
> INIT_LIST_HEAD(&tsk->cong_links);
> msg = &tsk->phdr;
> - tn = net_generic(sock_net(sk), tipc_net_id);
>
> /* Finish initializing socket data structures */
> sock->ops = ops;
> @@ -1117,7 +1115,7 @@ void tipc_sk_mcast_rcv(struct net *net, struct sk_buff_head *arrvq,
> u32 self = tipc_own_addr(net);
> u32 type, lower, upper, scope;
> struct sk_buff *skb, *_skb;
> - u32 portid, oport, onode;
> + u32 portid, onode;
> struct sk_buff_head tmpq;
> struct list_head dports;
> struct tipc_msg *hdr;
> @@ -1133,7 +1131,6 @@ void tipc_sk_mcast_rcv(struct net *net, struct sk_buff_head *arrvq,
> user = msg_user(hdr);
> mtyp = msg_type(hdr);
> hlen = skb_headroom(skb) + msg_hdr_sz(hdr);
> - oport = msg_origport(hdr);
> onode = msg_orignode(hdr);
> type = msg_nametype(hdr);
>
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
^ permalink raw reply
* Re: [patch net-next 2/2] net: sched: fix notifications for action-held chains
From: Cong Wang @ 2018-08-01 4:27 UTC (permalink / raw)
To: Jiri Pirko
Cc: Linux Kernel Network Developers, David Miller, Jamal Hadi Salim,
Jakub Kicinski, mlxsw
In-Reply-To: <20180731120745.1230-3-jiri@resnulli.us>
On Tue, Jul 31, 2018 at 5:10 AM Jiri Pirko <jiri@resnulli.us> wrote:
>
> From: Jiri Pirko <jiri@mellanox.com>
>
> Chains that only have action references serve as placeholders.
> Until a non-action reference is created, user should not be aware
> of the chain. Also he should not receive any notifications about it.
> So send notifications for the new chain only in case the chain gets
> the first non-action reference. Symmetrically to that, when
> the last non-action reference is dropped, send the notification about
> deleted chain.
>
> Reported-by: Cong Wang <xiyou.wangcong@gmail.com>
> Signed-off-by: Jiri Pirko <jiri@mellanox.com>
I think __tcf_chain_{get,put}() can be static.
Other than that,
Acked-by: Cong Wang <xiyou.wangcong@gmail.com>
Thanks.
^ permalink raw reply
* Re: [patch net-next 1/2] net: sched: change name of zombie chain to "held_by_acts_only"
From: Cong Wang @ 2018-08-01 4:26 UTC (permalink / raw)
To: Jiri Pirko
Cc: Linux Kernel Network Developers, David Miller, Jamal Hadi Salim,
Jakub Kicinski, mlxsw
In-Reply-To: <20180731120745.1230-2-jiri@resnulli.us>
On Tue, Jul 31, 2018 at 5:10 AM Jiri Pirko <jiri@resnulli.us> wrote:
>
> From: Jiri Pirko <jiri@mellanox.com>
>
> As mentioned by Cong and Jakub during the review process, it is a bit
> odd to sometimes (act flow) create a new chain which would be
> immediately a "zombie". So just rename it to "held_by_acts_only".
>
> Signed-off-by: Jiri Pirko <jiri@mellanox.com>
> Suggested-by: Cong Wang <xiyou.wangcong@gmail.com>
> Suggested-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Acked-by: Cong Wang <xiyou.wangcong@gmail.com>
Thanks for the update!
^ permalink raw reply
* Re: [PATCH net-next v7 3/4] net: vhost: factor out busy polling logic to vhost_net_busy_poll()
From: Jason Wang @ 2018-08-01 6:01 UTC (permalink / raw)
To: xiangxia.m.yue; +Cc: netdev, virtualization, mst
In-Reply-To: <1533092454-37196-4-git-send-email-xiangxia.m.yue@gmail.com>
On 2018年08月01日 11:00, xiangxia.m.yue@gmail.com wrote:
> From: Tonghao Zhang <xiangxia.m.yue@gmail.com>
>
> Factor out generic busy polling logic and will be
> used for in tx path in the next patch. And with the patch,
> qemu can set differently the busyloop_timeout for rx queue.
>
> In the handle_tx, the busypoll will vhost_net_disable/enable_vq
> because we have poll the sock. This can improve performance.
> [This is suggested by Toshiaki Makita <makita.toshiaki@lab.ntt.co.jp>]
>
> And when the sock receive skb, we should queue the poll if necessary.
>
> Signed-off-by: Tonghao Zhang <xiangxia.m.yue@gmail.com>
> ---
> drivers/vhost/net.c | 131 ++++++++++++++++++++++++++++++++++++----------------
> 1 file changed, 91 insertions(+), 40 deletions(-)
>
> diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
> index 32c1b52..5b45463 100644
> --- a/drivers/vhost/net.c
> +++ b/drivers/vhost/net.c
> @@ -440,6 +440,95 @@ static void vhost_net_signal_used(struct vhost_net_virtqueue *nvq)
> nvq->done_idx = 0;
> }
>
> +static int sk_has_rx_data(struct sock *sk)
> +{
> + struct socket *sock = sk->sk_socket;
> +
> + if (sock->ops->peek_len)
> + return sock->ops->peek_len(sock);
> +
> + return skb_queue_empty(&sk->sk_receive_queue);
> +}
> +
> +static void vhost_net_busy_poll_try_queue(struct vhost_net *net,
> + struct vhost_virtqueue *vq)
> +{
> + if (!vhost_vq_avail_empty(&net->dev, vq)) {
> + vhost_poll_queue(&vq->poll);
> + } else if (unlikely(vhost_enable_notify(&net->dev, vq))) {
> + vhost_disable_notify(&net->dev, vq);
> + vhost_poll_queue(&vq->poll);
> + }
> +}
> +
> +static void vhost_net_busy_poll_check(struct vhost_net *net,
> + struct vhost_virtqueue *rvq,
> + struct vhost_virtqueue *tvq,
> + bool rx)
> +{
> + struct socket *sock = rvq->private_data;
> +
> + if (rx)
> + vhost_net_busy_poll_try_queue(net, tvq);
> + else if (sock && sk_has_rx_data(sock->sk))
> + vhost_net_busy_poll_try_queue(net, rvq);
> + else {
> + /* On tx here, sock has no rx data, so we
> + * will wait for sock wakeup for rx, and
> + * vhost_enable_notify() is not needed. */
A possible case is we do have rx data but guest does not refill the rx
queue. In this case we may lose notifications from guest.
> + }
> +}
> +
> +static void vhost_net_busy_poll(struct vhost_net *net,
> + struct vhost_virtqueue *rvq,
> + struct vhost_virtqueue *tvq,
> + bool *busyloop_intr,
> + bool rx)
> +{
> + unsigned long busyloop_timeout;
> + unsigned long endtime;
> + struct socket *sock;
> + struct vhost_virtqueue *vq = rx ? tvq : rvq;
> +
> + mutex_lock_nested(&vq->mutex, rx ? VHOST_NET_VQ_TX: VHOST_NET_VQ_RX);
> + vhost_disable_notify(&net->dev, vq);
> + sock = rvq->private_data;
> +
> + busyloop_timeout = rx ? rvq->busyloop_timeout:
> + tvq->busyloop_timeout;
> +
> +
> + /* Busypoll the sock, so don't need rx wakeups during it. */
> + if (!rx)
> + vhost_net_disable_vq(net, vq);
Actually this piece of code is not a factoring out. I would suggest to
add this in another patch, or on top of this series.
> +
> + preempt_disable();
> + endtime = busy_clock() + busyloop_timeout;
> +
> + while (vhost_can_busy_poll(endtime)) {
> + if (vhost_has_work(&net->dev)) {
> + *busyloop_intr = true;
> + break;
> + }
> +
> + if ((sock && sk_has_rx_data(sock->sk) &&
> + !vhost_vq_avail_empty(&net->dev, rvq)) ||
> + !vhost_vq_avail_empty(&net->dev, tvq))
> + break;
Some checks were duplicated in vhost_net_busy_poll_check(). Need
consider to unify them.
> +
> + cpu_relax();
> + }
> +
> + preempt_enable();
> +
> + if (!rx)
> + vhost_net_enable_vq(net, vq);
No need to enable rx virtqueue, if we are sure handle_rx() will be
called soon.
> +
> + vhost_net_busy_poll_check(net, rvq, tvq, rx);
It looks to me just open code all check here is better and easier to be
reviewed.
Thanks
> +
> + mutex_unlock(&vq->mutex);
> +}
> +
> static int vhost_net_tx_get_vq_desc(struct vhost_net *net,
> struct vhost_net_virtqueue *nvq,
> unsigned int *out_num, unsigned int *in_num,
> @@ -753,16 +842,6 @@ static int peek_head_len(struct vhost_net_virtqueue *rvq, struct sock *sk)
> return len;
> }
>
> -static int sk_has_rx_data(struct sock *sk)
> -{
> - struct socket *sock = sk->sk_socket;
> -
> - if (sock->ops->peek_len)
> - return sock->ops->peek_len(sock);
> -
> - return skb_queue_empty(&sk->sk_receive_queue);
> -}
> -
> static int vhost_net_rx_peek_head_len(struct vhost_net *net, struct sock *sk,
> bool *busyloop_intr)
> {
> @@ -770,41 +849,13 @@ static int vhost_net_rx_peek_head_len(struct vhost_net *net, struct sock *sk,
> struct vhost_net_virtqueue *tnvq = &net->vqs[VHOST_NET_VQ_TX];
> struct vhost_virtqueue *rvq = &rnvq->vq;
> struct vhost_virtqueue *tvq = &tnvq->vq;
> - unsigned long uninitialized_var(endtime);
> int len = peek_head_len(rnvq, sk);
>
> - if (!len && tvq->busyloop_timeout) {
> + if (!len && rvq->busyloop_timeout) {
> /* Flush batched heads first */
> vhost_net_signal_used(rnvq);
> /* Both tx vq and rx socket were polled here */
> - mutex_lock_nested(&tvq->mutex, VHOST_NET_VQ_TX);
> - vhost_disable_notify(&net->dev, tvq);
> -
> - preempt_disable();
> - endtime = busy_clock() + tvq->busyloop_timeout;
> -
> - while (vhost_can_busy_poll(endtime)) {
> - if (vhost_has_work(&net->dev)) {
> - *busyloop_intr = true;
> - break;
> - }
> - if ((sk_has_rx_data(sk) &&
> - !vhost_vq_avail_empty(&net->dev, rvq)) ||
> - !vhost_vq_avail_empty(&net->dev, tvq))
> - break;
> - cpu_relax();
> - }
> -
> - preempt_enable();
> -
> - if (!vhost_vq_avail_empty(&net->dev, tvq)) {
> - vhost_poll_queue(&tvq->poll);
> - } else if (unlikely(vhost_enable_notify(&net->dev, tvq))) {
> - vhost_disable_notify(&net->dev, tvq);
> - vhost_poll_queue(&tvq->poll);
> - }
> -
> - mutex_unlock(&tvq->mutex);
> + vhost_net_busy_poll(net, rvq, tvq, busyloop_intr, true);
>
> len = peek_head_len(rnvq, sk);
> }
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
^ permalink raw reply
* AW: PROBLEM: Kernel Oops in UDP stack
From: Marcel Hellwig @ 2018-08-01 5:55 UTC (permalink / raw)
To: 'Eric Dumazet', 'davem@davemloft.net',
'kuznet@ms2.inr.ac.ru', 'yoshfuji@linux-ipv6.org',
'andrew@lunn.ch'
Cc: 'netdev@vger.kernel.org',
'linux-kernel@vger.kernel.org', Matthias Wystrik
In-Reply-To: <f1940127-7307-e1ba-7a05-075680a6d3c1@gmail.com>
On Tue, Jul 31, 2018 at 15:36:05PM +0000 Andrew Lunn wrote:
> Is this mainline 3.4.113, or LPC version?
Mainline, afaik there is no newer version of the lpc kernel and the lpc driver are upstream since 3.4 (hence the 3.4.113 kernel version we tried).
> How much work is involved in testing a newer kernel. You are not going to get too much help from the community with such an old kernel. If you can reproduce it with a modern day kernel, then people are more likely to help.
We haven't tried any newer version, because DTS is mandatory since 3.5 afaik? We hadn't the time to look into, although it looks pretty straight forward.
>> Kernel oops:
>> [ 1125.090000] Unable to handle kernel paging request at virtual
>> address c14fe63a [ 1125.100000] pgd = c14d8000 [ 1125.100000]
>> [c14fe63a] *pgd=8140041e(bad) [ 1125.100000] Internal error: Oops: 1
>> [#1] PREEMPT ARM [ 1125.100000] Modules linked in:
>> [ 1125.100000] CPU: 0 Not tainted (3.4.113.7 #1)
>> [ 1125.100000] PC is at udp_recvmsg+0x284/0x33c [ 1125.100000] LR is
>> at 0x0
> LR == 0 is suspicious. It should contain the return address, inet_recvmsg+0x38/0x4c. That is assuming the calling convention is the same for this old kernel as todays kernels on ARM.
I will do a little debugging why LR is 0 here. Maybe that's the clue.
> Could you produce net/ipv4/udp.lst for this exact kernel build?
Sure: https://gist.github.com/hellow554/6b11c6c0827d5db80a7e66f71f5636ff#file-net_uipv4_udp-lst
> Any idea how you could get file:line information ?
> ( like : udp_setsockopt+0x62/0xa0 net/ipv4/udp.c:2502 )
[<c0228adc>] (udp_recvmsg+0x284/0x33c) from [<c02306e0>] (inet_recvmsg+0x38/0x4c): net/ipv4/udp.c:1234
[<c02306e0>] (inet_recvmsg+0x38/0x4c) from [<c01d2c38>] (sock_recvmsg+0xa8/0xcc): include/linux/file.h:25
[<c01d2c38>] (sock_recvmsg+0xa8/0xcc) from [<c01d3fac>] (___sys_recvmsg.part.4+0xe0/0x1bc): net/socket.c:751
[<c01d3fac>] (___sys_recvmsg.part.4+0xe0/0x1bc) from [<c01d4fbc>] (__sys_recvmsg+0x50/0x80): net/socket.c:2193
[<c01d4fbc>] (__sys_recvmsg+0x50/0x80) from [<c000dfe0>] (ret_fast_syscall+0x0/0x2c): include/linux/file.h:25 (from arch/arm/kernel/entry-common.S:34)
https://elixir.bootlin.com/linux/v3.4.113/source :)
Many thanks for the answer, I hope I could answer your questions.
Mit freundlichen Grüßen / With kind regards
Marcel Hellwig
B. Sc. Informatik
Entwickler
m-u-t GmbH
Am Marienhof 2
22880 Wedel
Germany
Phone: +49 4103 9308 - 474
Fax: +49 4103 9308 - 99
mhellwig@mut-group.com
www.mut-group.com
Geschäftsführer (Managing Director): Fabian Peters
Amtsgericht Pinneberg (Commercial Register No.): HRB 10304 PI
USt-IdNr. (VAT-No.): DE228275390
WEEE-Reg-Nr.: DE 72271808
^ permalink raw reply
* Wichtige Mitteilung
From: elena_figueroa @ 2018-08-01 1:59 UTC (permalink / raw)
To: Recipients
Hallo, ich bin Herr Tayeb Souami, New Jersey, Vereinigte Staaten von Amerika, Sie haben eine Wohltätigkeitsspende in Höhe von € 2.000.000,00, ich habe die America Lotterie in Amerika im Wert von $ 315 Millionen gewonnen, und ich gebe einen Teil davon an fünf glückliche Menschen und wohltätige Häuser, um Armut aus dieser Welt zu beseitigen, bekämpfe ich die Armut. Kontaktieren Sie mich für weitere Informationen: wumt.claimservice@gmail.com
Das ist dein Spendencode: [DFC530342018]
Antworten Sie mit dem Spendencode auf diese E-Mail: wumt.claimservice@gmail.com
Ich hoffe, Sie und Ihre Familie glücklich zu machen.
Grüße
Herr Tayeb Souami
^ permalink raw reply
* Re: linux-next: manual merge of the net-next tree with the rdma tree
From: Stephen Rothwell @ 2018-08-01 5:33 UTC (permalink / raw)
To: Parav Pandit
Cc: Jason Gunthorpe, David Miller, Networking, Doug Ledford,
Linux-Next Mailing List, Linux Kernel Mailing List, Ursula Braun,
Leon Romanovsky, linux-rdma@vger.kernel.org
In-Reply-To: <VI1PR0502MB3008076016496152D4898D8ED12E0@VI1PR0502MB3008.eurprd05.prod.outlook.com>
[-- Attachment #1: Type: text/plain, Size: 635 bytes --]
Hi Parav,
On Tue, 31 Jul 2018 21:12:00 +0000 Parav Pandit <parav@mellanox.com> wrote:
>
> You might want to consider this compatibility patch in Linux-rdma
> tree to avoid a merge conflict of smc.
>
> https://git.kernel.org/pub/scm/linux/kernel/git/rdma/rdma.git/commit/?h=for-next&id=7aaa1807e698f73094b78f0ef25b1a37a4409a55
Ok, since commit that is now in the rdma tree, my resolution of the
original conflicts comes down to dropping all the changes to
net/smc/smc_core.c net/smc/smc_ib.c that come from the rdma tree and
adding
#include <rdma/ib_cache.h>
to net/smc/smc_ib.c.
--
Cheers,
Stephen Rothwell
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply
* [PATCH bpf-next 13/13] docs: net: Fix authors list to render as a list
From: Tobin C. Harding @ 2018-08-01 5:09 UTC (permalink / raw)
To: Daniel Borkmann, Alexei Starovoitov
Cc: Tobin C. Harding, Jonathan Corbet, David S. Miller, linux-doc,
netdev, linux-kernel
In-Reply-To: <20180801050908.29970-1-me@tobin.cc>
Currently authors list renders on a single line in HTML. The text
format implies that a list was meant.
Use RST list construct to fix authors contact details to be rendered as
a list.
Signed-off-by: Tobin C. Harding <me@tobin.cc>
---
Documentation/networking/filter.rst | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/Documentation/networking/filter.rst b/Documentation/networking/filter.rst
index b989a6c882b8..1913718e3f2a 100644
--- a/Documentation/networking/filter.rst
+++ b/Documentation/networking/filter.rst
@@ -1532,6 +1532,6 @@ The document was written in the hope that it is found useful and in order
to give potential BPF hackers or security auditors a better overview of
the underlying architecture.
-Jay Schulist <jschlst@samba.org>
-Daniel Borkmann <daniel@iogearbox.net>
-Alexei Starovoitov <ast@kernel.org>
+- Jay Schulist <jschlst@samba.org>
+- Daniel Borkmann <daniel@iogearbox.net>
+- Alexei Starovoitov <ast@kernel.org>
--
2.17.1
^ permalink raw reply related
* [PATCH bpf-next 11/13] docs: net: Use correct RST list construct
From: Tobin C. Harding @ 2018-08-01 5:09 UTC (permalink / raw)
To: Daniel Borkmann, Alexei Starovoitov
Cc: Tobin C. Harding, Jonathan Corbet, David S. Miller, linux-doc,
netdev, linux-kernel
In-Reply-To: <20180801050908.29970-1-me@tobin.cc>
Currently we are using a custom list format. We should use the correct
standard list construct. Also lists require a newline before and after
the list items.
Use correct RST list construct.
Signed-off-by: Tobin C. Harding <me@tobin.cc>
---
Documentation/networking/filter.rst | 30 ++++++++++++++++-------------
1 file changed, 17 insertions(+), 13 deletions(-)
diff --git a/Documentation/networking/filter.rst b/Documentation/networking/filter.rst
index 1ed6972c3544..99dfa74fc4f7 100644
--- a/Documentation/networking/filter.rst
+++ b/Documentation/networking/filter.rst
@@ -1162,18 +1162,21 @@ arithmetic), and this is tracked in two parts: the 'fixed offset' and 'variable
offset'. The former is used when an exactly-known value (e.g. an immediate
operand) is added to a pointer, while the latter is used for values which are
not exactly known. The variable offset is also used in SCALAR_VALUEs, to track
-the range of possible values in the register.
-The verifier's knowledge about the variable offset consists of:
+the range of possible values in the register. The verifier's knowledge
+about the variable offset consists of:
+
* minimum and maximum values as unsigned
* minimum and maximum values as signed
* knowledge of the values of individual bits, in the form of a 'tnum': a u64
-'mask' and a u64 'value'. 1s in the mask represent bits whose value is unknown;
-1s in the value represent bits known to be 1. Bits known to be 0 have 0 in both
-mask and value; no bit should ever be 1 in both. For example, if a byte is read
-into a register from memory, the register's top 56 bits are known zero, while
-the low 8 are unknown - which is represented as the tnum (0x0; 0xff). If we
-then OR this with 0x40, we get (0x40; 0xbf), then if we add 1 we get (0x0;
-0x1ff), because of potential carries.
+ 'mask' and a u64 'value'
+
+1s in the mask represent bits whose value is unknown; 1s in the value
+represent bits known to be 1. Bits known to be 0 have 0 in both mask and
+value; no bit should ever be 1 in both. For example, if a byte is read
+into a register from memory, the register's top 56 bits are known zero,
+while the low 8 are unknown - which is represented as the tnum (0x0; 0xff).
+If we then OR this with 0x40, we get (0x40; 0xbf), then if we add 1 we get
+(0x0; 0x1ff), because of potential carries.
Besides arithmetic, the register state can also be updated by conditional
branches. For instance, if a SCALAR_VALUE is compared > 8, in the 'true' branch
@@ -1329,10 +1332,11 @@ are concurrently updating.
maps can have different types: hash, array, bloom filter, radix-tree, etc.
The map is defined by:
- . type
- . max number of elements
- . key size in bytes
- . value size in bytes
+
+- type
+- max number of elements
+- key size in bytes
+- value size in bytes
Pruning
=======
--
2.17.1
^ permalink raw reply related
* [PATCH bpf-next 10/13] docs: net: Embed reference to seccomp_filter
From: Tobin C. Harding @ 2018-08-01 5:09 UTC (permalink / raw)
To: Daniel Borkmann, Alexei Starovoitov
Cc: Tobin C. Harding, Jonathan Corbet, David S. Miller, linux-doc,
netdev, linux-kernel
In-Reply-To: <20180801050908.29970-1-me@tobin.cc>
Typical RST documents embed the reference link straight in the text.
Currently document uses a '[1]' with the reference below that
paragraph.
Use RST :ref:`path/to/file` <label>` format and embed the reference to
seccomp_filter directly in the text. Add a label to seccomp_filter.rst
to enable the reference to function correctly.
Signed-off-by: Tobin C. Harding <me@tobin.cc>
---
Documentation/networking/filter.rst | 12 ++++++------
Documentation/userspace-api/seccomp_filter.rst | 2 ++
2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/Documentation/networking/filter.rst b/Documentation/networking/filter.rst
index 10c4eab042df..1ed6972c3544 100644
--- a/Documentation/networking/filter.rst
+++ b/Documentation/networking/filter.rst
@@ -43,12 +43,12 @@ internal compiler that generates a structure that can eventually be loaded
via SO_ATTACH_FILTER to the kernel. ``tcpdump -i em1 port 22 -ddd``
displays what is being placed into this structure.
-Although we were only speaking about sockets here, BPF in Linux is used
-in many more places. There's xt_bpf for netfilter, cls_bpf in the kernel
-qdisc layer, SECCOMP-BPF (SECure COMPuting [1]), and lots of other places
-such as team driver, PTP code, etc where BPF is being used.
-
- [1] Documentation/userspace-api/seccomp_filter.rst
+Although we were only speaking about sockets here, BPF in Linux is used in
+many more places. There's xt_bpf for netfilter, cls_bpf in the kernel qdisc
+layer, SECCOMP-BPF (SECure COMPuting
+:ref:`Documentation/userspace-api/seccomp_filter.rst <seccomp_filter>`),
+and lots of other places such as team driver, PTP code, etc where BPF is
+being used.
Original BPF paper:
diff --git a/Documentation/userspace-api/seccomp_filter.rst b/Documentation/userspace-api/seccomp_filter.rst
index 82a468bc7560..6c3eb4908818 100644
--- a/Documentation/userspace-api/seccomp_filter.rst
+++ b/Documentation/userspace-api/seccomp_filter.rst
@@ -2,6 +2,8 @@
Seccomp BPF (SECure COMPuting with filters)
===========================================
+.. _seccomp_filter:
+
Introduction
============
--
2.17.1
^ permalink raw reply related
* [PATCH bpf-next 09/13] docs: net: Use lowercase 'k' for kernel
From: Tobin C. Harding @ 2018-08-01 5:09 UTC (permalink / raw)
To: Daniel Borkmann, Alexei Starovoitov
Cc: Tobin C. Harding, Jonathan Corbet, David S. Miller, linux-doc,
netdev, linux-kernel
In-Reply-To: <20180801050908.29970-1-me@tobin.cc>
The whole document uses a lowercase 'k' for 'kernel' except in one
instance. The kernel community also favours a lowercase 'k'.
Use lowercase 'k' for kernel instead of uppercase 'K'.
Signed-off-by: Tobin C. Harding <me@tobin.cc>
---
Documentation/networking/filter.rst | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Documentation/networking/filter.rst b/Documentation/networking/filter.rst
index dda1afdb5f26..10c4eab042df 100644
--- a/Documentation/networking/filter.rst
+++ b/Documentation/networking/filter.rst
@@ -9,7 +9,7 @@ Introduction
Linux Socket Filtering (LSF) is derived from the Berkeley Packet Filter.
Though there are some distinct differences between the BSD and Linux
-Kernel filtering, but when we speak of BPF or LSF in Linux context, we
+kernel filtering, but when we speak of BPF or LSF in Linux context, we
mean the very same mechanism of filtering in the Linux kernel.
BPF allows a user-space program to attach a filter onto any socket and
--
2.17.1
^ permalink raw reply related
* [PATCH bpf-next 08/13] docs: net: Use double ticks instead of single tick
From: Tobin C. Harding @ 2018-08-01 5:09 UTC (permalink / raw)
To: Daniel Borkmann, Alexei Starovoitov
Cc: Tobin C. Harding, Jonathan Corbet, David S. Miller, linux-doc,
netdev, linux-kernel
In-Reply-To: <20180801050908.29970-1-me@tobin.cc>
Single tick around a command should be converted to a double
tick for RST files (excluding ticks in a code snippet section).
Use double ticks instead of single tick.
Signed-off-by: Tobin C. Harding <me@tobin.cc>
---
Documentation/networking/filter.rst | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/Documentation/networking/filter.rst b/Documentation/networking/filter.rst
index f9ec58144ed3..dda1afdb5f26 100644
--- a/Documentation/networking/filter.rst
+++ b/Documentation/networking/filter.rst
@@ -38,9 +38,9 @@ setup a socket, attach a filter, lock it then drop privileges and be
assured that the filter will be kept until the socket is closed.
The biggest user of this construct might be libpcap. Issuing a high-level
-filter command like `tcpdump -i em1 port 22` passes through the libpcap
+filter command like ``tcpdump -i em1 port 22`` passes through the libpcap
internal compiler that generates a structure that can eventually be loaded
-via SO_ATTACH_FILTER to the kernel. `tcpdump -i em1 port 22 -ddd`
+via SO_ATTACH_FILTER to the kernel. ``tcpdump -i em1 port 22 -ddd``
displays what is being placed into this structure.
Although we were only speaking about sockets here, BPF in Linux is used
@@ -375,7 +375,7 @@ Starting bpf_dbg is trivial and just requires issuing::
In case input and output do not equal stdin/stdout, bpf_dbg takes an
alternative stdin source as a first argument, and an alternative stdout
-sink as a second one, e.g. `./bpf_dbg test_in.txt test_out.txt`.
+sink as a second one, e.g. ``./bpf_dbg test_in.txt test_out.txt``.
Other than that, a particular libreadline configuration can be set via
file "~/.bpf_dbg_init" and the command history is stored in the file
@@ -388,7 +388,7 @@ The usual workflow would be to ...
> load bpf 6,40 0 0 12,21 0 3 2048,48 0 0 23,21 0 1 1,6 0 0 65535,6 0 0 0
Loads a BPF filter from standard output of bpf_asm, or transformed via
- e.g. `tcpdump -iem1 -ddd port 22 | tr '\n' ','`. Note that for JIT
+ e.g. tcpdump -iem1 -ddd port 22 | tr '\n' ','`. Note that for JIT
debugging (next section), this command creates a temporary socket and
loads the BPF code into the kernel. Thus, this will also be useful for
JIT developers.
@@ -523,7 +523,7 @@ generating disassembly out of the kernel log's hexdump::
44: leaveq
45: retq
-Issuing option `-o` will "annotate" opcodes to resulting assembler
+Issuing option ``-o`` will "annotate" opcodes to resulting assembler
instructions, which can be very useful for JIT developers::
# ./bpf_jit_disasm -o
--
2.17.1
^ permalink raw reply related
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox