Skip to content

Commit c3ebd6f

Browse files
yuchuyangwenlingz
authored andcommitted
HV: get tss address from per cpu data
TR selector initianlization using pre-defined HOST_GDT_RING0_CPU_TSS_SEL rather than loading from register. Instead calculating real base address of TSS based on TR selector and gdt, getting it from per cpu data. Tracked-On: #1394 Signed-off-by: Yang, Yu-chu <yu-chu.yang@intel.com> Acked-by: Anthony Xu <anthony.xu@intel.com>
1 parent 0c7e59f commit c3ebd6f

File tree

1 file changed

+7
-32
lines changed

1 file changed

+7
-32
lines changed

hypervisor/arch/x86/vmx.c

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -744,13 +744,9 @@ static void init_host_state(void)
744744
uint16_t value16;
745745
uint64_t value64;
746746
uint64_t value;
747-
uint64_t trbase;
748-
uint64_t trbase_lo;
749-
uint64_t trbase_hi;
750-
uint64_t realtrbase;
747+
uint64_t tss_addr;
751748
descriptor_table gdtb = {0U, 0UL};
752749
descriptor_table idtb = {0U, 0UL};
753-
uint16_t tr_sel;
754750

755751
pr_dbg("*********************");
756752
pr_dbg("Initialize host state");
@@ -787,9 +783,8 @@ static void init_host_state(void)
787783
exec_vmwrite16(VMX_HOST_GS_SEL, value16);
788784
pr_dbg("VMX_HOST_GS_SEL: 0x%hu ", value16);
789785

790-
asm volatile ("str %%ax":"=a" (tr_sel));
791-
exec_vmwrite16(VMX_HOST_TR_SEL, tr_sel);
792-
pr_dbg("VMX_HOST_TR_SEL: 0x%hx ", tr_sel);
786+
exec_vmwrite16(VMX_HOST_TR_SEL, HOST_GDT_RING0_CPU_TSS_SEL);
787+
pr_dbg("VMX_HOST_TR_SEL: 0x%hx ", HOST_GDT_RING0_CPU_TSS_SEL);
793788

794789
/******************************************************
795790
* 32-bit fields
@@ -809,30 +804,10 @@ static void init_host_state(void)
809804
exec_vmwrite(VMX_HOST_GDTR_BASE, gdtb.base);
810805
pr_dbg("VMX_HOST_GDTR_BASE: 0x%x ", gdtb.base);
811806

812-
/* TODO: Should guest TR point to host TR ? */
813-
trbase = gdtb.base + tr_sel;
814-
if (((trbase >> 47U) & 0x1UL) != 0UL) {
815-
trbase |= 0xffff000000000000UL;
816-
}
817-
818-
/* SS segment override */
819-
asm volatile ("mov %0,%%rax\n"
820-
".byte 0x36\n"
821-
"movq (%%rax),%%rax\n":"=a" (trbase_lo):"0"(trbase)
822-
);
823-
realtrbase = ((trbase_lo >> 16U) & (0x0ffffUL)) |
824-
(((trbase_lo >> 32U) & 0x000000ffUL) << 16U) |
825-
(((trbase_lo >> 56U) & 0xffUL) << 24U);
826-
827-
/* SS segment override for upper32 bits of base in ia32e mode */
828-
asm volatile (
829-
".byte 0x36\n"
830-
"movq 8(%%rax),%%rax\n":"=a" (trbase_hi):"0"(trbase));
831-
realtrbase = realtrbase | (trbase_hi << 32U);
832-
833-
/* Set up host and guest TR base fields */
834-
exec_vmwrite(VMX_HOST_TR_BASE, realtrbase);
835-
pr_dbg("VMX_HOST_TR_BASE: 0x%016llx ", realtrbase);
807+
tss_addr = hva2hpa((void *)&get_cpu_var(tss));
808+
/* Set up host TR base fields */
809+
exec_vmwrite(VMX_HOST_TR_BASE, tss_addr);
810+
pr_dbg("VMX_HOST_TR_BASE: 0x%016llx ", tss_addr);
836811

837812
/* Obtain the current interrupt descriptor table base */
838813
asm volatile ("sidt %0":"=m"(idtb)::"memory");

0 commit comments

Comments
 (0)