Skip to content

Commit bb2127e

Browse files
arch: KVM CPUID definitions
We introduce CPUID definitions defined for the KVM hypervisor. These definitions will later be utilized by the upcoming CPU profile generation tool. Signed-off-by: Oliver Anderson <oliver.anderson@cyberus-technology.de> On-behalf-of: SAP oliver.anderson@sap.com
1 parent 8bed5b0 commit bb2127e

File tree

2 files changed

+206
-0
lines changed

2 files changed

+206
-0
lines changed
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
//! This module contains CPUID definitions for the KVM hypervisor.
2+
3+
use std::ops::RangeInclusive;
4+
5+
use crate::x86_64::CpuidReg;
6+
use crate::x86_64::cpuid_definitions::{
7+
CpuidDefinitions, Parameters, ProfilePolicy, ValueDefinition, ValueDefinitions,
8+
};
9+
10+
/// CPUID features defined for the KVM hypervisor.
11+
///
12+
/// See https://www.kernel.org/doc/html/latest/virt/kvm/x86/cpuid.html
13+
pub const KVM_CPUID_DEFINITIONS: CpuidDefinitions<6> = const {
14+
CpuidDefinitions([
15+
//=====================================================================
16+
// KVM CPUID Signature
17+
// ===================================================================
18+
(
19+
Parameters {
20+
leaf: 0x4000_0000,
21+
sub_leaf: RangeInclusive::new(0, 0),
22+
register: CpuidReg::EAX,
23+
},
24+
ValueDefinitions::new(&[ValueDefinition {
25+
short: "max_hypervisor_leaf",
26+
description: "The maximum valid leaf between 0x4000_0000 and 0x4FFF_FFF",
27+
bits_range: (0, 31),
28+
policy: ProfilePolicy::Passthrough,
29+
}]),
30+
),
31+
(
32+
Parameters {
33+
leaf: 0x4000_0000,
34+
sub_leaf: RangeInclusive::new(0, 0),
35+
register: CpuidReg::EBX,
36+
},
37+
ValueDefinitions::new(&[ValueDefinition {
38+
short: "hypervisor_string_ebx",
39+
description: "Part of the hypervisor string",
40+
bits_range: (0, 31),
41+
policy: ProfilePolicy::Passthrough,
42+
}]),
43+
),
44+
(
45+
Parameters {
46+
leaf: 0x4000_0000,
47+
sub_leaf: RangeInclusive::new(0, 0),
48+
register: CpuidReg::ECX,
49+
},
50+
ValueDefinitions::new(&[ValueDefinition {
51+
short: "hypervisor_string_ecx",
52+
description: "Part of the hypervisor string",
53+
bits_range: (0, 31),
54+
policy: ProfilePolicy::Passthrough,
55+
}]),
56+
),
57+
(
58+
Parameters {
59+
leaf: 0x4000_0000,
60+
sub_leaf: RangeInclusive::new(0, 0),
61+
register: CpuidReg::EDX,
62+
},
63+
ValueDefinitions::new(&[ValueDefinition {
64+
short: "hypervisor_string_edx",
65+
description: "Part of the hypervisor string",
66+
bits_range: (0, 31),
67+
policy: ProfilePolicy::Passthrough,
68+
}]),
69+
),
70+
//=====================================================================
71+
// KVM CPUID Features
72+
// ===================================================================
73+
(
74+
Parameters {
75+
leaf: 0x4000_0001,
76+
sub_leaf: RangeInclusive::new(0, 0),
77+
register: CpuidReg::EAX,
78+
},
79+
ValueDefinitions::new(&[
80+
ValueDefinition {
81+
short: "kvm_feature_clocksource",
82+
description: "kvmclock available at MSRs 0x11 and 0x12",
83+
bits_range: (0, 0),
84+
policy: ProfilePolicy::Passthrough,
85+
},
86+
ValueDefinition {
87+
short: "kvm_feature_nop_io_delay",
88+
description: "Not necessary to perform delays on PIO operations",
89+
bits_range: (1, 1),
90+
policy: ProfilePolicy::Passthrough,
91+
},
92+
ValueDefinition {
93+
short: "kvm_feature_mmu_op",
94+
description: "Deprecated",
95+
bits_range: (2, 2),
96+
policy: ProfilePolicy::Passthrough,
97+
},
98+
ValueDefinition {
99+
short: "kvm_feature_clocksource2",
100+
description: "kvmclock available at MSRs 0x4b564d00 and 0x4b564d01",
101+
bits_range: (3, 3),
102+
policy: ProfilePolicy::Passthrough,
103+
},
104+
ValueDefinition {
105+
short: "kvm_feature_async_pf",
106+
description: "async pf can be enabled by writing to MSR 0x4b564d02",
107+
bits_range: (4, 4),
108+
policy: ProfilePolicy::Passthrough,
109+
},
110+
ValueDefinition {
111+
short: "kvm_feature_steal_time",
112+
description: "steal time can be enabled by writing to msr 0x4b564d03",
113+
bits_range: (5, 5),
114+
policy: ProfilePolicy::Passthrough,
115+
},
116+
ValueDefinition {
117+
short: "kvm_feature_pv_eoi",
118+
description: "paravirtualized end of interrupt handler can be enabled by writing to msr 0x4b564d04",
119+
bits_range: (6, 6),
120+
policy: ProfilePolicy::Passthrough,
121+
},
122+
ValueDefinition {
123+
short: "kvm_feature_pv_unhalt",
124+
description: "guest checks this feature bit before enabling paravirtualized spinlock support",
125+
bits_range: (7, 7),
126+
policy: ProfilePolicy::Passthrough,
127+
},
128+
ValueDefinition {
129+
short: "kvm_feature_pv_tlb_flush",
130+
description: "guest checks this feature bit before enabling paravirtualized tlb flush",
131+
bits_range: (9, 9),
132+
policy: ProfilePolicy::Passthrough,
133+
},
134+
ValueDefinition {
135+
short: "kvm_feature_async_pf_vmexit",
136+
description: "paravirtualized async PF VM EXIT can be enabled by setting bit 2 when writing to msr 0x4b564d02",
137+
bits_range: (10, 10),
138+
policy: ProfilePolicy::Passthrough,
139+
},
140+
ValueDefinition {
141+
short: "kvm_feature_pv_send_ipi",
142+
description: "guest checks this feature bit before enabling paravirtualized send IPIs",
143+
bits_range: (11, 11),
144+
policy: ProfilePolicy::Passthrough,
145+
},
146+
ValueDefinition {
147+
short: "kvm_feature_poll_control",
148+
description: "host-side polling on HLT can be disabled by writing to msr 0x4b564d05.",
149+
bits_range: (12, 12),
150+
policy: ProfilePolicy::Passthrough,
151+
},
152+
ValueDefinition {
153+
short: "kvm_feature_pv_sched_yield",
154+
description: "guest checks this feature bit before using paravirtualized sched yield.",
155+
bits_range: (13, 13),
156+
policy: ProfilePolicy::Passthrough,
157+
},
158+
ValueDefinition {
159+
short: "kvm_feature_async_pf_int",
160+
description: "guest checks this feature bit before using the second async pf control msr 0x4b564d06 and async pf acknowledgment msr 0x4b564d07.",
161+
bits_range: (14, 14),
162+
policy: ProfilePolicy::Passthrough,
163+
},
164+
ValueDefinition {
165+
short: "kvm_feature_msi_ext_dest_id",
166+
description: "guest checks this feature bit before using extended destination ID bits in MSI address bits 11-5.",
167+
bits_range: (15, 15),
168+
policy: ProfilePolicy::Passthrough,
169+
},
170+
ValueDefinition {
171+
short: "kvm_feature_hc_map_gpa_range",
172+
description: "guest checks this feature bit before using the map gpa range hypercall to notify the page state change",
173+
bits_range: (16, 16),
174+
policy: ProfilePolicy::Passthrough,
175+
},
176+
ValueDefinition {
177+
short: "kvm_feature_migration_control",
178+
description: "guest checks this feature bit before using MSR_KVM_MIGRATION_CONTROL",
179+
bits_range: (17, 17),
180+
policy: ProfilePolicy::Passthrough,
181+
},
182+
ValueDefinition {
183+
short: "kvm_feature_clocksource_stable_bit",
184+
description: "host will warn if no guest-side per-cpu warps are expected in kvmclock",
185+
bits_range: (24, 24),
186+
policy: ProfilePolicy::Passthrough,
187+
},
188+
]),
189+
),
190+
(
191+
Parameters {
192+
leaf: 0x4000_0001,
193+
sub_leaf: RangeInclusive::new(0, 0),
194+
register: CpuidReg::EDX,
195+
},
196+
ValueDefinitions::new(&[ValueDefinition {
197+
short: "kvm_hints_realtime",
198+
description: "guest checks this feature bit to determine that vCPUs are never preempted for an unlimited time allowing optimizations",
199+
bits_range: (0, 0),
200+
policy: ProfilePolicy::Passthrough,
201+
}]),
202+
),
203+
])
204+
};

arch/src/x86_64/cpuid_definitions/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
66
use crate::x86_64::CpuidReg;
77

88
pub mod intel;
9+
#[cfg(feature = "kvm")]
10+
pub mod kvm;
911

1012
pub(in crate::x86_64) fn serialize_as_hex<S: Serializer>(
1113
input: &u32,

0 commit comments

Comments
 (0)