Skip to content

Commit da67179

Browse files
committed
drm/nouveau/gsp: Allocate fwsec-sb at boot
At the moment - the memory allocation for fwsec-sb is created as-needed and is released after being used. Typically this is at some point well after driver load, which can cause runtime suspend/resume to initially work on driver load but then later fail on a machine that has been running for long enough with sufficiently high enough memory pressure: kworker/7:1: page allocation failure: order:5, mode:0xcc0(GFP_KERNEL), nodemask=(null),cpuset=/,mems_allowed=0 CPU: 7 UID: 0 PID: 875159 Comm: kworker/7:1 Not tainted 6.17.8-300.fc43.x86_64 #1 PREEMPT(lazy) Hardware name: SLIMBOOK Executive/Executive, BIOS N.1.10GRU06 02/02/2024 Workqueue: pm pm_runtime_work Call Trace: <TASK> dump_stack_lvl+0x5d/0x80 warn_alloc+0x163/0x190 ? __alloc_pages_direct_compact+0x1b3/0x220 __alloc_pages_slowpath.constprop.0+0x57a/0xb10 __alloc_frozen_pages_noprof+0x334/0x350 __alloc_pages_noprof+0xe/0x20 __dma_direct_alloc_pages.isra.0+0x1eb/0x330 dma_direct_alloc_pages+0x3c/0x190 dma_alloc_pages+0x29/0x130 nvkm_firmware_ctor+0x1ae/0x280 [nouveau] nvkm_falcon_fw_ctor+0x3e/0x60 [nouveau] nvkm_gsp_fwsec+0x10e/0x2c0 [nouveau] ? sysvec_apic_timer_interrupt+0xe/0x90 nvkm_gsp_fwsec_sb+0x27/0x70 [nouveau] tu102_gsp_fini+0x65/0x110 [nouveau] ? ktime_get+0x3c/0xf0 nvkm_subdev_fini+0x67/0xc0 [nouveau] nvkm_device_fini+0x94/0x140 [nouveau] nvkm_udevice_fini+0x50/0x70 [nouveau] nvkm_object_fini+0xb1/0x140 [nouveau] nvkm_object_fini+0x70/0x140 [nouveau] ? __pfx_pci_pm_runtime_suspend+0x10/0x10 nouveau_do_suspend+0xe4/0x170 [nouveau] nouveau_pmops_runtime_suspend+0x3e/0xb0 [nouveau] pci_pm_runtime_suspend+0x67/0x1a0 ? __pfx_pci_pm_runtime_suspend+0x10/0x10 __rpm_callback+0x45/0x1f0 ? __pfx_pci_pm_runtime_suspend+0x10/0x10 rpm_callback+0x6d/0x80 rpm_suspend+0xe5/0x5e0 ? finish_task_switch.isra.0+0x99/0x2c0 pm_runtime_work+0x98/0xb0 process_one_work+0x18f/0x350 worker_thread+0x25a/0x3a0 ? __pfx_worker_thread+0x10/0x10 kthread+0xf9/0x240 ? __pfx_kthread+0x10/0x10 ? __pfx_kthread+0x10/0x10 ret_from_fork+0xf1/0x110 ? __pfx_kthread+0x10/0x10 ret_from_fork_asm+0x1a/0x30 </TASK> The reason this happens is because the fwsec-sb firmware image only supports being booted from a contiguous coherent sysmem allocation. If a system runs into enough memory fragmentation from memory pressure, such as what can happen on systems with low amounts of memory, this can lead to a situation where it later becomes impossible to find space for a large enough contiguous allocation to hold fwsec-sb. This causes us to fail to boot the firmware image, causing the GPU to fail booting and causing the driver to fail. Since this firmware can't use non-contiguous allocations, the best solution to avoid this issue is to simply allocate the memory for fwsec-sb during initial driver-load, and reuse the memory allocation when fwsec-sb needs to be used. We then release the memory allocations on driver unload. Signed-off-by: Lyude Paul <lyude@redhat.com> Fixes: 594766c ("drm/nouveau/gsp: move booter handling to GPU-specific code") Cc: <stable@vger.kernel.org> # v6.16+ Reviewed-by: Timur Tabi <ttabi@nvidia.com> Link: https://patch.msgid.link/20251202175918.63533-1-lyude@redhat.com
1 parent 1a7a7b8 commit da67179

File tree

4 files changed

+58
-20
lines changed

4 files changed

+58
-20
lines changed

