1. 31 Mar, 2020 16 commits
    • David S. Miller's avatar
      Merge branch 'Add-packet-trap-policers-support' · 6fe9a949
      David S. Miller authored
      Ido Schimmel says:
      
      ====================
      Add packet trap policers support
      
      Background
      ==========
      
      Devices capable of offloading the kernel's datapath and perform
      functions such as bridging and routing must also be able to send (trap)
      specific packets to the kernel (i.e., the CPU) for processing.
      
      For example, a device acting as a multicast-aware bridge must be able to
      trap IGMP membership reports to the kernel for processing by the bridge
      module.
      
      Motivation
      ==========
      
      In most cases, the underlying device is capable of handling packet rates
      that are several orders of magnitude higher compared to those that can
      be handled by the CPU.
      
      Therefore, in order to prevent the underlying device from overwhelming
      the CPU, devices usually include packet trap policers that are able to
      police the trapped packets to rates that can be handled by the CPU.
      
      Proposed solution
      =================
      
      This patch set allows capable device drivers to register their supported
      packet trap policers with devlink. User space can then tune the
      parameters of these policers (currently, rate and burst size) and read
      from the device the number of packets that were dropped by the policer,
      if supported.
      
      These packet trap policers can then be bound to existing packet trap
      groups, which are used to aggregate logically related packet traps. As a
      result, trapped packets are policed to rates that can be handled the
      host CPU.
      
      Example usage
      =============
      
      Instantiate netdevsim:
      
      Dump available packet trap policers:
      netdevsim/netdevsim10:
        policer 1 rate 1000 burst 128
        policer 2 rate 2000 burst 256
        policer 3 rate 3000 burst 512
      
      Change the parameters of a packet trap policer:
      
      Bind a packet trap policer to a packet trap group:
      
      Dump parameters and statistics of a packet trap policer:
      netdevsim/netdevsim10:
        policer 3 rate 100 burst 16
          stats:
              rx:
                dropped 92
      
      Unbind a packet trap policer from a packet trap group:
      
      Patch set overview
      ==================
      
      Patch #1 adds the core infrastructure in devlink which allows capable
      device drivers to register their supported packet trap policers with
      devlink.
      
      Patch #2 extends the existing devlink-trap documentation.
      
      Patch #3 extends netdevsim to register a few dummy packet trap policers
      with devlink. Used later on to selftests the core infrastructure.
      
      Patches #4-#5 adds infrastructure in devlink to allow binding of packet
      trap policers to packet trap groups.
      
      Patch #6 extends netdevsim to allow such binding.
      
      Patch #7 adds a selftest over netdevsim that verifies the core
      devlink-trap policers functionality.
      
      Patches #8-#14 gradually add devlink-trap policers support in mlxsw.
      
      Patch #15 adds a selftest over mlxsw. All registered packet trap
      policers are verified to handle the configured rate and burst size.
      
      Future plans
      ============
      
      * Allow changing default association between packet traps and packet
        trap groups
      * Add more packet traps. For example, for control packets (e.g., IGMP)
      
      v3:
      * Rebase
      
      v2 (address comments from Jiri and Jakub):
      * Patch #1: Add 'strict_start_type' in devlink policy
      * Patch #1: Have device drivers provide max/min rate/burst size for each
        policer. Use them to check validity of user provided parameters
      * Patch #3: Remove check about burst size being a power of 2 and instead
        add a debugfs knob to fail the operation
      * Patch #3: Provide max/min rate/burst size when registering policers
        and remove the validity checks from nsim_dev_devlink_trap_policer_set()
      * Patch #5: Check for presence of 'DEVLINK_ATTR_TRAP_POLICER_ID' in
        devlink_trap_group_set() and bail if not present
      * Patch #5: Add extack error message in case trap group was partially
        modified
      * Patch #7: Add test case with new 'fail_trap_policer_set' knob
      * Patch #7: Add test case for partially modified trap group
      * Patch #10: Provide max/min rate/burst size when registering policers
      * Patch #11: Remove the max/min validity checks from
        __mlxsw_sp_trap_policer_set()
      ====================
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      6fe9a949
    • Ido Schimmel's avatar
      selftests: mlxsw: Add test cases for devlink-trap policers · 9f3e63c5
      Ido Schimmel authored
      Add test cases that verify that each registered packet trap policer:
      
      * Honors that imposed limitations of rate and burst size
      * Able to police trapped packets to the specified rate
      * Able to police trapped packets to the specified burst size
      * Able to be unbound from its trap group
      Signed-off-by: default avatarIdo Schimmel <idosch@mellanox.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      9f3e63c5
    • Ido Schimmel's avatar
      mlxsw: spectrum_trap: Add support for setting of packet trap group parameters · 39defcbb
      Ido Schimmel authored
      Implement support for setting of packet trap group parameters by
      invoking the trap_group_init() callback with the new parameters.
      Signed-off-by: default avatarIdo Schimmel <idosch@mellanox.com>
      Reviewed-by: default avatarJiri Pirko <jiri@mellanox.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      39defcbb
    • Ido Schimmel's avatar
      mlxsw: spectrum_trap: Switch to use correct packet trap group · d12d8468
      Ido Schimmel authored
      Some packet traps are currently exposed to user space as being member of
      "l3_drops" trap group, but internally they are member of a different
      group.
      
      Switch these traps to use the correct group so that they are all subject
      to the same policer, as exposed to user space.
      
      Set the trap priority of packets trapped due to loopback error during
      routing to the lowest priority. Such packets are not routed again by the
      kernel and therefore should not mask other traps (e.g., host miss) that
      should be routed.
      Signed-off-by: default avatarIdo Schimmel <idosch@mellanox.com>
      Reviewed-by: default avatarJiri Pirko <jiri@mellanox.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      d12d8468
    • Ido Schimmel's avatar
      mlxsw: spectrum_trap: Do not initialize dedicated discard policer · bc82521e
      Ido Schimmel authored
      The policer is now initialized as part of the registration with devlink,
      so there is no need to initialize it before the registration.
      
      Remove the initialization.
      Signed-off-by: default avatarIdo Schimmel <idosch@mellanox.com>
      Reviewed-by: default avatarJiri Pirko <jiri@mellanox.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      bc82521e
    • Ido Schimmel's avatar
      mlxsw: spectrum_trap: Add devlink-trap policer support · 13f2e64b
      Ido Schimmel authored
      Register supported packet trap policers with devlink and implement
      callbacks to change their parameters and read their counters.
      
      Prevent user space from passing invalid policer parameters down to the
      device by checking their validity and communicating the failure via an
      appropriate extack message.
      
      v2:
      * Remove the max/min validity checks from __mlxsw_sp_trap_policer_set()
      Signed-off-by: default avatarIdo Schimmel <idosch@mellanox.com>
      Reviewed-by: default avatarJiri Pirko <jiri@mellanox.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      13f2e64b
    • Ido Schimmel's avatar
      mlxsw: spectrum_trap: Prepare policers for registration with devlink · 4561705b
      Ido Schimmel authored
      Prepare an array of policer IDs to register with devlink and their
      associated parameters.
      
      The array is composed from both policers that are currently bound to
      exposed trap groups and policers that are not bound to any trap group.
      
      v2:
      * Provide max/min rate/burst size when registering policers
      Signed-off-by: default avatarIdo Schimmel <idosch@mellanox.com>
      Reviewed-by: default avatarJiri Pirko <jiri@mellanox.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      4561705b
    • Ido Schimmel's avatar
      mlxsw: spectrum: Track used packet trap policer IDs · 03484e49
      Ido Schimmel authored
      During initialization the driver configures various packet trap groups
      and binds policers to them.
      
      Currently, most of these groups are not exposed to user space and
      therefore their policers should not be exposed as well. Otherwise, user
      space will be able to alter policer parameters without knowing which
      packet traps are policed by the policer.
      
      Use a bitmap to track the used policer IDs so that these policers will
      not be registered with devlink in a subsequent patch.
      Signed-off-by: default avatarIdo Schimmel <idosch@mellanox.com>
      Reviewed-by: default avatarJiri Pirko <jiri@mellanox.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      03484e49
    • Ido Schimmel's avatar
      mlxsw: reg: Extend QPCR register · 2b84d7c3
      Ido Schimmel authored
      The QoS Policer Configuration Register (QPCR) is used to configure
      hardware policers. Extend this register with following fields and
      defines which will be used by subsequent patches:
      
      1. Violate counter: reads number of packets dropped by the policer
      2. Clear counter: to ensure we start counting from 0
      3. Rate and burst size limits
      Signed-off-by: default avatarIdo Schimmel <idosch@mellanox.com>
      Reviewed-by: default avatarJiri Pirko <jiri@mellanox.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      2b84d7c3
    • Ido Schimmel's avatar
      selftests: netdevsim: Add test cases for devlink-trap policers · 5fbff58e
      Ido Schimmel authored
      Add test cases for packet trap policer set / show commands as well as
      for the binding of these policers to packet trap groups.
      
      Both good and bad flows are tested for maximum coverage.
      
      v2:
      * Add test case with new 'fail_trap_policer_set' knob
      * Add test case for partially modified trap group
      Signed-off-by: default avatarIdo Schimmel <idosch@mellanox.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      5fbff58e
    • Ido Schimmel's avatar
      netdevsim: Add support for setting of packet trap group parameters · 0dc8249a
      Ido Schimmel authored
      Add a dummy callback to set trap group parameters. Return an error when
      the 'fail_trap_group_set' debugfs file is set in order to exercise error
      paths and verify that error is propagated to user space when should.
      Signed-off-by: default avatarIdo Schimmel <idosch@mellanox.com>
      Reviewed-by: default avatarJiri Pirko <jiri@mellanox.com>
      Reviewed-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      0dc8249a
    • Ido Schimmel's avatar
      devlink: Allow setting of packet trap group parameters · c064875a
      Ido Schimmel authored
      The previous patch allowed device drivers to publish their default
      binding between packet trap policers and packet trap groups. However,
      some users might not be content with this binding and would like to
      change it.
      
      In case user space passed a packet trap policer identifier when setting
      a packet trap group, invoke the appropriate device driver callback and
      pass the new policer identifier.
      
      v2:
      * Check for presence of 'DEVLINK_ATTR_TRAP_POLICER_ID' in
        devlink_trap_group_set() and bail if not present
      * Add extack error message in case trap group was partially modified
      Signed-off-by: default avatarIdo Schimmel <idosch@mellanox.com>
      Reviewed-by: default avatarJiri Pirko <jiri@mellanox.com>
      Acked-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      c064875a
    • Ido Schimmel's avatar
      devlink: Add packet trap group parameters support · f9f54392
      Ido Schimmel authored
      Packet trap groups are used to aggregate logically related packet traps.
      Currently, these groups allow user space to batch operations such as
      setting the trap action of all member traps.
      
      In order to prevent the CPU from being overwhelmed by too many trapped
      packets, it is desirable to bind a packet trap policer to these groups.
      For example, to limit all the packets that encountered an exception
      during routing to 10Kpps.
      
      Allow device drivers to bind default packet trap policers to packet trap
      groups when the latter are registered with devlink.
      
      The next patch will enable user space to change this default binding.
      Signed-off-by: default avatarIdo Schimmel <idosch@mellanox.com>
      Reviewed-by: default avatarJiri Pirko <jiri@mellanox.com>
      Reviewed-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      f9f54392
    • Ido Schimmel's avatar
      netdevsim: Add devlink-trap policer support · ad188458
      Ido Schimmel authored
      Register three dummy packet trap policers with devlink and implement
      callbacks to change their parameters and read their counters.
      
      This will be used later on in the series to test the devlink-trap
      policer infrastructure.
      
      v2:
      * Remove check about burst size being a power of 2 and instead add a
        debugfs knob to fail the operation
      * Provide max/min rate/burst size when registering policers and remove
        the validity checks from nsim_dev_devlink_trap_policer_set()
      Signed-off-by: default avatarIdo Schimmel <idosch@mellanox.com>
      Reviewed-by: default avatarJiri Pirko <jiri@mellanox.com>
      Reviewed-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      ad188458
    • Ido Schimmel's avatar
      Documentation: Add description of packet trap policers · ef7d5c7d
      Ido Schimmel authored
      Extend devlink-trap documentation with information about packet trap
      policers.
      Signed-off-by: default avatarIdo Schimmel <idosch@mellanox.com>
      Reviewed-by: default avatarJiri Pirko <jiri@mellanox.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      ef7d5c7d
    • Ido Schimmel's avatar
      devlink: Add packet trap policers support · 1e8c6619
      Ido Schimmel authored
      Devices capable of offloading the kernel's datapath and perform
      functions such as bridging and routing must also be able to send (trap)
      specific packets to the kernel (i.e., the CPU) for processing.
      
      For example, a device acting as a multicast-aware bridge must be able to
      trap IGMP membership reports to the kernel for processing by the bridge
      module.
      
      In most cases, the underlying device is capable of handling packet rates
      that are several orders of magnitude higher compared to those that can
      be handled by the CPU.
      
      Therefore, in order to prevent the underlying device from overwhelming
      the CPU, devices usually include packet trap policers that are able to
      police the trapped packets to rates that can be handled by the CPU.
      
      This patch allows capable device drivers to register their supported
      packet trap policers with devlink. User space can then tune the
      parameters of these policer (currently, rate and burst size) and read
      from the device the number of packets that were dropped by the policer,
      if supported.
      
      Subsequent patches in the series will allow device drivers to create
      default binding between these policers and packet trap groups and allow
      user space to change the binding.
      
      v2:
      * Add 'strict_start_type' in devlink policy
      * Have device drivers provide max/min rate/burst size for each policer.
        Use them to check validity of user provided parameters
      Signed-off-by: default avatarIdo Schimmel <idosch@mellanox.com>
      Reviewed-by: default avatarJiri Pirko <jiri@mellanox.com>
      Reviewed-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      1e8c6619
  2. 30 Mar, 2020 24 commits