Skip to content

Remove redundant code in mshv_vtl_main.c#145

Merged
namancse merged 1 commit into
product/hcl-main/6.18from
user/namjain/6.18-warn-fix-v5
Jun 10, 2026
Merged

Remove redundant code in mshv_vtl_main.c#145
namancse merged 1 commit into
product/hcl-main/6.18from
user/namjain/6.18-warn-fix-v5

Conversation

@namancse

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI review requested due to automatic review settings June 10, 2026 04:53
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>
@namancse namancse force-pushed the user/namjain/6.18-warn-fix-v5 branch from 7e326f4 to d092393 Compare June 10, 2026 04:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_ranges is traversed under RCU, but struct mshv_vtl_low_range currently lacks an rcu_head, which makes it hard to safely free entries via kfree_rcu() (and the current exit path reuses the list pointers before a grace period, see other comment). Add an rcu_head to 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 same list_head by linking it into the local stale list. This violates list_del_rcu()'s requirement to keep the forward pointer intact for in-flight list_for_each_entry_rcu() readers, and can corrupt RCU traversal before synchronize_rcu() runs. Prefer deleting with list_del_rcu() and deferring the free via kfree_rcu() (after adding an rcu_head to the node), eliminating the need to relink into stale/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.

@namancse namancse merged commit fd75aff into product/hcl-main/6.18 Jun 10, 2026
10 checks passed
@namancse namancse deleted the user/namjain/6.18-warn-fix-v5 branch June 10, 2026 05:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants