Skip to content

Commit e32bc9e

Browse files
fyin1lijinxia
authored andcommitted
hv: avoid hardcode cs.limit in set_vcpu_regs()
For SOS BSP, we reuse native saved cs.limit For UOS BSP, we set cs.limit in DM For AP, we use initialized data from realmode_init_regs. Tracked-On: #1231 Signed-off-by: Yin Fengwei <fengwei.yin@intel.com> Acked-by: Eddie Dong <Eddie.dong@intel.com>
1 parent 0cd8574 commit e32bc9e

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

hypervisor/arch/x86/guest/vcpu.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,16 +189,17 @@ void set_vcpu_regs(struct vcpu *vcpu, struct acrn_vcpu_regs *vcpu_regs)
189189
ectx = &(vcpu->arch_vcpu.contexts[vcpu->arch_vcpu.cur_context].ext_ctx);
190190
ctx = &(vcpu->arch_vcpu.contexts[vcpu->arch_vcpu.cur_context].run_ctx);
191191

192-
if (vcpu_regs->cs_ar & (1U << 15U)) {
193-
limit = 0xFFFFFFFFU;
194-
} else {
195-
limit = 0xFFFFU;
196-
}
197-
192+
/* NOTE:
193+
* This is to set the attr and limit to default value.
194+
* If the set_vcpu_regs is used not only for vcpu state
195+
* initialization, this part of code needs be revised.
196+
*/
198197
if (vcpu_regs->cr0 & CR0_PE) {
199198
attr = PROTECTED_MODE_DATA_SEG_AR;
199+
limit = PROTECTED_MODE_SEG_LIMIT;
200200
} else {
201201
attr = REAL_MODE_DATA_SEG_AR;
202+
limit = REAL_MODE_SEG_LIMIT;
202203
}
203204

204205
for (seg = &(ectx->cs); seg <= &(ectx->gs); seg++) {
@@ -209,9 +210,10 @@ void set_vcpu_regs(struct vcpu *vcpu, struct acrn_vcpu_regs *vcpu_regs)
209210
sel++;
210211
}
211212

212-
/* override cs attr/base */
213+
/* override cs attr/base/limit */
213214
ectx->cs.attr = vcpu_regs->cs_ar;
214215
ectx->cs.base = vcpu_regs->cs_base;
216+
ectx->cs.limit = vcpu_regs->cs_limit;
215217

216218
ectx->gdtr.base = vcpu_regs->gdt.base;
217219
ectx->gdtr.limit = vcpu_regs->gdt.limit;
@@ -271,6 +273,7 @@ static struct acrn_vcpu_regs realmode_init_regs = {
271273
.cs_ar = REAL_MODE_CODE_SEG_AR,
272274
.cs_sel = REAL_MODE_BSP_INIT_CODE_SEL,
273275
.cs_base = 0xFFFF0000UL,
276+
.cs_limit = 0xFFFFU,
274277
.rip = 0xFFF0UL,
275278
.cr0 = CR0_ET | CR0_NE,
276279
.cr3 = 0UL,

hypervisor/include/arch/x86/guest/guest.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@
6969
#define REAL_MODE_CODE_SEG_AR (0x009fU)
7070
#define PROTECTED_MODE_DATA_SEG_AR (0xc093U)
7171
#define PROTECTED_MODE_CODE_SEG_AR (0xc09bU)
72+
#define REAL_MODE_SEG_LIMIT (0xffffU)
73+
#define PROTECTED_MODE_SEG_LIMIT (0xffffffffU)
7274
#define DR7_INIT_VALUE (0x400UL)
7375
#define LDTR_AR (0x0082U) /* LDT, type must be 2, refer to SDM Vol3 26.3.1.2 */
7476
#define TR_AR (0x008bU) /* TSS (busy), refer to SDM Vol3 26.3.1.2 */

0 commit comments

Comments
 (0)