CUDA fails in guests with a passed-through NVIDIA GPU: the 64-bit PCI window leaves no free range for HMM
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 30/100
Piste de recherche
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.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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.
- Langage dominant
- Rust
- Étoiles
- 6.3k
- Forks
- 786
- Merge moyen
- 1 j 3 h
- PR mergées (30 j)
- 195
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Aucun modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de cloud-hypervisor/cloud-hypervisor
-
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
cloud-hypervisor/cloud-hypervisor#9562 · 5 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 35/100
cloud-hypervisor/cloud-hypervisor#9553 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 4/5 3-5 jours Accessibilité débutants 48/100
cloud-hypervisor/cloud-hypervisor#9551 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 4/5 3-5 jours Accessibilité débutants 46/100
cloud-hypervisor/cloud-hypervisor#9550 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 20/100
cloud-hypervisor/cloud-hypervisor#9528 · 2 réactions ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de cloud-hypervisor/cloud-hypervisor
Issues similaires
-
bug nvim
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
-
chip:esp32c6 peripheral:dma
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
esp-rs/esp-hal#7037 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
BrettMayson/HEMTT#1445 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 65/100
Choochmeque/tauri-plugin-webdriver#134 ·
Les mainteneurs répondent en général sous 17 jours
-
bug(c-sdk): boxlite_box_exec does not check runtime liveness before dispatching streaming execOuvertebug rust SDK & CLI & REST API
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
boxlite-ai/boxlite#3292 ·
Les mainteneurs répondent en général sous 1 jour