diff --git a/hypervisor/arch/x86/guest/vcpu.c b/hypervisor/arch/x86/guest/vcpu.c index f644c13aa..aee87f13f 100644 --- a/hypervisor/arch/x86/guest/vcpu.c +++ b/hypervisor/arch/x86/guest/vcpu.c @@ -729,22 +729,14 @@ void save_xsave_area(struct ext_context *ectx) { ectx->xcr0 = read_xcr(0); ectx->xss = msr_read(MSR_IA32_XSS); - asm volatile("xsaves %0" - : : "m" (ectx->xs_area), - "d" (UINT32_MAX), - "a" (UINT32_MAX): - "memory"); + xsaves(&ectx->xs_area, UINT64_MAX); } void rstore_xsave_area(const struct ext_context *ectx) { write_xcr(0, ectx->xcr0); msr_write(MSR_IA32_XSS, ectx->xss); - asm volatile("xrstors %0" - : : "m" (ectx->xs_area), - "d" (UINT32_MAX), - "a" (UINT32_MAX): - "memory"); + xrstors(&ectx->xs_area, UINT64_MAX); } /* TODO: diff --git a/hypervisor/include/arch/x86/cpu.h b/hypervisor/include/arch/x86/cpu.h index a68c2c2bd..27e9abd31 100644 --- a/hypervisor/include/arch/x86/cpu.h +++ b/hypervisor/include/arch/x86/cpu.h @@ -635,6 +635,25 @@ static inline uint64_t read_xcr(int32_t reg) asm volatile ("xgetbv ": "=a"(xcrl), "=d"(xcrh) : "c" (reg)); return (((uint64_t)xcrh << 32U) | xcrl); } + +static inline void xsaves(struct xsave_area *region_addr, uint64_t mask) +{ + asm volatile("xsaves %0" + : : "m" (*(region_addr)), + "d" ((uint32_t)(mask >> 32U)), + "a" ((uint32_t)mask): + "memory"); +} + +static inline void xrstors(const struct xsave_area *region_addr, uint64_t mask) +{ + asm volatile("xrstors %0" + : : "m" (*(region_addr)), + "d" ((uint32_t)(mask >> 32U)), + "a" ((uint32_t)mask): + "memory"); +} + /* * stac/clac pair is used to access guest's memory protected by SMAP, * following below flow: