Skip to content

Commit d674497

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 <[email protected]> On-behalf-of: SAP [email protected]
1 parent 91564b1 commit d674497

File tree

2 files changed

+211
-0
lines changed

2 files changed

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

arch/src/x86_64/cpuid_definitions/mod.rs

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

1313
pub mod intel;
14+
#[cfg(feature = "kvm")]
15+
pub mod kvm;
1416

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

0 commit comments

Comments
 (0)