Netdev List
 help / color / mirror / Atom feed
* [PATCH net-next 0/7] mlxsw: Various updates
From: Ido Schimmel @ 2018-08-09  8:59 UTC (permalink / raw)
  To: netdev; +Cc: davem, jiri, mlxsw, Ido Schimmel

Patches 1-3 update the driver to use a new firmware version. Due to a
recently discovered issue, the version (and future ones) does not
support matching on VLAN ID at egress. This is enforced in the driver
and reported back to the user via extack.

Patch 4 adds a new selftest for the recently introduced algorithmic
TCAM.

Patch 5 converts the driver to use SPDX identifiers.

Patches 6-7 fix a bug in ethtool stats reporting and expose counters for
all 16 TCs, following recent MC-aware changes that utilize TCs 8-15.

Ido Schimmel (1):
  selftests: mlxsw: Add TC flower test for Spectrum-2

Jiri Pirko (2):
  mlxsw: spectrum: Reset FW after flash
  mlxsw: Replace license text with SPDX identifiers and adjust
    copyrights

Nir Dotan (2):
  mlxsw: spectrum_flower: Disallow usage of vlan_id key on egress
  mlxsw: spectrum: Update the supported firmware to version 13.1702.6

Petr Machata (2):
  mlxsw: spectrum: Include RFC-2819 counters in stats length
  mlxsw: spectrum: Expose counter for all 16 TCs

 drivers/net/ethernet/mellanox/mlxsw/cmd.h     |  36 +-
 drivers/net/ethernet/mellanox/mlxsw/core.c    |  37 +-
 drivers/net/ethernet/mellanox/mlxsw/core.h    |  38 +-
 .../mellanox/mlxsw/core_acl_flex_actions.c    |  35 +-
 .../mellanox/mlxsw/core_acl_flex_actions.h    |  35 +-
 .../mellanox/mlxsw/core_acl_flex_keys.c       |  35 +-
 .../mellanox/mlxsw/core_acl_flex_keys.h       |  35 +-
 .../net/ethernet/mellanox/mlxsw/core_hwmon.c  |  35 +-
 .../ethernet/mellanox/mlxsw/core_thermal.c    |  32 +-
 drivers/net/ethernet/mellanox/mlxsw/emad.h    |  36 +-
 drivers/net/ethernet/mellanox/mlxsw/i2c.c     |  35 +-
 drivers/net/ethernet/mellanox/mlxsw/i2c.h     |  35 +-
 drivers/net/ethernet/mellanox/mlxsw/ib.h      |  36 +-
 drivers/net/ethernet/mellanox/mlxsw/item.h    |  36 +-
 drivers/net/ethernet/mellanox/mlxsw/minimal.c |  35 +-
 drivers/net/ethernet/mellanox/mlxsw/pci.c     |  46 +--
 drivers/net/ethernet/mellanox/mlxsw/pci.h     |  35 +-
 drivers/net/ethernet/mellanox/mlxsw/pci_hw.h  |  35 +-
 drivers/net/ethernet/mellanox/mlxsw/port.h    |  38 +-
 drivers/net/ethernet/mellanox/mlxsw/reg.h     |  39 +-
 .../net/ethernet/mellanox/mlxsw/resources.h   |  35 +-
 .../net/ethernet/mellanox/mlxsw/spectrum.c    |  70 ++--
 .../net/ethernet/mellanox/mlxsw/spectrum.h    |  38 +-
 .../mellanox/mlxsw/spectrum1_acl_tcam.c       |  35 +-
 .../ethernet/mellanox/mlxsw/spectrum1_kvdl.c  |  35 +-
 .../mellanox/mlxsw/spectrum1_mr_tcam.c        |  36 +-
 .../mellanox/mlxsw/spectrum2_acl_tcam.c       |  35 +-
 .../ethernet/mellanox/mlxsw/spectrum2_kvdl.c  |  35 +-
 .../mellanox/mlxsw/spectrum2_mr_tcam.c        |  35 +-
 .../ethernet/mellanox/mlxsw/spectrum_acl.c    |  46 +--
 .../mellanox/mlxsw/spectrum_acl_atcam.c       |  36 +-
 .../mellanox/mlxsw/spectrum_acl_ctcam.c       |  35 +-
 .../mellanox/mlxsw/spectrum_acl_erp.c         |  35 +-
 .../mlxsw/spectrum_acl_flex_actions.c         |  36 +-
 .../mlxsw/spectrum_acl_flex_actions.h         |  36 +-
 .../mellanox/mlxsw/spectrum_acl_flex_keys.c   |  35 +-
 .../mellanox/mlxsw/spectrum_acl_tcam.c        |  35 +-
 .../mellanox/mlxsw/spectrum_acl_tcam.h        |  35 +-
 .../mellanox/mlxsw/spectrum_buffers.c         |  35 +-
 .../ethernet/mellanox/mlxsw/spectrum_cnt.c    |  35 +-
 .../ethernet/mellanox/mlxsw/spectrum_cnt.h    |  35 +-
 .../ethernet/mellanox/mlxsw/spectrum_dcb.c    |  35 +-
 .../ethernet/mellanox/mlxsw/spectrum_dpipe.c  |  35 +-
 .../ethernet/mellanox/mlxsw/spectrum_dpipe.h  |  35 +-
 .../ethernet/mellanox/mlxsw/spectrum_fid.c    |  35 +-
 .../ethernet/mellanox/mlxsw/spectrum_flower.c |  40 +-
 .../ethernet/mellanox/mlxsw/spectrum_ipip.c   |  35 +-
 .../ethernet/mellanox/mlxsw/spectrum_ipip.h   |  35 +-
 .../ethernet/mellanox/mlxsw/spectrum_kvdl.c   |  35 +-
 .../net/ethernet/mellanox/mlxsw/spectrum_mr.c |  35 +-
 .../net/ethernet/mellanox/mlxsw/spectrum_mr.h |  35 +-
 .../mellanox/mlxsw/spectrum_mr_tcam.c         |  36 +-
 .../mellanox/mlxsw/spectrum_mr_tcam.h         |  35 +-
 .../ethernet/mellanox/mlxsw/spectrum_qdisc.c  |  35 +-
 .../ethernet/mellanox/mlxsw/spectrum_router.c |  38 +-
 .../ethernet/mellanox/mlxsw/spectrum_router.h |  35 +-
 .../ethernet/mellanox/mlxsw/spectrum_span.c   |  35 +-
 .../ethernet/mellanox/mlxsw/spectrum_span.h   |  34 +-
 .../mellanox/mlxsw/spectrum_switchdev.c       |  37 +-
 .../mellanox/mlxsw/spectrum_switchdev.h       |  34 +-
 .../net/ethernet/mellanox/mlxsw/switchib.c    |  35 +-
 .../net/ethernet/mellanox/mlxsw/switchx2.c    |  37 +-
 drivers/net/ethernet/mellanox/mlxsw/trap.h    |  38 +-
 .../net/ethernet/mellanox/mlxsw/txheader.h    |  36 +-
 .../drivers/net/mlxsw/spectrum-2/tc_flower.sh | 366 ++++++++++++++++++
 65 files changed, 547 insertions(+), 2151 deletions(-)
 create mode 100755 tools/testing/selftests/drivers/net/mlxsw/spectrum-2/tc_flower.sh

-- 
2.17.1

^ permalink raw reply

* Re: [PATCH 14/28] net: split eth_platform_get_mac_address() into subroutines
From: Bartosz Golaszewski @ 2018-08-09 11:12 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Jonathan Corbet, Sekhar Nori, Kevin Hilman, Russell King,
	Arnd Bergmann, Greg Kroah-Hartman, David Woodhouse, Brian Norris,
	Boris Brezillon, Marek Vasut, Richard Weinberger,
	Grygorii Strashko, David S . Miller, Srinivas Kandagatla, Naren,
	Mauro Carvalho Chehab, Andrew Morton, Lukas Wunner, Dan Carpenter
In-Reply-To: <CAHp75VfxVOPzAtBgTe4RSax1Ki+323WDBTSmh=j7LV_c+vsXDA@mail.gmail.com>

2018-08-08 19:50 GMT+02:00 Andy Shevchenko <andy.shevchenko@gmail.com>:
> On Wed, Aug 8, 2018 at 6:31 PM, Bartosz Golaszewski <brgl@bgdev.pl> wrote:
>> From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
>>
>> We want do add more sources from which to read the MAC address. In
>> order to avoid bloating this function too much, start by splitting it
>> into subroutines, each of which takes care of reading the MAC from
>> one source.
>
>> +static int mac_address_from_of(struct device *dev, u8 *mac_addr)
>>  {
>>         const unsigned char *addr;
>> +       struct device_node *np;
>>
>
>> +       np = dev_is_pci(dev) ? pci_device_to_OF_node(to_pci_dev(dev))
>> +                            : dev->of_node;
>
> I didn't get these manipulations.
>
> What the scenario when pci_dev->dev.of_node != dev->of_node?
>
> --
> With Best Regards,
> Andy Shevchenko

I'll add an additional patch that addresses it.

Bart

^ permalink raw reply

* Re: [PATCH v2 0/2] net/sctp: Avoid allocating high order memory with kmalloc()
From: Konstantin Khorenko @ 2018-08-09  8:43 UTC (permalink / raw)
  To: Marcelo Ricardo Leitner
  Cc: oleg.babin, netdev, linux-sctp, David S . Miller, Vlad Yasevich,
	Neil Horman, Xin Long, Andrey Ryabinin
In-Reply-To: <20180803233626.GI5482@localhost.localdomain>

On 08/04/2018 02:36 AM, Marcelo Ricardo Leitner wrote:
> On Fri, Aug 03, 2018 at 07:21:00PM +0300, Konstantin Khorenko wrote:
> ...
>> Performance results:
>> ====================
>>   * Kernel: v4.18-rc6 - stock and with 2 patches from Oleg (earlier in this thread)
>>   * Node: CPU (8 cores): Intel(R) Xeon(R) CPU E31230 @ 3.20GHz
>>           RAM: 32 Gb
>>
>>   * netperf: taken from https://github.com/HewlettPackard/netperf.git,
>> 	     compiled from sources with sctp support
>>   * netperf server and client are run on the same node
>>   * ip link set lo mtu 1500
>>
>> The script used to run tests:
>>  # cat run_tests.sh
>>  #!/bin/bash
>>
>> for test in SCTP_STREAM SCTP_STREAM_MANY SCTP_RR SCTP_RR_MANY; do
>>   echo "TEST: $test";
>>   for i in `seq 1 3`; do
>>     echo "Iteration: $i";
>>     set -x
>>     netperf -t $test -H localhost -p 22222 -S 200000,200000 -s 200000,200000 \
>>             -l 60 -- -m 1452;
>>     set +x
>>   done
>> done
>> ================================================
>>
>> Results (a bit reformatted to be more readable):
> ...
>
> Nice, good numbers.
>
> I'm missing some test that actually uses more than 1 stream. All tests
> in netperf uses only 1 stream. They can use 1 or Many associations on
> a socket, but not multiple streams. That means the numbers here show
> that we shouldn't see any regression on the more traditional uses, per
> Michael's reply on the other email, but it is not testing how it will
> behave if we go crazy and use the 64k streams (worst case).
>
> You'll need some other tool to test it. One idea is sctp_test, from
> lksctp-tools. Something like:
>
> Server side:
> 	./sctp_test -H 172.0.0.1 -P 22222 -l -d 0
> Client side:
> 	time ./sctp_test -H 172.0.0.1 -P 22221 \
> 		-h 172.0.0.1 -p 22222 -s \
> 		-c 1 -M 65535 -T -t 1 -x 100000 -d 0
>
> And then measure the difference on how long each test took. Can you
> get these too?
>
> Interesting that in my laptop just to start this test for the first
> time can took some *seconds*. Seems kernel had a hard time
> defragmenting the memory here. :)

No problem, will do those measurements as well.

Even more, to get the test results more repeatable, i think i make
the memory highly fragmented before the test. :)

Thank you!

^ permalink raw reply

* Re: [PATCH v2 1/2] net/sctp: Make wrappers for accessing in/out streams
From: Konstantin Khorenko @ 2018-08-09  8:40 UTC (permalink / raw)
  To: Marcelo Ricardo Leitner
  Cc: oleg.babin, netdev, linux-sctp, David S . Miller, Vlad Yasevich,
	Neil Horman, Xin Long, Andrey Ryabinin
In-Reply-To: <20180803204011.GH5482@localhost.localdomain>

