Skip to content
  1. Jun 16, 2024
    • Friedrich Vock's avatar
      bpf: Fix potential integer overflow in resolve_btfids · e5138f43
      Friedrich Vock authored
      [ Upstream commit 44382b3e ]
      
      err is a 32-bit integer, but elf_update returns an off_t, which is 64-bit
      at least on 64-bit platforms. If symbols_patch is called on a binary between
      2-4GB in size, the result will be negative when cast to a 32-bit integer,
      which the code assumes means an error occurred. This can wrongly trigger
      build failures when building very large kernel images.
      
      Fixes: fbbb68de
      
       ("bpf: Add resolve_btfids tool to resolve BTF IDs in ELF object")
      Signed-off-by: default avatarFriedrich Vock <friedrich.vock@gmx.de>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Acked-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Link: https://lore.kernel.org/bpf/20240514070931.199694-1-friedrich.vock@gmx.de
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      e5138f43
    • Tetsuo Handa's avatar
      dma-buf/sw-sync: don't enable IRQ from sync_print_obj() · 9d75fab2
      Tetsuo Handa authored
      [ Upstream commit b7949189 ]
      
      Since commit a6aa8fca
      
       ("dma-buf/sw-sync: Reduce irqsave/irqrestore from
      known context") by error replaced spin_unlock_irqrestore() with
      spin_unlock_irq() for both sync_debugfs_show() and sync_print_obj() despite
      sync_print_obj() is called from sync_debugfs_show(), lockdep complains
      inconsistent lock state warning.
      
      Use plain spin_{lock,unlock}() for sync_print_obj(), for
      sync_debugfs_show() is already using spin_{lock,unlock}_irq().
      
      Reported-by: default avatarsyzbot <syzbot+a225ee3df7e7f9372dbe@syzkaller.appspotmail.com>
      Closes: https://syzkaller.appspot.com/bug?extid=a225ee3df7e7f9372dbe
      Fixes: a6aa8fca
      
       ("dma-buf/sw-sync: Reduce irqsave/irqrestore from known context")
      Signed-off-by: default avatarTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
      Reviewed-by: default avatarChristian König <christian.koenig@amd.com>
      Link: https://patchwork.freedesktop.org/patch/msgid/c2e46020-aaa6-4e06-bf73-f05823f913f0@I-love.SAKURA.ne.jp
      Signed-off-by: default avatarChristian König <christian.koenig@amd.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      9d75fab2
    • Carolina Jubran's avatar
      net/mlx5e: Use rx_missed_errors instead of rx_dropped for reporting buffer exhaustion · d523719e
      Carolina Jubran authored
      [ Upstream commit 5c74195d ]
      
      Previously, the driver incorrectly used rx_dropped to report device
      buffer exhaustion.
      
      According to the documentation, rx_dropped should not be used to count
      packets dropped due to buffer exhaustion, which is the purpose of
      rx_missed_errors.
      
      Use rx_missed_errors as intended for counting packets dropped due to
      buffer exhaustion.
      
      Fixes: 269e6b3a
      
       ("net/mlx5e: Report additional error statistics in get stats ndo")
      Signed-off-by: default avatarCarolina Jubran <cjubran@nvidia.com>
      Signed-off-by: default avatarTariq Toukan <tariqt@nvidia.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>
      d523719e
    • Rahul Rameshbabu's avatar
      net/mlx5e: Fix IPsec tunnel mode offload feature check · 98f1c6e5
      Rahul Rameshbabu authored
      [ Upstream commit 9a52f6d4 ]
      
      Remove faulty check disabling checksum offload and GSO for offload of
      simple IPsec tunnel L4 traffic. Comment previously describing the deleted
      code incorrectly claimed the check prevented double tunnel (or three layers
      of ip headers).
      
      Fixes: f1267798
      
       ("net/mlx5: Fix checksum issue of VXLAN and IPsec crypto offload")
      Signed-off-by: default avatarRahul Rameshbabu <rrameshbabu@nvidia.com>
      Signed-off-by: default avatarTariq Toukan <tariqt@nvidia.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>
      98f1c6e5
    • Mathieu Othacehe's avatar
      net: phy: micrel: set soft_reset callback to genphy_soft_reset for KSZ8061 · 16f0de91
      Mathieu Othacehe authored
      [ Upstream commit 128d54fb ]
      
      Following a similar reinstate for the KSZ8081 and KSZ9031.
      
      Older kernels would use the genphy_soft_reset if the PHY did not implement
      a .soft_reset.
      
      The KSZ8061 errata described here:
      https://ww1.microchip.com/downloads/en/DeviceDoc/KSZ8061-Errata-DS80000688B.pdf
      and worked around with 232ba3a5 ("net: phy: Micrel KSZ8061: link failure after cable connect")
      is back again without this soft reset.
      
      Fixes: 6e2d85ec
      
       ("net: phy: Stop with excessive soft reset")
      Tested-by: default avatarKarim Ben Houcine <karim.benhoucine@landisgyr.com>
      Signed-off-by: default avatarMathieu Othacehe <othacehe@gnu.org>
      Reviewed-by: default avatarAndrew Lunn <andrew@lunn.ch>
      Reviewed-by: default avatarFlorian Fainelli <florian.fainelli@broadcom.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      16f0de91
    • Sagi Grimberg's avatar
      nvmet: fix ns enable/disable possible hang · 81f9b2a9
      Sagi Grimberg authored
      [ Upstream commit f97914e3 ]
      
      When disabling an nvmet namespace, there is a period where the
      subsys->lock is released, as the ns disable waits for backend IO to
      complete, and the ns percpu ref to be properly killed. The original
      intent was to avoid taking the subsystem lock for a prolong period as
      other processes may need to acquire it (for example new incoming
      connections).
      
      However, it opens up a window where another process may come in and
      enable the ns, (re)intiailizing the ns percpu_ref, causing the disable
      sequence to hang.
      
      Solve this by taking the global nvmet_config_sem over the entire configfs
      enable/disable sequence.
      
      Fixes: a07b4970
      
       ("nvmet: add a generic NVMe target")
      Signed-off-by: default avatarSagi Grimberg <sagi@grimberg.me>
      Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
      Reviewed-by: default avatarChaitanya Kulkarni <kch@nvidia.com>
      Signed-off-by: default avatarKeith Busch <kbusch@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      81f9b2a9
    • Fedor Pchelkin's avatar
      dma-mapping: benchmark: handle NUMA_NO_NODE correctly · b41b0018
      Fedor Pchelkin authored
      [ Upstream commit e64746e7 ]
      
      cpumask_of_node() can be called for NUMA_NO_NODE inside do_map_benchmark()
      resulting in the following sanitizer report:
      
      UBSAN: array-index-out-of-bounds in ./arch/x86/include/asm/topology.h:72:28
      index -1 is out of range for type 'cpumask [64][1]'
      CPU: 1 PID: 990 Comm: dma_map_benchma Not tainted 6.9.0-rc6 #29
      Hardware name: QEMU Standard PC (i440FX + PIIX, 1996)
      Call Trace:
       <TASK>
      dump_stack_lvl (lib/dump_stack.c:117)
      ubsan_epilogue (lib/ubsan.c:232)
      __ubsan_handle_out_of_bounds (lib/ubsan.c:429)
      cpumask_of_node (arch/x86/include/asm/topology.h:72) [inline]
      do_map_benchmark (kernel/dma/map_benchmark.c:104)
      map_benchmark_ioctl (kernel/dma/map_benchmark.c:246)
      full_proxy_unlocked_ioctl (fs/debugfs/file.c:333)
      __x64_sys_ioctl (fs/ioctl.c:890)
      do_syscall_64 (arch/x86/entry/common.c:83)
      entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:130)
      
      Use cpumask_of_node() in place when binding a kernel thread to a cpuset
      of a particular node.
      
      Note that the provided node id is checked inside map_benchmark_ioctl().
      It's just a NUMA_NO_NODE case which is not handled properly later.
      
      Found by Linux Verification Center (linuxtesting.org).
      
      Fixes: 65789daa
      
       ("dma-mapping: add benchmark support for streaming DMA APIs")
      Signed-off-by: default avatarFedor Pchelkin <pchelkin@ispras.ru>
      Acked-by: default avatarBarry Song <baohua@kernel.org>
      Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      b41b0018
    • Fedor Pchelkin's avatar
      dma-mapping: benchmark: fix node id validation · 35d31c8b
      Fedor Pchelkin authored
      [ Upstream commit 1ff05e72 ]
      
      While validating node ids in map_benchmark_ioctl(), node_possible() may
      be provided with invalid argument outside of [0,MAX_NUMNODES-1] range
      leading to:
      
      BUG: KASAN: wild-memory-access in map_benchmark_ioctl (kernel/dma/map_benchmark.c:214)
      Read of size 8 at addr 1fffffff8ccb6398 by task dma_map_benchma/971
      CPU: 7 PID: 971 Comm: dma_map_benchma Not tainted 6.9.0-rc6 #37
      Hardware name: QEMU Standard PC (i440FX + PIIX, 1996)
      Call Trace:
       <TASK>
      dump_stack_lvl (lib/dump_stack.c:117)
      kasan_report (mm/kasan/report.c:603)
      kasan_check_range (mm/kasan/generic.c:189)
      variable_test_bit (arch/x86/include/asm/bitops.h:227) [inline]
      arch_test_bit (arch/x86/include/asm/bitops.h:239) [inline]
      _test_bit at (include/asm-generic/bitops/instrumented-non-atomic.h:142) [inline]
      node_state (include/linux/nodemask.h:423) [inline]
      map_benchmark_ioctl (kernel/dma/map_benchmark.c:214)
      full_proxy_unlocked_ioctl (fs/debugfs/file.c:333)
      __x64_sys_ioctl (fs/ioctl.c:890)
      do_syscall_64 (arch/x86/entry/common.c:83)
      entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:130)
      
      Compare node ids with sane bounds first. NUMA_NO_NODE is considered a
      special valid case meaning that benchmarking kthreads won't be bound to a
      cpuset of a given node.
      
      Found by Linux Verification Center (linuxtesting.org).
      
      Fixes: 65789daa
      
       ("dma-mapping: add benchmark support for streaming DMA APIs")
      Signed-off-by: default avatarFedor Pchelkin <pchelkin@ispras.ru>
      Reviewed-by: default avatarRobin Murphy <robin.murphy@arm.com>
      Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      35d31c8b
    • Andy Shevchenko's avatar
      spi: Don't mark message DMA mapped when no transfer in it is · 314607e6
      Andy Shevchenko authored
      [ Upstream commit 9f788ba4 ]
      
      There is no need to set the DMA mapped flag of the message if it has
      no mapped transfers. Moreover, it may give the code a chance to take
      the wrong paths, i.e. to exercise DMA related APIs on unmapped data.
      Make __spi_map_msg() to bail earlier on the above mentioned cases.
      
      Fixes: 99adef31
      
       ("spi: Provide core support for DMA mapping transfers")
      Signed-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
      Link: https://msgid.link/r/20240522171018.3362521-2-andriy.shevchenko@linux.intel.com
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      314607e6
    • Pablo Neira Ayuso's avatar
      netfilter: nft_payload: restore vlan q-in-q match support · 748cf3c2
      Pablo Neira Ayuso authored
      [ Upstream commit aff5c01f ]
      
      Revert f6ae9f12 ("netfilter: nft_payload: add C-VLAN support").
      
      f41f72d0 ("netfilter: nft_payload: simplify vlan header handling")
      already allows to match on inner vlan tags by subtract the vlan header
      size to the payload offset which has been popped and stored in skbuff
      metadata fields.
      
      Fixes: f6ae9f12
      
       ("netfilter: nft_payload: add C-VLAN support")
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      748cf3c2
    • Eric Dumazet's avatar
      netfilter: nfnetlink_queue: acquire rcu_read_lock() in instance_destroy_rcu() · 25ea5377
      Eric Dumazet authored
      [ Upstream commit dc21c6cc ]
      
      syzbot reported that nf_reinject() could be called without rcu_read_lock() :
      
      WARNING: suspicious RCU usage
      6.9.0-rc7-syzkaller-02060-g5c1672705a1a #0 Not tainted
      
      net/netfilter/nfnetlink_queue.c:263 suspicious rcu_dereference_check() usage!
      
      other info that might help us debug this:
      
      rcu_scheduler_active = 2, debug_locks = 1
      2 locks held by syz-executor.4/13427:
        #0: ffffffff8e334f60 (rcu_callback){....}-{0:0}, at: rcu_lock_acquire include/linux/rcupdate.h:329 [inline]
        #0: ffffffff8e334f60 (rcu_callback){....}-{0:0}, at: rcu_do_batch kernel/rcu/tree.c:2190 [inline]
        #0: ffffffff8e334f60 (rcu_callback){....}-{0:0}, at: rcu_core+0xa86/0x1830 kernel/rcu/tree.c:2471
        #1: ffff88801ca92958 (&inst->lock){+.-.}-{2:2}, at: spin_lock_bh include/linux/spinlock.h:356 [inline]
        #1: ffff88801ca92958 (&inst->lock){+.-.}-{2:2}, at: nfqnl_flush net/netfilter/nfnetlink_queue.c:405 [inline]
        #1: ffff88801ca92958 (&inst->lock){+.-.}-{2:2}, at: instance_destroy_rcu+0x30/0x220 net/netfilter/nfnetlink_queue.c:172
      
      stack backtrace:
      CPU: 0 PID: 13427 Comm: syz-executor.4 Not tainted 6.9.0-rc7-syzkaller-02060-g5c1672705a1a #0
      Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 04/02/2024
      Call Trace:
       <IRQ>
        __dump_stack lib/dump_stack.c:88 [inline]
        dump_stack_lvl+0x241/0x360 lib/dump_stack.c:114
        lockdep_rcu_suspicious+0x221/0x340 kernel/locking/lockdep.c:6712
        nf_reinject net/netfilter/nfnetlink_queue.c:323 [inline]
        nfqnl_reinject+0x6ec/0x1120 net/netfilter/nfnetlink_queue.c:397
        nfqnl_flush net/netfilter/nfnetlink_queue.c:410 [inline]
        instance_destroy_rcu+0x1ae/0x220 net/netfilter/nfnetlink_queue.c:172
        rcu_do_batch kernel/rcu/tree.c:2196 [inline]
        rcu_core+0xafd/0x1830 kernel/rcu/tree.c:2471
        handle_softirqs+0x2d6/0x990 kernel/softirq.c:554
        __do_softirq kernel/softirq.c:588 [inline]
        invoke_softirq kernel/softirq.c:428 [inline]
        __irq_exit_rcu+0xf4/0x1c0 kernel/softirq.c:637
        irq_exit_rcu+0x9/0x30 kernel/softirq.c:649
        instr_sysvec_apic_timer_interrupt arch/x86/kernel/apic/apic.c:1043 [inline]
        sysvec_apic_timer_interrupt+0xa6/0xc0 arch/x86/kernel/apic/apic.c:1043
       </IRQ>
       <TASK>
      
      Fixes: 9872bec7
      
       ("[NETFILTER]: nfnetlink: use RCU for queue instances hash")
      Reported-by: default avatarsyzbot <syzkaller@googlegroups.com>
      Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
      Acked-by: default avatarFlorian Westphal <fw@strlen.de>
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      25ea5377
    • Larysa Zaremba's avatar
      ice: Interpret .set_channels() input differently · 5935b9ff
      Larysa Zaremba authored
      [ Upstream commit 05d6f442 ]
      
      A bug occurs because a safety check guarding AF_XDP-related queues in
      ethnl_set_channels(), does not trigger. This happens, because kernel and
      ice driver interpret the ethtool command differently.
      
      How the bug occurs:
      1. ethtool -l <IFNAME> -> combined: 40
      2. Attach AF_XDP to queue 30
      3. ethtool -L <IFNAME> rx 15 tx 15
         combined number is not specified, so command becomes {rx_count = 15,
         tx_count = 15, combined_count = 40}.
      4. ethnl_set_channels checks, if there are any AF_XDP of queues from the
         new (combined_count + rx_count) to the old one, so from 55 to 40, check
         does not trigger.
      5. ice interprets `rx 15 tx 15` as 15 combined channels and deletes the
         queue that AF_XDP is attached to.
      
      Interpret the command in a way that is more consistent with ethtool
      manual [0] (--show-channels and --set-channels).
      
      Considering that in the ice driver only the difference between RX and TX
      queues forms dedicated channels, change the correct way to set number of
      channels to:
      
      ethtool -L <IFNAME> combined 10 /* For symmetric queues */
      ethtool -L <IFNAME> combined 8 tx 2 rx 0 /* For asymmetric queues */
      
      [0] https://man7.org/linux/man-pages/man8/ethtool.8.html
      
      Fixes: 87324e74
      
       ("ice: Implement ethtool ops for channels")
      Reviewed-by: default avatarMichal Swiatkowski <michal.swiatkowski@linux.intel.com>
      Signed-off-by: default avatarLarysa Zaremba <larysa.zaremba@intel.com>
      Tested-by: default avatarChandan Kumar Rout <chandanx.rout@intel.com>
      Tested-by: default avatarPucha Himasekhar Reddy <himasekharx.reddy.pucha@intel.com>
      Acked-by: default avatarMaciej Fijalkowski <maciej.fijalkowski@intel.com>
      Signed-off-by: default avatarJacob Keller <jacob.e.keller@intel.com>
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      5935b9ff
    • Ryosuke Yasuoka's avatar
      nfc: nci: Fix handling of zero-length payload packets in nci_rx_work() · 0f3ced8b
      Ryosuke Yasuoka authored
      [ Upstream commit 6671e352 ]
      
      When nci_rx_work() receives a zero-length payload packet, it should not
      discard the packet and exit the loop. Instead, it should continue
      processing subsequent packets.
      
      Fixes: d24b0353
      
       ("nfc: nci: Fix uninit-value in nci_dev_up and nci_ntf_packet")
      Signed-off-by: default avatarRyosuke Yasuoka <ryasuoka@redhat.com>
      Reviewed-by: default avatarSimon Horman <horms@kernel.org>
      Reviewed-by: default avatarKrzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
      Link: https://lore.kernel.org/r/20240521153444.535399-1-ryasuoka@redhat.com
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      0f3ced8b
    • Tetsuo Handa's avatar
      nfc: nci: Fix kcov check in nci_rx_work() · 6e48baec
      Tetsuo Handa authored
      [ Upstream commit 19e35f24 ]
      
      Commit 7e8cdc97 ("nfc: Add KCOV annotations") added
      kcov_remote_start_common()/kcov_remote_stop() pair into nci_rx_work(),
      with an assumption that kcov_remote_stop() is called upon continue of
      the for loop. But commit d24b0353
      
       ("nfc: nci: Fix uninit-value in
      nci_dev_up and nci_ntf_packet") forgot to call kcov_remote_stop() before
      break of the for loop.
      
      Reported-by: default avatarsyzbot <syzbot+0438378d6f157baae1a2@syzkaller.appspotmail.com>
      Closes: https://syzkaller.appspot.com/bug?extid=0438378d6f157baae1a2
      Fixes: d24b0353
      
       ("nfc: nci: Fix uninit-value in nci_dev_up and nci_ntf_packet")
      Suggested-by: default avatarAndrey Konovalov <andreyknvl@gmail.com>
      Signed-off-by: default avatarTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
      Reviewed-by: default avatarKrzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
      Link: https://lore.kernel.org/r/6d10f829-5a0c-405a-b39a-d7266f3a1a0b@I-love.SAKURA.ne.jp
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Stable-dep-of: 6671e352
      
       ("nfc: nci: Fix handling of zero-length payload packets in nci_rx_work()")
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      6e48baec
    • Dae R. Jeong's avatar
      tls: fix missing memory barrier in tls_init · 2c260a24
      Dae R. Jeong authored
      [ Upstream commit 91e61dd7 ]
      
      In tls_init(), a write memory barrier is missing, and store-store
      reordering may cause NULL dereference in tls_{setsockopt,getsockopt}.
      
      CPU0                               CPU1
      -----                              -----
      // In tls_init()
      // In tls_ctx_create()
      ctx = kzalloc()
      ctx->sk_proto = READ_ONCE(sk->sk_prot) -(1)
      
      // In update_sk_prot()
      WRITE_ONCE(sk->sk_prot, tls_prots)     -(2)
      
                                         // In sock_common_setsockopt()
                                         READ_ONCE(sk->sk_prot)->setsockopt()
      
                                         // In tls_{setsockopt,getsockopt}()
                                         ctx->sk_proto->setsockopt()    -(3)
      
      In the above scenario, when (1) and (2) are reordered, (3) can observe
      the NULL value of ctx->sk_proto, causing NULL dereference.
      
      To fix it, we rely on rcu_assign_pointer() which implies the release
      barrier semantic. By moving rcu_assign_pointer() after ctx->sk_proto is
      initialized, we can ensure that ctx->sk_proto are visible when
      changing sk->sk_prot.
      
      Fixes: d5bee737
      
       ("net/tls: Annotate access to sk_prot with READ_ONCE/WRITE_ONCE")
      Signed-off-by: default avatarYewon Choi <woni9911@gmail.com>
      Signed-off-by: default avatarDae R. Jeong <threeearcat@gmail.com>
      Link: https://lore.kernel.org/netdev/ZU4OJG56g2V9z_H7@dragonet/T/
      Link: https://lore.kernel.org/r/Zkx4vjSFp0mfpjQ2@libra05
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      2c260a24
    • Wei Fang's avatar
      net: fec: avoid lock evasion when reading pps_enable · 2cc3da9a
      Wei Fang authored
      [ Upstream commit 3b1c92f8 ]
      
      The assignment of pps_enable is protected by tmreg_lock, but the read
      operation of pps_enable is not. So the Coverity tool reports a lock
      evasion warning which may cause data race to occur when running in a
      multithread environment. Although this issue is almost impossible to
      occur, we'd better fix it, at least it seems more logically reasonable,
      and it also prevents Coverity from continuing to issue warnings.
      
      Fixes: 278d2404
      
       ("net: fec: ptp: Enable PPS output based on ptp clock")
      Signed-off-by: default avatarWei Fang <wei.fang@nxp.com>
      Link: https://lore.kernel.org/r/20240521023800.17102-1-wei.fang@nxp.com
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      2cc3da9a
    • Matthew Bystrin's avatar
      riscv: stacktrace: fixed walk_stackframe() · b8d78a75
      Matthew Bystrin authored
      [ Upstream commit a2a4d4a6 ]
      
      If the load access fault occures in a leaf function (with
      CONFIG_FRAME_POINTER=y), when wrong stack trace will be displayed:
      
      [<ffffffff804853c2>] regmap_mmio_read32le+0xe/0x1c
      ---[ end trace 0000000000000000 ]---
      
      Registers dump:
          ra     0xffffffff80485758 <regmap_mmio_read+36>
          sp     0xffffffc80200b9a0
          fp     0xffffffc80200b9b0
          pc     0xffffffff804853ba <regmap_mmio_read32le+6>
      
      Stack dump:
          0xffffffc80200b9a0:  0xffffffc80200b9e0  0xffffffc80200b9e0
          0xffffffc80200b9b0:  0xffffffff8116d7e8  0x0000000000000100
          0xffffffc80200b9c0:  0xffffffd8055b9400  0xffffffd8055b9400
          0xffffffc80200b9d0:  0xffffffc80200b9f0  0xffffffff8047c526
          0xffffffc80200b9e0:  0xffffffc80200ba30  0xffffffff8047fe9a
      
      The assembler dump of the function preambula:
          add     sp,sp,-16
          sd      s0,8(sp)
          add     s0,sp,16
      
      In the fist stack frame, where ra is not stored on the stack we can
      observe:
      
              0(sp)                  8(sp)
              .---------------------------------------------.
          sp->|       frame->fp      | frame->ra (saved fp) |
              |---------------------------------------------|
          fp->|         ....         |         ....         |
              |---------------------------------------------|
              |                      |                      |
      
      and in the code check is performed:
      	if (regs && (regs->epc == pc) && (frame->fp & 0x7))
      
      I see no reason to check frame->fp value at all, because it is can be
      uninitialized value on the stack. A better way is to check frame->ra to
      be an address on the stack. After the stacktrace shows as expect:
      
      [<ffffffff804853c2>] regmap_mmio_read32le+0xe/0x1c
      [<ffffffff80485758>] regmap_mmio_read+0x24/0x52
      [<ffffffff8047c526>] _regmap_bus_reg_read+0x1a/0x22
      [<ffffffff8047fe9a>] _regmap_read+0x5c/0xea
      [<ffffffff80480376>] _regmap_update_bits+0x76/0xc0
      ...
      ---[ end trace 0000000000000000 ]---
      As pointed by Samuel Holland it is incorrect to remove check of the stackframe
      entirely.
      
      Changes since v2 [2]:
       - Add accidentally forgotten curly brace
      
      Changes since v1 [1]:
       - Instead of just dropping frame->fp check, replace it with validation of
         frame->ra, which should be a stack address.
       - Move frame pointer validation into the separate function.
      
      [1] https://lore.kernel.org/linux-riscv/20240426072701.6463-1-dev.mbstr@gmail.com/
      [2] https://lore.kernel.org/linux-riscv/20240521131314.48895-1-dev.mbstr@gmail.com/
      
      Fixes: f766f77a
      
       ("riscv/stacktrace: Fix stack output without ra on the stack top")
      Signed-off-by: default avatarMatthew Bystrin <dev.mbstr@gmail.com>
      Reviewed-by: default avatarSamuel Holland <samuel.holland@sifive.com>
      Link: https://lore.kernel.org/r/20240521191727.62012-1-dev.mbstr@gmail.com
      Signed-off-by: default avatarPalmer Dabbelt <palmer@rivosinc.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      b8d78a75
    • Guo Ren's avatar
      riscv: stacktrace: Make walk_stackframe cross pt_regs frame · aae5f57c
      Guo Ren authored
      [ Upstream commit 7ecdadf7
      
       ]
      
      The current walk_stackframe with FRAME_POINTER would stop unwinding at
      ret_from_exception:
        BUG: sleeping function called from invalid context at kernel/locking/rwsem.c:1518
        in_atomic(): 0, irqs_disabled(): 1, non_block: 0, pid: 1, name: init
        CPU: 0 PID: 1 Comm: init Not tainted 5.10.113-00021-g15c15974895c-dirty #192
        Call Trace:
        [<ffffffe0002038c8>] walk_stackframe+0x0/0xee
        [<ffffffe000aecf48>] show_stack+0x32/0x4a
        [<ffffffe000af1618>] dump_stack_lvl+0x72/0x8e
        [<ffffffe000af1648>] dump_stack+0x14/0x1c
        [<ffffffe000239ad2>] ___might_sleep+0x12e/0x138
        [<ffffffe000239aec>] __might_sleep+0x10/0x18
        [<ffffffe000afe3fe>] down_read+0x22/0xa4
        [<ffffffe000207588>] do_page_fault+0xb0/0x2fe
        [<ffffffe000201b80>] ret_from_exception+0x0/0xc
      
      The optimization would help walk_stackframe cross the pt_regs frame and
      get more backtrace of debug info:
        BUG: sleeping function called from invalid context at kernel/locking/rwsem.c:1518
        in_atomic(): 0, irqs_disabled(): 1, non_block: 0, pid: 1, name: init
        CPU: 0 PID: 1 Comm: init Not tainted 5.10.113-00021-g15c15974895c-dirty #192
        Call Trace:
        [<ffffffe0002038c8>] walk_stackframe+0x0/0xee
        [<ffffffe000aecf48>] show_stack+0x32/0x4a
        [<ffffffe000af1618>] dump_stack_lvl+0x72/0x8e
        [<ffffffe000af1648>] dump_stack+0x14/0x1c
        [<ffffffe000239ad2>] ___might_sleep+0x12e/0x138
        [<ffffffe000239aec>] __might_sleep+0x10/0x18
        [<ffffffe000afe3fe>] down_read+0x22/0xa4
        [<ffffffe000207588>] do_page_fault+0xb0/0x2fe
        [<ffffffe000201b80>] ret_from_exception+0x0/0xc
        [<ffffffe000613c06>] riscv_intc_irq+0x1a/0x72
        [<ffffffe000201b80>] ret_from_exception+0x0/0xc
        [<ffffffe00033f44a>] vma_link+0x54/0x160
        [<ffffffe000341d7a>] mmap_region+0x2cc/0x4d0
        [<ffffffe000342256>] do_mmap+0x2d8/0x3ac
        [<ffffffe000326318>] vm_mmap_pgoff+0x70/0xb8
        [<ffffffe00032638a>] vm_mmap+0x2a/0x36
        [<ffffffe0003cfdde>] elf_map+0x72/0x84
        [<ffffffe0003d05f8>] load_elf_binary+0x69a/0xec8
        [<ffffffe000376240>] bprm_execve+0x246/0x53a
        [<ffffffe00037786c>] kernel_execve+0xe8/0x124
        [<ffffffe000aecdf2>] run_init_process+0xfa/0x10c
        [<ffffffe000aece16>] try_to_run_init_process+0x12/0x3c
        [<ffffffe000afa920>] kernel_init+0xb4/0xf8
        [<ffffffe000201b80>] ret_from_exception+0x0/0xc
      
      Here is the error injection test code for the above output:
       drivers/irqchip/irq-riscv-intc.c:
       static asmlinkage void riscv_intc_irq(struct pt_regs *regs)
       {
              unsigned long cause = regs->cause & ~CAUSE_IRQ_FLAG;
      +       u32 tmp; __get_user(tmp, (u32 *)0);
      
      Signed-off-by: default avatarGuo Ren <guoren@linux.alibaba.com>
      Signed-off-by: default avatarGuo Ren <guoren@kernel.org>
      Link: https://lore.kernel.org/r/20221109064937.3643993-3-guoren@kernel.org
      [Palmer: use SYM_CODE_*]
      Signed-off-by: default avatarPalmer Dabbelt <palmer@rivosinc.com>
      Stable-dep-of: a2a4d4a6
      
       ("riscv: stacktrace: fixed walk_stackframe()")
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      aae5f57c
    • Jiri Pirko's avatar
      virtio: delete vq in vp_find_vqs_msix() when request_irq() fails · 42d30da5
      Jiri Pirko authored
      [ Upstream commit 89875151 ]
      
      When request_irq() fails, error path calls vp_del_vqs(). There, as vq is
      present in the list, free_irq() is called for the same vector. That
      causes following splat:
      
      [    0.414355] Trying to free already-free IRQ 27
      [    0.414403] WARNING: CPU: 1 PID: 1 at kernel/irq/manage.c:1899 free_irq+0x1a1/0x2d0
      [    0.414510] Modules linked in:
      [    0.414540] CPU: 1 PID: 1 Comm: swapper/0 Not tainted 6.9.0-rc4+ #27
      [    0.414540] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.3-1.fc39 04/01/2014
      [    0.414540] RIP: 0010:free_irq+0x1a1/0x2d0
      [    0.414540] Code: 1e 00 48 83 c4 08 48 89 e8 5b 5d 41 5c 41 5d 41 5e 41 5f c3 cc cc cc cc 90 8b 74 24 04 48 c7 c7 98 80 6c b1 e8 00 c9 f7 ff 90 <0f> 0b 90 90 48 89 ee 4c 89 ef e8 e0 20 b8 00 49 8b 47 40 48 8b 40
      [    0.414540] RSP: 0000:ffffb71480013ae0 EFLAGS: 00010086
      [    0.414540] RAX: 0000000000000000 RBX: ffffa099c2722000 RCX: 0000000000000000
      [    0.414540] RDX: 0000000000000000 RSI: ffffb71480013998 RDI: 0000000000000001
      [    0.414540] RBP: 0000000000000246 R08: 00000000ffffdfff R09: 0000000000000001
      [    0.414540] R10: 00000000ffffdfff R11: ffffffffb18729c0 R12: ffffa099c1c91760
      [    0.414540] R13: ffffa099c1c916a4 R14: ffffa099c1d2f200 R15: ffffa099c1c91600
      [    0.414540] FS:  0000000000000000(0000) GS:ffffa099fec40000(0000) knlGS:0000000000000000
      [    0.414540] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      [    0.414540] CR2: 0000000000000000 CR3: 0000000008e3e001 CR4: 0000000000370ef0
      [    0.414540] Call Trace:
      [    0.414540]  <TASK>
      [    0.414540]  ? __warn+0x80/0x120
      [    0.414540]  ? free_irq+0x1a1/0x2d0
      [    0.414540]  ? report_bug+0x164/0x190
      [    0.414540]  ? handle_bug+0x3b/0x70
      [    0.414540]  ? exc_invalid_op+0x17/0x70
      [    0.414540]  ? asm_exc_invalid_op+0x1a/0x20
      [    0.414540]  ? free_irq+0x1a1/0x2d0
      [    0.414540]  vp_del_vqs+0xc1/0x220
      [    0.414540]  vp_find_vqs_msix+0x305/0x470
      [    0.414540]  vp_find_vqs+0x3e/0x1a0
      [    0.414540]  vp_modern_find_vqs+0x1b/0x70
      [    0.414540]  init_vqs+0x387/0x600
      [    0.414540]  virtnet_probe+0x50a/0xc80
      [    0.414540]  virtio_dev_probe+0x1e0/0x2b0
      [    0.414540]  really_probe+0xc0/0x2c0
      [    0.414540]  ? __pfx___driver_attach+0x10/0x10
      [    0.414540]  __driver_probe_device+0x73/0x120
      [    0.414540]  driver_probe_device+0x1f/0xe0
      [    0.414540]  __driver_attach+0x88/0x180
      [    0.414540]  bus_for_each_dev+0x85/0xd0
      [    0.414540]  bus_add_driver+0xec/0x1f0
      [    0.414540]  driver_register+0x59/0x100
      [    0.414540]  ? __pfx_virtio_net_driver_init+0x10/0x10
      [    0.414540]  virtio_net_driver_init+0x90/0xb0
      [    0.414540]  do_one_initcall+0x58/0x230
      [    0.414540]  kernel_init_freeable+0x1a3/0x2d0
      [    0.414540]  ? __pfx_kernel_init+0x10/0x10
      [    0.414540]  kernel_init+0x1a/0x1c0
      [    0.414540]  ret_from_fork+0x31/0x50
      [    0.414540]  ? __pfx_kernel_init+0x10/0x10
      [    0.414540]  ret_from_fork_asm+0x1a/0x30
      [    0.414540]  </TASK>
      
      Fix this by calling deleting the current vq when request_irq() fails.
      
      Fixes: 0b0f9dc5
      
       ("Revert "virtio_pci: use shared interrupts for virtqueues"")
      Signed-off-by: default avatarJiri Pirko <jiri@nvidia.com>
      Message-Id: <20240426150845.3999481-1-jiri@resnulli.us>
      Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      42d30da5
    • Jiangfeng Xiao's avatar
      arm64: asm-bug: Add .align 2 to the end of __BUG_ENTRY · c1929c04
      Jiangfeng Xiao authored
      [ Upstream commit ffbf4fb9 ]
      
      When CONFIG_DEBUG_BUGVERBOSE=n, we fail to add necessary padding bytes
      to bug_table entries, and as a result the last entry in a bug table will
      be ignored, potentially leading to an unexpected panic(). All prior
      entries in the table will be handled correctly.
      
      The arm64 ABI requires that struct fields of up to 8 bytes are
      naturally-aligned, with padding added within a struct such that struct
      are suitably aligned within arrays.
      
      When CONFIG_DEBUG_BUGVERPOSE=y, the layout of a bug_entry is:
      
      	struct bug_entry {
      		signed int      bug_addr_disp;	// 4 bytes
      		signed int      file_disp;	// 4 bytes
      		unsigned short  line;		// 2 bytes
      		unsigned short  flags;		// 2 bytes
      	}
      
      ... with 12 bytes total, requiring 4-byte alignment.
      
      When CONFIG_DEBUG_BUGVERBOSE=n, the layout of a bug_entry is:
      
      	struct bug_entry {
      		signed int      bug_addr_disp;	// 4 bytes
      		unsigned short  flags;		// 2 bytes
      		< implicit padding >		// 2 bytes
      	}
      
      ... with 8 bytes total, with 6 bytes of data and 2 bytes of trailing
      padding, requiring 4-byte alginment.
      
      When we create a bug_entry in assembly, we align the start of the entry
      to 4 bytes, which implicitly handles padding for any prior entries.
      However, we do not align the end of the entry, and so when
      CONFIG_DEBUG_BUGVERBOSE=n, the final entry lacks the trailing padding
      bytes.
      
      For the main kernel image this is not a problem as find_bug() doesn't
      depend on the trailing padding bytes when searching for entries:
      
      	for (bug = __start___bug_table; bug < __stop___bug_table; ++bug)
      		if (bugaddr == bug_addr(bug))
      			return bug;
      
      However for modules, module_bug_finalize() depends on the trailing
      bytes when calculating the number of entries:
      
      	mod->num_bugs = sechdrs[i].sh_size / sizeof(struct bug_entry);
      
      ... and as the last bug_entry lacks the necessary padding bytes, this entry
      will not be counted, e.g. in the case of a single entry:
      
      	sechdrs[i].sh_size == 6
      	sizeof(struct bug_entry) == 8;
      
      	sechdrs[i].sh_size / sizeof(struct bug_entry) == 0;
      
      Consequently module_find_bug() will miss the last bug_entry when it does:
      
      	for (i = 0; i < mod->num_bugs; ++i, ++bug)
      		if (bugaddr == bug_addr(bug))
      			goto out;
      
      ... which can lead to a kenrel panic due to an unhandled bug.
      
      This can be demonstrated with the following module:
      
      	static int __init buginit(void)
      	{
      		WARN(1, "hello\n");
      		return 0;
      	}
      
      	static void __exit bugexit(void)
      	{
      	}
      
      	module_init(buginit);
      	module_exit(bugexit);
      	MODULE_LICENSE("GPL");
      
      ... which will trigger a kernel panic when loaded:
      
      	------------[ cut here ]------------
      	hello
      	Unexpected kernel BRK exception at EL1
      	Internal error: BRK handler: 00000000f2000800 [#1] PREEMPT SMP
      	Modules linked in: hello(O+)
      	CPU: 0 PID: 50 Comm: insmod Tainted: G           O       6.9.1 #8
      	Hardware name: linux,dummy-virt (DT)
      	pstate: 60400005 (nZCv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--)
      	pc : buginit+0x18/0x1000 [hello]
      	lr : buginit+0x18/0x1000 [hello]
      	sp : ffff800080533ae0
      	x29: ffff800080533ae0 x28: 0000000000000000 x27: 0000000000000000
      	x26: ffffaba8c4e70510 x25: ffff800080533c30 x24: ffffaba8c4a28a58
      	x23: 0000000000000000 x22: 0000000000000000 x21: ffff3947c0eab3c0
      	x20: ffffaba8c4e3f000 x19: ffffaba846464000 x18: 0000000000000006
      	x17: 0000000000000000 x16: ffffaba8c2492834 x15: 0720072007200720
      	x14: 0720072007200720 x13: ffffaba8c49b27c8 x12: 0000000000000312
      	x11: 0000000000000106 x10: ffffaba8c4a0a7c8 x9 : ffffaba8c49b27c8
      	x8 : 00000000ffffefff x7 : ffffaba8c4a0a7c8 x6 : 80000000fffff000
      	x5 : 0000000000000107 x4 : 0000000000000000 x3 : 0000000000000000
      	x2 : 0000000000000000 x1 : 0000000000000000 x0 : ffff3947c0eab3c0
      	Call trace:
      	 buginit+0x18/0x1000 [hello]
      	 do_one_initcall+0x80/0x1c8
      	 do_init_module+0x60/0x218
      	 load_module+0x1ba4/0x1d70
      	 __do_sys_init_module+0x198/0x1d0
      	 __arm64_sys_init_module+0x1c/0x28
      	 invoke_syscall+0x48/0x114
      	 el0_svc_common.constprop.0+0x40/0xe0
      	 do_el0_svc+0x1c/0x28
      	 el0_svc+0x34/0xd8
      	 el0t_64_sync_handler+0x120/0x12c
      	 el0t_64_sync+0x190/0x194
      	Code: d0ffffe0 910003fd 91000000 9400000b (d4210000)
      	---[ end trace 0000000000000000 ]---
      	Kernel panic - not syncing: BRK handler: Fatal exception
      
      Fix this by always aligning the end of a bug_entry to 4 bytes, which is
      correct regardless of CONFIG_DEBUG_BUGVERBOSE.
      
      Fixes: 9fb7410f
      
       ("arm64/BUG: Use BRK instruction for generic BUG traps")
      
      Signed-off-by: default avatarYuanbin Xie <xieyuanbin1@huawei.com>
      Signed-off-by: default avatarJiangfeng Xiao <xiaojiangfeng@huawei.com>
      Reviewed-by: default avatarMark Rutland <mark.rutland@arm.com>
      Link: https://lore.kernel.org/r/1716212077-43826-1-git-send-email-xiaojiangfeng@huawei.com
      Signed-off-by: default avatarWill Deacon <will@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      c1929c04
    • Aaron Conole's avatar
      openvswitch: Set the skbuff pkt_type for proper pmtud support. · 6eec23fa
      Aaron Conole authored
      [ Upstream commit 30a92c9e
      
       ]
      
      Open vSwitch is originally intended to switch at layer 2, only dealing with
      Ethernet frames.  With the introduction of l3 tunnels support, it crossed
      into the realm of needing to care a bit about some routing details when
      making forwarding decisions.  If an oversized packet would need to be
      fragmented during this forwarding decision, there is a chance for pmtu
      to get involved and generate a routing exception.  This is gated by the
      skbuff->pkt_type field.
      
      When a flow is already loaded into the openvswitch module this field is
      set up and transitioned properly as a packet moves from one port to
      another.  In the case that a packet execute is invoked after a flow is
      newly installed this field is not properly initialized.  This causes the
      pmtud mechanism to omit sending the required exception messages across
      the tunnel boundary and a second attempt needs to be made to make sure
      that the routing exception is properly setup.  To fix this, we set the
      outgoing packet's pkt_type to PACKET_OUTGOING, since it can only get
      to the openvswitch module via a port device or packet command.
      
      Even for bridge ports as users, the pkt_type needs to be reset when
      doing the transmit as the packet is truly outgoing and routing needs
      to get involved post packet transformations, in the case of
      VXLAN/GENEVE/udp-tunnel packets.  In general, the pkt_type on output
      gets ignored, since we go straight to the driver, but in the case of
      tunnel ports they go through IP routing layer.
      
      This issue is periodically encountered in complex setups, such as large
      openshift deployments, where multiple sets of tunnel traversal occurs.
      A way to recreate this is with the ovn-heater project that can setup
      a networking environment which mimics such large deployments.  We need
      larger environments for this because we need to ensure that flow
      misses occur.  In these environment, without this patch, we can see:
      
        ./ovn_cluster.sh start
        podman exec ovn-chassis-1 ip r a 170.168.0.5/32 dev eth1 mtu 1200
        podman exec ovn-chassis-1 ip netns exec sw01p1 ip r flush cache
        podman exec ovn-chassis-1 ip netns exec sw01p1 \
               ping 21.0.0.3 -M do -s 1300 -c2
        PING 21.0.0.3 (21.0.0.3) 1300(1328) bytes of data.
        From 21.0.0.3 icmp_seq=2 Frag needed and DF set (mtu = 1142)
      
        --- 21.0.0.3 ping statistics ---
        ...
      
      Using tcpdump, we can also see the expected ICMP FRAG_NEEDED message is not
      sent into the server.
      
      With this patch, setting the pkt_type, we see the following:
      
        podman exec ovn-chassis-1 ip netns exec sw01p1 \
               ping 21.0.0.3 -M do -s 1300 -c2
        PING 21.0.0.3 (21.0.0.3) 1300(1328) bytes of data.
        From 21.0.0.3 icmp_seq=1 Frag needed and DF set (mtu = 1222)
        ping: local error: message too long, mtu=1222
      
        --- 21.0.0.3 ping statistics ---
        ...
      
      In this case, the first ping request receives the FRAG_NEEDED message and
      a local routing exception is created.
      
      Tested-by: default avatarJaime Caamano <jcaamano@redhat.com>
      Reported-at: https://issues.redhat.com/browse/FDP-164
      Fixes: 58264848
      
       ("openvswitch: Add vxlan tunneling support.")
      Signed-off-by: default avatarAaron Conole <aconole@redhat.com>
      Acked-by: default avatarEelco Chaudron <echaudro@redhat.com>
      Link: https://lore.kernel.org/r/20240516200941.16152-1-aconole@redhat.com
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      6eec23fa
    • Kuniyuki Iwashima's avatar
      tcp: Fix shift-out-of-bounds in dctcp_update_alpha(). · 86021502
      Kuniyuki Iwashima authored
      [ Upstream commit 3ebc46ca
      
       ]
      
      In dctcp_update_alpha(), we use a module parameter dctcp_shift_g
      as follows:
      
        alpha -= min_not_zero(alpha, alpha >> dctcp_shift_g);
        ...
        delivered_ce <<= (10 - dctcp_shift_g);
      
      It seems syzkaller started fuzzing module parameters and triggered
      shift-out-of-bounds [0] by setting 100 to dctcp_shift_g:
      
        memcpy((void*)0x20000080,
               "/sys/module/tcp_dctcp/parameters/dctcp_shift_g\000", 47);
        res = syscall(__NR_openat, /*fd=*/0xffffffffffffff9cul, /*file=*/0x20000080ul,
                      /*flags=*/2ul, /*mode=*/0ul);
        memcpy((void*)0x20000000, "100\000", 4);
        syscall(__NR_write, /*fd=*/r[0], /*val=*/0x20000000ul, /*len=*/4ul);
      
      Let's limit the max value of dctcp_shift_g by param_set_uint_minmax().
      
      With this patch:
      
        # echo 10 > /sys/module/tcp_dctcp/parameters/dctcp_shift_g
        # cat /sys/module/tcp_dctcp/parameters/dctcp_shift_g
        10
        # echo 11 > /sys/module/tcp_dctcp/parameters/dctcp_shift_g
        -bash: echo: write error: Invalid argument
      
      [0]:
      UBSAN: shift-out-of-bounds in net/ipv4/tcp_dctcp.c:143:12
      shift exponent 100 is too large for 32-bit type 'u32' (aka 'unsigned int')
      CPU: 0 PID: 8083 Comm: syz-executor345 Not tainted 6.9.0-05151-g1b294a1f3561 #2
      Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS
      1.13.0-1ubuntu1.1 04/01/2014
      Call Trace:
       <TASK>
       __dump_stack lib/dump_stack.c:88 [inline]
       dump_stack_lvl+0x201/0x300 lib/dump_stack.c:114
       ubsan_epilogue lib/ubsan.c:231 [inline]
       __ubsan_handle_shift_out_of_bounds+0x346/0x3a0 lib/ubsan.c:468
       dctcp_update_alpha+0x540/0x570 net/ipv4/tcp_dctcp.c:143
       tcp_in_ack_event net/ipv4/tcp_input.c:3802 [inline]
       tcp_ack+0x17b1/0x3bc0 net/ipv4/tcp_input.c:3948
       tcp_rcv_state_process+0x57a/0x2290 net/ipv4/tcp_input.c:6711
       tcp_v4_do_rcv+0x764/0xc40 net/ipv4/tcp_ipv4.c:1937
       sk_backlog_rcv include/net/sock.h:1106 [inline]
       __release_sock+0x20f/0x350 net/core/sock.c:2983
       release_sock+0x61/0x1f0 net/core/sock.c:3549
       mptcp_subflow_shutdown+0x3d0/0x620 net/mptcp/protocol.c:2907
       mptcp_check_send_data_fin+0x225/0x410 net/mptcp/protocol.c:2976
       __mptcp_close+0x238/0xad0 net/mptcp/protocol.c:3072
       mptcp_close+0x2a/0x1a0 net/mptcp/protocol.c:3127
       inet_release+0x190/0x1f0 net/ipv4/af_inet.c:437
       __sock_release net/socket.c:659 [inline]
       sock_close+0xc0/0x240 net/socket.c:1421
       __fput+0x41b/0x890 fs/file_table.c:422
       task_work_run+0x23b/0x300 kernel/task_work.c:180
       exit_task_work include/linux/task_work.h:38 [inline]
       do_exit+0x9c8/0x2540 kernel/exit.c:878
       do_group_exit+0x201/0x2b0 kernel/exit.c:1027
       __do_sys_exit_group kernel/exit.c:1038 [inline]
       __se_sys_exit_group kernel/exit.c:1036 [inline]
       __x64_sys_exit_group+0x3f/0x40 kernel/exit.c:1036
       do_syscall_x64 arch/x86/entry/common.c:52 [inline]
       do_syscall_64+0xe4/0x240 arch/x86/entry/common.c:83
       entry_SYSCALL_64_after_hwframe+0x67/0x6f
      RIP: 0033:0x7f6c2b5005b6
      Code: Unable to access opcode bytes at 0x7f6c2b50058c.
      RSP: 002b:00007ffe883eb948 EFLAGS: 00000246 ORIG_RAX: 00000000000000e7
      RAX: ffffffffffffffda RBX: 00007f6c2b5862f0 RCX: 00007f6c2b5005b6
      RDX: 0000000000000001 RSI: 000000000000003c RDI: 0000000000000001
      RBP: 0000000000000001 R08: 00000000000000e7 R09: ffffffffffffffc0
      R10: 0000000000000006 R11: 0000000000000246 R12: 00007f6c2b5862f0
      R13: 0000000000000001 R14: 0000000000000000 R15: 0000000000000001
       </TASK>
      
      Reported-by: default avatarsyzkaller <syzkaller@googlegroups.com>
      Reported-by: default avatarYue Sun <samsun1006219@gmail.com>
      Reported-by: default avatarxingwei lee <xrivendell7@gmail.com>
      Closes: https://lore.kernel.org/netdev/CAEkJfYNJM=cw-8x7_Vmj1J6uYVCWMbbvD=EFmDPVBGpTsqOxEA@mail.gmail.com/
      Fixes: e3118e83
      
       ("net: tcp: add DCTCP congestion control algorithm")
      Signed-off-by: default avatarKuniyuki Iwashima <kuniyu@amazon.com>
      Reviewed-by: default avatarSimon Horman <horms@kernel.org>
      Link: https://lore.kernel.org/r/20240517091626.32772-1-kuniyu@amazon.com
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      86021502
    • Hangbin Liu's avatar
      ipv6: sr: fix memleak in seg6_hmac_init_algo · 61d31ac8
      Hangbin Liu authored
      [ Upstream commit efb9f4f1 ]
      
      seg6_hmac_init_algo returns without cleaning up the previous allocations
      if one fails, so it's going to leak all that memory and the crypto tfms.
      
      Update seg6_hmac_exit to only free the memory when allocated, so we can
      reuse the code directly.
      
      Fixes: bf355b8d
      
       ("ipv6: sr: add core files for SR HMAC support")
      Reported-by: default avatarSabrina Dubroca <sd@queasysnail.net>
      Closes: https://lore.kernel.org/netdev/Zj3bh-gE7eT6V6aH@hog/
      Signed-off-by: default avatarHangbin Liu <liuhangbin@gmail.com>
      Reviewed-by: default avatarSimon Horman <horms@kernel.org>
      Reviewed-by: default avatarSabrina Dubroca <sd@queasysnail.net>
      Link: https://lore.kernel.org/r/20240517005435.2600277-1-liuhangbin@gmail.com
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      61d31ac8
    • Kuniyuki Iwashima's avatar
      af_unix: Update unix_sk(sk)->oob_skb under sk_receive_queue lock. · 518a994a
      Kuniyuki Iwashima authored
      [ Upstream commit 9841991a ]
      
      Billy Jheng Bing-Jhong reported a race between __unix_gc() and
      queue_oob().
      
      __unix_gc() tries to garbage-collect close()d inflight sockets,
      and then if the socket has MSG_OOB in unix_sk(sk)->oob_skb, GC
      will drop the reference and set NULL to it locklessly.
      
      However, the peer socket still can send MSG_OOB message and
      queue_oob() can update unix_sk(sk)->oob_skb concurrently, leading
      NULL pointer dereference. [0]
      
      To fix the issue, let's update unix_sk(sk)->oob_skb under the
      sk_receive_queue's lock and take it everywhere we touch oob_skb.
      
      Note that we defer kfree_skb() in manage_oob() to silence lockdep
      false-positive (See [1]).
      
      [0]:
      BUG: kernel NULL pointer dereference, address: 0000000000000008
       PF: supervisor write access in kernel mode
       PF: error_code(0x0002) - not-present page
      PGD 8000000009f5e067 P4D 8000000009f5e067 PUD 9f5d067 PMD 0
      Oops: 0002 [#1] PREEMPT SMP PTI
      CPU: 3 PID: 50 Comm: kworker/3:1 Not tainted 6.9.0-rc5-00191-gd091e579b864 #110
      Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.0-0-gd239552ce722-prebuilt.qemu.org 04/01/2014
      Workqueue: events delayed_fput
      RIP: 0010:skb_dequeue (./include/linux/skbuff.h:2386 ./include/linux/skbuff.h:2402 net/core/skbuff.c:3847)
      Code: 39 e3 74 3e 8b 43 10 48 89 ef 83 e8 01 89 43 10 49 8b 44 24 08 49 c7 44 24 08 00 00 00 00 49 8b 14 24 49 c7 04 24 00 00 00 00 <48> 89 42 08 48 89 10 e8 e7 c5 42 00 4c 89 e0 5b 5d 41 5c c3 cc cc
      RSP: 0018:ffffc900001bfd48 EFLAGS: 00000002
      RAX: 0000000000000000 RBX: ffff8880088f5ae8 RCX: 00000000361289f9
      RDX: 0000000000000000 RSI: 0000000000000206 RDI: ffff8880088f5b00
      RBP: ffff8880088f5b00 R08: 0000000000080000 R09: 0000000000000001
      R10: 0000000000000003 R11: 0000000000000001 R12: ffff8880056b6a00
      R13: ffff8880088f5280 R14: 0000000000000001 R15: ffff8880088f5a80
      FS:  0000000000000000(0000) GS:ffff88807dd80000(0000) knlGS:0000000000000000
      CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      CR2: 0000000000000008 CR3: 0000000006314000 CR4: 00000000007506f0
      PKRU: 55555554
      Call Trace:
       <TASK>
       unix_release_sock (net/unix/af_unix.c:654)
       unix_release (net/unix/af_unix.c:1050)
       __sock_release (net/socket.c:660)
       sock_close (net/socket.c:1423)
       __fput (fs/file_table.c:423)
       delayed_fput (fs/file_table.c:444 (discriminator 3))
       process_one_work (kernel/workqueue.c:3259)
       worker_thread (kernel/workqueue.c:3329 kernel/workqueue.c:3416)
       kthread (kernel/kthread.c:388)
       ret_from_fork (arch/x86/kernel/process.c:153)
       ret_from_fork_asm (arch/x86/entry/entry_64.S:257)
       </TASK>
      Modules linked in:
      CR2: 0000000000000008
      
      Link: https://lore.kernel.org/netdev/a00d3993-c461-43f2-be6d-07259c98509a@rbox.co/ [1]
      Fixes: 1279f9d9
      
       ("af_unix: Call kfree_skb() for dead unix_(sk)->oob_skb in GC.")
      Reported-by: default avatarBilly Jheng Bing-Jhong <billy@starlabs.sg>
      Signed-off-by: default avatarKuniyuki Iwashima <kuniyu@amazon.com>
      Link: https://lore.kernel.org/r/20240516134835.8332-1-kuniyu@amazon.com
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      518a994a
    • Dan Aloni's avatar
      rpcrdma: fix handling for RDMA_CM_EVENT_DEVICE_REMOVAL · 39818fbd
      Dan Aloni authored
      [ Upstream commit 4836da21 ]
      
      Under the scenario of IB device bonding, when bringing down one of the
      ports, or all ports, we saw xprtrdma entering a non-recoverable state
      where it is not even possible to complete the disconnect and shut it
      down the mount, requiring a reboot. Following debug, we saw that
      transport connect never ended after receiving the
      RDMA_CM_EVENT_DEVICE_REMOVAL callback.
      
      The DEVICE_REMOVAL callback is irrespective of whether the CM_ID is
      connected, and ESTABLISHED may not have happened. So need to work with
      each of these states accordingly.
      
      Fixes: 2acc5cae
      
       ('xprtrdma: Prevent dereferencing r_xprt->rx_ep after it is freed')
      Cc: Sagi Grimberg <sagi.grimberg@vastdata.com>
      Signed-off-by: default avatarDan Aloni <dan.aloni@vastdata.com>
      Reviewed-by: default avatarSagi Grimberg <sagi@grimberg.me>
      Reviewed-by: default avatarChuck Lever <chuck.lever@oracle.com>
      Signed-off-by: default avatarTrond Myklebust <trond.myklebust@hammerspace.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      39818fbd
    • Dan Aloni's avatar
      sunrpc: fix NFSACL RPC retry on soft mount · e5c34f10
      Dan Aloni authored
      [ Upstream commit 0dc9f430 ]
      
      It used to be quite awhile ago since 1b63a751 ('SUNRPC: Refactor
      rpc_clone_client()'), in 2012, that `cl_timeout` was copied in so that
      all mount parameters propagate to NFSACL clients. However since that
      change, if mount options as follows are given:
      
          soft,timeo=50,retrans=16,vers=3
      
      The resultant NFSACL client receives:
      
          cl_softrtry: 1
          cl_timeout: to_initval=60000, to_maxval=60000, to_increment=0, to_retries=2, to_exponential=0
      
      These values lead to NFSACL operations not being retried under the
      condition of transient network outages with soft mount. Instead, getacl
      call fails after 60 seconds with EIO.
      
      The simple fix is to pass the existing client's `cl_timeout` as the new
      client timeout.
      
      Cc: Chuck Lever <chuck.lever@oracle.com>
      Cc: Benjamin Coddington <bcodding@redhat.com>
      Link: https://lore.kernel.org/all/20231105154857.ryakhmgaptq3hb6b@gmail.com/T/
      Fixes: 1b63a751
      
       ('SUNRPC: Refactor rpc_clone_client()')
      Signed-off-by: default avatarDan Aloni <dan.aloni@vastdata.com>
      Reviewed-by: default avatarBenjamin Coddington <bcodding@redhat.com>
      Signed-off-by: default avatarTrond Myklebust <trond.myklebust@hammerspace.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      e5c34f10
    • Benjamin Coddington's avatar
      NFSv4: Fixup smatch warning for ambiguous return · 61ceeebb
      Benjamin Coddington authored
      [ Upstream commit 37ffe065
      
       ]
      
      Dan Carpenter reports smatch warning for nfs4_try_migration() when a memory
      allocation failure results in a zero return value.  In this case, a
      transient allocation failure error will likely be retried the next time the
      server responds with NFS4ERR_MOVED.
      
      We can fixup the smatch warning with a small refactor: attempt all three
      allocations before testing and returning on a failure.
      
      Reported-by: default avatarDan Carpenter <dan.carpenter@linaro.org>
      Fixes: c3ed2227
      
       ("NFSv4: Fix free of uninitialized nfs4_label on referral lookup.")
      Signed-off-by: default avatarBenjamin Coddington <bcodding@redhat.com>
      Reviewed-by: default avatarDan Carpenter <dan.carpenter@linaro.org>
      Reviewed-by: default avatarChuck Lever <chuck.lever@oracle.com>
      Signed-off-by: default avatarTrond Myklebust <trond.myklebust@hammerspace.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      61ceeebb
    • Shenghao Ding's avatar
      ASoC: tas2552: Add TX path for capturing AUDIO-OUT data · 1c03ea9a
      Shenghao Ding authored
      [ Upstream commit 7078ac4f ]
      
      TAS2552 is a Smartamp with I/V sense data, add TX path
      to support capturing I/V data.
      
      Fixes: 38803ce7
      
       ("ASoC: codecs: tas*: merge .digital_mute() into .mute_stream()")
      Signed-off-by: default avatarShenghao Ding <shenghao-ding@ti.com>
      Link: https://msgid.link/r/20240518033515.866-1-shenghao-ding@ti.com
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      1c03ea9a
    • Ryosuke Yasuoka's avatar
      nfc: nci: Fix uninit-value in nci_rx_work · ad4d196d
      Ryosuke Yasuoka authored
      [ Upstream commit e4a87abf ]
      
      syzbot reported the following uninit-value access issue [1]
      
      nci_rx_work() parses received packet from ndev->rx_q. It should be
      validated header size, payload size and total packet size before
      processing the packet. If an invalid packet is detected, it should be
      silently discarded.
      
      Fixes: d24b0353
      
       ("nfc: nci: Fix uninit-value in nci_dev_up and nci_ntf_packet")
      Reported-and-tested-by: default avatar <syzbot+d7b4dc6cd50410152534@syzkaller.appspotmail.com>
      Closes: https://syzkaller.appspot.com/bug?extid=d7b4dc6cd50410152534 [1]
      Signed-off-by: default avatarRyosuke Yasuoka <ryasuoka@redhat.com>
      Reviewed-by: default avatarKrzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      ad4d196d
    • Andrea Mayer's avatar
      ipv6: sr: fix missing sk_buff release in seg6_input_core · e8688218
      Andrea Mayer authored
      [ Upstream commit 5447f970 ]
      
      The seg6_input() function is responsible for adding the SRH into a
      packet, delegating the operation to the seg6_input_core(). This function
      uses the skb_cow_head() to ensure that there is sufficient headroom in
      the sk_buff for accommodating the link-layer header.
      In the event that the skb_cow_header() function fails, the
      seg6_input_core() catches the error but it does not release the sk_buff,
      which will result in a memory leak.
      
      This issue was introduced in commit af3b5158 ("ipv6: sr: fix BUG due
      to headroom too small after SRH push") and persists even after commit
      7a3f5b0d ("netfilter: add netfilter hooks to SRv6 data plane"),
      where the entire seg6_input() code was refactored to deal with netfilter
      hooks.
      
      The proposed patch addresses the identified memory leak by requiring the
      seg6_input_core() function to release the sk_buff in the event that
      skb_cow_head() fails.
      
      Fixes: af3b5158
      
       ("ipv6: sr: fix BUG due to headroom too small after SRH push")
      Signed-off-by: default avatarAndrea Mayer <andrea.mayer@uniroma2.it>
      Reviewed-by: default avatarSimon Horman <horms@kernel.org>
      Reviewed-by: default avatarDavid Ahern <dsahern@kernel.org>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      e8688218
    • Florian Fainelli's avatar
      net: Always descend into dsa/ folder with CONFIG_NET_DSA enabled · c707bf57
      Florian Fainelli authored
      [ Upstream commit b1fa60ec ]
      
      Stephen reported that he was unable to get the dsa_loop driver to get
      probed, and the reason ended up being because he had CONFIG_FIXED_PHY=y
      in his kernel configuration. As Masahiro explained it:
      
        "obj-m += dsa/" means everything under dsa/ must be modular.
      
        If there is a built-in object under dsa/ with CONFIG_NET_DSA=m,
        you cannot do  "obj-$(CONFIG_NET_DSA) += dsa/".
      
        You need to change it back to "obj-y += dsa/".
      
      This was the case here whereby CONFIG_NET_DSA=m, and so the
      obj-$(CONFIG_FIXED_PHY) += dsa_loop_bdinfo.o rule is not executed and
      the DSA loop mdio_board info structure is not registered with the
      kernel, and eventually the device is simply not found.
      
      To preserve the intention of the original commit of limiting the amount
      of folder descending, conditionally descend into drivers/net/dsa when
      CONFIG_NET_DSA is enabled.
      
      Fixes: 227d7206
      
       ("dsa: simplify Kconfig symbols and dependencies")
      Reported-by: default avatarStephen Langstaff <stephenlangstaff1@gmail.com>
      Signed-off-by: default avatarFlorian Fainelli <florian.fainelli@broadcom.com>
      Reviewed-by: default avatarVladimir Oltean <olteanv@gmail.com>
      Reviewed-by: default avatarAlexander Lobakin <aleksander.lobakin@intel.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      c707bf57
    • Masahiro Yamada's avatar
      x86/kconfig: Select ARCH_WANT_FRAME_POINTERS again when UNWINDER_FRAME_POINTER=y · 42952002
      Masahiro Yamada authored
      [ Upstream commit 66ee3636 ]
      
      It took me some time to understand the purpose of the tricky code at
      the end of arch/x86/Kconfig.debug.
      
      Without it, the following would be shown:
      
        WARNING: unmet direct dependencies detected for FRAME_POINTER
      
      because
      
        81d38719 ("x86/kconfig: Consolidate unwinders into multiple choice selection")
      
      removed 'select ARCH_WANT_FRAME_POINTERS'.
      
      The correct and more straightforward approach should have been to move
      it where 'select FRAME_POINTER' is located.
      
      Several architectures properly handle the conditional selection of
      ARCH_WANT_FRAME_POINTERS. For example, 'config UNWINDER_FRAME_POINTER'
      in arch/arm/Kconfig.debug.
      
      Fixes: 81d38719
      
       ("x86/kconfig: Consolidate unwinders into multiple choice selection")
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      Signed-off-by: default avatarBorislav Petkov (AMD) <bp@alien8.de>
      Acked-by: default avatarJosh Poimboeuf <jpoimboe@kernel.org>
      Link: https://lore.kernel.org/r/20240204122003.53795-1-masahiroy@kernel.org
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      42952002
    • Matti Vaittinen's avatar
      regulator: bd71828: Don't overwrite runtime voltages · dab0d7e6
      Matti Vaittinen authored
      [ Upstream commit 0f9f7c63
      
       ]
      
      Some of the regulators on the BD71828 have common voltage setting for
      RUN/SUSPEND/IDLE/LPSR states. The enable control can be set for each
      state though.
      
      The driver allows setting the voltage values for these states via
      device-tree. As a side effect, setting the voltages for
      SUSPEND/IDLE/LPSR will also change the RUN level voltage which is not
      desired and can break the system.
      
      The comment in code reflects this behaviour, but it is likely to not
      make people any happier. The right thing to do is to allow setting the
      enable/disable state at SUSPEND/IDLE/LPSR via device-tree, but to
      disallow setting state specific voltages for those regulators.
      
      BUCK1 is a bit different. It only shares the SUSPEND and LPSR state
      voltages. The former behaviour of allowing to silently overwrite the
      SUSPEND state voltage by LPSR state voltage is also changed here so that
      the SUSPEND voltage is prioritized over LPSR voltage.
      
      Prevent setting PMIC state specific voltages for regulators which do not
      support it.
      
      Signed-off-by: default avatarMatti Vaittinen <mazziesaccount@gmail.com>
      Fixes: 522498f8
      
       ("regulator: bd71828: Basic support for ROHM bd71828 PMIC regulators")
      Link: https://msgid.link/r/e1883ae1e3ae5668f1030455d4750923561f3d68.1715848512.git.mazziesaccount@gmail.com
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      dab0d7e6
    • Hsin-Te Yuan's avatar
      ASoC: mediatek: mt8192: fix register configuration for tdm · fde10aab
      Hsin-Te Yuan authored
      [ Upstream commit a85ed162 ]
      
      For DSP_A, data is a BCK cycle behind LRCK trigger edge. For DSP_B, this
      delay doesn't exist. Fix the delay configuration to match the standard.
      
      Fixes: 52fcd654
      
       ("ASoC: mediatek: mt8192: support tdm in platform driver")
      Signed-off-by: default avatarHsin-Te Yuan <yuanhsinte@chromium.org>
      Reviewed-by: default avatarAngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
      Reviewed-by: default avatarChen-Yu Tsai <wenst@chromium.org>
      Link: https://lore.kernel.org/r/20240509-8192-tdm-v1-1-530b54645763@chromium.org
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      fde10aab
    • Zhu Yanjun's avatar
      null_blk: Fix the WARNING: modpost: missing MODULE_DESCRIPTION() · 4bb60a0e
      Zhu Yanjun authored
      [ Upstream commit 9e6727f8 ]
      
      No functional changes intended.
      
      Fixes: f2298c04
      
       ("null_blk: multi queue aware block test driver")
      Signed-off-by: default avatarZhu Yanjun <yanjun.zhu@linux.dev>
      Reviewed-by: default avatarChaitanya Kulkarni <kch@nvidia.com>
      Link: https://lore.kernel.org/r/20240506075538.6064-1-yanjun.zhu@linux.dev
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      4bb60a0e
    • Hans Verkuil's avatar
      media: cec: core: avoid confusing "transmit timed out" message · f86a3b7c
      Hans Verkuil authored
      [ Upstream commit cbe49997
      
       ]
      
      If, when waiting for a transmit to finish, the wait is interrupted,
      then you might get a "transmit timed out" message, even though the
      transmit was interrupted and did not actually time out.
      
      Set transmit_in_progress_aborted to true if the
      wait_for_completion_killable() call was interrupted and ensure
      that the transmit is properly marked as ABORTED.
      
      Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
      Reported-by: default avatarYang, Chenyuan <cy54@illinois.edu>
      Closes: https://lore.kernel.org/linux-media/PH7PR11MB57688E64ADE4FE82E658D86DA09EA@PH7PR11MB5768.namprd11.prod.outlook.com/
      Fixes: 590a8e56
      
       ("media: cec: abort if the current transmit was canceled")
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      f86a3b7c
    • Hans Verkuil's avatar
      media: cec: core: avoid recursive cec_claim_log_addrs · b5da8217
      Hans Verkuil authored
      [ Upstream commit 47c82aac
      
       ]
      
      Keep track if cec_claim_log_addrs() is running, and return -EBUSY
      if it is when calling CEC_ADAP_S_LOG_ADDRS.
      
      This prevents a case where cec_claim_log_addrs() could be called
      while it was still in progress.
      
      Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
      Reported-by: default avatarYang, Chenyuan <cy54@illinois.edu>
      Closes: https://lore.kernel.org/linux-media/PH7PR11MB57688E64ADE4FE82E658D86DA09EA@PH7PR11MB5768.namprd11.prod.outlook.com/
      Fixes: ca684386
      
       ("[media] cec: add HDMI CEC framework (api)")
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      b5da8217
    • Hans Verkuil's avatar
      media: cec-adap.c: drop activate_cnt, use state info instead · 1e2dbdf6
      Hans Verkuil authored
      [ Upstream commit f9222f8c
      
       ]
      
      Using an activation counter to decide when the enable or disable the
      cec adapter is not the best approach and can lead to race conditions.
      
      Change this to determining the current status of the adapter, and
      enable or disable the adapter accordingly.
      
      It now only needs to be called whenever there is a chance that the
      state changes, and it can handle enabling/disabling monitoring as
      well if needed.
      
      This simplifies the code and it should be a more robust approach as well.
      
      Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@kernel.org>
      Stable-dep-of: 47c82aac
      
       ("media: cec: core: avoid recursive cec_claim_log_addrs")
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      1e2dbdf6
    • Hans Verkuil's avatar
      media: cec: use call_op and check for !unregistered · 1d1d76a6
      Hans Verkuil authored
      [ Upstream commit e2ed5024
      
       ]
      
      Use call_(void_)op consistently in the CEC core framework. Ditto
      for the cec pin ops. And check if !adap->devnode.unregistered before
      calling each op. This avoids calls to ops when the device has been
      unregistered and the underlying hardware may be gone.
      
      Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@kernel.org>
      Stable-dep-of: 47c82aac
      
       ("media: cec: core: avoid recursive cec_claim_log_addrs")
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      1d1d76a6
    • Hans Verkuil's avatar
      media: cec: correctly pass on reply results · 54e5e151
      Hans Verkuil authored
      [ Upstream commit f9d0ecbf
      
       ]
      
      The results of non-blocking transmits were not correctly communicated
      to userspace.
      
      Specifically:
      
      1) if a non-blocking transmit was canceled, then rx_status wasn't set to 0
         as it should.
      2) if the non-blocking transmit succeeded, but the corresponding reply
         never arrived (aborted or timed out), then tx_status wasn't set to 0
         as it should, and rx_status was hardcoded to ABORTED instead of the
         actual reason, such as TIMEOUT. In addition, adap->ops->received() was
         never called, so drivers that want to do message processing themselves
         would not be informed of the failed reply.
      
      Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@kernel.org>
      Stable-dep-of: 47c82aac
      
       ("media: cec: core: avoid recursive cec_claim_log_addrs")
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      54e5e151