Skip to content
  1. Sep 19, 2023
    • Kuniyuki Iwashima's avatar
      tcp: Factorise sk_family-independent comparison in inet_bind2_bucket_match(_addr_any). · 489ced24
      Kuniyuki Iwashima authored
      [ Upstream commit c6d27706
      
       ]
      
      This is a prep patch to make the following patches cleaner that touch
      inet_bind2_bucket_match() and inet_bind2_bucket_match_addr_any().
      
      Both functions have duplicated comparison for netns, port, and l3mdev.
      Let's factorise them.
      
      Signed-off-by: default avatarKuniyuki Iwashima <kuniyu@amazon.com>
      Reviewed-by: default avatarEric Dumazet <edumazet@google.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Stable-dep-of: aa99e5f8
      
       ("tcp: Fix bind() regression for v4-mapped-v6 wildcard address.")
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      489ced24
    • Kuniyuki Iwashima's avatar
      ipv6: Remove in6addr_any alternatives. · 82f9af46
      Kuniyuki Iwashima authored
      [ Upstream commit 8cdc3223
      
       ]
      
      Some code defines the IPv6 wildcard address as a local variable and
      use it with memcmp() or ipv6_addr_equal().
      
      Let's use in6addr_any and ipv6_addr_any() instead.
      
      Signed-off-by: default avatarKuniyuki Iwashima <kuniyu@amazon.com>
      Reviewed-by: default avatarMark Bloch <mbloch@nvidia.com>
      Reviewed-by: default avatarDavid Ahern <dsahern@kernel.org>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Stable-dep-of: aa99e5f8
      
       ("tcp: Fix bind() regression for v4-mapped-v6 wildcard address.")
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      82f9af46
    • Eric Dumazet's avatar
      ipv6: fix ip6_sock_set_addr_preferences() typo · 8b6556c4
      Eric Dumazet authored
      [ Upstream commit 8cdd9f1a ]
      
      ip6_sock_set_addr_preferences() second argument should be an integer.
      
      SUNRPC attempts to set IPV6_PREFER_SRC_PUBLIC were
      translated to IPV6_PREFER_SRC_TMP
      
      Fixes: 18d5ad62
      
       ("ipv6: add ip6_sock_set_addr_preferences")
      Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: Chuck Lever <chuck.lever@oracle.com>
      Reviewed-by: default avatarSimon Horman <horms@kernel.org>
      Link: https://lore.kernel.org/r/20230911154213.713941-1-edumazet@google.com
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      8b6556c4
    • Sascha Hauer's avatar
      net: macb: fix sleep inside spinlock · d5d315cf
      Sascha Hauer authored
      [ Upstream commit 403f0e77 ]
      
      macb_set_tx_clk() is called under a spinlock but itself calls clk_set_rate()
      which can sleep. This results in:
      
      | BUG: sleeping function called from invalid context at kernel/locking/mutex.c:580
      | pps pps1: new PPS source ptp1
      | in_atomic(): 1, irqs_disabled(): 1, non_block: 0, pid: 40, name: kworker/u4:3
      | preempt_count: 1, expected: 0
      | RCU nest depth: 0, expected: 0
      | 4 locks held by kworker/u4:3/40:
      |  #0: ffff000003409148
      | macb ff0c0000.ethernet: gem-ptp-timer ptp clock registered.
      |  ((wq_completion)events_power_efficient){+.+.}-{0:0}, at: process_one_work+0x14c/0x51c
      |  #1: ffff8000833cbdd8 ((work_completion)(&pl->resolve)){+.+.}-{0:0}, at: process_one_work+0x14c/0x51c
      |  #2: ffff000004f01578 (&pl->state_mutex){+.+.}-{4:4}, at: phylink_resolve+0x44/0x4e8
      |  #3: ffff000004f06f50 (&bp->lock){....}-{3:3}, at: macb_mac_link_up+0x40/0x2ac
      | irq event stamp: 113998
      | hardirqs last  enabled at (113997): [<ffff800080e8503c>] _raw_spin_unlock_irq+0x30/0x64
      | hardirqs last disabled at (113998): [<ffff800080e84478>] _raw_spin_lock_irqsave+0xac/0xc8
      | softirqs last  enabled at (113608): [<ffff800080010630>] __do_softirq+0x430/0x4e4
      | softirqs last disabled at (113597): [<ffff80008001614c>] ____do_softirq+0x10/0x1c
      | CPU: 0 PID: 40 Comm: kworker/u4:3 Not tainted 6.5.0-11717-g9355ce8b2f50-dirty #368
      | Hardware name: ... ZynqMP ... (DT)
      | Workqueue: events_power_efficient phylink_resolve
      | Call trace:
      |  dump_backtrace+0x98/0xf0
      |  show_stack+0x18/0x24
      |  dump_stack_lvl+0x60/0xac
      |  dump_stack+0x18/0x24
      |  __might_resched+0x144/0x24c
      |  __might_sleep+0x48/0x98
      |  __mutex_lock+0x58/0x7b0
      |  mutex_lock_nested+0x24/0x30
      |  clk_prepare_lock+0x4c/0xa8
      |  clk_set_rate+0x24/0x8c
      |  macb_mac_link_up+0x25c/0x2ac
      |  phylink_resolve+0x178/0x4e8
      |  process_one_work+0x1ec/0x51c
      |  worker_thread+0x1ec/0x3e4
      |  kthread+0x120/0x124
      |  ret_from_fork+0x10/0x20
      
      The obvious fix is to move the call to macb_set_tx_clk() out of the
      protected area. This seems safe as rx and tx are both disabled anyway at
      this point.
      It is however not entirely clear what the spinlock shall protect. It
      could be the read-modify-write access to the NCFGR register, but this
      is accessed in macb_set_rx_mode() and macb_set_rxcsum_feature() as well
      without holding the spinlock. It could also be the register accesses
      done in mog_init_rings() or macb_init_buffers(), but again these
      functions are called without holding the spinlock in macb_hresp_error_task().
      The locking seems fishy in this driver and it might deserve another look
      before this patch is applied.
      
      Fixes: 633e98a7
      
       ("net: macb: use resolved link config in mac_link_up()")
      Signed-off-by: default avatarSascha Hauer <s.hauer@pengutronix.de>
      Link: https://lore.kernel.org/r/20230908112913.1701766-1-s.hauer@pengutronix.de
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      d5d315cf
    • Harini Katakam's avatar
      net: macb: Enable PTP unicast · 7aa720c3
      Harini Katakam authored
      [ Upstream commit ee4e92c2
      
       ]
      
      Enable transmission and reception of PTP unicast packets by
      updating PTP unicast config bit and setting current HW mac
      address as allowed address in PTP unicast filter registers.
      
      Signed-off-by: default avatarHarini Katakam <harini.katakam@xilinx.com>
      Signed-off-by: default avatarMichal Simek <michal.simek@xilinx.com>
      Signed-off-by: default avatarRadhey Shyam Pandey <radhey.shyam.pandey@xilinx.com>
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Stable-dep-of: 403f0e77
      
       ("net: macb: fix sleep inside spinlock")
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      7aa720c3
    • Liu Jian's avatar
      net/tls: do not free tls_rec on async operation in bpf_exec_tx_verdict() · 7f4116c6
      Liu Jian authored
      [ Upstream commit cfaa80c9 ]
      
      I got the below warning when do fuzzing test:
      BUG: KASAN: null-ptr-deref in scatterwalk_copychunks+0x320/0x470
      Read of size 4 at addr 0000000000000008 by task kworker/u8:1/9
      
      CPU: 0 PID: 9 Comm: kworker/u8:1 Tainted: G           OE
      Hardware name: linux,dummy-virt (DT)
      Workqueue: pencrypt_parallel padata_parallel_worker
      Call trace:
       dump_backtrace+0x0/0x420
       show_stack+0x34/0x44
       dump_stack+0x1d0/0x248
       __kasan_report+0x138/0x140
       kasan_report+0x44/0x6c
       __asan_load4+0x94/0xd0
       scatterwalk_copychunks+0x320/0x470
       skcipher_next_slow+0x14c/0x290
       skcipher_walk_next+0x2fc/0x480
       skcipher_walk_first+0x9c/0x110
       skcipher_walk_aead_common+0x380/0x440
       skcipher_walk_aead_encrypt+0x54/0x70
       ccm_encrypt+0x13c/0x4d0
       crypto_aead_encrypt+0x7c/0xfc
       pcrypt_aead_enc+0x28/0x84
       padata_parallel_worker+0xd0/0x2dc
       process_one_work+0x49c/0xbdc
       worker_thread+0x124/0x880
       kthread+0x210/0x260
       ret_from_fork+0x10/0x18
      
      This is because the value of rec_seq of tls_crypto_info configured by the
      user program is too large, for example, 0xffffffffffffff. In addition, TLS
      is asynchronously accelerated. When tls_do_encryption() returns
      -EINPROGRESS and sk->sk_err is set to EBADMSG due to rec_seq overflow,
      skmsg is released before the asynchronous encryption process ends. As a
      result, the UAF problem occurs during the asynchronous processing of the
      encryption module.
      
      If the operation is asynchronous and the encryption module returns
      EINPROGRESS, do not free the record information.
      
      Fixes: 635d9398
      
       ("net/tls: free record only on encryption error")
      Signed-off-by: default avatarLiu Jian <liujian56@huawei.com>
      Reviewed-by: default avatarSabrina Dubroca <sd@queasysnail.net>
      Link: https://lore.kernel.org/r/20230909081434.2324940-1-liujian56@huawei.com
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      7f4116c6
    • Geert Uytterhoeven's avatar
      platform/mellanox: NVSW_SN2201 should depend on ACPI · f72497c5
      Geert Uytterhoeven authored
      [ Upstream commit 0a138f16 ]
      
      The only probing method supported by the Nvidia SN2201 platform driver
      is probing through an ACPI match table.  Hence add a dependency on
      ACPI, to prevent asking the user about this driver when configuring a
      kernel without ACPI support.
      
      Fixes: 662f2482
      
       ("platform/mellanox: Add support for new SN2201 system")
      Signed-off-by: default avatarGeert Uytterhoeven <geert+renesas@glider.be>
      Acked-by: default avatarVadim Pasternak <vadimp@nvidia.com>
      Acked-by: default avatarAndi Shyti <andi.shyti@kernel.org>
      Link: https://lore.kernel.org/r/ec5a4071691ab08d58771b7732a9988e89779268.1693828363.git.geert+renesas@glider.be
      Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      f72497c5
    • Shravan Kumar Ramani's avatar
      platform/mellanox: mlxbf-pmc: Fix reading of unprogrammed events · 9d392695
      Shravan Kumar Ramani authored
      [ Upstream commit 0f596945 ]
      
      This fix involves 2 changes:
       - All event regs have a reset value of 0, which is not a valid
         event_number as per the event_list for most blocks and hence seen
         as an error. Add a "disable" event with event_number 0 for all blocks.
      
       - The enable bit for each counter need not be checked before
         reading the event info, and hence removed.
      
      Fixes: 1a218d31
      
       ("platform/mellanox: mlxbf-pmc: Add Mellanox BlueField PMC driver")
      Signed-off-by: default avatarShravan Kumar Ramani <shravankr@nvidia.com>
      Reviewed-by: default avatarVadim Pasternak <vadimp@nvidia.com>
      Reviewed-by: default avatarDavid Thompson <davthompson@nvidia.com>
      Link: https://lore.kernel.org/r/04d0213932d32681de1c716b54320ed894e52425.1693917738.git.shravankr@nvidia.com
      Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      9d392695
    • Shravan Kumar Ramani's avatar
      platform/mellanox: mlxbf-pmc: Fix potential buffer overflows · 3f16330a
      Shravan Kumar Ramani authored
      [ Upstream commit 80ccd405 ]
      
      Replace sprintf with sysfs_emit where possible.
      Size check in mlxbf_pmc_event_list_show should account for "\0".
      
      Fixes: 1a218d31
      
       ("platform/mellanox: mlxbf-pmc: Add Mellanox BlueField PMC driver")
      Signed-off-by: default avatarShravan Kumar Ramani <shravankr@nvidia.com>
      Reviewed-by: default avatarVadim Pasternak <vadimp@nvidia.com>
      Reviewed-by: default avatarDavid Thompson <davthompson@nvidia.com>
      Link: https://lore.kernel.org/r/bef39ef32319a31b32f999065911f61b0d3b17c3.1693917738.git.shravankr@nvidia.com
      Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      3f16330a
    • Liming Sun's avatar
      platform/mellanox: mlxbf-tmfifo: Drop jumbo frames · 3a45dcfb
      Liming Sun authored
      [ Upstream commit fc4c6558 ]
      
      This commit drops over-sized network packets to avoid tmfifo
      queue stuck.
      
      Fixes: 1357dfd7
      
       ("platform/mellanox: Add TmFifo driver for Mellanox BlueField Soc")
      Signed-off-by: default avatarLiming Sun <limings@nvidia.com>
      Reviewed-by: default avatarVadim Pasternak <vadimp@nvidia.com>
      Reviewed-by: default avatarDavid Thompson <davthompson@nvidia.com>
      Link: https://lore.kernel.org/r/9318936c2447f76db475c985ca6d91f057efcd41.1693322547.git.limings@nvidia.com
      Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      3a45dcfb
    • Liming Sun's avatar
      platform/mellanox: mlxbf-tmfifo: Drop the Rx packet if no more descriptors · 30c8bbe1
      Liming Sun authored
      [ Upstream commit 78034cbe ]
      
      This commit fixes tmfifo console stuck issue when the virtual
      networking interface is in down state. In such case, the network
      Rx descriptors runs out and causes the Rx network packet staying
      in the head of the tmfifo thus blocking the console packets. The
      fix is to drop the Rx network packet when no more Rx descriptors.
      Function name mlxbf_tmfifo_release_pending_pkt() is also renamed
      to mlxbf_tmfifo_release_pkt() to be more approperiate.
      
      Fixes: 1357dfd7
      
       ("platform/mellanox: Add TmFifo driver for Mellanox BlueField Soc")
      Signed-off-by: default avatarLiming Sun <limings@nvidia.com>
      Reviewed-by: default avatarVadim Pasternak <vadimp@nvidia.com>
      Reviewed-by: default avatarDavid Thompson <davthompson@nvidia.com>
      Link: https://lore.kernel.org/r/8c0177dc938ae03f52ff7e0b62dbeee74b7bec09.1693322547.git.limings@nvidia.com
      Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      30c8bbe1
    • Shigeru Yoshida's avatar
      kcm: Fix memory leak in error path of kcm_sendmsg() · 16989de7
      Shigeru Yoshida authored
      [ Upstream commit c821a88b ]
      
      syzbot reported a memory leak like below:
      
      BUG: memory leak
      unreferenced object 0xffff88810b088c00 (size 240):
        comm "syz-executor186", pid 5012, jiffies 4294943306 (age 13.680s)
        hex dump (first 32 bytes):
          00 89 08 0b 81 88 ff ff 00 00 00 00 00 00 00 00  ................
          00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
        backtrace:
          [<ffffffff83e5d5ff>] __alloc_skb+0x1ef/0x230 net/core/skbuff.c:634
          [<ffffffff84606e59>] alloc_skb include/linux/skbuff.h:1289 [inline]
          [<ffffffff84606e59>] kcm_sendmsg+0x269/0x1050 net/kcm/kcmsock.c:815
          [<ffffffff83e479c6>] sock_sendmsg_nosec net/socket.c:725 [inline]
          [<ffffffff83e479c6>] sock_sendmsg+0x56/0xb0 net/socket.c:748
          [<ffffffff83e47f55>] ____sys_sendmsg+0x365/0x470 net/socket.c:2494
          [<ffffffff83e4c389>] ___sys_sendmsg+0xc9/0x130 net/socket.c:2548
          [<ffffffff83e4c536>] __sys_sendmsg+0xa6/0x120 net/socket.c:2577
          [<ffffffff84ad7bb8>] do_syscall_x64 arch/x86/entry/common.c:50 [inline]
          [<ffffffff84ad7bb8>] do_syscall_64+0x38/0xb0 arch/x86/entry/common.c:80
          [<ffffffff84c0008b>] entry_SYSCALL_64_after_hwframe+0x63/0xcd
      
      In kcm_sendmsg(), kcm_tx_msg(head)->last_skb is used as a cursor to append
      newly allocated skbs to 'head'. If some bytes are copied, an error occurred,
      and jumped to out_error label, 'last_skb' is left unmodified. A later
      kcm_sendmsg() will use an obsoleted 'last_skb' reference, corrupting the
      'head' frag_list and causing the leak.
      
      This patch fixes this issue by properly updating the last allocated skb in
      'last_skb'.
      
      Fixes: ab7ac4eb
      
       ("kcm: Kernel Connection Multiplexor module")
      Reported-and-tested-by: default avatar <syzbot+6f98de741f7dbbfc4ccb@syzkaller.appspotmail.com>
      Closes: https://syzkaller.appspot.com/bug?extid=6f98de741f7dbbfc4ccb
      Signed-off-by: default avatarShigeru Yoshida <syoshida@redhat.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      16989de7
    • Hayes Wang's avatar
      r8152: check budget for r8152_poll() · 2323397e
      Hayes Wang authored
      [ Upstream commit a7b8d60b ]
      
      According to the document of napi, there is no rx process when the
      budget is 0. Therefore, r8152_poll() has to return 0 directly when the
      budget is equal to 0.
      
      Fixes: d2187f8e
      
       ("r8152: divide the tx and rx bottom functions")
      Signed-off-by: default avatarHayes Wang <hayeswang@realtek.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      2323397e
    • Vladimir Oltean's avatar
      net: dsa: sja1105: block FDB accesses that are concurrent with a switch reset · 44c8ffd4
      Vladimir Oltean authored
      [ Upstream commit 86899e9e ]
      
      Currently, when we add the first sja1105 port to a bridge with
      vlan_filtering 1, then we sometimes see this output:
      
      sja1105 spi2.2: port 4 failed to read back entry for be:79:b4:9e:9e:96 vid 3088: -ENOENT
      sja1105 spi2.2: Reset switch and programmed static config. Reason: VLAN filtering
      sja1105 spi2.2: port 0 failed to add be:79:b4:9e:9e:96 vid 0 to fdb: -2
      
      It is because sja1105_fdb_add() runs from the dsa_owq which is no longer
      serialized with switch resets since it dropped the rtnl_lock() in the
      blamed commit.
      
      Either performing the FDB accesses before the reset, or after the reset,
      is equally fine, because sja1105_static_fdb_change() backs up those
      changes in the static config, but FDB access during reset isn't ok.
      
      Make sja1105_static_config_reload() take the fdb_lock to fix that.
      
      Fixes: 0faf890f
      
       ("net: dsa: drop rtnl_lock from dsa_slave_switchdev_event_work")
      Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      44c8ffd4
    • Vladimir Oltean's avatar
      net: dsa: sja1105: serialize sja1105_port_mcast_flood() with other FDB accesses · e74bd1b2
      Vladimir Oltean authored
      [ Upstream commit ea32690d ]
      
      sja1105_fdb_add() runs from the dsa_owq, and sja1105_port_mcast_flood()
      runs from switchdev_deferred_process_work(). Prior to the blamed commit,
      they used to be indirectly serialized through the rtnl_lock(), which
      no longer holds true because dsa_owq dropped that.
      
      So, it is now possible that we traverse the static config BLK_IDX_L2_LOOKUP
      elements concurrently compared to when we change them, in
      sja1105_static_fdb_change(). That is not ideal, since it might result in
      data corruption.
      
      Introduce a mutex which serializes accesses to the hardware FDB and to
      the static config elements for the L2 Address Lookup table.
      
      I can't find a good reason to add locking around sja1105_fdb_dump().
      I'll add it later if needed.
      
      Fixes: 0faf890f
      
       ("net: dsa: drop rtnl_lock from dsa_slave_switchdev_event_work")
      Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      e74bd1b2
    • Vladimir Oltean's avatar
      net: dsa: sja1105: fix multicast forwarding working only for last added mdb entry · d766cf9d
      Vladimir Oltean authored
      [ Upstream commit 7cef293b ]
      
      The commit cited in Fixes: did 2 things: it refactored the read-back
      polling from sja1105_dynamic_config_read() into a new function,
      sja1105_dynamic_config_wait_complete(), and it called that from
      sja1105_dynamic_config_write() too.
      
      What is problematic is the refactoring.
      
      The refactored code from sja1105_dynamic_config_poll_valid() works like
      the previous one, but the problem is that it uses another packed_buf[]
      SPI buffer, and there was code at the end of sja1105_dynamic_config_read()
      which was relying on the read-back packed_buf[]:
      
      	/* Don't dereference possibly NULL pointer - maybe caller
      	 * only wanted to see whether the entry existed or not.
      	 */
      	if (entry)
      		ops->entry_packing(packed_buf, entry, UNPACK);
      
      After the change, the packed_buf[] that this code sees is no longer the
      entry read back from hardware, but the original entry that the caller
      passed to the sja1105_dynamic_config_read(), packed into this buffer.
      
      This difference is the most notable with the SJA1105_SEARCH uses from
      sja1105pqrs_fdb_add() - used for both fdb and mdb. There, we have logic
      added by commit 728db843 ("net: dsa: sja1105: ignore the FDB entry
      for unknown multicast when adding a new address") to figure out whether
      the address we're trying to add matches on any existing hardware entry,
      with the exception of the catch-all multicast address.
      
      That logic was broken, because with sja1105_dynamic_config_read() not
      working properly, it doesn't return us the entry read back from
      hardware, but the entry that we passed to it. And, since for multicast,
      a match will always exist, it will tell us that any mdb entry already
      exists at index=0 L2 Address Lookup table. It is index=0 because the
      caller doesn't know the index - it wants to find it out, and
      sja1105_dynamic_config_read() does:
      
      	if (index < 0) { // SJA1105_SEARCH
      		/* Avoid copying a signed negative number to an u64 */
      		cmd.index = 0; // <- this
      		cmd.search = true;
      	} else {
      		cmd.index = index;
      		cmd.search = false;
      	}
      
      So, to the caller of sja1105_dynamic_config_read(), the returned info
      looks entirely legit, and it will add all mdb entries to FDB index 0.
      There, they will always overwrite each other (not to mention,
      potentially they can also overwrite a pre-existing bridge fdb entry),
      and the user-visible impact will be that only the last mdb entry will be
      forwarded as it should. The others won't (will be flooded or dropped,
      depending on the egress flood settings).
      
      Fixing is a bit more complicated, and involves either passing the same
      packed_buf[] to sja1105_dynamic_config_wait_complete(), or moving all
      the extra processing on the packed_buf[] to
      sja1105_dynamic_config_wait_complete(). I've opted for the latter,
      because it makes sja1105_dynamic_config_wait_complete() a bit more
      self-contained.
      
      Fixes: df405910
      
       ("net: dsa: sja1105: wait for dynamic config command completion on writes too")
      Reported-by: default avatarYanan Yang <yanan.yang@nxp.com>
      Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      d766cf9d
    • Vladimir Oltean's avatar
      net: dsa: sja1105: propagate exact error code from sja1105_dynamic_config_poll_valid() · 538e7fe6
      Vladimir Oltean authored
      [ Upstream commit c9567980
      
       ]
      
      Currently, sja1105_dynamic_config_wait_complete() returns either 0 or
      -ETIMEDOUT, because it just looks at the read_poll_timeout() return code.
      
      There will be future changes which move some more checks to
      sja1105_dynamic_config_poll_valid(). It is important that we propagate
      their exact return code (-ENOENT, -EINVAL), because callers of
      sja1105_dynamic_config_read() depend on them.
      
      Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Stable-dep-of: 7cef293b
      
       ("net: dsa: sja1105: fix multicast forwarding working only for last added mdb entry")
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      538e7fe6
    • Vladimir Oltean's avatar
      net: dsa: sja1105: hide all multicast addresses from "bridge fdb show" · 9a3e7eca
      Vladimir Oltean authored
      [ Upstream commit 02c652f5 ]
      
      Commit 4d942354 ("net: dsa: sja1105: offload bridge port flags to
      device") has partially hidden some multicast entries from showing up in
      the "bridge fdb show" output, but it wasn't enough. Addresses which are
      added through "bridge mdb add" still show up. Hide them all.
      
      Fixes: 291d1e72
      
       ("net: dsa: sja1105: Add support for FDB and MDB management")
      Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      9a3e7eca
    • Ciprian Regus's avatar
      net:ethernet:adi:adin1110: Fix forwarding offload · 66e79c2f
      Ciprian Regus authored
      [ Upstream commit 32530dba ]
      
      Currently, when a new fdb entry is added (with both ports of the
      ADIN2111 bridged), the driver configures the MAC filters for the wrong
      port, which results in the forwarding being done by the host, and not
      actually hardware offloaded.
      
      The ADIN2111 offloads the forwarding by setting filters on the
      destination MAC address of incoming frames. Based on these, they may be
      routed to the other port. Thus, if a frame has to be forwarded from port
      1 to port 2, the required configuration for the ADDR_FILT_UPRn register
      should set the APPLY2PORT1 bit (instead of APPLY2PORT2, as it's
      currently the case).
      
      Fixes: bc93e19d
      
       ("net: ethernet: adi: Add ADIN1110 support")
      Signed-off-by: default avatarCiprian Regus <ciprian.regus@analog.com>
      Reviewed-by: default avatarSimon Horman <horms@kernel.org>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      66e79c2f
    • Yang Yingliang's avatar
      net: ethernet: adi: adin1110: use eth_broadcast_addr() to assign broadcast address · c281948c
      Yang Yingliang authored
      [ Upstream commit 54024dbe
      
       ]
      
      Use eth_broadcast_addr() to assign broadcast address instead
      of memset().
      
      Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
      Reviewed-by: default avatarSimon Horman <horms@kernel.org>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Stable-dep-of: 32530dba
      
       ("net:ethernet:adi:adin1110: Fix forwarding offload")
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      c281948c
    • Ziyang Xuan's avatar
      hsr: Fix uninit-value access in fill_frame_info() · 61866f7d
      Ziyang Xuan authored
      [ Upstream commit 484b4833 ]
      
      Syzbot reports the following uninit-value access problem.
      
      =====================================================
      BUG: KMSAN: uninit-value in fill_frame_info net/hsr/hsr_forward.c:601 [inline]
      BUG: KMSAN: uninit-value in hsr_forward_skb+0x9bd/0x30f0 net/hsr/hsr_forward.c:616
       fill_frame_info net/hsr/hsr_forward.c:601 [inline]
       hsr_forward_skb+0x9bd/0x30f0 net/hsr/hsr_forward.c:616
       hsr_dev_xmit+0x192/0x330 net/hsr/hsr_device.c:223
       __netdev_start_xmit include/linux/netdevice.h:4889 [inline]
       netdev_start_xmit include/linux/netdevice.h:4903 [inline]
       xmit_one net/core/dev.c:3544 [inline]
       dev_hard_start_xmit+0x247/0xa10 net/core/dev.c:3560
       __dev_queue_xmit+0x34d0/0x52a0 net/core/dev.c:4340
       dev_queue_xmit include/linux/netdevice.h:3082 [inline]
       packet_xmit+0x9c/0x6b0 net/packet/af_packet.c:276
       packet_snd net/packet/af_packet.c:3087 [inline]
       packet_sendmsg+0x8b1d/0x9f30 net/packet/af_packet.c:3119
       sock_sendmsg_nosec net/socket.c:730 [inline]
       sock_sendmsg net/socket.c:753 [inline]
       __sys_sendto+0x781/0xa30 net/socket.c:2176
       __do_sys_sendto net/socket.c:2188 [inline]
       __se_sys_sendto net/socket.c:2184 [inline]
       __ia32_sys_sendto+0x11f/0x1c0 net/socket.c:2184
       do_syscall_32_irqs_on arch/x86/entry/common.c:112 [inline]
       __do_fast_syscall_32+0xa2/0x100 arch/x86/entry/common.c:178
       do_fast_syscall_32+0x37/0x80 arch/x86/entry/common.c:203
       do_SYSENTER_32+0x1f/0x30 arch/x86/entry/common.c:246
       entry_SYSENTER_compat_after_hwframe+0x70/0x82
      
      Uninit was created at:
       slab_post_alloc_hook+0x12f/0xb70 mm/slab.h:767
       slab_alloc_node mm/slub.c:3478 [inline]
       kmem_cache_alloc_node+0x577/0xa80 mm/slub.c:3523
       kmalloc_reserve+0x148/0x470 net/core/skbuff.c:559
       __alloc_skb+0x318/0x740 net/core/skbuff.c:644
       alloc_skb include/linux/skbuff.h:1286 [inline]
       alloc_skb_with_frags+0xc8/0xbd0 net/core/skbuff.c:6299
       sock_alloc_send_pskb+0xa80/0xbf0 net/core/sock.c:2794
       packet_alloc_skb net/packet/af_packet.c:2936 [inline]
       packet_snd net/packet/af_packet.c:3030 [inline]
       packet_sendmsg+0x70e8/0x9f30 net/packet/af_packet.c:3119
       sock_sendmsg_nosec net/socket.c:730 [inline]
       sock_sendmsg net/socket.c:753 [inline]
       __sys_sendto+0x781/0xa30 net/socket.c:2176
       __do_sys_sendto net/socket.c:2188 [inline]
       __se_sys_sendto net/socket.c:2184 [inline]
       __ia32_sys_sendto+0x11f/0x1c0 net/socket.c:2184
       do_syscall_32_irqs_on arch/x86/entry/common.c:112 [inline]
       __do_fast_syscall_32+0xa2/0x100 arch/x86/entry/common.c:178
       do_fast_syscall_32+0x37/0x80 arch/x86/entry/common.c:203
       do_SYSENTER_32+0x1f/0x30 arch/x86/entry/common.c:246
       entry_SYSENTER_compat_after_hwframe+0x70/0x82
      
      It is because VLAN not yet supported in hsr driver. Return error
      when protocol is ETH_P_8021Q in fill_frame_info() now to fix it.
      
      Fixes: 451d8123
      
       ("net: prp: add packet handling support")
      Reported-by: default avatar <syzbot+bf7e6250c7ce248f3ec9@syzkaller.appspotmail.com>
      Closes: https://syzkaller.appspot.com/bug?extid=bf7e6250c7ce248f3ec9
      Signed-off-by: default avatarZiyang Xuan <william.xuanziyang@huawei.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      61866f7d
    • Hangyu Hua's avatar
      net: ethernet: mtk_eth_soc: fix possible NULL pointer dereference in mtk_hwlro_get_fdir_all() · ff5faed5
      Hangyu Hua authored
      [ Upstream commit e4c79810 ]
      
      rule_locs is allocated in ethtool_get_rxnfc and the size is determined by
      rule_cnt from user space. So rule_cnt needs to be check before using
      rule_locs to avoid NULL pointer dereference.
      
      Fixes: 7aab747e
      
       ("net: ethernet: mediatek: add ethtool functions to configure RX flows of HW LRO")
      Signed-off-by: default avatarHangyu Hua <hbh25y@gmail.com>
      Reviewed-by: default avatarSimon Horman <horms@kernel.org>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      ff5faed5
    • Hangyu Hua's avatar
      net: ethernet: mvpp2_main: fix possible OOB write in mvpp2_ethtool_get_rxnfc() · 349638f7
      Hangyu Hua authored
      [ Upstream commit 51fe0a47 ]
      
      rules is allocated in ethtool_get_rxnfc and the size is determined by
      rule_cnt from user space. So rule_cnt needs to be check before using
      rules to avoid OOB writing or NULL pointer dereference.
      
      Fixes: 90b509b3
      
       ("net: mvpp2: cls: Add Classification offload support")
      Signed-off-by: default avatarHangyu Hua <hbh25y@gmail.com>
      Reviewed-by: default avatarMarcin Wojtas <mw@semihalf.com>
      Reviewed-by: default avatarRussell King (Oracle) <rmk+kernel@armlinux.org.uk>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      349638f7
    • Vincent Whitchurch's avatar
      net: stmmac: fix handling of zero coalescing tx-usecs · 9dbbc87d
      Vincent Whitchurch authored
      [ Upstream commit fa60b816 ]
      
      Setting ethtool -C eth0 tx-usecs 0 is supposed to disable the use of the
      coalescing timer but currently it gets programmed with zero delay
      instead.
      
      Disable the use of the coalescing timer if tx-usecs is zero by
      preventing it from being restarted.  Note that to keep things simple we
      don't start/stop the timer when the coalescing settings are changed, but
      just let that happen on the next transmit or timer expiry.
      
      Fixes: 8fce3331
      
       ("net: stmmac: Rework coalesce timer and fix multi-queue races")
      Signed-off-by: default avatarVincent Whitchurch <vincent.whitchurch@axis.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      9dbbc87d
    • Guangguan Wang's avatar
      net/smc: use smc_lgr_list.lock to protect smc_lgr_list.list iterate in smcr_port_add · 70c8d170
      Guangguan Wang authored
      [ Upstream commit f5146e3e ]
      
      While doing smcr_port_add, there maybe linkgroup add into or delete
      from smc_lgr_list.list at the same time, which may result kernel crash.
      So, use smc_lgr_list.lock to protect smc_lgr_list.list iterate in
      smcr_port_add.
      
      The crash calltrace show below:
      BUG: kernel NULL pointer dereference, address: 0000000000000000
      PGD 0 P4D 0
      Oops: 0000 [#1] SMP NOPTI
      CPU: 0 PID: 559726 Comm: kworker/0:92 Kdump: loaded Tainted: G
      Hardware name: Alibaba Cloud Alibaba Cloud ECS, BIOS 449e491 04/01/2014
      Workqueue: events smc_ib_port_event_work [smc]
      RIP: 0010:smcr_port_add+0xa6/0xf0 [smc]
      RSP: 0000:ffffa5a2c8f67de0 EFLAGS: 00010297
      RAX: 0000000000000001 RBX: ffff9935e0650000 RCX: 0000000000000000
      RDX: 0000000000000010 RSI: ffff9935e0654290 RDI: ffff9935c8560000
      RBP: 0000000000000000 R08: 0000000000000000 R09: ffff9934c0401918
      R10: 0000000000000000 R11: ffffffffb4a5c278 R12: ffff99364029aae4
      R13: ffff99364029aa00 R14: 00000000ffffffed R15: ffff99364029ab08
      FS:  0000000000000000(0000) GS:ffff994380600000(0000) knlGS:0000000000000000
      CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      CR2: 0000000000000000 CR3: 0000000f06a10003 CR4: 0000000002770ef0
      PKRU: 55555554
      Call Trace:
       smc_ib_port_event_work+0x18f/0x380 [smc]
       process_one_work+0x19b/0x340
       worker_thread+0x30/0x370
       ? process_one_work+0x340/0x340
       kthread+0x114/0x130
       ? __kthread_cancel_work+0x50/0x50
       ret_from_fork+0x1f/0x30
      
      Fixes: 1f90a05d
      
       ("net/smc: add smcr_port_add() and smcr_link_up() processing")
      Signed-off-by: default avatarGuangguan Wang <guangguan.wang@linux.alibaba.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      70c8d170
    • Björn Töpel's avatar
      selftests: Keep symlinks, when possible · ef5d546b
      Björn Töpel authored
      [ Upstream commit 3f3f3841 ]
      
      When kselftest is built/installed with the 'gen_tar' target, rsync is
      used for the installation step to copy files. Extra care is needed for
      tests that have symlinks. Commit ae108c48 ("selftests: net: Fix
      cross-tree inclusion of scripts") added '-L' (transform symlink into
      referent file/dir) to rsync, to fix dangling links. However, that
      broke some tests where the symlink (being a symlink) is part of the
      test (e.g. exec:execveat).
      
      Use rsync's '--copy-unsafe-links' that does right thing.
      
      Fixes: ae108c48
      
       ("selftests: net: Fix cross-tree inclusion of scripts")
      Signed-off-by: default avatarBjörn Töpel <bjorn@rivosinc.com>
      Reviewed-by: default avatarBenjamin Poirier <bpoirier@nvidia.com>
      Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      ef5d546b
    • Björn Töpel's avatar
      kselftest/runner.sh: Propagate SIGTERM to runner child · cdd61a27
      Björn Töpel authored
      [ Upstream commit 9616cb34 ]
      
      Timeouts in kselftest are done using the "timeout" command with the
      "--foreground" option. Without the "foreground" option, it is not
      possible for a user to cancel the runner using SIGINT, because the
      signal is not propagated to timeout which is running in a different
      process group. The "forground" options places the timeout in the same
      process group as its parent, but only sends the SIGTERM (on timeout)
      signal to the forked process. Unfortunately, this does not play nice
      with all kselftests, e.g. "net:fcnal-test.sh", where the child
      processes will linger because timeout does not send SIGTERM to the
      group.
      
      Some users have noted these hangs [1].
      
      Fix this by nesting the timeout with an additional timeout without the
      foreground option.
      
      Link: https://lore.kernel.org/all/7650b2eb-0aee-a2b0-2e64-c9bc63210f67@alu.unizg.hr/ # [1]
      Fixes: 651e0d88
      
       ("kselftest/runner: allow to properly deliver signals to tests")
      Signed-off-by: default avatarBjörn Töpel <bjorn@rivosinc.com>
      Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      cdd61a27
    • Liu Jian's avatar
      net: ipv4: fix one memleak in __inet_del_ifa() · 980f8445
      Liu Jian authored
      [ Upstream commit ac28b1ec ]
      
      I got the below warning when do fuzzing test:
      unregister_netdevice: waiting for bond0 to become free. Usage count = 2
      
      It can be repoduced via:
      
      ip link add bond0 type bond
      sysctl -w net.ipv4.conf.bond0.promote_secondaries=1
      ip addr add 4.117.174.103/0 scope 0x40 dev bond0
      ip addr add 192.168.100.111/255.255.255.254 scope 0 dev bond0
      ip addr add 0.0.0.4/0 scope 0x40 secondary dev bond0
      ip addr del 4.117.174.103/0 scope 0x40 dev bond0
      ip link delete bond0 type bond
      
      In this reproduction test case, an incorrect 'last_prim' is found in
      __inet_del_ifa(), as a result, the secondary address(0.0.0.4/0 scope 0x40)
      is lost. The memory of the secondary address is leaked and the reference of
      in_device and net_device is leaked.
      
      Fix this problem:
      Look for 'last_prim' starting at location of the deleted IP and inserting
      the promoted IP into the location of 'last_prim'.
      
      Fixes: 0ff60a45
      
       ("[IPV4]: Fix secondary IP addresses after promotion")
      Signed-off-by: default avatarLiu Jian <liujian56@huawei.com>
      Signed-off-by: default avatarJulian Anastasov <ja@ssi.bg>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      980f8445
    • Jinjie Ruan's avatar
      kunit: Fix wild-memory-access bug in kunit_free_suite_set() · 9acb294e
      Jinjie Ruan authored
      [ Upstream commit 2810c1e9 ]
      
      Inject fault while probing kunit-example-test.ko, if kstrdup()
      fails in mod_sysfs_setup() in load_module(), the mod->state will
      switch from MODULE_STATE_COMING to MODULE_STATE_GOING instead of
      from MODULE_STATE_LIVE to MODULE_STATE_GOING, so only
      kunit_module_exit() will be called without kunit_module_init(), and
      the mod->kunit_suites is no set correctly and the free in
      kunit_free_suite_set() will cause below wild-memory-access bug.
      
      The mod->state state machine when load_module() succeeds:
      
      MODULE_STATE_UNFORMED ---> MODULE_STATE_COMING ---> MODULE_STATE_LIVE
      	 ^						|
      	 |						| delete_module
      	 +---------------- MODULE_STATE_GOING <---------+
      
      The mod->state state machine when load_module() fails at
      mod_sysfs_setup():
      
      MODULE_STATE_UNFORMED ---> MODULE_STATE_COMING ---> MODULE_STATE_GOING
      	^						|
      	|						|
      	+-----------------------------------------------+
      
      Call kunit_module_init() at MODULE_STATE_COMING state to fix the issue
      because MODULE_STATE_LIVE is transformed from it.
      
       Unable to handle kernel paging request at virtual address ffffff341e942a88
       KASAN: maybe wild-memory-access in range [0x0003f9a0f4a15440-0x0003f9a0f4a15447]
       Mem abort info:
         ESR = 0x0000000096000004
         EC = 0x25: DABT (current EL), IL = 32 bits
         SET = 0, FnV = 0
         EA = 0, S1PTW = 0
         FSC = 0x04: level 0 translation fault
       Data abort info:
         ISV = 0, ISS = 0x00000004, ISS2 = 0x00000000
         CM = 0, WnR = 0, TnD = 0, TagAccess = 0
         GCS = 0, Overlay = 0, DirtyBit = 0, Xs = 0
       swapper pgtable: 4k pages, 48-bit VAs, pgdp=00000000441ea000
       [ffffff341e942a88] pgd=0000000000000000, p4d=0000000000000000
       Internal error: Oops: 0000000096000004 [#1] PREEMPT SMP
       Modules linked in: kunit_example_test(-) cfg80211 rfkill 8021q garp mrp stp llc ipv6 [last unloaded: kunit_example_test]
       CPU: 3 PID: 2035 Comm: modprobe Tainted: G        W        N 6.5.0-next-20230828+ #136
       Hardware name: linux,dummy-virt (DT)
       pstate: a0000005 (NzCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--)
       pc : kfree+0x2c/0x70
       lr : kunit_free_suite_set+0xcc/0x13c
       sp : ffff8000829b75b0
       x29: ffff8000829b75b0 x28: ffff8000829b7b90 x27: 0000000000000000
       x26: dfff800000000000 x25: ffffcd07c82a7280 x24: ffffcd07a50ab300
       x23: ffffcd07a50ab2e8 x22: 1ffff00010536ec0 x21: dfff800000000000
       x20: ffffcd07a50ab2f0 x19: ffffcd07a50ab2f0 x18: 0000000000000000
       x17: 0000000000000000 x16: 0000000000000000 x15: ffffcd07c24b6764
       x14: ffffcd07c24b63c0 x13: ffffcd07c4cebb94 x12: ffff700010536ec7
       x11: 1ffff00010536ec6 x10: ffff700010536ec6 x9 : dfff800000000000
       x8 : 00008fffefac913a x7 : 0000000041b58ab3 x6 : 0000000000000000
       x5 : 1ffff00010536ec5 x4 : ffff8000829b7628 x3 : dfff800000000000
       x2 : ffffff341e942a80 x1 : ffffcd07a50aa000 x0 : fffffc0000000000
       Call trace:
        kfree+0x2c/0x70
        kunit_free_suite_set+0xcc/0x13c
        kunit_module_notify+0xd8/0x360
        blocking_notifier_call_chain+0xc4/0x128
        load_module+0x382c/0x44a4
        init_module_from_file+0xd4/0x128
        idempotent_init_module+0x2c8/0x524
        __arm64_sys_finit_module+0xac/0x100
        invoke_syscall+0x6c/0x258
        el0_svc_common.constprop.0+0x160/0x22c
        do_el0_svc+0x44/0x5c
        el0_svc+0x38/0x78
        el0t_64_sync_handler+0x13c/0x158
        el0t_64_sync+0x190/0x194
       Code: aa0003e1 b25657e0 d34cfc42 8b021802 (f9400440)
       ---[ end trace 0000000000000000 ]---
       Kernel panic - not syncing: Oops: Fatal exception
       SMP: stopping secondary CPUs
       Kernel Offset: 0x4d0742200000 from 0xffff800080000000
       PHYS_OFFSET: 0xffffee43c0000000
       CPU features: 0x88000203,3c020000,1000421b
       Memory Limit: none
       Rebooting in 1 seconds..
      
      Fixes: 3d6e4462
      
       ("kunit: unify module and builtin suite definitions")
      Signed-off-by: default avatarJinjie Ruan <ruanjinjie@huawei.com>
      Reviewed-by: default avatarRae Moar <rmoar@google.com>
      Reviewed-by: default avatarDavid Gow <davidgow@google.com>
      Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      9acb294e
    • Hamza Mahfooz's avatar
      drm/amdgpu: register a dirty framebuffer callback for fbcon · cb30ff2a
      Hamza Mahfooz authored
      commit 0a611560
      
       upstream.
      
      fbcon requires that we implement &drm_framebuffer_funcs.dirty.
      Otherwise, the framebuffer might take a while to flush (which would
      manifest as noticeable lag). However, we can't enable this callback for
      non-fbcon cases since it may cause too many atomic commits to be made at
      once. So, implement amdgpu_dirtyfb() and only enable it for fbcon
      framebuffers (we can use the "struct drm_file file" parameter in the
      callback to check for this since it is only NULL when called by fbcon,
      at least in the mainline kernel) on devices that support atomic KMS.
      
      Cc: Aurabindo Pillai <aurabindo.pillai@amd.com>
      Cc: Mario Limonciello <mario.limonciello@amd.com>
      Cc: stable@vger.kernel.org # 6.1+
      Link: https://gitlab.freedesktop.org/drm/amd/-/issues/2519
      Reviewed-by: default avatarMario Limonciello <mario.limonciello@amd.com>
      Signed-off-by: default avatarHamza Mahfooz <hamza.mahfooz@amd.com>
      Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      cb30ff2a
    • Gabe Teeger's avatar
      drm/amd/display: Remove wait while locked · b53fee19
      Gabe Teeger authored
      commit 5a3ccb14 upstream.
      
      [Why]
      We wait for mpc idle while in a locked state, leading to potential
      deadlock.
      
      [What]
      Move the wait_for_idle call to outside of HW lock. This and a
      call to wait_drr_doublebuffer_pending_clear are moved added to a new
      static helper function called wait_for_outstanding_hw_updates, to make
      the interface clearer.
      
      Cc: stable@vger.kernel.org
      Fixes: 8f0d304d
      
       ("drm/amd/display: Do not commit pipe when updating DRR")
      Reviewed-by: default avatarJun Lei <jun.lei@amd.com>
      Acked-by: default avatarHamza Mahfooz <hamza.mahfooz@amd.com>
      Signed-off-by: default avatarGabe Teeger <gabe.teeger@amd.com>
      Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b53fee19
    • Wenjing Liu's avatar
      drm/amd/display: always switch off ODM before committing more streams · 2d7a6fcb
      Wenjing Liu authored
      commit 49a30c3d upstream.
      
      ODM power optimization is only supported with single stream. When ODM
      power optimization is enabled, we might not have enough free pipes for
      enabling other stream. So when we are committing more than 1 stream we
      should first switch off ODM power optimization to make room for new
      stream and then allocating pipe resource for the new stream.
      
      Cc: stable@vger.kernel.org
      Fixes: 59de751e
      
       ("drm/amd/display: add ODM case when looking for first split pipe")
      Reviewed-by: default avatarDillon Varone <dillon.varone@amd.com>
      Acked-by: default avatarHamza Mahfooz <hamza.mahfooz@amd.com>
      Signed-off-by: default avatarWenjing Liu <wenjing.liu@amd.com>
      Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2d7a6fcb
    • Namhyung Kim's avatar
      perf hists browser: Fix the number of entries for 'e' key · c29bfda6
      Namhyung Kim authored
      commit f6b8436b upstream.
      
      The 'e' key is to toggle expand/collapse the selected entry only.  But
      the current code has a bug that it only increases the number of entries
      by 1 in the hierarchy mode so users cannot move under the current entry
      after the key stroke.  This is due to a wrong assumption in the
      hist_entry__set_folding().
      
      The commit b33f9226 ("perf hists browser: Put hist_entry folding
      logic into single function") factored out the code, but actually it
      should be handled separately.  The hist_browser__set_folding() is to
      update fold state for each entry so it needs to traverse all (child)
      entries regardless of the current fold state.  So it increases the
      number of entries by 1.
      
      But the hist_entry__set_folding() only cares the currently selected
      entry and its all children.  So it should count all unfolded child
      entries.  This code is implemented in hist_browser__toggle_fold()
      already so we can just call it.
      
      Fixes: b33f9226
      
       ("perf hists browser: Put hist_entry folding logic into single function")
      Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: stable@vger.kernel.org
      Link: https://lore.kernel.org/r/20230731094934.1616495-2-namhyung@kernel.org
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c29bfda6
    • Namhyung Kim's avatar
      perf tools: Handle old data in PERF_RECORD_ATTR · f4618f13
      Namhyung Kim authored
      commit 9bf63282 upstream.
      
      The PERF_RECORD_ATTR is used for a pipe mode to describe an event with
      attribute and IDs.  The ID table comes after the attr and it calculate
      size of the table using the total record size and the attr size.
      
        n_ids = (total_record_size - end_of_the_attr_field) / sizeof(u64)
      
      This is fine for most use cases, but sometimes it saves the pipe output
      in a file and then process it later.  And it becomes a problem if there
      is a change in attr size between the record and report.
      
        $ perf record -o- > perf-pipe.data  # old version
        $ perf report -i- < perf-pipe.data  # new version
      
      For example, if the attr size is 128 and it has 4 IDs, then it would
      save them in 168 byte like below:
      
         8 byte: perf event header { .type = PERF_RECORD_ATTR, .size = 168 },
       128 byte: perf event attr { .size = 128, ... },
        32 byte: event IDs [] = { 1234, 1235, 1236, 1237 },
      
      But when report later, it thinks the attr size is 136 then it only read
      the last 3 entries as ID.
      
         8 byte: perf event header { .type = PERF_RECORD_ATTR, .size = 168 },
       136 byte: perf event attr { .size = 136, ... },
        24 byte: event IDs [] = { 1235, 1236, 1237 },  // 1234 is missing
      
      So it should use the recorded version of the attr.  The attr has the
      size field already then it should honor the size when reading data.
      
      Fixes: 2c46dbb5
      
       ("perf: Convert perf header attrs into attr events")
      Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Tom Zanussi <zanussi@kernel.org>
      Cc: stable@vger.kernel.org
      Link: https://lore.kernel.org/r/20230825152552.112913-1-namhyung@kernel.org
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f4618f13
    • Namhyung Kim's avatar
      perf test shell stat_bpf_counters: Fix test on Intel · be69e8c8
      Namhyung Kim authored
      commit 68ca249c upstream.
      
      As of now, bpf counters (bperf) don't support event groups.  But the
      default perf stat includes topdown metrics if supported (on recent Intel
      machines) which require groups.  That makes perf stat exiting.
      
        $ sudo perf stat --bpf-counter true
        bpf managed perf events do not yet support groups.
      
      Actually the test explicitly uses cycles event only, but it missed to
      pass the option when it checks the availability of the command.
      
      Fixes: 2c0cb9f5
      
       ("perf test: Add a shell test for 'perf stat --bpf-counters' new option")
      Reviewed-by: default avatarSong Liu <song@kernel.org>
      Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: bpf@vger.kernel.org
      Cc: stable@vger.kernel.org
      Link: https://lore.kernel.org/r/20230825164152.165610-2-namhyung@kernel.org
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      be69e8c8
    • Namhyung Kim's avatar
      perf hists browser: Fix hierarchy mode header · cb094064
      Namhyung Kim authored
      commit e2cabf2a upstream.
      
      The commit ef9ff601 ("perf ui browser: Move the extra title
      lines from the hists browser") introduced ui_browser__gotorc_title() to
      help moving non-title lines easily.  But it missed to update the title
      for the hierarchy mode so it won't print the header line on TUI at all.
      
        $ perf report --hierarchy
      
      Fixes: ef9ff601
      
       ("perf ui browser: Move the extra title lines from the hists browser")
      Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: stable@vger.kernel.org
      Link: https://lore.kernel.org/r/20230731094934.1616495-1-namhyung@kernel.org
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      cb094064
    • Maciej W. Rozycki's avatar
      MIPS: Fix CONFIG_CPU_DADDI_WORKAROUNDS `modules_install' regression · ec540961
      Maciej W. Rozycki authored
      commit a79a404e upstream.
      
      Remove a build-time check for the presence of the GCC `-msym32' option.
      This option has been there since GCC 4.1.0, which is below the minimum
      required as at commit 805b2e1d
      
       ("kbuild: include Makefile.compiler
      only when compiler is needed"), when an error message:
      
      arch/mips/Makefile:306: *** CONFIG_CPU_DADDI_WORKAROUNDS unsupported without -msym32.  Stop.
      
      started to trigger for the `modules_install' target with configurations
      such as `decstation_64_defconfig' that set CONFIG_CPU_DADDI_WORKAROUNDS,
      because said commit has made `cc-option-yn' an undefined function for
      non-build targets.
      
      Reported-by: default avatarJan-Benedict Glaw <jbglaw@lug-owl.de>
      Signed-off-by: default avatarMaciej W. Rozycki <macro@orcam.me.uk>
      Fixes: 805b2e1d
      
       ("kbuild: include Makefile.compiler only when compiler is needed")
      Cc: stable@vger.kernel.org # v5.13+
      Reviewed-by: default avatarPhilippe Mathieu-Daudé <philmd@linaro.org>
      Signed-off-by: default avatarThomas Bogendoerfer <tsbogend@alpha.franken.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ec540961
    • Sean Christopherson's avatar
      KVM: SVM: Skip VMSA init in sev_es_init_vmcb() if pointer is NULL · 60b5ef4c
      Sean Christopherson authored
      commit 1952e74d upstream.
      
      Skip initializing the VMSA physical address in the VMCB if the VMSA is
      NULL, which occurs during intrahost migration as KVM initializes the VMCB
      before copying over state from the source to the destination (including
      the VMSA and its physical address).
      
      In normal builds, __pa() is just math, so the bug isn't fatal, but with
      CONFIG_DEBUG_VIRTUAL=y, the validity of the virtual address is verified
      and passing in NULL will make the kernel unhappy.
      
      Fixes: 6defa24d
      
       ("KVM: SEV: Init target VMCBs in sev_migrate_from")
      Cc: stable@vger.kernel.org
      Cc: Peter Gonda <pgonda@google.com>
      Reviewed-by: default avatarPeter Gonda <pgonda@google.com>
      Reviewed-by: default avatarPankaj Gupta <pankaj.gupta@amd.com>
      Link: https://lore.kernel.org/r/20230825022357.2852133-3-seanjc@google.com
      Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      60b5ef4c
    • Sean Christopherson's avatar
      KVM: SVM: Set target pCPU during IRTE update if target vCPU is running · 12645e62
      Sean Christopherson authored
      commit f3cebc75 upstream.
      
      Update the target pCPU for IOMMU doorbells when updating IRTE routing if
      KVM is actively running the associated vCPU.  KVM currently only updates
      the pCPU when loading the vCPU (via avic_vcpu_load()), and so doorbell
      events will be delayed until the vCPU goes through a put+load cycle (which
      might very well "never" happen for the lifetime of the VM).
      
      To avoid inserting a stale pCPU, e.g. due to racing between updating IRTE
      routing and vCPU load/put, get the pCPU information from the vCPU's
      Physical APIC ID table entry (a.k.a. avic_physical_id_cache in KVM) and
      update the IRTE while holding ir_list_lock.  Add comments with --verbose
      enabled to explain exactly what is and isn't protected by ir_list_lock.
      
      Fixes: 411b44ba
      
       ("svm: Implements update_pi_irte hook to setup posted interrupt")
      Reported-by: default avatardengqiao.joey <dengqiao.joey@bytedance.com>
      Cc: stable@vger.kernel.org
      Cc: Alejandro Jimenez <alejandro.j.jimenez@oracle.com>
      Cc: Joao Martins <joao.m.martins@oracle.com>
      Cc: Maxim Levitsky <mlevitsk@redhat.com>
      Cc: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
      Tested-by: default avatarAlejandro Jimenez <alejandro.j.jimenez@oracle.com>
      Reviewed-by: default avatarJoao Martins <joao.m.martins@oracle.com>
      Link: https://lore.kernel.org/r/20230808233132.2499764-3-seanjc@google.com
      Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      12645e62
    • Sean Christopherson's avatar
      KVM: nSVM: Load L1's TSC multiplier based on L1 state, not L2 state · 5b2b0535
      Sean Christopherson authored
      commit 0c94e246 upstream.
      
      When emulating nested VM-Exit, load L1's TSC multiplier if L1's desired
      ratio doesn't match the current ratio, not if the ratio L1 is using for
      L2 diverges from the default.  Functionally, the end result is the same
      as KVM will run L2 with L1's multiplier if L2's multiplier is the default,
      i.e. checking that L1's multiplier is loaded is equivalent to checking if
      L2 has a non-default multiplier.
      
      However, the assertion that TSC scaling is exposed to L1 is flawed, as
      userspace can trigger the WARN at will by writing the MSR and then
      updating guest CPUID to hide the feature (modifying guest CPUID is
      allowed anytime before KVM_RUN).  E.g. hacking KVM's state_test
      selftest to do
      
                      vcpu_set_msr(vcpu, MSR_AMD64_TSC_RATIO, 0);
                      vcpu_clear_cpuid_feature(vcpu, X86_FEATURE_TSCRATEMSR);
      
      after restoring state in a new VM+vCPU yields an endless supply of:
      
        ------------[ cut here ]------------
        WARNING: CPU: 10 PID: 206939 at arch/x86/kvm/svm/nested.c:1105
                 nested_svm_vmexit+0x6af/0x720 [kvm_amd]
        Call Trace:
         nested_svm_exit_handled+0x102/0x1f0 [kvm_amd]
         svm_handle_exit+0xb9/0x180 [kvm_amd]
         kvm_arch_vcpu_ioctl_run+0x1eab/0x2570 [kvm]
         kvm_vcpu_ioctl+0x4c9/0x5b0 [kvm]
         ? trace_hardirqs_off+0x4d/0xa0
         __se_sys_ioctl+0x7a/0xc0
         __x64_sys_ioctl+0x21/0x30
         do_syscall_64+0x41/0x90
         entry_SYSCALL_64_after_hwframe+0x63/0xcd
      
      Unlike the nested VMRUN path, hoisting the svm->tsc_scaling_enabled check
      into the if-statement is wrong as KVM needs to ensure L1's multiplier is
      loaded in the above scenario.   Alternatively, the WARN_ON() could simply
      be deleted, but that would make KVM's behavior even more subtle, e.g. it's
      not immediately obvious why it's safe to write MSR_AMD64_TSC_RATIO when
      checking only tsc_ratio_msr.
      
      Fixes: 5228eb96
      
       ("KVM: x86: nSVM: implement nested TSC scaling")
      Cc: Maxim Levitsky <mlevitsk@redhat.com>
      Cc: stable@vger.kernel.org
      Link: https://lore.kernel.org/r/20230729011608.1065019-3-seanjc@google.com
      Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5b2b0535