On 08/03/2018 11:40 PM, Marcelo Ricardo Leitner wrote:
> On Fri, Aug 03, 2018 at 07:21:01PM +0300, Konstantin Khorenko wrote:
>> This patch introduces wrappers for accessing in/out streams indirectly.
>> This will enable to replace physically contiguous memory arrays
>> of streams with flexible arrays (or maybe any other appropriate
>> mechanism) which do memory allocation on a per-page basis.
>>
>> Signed-off-by: Oleg Babin <obabin@virtuozzo.com>
>> Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
>>
>> ---
>> v2 changes:
>>  sctp_stream_in() users are updated to provide stream as an argument,
>>  sctp_stream_{in,out}_ptr() are now just sctp_stream_{in,out}().
>> ---
>
> ...
>
>>
>>  struct sctp_stream {
>> -	struct sctp_stream_out *out;
>> -	struct sctp_stream_in *in;
>> +	struct flex_array *out;
>> +	struct flex_array *in;
>
> If this patch was meant to be a preparation, shouldn't this belong to
> the next patch instead?

Marcelo,

agree, that will be better, will move the hunk along with changes in
sctp_stream_alloc_{in,out}().

Thank you!

^ permalink raw reply

* Re: [PATCH v2 1/2] net/sctp: Make wrappers for accessing in/out streams
From: Konstantin Khorenko @ 2018-08-09  8:39 UTC (permalink / raw)
  To: David Miller, David Laight
  Cc: marcelo.leitner, oleg.babin, netdev, linux-sctp, vyasevich,
	nhorman, lucien.xin, aryabinin
In-Reply-To: <20180803.125000.55557304308180305.davem@davemloft.net>

On 08/03/2018 10:50 PM, David Miller wrote:
> From: Konstantin Khorenko <khorenko@virtuozzo.com>
> Date: Fri,  3 Aug 2018 19:21:01 +0300
>
>> +struct sctp_stream_out *sctp_stream_out(const struct sctp_stream *stream,
>> +					__u16 sid)
>> +{
>> +	return ((struct sctp_stream_out *)(stream->out)) + sid;
>> +}
>> +
>> +struct sctp_stream_in *sctp_stream_in(const struct sctp_stream *stream,
>> +				      __u16 sid)
>> +{
>> +	return ((struct sctp_stream_in *)(stream->in)) + sid;
>> +}
>
> I agree with David that these should be in a header file, and marked
> inline.

David and David,

sure, will move them, thank you!

^ permalink raw reply

* [PATCH] rxrpc: remove redundant static int 'zero'
From: Colin King @ 2018-08-09 11:00 UTC (permalink / raw)
  To: David Howells, David S . Miller, linux-afs, netdev
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

The static int 'zero' is defined but is never used hence it is
redundant and can be removed. The use of this variable was removed
with commit a158bdd3247b ("rxrpc: Fix call timeouts").

Cleans up clang warning:
warning: 'zero' defined but not used [-Wunused-const-variable=]

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 net/rxrpc/sysctl.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/net/rxrpc/sysctl.c b/net/rxrpc/sysctl.c
index 4a7af7aff37d..d75bd15151e6 100644
--- a/net/rxrpc/sysctl.c
+++ b/net/rxrpc/sysctl.c
@@ -15,7 +15,6 @@
 #include "ar-internal.h"
 
 static struct ctl_table_header *rxrpc_sysctl_reg_table;
-static const unsigned int zero = 0;
 static const unsigned int one = 1;
 static const unsigned int four = 4;
 static const unsigned int thirtytwo = 32;
-- 
2.17.1

^ permalink raw reply related

* Creating custom ipsets
From: Akshat Kakkar @ 2018-08-09  8:29 UTC (permalink / raw)
  To: netdev

I want to create custom ipsets like hash: iface,iface ,etc.
Can anybody guide which is the best place to start development for the
same? Any documents, etc.

Also, can we store some IP in skbinfo?

Thanks and Regards,
Akshat

^ permalink raw reply

* Re: [PATCH] fix build for MediaTek MT7610U USB wireless dongle
From: Stanislaw Gruszka @ 2018-08-09 10:51 UTC (permalink / raw)
  To: valdis.kletnieks
  Cc: Kalle Valo, David S. Miller, netdev, linux-kernel, linux-wireless
In-Reply-To: <145751.1533759414@turing-police.cc.vt.edu>

On Wed, Aug 08, 2018 at 04:16:54PM -0400, valdis.kletnieks@vt.edu wrote:
> The mt76x0 driver requires the mt76 core driver to actually function.
> So add a 'select' to avoid embarrassing 'symbol unknown' errors
> when attempting to modprobe it in a module tree that doesn't
> include mt76.ko
> 
> Signed-off-by: Valdis Kletnieks <valdis.kletnieks@vt.edu>
> ---
> Still need to figure out why it totally fails to see the 5gz band,
> it works find on 2.4 but ends up locked at 72mbits/sec. Works
> OK otherwise...

This may depend on HW configuration written in the EEPROM. My dongle
Linksys AE6000 do not require various features that Mediatek driver has,
those are not implemented in mt76x0 driver and should be added. Your
hardware may require those features.

You can try version of the driver from:
https://github.com/sgruszka/wireless-drivers-next/commits/mt76x0-draft-v2
which include various fixes and possibly can make things better
(or worse, there can be regressions too)

Cheers
Stanislaw

^ permalink raw reply

* Re: [PATCH wireless-drivers] mt76x0: Remove VLA usage
From: Kalle Valo @ 2018-08-09 10:51 UTC (permalink / raw)
  To: Stanislaw Gruszka
  Cc: Kees Cook, David S. Miller, linux-wireless, Network Development,
	LKML, Jonathan Corbet
In-Reply-To: <20180809104137.GA1955@redhat.com>

Stanislaw Gruszka <sgruszka@redhat.com> writes:

> On Wed, Aug 08, 2018 at 08:41:28AM -0700, Kees Cook wrote:
>> >> I thought SPDX line is needed only if file has no license and eeprom.c
>> >> file and other mt76x0 files have specified the license. Is SPDX still
>> >> needed in that case ?
>> 
>> I thought all source files needed SPDX: https://lwn.net/Articles/739183/
>
> Ok, goal is to have all kernel source files with SPDX header.

Yeah, it's a goal but I don't think it's a hard requirement yet. At
least I don't see it as a reason to reject patches.

And besides, mt76 uses ISC license and that's not in LICENSES directory.
So someone should add that first, and I think that patch should go via
Jonathan Corbet's tree (CCed).

-- 
Kalle Valo

^ permalink raw reply

* Re: [PATCH] net: macb: do not disable MDIO bus when closing interface
From: Claudiu Beznea @ 2018-08-09  8:26 UTC (permalink / raw)
  To: Anssi Hannula, Nicolas Ferre, David S. Miller; +Cc: netdev
In-Reply-To: <20180808121901.10264-1-anssi.hannula@bitwise.fi>



On 08.08.2018 15:19, Anssi Hannula wrote:
> macb_close() calls macb_reset_hw() which zeroes NCR register, including
> the MPE (Management Port Enable) bit.
> 
> This will prevent accessing any other PHYs for other Ethernet MACs on
> the MDIO bus which is still registered.
> 
> Fix that by keeping the MPE bit set.
> 
> Signed-off-by: Anssi Hannula <anssi.hannula@bitwise.fi>
> ---
>  drivers/net/ethernet/cadence/macb_main.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
> index dc09f9a8a49b..3ca98fc32144 100644
> --- a/drivers/net/ethernet/cadence/macb_main.c
> +++ b/drivers/net/ethernet/cadence/macb_main.c
> @@ -2030,12 +2030,13 @@ static void macb_reset_hw(struct macb *bp)
>  	unsigned int q;
>  
>  	/* Disable RX and TX (XXX: Should we halt the transmission
> -	 * more gracefully?)
> +	 * more gracefully?) but keep management port open since there
> +	 * may be other users of the mdio bus
>  	 */
> -	macb_writel(bp, NCR, 0);
> +	macb_writel(bp, NCR, MACB_BIT(MPE));

Would be better to read the NCR and clear only RX and TX bits, something like:
	val = macb_readl(bp, NCR);

	/* Disable TX and RX. */
	val &= ~(MACB_BIT(TE) | MACB_BIT(RE));

	/* Clear statistics */
	val |= MACB_BIT(CLRSTAT);

	macb_writel(bp, NCR, val);

MPE should have been enabled by previous operations.

Thank you,
Claudiu Beznea

>  
>  	/* Clear the stats registers (XXX: Update stats first?) */
> -	macb_writel(bp, NCR, MACB_BIT(CLRSTAT));
> +	macb_writel(bp, NCR, MACB_BIT(CLRSTAT) | MACB_BIT(MPE));
>  
>  	/* Clear all status flags */
>  	macb_writel(bp, TSR, -1);
> 

^ permalink raw reply

* The recvmsg() with IP_PKTINFO for local addresses returns various ipi_ifindex
From: Damir Mansurov @ 2018-08-09  8:13 UTC (permalink / raw)
  To: netdev; +Cc: Alexandra N. Kossovsky

Greetings,

I use the IP_PKTINFO to detect ipi_ifindex from which the packet was 
arrived, it used to work for local addresses also.

For local addresses ipi_ifindex always returned 1, but starting from 
Linux 4.14 ip_ifindex began to return various values.

Example host configuration:
1:  lo:   127.0.0.1
2:  eth0: 192.168.3.45
3:  eth1: 192.168.4.45

I use sendto() with addresses {127.0.0.1, 192.168.3.45 and 
192.168.4.45}, call recvmsg() and than use standard procedure to get 
ipi_ifindex, it shows results:

                  |      ipi_ifindex     |      ipi_ifindex
  sendto(address) |   Linux ver < 4.14   |   Linux ver >= 4.14
---------------------------------------------------------------
   127.0.0.1      |          1           |           1
---------------------------------------------------------------
   192.168.3.45   |          1           |           2
---------------------------------------------------------------
   192.168.4.45   |          1           |           3


It seems that this behavior depends from commit:
net: ipv4: set orig_oif based on fib result for local traffic

https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?h=linux-4.14.y&id=839da4d98960bcc68e6b7b945b33ad3916ec1e92

I believe that ipi_ifindex for local addresses should be 1.
Is there a Bug for Linux >= 4.14 or is this a valid behavior?



************************
Thanks,
Damir Mansurov
dnman@oktetlabs.ru

^ permalink raw reply

* Re: [PATCH wireless-drivers] mt76x0: Remove VLA usage
From: Stanislaw Gruszka @ 2018-08-09 10:41 UTC (permalink / raw)
  To: Kees Cook
  Cc: Kalle Valo, David S. Miller, linux-wireless, Network Development,
	LKML
In-Reply-To: <CAGXu5jKqeAHDWdNg++QJko5AM4g160kEQ54jLAojpRq6FszqgA@mail.gmail.com>

On Wed, Aug 08, 2018 at 08:41:28AM -0700, Kees Cook wrote:
> >> I thought SPDX line is needed only if file has no license and eeprom.c
> >> file and other mt76x0 files have specified the license. Is SPDX still
> >> needed in that case ?
> 
> I thought all source files needed SPDX: https://lwn.net/Articles/739183/

Ok, goal is to have all kernel source files with SPDX header.

> >>> +#define MT_MAP_READS        DIV_ROUND_UP(MT_EFUSE_USAGE_MAP_SIZE, 16)
> >>>  static int
> >>>  mt76x0_efuse_physical_size_check(struct mt76x0_dev *dev)
> >>>  {
> >>> -    const int map_reads = DIV_ROUND_UP(MT_EFUSE_USAGE_MAP_SIZE, 16);
> >>> -    u8 data[map_reads * 16];
> >>
> >> Why this is variable length array? DIV_ROUND_UP can not be calculated
> >> at compile time? But if so, macro do not change the situation either.
> >
> > The commit log mentioned:
> >
> >   "Even with "const" variables, the compiler will generate warnings about
> >    VLA usage."
> >
> > So I guess the compiler (gcc?) is just not smart enough in this case?
> 
> Correct. This is technically a false positive, but with the goal of
> adding -Wvla to the build globally, we have to get rid of these as
> well. It's a little frustrating, I agree, but with all others fixed
> now, these stand out. :)

Then:
Acked-by: Stanislaw Gruszka <sgruszka@redhat.com>

^ permalink raw reply

* [PATCH v5] selftests: add headers_install to lib.mk
From: Anders Roxell @ 2018-08-09  8:04 UTC (permalink / raw)
  To: yamada.masahiro, michal.lkml, shuah, bamv2005, brgl, pbonzini,
	akpm, rppt, aarcange
  Cc: linux-kbuild, linux-kernel, linux-kselftest, netdev,
	Anders Roxell
In-Reply-To: <3f332e65-0b33-9952-6aba-f9c8953a1f26@kernel.org>

If the kernel headers aren't installed we can't build all the tests.
Add a new make target rule 'khdr' in the file lib.mk to generate the
kernel headers and that gets include for every test-dir Makefile that
includes lib.mk If the testdir in turn have its own sub-dirs the
top_srcdir needs to be set to the linux-rootdir to be able to generate
the kernel headers.

Signed-off-by: Anders Roxell <anders.roxell@linaro.org>
Reviewed-by: Fathi Boudra <fathi.boudra@linaro.org>
---

Rebased onto next-20180808

Cheers,
Anders

 Makefile                                           | 14 +-------------
 scripts/subarch.include                            | 13 +++++++++++++
 tools/testing/selftests/android/Makefile           |  2 +-
 tools/testing/selftests/android/ion/Makefile       |  2 ++
 tools/testing/selftests/futex/functional/Makefile  |  1 +
 tools/testing/selftests/gpio/Makefile              |  7 ++-----
 tools/testing/selftests/kvm/Makefile               |  7 ++-----
 tools/testing/selftests/lib.mk                     | 12 ++++++++++++
 tools/testing/selftests/net/Makefile               |  1 +
 .../selftests/networking/timestamping/Makefile     |  1 +
 tools/testing/selftests/vm/Makefile                |  4 ----
 11 files changed, 36 insertions(+), 28 deletions(-)
 create mode 100644 scripts/subarch.include

diff --git a/Makefile b/Makefile
index c88d56de7fda..49dc0c6e1f23 100644
--- a/Makefile
+++ b/Makefile
@@ -299,19 +299,7 @@ KERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null)
 KERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION)
 export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION
 
