Remove redundant code in mshv_vtl_main.c#145
Merged
Merged
Conversation
mshv_vtl_exit() calls misc_deregister(&mshv_vtl_sint_dev) and misc_deregister(&mshv_vtl_low) twice. The first pair (added when the TDX APIC handling code was introduced) is redundant: the same deregistrations are performed again a few lines below, in the order that mirrors the registration sequence in mshv_vtl_init(). Calling misc_deregister() twice on the same struct miscdevice is not safe -- it ends up doing list_del() twice on the device's misc_list node, corrupting the global list and yielding 'list_del corruption' splats on rmmod (or any module exit path). Drop the redundant calls so each device is deregistered exactly once, in the reverse order of registration. Fixes: 06eb1e3 ("mshv_vtl/tdx: Handle some APIC functionality in kernel") Signed-off-by: Naman Jain <namjain@linux.microsoft.com>
7e326f4 to
d092393
Compare
hargar19
approved these changes
Jun 10, 2026
There was a problem hiding this comment.
Pull request overview
This PR changes how /dev/mshv_vtl_low page faults determine whether a PFN belongs to an mshv_vtl-owned dev_pagemap, aiming to avoid a race where get_dev_pagemap() can observe a pgmap before the vmemmap/struct page backing is fully initialized.
Changes:
- Introduces a driver-owned RCU-published list of “ready” PFN ranges, populated only after
devm_memremap_pages()completes. - Updates the low-fault PFN resolution path to consult the published ranges and then validate ownership via
page_pgmap(). - Adds module-exit teardown to unlink and free the published range metadata.
Comments suppressed due to low confidence (2)
drivers/hv/mshv_vtl_main.c:1181
mshv_vtl_low_rangesis traversed under RCU, butstruct mshv_vtl_low_rangecurrently lacks anrcu_head, which makes it hard to safely free entries viakfree_rcu()(and the current exit path reuses the list pointers before a grace period, see other comment). Add anrcu_headto the node so deletion can defer freeing without touching the forward link that RCU readers may still be using.
struct mshv_vtl_low_range {
struct list_head list;
unsigned long start_pfn;
unsigned long end_pfn; /* exclusive */
};
drivers/hv/mshv_vtl_main.c:4123
- The module-exit cleanup deletes entries with
list_del_rcu()and then immediately reuses the samelist_headby linking it into the localstalelist. This violateslist_del_rcu()'s requirement to keep the forward pointer intact for in-flightlist_for_each_entry_rcu()readers, and can corrupt RCU traversal beforesynchronize_rcu()runs. Prefer deleting withlist_del_rcu()and deferring the free viakfree_rcu()(after adding anrcu_headto the node), eliminating the need to relink intostale/synchronize_rcu().
spin_lock(&mshv_vtl_low_ranges_lock);
list_for_each_entry_safe(r, tmp, &mshv_vtl_low_ranges, list) {
list_del_rcu(&r->list);
list_add(&r->list, &stale);
}
spin_unlock(&mshv_vtl_low_ranges_lock);
synchronize_rcu();
list_for_each_entry_safe(r, tmp, &stale, list)
kfree(r);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
No description provided.