tools/testing/selftests/kvm/lib/guest_modes.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/kvm/lib/guest_modes.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/kvm/lib/guest_modes.c- Extension
.c- Size
- 4453 bytes
- Lines
- 157
- 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
guest_modes.hprocessor.h
Detected Declarations
function guest_modes_append_defaultfunction for_each_guest_modefunction guest_modes_helpfunction guest_modes_cmdline
Annotated Snippet
switch (sz) {
case 59:
guest_mode_append(VM_MODE_P56V57_4K, satp_mode >= SATP_MODE_57);
guest_mode_append(VM_MODE_P56V48_4K, satp_mode >= SATP_MODE_48);
guest_mode_append(VM_MODE_P56V39_4K, satp_mode >= SATP_MODE_39);
break;
case 50:
guest_mode_append(VM_MODE_P50V57_4K, satp_mode >= SATP_MODE_57);
guest_mode_append(VM_MODE_P50V48_4K, satp_mode >= SATP_MODE_48);
guest_mode_append(VM_MODE_P50V39_4K, satp_mode >= SATP_MODE_39);
break;
case 41:
guest_mode_append(VM_MODE_P41V57_4K, satp_mode >= SATP_MODE_57);
guest_mode_append(VM_MODE_P41V48_4K, satp_mode >= SATP_MODE_48);
guest_mode_append(VM_MODE_P41V39_4K, satp_mode >= SATP_MODE_39);
break;
default:
break;
}
/* set the first supported mode as default */
vm_mode_default = NUM_VM_MODES;
for (i = 0; vm_mode_default == NUM_VM_MODES && i < NUM_VM_MODES; i++) {
if (guest_modes[i].supported && guest_modes[i].enabled)
vm_mode_default = i;
}
TEST_ASSERT(vm_mode_default != NUM_VM_MODES, "No supported mode!");
}
#endif
}
void for_each_guest_mode(void (*func)(enum vm_guest_mode, void *), void *arg)
{
int i;
for (i = 0; i < NUM_VM_MODES; ++i) {
if (!guest_modes[i].enabled)
continue;
TEST_ASSERT(guest_modes[i].supported,
"Guest mode ID %d (%s) not supported.",
i, vm_guest_mode_string(i));
func(i, arg);
}
}
void guest_modes_help(void)
{
int i;
printf(" -m: specify the guest mode ID to test\n"
" (default: test all supported modes)\n"
" This option may be used multiple times.\n"
" Guest mode IDs:\n");
for (i = 0; i < NUM_VM_MODES; ++i) {
printf(" %d: %s%s\n", i, vm_guest_mode_string(i),
guest_modes[i].supported ? " (supported)" : "");
}
}
void guest_modes_cmdline(const char *arg)
{
static bool mode_selected;
unsigned int mode;
int i;
if (!mode_selected) {
for (i = 0; i < NUM_VM_MODES; ++i)
guest_modes[i].enabled = false;
mode_selected = true;
}
mode = atoi_non_negative("Guest mode ID", arg);
TEST_ASSERT(mode < NUM_VM_MODES, "Guest mode ID %d too big", mode);
guest_modes[mode].enabled = true;
}
Annotation
- Immediate include surface: `guest_modes.h`, `processor.h`.
- Detected declarations: `function guest_modes_append_default`, `function for_each_guest_mode`, `function guest_modes_help`, `function guest_modes_cmdline`.
- 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.