-# SUBARCH tells the usermode build what the underlying arch is.  That is set
-# first, and if a usermode build is happening, the "ARCH=um" on the command
-# line overrides the setting of ARCH below.  If a native build is happening,
-# then ARCH is assigned, getting whatever value it gets normally, and
-# SUBARCH is subsequently ignored.
-
-SUBARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \
-				  -e s/sun4u/sparc64/ \
-				  -e s/arm.*/arm/ -e s/sa110/arm/ \
-				  -e s/s390x/s390/ -e s/parisc64/parisc/ \
-				  -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \
-				  -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ \
-				  -e s/riscv.*/riscv/)
+include scripts/subarch.include
 
 # Cross compiling and selecting different set of gcc/bin-utils
 # ---------------------------------------------------------------------------
diff --git a/scripts/subarch.include b/scripts/subarch.include
new file mode 100644
index 000000000000..650682821126
--- /dev/null
+++ b/scripts/subarch.include
@@ -0,0 +1,13 @@
+# SUBARCH tells the usermode build what the underlying arch is.  That is set
+# first, and if a usermode build is happening, the "ARCH=um" on the command
+# line overrides the setting of ARCH below.  If a native build is happening,
+# then ARCH is assigned, getting whatever value it gets normally, and
+# SUBARCH is subsequently ignored.
+
+SUBARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \
+				  -e s/sun4u/sparc64/ \
+				  -e s/arm.*/arm/ -e s/sa110/arm/ \
+				  -e s/s390x/s390/ -e s/parisc64/parisc/ \
+				  -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \
+				  -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ \
+				  -e s/riscv.*/riscv/)
diff --git a/tools/testing/selftests/android/Makefile b/tools/testing/selftests/android/Makefile
index 72c25a3cb658..d9a725478375 100644
--- a/tools/testing/selftests/android/Makefile
+++ b/tools/testing/selftests/android/Makefile
@@ -6,7 +6,7 @@ TEST_PROGS := run.sh
 
 include ../lib.mk
 
-all:
+all: khdr
 	@for DIR in $(SUBDIRS); do		\
 		BUILD_TARGET=$(OUTPUT)/$$DIR;	\
 		mkdir $$BUILD_TARGET  -p;	\
diff --git a/tools/testing/selftests/android/ion/Makefile b/tools/testing/selftests/android/ion/Makefile
index e03695287f76..88cfe88e466f 100644
--- a/tools/testing/selftests/android/ion/Makefile
+++ b/tools/testing/selftests/android/ion/Makefile
@@ -10,6 +10,8 @@ $(TEST_GEN_FILES): ipcsocket.c ionutils.c
 
 TEST_PROGS := ion_test.sh
 
+KSFT_KHDR_INSTALL := 1
+top_srcdir = ../../../../..
 include ../../lib.mk
 
 $(OUTPUT)/ionapp_export: ionapp_export.c ipcsocket.c ionutils.c
diff --git a/tools/testing/selftests/futex/functional/Makefile b/tools/testing/selftests/futex/functional/Makefile
index ff8feca49746..ad1eeb14fda7 100644
--- a/tools/testing/selftests/futex/functional/Makefile
+++ b/tools/testing/selftests/futex/functional/Makefile
@@ -18,6 +18,7 @@ TEST_GEN_FILES := \
 
 TEST_PROGS := run.sh
 
+top_srcdir = ../../../../..
 include ../../lib.mk
 
 $(TEST_GEN_FILES): $(HEADERS)
diff --git a/tools/testing/selftests/gpio/Makefile b/tools/testing/selftests/gpio/Makefile
index 1bbb47565c55..4665cdbf1a8d 100644
--- a/tools/testing/selftests/gpio/Makefile
+++ b/tools/testing/selftests/gpio/Makefile
@@ -21,11 +21,8 @@ endef
 CFLAGS += -O2 -g -std=gnu99 -Wall -I../../../../usr/include/
 LDLIBS += -lmount -I/usr/include/libmount
 
-$(BINARIES): ../../../gpio/gpio-utils.o ../../../../usr/include/linux/gpio.h
+$(BINARIES):| khdr
+$(BINARIES): ../../../gpio/gpio-utils.o
 
 ../../../gpio/gpio-utils.o:
 	make ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C ../../../gpio
-
-../../../../usr/include/linux/gpio.h:
-	make -C ../../../.. headers_install INSTALL_HDR_PATH=$(shell pwd)/../../../../usr/
-
diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile
index dd0e5163f01f..34d492b77a7c 100644
--- a/tools/testing/selftests/kvm/Makefile
+++ b/tools/testing/selftests/kvm/Makefile
@@ -34,9 +34,6 @@ $(LIBKVM_OBJ): $(OUTPUT)/%.o: %.c
 $(OUTPUT)/libkvm.a: $(LIBKVM_OBJ)
 	$(AR) crs $@ $^
 
-$(LINUX_HDR_PATH):
-	make -C $(top_srcdir) headers_install
-
-all: $(STATIC_LIBS) $(LINUX_HDR_PATH)
+all: $(STATIC_LIBS)
 $(TEST_GEN_PROGS): $(STATIC_LIBS)
-$(TEST_GEN_PROGS) $(LIBKVM_OBJ): | $(LINUX_HDR_PATH)
+$(STATIC_LIBS):| khdr
diff --git a/tools/testing/selftests/lib.mk b/tools/testing/selftests/lib.mk
index 17ab36605a8e..0a8e75886224 100644
--- a/tools/testing/selftests/lib.mk
+++ b/tools/testing/selftests/lib.mk
@@ -16,8 +16,20 @@ TEST_GEN_PROGS := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS))
 TEST_GEN_PROGS_EXTENDED := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS_EXTENDED))
 TEST_GEN_FILES := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_FILES))
 
+top_srcdir ?= ../../../..
+include $(top_srcdir)/scripts/subarch.include
+ARCH		?= $(SUBARCH)
+
 all: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES)
 
+.PHONY: khdr
+khdr:
+	make ARCH=$(ARCH) -C $(top_srcdir) headers_install
+
+ifdef KSFT_KHDR_INSTALL
+$(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES):| khdr
+endif
+
 .ONESHELL:
 define RUN_TEST_PRINT_RESULT
 	TEST_HDR_MSG="selftests: "`basename $$PWD`:" $$BASENAME_TEST";	\
diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile
index 9cca68e440a0..919aa2ac00af 100644
--- a/tools/testing/selftests/net/Makefile
+++ b/tools/testing/selftests/net/Makefile
@@ -15,6 +15,7 @@ TEST_GEN_FILES += udpgso udpgso_bench_tx udpgso_bench_rx
 TEST_GEN_PROGS = reuseport_bpf reuseport_bpf_cpu reuseport_bpf_numa
 TEST_GEN_PROGS += reuseport_dualstack reuseaddr_conflict tls
 
+KSFT_KHDR_INSTALL := 1
 include ../lib.mk
 
 $(OUTPUT)/reuseport_bpf_numa: LDFLAGS += -lnuma
diff --git a/tools/testing/selftests/networking/timestamping/Makefile b/tools/testing/selftests/networking/timestamping/Makefile
index a728040edbe1..14cfcf006936 100644
--- a/tools/testing/selftests/networking/timestamping/Makefile
+++ b/tools/testing/selftests/networking/timestamping/Makefile
@@ -5,6 +5,7 @@ TEST_PROGS := hwtstamp_config rxtimestamp timestamping txtimestamp
 
 all: $(TEST_PROGS)
 
+top_srcdir = ../../../../..
 include ../../lib.mk
 
 clean:
diff --git a/tools/testing/selftests/vm/Makefile b/tools/testing/selftests/vm/Makefile
index 9881876d2aa0..e94b7b14bcb2 100644
--- a/tools/testing/selftests/vm/Makefile
+++ b/tools/testing/selftests/vm/Makefile
@@ -26,10 +26,6 @@ TEST_PROGS := run_vmtests
 
 include ../lib.mk
 
-$(OUTPUT)/userfaultfd: ../../../../usr/include/linux/kernel.h
 $(OUTPUT)/userfaultfd: LDLIBS += -lpthread
 
 $(OUTPUT)/mlock-random-test: LDLIBS += -lcap
-
-../../../../usr/include/linux/kernel.h:
-	make -C ../../../.. headers_install
-- 
2.18.0

^ permalink raw reply related

* [net-next, PATCH 2/2] net: socionext: Increase descriptors to 256
From: Ilias Apalodimas @ 2018-08-09  8:02 UTC (permalink / raw)
  To: netdev, jaswinder.singh; +Cc: arnd, Ilias Apalodimas
In-Reply-To: <1533801739-15312-1-git-send-email-ilias.apalodimas@linaro.org>

Increasing descriptors to 256 from 128 and adjusting the NAPI weight
to 64 increases performace on Rx by ~20% on 64byte packets

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
---
 drivers/net/ethernet/socionext/netsec.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/socionext/netsec.c b/drivers/net/ethernet/socionext/netsec.c
index ae32909..5d2007b 100644
--- a/drivers/net/ethernet/socionext/netsec.c
+++ b/drivers/net/ethernet/socionext/netsec.c
@@ -232,8 +232,7 @@
 #define NETSEC_EEPROM_PKT_ME_ADDRESS		0x20
 #define NETSEC_EEPROM_PKT_ME_SIZE		0x24
 
-#define DESC_NUM	128
-#define NAPI_BUDGET	(DESC_NUM / 2)
+#define DESC_NUM	256
 
 #define DESC_SZ	sizeof(struct netsec_de)
 
@@ -1655,7 +1654,7 @@ static int netsec_probe(struct platform_device *pdev)
 	dev_info(&pdev->dev, "hardware revision %d.%d\n",
 		 hw_ver >> 16, hw_ver & 0xffff);
 
-	netif_napi_add(ndev, &priv->napi, netsec_napi_poll, NAPI_BUDGET);
+	netif_napi_add(ndev, &priv->napi, netsec_napi_poll, NAPI_POLL_WEIGHT);
 
 	ndev->netdev_ops = &netsec_netdev_ops;
 	ndev->ethtool_ops = &netsec_ethtool_ops;
-- 
2.7.4

^ permalink raw reply related

* [net-next, PATCH 1/2] net: socionext: Use descriptor info instead of MMIO reads on Rx
From: Ilias Apalodimas @ 2018-08-09  8:02 UTC (permalink / raw)
  To: netdev, jaswinder.singh; +Cc: arnd, Ilias Apalodimas

MMIO reads for remaining packets in queue occur (at least)twice per
invocation of netsec_process_rx(). We can use the packet descriptor to
identify if it's owned by the hardware and break out, avoiding the more
expensive MMIO read operations. This has a ~2% increase on the pps of the
Rx path when tested with 64byte packets

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
---
 drivers/net/ethernet/socionext/netsec.c | 19 +++++--------------
 1 file changed, 5 insertions(+), 14 deletions(-)

diff --git a/drivers/net/ethernet/socionext/netsec.c b/drivers/net/ethernet/socionext/netsec.c
index 01589b6..ae32909 100644
--- a/drivers/net/ethernet/socionext/netsec.c
+++ b/drivers/net/ethernet/socionext/netsec.c
@@ -657,8 +657,6 @@ static struct sk_buff *netsec_get_rx_pkt_data(struct netsec_priv *priv,
 	/* move tail ahead */
 	dring->tail = (dring->tail + 1) % DESC_NUM;
 
-	dring->pkt_cnt--;
-
 	return skb;
 }
 
@@ -731,25 +729,18 @@ static int netsec_process_rx(struct netsec_priv *priv, int budget)
 	struct netsec_desc_ring *dring = &priv->desc_ring[NETSEC_RING_RX];
 	struct net_device *ndev = priv->ndev;
 	struct netsec_rx_pkt_info rx_info;
-	int done = 0, rx_num = 0;
+	int done = 0;
 	struct netsec_desc desc;
 	struct sk_buff *skb;
 	u16 len;
 
 	while (done < budget) {
-		if (!rx_num) {
-			rx_num = netsec_read(priv, NETSEC_REG_NRM_RX_PKTCNT);
-			dring->pkt_cnt += rx_num;
-
-			/* move head 'rx_num' */
-			dring->head = (dring->head + rx_num) % DESC_NUM;
+		u16 idx = dring->tail;
+		struct netsec_de *de = dring->vaddr + (DESC_SZ * idx);
 
-			rx_num = dring->pkt_cnt;
-			if (!rx_num)
-				break;
-		}
+		if (de->attr & (1U << NETSEC_RX_PKT_OWN_FIELD))
+			break;
 		done++;
-		rx_num--;
 		skb = netsec_get_rx_pkt_data(priv, &rx_info, &desc, &len);
 		if (unlikely(!skb) || rx_info.err_flag) {
 			netif_err(priv, drv, priv->ndev,
-- 
2.7.4

^ permalink raw reply related

* Re: [Patch net-next] net_sched: fix a potential out-of-bound access
From: Vlad Buslov @ 2018-08-09  7:32 UTC (permalink / raw)
  To: Cong Wang; +Cc: netdev, Jiri Pirko
In-Reply-To: <20180808213256.16425-1-xiyou.wangcong@gmail.com>

On Wed 08 Aug 2018 at 21:32, Cong Wang <xiyou.wangcong@gmail.com> wrote:
> In tca_action_gd(), when tcf_action_get_1() fails in the middle
> of the loop, tcf_action_put_many(&actions[acts_deleted]) is
> called to cleanup.
>
> But inside tcf_action_put_many() it still iterates from
> 0 to TCA_ACT_MAX_PRIO, so inside it would be:
>
> &actions[acts_deleted][0]...&actions[acts_deleted][MAX_PRIO]
>
> Then the overall of the result is:
>
> actions[acts_deleted]...actions[acts_deleted + MAX_PRIO]
>
> We have a potential out-of-bound access when acts_deleted > 1.
>
> acts_deleted is completely unnecessary since tcf_action_put_many()
> checks against NULL pointer.
>
> Fixes: 90b73b77d08e ("net: sched: change action API to use array of pointers to actions")
> Cc: Jiri Pirko <jiri@mellanox.com>
> Cc: Vlad Buslov <vladbu@mellanox.com>
> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
> ---
>  net/sched/act_api.c | 17 ++++++-----------
>  1 file changed, 6 insertions(+), 11 deletions(-)
>
> diff --git a/net/sched/act_api.c b/net/sched/act_api.c
> index 229d63c99be2..36549bc7ce78 100644
> --- a/net/sched/act_api.c
> +++ b/net/sched/act_api.c
> @@ -1176,7 +1176,7 @@ static int tca_action_flush(struct net *net, struct nlattr *nla,
>  }
>  
>  static int tcf_action_delete(struct net *net, struct tc_action *actions[],
> -			     int *acts_deleted, struct netlink_ext_ack *extack)
> +			     struct netlink_ext_ack *extack)
>  {
>  	u32 act_index;
>  	int ret, i;
> @@ -1196,20 +1196,16 @@ static int tcf_action_delete(struct net *net, struct tc_action *actions[],
>  		} else  {
>  			/* now do the delete */
>  			ret = ops->delete(net, act_index);
> -			if (ret < 0) {
> -				*acts_deleted = i + 1;
> +			if (ret < 0)
>  				return ret;
> -			}
>  		}
>  	}
> -	*acts_deleted = i;
>  	return 0;
>  }
>  
>  static int
>  tcf_del_notify(struct net *net, struct nlmsghdr *n, struct tc_action *actions[],
> -	       int *acts_deleted, u32 portid, size_t attr_size,
> -	       struct netlink_ext_ack *extack)
> +	       u32 portid, size_t attr_size, struct netlink_ext_ack *extack)
>  {
>  	int ret;
>  	struct sk_buff *skb;
> @@ -1227,7 +1223,7 @@ tcf_del_notify(struct net *net, struct nlmsghdr *n, struct tc_action *actions[],
>  	}
>  
>  	/* now do the delete */
> -	ret = tcf_action_delete(net, actions, acts_deleted, extack);
> +	ret = tcf_action_delete(net, actions, extack);
>  	if (ret < 0) {
>  		NL_SET_ERR_MSG(extack, "Failed to delete TC action");
>  		kfree_skb(skb);
> @@ -1250,7 +1246,6 @@ tca_action_gd(struct net *net, struct nlattr *nla, struct nlmsghdr *n,
>  	struct tc_action *act;
>  	size_t attr_size = 0;
>  	struct tc_action *actions[TCA_ACT_MAX_PRIO + 1] = {};
> -	int acts_deleted = 0;
>  
>  	ret = nla_parse_nested(tb, TCA_ACT_MAX_PRIO, nla, NULL, extack);
>  	if (ret < 0)
> @@ -1280,14 +1275,14 @@ tca_action_gd(struct net *net, struct nlattr *nla, struct nlmsghdr *n,
>  	if (event == RTM_GETACTION)
>  		ret = tcf_get_notify(net, portid, n, actions, event, extack);
>  	else { /* delete */
> -		ret = tcf_del_notify(net, n, actions, &acts_deleted, portid,
> +		ret = tcf_del_notify(net, n, actions, portid,
>  				     attr_size, extack);
>  		if (ret)
>  			goto err;
>  		return ret;
>  	}
>  err:
> -	tcf_action_put_many(&actions[acts_deleted]);
> +	tcf_action_put_many(actions);
>  	return ret;
>  }

Hello Cong,

Before version V5 of my action API patchset this functionality was
implemented in exactly the same way as in your patch. Unfortunately, it
has a double-free bug. The problem is that if you have multiple
actions(N) being deleted, and deleted succeeded for first K actions,
this implementation will try to delete all N actions second time
(including first K actions that were already deleted). That is why I
added 'acts_deleted' variable that tracks actual amount of actions that
were deleted successfully, and only delete last N-K actions in case of
error.

In order to fix that issue I did following code changes in V5:
- Added 'acts_deleted' variable to delete only actions [K, N) in case of
error.
- Extended 'actions' array size by one to ensure that it always ends
with NULL pointer.

^ permalink raw reply

* Re: [PATCH net-next v6 11/11] net: sched: change action API to use array of pointers to actions
From: Vlad Buslov @ 2018-08-09  7:03 UTC (permalink / raw)
  To: Cong Wang
  Cc: Linux Kernel Network Developers, David Miller, Jamal Hadi Salim,
	Jiri Pirko, Alexei Starovoitov, Daniel Borkmann,
	Yevgeny Kliteynik
In-Reply-To: <CAM_iQpW9_hh8XJOJsMESbOKdGU_qAZ-tQw9n_HrdXTFLTDUCDg@mail.gmail.com>


On Wed 08 Aug 2018 at 18:29, Cong Wang <xiyou.wangcong@gmail.com> wrote:
> On Wed, Aug 8, 2018 at 4:41 AM Vlad Buslov <vladbu@mellanox.com> wrote:
>>
>>
>> On Tue 07 Aug 2018 at 23:26, Cong Wang <xiyou.wangcong@gmail.com> wrote:
>> > On Thu, Jul 5, 2018 at 7:24 AM Vlad Buslov <vladbu@mellanox.com> wrote:
>> >>         attr_size = tcf_action_full_attrs_size(attr_size);
>> >>
>> >>         if (event == RTM_GETACTION)
>> >> -               ret = tcf_get_notify(net, portid, n, &actions, event, extack);
>> >> +               ret = tcf_get_notify(net, portid, n, actions, event, extack);
>> >>         else { /* delete */
>> >> -               ret = tcf_del_notify(net, n, &actions, portid, attr_size, extack);
>> >> +               ret = tcf_del_notify(net, n, actions, &acts_deleted, portid,
>> >> +                                    attr_size, extack);
>> >>                 if (ret)
>> >>                         goto err;
>> >>                 return ret;
>> >>         }
>> >>  err:
>> >> -       tcf_action_put_lst(&actions);
>> >> +       tcf_action_put_many(&actions[acts_deleted]);
>> >>         return ret;
>> >
>> > How does this even work?
>> >
>> > You save an index in 'acts_deleted', but you pass &actions[acts_deleted]
>> > to tcf_action_put_many(), which seems you want to start from
>> > where it fails, but inside tcf_action_put_many() it starts from 0
>> > to TCA_ACT_MAX_PRIO, out-of-bound access at least?
>>
>> Actions array is declared to be TCA_ACT_MAX_PRIO+1 in size, and
>
>
> Declaration doesn't matter at all, functions see it as a pure pointer
> once you pass it as an argument.
>
>
>> initialized to NULL pointers. In loop inside tcf_action_put_many() there
>> are two checks: One is that index is less than TCA_ACT_MAX_PRIO and
>> another one that pointer is not NULL. In this case I rely on extra NULL
>> pointer at the end of actions array to prevent out-of-bound access.
>
> True, but you pass &actions[acts_deleted] as the start of the array,
> so inside it would be:
>
> &actions[acts_deleted][0]...&actions[acts_deleted][MAX_PRIO]
>
> So, the overall of the result is:
>
> actions[acts_deleted]...actions[acts_deleted + MAX_PRIO]
>
> You have out-of-bound access when acts_deleted > 1.
>
> And if acts_deleted == MAX_PRIO-1, then you don't have any
> NULL pointer to rely on.

Lets look at the loop inside tcf_action_put_many():

	for (i = 0; i < TCA_ACT_MAX_PRIO && actions[i]; i++) {
		struct tc_action *a = actions[i];
		const struct tc_action_ops *ops = a->ops;

		if (tcf_action_put(a))
			module_put(ops->owner);
	}

In the case you highlighted I rely on second conditional - pointer to
action in array is not NULL. As I already explained in my previous
email, by making initial array TCA_ACT_MAX_PRIO+1 in size I ensure that
there is always a NULL pointer at the end of sequence of actions pointed
by 'actions' pointer/array.

^ permalink raw reply

* [PATCH net-next] cxgb4: update 1.20.8.0 as the latest firmware supported
From: Ganesh Goudar @ 2018-08-09  7:02 UTC (permalink / raw)
  To: netdev, davem; +Cc: nirranjan, indranil, dt, Ganesh Goudar

Change t4fw_version.h to update latest firmware version
number to 1.20.8.0.

Signed-off-by: Ganesh Goudar <ganeshgr@chelsio.com>
---
 drivers/net/ethernet/chelsio/cxgb4/t4fw_version.h | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/chelsio/cxgb4/t4fw_version.h b/drivers/net/ethernet/chelsio/cxgb4/t4fw_version.h
index 4eb15ce..a844296 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/t4fw_version.h
+++ b/drivers/net/ethernet/chelsio/cxgb4/t4fw_version.h
@@ -36,8 +36,8 @@
 #define __T4FW_VERSION_H__
 
 #define T4FW_VERSION_MAJOR 0x01
-#define T4FW_VERSION_MINOR 0x13
-#define T4FW_VERSION_MICRO 0x01
+#define T4FW_VERSION_MINOR 0x14
+#define T4FW_VERSION_MICRO 0x08
 #define T4FW_VERSION_BUILD 0x00
 
 #define T4FW_MIN_VERSION_MAJOR 0x01
@@ -45,8 +45,8 @@
 #define T4FW_MIN_VERSION_MICRO 0x00
 
 #define T5FW_VERSION_MAJOR 0x01
-#define T5FW_VERSION_MINOR 0x13
-#define T5FW_VERSION_MICRO 0x01
+#define T5FW_VERSION_MINOR 0x14
+#define T5FW_VERSION_MICRO 0x08
 #define T5FW_VERSION_BUILD 0x00
 
 #define T5FW_MIN_VERSION_MAJOR 0x00
@@ -54,8 +54,8 @@
 #define T5FW_MIN_VERSION_MICRO 0x00
 
 #define T6FW_VERSION_MAJOR 0x01
-#define T6FW_VERSION_MINOR 0x13
-#define T6FW_VERSION_MICRO 0x01
+#define T6FW_VERSION_MINOR 0x14
+#define T6FW_VERSION_MICRO 0x08
 #define T6FW_VERSION_BUILD 0x00
 
 #define T6FW_MIN_VERSION_MAJOR 0x00
-- 
2.1.0

^ permalink raw reply related

* Re: [PATCH net-next] ieee802154: Use kmemdup instead of duplicating it in ca8210_test_int_driver_write
From: Stefan Schmidt @ 2018-08-09  8:57 UTC (permalink / raw)
  To: YueHaibing, davem, h.morris, alex.aring; +Cc: linux-kernel, netdev, linux-wpan
In-Reply-To: <aaf879dd-c630-a201-b8ae-66c39a359a99@huawei.com>

Hello Yue.

On 08/09/2018 10:44 AM, YueHaibing wrote:
> On 2018/8/9 16:13, Stefan Schmidt wrote:
>> Hello.
>>
>> On 08/09/2018 08:44 AM, YueHaibing wrote:
>>> Replace calls to kmalloc followed by a memcpy with a direct call to
>>> kmemdup.
>>>
>>> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
>>
>> Is Yue your forname and Haibing your surname? In that case having it
>> written as
>>
>> Yue Haibing <yuehaibing@huawei.com>
> 
> Well, It should be this, but it's been a long time to use the former

Never to late to fix something I guess. :-)
Not blocking this patch base on this though.

>> in the from line as well as in the SOB would be better.
>>
>>> ---
>>>  drivers/net/ieee802154/ca8210.c | 3 +--
>>>  1 file changed, 1 insertion(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/net/ieee802154/ca8210.c b/drivers/net/ieee802154/ca8210.c
>>> index 58299fb..e21279d 100644
>>> --- a/drivers/net/ieee802154/ca8210.c
>>> +++ b/drivers/net/ieee802154/ca8210.c
>>> @@ -634,10 +634,9 @@ static int ca8210_test_int_driver_write(
>>>  	for (i = 0; i < len; i++)
>>>  		dev_dbg(&priv->spi->dev, "%#03x\n", buf[i]);
>>>  
>>> -	fifo_buffer = kmalloc(len, GFP_KERNEL);
>>> +	fifo_buffer = kmemdup(buf, len, GFP_KERNEL);
>>>  	if (!fifo_buffer)
>>>  		return -ENOMEM;
>>> -	memcpy(fifo_buffer, buf, len);
>>>  	kfifo_in(&test->up_fifo, &fifo_buffer, 4);
>>>  	wake_up_interruptible(&priv->test.readq);
>>
>> Is this some kernel tree wide change you are submitting patches for or
>> only for the ca8210 driver? Is there any specific problem you see with
>> the kmalloc and memcpy code here? To me it looks fine.
>>
>> The reason I ask is to understand if this is bug fix or a cleanup.
> 
> It just a code cleanup only for ca8210.

Thanks for the info. I will wait for Harry's ack and apply it to
wpan-next afterwards.

regards
Stefan Schmidt

^ permalink raw reply

* Re: [PATCH net-next] ieee802154: Use kmemdup instead of duplicating it in ca8210_test_int_driver_write
From: YueHaibing @ 2018-08-09  8:44 UTC (permalink / raw)
  To: Stefan Schmidt, davem, h.morris, alex.aring
  Cc: linux-kernel, netdev, linux-wpan
In-Reply-To: <488f54b7-cfe2-f64b-168e-11f79d4d4e96@datenfreihafen.org>

On 2018/8/9 16:13, Stefan Schmidt wrote:
> Hello.
> 
> On 08/09/2018 08:44 AM, YueHaibing wrote:
>> Replace calls to kmalloc followed by a memcpy with a direct call to
>> kmemdup.
>>
>> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
> 
> Is Yue your forname and Haibing your surname? In that case having it
> written as
> 
> Yue Haibing <yuehaibing@huawei.com>

Well, It should be this, but it's been a long time to use the former

> 
> in the from line as well as in the SOB would be better.
> 
>> ---
>>  drivers/net/ieee802154/ca8210.c | 3 +--
>>  1 file changed, 1 insertion(+), 2 deletions(-)
>>
>> diff --git a/drivers/net/ieee802154/ca8210.c b/drivers/net/ieee802154/ca8210.c
>> index 58299fb..e21279d 100644
>> --- a/drivers/net/ieee802154/ca8210.c
>> +++ b/drivers/net/ieee802154/ca8210.c
>> @@ -634,10 +634,9 @@ static int ca8210_test_int_driver_write(
>>  	for (i = 0; i < len; i++)
>>  		dev_dbg(&priv->spi->dev, "%#03x\n", buf[i]);
>>  
>> -	fifo_buffer = kmalloc(len, GFP_KERNEL);
>> +	fifo_buffer = kmemdup(buf, len, GFP_KERNEL);
>>  	if (!fifo_buffer)
>>  		return -ENOMEM;
>> -	memcpy(fifo_buffer, buf, len);
>>  	kfifo_in(&test->up_fifo, &fifo_buffer, 4);
>>  	wake_up_interruptible(&priv->test.readq);
> 
> Is this some kernel tree wide change you are submitting patches for or
> only for the ca8210 driver? Is there any specific problem you see with
> the kmalloc and memcpy code here? To me it looks fine.
> 
> The reason I ask is to understand if this is bug fix or a cleanup.

It just a code cleanup only for ca8210.

> 
> Harry, if you are ok with this one let me know with an Acked-By
> 
> regards
> Stefan Schmidt
> 
> .
> 

^ permalink raw reply

* Re: [PATCH bpf-next 0/4] Convert filter.txt to RST
From: Alexei Starovoitov @ 2018-08-09  6:07 UTC (permalink / raw)
  To: Tobin C. Harding
  Cc: Daniel Borkmann, Alexei Starovoitov, Jonathan Corbet,
	David S. Miller, Kees Cook, Andy Lutomirski, Will Drewry,
	linux-doc, netdev, linux-kernel
In-Reply-To: <20180809052328.27942-1-me@tobin.cc>

On Thu, Aug 09, 2018 at 03:23:24PM +1000, Tobin C. Harding wrote:
> 
> Daniel and Alexei, can I please have permission to add GPLv2+ to the BPF
> docs?

kernel licensing is GPLv2 without +
every file (including docs) can potentially have a different
compatible license, but since they were developed
implicitly under v2 only you would need to get a buy-in from
all contributors before making such change.

^ permalink raw reply

* Re: [PATCH bpf-next 0/4] Convert filter.txt to RST
From: Daniel Borkmann @ 2018-08-09  8:24 UTC (permalink / raw)
  To: Tobin C. Harding, Alexei Starovoitov
  Cc: Alexei Starovoitov, Jonathan Corbet, David S. Miller, Kees Cook,
	Andy Lutomirski, Will Drewry, linux-doc, netdev, linux-kernel
In-Reply-To: <20180809072753.GF32374@eros>

On 08/09/2018 09:27 AM, Tobin C. Harding wrote:
> On Wed, Aug 08, 2018 at 11:07:35PM -0700, Alexei Starovoitov wrote:
>> On Thu, Aug 09, 2018 at 03:23:24PM +1000, Tobin C. Harding wrote:
>>>
>>> Daniel and Alexei, can I please have permission to add GPLv2+ to the BPF
>>> docs?
>>
>> kernel licensing is GPLv2 without +
> 
> According to process/license-rules.rst
> 
> 	    GPL-2.0+  :  GNU General Public License v2.0 or later

Not really, please see the first three paragraphs of process/license-rules.rst.
The COPYING file of the kernel says that it's 'v2' and not 'v2 or later',
unless otherwise _explicitly_ noted. Given that and given there is no other
specific note in filter.txt, it would mean it's v2-only due to that rule.

>> every file (including docs) can potentially have a different
>> compatible license, but since they were developed
>> implicitly under v2 only you would need to get a buy-in from
>> all contributors before making such change.
> 
> So if a file does not _explicitly_ state that it is under another
> licence it is ok to add GPLv2?
> 
> 
> thanks,
> Tobin.
> 

^ permalink raw reply

* Re: [PATCH net-next] ieee802154: Use kmemdup instead of duplicating it in ca8210_test_int_driver_write
From: Stefan Schmidt @ 2018-08-09  8:13 UTC (permalink / raw)
  To: YueHaibing, davem, h.morris, alex.aring; +Cc: linux-kernel, netdev, linux-wpan
In-Reply-To: <20180809064429.13348-1-yuehaibing@huawei.com>

Hello.

On 08/09/2018 08:44 AM, YueHaibing wrote:
> Replace calls to kmalloc followed by a memcpy with a direct call to
> kmemdup.
> 
> Signed-off-by: YueHaibing <yuehaibing@huawei.com>

Is Yue your forname and Haibing your surname? In that case having it
written as

Yue Haibing <yuehaibing@huawei.com>

in the from line as well as in the SOB would be better.

> ---
>  drivers/net/ieee802154/ca8210.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/net/ieee802154/ca8210.c b/drivers/net/ieee802154/ca8210.c
> index 58299fb..e21279d 100644
> --- a/drivers/net/ieee802154/ca8210.c
> +++ b/drivers/net/ieee802154/ca8210.c
> @@ -634,10 +634,9 @@ static int ca8210_test_int_driver_write(
>  	for (i = 0; i < len; i++)
>  		dev_dbg(&priv->spi->dev, "%#03x\n", buf[i]);
>  
> -	fifo_buffer = kmalloc(len, GFP_KERNEL);
> +	fifo_buffer = kmemdup(buf, len, GFP_KERNEL);
>  	if (!fifo_buffer)
>  		return -ENOMEM;
> -	memcpy(fifo_buffer, buf, len);
>  	kfifo_in(&test->up_fifo, &fifo_buffer, 4);
>  	wake_up_interruptible(&priv->test.readq);

Is this some kernel tree wide change you are submitting patches for or
only for the ca8210 driver? Is there any specific problem you see with
the kmalloc and memcpy code here? To me it looks fine.

The reason I ask is to understand if this is bug fix or a cleanup.

Harry, if you are ok with this one let me know with an Acked-By

regards
Stefan Schmidt

^ permalink raw reply

* [PATCH bpf-next 2/4] docs: Separate and convert filter.txt to RST
From: Tobin C. Harding @ 2018-08-09  5:23 UTC (permalink / raw)
  To: Daniel Borkmann, Alexei Starovoitov
  Cc: Tobin C. Harding, Jonathan Corbet, David S. Miller, Kees Cook,
	Andy Lutomirski, Will Drewry, linux-doc, netdev, linux-kernel
In-Reply-To: <20180809052328.27942-1-me@tobin.cc>

RST is the preferred format for kernel documentation now.  Convert
networking/filter.txt to RST format.  Currently filer.txt contains
documentation on various things related to BPF.  To improve the quality
of the kernel documentation we can split this file up.  Also, BPF is
useful to userspace for applications outside of just networking.

Split filter.txt up into three RST files, all now located under
Documentation/userspace-api/.  After the split there should be no Sphinx
warnings.

Create three new files from the content of filter.txt

 - socket-filter.rst on how to write socket filters
 - cBPF.rst describing classic BPF and its tools
 - eBPF.rst describing extended BPF

Add files to MAINTAINERS.

Do conversion

 - Fix line length (72 character maximum).
 - Use double spaces after a period (full stop).
 - Use RST format directives for code snippets (::).
 - Fix indentation of code snippets.
 - Use correct heading adornments.
 - Add SPDX license comment

Because these three files are related (also seccomp_filter.rst) there
are a number of references to each.  Add an RST reference label to the
top of each file and use it with the relative path (starting at
Documentation) as is typical in kernel docs.  Use a list so as to make
the text file readable as well as the rendered HTML.

Add RST label and SPDX licence comment to seccomp_filter.rst

Signed-off-by: Tobin C. Harding <me@tobin.cc>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Kees Cook <keescook@chromium.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Will Drewry <wad@chromium.org>
---
 Documentation/userspace-api/cBPF.rst          |  432 +++++++
 Documentation/userspace-api/eBPF.rst          | 1007 +++++++++++++++++
 Documentation/userspace-api/index.rst         |    3 +
 .../userspace-api/seccomp_filter.rst          |   11 +
 Documentation/userspace-api/socket_filter.rst |  183 +++
 MAINTAINERS                                   |    4 +-
 6 files changed, 1639 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/userspace-api/cBPF.rst
 create mode 100644 Documentation/userspace-api/eBPF.rst
 create mode 100644 Documentation/userspace-api/socket_filter.rst

diff --git a/Documentation/userspace-api/cBPF.rst b/Documentation/userspace-api/cBPF.rst
new file mode 100644
index 000000000000..9d50c202bb60
--- /dev/null
+++ b/Documentation/userspace-api/cBPF.rst
@@ -0,0 +1,432 @@
+.. SPDX-License-Identifier: GPL-2.0+
+
+.. _cbpf:
+
+====================================
+Classic Berkley Packet Filter (cBPF)
+====================================
+
+For an introduction to BPF and Linux Socket Filtering please see
+:ref:`Documentation/userspace-api/socket-filter.rst <socket-filter>`
+
+Under tools/bpf/ there's a small helper tool called bpf_asm which can be
+used to write low-level filters for example scenarios mentioned in the
+above linked document.  Asm-like syntax mentioned here has been
+implemented in 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 [1].
+
+The BPF architecture consists of the following basic elements:
+
+.. flat-table:: BPF Elements
+
+   * - 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 program, that is translated by bpf_asm into "opcodes" is an array that
+consists of the following elements (as already mentioned)::
+
+  op:16, jt:8, jf:8, k:32
+
+The element op is a 16 bit wide opcode that has a particular instruction
+encoded.  jt and jf are two 8 bit wide jump targets, one for condition
+"jump if true", the other one "jump if false".  Eventually, element k
+contains a miscellaneous argument that can be interpreted in different
+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:
+::
+
+  Instruction      Addressing mode      Description
+
+  ld               1, 2, 3, 4, 10       Load word into A
+  ldi              4                    Load word into A
+  ldh              1, 2                 Load half-word into A
+  ldb              1, 2                 Load byte into A
+  ldx              3, 4, 5, 10          Load word into X
+  ldxi             4                    Load word into X
+  ldxb             5                    Load byte into X
+
+  st               3                    Store A into M[]
+  stx              3                    Store X into M[]
+
+  jmp              6                    Jump to label
+  ja               6                    Jump to label
+  jeq              7, 8                 Jump on A == k
+  jneq             8                    Jump on A != k
+  jne              8                    Jump on A != k
+  jlt              8                    Jump on A <  k
+  jle              8                    Jump on A <= k
+  jgt              7, 8                 Jump on A >  k
+  jge              7, 8                 Jump on A >= k
+  jset             7, 8                 Jump on A &  k
+
+  add              0, 4                 A + <x>
+  sub              0, 4                 A - <x>
+  mul              0, 4                 A * <x>
+  div              0, 4                 A / <x>
+  mod              0, 4                 A % <x>
+  neg                                   !A
+  and              0, 4                 A & <x>
+  or               0, 4                 A | <x>
+  xor              0, 4                 A ^ <x>
+  lsh              0, 4                 A << <x>
+  rsh              0, 4                 A >> <x>
+
+  tax                                   Copy A into X
+  txa                                   Copy X into A
+
+  ret              4, 9                 Return
+
+The next table shows addressing formats from the 2nd column::
+
+  Addressing mode  Syntax               Description
+
+   0               x/%x                 Register X
+   1               [k]                  BHW at byte offset k in the packet
+   2               [x + k]              BHW at the offset X + k in the packet
+   3               M[k]                 Word at offset k in M[]
+   4               #k                   Literal value stored in k
+   5               4*([k]&0xf)          Lower nibble * 4 at byte offset k in the packet
+   6               L                    Jump label L
+   7               #k,Lt,Lf             Jump to Lt if true, otherwise jump to Lf
+   8               #k,Lt                Jump to Lt if predicate is true
+   9               a/%a                 Accumulator A
+  10               extension            BPF extension
+
+The Linux kernel also has a couple of BPF extensions that are used along
+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::
+
+  Extension                             Description
+
+  len                                   skb->len
+  proto                                 skb->protocol
+  type                                  skb->pkt_type
+  poff                                  Payload start offset
+  ifidx                                 skb->dev->ifindex
+  nla                                   Netlink attribute of type X with offset A
+  nlan                                  Nested Netlink attribute of type X with offset A
+  mark                                  skb->mark
+  queue                                 skb->queue_mapping
+  hatype                                skb->dev->type
+  rxhash                                skb->hash
+  cpu                                   raw_smp_processor_id()
+  vlan_tci                              skb_vlan_tag_get(skb)
+  vlan_avail                            skb_vlan_tag_present(skb)
+  vlan_tpid                             skb->vlan_proto
+  rand                                  prandom_u32()
+
+These extensions can also be prefixed with '#'.
+Examples for low-level BPF:
+
+ARP packets::
+
+  ldh [12]
+  jne #0x806, drop
+  ret #-1
+  drop: ret #0
+
+IPv4 TCP packets::
+
+  ldh [12]
+  jne #0x800, drop
+  ldb [23]
+  jneq #6, drop
+  ret #-1
+  drop: ret #0
+
+(Accelerated) VLAN w/ id 10::
+
+  ld vlan_tci
+  jneq #10, drop
+  ret #-1
+  drop: ret #0
+
+icmp random packet sampling, 1 in 4::
+
+  ldh [12]
+  jne #0x800, drop
+  ldb [23]
+  jneq #1, drop
+  # get a random uint32 number
+  ld rand
+  mod #4
+  jneq #1, drop
+  ret #-1
+  drop: ret #0
+
+SECCOMP filter example::
+
+  ld [4]                  /* offsetof(struct seccomp_data, arch) */
+  jne #0xc000003e, bad    /* AUDIT_ARCH_X86_64 */
+  ld [0]                  /* offsetof(struct seccomp_data, nr) */
+  jeq #15, good           /* __NR_rt_sigreturn */
+  jeq #231, good          /* __NR_exit_group */
+  jeq #60, good           /* __NR_exit */
+  jeq #0, good            /* __NR_read */
+  jeq #1, good            /* __NR_write */
+  jeq #5, good            /* __NR_fstat */
+  jeq #9, good            /* __NR_mmap */
+  jeq #14, good           /* __NR_rt_sigprocmask */
+  jeq #13, good           /* __NR_rt_sigaction */
+  jeq #35, good           /* __NR_nanosleep */
+  bad: ret #0             /* SECCOMP_RET_KILL_THREAD */
+  good: ret #0x7fff0000   /* SECCOMP_RET_ALLOW */
+
+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::
+
+  $ ./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::
+
+  $ ./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 attaching to a live system.  For that purpose,
+there's a small tool called 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::
+
+  # ./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
+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
+"~/.bpf_dbg_history".
+
+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.
+
+JIT compiler
+============
+
+The Linux kernel has a built-in BPF JIT compiler for x86_64, SPARC,
+PowerPC, 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::
+
+  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::
+
+  echo 2 > /proc/sys/net/core/bpf_jit_enable
+
+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
+
+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 setting bpf_jit_enable to 2, since dumping the
+final JIT image into the kernel log is discouraged and introspection
+through bpftool (under tools/bpf/bpftool/) is the 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
+
+Issuing option `-o` will "annotate" opcodes to resulting assembler
+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
+	  55
+     1:	  mov    %rsp,%rbp
+	  48 89 e5
+     4:	  sub    $0x60,%rsp
+	  48 83 ec 60
+     8:	  mov    %rbx,-0x8(%rbp)
+	  48 89 5d f8
+     c:	  mov    0x68(%rdi),%r9d
+	  44 8b 4f 68
+    10:	  sub    0x6c(%rdi),%r9d
+	  44 2b 4f 6c
+    14:	  mov    0xd8(%rdi),%r8
+	  4c 8b 87 d8 00 00 00
+    1b:	  mov    $0xc,%esi
+	  be 0c 00 00 00
+    20:	  callq  0xffffffffe0ff9442
+	  e8 1d 94 ff e0
+    25:	  cmp    $0x800,%eax
+	  3d 00 08 00 00
+    2a:	  jne    0x0000000000000042
+	  75 16
+    2c:	  mov    $0x17,%esi
+	  be 17 00 00 00
+    31:	  callq  0xffffffffe0ff945e
+	  e8 28 94 ff e0
+    36:	  cmp    $0x1,%eax
+	  83 f8 01
+    39:	  jne    0x0000000000000042
+	  75 07
+    3b:	  mov    $0xffff,%eax
+	  b8 ff ff 00 00
+    40:	  jmp    0x0000000000000044
+	  eb 02
+    42:	  xor    %eax,%eax
+	  31 c0
+    44:	  leaveq
+	  c9
+    45:	  retq
+	  c3
+
+For BPF JIT developers, bpf_jit_disasm, bpf_asm and bpf_dbg provides a
+useful toolchain for developing and testing the kernel's JIT compiler.
+
+Reference
+=========
+
+The original BPF paper:
+
+[1] Steven McCanne and Van Jacobson. 1993.  The BSD packet filter: a new
+architecture for user-level packet capture.  In Proceedings of the
+USENIX Winter 1993 Conference Proceedings on USENIX Winter 1993
+Conference Proceedings (USENIX'93).  USENIX Association, Berkeley, CA,
+USA, 2-2. [http://www.tcpdump.org/papers/bpf-usenix93.pdf]
diff --git a/Documentation/userspace-api/eBPF.rst b/Documentation/userspace-api/eBPF.rst
new file mode 100644
index 000000000000..39fbe18a38fa
--- /dev/null
+++ b/Documentation/userspace-api/eBPF.rst
@@ -0,0 +1,1007 @@
+.. SPDX-License-Identifier: GPL-2.0+
+
+.. _ebpf:
+
+=====================================
+Internal Berkley Packet Filter (eBPF)
+=====================================
+
+For an introduction to BPF and Linux Socket Filtering please see
+:ref:`Documentation/userspace-api/socket-filter.rst <socket-filter>`
+
+Internally, for the kernel interpreter, a different instruction set format
+with similar underlying principles from BPF described in the document
+linked to above is being used.  However, the instruction set format is
+modelled closer to the underlying architecture to mimic native instruction
+sets, so 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' of BPF_LD | BPF_{B,H,W} | BPF_ABS instruction.)
+
+It is designed to be JITed with one to one mapping, which can also open up
+the possibility for GCC/LLVM compilers to generate optimized eBPF code
+through an eBPF backend that performs almost as fast as natively compiled
+code.
+
+The new instruction set was originally designed with the possible goal in
+mind to write programs in "restricted C" and compile into eBPF with a
+optional GCC/LLVM backend, so that it can just-in-time map to modern 64-bit
+CPUs with minimal performance overhead over two steps, that is, C -> eBPF
+-> native code.
+
+Currently, the new format is being used for running user BPF programs,
+which includes seccomp BPF, classic socket filters, cls_bpf traffic
+classifier, team driver's classifier for its load-balancing mode,
+netfilter's xt_bpf extension, PTP dissector/classifier, and much more.
+
+For more information please see:
+
+- :ref:`Documentation/userspace-api/seccomp_filter.rst <seccomp-filter>`
+- :ref:`Documentation/userspace-api/socket_filter.rst <socket-filter>`
+- :ref:`Documentation/userspace-api/cBPF.rst <ebpf>`
+
+They are all internally converted by the kernel into the new instruction
+set representation and run in the eBPF interpreter.  For in-kernel
+handlers, this all works transparently by using bpf_prog_create() for
+setting up the filter, resp.  bpf_prog_destroy() for destroying it.  The
+macro BPF_PROG_RUN(filter, ctx) transparently invokes eBPF interpreter or
+JITed code to run the filter.  'filter' is a pointer to struct bpf_prog
+that we got from bpf_prog_create(), and 'ctx' the given context (e.g.  skb
+pointer).  All constraints and restrictions from bpf_check_classic() apply
+before a conversion to the new layout is being done behind the scenes!
+
+Currently, the classic BPF format is being used for JITing on most 32-bit
+architectures, whereas x86-64, aarch64, s390x, powerpc64, sparc64, arm32
+perform JIT compilation from eBPF instruction set. (see cBPF document
+linked above.)
+
+Some core changes of the new internal format
+--------------------------------------------
+
+Number of registers increase from 2 to 10
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The old format had two registers A and X, and a hidden frame pointer.
+The new layout extends this to be 10 internal registers and a read-only
+frame pointer.  Since 64-bit CPUs are passing arguments to functions via
+registers the number of args from eBPF program to in-kernel function is
+restricted to 5 and one register is used to accept return value from an
+in-kernel function.  Natively, x86_64 passes first 6 arguments in
+registers, aarch64/ sparcv9/mips64 have 7 - 8 registers for arguments;
+x86_64 has 6 callee saved registers, and aarch64/sparcv9/mips64 have 11
+or more callee saved registers.
+
+.. flat-table:: eBPF Calling Convention
+   :widths: 1 2
+
+   * - Register
+     - Convention
+
+   * - R0
+     - return value from in-kernel function, and exit value for eBPF
+       program
+
+   * - R1 - R5
+     - arguments from eBPF program to in-kernel function
+
+   * - R6 - R9
+     - callee saved registers that in-kernel function will preserve
+
+   * - R10
+     - read-only frame pointer to access stack
+
+Thus, all eBPF registers map one to one to HW registers on x86_64,
+aarch64, etc, and eBPF calling convention maps directly to ABIs used by
+the kernel on 64-bit architectures.
+
+On 32-bit architectures JIT may map programs that use only 32-bit
+arithmetic and may let more complex programs to be interpreted.
+
+R0 - R5 are scratch registers and eBPF program needs spill/fill them if
+necessary across calls.  Note that there is only one eBPF program (==
+one eBPF main routine) and it cannot call other eBPF functions, it can
+only call predefined in-kernel functions, though.
+
+Register width increases from 32-bit to 64-bit
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Still, the semantics of the original 32-bit ALU operations are preserved
+via 32-bit subregisters.  All eBPF registers are 64-bit with 32-bit
+lower subregisters that zero-extend into 64-bit if they are being
+written to.  That behavior maps directly to x86_64 and arm64 subregister
+definition, but makes other JITs more difficult.
+
+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 be interpreted.
+
+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.
+
+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 */".
+
+Zero overhead calls from/to other kernel functions
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Introduces bpf_call insn and register passing convention for zero
+overhead calls from/to other kernel functions.
+
+Before an in-kernel function call, the internal BPF program needs to
+place function arguments into R1 to R5 registers to satisfy calling
+convention, then the interpreter will take them from registers and pass
+to in-kernel function.  If R1 - R5 registers are mapped to CPU registers
+that are used for argument passing on given architecture, the JIT
+compiler doesn't need to emit extra moves.  Function arguments will be
+in the correct registers and BPF_CALL instruction will be JITed as
+single 'call' HW instruction.  This calling convention was picked to
+cover common call situations without performance penalty.
+
+After an in-kernel function call, R1 - R5 are reset to unreadable and R0
+has 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::
+
+  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::
+
+  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::
+
+  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 be used to call into f2.
+
+For practical reasons all eBPF programs have only one argument 'ctx'
+which is already placed into R1 (e.g. on __bpf_prog_run() startup) and
+the programs can call kernel functions with up to 5 arguments.  Calls
+with 6 or more arguments are currently not supported, but these
+restrictions can be lifted if necessary in the future.
+
+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
+  R1 - rdi
+  R2 - rsi
+  R3 - rdx
+  R4 - rcx
+  R5 - r8
+  R6 - rbx
+  R7 - r13
+  R8 - r14
+  R9 - r15
+  R10 - rbp
+
+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::
+
+  bpf_mov R6, R1 /* save ctx */
+  bpf_mov R2, 2
+  bpf_mov R3, 3
+  bpf_mov R4, 4
+  bpf_mov R5, 5
+  bpf_call foo
+  bpf_mov R7, R0 /* save foo() return value */
+  bpf_mov R1, R6 /* restore ctx for next call */
+  bpf_mov R2, 6
+  bpf_mov R3, 7
+  bpf_mov R4, 8
+  bpf_mov R5, 9
+  bpf_call bar
+  bpf_add R0, R7
+  bpf_exit
+
+After JIT to x86_64 may look like::
+
+  push %rbp
+  mov %rsp,%rbp
+  sub $0x228,%rsp
+  mov %rbx,-0x228(%rbp)
+  mov %r13,-0x220(%rbp)
+  mov %rdi,%rbx
+  mov $0x2,%esi
+  mov $0x3,%edx
+  mov $0x4,%ecx
+  mov $0x5,%r8d
+  callq foo
+  mov %rax,%r13
+  mov %rbx,%rdi
+  mov $0x2,%esi
+  mov $0x3,%edx
+  mov $0x4,%ecx
+  mov $0x5,%r8d
+  callq bar
+  add %r13,%rax
+  mov -0x228(%rbp),%rbx
+  mov -0x220(%rbp),%r13
+  leaveq
+  retq
+
+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);
+  }
+
+In-kernel functions foo() and bar() with prototype: u64 (*)(u64 arg1,
+u64 arg2, u64 arg3, u64 arg4, u64 arg5); will receive arguments in
+proper registers and place their return value into '%rax' which is R0 in
+eBPF.  Prologue and epilogue are emitted by JIT and are implicit in the
+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::
+
+  bpf_mov R1, 1
+  bpf_call foo
+  bpf_mov R0, R1
+  bpf_exit
+
+After the call the registers R1-R5 contain junk values and cannot be
+read.  An in-kernel eBPF verifier is used to validate internal BPF
+programs.
+
+Additional miscellaneous changes
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Also in the new design, eBPF is limited to 4096 insns, which means that
+any program will terminate quickly and will only call a fixed number of
+kernel functions.  Original BPF and the new format are two operand
+instructions, which helps to do one-to-one mapping between eBPF insn and
+x86 insn during JIT.
+
+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::
+
+  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 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.  For example, socket filters are not using 'exclusive
+add' instruction, but tracing filters may do to maintain counters of
+events, for example.  Register R9 is not used by socket filters either,
+but more complex filters may be running 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 may not be bounded by security considerations, since
+generated internal BPF code 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 can be determined in two steps: first step does
+depth-first-search to disallow loops and other CFG validation; second
+step starts from the first insn and descends all possible paths.  It
+simulates execution of every insn and observes the state change of
+registers and stack.
+
+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::
+
+  +----------------+--------+--------------------+
+  |   4 bits       |  1 bit |   3 bits           |
+  | operation code | source | instruction class  |
+  +----------------+--------+--------------------+
+  (MSB)                                      (LSB)
+
+Three LSB bits store instruction class which is one of::
+
+  Classic BPF classes:    eBPF classes:
+
+  BPF_LD    0x00          BPF_LD    0x00
+  BPF_LDX   0x01          BPF_LDX   0x01
+  BPF_ST    0x02          BPF_ST    0x02
+  BPF_STX   0x03          BPF_STX   0x03
+  BPF_ALU   0x04          BPF_ALU   0x04
+  BPF_JMP   0x05          BPF_JMP   0x05
+  BPF_RET   0x06          [ class 6 unused, for future if needed ]
+  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::
+
+  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::
+
+  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::
+
+  BPF_ADD   0x00
+  BPF_SUB   0x10
+  BPF_MUL   0x20
+  BPF_DIV   0x30
+  BPF_OR    0x40
+  BPF_AND   0x50
+  BPF_LSH   0x60
+  BPF_RSH   0x70
+  BPF_NEG   0x80
+  BPF_MOD   0x90
+  BPF_XOR   0xa0
+  BPF_MOV   0xb0  /* eBPF only: mov reg to reg */
+  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::
+
+  BPF_JA    0x00
+  BPF_JEQ   0x10
+  BPF_JGT   0x20
+  BPF_JGE   0x30
+  BPF_JSET  0x40
+  BPF_JNE   0x50  /* eBPF only: jump != */
+  BPF_JSGT  0x60  /* eBPF only: signed '>' */
+  BPF_JSGE  0x70  /* eBPF only: signed '>=' */
+  BPF_CALL  0x80  /* eBPF only: function call */
+  BPF_EXIT  0x90  /* eBPF only: function return */
+  BPF_JLT   0xa0  /* eBPF only: unsigned '<' */
+  BPF_JLE   0xb0  /* eBPF only: unsigned '<=' */
+  BPF_JSLT  0xc0  /* eBPF only: signed '<' */
+  BPF_JSLE  0xd0  /* eBPF only: signed '<=' */
+
+So BPF_ADD | BPF_X | BPF_ALU means 32-bit addition in both classic BPF
+and eBPF.  There are only two registers in classic BPF, so it means A
++= X.  In eBPF it means dst_reg = (u32) dst_reg + (u32) src_reg;
+similarly, BPF_XOR | BPF_K | BPF_ALU means A ^= imm32 in classic BPF and
+analogous src_reg = (u32) src_reg ^ (u32) imm32 in eBPF.
+
+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.
+dst_reg = dst_reg + src_reg
+
+Classic BPF wastes the whole BPF_RET class to represent a single 'ret'
+operation.  Classic BPF_RET | BPF_K means copy imm32 into return
+register and perform function exit.  eBPF is modeled to match CPU, so
+BPF_JMP | BPF_EXIT 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::
+
+  +--------+--------+-------------------+
+  | 3 bits | 2 bits |   3 bits          |
+  |  mode  |  size  | instruction class |
+  +--------+--------+-------------------+
+  (MSB)                             (LSB)
+
+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::
+
+  B  - 1 byte
+  H  - 2 byte
+  W  - 4 byte
+  DW - 8 byte (eBPF only)
+
+Mode modifier is one of::
+
+  BPF_IMM  0x00  /* used for 32-bit mov in classic BPF and 64-bit in eBPF */
+  BPF_ABS  0x20
+  BPF_IND  0x40
+  BPF_MEM  0x60
+  BPF_LEN  0x80  /* classic BPF only, reserved in eBPF */
+  BPF_MSH  0xa0  /* classic BPF only, reserved in eBPF */
+  BPF_XADD 0xc0  /* eBPF only, exclusive add */
+
+eBPF has two non-generic instructions: (BPF_ABS | <size> | BPF_LD) and
+(BPF_IND | <size> | BPF_LD) which are used to access packet data.
+
+They had to be carried over from classic to have strong performance of
+socket filters running in eBPF interpreter.  These instructions can only
+be used when interpreter context is a pointer to 'struct sk_buff' and
+have seven implicit operands.  Register R6 is an implicit input that
+must contain pointer to sk_buff.  Register R0 is an implicit output
+which contains the data fetched from the packet.  Registers R1-R5 are
+scratch registers and must not be used to store the data across BPF_ABS
+| BPF_LD or BPF_IND | BPF_LD instructions.
+
+These instructions have implicit program exit condition as well.  When
+eBPF program is trying to access the data beyond the packet boundary,
+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::
+
+  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::
+
+  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.
+
+eBPF has one 16-byte instruction: BPF_LD | BPF_DW | BPF_IMM which
+consists of two consecutive 'struct bpf_insn' 8-byte blocks and is
+interpreted as 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.
+
+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).
+
+Second step starts from the first insn and descends all possible paths.
+It simulates execution of every insn and observes the state change of
+registers and stack.
+
+At the start of the program the register R1 contains a pointer to context
+and has type PTR_TO_CTX.
+
+If verifier sees an insn that does R2=R1, then R2 has now type
+PTR_TO_CTX as well and can be used on the right hand side of expression.
+
+If R1=PTR_TO_CTX and insn is R2=R1+R1, then R2=SCALAR_VALUE, 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::
+
+  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.::
+
+  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::
+
+ 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.
+
+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::
+
+  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 the
+verifier will reject the program.
+
+If R6=PTR_TO_STACK, then access should be aligned and be within stack
+bounds, which are [-MAX_BPF_STACK, 0).  In this example offset is 8, 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::
+
+  bpf_ld R0 = *(u32 *)(R10 - 4)
+  bpf_exit
+
+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.
+
+Pointer register spill/fill is tracked as well, since four (R6-R9)
+callee saved registers may not be enough for some programs.
+
+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 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 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 by seccomp verifier.  In case of eBPF one
+configurable verifier is shared for all use cases.
+
+See details of eBPF verifier in kernel/bpf/verifier.c
+
+Register value tracking
+=======================
+
+In order to determine the safety of an eBPF program, the verifier must
+track the range of possible values in each register and also in each
+stack slot.  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::
+
+    PTR_TO_CTX          Pointer to bpf_context.
+    CONST_PTR_TO_MAP    Pointer to struct bpf_map.  "Const" because arithmetic
+                        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.
+    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 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 three
+things 1) minimum and maximum values as unsigned. 2) minimum and maximum
+values as signed. 3) 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.
+
+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 it will have a umin_value (unsigned minimum value)
+of 9, whereas in the 'false' branch it will have a umax_value of 8.  A
+signed compare (with BPF_JSGT or BPF_JSGE) would instead update the
+signed minimum/maximum values.  Information from the signed and unsigned
+bounds can be combined; for instance if a value is first tested < 8 and
+then tested s> 4, the verifier will conclude that the value is also > 4
+and s< 8, since the bounds prevent crossing the sign boundary.
+
+PTR_TO_PACKETs with a variable offset part have an 'id', which is common
+to all pointers sharing that same variable offset.  This is important
+for packet range checks: after adding a variable to a packet pointer
+register A, if you then copy it to another register B and then add a
+constant 4 to A, both registers will share the same 'id' but the A will
+have a fixed offset of +4.  Then if A is bounds-checked and found to be
+less than a PTR_TO_PACKET_END, the register B is now known to have a
+safe range of at least 4 bytes.  See 'Direct packet access', below, for
+more on PTR_TO_PACKET ranges.
+
+The 'id' field is also used on PTR_TO_MAP_VALUE_OR_NULL, common to all
+copies of the pointer returned from a map lookup.  This means that when
+one copy is 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 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.
+
+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, e.g.::
+
+  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 means that in the fall-through case the register R3 (which points
+to skb->data) has at least 14 directly accessible bytes.  The verifier
+marks it as R3=pkt(id=0,off=0,r=14).  id=0 means that no additional
+variables were added to the register.  off=0 means that no additional
+constants were added.  r=14 is the range of safe access which means that
+bytes [R3, R3 + 14) are ok.  Note that R5 is marked as
+R5=pkt(id=0,off=14,r=14).  It also points 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)
+
+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 'if (r3 + 8 > r1) goto
+err' at insn #18, the safe range is [R3, R3 + 8).  The verifier only
+allows 'add'/'sub' operations on packet registers.  Any other operation
+will set the register state to 'SCALAR_VALUE' and it won't be available
+for direct packet access.  Operation 'r3 += rX' may overflow and become
+less than original skb->data, therefore the verifier has to prevent
+that.  So when it sees 'r3 += rX' instruction and rX is more than 16-bit
+value, any subsequent bounds-check of r3 against skb->data_end will not
+give us 'range' information, so attempts to read through the pointer
+will give "invalid access to packet" error.  Ex. after insn 'r4 = *(u8
+*)(r3 +12)' (insn #7 above) the state of r4 is
+R4=inv(id=0,umax_value=255,var_off=(0x0; 0xff)) which means that upper
+56 bits of the register are guaranteed to be zero, and nothing is known
+about the lower 8 bits.  After insn 'r4 *= 14' the state becomes
+R4=inv(id=0,umax_value=3570,var_off=(0x0; 0xfffe)), since multiplying an
+8-bit value by constant 14 will keep upper 52 bits as zero, also the
+least significant bit will be zero as 14 is even.  Similarly 'r2 >>= 48'
+will make R2=inv(id=0,umax_value=65535,var_off=(0x0; 0xffff)), since the
+shift is not sign extending.  This logic is implemented in
+adjust_reg_min_max_vals() function, 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::
+
+  void *data = (void *)(long)skb->data;
+  void *data_end = (void *)(long)skb->data_end;
+  struct eth_hdr *eth = data;
+  struct iphdr *iph = data + sizeof(*eth);
+  struct udphdr *udp = data + sizeof(*eth) + sizeof(*iph);
+
+  if (data + sizeof(*eth) + sizeof(*iph) + sizeof(*udp) > data_end)
+          return 0;
+  if (eth->h_proto != htons(ETH_P_IP))
+          return 0;
+  if (iph->protocol != IPPROTO_UDP || iph->ihl != 5)
+          return 0;
+  if (udp->dest == 53 || udp->source == 9)
+          ...;
+
+which makes such programs easier to write comparing to LD_ABS insn
+and significantly faster.
+
+eBPF maps
+=========
+
+'maps' is a generic storage of different types for sharing data between
+kernel 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
+    returns process-local file descriptor or negative error
+
+- lookup key in a given map::
+
+    err = bpf(BPF_MAP_LOOKUP_ELEM, union bpf_attr *attr, u32 size)
+    using attr->map_fd, attr->key, attr->value
+    returns zero and stores found elem into value or negative error
+
+- create or update key/value pair in a given map::
+
+    err = bpf(BPF_MAP_UPDATE_ELEM, union bpf_attr *attr, u32 size)
+    using attr->map_fd, attr->key, attr->value
+    returns zero or negative error
+
+- find and delete element by key in a given map::
+
+    err = bpf(BPF_MAP_DELETE_ELEM, union bpf_attr *attr, u32 size)
+    using attr->map_fd, attr->key
+
+- to delete map::
+
+    close(fd)
+    Exiting process will delete maps automatically
+
+userspace programs use this syscall to create/access maps that eBPF
+programs 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
+
+Pruning
+=======
+
+The verifier does not actually walk all possible paths through the
+program.  For each new branch to analyse, the verifier looks at all the
+states it's previously been in when at this instruction.  If any of them
+contain the current state as a subset, the branch is 'pruned' - that is,
+the fact that the previous state was accepted implies the current state
+would be as well.  For instance, if in the previous state, r1 held a
+packet-pointer, and in the current state, r1 holds a packet-pointer with
+a range as long or longer and at least as strict an alignment, then r1
+is safe.  Similarly, if r2 was NOT_INIT before then it can't have been
+used by any path from that point, so any value in r2 (including another
+NOT_INIT) is safe.  The implementation is in the function regsafe().
+Pruning considers not only the registers but also the stack (and any
+spilled registers it may hold).  They must all be safe for the branch to
+be pruned.  This is implemented in states_equal().
+
+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 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::
+
+  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::
+
+  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::
+
+  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::
+
+  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
+
+Program that doesn't check return value of map_lookup_elem() before
+accessing 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),
+  BPF_LD_MAP_FD(BPF_REG_1, 0),
+  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'
+
+Program that correctly checks map_lookup_elem() returned value for NULL,
+but 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),
+  BPF_LD_MAP_FD(BPF_REG_1, 0),
+  BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_map_lookup_elem),
+  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
+
+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::
+
+  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_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 2),
+  BPF_ST_MEM(BPF_DW, BPF_REG_0, 0, 0),
+  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'
diff --git a/Documentation/userspace-api/index.rst b/Documentation/userspace-api/index.rst
index a3233da7fa88..5e389aaf177c 100644
--- a/Documentation/userspace-api/index.rst
+++ b/Documentation/userspace-api/index.rst
@@ -18,8 +18,11 @@ place where this information is gathered.
 
    no_new_privs
    seccomp_filter
