From 2a59dcb768541b759ada9cd6f24986e2c234bd37 Mon Sep 17 00:00:00 2001 From: Arthur Hanson Rasmusson Date: Wed, 23 Sep 2026 14:03:27 -0400 Subject: kernel: track channels and execute host-class pushed work The guest's CUDA stack was stuck inside context creation because the work it submits is never executed by the emulated GPU. Two forms of pushed work were missing, and the completion path had grown far too slow to be useful: - Channel tracking: on a channel allocation parse the GPFIFO GPU VA and entry count, the USERD address/aperture and the instance block, hand them to the progress service and drop them again when the channel is freed. - Host-class (C46F) semaphore releases: pushes on a compute channel signal progress with a five-dword method run (SEM_ADDR_LO/HI, PAYLOAD_LO/HI, EXECUTE) rather than the copy-engine group the service already understood, so those releases were never applied. Decode both forms. - Emulated vidmem: channel blocks (USERD/instance) and some client semaphores live in the emulated frame buffer, whose VAs are a window over the BAR1 backing rather than guest RAM; access them through the right aperture. - Latency: the service's full-RAM sweep took seconds per pass, so guests' progress waits took whole seconds and the driver tore its own setup back down in the meantime. Sweep guest RAM in bounded, chunked windows on every pass, remember the pages pushes are actually found in and revisit those first, and keep the VA->PA map complete (dedup, sort, binary search) so semaphores resolve reliably. Also add a vidmem poke parameter for bringing up and debugging emulated frame-buffer state. --- kernel/main.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'kernel/main.c') diff --git a/kernel/main.c b/kernel/main.c index 2ec7ab9..84a05ca 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -2627,6 +2627,44 @@ static const struct kernel_param_ops nv_vgpu_dump_vidmem_ops = { module_param_cb(dump_vidmem, &nv_vgpu_dump_vidmem_ops, NULL, 0200); MODULE_PARM_DESC(dump_vidmem, "Dump emulated vidmem range (hex offset,hex len)"); +/* + * Debug: write a u32 into the emulated vidmem (BAR1 backing) at an offset: + * echo 0x,0x > .../parameters/poke_vidmem + */ +static int nv_vgpu_poke_vidmem_set(const char *val, const struct kernel_param *kp) +{ + struct nv_vgpu_device *vgpu; + u64 off = 0, value = 0; + char *end; + int ret = 0; + + if (sscanf(val, "%lli,%lli", &off, &value) != 2) + return -EINVAL; + + mutex_lock(&nv_vgpu_driver.lock); + list_for_each_entry(vgpu, &nv_vgpu_driver.devices, list) { + if (atomic_read(&vgpu->vfio_dev_open_count) <= 0) + continue; + if (!vgpu->bars[1].vaddr || off + 4 > vgpu->bars[1].size) { + ret = -EINVAL; + break; + } + memcpy(vgpu->bars[1].vaddr + off, &value, 4); + pr_info("poke_vidmem: [0x%llx] = 0x%llx\n", off, value); + break; + } + mutex_unlock(&nv_vgpu_driver.lock); + (void)end; + return ret; +} + +static const struct kernel_param_ops nv_vgpu_poke_vidmem_ops = { + .set = nv_vgpu_poke_vidmem_set, +}; + +module_param_cb(poke_vidmem, &nv_vgpu_poke_vidmem_ops, NULL, 0200); +MODULE_PARM_DESC(poke_vidmem, "Write u32 to emulated vidmem (hex offset,hex value)"); + /* * Debug: hex-dump a guest physical range (kthread: guest-DMA needs it): * echo 0x,0x > .../parameters/dump_guest -- cgit v1.2.3