Skip to content

Commit

Permalink
KVM: selftest: Add support for creating non-default type VMs
Browse files Browse the repository at this point in the history
Currently vm_create function only creates KVM_X86_LEGACY_VM type VMs.
Changing the vm_create function to accept type parameter to create
new VM types.

Signed-off-by: Erdem Aktas <erdemaktas@google.com>
Reviewed-by: Sean Christopherson <seanjc@google.com>
Reviewed-by: Peter Gonda <pgonda@google.com>
Reviewed-by: Marc Orr <marcorr@google.com>
Reviewed-by: Sagi Shahar <sagis@google.com>
Reviewed-by: David Matlack <dmatlack@google.com>
  • Loading branch information
ruleof2 authored and yamahata committed Aug 22, 2022
1 parent b27980d commit 38b15ce
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions tools/testing/selftests/kvm/include/kvm_util_base.h
Expand Up @@ -273,6 +273,7 @@ static inline void vm_enable_cap(struct kvm_vm *vm, uint32_t cap, uint64_t arg0)
void vm_enable_dirty_ring(struct kvm_vm *vm, uint32_t ring_size);
const char *vm_guest_mode_string(uint32_t i);

struct kvm_vm *______vm_create(enum vm_guest_mode mode, uint64_t phy_pages, int perm, int type); /* FIXME */
void kvm_vm_free(struct kvm_vm *vmp);
void kvm_vm_restart(struct kvm_vm *vmp);
void kvm_vm_release(struct kvm_vm *vmp);
Expand Down
31 changes: 30 additions & 1 deletion tools/testing/selftests/kvm/lib/kvm_util.c
Expand Up @@ -143,6 +143,35 @@ const struct vm_guest_mode_params vm_guest_mode_params[] = {
_Static_assert(sizeof(vm_guest_mode_params)/sizeof(struct vm_guest_mode_params) == NUM_VM_MODES,
"Missing new mode params?");

#if 0 /* FIXME */
/*
* VM Create with a custom type
*
* Input Args:
* mode - VM Mode (e.g. VM_MODE_P52V48_4K)
* phy_pages - Physical memory pages
* perm - permission
* type - VM type
*
* Output Args: None
*
* Return:
* Pointer to opaque structure that describes the created VM.
*
* Creates a VM with the mode specified by mode (e.g. VM_MODE_P52V48_4K) and the
* type specified in type (e.g. KVM_X86_LEGACY_VM, KVM_X86_TDX_VM ...).
* When phy_pages is non-zero, a memory region of phy_pages physical pages
* is created and mapped starting at guest physical address 0. The file
* descriptor to control the created VM is created with the permissions
* given by perm (e.g. O_RDWR).
*/
struct kvm_vm *__vm_create(enum vm_guest_mode mode, uint64_t phy_pages,
int perm, int type)
{
/*FIXME */
}
#endif

struct kvm_vm *____vm_create(enum vm_guest_mode mode, uint64_t nr_pages)
{
struct kvm_vm *vm;
Expand All @@ -159,7 +188,7 @@ struct kvm_vm *____vm_create(enum vm_guest_mode mode, uint64_t nr_pages)
hash_init(vm->regions.slot_hash);

vm->mode = mode;
vm->type = 0;
vm->type = type;

vm->pa_bits = vm_guest_mode_params[mode].pa_bits;
vm->va_bits = vm_guest_mode_params[mode].va_bits;
Expand Down

0 comments on commit 38b15ce

Please sign in to comment.