[pve-devel] [PATCH qemu-server 6/7] Handle CPU flags defined in custom CPU type

Stefan Reiter s.reiter at proxmox.com
Mon Sep 2 16:27:58 CEST 2019


Special care is taken not to overwrite any special flags, or ones
manually set on the VM by the user. We warn if a flag is overruled.

Signed-off-by: Stefan Reiter <s.reiter at proxmox.com>
---
 PVE/QemuServer.pm | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 417bea8..7cc1674 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -3597,6 +3597,7 @@ sub get_cpu_options {
     }
     my $hv_vendor_id;
     my $custom_cpu_config;
+    my @vm_specific_flags;
     if (my $cputype = $conf->{cpu}) {
 	my $cpuconf = PVE::JSONSchema::parse_property_string($cpu_fmt, $cputype)
 	    or die "Cannot parse cpu description: $cputype\n";
@@ -3624,7 +3625,8 @@ sub get_cpu_options {
 	$hv_vendor_id = $cpuconf->{'hv-vendor-id'};
 
 	if (defined(my $flags = $cpuconf->{flags})) {
-	    push @$cpuFlags, split(";", $flags);
+	    @vm_specific_flags = split(";", $flags);
+	    push @$cpuFlags, @vm_specific_flags;
 	}
     }
 
@@ -3649,6 +3651,28 @@ sub get_cpu_options {
 
     push @$cpuFlags, 'kvm=off' if $kvm_off;
 
+    if (defined($custom_cpu_config) && defined($custom_cpu_config->{flags})) {
+	my @custom_flags = split(/;/, $custom_cpu_config->{flags});
+	foreach my $flag (@custom_flags) {
+	    # find index of $flag in $cpuFlags while ignoring prefix [+-=]
+	    $flag =~ m/^[+-=]?(.*)$/;
+	    my $match_flag = $1;
+	    my @match_index = grep { $cpuFlags->[$_] =~ m/[+-=]?\Q$match_flag/ }
+		0..scalar(@$cpuFlags)-1;
+
+	    if (@match_index) {
+		my $other_flag = $cpuFlags->[$match_index[0]];
+		# warn only if prefix differs and flag is not vm specific
+		warn "warning: custom CPU model flag '$flag' overruled by '$other_flag' due to either default handling of basemodel or selected OS.\n"
+		    if (substr $other_flag, 0, 1) ne (substr $flag, 0, 1) &&
+		    (!@vm_specific_flags ||
+			!grep(m/[+-=]?\Q$match_flag/, @vm_specific_flags));
+	    } else {
+		push(@$cpuFlags, $flag);
+	    }
+	}
+    }
+
     if (defined($custom_cpu_config) && (my $custom_vendor = $custom_cpu_config->{vendor})) {
 	push @$cpuFlags, "vendor=${custom_vendor}"
 	    if $custom_vendor ne 'default';
-- 
2.20.1





More information about the pve-devel mailing list