1. Aug 23, 2022
    • Sergei Antonov's avatar
      net: moxa: get rid of asymmetry in DMA mapping/unmapping · 0ee7828d
      Sergei Antonov authored
      Since priv->rx_mapping[i] is maped in moxart_mac_open(), we
      should unmap it from moxart_mac_stop(). Fixes 2 warnings.
      
      1. During error unwinding in moxart_mac_probe(): "goto init_fail;",
      then moxart_mac_free_memory() calls dma_unmap_single() with
      priv->rx_mapping[i] pointers zeroed.
      
      WARNING: CPU: 0 PID: 1 at kernel/dma/debug.c:963 check_unmap+0x704/0x980
      DMA-API: moxart-ethernet 92000000.mac: device driver tries to free DMA memory it has not allocated [device address=0x0000000000000000] [size=1600 bytes]
      CPU: 0 PID: 1 Comm: swapper Not tainted 5.19.0+ #60
      Hardware name: Generic DT based system
       unwind_backtrace from show_stack+0x10/0x14
       show_stack from dump_stack_lvl+0x34/0x44
       dump_stack_lvl from __warn+0xbc/0x1f0
       __warn from warn_slowpath_fmt+0x94/0xc8
       warn_slowpath_fmt from check_unmap+0x704/0x980
       check_unmap from debug_dma_unmap_page+0x8c/0x9c
       debug_dma_unmap_page from moxart_mac_free_memory+0x3c/0xa8
       moxart_mac_free_memory from moxart_mac_probe+0x190/0x218
       moxart_mac_probe from platform_probe+0x48/0x88
       platform_probe from really_probe+0xc0/0x2e4
      
      2. After commands:
       ip link set dev eth0 down
       ip link set dev eth0 up
      
      WARNING: CPU: 0 PID: 55 at kernel/dma/debug.c:570 add_dma_entry+0x204/0x2ec
      DMA-API: moxart-ethernet 92000000.mac: cacheline tracking EEXIST, overlapping mappings aren't supported
      CPU: 0 PID: 55 Comm: ip Not tainted 5.19.0+ #57
      Hardware name: Generic DT based system
       unwind_backtrace from show_stack+0x10/0x14
       show_stack from dump_stack_lvl+0x34/0x44
       dump_stack_lvl from __warn+0xbc/0x1f0
       __warn from warn_slowpath_fmt+0x94/0xc8
       warn_slowpath_fmt from add_dma_entry+0x204/0x2ec
       add_dma_entry from dma_map_page_attrs+0x110/0x328
       dma_map_page_attrs from moxart_mac_open+0x134/0x320
       moxart_mac_open from __dev_open+0x11c/0x1ec
       __dev_open from __dev_change_flags+0x194/0x22c
       __dev_change_flags from dev_change_flags+0x14/0x44
       dev_change_flags from devinet_ioctl+0x6d4/0x93c
       devinet_ioctl from inet_ioctl+0x1ac/0x25c
      
      v1 -> v2:
      Extraneous change removed.
      
      Fixes: 6c821bd9
      
       ("net: Add MOXA ART SoCs ethernet driver")
      Signed-off-by: default avatarSergei Antonov <saproj@gmail.com>
      Reviewed-by: default avatarAndrew Lunn <andrew@lunn.ch>
      Link: https://lore.kernel.org/r/20220819110519.1230877-1-saproj@gmail.com
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      0ee7828d
    • Xiaolei Wang's avatar
      net: phy: Don't WARN for PHY_READY state in mdio_bus_phy_resume() · 6dbe852c
      Xiaolei Wang authored
      For some MAC drivers, they set the mac_managed_pm to true in its
      ->ndo_open() callback. So before the mac_managed_pm is set to true,
      we still want to leverage the mdio_bus_phy_suspend()/resume() for
      the phy device suspend and resume. In this case, the phy device is
      in PHY_READY, and we shouldn't warn about this. It also seems that
      the check of mac_managed_pm in WARN_ON is redundant since we already
      check this in the entry of mdio_bus_phy_resume(), so drop it.
      
      Fixes: 744d23c7
      
       ("net: phy: Warn about incorrect mdio_bus_phy_resume() state")
      Signed-off-by: default avatarXiaolei Wang <xiaolei.wang@windriver.com>
      Acked-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
      Link: https://lore.kernel.org/r/20220819082451.1992102-1-xiaolei.wang@windriver.com
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      6dbe852c
    • Alex Elder's avatar
      net: ipa: don't assume SMEM is page-aligned · b8d43803
      Alex Elder authored
      In ipa_smem_init(), a Qualcomm SMEM region is allocated (if needed)
      and then its virtual address is fetched using qcom_smem_get().  The
      physical address associated with that region is also fetched.
      
      The physical address is adjusted so that it is page-aligned, and an
      attempt is made to update the size of the region to compensate for
      any non-zero adjustment.
      
      But that adjustment isn't done properly.  The physical address is
      aligned twice, and as a result the size is never actually adjusted.
      
      Fix this by *not* aligning the "addr" local variable, and instead
      making the "phys" local variable be the adjusted "addr" value.
      
      Fixes: a0036bb4
      
       ("net: ipa: define SMEM memory region for IPA")
      Signed-off-by: default avatarAlex Elder <elder@linaro.org>
      Link: https://lore.kernel.org/r/20220818134206.567618-1-elder@linaro.org
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      b8d43803
    • Vladimir Oltean's avatar
      net: dsa: microchip: keep compatibility with device tree blobs with no phy-mode · 5fbb08eb
      Vladimir Oltean authored
      DSA has multiple ways of specifying a MAC connection to an internal PHY.
      One requires a DT description like this:
      
      	port@0 {
      		reg = <0>;
      		phy-handle = <&internal_phy>;
      		phy-mode = "internal";
      	};
      
      (which is IMO the recommended approach, as it is the clearest
      description)
      
      but it is also possible to leave the specification as just:
      
      	port@0 {
      		reg = <0>;
      	}
      
      and if the driver implements ds->ops->phy_read and ds->ops->phy_write,
      the DSA framework "knows" it should create a ds->slave_mii_bus, and it
      should connect to a non-OF-based internal PHY on this MDIO bus, at an
      MDIO address equal to the port address.
      
      There is also an intermediary way of describing things:
      
      	port@0 {
      		reg = <0>;
      		phy-handle = <&internal_phy>;
      	};
      
      In case 2, DSA calls phylink_connect_phy() and in case 3, it calls
      phylink_of_phy_connect(). In both cases, phylink_create() has been
      called with a phy_interface_t of PHY_INTERFACE_MODE_NA, and in both
      cases, PHY_INTERFACE_MODE_NA is translated into phy->interface.
      
      It is important to note that phy_device_create() initializes
      dev->interface = PHY_INTERFACE_MODE_GMII, and so, when we use
      phylink_create(PHY_INTERFACE_MODE_NA), no one will override this, and we
      will end up with a PHY_INTERFACE_MODE_GMII interface inherited from the
      PHY.
      
      All this means that in order to maintain compatibility with device tree
      blobs where the phy-mode property is missing, we need to allow the
      "gmii" phy-mode and treat it as "internal".
      
      Fixes: 2c709e0b ("net: dsa: microchip: ksz8795: add phylink support")
      Link: https://bugzilla.kernel.org/show_bug.cgi?id=216320
      
      
      Reported-by: default avatarCraig McQueen <craig@mcqueen.id.au>
      Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
      Reviewed-by: default avatarAlvin Šipraga <alsi@bang-olufsen.dk>
      Tested-by: default avatarRasmus Villemoes <rasmus.villemoes@prevas.dk>
      Link: https://lore.kernel.org/r/20220818143250.2797111-1-vladimir.oltean@nxp.com
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      5fbb08eb
  2. Aug 22, 2022
  3. Aug 20, 2022
  4. Aug 19, 2022
  5. Aug 18, 2022
    • Lorenzo Bianconi's avatar
      net: ethernet: mtk_eth_soc: fix possible NULL pointer dereference in mtk_xdp_run · a617ccc0
      Lorenzo Bianconi authored
      Fix possible NULL pointer dereference in mtk_xdp_run() if the
      ebpf program returns XDP_TX and xdp_convert_buff_to_frame routine fails
      returning NULL.
      
      Fixes: 5886d26f
      
       ("net: ethernet: mtk_eth_soc: add xmit XDP support")
      Signed-off-by: default avatarLorenzo Bianconi <lorenzo@kernel.org>
      Link: https://lore.kernel.org/r/627a07d759020356b64473e09f0855960e02db28.1660659112.git.lorenzo@kernel.org
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      a617ccc0
    • Leon Romanovsky's avatar
      net/mlx5e: Allocate flow steering storage during uplink initialization · d515f38c
      Leon Romanovsky authored
      IPsec code relies on valid priv->fs pointer that is the case in NIC
      flow, but not correct in uplink. Before commit that mentioned in the
      Fixes line, that pointer was valid in all flows as it was allocated
      together with priv struct.
      
      In addition, the cleanup representors routine called to that
      not-initialized priv->fs pointer and its internals which caused NULL
      deference.
      
      So, move FS allocation to be as early as possible.
      
      Fixes: af8bbf73
      
       ("net/mlx5e: Convert mlx5e_flow_steering member of mlx5e_priv to pointer")
      Signed-off-by: default avatarLeon Romanovsky <leonro@nvidia.com>
      Link: https://lore.kernel.org/r/ae46fa5bed3c67f937bfdfc0370101278f5422f1.1660639564.git.leonro@nvidia.com
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      d515f38c
    • Jakub Kicinski's avatar
      Merge branch 'fixes-for-ocelot-driver-statistics' · 5b6a0729
      Jakub Kicinski authored
      Vladimir Oltean says:
      
      ====================
      Fixes for Ocelot driver statistics
      
      This series contains bug fixes for the ocelot drivers (both switchdev
      and DSA). Some concern the counters exposed to ethtool -S, and others to
      the counters exposed to ifconfig. I'm aware that the changes are fairly
      large, but I wanted to prioritize on a proper approach to addressing the
      issues rather than a quick hack.
      
      Some of the noticed problems:
      - bad register offsets for some counters
      - unhandled concurrency leading to corrupted counters
      - unhandled 32-bit wraparound of ifconfig counters
      
      The issues on the ocelot switchdev driver were noticed through code
      inspection, I do not have the hardware to test.
      
      This patch set necessarily converts ocelot->stats_lock from a mutex to a
      spinlock. I know this affects Colin Foster's development with the SPI
      controlled VSC7512. I have other changes prepared for net-next that
      convert this back into a mutex (along with other changes in this area).
      ====================
      
      Link: https://lore.kernel.org/r/20220816135352.1431497-1-vladimir.oltean@nxp.com
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      5b6a0729
    • Vladimir Oltean's avatar
      net: mscc: ocelot: report ndo_get_stats64 from the wraparound-resistant ocelot->stats · e780e319
      Vladimir Oltean authored
      Rather than reading the stats64 counters directly from the 32-bit
      hardware, it's better to rely on the output produced by the periodic
      ocelot_port_update_stats().
      
      It would be even better to call ocelot_port_update_stats() right from
      ocelot_get_stats64() to make sure we report the current values rather
      than the ones from 2 seconds ago. But we need to export
      ocelot_port_update_stats() from the switch lib towards the switchdev
      driver for that, and future work will largely undo that.
      
      There are more ocelot-based drivers waiting to be introduced, an example
      of which is the SPI-controlled VSC7512. In that driver's case, it will
      be impossible to call ocelot_port_update_stats() from ndo_get_stats64
      context, since the latter is atomic, and reading the stats over SPI is
      sleepable. So the compromise taken here, which will also hold going
      forward, is to report 64-bit counters to stats64, which are not 100% up
      to date.
      
      Fixes: a556c76a
      
       ("net: mscc: Add initial Ocelot switch support")
      Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      e780e319
    • Vladimir Oltean's avatar
      net: mscc: ocelot: keep ocelot_stat_layout by reg address, not offset · d4c36765
      Vladimir Oltean authored
      
      
      With so many counter addresses recently discovered as being wrong, it is
      desirable to at least have a central database of information, rather
      than two: one through the SYS_COUNT_* registers (used for
      ndo_get_stats64), and the other through the offset field of struct
      ocelot_stat_layout elements (used for ethtool -S).
      
      The strategy will be to keep the SYS_COUNT_* definitions as the single
      source of truth, but for that we need to expand our current definitions
      to cover all registers. Then we need to convert the ocelot region
      creation logic, and stats worker, to the read semantics imposed by going
      through SYS_COUNT_* absolute register addresses, rather than offsets
      of 32-bit words relative to SYS_COUNT_RX_OCTETS (which should have been
      SYS_CNT, by the way).
      
      Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      d4c36765
    • Vladimir Oltean's avatar
      net: mscc: ocelot: make struct ocelot_stat_layout array indexable · 91904600
      Vladimir Oltean authored
      
      
      The ocelot counters are 32-bit and require periodic reading, every 2
      seconds, by ocelot_port_update_stats(), so that wraparounds are
      detected.
      
      Currently, the counters reported by ocelot_get_stats64() come from the
      32-bit hardware counters directly, rather than from the 64-bit
      accumulated ocelot->stats, and this is a problem for their integrity.
      
      The strategy is to make ocelot_get_stats64() able to cherry-pick
      individual stats from ocelot->stats the way in which it currently reads
      them out from SYS_COUNT_* registers. But currently it can't, because
      ocelot->stats is an opaque u64 array that's used only to feed data into
      ethtool -S.
      
      To solve that problem, we need to make ocelot->stats indexable, and
      associate each element with an element of struct ocelot_stat_layout used
      by ethtool -S.
      
      This makes ocelot_stat_layout a fat (and possibly sparse) array, so we
      need to change the way in which we access it. We no longer need
      OCELOT_STAT_END as a sentinel, because we know the array's size
      (OCELOT_NUM_STATS). We just need to skip the array elements that were
      left unpopulated for the switch revision (ocelot, felix, seville).
      
      Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      91904600
    • Vladimir Oltean's avatar
      net: mscc: ocelot: fix race between ndo_get_stats64 and ocelot_check_stats_work · 18d8e67d
      Vladimir Oltean authored
      The 2 methods can run concurrently, and one will change the window of
      counters (SYS_STAT_CFG_STAT_VIEW) that the other sees. The fix is
      similar to what commit 7fbf6795 ("net: mscc: ocelot: fix mutex lock
      error during ethtool stats read") has done for ethtool -S.
      
      Fixes: a556c76a
      
       ("net: mscc: Add initial Ocelot switch support")
      Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      18d8e67d
    • Vladimir Oltean's avatar
      net: mscc: ocelot: turn stats_lock into a spinlock · 22d842e3
      Vladimir Oltean authored
      
      
      ocelot_get_stats64() currently runs unlocked and therefore may collide
      with ocelot_port_update_stats() which indirectly accesses the same
      counters. However, ocelot_get_stats64() runs in atomic context, and we
      cannot simply take the sleepable ocelot->stats_lock mutex. We need to
      convert it to an atomic spinlock first. Do that as a preparatory change.
      
      Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      22d842e3
    • Vladimir Oltean's avatar
      net: mscc: ocelot: fix address of SYS_COUNT_TX_AGING counter · 173ca866
      Vladimir Oltean authored
      This register, used as part of stats->tx_dropped in
      ocelot_get_stats64(), has a wrong address. At the address currently
      given, there is actually the c_tx_green_prio_6 counter.
      
      Fixes: a556c76a
      
       ("net: mscc: Add initial Ocelot switch support")
      Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      173ca866
    • Vladimir Oltean's avatar
      net: mscc: ocelot: fix incorrect ndo_get_stats64 packet counters · 5152de7b
      Vladimir Oltean authored
      Reading stats using the SYS_COUNT_* register definitions is only used by
      ocelot_get_stats64() from the ocelot switchdev driver, however,
      currently the bucket definitions are incorrect.
      
      Separately, on both RX and TX, we have the following problems:
      - a 256-1023 bucket which actually tracks the 256-511 packets
      - the 1024-1526 bucket actually tracks the 512-1023 packets
      - the 1527-max bucket actually tracks the 1024-1526 packets
      
      => nobody tracks the packets from the real 1527-max bucket
      
      Additionally, the RX_PAUSE, RX_CONTROL, RX_LONGS and RX_CLASSIFIED_DROPS
      all track the wrong thing. However this doesn't seem to have any
      consequence, since ocelot_get_stats64() doesn't use these.
      
      Even though this problem only manifests itself for the switchdev driver,
      we cannot split the fix for ocelot and for DSA, since it requires fixing
      the bucket definitions from enum ocelot_reg, which makes us necessarily
      adapt the structures from felix and seville as well.
      
      Fixes: 84705fc1 ("net: dsa: felix: introduce support for Seville VSC9953 switch")
      Fixes: 56051948 ("net: dsa: ocelot: add driver for Felix switch family")
      Fixes: a556c76a
      
       ("net: mscc: Add initial Ocelot switch support")
      Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      5152de7b
    • Vladimir Oltean's avatar
      net: dsa: felix: fix ethtool 256-511 and 512-1023 TX packet counters · 40d21c45
      Vladimir Oltean authored
      What the driver actually reports as 256-511 is in fact 512-1023, and the
      TX packets in the 256-511 bucket are not reported. Fix that.
      
      Fixes: 56051948
      
       ("net: dsa: ocelot: add driver for Felix switch family")
      Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      40d21c45
    • Vladimir Oltean's avatar
      net: dsa: don't warn in dsa_port_set_state_now() when driver doesn't support it · 211987f3
      Vladimir Oltean authored
      ds->ops->port_stp_state_set() is, like most DSA methods, optional, and
      if absent, the port is supposed to remain in the forwarding state (as
      standalone). Such is the case with the mv88e6060 driver, which does not
      offload the bridge layer. DSA warns that the STP state can't be changed
      to FORWARDING as part of dsa_port_enable_rt(), when in fact it should not.
      
      The error message is also not up to modern standards, so take the
      opportunity to make it more descriptive.
      
      Fixes: fd364541
      
       ("net: dsa: change scope of STP state setter")
      Reported-by: default avatarSergei Antonov <saproj@gmail.com>
      Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
      Reviewed-by: default avatarSergei Antonov <saproj@gmail.com>
      Link: https://lore.kernel.org/r/20220816201445.1809483-1-vladimir.oltean@nxp.com
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      211987f3
    • Rustam Subkhankulov's avatar
      net: dsa: sja1105: fix buffer overflow in sja1105_setup_devlink_regions() · fd8e899c
      Rustam Subkhankulov authored
      
      
      If an error occurs in dsa_devlink_region_create(), then 'priv->regions'
      array will be accessed by negative index '-1'.
      
      Found by Linux Verification Center (linuxtesting.org) with SVACE.
      
      Signed-off-by: default avatarRustam Subkhankulov <subkhankulov@ispras.ru>
      Fixes: bf425b82 ("net: dsa: sja1105: expose static config as devlink region")
      Link: https://lore.kernel.org/r/20220817003845.389644-1-subkhankulov@ispras.ru
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      fd8e899c
    • Jakub Kicinski's avatar
      Merge git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf · bec13ba9
      Jakub Kicinski authored
      Florian Westphal says:
      
      ====================
      netfilter: conntrack and nf_tables bug fixes
      
      The following patchset contains netfilter fixes for net.
      
      Broken since 5.19:
        A few ancient connection tracking helpers assume TCP packets cannot
        exceed 64kb in size, but this isn't the case anymore with 5.19 when
        BIG TCP got merged, from myself.
      
      Regressions since 5.19:
        1. 'conntrack -E expect' won't display anything because nfnetlink failed
           to enable events for expectations, only for normal conntrack events.
      
        2. partially revert change that added resched calls to a function that can
           be in atomic context.  Both broken and fixed up by myself.
      
      Broken for several releases (up to original merge of nf_tables):
        Several fixes for nf_tables control plane, from Pablo.
        This fixes up resource leaks in error paths and adds more sanity
        checks for mutually exclusive attributes/flags.
      
      Kconfig:
        NF_CONNTRACK_PROCFS is very old and doesn't provide all info provided
        via ctnetlink, so it should not default to y. From Geert Uytterhoeven.
      
      Selftests:
        rework nft_flowtable.sh: it frequently indicated failure; the way it
        tried to detect an offload failure did not work reliably.
      
      * git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf:
        testing: selftests: nft_flowtable.sh: rework test to detect offload failure
        testing: selftests: nft_flowtable.sh: use random netns names
        netfilter: conntrack: NF_CONNTRACK_PROCFS should no longer default to y
        netfilter: nf_tables: check NFT_SET_CONCAT flag if field_count is specified
        netfilter: nf_tables: disallow NFT_SET_ELEM_CATCHALL and NFT_SET_ELEM_INTERVAL_END
        netfilter: nf_tables: NFTA_SET_ELEM_KEY_END requires concat and interval flags
        netfilter: nf_tables: validate NFTA_SET_ELEM_OBJREF based on NFT_SET_OBJECT flag
        netfilter: nf_tables: really skip inactive sets when allocating name
        netfilter: nfnetlink: re-enable conntrack expectation events
        netfilter: nf_tables: fix scheduling-while-atomic splat
        netfilter: nf_ct_irc: cap packet search space to 4k
        netfilter: nf_ct_ftp: prefer skb_linearize
        netfilter: nf_ct_h323: cap packet size at 64k
        netfilter: nf_ct_sane: remove pseudo skb linearization
        netfilter: nf_tables: possible module reference underflow in error path
        netfilter: nf_tables: disallow NFTA_SET_ELEM_KEY_END with NFT_SET_ELEM_INTERVAL_END flag
        netfilter: nf_tables: use READ_ONCE and WRITE_ONCE for shared generation id access
      ====================
      
      Link: https://lore.kernel.org/r/20220817140015.25843-1-fw@strlen.de
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      bec13ba9