virt: acrn: Introduce EPT mapping management
The HSM provides hypervisor services to the ACRN userspace. While
launching a User VM, ACRN userspace needs to allocate memory and request
the ACRN Hypervisor to set up the EPT mapping for the VM.
A mapping cache is introduced for accelerating the translation between
the Service VM kernel virtual address and User VM physical address.
>From the perspective of the hypervisor, the types of GPA of User VM can be
listed as following:
1) RAM region, which is used by User VM as system ram.
2) MMIO region, which is recognized by User VM as MMIO. MMIO region is
used to be utilized for devices emulation.
Generally, User VM RAM regions mapping is set up before VM started and
is released in the User VM destruction. MMIO regions mapping may be set
and unset dynamically during User VM running.
To achieve this, ioctls ACRN_IOCTL_SET_MEMSEG and ACRN_IOCTL_UNSET_MEMSEG
are introduced in HSM.
Cc: Zhi Wang <zhi.a.wang@intel.com>
Cc: Zhenyu Wang <zhenyuw@linux.intel.com>
Cc: Yu Wang <yu1.wang@intel.com>
Cc: Reinette Chatre <reinette.chatre@intel.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Zhi Wang <zhi.a.wang@intel.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Shuo Liu <shuo.a.liu@intel.com>
Link: https://lore.kernel.org/r/20210207031040.49576-9-shuo.a.liu@intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
2ad2aaee1b
commit
88f537d5e8
@@ -12,26 +12,104 @@
|
||||
|
||||
extern struct miscdevice acrn_dev;
|
||||
|
||||
#define ACRN_MEM_MAPPING_MAX 256
|
||||
|
||||
#define ACRN_MEM_REGION_ADD 0
|
||||
#define ACRN_MEM_REGION_DEL 2
|
||||
/**
|
||||
* struct vm_memory_region_op - Hypervisor memory operation
|
||||
* @type: Operation type (ACRN_MEM_REGION_*)
|
||||
* @attr: Memory attribute (ACRN_MEM_TYPE_* | ACRN_MEM_ACCESS_*)
|
||||
* @user_vm_pa: Physical address of User VM to be mapped.
|
||||
* @service_vm_pa: Physical address of Service VM to be mapped.
|
||||
* @size: Size of this region.
|
||||
*
|
||||
* Structure containing needed information that is provided to ACRN Hypervisor
|
||||
* to manage the EPT mappings of a single memory region of the User VM. Several
|
||||
* &struct vm_memory_region_op can be batched to ACRN Hypervisor, see &struct
|
||||
* vm_memory_region_batch.
|
||||
*/
|
||||
struct vm_memory_region_op {
|
||||
u32 type;
|
||||
u32 attr;
|
||||
u64 user_vm_pa;
|
||||
u64 service_vm_pa;
|
||||
u64 size;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct vm_memory_region_batch - A batch of vm_memory_region_op.
|
||||
* @vmid: A User VM ID.
|
||||
* @reserved: Reserved.
|
||||
* @regions_num: The number of vm_memory_region_op.
|
||||
* @regions_gpa: Physical address of a vm_memory_region_op array.
|
||||
*
|
||||
* HC_VM_SET_MEMORY_REGIONS uses this structure to manage EPT mappings of
|
||||
* multiple memory regions of a User VM. A &struct vm_memory_region_batch
|
||||
* contains multiple &struct vm_memory_region_op for batch processing in the
|
||||
* ACRN Hypervisor.
|
||||
*/
|
||||
struct vm_memory_region_batch {
|
||||
u16 vmid;
|
||||
u16 reserved[3];
|
||||
u32 regions_num;
|
||||
u64 regions_gpa;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct vm_memory_mapping - Memory map between a User VM and the Service VM
|
||||
* @pages: Pages in Service VM kernel.
|
||||
* @npages: Number of pages.
|
||||
* @service_vm_va: Virtual address in Service VM kernel.
|
||||
* @user_vm_pa: Physical address in User VM.
|
||||
* @size: Size of this memory region.
|
||||
*
|
||||
* HSM maintains memory mappings between a User VM GPA and the Service VM
|
||||
* kernel VA for accelerating the User VM GPA translation.
|
||||
*/
|
||||
struct vm_memory_mapping {
|
||||
struct page **pages;
|
||||
int npages;
|
||||
void *service_vm_va;
|
||||
u64 user_vm_pa;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
#define ACRN_INVALID_VMID (0xffffU)
|
||||
|
||||
#define ACRN_VM_FLAG_DESTROYED 0U
|
||||
/**
|
||||
* struct acrn_vm - Properties of ACRN User VM.
|
||||
* @list: Entry within global list of all VMs
|
||||
* @vmid: User VM ID
|
||||
* @vcpu_num: Number of virtual CPUs in the VM
|
||||
* @flags: Flags (ACRN_VM_FLAG_*) of the VM. This is VM flag management
|
||||
* in HSM which is different from the &acrn_vm_creation.vm_flag.
|
||||
* @list: Entry within global list of all VMs.
|
||||
* @vmid: User VM ID.
|
||||
* @vcpu_num: Number of virtual CPUs in the VM.
|
||||
* @flags: Flags (ACRN_VM_FLAG_*) of the VM. This is VM
|
||||
* flag management in HSM which is different
|
||||
* from the &acrn_vm_creation.vm_flag.
|
||||
* @regions_mapping_lock: Lock to protect &acrn_vm.regions_mapping and
|
||||
* &acrn_vm.regions_mapping_count.
|
||||
* @regions_mapping: Memory mappings of this VM.
|
||||
* @regions_mapping_count: Number of memory mapping of this VM.
|
||||
*/
|
||||
struct acrn_vm {
|
||||
struct list_head list;
|
||||
u16 vmid;
|
||||
int vcpu_num;
|
||||
unsigned long flags;
|
||||
struct list_head list;
|
||||
u16 vmid;
|
||||
int vcpu_num;
|
||||
unsigned long flags;
|
||||
struct mutex regions_mapping_lock;
|
||||
struct vm_memory_mapping regions_mapping[ACRN_MEM_MAPPING_MAX];
|
||||
int regions_mapping_count;
|
||||
};
|
||||
|
||||
struct acrn_vm *acrn_vm_create(struct acrn_vm *vm,
|
||||
struct acrn_vm_creation *vm_param);
|
||||
int acrn_vm_destroy(struct acrn_vm *vm);
|
||||
int acrn_mm_region_add(struct acrn_vm *vm, u64 user_gpa, u64 service_gpa,
|
||||
u64 size, u32 mem_type, u32 mem_access_right);
|
||||
int acrn_mm_region_del(struct acrn_vm *vm, u64 user_gpa, u64 size);
|
||||
int acrn_vm_memseg_map(struct acrn_vm *vm, struct acrn_vm_memmap *memmap);
|
||||
int acrn_vm_memseg_unmap(struct acrn_vm *vm, struct acrn_vm_memmap *memmap);
|
||||
int acrn_vm_ram_map(struct acrn_vm *vm, struct acrn_vm_memmap *memmap);
|
||||
void acrn_vm_all_ram_unmap(struct acrn_vm *vm);
|
||||
|
||||
#endif /* __ACRN_HSM_DRV_H */
|
||||
|
||||
Reference in New Issue
Block a user