-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcmpe283-2.txt
executable file
·122 lines (114 loc) · 3.15 KB
/
cmpe283-2.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
old mode 100644
new mode 100755
index 7bcfa61..34017fc
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -936,16 +936,49 @@ bool kvm_cpuid(struct kvm_vcpu *vcpu, u32 *eax, u32 *ebx,
}
EXPORT_SYMBOL_GPL(kvm_cpuid);
+
+EXPORT_SYMBOL(total_vm_exits);
+EXPORT_SYMBOL(totalExitTime);
+
int kvm_emulate_cpuid(struct kvm_vcpu *vcpu)
{
u32 eax, ebx, ecx, edx;
+ u64 val;
if (cpuid_fault_enabled(vcpu) && !kvm_require_cpl(vcpu, 0))
return 1;
eax = kvm_register_read(vcpu, VCPU_REGS_RAX);
ecx = kvm_register_read(vcpu, VCPU_REGS_RCX);
+
+
+ if(eax == 0x4FFFFFFF)
+ {
+
+ eax = total_vm_exits;
+ val = totalExitTime;
+ ecx = (val & 0x00000000FFFFFFFF);
+ val = totalExitTime;
+ ebx = (val & 0xFFFFFFFF00000000)>>32;
+ edx = 0;
+
+ kvm_register_write(vcpu, VCPU_REGS_RAX, eax);
+ kvm_register_write(vcpu, VCPU_REGS_RBX, ebx);
+ kvm_register_write(vcpu, VCPU_REGS_RCX, ecx);
+ kvm_register_write(vcpu, VCPU_REGS_RDX, edx);
+ printk(KERN_INFO "CPUID(0x4FFFFFFF), exits=%d, cycles spent in exit=%llu", total_vm_exits,totalExitTime);
+ printk(KERN_INFO "EAX: %u", eax);
+ printk(KERN_INFO "EBX: %u", ebx);
+ printk(KERN_INFO "ECX: %u", ecx);
+ printk(KERN_INFO "EDX: %u", edx);
+
+ }else{
+
kvm_cpuid(vcpu, &eax, &ebx, &ecx, &edx, true);
+
+ }
+
+
kvm_register_write(vcpu, VCPU_REGS_RAX, eax);
kvm_register_write(vcpu, VCPU_REGS_RBX, ebx);
kvm_register_write(vcpu, VCPU_REGS_RCX, ecx);
diff --git a/arch/x86/kvm/cpuid.h b/arch/x86/kvm/cpuid.h
old mode 100644
new mode 100755
index 9a327d5..51f3bdb
--- a/arch/x86/kvm/cpuid.h
+++ b/arch/x86/kvm/cpuid.h
@@ -6,6 +6,11 @@
#include <asm/cpu.h>
#include <asm/processor.h>
+
+/* changes by chaitrali */
+extern int total_vm_exits;
+extern u64 totalExitTime;
+
int kvm_update_cpuid(struct kvm_vcpu *vcpu);
bool kvm_mpx_supported(void);
struct kvm_cpuid_entry2 *kvm_find_cpuid_entry(struct kvm_vcpu *vcpu,
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
old mode 100644
new mode 100755
index 542f631..c3b5235
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -105,6 +105,11 @@ static void __kvm_set_rflags(struct kvm_vcpu *vcpu, unsigned long rflags);
static void store_regs(struct kvm_vcpu *vcpu);
static int sync_regs(struct kvm_vcpu *vcpu);
+
+/* edited by chaitrali */
+int total_vm_exits;
+u64 totalExitTime;
+
struct kvm_x86_ops *kvm_x86_ops __read_mostly;
EXPORT_SYMBOL_GPL(kvm_x86_ops);
@@ -7369,6 +7374,9 @@ EXPORT_SYMBOL_GPL(kvm_vcpu_reload_apic_access_page);
static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
{
int r;
+
+ u64 startTime, endTime;
+
bool req_int_win =
dm_request_for_irq_injection(vcpu) &&
kvm_cpu_accept_dm_intr(vcpu);
@@ -7645,7 +7653,19 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
kvm_lapic_sync_from_vapic(vcpu);
vcpu->arch.gpa_available = false;
+
+
+ total_vm_exits++;
+ printk(KERN_INFO "Total exits: %d\n", total_vm_exits);
+ startTime = rdtsc();
+
+
r = kvm_x86_ops->handle_exit(vcpu);
+
+
+ endTime = rdtsc();
+ totalExitTime += endTime - startTime;
+
return r;
cancel_injection: