1 package PVE
::QemuServer
::CPUConfig
;
7 use PVE
::QemuServer
::Helpers
qw(min_version);
16 my $cpu_vendor_list = {
18 486 => 'GenuineIntel',
19 pentium
=> 'GenuineIntel',
20 pentium2
=> 'GenuineIntel',
21 pentium3
=> 'GenuineIntel',
22 coreduo
=> 'GenuineIntel',
23 core2duo
=> 'GenuineIntel',
24 Conroe
=> 'GenuineIntel',
25 Penryn
=> 'GenuineIntel',
26 Nehalem
=> 'GenuineIntel',
27 'Nehalem-IBRS' => 'GenuineIntel',
28 Westmere
=> 'GenuineIntel',
29 'Westmere-IBRS' => 'GenuineIntel',
30 SandyBridge
=> 'GenuineIntel',
31 'SandyBridge-IBRS' => 'GenuineIntel',
32 IvyBridge
=> 'GenuineIntel',
33 'IvyBridge-IBRS' => 'GenuineIntel',
34 Haswell
=> 'GenuineIntel',
35 'Haswell-IBRS' => 'GenuineIntel',
36 'Haswell-noTSX' => 'GenuineIntel',
37 'Haswell-noTSX-IBRS' => 'GenuineIntel',
38 Broadwell
=> 'GenuineIntel',
39 'Broadwell-IBRS' => 'GenuineIntel',
40 'Broadwell-noTSX' => 'GenuineIntel',
41 'Broadwell-noTSX-IBRS' => 'GenuineIntel',
42 'Skylake-Client' => 'GenuineIntel',
43 'Skylake-Client-IBRS' => 'GenuineIntel',
44 'Skylake-Server' => 'GenuineIntel',
45 'Skylake-Server-IBRS' => 'GenuineIntel',
46 'Cascadelake-Server' => 'GenuineIntel',
47 KnightsMill
=> 'GenuineIntel',
50 athlon
=> 'AuthenticAMD',
51 phenom
=> 'AuthenticAMD',
52 Opteron_G1
=> 'AuthenticAMD',
53 Opteron_G2
=> 'AuthenticAMD',
54 Opteron_G3
=> 'AuthenticAMD',
55 Opteron_G4
=> 'AuthenticAMD',
56 Opteron_G5
=> 'AuthenticAMD',
57 EPYC
=> 'AuthenticAMD',
58 'EPYC-IBPB' => 'AuthenticAMD',
60 # generic types, use vendor from host node
69 my @supported_cpu_flags = (
83 my $cpu_flag = qr/[+-](@{[join('|', @supported_cpu_flags)]})/;
87 description
=> "Emulated CPU type.",
89 enum
=> [ sort { "\L$a" cmp "\L$b" } keys %$cpu_vendor_list ],
94 description
=> "Do not identify as a KVM virtual machine.",
101 pattern
=> qr/[a-zA-Z0-9]{1,12}/,
102 format_description
=> 'vendor-id',
103 description
=> 'The Hyper-V vendor ID. Some drivers or programs inside Windows guests need a specific ID.',
107 description
=> "List of additional CPU flags separated by ';'."
108 . " Use '+FLAG' to enable, '-FLAG' to disable a flag."
109 . " Currently supported flags: @{[join(', ', @supported_cpu_flags)]}.",
110 format_description
=> '+FLAG[;-FLAG...]',
112 pattern
=> qr/$cpu_flag(;$cpu_flag)*/,
117 # Print a QEMU device node for a given VM configuration for hotplugging CPUs
118 sub print_cpu_device
{
119 my ($conf, $id) = @_;
121 my $kvm = $conf->{kvm
} // 1;
122 my $cpu = $kvm ?
"kvm64" : "qemu64";
123 if (my $cputype = $conf->{cpu
}) {
124 my $cpuconf = PVE
::JSONSchema
::parse_property_string
($cpu_fmt, $cputype)
125 or die "Cannot parse cpu description: $cputype\n";
126 $cpu = $cpuconf->{cputype
};
129 my $cores = $conf->{cores
} || 1;
131 my $current_core = ($id - 1) % $cores;
132 my $current_socket = int(($id - 1 - $current_core)/$cores);
134 return "$cpu-x86_64-cpu,id=cpu$id,socket-id=$current_socket,core-id=$current_core,thread-id=0";
137 # Calculate QEMU's '-cpu' argument from a given VM configuration
138 sub get_cpu_options
{
139 my ($conf, $arch, $kvm, $kvm_off, $machine_version, $winversion, $gpu_passthrough) = @_;
142 my $ostype = $conf->{ostype
};
144 my $cpu = $kvm ?
"kvm64" : "qemu64";
145 if ($arch eq 'aarch64') {
149 if (my $cputype = $conf->{cpu
}) {
150 my $cpuconf = PVE
::JSONSchema
::parse_property_string
($cpu_fmt, $cputype)
151 or die "Cannot parse cpu description: $cputype\n";
152 $cpu = $cpuconf->{cputype
};
153 $kvm_off = 1 if $cpuconf->{hidden
};
154 $hv_vendor_id = $cpuconf->{'hv-vendor-id'};
156 if (defined(my $flags = $cpuconf->{flags
})) {
157 push @$cpuFlags, split(";", $flags);
161 push @$cpuFlags , '+lahf_lm' if $cpu eq 'kvm64' && $arch eq 'x86_64';
163 push @$cpuFlags , '-x2apic' if $ostype && $ostype eq 'solaris';
165 push @$cpuFlags, '+sep' if $cpu eq 'kvm64' || $cpu eq 'kvm32';
167 push @$cpuFlags, '-rdtscp' if $cpu =~ m/^Opteron/;
169 if (min_version
($machine_version, 2, 3) && $arch eq 'x86_64') {
171 push @$cpuFlags , '+kvm_pv_unhalt' if $kvm;
172 push @$cpuFlags , '+kvm_pv_eoi' if $kvm;
175 add_hyperv_enlightenments
($cpuFlags, $winversion, $machine_version, $conf->{bios
}, $gpu_passthrough, $hv_vendor_id) if $kvm;
177 push @$cpuFlags, 'enforce' if $cpu ne 'host' && $kvm && $arch eq 'x86_64';
179 push @$cpuFlags, 'kvm=off' if $kvm_off;
181 if (my $cpu_vendor = $cpu_vendor_list->{$cpu}) {
182 push @$cpuFlags, "vendor=${cpu_vendor}"
183 if $cpu_vendor ne 'default';
184 } elsif ($arch ne 'aarch64') {
185 die "internal error"; # should not happen
188 $cpu .= "," . join(',', @$cpuFlags) if scalar(@$cpuFlags);
190 return ('-cpu', $cpu);
193 sub add_hyperv_enlightenments
{
194 my ($cpuFlags, $winversion, $machine_version, $bios, $gpu_passthrough, $hv_vendor_id) = @_;
196 return if $winversion < 6;
197 return if $bios && $bios eq 'ovmf' && $winversion < 8;
199 if ($gpu_passthrough || defined($hv_vendor_id)) {
200 $hv_vendor_id //= 'proxmox';
201 push @$cpuFlags , "hv_vendor_id=$hv_vendor_id";
204 if (min_version
($machine_version, 2, 3)) {
205 push @$cpuFlags , 'hv_spinlocks=0x1fff';
206 push @$cpuFlags , 'hv_vapic';
207 push @$cpuFlags , 'hv_time';
209 push @$cpuFlags , 'hv_spinlocks=0xffff';
212 if (min_version
($machine_version, 2, 6)) {
213 push @$cpuFlags , 'hv_reset';
214 push @$cpuFlags , 'hv_vpindex';
215 push @$cpuFlags , 'hv_runtime';
218 if ($winversion >= 7) {
219 push @$cpuFlags , 'hv_relaxed';
221 if (min_version
($machine_version, 2, 12)) {
222 push @$cpuFlags , 'hv_synic';
223 push @$cpuFlags , 'hv_stimer';
226 if (min_version
($machine_version, 3, 1)) {
227 push @$cpuFlags , 'hv_ipi';