@@ -82,11 +82,45 @@ struct userspace_mem_regions {
DECLARE_HASHTABLE(slot_hash, 9);
};
+/*
+ * Memory region types are passed to various page allocators to communicate
+ * various properties and metadata related to the allocation. Note, the
+ * descriptions below described the primary usage of each type. Individual
+ * tests may allocate memory for other purposes.
+ *
+ * By default, all regions except TEST_EXTRA are mapped to memslot '0'. The
+ * TEXT_EXTRA region is left unmapped as it's intended to be used only for test
+ * specific allocations, i.e. should never be used by core/infrastructure code.
+ * Tests can override the memslot for any or all types, e.g. so that all test
+ * data is allocated from a curated memslot.
+ */
enum kvm_mem_region_type {
+ /*
+ * The CODE region is used by lib/elf when loading the test's code into
+ * guest memory.
+ */
MEM_REGION_CODE,
+ /*
+ * The DATA region is used to allocate core data structures, e.g. vCPU
+ * stacks, VM exception tables, x86's TSS, etc.
+ */
MEM_REGION_DATA,
+ /*
+ * The PT region, a.k.a. Page Table region, is used to allocate page
+ * table pages.
+ */
MEM_REGION_PT,
+ /*
+ * The TEST_DATA region is used for allocating test data that is either
+ * test specific, and/or isn't considered a "core" data structure.
+ */
MEM_REGION_TEST_DATA,
+ /*
+ * The TEST_EXTRA region is for special snowflakes, where a test wants
+ * to create and use a one-off memslot, without impacting "normal" test
+ * data allocations.
+ */
+ MEM_REGION_TEST_EXTRA,
NR_MEM_REGIONS,
};
@@ -129,11 +163,6 @@ struct kvm_vm {
struct kvm_binary_stats stats;
- /*
- * KVM region slots. These are the default memslots used by page
- * allocators, e.g., lib/elf uses the memslots[MEM_REGION_CODE]
- * memslot.
- */
u32 memslots[NR_MEM_REGIONS];
};
@@ -8,7 +8,7 @@
#define SMRAM_MEMSLOT ((1 << 16) | 1)
#define SMRAM_PAGES (SMRAM_SIZE / PAGE_SIZE)
-void setup_smram(struct kvm_vm *vm, struct kvm_vcpu *vcpu, u64 smram_gpa,
+void setup_smram(struct kvm_vm *vm, struct kvm_vcpu *vcpu, gpa_t smram_gpa,
const void *smi_handler, size_t handler_size);
void inject_smi(struct kvm_vcpu *vcpu);
@@ -1468,11 +1468,12 @@ bool kvm_arch_has_default_irqchip(void)
return true;
}
-void setup_smram(struct kvm_vm *vm, struct kvm_vcpu *vcpu, u64 smram_gpa,
+void setup_smram(struct kvm_vm *vm, struct kvm_vcpu *vcpu, gpa_t smram_gpa,
const void *smi_handler, size_t handler_size)
{
- vm_userspace_mem_region_add(vm, VM_MEM_SRC_ANONYMOUS, smram_gpa,
- SMRAM_MEMSLOT, SMRAM_PAGES, 0);
+ vm_override_mem_region(vm, MEM_REGION_TEST_EXTRA, VM_MEM_SRC_ANONYMOUS,
+ smram_gpa, SMRAM_MEMSLOT, SMRAM_PAGES);
+
TEST_ASSERT(vm_phy_pages_alloc(vm, SMRAM_PAGES, smram_gpa,
SMRAM_MEMSLOT) == smram_gpa,
"Could not allocate guest physical addresses for SMRAM");