arch/x86/kvm/mmu/page_track.c
Source file repositories/reference/linux-study-clean/arch/x86/kvm/mmu/page_track.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/kvm/mmu/page_track.c- Extension
.c- Size
- 9501 bytes
- Lines
- 375
- Domain
- Architecture Layer
- Bucket
- arch/x86
- Inferred role
- Architecture Layer: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/lockdep.hlinux/kvm_host.hlinux/rculist.hmmu.hmmu_internal.hpage_track.h
Detected Declarations
function Copyrightfunction kvm_page_track_write_tracking_enabledfunction kvm_page_track_free_memslotfunction __kvm_page_track_write_tracking_allocfunction kvm_page_track_create_memslotfunction kvm_page_track_write_tracking_allocfunction update_gfn_write_trackfunction __kvm_write_track_add_gfnfunction __kvm_write_track_remove_gfnfunction kvm_gfn_is_write_trackedfunction kvm_page_track_cleanupfunction kvm_page_track_initfunction kvm_enable_external_write_trackingfunction kvm_for_each_memslotfunction kvm_page_track_register_notifierfunction kvm_page_track_register_notifierfunction __kvm_page_track_writefunction kvm_page_track_delete_slotfunction kvm_write_track_add_gfnfunction kvm_write_track_remove_gfnexport kvm_page_track_register_notifierexport kvm_page_track_unregister_notifierexport kvm_write_track_add_gfnexport kvm_write_track_remove_gfn
Annotated Snippet
kvm_for_each_memslot(slot, bkt, slots) {
/*
* Intentionally do NOT free allocations on failure to
* avoid having to track which allocations were made
* now versus when the memslot was created. The
* metadata is guaranteed to be freed when the slot is
* freed, and will be kept/used if userspace retries
* the failed ioctl() instead of killing the VM.
*/
r = kvm_page_track_write_tracking_alloc(slot);
if (r)
goto out_unlock;
}
}
out_success:
/*
* Ensure that external_write_tracking_enabled becomes true strictly
* after all the related pointers are set.
*/
smp_store_release(&kvm->arch.external_write_tracking_enabled, true);
out_unlock:
mutex_unlock(&kvm->slots_arch_lock);
return r;
}
/*
* register the notifier so that event interception for the tracked guest
* pages can be received.
*/
int kvm_page_track_register_notifier(struct kvm *kvm,
struct kvm_page_track_notifier_node *n)
{
struct kvm_page_track_notifier_head *head;
int r;
if (!kvm || kvm->mm != current->mm)
return -ESRCH;
if (!kvm_external_write_tracking_enabled(kvm)) {
r = kvm_enable_external_write_tracking(kvm);
if (r)
return r;
}
kvm_get_kvm(kvm);
head = &kvm->arch.track_notifier_head;
write_lock(&kvm->mmu_lock);
hlist_add_head_rcu(&n->node, &head->track_notifier_list);
write_unlock(&kvm->mmu_lock);
return 0;
}
EXPORT_SYMBOL_GPL(kvm_page_track_register_notifier);
/*
* stop receiving the event interception. It is the opposed operation of
* kvm_page_track_register_notifier().
*/
void kvm_page_track_unregister_notifier(struct kvm *kvm,
struct kvm_page_track_notifier_node *n)
{
struct kvm_page_track_notifier_head *head;
head = &kvm->arch.track_notifier_head;
write_lock(&kvm->mmu_lock);
hlist_del_rcu(&n->node);
write_unlock(&kvm->mmu_lock);
synchronize_srcu(&head->track_srcu);
kvm_put_kvm(kvm);
}
EXPORT_SYMBOL_GPL(kvm_page_track_unregister_notifier);
/*
* Notify the node that write access is intercepted and write emulation is
* finished at this time.
*
* The node should figure out if the written page is the one that node is
* interested in by itself.
*/
void __kvm_page_track_write(struct kvm *kvm, gpa_t gpa, const u8 *new, int bytes)
{
struct kvm_page_track_notifier_head *head;
struct kvm_page_track_notifier_node *n;
int idx;
head = &kvm->arch.track_notifier_head;
Annotation
- Immediate include surface: `linux/lockdep.h`, `linux/kvm_host.h`, `linux/rculist.h`, `mmu.h`, `mmu_internal.h`, `page_track.h`.
- Detected declarations: `function Copyright`, `function kvm_page_track_write_tracking_enabled`, `function kvm_page_track_free_memslot`, `function __kvm_page_track_write_tracking_alloc`, `function kvm_page_track_create_memslot`, `function kvm_page_track_write_tracking_alloc`, `function update_gfn_write_track`, `function __kvm_write_track_add_gfn`, `function __kvm_write_track_remove_gfn`, `function kvm_gfn_is_write_tracked`.
- Atlas domain: Architecture Layer / arch/x86.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.