+   socket_filter
    unshare
    spec_ctrl
+   cBPF
+   eBPF
 
 .. only::  subproject and html
 
diff --git a/Documentation/userspace-api/seccomp_filter.rst b/Documentation/userspace-api/seccomp_filter.rst
index 82a468bc7560..7c057115299b 100644
--- a/Documentation/userspace-api/seccomp_filter.rst
+++ b/Documentation/userspace-api/seccomp_filter.rst
@@ -1,3 +1,7 @@
+.. SPDX-License-Identifier: GPL-2.0+
+
+.. _seccomp-filter:
+
 ===========================================
 Seccomp BPF (SECure COMPuting with filters)
 ===========================================
@@ -40,6 +44,13 @@ path (avoiding pathological sizes or selecting which of the multiplexed
 system calls in socketcall() is allowed, for instance) which could be
 construed, incorrectly, as a more complete sandboxing solution.
 
+For more information on BPF please see:
+
+- Linux Socket Filters -
+  :ref:`Documentation/userspace-api/socket_filter.rst <socket-filter>`
+- Classic BPF (cBPF) - :ref:`Documentation/userspace-api/cBPF.rst <cbpf>`
+- Internal BPF (eBPF) - :ref:`Documentation/userspace-api/eBPF.rst <ebpf>`
+
 Usage
 =====
 
