kernel_samsung_a53x/drivers/gpu/drm/nouveau
Dave Airlie dc108b87d9 nouveau: fix instmem race condition around ptr stores
commit fff1386cc889d8fb4089d285f883f8cba62d82ce 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: be55287aa5ba ("drm/nouveau/imem/nv50: embed nvkm_instobj directly into nv04_instobj")
Signed-off-by: Dave Airlie <airlied@redhat.com>
Signed-off-by: Danilo Krummrich <dakr@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20240411011510.2546857-1-airlied@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-11-19 11:32:23 +01:00
..
dispnv04 Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
dispnv50 Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
include Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nvif Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nvkm nouveau: fix instmem race condition around ptr stores 2024-11-19 11:32:23 +01:00
Kbuild Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
Kconfig Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_abi16.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_abi16.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_acpi.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_acpi.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_backlight.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_bios.c drm: nv04: Fix out of bounds access 2024-11-19 11:32:21 +01:00
nouveau_bios.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_bo.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_bo.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_bo0039.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_bo74c1.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_bo85b5.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_bo90b5.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_bo5039.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_bo9039.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_boa0b5.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_chan.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_chan.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_connector.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_connector.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_crtc.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_debugfs.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_debugfs.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_display.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_display.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_dma.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_dma.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_dmem.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_dmem.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_dp.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_drm.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_drv.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_encoder.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_fbcon.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_fbcon.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_fence.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_fence.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_gem.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_gem.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_hwmon.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_hwmon.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_ioc32.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_ioctl.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_led.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_led.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_mem.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_mem.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_nvif.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_platform.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_platform.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_prime.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_reg.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_sgdma.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_svm.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_svm.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_ttm.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_ttm.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_usif.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_usif.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_vga.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_vga.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nouveau_vmm.c nouveau/vmm: don't set addr on the fail path to avoid warning 2024-11-18 12:12:59 +01:00
nouveau_vmm.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nv04_fbcon.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nv04_fence.c drm/nouveau/fence:: fix warning directly dereferencing a rcu pointer 2024-11-18 12:12:39 +01:00
nv10_fence.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nv10_fence.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nv17_fence.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nv50_display.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nv50_fbcon.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nv50_fence.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nv84_fence.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nvc0_fbcon.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nvc0_fence.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00