Skip to content
  1. Feb 09, 2022
  2. Feb 08, 2022
    • Jakub Kicinski's avatar
      Merge branch 'inet-separate-dscp-from-ecn-bits-using-new-dscp_t-type' · c3e676b9
      Jakub Kicinski authored
      Guillaume Nault says:
      
      ====================
      inet: Separate DSCP from ECN bits using new dscp_t type
      
      The networking stack currently doesn't clearly distinguish between DSCP
      and ECN bits. The entire DSCP+ECN bits are stored in u8 variables (or
      structure fields), and each part of the stack handles them in their own
      way, using different macros. This has created several bugs in the past
      and some uncommon code paths are still unfixed.
      
      Such bugs generally manifest by selecting invalid routes because of ECN
      bits interfering with FIB routes and rules lookups (more details in the
      LPC 2021 talk[1] and in the RFC of this series[2]).
      
      This patch series aims at preventing the introduction of such bugs (and
      detecting existing ones), by introducing a dscp_t type, representing
      "sanitised" DSCP values (that is, with no ECN information), as opposed
      to plain u8 values that contain both DSCP and ECN information. dscp_t
      makes it clear for the reader what we're working on, and Sparse can
      flag invalid interactions between dscp_t and plain u8.
      
      This series converts only a few variables and structures:
      
        * Patch 1 converts the tclass field of struct fib6_rule. It
          effectively forbids the use of ECN bits in the tos/dsfield option
          of ip -6 rule. Rules now match packets solely based on their DSCP
          bits, so ECN doesn't influence the result any more. This contrasts
          with the previous behaviour where all 8 bits of the Traffic Class
          field were used. It is believed that this change is acceptable as
          matching ECN bits wasn't usable for IPv4, so only IPv6-only
          deployments could be depending on it. Also the previous behaviour
          made DSCP-based ip6-rules fail for packets with both a DSCP and an
          ECN mark, which is another reason why any such deploy is unlikely.
      
        * Patch 2 converts the tos field of struct fib4_rule. This one too
          effectively forbids defining ECN bits, this time in ip -4 rule.
          Before that, setting ECN bit 1 was accepted, while ECN bit 0 was
          rejected. But even when accepted, the rule would never match, as
          the packets would have their ECN bits cleared before doing the
          rule lookup.
      
        * Patch 3 converts the fc_tos field of struct fib_config. This is
          equivalent to patch 2, but for IPv4 routes. Routes using a
          tos/dsfield option with any ECN bit set is now rejected. Before
          this patch, they were accepted but, as with ip4 rules, these routes
          couldn't match any packet, since their ECN bits are cleared before
          the lookup.
      
        * Patch 4 converts the fa_tos field of struct fib_alias. This one is
          pure internal u8 to dscp_t conversion. While patches 1-3 had user
          facing consequences, this patch shouldn't have any side effect and
          is there to give an overview of what future conversion patches will
          look like. Conversions are quite mechanical, but imply some code
          churn, which is the price for the extra clarity a possibility of
          type checking.
      
      To summarise, all the behaviour changes required for the dscp_t type
      approach to work should be contained in patches 1-3. These changes are
      edge cases of ip-route and ip-rule that don't currently work properly.
      So they should be safe. Also, a kernel selftest is added for each of
      them.
      
      Finally, this work also paves the way for allowing the usage of the 3
      high order DSCP bits in IPv4 (a few call paths already handle them, but
      in general the stack clears them before IPv4 rule and route lookups).
      
      References:
        [1] LPC 2021 talk:
              - https://linuxplumbersconf.org/event/11/contributions/943/
              - Direct link to slide deck:
                  https://linuxplumbersconf.org/event/11/contributions/943/attachments/901/1780/inet_tos_lpc2021.pdf
        [2] RFC version of this series:
            - https://lore.kernel.org/netdev/cover.1638814614.git.gnault@redhat.com/
      ====================
      
      Link: https://lore.kernel.org/r/cover.1643981839.git.gnault@redhat.com
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      c3e676b9
    • Guillaume Nault's avatar
      ipv4: Use dscp_t in struct fib_alias · 32ccf110
      Guillaume Nault authored
      
      
      Use the new dscp_t type to replace the fa_tos field of fib_alias. This
      ensures ECN bits are ignored and makes the field compatible with the
      fc_dscp field of struct fib_config.
      
      Converting old *tos variables and fields to dscp_t allows sparse to
      flag incorrect uses of DSCP and ECN bits. This patch is entirely about
      type annotation and shouldn't change any existing behaviour.
      
      Signed-off-by: default avatarGuillaume Nault <gnault@redhat.com>
      Acked-by: default avatarDavid Ahern <dsahern@kernel.org>
      Reviewed-by: default avatarToke Høiland-Jørgensen <toke@redhat.com>
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      32ccf110
    • Guillaume Nault's avatar
      ipv4: Reject routes specifying ECN bits in rtm_tos · f55fbb6a
      Guillaume Nault authored
      
      
      Use the new dscp_t type to replace the fc_tos field of fib_config, to
      ensure IPv4 routes aren't influenced by ECN bits when configured with
      non-zero rtm_tos.
      
      Before this patch, IPv4 routes specifying an rtm_tos with some of the
      ECN bits set were accepted. However they wouldn't work (never match) as
      IPv4 normally clears the ECN bits with IPTOS_RT_MASK before doing a FIB
      lookup (although a few buggy code paths don't).
      
      After this patch, IPv4 routes specifying an rtm_tos with any ECN bit
      set is rejected.
      
      Note: IPv6 routes ignore rtm_tos altogether, any rtm_tos is accepted,
      but treated as if it were 0.
      
      Signed-off-by: default avatarGuillaume Nault <gnault@redhat.com>
      Acked-by: default avatarDavid Ahern <dsahern@kernel.org>
      Reviewed-by: default avatarToke Høiland-Jørgensen <toke@redhat.com>
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      f55fbb6a
    • Guillaume Nault's avatar
      ipv4: Stop taking ECN bits into account in fib4-rules · 563f8e97
      Guillaume Nault authored
      
      
      Use the new dscp_t type to replace the tos field of struct fib4_rule,
      so that fib4-rules consistently ignore ECN bits.
      
      Before this patch, fib4-rules did accept rules with the high order ECN
      bit set (but not the low order one). Also, it relied on its callers
      masking the ECN bits of ->flowi4_tos to prevent those from influencing
      the result. This was brittle and a few call paths still do the lookup
      without masking the ECN bits first.
      
      After this patch fib4-rules only compare the DSCP bits. ECN can't
      influence the result anymore, even if the caller didn't mask these
      bits. Also, fib4-rules now must have both ECN bits cleared or they will
      be rejected.
      
      Signed-off-by: default avatarGuillaume Nault <gnault@redhat.com>
      Acked-by: default avatarDavid Ahern <dsahern@kernel.org>
      Reviewed-by: default avatarToke Høiland-Jørgensen <toke@redhat.com>
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      563f8e97
    • Guillaume Nault's avatar
      ipv6: Define dscp_t and stop taking ECN bits into account in fib6-rules · a410a0cf
      Guillaume Nault authored
      
      
      Define a dscp_t type and its appropriate helpers that ensure ECN bits
      are not taken into account when handling DSCP.
      
      Use this new type to replace the tclass field of struct fib6_rule, so
      that fib6-rules don't get influenced by ECN bits anymore.
      
      Before this patch, fib6-rules didn't make any distinction between the
      DSCP and ECN bits. Therefore, rules specifying a DSCP (tos or dsfield
      options in iproute2) stopped working as soon a packets had at least one
      of its ECN bits set (as a work around one could create four rules for
      each DSCP value to match, one for each possible ECN value).
      
      After this patch fib6-rules only compare the DSCP bits. ECN doesn't
      influence the result anymore. Also, fib6-rules now must have the ECN
      bits cleared or they will be rejected.
      
      Signed-off-by: default avatarGuillaume Nault <gnault@redhat.com>
      Acked-by: default avatarDavid Ahern <dsahern@kernel.org>
      Reviewed-by: default avatarToke Høiland-Jørgensen <toke@redhat.com>
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      a410a0cf
    • Yannick Vignon's avatar
      net: stmmac: optimize locking around PTP clock reads · 642436a1
      Yannick Vignon authored
      
      
      Reading the PTP clock is a simple operation requiring only 3 register
      reads. Under a PREEMPT_RT kernel, protecting those reads by a spin_lock is
      counter-productive: if the 2nd task preempting the 1st has a higher prio
      but needs to read time as well, it will require 2 context switches, which
      will pretty much always be more costly than just disabling preemption for
      the duration of the reads. Moreover, with the code logic recently added
      to get_systime(), disabling preemption is not even required anymore:
      reads and writes just need to be protected from each other, to prevent a
      clock read while the clock is being updated.
      
      Improve the above situation by replacing the PTP spinlock by a rwlock, and
      using read_lock for PTP clock reads so simultaneous reads do not block
      each other.
      
      Signed-off-by: default avatarYannick Vignon <yannick.vignon@nxp.com>
      Link: https://lore.kernel.org/r/20220204135545.2770625-1-yannick.vignon@oss.nxp.com
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      642436a1
    • Eric Dumazet's avatar
      net: typhoon: include <net/vxlan.h> · d1d5bd64
      Eric Dumazet authored
      We need this to get vxlan_features_check() definition.
      
      Fixes: d2692eee
      
       ("net: typhoon: implement ndo_features_check method")
      Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
      Link: https://lore.kernel.org/r/20220208003502.1799728-1-eric.dumazet@gmail.com
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      d1d5bd64
    • Corinna Vinschen's avatar
      igb: refactor XDP registration · e62ad74a
      Corinna Vinschen authored
      On changing the RX ring parameters igb uses a hack to avoid a warning
      when calling xdp_rxq_info_reg via igb_setup_rx_resources.  It just
      clears the struct xdp_rxq_info content.
      
      Instead, change this to unregister if we're already registered.  Align
      code to the igc code.
      
      Fixes: 9cbc948b
      
       ("igb: add XDP support")
      Signed-off-by: default avatarCorinna Vinschen <vinschen@redhat.com>
      Acked-by: default avatarVinicius Costa Gomes <vinicius.gomes@intel.com>
      Tested-by: default avatarSandeep Penigalapati <sandeep.penigalapati@intel.com>
      Signed-off-by: default avatarTony Nguyen <anthony.l.nguyen@intel.com>
      e62ad74a
    • Corinna Vinschen's avatar
      igc: avoid kernel warning when changing RX ring parameters · 453307b5
      Corinna Vinschen authored
      Calling ethtool changing the RX ring parameters like this:
      
        $ ethtool -G eth0 rx 1024
      
      on igc triggers kernel warnings like this:
      
      [  225.198467] ------------[ cut here ]------------
      [  225.198473] Missing unregister, handled but fix driver
      [  225.198485] WARNING: CPU: 7 PID: 959 at net/core/xdp.c:168
      xdp_rxq_info_reg+0x79/0xd0
      [...]
      [  225.198601] Call Trace:
      [  225.198604]  <TASK>
      [  225.198609]  igc_setup_rx_resources+0x3f/0xe0 [igc]
      [  225.198617]  igc_ethtool_set_ringparam+0x30e/0x450 [igc]
      [  225.198626]  ethnl_set_rings+0x18a/0x250
      [  225.198631]  genl_family_rcv_msg_doit+0xca/0x110
      [  225.198637]  genl_rcv_msg+0xce/0x1c0
      [  225.198640]  ? rings_prepare_data+0x60/0x60
      [  225.198644]  ? genl_get_cmd+0xd0/0xd0
      [  225.198647]  netlink_rcv_skb+0x4e/0xf0
      [  225.198652]  genl_rcv+0x24/0x40
      [  225.198655]  netlink_unicast+0x20e/0x330
      [  225.198659]  netlink_sendmsg+0x23f/0x480
      [  225.198663]  sock_sendmsg+0x5b/0x60
      [  225.198667]  __sys_sendto+0xf0/0x160
      [  225.198671]  ? handle_mm_fault+0xb2/0x280
      [  225.198676]  ? do_user_addr_fault+0x1eb/0x690
      [  225.198680]  __x64_sys_sendto+0x20/0x30
      [  225.198683]  do_syscall_64+0x38/0x90
      [  225.198687]  entry_SYSCALL_64_after_hwframe+0x44/0xae
      [  225.198693] RIP: 0033:0x7f7ae38ac3aa
      
      igc_ethtool_set_ringparam() copies the igc_ring structure but neglects to
      reset the xdp_rxq_info member before calling igc_setup_rx_resources().
      This in turn calls xdp_rxq_info_reg() with an already registered xdp_rxq_info.
      
      Make sure to unregister the xdp_rxq_info structure first in
      igc_setup_rx_resources.
      
      Fixes: 73f1071c
      
       ("igc: Add support for XDP_TX action")
      Reported-by: default avatarLennert Buytenhek <buytenh@arista.com>
      Signed-off-by: default avatarCorinna Vinschen <vinschen@redhat.com>
      Acked-by: default avatarVinicius Costa Gomes <vinicius.gomes@intel.com>
      Tested-by: default avatarDvora Fuxbrumer <dvorax.fuxbrumer@linux.intel.com>
      Signed-off-by: default avatarTony Nguyen <anthony.l.nguyen@intel.com>
      453307b5
  3. Feb 07, 2022