diff --git a/Documentation/userspace-api/socket_filter.rst b/Documentation/userspace-api/socket_filter.rst
new file mode 100644
index 000000000000..3f20eb5809c6
--- /dev/null
+++ b/Documentation/userspace-api/socket_filter.rst
@@ -0,0 +1,183 @@
+.. SPDX-License-Identifier: GPL-2.0+
+
+.. _socket-filter:
+
+======================
+Linux Socket Filtering
+======================
+
+Linux Socket Filtering (LSF) is derived from the Berkeley Packet
+Filter.
+
+Introduction
+============
+
+Though there are some distinct differences between the BSD and Linux
+kernel socket 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
+allow or disallow certain types of data to come through the socket.  LSF
+follows exactly the same filter code structure as BSD's BPF, so
+referring to the BSD bpf.4 manpage is very helpful in creating filters.
+
+On Linux, BPF is much simpler than on BSD.  One does not have to worry
+about devices or anything like that.  You simply create your filter
+code, send it to the kernel via the SO_ATTACH_FILTER option and if your
+filter code passes the kernel check on it, you then immediately begin
+filtering data on that socket.
+
+You can also detach filters from your socket via the SO_DETACH_FILTER
+option.  This will probably not be used much since when you close a
+socket that has a filter on it the filter is automagically removed.  The
+other less common case may be adding a different filter on the same
+socket where you had another filter that is still running: the kernel
+takes care of 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 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.
+
+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 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), and lots of
+other places such as team driver, PTP code, etc. where BPF is being used.
+
+For more information please see the following documents:
+
+- Classic BPF (cBPF) - :ref:`Documentation/userspace-api/cBPF.rst <cbpf>`
+- Internal BPF (eBPF) - :ref:`Documentation/userspace-api/eBPF.rst <ebpf>`
+- SECCOMP BPF -
+  :ref:`Documentation/userspace-api/seccomp_filter.rst <seccomp-filter>`
+
+And the original BPF paper:
+
+Steven McCanne and Van Jacobson. 1993.  The BSD packet filter: a new
+architecture for user-level packet capture.  In Proceedings of the
+USENIX Winter 1993 Conference Proceedings on USENIX Winter 1993
+Conference Proceedings (USENIX'93).  USENIX Association, Berkeley,
+CA, USA, 2-2. [http://www.tcpdump.org/papers/bpf-usenix93.pdf]
+
+Structure
+=========
+
+User space applications include <linux/filter.h> which contains the
+following relevant structures::
+
+  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. */
+	  unsigned short len;   /* Number of filter blocks. */
+	  struct sock_filter __user *filter;
+  };
+
+For socket filtering, a pointer to this structure (as shown in the
+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>
+  /* ... */
+
+  /* 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 },
+	  { 0x15,  2,  0, 0x00000084 },
+	  { 0x15,  1,  0, 0x00000006 },
+	  { 0x15,  0, 17, 0x00000011 },
+	  { 0x28,  0,  0, 0x00000036 },
+	  { 0x15, 14,  0, 0x00000016 },
+	  { 0x28,  0,  0, 0x00000038 },
+	  { 0x15, 12, 13, 0x00000016 },
+	  { 0x15,  0, 12, 0x00000800 },
+	  { 0x30,  0,  0, 0x00000017 },
+	  { 0x15,  2,  0, 0x00000084 },
+	  { 0x15,  1,  0, 0x00000006 },
+	  { 0x15,  0,  8, 0x00000011 },
+	  { 0x28,  0,  0, 0x00000014 },
+	  { 0x45,  6,  0, 0x00001fff },
+	  { 0xb1,  0,  0, 0x0000000e },
+	  { 0x48,  0,  0, 0x0000000e },
+	  { 0x15,  2,  0, 0x00000016 },
+	  { 0x48,  0,  0, 0x00000010 },
+	  { 0x15,  0,  1, 0x00000016 },
+	  { 0x06,  0,  0, 0x0000ffff },
+	  { 0x06,  0,  0, 0x00000000 },
+  };
+
+  struct sock_fprog bpf = {
+	  .len = ARRAY_SIZE(code),
+	  .filter = code,
+  };
+
+  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)
+	  /* ... bail out ... */
+
+  /* ... */
+  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
+be dropped for this socket.
+
+The setsockopt(2) call to SO_DETACH_FILTER doesn't need any arguments
+and SO_LOCK_FILTER for preventing the filter to be detached, takes an
+integer value with 0 or 1.
+
+Note that socket filters are not restricted to PF_PACKET sockets only,
+but can also be used on other socket families.
+
+Summary of system calls::
+
+  setsockopt(sockfd, SOL_SOCKET, SO_ATTACH_FILTER, &val, sizeof(val));
+  setsockopt(sockfd, SOL_SOCKET, SO_DETACH_FILTER, &val, sizeof(val));
+  setsockopt(sockfd, SOL_SOCKET, SO_LOCK_FILTER,   &val, sizeof(val));
+
+Normally, most use cases for socket filtering on packet sockets will be
+covered by libpcap in high-level syntax, so as an application developer
+you should stick to that.  libpcap wraps its own layer around all that.
+
+Unless i) using/linking to libpcap is not an option, ii) the required
+BPF filters use Linux extensions that are not supported by libpcap's
+compiler, iii) a filter might be more complex and not cleanly
+implementable with libpcap's compiler, or iv) particular filter codes
+should be optimized differently than libpcap's internal compiler does;
+then in such cases writing such a filter "by hand" can be of an
+alternative.  For example, xt_bpf and cls_bpf users might have
+requirements that could result in more complex filter code, or one that
+cannot be expressed with libpcap (e.g. different return codes for
+various code paths).  Moreover, BPF JIT implementors may wish to
+manually write test cases and thus need low-level access to BPF code as
+well.
+
diff --git a/MAINTAINERS b/MAINTAINERS
index 82f277462349..1611f9f6607f 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2746,8 +2746,10 @@ T:	git git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git
 Q:	https://patchwork.ozlabs.org/project/netdev/list/?delegate=77147
 S:	Supported
 F:	arch/x86/net/bpf_jit*
