[WIP] usdm: add hugepage allocation fallback for VFIO#145
Open
[WIP] usdm: add hugepage allocation fallback for VFIO#145
Conversation
When hugepages are configured but none are free (e.g. all consumed by DPDK), QATlib VFIO hugepage allocations fail with no fallback, breaking all QAT hardware offload. Add a three-layer defense: 1. Init-time check: Read free_hugepages from sysfs during __qae_vfio_init_hugepages(). If zero, disable hugepage mode immediately. 2. Runtime fallback: If hugepage slab allocation fails and no hugepage slab has ever been successfully allocated, disable hugepage mode and fall back to regular (4KB) VFIO memory allocation via ioctl path. 3. Mixed-state guard: If hugepage slabs already exist, refuse to fall back to avoid mixing 2MB and 4KB page table entries which would corrupt IOVA mappings. Also fix store_mmap_range() to derive page table granularity from the actual slab type (p_ctrl_blk->type) rather than the global hugepage mode flag, ensuring correctness after fallback. Signed-off-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
fionatrahe
reviewed
Mar 3, 2026
| */ | ||
| snprintf(free_hp_path, sizeof(free_hp_path), "%s/%s/free_hugepages", | ||
| sys_dir_path, HUGEPAGE_SYS_NODE); | ||
| if (parse_sysfs_value(free_hp_path, &free_hp) == 0 && free_hp == 0) |
Contributor
There was a problem hiding this comment.
If the parse fails (returns -1) g_num_hugepages will not be set to 0 here. Shouldn't the logic be:
if (parse... == 0)
{
if (free_hp == 0)
g_num_hugepages = 0;
}
else // failed to parse the free_hugepages value
{
g_num_hugepages = 0;
}
Contributor
Author
There was a problem hiding this comment.
Yes, right. Can be written:
ret = parse_sysfs_value(free_hp_path, &free_hp);
if (ret || ret == 0 && free_hp == 0) {
g_num_hugepages = 0;
}
This way the return value can be preserved and returned to the calleer.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When hugepages are configured but none are free (e.g. all consumed by DPDK), QATlib VFIO hugepage allocations fail with no fallback, breaking all QAT hardware offload.
Add a three-layer defense:
Init-time check: Read free_hugepages from sysfs during __qae_vfio_init_hugepages(). If zero, disable hugepage mode immediately.
Runtime fallback: If hugepage slab allocation fails and no hugepage slab has ever been successfully allocated, disable hugepage mode and fall back to regular (4KB) VFIO memory allocation via ioctl path.
Mixed-state guard: If hugepage slabs already exist, refuse to fall back to avoid mixing 2MB and 4KB page table entries which would corrupt IOVA mappings.
Also fix store_mmap_range() to derive page table granularity from the actual slab type (p_ctrl_blk->type) rather than the global hugepage mode flag, ensuring correctness after fallback.