Skip to content
  1. May 02, 2024
  2. Apr 29, 2024
  3. Apr 27, 2024
    • Greg Kroah-Hartman's avatar
    • Johan Hovold's avatar
      PCI/ASPM: Fix deadlock when enabling ASPM · 0f7908a0
      Johan Hovold authored
      commit 1e560864 upstream.
      
      A last minute revert in 6.7-final introduced a potential deadlock when
      enabling ASPM during probe of Qualcomm PCIe controllers as reported by
      lockdep:
      
        ============================================
        WARNING: possible recursive locking detected
        6.7.0 #40 Not tainted
        --------------------------------------------
        kworker/u16:5/90 is trying to acquire lock:
        ffffacfa78ced000 (pci_bus_sem){++++}-{3:3}, at: pcie_aspm_pm_state_change+0x58/0xdc
      
                    but task is already holding lock:
        ffffacfa78ced000 (pci_bus_sem){++++}-{3:3}, at: pci_walk_bus+0x34/0xbc
      
                    other info that might help us debug this:
         Possible unsafe locking scenario:
      
               CPU0
               ----
          lock(pci_bus_sem);
          lock(pci_bus_sem);
      
                     *** DEADLOCK ***
      
        Call trace:
         print_deadlock_bug+0x25c/0x348
         __lock_acquire+0x10a4/0x2064
         lock_acquire+0x1e8/0x318
         down_read+0x60/0x184
         pcie_aspm_pm_state_change+0x58/0xdc
         pci_set_full_power_state+0xa8/0x114
         pci_set_power_state+0xc4/0x120
         qcom_pcie_enable_aspm+0x1c/0x3c [pcie_qcom]
         pci_walk_bus+0x64/0xbc
         qcom_pcie_host_post_init_2_7_0+0x28/0x34 [pcie_qcom]
      
      The deadlock can easily be reproduced on machines like the Lenovo ThinkPad
      X13s by adding a delay to increase the race window during asynchronous
      probe where another thread can take a write lock.
      
      Add a new pci_set_power_state_locked() and associated helper functions that
      can be called with the PCI bus semaphore held to avoid taking the read lock
      twice.
      
      Link: https://lore.kernel.org/r/ZZu0qx2cmn7IwTyQ@hovoldconsulting.com
      Link: https://lore.kernel.org/r/20240130100243.11011-1-johan+linaro@kernel.org
      Fixes: f93e71ae
      
       ("Revert "PCI/ASPM: Remove pcie_aspm_pm_state_change()"")
      Signed-off-by: default avatarJohan Hovold <johan+linaro@kernel.org>
      Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
      Cc: <stable@vger.kernel.org>	# 6.7
      [bhelgaas: backported to v6.1.y, which contains b9c370b6 ("Revert
       "PCI/ASPM: Remove pcie_aspm_pm_state_change()""), a backport of
       f93e71ae.  This omits the drivers/pci/controller/dwc/pcie-qcom.c hunk
       that updates qcom_pcie_enable_aspm(), which was added by 9f4f3dfa
      
      
       ("PCI: qcom: Enable ASPM for platforms supporting 1.9.0 ops"), which is not
       present in v6.1.87.]
      Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0f7908a0
    • Namjae Jeon's avatar
      ksmbd: common: use struct_group_attr instead of struct_group for network_open_info · 67a87712
      Namjae Jeon authored
      commit 0268a7cc upstream.
      
      4byte padding cause the connection issue with the applications of MacOS.
      smb2_close response size increases by 4 bytes by padding, And the smb
      client of MacOS check it and stop the connection. This patch use
      struct_group_attr instead of struct_group for network_open_info to use
       __packed to avoid padding.
      
      Fixes: 0015eb6e
      
       ("smb: client, common: fix fortify warnings")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarNamjae Jeon <linkinjeon@kernel.org>
      Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      67a87712
    • Marios Makassikis's avatar
      ksmbd: clear RENAME_NOREPLACE before calling vfs_rename · 4687606d
      Marios Makassikis authored
      commit 4973b04d
      
       upstream.
      
      File overwrite case is explicitly handled, so it is not necessary to
      pass RENAME_NOREPLACE to vfs_rename.
      
      Clearing the flag fixes rename operations when the share is a ntfs-3g
      mount. The latter uses an older version of fuse with no support for
      flags in the ->rename op.
      
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarMarios Makassikis <mmakassikis@freebox.fr>
      Acked-by: default avatarNamjae Jeon <linkinjeon@kernel.org>
      Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4687606d
    • Namjae Jeon's avatar
      ksmbd: validate request buffer size in smb2_allocate_rsp_buf() · 21ff9d7d
      Namjae Jeon authored
      commit 17cf0c27
      
       upstream.
      
      The response buffer should be allocated in smb2_allocate_rsp_buf
      before validating request. But the fields in payload as well as smb2 header
      is used in smb2_allocate_rsp_buf(). This patch add simple buffer size
      validation to avoid potencial out-of-bounds in request buffer.
      
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarNamjae Jeon <linkinjeon@kernel.org>
      Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      21ff9d7d
    • Namjae Jeon's avatar
      ksmbd: fix slab-out-of-bounds in smb2_allocate_rsp_buf · b80ba648
      Namjae Jeon authored
      commit c119f4ed
      
       upstream.
      
      If ->ProtocolId is SMB2_TRANSFORM_PROTO_NUM, smb2 request size
      validation could be skipped. if request size is smaller than
      sizeof(struct smb2_query_info_req), slab-out-of-bounds read can happen in
      smb2_allocate_rsp_buf(). This patch allocate response buffer after
      decrypting transform request. smb3_decrypt_req() will validate transform
      request size and avoid slab-out-of-bound in smb2_allocate_rsp_buf().
      
      Reported-by: default avatarNorbert Szetei <norbert@doyensec.com>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarNamjae Jeon <linkinjeon@kernel.org>
      Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b80ba648
    • Arınç ÜNAL's avatar
      net: dsa: mt7530: fix enabling EEE on MT7531 switch on all boards · 7d51db45
      Arınç ÜNAL authored
      commit 06dfcd40 upstream.
      
      The commit 40b5d2f1 ("net: dsa: mt7530: Add support for EEE features")
      brought EEE support but did not enable EEE on MT7531 switch MACs. EEE is
      enabled on MT7531 switch MACs by pulling the LAN2LED0 pin low on the board
      (bootstrapping), unsetting the EEE_DIS bit on the trap register, or setting
      the internal EEE switch bit on the CORE_PLL_GROUP4 register. Thanks to
      SkyLake Huang (黃啟澤) from MediaTek for providing information on the
      internal EEE switch bit.
      
      There are existing boards that were not designed to pull the pin low.
      Because of that, the EEE status currently depends on the board design.
      
      The EEE_DIS bit on the trap pertains to the LAN2LED0 pin which is usually
      used to control an LED. Once the bit is unset, the pin will be low. That
      will make the active low LED turn on. The pin is controlled by the switch
      PHY. It seems that the PHY controls the pin in the way that it inverts the
      pin state. That means depending on the wiring of the LED connected to
      LAN2LED0 on the board, the LED may be on without an active link.
      
      To not cause this unwanted behaviour whilst enabling EEE on all boards, set
      the internal EEE switch bit on the CORE_PLL_GROUP4 register.
      
      My testing on MT7531 shows a certain amount of traffic loss when EEE is
      enabled. That said, I haven't come across a board that enables EEE. So
      enable EEE on the switch MACs but disable EEE advertisement on the switch
      PHYs. This way, we don't change the behaviour of the majority of the boards
      that have this switch. The mediatek-ge PHY driver already disables EEE
      advertisement on the switch PHYs but my testing shows that it is somehow
      enabled afterwards. Disabling EEE advertisement before the PHY driver
      initialises keeps it off.
      
      With this change, EEE can now be enabled using ethtool.
      
      Fixes: 40b5d2f1
      
       ("net: dsa: mt7530: Add support for EEE features")
      Reviewed-by: default avatarFlorian Fainelli <florian.fainelli@broadcom.com>
      Signed-off-by: default avatarArınç ÜNAL <arinc.unal@arinc9.com>
      Tested-by: default avatarDaniel Golle <daniel@makrotopia.org>
      Reviewed-by: default avatarDaniel Golle <daniel@makrotopia.org>
      Link: https://lore.kernel.org/r/20240408-for-net-mt7530-fix-eee-for-mt7531-mt7988-v3-1-84fdef1f008b@arinc9.com
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7d51db45
    • Arınç ÜNAL's avatar
      net: dsa: mt7530: fix improper frames on all 25MHz and 40MHz XTAL MT7530 · 41a004ff
      Arınç ÜNAL authored
      commit 5f563c31 upstream.
      
      The MT7530 switch after reset initialises with a core clock frequency that
      works with a 25MHz XTAL connected to it. For 40MHz XTAL, the core clock
      frequency must be set to 500MHz.
      
      The mt7530_pll_setup() function is responsible of setting the core clock
      frequency. Currently, it runs on MT7530 with 25MHz and 40MHz XTAL. This
      causes MT7530 switch with 25MHz XTAL to egress and ingress frames
      improperly.
      
      Introduce a check to run it only on MT7530 with 40MHz XTAL.
      
      The core clock frequency is set by writing to a switch PHY's register.
      Access to the PHY's register is done via the MDIO bus the switch is also
      on. Therefore, it works only when the switch makes switch PHYs listen on
      the MDIO bus the switch is on. This is controlled either by the state of
      the ESW_P1_LED_1 pin after reset deassertion or modifying bit 5 of the
      modifiable trap register.
      
      When ESW_P1_LED_1 is pulled high, PHY indirect access is used. That means
      accessing PHY registers via the PHY indirect access control register of the
      switch.
      
      When ESW_P1_LED_1 is pulled low, PHY direct access is used. That means
      accessing PHY registers via the MDIO bus the switch is on.
      
      For MT7530 switch with 40MHz XTAL on a board with ESW_P1_LED_1 pulled high,
      the core clock frequency won't be set to 500MHz, causing the switch to
      egress and ingress frames improperly.
      
      Run mt7530_pll_setup() after PHY direct access is set on the modifiable
      trap register.
      
      With these two changes, all MT7530 switches with 25MHz and 40MHz, and
      P1_LED_1 pulled high or low, will egress and ingress frames properly.
      
      Link: https://github.com/BPI-SINOVOIP/BPI-R2-bsp/blob/4a5dd143f2172ec97a2872fa29c7c4cd520f45b5/linux-mt/drivers/net/ethernet/mediatek/gsw_mt7623.c#L1039
      Fixes: b8f126a8
      
       ("net-next: dsa: add dsa support for Mediatek MT7530 switch")
      Signed-off-by: default avatarArınç ÜNAL <arinc.unal@arinc9.com>
      Link: https://lore.kernel.org/r/20240320-for-net-mt7530-fix-25mhz-xtal-with-direct-phy-access-v1-1-d92f605f1160@arinc9.com
      
      
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      41a004ff
    • Vladimir Oltean's avatar
      net: dsa: introduce preferred_default_local_cpu_port and use on MT7530 · d9c2f69c
      Vladimir Oltean authored
      commit b79d7c14 upstream.
      
      Since the introduction of the OF bindings, DSA has always had a policy that
      in case multiple CPU ports are present in the device tree, the numerically
      smallest one is always chosen.
      
      The MT7530 switch family, except the switch on the MT7988 SoC, has 2 CPU
      ports, 5 and 6, where port 6 is preferable on the MT7531BE switch because
      it has higher bandwidth.
      
      The MT7530 driver developers had 3 options:
      - to modify DSA when the MT7531 switch support was introduced, such as to
        prefer the better port
      - to declare both CPU ports in device trees as CPU ports, and live with the
        sub-optimal performance resulting from not preferring the better port
      - to declare just port 6 in the device tree as a CPU port
      
      Of course they chose the path of least resistance (3rd option), kicking the
      can down the road. The hardware description in the device tree is supposed
      to be stable - developers are not supposed to adopt the strategy of
      piecemeal hardware description, where the device tree is updated in
      lockstep with the features that the kernel currently supports.
      
      Now, as a result of the fact that they did that, any attempts to modify the
      device tree and describe both CPU ports as CPU ports would make DSA change
      its default selection from port 6 to 5, effectively resulting in a
      performance degradation visible to users with the MT7531BE switch as can be
      seen below.
      
      Without preferring port 6:
      
      [ ID][Role] Interval           Transfer     Bitrate         Retr
      [  5][TX-C]   0.00-20.00  sec   374 MBytes   157 Mbits/sec  734    sender
      [  5][TX-C]   0.00-20.00  sec   373 MBytes   156 Mbits/sec    receiver
      [  7][RX-C]   0.00-20.00  sec  1.81 GBytes   778 Mbits/sec    0    sender
      [  7][RX-C]   0.00-20.00  sec  1.81 GBytes   777 Mbits/sec    receiver
      
      With preferring port 6:
      
      [ ID][Role] Interval           Transfer     Bitrate         Retr
      [  5][TX-C]   0.00-20.00  sec  1.99 GBytes   856 Mbits/sec  273    sender
      [  5][TX-C]   0.00-20.00  sec  1.99 GBytes   855 Mbits/sec    receiver
      [  7][RX-C]   0.00-20.00  sec  1.72 GBytes   737 Mbits/sec   15    sender
      [  7][RX-C]   0.00-20.00  sec  1.71 GBytes   736 Mbits/sec    receiver
      
      Using one port for WAN and the other ports for LAN is a very popular use
      case which is what this test emulates.
      
      As such, this change proposes that we retroactively modify stable kernels
      (which don't support the modification of the CPU port assignments, so as to
      let user space fix the problem and restore the throughput) to keep the
      mt7530 driver preferring port 6 even with device trees where the hardware
      is more fully described.
      
      Fixes: c288575f
      
       ("net: dsa: mt7530: Add the support of MT7531 switch")
      Signed-off-by: default avatarVladimir Oltean <olteanv@gmail.com>
      Signed-off-by: default avatarArınç ÜNAL <arinc.unal@arinc9.com>
      Reviewed-by: default avatarRussell King (Oracle) <rmk+kernel@armlinux.org.uk>
      Reviewed-by: default avatarFlorian Fainelli <florian.fainelli@broadcom.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarArınç ÜNAL <arinc.unal@arinc9.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d9c2f69c
    • Arınç ÜNAL's avatar
      net: dsa: mt7530: set all CPU ports in MT7531_CPU_PMAP · 013c787d
      Arınç ÜNAL authored
      commit ff221029
      
       upstream.
      
      MT7531_CPU_PMAP represents the destination port mask for trapped-to-CPU
      frames (further restricted by PCR_MATRIX).
      
      Currently the driver sets the first CPU port as the single port in this bit
      mask, which works fine regardless of whether the device tree defines port
      5, 6 or 5+6 as CPU ports. This is because the logic coincides with DSA's
      logic of picking the first CPU port as the CPU port that all user ports are
      affine to, by default.
      
      An upcoming change would like to influence DSA's selection of the default
      CPU port to no longer be the first one, and in that case, this logic needs
      adaptation.
      
      Since there is no observed leakage or duplication of frames if all CPU
      ports are defined in this bit mask, simply include them all.
      
      Suggested-by: default avatarRussell King (Oracle) <linux@armlinux.org.uk>
      Suggested-by: default avatarVladimir Oltean <olteanv@gmail.com>
      Signed-off-by: default avatarArınç ÜNAL <arinc.unal@arinc9.com>
      Reviewed-by: default avatarVladimir Oltean <olteanv@gmail.com>
      Reviewed-by: default avatarRussell King (Oracle) <rmk+kernel@armlinux.org.uk>
      Reviewed-by: default avatarFlorian Fainelli <florian.fainelli@broadcom.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarArınç ÜNAL <arinc.unal@arinc9.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      013c787d
    • Jeongjun Park's avatar
      nilfs2: fix OOB in nilfs_set_de_type · 897ac530
      Jeongjun Park authored
      commit c4a7dc95 upstream.
      
      The size of the nilfs_type_by_mode array in the fs/nilfs2/dir.c file is
      defined as "S_IFMT >> S_SHIFT", but the nilfs_set_de_type() function,
      which uses this array, specifies the index to read from the array in the
      same way as "(mode & S_IFMT) >> S_SHIFT".
      
      static void nilfs_set_de_type(struct nilfs_dir_entry *de, struct inode
       *inode)
      {
      	umode_t mode = inode->i_mode;
      
      	de->file_type = nilfs_type_by_mode[(mode & S_IFMT)>>S_SHIFT]; // oob
      }
      
      However, when the index is determined this way, an out-of-bounds (OOB)
      error occurs by referring to an index that is 1 larger than the array size
      when the condition "mode & S_IFMT == S_IFMT" is satisfied.  Therefore, a
      patch to resize the nilfs_type_by_mode array should be applied to prevent
      OOB errors.
      
      Link: https://lkml.kernel.org/r/20240415182048.7144-1-konishi.ryusuke@gmail.com
      
      
      Reported-by: default avatar <syzbot+2e22057de05b9f3b30d8@syzkaller.appspotmail.com>
      Closes: https://syzkaller.appspot.com/bug?extid=2e22057de05b9f3b30d8
      Fixes: 2ba466d7
      
       ("nilfs2: directory entry operations")
      Signed-off-by: default avatarJeongjun Park <aha310510@gmail.com>
      Signed-off-by: default avatarRyusuke Konishi <konishi.ryusuke@gmail.com>
      Tested-by: default avatarRyusuke Konishi <konishi.ryusuke@gmail.com>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      897ac530
    • Qiang Zhang's avatar
      bootconfig: use memblock_free_late to free xbc memory to buddy · 1e7feb31
      Qiang Zhang authored
      commit 89f9a1e8 upstream.
      
      On the time to free xbc memory in xbc_exit(), memblock may has handed
      over memory to buddy allocator. So it doesn't make sense to free memory
      back to memblock. memblock_free() called by xbc_exit() even causes UAF bugs
      on architectures with CONFIG_ARCH_KEEP_MEMBLOCK disabled like x86.
      Following KASAN logs shows this case.
      
      This patch fixes the xbc memory free problem by calling memblock_free()
      in early xbc init error rewind path and calling memblock_free_late() in
      xbc exit path to free memory to buddy allocator.
      
      [    9.410890] ==================================================================
      [    9.418962] BUG: KASAN: use-after-free in memblock_isolate_range+0x12d/0x260
      [    9.426850] Read of size 8 at addr ffff88845dd30000 by task swapper/0/1
      
      [    9.435901] CPU: 9 PID: 1 Comm: swapper/0 Tainted: G     U             6.9.0-rc3-00208-g586b5dfb51b9 #5
      [    9.446403] Hardware name: Intel Corporation RPLP LP5 (CPU:RaptorLake)/RPLP LP5 (ID:13), BIOS IRPPN02.01.01.00.00.19.015.D-00000000 Dec 28 2023
      [    9.460789] Call Trace:
      [    9.463518]  <TASK>
      [    9.465859]  dump_stack_lvl+0x53/0x70
      [    9.469949]  print_report+0xce/0x610
      [    9.473944]  ? __virt_addr_valid+0xf5/0x1b0
      [    9.478619]  ? memblock_isolate_range+0x12d/0x260
      [    9.483877]  kasan_report+0xc6/0x100
      [    9.487870]  ? memblock_isolate_range+0x12d/0x260
      [    9.493125]  memblock_isolate_range+0x12d/0x260
      [    9.498187]  memblock_phys_free+0xb4/0x160
      [    9.502762]  ? __pfx_memblock_phys_free+0x10/0x10
      [    9.508021]  ? mutex_unlock+0x7e/0xd0
      [    9.512111]  ? __pfx_mutex_unlock+0x10/0x10
      [    9.516786]  ? kernel_init_freeable+0x2d4/0x430
      [    9.521850]  ? __pfx_kernel_init+0x10/0x10
      [    9.526426]  xbc_exit+0x17/0x70
      [    9.529935]  kernel_init+0x38/0x1e0
      [    9.533829]  ? _raw_spin_unlock_irq+0xd/0x30
      [    9.538601]  ret_from_fork+0x2c/0x50
      [    9.542596]  ? __pfx_kernel_init+0x10/0x10
      [    9.547170]  ret_from_fork_asm+0x1a/0x30
      [    9.551552]  </TASK>
      
      [    9.555649] The buggy address belongs to the physical page:
      [    9.561875] page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x1 pfn:0x45dd30
      [    9.570821] flags: 0x200000000000000(node=0|zone=2)
      [    9.576271] page_type: 0xffffffff()
      [    9.580167] raw: 0200000000000000 ffffea0011774c48 ffffea0012ba1848 0000000000000000
      [    9.588823] raw: 0000000000000001 0000000000000000 00000000ffffffff 0000000000000000
      [    9.597476] page dumped because: kasan: bad access detected
      
      [    9.605362] Memory state around the buggy address:
      [    9.610714]  ffff88845dd2ff00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      [    9.618786]  ffff88845dd2ff80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      [    9.626857] >ffff88845dd30000: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
      [    9.634930]                    ^
      [    9.638534]  ffff88845dd30080: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
      [    9.646605]  ffff88845dd30100: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
      [    9.654675] ==================================================================
      
      Link: https://lore.kernel.org/all/20240414114944.1012359-1-qiang4.zhang@linux.intel.com/
      
      Fixes: 40caa127
      
       ("init: bootconfig: Remove all bootconfig data when the init memory is removed")
      Cc: Stable@vger.kernel.org
      Signed-off-by: default avatarQiang Zhang <qiang4.zhang@intel.com>
      Acked-by: default avatarMasami Hiramatsu (Google) <mhiramat@kernel.org>
      Signed-off-by: default avatarMasami Hiramatsu (Google) <mhiramat@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1e7feb31
    • Dave Airlie's avatar
      nouveau: fix instmem race condition around ptr stores · ad74d208
      Dave Airlie authored
      commit fff1386c upstream.
      
      Running a lot of VK CTS in parallel against nouveau, once every
      few hours you might see something like this crash.
      
      BUG: kernel NULL pointer dereference, address: 0000000000000008
      PGD 8000000114e6e067 P4D 8000000114e6e067 PUD 109046067 PMD 0
      Oops: 0000 [#1] PREEMPT SMP PTI
      CPU: 7 PID: 53891 Comm: deqp-vk Not tainted 6.8.0-rc6+ #27
      Hardware name: Gigabyte Technology Co., Ltd. Z390 I AORUS PRO WIFI/Z390 I AORUS PRO WIFI-CF, BIOS F8 11/05/2021
      RIP: 0010:gp100_vmm_pgt_mem+0xe3/0x180 [nouveau]
      Code: c7 48 01 c8 49 89 45 58 85 d2 0f 84 95 00 00 00 41 0f b7 46 12 49 8b 7e 08 89 da 42 8d 2c f8 48 8b 47 08 41 83 c7 01 48 89 ee <48> 8b 40 08 ff d0 0f 1f 00 49 8b 7e 08 48 89 d9 48 8d 75 04 48 c1
      RSP: 0000:ffffac20c5857838 EFLAGS: 00010202
      RAX: 0000000000000000 RBX: 00000000004d8001 RCX: 0000000000000001
      RDX: 00000000004d8001 RSI: 00000000000006d8 RDI: ffffa07afe332180
      RBP: 00000000000006d8 R08: ffffac20c5857ad0 R09: 0000000000ffff10
      R10: 0000000000000001 R11: ffffa07af27e2de0 R12: 000000000000001c
      R13: ffffac20c5857ad0 R14: ffffa07a96fe9040 R15: 000000000000001c
      FS:  00007fe395eed7c0(0000) GS:ffffa07e2c980000(0000) knlGS:0000000000000000
      CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      CR2: 0000000000000008 CR3: 000000011febe001 CR4: 00000000003706f0
      DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
      DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
      Call Trace:
      
      ...
      
       ? gp100_vmm_pgt_mem+0xe3/0x180 [nouveau]
       ? gp100_vmm_pgt_mem+0x37/0x180 [nouveau]
       nvkm_vmm_iter+0x351/0xa20 [nouveau]
       ? __pfx_nvkm_vmm_ref_ptes+0x10/0x10 [nouveau]
       ? __pfx_gp100_vmm_pgt_mem+0x10/0x10 [nouveau]
       ? __pfx_gp100_vmm_pgt_mem+0x10/0x10 [nouveau]
       ? __lock_acquire+0x3ed/0x2170
       ? __pfx_gp100_vmm_pgt_mem+0x10/0x10 [nouveau]
       nvkm_vmm_ptes_get_map+0xc2/0x100 [nouveau]
       ? __pfx_nvkm_vmm_ref_ptes+0x10/0x10 [nouveau]
       ? __pfx_gp100_vmm_pgt_mem+0x10/0x10 [nouveau]
       nvkm_vmm_map_locked+0x224/0x3a0 [nouveau]
      
      Adding any sort of useful debug usually makes it go away, so I hand
      wrote the function in a line, and debugged the asm.
      
      Every so often pt->memory->ptrs is NULL. This ptrs ptr is set in
      the nv50_instobj_acquire called from nvkm_kmap.
      
      If Thread A and Thread B both get to nv50_instobj_acquire around
      the same time, and Thread A hits the refcount_set line, and in
      lockstep thread B succeeds at refcount_inc_not_zero, there is a
      chance the ptrs value won't have been stored since refcount_set
      is unordered. Force a memory barrier here, I picked smp_mb, since
      we want it on all CPUs and it's write followed by a read.
      
      v2: use paired smp_rmb/smp_wmb.
      
      Cc: <stable@vger.kernel.org>
      Fixes: be55287a
      
       ("drm/nouveau/imem/nv50: embed nvkm_instobj directly into nv04_instobj")
      Signed-off-by: default avatarDave Airlie <airlied@redhat.com>
      Signed-off-by: default avatarDanilo Krummrich <dakr@redhat.com>
      Link: https://patchwork.freedesktop.org/patch/msgid/20240411011510.2546857-1-airlied@gmail.com
      
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ad74d208