drivers/gpu/drm/nouveau/include/nvkm/subdev/gsp.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ struct nvkm_gsp {
7373

7474
const struct firmware *bl;
7575
const struct firmware *rm;
76+
77+
struct {
78+
struct nvkm_falcon_fw sb;
79+
} falcon;
7680
} fws;
7781

7882
struct nvkm_firmware fw;

drivers/gpu/drm/nouveau/nvkm/subdev/gsp/fwsec.c

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -259,18 +259,16 @@ nvkm_gsp_fwsec_v3(struct nvkm_gsp *gsp, const char *name,
259259
}
260260

261261
static int
262-
nvkm_gsp_fwsec(struct nvkm_gsp *gsp, const char *name, u32 init_cmd)
262+
nvkm_gsp_fwsec_init(struct nvkm_gsp *gsp, struct nvkm_falcon_fw *fw, const char *name, u32 init_cmd)
263263
{
264264
struct nvkm_subdev *subdev = &gsp->subdev;
265265
struct nvkm_device *device = subdev->device;
266266
struct nvkm_bios *bios = device->bios;
267267
const union nvfw_falcon_ucode_desc *desc;
268268
struct nvbios_pmuE flcn_ucode;
269-
u8 idx, ver, hdr;
270269
u32 data;
271270
u16 size, vers;
272-
struct nvkm_falcon_fw fw = {};
273-
u32 mbox0 = 0;
271+
u8 idx, ver, hdr;
274272
int ret;
275273

276274
/* Lookup in VBIOS. */
@@ -291,8 +289,8 @@ nvkm_gsp_fwsec(struct nvkm_gsp *gsp, const char *name, u32 init_cmd)
291289
vers = (desc->v2.Hdr & 0x0000ff00) >> 8;
292290

293291
switch (vers) {
294-
case 2: ret = nvkm_gsp_fwsec_v2(gsp, name, &desc->v2, size, init_cmd, &fw); break;
295-
case 3: ret = nvkm_gsp_fwsec_v3(gsp, name, &desc->v3, size, init_cmd, &fw); break;
292+
case 2: ret = nvkm_gsp_fwsec_v2(gsp, name, &desc->v2, size, init_cmd, fw); break;
293+
case 3: ret = nvkm_gsp_fwsec_v3(gsp, name, &desc->v3, size, init_cmd, fw); break;
296294
default:
297295
nvkm_error(subdev, "%s(v%d): version unknown\n", name, vers);
298296
return -EINVAL;
@@ -303,15 +301,19 @@ nvkm_gsp_fwsec(struct nvkm_gsp *gsp, const char *name, u32 init_cmd)
303301
return ret;
304302
}
305303

306-
/* Boot. */
307-
ret = nvkm_falcon_fw_boot(&fw, subdev, true, &mbox0, NULL, 0, 0);
308-
nvkm_falcon_fw_dtor(&fw);
309-
if (ret)
310-
return ret;
311-
312304
return 0;
313305
}
314306

307+
static int
308+
nvkm_gsp_fwsec_boot(struct nvkm_gsp *gsp, struct nvkm_falcon_fw *fw)
309+
{
310+
struct nvkm_subdev *subdev = &gsp->subdev;
311+
u32 mbox0 = 0;
312+
313+
/* Boot */
314+
return nvkm_falcon_fw_boot(fw, subdev, true, &mbox0, NULL, 0, 0);
315+
}
316+
315317
int
316318
nvkm_gsp_fwsec_sb(struct nvkm_gsp *gsp)
317319
{
@@ -320,7 +322,7 @@ nvkm_gsp_fwsec_sb(struct nvkm_gsp *gsp)
320322
int ret;
321323
u32 err;
322324

323-
ret = nvkm_gsp_fwsec(gsp, "fwsec-sb", NVFW_FALCON_APPIF_DMEMMAPPER_CMD_SB);
325+
ret = nvkm_gsp_fwsec_boot(gsp, &gsp->fws.falcon.sb);
324326
if (ret)
325327
return ret;
326328

@@ -334,27 +336,48 @@ nvkm_gsp_fwsec_sb(struct nvkm_gsp *gsp)
334336
return 0;
335337
}
336338

