/* *Spinuntilthememoryregionstartsgettingmovedtoa *misalignedaddress. *EveryregionmovemayormaynottriggerMMIO,asthe *windowwherethememslotisinvalidisusuallyquitesmall.
*/
val = guest_spin_on_val(0);
__GUEST_ASSERT(val == 1 || val == MMIO_VAL, "Expected '1' or MMIO ('%lx'), got '%lx'", MMIO_VAL, val);
/* Spin until the misaligning memory region move completes. */
val = guest_spin_on_val(MMIO_VAL);
__GUEST_ASSERT(val == 1 || val == 0, "Expected '0' or '1' (no MMIO), got '%lx'", val);
/* Spin until the memory region starts to get re-aligned. */
val = guest_spin_on_val(0);
__GUEST_ASSERT(val == 1 || val == MMIO_VAL, "Expected '1' or MMIO ('%lx'), got '%lx'", MMIO_VAL, val);
/* Spin until the re-aligning memory region move completes. */
val = guest_spin_on_val(MMIO_VAL);
GUEST_ASSERT_EQ(val, 1);
/* Restore the original base, the guest should see "1". */
vm_mem_region_move(vm, MEM_REGION_SLOT, MEM_REGION_GPA);
wait_for_vcpu(); /* Defered sync from when the memslot was misaligned (above). */
wait_for_vcpu();
vm = spawn_vm(&vcpu, &vcpu_thread, guest_code_delete_memory_region);
if (disable_slot_zap_quirk)
vm_enable_cap(vm, KVM_CAP_DISABLE_QUIRKS2, KVM_X86_QUIRK_SLOT_ZAP_ALL);
/* Delete the memory region, the guest should not die. */
vm_mem_region_delete(vm, MEM_REGION_SLOT);
wait_for_vcpu();
/* Recreate the memory region. The guest should see "0". */
vm_userspace_mem_region_add(vm, VM_MEM_SRC_ANONYMOUS_THP,
MEM_REGION_GPA, MEM_REGION_SLOT,
MEM_REGION_SIZE / getpagesize(), 0);
wait_for_vcpu();
/* Delete the region again so that there's only one memslot left. */
vm_mem_region_delete(vm, MEM_REGION_SLOT);
wait_for_vcpu();
#ifdefined __aarch64__ || defined __riscv || defined __x86_64__ || defined __loongarch__
supported_flags |= KVM_MEM_READONLY; #endif
#ifdef __x86_64__ if (kvm_check_cap(KVM_CAP_VM_TYPES) & BIT(KVM_X86_SW_PROTECTED_VM))
vm = vm_create_barebones_type(KVM_X86_SW_PROTECTED_VM); else #endif
vm = vm_create_barebones();
if (kvm_check_cap(KVM_CAP_MEMORY_ATTRIBUTES) & KVM_MEMORY_ATTRIBUTE_PRIVATE)
supported_flags |= KVM_MEM_GUEST_MEMFD;
for (i = 0; i < 32; i++) { if ((supported_flags & BIT(i)) && !(v2_only_flags & BIT(i))) continue;
r = __vm_set_user_memory_region(vm, 0, BIT(i), 0, MEM_REGION_SIZE, NULL);
TEST_ASSERT(r && errno == EINVAL, "KVM_SET_USER_MEMORY_REGION should have failed on v2 only flag 0x%lx", BIT(i));
if (supported_flags & BIT(i)) continue;
r = __vm_set_user_memory_region2(vm, 0, BIT(i), 0, MEM_REGION_SIZE, NULL, 0, 0);
TEST_ASSERT(r && errno == EINVAL, "KVM_SET_USER_MEMORY_REGION2 should have failed on unsupported flag 0x%lx", BIT(i));
}
if (supported_flags & KVM_MEM_GUEST_MEMFD) { int guest_memfd = vm_create_guest_memfd(vm, MEM_REGION_SIZE, 0);
r = __vm_set_user_memory_region2(vm, 0,
KVM_MEM_LOG_DIRTY_PAGES | KVM_MEM_GUEST_MEMFD, 0, MEM_REGION_SIZE, NULL, guest_memfd, 0);
TEST_ASSERT(r && errno == EINVAL, "KVM_SET_USER_MEMORY_REGION2 should have failed, dirty logging private memory is unsupported");
r = __vm_set_user_memory_region2(vm, 0,
KVM_MEM_READONLY | KVM_MEM_GUEST_MEMFD, 0, MEM_REGION_SIZE, NULL, guest_memfd, 0);
TEST_ASSERT(r && errno == EINVAL, "KVM_SET_USER_MEMORY_REGION2 should have failed, read-only GUEST_MEMFD memslots are unsupported");
#ifdef __s390x__ /* On s390x, the host address must be aligned to 1M (due to PGSTEs) */
alignment = 0x100000; #else
alignment = 1; #endif
max_mem_slots = kvm_check_cap(KVM_CAP_NR_MEMSLOTS);
TEST_ASSERT(max_mem_slots > 0, "KVM_CAP_NR_MEMSLOTS should be greater than 0");
pr_info("Allowed number of memory slots: %i\n", max_mem_slots);
vm = vm_create_barebones();
/* Check it can be added memory slots up to the maximum allowed */
pr_info("Adding slots 0..%i, each memory region with %dK size\n",
(max_mem_slots - 1), MEM_REGION_SIZE >> 10);
memfd = vm_create_guest_memfd(vm, MEM_REGION_SIZE, 0); for (i = 1; i < PAGE_SIZE; i++)
test_invalid_guest_memfd(vm, memfd, i, "Unaligned offset should fail");
/* Overlap the front half of the other slot. */
r = __vm_set_user_memory_region2(vm, MEM_REGION_SLOT, KVM_MEM_GUEST_MEMFD,
MEM_REGION_GPA * 2 - MEM_REGION_SIZE,
MEM_REGION_SIZE * 2, 0, memfd, 0);
TEST_ASSERT(r == -1 && errno == EEXIST, "%s", "Overlapping guest_memfd() bindings should fail with EEXIST");
/* And now the back half of the other slot. */
r = __vm_set_user_memory_region2(vm, MEM_REGION_SLOT, KVM_MEM_GUEST_MEMFD,
MEM_REGION_GPA * 2 + MEM_REGION_SIZE,
MEM_REGION_SIZE * 2, 0, memfd, 0);
TEST_ASSERT(r == -1 && errno == EEXIST, "%s", "Overlapping guest_memfd() bindings should fail with EEXIST");
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.