Skip to content

Commit 853b1c7

Browse files
fyin1wenlingz
authored andcommitted
dm: add API to set vcpu regs of guest
Add ioctl parameter and API to set vcpu regs. The guest software loader will call this API to set guest vcpu registers. Tracked-On: #1231 Signed-off-by: Yin Fengwei <fengwei.yin@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 3cfbc00 commit 853b1c7

File tree

5 files changed

+84
-0
lines changed

5 files changed

+84
-0
lines changed

devicemodel/core/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ add_cpu(struct vmctx *ctx, int guest_ncpus)
269269
mt_vmm_info[i].mt_vcpu = i;
270270
}
271271

272+
vm_set_vcpu_regs(ctx, &ctx->bsp_regs);
273+
272274
error = pthread_create(&mt_vmm_info[0].mt_thr, NULL,
273275
start_thread, &mt_vmm_info[0]);
274276

devicemodel/core/vmmapi.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,12 @@ vm_create_vcpu(struct vmctx *ctx, uint16_t vcpu_id)
612612
return error;
613613
}
614614

615+
int
616+
vm_set_vcpu_regs(struct vmctx *ctx, struct acrn_set_vcpu_regs *vcpu_regs)
617+
{
618+
return ioctl(ctx->fd, IC_SET_VCPU_REGS, vcpu_regs);
619+
}
620+
615621
int
616622
vm_get_device_fd(struct vmctx *ctx)
617623
{

devicemodel/include/public/acrn_common.h

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,77 @@ struct acrn_create_vcpu {
269269
uint16_t pcpu_id;
270270
} __aligned(8);
271271

272+
struct acrn_gp_regs {
273+
uint64_t rax;
274+
uint64_t rcx;
275+
uint64_t rdx;
276+
uint64_t rbx;
277+
uint64_t rsp;
278+
uint64_t rbp;
279+
uint64_t rsi;
280+
uint64_t rdi;
281+
uint64_t r8;
282+
uint64_t r9;
283+
uint64_t r10;
284+
uint64_t r11;
285+
uint64_t r12;
286+
uint64_t r13;
287+
uint64_t r14;
288+
uint64_t r15;
289+
};
290+
291+
struct acrn_descriptor_ptr {
292+
uint16_t limit;
293+
uint64_t base;
294+
uint16_t reserved[3];
295+
} __attribute__((packed));
296+
297+
struct acrn_vcpu_regs {
298+
struct acrn_gp_regs gprs;
299+
struct acrn_descriptor_ptr gdt;
300+
struct acrn_descriptor_ptr idt;
301+
302+
uint64_t rip;
303+
uint64_t cs_base;
304+
uint64_t cr0;
305+
uint64_t cr4;
306+
uint64_t cr3;
307+
uint64_t ia32_efer;
308+
uint64_t rflags;
309+
uint64_t reserved_64[4];
310+
311+
uint32_t cs_ar;
312+
uint32_t reserved_32[4];
313+
314+
/* don't change the order of following sel */
315+
uint16_t cs_sel;
316+
uint16_t ss_sel;
317+
uint16_t ds_sel;
318+
uint16_t es_sel;
319+
uint16_t fs_sel;
320+
uint16_t gs_sel;
321+
uint16_t ldt_sel;
322+
uint16_t tr_sel;
323+
324+
uint16_t reserved_16[4];
325+
};
326+
327+
/**
328+
* @brief Info to set vcpu state
329+
*
330+
* the pamameter for HC_SET_VCPU_STATE
331+
*/
332+
struct acrn_set_vcpu_regs {
333+
/** the virtual CPU ID for the VCPU to set state */
334+
uint16_t vcpu_id;
335+
336+
/** reserved space to make cpu_state aligned to 8 bytes */
337+
uint16_t reserved0[3];
338+
339+
/** the structure to hold vcpu state */
340+
struct acrn_vcpu_regs vcpu_regs;
341+
} __attribute__((aligned(8)));
342+
272343
/**
273344
* @brief Info to set ioreq buffer for a created VM
274345
*

devicemodel/include/public/vhm_ioctl_defs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
#define IC_PAUSE_VM _IC_ID(IC_ID, IC_ID_VM_BASE + 0x03)
7474
#define IC_CREATE_VCPU _IC_ID(IC_ID, IC_ID_VM_BASE + 0x04)
7575
#define IC_RESET_VM _IC_ID(IC_ID, IC_ID_VM_BASE + 0x05)
76+
#define IC_SET_VCPU_REGS _IC_ID(IC_ID, IC_ID_VM_BASE + 0x06)
7677

7778
/* IRQ and Interrupts */
7879
#define IC_ID_IRQ_BASE 0x20UL

devicemodel/include/vmmapi.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ struct vmctx {
6464
void *vrtc;
6565
void *vpit;
6666
void *ioc_dev;
67+
68+
/* BSP state. guest loader needs to fill it */
69+
struct acrn_set_vcpu_regs bsp_regs;
6770
};
6871

6972
/*
@@ -148,6 +151,7 @@ int vm_set_ptdev_intx_info(struct vmctx *ctx, uint16_t virt_bdf,
148151
int vm_reset_ptdev_intx_info(struct vmctx *ctx, int virt_pin, bool pic_pin);
149152

150153
int vm_create_vcpu(struct vmctx *ctx, uint16_t vcpu_id);
154+
int vm_set_vcpu_regs(struct vmctx *ctx, struct acrn_set_vcpu_regs *cpu_regs);
151155

152156
int vm_get_cpu_state(struct vmctx *ctx, void *state_buf);
153157
int vm_intr_monitor(struct vmctx *ctx, void *intr_buf);

0 commit comments

Comments
 (0)