339+
int
340+
nvkm_gsp_fwsec_sb_ctor(struct nvkm_gsp *gsp)
341+
{
342+
return nvkm_gsp_fwsec_init(gsp, &gsp->fws.falcon.sb, "fwsec-sb",
343+
NVFW_FALCON_APPIF_DMEMMAPPER_CMD_SB);
344+
}
345+
346+
void
347+
nvkm_gsp_fwsec_sb_dtor(struct nvkm_gsp *gsp)
348+
{
349+
nvkm_falcon_fw_dtor(&gsp->fws.falcon.sb);
350+
}
351+
337352
int
338353
nvkm_gsp_fwsec_frts(struct nvkm_gsp *gsp)
339354
{
340355
struct nvkm_subdev *subdev = &gsp->subdev;
341356
struct nvkm_device *device = subdev->device;
357+
struct nvkm_falcon_fw fw = {};
342358
int ret;
343359
u32 err, wpr2_lo, wpr2_hi;
344360

345-
ret = nvkm_gsp_fwsec(gsp, "fwsec-frts", NVFW_FALCON_APPIF_DMEMMAPPER_CMD_FRTS);
361+
ret = nvkm_gsp_fwsec_init(gsp, &fw, "fwsec-frts", NVFW_FALCON_APPIF_DMEMMAPPER_CMD_FRTS);
346362
if (ret)
347363
return ret;
348364

365+
ret = nvkm_gsp_fwsec_boot(gsp, &fw);
366+
if (ret)
367+
goto fwsec_dtor;
368+
349369
/* Verify. */
350370
err = nvkm_rd32(device, 0x001400 + (0xe * 4)) >> 16;
351371
if (err) {
352372
nvkm_error(subdev, "fwsec-frts: 0x%04x\n", err);
353-
return -EIO;
373+
ret = -EIO;
374+
} else {
375+
wpr2_lo = nvkm_rd32(device, 0x1fa824);
376+
wpr2_hi = nvkm_rd32(device, 0x1fa828);
377+
nvkm_debug(subdev, "fwsec-frts: WPR2 @ %08x - %08x\n", wpr2_lo, wpr2_hi);
354378
}
355379

356-
wpr2_lo = nvkm_rd32(device, 0x1fa824);
357-
wpr2_hi = nvkm_rd32(device, 0x1fa828);
358-
nvkm_debug(subdev, "fwsec-frts: WPR2 @ %08x - %08x\n", wpr2_lo, wpr2_hi);
359-
return 0;
380+
fwsec_dtor:
381+
nvkm_falcon_fw_dtor(&fw);
382+
return ret;
360383
}

drivers/gpu/drm/nouveau/nvkm/subdev/gsp/priv.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
enum nvkm_acr_lsf_id;
77

88
int nvkm_gsp_fwsec_frts(struct nvkm_gsp *);
9+
10+
int nvkm_gsp_fwsec_sb_ctor(struct nvkm_gsp *);
911
int nvkm_gsp_fwsec_sb(struct nvkm_gsp *);
12+
void nvkm_gsp_fwsec_sb_dtor(struct nvkm_gsp *);
1013

1114
struct nvkm_gsp_fwif {
1215
int version;

drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/gsp.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1817,12 +1817,16 @@ r535_gsp_rm_boot_ctor(struct nvkm_gsp *gsp)
18171817
RM_RISCV_UCODE_DESC *desc;
18181818
int ret;
18191819

1820+
ret = nvkm_gsp_fwsec_sb_ctor(gsp);
1821+
if (ret)
1822+
return ret;
1823+
18201824
hdr = nvfw_bin_hdr(&gsp->subdev, fw->data);
18211825
desc = (void *)fw->data + hdr->header_offset;
18221826

18231827
ret = nvkm_gsp_mem_ctor(gsp, hdr->data_size, &gsp->boot.fw);
18241828
if (ret)
1825-
return ret;
1829+
goto dtor_fwsec;
18261830

18271831
memcpy(gsp->boot.fw.data, fw->data + hdr->data_offset, hdr->data_size);
18281832

@@ -1831,6 +1835,9 @@ r535_gsp_rm_boot_ctor(struct nvkm_gsp *gsp)
18311835
gsp->boot.manifest_offset = desc->manifestOffset;
18321836
gsp->boot.app_version = desc->appVersion;
18331837
return 0;
1838+
dtor_fwsec:
1839+
nvkm_gsp_fwsec_sb_dtor(gsp);
1840+
return ret;
18341841
}
18351842

18361843
static const struct nvkm_firmware_func
@@ -2101,6 +2108,7 @@ r535_gsp_dtor(struct nvkm_gsp *gsp)
21012108
mutex_destroy(&gsp->cmdq.mutex);
21022109

21032110
nvkm_gsp_dtor_fws(gsp);
2111+
nvkm_gsp_fwsec_sb_dtor(gsp);
21042112

21052113
nvkm_gsp_mem_dtor(&gsp->rmargs);
21062114
nvkm_gsp_mem_dtor(&gsp->wpr_meta);

0 commit comments

Comments
 (0)