Skip to content

Commit

Permalink
Support TrustVisor detection through CPUID
Browse files Browse the repository at this point in the history
  • Loading branch information
lxylxy123456 committed Nov 25, 2022
1 parent 5331f23 commit ab560c7
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
23 changes: 23 additions & 0 deletions hypapps/trustvisor/src/appmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,29 @@ void tv_app_handleshutdown(VCPU *vcpu, struct regs __attribute__((unused)) *r)
xmhf_baseplatform_reboot(vcpu);
}

/*
* Activated when EAX=0x7a567254 (TrVz) and ECX=0.
* Set EAX=0x7a767274 (TRVZ).
* Set EBX=UINT_MAX if not in PAL, or whitelist_entry.id if in PAL.
* Set ECX[0]=0 if calling process is 32-bit, 1 if 64-bit.
* Set ECX[1-31]=undefined.
* Set EDX=undefined.
*/
u32 tv_app_handlecpuid(VCPU *vcpu, struct regs *r)
{
if (r->eax == 0x7a567254U && r->ecx == 0) {
r->eax = 0x7a767274U;
r->ebx = (u32)hpt_scode_get_scode_id(vcpu);
r->ecx = 0U;
if (VCPU_g64(vcpu)) {
r->ecx |= (1U << 1);
}
r->edx = 0U;
return APP_CPUID_SKIP;
}
return APP_CPUID_CHAIN;
}

/* Local Variables: */
/* mode:c */
/* indent-tabs-mode:nil */
Expand Down
3 changes: 1 addition & 2 deletions hypapps/trustvisor/src/emhf_callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,5 @@ void xmhf_app_handleshutdown(VCPU *vcpu, struct regs *r)
// Detect the presence of TrustVisor
u32 xmhf_app_handlecpuid(VCPU *vcpu, struct regs *r)
{
(void)vcpu;(void)r;
return APP_CPUID_CHAIN;
return tv_app_handlecpuid(vcpu, r);
}
1 change: 1 addition & 0 deletions hypapps/trustvisor/src/include/scode.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ int copy_to_current_guest(VCPU * vcpu, gva_t gvaddr, void *src, size_t len);
u32 hpt_scode_switch_scode(VCPU * vcpu, struct regs *r);
u32 hpt_scode_switch_regular(VCPU * vcpu);
u32 hpt_scode_npf(VCPU * vcpu, uintptr_t gpaddr, u64 errorcode, struct regs *r);
int hpt_scode_get_scode_id(VCPU * vcpu);
u32 scode_share(VCPU * vcpu, u32 scode_entry, u32 addr, u32 len);
u32 scode_share_ranges(VCPU * vcpu, u32 scode_entry, u32 gva_base[], u32 gva_len[], u32 count);

Expand Down
1 change: 1 addition & 0 deletions hypapps/trustvisor/src/include/tv_emhf.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,6 @@ u32 tv_app_handleintercept_hwpgtblviolation(VCPU *vcpu,
u32 tv_app_handleintercept_portaccess(VCPU *vcpu, struct regs *r,
u32 portnum, u32 access_type, u32 access_size);
void tv_app_handleshutdown(VCPU *vcpu, struct regs *r);
u32 tv_app_handlecpuid(VCPU *vcpu, struct regs *r);

#endif
6 changes: 6 additions & 0 deletions hypapps/trustvisor/src/scode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1418,6 +1418,12 @@ u32 hpt_scode_npf(VCPU * vcpu, uintptr_t gpaddr, u64 errorcode, struct regs *r)
return err;
}

/* Return ID of the scode current CPU is running, or -1 if not running scode */
int hpt_scode_get_scode_id(VCPU * vcpu)
{
return scode_curr[vcpu->id];
}

/* caller is responsible for flushing TLB */
void scode_release_all_shared_pages(VCPU *vcpu, whitelist_entry_t* wle)
{
Expand Down

0 comments on commit ab560c7

Please sign in to comment.