]> git.proxmox.com Git - qemu-server.git/blobdiff - PVE/QemuServer/CPUConfig.pm
cpu config: indentation fixup
[qemu-server.git] / PVE / QemuServer / CPUConfig.pm
index 66624fb0de709fd623355da231a269358cc87799..fb0861bb6ab641cc07c4801f0b55f02d05ea717c 100644 (file)
@@ -21,14 +21,22 @@ if (PVE::Cluster::check_cfs_is_mounted(1)) {
 }
 
 my $default_filename = "virtual-guest/cpu-models.conf";
-cfs_register_file($default_filename,
-                 sub { PVE::QemuServer::CPUConfig->parse_config(@_); },
-                 sub { PVE::QemuServer::CPUConfig->write_config(@_); });
+cfs_register_file(
+    $default_filename,
+    sub { PVE::QemuServer::CPUConfig->parse_config(@_); },
+    sub { PVE::QemuServer::CPUConfig->write_config(@_); },
+);
 
 sub load_custom_model_conf {
     return cfs_read_file($default_filename);
 }
 
+my $depreacated_cpu_map = {
+    # there never was such a client CPU, so map it to the server one for backward compat
+    'Icelake-Client' => 'Icelake-Server',
+    'Icelake-Client-noTSX' => 'Icelake-Server-noTSX',
+};
+
 my $cpu_vendor_list = {
     # Intel CPUs
     486 => 'GenuineIntel',
@@ -64,8 +72,8 @@ my $cpu_vendor_list = {
     'Cascadelake-Server' => 'GenuineIntel',
     'Cascadelake-Server-noTSX' => 'GenuineIntel',
     KnightsMill => 'GenuineIntel',
-    'Icelake-Client' => 'GenuineIntel',
-    'Icelake-Client-noTSX' => 'GenuineIntel',
+    'Icelake-Client' => 'GenuineIntel', # depreacated, removed with QEMU 7.1
+    'Icelake-Client-noTSX' => 'GenuineIntel', # depreacated, removed with QEMU 7.1
     'Icelake-Server' => 'GenuineIntel',
     'Icelake-Server-noTSX' => 'GenuineIntel',
 
@@ -80,6 +88,7 @@ my $cpu_vendor_list = {
     EPYC => 'AuthenticAMD',
     'EPYC-IBPB' => 'AuthenticAMD',
     'EPYC-Rome' => 'AuthenticAMD',
+    'EPYC-Milan' => 'AuthenticAMD',
 
     # generic types, use vendor from host node
     host => 'default',
@@ -120,7 +129,7 @@ my $cpu_fmt = {
     },
     'reported-model' => {
        description => "CPU model and vendor to report to the guest. Must be a QEMU/KVM supported model."
-                    . " Only valid for custom CPU model definitions, default models will always report themselves to the guest OS.",
+           ." Only valid for custom CPU model definitions, default models will always report themselves to the guest OS.",
        type => 'string',
        enum => [ sort { lc("$a") cmp lc("$b") } keys %$cpu_vendor_list ],
        default => 'kvm64',
@@ -140,11 +149,10 @@ my $cpu_fmt = {
        optional => 1,
     },
     flags => {
-       description => "List of additional CPU flags separated by ';'."
-                    . " Use '+FLAG' to enable, '-FLAG' to disable a flag."
-                    . " Custom CPU models can specify any flag supported by"
-                    . " QEMU/KVM, VM-specific flags must be from the following"
-                    . " set for security reasons: @{[join(', ', @supported_cpu_flags)]}.",
+       description => "List of additional CPU flags separated by ';'. Use '+FLAG' to enable,"
+           ." '-FLAG' to disable a flag. Custom CPU models can specify any flag supported by"
+           ." QEMU/KVM, VM-specific flags must be from the following set for security reasons: "
+           . join(', ', @supported_cpu_flags),
        format_description => '+FLAG[;-FLAG...]',
        type => 'string',
        pattern => qr/$cpu_flag_any_re(;$cpu_flag_any_re)*/,
@@ -154,10 +162,9 @@ my $cpu_fmt = {
        type => 'string',
        format => 'pve-phys-bits',
        format_description => '8-64|host',
-       description => "The physical memory address bits that are reported to"
-                    . " the guest OS. Should be smaller or equal to the host's."
-                    . " Set to 'host' to use value from host CPU, but note that"
-                    . " doing so will break live migration to CPUs with other values.",
+       description => "The physical memory address bits that are reported to the guest OS. Should"
+           ." be smaller or equal to the host's. Set to 'host' to use value from host CPU, but"
+           ." note that doing so will break live migration to CPUs with other values.",
        optional => 1,
     },
 };
@@ -170,12 +177,12 @@ sub parse_phys_bits {
 
     if ($str !~ m/^(host|\d{1,2})$/) {
        die $err_msg if !$noerr;
-       return undef;
+       return;
     }
 
     if ($str =~ m/^\d+$/ && (int($str) < 8 || int($str) > 64)) {
        die $err_msg if !$noerr;
-       return undef;
+       return;
     }
 
     return $str;
@@ -187,11 +194,8 @@ sub parse_phys_bits {
 PVE::JSONSchema::register_format('pve-cpu-conf', $cpu_fmt, \&validate_cpu_conf);
 sub validate_cpu_conf {
     my ($cpu) = @_;
-
-    # required, but can't be forced in schema since it's encoded in section
-    # header for custom models
+    # required, but can't be forced in schema since it's encoded in section header for custom models
     die "CPU is missing cputype\n" if !$cpu->{cputype};
-
     return $cpu;
 }
 PVE::JSONSchema::register_format('pve-vm-cpu-conf', $cpu_fmt, \&validate_vm_cpu_conf);
@@ -214,7 +218,7 @@ sub validate_vm_cpu_conf {
     # in a VM-specific config, certain properties are limited/forbidden
 
     die "VM-specific CPU flags must be a subset of: @{[join(', ', @supported_cpu_flags)]}\n"
-       if ($cpu->{flags} && $cpu->{flags} !~ m/$cpu_flag_supported_re(;$cpu_flag_supported_re)*/);
+       if ($cpu->{flags} && $cpu->{flags} !~ m/^$cpu_flag_supported_re(;$cpu_flag_supported_re)*$/);
 
     die "Property 'reported-model' not allowed in VM-specific CPU config.\n"
        if defined($cpu->{'reported-model'});
@@ -246,7 +250,7 @@ sub parse_section_header {
     my ($type, $sectionId, $errmsg, $config) =
        $class->SUPER::parse_section_header($line);
 
-    return undef if !$type;
+    return if !$type;
     return ($type, $sectionId, $errmsg, {
        # name is given by section header, and we can always prepend 'custom-'
        # since we're reading the custom CPU file
@@ -331,7 +335,7 @@ sub get_custom_model {
     my $entry = $conf->{ids}->{$name};
     if (!defined($entry)) {
        die "Custom cputype '$name' not found\n" if !$noerr;
-       return undef;
+       return;
     }
 
     my $model = {};
@@ -358,8 +362,10 @@ sub print_cpu_device {
        if (is_custom_model($cpu)) {
            my $custom_cpu = get_custom_model($cpu);
 
-           $cpu = $custom_cpu->{'reported-model'} //
-               $cpu_fmt->{'reported-model'}->{default};
+           $cpu = $custom_cpu->{'reported-model'} // $cpu_fmt->{'reported-model'}->{default};
+       }
+       if (my $replacement_type = $depreacated_cpu_map->{$cpu}) {
+           $cpu = $replacement_type;
        }
     }
 
@@ -368,6 +374,7 @@ sub print_cpu_device {
     my $current_core = ($id - 1) % $cores;
     my $current_socket = int(($id - 1 - $current_core)/$cores);
 
+    # FIXME: hot plugging other architectures like our unofficial arch64 support?
     return "$cpu-x86_64-cpu,id=cpu$id,socket-id=$current_socket,core-id=$current_core,thread-id=0";
 }
 
@@ -442,7 +449,7 @@ sub parse_cpuflag_list {
     return $res if !$flaglist;
 
     foreach my $flag (split(";", $flaglist)) {
-       if ($flag =~ $re) {
+       if ($flag =~ m/^$re$/) {
            $res->{$2} = { op => $1, reason => $reason };
        }
     }
@@ -471,31 +478,37 @@ sub get_cpu_options {
        if (is_custom_model($cputype)) {
            $custom_cpu = get_custom_model($cputype);
 
-           $cputype = $custom_cpu->{'reported-model'} //
-               $cpu_fmt->{'reported-model'}->{default};
-           $kvm_off = $custom_cpu->{hidden}
-               if defined($custom_cpu->{hidden});
+           $cputype = $custom_cpu->{'reported-model'} // $cpu_fmt->{'reported-model'}->{default};
+           $kvm_off = $custom_cpu->{hidden} if defined($custom_cpu->{hidden});
            $hv_vendor_id = $custom_cpu->{'hv-vendor-id'};
        }
 
+       if (my $replacement_type = $depreacated_cpu_map->{$cputype}) {
+           $cputype = $replacement_type;
+       }
+
        # VM-specific settings override custom CPU config
-       $kvm_off = $cpu->{hidden}
-           if defined($cpu->{hidden});
-       $hv_vendor_id = $cpu->{'hv-vendor-id'}
-           if defined($cpu->{'hv-vendor-id'});
+       $kvm_off = $cpu->{hidden} if defined($cpu->{hidden});
+       $hv_vendor_id = $cpu->{'hv-vendor-id'} if defined($cpu->{'hv-vendor-id'});
     }
 
-    my $pve_flags = get_pve_cpu_flags($conf, $kvm, $cputype, $arch,
-                                     $machine_version);
+    my $pve_flags = get_pve_cpu_flags($conf, $kvm, $cputype, $arch, $machine_version);
 
-    my $hv_flags = get_hyperv_enlightenments($winversion, $machine_version,
-       $conf->{bios}, $gpu_passthrough, $hv_vendor_id) if $kvm;
+    my $hv_flags = $kvm
+       ? get_hyperv_enlightenments(
+           $winversion,
+           $machine_version,
+           $conf->{bios},
+           $gpu_passthrough,
+           $hv_vendor_id,
+       )
+       : undef;
 
-    my $custom_cputype_flags = parse_cpuflag_list($cpu_flag_any_re,
-       "set by custom CPU model", $custom_cpu->{flags});
+    my $custom_cputype_flags = parse_cpuflag_list(
+       $cpu_flag_any_re, "set by custom CPU model", $custom_cpu->{flags});
 
-    my $vm_flags = parse_cpuflag_list($cpu_flag_supported_re,
-       "manually set for VM", $cpu->{flags});
+    my $vm_flags = parse_cpuflag_list(
+       $cpu_flag_supported_re, "manually set for VM", $cpu->{flags});
 
     my $pve_forced_flags = {};
     $pve_forced_flags->{'enforce'} = {
@@ -520,8 +533,8 @@ sub get_cpu_options {
     my $cpu_str = $cputype;
 
     # will be resolved in parameter order
-    $cpu_str .= resolve_cpu_flags($pve_flags, $hv_flags, $custom_cputype_flags,
-                             $vm_flags, $pve_forced_flags);
+    $cpu_str .= resolve_cpu_flags(
+       $pve_flags, $hv_flags, $custom_cputype_flags, $vm_flags, $pve_forced_flags);
 
     my $phys_bits = '';
     foreach my $conf ($custom_cpu, $cpu) {