Repository navigation
Expand file tree
/
Copy path0002-add-port-support.patch
More file actions
677 lines (622 loc) · 21.7 KB
/
Copy path0002-add-port-support.patch
File metadata and controls
677 lines (622 loc) · 21.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
From d129754b2c456da7d53822024690ef19e10f3a35 Mon Sep 17 00:00:00 2001
From: jiangcuo <jiangcuo@bingsin.com>
Date: Mon, 3 Feb 2025 13:52:51 +0800
Subject: [PATCH 2/9] add port support
---
PVE/API2/Qemu.pm | 41 ++++++++-
PVE/API2/Qemu/Machine.pm | 4 +-
PVE/QemuServer.pm | 178 +++++++++++++++++++++++++++++-------
PVE/QemuServer/CPUConfig.pm | 56 +++++++++---
PVE/QemuServer/Helpers.pm | 2 +
PVE/QemuServer/Machine.pm | 6 +-
6 files changed, 234 insertions(+), 53 deletions(-)
diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 295260e7..43a91b80 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -17,7 +17,7 @@ use PVE::CGroup;
use PVE::Cluster qw (cfs_read_file cfs_write_file);;
use PVE::RRD;
use PVE::SafeSyslog;
-use PVE::Tools qw(extract_param);
+use PVE::Tools qw(extract_param get_host_arch);
use PVE::Exception qw(raise raise_param_exc raise_perm_exc);
use PVE::Storage;
use PVE::JSONSchema qw(get_standard_option);
@@ -28,7 +28,7 @@ use PVE::GuestImport;
use PVE::QemuConfig;
use PVE::QemuServer;
use PVE::QemuServer::Cloudinit;
-use PVE::QemuServer::CPUConfig;
+use PVE::QemuServer::CPUConfig qw(get_default_cpu_type);
use PVE::QemuServer::Drive qw(checked_volume_format checked_parse_volname);
use PVE::QemuServer::Helpers;
use PVE::QemuServer::ImportDisk;
@@ -664,6 +664,7 @@ my $memoryoptions = {
my $hwtypeoptions = {
'acpi' => 1,
+ 'arch' => 1,
'hotplug' => 1,
'kvm' => 1,
'machine' => 1,
@@ -687,6 +688,7 @@ my $generaloptions = {
'name' => 1,
'onboot' => 1,
'ostype' => 1,
+ 'gicversion' =>1,
'protection' => 1,
'reboot' => 1,
'startdate' => 1,
@@ -1239,10 +1241,43 @@ __PACKAGE__->register_method({
$conf->{smbios1} = PVE::QemuServer::generate_smbios1_uuid();
}
- if ((!defined($conf->{vmgenid}) || $conf->{vmgenid} eq '1') && $arch ne 'aarch64') {
+ # set default bios to ovmf
+ if (!$conf->{bios}){
+ $conf->{bios} = 'ovmf';
+ }
+
+ # set default arch for vm
+ my $hostarch = get_host_arch();
+ if (!$conf->{arch}) {
+ $conf->{arch} = $hostarch;
+ }
+
+ # We check the status of the kvm
+ # if it is a different architecture, the kvm will be disabled in vm config.
+ my $kvm = $conf->{kvm} // 1;
+ if ($conf->{arch} ne $hostarch) {
+ $kvm = 0;
+ }
+ $conf->{kvm} = $kvm;
+
+ if (!$conf->{cpu}) {
+ $conf->{cpu} = get_default_cpu_type($arch,$kvm);
+ }
+
+ if ((!defined($conf->{vmgenid}) || $conf->{vmgenid} eq '1') && $arch eq 'x86_64') {
$conf->{vmgenid} = PVE::QemuServer::generate_uuid();
}
+ # We detect the value of machine
+ # and if not, force it to be specified
+ if (!$conf->{machine}){
+ if ($conf->{arch} eq 'x86_64'){
+ $conf->{machine} = 'pc';
+ }else{
+ $conf->{machine} = 'virt';
+ }
+ }
+
# always pin Windows' machine version on create, they get confused too easily
my $machine_string = PVE::QemuServer::Machine::check_and_pin_machine_string(
$conf->{machine}, $conf->{ostype});
diff --git a/PVE/API2/Qemu/Machine.pm b/PVE/API2/Qemu/Machine.pm
index afb535c2..e9c9058b 100644
--- a/PVE/API2/Qemu/Machine.pm
+++ b/PVE/API2/Qemu/Machine.pm
@@ -38,7 +38,7 @@ __PACKAGE__->register_method({
},
type => {
type => 'string',
- enum => ['q35', 'i440fx'],
+ enum => ['q35', 'i440fx','virt'],
description => "The machine type.",
},
version => {
@@ -50,7 +50,7 @@ __PACKAGE__->register_method({
},
code => sub {
my $machines = eval {
- my $raw = file_get_contents('/usr/share/kvm/machine-versions-x86_64.json');
+ my $raw = file_get_contents('/usr/share/kvm/machine-versions.json');
return from_json($raw, { utf8 => 1 });
};
die "could not load supported machine versions - $@\n" if $@;
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 808c0e1c..56ecb1cd 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -97,11 +97,72 @@ my $OVMF = {
],
},
aarch64 => {
+ '4m-no-smm' => [
+ "$EDK2_FW_BASE/AAVMF_CODE.fd",
+ "$EDK2_FW_BASE/AAVMF_VARS.fd",
+ ],
+ '4m-no-smm-ms' => [
+ "$EDK2_FW_BASE/AAVMF_CODE.ms.fd",
+ "$EDK2_FW_BASE/AAVMF_VARS.ms.fd",
+ ],
+ '4m' => [
+ "$EDK2_FW_BASE/AAVMF_CODE.fd",
+ "$EDK2_FW_BASE/AAVMF_VARS.fd",
+ ],
+ '4m-ms' => [
+ "$EDK2_FW_BASE/AAVMF_CODE.ms.fd",
+ "$EDK2_FW_BASE/AAVMF_VARS.ms.fd",
+ ],
default => [
"$EDK2_FW_BASE/AAVMF_CODE.fd",
"$EDK2_FW_BASE/AAVMF_VARS.fd",
],
},
+ loongarch64 => {
+ default => [
+ "$EDK2_FW_BASE/LOONGARCH64_VIRT_CODE.fd",
+ "$EDK2_FW_BASE/LOONGARCH64_VIRT_VARS.fd",
+ ],
+ '4m-no-smm' => [
+ "$EDK2_FW_BASE/LOONGARCH64_VIRT_CODE.fd",
+ "$EDK2_FW_BASE/LOONGARCH64_VIRT_VARS.fd",
+ ],
+ '4m-no-smm-ms' => [
+ "$EDK2_FW_BASE/LOONGARCH64_VIRT_CODE.fd",
+ "$EDK2_FW_BASE/LOONGARCH64_VIRT_VARS.fd",
+ ],
+ '4m' => [
+ "$EDK2_FW_BASE/LOONGARCH64_VIRT_CODE.fd",
+ "$EDK2_FW_BASE/LOONGARCH64_VIRT_VARS.fd",
+ ],
+ '4m-ms' => [
+ "$EDK2_FW_BASE/LOONGARCH64_VIRT_CODE.fd",
+ "$EDK2_FW_BASE/LOONGARCH64_VIRT_VARS.fd",
+ ],
+ },
+ riscv64 => {
+ default => [
+ "$EDK2_FW_BASE/RISCV_VIRT_CODE.fd",
+ "$EDK2_FW_BASE/RISCV_VIRT_VARS.fd",
+ ],
+ '4m-no-smm' => [
+ "$EDK2_FW_BASE/RISCV_VIRT_CODE.fd",
+ "$EDK2_FW_BASE/RISCV_VIRT_VARS.fd",
+ ],
+ '4m-no-smm-ms' => [
+ "$EDK2_FW_BASE/RISCV_VIRT_CODE.fd",
+ "$EDK2_FW_BASE/RISCV_VIRT_VARS.fd",
+ ],
+ '4m' => [
+ "$EDK2_FW_BASE/RISCV_VIRT_CODE.fd",
+ "$EDK2_FW_BASE/RISCV_VIRT_VARS.fd",
+ ],
+ '4m-ms' => [
+ "$EDK2_FW_BASE/RISCV_VIRT_CODE.fd",
+ "$EDK2_FW_BASE/RISCV_VIRT_VARS.fd",
+ ],
+
+ },
};
my $cpuinfo = PVE::ProcFSTools::read_cpuinfo();
@@ -184,7 +245,7 @@ my $vga_fmt = {
default => 'std',
optional => 1,
default_key => 1,
- enum => [qw(cirrus qxl qxl2 qxl3 qxl4 none serial0 serial1 serial2 serial3 std virtio virtio-gl vmware)],
+ enum => [qw(cirrus qxl qxl2 qxl3 qxl4 none serial0 serial1 serial2 serial3 std virtio virtio-gl vmware ramfb)],
},
memory => {
description => "Sets the VGA memory (in MiB). Has no effect with serial display.",
@@ -342,6 +403,12 @@ my $confdesc = {
type => 'string',
description => "Memory properties.",
format => $PVE::QemuServer::Memory::memory_fmt
+ },
+ gicversion => {
+ optional => 1,
+ type => 'string',
+ description => "Set virt gic-version",
+ enum => [qw(host 2 3 4 max)],
},
'amd-sev' => {
description => "Secure Encrypted Virtualization (SEV) features by AMD CPUs",
@@ -383,7 +450,7 @@ my $confdesc = {
type => 'string',
description => "SCSI controller model",
enum => [qw(lsi lsi53c810 virtio-scsi-pci virtio-scsi-single megasas pvscsi)],
- default => 'lsi',
+ default => 'virtio-scsi-pci',
},
description => {
optional => 1,
@@ -637,7 +704,7 @@ EODESCR
description => "Virtual processor architecture. Defaults to the host.",
optional => 1,
type => 'string',
- enum => [qw(x86_64 aarch64)],
+ enum => [qw(x86_64 aarch64 loongarch64 riscv64)],
},
smbios1 => {
description => "Specify SMBIOS type 1 fields.",
@@ -1302,11 +1369,15 @@ sub print_tabletdevice_full {
# we use uhci for old VMs because tablet driver was buggy in older qemu
my $usbbus;
- if ($q35 || $arch eq 'aarch64') {
- $usbbus = 'ehci';
+ if ($q35) {
+ $usbbus = 'ehci';
} else {
- $usbbus = 'uhci';
+ $usbbus = 'uhci';
}
+
+ if ($arch ne 'x86_64'){
+ $usbbus = 'ehci';
+ }
return "usb-tablet,id=tablet,bus=$usbbus.0,port=1";
}
@@ -1314,7 +1385,7 @@ sub print_tabletdevice_full {
sub print_keyboarddevice_full {
my ($conf, $arch) = @_;
- return if $arch ne 'aarch64';
+ return if $arch eq 'x86_64';
return "usb-kbd,id=keyboard,bus=ehci.0,port=2";
}
@@ -1690,15 +1761,19 @@ my $vga_map = {
'std' => 'VGA',
'vmware' => 'vmware-svga',
'virtio' => 'virtio-vga',
- 'virtio-gl' => 'virtio-vga-gl',
+ 'virtio-gl' => 'virtio-gpu-gl',
+ 'ramfb' => 'ramfb',
};
sub print_vga_device {
my ($conf, $vga, $arch, $machine_version, $machine, $id, $qxlnum, $bridges) = @_;
my $type = $vga_map->{$vga->{type}};
- if ($arch eq 'aarch64' && defined($type) && $type eq 'virtio-vga') {
- $type = 'virtio-gpu';
+ if ($arch ne 'x86_64' && defined($type) && $type eq 'virtio-vga') {
+ $type = 'virtio-gpu-pci';
+ }
+ if ($arch ne 'x86_64' && defined($type) && $type eq 'virtio-gpu-gl') {
+ $type = 'virtio-gpu-gl';
}
my $vgamem_mb = $vga->{memory};
@@ -1750,7 +1825,7 @@ sub print_vga_device {
}
if ($vga->{type} eq 'virtio-gl') {
- my $base = '/usr/lib/x86_64-linux-gnu/lib';
+ my $base = '/usr/lib/$arch-linux-gnu/lib';
die "missing libraries for '$vga->{type}' detected! Please install 'libgl1' and 'libegl1'\n"
if !-e "${base}EGL.so.1" || !-e "${base}GL.so.1";
@@ -2814,6 +2889,7 @@ sub vmstatus {
$d->{cpus} = $conf->{vcpus} if $conf->{vcpus};
$d->{name} = $conf->{name} || "VM $vmid";
+ $d->{arch} = $conf->{arch} || get_host_arch();
$d->{maxmem} = get_current_memory($conf->{memory})*(1024*1024);
if ($conf->{balloon}) {
@@ -3082,7 +3158,12 @@ sub add_tpm_device {
push @$devices, "-chardev", "socket,id=tpmchar,path=$paths->{socket}";
push @$devices, "-tpmdev", "emulator,id=tpmdev,chardev=tpmchar";
+ my $arch = $conf->{arch} // get_host_arch();
+ if ($arch eq 'x86_64'){
push @$devices, "-device", "tpm-tis,tpmdev=tpmdev";
+ }else{
+ push @$devices, "-device", "tpm-tis-device,tpmdev=tpmdev";
+ }
}
sub start_swtpm {
@@ -3179,14 +3260,13 @@ sub get_ovmf_files($$$) {
or die "no OVMF images known for architecture '$arch'\n";
my $type = 'default';
- if ($arch eq 'x86_64') {
if (defined($efidisk->{efitype}) && $efidisk->{efitype} eq '4m') {
$type = $smm ? "4m" : "4m-no-smm";
$type .= '-ms' if $efidisk->{'pre-enrolled-keys'};
} else {
# TODO: log_warn about use of legacy images for x86_64 with Promxox VE 9
}
- }
+
my ($ovmf_code, $ovmf_vars) = $types->{$type}->@*;
die "EFI base image '$ovmf_code' not found\n" if ! -f $ovmf_code;
@@ -3225,8 +3305,8 @@ sub query_supported_cpu_flags {
# FIXME: Once this is merged, the code below should work for ARM as well:
# https://lists.nongnu.org/archive/html/qemu-devel/2019-06/msg04947.html
- die "QEMU/KVM cannot detect CPU flags on ARM (aarch64)\n" if
- $arch eq "aarch64";
+ die "QEMU/KVM cannot detect CPU flags on LoongArch64 \n" if
+ $arch eq "loongarch64";
my $kvm_supported = defined(kvm_version());
my $qemu_cmd = PVE::QemuServer::Helpers::get_command_for_arch($arch);
@@ -3245,7 +3325,8 @@ sub query_supported_cpu_flags {
'-chardev', "socket,id=qmp,path=/var/run/qemu-server/$fakevmid.qmp,server=on,wait=off",
'-mon', 'chardev=qmp,mode=control',
'-pidfile', $pidfile,
- '-S', '-daemonize'
+ '-S', '-daemonize',
+ '-cpu', 'max',
];
if (!$kvm) {
@@ -3260,7 +3341,7 @@ sub query_supported_cpu_flags {
$fakevmid,
'query-cpu-model-expansion',
type => 'full',
- model => { name => 'host' }
+ model => { name => 'max' }
);
my $props = $cmd_result->{model}->{props};
@@ -3370,7 +3451,7 @@ my sub get_vga_properties {
$vga->{type} = 'qxl' if $qxlnum;
if (!$vga->{type}) {
- if ($arch eq 'aarch64') {
+ if ($arch ne 'x86_64') {
$vga->{type} = 'virtio';
} elsif (min_version($machine_version, 2, 9)) {
$vga->{type} = (!$winversion || $winversion >= 6) ? 'std' : 'cirrus';
@@ -3482,7 +3563,10 @@ sub config_to_command {
push @$cmd, '-name', "$vmname,debug-threads=on";
- push @$cmd, '-no-shutdown';
+ # fix nvram poweroff issue on loongarch
+ if ( $arch ne 'loongarch64'){
+ push @$cmd, '-no-shutdown';
+ }
my $use_virtio = 0;
@@ -3545,7 +3629,7 @@ sub config_to_command {
push @$cmd, $fixups->@*;
}
- if ($conf->{vmgenid}) {
+ if ($conf->{vmgenid} && $arch eq 'x86_64' ) {
push @$devices, '-device', 'vmgenid,guid='.$conf->{vmgenid};
}
@@ -3593,7 +3677,7 @@ sub config_to_command {
# On aarch64, serial0 is the UART device. QEMU only allows
# connecting UART devices via the '-serial' command line, as
# the device has a fixed slot on the hardware...
- if ($arch eq 'aarch64' && $i == 0) {
+ if ($arch ne 'x86_64' && $i == 0) {
push @$devices, '-serial', "chardev:serial$i";
} else {
push @$devices, '-device', "isa-serial,chardev=serial$i";
@@ -3654,14 +3738,18 @@ sub config_to_command {
push @$cmd, '-boot', "menu=on,strict=on,reboot-timeout=1000,splash=/usr/share/qemu-server/bootsplash.jpg";
- push $machineFlags->@*, 'acpi=off' if defined($conf->{acpi}) && $conf->{acpi} == 0;
+ push $machineFlags->@*, 'acpi=off' if defined($conf->{acpi}) && $conf->{acpi} == 0 && $arch ne 'loongarch64';
push @$cmd, '-no-reboot' if defined($conf->{reboot}) && $conf->{reboot} == 0;
if ($vga->{type} && $vga->{type} !~ m/^serial\d+$/ && $vga->{type} ne 'none'){
+
+ if ($vga->{type} eq 'ramfb'){
+ push @$devices, '-device', 'ramfb';
+ }else{
push @$devices, '-device', print_vga_device(
$conf, $vga, $arch, $machine_version, $machine_type, undef, $qxlnum, $bridges);
-
+ }
push @$cmd, '-display', 'egl-headless,gl=core' if $vga->{type} eq 'virtio-gl'; # VIRGL
my $socket = PVE::QemuServer::Helpers::vnc_socket($vmid);
@@ -3957,14 +4045,18 @@ sub config_to_command {
if ($k == 2 && $legacy_igd) {
$k_name = "$k-igd";
}
+ if ( $arch eq 'x86_64' ){
my $pciaddr = print_pci_addr("pci.$k_name", undef, $arch, $machine_type);
my $devstr = "pci-bridge,id=pci.$k,chassis_nr=$k$pciaddr";
-
- if ($q35) { # add after -readconfig pve-q35.cfg
- splice @$devices, 2, 0, '-device', $devstr;
- } else {
- unshift @$devices, '-device', $devstr if $k > 0;
+ if ($q35) { # add after -readconfig pve-q35.cfg
+ splice @$devices, 2, 0, '-device', $devstr;
+ } else {
+ unshift @$devices, '-device', $devstr if $k > 0;
+ }
+ }
}
+ if ($arch ne 'x86_64') {
+ unshift @$devices, '-readconfig', '/usr/share/qemu-server/pve-port.cfg';
}
if (!$kvm) {
@@ -3976,12 +4068,11 @@ sub config_to_command {
my $machine_type_min = $machine_type;
$machine_type_min =~ s/\+pve\d+$//;
$machine_type_min .= "+pve$required_pve_version";
- push @$machineFlags, "type=${machine_type_min}";
PVE::QemuServer::Machine::assert_valid_machine_property($machine_conf);
if (my $viommu = $machine_conf->{viommu}) {
- if ($viommu eq 'intel') {
+ if ($viommu eq 'intel' && ($arch eq 'x86_64')) {
unshift @$devices, '-device', 'intel-iommu,intremap=on,caching-mode=on';
push @$machineFlags, 'kernel-irqchip=split';
} elsif ($viommu eq 'virtio') {
@@ -3989,7 +4080,18 @@ sub config_to_command {
}
}
- if ($conf->{'amd-sev'}) {
+ my $gicv = $kvm ? 'host' : 'max';
+ if ( $conf->{gicversion} ) {
+ $gicv = $conf->{gicversion};
+ }
+
+ if ($arch eq 'aarch64'){
+ push @$machineFlags, "type=${machine_type_min},gic-version=${gicv}";
+ }else{
+ push @$machineFlags, "type=${machine_type_min}";
+ }
+
+ if ($conf->{'amd-sev'} && ($arch eq 'x86_64')) {
push @$devices, '-object', get_amd_sev_object($conf->{'amd-sev'}, $conf->{bios});
push @$machineFlags, 'confidential-guest-support=sev0';
}
@@ -4163,6 +4265,12 @@ sub vm_deviceplug {
my $machine_type = PVE::QemuServer::Machine::qemu_machine_pxe($vmid, $conf);
my $machine_version = PVE::QemuServer::Machine::extract_version($machine_type);
+
+ #loongarch64 and riscv64 qemu is special, we get machine_version from the current qemu version
+ if ( $arch eq 'loongarch64'|| $arch eq 'riscv64' ) {
+ $machine_version = extract_version($machine_type, kvm_user_version());
+ }
+
my $use_old_bios_files = undef;
($use_old_bios_files, $machine_type) = qemu_use_old_bios_files($machine_type);
@@ -4853,10 +4961,10 @@ sub vmconfig_hotplug_pending {
if ($defaults->{tablet}) {
vm_deviceplug($storecfg, $conf, $vmid, 'tablet', $arch, $machine_type);
vm_deviceplug($storecfg, $conf, $vmid, 'keyboard', $arch, $machine_type)
- if $arch eq 'aarch64';
+ if $arch ne 'x86_64';
} else {
vm_deviceunplug($vmid, $conf, 'tablet');
- vm_deviceunplug($vmid, $conf, 'keyboard') if $arch eq 'aarch64';
+ vm_deviceunplug($vmid, $conf, 'keyboard') if $arch ne 'x86_64';
}
} elsif ($opt =~ m/^usb(\d+)$/) {
my $index = $1;
@@ -4918,10 +5026,10 @@ sub vmconfig_hotplug_pending {
if ($value == 1) {
vm_deviceplug($storecfg, $conf, $vmid, 'tablet', $arch, $machine_type);
vm_deviceplug($storecfg, $conf, $vmid, 'keyboard', $arch, $machine_type)
- if $arch eq 'aarch64';
+ if $arch ne 'x86_64';
} elsif ($value == 0) {
vm_deviceunplug($vmid, $conf, 'tablet');
- vm_deviceunplug($vmid, $conf, 'keyboard') if $arch eq 'aarch64';
+ vm_deviceunplug($vmid, $conf, 'keyboard') if $arch ne 'x86_64';
}
} elsif ($opt =~ m/^usb(\d+)$/) {
my $index = $1;
diff --git a/PVE/QemuServer/CPUConfig.pm b/PVE/QemuServer/CPUConfig.pm
index e65d8c26..01f92282 100644
--- a/PVE/QemuServer/CPUConfig.pm
+++ b/PVE/QemuServer/CPUConfig.pm
@@ -18,6 +18,7 @@ get_cpu_options
get_cpu_bitness
is_native_arch
get_amd_sev_object
+get_default_cpu_type
);
# under certain race-conditions, this module might be loaded before pve-cluster
@@ -156,6 +157,27 @@ my $cpu_vendor_list = {
qemu32 => 'default',
qemu64 => 'default',
max => 'default',
+
+ # Arm
+ 'cortex-a35' => 'ARM',
+ 'cortex-a53' => 'ARM',
+ 'cortex-a55' => 'ARM',
+ 'cortex-a57' => 'ARM',
+ 'cortex-a72' => 'ARM',
+ 'cortex-a76' => 'ARM',
+ 'neoverse-n1' => 'ARM',
+ 'neoverse-n2' => 'ARM',
+ 'neoverse-v1' => 'ARM',
+ 'Kunpeng-920' => 'ARM',
+
+ # LoongArch
+ 'la464_loongarch_cpu' => 'LoongARCH',
+ 'la464' => 'LoongARCH',
+ 'la132' => 'LoongARCH',
+
+ # RISCV
+ 'rv64' => 'RISCV',
+
};
my @supported_cpu_flags = (
@@ -191,7 +213,7 @@ my $cpu_fmt = {
." 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',
+ default => 'max',
optional => 1,
},
hidden => {
@@ -576,6 +598,11 @@ sub get_cpu_options {
or die "Cannot parse cpu description: $cpu_prop_str\n";
$cputype = $cpu->{cputype};
+
+ if ( $cputype eq 'la464_loongarch_cpu' ) {
+ $cputype = 'la464';
+ }
+
if (my $model = $builtin_models->{$cputype}) {
$cputype = $model->{'reported-model'};
$builtin_cpu->{flags} = $model->{'flags'};
@@ -628,15 +655,12 @@ sub get_cpu_options {
# $cputype is the "reported-model" for custom types, so we can just look up
# the vendor in the default list
- my $cpu_vendor = $cpu_vendor_list->{$cputype};
+ my $cpu_vendor = $cpu_vendor_list->{$cputype} if $arch eq 'x86_64';
if ($cpu_vendor) {
- $pve_forced_flags->{'vendor'} = {
- value => $cpu_vendor,
- } if $cpu_vendor ne 'default';
- } elsif ($arch ne 'aarch64') {
- die "internal error"; # should not happen
- }
-
+ $pve_forced_flags->{'vendor'} = {
+ value => $cpu_vendor,
+ } if $cpu_vendor ne 'default';
+ }
my $cpu_str = $cputype;
# will be resolved in parameter order
@@ -769,8 +793,14 @@ sub get_cpu_from_running_vm {
sub get_default_cpu_type {
my ($arch, $kvm) = @_;
- my $cputype = $kvm ? 'kvm64' : 'qemu64';
- $cputype = 'cortex-a57' if $arch eq 'aarch64';
+ # if !kvm ,cpu will set to max for all arch
+ my $cputype = 'max';
+ if ($kvm){
+ $cputype = 'host' if $arch eq 'x86_64';
+ $cputype = 'host' if $arch eq 'aarch64';
+ $cputype = 'rv64' if $arch eq 'riscv64';
+ $cputype = 'la464' if $arch eq 'loongarch64';
+ }
return $cputype;
}
@@ -802,7 +832,9 @@ sub get_cpu_bitness {
}
return $cputypes_32bit->{$cputype} ? 32 : 64 if $arch eq 'x86_64';
- return 64 if $arch eq 'aarch64';
+ if ($arch eq 'aarch64' || $arch eq 'loongarch64' || $arch eq 'riscv64') {
+ return 64;
+ }
die "unsupported architecture '$arch'\n";
}
diff --git a/PVE/QemuServer/Helpers.pm b/PVE/QemuServer/Helpers.pm
index 8e9f4fc0..ac406b71 100644
--- a/PVE/QemuServer/Helpers.pm
+++ b/PVE/QemuServer/Helpers.pm
@@ -24,6 +24,8 @@ my $nodename = PVE::INotify::nodename();
my $arch_to_qemu_binary = {
aarch64 => '/usr/bin/qemu-system-aarch64',
x86_64 => '/usr/bin/qemu-system-x86_64',
+ loongarch64 => '/usr/bin/qemu-system-loongarch64',
+ riscv64 => '/usr/bin/qemu-system-riscv64',
};
sub get_command_for_arch($) {
my ($arch) = @_;
diff --git a/PVE/QemuServer/Machine.pm b/PVE/QemuServer/Machine.pm
index f1acde8f..33ed1756 100644
--- a/PVE/QemuServer/Machine.pm
+++ b/PVE/QemuServer/Machine.pm
@@ -7,6 +7,8 @@ use PVE::QemuServer::Helpers;
use PVE::QemuServer::MetaInfo;
use PVE::QemuServer::Monitor;
use PVE::JSONSchema qw(get_standard_option parse_property_string print_property_string);
+use PVE::Tools qw(get_host_arch);
+
# Bump this for VM HW layout changes during a release (where the QEMU machine
# version stays the same)
@@ -59,6 +61,8 @@ sub print_machine {
my $default_machines = {
x86_64 => 'pc',
aarch64 => 'virt',
+ riscv64 => 'virt',
+ loongarch64 => 'virt',
};
sub default_machine_for_arch {
@@ -241,7 +245,7 @@ sub get_vm_machine {
}
$machine = windows_get_pinned_machine_version($machine, $base_version, $kvmversion);
}
- $arch //= 'x86_64';
+ $arch //= get_host_arch();
$machine ||= default_machine_for_arch($arch);
my $pvever = get_pve_version($kvmversion);
$machine .= "+pve$pvever";
--
2.39.5