diff options
| author | Open-IOV <dev@open-iov.org> | 2026-09-23 05:44:08 -0400 |
|---|---|---|
| committer | Open-IOV <dev@open-iov.org> | 2026-09-23 05:46:43 -0400 |
| commit | 2302fc09080bad51c73f293294e19fd4db464eb0 (patch) | |
| tree | c722d186347fdef5a34131e9e143b1549b1daf8e /legacy-driver-guest/debugfs/gsp_debugfs.c | |
| download | open-iov-2302fc09080bad51c73f293294e19fd4db464eb0.tar.gz open-iov-2302fc09080bad51c73f293294e19fd4db464eb0.zip | |
Open-IOV: initial public release
Open-IOV virtualizes NVIDIA GPUs so that unmodified guest drivers run with
real GPU functionality - CUDA first, 3D and video to follow - on unmodified
hosts, without a proprietary vGPU license and without patching any driver,
firmware or hypervisor.
Core principle: emulate the interface, pass through the work.
kernel/ open-iov-vfio.ko - host VFIO mdev driver: virtual GPU device
(PCI config space, BAR shadows, MSI-X), GSP boot emulation,
GSP-RM message-queue/RPC emulation, memory model (GPU-VA to
guest-PA discovery) and the semaphore-completion service that
advances guest UVM progress.
userspace/ libiov.so management API and examples.
tools/ guest diagnostics, firmware analysis wrappers, RM probes.
scripts/ stack manager, VM harness, build/load/test automation.
config/ hardware/version profiles (the portability surface).
docs/ documentation tree - start at docs/README.md.
wiki/ long-form firmware and protocol deep dives.
Status: initialization works end to end for a stock 570.144 Linux guest on
Turing (TU104): driver probe, nvidia-smi, the full GSP-RM control battery,
object creation and the early CUDA/UVM start-up path. GPU work forwarding -
the step that makes CUDA kernels execute on real hardware - is the active
work item; see docs/04-implementation/01-known-knowns-and-unknowns.md.
License: BSD-3-Clause for the project; GPL-2.0 for kernel modules that link
GPL-only kernel interfaces. See LICENSE and docs/09-reference/legal-and-licensing.md.
Diffstat (limited to 'legacy-driver-guest/debugfs/gsp_debugfs.c')
| -rw-r--r-- | legacy-driver-guest/debugfs/gsp_debugfs.c | 273 |
1 files changed, 273 insertions, 0 deletions
diff --git a/legacy-driver-guest/debugfs/gsp_debugfs.c b/legacy-driver-guest/debugfs/gsp_debugfs.c new file mode 100644 index 0000000..f3df124 --- /dev/null +++ b/legacy-driver-guest/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 |
