hv: xsave: move assembler to individual function

Current code avoid the rule 88 S in MISRA-C, so move xsaves and xrstors
assembler to individual functions.

Tracked-On: #4436
Signed-off-by: Conghui Chen <conghui.chen@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
Conghui Chen 2020-01-13 10:03:58 +00:00 committed by wenlingz
parent 2f7483065b
commit 595cefe3f2
2 changed files with 21 additions and 10 deletions

View File

@ -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:

View File

@ -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: