ice: add PFCP filter support
Subsystems (28)
v6 cover ice: add PFCP filter support
Add support for creating PFCP filters in switchdev mode. Add pfcp module that allows to create a PFCP-type netdev. The netdev then can be passed to tc when creating a filter to indicate that PFCP filter should be created.
To add a PFCP filter, a special netdev must be created and passed to tc command:
ip link add pfcp0 type pfcp
tc filter add dev eth0 ingress prio 1 flower pfcp_opts \
1:12ab/ff:fffffffffffffff0 skip_hw action mirred egress redirect \
dev pfcp0Changes in iproute2 [1] are required to use pfcp_opts in tc.
ICE COMMS package is required as it contains PFCP profiles.
Part of this patchset modifies IP_TUNNEL_*_OPTs, which were previously stored in a __be16. All possible values have already been used, making it impossible to add new ones.
* 1-3: add new bitmap_{read,write}(), which is used later in the IP
tunnel flags code (from Alexander's ARM64 MTE series[2]);
* 4-14: some bitmap code preparations also used later in IP tunnels;
* 15-17: convert IP tunnel flags from __be16 to a bitmap;
* 18-21: add PFCP module and support for it in ice.
[1] https://lore.kernel.org/netdev/[email protected]
[2] https://lore.kernel.org/linux-kernel/[email protected]
Alexander Lobakin (14):
bitops: add missing prototype check
bitops: make BYTES_TO_BITS() treewide-available
bitops: let the compiler optimize {__,}assign_bit()
linkmode: convert linkmode_{test,set,clear,mod}_bit() to macros s390/cio: rename bitmap_size() -> idset_bitmap_size() fs/ntfs3: add prefix to bitmap_size() and use BITS_TO_U64()
btrfs: rename bitmap_set_bits() -> btrfs_bitmap_set_bits()
tools: move alignment-related macros to new <linux/align.h>
bitmap: introduce generic optimized bitmap_size()
bitmap: make bitmap_{get,set}_value8() use bitmap_{read,write}() lib/bitmap: add compile-time test for __assign_bit() optimization
ip_tunnel: use a separate struct to store tunnel params in the kernel
ip_tunnel: convert __be16 tunnel flags to bitmaps
net: net_test: add tests for IP tunnel flags conversion helpers
Alexander Potapenko (2):
lib/test_bitmap: add tests for bitmap_{read,write}() lib/test_bitmap: use pr_info() for non-error messages
Marcin Szycik (2):
ice: refactor ICE_TC_FLWR_FIELD_ENC_OPTS
ice: Add support for PFCP hardware offload in switchdev
Michal Swiatkowski (1):
pfcp: always set pfcp metadata
Syed Nayyar Waris (1):
lib/bitmap: add bitmap_{read,write}()
Wojciech Drewek (1):
pfcp: add PFCP module
drivers/net/Kconfig | 13 +
drivers/net/Makefile | 1 +
net/core/Makefile | 2 +-
.../net/ethernet/intel/ice/ice_flex_type.h | 4 +-
.../ethernet/intel/ice/ice_protocol_type.h | 12 +
drivers/net/ethernet/intel/ice/ice_switch.h | 2 +
drivers/net/ethernet/intel/ice/ice_tc_lib.h | 8 +-
.../ethernet/mellanox/mlx5/core/en/tc_tun.h | 2 +-
.../ethernet/mellanox/mlxsw/spectrum_ipip.h | 2 +-
fs/ntfs3/ntfs_fs.h | 4 +-
include/linux/bitmap.h | 95 ++++--
include/linux/bitops.h | 23 +-
include/linux/cpumask.h | 2 +-
include/linux/linkmode.h | 27 +-
include/linux/netdevice.h | 7 +-
include/net/dst_metadata.h | 10 +-
include/net/flow_dissector.h | 2 +-
include/net/gre.h | 70 ++--
include/net/ip6_tunnel.h | 4 +-
include/net/ip_tunnels.h | 139 ++++++--
include/net/pfcp.h | 90 ++++++
include/net/udp_tunnel.h | 4 +-
include/uapi/linux/if_tunnel.h | 36 +++
include/uapi/linux/pkt_cls.h | 14 +
tools/include/linux/align.h | 12 +
tools/include/linux/bitmap.h | 9 +-
tools/include/linux/bitops.h | 2 +
tools/include/linux/mm.h | 5 +-
drivers/md/dm-clone-metadata.c | 5 -
drivers/net/bareudp.c | 19 +-
drivers/net/ethernet/intel/ice/ice_ddp.c | 9 +
drivers/net/ethernet/intel/ice/ice_switch.c | 85 +++++
drivers/net/ethernet/intel/ice/ice_tc_lib.c | 68 +++-
.../mellanox/mlx5/core/en/tc_tun_encap.c | 6 +-
.../mellanox/mlx5/core/en/tc_tun_geneve.c | 12 +-
.../mellanox/mlx5/core/en/tc_tun_gre.c | 8 +-
.../mellanox/mlx5/core/en/tc_tun_vxlan.c | 9 +-
.../net/ethernet/mellanox/mlx5/core/en_tc.c | 16 +-
.../ethernet/mellanox/mlxsw/spectrum_ipip.c | 56 ++--
.../ethernet/mellanox/mlxsw/spectrum_span.c | 10 +-
.../ethernet/netronome/nfp/flower/action.c | 27 +-
drivers/net/geneve.c | 44 ++-
drivers/net/pfcp.c | 302 ++++++++++++++++++
drivers/net/vxlan/vxlan_core.c | 14 +-
drivers/s390/cio/idset.c | 12 +-
fs/btrfs/free-space-cache.c | 8 +-
fs/ntfs3/bitmap.c | 4 +-
fs/ntfs3/fsntfs.c | 2 +-
fs/ntfs3/index.c | 11 +-
fs/ntfs3/super.c | 2 +-
kernel/trace/trace_probe.c | 2 -
lib/math/prime_numbers.c | 2 -
lib/test_bitmap.c | 203 ++++++++++--
net/bridge/br_vlan_tunnel.c | 9 +-
net/core/filter.c | 26 +-
net/core/flow_dissector.c | 20 +-
net/core/{gso_test.c => net_test.c} | 129 +++++++-
net/ipv4/fou_bpf.c | 2 +-
net/ipv4/gre_demux.c | 2 +-
net/ipv4/ip_gre.c | 144 +++++----
net/ipv4/ip_tunnel.c | 109 +++++--
net/ipv4/ip_tunnel_core.c | 82 +++--
net/ipv4/ip_vti.c | 41 ++-
net/ipv4/ipip.c | 33 +-
net/ipv4/ipmr.c | 2 +-
net/ipv4/udp_tunnel_core.c | 5 +-
net/ipv6/addrconf.c | 3 +-
net/ipv6/ip6_gre.c | 85 ++---
net/ipv6/ip6_tunnel.c | 14 +-
net/ipv6/sit.c | 38 ++-
net/netfilter/ipvs/ip_vs_core.c | 6 +-
net/netfilter/ipvs/ip_vs_xmit.c | 20 +-
net/netfilter/nft_tunnel.c | 44 +--
net/openvswitch/flow_netlink.c | 61 ++--
net/psample/psample.c | 26 +-
net/sched/act_tunnel_key.c | 36 +--
net/sched/cls_flower.c | 134 +++++++-
tools/perf/util/probe-finder.c | 4 +-
78 files changed, 1988 insertions(+), 624 deletions(-)
create mode 100644 include/net/pfcp.h
create mode 100644 tools/include/linux/align.h
create mode 100644 drivers/net/pfcp.c
rename net/core/{gso_test.c => net_test.c} (67%)---
From v5[3]:
* 6.9-rc1;
* move IP tunnel flags KUnit test from the bitmap test suite to the networking KUnit (CONFIG_NET_TEST) (Yury);
* pick tags (Yury, Peter); now the entire series is fully tagged (except the above tests);
* no functional changes besides the tests.
From v4[4]:
* rebase on top of 6.8-rc1;
* collect all the dependencies together in one series (did I get it right? :s);
* no functional changes.
[3] https://lore.kernel.org/netdev/[email protected]
[4] https://lore.kernel.org/netdev/[email protected]
v3: https://lore.kernel.org/intel-wired-lan/[email protected]
v2: https://lore.kernel.org/intel-wired-lan/[email protected]
v1: https://lore.kernel.org/intel-wired-lan/[email protected]
Signature · 1 line
2.44.0
PATCH v6 1/21 lib/bitmap: add bitmap_{read,write}()
From: Syed Nayyar Waris <[email protected]>
The two new functions allow reading/writing values of length up to BITS_PER_LONG bits at arbitrary position in the bitmap.
The code was taken from "bitops: Introduce the for_each_set_clump macro" by Syed Nayyar Waris with a number of changes and simplifications:
- instead of using roundup(), which adds an unnecessary dependency on <linux/math.h>, we calculate space as BITS_PER_LONG-offset;
- indentation is reduced by not using else-clauses (suggested by checkpatch for bitmap_get_value());
- bitmap_get_value()/bitmap_set_value() are renamed to bitmap_read() and bitmap_write();
- some redundant computations are omitted.
--- include/linux/bitmap.h | 77 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+)
include/linux/bitmap.h +77 -0
@@ -83,6 +83,10 @@ struct device;* bitmap_to_arr64(buf, src, nbits) Copy nbits from buf to u64[] dst * bitmap_get_value8(map, start) Get 8bit value from map at start * bitmap_set_value8(map, value, start) Set 8bit value to map at start +* bitmap_read(map, start, nbits) Read an nbits-sized value from +* map at start +* bitmap_write(map, value, start, nbits) Write an nbits-sized value to +* map at start * * Note, bitmap_zero() and bitmap_fill() operate over the region of * unsigned longs, that is, bits behind bitmap till the unsigned long
@@ -754,6 +758,79 @@ static inline void bitmap_set_value8(unsigned long *map, unsigned long value, map[index] |= value << offset; } +/** +* bitmap_read - read a value of n-bits from the memory region +* @map: address to the bitmap memory region +* @start: bit offset of the n-bit value +* @nbits: size of value in bits, nonzero, up to BITS_PER_LONG +* +* Returns: value of @nbits bits located at the @start bit offset within the +* @map memory region. For @nbits = 0 and @nbits > BITS_PER_LONG the return +* value is undefined. +*/ +static inline unsigned long bitmap_read (const unsigned long *map, +unsigned long start, +unsigned long nbits) +{ +size_t index =BIT_WORD (start); +unsigned long offset = start %BITS_PER_LONG ; +unsigned long space =BITS_PER_LONG - offset; +unsigned long value_low, value_high; + +if (unlikely (!nbits || nbits >BITS_PER_LONG )) +return 0 ; + +if (space >= nbits) +return (map[index] >> offset) &BITMAP_LAST_WORD_MASK (nbits); + + value_low = map[index] &BITMAP_FIRST_WORD_MASK (start); + value_high = map[index +1 ] &BITMAP_LAST_WORD_MASK (start + nbits); +return (value_low >> offset) | (value_high << space); +} + +/** +* bitmap_write - write n-bit value within a memory region +* @map: address to the bitmap memory region +* @value: value to write, clamped to nbits +* @start: bit offset of the n-bit value +* @nbits: size of value in bits, nonzero, up to BITS_PER_LONG. +* +* bitmap_write() behaves as-if implemented as @nbits calls of __assign_bit(), +* i.e. bits beyond @nbits are ignored: +* +* for (bit = 0; bit < nbits; bit++) +* __assign_bit(start + bit, bitmap, val & BIT(bit)); +* +* For @nbits == 0 and @nbits > BITS_PER_LONG no writes are performed. +*/ +static inline void bitmap_write (unsigned long *map,unsigned long value, +unsigned long start,unsigned long nbits) +{ +size_t index; +unsigned long offset; +unsigned long space; +unsigned long mask; +bool fit; + +if (unlikely (!nbits || nbits >BITS_PER_LONG )) +return ; + + mask =BITMAP_LAST_WORD_MASK (nbits); + value &= mask; + offset = start %BITS_PER_LONG ; + space =BITS_PER_LONG - offset; + fit = space >= nbits; + index =BIT_WORD (start); + + map[index] &= (fit ? (~(mask << offset)) : ~BITMAP_FIRST_WORD_MASK (start)); + map[index] |= value << offset; +if (fit) +return ; + + map[index +1 ] &=BITMAP_FIRST_WORD_MASK (start + nbits); + map[index +1 ] |= (value >> space); +} +#endif /* __ASSEMBLY__ */ #endif /* __LINUX_BITMAP_H */
Signature · 1 line
2.44.0
PATCH v6 2/21 lib/test_bitmap: add tests for bitmap_{read,write}()
In reply to Alexander LobakinFrom: Alexander Potapenko <[email protected]>
Add basic tests ensuring that values can be added at arbitrary positions of the bitmap, including those spanning into the adjacent unsigned longs.
Two new performance tests, test_bitmap_read_perf() and test_bitmap_write_perf(), can be used to assess future performance improvements of bitmap_read() and bitmap_write():
[ 0.431119][ T1] test_bitmap: Time spent in test_bitmap_read_perf: 615253 [ 0.433197][ T1] test_bitmap: Time spent in test_bitmap_write_perf: 916313
(numbers from a Intel(R) Xeon(R) Gold 6154 CPU @ 3.00GHz machine running QEMU).
--- lib/test_bitmap.c | 179 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 172 insertions(+), 7 deletions(-)
lib/test_bitmap.c +172 -7
@@ -60,18 +60,17 @@ static const unsigned long exp3_1_0[] __initconst = { };static bool __init -__check_eq_uint (const char *srcfile,unsigned int line, -const unsigned int exp_uint,unsigned int x) +__check_eq_ulong (const char *srcfile,unsigned int line, +const unsigned long exp_ulong,unsigned long x) { -if (exp_uint != x) { -pr_err ("[%s:%u] expected %u, got %u\n" , - srcfile, line, exp_uint, x); +if (exp_ulong != x) { +pr_err ("[%s:%u] expected %lu, got %lu\n" , + srcfile, line, exp_ulong, x);return false; }return true; } - static bool __init __check_eq_bitmap(const char *srcfile, unsigned int line, const unsigned long *exp_bmap, const unsigned long *bmap,
@@ -185,7 +184,8 @@ __check_eq_str(const char *srcfile, unsigned int line, result; \ }) -#define expect_eq_uint (...) __expect_eq(uint, ##__VA_ARGS__) +#define expect_eq_ulong (...) __expect_eq(ulong, ##__VA_ARGS__) +#define expect_eq_uint (x, y) expect_eq_ulong((unsigned int)(x), (unsigned int)(y))#define expect_eq_bitmap (...) __expect_eq(bitmap, ##__VA_ARGS__)#define expect_eq_pbl (...) __expect_eq(pbl, ##__VA_ARGS__)#define expect_eq_u32_array (...) __expect_eq(u32_array, ##__VA_ARGS__)
@@ -1286,6 +1286,168 @@ static void __init test_bitmap_const_eval(void)BUILD_BUG_ON (~var != ~BIT (25 )); } +/* +* Test bitmap should be big enough to include the cases when start is not in +* the first word, and start+nbits lands in the following word. +*/ +#define TEST_BIT_LEN (1000) + +/* +* Helper function to test bitmap_write() overwriting the chosen byte pattern. +*/ +static void __init test_bitmap_write_helper (const char *pattern) +{ +DECLARE_BITMAP (bitmap,TEST_BIT_LEN ); +DECLARE_BITMAP (exp_bitmap,TEST_BIT_LEN ); +DECLARE_BITMAP (pat_bitmap,TEST_BIT_LEN ); +unsigned long w, r, bit; +int i, n, nbits; + +/* +* Only parse the pattern once and store the result in the intermediate +* bitmap. +*/ +bitmap_parselist (pattern, pat_bitmap,TEST_BIT_LEN ); + +/* +* Check that writing a single bit does not accidentally touch the +* adjacent bits. +*/ +for (i =0 ; i <TEST_BIT_LEN ; i++) { +bitmap_copy (bitmap, pat_bitmap,TEST_BIT_LEN ); +bitmap_copy (exp_bitmap, pat_bitmap,TEST_BIT_LEN ); +for (bit =0 ; bit <=1 ; bit++) { +bitmap_write (bitmap, bit, i,1 ); +__assign_bit (i, exp_bitmap, bit); +expect_eq_bitmap (exp_bitmap, bitmap, +TEST_BIT_LEN ); + } + } + +/* Ensure writing 0 bits does not change anything. */ +bitmap_copy (bitmap, pat_bitmap,TEST_BIT_LEN ); +bitmap_copy (exp_bitmap, pat_bitmap,TEST_BIT_LEN ); +for (i =0 ; i <TEST_BIT_LEN ; i++) { +bitmap_write (bitmap, ~0UL , i,0 ); +expect_eq_bitmap (exp_bitmap, bitmap,TEST_BIT_LEN ); + } + +for (nbits =BITS_PER_LONG ; nbits >=1 ; nbits--) { + w =IS_ENABLED (CONFIG_64BIT ) ?0xdeadbeefdeadbeefUL + :0xdeadbeefUL ; + w >>= (BITS_PER_LONG - nbits); +for (i =0 ; i <=TEST_BIT_LEN - nbits; i++) { +bitmap_copy (bitmap, pat_bitmap,TEST_BIT_LEN ); +bitmap_copy (exp_bitmap, pat_bitmap,TEST_BIT_LEN ); +for (n =0 ; n < nbits; n++) +__assign_bit (i + n, exp_bitmap, w &BIT (n)); +bitmap_write (bitmap, w, i, nbits); +expect_eq_bitmap (exp_bitmap, bitmap,TEST_BIT_LEN ); + r =bitmap_read (bitmap, i, nbits); +expect_eq_ulong (r, w); + } + } +} + +static void __init test_bitmap_read_write (void ) +{ +unsigned char *pattern[3 ] = {"" ,"all:1/2" ,"all" }; +DECLARE_BITMAP (bitmap,TEST_BIT_LEN ); +unsigned long zero_bits =0 , bits_per_long =BITS_PER_LONG ; +unsigned long val; +int i, pi; + +/* +* Reading/writing zero bits should not crash the kernel. +* READ_ONCE() prevents constant folding. +*/ +bitmap_write (NULL ,0 ,0 ,READ_ONCE (zero_bits)); +/* Return value of bitmap_read() is undefined here. */ +bitmap_read (NULL ,0 ,READ_ONCE (zero_bits)); + +/* +* Reading/writing more than BITS_PER_LONG bits should not crash the +* kernel. READ_ONCE() prevents constant folding. +*/ +bitmap_write (NULL ,0 ,0 ,READ_ONCE (bits_per_long) +1 ); +/* Return value of bitmap_read() is undefined here. */ +bitmap_read (NULL ,0 ,READ_ONCE (bits_per_long) +1 ); + +/* +* Ensure that bitmap_read() reads the same value that was previously +* written, and two consequent values are correctly merged. +* The resulting bit pattern is asymmetric to rule out possible issues +* with bit numeration order. +*/ +for (i =0 ; i <TEST_BIT_LEN -7 ; i++) { +bitmap_zero (bitmap,TEST_BIT_LEN ); + +bitmap_write (bitmap,0b10101UL , i,5 ); + val =bitmap_read (bitmap, i,5 ); +expect_eq_ulong (0b10101UL , val); + +bitmap_write (bitmap,0b101UL , i +5 ,3 ); + val =bitmap_read (bitmap, i +5 ,3 ); +expect_eq_ulong (0b101UL , val); + + val =bitmap_read (bitmap, i,8 ); +expect_eq_ulong (0b10110101UL , val); + } + +for (pi =0 ; pi <ARRAY_SIZE (pattern); pi++) +test_bitmap_write_helper (pattern[pi]); +} + +static void __init test_bitmap_read_perf (void ) +{ +DECLARE_BITMAP (bitmap,TEST_BIT_LEN ); +unsigned int cnt, nbits, i; +unsigned long val; +ktime_t time; + +bitmap_fill (bitmap,TEST_BIT_LEN ); + time =ktime_get (); +for (cnt =0 ; cnt <5 ; cnt++) { +for (nbits =1 ; nbits <=BITS_PER_LONG ; nbits++) { +for (i =0 ; i <TEST_BIT_LEN ; i++) { +if (i + nbits >TEST_BIT_LEN ) +break ; +/* +* Prevent the compiler from optimizing away the +* bitmap_read() by using its value. +*/ +WRITE_ONCE (val,bitmap_read (bitmap, i, nbits)); + } + } + } + time =ktime_get () - time; +pr_err ("Time spent in %s:\t%llu\n" , __func__, time); +} + +static void __init test_bitmap_write_perf (void ) +{ +DECLARE_BITMAP (bitmap,TEST_BIT_LEN ); +unsigned int cnt, nbits, i; +unsigned long val =0xfeedface ; +ktime_t time; + +bitmap_zero (bitmap,TEST_BIT_LEN ); + time =ktime_get (); +for (cnt =0 ; cnt <5 ; cnt++) { +for (nbits =1 ; nbits <=BITS_PER_LONG ; nbits++) { +for (i =0 ; i <TEST_BIT_LEN ; i++) { +if (i + nbits >TEST_BIT_LEN ) +break ; +bitmap_write (bitmap, val, i, nbits); + } + } + } + time =ktime_get () - time; +pr_err ("Time spent in %s:\t%llu\n" , __func__, time); +} + +#undef TEST_BIT_LEN +static void __init selftest (void ) {test_zero_clear ();
@@ -1303,6 +1465,9 @@ static void __init selftest(void)test_bitmap_cut ();test_bitmap_print_buf ();test_bitmap_const_eval (); +test_bitmap_read_write (); +test_bitmap_read_perf (); +test_bitmap_write_perf ();test_find_nth_bit (); test_for_each_set_bit();
Signature · 1 line
2.44.0
Re: [PATCH net-next v6 02/21] lib/test_bitmap: add tests for bitmap_{read,write}()
Quoted 13 lines · Alexander Lobakin
From: Alexander Potapenko <[email protected]>
Add basic tests ensuring that values can be added at arbitrary positions of the bitmap, including those spanning into the adjacent unsigned longs.
Two new performance tests,
test_bitmap_read_perf()andtest_bitmap_write_perf(), can be used to assess future performance improvements ofbitmap_read()andbitmap_write():[ 0.431119][ T1] test_bitmap: Time spent in test_bitmap_read_perf: 615253 [ 0.433197][ T1] test_bitmap: Time spent in test_bitmap_write_perf: 916313
Quoted 8 lines
(numbers from a Intel(R) Xeon(R) Gold 6154 CPU @ 3.00GHz machine running QEMU).
Signed-off-by Alexander Potapenko <[email protected]>Reviewed-by Andy Shevchenko <[email protected]>Acked-by Yury Norov <[email protected]>Signed-off-by Yury Norov <[email protected]>
This is a bit strange.
Can you explain the SoB chain in this patch and similar which have Yury's SoB?
Quoted 1 line
Signed-off-by Alexander Lobakin <[email protected]>
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH net-next v6 02/21] lib/test_bitmap: add tests for bitmap_{read,write}()
From: Andy Shevchenko <[email protected]>
Date: Wed, 27 Mar 2024 17:47:56 +0200
Quoted 17 lines · Alexander Lobakin
Quoted 16 lines
From: Alexander Potapenko <[email protected]>
Add basic tests ensuring that values can be added at arbitrary positions of the bitmap, including those spanning into the adjacent unsigned longs.
Two new performance tests,
test_bitmap_read_perf()andtest_bitmap_write_perf(), can be used to assess future performance improvements ofbitmap_read()andbitmap_write():[ 0.431119][ T1] test_bitmap: Time spent in test_bitmap_read_perf: 615253 [ 0.433197][ T1] test_bitmap: Time spent in test_bitmap_write_perf: 916313(numbers from a Intel(R) Xeon(R) Gold 6154 CPU @ 3.00GHz machine running QEMU).
Quoted 8 lines
Quoted 5 lines
Signed-off-by Alexander Potapenko <[email protected]>Reviewed-by Andy Shevchenko <[email protected]>Acked-by Yury Norov <[email protected]>Signed-off-by Yury Norov <[email protected]>This is a bit strange.
Can you explain the SoB chain in this patch and similar which have Yury's SoB?
Yury gave me them in the previous thread ¯\_(ツ)_/¯ I didn't ask why.
Quoted 3 lines
Quoted 2 lines
Signed-off-by Alexander Lobakin <[email protected]>
Thanks,
Olek
PATCH v6 3/21 lib/test_bitmap: use pr_info() for non-error messages
In reply to Alexander LobakinFrom: Alexander Potapenko <[email protected]>
pr_err() messages may be treated as errors by some log readers, so let us only use them for test failures. For non-error messages, replace them with pr_info().
--- lib/test_bitmap.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
lib/test_bitmap.c +5 -5
@@ -548,7 +548,7 @@ static void __init test_bitmap_parselist(void) }if (ptest.flags &PARSE_TIME ) -pr_err ("parselist: %d: input is '%s' OK, Time: %llu\n" , +pr_info ("parselist: %d: input is '%s' OK, Time: %llu\n" , i, ptest.in, time);#undef ptest
@@ -587,7 +587,7 @@ static void __init test_bitmap_printlist(void) goto out; } -pr_err ("bitmap_print_to_pagebuf: input is '%s', Time: %llu\n" , buf, time); +pr_info ("bitmap_print_to_pagebuf: input is '%s', Time: %llu\n" , buf, time); out:kfree (buf);kfree (bmap);
@@ -665,7 +665,7 @@ static void __init test_bitmap_parse(void) }if (test.flags &PARSE_TIME ) -pr_err ("parse: %d: input is '%s' OK, Time: %llu\n" , +pr_info ("parse: %d: input is '%s' OK, Time: %llu\n" , i, test.in, time); } }
@@ -1421,7 +1421,7 @@ static void __init test_bitmap_read_perf(void) } } time =ktime_get () - time; -pr_err ("Time spent in %s:\t%llu\n" , __func__, time); +pr_info ("Time spent in %s:\t%llu\n" , __func__, time); }static void __init test_bitmap_write_perf (void )
@@ -1443,7 +1443,7 @@ static void __init test_bitmap_write_perf(void) } } time =ktime_get () - time; -pr_err ("Time spent in %s:\t%llu\n" , __func__, time); +pr_info ("Time spent in %s:\t%llu\n" , __func__, time); }#undef TEST_BIT_LEN
Signature · 1 line
2.44.0
PATCH v6 4/21 bitops: add missing prototype check
In reply to Alexander LobakinCommit 8238b4579866 ("wait_on_bit: add an acquire memory barrier") added a new bitop, test_bit_acquire(), with proper wrapping in order to try to optimize it at compile-time, but missed the list of bitops used for checking their prototypes a bit below.
The functions added have consistent prototypes, so that no more changes are required and no functional changes take place.
--- include/linux/bitops.h | 1 + 1 file changed, 1 insertion(+)
include/linux/bitops.h +1 -0
@@ -80,6 +80,7 @@ __check_bitop_pr(__test_and_set_bit);__check_bitop_pr (__test_and_clear_bit);__check_bitop_pr (__test_and_change_bit);__check_bitop_pr (test_bit); +__check_bitop_pr (test_bit_acquire);#undef __check_bitop_pr
Signature · 1 line
2.44.0
PATCH v6 5/21 bitops: make BYTES_TO_BITS() treewide-available
In reply to Alexander LobakinAvoid open-coding that simple expression each time by moving BYTES_TO_BITS() from the probes code to <linux/bitops.h> to export it to the rest of the kernel.
Simplify the macro while at it. BITS_PER_LONG / sizeof(long) always equals to %BITS_PER_BYTE, regardless of the target architecture. Do the same for the tools ecosystem as well (incl. its version of bitops.h). The previous implementation had its implicit type of long, while the new one is int, so adjust the format literal accordingly in the perf code.
--- include/linux/bitops.h | 2 ++ tools/include/linux/bitops.h | 2 ++ kernel/trace/trace_probe.c | 2 -- tools/perf/util/probe-finder.c | 4 +--- 4 files changed, 5 insertions(+), 5 deletions(-)
include/linux/bitops.h +2 -0
@@ -21,6 +21,8 @@#define BITS_TO_U32 (nr) __KERNEL_DIV_ROUND_UP(nr, BITS_PER_TYPE(u32))#define BITS_TO_BYTES (nr) __KERNEL_DIV_ROUND_UP(nr, BITS_PER_TYPE(char)) +#define BYTES_TO_BITS (nb) ((nb) * BITS_PER_BYTE) +extern unsigned int __sw_hweight8 (unsigned int w);extern unsigned int __sw_hweight16 (unsigned int w);extern unsigned int __sw_hweight32 (unsigned int w);
tools/include/linux/bitops.h +2 -0
@@ -20,6 +20,8 @@#define BITS_TO_U32 (nr) DIV_ROUND_UP(nr, BITS_PER_TYPE(u32))#define BITS_TO_BYTES (nr) DIV_ROUND_UP(nr, BITS_PER_TYPE(char)) +#define BYTES_TO_BITS (nb) ((nb) * BITS_PER_BYTE) +extern unsigned int __sw_hweight8 (unsigned int w);extern unsigned int __sw_hweight16 (unsigned int w);extern unsigned int __sw_hweight32 (unsigned int w);
kernel/trace/trace_probe.c +0 -2
@@ -1180,8 +1180,6 @@ parse_probe_arg(char *arg, const struct fetch_type *type,return ret; } -#define BYTES_TO_BITS (nb) ((BITS_PER_LONG * (nb)) / sizeof(long)) -/* Bitfield type needs to be parsed into a fetch function */ static int __parse_bitfield_probe_arg(const char *bf, const struct fetch_type *t,
tools/perf/util/probe-finder.c +1 -3
@@ -186,8 +186,6 @@ static int convert_variable_location(Dwarf_Die *vr_die, Dwarf_Addr addr,return ret2; } -#define BYTES_TO_BITS (nb) ((nb) * BITS_PER_LONG / sizeof(long)) -static int convert_variable_type (Dwarf_Die *vr_die,struct probe_trace_arg *tvar,const char *cast,bool user_access)
@@ -217,7 +215,7 @@ static int convert_variable_type(Dwarf_Die *vr_die, total =dwarf_bytesize (vr_die);if (boffs <0 || total <0 )return -ENOENT ; - ret =snprintf (buf,16 ,"b%d@%d/%zd" , bsize, boffs, + ret =snprintf (buf,16 ,"b%d@%d/%d" , bsize, boffs,BYTES_TO_BITS (total)); goto formatted; }
Signature · 1 line
2.44.0
PATCH v6 6/21 bitops: let the compiler optimize {__,}assign_bit()
In reply to Alexander LobakinSince commit b03fc1173c0c ("bitops: let optimize out non-atomic bitops on compile-time constants"), the compilers are able to expand inline bitmap operations to compile-time initializers when possible. However, during the round of replacement if-__set-else-__clear with __assign_bit() as per Andy's advice, bloat-o-meter showed +1024 bytes difference in object code size for one module (even one function), where the pattern:
DECLARE_BITMAP(foo) = { }; // on the stack, zeroed
if (a)
__set_bit(const_bit_num, foo);
if (b)
__set_bit(another_const_bit_num, foo);
...is heavily used, although there should be no difference: the bitmap is zeroed, so the second half of __assign_bit() should be compiled-out as a no-op.
I either missed the fact that __assign_bit() has bitmap pointer marked as volatile (as we usually do for bitops) or was hoping that the compilers would at least try to look past the volatile for __always_inline functions. Anyhow, due to that attribute, the compilers were always compiling the whole expression and no mentioned compile-time optimizations were working.
Convert __assign_bit() to a macro since it's a very simple if-else and all of the checks are performed inside __set_bit() and __clear_bit(), thus that wrapper has to be as transparent as possible. After that change, despite it showing only -20 bytes change for vmlinux (due to that it's still relatively unpopular), no drastic code size changes happen when replacing if-set-else-clear for onstack bitmaps with __assign_bit(), meaning the compiler now expands them to the actual operations will all the expected optimizations.
Atomic assign_bit() is less affected due to its nature, but let's convert it to a macro as well to keep the code consistent and not leave a place for possible suboptimal codegen. Moreover, with certain kernel configuration it actually gives some saves (x86):
do_ip_setsockopt 4154 4099 -55
--- include/linux/bitops.h | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-)
include/linux/bitops.h +4 -16
@@ -275,23 +275,11 @@ static inline unsigned long fns(unsigned long word, unsigned int n)* @addr: the address to start counting from * @value: the value to assign */ -static __always_inline void assign_bit(long nr, volatile unsigned long *addr, -bool value) -{ -if (value) -set_bit (nr, addr); -else -clear_bit (nr, addr); -} +#define assign_bit (nr, addr, value) \ + ((value) ? set_bit((nr), (addr)) : clear_bit((nr), (addr))) -static __always_inline void __assign_bit(long nr, volatile unsigned long *addr, -bool value) -{ -if (value) -__set_bit (nr, addr); -else -__clear_bit (nr, addr); -} +#define __assign_bit (nr, addr, value) \ + ((value) ? __set_bit((nr), (addr)) : __clear_bit((nr), (addr)))/** * __ptr_set_bit - Set bit in a pointer's value
Signature · 1 line
2.44.0
PATCH v6 7/21 linkmode: convert linkmode_{test,set,clear,mod}_bit() to macros
In reply to Alexander LobakinSince commit b03fc1173c0c ("bitops: let optimize out non-atomic bitops on compile-time constants"), the non-atomic bitops are macros which can be expanded by the compilers into compile-time expressions, which will result in better optimized object code. Unfortunately, turned out that passing volatile to those macros discards any possibility of optimization, as the compilers then don't even try to look whether the passed bitmap is known at compilation time. In addition to that, the mentioned linkmode helpers are marked with inline, not __always_inline, meaning that it's not guaranteed some compiler won't uninline them for no reason, which will also effectively prevent them from being optimized (it's a well-known thing the compilers sometimes uninline 2 + 2).
Convert linkmode_*_bit() from inlines to macros. Their calling convention are 1:1 with the corresponding bitops, so that it's not even needed to enumerate and map the arguments, only the names. No changes in vmlinux' object code (compiled by LLVM for x86_64) whatsoever, but that doesn't necessarily means the change is meaningless.
--- include/linux/linkmode.h | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-)
include/linux/linkmode.h +4 -23
@@ -43,29 +43,10 @@ static inline int linkmode_andnot(unsigned long *dst, const unsigned long *src1,return bitmap_andnot (dst, src1, src2, __ETHTOOL_LINK_MODE_MASK_NBITS); } -static inline void linkmode_set_bit (int nr,volatile unsigned long *addr) -{ -__set_bit (nr, addr); -} - -static inline void linkmode_clear_bit (int nr,volatile unsigned long *addr) -{ -__clear_bit (nr, addr); -} - -static inline void linkmode_mod_bit (int nr,volatile unsigned long *addr, -int set) -{ -if (set) -linkmode_set_bit (nr, addr); -else -linkmode_clear_bit (nr, addr); -} - -static inline int linkmode_test_bit (int nr,const volatile unsigned long *addr) -{ -return test_bit (nr, addr); -} +#define linkmode_test_bit test_bit +#define linkmode_set_bit __set_bit +#define linkmode_clear_bit __clear_bit +#define linkmode_mod_bit __assign_bitstatic inline void linkmode_set_bit_array (const int *array,int array_size,unsigned long *addr)
Signature · 1 line
2.44.0
PATCH v6 8/21 s390/cio: rename bitmap_size() -> idset_bitmap_size()
In reply to Alexander Lobakinbitmap_size() is a pretty generic name and one may want to use it for a generic bitmap API function. At the same time, its logic is not "generic", i.e. it's not just nbits -> size of bitmap in bytes converter as it would be expected from its name.
Add the prefix 'idset_' used throughout the file where the function resides.
--- drivers/s390/cio/idset.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/s390/cio/idset.c +6 -4
@@ -16,7 +16,7 @@ struct idset {unsigned long bitmap[]; }; -static inline unsigned long bitmap_size (int num_ssid,int num_id) +static inline unsigned long idset_bitmap_size (int num_ssid,int num_id) {return BITS_TO_LONGS (num_ssid * num_id) *sizeof (unsigned long ); }
@@ -25,11 +25,12 @@ static struct idset *idset_new(int num_ssid, int num_id) {struct idset *set; - set =vmalloc (sizeof (struct idset ) +bitmap_size (num_ssid, num_id)); + set =vmalloc (sizeof (struct idset ) + +idset_bitmap_size (num_ssid, num_id));if (set) { set->num_ssid = num_ssid; set->num_id = num_id; -memset (set->bitmap,0 ,bitmap_size (num_ssid, num_id)); +memset (set->bitmap,0 ,idset_bitmap_size (num_ssid, num_id)); }return set; }
@@ -41,7 +42,8 @@ void idset_free(struct idset *set)void idset_fill (struct idset *set) { -memset (set->bitmap,0xff ,bitmap_size (set->num_ssid, set->num_id)); +memset (set->bitmap,0xff , +idset_bitmap_size (set->num_ssid, set->num_id)); }static inline void idset_add (struct idset *set,int ssid,int id)
Signature · 1 line
2.44.0
PATCH v6 9/21 fs/ntfs3: add prefix to bitmap_size() and use BITS_TO_U64()
In reply to Alexander Lobakinbitmap_size() is a pretty generic name and one may want to use it for a generic bitmap API function. At the same time, its logic is NTFS-specific, as it aligns to the sizeof(u64), not the sizeof(long) (although it uses ideologically right ALIGN() instead of division). Add the prefix 'ntfs3_' used for that FS (not just 'ntfs_' to not mix it with the legacy module) and use generic BITS_TO_U64() while at it.
--- fs/ntfs3/ntfs_fs.h | 4 ++-- fs/ntfs3/bitmap.c | 4 ++-- fs/ntfs3/fsntfs.c | 2 +- fs/ntfs3/index.c | 11 ++++++----- fs/ntfs3/super.c | 2 +- 5 files changed, 12 insertions(+), 11 deletions(-)
fs/ntfs3/ntfs_fs.h +2 -2
@@ -966,9 +966,9 @@ static inline bool run_is_empty(struct runs_tree *run) }/* NTFS uses quad aligned bitmaps. */ -static inline size_t bitmap_size (size_t bits) +static inline size_t ntfs3_bitmap_size (size_t bits) { -return ALIGN ((bits +7 ) >>3 ,8 ); +return BITS_TO_U64 (bits) *sizeof (u64); }#define _100ns2seconds 10000000
fs/ntfs3/bitmap.c +2 -2
@@ -654,7 +654,7 @@ int wnd_init(struct wnd_bitmap *wnd, struct super_block *sb, size_t nbits) wnd->total_zeroes = nbits; wnd->extent_max =MINUS_ONE_T ; wnd->zone_bit = wnd->zone_end =0 ; - wnd->nwnd =bytes_to_block (sb,bitmap_size (nbits)); + wnd->nwnd =bytes_to_block (sb,ntfs3_bitmap_size (nbits)); wnd->bits_last = nbits & (wbits -1 );if (!wnd->bits_last) wnd->bits_last = wbits;
@@ -1347,7 +1347,7 @@ int wnd_extend(struct wnd_bitmap *wnd, size_t new_bits)return -EINVAL ;/* Align to 8 byte boundary. */ - new_wnd =bytes_to_block (sb,bitmap_size (new_bits)); + new_wnd =bytes_to_block (sb,ntfs3_bitmap_size (new_bits)); new_last = new_bits & (wbits -1 );if (!new_last) new_last = wbits;
fs/ntfs3/fsntfs.c +1 -1
@@ -522,7 +522,7 @@ static int ntfs_extend_mft(struct ntfs_sb_info *sbi) ni->mi.dirty = true;/* Step 2: Resize $MFT::BITMAP. */ - new_bitmap_bytes =bitmap_size (new_mft_total); + new_bitmap_bytes =ntfs3_bitmap_size (new_mft_total); err =attr_set_size (ni,ATTR_BITMAP ,NULL ,0 , &sbi->mft.bitmap.run, new_bitmap_bytes, &new_bitmap_bytes, true,NULL );
fs/ntfs3/index.c +6 -5
@@ -1456,8 +1456,8 @@ static int indx_create_allocate(struct ntfs_index *indx, struct ntfs_inode *ni, alloc->nres.valid_size = alloc->nres.data_size =cpu_to_le64 (data_size); - err =ni_insert_resident (ni,bitmap_size (1 ),ATTR_BITMAP , in->name, - in->name_len, &bitmap,NULL ,NULL ); + err =ni_insert_resident (ni,ntfs3_bitmap_size (1 ),ATTR_BITMAP , + in->name, in->name_len, &bitmap,NULL ,NULL );if (err) goto out2;
@@ -1518,8 +1518,9 @@ static int indx_add_allocate(struct ntfs_index *indx, struct ntfs_inode *ni,if (bmp) {/* Increase bitmap. */ err =attr_set_size (ni,ATTR_BITMAP , in->name, in->name_len, - &indx->bitmap_run,bitmap_size (bit +1 ), -NULL , true,NULL ); + &indx->bitmap_run, +ntfs3_bitmap_size (bit +1 ),NULL , true, +NULL );if (err) goto out1; }
@@ -2092,7 +2093,7 @@ static int indx_shrink(struct ntfs_index *indx, struct ntfs_inode *ni,if (in->name ==I30_NAME )i_size_write (&ni->vfs_inode, new_data); - bpb =bitmap_size (bit); + bpb =ntfs3_bitmap_size (bit);if (bpb *8 == nbits)return 0 ;
fs/ntfs3/super.c +1 -1
@@ -1341,7 +1341,7 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc)/* Check bitmap boundary. */ tt = sbi->used.bitmap.nbits; -if (inode->i_size <bitmap_size (tt)) { +if (inode->i_size <ntfs3_bitmap_size (tt)) {ntfs_err (sb,"$Bitmap is corrupted." ); err = -EINVAL ; goto put_inode_out;
Signature · 1 line
2.44.0
PATCH v6 10/21 btrfs: rename bitmap_set_bits() -> btrfs_bitmap_set_bits()
In reply to Alexander Lobakinbitmap_set_bits() does not start with the FS' prefix and may collide with a new generic helper one day. It operates with the FS-specific types, so there's no change those two could do the same thing. Just add the prefix to exclude such possible conflict.
--- fs/btrfs/free-space-cache.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/btrfs/free-space-cache.c +4 -4
@@ -1911,9 +1911,9 @@ static inline void bitmap_clear_bits(struct btrfs_free_space_ctl *ctl, ctl->free_space -= bytes; } -static void bitmap_set_bits (struct btrfs_free_space_ctl *ctl, -struct btrfs_free_space *info,u64 offset, -u64 bytes) +static void btrfs_bitmap_set_bits (struct btrfs_free_space_ctl *ctl, +struct btrfs_free_space *info,u64 offset, +u64 bytes) {unsigned long start, count, end;int extent_delta =1 ;
@@ -2249,7 +2249,7 @@ static u64 add_bytes_to_bitmap(struct btrfs_free_space_ctl *ctl, bytes_to_set =min (end - offset, bytes); -bitmap_set_bits (ctl, info, offset, bytes_to_set); +btrfs_bitmap_set_bits (ctl, info, offset, bytes_to_set);return bytes_to_set;
Signature · 1 line
2.44.0
PATCH v6 11/21 tools: move alignment-related macros to new <linux/align.h>
In reply to Alexander LobakinCurrently, tools have *ALIGN*() macros scattered across the unrelated headers, as there are only 3 of them and they were added separately each time on an as-needed basis.
Anyway, let's make it more consistent with the kernel headers and allow using those macros outside of the mentioned headers. Create <linux/align.h> inside the tools/ folder and include it where needed.
--- tools/include/linux/align.h | 12 ++++++++++++ tools/include/linux/bitmap.h | 2 +- tools/include/linux/mm.h | 5 +---- 3 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 tools/include/linux/align.h
tools/include/linux/align.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef _TOOLS_LINUX_ALIGN_H +#define _TOOLS_LINUX_ALIGN_H + +#include <uapi/linux/const.h> + +#define ALIGN (x, a) __ALIGN_KERNEL((x), (a)) +#define ALIGN_DOWN (x, a) __ALIGN_KERNEL((x) - ((a) - 1), (a)) +#define IS_ALIGNED (x, a) (((x) & ((typeof(x))(a) - 1)) == 0) + +#endif /* _TOOLS_LINUX_ALIGN_H */
tools/include/linux/bitmap.h +1 -1
@@ -3,6 +3,7 @@#define _TOOLS_LINUX_BITMAP_H#include <string.h> +#include <linux/align.h> #include <linux/bitops.h> #include <linux/find.h> #include <stdlib.h>
@@ -126,7 +127,6 @@ static inline bool bitmap_and(unsigned long *dst, const unsigned long *src1,#define BITMAP_MEM_ALIGNMENT (8 * sizeof(unsigned long))#endif #define BITMAP_MEM_MASK (BITMAP_MEM_ALIGNMENT - 1) -#define IS_ALIGNED (x, a) (((x) & ((typeof(x))(a) - 1)) == 0)static inline bool bitmap_equal (const unsigned long *src1,const unsigned long *src2,unsigned int nbits)
tools/include/linux/mm.h +1 -4
@@ -2,8 +2,8 @@#ifndef _TOOLS_LINUX_MM_H#define _TOOLS_LINUX_MM_H +#include <linux/align.h> #include <linux/mmzone.h> -#include <uapi/linux/const.h> #define PAGE_SHIFT 12#define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
@@ -11,9 +11,6 @@#define PHYS_ADDR_MAX (~(phys_addr_t)0) -#define ALIGN (x, a) __ALIGN_KERNEL((x), (a)) -#define ALIGN_DOWN (x, a) __ALIGN_KERNEL((x) - ((a) - 1), (a)) -#define PAGE_ALIGN (addr) ALIGN(addr, PAGE_SIZE)#define __va (x) ((void *)((unsigned long)(x)))
Signature · 1 line
2.44.0
PATCH v6 12/21 bitmap: introduce generic optimized bitmap_size()
In reply to Alexander LobakinThe number of times yet another open coded BITS_TO_LONGS(nbits) * sizeof(long) can be spotted is huge. Some generic helper is long overdue.
Add one, bitmap_size(), but with one detail. BITS_TO_LONGS() uses DIV_ROUND_UP(). The latter works well when both divident and divisor are compile-time constants or when the divisor is not a pow-of-2. When it is however, the compilers sometimes tend to generate suboptimal code (GCC 13):
48 83 c0 3f add $0x3f,%rax 48 c1 e8 06 shr $0x6,%rax
48 8d 14 c5 00 00 00 00 lea 0x0(,%rax,8),%rdx
%BITS_PER_LONG is always a pow-2 (either 32 or 64), but GCC still does full division of nbits + 63 by it and then multiplication by 8. Instead of BITS_TO_LONGS(), use ALIGN() and then divide by 8. GCC:
8d 50 3f lea 0x3f(%rax),%edx c1 ea 03 shr $0x3,%edx 81 e2 f8 ff ff 1f and $0x1ffffff8,%edx
Now it shifts nbits + 63 by 3 positions (IOW performs fast division by 8) and then masks bits[2:0]. bloat-o-meter:
add/remove: 0/0 grow/shrink: 20/133 up/down: 156/-773 (-617)
Clang does it better and generates the same code before/after starting from -O1, except that with the ALIGN() approach it uses %edx and thus still saves some bytes:
add/remove: 0/0 grow/shrink: 9/133 up/down: 18/-538 (-520)
Note that we can't expand DIV_ROUND_UP() by adding a check and using this approach there, as it's used in array declarations where expressions are not allowed.
Add this helper to tools/ as well.
--- include/linux/bitmap.h | 8 +++++--- include/linux/cpumask.h | 2 +- tools/include/linux/bitmap.h | 7 ++++--- drivers/md/dm-clone-metadata.c | 5 ----- drivers/s390/cio/idset.c | 2 +- lib/math/prime_numbers.c | 2 -- 6 files changed, 11 insertions(+), 15 deletions(-)
include/linux/bitmap.h +5 -3
@@ -226,9 +226,11 @@ void bitmap_fold(unsigned long *dst, const unsigned long *orig,#define BITMAP_FIRST_WORD_MASK (start) (~0UL << ((start) & (BITS_PER_LONG - 1)))#define BITMAP_LAST_WORD_MASK (nbits) (~0UL >> (-(nbits) & (BITS_PER_LONG - 1))) +#define bitmap_size (nbits) (ALIGN(nbits, BITS_PER_LONG) / BITS_PER_BYTE) +static inline void bitmap_zero (unsigned long *dst,unsigned int nbits) { -unsigned int len =BITS_TO_LONGS (nbits) *sizeof (unsigned long ); +unsigned int len =bitmap_size (nbits);if (small_const_nbits (nbits)) *dst =0 ;
@@ -238,7 +240,7 @@ static inline void bitmap_zero(unsigned long *dst, unsigned int nbits)static inline void bitmap_fill (unsigned long *dst,unsigned int nbits) { -unsigned int len =BITS_TO_LONGS (nbits) *sizeof (unsigned long ); +unsigned int len =bitmap_size (nbits);if (small_const_nbits (nbits)) *dst = ~0UL ;
@@ -249,7 +251,7 @@ static inline void bitmap_fill(unsigned long *dst, unsigned int nbits)static inline void bitmap_copy (unsigned long *dst,const unsigned long *src,unsigned int nbits) { -unsigned int len =BITS_TO_LONGS (nbits) *sizeof (unsigned long ); +unsigned int len =bitmap_size (nbits);if (small_const_nbits (nbits)) *dst = *src;
include/linux/cpumask.h +1 -1
@@ -853,7 +853,7 @@ static inline int cpulist_parse(const char *buf, struct cpumask *dstp)*/ static inline unsigned int cpumask_size (void ) { -return BITS_TO_LONGS (large_cpumask_bits) *sizeof (long ); +return bitmap_size (large_cpumask_bits); }/*
tools/include/linux/bitmap.h +4 -3
@@ -26,13 +26,14 @@ bool __bitmap_intersects(const unsigned long *bitmap1,#define BITMAP_FIRST_WORD_MASK (start) (~0UL << ((start) & (BITS_PER_LONG - 1)))#define BITMAP_LAST_WORD_MASK (nbits) (~0UL >> (-(nbits) & (BITS_PER_LONG - 1))) +#define bitmap_size (nbits) (ALIGN(nbits, BITS_PER_LONG) / BITS_PER_BYTE) +static inline void bitmap_zero (unsigned long *dst,unsigned int nbits) {if (small_const_nbits (nbits)) *dst =0UL ;else { -int len =BITS_TO_LONGS (nbits) *sizeof (unsigned long ); -memset (dst,0 , len); +memset (dst,0 ,bitmap_size (nbits)); } }
@@ -84,7 +85,7 @@ static inline void bitmap_or(unsigned long *dst, const unsigned long *src1,*/ static inline unsigned long *bitmap_zalloc (int nbits) { -return calloc (1 ,BITS_TO_LONGS (nbits) *sizeof (unsigned long )); +return calloc (1 ,bitmap_size (nbits)); }/*
drivers/md/dm-clone-metadata.c +0 -5
@@ -465,11 +465,6 @@ static void __destroy_persistent_data_structures(struct dm_clone_metadata *cmd)/*---------------------------------------------------------------------------*/ -static size_t bitmap_size (unsigned long nr_bits) -{ -return BITS_TO_LONGS (nr_bits) *sizeof (long ); -} -static int __dirty_map_init (struct dirty_map *dmap,unsigned long nr_words,unsigned long nr_regions) {
drivers/s390/cio/idset.c +1 -1
@@ -18,7 +18,7 @@ struct idset {static inline unsigned long idset_bitmap_size (int num_ssid,int num_id) { -return BITS_TO_LONGS (num_ssid * num_id) *sizeof (unsigned long ); +return bitmap_size (size_mul (num_ssid, num_id)); }static struct idset *idset_new (int num_ssid,int num_id)
lib/math/prime_numbers.c +0 -2
@@ -6,8 +6,6 @@#include <linux/prime_numbers.h> #include <linux/slab.h> -#define bitmap_size (nbits) (BITS_TO_LONGS(nbits) * sizeof(unsigned long)) -struct primes {struct rcu_head rcu;unsigned long last, sz;
Signature · 1 line
2.44.0
PATCH v6 13/21 bitmap: make bitmap_{get,set}_value8() use bitmap_{read,write}()
In reply to Alexander LobakinNow that we have generic bitmap_read() and bitmap_write(), which are inline and try to take care of non-bound-crossing and aligned cases to keep them optimized, collapse bitmap_{get,set}_value8() into simple wrappers around the former ones.
bloat-o-meter shows no difference in vmlinux and -2 bytes for gpio-pca953x.ko, which says the optimization didn't suffer due to that change. The converted helpers have the value width embedded and always compile-time constant and that helps a lot.
--- include/linux/bitmap.h | 38 +++++--------------------------------- 1 file changed, 5 insertions(+), 33 deletions(-)
include/linux/bitmap.h +5 -33
@@ -727,39 +727,6 @@ static inline void bitmap_from_u64(unsigned long *dst, u64 mask)bitmap_from_arr64 (dst, &mask,64 ); } -/** -* bitmap_get_value8 - get an 8-bit value within a memory region -* @map: address to the bitmap memory region -* @start: bit offset of the 8-bit value; must be a multiple of 8 -* -* Returns the 8-bit value located at the @start bit offset within the @src -* memory region. -*/ -static inline unsigned long bitmap_get_value8 (const unsigned long *map, -unsigned long start) -{ -const size_t index =BIT_WORD (start); -const unsigned long offset = start %BITS_PER_LONG ; - -return (map[index] >> offset) &0xFF ; -} - -/** -* bitmap_set_value8 - set an 8-bit value within a memory region -* @map: address to the bitmap memory region -* @value: the 8-bit value; values wider than 8 bits may clobber bitmap -* @start: bit offset of the 8-bit value; must be a multiple of 8 -*/ -static inline void bitmap_set_value8 (unsigned long *map,unsigned long value, -unsigned long start) -{ -const size_t index =BIT_WORD (start); -const unsigned long offset = start %BITS_PER_LONG ; - - map[index] &= ~(0xFFUL << offset); - map[index] |= value << offset; -} -/** * bitmap_read - read a value of n-bits from the memory region * @map: address to the bitmap memory region
@@ -833,6 +800,11 @@ static inline void bitmap_write(unsigned long *map, unsigned long value, map[index +1 ] |= (value >> space); } +#define bitmap_get_value8 (map, start) \ + bitmap_read(map, start, BITS_PER_BYTE) +#define bitmap_set_value8 (map, value, start) \ + bitmap_write(map, value, start, BITS_PER_BYTE) +#endif /* __ASSEMBLY__ */ #endif /* __LINUX_BITMAP_H */
Signature · 1 line
2.44.0
Re: [PATCH net-next v6 13/21] bitmap: make bitmap_{get,set}_value8() use bitmap_{read,write}()
Hi Alexander,
Quoted 8 lines · Alexander Lobakin
Now that we have generic
bitmap_read()andbitmap_write(), which are inline and try to take care of non-bound-crossing and aligned cases to keep them optimized, collapse bitmap_{get,set}_value8() into simple wrappers around the former ones.
bloat-o-meter shows no difference in vmlinux and -2 bytes for gpio-pca953x.ko, which says the optimization didn't suffer due to that change. The converted helpers have the value width embedded and always compile-time constant and that helps a lot.
This change appears to have introduced a build failure for me on arm64 (with GCC 9.4.0 from Ubuntu 20.04.02) - reverting b44759705f7d makes these errors go away again:
In file included from drivers/gpio/gpio-pca953x.c:12:drivers/gpio/gpio-pca953x.c: In function ‘pca953x_probe’:./include/linux/bitmap.h:799:17: error: array subscript [1, 1024] is outside array bounds of ‘long unsigned int[1]’ [-Werror=array-bounds]
799 | map[index + 1] &= BITMAP_FIRST_WORD_MASK(start + nbits);
| ^~
In file included from ./include/linux/atomic.h:5,
from drivers/gpio/gpio-pca953x.c:11:
drivers/gpio/gpio-pca953x.c:1015:17: note: while referencing ‘val’
1015 | DECLARE_BITMAP(val, MAX_LINE);
| ^~~./include/linux/types.h:11:16: note: in definition of macro ‘DECLARE_BITMAP’
11 | unsigned long name[BITS_TO_LONGS(bits)]
| ^~~~
In file included from drivers/gpio/gpio-pca953x.c:12:./include/linux/bitmap.h:800:17: error: array subscript [1, 1024] is outside array bounds of ‘long unsigned int[1]’ [-Werror=array-bounds]
800 | map[index + 1] |= (value >> space);
| ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
In file included from ./include/linux/atomic.h:5,
from drivers/gpio/gpio-pca953x.c:11:drivers/gpio/gpio-pca953x.c:1015:17: note: while referencing ‘val’
1015 | DECLARE_BITMAP(val, MAX_LINE);
| ^~~./include/linux/types.h:11:16: note: in definition of macro ‘DECLARE_BITMAP’
11 | unsigned long name[BITS_TO_LONGS(bits)]
| ^~~~
I've not dug further since I don't have any interest in the pca953x driver - it just happened to be enabled in my config, so for now I've turned it off. However I couldn't obviously see any other reports of this, so here it is.
Thanks,
Robin.
Yury Norov
maintainerRe: [PATCH net-next v6 13/21] bitmap: make bitmap_{get,set}_value8() use bitmap_{read,write}()
Quoted 42 lines · Robin Murphy
Hi Alexander,
Quoted 8 lines · Alexander Lobakin
Now that we have generic
bitmap_read()andbitmap_write(), which are inline and try to take care of non-bound-crossing and aligned cases to keep them optimized, collapse bitmap_{get,set}_value8() into simple wrappers around the former ones.
bloat-o-meter shows no difference in vmlinux and -2 bytes for gpio-pca953x.ko, which says the optimization didn't suffer due to that change. The converted helpers have the value width embedded and always compile-time constant and that helps a lot.This change appears to have introduced a build failure for me on arm64 (with GCC 9.4.0 from Ubuntu 20.04.02) - reverting
b44759705f7dmakes these errors go away again:In file included from
drivers/gpio/gpio-pca953x.c:12:drivers/gpio/gpio-pca953x.c: In function ‘pca953x_probe’:./include/linux/bitmap.h:799:17: error: array subscript [1, 1024] is outside array bounds of ‘long unsigned int[1]’ [-Werror=array-bounds]
799 | map[index + 1] &=BITMAP_FIRST_WORD_MASK(start + nbits);
| ^~
In file included from./include/linux/atomic.h:5,from drivers/gpio/gpio-pca953x.c:11:
drivers/gpio/gpio-pca953x.c:1015:17: note: while referencing ‘val’
1015 |DECLARE_BITMAP(val, MAX_LINE);
| ^~~./include/linux/types.h:11:16: note: in definition of macro ‘DECLARE_BITMAP’
11 | unsigned long name[BITS_TO_LONGS(bits)]
| ^~~~
In file included fromdrivers/gpio/gpio-pca953x.c:12:./include/linux/bitmap.h:800:17: error: array subscript [1, 1024] is outside array bounds of ‘long unsigned int[1]’ [-Werror=array-bounds]800 | map[index + 1] |= (value >> space); | ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~ In file included from ./include/linux/atomic.h:5, from drivers/gpio/gpio-pca953x.c:11:
drivers/gpio/gpio-pca953x.c:1015:17: note: while referencing ‘val’
1015 |DECLARE_BITMAP(val, MAX_LINE);
| ^~~./include/linux/types.h:11:16: note: in definition of macro ‘DECLARE_BITMAP’
11 | unsigned long name[BITS_TO_LONGS(bits)]
| ^~~~
Quoted 4 lines
I've not dug further since I don't have any interest in the pca953x driver - it just happened to be enabled in my config, so for now I've turned it off. However I couldn't obviously see any other reports of this, so here it is.
It's a compiler false-positive. The straightforward fix is to disable the warning For gcc9+, and it's in Andrew Morton's tree alrady. but there's some discussion ongoing on how it should be mitigated properlu:
https://lore.kernel.org/all/[email protected]/T/
Thanks,
YUry
Re: [PATCH net-next v6 13/21] bitmap: make bitmap_{get,set}_value8() use bitmap_{read,write}()
Quoted 48 lines · Yury Norov
Quoted 42 lines · Robin Murphy
Hi Alexander,
Quoted 8 lines · Alexander Lobakin
Now that we have generic
bitmap_read()andbitmap_write(), which are inline and try to take care of non-bound-crossing and aligned cases to keep them optimized, collapse bitmap_{get,set}_value8() into simple wrappers around the former ones.
bloat-o-meter shows no difference in vmlinux and -2 bytes for gpio-pca953x.ko, which says the optimization didn't suffer due to that change. The converted helpers have the value width embedded and always compile-time constant and that helps a lot.This change appears to have introduced a build failure for me on arm64 (with GCC 9.4.0 from Ubuntu 20.04.02) - reverting
b44759705f7dmakes these errors go away again:In file included from
drivers/gpio/gpio-pca953x.c:12:drivers/gpio/gpio-pca953x.c: In function ‘pca953x_probe’:./include/linux/bitmap.h:799:17: error: array subscript [1, 1024] is outside array bounds of ‘long unsigned int[1]’ [-Werror=array-bounds]
799 | map[index + 1] &=BITMAP_FIRST_WORD_MASK(start + nbits);
| ^~
In file included from./include/linux/atomic.h:5,from drivers/gpio/gpio-pca953x.c:11:
drivers/gpio/gpio-pca953x.c:1015:17: note: while referencing ‘val’
1015 |DECLARE_BITMAP(val, MAX_LINE);
| ^~~./include/linux/types.h:11:16: note: in definition of macro ‘DECLARE_BITMAP’
11 | unsigned long name[BITS_TO_LONGS(bits)]
| ^~~~
In file included fromdrivers/gpio/gpio-pca953x.c:12:./include/linux/bitmap.h:800:17: error: array subscript [1, 1024] is outside array bounds of ‘long unsigned int[1]’ [-Werror=array-bounds]800 | map[index + 1] |= (value >> space); | ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~ In file included from ./include/linux/atomic.h:5, from drivers/gpio/gpio-pca953x.c:11:
drivers/gpio/gpio-pca953x.c:1015:17: note: while referencing ‘val’
1015 |DECLARE_BITMAP(val, MAX_LINE);
| ^~~./include/linux/types.h:11:16: note: in definition of macro ‘DECLARE_BITMAP’
11 | unsigned long name[BITS_TO_LONGS(bits)]
| ^~~~Quoted 4 lines
I've not dug further since I don't have any interest in the pca953x driver - it just happened to be enabled in my config, so for now I've turned it off. However I couldn't obviously see any other reports of this, so here it is.
Quoted 5 lines
It's a compiler false-positive. The straightforward fix is to disable the warning For gcc9+, and it's in Andrew Morton's tree alrady. but there's some discussion ongoing on how it should be mitigated properlu:
Ah, great! Guess I really should have scrolled further down my lore search results - I assumed I was looking for any other reports of a recent regression in mainline, not ones from 6 months ago :)
Cheers,
Robin.
PATCH v6 14/21 lib/bitmap: add compile-time test for __assign_bit() optimization
In reply to Alexander LobakinCommit dc34d5036692 ("lib: test_bitmap: add compile-time optimization/evaluations assertions") initially missed __assign_bit(), which led to that quite a time passed before I realized it doesn't get optimized at compilation time. Now that it does, add test for that just to make sure nothing will break one day.
To make things more interesting, use bitmap_complement() and bitmap_full(), thus checking their compile-time evaluation as well. And remove the misleading comment mentioning the workaround removed recently in favor of adding the whole file to GCov exceptions.
--- lib/test_bitmap.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
lib/test_bitmap.c +10 -8
@@ -1245,14 +1245,7 @@ static void __init test_bitmap_const_eval(void)* in runtime. */ -/* -* Equals to `unsigned long bitmap[1] = { GENMASK(6, 5), }`. -* Clang on s390 optimizes bitops at compile-time as intended, but at -* the same time stops treating @bitmap and @bitopvar as compile-time -* constants after regular test_bit() is executed, thus triggering the -* build bugs below. So, call const_test_bit() there directly until -* the compiler is fixed. -*/ +/* Equals to `unsigned long bitmap[1] = { GENMASK(6, 5), }` */ bitmap_clear (bitmap,0 ,BITS_PER_LONG );if (!test_bit (7 , bitmap))bitmap_set (bitmap,5 ,2 );
@@ -1284,6 +1277,15 @@ static void __init test_bitmap_const_eval(void)/* ~BIT(25) */ BUILD_BUG_ON (!__builtin_constant_p (~var));BUILD_BUG_ON (~var != ~BIT (25 )); + +/* ~BIT(25) | BIT(25) == ~0UL */ +bitmap_complement (&var, &var,BITS_PER_LONG ); +__assign_bit (25 , &var, true); + +/* !(~(~0UL)) == 1 */ + res =bitmap_full (&var,BITS_PER_LONG ); +BUILD_BUG_ON (!__builtin_constant_p (res)); +BUILD_BUG_ON (!res); }/*
Signature · 1 line
2.44.0
PATCH v6 15/21 ip_tunnel: use a separate struct to store tunnel params in the kernel
In reply to Alexander LobakinUnlike IPv6 tunnels which use purely-kernel __ip6_tnl_parm structure to store params inside the kernel, IPv4 tunnel code uses the same ip_tunnel_parm which is being used to talk with the userspace. This makes it difficult to alter or add any fields or use a different format for whatever data.
Define struct ip_tunnel_parm_kern, a 1:1 copy of ip_tunnel_parm for now, and use it throughout the code. Define the pieces, where the copy user <-> kernel happens, as standalone functions, and copy the data there field-by-field, so that the kernel-side structure could be easily modified later on and the users wouldn't have to care about this.
--- .../ethernet/mellanox/mlxsw/spectrum_ipip.h | 2 +- include/linux/netdevice.h | 7 ++- include/net/ip_tunnels.h | 25 ++++++-- .../ethernet/mellanox/mlxsw/spectrum_ipip.c | 30 +++++---- .../ethernet/mellanox/mlxsw/spectrum_span.c | 4 +- net/ipv4/ip_gre.c | 17 ++--- net/ipv4/ip_tunnel.c | 63 +++++++++++++++---- net/ipv4/ip_tunnel_core.c | 2 +- net/ipv4/ip_vti.c | 12 ++-- net/ipv4/ipip.c | 12 ++-- net/ipv4/ipmr.c | 2 +- net/ipv6/addrconf.c | 3 +- net/ipv6/sit.c | 33 +++++----- 13 files changed, 137 insertions(+), 75 deletions(-)
drivers/net/ethernet/mellanox/mlxsw/spectrum_ipip.h +1 -1
@@ -9,7 +9,7 @@#include <linux/if_tunnel.h> #include <net/ip6_tunnel.h> -struct ip_tunnel_parm +struct ip_tunnel_parm_kern mlxsw_sp_ipip_netdev_parms4 (const struct net_device *ol_dev);struct __ip6_tnl_parm mlxsw_sp_ipip_netdev_parms6 (const struct net_device *ol_dev);
include/linux/netdevice.h +4 -3
@@ -59,7 +59,7 @@ struct ethtool_ops;struct kernel_hwtstamp_config ;struct phy_device ;struct dsa_port ; -struct ip_tunnel_parm ; +struct ip_tunnel_parm_kern ;struct macsec_context ;struct macsec_ops ;struct netdev_name_node ;
@@ -1327,7 +1327,7 @@ struct netdev_net_notifier {* queue id bound to an AF_XDP socket. The flags field specifies if * only RX, only Tx, or both should be woken up using the flags * XDP_WAKEUP_RX and XDP_WAKEUP_TX. -* int (*ndo_tunnel_ctl)(struct net_device *dev, struct ip_tunnel_parm *p, +* int (*ndo_tunnel_ctl)(struct net_device *dev, struct ip_tunnel_parm_kern *p, * int cmd); * Add, change, delete or get information on an IPv4 tunnel. * struct net_device *(*ndo_get_peer_dev)(struct net_device *dev);
@@ -1583,7 +1583,8 @@ struct net_device_ops {int (*ndo_xsk_wakeup)(struct net_device *dev,u32 queue_id,u32 flags);int (*ndo_tunnel_ctl)(struct net_device *dev, -struct ip_tunnel_parm *p,int cmd); +struct ip_tunnel_parm_kern *p, +int cmd);struct net_device * (*ndo_get_peer_dev)(struct net_device *dev);int (*ndo_fill_forward_path)(struct net_device_path_ctx *ctx,struct net_device_path *path);
include/net/ip_tunnels.h +20 -5
@@ -110,6 +110,17 @@ struct ip_tunnel_prl_entry {struct metadata_dst ; +/* Kernel-side copy of ip_tunnel_parm */ +struct ip_tunnel_parm_kern { +char name[IFNAMSIZ ]; +int link; +__be16 i_flags; +__be16 o_flags; +__be32 i_key; +__be32 o_key; +struct iphdr iph; +}; +struct ip_tunnel {struct ip_tunnel __rcu *next;struct hlist_node hash_node;
@@ -136,7 +147,7 @@ struct ip_tunnel {struct dst_cache dst_cache; -struct ip_tunnel_parm parms; +struct ip_tunnel_parm_kern parms;int mlink;int encap_hlen;/* Encap header length (FOU,GUE) */
@@ -291,7 +302,11 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev, const struct iphdr *tnl_params, const u8 protocol);void ip_md_tunnel_xmit (struct sk_buff *skb,struct net_device *dev,const u8 proto,int tunnel_hlen); -int ip_tunnel_ctl (struct net_device *dev,struct ip_tunnel_parm *p,int cmd); +int ip_tunnel_ctl (struct net_device *dev,struct ip_tunnel_parm_kern *p, +int cmd); +bool ip_tunnel_parm_from_user (struct ip_tunnel_parm_kern *kp, +const void __user *data); +bool ip_tunnel_parm_to_user (void __user *data,struct ip_tunnel_parm_kern *kp);int ip_tunnel_siocdevprivate (struct net_device *dev,struct ifreq *ifr,void __user *data,int cmd);int __ip_tunnel_change_mtu (struct net_device *dev,int new_mtu,bool strict);
@@ -307,16 +322,16 @@ int ip_tunnel_rcv(struct ip_tunnel *tunnel, struct sk_buff *skb, const struct tnl_ptk_info *tpi, struct metadata_dst *tun_dst, bool log_ecn_error);int ip_tunnel_changelink (struct net_device *dev,struct nlattr *tb[], -struct ip_tunnel_parm *p,__u32 fwmark); +struct ip_tunnel_parm_kern *p,__u32 fwmark);int ip_tunnel_newlink (struct net_device *dev,struct nlattr *tb[], -struct ip_tunnel_parm *p,__u32 fwmark); +struct ip_tunnel_parm_kern *p,__u32 fwmark);void ip_tunnel_setup (struct net_device *dev,unsigned int net_id);bool ip_tunnel_netlink_encap_parms (struct nlattr *data[],struct ip_tunnel_encap *encap);void ip_tunnel_netlink_parms (struct nlattr *data[], -struct ip_tunnel_parm *parms); +struct ip_tunnel_parm_kern *parms);extern const struct header_ops ip_tunnel_header_ops;__be16 ip_tunnel_parse_protocol (const struct sk_buff *skb);
drivers/net/ethernet/mellanox/mlxsw/spectrum_ipip.c +17 -13
@@ -8,7 +8,7 @@#include "spectrum_ipip.h" #include "reg.h" -struct ip_tunnel_parm +struct ip_tunnel_parm_kern mlxsw_sp_ipip_netdev_parms4 (const struct net_device *ol_dev) {struct ip_tunnel *tun =netdev_priv (ol_dev);
@@ -24,7 +24,8 @@ mlxsw_sp_ipip_netdev_parms6(const struct net_device *ol_dev)return tun->parms; } -static bool mlxsw_sp_ipip_parms4_has_ikey (const struct ip_tunnel_parm *parms) +static bool +mlxsw_sp_ipip_parms4_has_ikey (const struct ip_tunnel_parm_kern *parms) {return !!(parms->i_flags &TUNNEL_KEY ); }
@@ -34,7 +35,8 @@ static bool mlxsw_sp_ipip_parms6_has_ikey(const struct __ip6_tnl_parm *parms)return !!(parms->i_flags &TUNNEL_KEY ); } -static bool mlxsw_sp_ipip_parms4_has_okey (const struct ip_tunnel_parm *parms) +static bool +mlxsw_sp_ipip_parms4_has_okey (const struct ip_tunnel_parm_kern *parms) {return !!(parms->o_flags &TUNNEL_KEY ); }
@@ -44,7 +46,7 @@ static bool mlxsw_sp_ipip_parms6_has_okey(const struct __ip6_tnl_parm *parms)return !!(parms->o_flags &TUNNEL_KEY ); } -static u32 mlxsw_sp_ipip_parms4_ikey (const struct ip_tunnel_parm *parms) +static u32 mlxsw_sp_ipip_parms4_ikey (const struct ip_tunnel_parm_kern *parms) {return mlxsw_sp_ipip_parms4_has_ikey (parms) ?be32_to_cpu (parms->i_key) :0 ;
@@ -56,7 +58,7 @@ static u32 mlxsw_sp_ipip_parms6_ikey(const struct __ip6_tnl_parm *parms) be32_to_cpu(parms->i_key) : 0; } -static u32 mlxsw_sp_ipip_parms4_okey (const struct ip_tunnel_parm *parms) +static u32 mlxsw_sp_ipip_parms4_okey (const struct ip_tunnel_parm_kern *parms) {return mlxsw_sp_ipip_parms4_has_okey (parms) ?be32_to_cpu (parms->o_key) :0 ;
@@ -69,7 +71,7 @@ static u32 mlxsw_sp_ipip_parms6_okey(const struct __ip6_tnl_parm *parms) }static union mlxsw_sp_l3addr -mlxsw_sp_ipip_parms4_saddr (const struct ip_tunnel_parm *parms) +mlxsw_sp_ipip_parms4_saddr (const struct ip_tunnel_parm_kern *parms) {return (union mlxsw_sp_l3addr ) { .addr4 = parms->iph.saddr }; }
@@ -81,7 +83,7 @@ mlxsw_sp_ipip_parms6_saddr(const struct __ip6_tnl_parm *parms) }static union mlxsw_sp_l3addr -mlxsw_sp_ipip_parms4_daddr (const struct ip_tunnel_parm *parms) +mlxsw_sp_ipip_parms4_daddr (const struct ip_tunnel_parm_kern *parms) {return (union mlxsw_sp_l3addr ) { .addr4 = parms->iph.daddr }; }
@@ -96,7 +98,7 @@ union mlxsw_sp_l3addr mlxsw_sp_ipip_netdev_saddr(enum mlxsw_sp_l3proto proto, const struct net_device *ol_dev) { - struct ip_tunnel_parm parms4; + struct ip_tunnel_parm_kern parms4;struct __ip6_tnl_parm parms6;switch (proto) {
@@ -115,7 +117,9 @@ mlxsw_sp_ipip_netdev_saddr(enum mlxsw_sp_l3proto proto,static __be32 mlxsw_sp_ipip_netdev_daddr4 (const struct net_device *ol_dev) { -struct ip_tunnel_parm parms4 =mlxsw_sp_ipip_netdev_parms4 (ol_dev); +struct ip_tunnel_parm_kern parms4; + + parms4 =mlxsw_sp_ipip_netdev_parms4 (ol_dev);return mlxsw_sp_ipip_parms4_daddr (&parms4).addr4; }
@@ -124,7 +128,7 @@ static union mlxsw_sp_l3addr mlxsw_sp_ipip_netdev_daddr(enum mlxsw_sp_l3proto proto, const struct net_device *ol_dev) { - struct ip_tunnel_parm parms4; + struct ip_tunnel_parm_kern parms4;struct __ip6_tnl_parm parms6;switch (proto) {
@@ -150,7 +154,7 @@ bool mlxsw_sp_l3addr_is_zero(union mlxsw_sp_l3addr addr)static struct mlxsw_sp_ipip_parms mlxsw_sp_ipip_netdev_parms_init_gre4 (const struct net_device *ol_dev) { -struct ip_tunnel_parm parms =mlxsw_sp_ipip_netdev_parms4 (ol_dev); +struct ip_tunnel_parm_kern parms =mlxsw_sp_ipip_netdev_parms4 (ol_dev);return (struct mlxsw_sp_ipip_parms ) { .proto =MLXSW_SP_L3_PROTO_IPV4 ,
@@ -187,8 +191,8 @@ mlxsw_sp_ipip_decap_config_gre4(struct mlxsw_sp *mlxsw_sp, {u16 rif_index =mlxsw_sp_ipip_lb_rif_index (ipip_entry->ol_lb);u16 ul_rif_id =mlxsw_sp_ipip_lb_ul_rif_id (ipip_entry->ol_lb); +struct ip_tunnel_parm_kern parms;char rtdp_pl[MLXSW_REG_RTDP_LEN ]; -struct ip_tunnel_parm parms;unsigned int type_check;bool has_ikey;u32 daddr4;
@@ -252,7 +256,7 @@ static struct mlxsw_sp_rif_ipip_lb_config mlxsw_sp_ipip_ol_loopback_config_gre4(struct mlxsw_sp *mlxsw_sp, const struct net_device *ol_dev) { - struct ip_tunnel_parm parms = mlxsw_sp_ipip_netdev_parms4(ol_dev); + struct ip_tunnel_parm_kern parms = mlxsw_sp_ipip_netdev_parms4(ol_dev);enum mlxsw_reg_ritr_loopback_ipip_type lb_ipipt; lb_ipipt = mlxsw_sp_ipip_parms4_has_okey(&parms) ?
drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c +2 -2
@@ -413,8 +413,8 @@ mlxsw_sp_span_gretap4_route(const struct net_device *to_dev, __be32 *saddrp, __be32 *daddrp) {struct ip_tunnel *tun =netdev_priv (to_dev); +struct ip_tunnel_parm_kern parms;struct net_device *dev =NULL ; -struct ip_tunnel_parm parms;struct rtable *rt =NULL ;struct flowi4 fl4;
@@ -451,7 +451,7 @@ mlxsw_sp_span_entry_gretap4_parms(struct mlxsw_sp *mlxsw_sp,const struct net_device *to_dev, struct mlxsw_sp_span_parms *sparmsp) { - struct ip_tunnel_parm tparm = mlxsw_sp_ipip_netdev_parms4(to_dev); + struct ip_tunnel_parm_kern tparm = mlxsw_sp_ipip_netdev_parms4(to_dev);union mlxsw_sp_l3addr saddr = { .addr4 = tparm.iph.saddr };union mlxsw_sp_l3addr daddr = { .addr4 = tparm.iph.daddr };bool inherit_tos = tparm.iph.tos &0x1 ;
net/ipv4/ip_gre.c +9 -8
@@ -785,7 +785,8 @@ static void ipgre_link_update(struct net_device *dev, bool set_mtu) } } -static int ipgre_tunnel_ctl (struct net_device *dev,struct ip_tunnel_parm *p, +static int ipgre_tunnel_ctl (struct net_device *dev, +struct ip_tunnel_parm_kern *p,int cmd) {int err;
@@ -1131,7 +1132,7 @@ static int erspan_validate(struct nlattr *tb[], struct nlattr *data[],static int ipgre_netlink_parms (struct net_device *dev,struct nlattr *data[],struct nlattr *tb[], -struct ip_tunnel_parm *parms, +struct ip_tunnel_parm_kern *parms,__u32 *fwmark) {struct ip_tunnel *t =netdev_priv (dev);
@@ -1198,7 +1199,7 @@ static int ipgre_netlink_parms(struct net_device *dev,static int erspan_netlink_parms (struct net_device *dev,struct nlattr *data[],struct nlattr *tb[], -struct ip_tunnel_parm *parms, +struct ip_tunnel_parm_kern *parms,__u32 *fwmark) {struct ip_tunnel *t =netdev_priv (dev);
@@ -1357,7 +1358,7 @@ static int ipgre_newlink(struct net *src_net, struct net_device *dev, struct nlattr *tb[], struct nlattr *data[], struct netlink_ext_ack *extack) { - struct ip_tunnel_parm p; + struct ip_tunnel_parm_kern p;__u32 fwmark =0 ;int err;
@@ -1375,7 +1376,7 @@ static int erspan_newlink(struct net *src_net, struct net_device *dev, struct nlattr *tb[], struct nlattr *data[], struct netlink_ext_ack *extack) { - struct ip_tunnel_parm p; + struct ip_tunnel_parm_kern p;__u32 fwmark =0 ;int err;
@@ -1394,8 +1395,8 @@ static int ipgre_changelink(struct net_device *dev, struct nlattr *tb[], struct netlink_ext_ack *extack) {struct ip_tunnel *t =netdev_priv (dev); +struct ip_tunnel_parm_kern p;__u32 fwmark = t->fwmark; -struct ip_tunnel_parm p;int err; err =ipgre_newlink_encap_setup (dev, data);
@@ -1423,8 +1424,8 @@ static int erspan_changelink(struct net_device *dev, struct nlattr *tb[], struct netlink_ext_ack *extack) {struct ip_tunnel *t =netdev_priv (dev); +struct ip_tunnel_parm_kern p;__u32 fwmark = t->fwmark; -struct ip_tunnel_parm p;int err; err =ipgre_newlink_encap_setup (dev, data);
@@ -1496,7 +1497,7 @@ static size_t ipgre_get_size(const struct net_device *dev)static int ipgre_fill_info (struct sk_buff *skb,const struct net_device *dev) {struct ip_tunnel *t =netdev_priv (dev); -struct ip_tunnel_parm *p = &t->parms; +struct ip_tunnel_parm_kern *p = &t->parms;__be16 o_flags = p->o_flags; if (nla_put_u32(skb, IFLA_GRE_LINK, p->link) ||
net/ipv4/ip_tunnel.c +50 -13
136 lines not on this page · raw message
net/ipv4/ip_tunnel_core.c +1 -1
@@ -1116,7 +1116,7 @@ bool ip_tunnel_netlink_encap_parms(struct nlattr *data[],EXPORT_SYMBOL_GPL (ip_tunnel_netlink_encap_parms);void ip_tunnel_netlink_parms (struct nlattr *data[], -struct ip_tunnel_parm *parms) +struct ip_tunnel_parm_kern *parms) {if (data[IFLA_IPTUN_LINK ]) parms->link =nla_get_u32 (data[IFLA_IPTUN_LINK ]);
net/ipv4/ip_vti.c +6 -6
@@ -167,7 +167,7 @@ static netdev_tx_t vti_xmit(struct sk_buff *skb, struct net_device *dev, struct flowi *fl) {struct ip_tunnel *tunnel =netdev_priv (dev); -struct ip_tunnel_parm *parms = &tunnel->parms; +struct ip_tunnel_parm_kern *parms = &tunnel->parms;struct dst_entry *dst =skb_dst (skb);struct net_device *tdev;/* Device to other host */ int pkt_len = skb->len;
@@ -373,7 +373,7 @@ static int vti4_err(struct sk_buff *skb, u32 info) }static int -vti_tunnel_ctl (struct net_device *dev,struct ip_tunnel_parm *p,int cmd) +vti_tunnel_ctl (struct net_device *dev,struct ip_tunnel_parm_kern *p,int cmd) {int err =0 ;
@@ -531,7 +531,7 @@ static int vti_tunnel_validate(struct nlattr *tb[], struct nlattr *data[], }static void vti_netlink_parms (struct nlattr *data[], -struct ip_tunnel_parm *parms, +struct ip_tunnel_parm_kern *parms,__u32 *fwmark) {memset (parms,0 ,sizeof (*parms));
@@ -566,7 +566,7 @@ static int vti_newlink(struct net *src_net, struct net_device *dev, struct nlattr *tb[], struct nlattr *data[], struct netlink_ext_ack *extack) { - struct ip_tunnel_parm parms; + struct ip_tunnel_parm_kern parms;__u32 fwmark =0 ;vti_netlink_parms (data, &parms, &fwmark);
@@ -578,8 +578,8 @@ static int vti_changelink(struct net_device *dev, struct nlattr *tb[], struct netlink_ext_ack *extack) {struct ip_tunnel *t =netdev_priv (dev); +struct ip_tunnel_parm_kern p;__u32 fwmark = t->fwmark; -struct ip_tunnel_parm p;vti_netlink_parms (data, &p, &fwmark);return ip_tunnel_changelink (dev, tb, &p, fwmark);
@@ -606,7 +606,7 @@ static size_t vti_get_size(const struct net_device *dev)static int vti_fill_info (struct sk_buff *skb,const struct net_device *dev) {struct ip_tunnel *t =netdev_priv (dev); -struct ip_tunnel_parm *p = &t->parms; +struct ip_tunnel_parm_kern *p = &t->parms; if (nla_put_u32(skb, IFLA_VTI_LINK, p->link) || nla_put_be32(skb, IFLA_VTI_IKEY, p->i_key) ||
net/ipv4/ipip.c +6 -6
@@ -330,7 +330,7 @@ static bool ipip_tunnel_ioctl_verify_protocol(u8 ipproto) }static int -ipip_tunnel_ctl (struct net_device *dev,struct ip_tunnel_parm *p,int cmd) +ipip_tunnel_ctl (struct net_device *dev,struct ip_tunnel_parm_kern *p,int cmd) {if (cmd ==SIOCADDTUNNEL || cmd ==SIOCCHGTUNNEL ) { if (p->iph.version != 4 ||
@@ -405,8 +405,8 @@ static int ipip_tunnel_validate(struct nlattr *tb[], struct nlattr *data[], }static void ipip_netlink_parms (struct nlattr *data[], -struct ip_tunnel_parm *parms,bool *collect_md, -__u32 *fwmark) +struct ip_tunnel_parm_kern *parms, +bool *collect_md,__u32 *fwmark) {memset (parms,0 ,sizeof (*parms));
@@ -432,8 +432,8 @@ static int ipip_newlink(struct net *src_net, struct net_device *dev, struct netlink_ext_ack *extack) {struct ip_tunnel *t =netdev_priv (dev); -struct ip_tunnel_parm p;struct ip_tunnel_encap ipencap; +struct ip_tunnel_parm_kern p;__u32 fwmark =0 ;if (ip_tunnel_netlink_encap_parms (data, &ipencap)) {
@@ -452,8 +452,8 @@ static int ipip_changelink(struct net_device *dev, struct nlattr *tb[], struct netlink_ext_ack *extack) {struct ip_tunnel *t =netdev_priv (dev); -struct ip_tunnel_parm p;struct ip_tunnel_encap ipencap; +struct ip_tunnel_parm_kern p;bool collect_md;__u32 fwmark = t->fwmark;
@@ -510,7 +510,7 @@ static size_t ipip_get_size(const struct net_device *dev)static int ipip_fill_info (struct sk_buff *skb,const struct net_device *dev) {struct ip_tunnel *tunnel =netdev_priv (dev); -struct ip_tunnel_parm *parm = &tunnel->parms; +struct ip_tunnel_parm_kern *parm = &tunnel->parms; if (nla_put_u32(skb, IFLA_IPTUN_LINK, parm->link) || nla_put_in_addr(skb, IFLA_IPTUN_LOCAL, parm->iph.saddr) ||
net/ipv4/ipmr.c +1 -1
@@ -441,7 +441,7 @@ static bool ipmr_init_vif_indev(const struct net_device *dev)static struct net_device *ipmr_new_tunnel (struct net *net,struct vifctl *v) {struct net_device *tunnel_dev, *new_dev; -struct ip_tunnel_parm p = { }; +struct ip_tunnel_parm_kern p = { };int err; tunnel_dev =__dev_get_by_name (net,"tunl0" );
net/ipv6/addrconf.c +2 -1
@@ -63,6 +63,7 @@#include <linux/string.h> #include <linux/hash.h> +#include <net/ip_tunnels.h> #include <net/net_namespace.h> #include <net/sock.h> #include <net/snmp.h>
@@ -2917,7 +2918,7 @@ void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len, bool sllao)static int addrconf_set_sit_dstaddr (struct net *net,struct net_device *dev,struct in6_ifreq *ireq) { -struct ip_tunnel_parm p = { }; +struct ip_tunnel_parm_kern p = { };int err;if (!(ipv6_addr_type (&ireq->ifr6_addr) & IPV6_ADDR_COMPATv4))
net/ipv6/sit.c +18 -15
@@ -132,8 +132,8 @@ static struct ip_tunnel *ipip6_tunnel_lookup(struct net *net,return NULL ; } -static struct ip_tunnel __rcu **__ipip6_bucket (struct sit_net *sitn, -struct ip_tunnel_parm *parms) +static struct ip_tunnel __rcu ** +__ipip6_bucket (struct sit_net *sitn,struct ip_tunnel_parm_kern *parms) {__be32 remote = parms->iph.daddr;__be32 local = parms->iph.saddr;
@@ -226,7 +226,8 @@ static int ipip6_tunnel_create(struct net_device *dev) }static struct ip_tunnel *ipip6_tunnel_locate (struct net *net, -struct ip_tunnel_parm *parms,int create) +struct ip_tunnel_parm_kern *parms, +int create) {__be32 remote = parms->iph.daddr;__be32 local = parms->iph.saddr;
@@ -1135,7 +1136,8 @@ static void ipip6_tunnel_bind_dev(struct net_device *dev) dev->needed_headroom = t_hlen + hlen; } -static void ipip6_tunnel_update (struct ip_tunnel *t,struct ip_tunnel_parm *p, +static void ipip6_tunnel_update (struct ip_tunnel *t, +struct ip_tunnel_parm_kern *p,__u32 fwmark) {struct net *net = t->net;
@@ -1196,11 +1198,11 @@ static int ipip6_tunnel_get6rd(struct net_device *dev, struct ip_tunnel_parm __user *data) { struct ip_tunnel *t = netdev_priv(dev); +struct ip_tunnel_parm_kern p;struct ip_tunnel_6rd ip6rd; -struct ip_tunnel_parm p;if (dev ==dev_to_sit_net (dev)->fb_tunnel_dev) { -if (copy_from_user (&p, data,sizeof (p))) +if (!ip_tunnel_parm_from_user (&p, data))return -EFAULT ; t =ipip6_tunnel_locate (t->net, &p,0 ); }
@@ -1251,7 +1253,7 @@ static bool ipip6_valid_ip_proto(u8 ipproto) }static int -__ipip6_tunnel_ioctl_validate (struct net *net,struct ip_tunnel_parm *p) +__ipip6_tunnel_ioctl_validate (struct net *net,struct ip_tunnel_parm_kern *p) {if (!ns_capable (net->user_ns,CAP_NET_ADMIN ))return -EPERM ;
@@ -1268,7 +1270,7 @@ __ipip6_tunnel_ioctl_validate(struct net *net, struct ip_tunnel_parm *p) }static int -ipip6_tunnel_get (struct net_device *dev,struct ip_tunnel_parm *p) +ipip6_tunnel_get (struct net_device *dev,struct ip_tunnel_parm_kern *p) {struct ip_tunnel *t =netdev_priv (dev);
@@ -1281,7 +1283,7 @@ ipip6_tunnel_get(struct net_device *dev, struct ip_tunnel_parm *p) }static int -ipip6_tunnel_add (struct net_device *dev,struct ip_tunnel_parm *p) +ipip6_tunnel_add (struct net_device *dev,struct ip_tunnel_parm_kern *p) {struct ip_tunnel *t =netdev_priv (dev);int err;
@@ -1297,7 +1299,7 @@ ipip6_tunnel_add(struct net_device *dev, struct ip_tunnel_parm *p) }static int -ipip6_tunnel_change (struct net_device *dev,struct ip_tunnel_parm *p) +ipip6_tunnel_change (struct net_device *dev,struct ip_tunnel_parm_kern *p) {struct ip_tunnel *t =netdev_priv (dev);int err;
@@ -1328,7 +1330,7 @@ ipip6_tunnel_change(struct net_device *dev, struct ip_tunnel_parm *p) }static int -ipip6_tunnel_del (struct net_device *dev,struct ip_tunnel_parm *p) +ipip6_tunnel_del (struct net_device *dev,struct ip_tunnel_parm_kern *p) {struct ip_tunnel *t =netdev_priv (dev);
@@ -1348,7 +1350,8 @@ ipip6_tunnel_del(struct net_device *dev, struct ip_tunnel_parm *p) }static int -ipip6_tunnel_ctl (struct net_device *dev,struct ip_tunnel_parm *p,int cmd) +ipip6_tunnel_ctl (struct net_device *dev,struct ip_tunnel_parm_kern *p, +int cmd) {switch (cmd) {case SIOCGETTUNNEL :
@@ -1490,7 +1493,7 @@ static int ipip6_validate(struct nlattr *tb[], struct nlattr *data[], }static void ipip6_netlink_parms (struct nlattr *data[], -struct ip_tunnel_parm *parms, +struct ip_tunnel_parm_kern *parms,__u32 *fwmark) {memset (parms,0 ,sizeof (*parms));
@@ -1599,8 +1602,8 @@ static int ipip6_changelink(struct net_device *dev, struct nlattr *tb[], struct netlink_ext_ack *extack) {struct ip_tunnel *t =netdev_priv (dev); -struct ip_tunnel_parm p;struct ip_tunnel_encap ipencap; +struct ip_tunnel_parm_kern p;struct net *net = t->net;struct sit_net *sitn =net_generic (net, sit_net_id);#ifdef CONFIG_IPV6_SIT_6RD
@@ -1687,7 +1690,7 @@ static size_t ipip6_get_size(const struct net_device *dev)static int ipip6_fill_info (struct sk_buff *skb,const struct net_device *dev) {struct ip_tunnel *tunnel =netdev_priv (dev); -struct ip_tunnel_parm *parm = &tunnel->parms; +struct ip_tunnel_parm_kern *parm = &tunnel->parms; if (nla_put_u32(skb, IFLA_IPTUN_LINK, parm->link) || nla_put_in_addr(skb, IFLA_IPTUN_LOCAL, parm->iph.saddr) ||
Signature · 1 line
2.44.0
Re: [PATCH net-next v6 15/21] ip_tunnel: use a separate struct to store tunnel params in the kernel
net/ipv4/ip_tunnel.c int ip_tunnel_ctl(struct net_device *dev, struct ip_tunnel_parm *p, int cmd) · line 1033
Quoted 5 lines · Alexander Lobakin
net/ipv4/ip_tunnel.c +5
-0+bool ip_tunnel_parm_to_user (void __user *data,struct ip_tunnel_parm_kern *kp) +{ +struct ip_tunnel_parm p; + +strscpy (p.name, kp->name);
We need to clear out p before copying to user space to avoid an information leak. So this strscpy() needs to be strcpy_pad()
net/ipv4/ip_tunnel.c int ip_tunnel_ctl(struct net_device *dev, struct ip_tunnel_parm *p, int cmd) · line 1039
Quoted 6 lines
net/ipv4/ip_tunnel.c +6
-0+ p.link = kp->link; + p.i_flags = kp->i_flags; + p.o_flags = kp->o_flags; + p.i_key = kp->i_key; + p.o_key = kp->o_key; +memcpy (&p.iph, &kp->iph,min (sizeof (p.iph),sizeof (kp->iph)));
And this memcpy() doesn't necessarily clear the whole of p.iph.
net/ipv4/ip_tunnel.c int ip_tunnel_ctl(struct net_device *dev, struct ip_tunnel_parm *p, int cmd) · line 1042
Quoted 3 lines
net/ipv4/ip_tunnel.c +3
-0+ +return !copy_to_user (data, &p,sizeof (p)); +}
regards,
dan carpenter
Re: [PATCH net-next v6 15/21] ip_tunnel: use a separate struct to store tunnel params in the kernel
From: Dan Carpenter <[email protected]>
Date: Thu, 4 Apr 2024 17:24:23 +0300
Quoted 10 lines · Alexander Lobakin
net/ipv4/ip_tunnel.c int ip_tunnel_ctl(struct net_device *dev, struct ip_tunnel_parm *p, int cmd) · line 1033
Quoted 5 lines
net/ipv4/ip_tunnel.c +5
-0+bool ip_tunnel_parm_to_user (void __user *data,struct ip_tunnel_parm_kern *kp) +{ +struct ip_tunnel_parm p; + +strscpy (p.name, kp->name);We need to clear out p before copying to user space to avoid an information leak. So this
strscpy()needs to bestrcpy_pad()
Quoted 8 lines
net/ipv4/ip_tunnel.c int ip_tunnel_ctl(struct net_device *dev, struct ip_tunnel_parm *p, int cmd) · line 1039
Quoted 6 lines
net/ipv4/ip_tunnel.c +6
-0+ p.link = kp->link; + p.i_flags = kp->i_flags; + p.o_flags = kp->o_flags; + p.i_key = kp->i_key; + p.o_key = kp->o_key; +memcpy (&p.iph, &kp->iph,min (sizeof (p.iph),sizeof (kp->iph)));And this
memcpy()doesn't necessarily clear the whole of p.iph.
Oh, let me send a follow-up covering all this.
Quoted 7 lines
net/ipv4/ip_tunnel.c int ip_tunnel_ctl(struct net_device *dev, struct ip_tunnel_parm *p, int cmd) · line 1042
Quoted 4 lines
net/ipv4/ip_tunnel.c +3
-0+ +return !copy_to_user (data, &p,sizeof (p)); +}regards,
dan carpenter
Thanks!
Olek
PATCH v6 16/21 ip_tunnel: convert __be16 tunnel flags to bitmaps
In reply to Alexander LobakinHistorically, tunnel flags like TUNNEL_CSUM or TUNNEL_ERSPAN_OPT have been defined as __be16. Now all of those 16 bits are occupied and there's no more free space for new flags.
It can't be simply switched to a bigger container with no adjustments to the values, since it's an explicit Endian storage, and on LE systems (__be16)0x0001 equals to (__be64)0x0001000000000000.
We could probably define new 64-bit flags depending on the Endianness, i.e. (__be64)0x0001 on BE and (__be64)0x00010000... on LE, but that would introduce an Endianness dependency and spawn a ton of Sparse warnings. To mitigate them, all of those places which were adjusted with this change would be touched anyway, so why not define stuff properly if there's no choice.
Define IP_TUNNEL_*_BIT counterparts as a bit number instead of the value already coded and a fistful of <16 <-> bitmap> converters and helpers. The two flags which have a different bit position are SIT_ISATAP_BIT and VTI_ISVTI_BIT, as they were defined not as __cpu_to_be16(), but as (__force __be16), i.e. had different positions on LE and BE. Now they both have strongly defined places. Change all __be16 fields which were used to store those flags, to IP_TUNNEL_DECLARE_FLAGS() -> DECLARE_BITMAP(__IP_TUNNEL_FLAG_NUM) -> unsigned long[1] for now, and replace all TUNNEL_* occurrences to their bitmap counterparts. Use the converters in the places which talk to the userspace, hardware (NFP) or other hosts (GRE header). The rest must explicitly use the new flags only. This must be done at once, otherwise there will be too many conversions throughout the code in the intermediate commits.
Finally, disable the old __be16 flags for use in the kernel code (except for the two 'irregular' flags mentioned above), to prevent any accidental (mis)use of them. For the userspace, nothing is changed, only additions were made.
Most noticeable bloat-o-meter difference (.text):
vmlinux: 307/-1 (306)
gre.ko: 62/0 (62)
ip_gre.ko: 941/-217 (724) [*]
ip_tunnel.ko: 390/-900 (-510) [**]
ip_vti.ko: 138/0 (138)
ip6_gre.ko: 534/-18 (516) [*]
ip6_tunnel.ko: 118/-10 (108)
[*] gre_flags_to_tnl_flags() grew, but still is inlined [**] ip_tunnel_find() got uninlined, hence such decrease
The average code size increase in non-extreme case is 100-200 bytes per module, mostly due to sizeof(long) > sizeof(__be16), as %__IP_TUNNEL_FLAG_NUM is less than %BITS_PER_LONG and the compilers are able to expand the majority of bitmap_*() calls here into direct operations on scalars.
--- .../ethernet/mellanox/mlx5/core/en/tc_tun.h | 2 +- include/net/dst_metadata.h | 10 +- include/net/flow_dissector.h | 2 +- include/net/gre.h | 70 +++++----- include/net/ip6_tunnel.h | 4 +- include/net/ip_tunnels.h | 119 +++++++++++++--- include/net/udp_tunnel.h | 4 +- include/uapi/linux/if_tunnel.h | 33 +++++ drivers/net/bareudp.c | 19 ++- .../mellanox/mlx5/core/en/tc_tun_encap.c | 6 +- .../mellanox/mlx5/core/en/tc_tun_geneve.c | 12 +- .../mellanox/mlx5/core/en/tc_tun_gre.c | 8 +- .../mellanox/mlx5/core/en/tc_tun_vxlan.c | 9 +- .../net/ethernet/mellanox/mlx5/core/en_tc.c | 16 ++- .../ethernet/mellanox/mlxsw/spectrum_ipip.c | 26 ++-- .../ethernet/mellanox/mlxsw/spectrum_span.c | 6 +- .../ethernet/netronome/nfp/flower/action.c | 27 +++- drivers/net/geneve.c | 44 +++--- drivers/net/vxlan/vxlan_core.c | 14 +- net/bridge/br_vlan_tunnel.c | 9 +- net/core/filter.c | 26 ++-- net/core/flow_dissector.c | 20 ++- net/ipv4/fou_bpf.c | 2 +- net/ipv4/gre_demux.c | 2 +- net/ipv4/ip_gre.c | 127 +++++++++++------- net/ipv4/ip_tunnel.c | 54 ++++---- net/ipv4/ip_tunnel_core.c | 80 ++++++----- net/ipv4/ip_vti.c | 29 ++-- net/ipv4/ipip.c | 21 ++- net/ipv4/udp_tunnel_core.c | 5 +- net/ipv6/ip6_gre.c | 85 +++++++----- net/ipv6/ip6_tunnel.c | 14 +- net/ipv6/sit.c | 5 +- net/netfilter/ipvs/ip_vs_core.c | 6 +- net/netfilter/ipvs/ip_vs_xmit.c | 20 +-- net/netfilter/nft_tunnel.c | 44 +++--- net/openvswitch/flow_netlink.c | 61 +++++---- net/psample/psample.c | 26 ++-- net/sched/act_tunnel_key.c | 36 ++--- net/sched/cls_flower.c | 27 ++-- 40 files changed, 715 insertions(+), 415 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.h +1 -1
@@ -117,7 +117,7 @@ bool mlx5e_tc_tun_encap_info_equal_generic(struct mlx5e_encap_key *a,bool mlx5e_tc_tun_encap_info_equal_options (struct mlx5e_encap_key *a,struct mlx5e_encap_key *b, -__be16 tun_flags); +u32 tun_type);#endif /* CONFIG_MLX5_ESWITCH */ #endif //__MLX5_EN_TC_TUNNEL_H__
include/net/dst_metadata.h +5 -5
@@ -198,7 +198,7 @@ static inline struct metadata_dst *__ip_tun_set_dst(__be32 saddr,__be32 daddr, __u8 tos, __u8 ttl, __be16 tp_dst, - __be16 flags, + const unsigned long *flags, __be64 tunnel_id, int md_size) {
@@ -215,7 +215,7 @@ static inline struct metadata_dst *__ip_tun_set_dst(__be32 saddr, }static inline struct metadata_dst *ip_tun_rx_dst (struct sk_buff *skb, -__be16 flags, +const unsigned long *flags,__be64 tunnel_id,int md_size) {
@@ -230,7 +230,7 @@ static inline struct metadata_dst *__ipv6_tun_set_dst(const struct in6_addr *sad __u8 tos, __u8 ttl, __be16 tp_dst, __be32 label, - __be16 flags, + const unsigned long *flags, __be64 tunnel_id, int md_size) {
@@ -243,7 +243,7 @@ static inline struct metadata_dst *__ipv6_tun_set_dst(const struct in6_addr *sad info = &tun_dst->u.tun_info; info->mode =IP_TUNNEL_INFO_IPV6 ; - info->key.tun_flags = flags; +ip_tunnel_flags_copy (info->key.tun_flags, flags); info->key.tun_id = tunnel_id; info->key.tp_src =0 ; info->key.tp_dst = tp_dst;
@@ -259,7 +259,7 @@ static inline struct metadata_dst *__ipv6_tun_set_dst(const struct in6_addr *sad }static inline struct metadata_dst *ipv6_tun_rx_dst (struct sk_buff *skb, -__be16 flags, +const unsigned long *flags,__be64 tunnel_id,int md_size) {
include/net/flow_dissector.h +1 -1
@@ -97,7 +97,7 @@ struct flow_dissector_key_enc_opts {* here but seems difficult to #include */ u8 len; -__be16 dst_opt_type; +u32 dst_opt_type; };struct flow_dissector_key_keyid {
include/net/gre.h +34 -36
119 lines not on this page · raw message
include/net/ip6_tunnel.h +2 -2
@@ -30,8 +30,8 @@ struct __ip6_tnl_parm {struct in6_addr laddr;/* local tunnel end-point address */ struct in6_addr raddr;/* remote tunnel end-point address */ -__be16 i_flags; -__be16 o_flags; +IP_TUNNEL_DECLARE_FLAGS (i_flags); +IP_TUNNEL_DECLARE_FLAGS (o_flags);__be32 i_key;__be32 o_key;
include/net/ip_tunnels.h +100 -19
194 lines not on this page · raw message
include/net/udp_tunnel.h +2 -2
@@ -179,8 +179,8 @@ struct dst_entry *udp_tunnel6_dst_lookup(struct sk_buff *skb, struct dst_cache *dst_cache);struct metadata_dst *udp_tun_rx_dst (struct sk_buff *skb,unsigned short family, -__be16 flags,__be64 tunnel_id, -int md_size); +const unsigned long *flags, +__be64 tunnel_id,int md_size);#ifdef CONFIG_INET static inline int udp_tunnel_handle_offloads (struct sk_buff *skb,bool udp_csum)
include/uapi/linux/if_tunnel.h +33 -0
@@ -161,6 +161,14 @@ enum {#define IFLA_VTI_MAX (__IFLA_VTI_MAX - 1) +#ifndef __KERNEL__ +/* Historically, tunnel flags have been defined as __be16 and now there are +* no free bits left. It is strongly advised to switch the already existing +* userspace code to the new *_BIT definitions from down below, as __be16 +* can't be simply cast to a wider type on LE systems. All new flags and +* code must use *_BIT only. +*/ +#define TUNNEL_CSUM __cpu_to_be16(0x01)#define TUNNEL_ROUTING __cpu_to_be16(0x02)#define TUNNEL_KEY __cpu_to_be16(0x04)
@@ -181,5 +189,30 @@ enum {#define TUNNEL_OPTIONS_PRESENT \ (TUNNEL_GENEVE_OPT | TUNNEL_VXLAN_OPT | TUNNEL_ERSPAN_OPT | \ TUNNEL_GTP_OPT) +#endif + +enum { +IP_TUNNEL_CSUM_BIT =0U , +IP_TUNNEL_ROUTING_BIT , +IP_TUNNEL_KEY_BIT , +IP_TUNNEL_SEQ_BIT , +IP_TUNNEL_STRICT_BIT , +IP_TUNNEL_REC_BIT , +IP_TUNNEL_VERSION_BIT , +IP_TUNNEL_NO_KEY_BIT , +IP_TUNNEL_DONT_FRAGMENT_BIT , +IP_TUNNEL_OAM_BIT , +IP_TUNNEL_CRIT_OPT_BIT , +IP_TUNNEL_GENEVE_OPT_BIT ,/* OPTIONS_PRESENT */ +IP_TUNNEL_VXLAN_OPT_BIT ,/* OPTIONS_PRESENT */ +IP_TUNNEL_NOCACHE_BIT , +IP_TUNNEL_ERSPAN_OPT_BIT ,/* OPTIONS_PRESENT */ +IP_TUNNEL_GTP_OPT_BIT ,/* OPTIONS_PRESENT */ + +IP_TUNNEL_VTI_BIT , +IP_TUNNEL_SIT_ISATAP_BIT =IP_TUNNEL_VTI_BIT , + + __IP_TUNNEL_FLAG_NUM, +};#endif /* _UAPI_IF_TUNNEL_H_ */
drivers/net/bareudp.c +13 -6
@@ -61,6 +61,7 @@ struct bareudp_dev {static int bareudp_udp_encap_recv (struct sock *sk,struct sk_buff *skb) {struct metadata_dst *tun_dst =NULL ; +IP_TUNNEL_DECLARE_FLAGS (key) = { };struct bareudp_dev *bareudp;unsigned short family;unsigned int len;
@@ -137,7 +138,10 @@ static int bareudp_udp_encap_recv(struct sock *sk, struct sk_buff *skb) bareudp->dev->stats.rx_dropped++; goto drop; } - tun_dst =udp_tun_rx_dst (skb, family,TUNNEL_KEY ,0 ,0 ); + +__set_bit (IP_TUNNEL_KEY_BIT , key); + + tun_dst =udp_tun_rx_dst (skb, family, key,0 ,0 );if (!tun_dst) { bareudp->dev->stats.rx_dropped++; goto drop;
@@ -285,10 +289,10 @@ static int bareudp_xmit_skb(struct sk_buff *skb, struct net_device *dev,struct bareudp_dev *bareudp, const struct ip_tunnel_info *info) { + bool udp_sum = test_bit(IP_TUNNEL_CSUM_BIT, info->key.tun_flags);bool xnet = !net_eq (bareudp->net,dev_net (bareudp->dev));bool use_cache =ip_tunnel_dst_cache_usable (skb, info);struct socket *sock =rcu_dereference (bareudp->sock); -bool udp_sum = !!(info->key.tun_flags &TUNNEL_CSUM );const struct ip_tunnel_key *key = &info->key;struct rtable *rt;__be16 sport, df;
@@ -316,7 +320,8 @@ static int bareudp_xmit_skb(struct sk_buff *skb, struct net_device *dev, tos =ip_tunnel_ecn_encap (key->tos,ip_hdr (skb), skb); ttl = key->ttl; - df = key->tun_flags &TUNNEL_DONT_FRAGMENT ?htons (IP_DF ) :0 ; + df =test_bit (IP_TUNNEL_DONT_FRAGMENT_BIT , key->tun_flags) ? +htons (IP_DF ) :0 ;skb_scrub_packet (skb, xnet); err = -ENOSPC ;
@@ -338,7 +343,8 @@ static int bareudp_xmit_skb(struct sk_buff *skb, struct net_device *dev,udp_tunnel_xmit_skb (rt, sock->sk, skb, saddr, info->key.u.ipv4.dst, tos, ttl, df, sport, bareudp->port, !net_eq (bareudp->net,dev_net (bareudp->dev)), - !(info->key.tun_flags &TUNNEL_CSUM )); + !test_bit (IP_TUNNEL_CSUM_BIT , + info->key.tun_flags));return 0 ; free_dst:
@@ -350,10 +356,10 @@ static int bareudp6_xmit_skb(struct sk_buff *skb, struct net_device *dev,struct bareudp_dev *bareudp, const struct ip_tunnel_info *info) { + bool udp_sum = test_bit(IP_TUNNEL_CSUM_BIT, info->key.tun_flags);bool xnet = !net_eq (bareudp->net,dev_net (bareudp->dev));bool use_cache =ip_tunnel_dst_cache_usable (skb, info);struct socket *sock =rcu_dereference (bareudp->sock); -bool udp_sum = !!(info->key.tun_flags &TUNNEL_CSUM );const struct ip_tunnel_key *key = &info->key;struct dst_entry *dst =NULL ;struct in6_addr saddr, daddr;
@@ -402,7 +408,8 @@ static int bareudp6_xmit_skb(struct sk_buff *skb, struct net_device *dev,udp_tunnel6_xmit_skb (dst, sock->sk, skb, dev, &saddr, &daddr, prio, ttl, info->key.label, sport, bareudp->port, - !(info->key.tun_flags &TUNNEL_CSUM )); + !test_bit (IP_TUNNEL_CSUM_BIT , + info->key.tun_flags));return 0 ; free_dst:
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c +3 -3
@@ -587,7 +587,7 @@ bool mlx5e_tc_tun_encap_info_equal_generic(struct mlx5e_encap_key *a,bool mlx5e_tc_tun_encap_info_equal_options (struct mlx5e_encap_key *a,struct mlx5e_encap_key *b, -__be16 tun_flags) +u32 tun_type) {struct ip_tunnel_info *a_info;struct ip_tunnel_info *b_info;
@@ -596,8 +596,8 @@ bool mlx5e_tc_tun_encap_info_equal_options(struct mlx5e_encap_key *a,if (!mlx5e_tc_tun_encap_info_equal_generic (a, b))return false; - a_has_opts = !!(a->ip_tun_key->tun_flags & tun_flags); - b_has_opts = !!(b->ip_tun_key->tun_flags & tun_flags); + a_has_opts =test_bit (tun_type, a->ip_tun_key->tun_flags); + b_has_opts =test_bit (tun_type, b->ip_tun_key->tun_flags);/* keys are equal when both don't have any options attached */ if (!a_has_opts && !b_has_opts)
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_geneve.c +7 -5
@@ -106,12 +106,13 @@ static int mlx5e_gen_ip_tunnel_header_geneve(char buf[],memset (geneveh,0 ,sizeof (*geneveh)); geneveh->ver =MLX5E_GENEVE_VER ; geneveh->opt_len = tun_info->options_len /4 ; - geneveh->oam = !!(tun_info->key.tun_flags &TUNNEL_OAM ); - geneveh->critical = !!(tun_info->key.tun_flags &TUNNEL_CRIT_OPT ); + geneveh->oam =test_bit (IP_TUNNEL_OAM_BIT , tun_info->key.tun_flags); + geneveh->critical =test_bit (IP_TUNNEL_CRIT_OPT_BIT , + tun_info->key.tun_flags);mlx5e_tunnel_id_to_vni (tun_info->key.tun_id, geneveh->vni); geneveh->proto_type =htons (ETH_P_TEB ); -if (tun_info->key.tun_flags &TUNNEL_GENEVE_OPT ) { +if (test_bit (IP_TUNNEL_GENEVE_OPT_BIT , tun_info->key.tun_flags)) {if (!geneveh->opt_len)return -EOPNOTSUPP ;ip_tunnel_info_opts_get (geneveh->options, tun_info);
@@ -188,7 +189,7 @@ static int mlx5e_tc_tun_parse_geneve_options(struct mlx5e_priv *priv,/* make sure that we're talking about GENEVE options */ -if (enc_opts.key->dst_opt_type !=TUNNEL_GENEVE_OPT ) { +if (enc_opts.key->dst_opt_type !=IP_TUNNEL_GENEVE_OPT_BIT ) {NL_SET_ERR_MSG_MOD (extack,"Matching on GENEVE options: option type is not GENEVE" ); netdev_warn(priv->netdev,
@@ -337,7 +338,8 @@ static int mlx5e_tc_tun_parse_geneve(struct mlx5e_priv *priv,static bool mlx5e_tc_tun_encap_info_equal_geneve (struct mlx5e_encap_key *a,struct mlx5e_encap_key *b) { -return mlx5e_tc_tun_encap_info_equal_options (a, b,TUNNEL_GENEVE_OPT ); +return mlx5e_tc_tun_encap_info_equal_options (a, b, +IP_TUNNEL_GENEVE_OPT_BIT ); }struct mlx5e_tc_tunnel geneve_tunnel = {
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_gre.c +6 -2
@@ -31,12 +31,16 @@ static int mlx5e_gen_ip_tunnel_header_gretap(char buf[],const struct ip_tunnel_key *tun_key = &e->tun_info->key;struct gre_base_hdr *greh = (struct gre_base_hdr *)(buf);__be32 tun_id =tunnel_id_to_key32 (tun_key->tun_id); +IP_TUNNEL_DECLARE_FLAGS (unsupp) = { };int hdr_len; *ip_proto =IPPROTO_GRE ;/* the HW does not calculate GRE csum or sequences */ -if (tun_key->tun_flags & (TUNNEL_CSUM |TUNNEL_SEQ )) +__set_bit (IP_TUNNEL_CSUM_BIT , unsupp); +__set_bit (IP_TUNNEL_SEQ_BIT , unsupp); + +if (ip_tunnel_flags_intersect (tun_key->tun_flags, unsupp))return -EOPNOTSUPP ; greh->protocol =htons (ETH_P_TEB );
@@ -44,7 +48,7 @@ static int mlx5e_gen_ip_tunnel_header_gretap(char buf[],/* GRE key */ hdr_len =mlx5e_tc_tun_calc_hlen_gretap (e); greh->flags =gre_tnl_flags_to_gre_flags (tun_key->tun_flags); -if (tun_key->tun_flags &TUNNEL_KEY ) { +if (test_bit (IP_TUNNEL_KEY_BIT , tun_key->tun_flags)) {__be32 *ptr = (__be32 *)(((u8 *)greh) + hdr_len -4 ); *ptr = tun_id; }
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +5 -4
@@ -90,7 +90,7 @@ static int mlx5e_gen_ip_tunnel_header_vxlan(char buf[],const struct vxlan_metadata *md;struct vxlanhdr *vxh; -if ((tun_key->tun_flags &TUNNEL_VXLAN_OPT ) && +if (test_bit (IP_TUNNEL_VXLAN_OPT_BIT , tun_key->tun_flags) && e->tun_info->options_len !=sizeof (*md))return -EOPNOTSUPP ; vxh = (struct vxlanhdr *)((char *)udp +sizeof (struct udphdr ));
@@ -99,7 +99,7 @@ static int mlx5e_gen_ip_tunnel_header_vxlan(char buf[], udp->dest = tun_key->tp_dst; vxh->vx_flags =VXLAN_HF_VNI ; vxh->vx_vni =vxlan_vni_field (tun_id); -if (tun_key->tun_flags &TUNNEL_VXLAN_OPT ) { +if (test_bit (IP_TUNNEL_VXLAN_OPT_BIT , tun_key->tun_flags)) { md =ip_tunnel_info_opts (e->tun_info);vxlan_build_gbp_hdr (vxh, md); }
@@ -125,7 +125,7 @@ static int mlx5e_tc_tun_parse_vxlan_gbp_option(struct mlx5e_priv *priv,return -EOPNOTSUPP ; } -if (enc_opts.key->dst_opt_type !=TUNNEL_VXLAN_OPT ) { +if (enc_opts.key->dst_opt_type !=IP_TUNNEL_VXLAN_OPT_BIT ) {NL_SET_ERR_MSG_MOD (extack,"Wrong VxLAN option type: not GBP" );return -EOPNOTSUPP ; }
@@ -208,7 +208,8 @@ static int mlx5e_tc_tun_parse_vxlan(struct mlx5e_priv *priv,static bool mlx5e_tc_tun_encap_info_equal_vxlan (struct mlx5e_encap_key *a,struct mlx5e_encap_key *b) { -return mlx5e_tc_tun_encap_info_equal_options (a, b,TUNNEL_VXLAN_OPT ); +return mlx5e_tc_tun_encap_info_equal_options (a, b, +IP_TUNNEL_VXLAN_OPT_BIT ); }static int mlx5e_tc_tun_get_remote_ifindex (struct net_device *mirred_dev)
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +12 -4
@@ -5464,6 +5464,7 @@ static bool mlx5e_tc_restore_tunnel(struct mlx5e_priv *priv, struct sk_buff *skbstruct mlx5_eswitch *esw = priv->mdev->priv.eswitch;struct tunnel_match_enc_opts enc_opts = {};struct mlx5_rep_uplink_priv *uplink_priv; +IP_TUNNEL_DECLARE_FLAGS (flags) = { };struct mlx5e_rep_priv *uplink_rpriv;struct metadata_dst *tun_dst;struct tunnel_match_key key;
@@ -5471,6 +5472,8 @@ static bool mlx5e_tc_restore_tunnel(struct mlx5e_priv *priv, struct sk_buff *skbstruct net_device *dev;int err; +__set_bit (IP_TUNNEL_KEY_BIT , flags); + enc_opts_id = tunnel_id &ENC_OPTS_BITS_MASK ; tun_id = tunnel_id >>ENC_OPTS_BITS ;
@@ -5503,14 +5506,14 @@ static bool mlx5e_tc_restore_tunnel(struct mlx5e_priv *priv, struct sk_buff *skbcase FLOW_DISSECTOR_KEY_IPV4_ADDRS : tun_dst =__ip_tun_set_dst (key.enc_ipv4.src, key.enc_ipv4.dst, key.enc_ip.tos, key.enc_ip.ttl, - key.enc_tp.dst,TUNNEL_KEY , + key.enc_tp.dst, flags,key32_to_tunnel_id (key.enc_key_id.keyid), enc_opts.key.len);break ;case FLOW_DISSECTOR_KEY_IPV6_ADDRS : tun_dst =__ipv6_tun_set_dst (&key.enc_ipv6.src, &key.enc_ipv6.dst, key.enc_ip.tos, key.enc_ip.ttl, - key.enc_tp.dst,0 ,TUNNEL_KEY , + key.enc_tp.dst,0 , flags,key32_to_tunnel_id (key.enc_key_id.keyid), enc_opts.key.len);break ;
@@ -5528,11 +5531,16 @@ static bool mlx5e_tc_restore_tunnel(struct mlx5e_priv *priv, struct sk_buff *skb tun_dst->u.tun_info.key.tp_src = key.enc_tp.src; -if (enc_opts.key.len) +if (enc_opts.key.len) { +ip_tunnel_flags_zero (flags); +if (enc_opts.key.dst_opt_type) +__set_bit (enc_opts.key.dst_opt_type, flags); +ip_tunnel_info_opts_set (&tun_dst->u.tun_info, enc_opts.key.data, enc_opts.key.len, - enc_opts.key.dst_opt_type); + flags); + }skb_dst_set (skb, (struct dst_entry *)tun_dst); dev =dev_get_by_index (&init_net, key.filter_ifindex);
drivers/net/ethernet/mellanox/mlxsw/spectrum_ipip.c +16 -10
@@ -27,23 +27,23 @@ mlxsw_sp_ipip_netdev_parms6(const struct net_device *ol_dev)static bool mlxsw_sp_ipip_parms4_has_ikey (const struct ip_tunnel_parm_kern *parms) { -return !!(parms->i_flags &TUNNEL_KEY ); +return test_bit (IP_TUNNEL_KEY_BIT , parms->i_flags); }static bool mlxsw_sp_ipip_parms6_has_ikey (const struct __ip6_tnl_parm *parms) { -return !!(parms->i_flags &TUNNEL_KEY ); +return test_bit (IP_TUNNEL_KEY_BIT , parms->i_flags); }static bool mlxsw_sp_ipip_parms4_has_okey (const struct ip_tunnel_parm_kern *parms) { -return !!(parms->o_flags &TUNNEL_KEY ); +return test_bit (IP_TUNNEL_KEY_BIT , parms->o_flags); }static bool mlxsw_sp_ipip_parms6_has_okey (const struct __ip6_tnl_parm *parms) { -return !!(parms->o_flags &TUNNEL_KEY ); +return test_bit (IP_TUNNEL_KEY_BIT , parms->o_flags); }static u32 mlxsw_sp_ipip_parms4_ikey (const struct ip_tunnel_parm_kern *parms)
@@ -242,12 +242,15 @@ static bool mlxsw_sp_ipip_can_offload_gre4(const struct mlxsw_sp *mlxsw_sp, const struct net_device *ol_dev) {struct ip_tunnel *tunnel =netdev_priv (ol_dev); -__be16 okflags =TUNNEL_KEY ;/* We can't offload any other features. */ bool inherit_ttl = tunnel->parms.iph.ttl ==0 ;bool inherit_tos = tunnel->parms.iph.tos &0x1 ; +IP_TUNNEL_DECLARE_FLAGS (okflags) = { }; -return (tunnel->parms.i_flags & ~okflags) ==0 && - (tunnel->parms.o_flags & ~okflags) ==0 && +/* We can't offload any other features. */ +__set_bit (IP_TUNNEL_KEY_BIT , okflags); + +return ip_tunnel_flags_subset (tunnel->parms.i_flags, okflags) && +ip_tunnel_flags_subset (tunnel->parms.o_flags, okflags) && inherit_ttl && inherit_tos &&mlxsw_sp_ipip_tunnel_complete (MLXSW_SP_L3_PROTO_IPV4 , ol_dev); }
@@ -443,10 +446,13 @@ static bool mlxsw_sp_ipip_can_offload_gre6(const struct mlxsw_sp *mlxsw_sp,struct __ip6_tnl_parm tparm =mlxsw_sp_ipip_netdev_parms6 (ol_dev);bool inherit_tos = tparm.flags &IP6_TNL_F_USE_ORIG_TCLASS ;bool inherit_ttl = tparm.hop_limit ==0 ; -__be16 okflags =TUNNEL_KEY ;/* We can't offload any other features. */ +IP_TUNNEL_DECLARE_FLAGS (okflags) = { }; + +/* We can't offload any other features. */ +__set_bit (IP_TUNNEL_KEY_BIT , okflags); -return (tparm.i_flags & ~okflags) ==0 && - (tparm.o_flags & ~okflags) ==0 && +return ip_tunnel_flags_subset (tparm.i_flags, okflags) && +ip_tunnel_flags_subset (tparm.o_flags, okflags) && inherit_ttl && inherit_tos &&mlxsw_sp_ipip_tunnel_complete (MLXSW_SP_L3_PROTO_IPV6 , ol_dev); }
drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c +4 -2
@@ -461,7 +461,8 @@ mlxsw_sp_span_entry_gretap4_parms(struct mlxsw_sp *mlxsw_sp, if (!(to_dev->flags & IFF_UP) || /* Reject tunnels with GRE keys, checksums, etc. */ - tparm.i_flags || tparm.o_flags || + !ip_tunnel_flags_empty(tparm.i_flags) || + !ip_tunnel_flags_empty(tparm.o_flags) || /* Require a fixed TTL and a TOS copied from the mirrored packet. */ inherit_ttl || !inherit_tos ||/* A destination address may not be "any". */
@@ -565,7 +566,8 @@ mlxsw_sp_span_entry_gretap6_parms(struct mlxsw_sp *mlxsw_sp, if (!(to_dev->flags & IFF_UP) || /* Reject tunnels with GRE keys, checksums, etc. */ - tparm.i_flags || tparm.o_flags || + !ip_tunnel_flags_empty(tparm.i_flags) || + !ip_tunnel_flags_empty(tparm.o_flags) || /* Require a fixed TTL and a TOS copied from the mirrored packet. */ inherit_ttl || !inherit_tos ||/* A destination address may not be "any". */
drivers/net/ethernet/netronome/nfp/flower/action.c +21 -6
@@ -396,6 +396,17 @@ nfp_fl_push_geneve_options(struct nfp_fl_payload *nfp_fl, int *list_len,return 0 ; } +#define NFP_FL_CHECK (flag) ({ \ + IP_TUNNEL_DECLARE_FLAGS(__check) = { }; \ + __be16 __res; \ + \ + __set_bit(IP_TUNNEL_##flag##_BIT, __check); \ + __res = ip_tunnel_flags_to_be16(__check); \ + \ + BUILD_BUG_ON(__builtin_constant_p(__res) && \ + NFP_FL_TUNNEL_##flag != __res); \ +}) + static int nfp_fl_set_tun(struct nfp_app *app, struct nfp_fl_set_tun *set_tun, const struct flow_action_entry *act,
@@ -410,6 +421,7 @@ nfp_fl_set_tun(struct nfp_app *app, struct nfp_fl_set_tun *set_tun,u32 tmp_set_ip_tun_type_index =0 ;/* Currently support one pre-tunnel so index is always 0. */ int pretun_idx =0 ; +__be16 tun_flags;if (!IS_ENABLED (CONFIG_IPV6 ) && ipv6)return -EOPNOTSUPP ;
@@ -417,9 +429,10 @@ nfp_fl_set_tun(struct nfp_app *app, struct nfp_fl_set_tun *set_tun,if (ipv6 && !(priv->flower_ext_feats &NFP_FL_FEATS_IPV6_TUN ))return -EOPNOTSUPP ; -BUILD_BUG_ON (NFP_FL_TUNNEL_CSUM !=TUNNEL_CSUM || -NFP_FL_TUNNEL_KEY !=TUNNEL_KEY || -NFP_FL_TUNNEL_GENEVE_OPT !=TUNNEL_GENEVE_OPT ); +NFP_FL_CHECK (CSUM ); +NFP_FL_CHECK (KEY ); +NFP_FL_CHECK (GENEVE_OPT ); +if (ip_tun->options_len && (tun_type !=NFP_FL_TUNNEL_GENEVE || !(priv->flower_ext_feats &NFP_FL_FEATS_GENEVE_OPT ))) {
@@ -427,7 +440,9 @@ nfp_fl_set_tun(struct nfp_app *app, struct nfp_fl_set_tun *set_tun,return -EOPNOTSUPP ; } -if (ip_tun->key.tun_flags & ~NFP_FL_SUPPORTED_UDP_TUN_FLAGS ) { + tun_flags =ip_tunnel_flags_to_be16 (ip_tun->key.tun_flags); +if (!ip_tunnel_flags_is_be16_compat (ip_tun->key.tun_flags) || + (tun_flags & ~NFP_FL_SUPPORTED_UDP_TUN_FLAGS )) {NL_SET_ERR_MSG_MOD (extack,"unsupported offload: loaded firmware does not support tunnel flag offload" );return -EOPNOTSUPP ;
@@ -442,7 +457,7 @@ nfp_fl_set_tun(struct nfp_app *app, struct nfp_fl_set_tun *set_tun,FIELD_PREP (NFP_FL_PRE_TUN_INDEX , pretun_idx); set_tun->tun_type_index =cpu_to_be32 (tmp_set_ip_tun_type_index); -if (ip_tun->key.tun_flags &NFP_FL_TUNNEL_KEY ) +if (tun_flags &NFP_FL_TUNNEL_KEY ) set_tun->tun_id = ip_tun->key.tun_id;if (ip_tun->key.ttl) {
@@ -486,7 +501,7 @@ nfp_fl_set_tun(struct nfp_app *app, struct nfp_fl_set_tun *set_tun, } set_tun->tos = ip_tun->key.tos; - set_tun->tun_flags = ip_tun->key.tun_flags; + set_tun->tun_flags = tun_flags;if (tun_type ==NFP_FL_TUNNEL_GENEVE ) { set_tun->tun_proto =htons (ETH_P_TEB );
drivers/net/geneve.c +27 -17
130 lines not on this page · raw message
drivers/net/vxlan/vxlan_core.c +9 -5
@@ -1584,7 +1584,8 @@ static void vxlan_parse_gbp_hdr(struct vxlanhdr *unparsed, tun_dst = (struct metadata_dst *)skb_dst (skb);if (tun_dst) { - tun_dst->u.tun_info.key.tun_flags |=TUNNEL_VXLAN_OPT ; +__set_bit (IP_TUNNEL_VXLAN_OPT_BIT , + tun_dst->u.tun_info.key.tun_flags); tun_dst->u.tun_info.options_len =sizeof (*md); }if (gbp->dont_learn)
@@ -1716,9 +1717,11 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb) goto drop;if (vxlan_collect_metadata (vs)) { +IP_TUNNEL_DECLARE_FLAGS (flags) = { };struct metadata_dst *tun_dst; - tun_dst =udp_tun_rx_dst (skb,vxlan_get_sk_family (vs),TUNNEL_KEY , +__set_bit (IP_TUNNEL_KEY_BIT , flags); + tun_dst =udp_tun_rx_dst (skb,vxlan_get_sk_family (vs), flags,key32_to_tunnel_id (vni),sizeof (*md));if (!tun_dst)
@@ -2403,14 +2406,14 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, vni =tunnel_id_to_key32 (info->key.tun_id); ifindex =0 ; dst_cache = &info->dst_cache; -if (info->key.tun_flags &TUNNEL_VXLAN_OPT ) { +if (test_bit (IP_TUNNEL_VXLAN_OPT_BIT , info->key.tun_flags)) {if (info->options_len <sizeof (*md)) goto drop; md =ip_tunnel_info_opts (info); } ttl = info->key.ttl; tos = info->key.tos; - udp_sum = !!(info->key.tun_flags &TUNNEL_CSUM ); + udp_sum =test_bit (IP_TUNNEL_CSUM_BIT , info->key.tun_flags); } src_port =udp_flow_src_port (dev_net (dev), skb, vxlan->cfg.port_min, vxlan->cfg.port_max, true);
@@ -2451,7 +2454,8 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, old_iph->frag_off & htons(IP_DF))) df =htons (IP_DF ); } - }else if (info->key.tun_flags &TUNNEL_DONT_FRAGMENT ) { + }else if (test_bit (IP_TUNNEL_DONT_FRAGMENT_BIT , + info->key.tun_flags)) { df =htons (IP_DF ); }
net/bridge/br_vlan_tunnel.c +6 -3
@@ -65,13 +65,14 @@ static int __vlan_tunnel_info_add(struct net_bridge_vlan_group *vg, {struct metadata_dst *metadata =rtnl_dereference (vlan->tinfo.tunnel_dst);__be64 key =key32_to_tunnel_id (cpu_to_be32 (tun_id)); +IP_TUNNEL_DECLARE_FLAGS (flags) = { };int err;if (metadata)return -EEXIST ; - metadata =__ip_tun_set_dst (0 ,0 ,0 ,0 ,0 ,TUNNEL_KEY , - key,0 ); +__set_bit (IP_TUNNEL_KEY_BIT , flags); + metadata =__ip_tun_set_dst (0 ,0 ,0 ,0 ,0 , flags, key,0 );if (!metadata)return -EINVAL ;
@@ -185,6 +186,7 @@ void br_handle_ingress_vlan_tunnel(struct sk_buff *skb,int br_handle_egress_vlan_tunnel (struct sk_buff *skb,struct net_bridge_vlan *vlan) { +IP_TUNNEL_DECLARE_FLAGS (flags) = { };struct metadata_dst *tunnel_dst;__be64 tunnel_id;int err;
@@ -202,7 +204,8 @@ int br_handle_egress_vlan_tunnel(struct sk_buff *skb,return err;if (BR_INPUT_SKB_CB (skb)->backup_nhid) { - tunnel_dst =__ip_tun_set_dst (0 ,0 ,0 ,0 ,0 ,TUNNEL_KEY , +__set_bit (IP_TUNNEL_KEY_BIT , flags); + tunnel_dst =__ip_tun_set_dst (0 ,0 ,0 ,0 ,0 , flags, tunnel_id,0 );if (!tunnel_dst)return -ENOMEM ;
net/core/filter.c +14 -12
@@ -4662,7 +4662,7 @@ BPF_CALL_4(bpf_skb_get_tunnel_key, struct sk_buff *, skb, struct bpf_tunnel_key to->tunnel_tos = info->key.tos; to->tunnel_ttl = info->key.ttl;if (flags &BPF_F_TUNINFO_FLAGS ) - to->tunnel_flags = info->key.tun_flags; + to->tunnel_flags =ip_tunnel_flags_to_be16 (info->key.tun_flags);else to->tunnel_ext =0 ;
@@ -4705,7 +4705,7 @@ BPF_CALL_3(bpf_skb_get_tunnel_opt, struct sk_buff *, skb, u8 *, to, u32, size)int err;if (unlikely (!info || - !(info->key.tun_flags &TUNNEL_OPTIONS_PRESENT ))) { + !ip_tunnel_is_options_present (info->key.tun_flags))) { err = -ENOENT ; goto err_clear; }
@@ -4775,15 +4775,15 @@ BPF_CALL_4(bpf_skb_set_tunnel_key, struct sk_buff *, skb,memset (info,0 ,sizeof (*info)); info->mode =IP_TUNNEL_INFO_TX ; - info->key.tun_flags =TUNNEL_KEY |TUNNEL_CSUM |TUNNEL_NOCACHE ; -if (flags &BPF_F_DONT_FRAGMENT ) - info->key.tun_flags |=TUNNEL_DONT_FRAGMENT ; -if (flags &BPF_F_ZERO_CSUM_TX ) - info->key.tun_flags &= ~TUNNEL_CSUM ; -if (flags &BPF_F_SEQ_NUMBER ) - info->key.tun_flags |=TUNNEL_SEQ ; -if (flags &BPF_F_NO_TUNNEL_KEY ) - info->key.tun_flags &= ~TUNNEL_KEY ; +__set_bit (IP_TUNNEL_NOCACHE_BIT , info->key.tun_flags); +__assign_bit (IP_TUNNEL_DONT_FRAGMENT_BIT , info->key.tun_flags, + flags &BPF_F_DONT_FRAGMENT ); +__assign_bit (IP_TUNNEL_CSUM_BIT , info->key.tun_flags, + !(flags &BPF_F_ZERO_CSUM_TX )); +__assign_bit (IP_TUNNEL_SEQ_BIT , info->key.tun_flags, + flags &BPF_F_SEQ_NUMBER ); +__assign_bit (IP_TUNNEL_KEY_BIT , info->key.tun_flags, + !(flags &BPF_F_NO_TUNNEL_KEY )); info->key.tun_id =cpu_to_be64 (from->tunnel_id); info->key.tos = from->tunnel_tos;
@@ -4821,13 +4821,15 @@ BPF_CALL_3(bpf_skb_set_tunnel_opt, struct sk_buff *, skb, {struct ip_tunnel_info *info =skb_tunnel_info (skb);const struct metadata_dst *md =this_cpu_ptr (md_dst); +IP_TUNNEL_DECLARE_FLAGS (present) = { };if (unlikely (info != &md->u.tun_info || (size & (sizeof (u32) -1 ))))return -EINVAL ;if (unlikely (size >IP_TUNNEL_OPTS_MAX ))return -ENOMEM ; -ip_tunnel_info_opts_set (info, from, size,TUNNEL_OPTIONS_PRESENT ); +ip_tunnel_set_options_present (present); +ip_tunnel_info_opts_set (info, from, size, present);return 0 ; }
net/core/flow_dissector.c +14 -6
@@ -455,17 +455,25 @@ skb_flow_dissect_tunnel_info(const struct sk_buff *skb,if (dissector_uses_key (flow_dissector,FLOW_DISSECTOR_KEY_ENC_OPTS )) {struct flow_dissector_key_enc_opts *enc_opt; +IP_TUNNEL_DECLARE_FLAGS (flags) = { }; +u32 val; enc_opt =skb_flow_dissector_target (flow_dissector,FLOW_DISSECTOR_KEY_ENC_OPTS , target_container); -if (info->options_len) { - enc_opt->len = info->options_len; -ip_tunnel_info_opts_get (enc_opt->data, info); - enc_opt->dst_opt_type = info->key.tun_flags & -TUNNEL_OPTIONS_PRESENT ; - } +if (!info->options_len) +return ; + + enc_opt->len = info->options_len; +ip_tunnel_info_opts_get (enc_opt->data, info); + +ip_tunnel_set_options_present (flags); +ip_tunnel_flags_and (flags, info->key.tun_flags, flags); + + val =find_next_bit (flags, __IP_TUNNEL_FLAG_NUM, +IP_TUNNEL_GENEVE_OPT_BIT ); + enc_opt->dst_opt_type = val < __IP_TUNNEL_FLAG_NUM ? val :0 ; } }EXPORT_SYMBOL (skb_flow_dissect_tunnel_info);
net/ipv4/fou_bpf.c +1 -1
@@ -64,7 +64,7 @@ __bpf_kfunc int bpf_skb_set_fou_encap(struct __sk_buff *skb_ctx, info->encap.type =TUNNEL_ENCAP_NONE ; } -if (info->key.tun_flags &TUNNEL_CSUM ) +if (test_bit (IP_TUNNEL_CSUM_BIT , info->key.tun_flags)) info->encap.flags |=TUNNEL_ENCAP_FLAG_CSUM ; info->encap.sport = encap->sport;
net/ipv4/gre_demux.c +1 -1
@@ -73,7 +73,7 @@ int gre_parse_header(struct sk_buff *skb, struct tnl_ptk_info *tpi,if (unlikely (greh->flags & (GRE_VERSION |GRE_ROUTING )))return -EINVAL ; - tpi->flags =gre_flags_to_tnl_flags (greh->flags); +gre_flags_to_tnl_flags (tpi->flags, greh->flags); hdr_len =gre_calc_hlen (tpi->flags);if (!pskb_may_pull (skb, nhs + hdr_len))
net/ipv4/ip_gre.c +78 -49
324 lines not on this page · raw message
net/ipv4/ip_tunnel.c +29 -25
128 lines not on this page · raw message
net/ipv4/ip_tunnel_core.c +50 -30
203 lines not on this page · raw message
net/ipv4/ip_vti.c +21 -8
@@ -51,8 +51,11 @@ static int vti_input(struct sk_buff *skb, int nexthdr, __be32 spi,const struct iphdr *iph =ip_hdr (skb);struct net *net =dev_net (skb->dev);struct ip_tunnel_net *itn =net_generic (net, vti_net_id); +IP_TUNNEL_DECLARE_FLAGS (flags) = { }; - tunnel =ip_tunnel_lookup (itn, skb->dev->ifindex,TUNNEL_NO_KEY , +__set_bit (IP_TUNNEL_NO_KEY_BIT , flags); + + tunnel =ip_tunnel_lookup (itn, skb->dev->ifindex, flags, iph->saddr, iph->daddr,0 );if (tunnel) {if (!xfrm4_policy_check (NULL ,XFRM_POLICY_IN , skb))
@@ -322,8 +325,11 @@ static int vti4_err(struct sk_buff *skb, u32 info)const struct iphdr *iph = (const struct iphdr *)skb->data;int protocol = iph->protocol;struct ip_tunnel_net *itn =net_generic (net, vti_net_id); +IP_TUNNEL_DECLARE_FLAGS (flags) = { }; + +__set_bit (IP_TUNNEL_NO_KEY_BIT , flags); - tunnel =ip_tunnel_lookup (itn, skb->dev->ifindex,TUNNEL_NO_KEY , + tunnel =ip_tunnel_lookup (itn, skb->dev->ifindex, flags, iph->daddr, iph->saddr,0 );if (!tunnel)return -1 ;
@@ -375,6 +381,7 @@ static int vti4_err(struct sk_buff *skb, u32 info)static int vti_tunnel_ctl (struct net_device *dev,struct ip_tunnel_parm_kern *p,int cmd) { +IP_TUNNEL_DECLARE_FLAGS (flags) = { };int err =0 ;if (cmd ==SIOCADDTUNNEL || cmd ==SIOCCHGTUNNEL ) {
@@ -383,20 +390,26 @@ vti_tunnel_ctl(struct net_device *dev, struct ip_tunnel_parm_kern *p, int cmd)return -EINVAL ; } -if (!(p->i_flags &GRE_KEY )) +if (!ip_tunnel_flags_is_be16_compat (p->i_flags) || + !ip_tunnel_flags_is_be16_compat (p->o_flags)) +return -EOVERFLOW ; + +if (!(ip_tunnel_flags_to_be16 (p->i_flags) &GRE_KEY )) p->i_key =0 ; -if (!(p->o_flags &GRE_KEY )) +if (!(ip_tunnel_flags_to_be16 (p->o_flags) &GRE_KEY )) p->o_key =0 ; - p->i_flags =VTI_ISVTI ; +__set_bit (IP_TUNNEL_VTI_BIT , flags); +ip_tunnel_flags_copy (p->i_flags, flags); err =ip_tunnel_ctl (dev, p, cmd);if (err)return err;if (cmd !=SIOCDELTUNNEL ) { - p->i_flags |=GRE_KEY ; - p->o_flags |=GRE_KEY ; +ip_tunnel_flags_from_be16 (flags,GRE_KEY ); +ip_tunnel_flags_or (p->i_flags, p->i_flags, flags); +ip_tunnel_flags_or (p->o_flags, p->o_flags, flags); }return 0 ; }
@@ -541,7 +554,7 @@ static void vti_netlink_parms(struct nlattr *data[],if (!data)return ; - parms->i_flags =VTI_ISVTI ; +__set_bit (IP_TUNNEL_VTI_BIT , parms->i_flags);if (data[IFLA_VTI_LINK ]) parms->link =nla_get_u32 (data[IFLA_VTI_LINK ]);
net/ipv4/ipip.c +15 -6
@@ -130,13 +130,16 @@ static int ipip_err(struct sk_buff *skb, u32 info)struct net *net =dev_net (skb->dev);struct ip_tunnel_net *itn =net_generic (net, ipip_net_id);const struct iphdr *iph = (const struct iphdr *)skb->data; +IP_TUNNEL_DECLARE_FLAGS (flags) = { };const int type =icmp_hdr (skb)->type;const int code =icmp_hdr (skb)->code;struct ip_tunnel *t;int err =0 ; - t =ip_tunnel_lookup (itn, skb->dev->ifindex,TUNNEL_NO_KEY , - iph->daddr, iph->saddr,0 ); +__set_bit (IP_TUNNEL_NO_KEY_BIT , flags); + + t =ip_tunnel_lookup (itn, skb->dev->ifindex, flags, iph->daddr, + iph->saddr,0 );if (!t) { err = -ENOENT ; goto out;
@@ -213,13 +216,16 @@ static int ipip_tunnel_rcv(struct sk_buff *skb, u8 ipproto) {struct net *net =dev_net (skb->dev);struct ip_tunnel_net *itn =net_generic (net, ipip_net_id); +IP_TUNNEL_DECLARE_FLAGS (flags) = { };struct metadata_dst *tun_dst =NULL ;struct ip_tunnel *tunnel;const struct iphdr *iph; +__set_bit (IP_TUNNEL_NO_KEY_BIT , flags); + iph =ip_hdr (skb); - tunnel =ip_tunnel_lookup (itn, skb->dev->ifindex,TUNNEL_NO_KEY , - iph->saddr, iph->daddr,0 ); + tunnel =ip_tunnel_lookup (itn, skb->dev->ifindex, flags, iph->saddr, + iph->daddr,0 );if (tunnel) {const struct tnl_ptk_info *tpi;
@@ -238,7 +244,9 @@ static int ipip_tunnel_rcv(struct sk_buff *skb, u8 ipproto)if (iptunnel_pull_header (skb,0 , tpi->proto, false)) goto drop;if (tunnel->collect_md) { - tun_dst =ip_tun_rx_dst (skb,0 ,0 ,0 ); +ip_tunnel_flags_zero (flags); + + tun_dst =ip_tun_rx_dst (skb, flags,0 ,0 );if (!tun_dst)return 0 ;ip_tunnel_md_udp_encap (skb, &tun_dst->u.tun_info);
@@ -340,7 +348,8 @@ ipip_tunnel_ctl(struct net_device *dev, struct ip_tunnel_parm_kern *p, int cmd) } p->i_key = p->o_key =0 ; - p->i_flags = p->o_flags =0 ; +ip_tunnel_flags_zero (p->i_flags); +ip_tunnel_flags_zero (p->o_flags);return ip_tunnel_ctl (dev, p, cmd); }
net/ipv4/udp_tunnel_core.c +3 -2
@@ -183,7 +183,8 @@ void udp_tunnel_sock_release(struct socket *sock)EXPORT_SYMBOL_GPL (udp_tunnel_sock_release);struct metadata_dst *udp_tun_rx_dst (struct sk_buff *skb,unsigned short family, -__be16 flags,__be64 tunnel_id,int md_size) +const unsigned long *flags, +__be64 tunnel_id,int md_size) {struct metadata_dst *tun_dst;struct ip_tunnel_info *info;
@@ -199,7 +200,7 @@ struct metadata_dst *udp_tun_rx_dst(struct sk_buff *skb, unsigned short family, info->key.tp_src =udp_hdr (skb)->source; info->key.tp_dst =udp_hdr (skb)->dest;if (udp_hdr (skb)->check) - info->key.tun_flags |=TUNNEL_CSUM ; +__set_bit (IP_TUNNEL_CSUM_BIT , info->key.tun_flags);return tun_dst; }EXPORT_SYMBOL_GPL (udp_tun_rx_dst);
net/ipv6/ip6_gre.c +49 -36
229 lines not on this page · raw message
net/ipv6/ip6_tunnel.c +7 -7
@@ -798,17 +798,15 @@ static int __ip6_tnl_rcv(struct ip6_tnl *tunnel, struct sk_buff *skb,const struct ipv6hdr *ipv6h;int nh, err; -if ((!(tpi->flags &TUNNEL_CSUM ) && - (tunnel->parms.i_flags &TUNNEL_CSUM )) || - ((tpi->flags &TUNNEL_CSUM ) && - !(tunnel->parms.i_flags &TUNNEL_CSUM ))) { +if (test_bit (IP_TUNNEL_CSUM_BIT , tunnel->parms.i_flags) != +test_bit (IP_TUNNEL_CSUM_BIT , tpi->flags)) {DEV_STATS_INC (tunnel->dev, rx_crc_errors);DEV_STATS_INC (tunnel->dev, rx_errors); goto drop; } -if (tunnel->parms.i_flags &TUNNEL_SEQ ) { -if (!(tpi->flags &TUNNEL_SEQ ) || +if (test_bit (IP_TUNNEL_SEQ_BIT , tunnel->parms.i_flags)) { +if (!test_bit (IP_TUNNEL_SEQ_BIT , tpi->flags) || (tunnel->i_seqno && (s32)(ntohl (tpi->seq) - tunnel->i_seqno) <0 )) {DEV_STATS_INC (tunnel->dev, rx_fifo_errors);
@@ -946,7 +944,9 @@ static int ipxip6_rcv(struct sk_buff *skb, u8 ipproto,if (iptunnel_pull_header (skb,0 , tpi->proto, false)) goto drop;if (t->parms.collect_md) { - tun_dst =ipv6_tun_rx_dst (skb,0 ,0 ,0 ); +IP_TUNNEL_DECLARE_FLAGS (flags) = { }; + + tun_dst =ipv6_tun_rx_dst (skb, flags,0 ,0 );if (!tun_dst) goto drop; }
net/ipv6/sit.c +3 -2
@@ -207,7 +207,7 @@ static int ipip6_tunnel_create(struct net_device *dev)__dev_addr_set (dev, &t->parms.iph.saddr,4 );memcpy (dev->broadcast, &t->parms.iph.daddr,4 ); -if ((__force u16 )t->parms.i_flags &SIT_ISATAP ) +if (test_bit (IP_TUNNEL_SIT_ISATAP_BIT , t->parms.i_flags)) dev->priv_flags |=IFF_ISATAP ; dev->rtnl_link_ops = &sit_link_ops;
@@ -1700,7 +1700,8 @@ static int ipip6_fill_info(struct sk_buff *skb, const struct net_device *dev)nla_put_u8 (skb,IFLA_IPTUN_PMTUDISC , !!(parm->iph.frag_off &htons (IP_DF ))) ||nla_put_u8 (skb,IFLA_IPTUN_PROTO , parm->iph.protocol) || -nla_put_be16 (skb,IFLA_IPTUN_FLAGS , parm->i_flags) || +nla_put_be16 (skb,IFLA_IPTUN_FLAGS , +ip_tunnel_flags_to_be16 (parm->i_flags)) || nla_put_u32(skb, IFLA_IPTUN_FWMARK, tunnel->fwmark)) goto nla_put_failure;
net/netfilter/ipvs/ip_vs_core.c +5 -1
@@ -1550,6 +1550,7 @@ static int ipvs_gre_decap(struct netns_ipvs *ipvs, struct sk_buff *skb,if (!dest) goto unk;if (dest->tun_type ==IP_VS_CONN_F_TUNNEL_TYPE_GRE ) { +IP_TUNNEL_DECLARE_FLAGS (flags);__be16 type;/* Only support version 0 and C (csum) */
@@ -1560,7 +1561,10 @@ static int ipvs_gre_decap(struct netns_ipvs *ipvs, struct sk_buff *skb,if (type !=htons (ETH_P_IP )) goto unk; *proto =IPPROTO_IPIP ; -return gre_calc_hlen (gre_flags_to_tnl_flags (greh->flags)); + +gre_flags_to_tnl_flags (flags, greh->flags); + +return gre_calc_hlen (flags); } unk:
net/netfilter/ipvs/ip_vs_xmit.c +10 -10
@@ -390,10 +390,10 @@ __ip_vs_get_out_rt(struct netns_ipvs *ipvs, int skb_af, struct sk_buff *skb, skb->ip_summed == CHECKSUM_PARTIAL) mtu -=GUE_PLEN_REMCSUM +GUE_LEN_PRIV ; }else if (dest->tun_type ==IP_VS_CONN_F_TUNNEL_TYPE_GRE ) { -__be16 tflags =0 ; +IP_TUNNEL_DECLARE_FLAGS (tflags) = { };if (dest->tun_flags &IP_VS_TUNNEL_ENCAP_FLAG_CSUM ) - tflags |=TUNNEL_CSUM ; +__set_bit (IP_TUNNEL_CSUM_BIT , tflags); mtu -=gre_calc_hlen (tflags); }if (mtu <68 ) {
@@ -553,10 +553,10 @@ __ip_vs_get_out_rt_v6(struct netns_ipvs *ipvs, int skb_af, struct sk_buff *skb, skb->ip_summed == CHECKSUM_PARTIAL) mtu -=GUE_PLEN_REMCSUM +GUE_LEN_PRIV ; }else if (dest->tun_type ==IP_VS_CONN_F_TUNNEL_TYPE_GRE ) { -__be16 tflags =0 ; +IP_TUNNEL_DECLARE_FLAGS (tflags) = { };if (dest->tun_flags &IP_VS_TUNNEL_ENCAP_FLAG_CSUM ) - tflags |=TUNNEL_CSUM ; +__set_bit (IP_TUNNEL_CSUM_BIT , tflags); mtu -=gre_calc_hlen (tflags); }if (mtu <IPV6_MIN_MTU ) {
@@ -1082,11 +1082,11 @@ ipvs_gre_encap(struct net *net, struct sk_buff *skb, {__be16 proto = *next_protocol ==IPPROTO_IPIP ?htons (ETH_P_IP ) :htons (ETH_P_IPV6 ); -__be16 tflags =0 ; +IP_TUNNEL_DECLARE_FLAGS (tflags) = { };size_t hdrlen;if (cp->dest->tun_flags &IP_VS_TUNNEL_ENCAP_FLAG_CSUM ) - tflags |=TUNNEL_CSUM ; +__set_bit (IP_TUNNEL_CSUM_BIT , tflags); hdrlen =gre_calc_hlen (tflags);gre_build_header (skb, hdrlen, tflags, proto,0 ,0 );
@@ -1165,11 +1165,11 @@ ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp, max_headroom +=sizeof (struct udphdr ) + gue_hdrlen; }else if (tun_type ==IP_VS_CONN_F_TUNNEL_TYPE_GRE ) { +IP_TUNNEL_DECLARE_FLAGS (tflags) = { };size_t gre_hdrlen; -__be16 tflags =0 ;if (tun_flags &IP_VS_TUNNEL_ENCAP_FLAG_CSUM ) - tflags |=TUNNEL_CSUM ; +__set_bit (IP_TUNNEL_CSUM_BIT , tflags); gre_hdrlen =gre_calc_hlen (tflags); max_headroom += gre_hdrlen;
@@ -1310,11 +1310,11 @@ ip_vs_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp, max_headroom +=sizeof (struct udphdr ) + gue_hdrlen; }else if (tun_type ==IP_VS_CONN_F_TUNNEL_TYPE_GRE ) { +IP_TUNNEL_DECLARE_FLAGS (tflags) = { };size_t gre_hdrlen; -__be16 tflags =0 ;if (tun_flags &IP_VS_TUNNEL_ENCAP_FLAG_CSUM ) - tflags |=TUNNEL_CSUM ; +__set_bit (IP_TUNNEL_CSUM_BIT , tflags); gre_hdrlen =gre_calc_hlen (tflags); max_headroom += gre_hdrlen;
net/netfilter/nft_tunnel.c +25 -19
134 lines not on this page · raw message
net/openvswitch/flow_netlink.c +37 -24
193 lines not on this page · raw message
net/psample/psample.c +14 -12
@@ -221,7 +221,7 @@ static int __psample_ip_tun_to_nlattr(struct sk_buff *skb,const struct ip_tunnel_key *tun_key = &tun_info->key;int tun_opts_len = tun_info->options_len; -if (tun_key->tun_flags &TUNNEL_KEY && +if (test_bit (IP_TUNNEL_KEY_BIT , tun_key->tun_flags) &&nla_put_be64 (skb,PSAMPLE_TUNNEL_KEY_ATTR_ID , tun_key->tun_id,PSAMPLE_TUNNEL_KEY_ATTR_PAD ))return -EMSGSIZE ;
@@ -257,10 +257,10 @@ static int __psample_ip_tun_to_nlattr(struct sk_buff *skb,return -EMSGSIZE ;if (nla_put_u8 (skb,PSAMPLE_TUNNEL_KEY_ATTR_TTL , tun_key->ttl))return -EMSGSIZE ; -if ((tun_key->tun_flags &TUNNEL_DONT_FRAGMENT ) && +if (test_bit (IP_TUNNEL_DONT_FRAGMENT_BIT , tun_key->tun_flags) &&nla_put_flag (skb,PSAMPLE_TUNNEL_KEY_ATTR_DONT_FRAGMENT ))return -EMSGSIZE ; -if ((tun_key->tun_flags &TUNNEL_CSUM ) && +if (test_bit (IP_TUNNEL_CSUM_BIT , tun_key->tun_flags) &&nla_put_flag (skb,PSAMPLE_TUNNEL_KEY_ATTR_CSUM ))return -EMSGSIZE ; if (tun_key->tp_src &&
@@ -269,15 +269,16 @@ static int __psample_ip_tun_to_nlattr(struct sk_buff *skb,if (tun_key->tp_dst &&nla_put_be16 (skb,PSAMPLE_TUNNEL_KEY_ATTR_TP_DST , tun_key->tp_dst))return -EMSGSIZE ; -if ((tun_key->tun_flags &TUNNEL_OAM ) && +if (test_bit (IP_TUNNEL_OAM_BIT , tun_key->tun_flags) &&nla_put_flag (skb,PSAMPLE_TUNNEL_KEY_ATTR_OAM ))return -EMSGSIZE ;if (tun_opts_len) { -if (tun_key->tun_flags &TUNNEL_GENEVE_OPT && +if (test_bit (IP_TUNNEL_GENEVE_OPT_BIT , tun_key->tun_flags) &&nla_put (skb,PSAMPLE_TUNNEL_KEY_ATTR_GENEVE_OPTS , tun_opts_len, tun_opts))return -EMSGSIZE ; -else if (tun_key->tun_flags &TUNNEL_ERSPAN_OPT && +else if (test_bit (IP_TUNNEL_ERSPAN_OPT_BIT , + tun_key->tun_flags) &&nla_put (skb,PSAMPLE_TUNNEL_KEY_ATTR_ERSPAN_OPTS , tun_opts_len, tun_opts))return -EMSGSIZE ;
@@ -314,7 +315,7 @@ static int psample_tunnel_meta_len(struct ip_tunnel_info *tun_info)int tun_opts_len = tun_info->options_len;int sum =nla_total_size (0 );/* PSAMPLE_ATTR_TUNNEL */ -if (tun_key->tun_flags &TUNNEL_KEY ) +if (test_bit (IP_TUNNEL_KEY_BIT , tun_key->tun_flags)) sum +=nla_total_size_64bit (sizeof (u64));if (tun_info->mode &IP_TUNNEL_INFO_BRIDGE )
@@ -337,20 +338,21 @@ static int psample_tunnel_meta_len(struct ip_tunnel_info *tun_info)if (tun_key->tos) sum +=nla_total_size (sizeof (u8)); sum +=nla_total_size (sizeof (u8));/* TTL */ -if (tun_key->tun_flags &TUNNEL_DONT_FRAGMENT ) +if (test_bit (IP_TUNNEL_DONT_FRAGMENT_BIT , tun_key->tun_flags)) sum +=nla_total_size (0 ); -if (tun_key->tun_flags &TUNNEL_CSUM ) +if (test_bit (IP_TUNNEL_CSUM_BIT , tun_key->tun_flags)) sum +=nla_total_size (0 );if (tun_key->tp_src) sum +=nla_total_size (sizeof (u16));if (tun_key->tp_dst) sum +=nla_total_size (sizeof (u16)); -if (tun_key->tun_flags &TUNNEL_OAM ) +if (test_bit (IP_TUNNEL_OAM_BIT , tun_key->tun_flags)) sum +=nla_total_size (0 );if (tun_opts_len) { -if (tun_key->tun_flags &TUNNEL_GENEVE_OPT ) +if (test_bit (IP_TUNNEL_GENEVE_OPT_BIT , tun_key->tun_flags)) sum +=nla_total_size (tun_opts_len); -else if (tun_key->tun_flags &TUNNEL_ERSPAN_OPT ) +else if (test_bit (IP_TUNNEL_ERSPAN_OPT_BIT , + tun_key->tun_flags)) sum +=nla_total_size (tun_opts_len); }
net/sched/act_tunnel_key.c +18 -18
@@ -230,7 +230,7 @@ static int tunnel_key_copy_opts(const struct nlattr *nla, u8 *dst,nla_for_each_attr (attr, head, len, rem) {switch (nla_type (attr)) {case TCA_TUNNEL_KEY_ENC_OPTS_GENEVE : -if (type && type !=TUNNEL_GENEVE_OPT ) { +if (type && type !=IP_TUNNEL_GENEVE_OPT_BIT ) {NL_SET_ERR_MSG (extack,"Duplicate type for geneve options" );return -EINVAL ; }
@@ -247,7 +247,7 @@ static int tunnel_key_copy_opts(const struct nlattr *nla, u8 *dst, dst_len -= opt_len; dst += opt_len; } - type =TUNNEL_GENEVE_OPT ; + type =IP_TUNNEL_GENEVE_OPT_BIT ;break ;case TCA_TUNNEL_KEY_ENC_OPTS_VXLAN :if (type) {
@@ -259,7 +259,7 @@ static int tunnel_key_copy_opts(const struct nlattr *nla, u8 *dst,if (opt_len <0 )return opt_len; opts_len += opt_len; - type =TUNNEL_VXLAN_OPT ; + type =IP_TUNNEL_VXLAN_OPT_BIT ;break ;case TCA_TUNNEL_KEY_ENC_OPTS_ERSPAN :if (type) {
@@ -271,7 +271,7 @@ static int tunnel_key_copy_opts(const struct nlattr *nla, u8 *dst,if (opt_len <0 )return opt_len; opts_len += opt_len; - type =TUNNEL_ERSPAN_OPT ; + type =IP_TUNNEL_ERSPAN_OPT_BIT ;break ; } }
@@ -302,7 +302,7 @@ static int tunnel_key_opts_set(struct nlattr *nla, struct ip_tunnel_info *info,switch (nla_type (nla_data (nla))) {case TCA_TUNNEL_KEY_ENC_OPTS_GENEVE :#if IS_ENABLED (CONFIG_INET ) - info->key.tun_flags |=TUNNEL_GENEVE_OPT ; +__set_bit (IP_TUNNEL_GENEVE_OPT_BIT , info->key.tun_flags);return tunnel_key_copy_opts (nla,ip_tunnel_info_opts (info), opts_len, extack);#else
@@ -310,7 +310,7 @@ static int tunnel_key_opts_set(struct nlattr *nla, struct ip_tunnel_info *info,#endif case TCA_TUNNEL_KEY_ENC_OPTS_VXLAN :#if IS_ENABLED (CONFIG_INET ) - info->key.tun_flags |=TUNNEL_VXLAN_OPT ; +__set_bit (IP_TUNNEL_VXLAN_OPT_BIT , info->key.tun_flags);return tunnel_key_copy_opts (nla,ip_tunnel_info_opts (info), opts_len, extack);#else
@@ -318,7 +318,7 @@ static int tunnel_key_opts_set(struct nlattr *nla, struct ip_tunnel_info *info,#endif case TCA_TUNNEL_KEY_ENC_OPTS_ERSPAN :#if IS_ENABLED (CONFIG_INET ) - info->key.tun_flags |=TUNNEL_ERSPAN_OPT ; +__set_bit (IP_TUNNEL_ERSPAN_OPT_BIT , info->key.tun_flags);return tunnel_key_copy_opts (nla,ip_tunnel_info_opts (info), opts_len, extack);#else
@@ -363,6 +363,7 @@ static int tunnel_key_init(struct net *net, struct nlattr *nla,bool bind = act_flags &TCA_ACT_FLAGS_BIND ;struct nlattr *tb[TCA_TUNNEL_KEY_MAX +1 ];struct tcf_tunnel_key_params *params_new; +IP_TUNNEL_DECLARE_FLAGS (flags) = { };struct metadata_dst *metadata =NULL ;struct tcf_chain *goto_ch =NULL ;struct tc_tunnel_key *parm;
@@ -371,7 +372,6 @@ static int tunnel_key_init(struct net *net, struct nlattr *nla,__be16 dst_port =0 ;__be64 key_id =0 ;int opts_len =0 ; -__be16 flags =0 ;u8 tos, ttl;int ret =0 ;u32 index;
@@ -412,16 +412,16 @@ static int tunnel_key_init(struct net *net, struct nlattr *nla, key32 =nla_get_be32 (tb[TCA_TUNNEL_KEY_ENC_KEY_ID ]); key_id =key32_to_tunnel_id (key32); - flags =TUNNEL_KEY ; +__set_bit (IP_TUNNEL_KEY_BIT , flags); } - flags |=TUNNEL_CSUM ; +__set_bit (IP_TUNNEL_CSUM_BIT , flags);if (tb[TCA_TUNNEL_KEY_NO_CSUM ] &&nla_get_u8 (tb[TCA_TUNNEL_KEY_NO_CSUM ])) - flags &= ~TUNNEL_CSUM ; +__clear_bit (IP_TUNNEL_CSUM_BIT , flags);if (nla_get_flag (tb[TCA_TUNNEL_KEY_NO_FRAG ])) - flags |=TUNNEL_DONT_FRAGMENT ; +__set_bit (IP_TUNNEL_DONT_FRAGMENT_BIT , flags);if (tb[TCA_TUNNEL_KEY_ENC_DST_PORT ]) dst_port =nla_get_be16 (tb[TCA_TUNNEL_KEY_ENC_DST_PORT ]);
@@ -663,15 +663,15 @@ static int tunnel_key_opts_dump(struct sk_buff *skb,if (!start)return -EMSGSIZE ; -if (info->key.tun_flags &TUNNEL_GENEVE_OPT ) { +if (test_bit (IP_TUNNEL_GENEVE_OPT_BIT , info->key.tun_flags)) { err =tunnel_key_geneve_opts_dump (skb, info);if (err) goto err_out; - }else if (info->key.tun_flags &TUNNEL_VXLAN_OPT ) { + }else if (test_bit (IP_TUNNEL_VXLAN_OPT_BIT , info->key.tun_flags)) { err =tunnel_key_vxlan_opts_dump (skb, info);if (err) goto err_out; - }else if (info->key.tun_flags &TUNNEL_ERSPAN_OPT ) { + }else if (test_bit (IP_TUNNEL_ERSPAN_OPT_BIT , info->key.tun_flags)) { err =tunnel_key_erspan_opts_dump (skb, info);if (err) goto err_out;
@@ -741,7 +741,7 @@ static int tunnel_key_dump(struct sk_buff *skb, struct tc_action *a,struct ip_tunnel_key *key = &info->key;__be32 key_id =tunnel_id_to_key32 (key->tun_id); - if (((key->tun_flags & TUNNEL_KEY) && + if ((test_bit(IP_TUNNEL_KEY_BIT, key->tun_flags) && nla_put_be32(skb, TCA_TUNNEL_KEY_ENC_KEY_ID, key_id)) || tunnel_key_dump_addresses(skb, ¶ms->tcft_enc_metadata->u.tun_info) ||
@@ -749,8 +749,8 @@ static int tunnel_key_dump(struct sk_buff *skb, struct tc_action *a,nla_put_be16 (skb,TCA_TUNNEL_KEY_ENC_DST_PORT , key->tp_dst)) ||nla_put_u8 (skb,TCA_TUNNEL_KEY_NO_CSUM , - !(key->tun_flags &TUNNEL_CSUM )) || - ((key->tun_flags &TUNNEL_DONT_FRAGMENT ) && + !test_bit (IP_TUNNEL_CSUM_BIT , key->tun_flags)) || + (test_bit (IP_TUNNEL_DONT_FRAGMENT_BIT , key->tun_flags) &&nla_put_flag (skb,TCA_TUNNEL_KEY_NO_FRAG )) || tunnel_key_opts_dump(skb, info)) goto nla_put_failure;
net/sched/cls_flower.c +14 -13
@@ -1454,12 +1454,13 @@ static int fl_set_enc_opt(struct nlattr **tb, struct fl_flow_key *key,switch (nla_type (nla_opt_key)) {case TCA_FLOWER_KEY_ENC_OPTS_GENEVE :if (key->enc_opts.dst_opt_type && - key->enc_opts.dst_opt_type !=TUNNEL_GENEVE_OPT ) { + key->enc_opts.dst_opt_type != +IP_TUNNEL_GENEVE_OPT_BIT ) {NL_SET_ERR_MSG (extack,"Duplicate type for geneve options" );return -EINVAL ; } option_len =0 ; - key->enc_opts.dst_opt_type =TUNNEL_GENEVE_OPT ; + key->enc_opts.dst_opt_type =IP_TUNNEL_GENEVE_OPT_BIT ; option_len =fl_set_geneve_opt (nla_opt_key, key, key_depth, option_len, extack);
@@ -1470,7 +1471,7 @@ static int fl_set_enc_opt(struct nlattr **tb, struct fl_flow_key *key,/* At the same time we need to parse through the mask * in order to verify exact and mask attribute lengths. */ - mask->enc_opts.dst_opt_type =TUNNEL_GENEVE_OPT ; + mask->enc_opts.dst_opt_type =IP_TUNNEL_GENEVE_OPT_BIT ; option_len =fl_set_geneve_opt (nla_opt_msk, mask, msk_depth, option_len, extack);
@@ -1489,7 +1490,7 @@ static int fl_set_enc_opt(struct nlattr **tb, struct fl_flow_key *key,return -EINVAL ; } option_len =0 ; - key->enc_opts.dst_opt_type =TUNNEL_VXLAN_OPT ; + key->enc_opts.dst_opt_type =IP_TUNNEL_VXLAN_OPT_BIT ; option_len =fl_set_vxlan_opt (nla_opt_key, key, key_depth, option_len, extack);
@@ -1500,7 +1501,7 @@ static int fl_set_enc_opt(struct nlattr **tb, struct fl_flow_key *key,/* At the same time we need to parse through the mask * in order to verify exact and mask attribute lengths. */ - mask->enc_opts.dst_opt_type =TUNNEL_VXLAN_OPT ; + mask->enc_opts.dst_opt_type =IP_TUNNEL_VXLAN_OPT_BIT ; option_len =fl_set_vxlan_opt (nla_opt_msk, mask, msk_depth, option_len, extack);
@@ -1519,7 +1520,7 @@ static int fl_set_enc_opt(struct nlattr **tb, struct fl_flow_key *key,return -EINVAL ; } option_len =0 ; - key->enc_opts.dst_opt_type =TUNNEL_ERSPAN_OPT ; + key->enc_opts.dst_opt_type =IP_TUNNEL_ERSPAN_OPT_BIT ; option_len =fl_set_erspan_opt (nla_opt_key, key, key_depth, option_len, extack);
@@ -1530,7 +1531,7 @@ static int fl_set_enc_opt(struct nlattr **tb, struct fl_flow_key *key,/* At the same time we need to parse through the mask * in order to verify exact and mask attribute lengths. */ - mask->enc_opts.dst_opt_type =TUNNEL_ERSPAN_OPT ; + mask->enc_opts.dst_opt_type =IP_TUNNEL_ERSPAN_OPT_BIT ; option_len =fl_set_erspan_opt (nla_opt_msk, mask, msk_depth, option_len, extack);
@@ -1550,7 +1551,7 @@ static int fl_set_enc_opt(struct nlattr **tb, struct fl_flow_key *key,return -EINVAL ; } option_len =0 ; - key->enc_opts.dst_opt_type =TUNNEL_GTP_OPT ; + key->enc_opts.dst_opt_type =IP_TUNNEL_GTP_OPT_BIT ; option_len =fl_set_gtp_opt (nla_opt_key, key, key_depth, option_len, extack);
@@ -1561,7 +1562,7 @@ static int fl_set_enc_opt(struct nlattr **tb, struct fl_flow_key *key,/* At the same time we need to parse through the mask * in order to verify exact and mask attribute lengths. */ - mask->enc_opts.dst_opt_type =TUNNEL_GTP_OPT ; + mask->enc_opts.dst_opt_type =IP_TUNNEL_GTP_OPT_BIT ; option_len =fl_set_gtp_opt (nla_opt_msk, mask, msk_depth, option_len, extack);
@@ -3202,22 +3203,22 @@ static int fl_dump_key_options(struct sk_buff *skb, int enc_opt_type, goto nla_put_failure;switch (enc_opts->dst_opt_type) { -case TUNNEL_GENEVE_OPT : +case IP_TUNNEL_GENEVE_OPT_BIT : err =fl_dump_key_geneve_opt (skb, enc_opts);if (err) goto nla_put_failure;break ; -case TUNNEL_VXLAN_OPT : +case IP_TUNNEL_VXLAN_OPT_BIT : err =fl_dump_key_vxlan_opt (skb, enc_opts);if (err) goto nla_put_failure;break ; -case TUNNEL_ERSPAN_OPT : +case IP_TUNNEL_ERSPAN_OPT_BIT : err =fl_dump_key_erspan_opt (skb, enc_opts);if (err) goto nla_put_failure;break ; -case TUNNEL_GTP_OPT : +case IP_TUNNEL_GTP_OPT_BIT : err =fl_dump_key_gtp_opt (skb, enc_opts);if (err) goto nla_put_failure;
Signature · 1 line
2.44.0
PATCH v6 17/21 net: net_test: add tests for IP tunnel flags conversion helpers
In reply to Alexander LobakinNow that there are helpers for converting IP tunnel flags between the old __be16 format and the bitmap format, make sure they work as expected by adding a couple of tests to the networking testing suite. The helpers are all inline, so no dependencies on the related CONFIG_* (or a standalone module) are needed.
Cover three possible cases:
1. No bits past BIT(15) are set, VTI/SIT bits are not set. This conversion is almost a direct assignment.
2. No bits past BIT(15) are set, but VTI/SIT bit is set. During the conversion, it must be transformed into BIT(16) in the bitmap, but still compatible with the __be16 format.
3. The bitmap has bits past BIT(15) set (not the VTI/SIT one). The result will be truncated.
Note that currently __IP_TUNNEL_FLAG_NUM is 17 (incl. special), which means that the result of this case is currently semi-false-positive. When BIT(17) is finally here, it will be adjusted accordingly.
---
net/core/Makefile | 2 +-
net/core/{gso_test.c => net_test.c} | 132 ++++++++++++++++++++++++++--
2 files changed, 125 insertions(+), 9 deletions(-)
rename net/core/{gso_test.c => net_test.c} (67%)net/core/Makefile +1 -1
@@ -41,4 +41,4 @@ obj-$(CONFIG_NET_SOCK_MSG) += skmsg.o obj-$(CONFIG_BPF_SYSCALL) += sock_map.o obj-$(CONFIG_BPF_SYSCALL) += bpf_sk_storage.o obj-$(CONFIG_OF) += of_net.o -obj-$(CONFIG_NET_TEST) += gso_test.o +obj-$(CONFIG_NET_TEST) += net_test.o
net/core/net_test.c renamed from net/core/gso_test.c +124 -8
147 lines not on this page · raw message
Signature · 1 line
2.44.0
PATCH v6 18/21 pfcp: add PFCP module
In reply to Alexander LobakinFrom: Wojciech Drewek <[email protected]>
Packet Forwarding Control Protocol (PFCP) is a 3GPP Protocol used between the control plane and the user plane function. It is specified in TS 29.244[1].
Note that this module is not designed to support this Protocol in the kernel space. There is no support for parsing any PFCP messages. There is no API that could be used by any userspace daemon. Basically it does not support PFCP. This protocol is sophisticated and there is no need for implementing it in the kernel. The purpose of this module is to allow users to setup software and hardware offload of PFCP packets using tc tool.
When user requests to create a PFCP device, a new socket is created. The socket is set up with port number 8805 which is specific for PFCP [29.244 4.2.2]. This allow to receive PFCP request messages, response messages use other ports.
Note that only one PFCP netdev can be created.
Only IPv4 is supported at this time.
[1] https://portal.3gpp.org/desktopmodules/Specifications/SpecificationDetails.aspx?specificationId=3111
--- drivers/net/Kconfig | 13 +++ drivers/net/Makefile | 1 + include/net/pfcp.h | 17 ++++ drivers/net/pfcp.c | 223 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 254 insertions(+) create mode 100644 include/net/pfcp.h create mode 100644 drivers/net/pfcp.c
drivers/net/Kconfig +13 -0
@@ -290,6 +290,19 @@ config GTP To compile this drivers as a module, choose M here: the module will be called gtp. +config PFCP + tristate "Packet Forwarding Control Protocol (PFCP)" + depends on INET + select NET_UDP_TUNNEL + help + This allows one to create PFCP virtual interfaces that allows to + set up software and hardware offload of PFCP packets. + Note that this module does not support PFCP protocol in the kernel space. + There is no support for parsing any PFCP messages. + + To compile this drivers as a module, choose M here: the module + will be called pfcp. + config AMT tristate "Automatic Multicast Tunneling (AMT)" depends on INET && IP_MULTICAST
drivers/net/Makefile +1 -0
@@ -38,6 +38,7 @@ obj-$(CONFIG_GENEVE) += geneve.o obj-$(CONFIG_BAREUDP) += bareudp.o obj-$(CONFIG_GTP) += gtp.o obj-$(CONFIG_NLMON) += nlmon.o +obj-$(CONFIG_PFCP) += pfcp.o obj-$(CONFIG_NET_VRF) += vrf.o obj-$(CONFIG_VSOCKMON) += vsockmon.o obj-$(CONFIG_MHI_NET) += mhi_net.o
include/net/pfcp.h new file +17 -0
@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _PFCP_H_ +#define _PFCP_H_ + +#include <linux/netdevice.h> +#include <linux/string.h> +#include <linux/types.h> + +#define PFCP_PORT 8805 + +static inline bool netif_is_pfcp (const struct net_device *dev) +{ +return dev->rtnl_link_ops && + !strcmp (dev->rtnl_link_ops->kind,"pfcp" ); +} + +#endif
drivers/net/pfcp.c new file +223 -0
223 lines not on this page · raw message
Signature · 1 line
2.44.0
PATCH v6 19/21 pfcp: always set pfcp metadata
In reply to Alexander LobakinFrom: Michal Swiatkowski <[email protected]>
In PFCP receive path set metadata needed by flower code to do correct classification based on this metadata.
--- include/net/ip_tunnels.h | 3 + include/net/pfcp.h | 73 ++++++++++++++++++++++ include/uapi/linux/if_tunnel.h | 3 + include/uapi/linux/pkt_cls.h | 14 +++++ drivers/net/pfcp.c | 81 ++++++++++++++++++++++++- net/core/net_test.c | 7 +-- net/sched/cls_flower.c | 107 +++++++++++++++++++++++++++++++++ 7 files changed, 282 insertions(+), 6 deletions(-)
include/net/ip_tunnels.h +3 -0
@@ -216,6 +216,7 @@ static inline void ip_tunnel_set_options_present(unsigned long *flags)__set_bit (IP_TUNNEL_VXLAN_OPT_BIT , present);__set_bit (IP_TUNNEL_ERSPAN_OPT_BIT , present);__set_bit (IP_TUNNEL_GTP_OPT_BIT , present); +__set_bit (IP_TUNNEL_PFCP_OPT_BIT , present);ip_tunnel_flags_or (flags, flags, present); }
@@ -228,6 +229,7 @@ static inline void ip_tunnel_clear_options_present(unsigned long *flags)__set_bit (IP_TUNNEL_VXLAN_OPT_BIT , present);__set_bit (IP_TUNNEL_ERSPAN_OPT_BIT , present);__set_bit (IP_TUNNEL_GTP_OPT_BIT , present); +__set_bit (IP_TUNNEL_PFCP_OPT_BIT , present);__ipt_flag_op (bitmap_andnot, flags, flags, present); }
@@ -240,6 +242,7 @@ static inline bool ip_tunnel_is_options_present(const unsigned long *flags)__set_bit (IP_TUNNEL_VXLAN_OPT_BIT , present);__set_bit (IP_TUNNEL_ERSPAN_OPT_BIT , present);__set_bit (IP_TUNNEL_GTP_OPT_BIT , present); +__set_bit (IP_TUNNEL_PFCP_OPT_BIT , present);return ip_tunnel_flags_intersect (flags, present); }
include/net/pfcp.h +73 -0
85 lines not on this page · raw message
include/uapi/linux/if_tunnel.h +3 -0
@@ -212,6 +212,9 @@ enum {IP_TUNNEL_VTI_BIT ,IP_TUNNEL_SIT_ISATAP_BIT =IP_TUNNEL_VTI_BIT , +/* Flags starting from here are not available via the old UAPI */ +IP_TUNNEL_PFCP_OPT_BIT ,/* OPTIONS_PRESENT */ + __IP_TUNNEL_FLAG_NUM, };
include/uapi/linux/pkt_cls.h +14 -0
@@ -587,6 +587,10 @@ enum {* TCA_FLOWER_KEY_ENC_OPT_GTP_ * attributes */ +TCA_FLOWER_KEY_ENC_OPTS_PFCP ,/* Nested +* TCA_FLOWER_KEY_ENC_IPT_PFCP +* attributes +*/ __TCA_FLOWER_KEY_ENC_OPTS_MAX, };
@@ -636,6 +640,16 @@ enum {#define TCA_FLOWER_KEY_ENC_OPT_GTP_MAX \ (__TCA_FLOWER_KEY_ENC_OPT_GTP_MAX - 1) +enum { +TCA_FLOWER_KEY_ENC_OPT_PFCP_UNSPEC , +TCA_FLOWER_KEY_ENC_OPT_PFCP_TYPE ,/* u8 */ +TCA_FLOWER_KEY_ENC_OPT_PFCP_SEID ,/* be64 */ + __TCA_FLOWER_KEY_ENC_OPT_PFCP_MAX, +}; + +#define TCA_FLOWER_KEY_ENC_OPT_PFCP_MAX \ + (__TCA_FLOWER_KEY_ENC_OPT_PFCP_MAX - 1) +enum {TCA_FLOWER_KEY_MPLS_OPTS_UNSPEC ,TCA_FLOWER_KEY_MPLS_OPTS_LSE ,
drivers/net/pfcp.c +80 -1
111 lines not on this page · raw message
net/core/net_test.c +2 -5
@@ -335,11 +335,8 @@ static const struct ip_tunnel_flags_test ip_tunnel_flags_test[] = { ip_tunnel_flags_1),IP_TUNNEL_FLAGS_TEST ("conflict" , ip_tunnel_flags_2_src, true,VTI_ISVTI , ip_tunnel_flags_2_exp), -IP_TUNNEL_FLAGS_TEST ("new" , ip_tunnel_flags_3_src, -/* This must be set to ``false`` once -* ``__IP_TUNNEL_FLAG_NUM`` goes above 17. -*/ - true,cpu_to_be16 (BIT (IP_TUNNEL_VXLAN_OPT_BIT )), +IP_TUNNEL_FLAGS_TEST ("new" , ip_tunnel_flags_3_src, false, +cpu_to_be16 (BIT (IP_TUNNEL_VXLAN_OPT_BIT )), ip_tunnel_flags_3_exp), };
net/sched/cls_flower.c +107 -0
149 lines not on this page · raw message
Signature · 1 line
2.44.0
Re: [PATCH net-next v6 19/21] pfcp: always set pfcp metadata
Quoted 26 lines · Alexander Lobakin
drivers/net/pfcp.c +26
-0+static int pfcp_encap_recv (struct sock *sk,struct sk_buff *skb) +{ +IP_TUNNEL_DECLARE_FLAGS (flags) = { }; +struct metadata_dst *tun_dst; +struct pfcp_metadata *md; +struct pfcphdr *unparsed; +struct pfcp_dev *pfcp; + +if (unlikely (!pskb_may_pull (skb,PFCP_HLEN ))) + goto drop; + + pfcp =rcu_dereference_sk_user_data (sk); +if (unlikely (!pfcp)) + goto drop; + + unparsed =pfcp_hdr (skb); + +ip_tunnel_flags_zero (flags); + tun_dst =udp_tun_rx_dst (skb, sk->sk_family, flags,0 , +sizeof (*md)); +if (unlikely (!tun_dst)) + goto drop; + + md =ip_tunnel_info_opts (&tun_dst->u.tun_info); +if (unlikely (!md)) + goto drop;
drivers/net/pfcp.c struct pfcp_net { · line 86
Quoted 10 lines
drivers/net/pfcp.c +10
-0+ +if (unparsed->flags &PFCP_SEID_FLAG ) +pfcp_session_recv (pfcp, skb, md); +else +pfcp_node_recv (pfcp, skb, md); + +__set_bit (IP_TUNNEL_PFCP_OPT_BIT , flags); +ip_tunnel_info_opts_set (&tun_dst->u.tun_info, md,sizeof (*md), + flags); +
The memcpy() in the ip_tunnel_info_opts_set() causes a string.h fortification warning, with at least gcc-13:
In function 'fortify_memcpy_chk',
inlined from 'ip_tunnel_info_opts_set' at include/net/ip_tunnels.h:619:3,
inlined from 'pfcp_encap_recv' at drivers/net/pfcp.c:84:2:
include/linux/fortify-string.h:553:25: error: call to '__write_overflow_field' declared with attribute warning: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror=attribute-warning]
553 | __write_overflow_field(p_size_field, size);
As far as I can tell, the warning is caused by the ambiguity of the union, but what I noticed is that it also seems to copy a buffer to itself, as 'md' is initialized to tun_dst->u.tun_info as well.
Is this intentional?
Arnd
Re: [PATCH net-next v6 19/21] pfcp: always set pfcp metadata
Quoted 48 lines · Arnd Bergmann
Quoted 26 lines · Alexander Lobakin
drivers/net/pfcp.c +26
-0+static int pfcp_encap_recv (struct sock *sk,struct sk_buff *skb) +{ +IP_TUNNEL_DECLARE_FLAGS (flags) = { }; +struct metadata_dst *tun_dst; +struct pfcp_metadata *md; +struct pfcphdr *unparsed; +struct pfcp_dev *pfcp; + +if (unlikely (!pskb_may_pull (skb,PFCP_HLEN ))) + goto drop; + + pfcp =rcu_dereference_sk_user_data (sk); +if (unlikely (!pfcp)) + goto drop; + + unparsed =pfcp_hdr (skb); + +ip_tunnel_flags_zero (flags); + tun_dst =udp_tun_rx_dst (skb, sk->sk_family, flags,0 , +sizeof (*md)); +if (unlikely (!tun_dst)) + goto drop; + + md =ip_tunnel_info_opts (&tun_dst->u.tun_info); +if (unlikely (!md)) + goto drop;drivers/net/pfcp.c struct pfcp_net { · line 86
Quoted 10 lines
drivers/net/pfcp.c +10
-0+ +if (unparsed->flags &PFCP_SEID_FLAG ) +pfcp_session_recv (pfcp, skb, md); +else +pfcp_node_recv (pfcp, skb, md); + +__set_bit (IP_TUNNEL_PFCP_OPT_BIT , flags); +ip_tunnel_info_opts_set (&tun_dst->u.tun_info, md,sizeof (*md), + flags); +The
memcpy()in theip_tunnel_info_opts_set()causes astring.hfortification warning, with at least gcc-13:In function '
fortify_memcpy_chk',
inlined from 'ip_tunnel_info_opts_set' atinclude/net/ip_tunnels.h:619:3,
inlined from 'pfcp_encap_recv' atdrivers/net/pfcp.c:84:2:
include/linux/fortify-string.h:553:25: error: call to '__write_overflow_field' declared with attribute warning: detected write beyond size of field (1st parameter); maybe usestruct_group()? [-Werror=attribute-warning]
553 |__write_overflow_field(p_size_field, size);
Quoted 6 lines
As far as I can tell, the warning is caused by the ambiguity of the union, but what I noticed is that it also seems to copy a buffer to itself, as 'md' is initialized to
tun_dst->u.tun_infoas well.Is this intentional?
I used ip_tunnel_info_opts_set() to set options_len and flags. You are right that it can and probably should be changed to:
__set_bit(IP_TUNNEL_PFCP_OPT_BIT, tun_dst->u.tun_info.key.tun_flags); tun_dst->u.tun_info.options_len = sizeof(*md);
instead of copying the buffer. Thanks for pointing it.
Should I sent a fix to the net or patch to the maintainer? Sorry, don't know how this kind of situations are being solved.
Michal
Quoted 2 lines
Arnd
Re: [PATCH net-next v6 19/21] pfcp: always set pfcp metadata
Quoted 22 lines · Michal Swiatkowski
Quoted 11 lines · Arnd Bergmann
On Wed, Mar 27, 2024, at 16:23, Alexander Lobakin wrote:
The
memcpy()in theip_tunnel_info_opts_set()causes astring.hfortification warning, with at least gcc-13:In function '
fortify_memcpy_chk',
inlined from 'ip_tunnel_info_opts_set' atinclude/net/ip_tunnels.h:619:3,
inlined from 'pfcp_encap_recv' atdrivers/net/pfcp.c:84:2:
include/linux/fortify-string.h:553:25: error: call to '__write_overflow_field' declared with attribute warning: detected write beyond size of field (1st parameter); maybe usestruct_group()? [-Werror=attribute-warning]
553 |__write_overflow_field(p_size_field, size);Quoted 6 lines
As far as I can tell, the warning is caused by the ambiguity of the union, but what I noticed is that it also seems to copy a buffer to itself, as 'md' is initialized to
tun_dst->u.tun_infoas well.Is this intentional?
I used
ip_tunnel_info_opts_set()to setoptions_lenand flags. You are right that it can and probably should be changed to:
Quoted 7 lines
__set_bit(IP_TUNNEL_PFCP_OPT_BIT, tun_dst->u.tun_info.key.tun_flags);tun_dst->u.tun_info.options_len=sizeof(*md);instead of copying the buffer. Thanks for pointing it.
Should I sent a fix to the net or patch to the maintainer? Sorry, don't know how this kind of situations are being solved.
I tend to just send fixes when I run into build problems like this, but since you already know what's going on, I think it's best if you send the fix as well, citing the warning I mention in the commit log, and explaining that the warning can be avoided by the simpler code but is otherwise a false-positive.
Arnd
Re: [Intel-wired-lan] [PATCH net-next v6 19/21] pfcp: always set pfcp metadata
Quoted 28 lines · Arnd Bergmann
Quoted 27 lines · Michal Swiatkowski
Quoted 11 lines · Arnd Bergmann
On Wed, Mar 27, 2024, at 16:23, Alexander Lobakin wrote:
The
memcpy()in theip_tunnel_info_opts_set()causes astring.hfortification warning, with at least gcc-13:In function '
fortify_memcpy_chk',
inlined from 'ip_tunnel_info_opts_set' atinclude/net/ip_tunnels.h:619:3,
inlined from 'pfcp_encap_recv' atdrivers/net/pfcp.c:84:2:
include/linux/fortify-string.h:553:25: error: call to '__write_overflow_field' declared with attribute warning: detected write beyond size of field (1st parameter); maybe usestruct_group()? [-Werror=attribute-warning]
553 |__write_overflow_field(p_size_field, size);Quoted 6 lines
As far as I can tell, the warning is caused by the ambiguity of the union, but what I noticed is that it also seems to copy a buffer to itself, as 'md' is initialized to
tun_dst->u.tun_infoas well.Is this intentional?
I used
ip_tunnel_info_opts_set()to setoptions_lenand flags. You are right that it can and probably should be changed to:
__set_bit(IP_TUNNEL_PFCP_OPT_BIT, tun_dst->u.tun_info.key.tun_flags);tun_dst->u.tun_info.options_len=sizeof(*md);instead of copying the buffer. Thanks for pointing it.
Quoted 9 lines
Quoted 2 lines
Should I sent a fix to the net or patch to the maintainer? Sorry, don't know how this kind of situations are being solved.
I tend to just send fixes when I run into build problems like this, but since you already know what's going on, I think it's best if you send the fix as well, citing the warning I mention in the commit log, and explaining that the warning can be avoided by the simpler code but is otherwise a false-positive.
Thanks, I will sent the fix ASAP.
Michal
Quoted 1 line
Arnd
PATCH v6 20/21 ice: refactor ICE_TC_FLWR_FIELD_ENC_OPTS
In reply to Alexander LobakinFrom: Marcin Szycik <[email protected]>
FLOW_DISSECTOR_KEY_ENC_OPTS can be used for multiple headers, but currently it is treated as GTP-exclusive in ice. Rename ICE_TC_FLWR_FIELD_ENC_OPTS to ICE_TC_FLWR_FIELD_GTP_OPTS and check for tunnel type earlier. After this refactor, it is easier to add new headers using FLOW_DISSECTOR_KEY_ENC_OPTS
- instead of checking tunnel type in ice_tc_count_lkups() and ice_tc_fill_tunnel_outer(), it needs to be checked only once, in ice_parse_tunnel_attr().
--- drivers/net/ethernet/intel/ice/ice_tc_lib.h | 2 +- drivers/net/ethernet/intel/ice/ice_tc_lib.c | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/net/ethernet/intel/ice/ice_tc_lib.h +1 -1
@@ -22,7 +22,7 @@#define ICE_TC_FLWR_FIELD_ENC_SRC_L4_PORT BIT(15)#define ICE_TC_FLWR_FIELD_ENC_DST_MAC BIT(16)#define ICE_TC_FLWR_FIELD_ETH_TYPE_ID BIT(17) -#define ICE_TC_FLWR_FIELD_ENC_OPTS BIT(18) +#define ICE_TC_FLWR_FIELD_GTP_OPTS BIT(18)#define ICE_TC_FLWR_FIELD_CVLAN BIT(19)#define ICE_TC_FLWR_FIELD_PPPOE_SESSID BIT(20)#define ICE_TC_FLWR_FIELD_PPP_PROTO BIT(21)
drivers/net/ethernet/intel/ice/ice_tc_lib.c +5 -5
@@ -35,7 +35,7 @@ ice_tc_count_lkups(u32 flags, struct ice_tc_flower_lyr_2_4_hdrs *headers,if (flags &ICE_TC_FLWR_FIELD_ENC_DST_MAC ) lkups_cnt++; -if (flags &ICE_TC_FLWR_FIELD_ENC_OPTS ) +if (flags &ICE_TC_FLWR_FIELD_GTP_OPTS ) lkups_cnt++; if (flags & (ICE_TC_FLWR_FIELD_ENC_SRC_IPV4 |
@@ -219,8 +219,7 @@ ice_tc_fill_tunnel_outer(u32 flags, struct ice_tc_flower_fltr *fltr, i++; } -if (flags &ICE_TC_FLWR_FIELD_ENC_OPTS && - (fltr->tunnel_type ==TNL_GTPU || fltr->tunnel_type ==TNL_GTPC )) { +if (flags &ICE_TC_FLWR_FIELD_GTP_OPTS ) { list[i].type =ice_proto_type_from_tunnel (fltr->tunnel_type);if (fltr->gtp_pdu_info_masks.pdu_type) {
@@ -1401,7 +1400,8 @@ ice_parse_tunnel_attr(struct net_device *dev, struct flow_rule *rule, } } -if (flow_rule_match_key (rule,FLOW_DISSECTOR_KEY_ENC_OPTS )) { +if (flow_rule_match_key (rule,FLOW_DISSECTOR_KEY_ENC_OPTS ) && + (fltr->tunnel_type ==TNL_GTPU || fltr->tunnel_type ==TNL_GTPC )) {struct flow_match_enc_opts match;flow_rule_match_enc_opts (rule, &match);
@@ -1412,7 +1412,7 @@ ice_parse_tunnel_attr(struct net_device *dev, struct flow_rule *rule,memcpy (&fltr->gtp_pdu_info_masks, &match.mask->data[0 ],sizeof (struct gtp_pdu_session_info )); - fltr->flags |=ICE_TC_FLWR_FIELD_ENC_OPTS ; + fltr->flags |=ICE_TC_FLWR_FIELD_GTP_OPTS ; }return 0 ;
Signature · 1 line
2.44.0
PATCH v6 21/21 ice: Add support for PFCP hardware offload in switchdev
In reply to Alexander LobakinFrom: Marcin Szycik <[email protected]>
Add support for creating PFCP filters in switchdev mode. Add support for parsing PFCP-specific tc options: S flag and SEID.
To create a PFCP filter, a special netdev must be created and passed to tc command:
ip link add pfcp0 type pfcp
tc filter add dev eth0 ingress prio 1 flower pfcp_opts \
1:123/ff:fffffffffffffff0 skip_hw action mirred egress redirect \
dev pfcp0Changes in iproute2 [1] are required to be able to use pfcp_opts in tc.
ICE COMMS package is required to create a filter as it contains PFCP profiles.
--- .../net/ethernet/intel/ice/ice_flex_type.h | 4 +- .../ethernet/intel/ice/ice_protocol_type.h | 12 +++ drivers/net/ethernet/intel/ice/ice_switch.h | 2 + drivers/net/ethernet/intel/ice/ice_tc_lib.h | 6 ++ drivers/net/ethernet/intel/ice/ice_ddp.c | 9 ++ drivers/net/ethernet/intel/ice/ice_switch.c | 85 +++++++++++++++++++ drivers/net/ethernet/intel/ice/ice_tc_lib.c | 58 +++++++++++-- 7 files changed, 169 insertions(+), 7 deletions(-)
drivers/net/ethernet/intel/ice/ice_flex_type.h +3 -1
@@ -93,6 +93,7 @@ enum ice_tunnel_type {TNL_GRETAP ,TNL_GTPC ,TNL_GTPU , +TNL_PFCP , __TNL_TYPE_CNT,TNL_LAST =0xFF , TNL_ALL = 0xFF,
@@ -358,7 +359,8 @@ enum ice_prof_type {ICE_PROF_TUN_GRE =0x4 ,ICE_PROF_TUN_GTPU =0x8 ,ICE_PROF_TUN_GTPC =0x10 , -ICE_PROF_TUN_ALL =0x1E , +ICE_PROF_TUN_PFCP =0x20 , +ICE_PROF_TUN_ALL =0x3E , ICE_PROF_ALL = 0xFF, };
drivers/net/ethernet/intel/ice/ice_protocol_type.h +12 -0
@@ -43,6 +43,7 @@ enum ice_protocol_type {ICE_NVGRE ,ICE_GTP ,ICE_GTP_NO_PAY , +ICE_PFCP ,ICE_PPPOE ,ICE_L2TPV3 , ICE_VLAN_EX,
@@ -61,6 +62,7 @@ enum ice_sw_tunnel_type {ICE_SW_TUN_NVGRE ,ICE_SW_TUN_GTPU ,ICE_SW_TUN_GTPC , +ICE_SW_TUN_PFCP , ICE_ALL_TUNNELS /* All tunnel types including NVGRE */ };
@@ -202,6 +204,15 @@ struct ice_udp_gtp_hdr {u8 rsvrd; }; +struct ice_pfcp_hdr { +u8 flags; +u8 msg_type; +__be16 length; +__be64 seid; +__be32 seq; +u8 spare; +} __packed__aligned(__alignof__(u16)) ; +struct ice_pppoe_hdr {u8 rsrvd_ver_type;u8 rsrvd_code;
@@ -418,6 +429,7 @@ union ice_prot_hdr {struct ice_udp_tnl_hdr tnl_hdr;struct ice_nvgre_hdr nvgre_hdr;struct ice_udp_gtp_hdr gtp_hdr; +struct ice_pfcp_hdr pfcp_hdr;struct ice_pppoe_hdr pppoe_hdr;struct ice_l2tpv3_sess_hdr l2tpv3_sess_hdr;struct ice_hw_metadata metadata;
drivers/net/ethernet/intel/ice/ice_switch.h +2 -0
@@ -21,6 +21,8 @@#define ICE_PROFID_IPV6_GTPC_NO_TEID 45#define ICE_PROFID_IPV6_GTPU_TEID 46#define ICE_PROFID_IPV6_GTPU_IPV6_TCP_INNER 70 +#define ICE_PROFID_IPV4_PFCP_NODE 79 +#define ICE_PROFID_IPV6_PFCP_SESSION 82#define ICE_SW_RULE_VSI_LIST_SIZE (s, n) struct_size((s), vsi, (n))#define ICE_SW_RULE_RX_TX_HDR_SIZE (s, l) struct_size((s), hdr_data, (l))
drivers/net/ethernet/intel/ice/ice_tc_lib.h +6 -0
@@ -4,6 +4,9 @@#ifndef _ICE_TC_LIB_H_#define _ICE_TC_LIB_H_ +#include <linux/bits.h> +#include <net/pfcp.h> +#define ICE_TC_FLWR_FIELD_DST_MAC BIT(0)#define ICE_TC_FLWR_FIELD_SRC_MAC BIT(1)#define ICE_TC_FLWR_FIELD_VLAN BIT(2)
@@ -34,6 +37,7 @@#define ICE_TC_FLWR_FIELD_VLAN_PRIO BIT(27)#define ICE_TC_FLWR_FIELD_CVLAN_PRIO BIT(28)#define ICE_TC_FLWR_FIELD_VLAN_TPID BIT(29) +#define ICE_TC_FLWR_FIELD_PFCP_OPTS BIT(30)#define ICE_TC_FLOWER_MASK_32 0xFFFFFFFF
@@ -161,6 +165,8 @@ struct ice_tc_flower_fltr {__be32 tenant_id;struct gtp_pdu_session_info gtp_pdu_info_keys;struct gtp_pdu_session_info gtp_pdu_info_masks; +struct pfcp_metadata pfcp_meta_keys; +struct pfcp_metadata pfcp_meta_masks;u32 flags;u8 tunnel_type;struct ice_tc_flower_action action;
drivers/net/ethernet/intel/ice/ice_ddp.c +9 -0
@@ -721,6 +721,12 @@ static bool ice_is_gtp_c_profile(u16 prof_idx) } } +static bool ice_is_pfcp_profile (u16 prof_idx) +{ +return prof_idx >=ICE_PROFID_IPV4_PFCP_NODE && + prof_idx <=ICE_PROFID_IPV6_PFCP_SESSION ; +} +/** * ice_get_sw_prof_type - determine switch profile type * @hw: pointer to the HW structure
@@ -738,6 +744,9 @@ static enum ice_prof_type ice_get_sw_prof_type(struct ice_hw *hw,if (ice_is_gtp_u_profile (prof_idx))return ICE_PROF_TUN_GTPU ; +if (ice_is_pfcp_profile (prof_idx)) +return ICE_PROF_TUN_PFCP ; +for (i =0 ; i < hw->blk[ICE_BLK_SW ].es.fvw; i++) {/* UDP tunnel will have UDP_OF protocol ID and VNI offset */ if (fv->ew[i].prot_id == (u8)ICE_PROT_UDP_OF &&
drivers/net/ethernet/intel/ice/ice_switch.c +85 -0
133 lines not on this page · raw message
drivers/net/ethernet/intel/ice/ice_tc_lib.c +52 -6
106 lines not on this page · raw message
Signature · 1 line
2.44.0
This series was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:
Quoted 8 lines · On Wed, 27 Mar 2024 16:23:37 +0100 you wrote:
Add support for creating PFCP filters in switchdev mode. Add pfcp module that allows to create a PFCP-type netdev. The netdev then can be passed to tc when creating a filter to indicate that PFCP filter should be created.
To add a PFCP filter, a special netdev must be created and passed to tc command:
[...]
Here is the summary with links:
- [net-next,v6,01/21] lib/bitmap: add bitmap_{read,write}()
https://git.kernel.org/netdev/net-next/c/63c15822b8dd - [net-next,v6,02/21] lib/test_bitmap: add tests for bitmap_{read,write}() https://git.kernel.org/netdev/net-next/c/991e5583647d - [net-next,v6,03/21] lib/test_bitmap: use pr_info() for non-error messages https://git.kernel.org/netdev/net-next/c/f3e28876b6e0 - [net-next,v6,04/21] bitops: add missing prototype check https://git.kernel.org/netdev/net-next/c/72cc1980a0ef - [net-next,v6,05/21] bitops: make BYTES_TO_BITS() treewide-available (no matching commit) - [net-next,v6,06/21] bitops: let the compiler optimize {__,}assign_bit() https://git.kernel.org/netdev/net-next/c/5259401ef8f4 - [net-next,v6,07/21] linkmode: convert linkmode_{test,set,clear,mod}_bit() to macros https://git.kernel.org/netdev/net-next/c/8fab6a9d72e4 - [net-next,v6,08/21] s390/cio: rename bitmap_size() -> idset_bitmap_size() https://git.kernel.org/netdev/net-next/c/c1023f5634b9 - [net-next,v6,09/21] fs/ntfs3: add prefix to bitmap_size() and use BITS_TO_U64() (no matching commit) - [net-next,v6,10/21] btrfs: rename bitmap_set_bits() -> btrfs_bitmap_set_bits() https://git.kernel.org/netdev/net-next/c/4ca532d64648 - [net-next,v6,11/21] tools: move alignment-related macros to new <linux/align.h> https://git.kernel.org/netdev/net-next/c/10a04ff09bcc - [net-next,v6,12/21] bitmap: introduce generic optimized bitmap_size() (no matching commit) - [net-next,v6,13/21] bitmap: make bitmap_{get,set}_value8() use bitmap_{read,write}() https://git.kernel.org/netdev/net-next/c/b44759705f7d - [net-next,v6,14/21] lib/bitmap: add compile-time test for __assign_bit() optimization https://git.kernel.org/netdev/net-next/c/7adaf37f7f10 - [net-next,v6,15/21] ip_tunnel: use a separate struct to store tunnel params in the kernel (no matching commit) - [net-next,v6,16/21] ip_tunnel: convert __be16 tunnel flags to bitmaps (no matching commit) - [net-next,v6,17/21] net: net_test: add tests for IP tunnel flags conversion helpers https://git.kernel.org/netdev/net-next/c/5b2be2ab76d1
- [net-next,v6,18/21] pfcp: add PFCP module
(no matching commit)
- [net-next,v6,19/21] pfcp: always set pfcp metadata
(no matching commit)
- [net-next,v6,20/21] ice: refactor ICE_TC_FLWR_FIELD_ENC_OPTS (no matching commit)
- [net-next,v6,21/21] ice: Add support for PFCP hardware offload in switchdev (no matching commit)
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Daer Alexander, Wojciech,
forgive me for being late to the party, but I just saw the PFCP support hitting Linus'' git repo in 1b294a1f35616977caddaddf3e9d28e576a1adbc and was trying to figure out what it is all about. Is there some kind of article, kernel documentation or other explanation about it?
I have a prehistoric background in Linux kernel networking, and have been spending much of the last two decades in creating open source implemenmtations of 3GPP specifications.
So I'm very familiar with what PFCP is, and what it does, and how it is used as a protocol by the 3GPP control plane to control the user/data plane.
Conceptually it seems very odd to me to have something like *pfcp net-devices*. PFCP is just a control plane protocol, not a tunnel mechanism.
From the Kconfig:
Review
Quoted 7 lines
(quoted diff) +7
-0+config PFCP + tristate "Packet Forwarding Control Protocol (PFCP)" + depends on INET + select NET_UDP_TUNNEL + help + This allows one to create PFCP virtual interfaces that allows to + set up software and hardware offload of PFCP packets.
I'm curious to understand why are *pfcp* packets hardware offloaded? PFCP is just the control plane, similar to you can consider netlink the control plane by which userspace programs control the data plane.
I can fully understand that GTP-U packets are offloaded to kernel space or hardware, and that then some control plane mechanism like PFCP is needed to control that data plane. But offloading packets of that control protocol?
I also see the following in the patch:
Quoted 1 line
+MODULE_DESCRIPTION("Interface driver for PFCP encapsulated traffic");
PFCP is not an encapsulation protocol for user plane traffic. It is not a tunneling protocol. GTP-U is the tunneling protocol, whose implementations (typically UPFs) are remote-controlled by PFCP.
Review
Quoted 2 lines
(quoted diff) +2
-0+ Note that this module does not support PFCP protocol in the kernel space. + There is no support for parsing any PFCP messages.
If I may be frank, why do we introduce something called "pfcp" to the kernel, if it doesn't actually implement any of the PFCP specification 3GPP TS 29.244 (which is specifying a very concrete protocol)?
Once again, I just try to understand what you're trying to do here. It's very much within my professional field, but I somehow cannot align what I see within this patch set with my existing world view of what PFCP is and how it works.
If anyone else has a better grasp of the architecture of this kernel PFCP support, or has any pointers, I'd be very happy to follow up on that.
Thanks for your time,
Harald
Signature · 4 lines
- Harald Welte <[email protected]> https://laforge.gnumonks.org/ ============================================================================ "Privacy in residential applications is a desirable marketing option." (ETSI EN 300 175-7 Ch. A6)
Quoted 1 line · Harald Welte
Daer Alexander, Wojciech,
Hi Harald,
Quoted 32 lines
forgive me for being late to the party, but I just saw the PFCP support hitting Linus'' git repo in
1b294a1f35616977caddaddf3e9d28e576a1adbcand was trying to figure out what it is all about. Is there some kind of article, kernel documentation or other explanation about it?I have a prehistoric background in Linux kernel networking, and have been spending much of the last two decades in creating open source implemenmtations of 3GPP specifications.
So I'm very familiar with what PFCP is, and what it does, and how it is used as a protocol by the 3GPP control plane to control the user/data plane.
Conceptually it seems very odd to me to have something like *pfcp net-devices*. PFCP is just a control plane protocol, not a tunnel mechanism.
From the
Kconfig:Review
Quoted 7 lines
(quoted diff) +7
-0+config PFCP + tristate "Packet Forwarding Control Protocol (PFCP)" + depends on INET + select NET_UDP_TUNNEL + help + This allows one to create PFCP virtual interfaces that allows to + set up software and hardware offload of PFCP packets.I'm curious to understand why are *pfcp* packets hardware offloaded? PFCP is just the control plane, similar to you can consider netlink the control plane by which userspace programs control the data plane.
Quoted 4 lines
I can fully understand that GTP-U packets are offloaded to kernel space or hardware, and that then some control plane mechanism like PFCP is needed to control that data plane. But offloading packets of that control protocol?
It is hard for me to answer your concerns, because oposite to you, I don't have any experience with telco implementations. We had client that want to add offload rule for PFCP in the same way as for GTP. Intel hardware support matching on specific PFCP packet parts. We spent some time looking at possible implementations. As you said, it is a little odd to follow the same scheme for GTP and PFCP, but it look for me like reasonable solution.
The main idea is to allow user to match in tc flower on PFCP specific parts. To do that we need PFCP device (which is like dummy device for now, it isn't doing anything related to PFCP specification, only parsing).
Do you have better idea for that?
Quoted 9 lines
I also see the following in the patch:
Quoted 1 line
+MODULE_DESCRIPTION("Interface driver for PFCP encapsulated traffic");
PFCP is not an encapsulation protocol for user plane traffic. It is not a tunneling protocol. GTP-U is the tunneling protocol, whose implementations (typically UPFs) are remote-controlled by PFCP.
Agree, it is done like that to simplify implementation and reuse kernel software stack.
Quoted 7 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ Note that this module does not support PFCP protocol in the kernel space. + There is no support for parsing any PFCP messages.If I may be frank, why do we introduce something called "pfcp" to the kernel, if it doesn't actually implement any of the PFCP specification 3GPP TS 29.244 (which is specifying a very concrete protocol)?
Quoted 8 lines
Once again, I just try to understand what you're trying to do here. It's very much within my professional field, but I somehow cannot align what I see within this patch set with my existing world view of what PFCP is and how it works.
If anyone else has a better grasp of the architecture of this kernel PFCP support, or has any pointers, I'd be very happy to follow up on that.
This is the way to allow user to steer PFCP packet based on specific opts (type and seid) using tc flower. If you have better solution for that I will probably agree with you and will be willing to help you with better implementation.
I assume the biggest problem here is with treating PFCP as a tunnel (done for simplification and reuse) and lack of any functionality of PFCP device (moving the PFCP specification implementation into kernel probably isn't good idea and may never be accepted).
Offloading doesn't sound like problematic. If there is a user that want to use that (to offload for better performance, or even to steer between VFs based on PFCP specific parts) why not allow to do that?
In your opinion there should not be the pfcp device in kernel, or the device should have more functionality (or any functionality, because now it is only parsing)?
Quoted 4 lines
Thanks for your time,
Harald
Thanks,
Michal
Quoted 5 lines
Signature · 4 lines
- Harald Welte <[email protected]> https://laforge.gnumonks.org/ ============================================================================ "Privacy in residential applications is a desirable marketing option." (ETSI EN 300 175-7 Ch. A6)
Hi Michal,
thanks for your response.
Quoted 4 lines · Michal Swiatkowski
Quoted 4 lines
I'm curious to understand why are *pfcp* packets hardware offloaded? PFCP is just the control plane, similar to you can consider netlink the control plane by which userspace programs control the data plane.
Quoted 8 lines
Quoted 4 lines
I can fully understand that GTP-U packets are offloaded to kernel space or hardware, and that then some control plane mechanism like PFCP is needed to control that data plane. But offloading packets of that control protocol?
It is hard for me to answer your concerns, because oposite to you, I don't have any experience with telco implementations. We had client that want to add offload rule for PFCP in the same way as for GTP.
I've meanwhile done some reading and it seems there are indeed some papers suggesting that in specific implementations of control/data plane splits, the transaction rate between control and data plane (to set up / tear down / modify tunnels) is to low. As a work-around, the entire PFCP parsing is then off-loaded into (e.g. P4 capable) hardware.
So it seems at least there appears to be equipment where PFCP offloading is useful to significantly incresae performance.
For those curious, https://faculty.iiitd.ac.in/~rinku/resources/slides/2022-sosr-accelupf-slides.pdf
seems to cover one such configuration where offloading processing the
control-plane protocol into the P4 hardware switch has massively
improved the previously poor PFCP processing rate.
Quoted 5 lines
Intel
hardware support matching on specific PFCP packet parts. We spent some time looking at possible implementations. As you said, it is a little odd to follow the same scheme for GTP and PFCP, but it look for me like reasonable solution.
Based on what I understand, I am not sure I would agree with the "reasonable solution" part. But then of course, it is a subjective point of view.
I understand and appreciate the high-level goal of giving the user some way to configure a specific feature of an intel NIC.
However, I really don't think that this should come at the expense of introducing tunnel devices (or other net-devs) for things that are not tunnels, and by calling things PFCP whcih are not an implementation of PFCP.
Tou are introducing something called "pfcp" into the kernel, whcih is not pfcp. What if somebody else at some point wanted to introduce some actual PFCP support in some form? How should they call their sub-systems / Kconfigs / etc? They could no longer call it simply "pfcp" as you already used this very generic term for (from the perspective of PFCP) a specific niche use case of configuring a NIC to handle all of PFCP.
Quoted 1 line
Do you have better idea for that?
I am not familiar with the use cases and the intel NICs and what kind of tooling or third party software might be out there wanting to configure it. It's really not my domain of expertise and as such I have no specific proposal, sorry.
It just seems mind-boggling to me that we would introduce
* a net-device for sometthing that's not a net-device
* a tunnel for something that does no tunneling whatsoeer
* code mentioning "PFCP encapsulated traffic" when in fact it is impossible to encapsulate any traffic in PFCP, and the code does not - to the best of my understanding - do any such encapsulation or even configure hardware to perform any such non-existant PFCP encapsulation
[and possibly more] *just* so that a user can use 'tc' to configure a hardware offloading feature in their NIC.
IMHO, there must be a better way.
Quoted 11 lines
Quoted 8 lines
I also see the following in the patch:
Quoted 1 line
+MODULE_DESCRIPTION("Interface driver for PFCP encapsulated traffic");
PFCP is not an encapsulation protocol for user plane traffic. It is not a tunneling protocol. GTP-U is the tunneling protocol, whose implementations (typically UPFs) are remote-controlled by PFCP.
Agree, it is done like that to simplify implementation and reuse kernel software stack.
My comment was about the module description. It claims something that makes no sense and that it does not actually implement. Unless I'm not understanding what the code does, it is outright wrong and misleading.
Likewise is the comment on top of the drivers/net/pfcp.c file says:
Quoted 1 line
* PFCP according to 3GPP TS 29.244
While the code is in fact *not* implementing any part of TS 29.244. The code is using the udp_tunnel infrastructure for something that's not a tunnel. From what i can tell it is creating an in-kernel UDP socket (whcih can be done without any relation to udp_tunnel) and it is configuring hardware offload features in a NIC. The fact that the payload of those UDP packets may be PFCP is circumstancial - nothing in the code actually implements even the tiniest bit of PFCP protocol parsing.
Quoted 4 lines
This is the way to allow user to steer PFCP packet based on specific opts (type and seid) using tc flower. If you have better solution for that I will probably agree with you and will be willing to help you with better implementation.
sadly, neither tc nor intel NIC hardware offload capabilities are my domain of expertise, so I am unable to propose detials of a better solution.
Quoted 3 lines
I assume the biggest problem here is with treating PFCP as a tunnel (done for simplification and reuse) and lack of any functionality of PFCP device
I don't think the kernel should introduce a net-device (here specifically a tunnel device) for something that is not a tunnel. This device [nor the hardware accelerator it controls] will never encapsulate or decapsulate any PFCP packet, as PFCP is not a tunnel / encapsulation protocol.
Quoted 2 lines
(moving the PFCP specification implementation into kernel probably isn't good idea and may never be accepted).
I would agree, but that is a completely separate discussion. Even if one ignores this, the hypothetical kernel PFCP implementation would not be a tunnel, and not be a net-device at all. It would simply be some kind of in-kernel UDP socket parsing and responding to packets, similar to the in-kernel nfs daemon or whatever other in-kernel UDP users exist.
Also: The fact that you or we think an actual PFCP implementation would not be accepted in the kernel should *not* be an argument in favor of accepting something else into the kernel, call it PFCP and create tunnel devices for things that are not tunnels :)
Quoted 3 lines
Offloading doesn't sound like problematic. If there is a user that want to use that (to offload for better performance, or even to steer between VFs based on PFCP specific parts) why not allow to do that?
The papers I read convinced me that there is a use case. I very much believe the use case is a work-around for a different problem (the inefficiency of the control->data plance protocol in this case), but my opinion on that doesn't matter here. I do agree with you that there are apparently people who would want to make use of such a feature, and that there is nothing wrong with provoding them means to do this.
However, the *how* is what I strongly object to. Once again, I may miss some part of your architecture, and I am happy to be proven otherwise.
But if all of this is *just* to configure hardware offloading in a nic, I don't think there should be net-devices or tunnels that never encap/decap a single packet or for protocols / use cases that clearly do not encap or decap packets.
I also think this sets very bad precedent. What about other prootocols in the future? Will we see new tunnels in the kernel for things that are not tunnels at all, every time there is some new protocol that gains hardware offloading capability in some NIC? Surely this kind of proliferation is not the kind of software architecture we want to have?
Once again, I do apologize for raising my concerns at such a late stage. I am not a kernel developer anymore these days, and I do not follow any of the related mailing lists. It was pure coincidence that the net-next merge of some GTP improvements I was involved in specifying also contained the PFCP code and I started digging what this was all about.
Regards,
Harald
Signature · 4 lines
- Harald Welte <[email protected]> https://laforge.gnumonks.org/ ============================================================================ "Privacy in residential applications is a desirable marketing option." (ETSI EN 300 175-7 Ch. A6)
Quoted 25 lines · Harald Welte
Hi Michal,
thanks for your response.
Quoted 4 lines · Michal Swiatkowski
Quoted 4 lines
I'm curious to understand why are *pfcp* packets hardware offloaded? PFCP is just the control plane, similar to you can consider netlink the control plane by which userspace programs control the data plane.
Quoted 8 lines
Quoted 4 lines
I can fully understand that GTP-U packets are offloaded to kernel space or hardware, and that then some control plane mechanism like PFCP is needed to control that data plane. But offloading packets of that control protocol?
It is hard for me to answer your concerns, because oposite to you, I don't have any experience with telco implementations. We had client that want to add offload rule for PFCP in the same way as for GTP.
I've meanwhile done some reading and it seems there are indeed some papers suggesting that in specific implementations of control/data plane splits, the transaction rate between control and data plane (to set up / tear down / modify tunnels) is to low. As a work-around, the entire PFCP parsing is then off-loaded into (e.g. P4 capable) hardware.
Quoted 7 lines
So it seems at least there appears to be equipment where PFCP offloading is useful to significantly incresae performance.
For those curious, https://faculty.iiitd.ac.in/~rinku/resources/slides/2022-sosr-accelupf-slides.pdf
seems to cover one such configuration where offloading processing the
control-plane protocol into the P4 hardware switch has massively
improved the previously poor PFCP processing rate.
Thanks for the interesting link.
Quoted 19 lines
Quoted 6 lines
Intel
hardware support matching on specific PFCP packet parts. We spent some time looking at possible implementations. As you said, it is a little odd to follow the same scheme for GTP and PFCP, but it look for me like reasonable solution.Based on what I understand, I am not sure I would agree with the "reasonable solution" part. But then of course, it is a subjective point of view.
I understand and appreciate the high-level goal of giving the user some way to configure a specific feature of an intel NIC.
However, I really don't think that this should come at the expense of introducing tunnel devices (or other net-devs) for things that are not tunnels, and by calling things PFCP whcih are not an implementation of PFCP.
Quoted 7 lines
Tou are introducing something called "pfcp" into the kernel, whcih is not pfcp. What if somebody else at some point wanted to introduce some actual PFCP support in some form? How should they call their sub-systems / Kconfigs / etc? They could no longer call it simply "pfcp" as you already used this very generic term for (from the perspective of PFCP) a specific niche use case of configuring a NIC to handle all of PFCP.
What about changing the name and the description to better reflect what this new device is for? I don't have any idea for good fitting name.
Quoted 17 lines
Quoted 2 lines
Do you have better idea for that?
I am not familiar with the use cases and the intel NICs and what kind of tooling or third party software might be out there wanting to configure it. It's really not my domain of expertise and as such I have no specific proposal, sorry.
It just seems mind-boggling to me that we would introduce
* a net-device for sometthing that's not a net-device
* a tunnel for something that does no tunneling whatsoeer
* code mentioning "PFCP encapsulated traffic" when in fact it is impossible to encapsulate any traffic in PFCP, and the code does not - to the best of my understanding - do any such encapsulation or even configure hardware to perform any such non-existant PFCP encapsulation
Quoted 4 lines
[and possibly more] *just* so that a user can use 'tc' to configure a hardware offloading feature in their NIC.
IMHO, there must be a better way.
Yeah, let's say we didn't find the better way. I agree with you that it isn't the best solution. The problem is that we couldn't have found the better.
In short, if I remember correctly (because we sent first RFC more than one year ago), to be sure that the packet is PFCP and has PFCP specific fields to match, the UDP port needs to be checked. Currently any matching for UDP port in flower kernel code is to match tunnel. Because of that we treated it as a tunnel, only for simplification of this matching.
Why we need specific net-device is because of this simplification. All tunnels have their net-devices, so in tc code the decision if specific fields from the protocol can be matched is done based on net-device type. If PFCP will have specific ip proto (as example) ther won't be any problem, but as specific is only UDP port we end up in this messy solution.
Quoted 21 lines
Quoted 5 lines
Quoted 5 lines
I also see the following in the patch:
Quoted 1 line
+MODULE_DESCRIPTION("Interface driver for PFCP encapsulated traffic");
Quoted 7 lines
Quoted 4 lines
PFCP is not an encapsulation protocol for user plane traffic. It is not a tunneling protocol. GTP-U is the tunneling protocol, whose implementations (typically UPFs) are remote-controlled by PFCP.
Agree, it is done like that to simplify implementation and reuse kernel software stack.
My comment was about the module description. It claims something that makes no sense and that it does not actually implement. Unless I'm not understanding what the code does, it is outright wrong and misleading.
Likewise is the comment on top of the
drivers/net/pfcp.cfile says:Quoted 1 line
* PFCP according to 3GPP TS 29.244
Quoted 9 lines
While the code is in fact *not* implementing any part of TS 29.244. The code is using the
udp_tunnelinfrastructure for something that's not a tunnel. From what i can tell it is creating an in-kernel UDP socket (whcih can be done without any relation toudp_tunnel) and it is configuring hardware offload features in a NIC. The fact that the payload of those UDP packets may be PFCP is circumstancial - nothing in the code actually implements even the tiniest bit of PFCP protocol parsing.
Like I said it is only for tc to allow matching on the PFCP specific fields.
Quoted 13 lines
Quoted 4 lines
This is the way to allow user to steer PFCP packet based on specific opts (type and seid) using tc flower. If you have better solution for that I will probably agree with you and will be willing to help you with better implementation.
sadly, neither tc nor intel NIC hardware offload capabilities are my domain of expertise, so I am unable to propose detials of a better solution.
Quoted 3 lines
I assume the biggest problem here is with treating PFCP as a tunnel (done for simplification and reuse) and lack of any functionality of PFCP device
Quoted 6 lines
I don't think the kernel should introduce a net-device (here specifically a tunnel device) for something that is not a tunnel. This device [nor the hardware accelerator it controls] will never encapsulate or decapsulate any PFCP packet, as PFCP is not a tunnel / encapsulation protocol.
Good point, I hope to treate PFCP as only one exception and even remove it when we have better solution for allowing tc to match PFCP packets.
Quoted 25 lines
Quoted 2 lines
(moving the PFCP specification implementation into kernel probably isn't good idea and may never be accepted).
I would agree, but that is a completely separate discussion. Even if one ignores this, the hypothetical kernel PFCP implementation would not be a tunnel, and not be a net-device at all. It would simply be some kind of in-kernel UDP socket parsing and responding to packets, similar to the in-kernel nfs daemon or whatever other in-kernel UDP users exist.
Also: The fact that you or we think an actual PFCP implementation would not be accepted in the kernel should *not* be an argument in favor of accepting something else into the kernel, call it PFCP and create tunnel devices for things that are not tunnels :)
Quoted 3 lines
Offloading doesn't sound like problematic. If there is a user that want to use that (to offload for better performance, or even to steer between VFs based on PFCP specific parts) why not allow to do that?
The papers I read convinced me that there is a use case. I very much believe the use case is a work-around for a different problem (the inefficiency of the
control->dataplance protocol in this case), but my opinion on that doesn't matter here. I do agree with you that there are apparently people who would want to make use of such a feature, and that there is nothing wrong with provoding them means to do this.
Quoted 3 lines
However, the *how* is what I strongly object to. Once again, I may miss some part of your architecture, and I am happy to be proven otherwise.
It will be hard. As you said it is done "just to configure hardware offloading". Can't it be an argument here?
Quoted 11 lines
But if all of this is *just* to configure hardware offloading in a nic, I don't think there should be net-devices or tunnels that never encap/decap a single packet or for protocols / use cases that clearly do not encap or decap packets.
I also think this sets very bad precedent. What about other prootocols in the future? Will we see new tunnels in the kernel for things that are not tunnels at all, every time there is some new protocol that gains hardware offloading capability in some NIC? Surely this kind of proliferation is not the kind of software architecture we want to have?
Quoted 6 lines
Once again, I do apologize for raising my concerns at such a late stage. I am not a kernel developer anymore these days, and I do not follow any of the related mailing lists. It was pure coincidence that the net-next merge of some GTP improvements I was involved in specifying also contained the PFCP code and I started digging what this was all about.
No problem, sorry for no CCing you during all this revision of this changes.
Probably I can't convince you. We agree that the solution with additional netdev and treating PFCP as a tunnel is ugly solution. It is done only to allow tc flower matching (in hardware with fallback to software). Currently I don't have any idea for more suitable solution.
I willing to work on better idea if anybody have any.
Quoted 3 lines
Regards,
Harald
Thanks,
Michal
Quoted 5 lines
Signature · 4 lines
- Harald Welte <[email protected]> https://laforge.gnumonks.org/ ============================================================================ "Privacy in residential applications is a desirable marketing option." (ETSI EN 300 175-7 Ch. A6)