summaryrefslogtreecommitdiffstats
path: root/kernel/main.c
diff options
context:
space:
mode:
authorArthur Hanson Rasmusson <arthur@vgpu.io>2026-09-23 14:03:27 -0400
committerArthur Hanson Rasmusson <arthur@vgpu.io>2026-09-23 14:03:27 -0400
commitdb34d52120055c927aad160b2c73c390485333ea (patch)
treea38f3a018eeabd01d09c5bad5c0fae199d450a93 /kernel/main.c
parent681494a79e6c0e084354eec0229386a696a314c0 (diff)
downloadopen-iov-db34d52120055c927aad160b2c73c390485333ea.tar.gz
open-iov-db34d52120055c927aad160b2c73c390485333ea.zip
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.
Diffstat (limited to 'kernel/main.c')
-rw-r--r--kernel/main.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/kernel/main.c b/kernel/main.c
index 2ec7ab9..84a05ca 100644
--- a/kernel/main.c
+++ b/kernel/main.c
@@ -2628,6 +2628,44 @@ 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<offset>,0x<value> > .../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<gpa>,0x<len> > .../parameters/dump_guest
*/