Skip to content
  1. May 18, 2022
    • Duoming Zhou's avatar
      RDMA/irdma: Fix deadlock in irdma_cleanup_cm_core() · 2f6b75c0
      Duoming Zhou authored
      [ Upstream commit 679ab61b ]
      
      There is a deadlock in irdma_cleanup_cm_core(), which is shown below:
      
         (Thread 1)              |      (Thread 2)
                                 | irdma_schedule_cm_timer()
      irdma_cleanup_cm_core()    |  add_timer()
       spin_lock_irqsave() //(1) |  (wait a time)
       ...                       | irdma_cm_timer_tick()
       del_timer_sync()          |  spin_lock_irqsave() //(2)
       (wait timer to stop)      |  ...
      
      We hold cm_core->ht_lock in position (1) of thread 1 and use
      del_timer_sync() to wait timer to stop, but timer handler also need
      cm_core->ht_lock in position (2) of thread 2.  As a result,
      irdma_cleanup_cm_core() will block forever.
      
      This patch removes the check of timer_pending() in
      irdma_cleanup_cm_core(), because the del_timer_sync() function will just
      return directly if there isn't a pending timer. As a result, the lock is
      redundant, because there is no resource it could protect.
      
      Link: https://lore.kernel.org/r/20220418153322.42524-1-duoming@zju.edu.cn
      
      
      Signed-off-by: default avatarDuoming Zhou <duoming@zju.edu.cn>
      Reviewed-by: default avatarShiraz Saleem <shiraz.saleem@intel.com>
      Signed-off-by: default avatarJason Gunthorpe <jgg@nvidia.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      2f6b75c0
    • Ji-Ze Hong (Peter Hong)'s avatar
      hwmon: (f71882fg) Fix negative temperature · f21579e4
      Ji-Ze Hong (Peter Hong) authored
      [ Upstream commit 4aaaaf0f
      
       ]
      
      All temperature of Fintek superio hwmonitor that using 1-byte reg will use
      2's complement.
      
      In show_temp()
      	temp = data->temp[nr] * 1000;
      
      When data->temp[nr] read as 255, it indicate -1C, but this code will report
      255C to userspace. It'll be ok when change to:
      	temp = ((s8)data->temp[nr]) * 1000;
      
      Signed-off-by: default avatarJi-Ze Hong (Peter Hong) <hpeter+linux_kernel@gmail.com>
      Link: https://lore.kernel.org/r/20220418090706.6339-1-hpeter+linux_kernel@gmail.com
      
      
      Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      f21579e4
    • Andreas Gruenbacher's avatar
      gfs2: Fix filesystem block deallocation for short writes · 41d5ad95
      Andreas Gruenbacher authored
      [ Upstream commit d031a886 ]
      
      When a write cannot be carried out in full, gfs2_iomap_end() releases
      blocks that have been allocated for this write but haven't been used.
      
      To compute the end of the allocation, gfs2_iomap_end() incorrectly
      rounded the end of the attempted write down to the next block boundary
      to arrive at the end of the allocation.  It would have to round up, but
      the end of the allocation is also available as iomap->offset +
      iomap->length, so just use that instead.
      
      In addition, use round_up() for computing the start of the unused range.
      
      Fixes: 64bc06bb
      
       ("gfs2: iomap buffered write support")
      Signed-off-by: default avatarAndreas Gruenbacher <agruenba@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      41d5ad95
    • Zack Rusin's avatar
      drm/vmwgfx: Fix fencing on SVGAv3 · cf2589a6
      Zack Rusin authored
      [ Upstream commit 1d6595b4 ]
      
      Port of the vmwgfx to SVGAv3 lacked support for fencing. SVGAv3 removed
      FIFO's and replaced them with command buffers and extra registers.
      The initial version of SVGAv3 lacked support for most advanced features
      (e.g. 3D) which made fences unnecessary. That is no longer the case,
      especially as 3D support is being turned on.
      
      Switch from FIFO commands and capabilities to command buffers and extra
      registers to enable fences on SVGAv3.
      
      Fixes: 2cd80dbd
      
       ("drm/vmwgfx: Add basic support for SVGA3")
      Signed-off-by: default avatarZack Rusin <zackr@vmware.com>
      Reviewed-by: default avatarMartin Krastev <krastevm@vmware.com>
      Reviewed-by: default avatarMaaz Mombasawala <mombasawalam@vmware.com>
      Link: https://patchwork.freedesktop.org/patch/msgid/20220302152426.885214-5-zack@kde.org
      
      
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      cf2589a6
    • Maxim Mikityanskiy's avatar
      tls: Fix context leak on tls_device_down · 70098cc9
      Maxim Mikityanskiy authored
      [ Upstream commit 3740651b ]
      
      The commit cited below claims to fix a use-after-free condition after
      tls_device_down. Apparently, the description wasn't fully accurate. The
      context stayed alive, but ctx->netdev became NULL, and the offload was
      torn down without a proper fallback, so a bug was present, but a
      different kind of bug.
      
      Due to misunderstanding of the issue, the original patch dropped the
      refcount_dec_and_test line for the context to avoid the alleged
      premature deallocation. That line has to be restored, because it matches
      the refcount_inc_not_zero from the same function, otherwise the contexts
      that survived tls_device_down are leaked.
      
      This patch fixes the described issue by restoring refcount_dec_and_test.
      After this change, there is no leak anymore, and the fallback to
      software kTLS still works.
      
      Fixes: c55dcdd4
      
       ("net/tls: Fix use-after-free after the TLS device goes down and up")
      Signed-off-by: default avatarMaxim Mikityanskiy <maximmi@nvidia.com>
      Reviewed-by: default avatarTariq Toukan <tariqt@nvidia.com>
      Link: https://lore.kernel.org/r/20220512091830.678684-1-maximmi@nvidia.com
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      70098cc9
    • Taehee Yoo's avatar
      net: sfc: ef10: fix memory leak in efx_ef10_mtd_probe() · 280a9374
      Taehee Yoo authored
      [ Upstream commit 1fa89ffb
      
       ]
      
      In the NIC ->probe() callback, ->mtd_probe() callback is called.
      If NIC has 2 ports, ->probe() is called twice and ->mtd_probe() too.
      In the ->mtd_probe(), which is efx_ef10_mtd_probe() it allocates and
      initializes mtd partiion.
      But mtd partition for sfc is shared data.
      So that allocated mtd partition data from last called
      efx_ef10_mtd_probe() will not be used.
      Therefore it must be freed.
      But it doesn't free a not used mtd partition data in efx_ef10_mtd_probe().
      
      kmemleak reports:
      unreferenced object 0xffff88811ddb0000 (size 63168):
        comm "systemd-udevd", pid 265, jiffies 4294681048 (age 348.586s)
        hex dump (first 32 bytes):
          00 00 00 00 00 00 00 00 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:
          [<ffffffffa3767749>] kmalloc_order_trace+0x19/0x120
          [<ffffffffa3873f0e>] __kmalloc+0x20e/0x250
          [<ffffffffc041389f>] efx_ef10_mtd_probe+0x11f/0x270 [sfc]
          [<ffffffffc0484c8a>] efx_pci_probe.cold.17+0x3df/0x53d [sfc]
          [<ffffffffa414192c>] local_pci_probe+0xdc/0x170
          [<ffffffffa4145df5>] pci_device_probe+0x235/0x680
          [<ffffffffa443dd52>] really_probe+0x1c2/0x8f0
          [<ffffffffa443e72b>] __driver_probe_device+0x2ab/0x460
          [<ffffffffa443e92a>] driver_probe_device+0x4a/0x120
          [<ffffffffa443f2ae>] __driver_attach+0x16e/0x320
          [<ffffffffa4437a90>] bus_for_each_dev+0x110/0x190
          [<ffffffffa443b75e>] bus_add_driver+0x39e/0x560
          [<ffffffffa4440b1e>] driver_register+0x18e/0x310
          [<ffffffffc02e2055>] 0xffffffffc02e2055
          [<ffffffffa3001af3>] do_one_initcall+0xc3/0x450
          [<ffffffffa33ca574>] do_init_module+0x1b4/0x700
      
      Acked-by: default avatarMartin Habets <habetsm.xilinx@gmail.com>
      Fixes: 8127d661
      
       ("sfc: Add support for Solarflare SFC9100 family")
      Signed-off-by: default avatarTaehee Yoo <ap420073@gmail.com>
      Link: https://lore.kernel.org/r/20220512054709.12513-1-ap420073@gmail.com
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      280a9374
    • Guangguan Wang's avatar
      net/smc: non blocking recvmsg() return -EAGAIN when no data and signal_pending · 8d75d66f
      Guangguan Wang authored
      [ Upstream commit f3c46e41 ]
      
      Non blocking sendmsg will return -EAGAIN when any signal pending
      and no send space left, while non blocking recvmsg return -EINTR
      when signal pending and no data received. This may makes confused.
      As TCP returns -EAGAIN in the conditions described above. Align the
      behavior of smc with TCP.
      
      Fixes: 846e344e
      
       ("net/smc: add receive timeout check")
      Signed-off-by: default avatarGuangguan Wang <guangguan.wang@linux.alibaba.com>
      Reviewed-by: default avatarTony Lu <tonylu@linux.alibaba.com>
      Acked-by: default avatarKarsten Graul <kgraul@linux.ibm.com>
      Link: https://lore.kernel.org/r/20220512030820.73848-1-guangguan.wang@linux.alibaba.com
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      8d75d66f
    • Florian Fainelli's avatar
      net: dsa: bcm_sf2: Fix Wake-on-LAN with mac_link_down() · e3e02d68
      Florian Fainelli authored
      [ Upstream commit b7be130c ]
      
      After commit 2d1f90f9 ("net: dsa/bcm_sf2: fix incorrect usage of
      state->link") the interface suspend path would call our mac_link_down()
      call back which would forcibly set the link down, thus preventing
      Wake-on-LAN packets from reaching our management port.
      
      Fix this by looking at whether the port is enabled for Wake-on-LAN and
      not clearing the link status in that case to let packets go through.
      
      Fixes: 2d1f90f9
      
       ("net: dsa/bcm_sf2: fix incorrect usage of state->link")
      Signed-off-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
      Link: https://lore.kernel.org/r/20220512021731.2494261-1-f.fainelli@gmail.com
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      e3e02d68
    • Hui Tang's avatar
      drm/vc4: hdmi: Fix build error for implicit function declaration · 18f03c33
      Hui Tang authored
      [ Upstream commit 6fed53de ]
      
      drivers/gpu/drm/vc4/vc4_hdmi.c: In function ‘vc4_hdmi_connector_detect’:
      drivers/gpu/drm/vc4/vc4_hdmi.c:228:7: error: implicit declaration of function ‘gpiod_get_value_cansleep’; did you mean ‘gpio_get_value_cansleep’? [-Werror=implicit-function-declaration]
         if (gpiod_get_value_cansleep(vc4_hdmi->hpd_gpio))
             ^~~~~~~~~~~~~~~~~~~~~~~~
             gpio_get_value_cansleep
        CC [M]  drivers/gpu/drm/vc4/vc4_validate.o
        CC [M]  drivers/gpu/drm/vc4/vc4_v3d.o
        CC [M]  drivers/gpu/drm/vc4/vc4_validate_shaders.o
        CC [M]  drivers/gpu/drm/vc4/vc4_debugfs.o
      drivers/gpu/drm/vc4/vc4_hdmi.c: In function ‘vc4_hdmi_bind’:
      drivers/gpu/drm/vc4/vc4_hdmi.c:2883:23: error: implicit declaration of function ‘devm_gpiod_get_optional’; did you mean ‘devm_clk_get_optional’? [-Werror=implicit-function-declaration]
        vc4_hdmi->hpd_gpio = devm_gpiod_get_optional(dev, "hpd", GPIOD_IN);
                             ^~~~~~~~~~~~~~~~~~~~~~~
                             devm_clk_get_optional
      drivers/gpu/drm/vc4/vc4_hdmi.c:2883:59: error: ‘GPIOD_IN’ undeclared (first use in this function); did you mean ‘GPIOF_IN’?
        vc4_hdmi->hpd_gpio = devm_gpiod_get_optional(dev, "hpd", GPIOD_IN);
                                                                 ^~~~~~~~
                                                                 GPIOF_IN
      drivers/gpu/drm/vc4/vc4_hdmi.c:2883:59: note: each undeclared identifier is reported only once for each function it appears in
      cc1: all warnings being treated as errors
      
      Fixes: 6800234c
      
       ("drm/vc4: hdmi: Convert to gpiod")
      Signed-off-by: default avatarHui Tang <tanghui20@huawei.com>
      Signed-off-by: default avatarMaxime Ripard <maxime@cerno.tech>
      Link: https://patchwork.freedesktop.org/patch/msgid/20220510135148.247719-1-tanghui20@huawei.com
      
      
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      18f03c33
    • Florian Fainelli's avatar
      net: bcmgenet: Check for Wake-on-LAN interrupt probe deferral · 6e4c10cb
      Florian Fainelli authored
      [ Upstream commit 6b77c066 ]
      
      The interrupt controller supplying the Wake-on-LAN interrupt line maybe
      modular on some platforms (irq-bcm7038-l1.c) and might be probed at a
      later time than the GENET driver. We need to specifically check for
      -EPROBE_DEFER and propagate that error to ensure that we eventually
      fetch the interrupt descriptor.
      
      Fixes: 9deb48b5 ("bcmgenet: add WOL IRQ check")
      Fixes: 5b1f0e62
      
       ("net: bcmgenet: Avoid touching non-existent interrupt")
      Signed-off-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
      Reviewed-by: default avatarStefan Wahren <stefan.wahren@i2se.com>
      Link: https://lore.kernel.org/r/20220511031752.2245566-1-f.fainelli@gmail.com
      
      
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      6e4c10cb
    • Yang Yingliang's avatar
      net: ethernet: mediatek: ppe: fix wrong size passed to memset() · 598483f1
      Yang Yingliang authored
      [ Upstream commit 00832b1d ]
      
      'foe_table' is a pointer, the real size of struct mtk_foe_entry
      should be pass to memset().
      
      Fixes: ba37b7ca
      
       ("net: ethernet: mtk_eth_soc: add support for initializing the PPE")
      Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
      Acked-by: default avatarFelix Fietkau <nbd@nbd.name>
      Link: https://lore.kernel.org/r/20220511030829.3308094-1-yangyingliang@huawei.com
      
      
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      598483f1
    • Paolo Abeni's avatar
      net/sched: act_pedit: really ensure the skb is writable · b773640d
      Paolo Abeni authored
      [ Upstream commit 8b796475 ]
      
      Currently pedit tries to ensure that the accessed skb offset
      is writable via skb_unclone(). The action potentially allows
      touching any skb bytes, so it may end-up modifying shared data.
      
      The above causes some sporadic MPTCP self-test failures, due to
      this code:
      
      	tc -n $ns2 filter add dev ns2eth$i egress \
      		protocol ip prio 1000 \
      		handle 42 fw \
      		action pedit munge offset 148 u8 invert \
      		pipe csum tcp \
      		index 100
      
      The above modifies a data byte outside the skb head and the skb is
      a cloned one, carrying a TCP output packet.
      
      This change addresses the issue by keeping track of a rough
      over-estimate highest skb offset accessed by the action and ensuring
      such offset is really writable.
      
      Note that this may cause performance regressions in some scenarios,
      but hopefully pedit is not in the critical path.
      
      Fixes: db2c2417
      
       ("act_pedit: access skb->data safely")
      Acked-by: default avatarMat Martineau <mathew.j.martineau@linux.intel.com>
      Tested-by: default avatarGeliang Tang <geliang.tang@suse.com>
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      Acked-by: default avatarJamal Hadi Salim <jhs@mojatatu.com>
      Link: https://lore.kernel.org/r/1fcf78e6679d0a287dd61bb0f04730ce33b3255d.1652194627.git.pabeni@redhat.com
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      b773640d
    • Alexandra Winter's avatar
      s390/lcs: fix variable dereferenced before check · 3a518561
      Alexandra Winter authored
      [ Upstream commit 671bb35c ]
      
      smatch complains about
      drivers/s390/net/lcs.c:1741 lcs_get_control() warn: variable dereferenced before check 'card->dev' (see line 1739)
      
      Fixes: 27eb5ac8
      
       ("[PATCH] s390: lcs driver bug fixes and improvements [1/2]")
      Signed-off-by: default avatarAlexandra Winter <wintera@linux.ibm.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      3a518561
    • Alexandra Winter's avatar
      s390/ctcm: fix potential memory leak · 2bd57101
      Alexandra Winter authored
      [ Upstream commit 0c0b2058 ]
      
      smatch complains about
      drivers/s390/net/ctcm_mpc.c:1210 ctcmpc_unpack_skb() warn: possible memory leak of 'mpcginfo'
      
      mpc_action_discontact() did not free mpcginfo. Consolidate the freeing in
      ctcmpc_unpack_skb().
      
      Fixes: 293d984f
      
       ("ctcm: infrastructure for replaced ctc driver")
      Signed-off-by: default avatarAlexandra Winter <wintera@linux.ibm.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      2bd57101
    • Alexandra Winter's avatar
      s390/ctcm: fix variable dereferenced before check · 21bb0246
      Alexandra Winter authored
      [ Upstream commit 2c50c686 ]
      
      Found by cppcheck and smatch.
      smatch complains about
      drivers/s390/net/ctcm_sysfs.c:43 ctcm_buffer_write() warn: variable dereferenced before check 'priv' (see line 42)
      
      Fixes: 3c09e264
      
       ("ctcm: rename READ/WRITE defines to avoid redefinitions")
      Reported-by: default avatarColin Ian King <colin.i.king@gmail.com>
      Signed-off-by: default avatarAlexandra Winter <wintera@linux.ibm.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      21bb0246
    • Shunsuke Mie's avatar
      virtio: fix virtio transitional ids · 79e87cfc
      Shunsuke Mie authored
      [ Upstream commit 7ff960a6 ]
      
      This commit fixes the transitional PCI device ID.
      
      Fixes: d61914ea
      
       ("virtio: update virtio id table, add transitional ids")
      Signed-off-by: default avatarShunsuke Mie <mie@igel.co.jp>
      Link: https://lore.kernel.org/r/20220510102723.87666-1-mie@igel.co.jp
      
      
      Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      79e87cfc
    • Joey Gouly's avatar
      arm64: vdso: fix makefile dependency on vdso.so · 4147d2e1
      Joey Gouly authored
      [ Upstream commit 205f3991 ]
      
      There is currently no dependency for vdso*-wrap.S on vdso*.so, which means that
      you can get a build that uses a stale vdso*-wrap.o.
      
      In commit a5b8ca97, the file that includes the vdso.so was moved and renamed
      from arch/arm64/kernel/vdso/vdso.S to arch/arm64/kernel/vdso-wrap.S, when this
      happened the Makefile was not updated to force the dependcy on vdso.so.
      
      Fixes: a5b8ca97
      
       ("arm64: do not descend to vdso directories twice")
      Signed-off-by: default avatarJoey Gouly <joey.gouly@arm.com>
      Cc: Masahiro Yamada <masahiroy@kernel.org>
      Cc: Vincenzo Frascino <vincenzo.frascino@arm.com>
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Cc: Will Deacon <will@kernel.org>
      Link: https://lore.kernel.org/r/20220510102721.50811-1-joey.gouly@arm.com
      
      
      Signed-off-by: default avatarWill Deacon <will@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      4147d2e1
    • Joel Savitz's avatar
      selftests: vm: Makefile: rename TARGETS to VMTARGETS · 00782d1d
      Joel Savitz authored
      [ Upstream commit 41c24009 ]
      
      The tools/testing/selftests/vm/Makefile uses the variable TARGETS
      internally to generate a list of platform-specific binary build targets
      suffixed with _{32,64}.  When building the selftests using its own
      Makefile directly, such as via the following command run in a kernel tree:
      
      One receives an error such as the following:
      
      make: Entering directory '/root/linux/tools/testing/selftests'
      make --no-builtin-rules ARCH=x86 -C ../../.. headers_install
      make[1]: Entering directory '/root/linux'
        INSTALL ./usr/include
      make[1]: Leaving directory '/root/linux'
      make[1]: Entering directory '/root/linux/tools/testing/selftests/vm'
      make[1]: *** No rule to make target 'vm.c', needed by '/root/linux/tools/testing/selftests/vm/vm_64'.  Stop.
      make[1]: Leaving directory '/root/linux/tools/testing/selftests/vm'
      make: *** [Makefile:175: all] Error 2
      make: Leaving directory '/root/linux/tools/testing/selftests'
      
      The TARGETS variable passed to tools/testing/selftests/Makefile collides
      with the TARGETS used in tools/testing/selftests/vm/Makefile, so rename
      the latter to VMTARGETS, eliminating the collision with no functional
      change.
      
      Link: https://lkml.kernel.org/r/20220504213454.1282532-1-jsavitz@redhat.com
      Fixes: f21fda8f
      
       ("selftests: vm: pkeys: fix multilib builds for x86")
      Signed-off-by: default avatarJoel Savitz <jsavitz@redhat.com>
      Acked-by: default avatarNico Pache <npache@redhat.com>
      Cc: Joel Savitz <jsavitz@redhat.com>
      Cc: Shuah Khan <shuah@kernel.org>
      Cc: Sandipan Das <sandipan@linux.ibm.com>
      Cc: Dave Hansen <dave.hansen@intel.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      00782d1d
    • Kalesh Singh's avatar
      procfs: prevent unprivileged processes accessing fdinfo dir · 62cbb098
      Kalesh Singh authored
      [ Upstream commit 1927e498 ]
      
      The file permissions on the fdinfo dir from were changed from
      S_IRUSR|S_IXUSR to S_IRUGO|S_IXUGO, and a PTRACE_MODE_READ check was added
      for opening the fdinfo files [1].  However, the ptrace permission check
      was not added to the directory, allowing anyone to get the open FD numbers
      by reading the fdinfo directory.
      
      Add the missing ptrace permission check for opening the fdinfo directory.
      
      [1] https://lkml.kernel.org/r/20210308170651.919148-1-kaleshsingh@google.com
      
      Link: https://lkml.kernel.org/r/20210713162008.1056986-1-kaleshsingh@google.com
      Fixes: 7bc3fa01
      
       ("procfs: allow reading fdinfo with PTRACE_MODE_READ")
      Signed-off-by: default avatarKalesh Singh <kaleshsingh@google.com>
      Cc: Kees Cook <keescook@chromium.org>
      Cc: Eric W. Biederman <ebiederm@xmission.com>
      Cc: Christian Brauner <christian.brauner@ubuntu.com>
      Cc: Suren Baghdasaryan <surenb@google.com>
      Cc: Hridya Valsaraju <hridya@google.com>
      Cc: Jann Horn <jannh@google.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      62cbb098
    • Randy Dunlap's avatar
      hwmon: (ltq-cputemp) restrict it to SOC_XWAY · 844c31a4
      Randy Dunlap authored
      [ Upstream commit 151d6dcb ]
      
      Building with SENSORS_LTQ_CPUTEMP=y with SOC_FALCON=y causes build
      errors since FALCON does not support the same features as XWAY.
      
      Change this symbol to depend on SOC_XWAY since that provides the
      necessary interfaces.
      
      Repairs these build errors:
      
      ../drivers/hwmon/ltq-cputemp.c: In function 'ltq_cputemp_enable':
      ../drivers/hwmon/ltq-cputemp.c:23:9: error: implicit declaration of function 'ltq_cgu_w32'; did you mean 'ltq_ebu_w32'? [-Werror=implicit-function-declaration]
         23 |         ltq_cgu_w32(ltq_cgu_r32(CGU_GPHY1_CR) | CGU_TEMP_PD, CGU_GPHY1_CR);
      ../drivers/hwmon/ltq-cputemp.c:23:21: error: implicit declaration of function 'ltq_cgu_r32'; did you mean 'ltq_ebu_r32'? [-Werror=implicit-function-declaration]
         23 |         ltq_cgu_w32(ltq_cgu_r32(CGU_GPHY1_CR) | CGU_TEMP_PD, CGU_GPHY1_CR);
      ../drivers/hwmon/ltq-cputemp.c: In function 'ltq_cputemp_probe':
      ../drivers/hwmon/ltq-cputemp.c:92:31: error: 'SOC_TYPE_VR9_2' undeclared (first use in this function)
         92 |         if (ltq_soc_type() != SOC_TYPE_VR9_2)
      
      Fixes: 7074d0a9
      
       ("hwmon: (ltq-cputemp) add cpu temp sensor driver")
      Signed-off-by: default avatarRandy Dunlap <rdunlap@infradead.org>
      Reported-by: default avatarkernel test robot <lkp@intel.com>
      Cc: Florian Eckert <fe@dev.tdt.de>
      Cc: Guenter Roeck <linux@roeck-us.net>
      Cc: Jean Delvare <jdelvare@suse.com>
      Cc: linux-hwmon@vger.kernel.org
      Link: https://lore.kernel.org/r/20220509234740.26841-1-rdunlap@infradead.org
      
      
      Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      844c31a4
    • Jesse Brandeburg's avatar
      dim: initialize all struct fields · 5f71bc9a
      Jesse Brandeburg authored
      [ Upstream commit ee1444b5 ]
      
      The W=2 build pointed out that the code wasn't initializing all the
      variables in the dim_cq_moder declarations with the struct initializers.
      The net change here is zero since these structs were already static
      const globals and were initialized with zeros by the compiler, but
      removing compiler warnings has value in and of itself.
      
      lib/dim/net_dim.c: At top level:
      lib/dim/net_dim.c:54:9: warning: missing initializer for field ‘comps’ of ‘const struct dim_cq_moder’ [-Wmissing-field-initializers]
         54 |         NET_DIM_RX_EQE_PROFILES,
            |         ^~~~~~~~~~~~~~~~~~~~~~~
      In file included from lib/dim/net_dim.c:6:
      ./include/linux/dim.h:45:13: note: ‘comps’ declared here
         45 |         u16 comps;
            |             ^~~~~
      
      and repeats for the tx struct, and once you fix the comps entry then
      the cq_period_mode field needs the same treatment.
      
      Use the commonly accepted style to indicate to the compiler that we
      know what we're doing, and add a comma at the end of each struct
      initializer to clean up the issue, and use explicit initializers
      for the fields we are initializing which makes the compiler happy.
      
      While here and fixing these lines, clean up the code slightly with
      a fix for the super long lines by removing the word "_MODERATION" from a
      couple defines only used in this file.
      
      Fixes: f8be17b8
      
       ("lib/dim: Fix -Wunused-const-variable warnings")
      Signed-off-by: default avatarJesse Brandeburg <jesse.brandeburg@intel.com>
      Link: https://lore.kernel.org/r/20220507011038.14568-1-jesse.brandeburg@intel.com
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      5f71bc9a
    • Yang Yingliang's avatar
      ionic: fix missing pci_release_regions() on error in ionic_probe() · 53a55a31
      Yang Yingliang authored
      [ Upstream commit e4b1045b ]
      
      If ionic_map_bars() fails, pci_release_regions() need be called.
      
      Fixes: fbfb8031
      
       ("ionic: Add hardware init and device commands")
      Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
      Link: https://lore.kernel.org/r/20220506034040.2614129-1-yangyingliang@huawei.com
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      53a55a31
    • Dan Aloni's avatar
      nfs: fix broken handling of the softreval mount option · 1a2e139e
      Dan Aloni authored
      [ Upstream commit 085d16d5 ]
      
      Turns out that ever since this mount option was added, passing
      `softreval` in NFS mount options cancelled all other flags while not
      affecting the underlying flag `NFS_MOUNT_SOFTREVAL`.
      
      Fixes: c74dfe97
      
       ("NFS: Add mount option 'softreval'")
      Signed-off-by: default avatarDan Aloni <dan.aloni@vastdata.com>
      Signed-off-by: default avatarTrond Myklebust <trond.myklebust@hammerspace.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      1a2e139e
    • Johannes Berg's avatar
      mac80211_hwsim: call ieee80211_tx_prepare_skb under RCU protection · 8bf4039e
      Johannes Berg authored
      [ Upstream commit 9e2db50f ]
      
      This is needed since it might use (and pass out) pointers to
      e.g. keys protected by RCU. Can't really happen here as the
      frames aren't encrypted, but we need to still adhere to the
      rules.
      
      Fixes: cacfddf8
      
       ("mac80211_hwsim: initialize ieee80211_tx_info at hw_scan_work")
      Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
      Link: https://lore.kernel.org/r/20220505230421.5f139f9de173.I77ae111a28f7c0e9fd1ebcee7f39dbec5c606770@changeid
      
      
      Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      8bf4039e
    • Taehee Yoo's avatar
      net: sfc: fix memory leak due to ptp channel · 7b2fa7ad
      Taehee Yoo authored
      [ Upstream commit 49e6123c ]
      
      It fixes memory leak in ring buffer change logic.
      
      When ring buffer size is changed(ethtool -G eth0 rx 4096), sfc driver
      works like below.
      1. stop all channels and remove ring buffers.
      2. allocates new buffer array.
      3. allocates rx buffers.
      4. start channels.
      
      While the above steps are working, it skips some steps if the channel
      doesn't have a ->copy callback function.
      Due to ptp channel doesn't have ->copy callback, these above steps are
      skipped for ptp channel.
      It eventually makes some problems.
      a. ptp channel's ring buffer size is not changed, it works only
         1024(default).
      b. memory leak.
      
      The reason for memory leak is to use the wrong ring buffer values.
      There are some values, which is related to ring buffer size.
      a. efx->rxq_entries
       - This is global value of rx queue size.
      b. rx_queue->ptr_mask
       - used for access ring buffer as circular ring.
       - roundup_pow_of_two(efx->rxq_entries) - 1
      c. rx_queue->max_fill
       - efx->rxq_entries - EFX_RXD_HEAD_ROOM
      
      These all values should be based on ring buffer size consistently.
      But ptp channel's values are not.
      a. efx->rxq_entries
       - This is global(for sfc) value, always new ring buffer size.
      b. rx_queue->ptr_mask
       - This is always 1023(default).
      c. rx_queue->max_fill
       - This is new ring buffer size - EFX_RXD_HEAD_ROOM.
      
      Let's assume we set 4096 for rx ring buffer,
      
                            normal channel     ptp channel
      efx->rxq_entries      4096               4096
      rx_queue->ptr_mask    4095               1023
      rx_queue->max_fill    4086               4086
      
      sfc driver allocates rx ring buffers based on these values.
      When it allocates ptp channel's ring buffer, 4086 ring buffers are
      allocated then, these buffers are attached to the allocated array.
      But ptp channel's ring buffer array size is still 1024(default)
      and ptr_mask is still 1023 too.
      So, 3062 ring buffers will be overwritten to the array.
      This is the reason for memory leak.
      
      Test commands:
         ethtool -G <interface name> rx 4096
         while :
         do
             ip link set <interface name> up
             ip link set <interface name> down
         done
      
      In order to avoid this problem, it adds ->copy callback to ptp channel
      type.
      So that rx_queue->ptr_mask value will be updated correctly.
      
      Fixes: 7c236c43
      
       ("sfc: Add support for IEEE-1588 PTP")
      Signed-off-by: default avatarTaehee Yoo <ap420073@gmail.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      7b2fa7ad
    • Jiapeng Chong's avatar
      sfc: Use swap() instead of open coding it · fc4615a8
      Jiapeng Chong authored
      [ Upstream commit 0cf765fb
      
       ]
      
      Clean the following coccicheck warning:
      
      ./drivers/net/ethernet/sfc/efx_channels.c:870:36-37: WARNING opportunity
      for swap().
      
      ./drivers/net/ethernet/sfc/efx_channels.c:824:36-37: WARNING opportunity
      for swap().
      
      Reported-by: default avatarAbaci Robot <abaci@linux.alibaba.com>
      Signed-off-by: default avatarJiapeng Chong <jiapeng.chong@linux.alibaba.com>
      Acked-by: default avatarMartin Habets <habetsm.xilinx@gmail.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      fc4615a8
    • Javier Martinez Canillas's avatar
      fbdev: efifb: Fix a use-after-free due early fb_info cleanup · ef090cd4
      Javier Martinez Canillas authored
      [ Upstream commit 1b5853df ]
      
      Commit d258d00f ("fbdev: efifb: Cleanup fb_info in .fb_destroy rather
      than .remove") attempted to fix a use-after-free error due driver freeing
      the fb_info in the .remove handler instead of doing it in .fb_destroy.
      
      But ironically that change introduced yet another use-after-free since the
      fb_info was still used after the free.
      
      This should fix for good by freeing the fb_info at the end of the handler.
      
      Fixes: d258d00f
      
       ("fbdev: efifb: Cleanup fb_info in .fb_destroy rather than .remove")
      Reported-by: default avatarVille Syrjälä <ville.syrjala@linux.intel.com>
      Reported-by: default avatarAndrzej Hajda <andrzej.hajda@intel.com>
      Signed-off-by: default avatarJavier Martinez Canillas <javierm@redhat.com>
      Reviewed-by: default avatarAndi Shyti <andi.shyti@linux.intel.com>
      Reviewed-by: default avatarAndrzej Hajda <andrzej.hajda@intel.com>
      Reviewed-by: default avatarThomas Zimmermann <tzimemrmann@suse.de>
      Signed-off-by: default avatarLucas De Marchi <lucas.demarchi@intel.com>
      Link: https://patchwork.freedesktop.org/patch/msgid/20220506132225.588379-1-javierm@redhat.com
      
      
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      ef090cd4
    • Kees Cook's avatar
      net: chelsio: cxgb4: Avoid potential negative array offset · 42125c81
      Kees Cook authored
      [ Upstream commit 1c7ab9cd
      
       ]
      
      Using min_t(int, ...) as a potential array index implies to the compiler
      that negative offsets should be allowed. This is not the case, though.
      Replace "int" with "unsigned int". Fixes the following warning exposed
      under future CONFIG_FORTIFY_SOURCE improvements:
      
      In file included from include/linux/string.h:253,
                       from include/linux/bitmap.h:11,
                       from include/linux/cpumask.h:12,
                       from include/linux/smp.h:13,
                       from include/linux/lockdep.h:14,
                       from include/linux/rcupdate.h:29,
                       from include/linux/rculist.h:11,
                       from include/linux/pid.h:5,
                       from include/linux/sched.h:14,
                       from include/linux/delay.h:23,
                       from drivers/net/ethernet/chelsio/cxgb4/t4_hw.c:35:
      drivers/net/ethernet/chelsio/cxgb4/t4_hw.c: In function 't4_get_raw_vpd_params':
      include/linux/fortify-string.h:46:33: warning: '__builtin_memcpy' pointer overflow between offset 29 and size [2147483648, 4294967295] [-Warray-bounds]
         46 | #define __underlying_memcpy     __builtin_memcpy
            |                                 ^
      include/linux/fortify-string.h:388:9: note: in expansion of macro '__underlying_memcpy'
        388 |         __underlying_##op(p, q, __fortify_size);                        \
            |         ^~~~~~~~~~~~~
      include/linux/fortify-string.h:433:26: note: in expansion of macro '__fortify_memcpy_chk'
        433 | #define memcpy(p, q, s)  __fortify_memcpy_chk(p, q, s,                  \
            |                          ^~~~~~~~~~~~~~~~~~~~
      drivers/net/ethernet/chelsio/cxgb4/t4_hw.c:2796:9: note: in expansion of macro 'memcpy'
       2796 |         memcpy(p->id, vpd + id, min_t(int, id_len, ID_LEN));
            |         ^~~~~~
      include/linux/fortify-string.h:46:33: warning: '__builtin_memcpy' pointer overflow between offset 0 and size [2147483648, 4294967295] [-Warray-bounds]
         46 | #define __underlying_memcpy     __builtin_memcpy
            |                                 ^
      include/linux/fortify-string.h:388:9: note: in expansion of macro '__underlying_memcpy'
        388 |         __underlying_##op(p, q, __fortify_size);                        \
            |         ^~~~~~~~~~~~~
      include/linux/fortify-string.h:433:26: note: in expansion of macro '__fortify_memcpy_chk'
        433 | #define memcpy(p, q, s)  __fortify_memcpy_chk(p, q, s,                  \
            |                          ^~~~~~~~~~~~~~~~~~~~
      drivers/net/ethernet/chelsio/cxgb4/t4_hw.c:2798:9: note: in expansion of macro 'memcpy'
       2798 |         memcpy(p->sn, vpd + sn, min_t(int, sn_len, SERNUM_LEN));
            |         ^~~~~~
      
      Additionally remove needless cast from u8[] to char * in last strim()
      call.
      
      Reported-by: default avatarkernel test robot <lkp@intel.com>
      Link: https://lore.kernel.org/lkml/202205031926.FVP7epJM-lkp@intel.com
      Fixes: fc927929 ("cxgb4: Search VPD with pci_vpd_find_ro_info_keyword()")
      Fixes: 24c521f8
      
       ("cxgb4: Use pci_vpd_find_id_string() to find VPD ID string")
      Cc: Raju Rangoju <rajur@chelsio.com>
      Cc: Eric Dumazet <edumazet@google.com>
      Cc: Paolo Abeni <pabeni@redhat.com>
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      Link: https://lore.kernel.org/r/20220505233101.1224230-1-keescook@chromium.org
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      42125c81
    • Eric Dumazet's avatar
      netlink: do not reset transport header in netlink_recvmsg() · fa189827
      Eric Dumazet authored
      [ Upstream commit d5076fe4 ]
      
      netlink_recvmsg() does not need to change transport header.
      
      If transport header was needed, it should have been reset
      by the producer (netlink_dump()), not the consumer(s).
      
      The following trace probably happened when multiple threads
      were using MSG_PEEK.
      
      BUG: KCSAN: data-race in netlink_recvmsg / netlink_recvmsg
      
      write to 0xffff88811e9f15b2 of 2 bytes by task 32012 on cpu 1:
       skb_reset_transport_header include/linux/skbuff.h:2760 [inline]
       netlink_recvmsg+0x1de/0x790 net/netlink/af_netlink.c:1978
       sock_recvmsg_nosec net/socket.c:948 [inline]
       sock_recvmsg net/socket.c:966 [inline]
       __sys_recvfrom+0x204/0x2c0 net/socket.c:2097
       __do_sys_recvfrom net/socket.c:2115 [inline]
       __se_sys_recvfrom net/socket.c:2111 [inline]
       __x64_sys_recvfrom+0x74/0x90 net/socket.c:2111
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x2b/0x70 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x44/0xae
      
      write to 0xffff88811e9f15b2 of 2 bytes by task 32005 on cpu 0:
       skb_reset_transport_header include/linux/skbuff.h:2760 [inline]
       netlink_recvmsg+0x1de/0x790 net/netlink/af_netlink.c:1978
       ____sys_recvmsg+0x162/0x2f0
       ___sys_recvmsg net/socket.c:2674 [inline]
       __sys_recvmsg+0x209/0x3f0 net/socket.c:2704
       __do_sys_recvmsg net/socket.c:2714 [inline]
       __se_sys_recvmsg net/socket.c:2711 [inline]
       __x64_sys_recvmsg+0x42/0x50 net/socket.c:2711
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x2b/0x70 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x44/0xae
      
      value changed: 0xffff -> 0x0000
      
      Reported by Kernel Concurrency Sanitizer on:
      CPU: 0 PID: 32005 Comm: syz-executor.4 Not tainted 5.18.0-rc1-syzkaller-00328-ge1f700ebd6be-dirty #0
      Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
      
      Fixes: 1da177e4
      
       ("Linux-2.6.12-rc2")
      Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
      Reported-by: default avatarsyzbot <syzkaller@googlegroups.com>
      Link: https://lore.kernel.org/r/20220505161946.2867638-1-eric.dumazet@gmail.com
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      fa189827
    • Christophe JAILLET's avatar
      drm/nouveau: Fix a potential theorical leak in nouveau_get_backlight_name() · 57d6374f
      Christophe JAILLET authored
      [ Upstream commit ab244be4 ]
      
      If successful ida_simple_get() calls are not undone when needed, some
      additional memory may be allocated and wasted.
      
      Here, an ID between 0 and MAX_INT is required. If this ID is >=100, it is
      not taken into account and is wasted. It should be released.
      
      Instead of calling ida_simple_remove(), take advantage of the 'max'
      parameter to require the ID not to be too big. Should it be too big, it
      is not allocated and don't need to be freed.
      
      While at it, use ida_alloc_xxx()/ida_free() instead to
      ida_simple_get()/ida_simple_remove().
      The latter is deprecated and more verbose.
      
      Fixes: db1a0ae2
      
       ("drm/nouveau/bl: Assign different names to interfaces")
      Signed-off-by: default avatarChristophe JAILLET <christophe.jaillet@wanadoo.fr>
      Reviewed-by: default avatarLyude Paul <lyude@redhat.com>
      [Fixed formatting warning from checkpatch]
      Signed-off-by: default avatarLyude Paul <lyude@redhat.com>
      Link: https://patchwork.freedesktop.org/patch/msgid/9ba85bca59df6813dc029e743a836451d5173221.1644386541.git.christophe.jaillet@wanadoo.fr
      
      
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      57d6374f
    • Lokesh Dhoundiyal's avatar
      ipv4: drop dst in multicast routing path · 33753005
      Lokesh Dhoundiyal authored
      [ Upstream commit 9e6c6d17 ]
      
      kmemleak reports the following when routing multicast traffic over an
      ipsec tunnel.
      
      Kmemleak output:
      unreferenced object 0x8000000044bebb00 (size 256):
        comm "softirq", pid 0, jiffies 4294985356 (age 126.810s)
        hex dump (first 32 bytes):
          00 00 00 00 00 00 00 00 80 00 00 00 05 13 74 80  ..............t.
          80 00 00 00 04 9b bf f9 00 00 00 00 00 00 00 00  ................
        backtrace:
          [<00000000f83947e0>] __kmalloc+0x1e8/0x300
          [<00000000b7ed8dca>] metadata_dst_alloc+0x24/0x58
          [<0000000081d32c20>] __ipgre_rcv+0x100/0x2b8
          [<00000000824f6cf1>] gre_rcv+0x178/0x540
          [<00000000ccd4e162>] gre_rcv+0x7c/0xd8
          [<00000000c024b148>] ip_protocol_deliver_rcu+0x124/0x350
          [<000000006a483377>] ip_local_deliver_finish+0x54/0x68
          [<00000000d9271b3a>] ip_local_deliver+0x128/0x168
          [<00000000bd4968ae>] xfrm_trans_reinject+0xb8/0xf8
          [<0000000071672a19>] tasklet_action_common.isra.16+0xc4/0x1b0
          [<0000000062e9c336>] __do_softirq+0x1fc/0x3e0
          [<00000000013d7914>] irq_exit+0xc4/0xe0
          [<00000000a4d73e90>] plat_irq_dispatch+0x7c/0x108
          [<000000000751eb8e>] handle_int+0x16c/0x178
          [<000000001668023b>] _raw_spin_unlock_irqrestore+0x1c/0x28
      
      The metadata dst is leaked when ip_route_input_mc() updates the dst for
      the skb. Commit f38a9eb1 ("dst: Metadata destinations") correctly
      handled dropping the dst in ip_route_input_slow() but missed the
      multicast case which is handled by ip_route_input_mc(). Drop the dst in
      ip_route_input_mc() avoiding the leak.
      
      Fixes: f38a9eb1
      
       ("dst: Metadata destinations")
      Signed-off-by: default avatarLokesh Dhoundiyal <lokesh.dhoundiyal@alliedtelesis.co.nz>
      Signed-off-by: default avatarChris Packham <chris.packham@alliedtelesis.co.nz>
      Reviewed-by: default avatarDavid Ahern <dsahern@kernel.org>
      Link: https://lore.kernel.org/r/20220505020017.3111846-1-chris.packham@alliedtelesis.co.nz
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      33753005
    • Michal Michalik's avatar
      ice: fix PTP stale Tx timestamps cleanup · 04b199e4
      Michal Michalik authored
      [ Upstream commit a11b6c1a ]
      
      Read stale PTP Tx timestamps from PHY on cleanup.
      
      After running out of Tx timestamps request handlers, hardware (HW) stops
      reporting finished requests. Function ice_ptp_tx_tstamp_cleanup() used
      to only clean up stale handlers in driver and was leaving the hardware
      registers not read. Not reading stale PTP Tx timestamps prevents next
      interrupts from arriving and makes timestamping unusable.
      
      Fixes: ea9b847c
      
       ("ice: enable transmit timestamps for E810 devices")
      Signed-off-by: default avatarMichal Michalik <michal.michalik@intel.com>
      Reviewed-by: default avatarJacob Keller <jacob.e.keller@intel.com>
      Reviewed-by: default avatarPaul Menzel <pmenzel@molgen.mpg.de>
      Tested-by: Gurucharan <gurucharanx.g@intel.com> (A Contingent worker at Intel)
      Signed-off-by: default avatarTony Nguyen <anthony.l.nguyen@intel.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      04b199e4
    • Ivan Vecera's avatar
      ice: Fix race during aux device (un)plugging · 4a5c4713
      Ivan Vecera authored
      [ Upstream commit 486b9eee ]
      
      Function ice_plug_aux_dev() assigns pf->adev field too early prior
      aux device initialization and on other side ice_unplug_aux_dev()
      starts aux device deinit and at the end assigns NULL to pf->adev.
      This is wrong because pf->adev should always be non-NULL only when
      aux device is fully initialized and ready. This wrong order causes
      a crash when ice_send_event_to_aux() call occurs because that function
      depends on non-NULL value of pf->adev and does not assume that
      aux device is half-initialized or half-destroyed.
      After order correction the race window is tiny but it is still there,
      as Leon mentioned and manipulation with pf->adev needs to be protected
      by mutex.
      
      Fix (un-)plugging functions so pf->adev field is set after aux device
      init and prior aux device destroy and protect pf->adev assignment by
      new mutex. This mutex is also held during ice_send_event_to_aux()
      call to ensure that aux device is valid during that call.
      Note that device lock used ice_send_event_to_aux() needs to be kept
      to avoid race with aux drv unload.
      
      Reproducer:
      cycle=1
      while :;do
              echo "#### Cycle: $cycle"
      
              ip link set ens7f0 mtu 9000
              ip link add bond0 type bond mode 1 miimon 100
              ip link set bond0 up
              ifenslave bond0 ens7f0
              ip link set bond0 mtu 9000
              ethtool -L ens7f0 combined 1
              ip link del bond0
              ip link set ens7f0 mtu 1500
              sleep 1
      
              let cycle++
      done
      
      In short when the device is added/removed to/from bond the aux device
      is unplugged/plugged. When MTU of the device is changed an event is
      sent to aux device asynchronously. This can race with (un)plugging
      operation and because pf->adev is set too early (plug) or too late
      (unplug) the function ice_send_event_to_aux() can touch uninitialized
      or destroyed fields. In the case of crash below pf->adev->dev.mutex.
      
      Crash:
      [   53.372066] bond0: (slave ens7f0): making interface the new active one
      [   53.378622] bond0: (slave ens7f0): Enslaving as an active interface with an u
      p link
      [   53.386294] IPv6: ADDRCONF(NETDEV_CHANGE): bond0: link becomes ready
      [   53.549104] bond0: (slave ens7f1): Enslaving as a backup interface with an up
       link
      [   54.118906] ice 0000:ca:00.0 ens7f0: Number of in use tx queues changed inval
      idating tc mappings. Priority traffic classification disabled!
      [   54.233374] ice 0000:ca:00.1 ens7f1: Number of in use tx queues changed inval
      idating tc mappings. Priority traffic classification disabled!
      [   54.248204] bond0: (slave ens7f0): Releasing backup interface
      [   54.253955] bond0: (slave ens7f1): making interface the new active one
      [   54.274875] bond0: (slave ens7f1): Releasing backup interface
      [   54.289153] bond0 (unregistering): Released all slaves
      [   55.383179] MII link monitoring set to 100 ms
      [   55.398696] bond0: (slave ens7f0): making interface the new active one
      [   55.405241] BUG: kernel NULL pointer dereference, address: 0000000000000080
      [   55.405289] bond0: (slave ens7f0): Enslaving as an active interface with an u
      p link
      [   55.412198] #PF: supervisor write access in kernel mode
      [   55.412200] #PF: error_code(0x0002) - not-present page
      [   55.412201] PGD 25d2ad067 P4D 0
      [   55.412204] Oops: 0002 [#1] PREEMPT SMP NOPTI
      [   55.412207] CPU: 0 PID: 403 Comm: kworker/0:2 Kdump: loaded Tainted: G S
                 5.17.0-13579-g57f2d6540f03 #1
      [   55.429094] bond0: (slave ens7f1): Enslaving as a backup interface with an up
       link
      [   55.430224] Hardware name: Dell Inc. PowerEdge R750/06V45N, BIOS 1.4.4 10/07/
      2021
      [   55.430226] Workqueue: ice ice_service_task [ice]
      [   55.468169] RIP: 0010:mutex_unlock+0x10/0x20
      [   55.472439] Code: 0f b1 13 74 96 eb e0 4c 89 ee eb d8 e8 79 54 ff ff 66 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 65 48 8b 04 25 40 ef 01 00 31 d2 <f0> 48 0f b1 17 75 01 c3 e9 e3 fe ff ff 0f 1f 00 0f 1f 44 00 00 48
      [   55.491186] RSP: 0018:ff4454230d7d7e28 EFLAGS: 00010246
      [   55.496413] RAX: ff1a79b208b08000 RBX: ff1a79b2182e8880 RCX: 0000000000000001
      [   55.503545] RDX: 0000000000000000 RSI: ff4454230d7d7db0 RDI: 0000000000000080
      [   55.510678] RBP: ff1a79d1c7e48b68 R08: ff4454230d7d7db0 R09: 0000000000000041
      [   55.517812] R10: 00000000000000a5 R11: 00000000000006e6 R12: ff1a79d1c7e48bc0
      [   55.524945] R13: 0000000000000000 R14: ff1a79d0ffc305c0 R15: 0000000000000000
      [   55.532076] FS:  0000000000000000(0000) GS:ff1a79d0ffc00000(0000) knlGS:0000000000000000
      [   55.540163] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      [   55.545908] CR2: 0000000000000080 CR3: 00000003487ae003 CR4: 0000000000771ef0
      [   55.553041] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
      [   55.560173] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
      [   55.567305] PKRU: 55555554
      [   55.570018] Call Trace:
      [   55.572474]  <TASK>
      [   55.574579]  ice_service_task+0xaab/0xef0 [ice]
      [   55.579130]  process_one_work+0x1c5/0x390
      [   55.583141]  ? process_one_work+0x390/0x390
      [   55.587326]  worker_thread+0x30/0x360
      [   55.590994]  ? process_one_work+0x390/0x390
      [   55.595180]  kthread+0xe6/0x110
      [   55.598325]  ? kthread_complete_and_exit+0x20/0x20
      [   55.603116]  ret_from_fork+0x1f/0x30
      [   55.606698]  </TASK>
      
      Fixes: f9f5301e
      
       ("ice: Register auxiliary device to provide RDMA")
      Reviewed-by: default avatarLeon Romanovsky <leonro@nvidia.com>
      Signed-off-by: default avatarIvan Vecera <ivecera@redhat.com>
      Reviewed-by: default avatarDave Ertman <david.m.ertman@intel.com>
      Tested-by: Gurucharan <gurucharanx.g@intel.com> (A Contingent worker at Intel)
      Signed-off-by: default avatarTony Nguyen <anthony.l.nguyen@intel.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      4a5c4713
    • Maximilian Luz's avatar
      platform/surface: aggregator: Fix initialization order when compiling as builtin module · 50bf9411
      Maximilian Luz authored
      [ Upstream commit 44acfc22 ]
      
      When building the Surface Aggregator Module (SAM) core, registry, and
      other SAM client drivers as builtin modules (=y), proper initialization
      order is not guaranteed. Due to this, client driver registration
      (triggered by device registration in the registry) races against bus
      initialization in the core.
      
      If any attempt is made at registering the device driver before the bus
      has been initialized (i.e. if bus initialization fails this race) driver
      registration will fail with a message similar to:
      
          Driver surface_battery was unable to register with bus_type surface_aggregator because the bus was not initialized
      
      Switch from module_init() to subsys_initcall() to resolve this issue.
      Note that the serdev subsystem uses postcore_initcall() so we are still
      able to safely register the serdev device driver for the core.
      
      Fixes: c167b9c7
      
       ("platform/surface: Add Surface Aggregator subsystem")
      Reported-by: default avatarBlaž Hrastnik <blaz@mxxn.io>
      Signed-off-by: default avatarMaximilian Luz <luzmaximilian@gmail.com>
      Link: https://lore.kernel.org/r/20220429195738.535751-1-luzmaximilian@gmail.com
      
      
      Reviewed-by: default avatarHans de Goede <hdegoede@redhat.com>
      Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      50bf9411
    • Javier Martinez Canillas's avatar
      fbdev: vesafb: Cleanup fb_info in .fb_destroy rather than .remove · f94aa46e
      Javier Martinez Canillas authored
      [ Upstream commit b3c9a924 ]
      
      The driver is calling framebuffer_release() in its .remove callback, but
      this will cause the struct fb_info to be freed too early. Since it could
      be that a reference is still hold to it if user-space opened the fbdev.
      
      This would lead to a use-after-free error if the framebuffer device was
      unregistered but later a user-space process tries to close the fbdev fd.
      
      To prevent this, move the framebuffer_release() call to fb_ops.fb_destroy
      instead of doing it in the driver's .remove callback.
      
      Strictly speaking, the code flow in the driver is still wrong because all
      the hardware cleanupd (i.e: iounmap) should be done in .remove while the
      software cleanup (i.e: releasing the framebuffer) should be done in the
      .fb_destroy handler. But this at least makes to match the behavior before
      commit 27599aac ("fbdev: Hot-unplug firmware fb devices on forced removal").
      
      Fixes: 27599aac
      
       ("fbdev: Hot-unplug firmware fb devices on forced removal")
      Suggested-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
      Signed-off-by: default avatarJavier Martinez Canillas <javierm@redhat.com>
      Reviewed-by: default avatarThomas Zimmermann <tzimmermann@suse.de>
      Reviewed-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
      Link: https://patchwork.freedesktop.org/patch/msgid/20220505220631.366371-1-javierm@redhat.com
      
      
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      f94aa46e
    • Javier Martinez Canillas's avatar
      fbdev: efifb: Cleanup fb_info in .fb_destroy rather than .remove · cd3c8abb
      Javier Martinez Canillas authored
      [ Upstream commit d258d00f ]
      
      The driver is calling framebuffer_release() in its .remove callback, but
      this will cause the struct fb_info to be freed too early. Since it could
      be that a reference is still hold to it if user-space opened the fbdev.
      
      This would lead to a use-after-free error if the framebuffer device was
      unregistered but later a user-space process tries to close the fbdev fd.
      
      To prevent this, move the framebuffer_release() call to fb_ops.fb_destroy
      instead of doing it in the driver's .remove callback.
      
      Strictly speaking, the code flow in the driver is still wrong because all
      the hardware cleanupd (i.e: iounmap) should be done in .remove while the
      software cleanup (i.e: releasing the framebuffer) should be done in the
      .fb_destroy handler. But this at least makes to match the behavior before
      commit 27599aac ("fbdev: Hot-unplug firmware fb devices on forced removal").
      
      Fixes: 27599aac
      
       ("fbdev: Hot-unplug firmware fb devices on forced removal")
      Suggested-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
      Signed-off-by: default avatarJavier Martinez Canillas <javierm@redhat.com>
      Reviewed-by: default avatarThomas Zimmermann <tzimmermann@suse.de>
      Reviewed-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
      Link: https://patchwork.freedesktop.org/patch/msgid/20220505220540.366218-1-javierm@redhat.com
      
      
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      cd3c8abb
    • Javier Martinez Canillas's avatar
      fbdev: simplefb: Cleanup fb_info in .fb_destroy rather than .remove · 02eef429
      Javier Martinez Canillas authored
      [ Upstream commit 666b90b3 ]
      
      The driver is calling framebuffer_release() in its .remove callback, but
      this will cause the struct fb_info to be freed too early. Since it could
      be that a reference is still hold to it if user-space opened the fbdev.
      
      This would lead to a use-after-free error if the framebuffer device was
      unregistered but later a user-space process tries to close the fbdev fd.
      
      To prevent this, move the framebuffer_release() call to fb_ops.fb_destroy
      instead of doing it in the driver's .remove callback.
      
      Strictly speaking, the code flow in the driver is still wrong because all
      the hardware cleanupd (i.e: iounmap) should be done in .remove while the
      software cleanup (i.e: releasing the framebuffer) should be done in the
      .fb_destroy handler. But this at least makes to match the behavior before
      commit 27599aac ("fbdev: Hot-unplug firmware fb devices on forced removal").
      
      Fixes: 27599aac
      
       ("fbdev: Hot-unplug firmware fb devices on forced removal")
      Suggested-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
      Signed-off-by: default avatarJavier Martinez Canillas <javierm@redhat.com>
      Reviewed-by: default avatarThomas Zimmermann <tzimmermann@suse.de>
      Reviewed-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
      Link: https://patchwork.freedesktop.org/patch/msgid/20220505220456.366090-1-javierm@redhat.com
      
      
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      02eef429
    • Vladimir Oltean's avatar
      net: mscc: ocelot: avoid corrupting hardware counters when moving VCAP filters · 4ebbf76d
      Vladimir Oltean authored
      [ Upstream commit 93a84170 ]
      
      Given the following order of operations:
      
      (1) we add filter A using tc-flower
      (2) we send a packet that matches it
      (3) we read the filter's statistics to find a hit count of 1
      (4) we add a second filter B with a higher preference than A, and A
          moves one position to the right to make room in the TCAM for it
      (5) we send another packet, and this matches the second filter B
      (6) we read the filter statistics again.
      
      When this happens, the hit count of filter A is 2 and of filter B is 1,
      despite a single packet having matched each filter.
      
      Furthermore, in an alternate history, reading the filter stats a second
      time between steps (3) and (4) makes the hit count of filter A remain at
      1 after step (6), as expected.
      
      The reason why this happens has to do with the filter->stats.pkts field,
      which is written to hardware through the call path below:
      
                     vcap_entry_set
                     /      |      \
                    /       |       \
                   /        |        \
                  /         |         \
      es0_entry_set   is1_entry_set   is2_entry_set
                  \         |         /
                   \        |        /
                    \       |       /
              vcap_data_set(data.counter, ...)
      
      The primary role of filter->stats.pkts is to transport the filter hit
      counters from the last readout all the way from vcap_entry_get() ->
      ocelot_vcap_filter_stats_update() -> ocelot_cls_flower_stats().
      The reason why vcap_entry_set() writes it to hardware is so that the
      counters (saturating and having a limited bit width) are cleared
      after each user space readout.
      
      The writing of filter->stats.pkts to hardware during the TCAM entry
      movement procedure is an unintentional consequence of the code design,
      because the hit count isn't up to date at this point.
      
      So at step (4), when filter A is moved by ocelot_vcap_filter_add() to
      make room for filter B, the hardware hit count is 0 (no packet matched
      on it in the meantime), but filter->stats.pkts is 1, because the last
      readout saw the earlier packet. The movement procedure programs the old
      hit count back to hardware, so this creates the impression to user space
      that more packets have been matched than they really were.
      
      The bug can be seen when running the gact_drop_and_ok_test() from the
      tc_actions.sh selftest.
      
      Fix the issue by reading back the hit count to tmp->stats.pkts before
      migrating the VCAP filter. Sure, this is a best-effort technique, since
      the packets that hit the rule between vcap_entry_get() and
      vcap_entry_set() won't be counted, but at least it allows the counters
      to be reliably used for selftests where the traffic is under control.
      
      The vcap_entry_get() name is a bit unintuitive, but it only reads back
      the counter portion of the TCAM entry, not the entire entry.
      
      The index from which we retrieve the counter is also a bit unintuitive
      (i - 1 during add, i + 1 during del), but this is the way in which TCAM
      entry movement works. The "entry index" isn't a stored integer for a
      TCAM filter, instead it is dynamically computed by
      ocelot_vcap_block_get_filter_index() based on the entry's position in
      the &block->rules list. That position (as well as block->count) is
      automatically updated by ocelot_vcap_filter_add_to_block() on add, and
      by ocelot_vcap_block_remove_filter() on del. So "i" is the new filter
      index, and "i - 1" or "i + 1" respectively are the old addresses of that
      TCAM entry (we only support installing/deleting one filter at a time).
      
      Fixes: b5962294
      
       ("net: mscc: ocelot: Add support for tcam")
      Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      4ebbf76d
    • Vladimir Oltean's avatar
      net: mscc: ocelot: restrict tc-trap actions to VCAP IS2 lookup 0 · e4a33862
      Vladimir Oltean authored
      [ Upstream commit 477d2b91 ]
      
      Once the CPU port was added to the destination port mask of a packet, it
      can never be cleared, so even packets marked as dropped by the MASK_MODE
      of a VCAP IS2 filter will still reach it. This is why we need the
      OCELOT_POLICER_DISCARD to "kill dropped packets dead" and make software
      stop seeing them.
      
      We disallow policer rules from being put on any other chain than the one
      for the first lookup, but we don't do this for "drop" rules, although we
      should. This change is merely ascertaining that the rules dont't
      (completely) work and letting the user know.
      
      The blamed commit is the one that introduced the multi-chain architecture
      in ocelot. Prior to that, we should have always offloaded the filters to
      VCAP IS2 lookup 0, where they did work.
      
      Fixes: 1397a2eb
      
       ("net: mscc: ocelot: create TCAM skeleton from tc filter chains")
      Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      e4a33862
    • Vladimir Oltean's avatar
      net: mscc: ocelot: fix VCAP IS2 filters matching on both lookups · ceffde8c
      Vladimir Oltean authored
      [ Upstream commit 6741e118 ]
      
      The VCAP IS2 TCAM is looked up twice per packet, and each filter can be
      configured to only match during the first, second lookup, or both, or
      none.
      
      The blamed commit wrote the code for making VCAP IS2 filters match only
      on the given lookup. But right below that code, there was another line
      that explicitly made the lookup a "don't care", and this is overwriting
      the lookup we've selected. So the code had no effect.
      
      Some of the more noticeable effects of having filters match on both
      lookups:
      
      - in "tc -s filter show dev swp0 ingress", we see each packet matching a
        VCAP IS2 filter counted twice. This throws off scripts such as
        tools/testing/selftests/net/forwarding/tc_actions.sh and makes them
        fail.
      
      - a "tc-drop" action offloaded to VCAP IS2 needs a policer as well,
        because once the CPU port becomes a member of the destination port
        mask of a packet, nothing removes it, not even a PERMIT/DENY mask mode
        with a port mask of 0. But VCAP IS2 rules with the POLICE_ENA bit in
        the action vector can only appear in the first lookup. What happens
        when a filter matches both lookups is that the action vector is
        combined, and this makes the POLICE_ENA bit ineffective, since the
        last lookup in which it has appeared is the second one. In other
        words, "tc-drop" actions do not drop packets for the CPU port, dropped
        packets are still seen by software unless there was an FDB entry that
        directed those packets to some other place different from the CPU.
      
      The last bit used to work, because in the initial commit b5962294
      ("net: mscc: ocelot: Add support for tcam"), we were writing the FIRST
      field of the VCAP IS2 half key with a 1, not with a "don't care".
      The change to "don't care" was made inadvertently by me in commit
      c1c3993e ("net: mscc: ocelot: generalize existing code for VCAP"),
      which I just realized, and which needs a separate fix from this one,
      for "stable" kernels that lack the commit blamed below.
      
      Fixes: 226e9cd8
      
       ("net: mscc: ocelot: only install TCAM entries into a specific lookup and PAG")
      Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      ceffde8c