summaryrefslogtreecommitdiffstats
path: root/driver/debugfs
diff options
context:
space:
mode:
authorArthur Hanson Rasmusson <arthur@vgpu.io>2026-09-13 18:36:21 -0400
committerArthur Hanson Rasmusson <arthur@vgpu.io>2026-09-13 18:36:21 -0400
commit00e54c13c7c9030c4d5f7151467f2d85a3730e29 (patch)
tree17a45239df8d2e4912ff3697ed06e85a10b969de /driver/debugfs
downloadopen-iov-00e54c13c7c9030c4d5f7151467f2d85a3730e29.tar.gz
open-iov-00e54c13c7c9030c4d5f7151467f2d85a3730e29.zip
Initial commit: Open-IOV vGPU-IO complete stack
- Firmware decompilation: GSP 570.144W (28.5MB ELF, RV64IMAC), 132 decompiled C files - Kernel modules: nvidia.ko (34MB, OpenRM), open-iov-vfio.ko (2.8MB, VFIO mdev), gsp-vgpu.ko (1.8MB, guest driver) - Userspace: libiov.so/libvgpu.so (76KB), example_vgpu (28KB), rpc_emulator.c - PCI config space emulation (256B with PM, MSI, MSI-X, PCIe caps) - 12 RPC types fully mapped from firmware decompilation - BAR trap, WPR, scheduling, notification, migration emulation - Helper scripts: load_vgpu_stack, create_mdev, launch_qemu_vgpu, test_vgpu_stack, setup_guest_driver, unload_vgpu_stack - Architecture documentation - Wiki: 10 technical documents - Git LFS for large binaries (.ko, .bin, .iso, .img, .o, ghidra repos) - nvidia-open-gpu-kernel-modules as submodule
Diffstat (limited to 'driver/debugfs')
-rw-r--r--driver/debugfs/gsp_debugfs.c273
1 files changed, 273 insertions, 0 deletions
diff --git a/driver/debugfs/gsp_debugfs.c b/driver/debugfs/gsp_debugfs.c
new file mode 100644
index 0000000..f3df124
--- /dev/null
+++ b/driver/debugfs/gsp_debugfs.c
@@ -0,0 +1,273 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * GSP vGPU-IO Driver - Debugfs Interface
+ */
+
+#include "gsp_core.h"
+#include <linux/debugfs.h>
+#include <linux/seq_file.h>
+
+static int gsp_debugfs_vfs_show(struct seq_file *s, void *unused)
+{
+ struct gsp_device *gsp = s->private;
+ struct gsp_vf *vf;
+
+ seq_printf(s, "%-4s %-12s %-10s %-18s %-18s\n",
+ "ID", "STATE", "REFCNT", "BAR1", "PAGE_TABLE");
+
+ mutex_lock(&gsp->vf_lock);
+ list_for_each_entry(vf, &gsp->vf_list, list) {
+ seq_printf(s, "%-4u %-12d %-10d 0x%016llx-0x%016llx 0x%016llx-0x%016llx\n",
+ vf->id, vf->state, atomic_read(&vf->refcount),
+ vf->bar1_offset, vf->bar1_offset + vf->bar1_size,
+ vf->pt_base, vf->pt_base + vf->pt_size);
+ }
+ mutex_unlock(&gsp->vf_lock);
+
+ return 0;
+}
+
+static int gsp_debugfs_vfs_open(struct inode *inode, struct file *file)
+{
+ return single_open(file, gsp_debugfs_vfs_show, inode->i_private);
+}
+
+static const struct file_operations gsp_debugfs_vfs_fops = {
+ .open = gsp_debugfs_vfs_open,
+ .read = seq_read,
+ .llseek = seq_lseek,
+ .release = single_release,
+};
+
+static int gsp_debugfs_vf_show(struct seq_file *s, void *unused)
+{
+ struct gsp_vf *vf = s->private;
+ struct gsp_wpr_region *rgn;
+
+ seq_printf(s, "VF %u\n", vf->id);
+ seq_printf(s, " State: %d\n", vf->state);
+ seq_printf(s, " Refcount: %d\n", atomic_read(&vf->refcount));
+ seq_printf(s, " BAR1: 0x%llx - 0x%llx (size: 0x%llx)\n",
+ vf->bar1_offset, vf->bar1_offset + vf->bar1_size, vf->bar1_size);
+ seq_printf(s, " Page Table: 0x%llx - 0x%llx (size: 0x%llx)\n",
+ vf->pt_base, vf->pt_base + vf->pt_size, vf->pt_size);
+ seq_printf(s, " Cmd Buffer: 0x%llx - 0x%llx (size: 0x%llx)\n",
+ vf->cmd_base, vf->cmd_base + vf->cmd_size, vf->cmd_size);
+ seq_printf(s, " BAR State:\n");
+ seq_printf(s, " Aperture: 0x%llx - 0x%llx\n",
+ vf->bar_state.aperture_offset,
+ vf->bar_state.aperture_offset + vf->bar_state.aperture_size);
+ seq_printf(s, " ForceAcc: %s (VF: %u)\n",
+ vf->bar_state.force_access ? "enabled" : "disabled",
+ vf->bar_state.force_vf);
+ seq_printf(s, " WPR Regions:\n");
+
+ mutex_lock(&vf->wpr_lock);
+ list_for_each_entry(rgn, &vf->wpr_list, list) {
+ seq_printf(s, " [0x%llx, 0x%llx) flags=0x%x\n",
+ rgn->base, rgn->base + rgn->size, rgn->flags);
+ }
+ mutex_unlock(&vf->wpr_lock);
+
+ if (vf->migration) {
+ seq_printf(s, " Migration:\n");
+ seq_printf(s, " State: %d\n", vf->migration->state);
+ seq_printf(s, " Dst VF: %llu\n", vf->migration->dst_vf);
+ seq_printf(s, " Token: 0x%llx\n", vf->migration->token);
+ seq_printf(s, " Progress: %llu pages, %llu bytes\n",
+ vf->migration->progress.pages_transferred,
+ vf->migration->progress.bytes_transferred);
+ }
+
+ return 0;
+}
+
+static int gsp_debugfs_vf_open(struct inode *inode, struct file *file)
+{
+ return single_open(file, gsp_debugfs_vf_show, inode->i_private);
+}
+
+static const struct file_operations gsp_debugfs_vf_fops = {
+ .open = gsp_debugfs_vf_open,
+ .read = seq_read,
+ .llseek = seq_lseek,
+ .release = single_release,
+};
+
+static int gsp_debugfs_rpc_show(struct seq_file *s, void *unused)
+{
+ struct gsp_device *gsp = s->private;
+
+ seq_printf(s, "RPC Statistics:\n");
+ seq_printf(s, " Total: %lld\n", atomic64_read(&gsp->rpc_total));
+ seq_printf(s, " Errors: %lld\n", atomic64_read(&gsp->rpc_errors));
+ seq_printf(s, " BAR Traps: %lld\n", atomic64_read(&gsp->bar_traps));
+ seq_printf(s, " WPR Events: %lld\n", atomic64_read(&gsp->wpr_events));
+ seq_printf(s, " Migrations: %lld\n", atomic64_read(&gsp->migrations));
+
+ return 0;
+}
+
+static int gsp_debugfs_rpc_open(struct inode *inode, struct file *file)
+{
+ return single_open(file, gsp_debugfs_rpc_show, inode->i_private);
+}
+
+static const struct file_operations gsp_debugfs_rpc_fops = {
+ .open = gsp_debugfs_rpc_open,
+ .read = seq_read,
+ .llseek = seq_lseek,
+ .release = single_release,
+};
+
+static int gsp_debugfs_bar_show(struct seq_file *s, void *unused)
+{
+ struct gsp_vf *vf = s->private;
+
+ seq_printf(s, "VF %u BAR State:\n", vf->id);
+ seq_printf(s, " Aperture Offset: 0x%llx\n", vf->bar_state.aperture_offset);
+ seq_printf(s, " Aperture Size: 0x%llx\n", vf->bar_state.aperture_size);
+ seq_printf(s, " Force Access: %s\n", vf->bar_state.force_access ? "enabled" : "disabled");
+ seq_printf(s, " Force VF: %u\n", vf->bar_state.force_vf);
+ seq_printf(s, " Backing Store: %p\n", vf->bar_state.backing_store);
+ seq_printf(s, " Backing Size: 0x%zx\n", vf->bar_state.backing_size);
+
+ return 0;
+}
+
+static int gsp_debugfs_bar_open(struct inode *inode, struct file *file)
+{
+ return single_open(file, gsp_debugfs_bar_show, inode->i_private);
+}
+
+static const struct file_operations gsp_debugfs_bar_fops = {
+ .open = gsp_debugfs_bar_open,
+ .read = seq_read,
+ .llseek = seq_lseek,
+ .release = single_release,
+};
+
+static int gsp_debugfs_wpr_show(struct seq_file *s, void *unused)
+{
+ struct gsp_vf *vf = s->private;
+ struct gsp_wpr_region *rgn;
+
+ seq_printf(s, "VF %u WPR Regions:\n", vf->id);
+
+ mutex_lock(&vf->wpr_lock);
+ list_for_each_entry(rgn, &vf->wpr_list, list) {
+ seq_printf(s, " [0x%llx, 0x%llx) size=0x%llx flags=0x%x\n",
+ rgn->base, rgn->base + rgn->size, rgn->size, rgn->flags);
+ }
+ mutex_unlock(&vf->wpr_lock);
+
+ return 0;
+}
+
+static int gsp_debugfs_wpr_open(struct inode *inode, struct file *file)
+{
+ return single_open(file, gsp_debugfs_wpr_show, inode->i_private);
+}
+
+static const struct file_operations gsp_debugfs_wpr_fops = {
+ .open = gsp_debugfs_wpr_open,
+ .read = seq_read,
+ .llseek = seq_lseek,
+ .release = single_release,
+};
+
+static int gsp_debugfs_migration_show(struct seq_file *s, void *unused)
+{
+ struct gsp_vf *vf = s->private;
+
+ if (!vf->migration) {
+ seq_printf(s, "No active migration\n");
+ return 0;
+ }
+
+ seq_printf(s, "VF %u Migration:\n", vf->id);
+ seq_printf(s, " State: %d\n", vf->migration->state);
+ seq_printf(s, " Destination VF: %llu\n", vf->migration->dst_vf);
+ seq_printf(s, " Token: 0x%llx\n", vf->migration->token);
+ seq_printf(s, " Flags: 0x%x\n", vf->migration->flags);
+ seq_printf(s, " Pages Xfer: %llu\n", vf->migration->progress.pages_transferred);
+ seq_printf(s, " Bytes Xfer: %llu\n", vf->migration->progress.bytes_transferred);
+ seq_printf(s, " Dirty Pages: %llu\n", vf->migration->progress.dirty_pages);
+ seq_printf(s, " Cancelled: %s\n", vf->migration->cancelled ? "yes" : "no");
+
+ return 0;
+}
+
+static int gsp_debugfs_migration_open(struct inode *inode, struct file *file)
+{
+ return single_open(file, gsp_debugfs_migration_show, inode->i_private);
+}
+
+static const struct file_operations gsp_debugfs_migration_fops = {
+ .open = gsp_debugfs_migration_open,
+ .read = seq_read,
+ .llseek = seq_lseek,
+ .release = single_release,
+};
+
+/* VF Debugfs Directory Creation */
+static void gsp_debugfs_vf_create(struct gsp_vf *vf)
+{
+ char name[16];
+ struct dentry *vf_dir;
+
+ snprintf(name, sizeof(name), "vf%u", vf->id);
+ vf_dir = debugfs_create_dir(name, vf->gsp->debugfs_vfs_dir);
+ if (!vf_dir)
+ return;
+
+ debugfs_create_file("status", 0444, vf_dir, vf, &gsp_debugfs_vf_fops);
+ debugfs_create_file("bar", 0444, vf_dir, vf, &gsp_debugfs_bar_fops);
+ debugfs_create_file("wpr", 0444, vf_dir, vf, &gsp_debugfs_wpr_fops);
+ debugfs_create_file("migration", 0444, vf_dir, vf, &gsp_debugfs_migration_fops);
+}
+
+/* Main Debugfs Init */
+int gsp_debugfs_init(struct gsp_device *gsp)
+{
+ gsp->debugfs_root = debugfs_create_dir("gsp-vgpu", NULL);
+ if (!gsp->debugfs_root)
+ return -ENOMEM;
+
+ debugfs_create_file("vfs", 0444, gsp->debugfs_root, gsp, &gsp_debugfs_vfs_fops);
+ debugfs_create_file("rpc", 0444, gsp->debugfs_root, gsp, &gsp_debugfs_rpc_fops);
+
+ gsp->debugfs_vfs_dir = debugfs_create_dir("vfs", gsp->debugfs_root);
+ if (!gsp->debugfs_vfs_dir) {
+ debugfs_remove_recursive(gsp->debugfs_root);
+ return -ENOMEM;
+ }
+
+ /* Create entries for existing VFs */
+ mutex_lock(&gsp->vf_lock);
+ struct gsp_vf *vf;
+ list_for_each_entry(vf, &gsp->vf_list, list)
+ gsp_debugfs_vf_create(vf);
+ mutex_unlock(&gsp->vf_lock);
+
+ return 0;
+}
+
+void gsp_debugfs_fini(struct gsp_device *gsp)
+{
+ if (gsp->debugfs_root)
+ debugfs_remove_recursive(gsp->debugfs_root);
+}
+
+/* Export for VF creation/destruction */
+void gsp_debugfs_vf_add(struct gsp_vf *vf)
+{
+ gsp_debugfs_vf_create(vf);
+}
+
+void gsp_debugfs_vf_remove(struct gsp_vf *vf)
+{
+ char name[16];
+ snprintf(name, sizeof(name), "vf%u", vf->id);
+ debugfs_remove_recursive(debugfs_lookup(name, vf->gsp->debugfs_vfs_dir));
+} \ No newline at end of file