hv: Wrap GUEST_FLAG_TEE/REE checks into function

This patch wraps the check of GUEST_FLAG_TEE/REE into functions
is_tee_vm/is_ree_vm for readability. No logic changes.

Tracked-On: #6571
Signed-off-by: Yifan Liu <yifan1.liu@intel.com>
Reviewed-by: Wang, Yu1 <yu1.wang@intel.com>
Acked-by: Anthony Xu <anthony.xu@intel.com>
This commit is contained in:
Yifan Liu 2021-11-27 00:48:56 +00:00 committed by wenlingz
parent 90c987b600
commit 98bc4cab35
2 changed files with 16 additions and 6 deletions

View File

@ -14,6 +14,16 @@
#include <hypercall.h>
#include <logmsg.h>
int is_tee_vm(struct acrn_vm *vm)
{
return (get_vm_config(vm->vm_id)->guest_flags & GUEST_FLAG_TEE) != 0;
}
int is_ree_vm(struct acrn_vm *vm)
{
return (get_vm_config(vm->vm_id)->guest_flags & GUEST_FLAG_REE) != 0;
}
void prepare_tee_vm_memmap(struct acrn_vm *vm, const struct acrn_vm_config *vm_config)
{
uint64_t hv_hpa;
@ -137,9 +147,9 @@ int32_t hcall_switch_ee(struct acrn_vcpu *vcpu, __unused struct acrn_vm *target_
{
int32_t ret = 0;
if ((get_vm_config(vcpu->vm->vm_id)->guest_flags & GUEST_FLAG_TEE) != 0U) {
if (is_tee_vm(vcpu->vm)) {
ret = tee_switch_to_ree(vcpu);
} else if ((get_vm_config(vcpu->vm->vm_id)->guest_flags & GUEST_FLAG_REE) != 0U) {
} else if (is_ree_vm(vcpu->vm)) {
ret = ree_switch_to_tee(vcpu);
}
@ -151,8 +161,7 @@ void handle_x86_tee_int(struct ptirq_remapping_info *entry, uint16_t pcpu_id)
struct acrn_vcpu *tee_vcpu;
struct acrn_vcpu *curr_vcpu = get_running_vcpu(pcpu_id);
if (((get_vm_config(entry->vm->vm_id)->guest_flags & GUEST_FLAG_REE) != 0U) &&
((get_vm_config(curr_vcpu->vm->vm_id)->guest_flags & GUEST_FLAG_TEE) != 0U)) {
if (is_ree_vm(entry->vm) && is_tee_vm(curr_vcpu->vm)) {
/*
* Non-Secure interrupt (interrupt belongs to REE) comes
* when REE vcpu is running, the interrupt will be injected
@ -162,8 +171,7 @@ void handle_x86_tee_int(struct ptirq_remapping_info *entry, uint16_t pcpu_id)
*/
tee_vcpu = vcpu_from_pid(get_companion_vm(entry->vm), pcpu_id);
vlapic_set_intr(tee_vcpu, TEE_NOTIFICATION_VECTOR, LAPIC_TRIG_EDGE);
} else if (((get_vm_config(entry->vm->vm_id)->guest_flags & GUEST_FLAG_TEE) != 0U) &&
((get_vm_config(curr_vcpu->vm->vm_id)->guest_flags & GUEST_FLAG_REE) != 0U)) {
} else if (is_tee_vm(entry->vm) && is_ree_vm(curr_vcpu->vm)) {
/*
* Secure interrupt (interrupt belongs to TEE) comes
* when TEE vcpu is running, the interrupt will be

View File

@ -19,6 +19,8 @@
/* This value tells OPTEE that this switch to TEE is due to secure interrupt */
#define OPTEE_FIQ_ENTRY 0xB20000FFUL
int is_tee_vm(struct acrn_vm *vm);
int is_ree_vm(struct acrn_vm *vm);
void prepare_tee_vm_memmap(struct acrn_vm *vm, const struct acrn_vm_config *vm_config);
void handle_x86_tee_int(struct ptirq_remapping_info *entry, uint16_t pcpu_id);