CUDA fails in guests with a passed-through NVIDIA GPU: the 64-bit PCI window leaves no free range for HMM
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
Start from mmio64_aperture_weight in the per-segment PCI aperture computation, and from PciSegmentConfig where the new optional field would be parsed and validated. The issue proposes a size bound on the 64-bit window that leaves the rest unclaimed, with the segment's start address kept. Done means the option is validated (non-zero, 4 KiB multiple), the default layout is unchanged, and the unit tests for the computed apertures and old-config deserialization pass.
由索引模型根据 Issue 内容生成。
描述
Elevator pitch
An opt-in per-segment cap on the 64-bit MMIO aperture, next to the existing mmio64_aperture_weight:
--pci-segment pci_segment=0,mmio64_aperture_size=64G
It leaves the rest of the guest physical address space unclaimed. Without it, CUDA fails in guests with a passed-through NVIDIA GPU: the 64-bit PCI window leaves no free range for the driver's HMM.
Motivation
With an NVIDIA GPU passed through via VFIO, nvidia-smi works in the guest, but every CUDA program fails in cuInit with CUDA_ERROR_NOT_INITIALIZED (3).
Setup:
- Host: AMD EPYC, RTX 4090.
- Guest: Ubuntu 24.04, kernel 6.8.0-147, NVIDIA open driver 580.178.04.
- Cloud Hypervisor v51.1 and v54.0 both fail.
Cause: Cloud Hypervisor's 64-bit PCI window runs from the end of RAM to just below the top of the guest physical address space. In an 8 GiB guest with 46 physical address bits:
100000000-23fffffff : System RAM
240000000-3fffffeeffff : PCI Bus 0000:00
The GPU itself uses much less (288 MiB) than the reserved window.
NVIDIA's nvidia_uvm uses Linux HMM by default on kernels with CONFIG_DEVICE_PRIVATE (e.g. Ubuntu's generic kernel). HMM registers the GPU's memory as device-private memory, which needs a free physical range the size of VRAM. It asks for one using request_free_mem_region() and finds none, upon which it errors:
nvidia-uvm: uvm_pmm_gpu.c:3252 devmem_alloc_pagemap[pid:767] request_free_mem_region() err -34
nvidia-uvm: ... init_parent_gpu ... failed to intialize device private memory: Out of memory [NV_ERR_NO_MEMORY]
UVM then does not initialize. nvidia-smi does not use UVM, so it keeps working.
Workarounds that work today, and confirm the cause, both with drawbacks:
nvidia_uvm.uvm_disable_hmm=1on the guest command line (3/3): requires changing the guest, and turns off HMM-based features in it.--memory hotplug_size=64G(3/3) or480G(2/2): the hotplug area is not claimed in iomem, so the driver finds a free range there. This reserves address space the user may not want, and the HMM region then sits inside the hotplug area.
Prior art
QEMU's q35 bounds its 64-bit window (pci-hole64-size, 32 GiB by default) and leaves the rest unclaimed. The same guest image and GPU work there: CUDA succeeded 11/11 with HMM on. The driver places its HMM region at the top of the space:
e0000000000-e07ffffffff : PCI Bus 0000:00
3ffa18000000-3fffffffffff : nvidia-uvm-hmm
In this project, mmio64_aperture_weight already lets a user shape the 64-bit apertures per segment; this adds a size bound next to it.
API/CLI
- CLI: a new optional
mmio64_aperture_size=<size>on--pci-segment. - API: a matching optional field on
PciSegmentConfig(OpenAPI schema updated). - Validation: non-zero, multiple of 4 KiB.
- Without the option nothing changes, and configs without the field deserialize as before.
Testing
- Unit tests:
- the computed apertures: no bound, a bound above the share, single and multi-segment, the aarch64/riscv64 base;
- config parsing and validation;
- serde of an old config without the field.
- On hardware, same binary, same guest, HMM on:
--pci-segment CUDA ok 64-bit window in guest iomem
(none) 0/3 240000000-3fffffeeffff
pci_segment=0,mmio64_aperture_size=64G 3/3 240000000-123fffffff
pci_segment=0,mmio64_aperture_size=32G 2/2 240000000-a3fffffff
- With two segments and segment 0 capped, segment 1 kept its default range (200040000000-3fffffeeffff).
- CI: the GPU job would not catch this, because it checks only nvidia-smi (check_nvidia_gpu). A small CUDA step (e.g. cuInit + cuDeviceGet) in vfio::test_nvidia would. That needs the CUDA driver API in the guest image, but no new hardware.
Interactions
- Device hotplug: the bound must leave room for the 64-bit BARs of every device on the segment, including devices hotplugged later. The default stays unbounded, so large-BAR hotplug is unaffected unless the option is set.
- Memory hotplug (ACPI and virtio-mem): those areas sit below the 64-bit window and are unchanged.
- Multiple segments and weights: a capped segment keeps its start address and the rest of its weighted share is left unclaimed. Other segments stay in place.
- aarch64/riscv64: the FDT describes the 64-bit window only from PCI_HIGH_BASE (8 GiB) up, so there the bound counts from PCI_HIGH_BASE.
- Snapshot/restore and live migration: configs without the field restore as before. A VM using the option, restored on an older binary, loses the bound silently (unknown fields are ignored). Its devices keep their BARs, but a later hotplug could land above the window the guest was told about.
Implementation
Per the contribution guidelines I'm opening this as an issue first rather than a PR. A tested implementation is on a branch in my fork: https://github.com/cloud-hypervisor/cloud-hypervisor/compare/main...mushroomcarbon:cloud-hypervisor:vmm-mmio64-aperture-size. Happy to open it as a PR if acceptable.
Full feature description
Things we ruled out as the cause:
- PCI topology: QEMU with the GPU directly on pcie.0 (no root port) still works. Ubicloud's B200 write-up and kata-containers #13992 attribute this failure to the flat PCI topology, but that is not what we found on our hardware and setup.
- Where the BARs land: max_phys_bits=40 still fails.
- KASLR: nokaslr still fails. NVIDIA's CUDA 13.0 release notes attribute this error line to KASLR, but that is not the cause here.
open-gpu-kernel-modules #901 reports the same symptom with HMM on bare metal. We have not tested on B200s or other datacenter GPU setups.
Alternatives considered:
- A bounded default: simpler for users, but it changes the default layout, which raises the same cross-version migration concern as #8279. It also limits how large a BAR can be hotplugged by default. An opt-in avoids both.
- Allocating BARs at the start of the window (#8195) or lowering max_phys_bits: neither frees address space, because the guest is still told the whole window is in use.
- 主要语言
- Rust
- 星标
- 6.3k
- 派生
- 786
- 平均合并
- 1 天 3 小时
- 30 天内合并 PR
- 195
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
cloud-hypervisor/cloud-hypervisor 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 68/100
cloud-hypervisor/cloud-hypervisor#9562 · 5 条评论 ·
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 35/100
cloud-hypervisor/cloud-hypervisor#9553 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 48/100
cloud-hypervisor/cloud-hypervisor#9551 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 46/100
cloud-hypervisor/cloud-hypervisor#9550 ·
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 20/100
cloud-hypervisor/cloud-hypervisor#9528 · 2 个 reaction ·
维护者通常 1 天内回复
查看 cloud-hypervisor/cloud-hypervisor 的全部 Issue
相似的 Issue
-
bug nvim
难度 2/5 1-3 小时 新手友好度 74/100
-
chip:esp32c6 peripheral:dma
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
BrettMayson/HEMTT#1445 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 65/100
Choochmeque/tauri-plugin-webdriver#134 ·
维护者通常 17 天内回复
-
bug rust SDK & CLI & REST API
难度 2/5 1-3 小时 新手友好度 75/100
boxlite-ai/boxlite#3292 ·
维护者通常 1 天内回复