Skip to content

Commit

Permalink
hv: add hypercall to set vcpu regs
Browse files Browse the repository at this point in the history
DM will use this hypercall to set UOS bsp regs like segment
selector/base, rip etc.

We also add init_ctx as one field of vcpu structure.
It will be initialized for BSP of VM from:
  - UEFI vm0: from efi_ctx saved in UEFI glue before acrn boot
  - none-UEFI VM0: from vm0_boot_context saved at very beginning
    of acrn boot
  - UOS: from hypercall called by DM

Tracked-On: projectacrn#1231
Signed-off-by: Yin Fengwei <fengwei.yin@intel.com>
  • Loading branch information
fyin1 committed Sep 20, 2018
1 parent 911ac3e commit 38e7b64
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 0 deletions.
5 changes: 5 additions & 0 deletions hypervisor/arch/x86/guest/vmcall.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ int vmcall_vmexit_handler(struct vcpu *vcpu)
ret = hcall_create_vcpu(vm, (uint16_t)param1, param2);
break;

case HC_SET_VCPU_REGS:
/* param1: vmid */
ret = hcall_set_vcpu_regs(vm, (uint16_t)param1, param2);
break;

case HC_ASSERT_IRQLINE:
/* param1: vmid */
ret = hcall_assert_irqline(vm, (uint16_t)param1, param2);
Expand Down
37 changes: 37 additions & 0 deletions hypervisor/common/hypercall.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,43 @@ int32_t hcall_reset_vm(uint16_t vmid)
return 0;
}

/**
*@pre Pointer vm shall point to VM0
*/
int32_t hcall_set_vcpu_regs(struct vm *vm, uint16_t vmid, uint64_t param)
{
struct vm *target_vm = get_vm_from_vmid(vmid);
struct acrn_set_vcpu_regs asvr;
struct vcpu *vcpu;

if ((target_vm == NULL) || (param == 0U) || is_vm0(target_vm)) {
return -1;
}

/* Only allow setup init ctx while target_vm is inactive */
if (target_vm->state == VM_STARTED) {
return -1;
}

if (copy_from_gpa(vm, &asvr, param, sizeof(asvr)) != 0) {
pr_err("%s: Unable copy param to vm\n", __func__);
return -1;
}

vcpu = vcpu_from_vid(target_vm, asvr.vcpu_id);
if (vcpu == NULL) {
pr_err("%s: invalid vcpu_id for set_vcpu_regs\n", __func__);
return -1;
}

memcpy_s(&(vcpu->arch_vcpu.init_ctx.vcpu_regs),
sizeof(struct acrn_vcpu_regs),
&(asvr.vcpu_regs),
sizeof(struct acrn_vcpu_regs));

return 0;
}

/**
*@pre Pointer vm shall point to VM0
*/
Expand Down
2 changes: 2 additions & 0 deletions hypervisor/include/arch/x86/guest/vcpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ struct vcpu_arch {
bool inject_event_pending;
struct event_injection_info inject_info;

/* CPU boot context */
struct boot_ctx init_ctx;
} __aligned(CPU_PAGE_SIZE);

struct vm;
Expand Down
1 change: 1 addition & 0 deletions hypervisor/include/arch/x86/hv_arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <mtrr.h>
#include <timer.h>
#include <vlapic.h>
#include <vm0_boot.h>
#include <vcpu.h>
#include <trusty.h>
#include <guest_pm.h>
Expand Down
16 changes: 16 additions & 0 deletions hypervisor/include/common/hypercall.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,22 @@ int32_t hcall_pause_vm(uint16_t vmid);
*/
int32_t hcall_create_vcpu(struct vm *vm, uint16_t vmid, uint64_t param);

/**
* @brief set vcpu regs
*
* Set the vcpu regs. It will set the vcpu init regs from DM. Now,
* it's only applied to BSP. AP always uses fixed init regs.
* The function will return -1 if the targat VM or BSP doesn't exist.
*
* @param vm Pointer to VM data structure
* @param vmid ID of the VM
* @param param guest physical address. This gpa points to
* struct acrn_cpu_regs
*
* @return 0 on success, non-zero on error.
*/
int32_t hcall_set_vcpu_regs(struct vm *vm, uint16_t vmid, uint64_t param);

/**
* @brief assert IRQ line
*
Expand Down
1 change: 1 addition & 0 deletions hypervisor/include/public/acrn_hv_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#define HC_PAUSE_VM BASE_HC_ID(HC_ID, HC_ID_VM_BASE + 0x03UL)
#define HC_CREATE_VCPU BASE_HC_ID(HC_ID, HC_ID_VM_BASE + 0x04UL)
#define HC_RESET_VM BASE_HC_ID(HC_ID, HC_ID_VM_BASE + 0x05UL)
#define HC_SET_VCPU_REGS BASE_HC_ID(HC_ID, HC_ID_VM_BASE + 0x06UL)

/* IRQ and Interrupts */
#define HC_ID_IRQ_BASE 0x20UL
Expand Down

0 comments on commit 38e7b64

Please sign in to comment.