feat: allow selective VFIO BAR mapping - #7991
Conversation
|
@DamianB-BitFlipper It would help reviewers if you could explain "why" we need this feature in the PR description. |
|
My bad, should have been a draft... |
|
@saravan2 Do you know who would be most capable to review these changes, before I proceed to add integration changes and fix the commit history? I just want to make sure that these changes make sense. I also updated the description, adding the purpose of this PR. |
|
@DamianB-BitFlipper What about lazily mapping the BARs on first access, at 1G granularity? |
|
It might be a bit of a skills issue from my end, that I didn't implement it this way. But if I get some pointers as to how to do it, I'll happily try it out and test it too on our system. |
|
@DamianB-BitFlipper I can review your changes. The maintainers would chime in and shape your PR to get it ready for merge. @DemiMarie We can consider lazy bar mapping as a feature request because it requires significant changes to the MMIO exit path. |
3b0b06e to
51f60c6
Compare
Can you check if you have Every other path I checked is lazy fault-based. So if your ML applications never touch the large BARs, with vfio_p2p_dma=off there shouldn't be any penalty for mmaping the 100+GB VRAM BAR. |
|
I do not pass it, but |
|
I just did an AB test where I booted four VMs with a single H200 passthrough. Two were with Here are the attach times: vfio_p2p_dma off -> 12.336837652s, 12.514751692s With these numbers in mind, I think this feature is quite useful. |
0e5ed4b to
a489e6b
Compare
|
For curiosity's sake, what was the time taken for |
|
This is peculiar, I double checked I compiled and ran the right code. I am; those are the timings. |
|
@DamianB-BitFlipper Is it possible that your host distro is Rocky 9 or RHEL 9 based with a 5.1x kernel? Older kernels do not have hugepage VFIO support, so the mmap of VRAM BAR forces the host kernel to perform ioremap and KVM memslot metadata allocation at 4K granularity. The ~7 seconds you are shaving off with |
|
Nope. I'm running debian and kernel 6.16.9. I tried really hard to enable hugepage mmap for the iommu, but couldn't. |
|
My bad, that's the guest. On the host, I am running Ubuntu 24.04 and 6.8.0. |
|
Linux 6.8 kernel does not have hugepage VFIO mmap support. It was introduced in kernel 6.11. On 6.8, the ioremap inside On a 6.11+ kernel with hugepage support enabled, the same mmap should be significantly faster and the savings from |
|
Interesting, I didn't know. Though changing the host's kernel might be out of our control unfortunately. |
|
@rbradford Would the maintainers accept this PR that primarily helps cloud-hypervisor VMs boot and hotplug GPUs faster on hosts running older kernels ( pre 6.11 ) without hugepage VFIO mmap support ? |
You could also discuss this in tomorrows Cloud Hypervisor Office Hour. @DamianB-BitFlipper same link, same time! |
You can verify this thesis by comparing page table sizes When we dont mmap the large VRAM BAR on Linux 6.8 host kernel, the pagetable bloat would not be seen in CH and results in faster boot. @DamianB-BitFlipper Since iommu mapping is not the source of latency, can you update the PR description with accurate information if you are going to table this in the office hour ? |
|
We discussed today - all I think we need is a.) @saravan2's comment about it being page table related not IOMMU b.) Change to |
a489e6b to
b0eb134
Compare
|
Changes should be in! |
saravan2
left a comment
There was a problem hiding this comment.
Overall PR looks good.
Requested minor changes.
|
I think @saravan2 recommended to widen to u64. See #7991 (comment) |
Okey dokey - still have a whitespace issue to fix? |
likebreath
left a comment
There was a problem hiding this comment.
Apologies for the delayed review. Overall this looks good. Just one clarification needed on the logging message, see below.
Allow VFIO devices to list BAR indices that should not be mmapped into the guest. This lets operators skip large BARs that are known not to be used by their workload. When a BAR is skipped, the log also calls out that P2P DMA mapping is skipped because the VFIO DMA map path uses the same mmap backing. Signed-off-by: Damian Barabonkov <[email protected]> Assisted-by: OpenCode:gpt-5.5
Explain how operators can exclude selected VFIO BARs from mmap when they know their workloads do not require MMIO access to those regions. Documenting the option separately keeps the new device argument discoverable and calls out the valid BAR index range. Signed-off-by: Damian Barabonkov <[email protected]> Assisted-by: OpenCode:gpt-5.5
2ab73a8 to
8dd9d95
Compare
|
Fails on the VFIO test - timeout reached. Please investigate - might just need timeout increasing or could be a real issue |
|
I'll give it a look |
Exercise the new VFIO BAR exclusion option with NVIDIA passthrough tests so the integration suite checks that selected BARs are skipped. The tests cover both legacy VFIO and iommufd paths while preserving the existing hardware availability guards. Signed-off-by: Damian Barabonkov <[email protected]> Assisted-by: OpenCode:gpt-5.5
8dd9d95 to
b317097
Compare
|
@rbradford I updated the integration test. Can you retry adding to the merge queue please? |
|
@DamianB-BitFlipper Your new test caused integration test failures that kicked this change off the MQ - please investigate: https://github.com/cloud-hypervisor/cloud-hypervisor/actions/runs/25453310169/job/74677202205 |
|
@saravan2 made some suggestions in the review comment that should address the failing integration test. I'll open a follow up PR |
@DamianB-BitFlipper I had an offline conversation with @likebreath The standard hugepages supported in IOMMU via That was because the PFN walk in https://elixir.bootlin.com/linux/v6.8/source/drivers/vfio/vfio_iommu_type1.c#L608-L722 The support to map in hugepage size was added later in Linux kernel in commit So as @likebreath mentioned in his comment the tradeoff for fast boot/hotplug achieved through The current implementation we merged is correct and no further changes are necessary. |
Purpose
On older host kernels, mmaping a very large VFIO BAR can add noticeable boot and hotplug latency because of host-side BAR mmap overhead and page-table growth. This option allows selected BARs to stay trap-and-emulate instead of being mmapped into the guest when that tradeoff is preferable.
For the original GPU use case, the large VRAM BAR was the main target: keeping that BAR out of the mmap path improved attach time while leaving smaller BARs available to be mmapped normally.
Summary
x_exclude_mmap_barsto VFIO device configuration so specific BARs can stay trap-and-emulate instead of being mmapped into the guestVfioPciDevice::map_mmio_regions()for the selected BAR indices