page walk during copy_from_vm/copy_to_vm

there are data transfer between guest(GPA) & hv(HPA), especially for
hypercall from guest.

guest should make sure these GPAs are address continous, but hv cannot
assure HPAs which mapped to these GPAs are address continous, for example,
after enable hugetlb, a contious GPA range could come from two different
2M pages.

this patch is handling such case by doing gpa page walking during
copy_from_vm & copy_to_vm.

Signed-off-by: Jason Chen CJ <jason.cj.chen@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
Jason Chen CJ
2018-05-21 22:26:52 +08:00
committed by lijinxia
parent 58c109e8de
commit 2ff7bf826e
5 changed files with 76 additions and 51 deletions

View File

@@ -372,33 +372,4 @@ int64_t hcall_initialize_trusty(struct vcpu *vcpu, uint64_t param);
* @}
*/
static inline int check_result(int found)
{
return found ? 0 : -1;
}
#define copy_from_vm(vm, ptr, gpa, size) ({ \
int found = 0; \
typeof(*(ptr)) *h_ptr = (ptr); \
typeof(*(ptr)) *g_ptr = \
HPA2HVA(gpa2hpa_check(vm, gpa, \
size, &found, true)); \
if (found) { \
memcpy_s(h_ptr, size, g_ptr, size); \
} \
check_result(found); \
})
#define copy_to_vm(vm, ptr, gpa, size) ({ \
int found = 0; \
typeof(*(ptr)) *h_ptr = (ptr); \
typeof(*(ptr)) *g_ptr = \
HPA2HVA(gpa2hpa_check(vm, gpa, \
size, &found, true)); \
if (found) { \
memcpy_s(g_ptr, size, h_ptr, size); \
} \
check_result(found); \
})
#endif /* HYPERCALL_H*/