hv: mmu: refine set guest memory region API

1. rename set_vm_memmap to set_vm_memory_region
2. split ept_mmap into ept_mr_add and ept_mr_del

Signed-off-by: Li, Fei1 <fei1.li@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
Li, Fei1
2018-07-22 10:27:30 +08:00
committed by lijinxia
parent 27fbf9b215
commit 502e3e2e65
8 changed files with 139 additions and 148 deletions

View File

@@ -398,10 +398,12 @@ void destroy_ept(struct vm *vm);
uint64_t gpa2hpa(struct vm *vm, uint64_t gpa);
uint64_t _gpa2hpa(struct vm *vm, uint64_t gpa, uint32_t *size);
uint64_t hpa2gpa(struct vm *vm, uint64_t hpa);
int ept_mmap(struct vm *vm, uint64_t hpa,
uint64_t gpa, uint64_t size, uint32_t type, uint32_t prot);
int ept_mr_add(struct vm *vm, uint64_t hpa,
uint64_t gpa, uint64_t size, uint32_t prot);
int ept_mr_modify(struct vm *vm, uint64_t gpa, uint64_t size,
uint64_t attr_set, uint64_t attr_clr);
int ept_mr_del(struct vm *vm, uint64_t hpa,
uint64_t gpa, uint64_t size);
int ept_violation_vmexit_handler(struct vcpu *vcpu);
int ept_misconfig_vmexit_handler(struct vcpu *vcpu);

View File

@@ -196,9 +196,6 @@ int32_t hcall_notify_req_finish(uint16_t vmid, uint16_t vcpu_id);
/**
* @brief setup ept memory mapping
*
* Set the ept memory mapping for a VM.
* The function will return -1 if the target VM does not exist.
*
* @param vm Pointer to VM data structure
* @param vmid ID of the VM
* @param param guest physical address. This gpa points to
@@ -206,7 +203,7 @@ int32_t hcall_notify_req_finish(uint16_t vmid, uint16_t vcpu_id);
*
* @return 0 on success, non-zero on error.
*/
int32_t hcall_set_vm_memmap(struct vm *vm, uint16_t vmid, uint64_t param);
int32_t hcall_set_vm_memory_region(struct vm *vm, uint16_t vmid, uint64_t param);
/**
* @brief setup ept memory mapping for multi regions
@@ -217,7 +214,7 @@ int32_t hcall_set_vm_memmap(struct vm *vm, uint16_t vmid, uint64_t param);
*
* @return 0 on success, non-zero on error.
*/
int32_t hcall_set_vm_memmaps(struct vm *vm, uint64_t param);
int32_t hcall_set_vm_memory_regions(struct vm *vm, uint64_t param);
/**
* @brief remap PCI MSI interrupt

View File

@@ -49,9 +49,9 @@
/* Guest memory management */
#define HC_ID_MEM_BASE 0x40UL
#define HC_VM_SET_MEMMAP _HC_ID(HC_ID, HC_ID_MEM_BASE + 0x00UL)
#define HC_VM_SET_MEMORY_REGION _HC_ID(HC_ID, HC_ID_MEM_BASE + 0x00UL)
#define HC_VM_GPA2HPA _HC_ID(HC_ID, HC_ID_MEM_BASE + 0x01UL)
#define HC_VM_SET_MEMMAPS _HC_ID(HC_ID, HC_ID_MEM_BASE + 0x02UL)
#define HC_VM_SET_MEMORY_REGIONS _HC_ID(HC_ID, HC_ID_MEM_BASE + 0x02UL)
/* PCI assignment*/
#define HC_ID_PCI_BASE 0x50UL
@@ -101,56 +101,33 @@
*/
/**
* @brief Info to set ept mapping
* @brief Info to set guest memory region mapping
*
* the parameter for HC_VM_SET_MEMMAP hypercall
* the parameter for HC_VM_SET_MEMORY_REGION hypercall
*/
struct vm_set_memmap {
#define MAP_MEM 0U
#define MAP_MMIO 1U
#define MAP_UNMAP 2U
/** map type: MAP_MEM, MAP_MMIO or MAP_UNMAP */
struct vm_memory_region {
#define MR_ADD 0U
#define MR_DEL 2U
/** set memory region type: MR_ADD or MAP_DEL */
uint32_t type;
/** memory attributes: memory type + RWX access right */
uint32_t prot;
/** guest physical address to map */
uint64_t remote_gpa;
/** the beginning guest physical address of the memory reion*/
uint64_t gpa;
/** VM0's guest physcial address which remote gpa will be mapped to */
/** VM0's guest physcial address which gpa will be mapped to */
uint64_t vm0_gpa;
/** length of the map range */
uint64_t length;
/** old memory attributes(will be removed in the future):
* memory type + RWX access right */
uint32_t prot_2;
} __aligned(8);
struct memory_map {
/** map type: MAP_MEM, MAP_MMIO or MAP_UNMAP */
uint32_t type;
/** memory attributes: memory type + RWX access right */
uint32_t prot;
/** guest physical address to map */
uint64_t remote_gpa;
/** VM0's guest physcial address which remote gpa will be mapped to */
uint64_t vm0_gpa;
/** length of the map range */
uint64_t length;
/** size of the memory region */
uint64_t size;
} __aligned(8);
/**
* multi memmap regions hypercall, used for HC_VM_SET_MEMMAPS
* set multi memory regions, used for HC_VM_SET_MEMORY_REGIONS
*/
struct set_memmaps {
struct set_regions {
/** vmid for this hypercall */
uint16_t vmid;
@@ -160,14 +137,14 @@ struct set_memmaps {
/** Reserved */
uint32_t reserved1;
/** multi memmaps numbers */
uint32_t memmaps_num;
/** memory region numbers */
uint32_t mr_num;
/** the gpa of memmaps buffer, point to the memmaps array:
* struct memory_map regions[memmaps_num]
/** the gpa of regions buffer, point to the regions array:
* struct vm_memory_region regions[mr_num]
* the max buffer size is one page.
*/
uint64_t memmaps_gpa;
uint64_t regions_gpa;
} __attribute__((aligned(8)));
/**