Skip to content

Commit 9b340ae

Browse files
airliedDanilo Krummrich
authored and
Danilo Krummrich
committed
nouveau/firmware: use dma non-coherent allocator
Currently, enabling SG_DEBUG in the kernel will cause nouveau to hit a BUG() on startup, when the iommu is enabled: kernel BUG at include/linux/scatterlist.h:187! invalid opcode: 0000 [Freescale#1] PREEMPT SMP NOPTI CPU: 7 PID: 930 Comm: (udev-worker) Not tainted 6.9.0-rc3Lyude-Test+ Freescale#30 Hardware name: MSI MS-7A39/A320M GAMING PRO (MS-7A39), BIOS 1.I0 01/22/2019 RIP: 0010:sg_init_one+0x85/0xa0 Code: 69 88 32 01 83 e1 03 f6 c3 03 75 20 a8 01 75 1e 48 09 cb 41 89 54 24 08 49 89 1c 24 41 89 6c 24 0c 5b 5d 41 5c e9 7b b9 88 00 <0f> 0b 0f 0b 0f 0b 48 8b 05 5e 46 9a 01 eb b2 66 66 2e 0f 1f 84 00 RSP: 0018:ffffa776017bf6a0 EFLAGS: 00010246 RAX: 0000000000000000 RBX: ffffa77600d87000 RCX: 000000000000002b RDX: 0000000000000001 RSI: 0000000000000000 RDI: ffffa77680d87000 RBP: 000000000000e000 R08: 0000000000000000 R09: 0000000000000000 R10: ffff98f4c46aa508 R11: 0000000000000000 R12: ffff98f4c46aa508 R13: ffff98f4c46aa008 R14: ffffa77600d4a000 R15: ffffa77600d4a018 FS: 00007feeb5aae980(0000) GS:ffff98f5c4dc0000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f22cb9a4520 CR3: 00000001043ba000 CR4: 00000000003506f0 Call Trace: <TASK> ? die+0x36/0x90 ? do_trap+0xdd/0x100 ? sg_init_one+0x85/0xa0 ? do_error_trap+0x65/0x80 ? sg_init_one+0x85/0xa0 ? exc_invalid_op+0x50/0x70 ? sg_init_one+0x85/0xa0 ? asm_exc_invalid_op+0x1a/0x20 ? sg_init_one+0x85/0xa0 nvkm_firmware_ctor+0x14a/0x250 [nouveau] nvkm_falcon_fw_ctor+0x42/0x70 [nouveau] ga102_gsp_booter_ctor+0xb4/0x1a0 [nouveau] r535_gsp_oneinit+0xb3/0x15f0 [nouveau] ? srso_return_thunk+0x5/0x5f ? srso_return_thunk+0x5/0x5f ? nvkm_udevice_new+0x95/0x140 [nouveau] ? srso_return_thunk+0x5/0x5f ? srso_return_thunk+0x5/0x5f ? ktime_get+0x47/0xb0 Fix this by using the non-coherent allocator instead, I think there might be a better answer to this, but it involve ripping up some of APIs using sg lists. Cc: [email protected] Fixes: 2541626 ("drm/nouveau/acr: use common falcon HS FW code for ACR FWs") Signed-off-by: Dave Airlie <[email protected]> Signed-off-by: Danilo Krummrich <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent fd45cc6 commit 9b340ae

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

drivers/gpu/drm/nouveau/nvkm/core/firmware.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ nvkm_firmware_dtor(struct nvkm_firmware *fw)
205205
break;
206206
case NVKM_FIRMWARE_IMG_DMA:
207207
nvkm_memory_unref(&memory);
208-
dma_free_coherent(fw->device->dev, sg_dma_len(&fw->mem.sgl), fw->img, fw->phys);
208+
dma_free_noncoherent(fw->device->dev, sg_dma_len(&fw->mem.sgl),
209+
fw->img, fw->phys, DMA_TO_DEVICE);
209210
break;
210211
case NVKM_FIRMWARE_IMG_SGT:
211212
nvkm_memory_unref(&memory);
@@ -236,10 +237,12 @@ nvkm_firmware_ctor(const struct nvkm_firmware_func *func, const char *name,
236237
break;
237238
case NVKM_FIRMWARE_IMG_DMA: {
238239
dma_addr_t addr;
239-
240240
len = ALIGN(fw->len, PAGE_SIZE);
241241

242-
fw->img = dma_alloc_coherent(fw->device->dev, len, &addr, GFP_KERNEL);
242+
fw->img = dma_alloc_noncoherent(fw->device->dev,
243+
len, &addr,
244+
DMA_TO_DEVICE,
245+
GFP_KERNEL);
243246
if (fw->img) {
244247
memcpy(fw->img, src, fw->len);
245248
fw->phys = addr;

drivers/gpu/drm/nouveau/nvkm/falcon/fw.c

+6
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ nvkm_falcon_fw_boot(struct nvkm_falcon_fw *fw, struct nvkm_subdev *user,
8989
nvkm_falcon_fw_dtor_sigs(fw);
9090
}
9191

92+
/* after last write to the img, sync dma mappings */
93+
dma_sync_single_for_device(fw->fw.device->dev,
94+
fw->fw.phys,
95+
sg_dma_len(&fw->fw.mem.sgl),
96+
DMA_TO_DEVICE);
97+
9298
FLCNFW_DBG(fw, "resetting");
9399
fw->func->reset(fw);
94100

0 commit comments

Comments
 (0)