-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlinux-7.2-kvm-cppc.patch
More file actions
90 lines (85 loc) · 3.62 KB
/
Copy pathlinux-7.2-kvm-cppc.patch
File metadata and controls
90 lines (85 loc) · 3.62 KB
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
diff -x '*.orig' -x '*.rej' -x .config --unified --recursive --text --new-file linux-7.0_unpatched/arch/x86/include/asm/kvm_host.h linux-7.0/arch/x86/include/asm/kvm_host.h
--- linux-7.0_unpatched/arch/x86/include/asm/kvm_host.h 2026-05-03 03:53:16.882324922 +0200
+++ linux-7.0/arch/x86/include/asm/kvm_host.h 2026-05-03 03:53:19.360281232 +0200
@@ -730,6 +730,8 @@
u64 vm_id;
u32 vp_id;
} nested;
+ /* HACK (CPPC) */
+ u32 cppc_hack_counter;
};
struct kvm_hypervisor_cpuid {
diff -x '*.orig' -x '*.rej' -x .config --unified --recursive --text --new-file linux-7.0_unpatched/arch/x86/kvm/cpuid.c linux-7.0/arch/x86/kvm/cpuid.c
--- linux-7.0_unpatched/arch/x86/kvm/cpuid.c 2026-05-03 03:53:16.894918883 +0200
+++ linux-7.0/arch/x86/kvm/cpuid.c 2026-05-03 03:53:19.372939703 +0200
@@ -2133,6 +2133,7 @@
*eax = vcpu->arch.hw_tsc_khz;
}
}
+ kvm_hv_override_cpuid(vcpu, function, eax, ebx, ecx, edx);
} else {
*eax = *ebx = *ecx = *edx = 0;
/*
diff -x '*.orig' -x '*.rej' -x .config --unified --recursive --text --new-file linux-7.0_unpatched/arch/x86/kvm/hyperv.h linux-7.0/arch/x86/kvm/hyperv.h
--- linux-7.0_unpatched/arch/x86/kvm/hyperv.h 2026-05-03 03:53:16.895081493 +0200
+++ linux-7.0/arch/x86/kvm/hyperv.h 2026-05-03 03:53:19.373138753 +0200
@@ -177,6 +177,47 @@
return !(to_kvm_hv(vcpu->kvm)->hv_invtsc_control & HV_EXPOSE_INVARIANT_TSC);
}
+/*
+ * HACK (CPPC) - disable HV_CPU_MANAGEMENT until hypercalls are enabled
+ * to work around a page mapping error in winload.
+ */
+static inline void kvm_hv_override_cpuid(struct kvm_vcpu *vcpu, int function,
+ u32 *eax, u32 *ebx, u32 *ecx, u32 *edx)
+{
+ struct kvm *kvm = vcpu->kvm;
+ struct kvm_vcpu_hv *hv_vcpu = to_hv_vcpu(vcpu);
+ struct kvm_hv *hv = to_kvm_hv(kvm);
+ if (unlikely(!hv || !hv_vcpu))
+ return;
+ if (vcpu->vcpu_idx != 0)
+ return;
+ if (hv->hv_hypercall & HV_X64_MSR_HYPERCALL_ENABLE) {
+ //Use a 'warmup' counter to fix another issue:
+ // Prevent requirement for nested Hyper-V;
+ // if Hyper-V is not enabled but HV_CPU_MANAGEMENT is,
+ // Windows refuses to boot.
+ // The check is usually 2(Win10)/5(Win11) HYPERV_CPUID_FEATURES
+ // calls after enabling hypercalls (winload).
+ if (hv_vcpu->cppc_hack_counter > 5)
+ return;
+ if (function == HYPERV_CPUID_FEATURES)
+ ++hv_vcpu->cppc_hack_counter;
+ }
+ else {
+ hv_vcpu->cppc_hack_counter = 0;
+ }
+ if (function == HYPERV_CPUID_FEATURES) {
+ if (*ebx & HV_CPU_MANAGEMENT) {
+ *ebx &= ~(HV_CPU_MANAGEMENT | HV_ISOLATION);
+ }
+ }
+ //if (function == HYPERV_CPUID_ENLIGHTMENT_INFO) {
+ // if (hv_vcpu->cpuid_cache.features_ebx & HV_CPU_MANAGEMENT) {
+ // *eax &= ~(HV_X64_HYPERV_NESTED);
+ // }
+ //}
+}
+
void kvm_hv_process_stimers(struct kvm_vcpu *vcpu);
void kvm_hv_setup_tsc_page(struct kvm *kvm,
diff -x '*.orig' -x '*.rej' -x .config --unified --recursive --text --new-file linux-7.0_unpatched/arch/x86/kvm/svm/svm.c linux-7.0/arch/x86/kvm/svm/svm.c
--- linux-7.0_unpatched/arch/x86/kvm/svm/svm.c 2026-05-03 03:53:16.896028883 +0200
+++ linux-7.0/arch/x86/kvm/svm/svm.c 2026-05-03 03:53:19.374106322 +0200
@@ -815,8 +815,10 @@
guest_cpuid_is_intel_compatible(vcpu));
if (kvm_aperfmperf_in_guest(vcpu->kvm)) {
- svm_disable_intercept_for_msr(vcpu, MSR_IA32_APERF, MSR_TYPE_R);
- svm_disable_intercept_for_msr(vcpu, MSR_IA32_MPERF, MSR_TYPE_R);
+ svm_disable_intercept_for_msr(vcpu, MSR_IA32_APERF, MSR_TYPE_RW);
+ svm_disable_intercept_for_msr(vcpu, MSR_IA32_MPERF, MSR_TYPE_RW);
+ svm_disable_intercept_for_msr(vcpu, 0xC00000E8, MSR_TYPE_R); //APERF_RO AMD
+ svm_disable_intercept_for_msr(vcpu, 0xC00000E7, MSR_TYPE_R); //MPERF_RO AMD
}
if (kvm_cpu_cap_has(X86_FEATURE_SHSTK)) {