From 549d1e8126f96b3515d37037ae22e0dce430c20b Mon Sep 17 00:00:00 2001 From: Arthur Hanson Rasmusson Date: Mon, 5 Oct 2026 12:25:05 -0400 Subject: vgsp: per-mdev emulated VRAM size (1.0 multiple mediate sizes) - nv_vgpu_type_info/ioctl gain vram_mb; nv_vgpu_device gains fb_emul_size bound from the mdev type at create (default 512 MiB). - New nvidia-vgpu-turing-1g type (1024 MiB); turing max_instances 1 -> 2; show_description reports the per-type framebuffer and max_instance. - Thread fb_emul_size through GSCI fb_length/region/frtsOffset, WPR2, NV_PFB_PRI_MMU_LOCAL_MEMORY_RANGE, the vidmem allocator bound and the BAR1 shadow; bar_info callback uses the per-device size. - UNTESTED at commit time: builds clean; validation blocked by the Xid 140 incident (reboot pending). See Handoff-vGPU-IO.md ADDENDUM 48. --- kernel/main.c | 51 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 9 deletions(-) (limited to 'kernel/main.c') diff --git a/kernel/main.c b/kernel/main.c index 7028bdd..a5a64fd 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -112,8 +112,22 @@ static unsigned int nv_vgpu_get_available(struct mdev_type *mtype) */ static ssize_t nv_vgpu_show_description(struct mdev_type *mtype, char *buf) { - return sysfs_emit(buf, "num_heads=1, frl_config=60, framebuffer=256M, " - "max_resolution=5120x2880, max_instance=1\n"); + struct nv_vgpu_type_info *info; + const char *name = mtype->sysfs_name; + u32 vram_mb = 512, max_inst = 1; + + if (name && str_has_prefix(name, "nvidia-")) + name += strlen("nvidia-"); + info = name ? nv_vgpu_find_type_info(name) : NULL; + if (info) { + if (info->vram_mb) + vram_mb = info->vram_mb; + if (info->max_instances) + max_inst = info->max_instances; + } + return sysfs_emit(buf, "num_heads=1, frl_config=60, framebuffer=%uM, " + "max_resolution=5120x2880, max_instance=%u\n", + vram_mb, max_inst); } struct mdev_driver nv_vgpu_mdev_driver = { @@ -199,7 +213,7 @@ static NV_STATUS nv_vgpu_bar_info_callback(struct pci_dev *pdev, const NvU8 *uui *size = NV_VGPU_BAR0_SIZE; /* 16MB */ break; case 1: - *size = NV_VGPU_BAR1_SIZE; /* 256MB */ + *size = nv_vgpu_fb_emul_size(vgpu_dev); /* per-type FB */ break; case 2: *size = NV_VGPU_BAR2_SIZE; /* 32MB */ @@ -370,14 +384,15 @@ EXPORT_SYMBOL(nv_vgpu_find_type_info); static void nv_vgpu_create_static_types(void) { int i; - struct nv_vgpu_type_info static_types[4] = { - { .name = "nvidia-vgpu-ampere", .description = "NVIDIA Ampere vGPU", .vdev_id = 0x10de2235, .pdev_id = 0x10de2235, .max_instances = 1 }, - { .name = "nvidia-vgpu-hopper", .description = "NVIDIA Hopper vGPU", .vdev_id = 0x10de2331, .pdev_id = 0x10de2331, .max_instances = 1 }, - { .name = "nvidia-vgpu-turing", .description = "NVIDIA Turing vGPU", .vdev_id = 0x10de1ed3, .pdev_id = 0x10de1ed3, .max_instances = 1 }, - { .name = "nvidia-vgpu-pascal", .description = "NVIDIA Pascal vGPU", .vdev_id = 0x10de1db1, .pdev_id = 0x10de1db1, .max_instances = 1 }, + struct nv_vgpu_type_info static_types[5] = { + { .name = "nvidia-vgpu-ampere", .description = "NVIDIA Ampere vGPU", .vdev_id = 0x10de2235, .pdev_id = 0x10de2235, .max_instances = 1, .vram_mb = 512 }, + { .name = "nvidia-vgpu-hopper", .description = "NVIDIA Hopper vGPU", .vdev_id = 0x10de2331, .pdev_id = 0x10de2331, .max_instances = 1, .vram_mb = 512 }, + { .name = "nvidia-vgpu-turing", .description = "NVIDIA Turing vGPU", .vdev_id = 0x10de1ed3, .pdev_id = 0x10de1ed3, .max_instances = 2, .vram_mb = 512 }, + { .name = "nvidia-vgpu-turing-1g", .description = "NVIDIA Turing vGPU (1 GiB)", .vdev_id = 0x10de1ed3, .pdev_id = 0x10de1ed3, .max_instances = 2, .vram_mb = 1024 }, + { .name = "nvidia-vgpu-pascal", .description = "NVIDIA Pascal vGPU", .vdev_id = 0x10de1db1, .pdev_id = 0x10de1db1, .max_instances = 1, .vram_mb = 512 }, }; - for (i = 0; i < 4; i++) { + for (i = 0; i < 5; i++) { nv_vgpu_register_type_info(&static_types[i]); } } @@ -546,6 +561,24 @@ static int nv_vgpu_mdev_create(struct mdev_device *mdev) vgpu->mdev = mdev; vgpu->state = NV_VGPU_STATE_UNINITIALIZED; + /* + * Bind the emulated FB size to this mdev's type (the type's vram_mb; + * 0/absent keeps the 512 MiB default). The type dir may carry an + * extra "nvidia-" prefix vs our registered names. + */ + { + const char *tname = mdev->type ? mdev->type->sysfs_name : NULL; + struct nv_vgpu_type_info *tinfo; + + if (tname && str_has_prefix(tname, "nvidia-")) + tname += strlen("nvidia-"); + tinfo = tname ? nv_vgpu_find_type_info(tname) : NULL; + vgpu->fb_emul_size = (tinfo && tinfo->vram_mb) ? + (u64)tinfo->vram_mb << 20 : NV_VGPU_EMUL_FB_SIZE; + pr_info("vgsp: mdev create: type=%s fb_emul_size=%llu MiB\n", + tname ? tname : "(none)", + (unsigned long long)(vgpu->fb_emul_size >> 20)); + } mutex_init(&vgpu->lock); INIT_WORK(&vgpu->init_work, nv_vgpu_device_init_work); INIT_WORK(&vgpu->cleanup_work, nv_vgpu_device_cleanup_work); -- cgit v1.2.3