tools/testing/selftests/kvm/dirty_log_test.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/kvm/dirty_log_test.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/kvm/dirty_log_test.c- Extension
.c- Size
- 27081 bytes
- Lines
- 921
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
stdio.hstdlib.hpthread.hsemaphore.hsys/types.hsignal.herrno.hlinux/bitmap.hlinux/bitops.hlinux/atomic.hasm/barrier.hkvm_util.htest_util.hguest_modes.hprocessor.hucall_common.h
Detected Declarations
struct log_modestruct test_paramsenum log_mode_tfunction guest_codefunction clear_log_supportedfunction clear_log_create_vm_donefunction dirty_log_collect_dirty_pagesfunction clear_log_collect_dirty_pagesfunction vcpu_handle_sync_stopfunction default_after_vcpu_runfunction dirty_ring_supportedfunction dirty_ring_create_vm_donefunction dirty_gfn_is_dirtiedfunction dirty_gfn_set_collectedfunction dirty_ring_collect_onefunction dirty_ring_collect_dirty_pagesfunction dirty_ring_after_vcpu_runfunction log_modes_dumpfunction log_mode_supportedfunction log_mode_create_vm_donefunction log_mode_collect_dirty_pagesfunction log_mode_after_vcpu_runfunction vm_dirty_log_verifyfunction run_testfunction helpfunction main
Annotated Snippet
struct log_mode {
const char *name;
/* Return true if this mode is supported, otherwise false */
bool (*supported)(void);
/* Hook when the vm creation is done (before vcpu creation) */
void (*create_vm_done)(struct kvm_vm *vm);
/* Hook to collect the dirty pages into the bitmap provided */
void (*collect_dirty_pages) (struct kvm_vcpu *vcpu, int slot,
void *bitmap, u32 num_pages,
u32 *ring_buf_idx);
/* Hook to call when after each vcpu run */
void (*after_vcpu_run)(struct kvm_vcpu *vcpu);
} log_modes[LOG_MODE_NUM] = {
{
.name = "dirty-log",
.collect_dirty_pages = dirty_log_collect_dirty_pages,
.after_vcpu_run = default_after_vcpu_run,
},
{
.name = "clear-log",
.supported = clear_log_supported,
.create_vm_done = clear_log_create_vm_done,
.collect_dirty_pages = clear_log_collect_dirty_pages,
.after_vcpu_run = default_after_vcpu_run,
},
{
.name = "dirty-ring",
.supported = dirty_ring_supported,
.create_vm_done = dirty_ring_create_vm_done,
.collect_dirty_pages = dirty_ring_collect_dirty_pages,
.after_vcpu_run = dirty_ring_after_vcpu_run,
},
};
static void log_modes_dump(void)
{
int i;
printf("all");
for (i = 0; i < LOG_MODE_NUM; i++)
printf(", %s", log_modes[i].name);
printf("\n");
}
static bool log_mode_supported(void)
{
struct log_mode *mode = &log_modes[host_log_mode];
if (mode->supported)
return mode->supported();
return true;
}
static void log_mode_create_vm_done(struct kvm_vm *vm)
{
struct log_mode *mode = &log_modes[host_log_mode];
if (mode->create_vm_done)
mode->create_vm_done(vm);
}
static void log_mode_collect_dirty_pages(struct kvm_vcpu *vcpu, int slot,
void *bitmap, u32 num_pages,
u32 *ring_buf_idx)
{
struct log_mode *mode = &log_modes[host_log_mode];
TEST_ASSERT(mode->collect_dirty_pages != NULL,
"collect_dirty_pages() is required for any log mode!");
mode->collect_dirty_pages(vcpu, slot, bitmap, num_pages, ring_buf_idx);
}
static void log_mode_after_vcpu_run(struct kvm_vcpu *vcpu)
{
struct log_mode *mode = &log_modes[host_log_mode];
if (mode->after_vcpu_run)
mode->after_vcpu_run(vcpu);
}
static void *vcpu_worker(void *data)
{
struct kvm_vcpu *vcpu = data;
sem_wait(&sem_vcpu_cont);
while (!READ_ONCE(host_quit)) {
/* Let the guest dirty the random pages */
vcpu_run(vcpu);
Annotation
- Immediate include surface: `stdio.h`, `stdlib.h`, `pthread.h`, `semaphore.h`, `sys/types.h`, `signal.h`, `errno.h`, `linux/bitmap.h`.
- Detected declarations: `struct log_mode`, `struct test_params`, `enum log_mode_t`, `function guest_code`, `function clear_log_supported`, `function clear_log_create_vm_done`, `function dirty_log_collect_dirty_pages`, `function clear_log_collect_dirty_pages`, `function vcpu_handle_sync_stop`, `function default_after_vcpu_run`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
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.