Skip to content
  1. Dec 09, 2019
  2. Dec 07, 2019
  3. Dec 05, 2019
  4. Dec 01, 2019
  5. Nov 30, 2019
  6. Nov 29, 2019
  7. Nov 28, 2019
  8. Nov 26, 2019
  9. Nov 25, 2019
  10. Nov 21, 2019
  11. Nov 20, 2019
  12. Nov 19, 2019
    • Andrii Nakryiko's avatar
      libbpf: Fix call relocation offset calculation bug · a0d7da26
      Andrii Nakryiko authored
      
      
      When relocating subprogram call, libbpf doesn't take into account
      relo->text_off, which comes from symbol's value. This generally works fine for
      subprograms implemented as static functions, but breaks for global functions.
      
      Taking a simplified test_pkt_access.c as an example:
      
      __attribute__ ((noinline))
      static int test_pkt_access_subprog1(volatile struct __sk_buff *skb)
      {
              return skb->len * 2;
      }
      
      __attribute__ ((noinline))
      static int test_pkt_access_subprog2(int val, volatile struct __sk_buff *skb)
      {
              return skb->len + val;
      }
      
      SEC("classifier/test_pkt_access")
      int test_pkt_access(struct __sk_buff *skb)
      {
              if (test_pkt_access_subprog1(skb) != skb->len * 2)
                      return TC_ACT_SHOT;
              if (test_pkt_access_subprog2(2, skb) != skb->len + 2)
                      return TC_ACT_SHOT;
              return TC_ACT_UNSPEC;
      }
      
      When compiled, we get two relocations, pointing to '.text' symbol. .text has
      st_value set to 0 (it points to the beginning of .text section):
      
      0000000000000008  000000050000000a R_BPF_64_32            0000000000000000 .text
      0000000000000040  000000050000000a R_BPF_64_32            0000000000000000 .text
      
      test_pkt_access_subprog1 and test_pkt_access_subprog2 offsets (targets of two
      calls) are encoded within call instruction's imm32 part as -1 and 2,
      respectively:
      
      0000000000000000 test_pkt_access_subprog1:
             0:       61 10 00 00 00 00 00 00 r0 = *(u32 *)(r1 + 0)
             1:       64 00 00 00 01 00 00 00 w0 <<= 1
             2:       95 00 00 00 00 00 00 00 exit
      
      0000000000000018 test_pkt_access_subprog2:
             3:       61 10 00 00 00 00 00 00 r0 = *(u32 *)(r1 + 0)
             4:       04 00 00 00 02 00 00 00 w0 += 2
             5:       95 00 00 00 00 00 00 00 exit
      
      0000000000000000 test_pkt_access:
             0:       bf 16 00 00 00 00 00 00 r6 = r1
      ===>   1:       85 10 00 00 ff ff ff ff call -1
             2:       bc 01 00 00 00 00 00 00 w1 = w0
             3:       b4 00 00 00 02 00 00 00 w0 = 2
             4:       61 62 00 00 00 00 00 00 r2 = *(u32 *)(r6 + 0)
             5:       64 02 00 00 01 00 00 00 w2 <<= 1
             6:       5e 21 08 00 00 00 00 00 if w1 != w2 goto +8 <LBB0_3>
             7:       bf 61 00 00 00 00 00 00 r1 = r6
      ===>   8:       85 10 00 00 02 00 00 00 call 2
             9:       bc 01 00 00 00 00 00 00 w1 = w0
            10:       61 62 00 00 00 00 00 00 r2 = *(u32 *)(r6 + 0)
            11:       04 02 00 00 02 00 00 00 w2 += 2
            12:       b4 00 00 00 ff ff ff ff w0 = -1
            13:       1e 21 01 00 00 00 00 00 if w1 == w2 goto +1 <LBB0_3>
            14:       b4 00 00 00 02 00 00 00 w0 = 2
      0000000000000078 LBB0_3:
            15:       95 00 00 00 00 00 00 00 exit
      
      Now, if we compile example with global functions, the setup changes.
      Relocations are now against specifically test_pkt_access_subprog1 and
      test_pkt_access_subprog2 symbols, with test_pkt_access_subprog2 pointing 24
      bytes into its respective section (.text), i.e., 3 instructions in:
      
      0000000000000008  000000070000000a R_BPF_64_32            0000000000000000 test_pkt_access_subprog1
      0000000000000048  000000080000000a R_BPF_64_32            0000000000000018 test_pkt_access_subprog2
      
      Calls instructions now encode offsets relative to function symbols and are both
      set ot -1:
      
      0000000000000000 test_pkt_access_subprog1:
             0:       61 10 00 00 00 00 00 00 r0 = *(u32 *)(r1 + 0)
             1:       64 00 00 00 01 00 00 00 w0 <<= 1
             2:       95 00 00 00 00 00 00 00 exit
      
      0000000000000018 test_pkt_access_subprog2:
             3:       61 20 00 00 00 00 00 00 r0 = *(u32 *)(r2 + 0)
             4:       0c 10 00 00 00 00 00 00 w0 += w1
             5:       95 00 00 00 00 00 00 00 exit
      
      0000000000000000 test_pkt_access:
             0:       bf 16 00 00 00 00 00 00 r6 = r1
      ===>   1:       85 10 00 00 ff ff ff ff call -1
             2:       bc 01 00 00 00 00 00 00 w1 = w0
             3:       b4 00 00 00 02 00 00 00 w0 = 2
             4:       61 62 00 00 00 00 00 00 r2 = *(u32 *)(r6 + 0)
             5:       64 02 00 00 01 00 00 00 w2 <<= 1
             6:       5e 21 09 00 00 00 00 00 if w1 != w2 goto +9 <LBB2_3>
             7:       b4 01 00 00 02 00 00 00 w1 = 2
             8:       bf 62 00 00 00 00 00 00 r2 = r6
      ===>   9:       85 10 00 00 ff ff ff ff call -1
            10:       bc 01 00 00 00 00 00 00 w1 = w0
            11:       61 62 00 00 00 00 00 00 r2 = *(u32 *)(r6 + 0)
            12:       04 02 00 00 02 00 00 00 w2 += 2
            13:       b4 00 00 00 ff ff ff ff w0 = -1
            14:       1e 21 01 00 00 00 00 00 if w1 == w2 goto +1 <LBB2_3>
            15:       b4 00 00 00 02 00 00 00 w0 = 2
      0000000000000080 LBB2_3:
            16:       95 00 00 00 00 00 00 00 exit
      
      Thus the right formula to calculate target call offset after relocation should
      take into account relocation's target symbol value (offset within section),
      call instruction's imm32 offset, and (subtracting, to get relative instruction
      offset) instruction index of call instruction itself. All that is shifted by
      number of instructions in main program, given all sub-programs are copied over
      after main program.
      
      Convert few selftests relying on bpf-to-bpf calls to use global functions
      instead of static ones.
      
      Fixes: 48cca7e4 ("libbpf: add support for bpf_call")
      Reported-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Signed-off-by: default avatarAndrii Nakryiko <andriin@fb.com>
      Acked-by: default avatarYonghong Song <yhs@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/20191119224447.3781271-1-andriin@fb.com
      a0d7da26
    • Amit Cohen's avatar
      selftests: forwarding: Add speed and auto-negotiation test · 64916b57
      Amit Cohen authored
      
      
      Check configurations and packets transference with different variations
      of autoneg and speed.
      
      Test plan:
      1. Test force of same speed with autoneg off
      2. Test force of different speeds with autoneg off (should fail)
      3. One side is autoneg on and other side sets force of common speeds
      4. One side is autoneg on and other side only advertises a subset of the
         common speeds (one speed of the subset)
      5. One side is autoneg on and other side only advertises a subset of the
         common speeds. Check that highest speed is negotiated
      6. Test autoneg on, but each side advertises different speeds (should
         fail)
      
      Signed-off-by: default avatarAmit Cohen <amitc@mellanox.com>
      Signed-off-by: default avatarIdo Schimmel <idosch@mellanox.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      64916b57
    • Amit Cohen's avatar
      selftests: forwarding: lib.sh: Add wait for dev with timeout · 8f72a9cf
      Amit Cohen authored
      
      
      Add a function that waits for device with maximum number of iterations.
      It enables to limit the waiting and prevent infinite loop.
      
      This will be used by the subsequent patch which will set two ports to
      different speeds in order to make sure they cannot negotiate a link.
      
      Waiting for all the setup is limited with 10 minutes for each device.
      
      Signed-off-by: default avatarAmit Cohen <amitc@mellanox.com>
      Signed-off-by: default avatarIdo Schimmel <idosch@mellanox.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      8f72a9cf
    • Amit Cohen's avatar
      selftests: forwarding: Add ethtool_lib.sh · 646cf7ed
      Amit Cohen authored
      
      
      Functions:
      1. speeds_arr_get
      	The function returns an array of speed values from
              /usr/include/linux/ethtool.h The array looks as follows:
      	[10baseT/Half] = 0,
      	[10baseT/Full] = 1,
      	...
      
      2. ethtool_set:
      	params: cmd
      	The function runs ethtool by cmd (ethtool -s cmd) and checks if
      	there was an error in configuration
      
      3. dev_speeds_get:
      	params: dev, with_mode (0 or 1), adver (0 or 1)
      	return value: Array of supported/Advertised link modes
      	with/without mode
      
      	* Example 1:
      	speeds_get swp1 0 0
      	return: 1000 10000 40000
      	* Example 2:
      	speeds_get swp1 1 1
      	return: 1000baseKX/Full 10000baseKR/Full 40000baseCR4/Full
      
      4. common_speeds_get:
      	params: dev1, dev2, with_mode (0 or 1), adver (0 or 1)
      	return value: Array of common speeds of dev1 and dev2
      
      	* Example:
      	common_speeds_get swp1 swp2 0 0
      	return: 1000 10000
      	Assuming that swp1 supports 1000 10000 40000 and swp2 supports
      	1000 10000
      
      Signed-off-by: default avatarAmit Cohen <amitc@mellanox.com>
      Signed-off-by: default avatarIdo Schimmel <idosch@mellanox.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      646cf7ed
    • Danielle Ratson's avatar
      selftests: mlxsw: Check devlink device before running test · b22b0b0b
      Danielle Ratson authored
      
      
      The scale test for Spectrum-2 should only be invoked for Spectrum-2.
      Skip the test otherwise.
      
      Signed-off-by: default avatarDanielle Ratson <danieller@mellanox.com>
      Signed-off-by: default avatarIdo Schimmel <idosch@mellanox.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      b22b0b0b
    • Danielle Ratson's avatar
      selftests: mlxsw: Add router scale test for Spectrum-2 · 0fed96fa
      Danielle Ratson authored
      
      
      Same as for Spectrum-1, test the ability to add the maximum number of
      routes possible to the switch.
      
      Invoke the test from the 'resource_scale' wrapper script.
      
      Signed-off-by: default avatarDanielle Ratson <danieller@mellanox.com>
      Signed-off-by: default avatarIdo Schimmel <idosch@mellanox.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      0fed96fa
Loading