Skip to content

Commit 595cefe

Browse files
conghuic23wenlingz
authored andcommitted
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>
1 parent 2f74830 commit 595cefe

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

hypervisor/arch/x86/guest/vcpu.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -729,22 +729,14 @@ void save_xsave_area(struct ext_context *ectx)
729729
{
730730
ectx->xcr0 = read_xcr(0);
731731
ectx->xss = msr_read(MSR_IA32_XSS);
732-
asm volatile("xsaves %0"
733-
: : "m" (ectx->xs_area),
734-
"d" (UINT32_MAX),
735-
"a" (UINT32_MAX):
736-
"memory");
732+
xsaves(&ectx->xs_area, UINT64_MAX);
737733
}
738734

739735
void rstore_xsave_area(const struct ext_context *ectx)
740736
{
741737
write_xcr(0, ectx->xcr0);
742738
msr_write(MSR_IA32_XSS, ectx->xss);
743-
asm volatile("xrstors %0"
744-
: : "m" (ectx->xs_area),
745-
"d" (UINT32_MAX),
746-
"a" (UINT32_MAX):
747-
"memory");
739+
xrstors(&ectx->xs_area, UINT64_MAX);
748740
}
749741

750742
/* TODO:

hypervisor/include/arch/x86/cpu.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,25 @@ static inline uint64_t read_xcr(int32_t reg)
635635
asm volatile ("xgetbv ": "=a"(xcrl), "=d"(xcrh) : "c" (reg));
636636
return (((uint64_t)xcrh << 32U) | xcrl);
637637
}
638+
639+
static inline void xsaves(struct xsave_area *region_addr, uint64_t mask)
640+
{
641+
asm volatile("xsaves %0"
642+
: : "m" (*(region_addr)),
643+
"d" ((uint32_t)(mask >> 32U)),
644+
"a" ((uint32_t)mask):
645+
"memory");
646+
}
647+
648+
static inline void xrstors(const struct xsave_area *region_addr, uint64_t mask)
649+
{
650+
asm volatile("xrstors %0"
651+
: : "m" (*(region_addr)),
652+
"d" ((uint32_t)(mask >> 32U)),
653+
"a" ((uint32_t)mask):
654+
"memory");
655+
}
656+
638657
/*
639658
* stac/clac pair is used to access guest's memory protected by SMAP,
640659
* following below flow:

0 commit comments

Comments
 (0)