From 79327c204237052d16b948c8fb42e0d4c992564e Mon Sep 17 00:00:00 2001 From: Arthur Hanson Rasmusson Date: Mon, 5 Oct 2026 12:47:47 -0400 Subject: vgsp: fix per-type VRAM type lookup and canonical FB-size encoding The 549d1e81 per-type VRAM change stripped an nvidia- prefix from mdev->type->sysfs_name, but sysfs_name is the registered type name verbatim; the mdev core only prefixes the type DIRECTORY with the parent driver string. Every lookup failed, so all mdevs silently fell back to 512 MiB, nvidia-vgpu-turing-1g was unreachable and available_instances capped at 1. Match sysfs_name directly in get_available, show_description and mdev_create. Also canonicalise the NV_PFB_PRI_MMU_LOCAL_MEMORY_RANGE encoder (BAR0+0x100ce0) by stripping factors of two from MAG so 512 MiB encodes 0x19 again (1 GiB 0x1a, 2 GiB 0x1b) instead of the non-canonical 0x204. Default-512M behaviour is now byte-equivalent to the known-good pre-VRAM module except max_instances=2. Module sha256 cb1724d3. --- kernel/bar_emulation.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'kernel/bar_emulation.c') diff --git a/kernel/bar_emulation.c b/kernel/bar_emulation.c index 8e3f8cf..d1702c8 100644 --- a/kernel/bar_emulation.c +++ b/kernel/bar_emulation.c @@ -290,13 +290,24 @@ int nv_vgpu_bar_emul_init(struct nv_vgpu_device *vgpu) * guest's fbSize - reserved arithmetic stays consistent. */ u64 fb = nv_vgpu_fb_emul_size(ctx->vgpu); - u32 scale = 0; + u32 scale = 0, mag; + /* + * Find the largest SCALE whose MAG fits the 6-bit field, then + * canonicalise: strip factors of two from MAG while SCALE can + * absorb them. 512 MiB -> mag=1,scale=9 -> 0x19 (the historical + * known-good value); 1 GiB -> 0x1a; 2 GiB -> 0x1b. Sizes that + * are not exactly representable round down. + */ while (scale < 15 && (fb >> (scale + 20)) > 0x3f) scale++; + mag = (u32)(fb >> (scale + 20)); + while (scale < 15 && mag > 1 && !(mag & 1u)) { + mag >>= 1; + scale++; + } *(u32 *)((u8 *)ctx->bar0_shadow + 0x100ce0) = - ((((u32)(fb >> (scale + 20))) & 0x3f) << 4) | - (scale & 0xf); + ((mag & 0x3f) << 4) | (scale & 0xf); } /* -- cgit v1.2.3