-F:	Documentation/networking/filter.txt
 F:	Documentation/bpf/
+F:	Documentation/userspace-api/socket_filter.rst
+F:	Documentation/userspace-api/eBPF.rst
+F:	Documentation/userspace-api/cBPF.rst
 F:	include/linux/bpf*
 F:	include/linux/filter.h
 F:	include/trace/events/xdp.h
-- 
2.17.1

^ permalink raw reply related

* Re: [PATCH bpf-next 0/4] Convert filter.txt to RST
From: Tobin C. Harding @ 2018-08-09  7:27 UTC (permalink / raw)
  To: Alexei Starovoitov
  Cc: Daniel Borkmann, Alexei Starovoitov, Jonathan Corbet,
	David S. Miller, Kees Cook, Andy Lutomirski, Will Drewry,
	linux-doc, netdev, linux-kernel
In-Reply-To: <20180809060734.rtqqu4sexbwzuqmm@ast-mbp>

On Wed, Aug 08, 2018 at 11:07:35PM -0700, Alexei Starovoitov wrote:
> On Thu, Aug 09, 2018 at 03:23:24PM +1000, Tobin C. Harding wrote:
> > 
> > Daniel and Alexei, can I please have permission to add GPLv2+ to the BPF
> > docs?
> 
> kernel licensing is GPLv2 without +

According to process/license-rules.rst

	    GPL-2.0+  :  GNU General Public License v2.0 or later

> every file (including docs) can potentially have a different
> compatible license, but since they were developed
> implicitly under v2 only you would need to get a buy-in from
> all contributors before making such change.

So if a file does not _explicitly_ state that it is under another
licence it is ok to add GPLv2?


thanks,
Tobin.

^ permalink raw reply


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox