Skip to content

Commit 3cfbc00

Browse files
fyin1wenlingz
authored andcommitted
hv: add hypercall to set vcpu init state
DM will use this hypercall to initialize the UOS BSP state. Tracked-On: #1231 Signed-off-by: Yin Fengwei <fengwei.yin@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 66b53f8 commit 3cfbc00

File tree

5 files changed

+72
-0
lines changed

5 files changed

+72
-0
lines changed

hypervisor/arch/x86/guest/vmcall.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ int vmcall_vmexit_handler(struct vcpu *vcpu)
7878
ret = hcall_create_vcpu(vm, (uint16_t)param1, param2);
7979
break;
8080

81+
case HC_SET_VCPU_REGS:
82+
/* param1: vmid */
83+
ret = hcall_set_vcpu_regs(vm, (uint16_t)param1, param2);
84+
break;
85+
8186
case HC_ASSERT_IRQLINE:
8287
/* param1: vmid */
8388
ret = hcall_assert_irqline(vm, (uint16_t)param1, param2);

hypervisor/common/hypercall.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,40 @@ int32_t hcall_pulse_irqline(struct vm *vm, uint16_t vmid, uint64_t param)
297297
return ret;
298298
}
299299

300+
/**
301+
*@pre Pointer vm shall point to VM0
302+
*/
303+
int32_t hcall_set_vcpu_regs(struct vm *vm, uint16_t vmid, uint64_t param)
304+
{
305+
struct vm *target_vm = get_vm_from_vmid(vmid);
306+
struct acrn_set_vcpu_regs vcpu_regs;
307+
struct vcpu *vcpu;
308+
309+
if ((target_vm == NULL) || (param == 0U) || is_vm0(target_vm)) {
310+
return -1;
311+
}
312+
313+
/* Only allow setup init ctx while target_vm is inactive */
314+
if (target_vm->state == VM_STARTED) {
315+
return -1;
316+
}
317+
318+
if (copy_from_gpa(vm, &vcpu_regs, param, sizeof(vcpu_regs)) != 0) {
319+
pr_err("%s: Unable copy param to vm\n", __func__);
320+
return -1;
321+
}
322+
323+
vcpu = vcpu_from_vid(target_vm, vcpu_regs.vcpu_id);
324+
if (vcpu == NULL) {
325+
pr_err("%s: invalid vcpu_id for set_vcpu_regs\n", __func__);
326+
return -1;
327+
}
328+
329+
set_vcpu_regs(vcpu, &(vcpu_regs.vcpu_regs));
330+
331+
return 0;
332+
}
333+
300334
/**
301335
*@pre Pointer vm shall point to VM0
302336
*/

hypervisor/include/common/hypercall.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,22 @@ int32_t hcall_pause_vm(uint16_t vmid);
136136
*/
137137
int32_t hcall_create_vcpu(struct vm *vm, uint16_t vmid, uint64_t param);
138138

139+
/**
140+
* @brief set vcpu regs
141+
*
142+
* Set the vcpu regs. It will set the vcpu init regs from DM. Now,
143+
* it's only applied to BSP. AP always uses fixed init regs.
144+
* The function will return -1 if the targat VM or BSP doesn't exist.
145+
*
146+
* @param vm Pointer to VM data structure
147+
* @param vmid ID of the VM
148+
* @param param guest physical address. This gpa points to
149+
* struct acrn_vcpu_regs
150+
*
151+
* @return 0 on success, non-zero on error.
152+
*/
153+
int32_t hcall_set_vcpu_regs(struct vm *vm, uint16_t vmid, uint64_t param);
154+
139155
/**
140156
* @brief assert IRQ line
141157
*

hypervisor/include/public/acrn_common.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,22 @@ struct acrn_vcpu_regs {
310310
uint16_t reserved_16[4];
311311
};
312312

313+
/**
314+
* @brief Info to set vcpu state
315+
*
316+
* the pamameter for HC_SET_VCPU_STATE
317+
*/
318+
struct acrn_set_vcpu_regs {
319+
/** the virtual CPU ID for the VCPU to set state */
320+
uint16_t vcpu_id;
321+
322+
/** reserved space to make cpu_state aligned to 8 bytes */
323+
uint16_t reserved0[3];
324+
325+
/** the structure to hold vcpu state */
326+
struct acrn_vcpu_regs vcpu_regs;
327+
} __attribute__((aligned(8)));
328+
313329
/**
314330
* @brief Info to set ioreq buffer for a created VM
315331
*

hypervisor/include/public/acrn_hv_defs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#define HC_PAUSE_VM BASE_HC_ID(HC_ID, HC_ID_VM_BASE + 0x03UL)
3838
#define HC_CREATE_VCPU BASE_HC_ID(HC_ID, HC_ID_VM_BASE + 0x04UL)
3939
#define HC_RESET_VM BASE_HC_ID(HC_ID, HC_ID_VM_BASE + 0x05UL)
40+
#define HC_SET_VCPU_REGS BASE_HC_ID(HC_ID, HC_ID_VM_BASE + 0x06UL)
4041

4142
/* IRQ and Interrupts */
4243
#define HC_ID_IRQ_BASE 0x20UL

0 commit comments

Comments
 (0)