Skip to content

Commit eada04b

Browse files
mingqiangchilijinxia
authored andcommitted
hv:Replace dynamic memory allocation for vmcs region
Replace vmcs pointer with static memory for vmcs region inside structure vcpu_arch. Tracked-On: #861 Signed-off-by: Mingqiang Chi <mingqiang.chi@intel.com> Reviewed-by: Anthony Xu <anthony.xu@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent ca75d50 commit eada04b

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

hypervisor/arch/x86/guest/vcpu.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,6 @@ int create_vcpu(uint16_t pcpu_id, struct vm *vm, struct vcpu **rtn_vcpu_handle)
224224

225225
vcpu->arch_vcpu.vpid = allocate_vpid();
226226

227-
/* Allocate VMCS region for this VCPU */
228-
vcpu->arch_vcpu.vmcs = alloc_page();
229-
ASSERT(vcpu->arch_vcpu.vmcs != NULL, "");
230-
231-
/* Memset VMCS region for this VCPU */
232-
(void)memset(vcpu->arch_vcpu.vmcs, 0U, CPU_PAGE_SIZE);
233-
234227
/* Initialize exception field in VCPU context */
235228
vcpu->arch_vcpu.exception_info.exception = VECTOR_INVALID;
236229

@@ -384,7 +377,6 @@ void destroy_vcpu(struct vcpu *vcpu)
384377
atomic_dec16(&vcpu->vm->hw.created_vcpus);
385378

386379
vlapic_free(vcpu);
387-
free(vcpu->arch_vcpu.vmcs);
388380
per_cpu(ever_run_vcpu, vcpu->pcpu_id) = NULL;
389381
free_pcpu(vcpu->pcpu_id);
390382
free(vcpu);

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,11 @@ struct cpu_context {
164164
};
165165

166166
struct vcpu_arch {
167+
/* vmcs region for this vcpu, MUST be 4KB-aligned */
168+
uint8_t vmcs[CPU_PAGE_SIZE];
167169
int cur_context;
168170
struct cpu_context contexts[NR_WORLD];
169171

170-
/* A pointer to the VMCS for this CPU. */
171-
void *vmcs;
172172
uint16_t vpid;
173173

174174
/* Holds the information needed for IRQ/exception handling. */
@@ -205,14 +205,14 @@ struct vcpu_arch {
205205

206206
/* per vcpu lapic */
207207
void *vlapic;
208-
};
208+
} __aligned(CPU_PAGE_SIZE);
209209

210210
struct vm;
211211
struct vcpu {
212+
/* Architecture specific definitions for this VCPU */
213+
struct vcpu_arch arch_vcpu;
212214
uint16_t pcpu_id; /* Physical CPU ID of this VCPU */
213215
uint16_t vcpu_id; /* virtual identifier for VCPU */
214-
struct vcpu_arch arch_vcpu;
215-
/* Architecture specific definitions for this VCPU */
216216
struct vm *vm; /* Reference to the VM this VCPU belongs to */
217217
void *entry_addr; /* Entry address for this VCPU when first started */
218218

@@ -246,7 +246,7 @@ struct vcpu {
246246
#endif
247247
uint64_t reg_cached;
248248
uint64_t reg_updated;
249-
};
249+
} __aligned(CPU_PAGE_SIZE);
250250

251251
struct vcpu_dump {
252252
struct vcpu *vcpu;

0 commit comments

Comments
 (0)