change icanhasvmx to report extra info only with -v

This commit is contained in:
aiju 2017-06-27 09:29:37 +00:00
parent dffbc1e45d
commit c4b02ff9e6

View file

@ -202,10 +202,11 @@ main(int argc, char **argv)
{ {
u64int msr, msr2; u64int msr, msr2;
int ext; int ext;
static int no, raw; static int no, raw, verbose;
ARGBEGIN { ARGBEGIN {
case 'r': raw++; break; case 'r': raw++; verbose++; break;
case 'v': verbose++; break;
default: goto usage; default: goto usage;
} ARGEND; } ARGEND;
if(argc != 0){ if(argc != 0){
@ -219,31 +220,33 @@ main(int argc, char **argv)
msrfd = open("#P/msr", OREAD); msrfd = open("#P/msr", OREAD);
if(msrfd < 0) sysfatal("open: %r"); if(msrfd < 0) sysfatal("open: %r");
if(cpuidcheck() < 0) sysfatal("CPU does not support VMX"); if(cpuidcheck() < 0) sysfatal("CPU does not support VMX");
msr = rdmsr(0x3a); if(!verbose){
if((msr & 5) == 0) wrmsr(0x3a, msr | 5); msr = rdmsr(0x3a);
if((rdmsr(0x3a) & 5) != 5){ if((msr & 5) == 0) wrmsr(0x3a, msr | 5);
fprint(2, "VMX disabled by BIOS"); if((rdmsr(0x3a) & 5) != 5){
no++; print("VMX disabled by BIOS\n");
}
msr = rdmsr(VMX_PROCB_CTLS_MSR);
if((vlong)msr >= 0){
fprint(2, "no secondary controls");
no++;
}else{
msr = rdmsr(VMX_PROCB_CTLS2_MSR);
if((msr >> 32 & PROCB_EPT) == 0){
fprint(2, "no EPT support");
no++; no++;
} }
if((msr >> 32 & PROCB_VPID) == 0){ msr = rdmsr(VMX_PROCB_CTLS_MSR);
fprint(2, "no VPID support"); if((vlong)msr >= 0){
print("no secondary controls\n");
no++; no++;
}else{
msr = rdmsr(VMX_PROCB_CTLS2_MSR);
if((msr >> 32 & PROCB_EPT) == 0){
print("no EPT support\n");
no++;
}
if((msr >> 32 & PROCB_VPID) == 0){
print("no VPID support\n");
no++;
}
} }
} if(no == 0)
if(no == 0) print("VMX is supported\n");
fprint(2, "VMX is supported\n"); else
print("Some needed features are missing\n");
if(!raw){ }else if(!raw){
msr = rdmsr(VMX_BASIC_MSR); msr = rdmsr(VMX_BASIC_MSR);
Bprint(out, "vmcsrev %#ux\n", (u32int)msr & 0x7fffffff); Bprint(out, "vmcsrev %#ux\n", (u32int)msr & 0x7fffffff);
Bprint(out, "vmxonsz %d\n", (u32int)(msr >> 32) & 0x1fff); Bprint(out, "vmxonsz %d\n", (u32int)(msr >> 32) & 0x1fff);
@ -296,7 +299,6 @@ main(int argc, char **argv)
if(no == 0) if(no == 0)
rawprint("vpidept", VMX_VPIDEPT_MSR); rawprint("vpidept", VMX_VPIDEPT_MSR);
} }
Bterm(out);
exits(nil); exits(nil);
} }