Browse Source

Merge remote-tracking branch 'remotes/ehabkost/tags/machine-next-pull-request' into staging

Machine queue, 2019-04-25

* 4.1 machine-types (Cornelia Huck)
* Support MAP_SYNC on pmem memory backends (Zhang Yi)
* -cpu parsing fixes and cleanups (Eduardo Habkost)
* machine initialization cleanups (Wei Yang, Markus Armbruster)

# gpg: Signature made Thu 25 Apr 2019 18:54:57 BST
# gpg:                using RSA key 2807936F984DC5A6
# gpg: Good signature from "Eduardo Habkost <ehabkost@redhat.com>" [full]
# Primary key fingerprint: 5A32 2FD5 ABC4 D3DB ACCF  D1AA 2807 936F 984D C5A6

* remotes/ehabkost/tags/machine-next-pull-request:
  util/mmap-alloc: support MAP_SYNC in qemu_ram_mmap()
  linux-headers: add linux/mman.h.
  scripts/update-linux-headers: add linux/mman.h
  util/mmap-alloc: Add a 'is_pmem' parameter to qemu_ram_mmap
  cpu: Fix crash with empty -cpu option
  cpu: Rename parse_cpu_model() to parse_cpu_option()
  vl: Simplify machine_parse()
  vl: Clean up after previous commit
  vl.c: allocate TYPE_MACHINE list once during bootup
  vl.c: make find_default_machine() local
  hw: add compat machines for 4.1

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
master
Peter Maydell 1 month ago
parent
commit
06e6433955

+ 1
- 1
bsd-user/main.c View File

@@ -905,7 +905,7 @@ int main(int argc, char **argv)
905 905
     /* init tcg before creating CPUs and to get qemu_host_page_size */
906 906
     tcg_exec_init(0);
907 907
 
908
-    cpu_type = parse_cpu_model(cpu_model);
908
+    cpu_type = parse_cpu_option(cpu_model);
909 909
     cpu = cpu_create(cpu_type);
910 910
     env = cpu->env_ptr;
911 911
 #if defined(TARGET_SPARC) || defined(TARGET_PPC)

+ 19
- 3
docs/nvdimm.txt View File

@@ -144,9 +144,25 @@ Guest Data Persistence
144 144
 ----------------------
145 145
 
146 146
 Though QEMU supports multiple types of vNVDIMM backends on Linux,
147
-currently the only one that can guarantee the guest write persistence
148
-is the device DAX on the real NVDIMM device (e.g., /dev/dax0.0), to
149
-which all guest access do not involve any host-side kernel cache.
147
+the only backend that can guarantee the guest write persistence is:
148
+
149
+A. DAX device (e.g., /dev/dax0.0, ) or
150
+B. DAX file(mounted with dax option)
151
+
152
+When using B (A file supporting direct mapping of persistent memory)
153
+as a backend, write persistence is guaranteed if the host kernel has
154
+support for the MAP_SYNC flag in the mmap system call (available
155
+since Linux 4.15 and on certain distro kernels) and additionally
156
+both 'pmem' and 'share' flags are set to 'on' on the backend.
157
+
158
+If these conditions are not satisfied i.e. if either 'pmem' or 'share'
159
+are not set, if the backend file does not support DAX or if MAP_SYNC
160
+is not supported by the host kernel, write persistence is not
161
+guaranteed after a system crash. For compatibility reasons, these
162
+conditions are ignored if not satisfied. Currently, no way is
163
+provided to test for them.
164
+For more details, please reference mmap(2) man page:
165
+http://man7.org/linux/man-pages/man2/mmap.2.html.
150 166
 
151 167
 When using other types of backends, it's suggested to set 'unarmed'
152 168
 option of '-device nvdimm' to 'on', which sets the unarmed flag of the

+ 7
- 3
exec.c View File

@@ -983,14 +983,18 @@ void cpu_exec_realizefn(CPUState *cpu, Error **errp)
983 983
 #endif
984 984
 }
985 985
 
986
-const char *parse_cpu_model(const char *cpu_model)
986
+const char *parse_cpu_option(const char *cpu_option)
987 987
 {
988 988
     ObjectClass *oc;
989 989
     CPUClass *cc;
990 990
     gchar **model_pieces;
991 991
     const char *cpu_type;
992 992
 
993
-    model_pieces = g_strsplit(cpu_model, ",", 2);
993
+    model_pieces = g_strsplit(cpu_option, ",", 2);
994
+    if (!model_pieces[0]) {
995
+        error_report("-cpu option cannot be empty");
996
+        exit(1);
997
+    }
994 998
 
995 999
     oc = cpu_class_by_name(CPU_RESOLVING_TYPE, model_pieces[0]);
996 1000
     if (oc == NULL) {
@@ -1915,7 +1919,7 @@ static void *file_ram_alloc(RAMBlock *block,
1915 1919
     }
1916 1920
 
1917 1921
     area = qemu_ram_mmap(fd, memory, block->mr->align,
1918
-                         block->flags & RAM_SHARED);
1922
+                         block->flags & RAM_SHARED, block->flags & RAM_PMEM);
1919 1923
     if (area == MAP_FAILED) {
1920 1924
         error_setg_errno(errp, errno,
1921 1925
                          "unable to map backing store for guest RAM");

+ 8
- 1
hw/arm/virt.c View File

@@ -1978,10 +1978,17 @@ static void machvirt_machine_init(void)
1978 1978
 }
1979 1979
 type_init(machvirt_machine_init);
1980 1980
 
1981
+static void virt_machine_4_1_options(MachineClass *mc)
1982
+{
1983
+}
1984
+DEFINE_VIRT_MACHINE_AS_LATEST(4, 1)
1985
+
1981 1986
 static void virt_machine_4_0_options(MachineClass *mc)
1982 1987
 {
1988
+    virt_machine_4_1_options(mc);
1989
+    compat_props_add(mc->compat_props, hw_compat_4_0, hw_compat_4_0_len);
1983 1990
 }
1984
-DEFINE_VIRT_MACHINE_AS_LATEST(4, 0)
1991
+DEFINE_VIRT_MACHINE(4, 0)
1985 1992
 
1986 1993
 static void virt_machine_3_1_options(MachineClass *mc)
1987 1994
 {

+ 3
- 0
hw/core/machine.c View File

@@ -24,6 +24,9 @@
24 24
 #include "hw/pci/pci.h"
25 25
 #include "hw/mem/nvdimm.h"
26 26
 
27
+GlobalProperty hw_compat_4_0[] = {};
28
+const size_t hw_compat_4_0_len = G_N_ELEMENTS(hw_compat_4_0);
29
+
27 30
 GlobalProperty hw_compat_3_1[] = {
28 31
     { "pcie-root-port", "x-speed", "2_5" },
29 32
     { "pcie-root-port", "x-width", "1" },

+ 3
- 0
hw/i386/pc.c View File

@@ -115,6 +115,9 @@ struct hpet_fw_config hpet_cfg = {.count = UINT8_MAX};
115 115
 /* Physical Address of PVH entry point read from kernel ELF NOTE */
116 116
 static size_t pvh_start_addr;
117 117
 
118
+GlobalProperty pc_compat_4_0[] = {};
119
+const size_t pc_compat_4_0_len = G_N_ELEMENTS(pc_compat_4_0);
120
+
118 121
 GlobalProperty pc_compat_3_1[] = {
119 122
     { "intel-iommu", "dma-drain", "off" },
120 123
     { "Opteron_G3" "-" TYPE_X86_CPU, "rdtscp", "off" },

+ 13
- 1
hw/i386/pc_piix.c View File

@@ -428,13 +428,25 @@ static void pc_i440fx_machine_options(MachineClass *m)
428 428
     machine_class_allow_dynamic_sysbus_dev(m, TYPE_RAMFB_DEVICE);
429 429
 }
430 430
 
431
-static void pc_i440fx_4_0_machine_options(MachineClass *m)
431
+static void pc_i440fx_4_1_machine_options(MachineClass *m)
432 432
 {
433 433
     pc_i440fx_machine_options(m);
434 434
     m->alias = "pc";
435 435
     m->is_default = 1;
436 436
 }
437 437
 
438
+DEFINE_I440FX_MACHINE(v4_1, "pc-i440fx-4.1", NULL,
439
+                      pc_i440fx_4_1_machine_options);
440
+
441
+static void pc_i440fx_4_0_machine_options(MachineClass *m)
442
+{
443
+    pc_i440fx_4_1_machine_options(m);
444
+    m->alias = NULL;
445
+    m->is_default = 0;
446
+    compat_props_add(m->compat_props, hw_compat_4_0, hw_compat_4_0_len);
447
+    compat_props_add(m->compat_props, pc_compat_4_0, pc_compat_4_0_len);
448
+}
449
+
438 450
 DEFINE_I440FX_MACHINE(v4_0, "pc-i440fx-4.0", NULL,
439 451
                       pc_i440fx_4_0_machine_options);
440 452
 

+ 12
- 1
hw/i386/pc_q35.c View File

@@ -365,12 +365,23 @@ static void pc_q35_machine_options(MachineClass *m)
365 365
     m->max_cpus = 288;
366 366
 }
367 367
 
368
-static void pc_q35_4_0_machine_options(MachineClass *m)
368
+static void pc_q35_4_1_machine_options(MachineClass *m)
369 369
 {
370 370
     pc_q35_machine_options(m);
371 371
     m->alias = "q35";
372 372
 }
373 373
 
374
+DEFINE_Q35_MACHINE(v4_1, "pc-q35-4.1", NULL,
375
+                   pc_q35_4_1_machine_options);
376
+
377
+static void pc_q35_4_0_machine_options(MachineClass *m)
378
+{
379
+    pc_q35_4_1_machine_options(m);
380
+    m->alias = NULL;
381
+    compat_props_add(m->compat_props, hw_compat_4_0, hw_compat_4_0_len);
382
+    compat_props_add(m->compat_props, pc_compat_4_0, pc_compat_4_0_len);
383
+}
384
+
374 385
 DEFINE_Q35_MACHINE(v4_0, "pc-q35-4.0", NULL,
375 386
                    pc_q35_4_0_machine_options);
376 387
 

+ 13
- 2
hw/ppc/spapr.c View File

@@ -4344,15 +4344,26 @@ static const TypeInfo spapr_machine_info = {
4344 4344
     }                                                                \
4345 4345
     type_init(spapr_machine_register_##suffix)
4346 4346
 
4347
+/*
4348
+ * pseries-4.1
4349
+ */
4350
+static void spapr_machine_4_1_class_options(MachineClass *mc)
4351
+{
4352
+    /* Defaults for the latest behaviour inherited from the base class */
4353
+}
4354
+
4355
+DEFINE_SPAPR_MACHINE(4_1, "4.1", true);
4356
+
4347 4357
 /*
4348 4358
  * pseries-4.0
4349 4359
  */
4350 4360
 static void spapr_machine_4_0_class_options(MachineClass *mc)
4351 4361
 {
4352
-    /* Defaults for the latest behaviour inherited from the base class */
4362
+    spapr_machine_4_1_class_options(mc);
4363
+    compat_props_add(mc->compat_props, hw_compat_4_0, hw_compat_4_0_len);
4353 4364
 }
4354 4365
 
4355
-DEFINE_SPAPR_MACHINE(4_0, "4.0", true);
4366
+DEFINE_SPAPR_MACHINE(4_0, "4.0", false);
4356 4367
 
4357 4368
 /*
4358 4369
  * pseries-3.1

+ 13
- 1
hw/s390x/s390-virtio-ccw.c View File

@@ -658,14 +658,26 @@ bool css_migration_enabled(void)
658 658
     }                                                                         \
659 659
     type_init(ccw_machine_register_##suffix)
660 660
 
661
+static void ccw_machine_4_1_instance_options(MachineState *machine)
662
+{
663
+}
664
+
665
+static void ccw_machine_4_1_class_options(MachineClass *mc)
666
+{
667
+}
668
+DEFINE_CCW_MACHINE(4_1, "4.1", true);
669
+
661 670
 static void ccw_machine_4_0_instance_options(MachineState *machine)
662 671
 {
672
+    ccw_machine_4_1_instance_options(machine);
663 673
 }
664 674
 
665 675
 static void ccw_machine_4_0_class_options(MachineClass *mc)
666 676
 {
677
+    ccw_machine_4_1_class_options(mc);
678
+    compat_props_add(mc->compat_props, hw_compat_4_0, hw_compat_4_0_len);
667 679
 }
668
-DEFINE_CCW_MACHINE(4_0, "4.0", true);
680
+DEFINE_CCW_MACHINE(4_0, "4.0", false);
669 681
 
670 682
 static void ccw_machine_3_1_instance_options(MachineState *machine)
671 683
 {

+ 3
- 1
include/hw/boards.h View File

@@ -57,7 +57,6 @@ void memory_region_allocate_system_memory(MemoryRegion *mr, Object *owner,
57 57
 #define MACHINE_CLASS(klass) \
58 58
     OBJECT_CLASS_CHECK(MachineClass, (klass), TYPE_MACHINE)
59 59
 
60
-MachineClass *find_default_machine(void);
61 60
 extern MachineState *current_machine;
62 61
 
63 62
 void machine_run_board_init(MachineState *machine);
@@ -293,6 +292,9 @@ struct MachineState {
293 292
     } \
294 293
     type_init(machine_initfn##_register_types)
295 294
 
295
+extern GlobalProperty hw_compat_4_0[];
296
+extern const size_t hw_compat_4_0_len;
297
+
296 298
 extern GlobalProperty hw_compat_3_1[];
297 299
 extern const size_t hw_compat_3_1_len;
298 300
 

+ 3
- 0
include/hw/i386/pc.h View File

@@ -293,6 +293,9 @@ int e820_add_entry(uint64_t, uint64_t, uint32_t);
293 293
 int e820_get_num_entries(void);
294 294
 bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *);
295 295
 
296
+extern GlobalProperty pc_compat_4_0[];
297
+extern const size_t pc_compat_4_0_len;
298
+
296 299
 extern GlobalProperty pc_compat_3_1[];
297 300
 extern const size_t pc_compat_3_1_len;
298 301
 

+ 20
- 1
include/qemu/mmap-alloc.h View File

@@ -7,7 +7,26 @@ size_t qemu_fd_getpagesize(int fd);
7 7
 
8 8
 size_t qemu_mempath_getpagesize(const char *mem_path);
9 9
 
10
-void *qemu_ram_mmap(int fd, size_t size, size_t align, bool shared);
10
+/**
11
+ * qemu_ram_mmap: mmap the specified file or device.
12
+ *
13
+ * Parameters:
14
+ *  @fd: the file or the device to mmap
15
+ *  @size: the number of bytes to be mmaped
16
+ *  @align: if not zero, specify the alignment of the starting mapping address;
17
+ *          otherwise, the alignment in use will be determined by QEMU.
18
+ *  @shared: map has RAM_SHARED flag.
19
+ *  @is_pmem: map has RAM_PMEM flag.
20
+ *
21
+ * Return:
22
+ *  On success, return a pointer to the mapped area.
23
+ *  On failure, return MAP_FAILED.
24
+ */
25
+void *qemu_ram_mmap(int fd,
26
+                    size_t size,
27
+                    size_t align,
28
+                    bool shared,
29
+                    bool is_pmem);
11 30
 
12 31
 void qemu_ram_munmap(int fd, void *ptr, size_t size);
13 32
 

+ 3
- 3
include/qom/cpu.h View File

@@ -681,15 +681,15 @@ ObjectClass *cpu_class_by_name(const char *typename, const char *cpu_model);
681 681
 CPUState *cpu_create(const char *typename);
682 682
 
683 683
 /**
684
- * parse_cpu_model:
685
- * @cpu_model: The model string including optional parameters.
684
+ * parse_cpu_option:
685
+ * @cpu_option: The -cpu option including optional parameters.
686 686
  *
687 687
  * processes optional parameters and registers them as global properties
688 688
  *
689 689
  * Returns: type of CPU to create or prints error and terminates process
690 690
  *          if an error occurred.
691 691
  */
692
-const char *parse_cpu_model(const char *cpu_model);
692
+const char *parse_cpu_option(const char *cpu_option);
693 693
 
694 694
 /**
695 695
  * cpu_has_work:

+ 4
- 0
linux-headers/asm-arm/mman.h View File

@@ -0,0 +1,4 @@
1
+#include <asm-generic/mman.h>
2
+
3
+#define arch_mmap_check(addr, len, flags) \
4
+	(((flags) & MAP_FIXED && (addr) < FIRST_USER_ADDRESS) ? -EINVAL : 0)

+ 1
- 0
linux-headers/asm-arm64/mman.h View File

@@ -0,0 +1 @@
1
+#include <asm-generic/mman.h>

+ 36
- 0
linux-headers/asm-generic/hugetlb_encode.h View File

@@ -0,0 +1,36 @@
1
+#ifndef _ASM_GENERIC_HUGETLB_ENCODE_H_
2
+#define _ASM_GENERIC_HUGETLB_ENCODE_H_
3
+
4
+/*
5
+ * Several system calls take a flag to request "hugetlb" huge pages.
6
+ * Without further specification, these system calls will use the
7
+ * system's default huge page size.  If a system supports multiple
8
+ * huge page sizes, the desired huge page size can be specified in
9
+ * bits [26:31] of the flag arguments.  The value in these 6 bits
10
+ * will encode the log2 of the huge page size.
11
+ *
12
+ * The following definitions are associated with this huge page size
13
+ * encoding in flag arguments.  System call specific header files
14
+ * that use this encoding should include this file.  They can then
15
+ * provide definitions based on these with their own specific prefix.
16
+ * for example:
17
+ * #define MAP_HUGE_SHIFT HUGETLB_FLAG_ENCODE_SHIFT
18
+ */
19
+
20
+#define HUGETLB_FLAG_ENCODE_SHIFT	26
21
+#define HUGETLB_FLAG_ENCODE_MASK	0x3f
22
+
23
+#define HUGETLB_FLAG_ENCODE_64KB	(16 << HUGETLB_FLAG_ENCODE_SHIFT)
24
+#define HUGETLB_FLAG_ENCODE_512KB	(19 << HUGETLB_FLAG_ENCODE_SHIFT)
25
+#define HUGETLB_FLAG_ENCODE_1MB		(20 << HUGETLB_FLAG_ENCODE_SHIFT)
26
+#define HUGETLB_FLAG_ENCODE_2MB		(21 << HUGETLB_FLAG_ENCODE_SHIFT)
27
+#define HUGETLB_FLAG_ENCODE_8MB		(23 << HUGETLB_FLAG_ENCODE_SHIFT)
28
+#define HUGETLB_FLAG_ENCODE_16MB	(24 << HUGETLB_FLAG_ENCODE_SHIFT)
29
+#define HUGETLB_FLAG_ENCODE_32MB	(25 << HUGETLB_FLAG_ENCODE_SHIFT)
30
+#define HUGETLB_FLAG_ENCODE_256MB	(28 << HUGETLB_FLAG_ENCODE_SHIFT)
31
+#define HUGETLB_FLAG_ENCODE_512MB	(29 << HUGETLB_FLAG_ENCODE_SHIFT)
32
+#define HUGETLB_FLAG_ENCODE_1GB		(30 << HUGETLB_FLAG_ENCODE_SHIFT)
33
+#define HUGETLB_FLAG_ENCODE_2GB		(31 << HUGETLB_FLAG_ENCODE_SHIFT)
34
+#define HUGETLB_FLAG_ENCODE_16GB	(34 << HUGETLB_FLAG_ENCODE_SHIFT)
35
+
36
+#endif /* _ASM_GENERIC_HUGETLB_ENCODE_H_ */

+ 77
- 0
linux-headers/asm-generic/mman-common.h View File

@@ -0,0 +1,77 @@
1
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2
+#ifndef __ASM_GENERIC_MMAN_COMMON_H
3
+#define __ASM_GENERIC_MMAN_COMMON_H
4
+
5
+/*
6
+ Author: Michael S. Tsirkin <mst@mellanox.co.il>, Mellanox Technologies Ltd.
7
+ Based on: asm-xxx/mman.h
8
+*/
9
+
10
+#define PROT_READ	0x1		/* page can be read */
11
+#define PROT_WRITE	0x2		/* page can be written */
12
+#define PROT_EXEC	0x4		/* page can be executed */
13
+#define PROT_SEM	0x8		/* page may be used for atomic ops */
14
+#define PROT_NONE	0x0		/* page can not be accessed */
15
+#define PROT_GROWSDOWN	0x01000000	/* mprotect flag: extend change to start of growsdown vma */
16
+#define PROT_GROWSUP	0x02000000	/* mprotect flag: extend change to end of growsup vma */
17
+
18
+#define MAP_SHARED	0x01		/* Share changes */
19
+#define MAP_PRIVATE	0x02		/* Changes are private */
20
+#define MAP_SHARED_VALIDATE 0x03	/* share + validate extension flags */
21
+#define MAP_TYPE	0x0f		/* Mask for type of mapping */
22
+#define MAP_FIXED	0x10		/* Interpret addr exactly */
23
+#define MAP_ANONYMOUS	0x20		/* don't use a file */
24
+#ifdef CONFIG_MMAP_ALLOW_UNINITIALIZED
25
+# define MAP_UNINITIALIZED 0x4000000	/* For anonymous mmap, memory could be uninitialized */
26
+#else
27
+# define MAP_UNINITIALIZED 0x0		/* Don't support this flag */
28
+#endif
29
+
30
+/* 0x0100 - 0x80000 flags are defined in asm-generic/mman.h */
31
+#define MAP_FIXED_NOREPLACE	0x100000	/* MAP_FIXED which doesn't unmap underlying mapping */
32
+
33
+/*
34
+ * Flags for mlock
35
+ */
36
+#define MLOCK_ONFAULT	0x01		/* Lock pages in range after they are faulted in, do not prefault */
37
+
38
+#define MS_ASYNC	1		/* sync memory asynchronously */
39
+#define MS_INVALIDATE	2		/* invalidate the caches */
40
+#define MS_SYNC		4		/* synchronous memory sync */
41
+
42
+#define MADV_NORMAL	0		/* no further special treatment */
43
+#define MADV_RANDOM	1		/* expect random page references */
44
+#define MADV_SEQUENTIAL	2		/* expect sequential page references */
45
+#define MADV_WILLNEED	3		/* will need these pages */
46
+#define MADV_DONTNEED	4		/* don't need these pages */
47
+
48
+/* common parameters: try to keep these consistent across architectures */
49
+#define MADV_FREE	8		/* free pages only if memory pressure */
50
+#define MADV_REMOVE	9		/* remove these pages & resources */
51
+#define MADV_DONTFORK	10		/* don't inherit across fork */
52
+#define MADV_DOFORK	11		/* do inherit across fork */
53
+#define MADV_HWPOISON	100		/* poison a page for testing */
54
+#define MADV_SOFT_OFFLINE 101		/* soft offline page for testing */
55
+
56
+#define MADV_MERGEABLE   12		/* KSM may merge identical pages */
57
+#define MADV_UNMERGEABLE 13		/* KSM may not merge identical pages */
58
+
59
+#define MADV_HUGEPAGE	14		/* Worth backing with hugepages */
60
+#define MADV_NOHUGEPAGE	15		/* Not worth backing with hugepages */
61
+
62
+#define MADV_DONTDUMP   16		/* Explicity exclude from the core dump,
63
+					   overrides the coredump filter bits */
64
+#define MADV_DODUMP	17		/* Clear the MADV_DONTDUMP flag */
65
+
66
+#define MADV_WIPEONFORK 18		/* Zero memory on fork, child only */
67
+#define MADV_KEEPONFORK 19		/* Undo MADV_WIPEONFORK */
68
+
69
+/* compatibility flags */
70
+#define MAP_FILE	0
71
+
72
+#define PKEY_DISABLE_ACCESS	0x1
73
+#define PKEY_DISABLE_WRITE	0x2
74
+#define PKEY_ACCESS_MASK	(PKEY_DISABLE_ACCESS |\
75
+				 PKEY_DISABLE_WRITE)
76
+
77
+#endif /* __ASM_GENERIC_MMAN_COMMON_H */

+ 24
- 0
linux-headers/asm-generic/mman.h View File

@@ -0,0 +1,24 @@
1
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2
+#ifndef __ASM_GENERIC_MMAN_H
3
+#define __ASM_GENERIC_MMAN_H
4
+
5
+#include <asm-generic/mman-common.h>
6
+
7
+#define MAP_GROWSDOWN	0x0100		/* stack-like segment */
8
+#define MAP_DENYWRITE	0x0800		/* ETXTBSY */
9
+#define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
10
+#define MAP_LOCKED	0x2000		/* pages are locked */
11
+#define MAP_NORESERVE	0x4000		/* don't check for reservations */
12
+#define MAP_POPULATE	0x8000		/* populate (prefault) pagetables */
13
+#define MAP_NONBLOCK	0x10000		/* do not block on IO */
14
+#define MAP_STACK	0x20000		/* give out an address that is best suited for process/thread stacks */
15
+#define MAP_HUGETLB	0x40000		/* create a huge page mapping */
16
+#define MAP_SYNC	0x80000		/* perform synchronous page faults for the mapping */
17
+
18
+/* Bits [26:31] are reserved, see mman-common.h for MAP_HUGETLB usage */
19
+
20
+#define MCL_CURRENT	1		/* lock all current mappings */
21
+#define MCL_FUTURE	2		/* lock all future mappings */
22
+#define MCL_ONFAULT	4		/* lock all pages that are faulted in */
23
+
24
+#endif /* __ASM_GENERIC_MMAN_H */

+ 108
- 0
linux-headers/asm-mips/mman.h View File

@@ -0,0 +1,108 @@
1
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2
+/*
3
+ * This file is subject to the terms and conditions of the GNU General Public
4
+ * License.  See the file "COPYING" in the main directory of this archive
5
+ * for more details.
6
+ *
7
+ * Copyright (C) 1995, 1999, 2002 by Ralf Baechle
8
+ */
9
+#ifndef _ASM_MMAN_H
10
+#define _ASM_MMAN_H
11
+
12
+/*
13
+ * Protections are chosen from these bits, OR'd together.  The
14
+ * implementation does not necessarily support PROT_EXEC or PROT_WRITE
15
+ * without PROT_READ.  The only guarantees are that no writing will be
16
+ * allowed without PROT_WRITE and no access will be allowed for PROT_NONE.
17
+ */
18
+#define PROT_NONE	0x00		/* page can not be accessed */
19
+#define PROT_READ	0x01		/* page can be read */
20
+#define PROT_WRITE	0x02		/* page can be written */
21
+#define PROT_EXEC	0x04		/* page can be executed */
22
+/*			0x08		   reserved for PROT_EXEC_NOFLUSH */
23
+#define PROT_SEM	0x10		/* page may be used for atomic ops */
24
+#define PROT_GROWSDOWN	0x01000000	/* mprotect flag: extend change to start of growsdown vma */
25
+#define PROT_GROWSUP	0x02000000	/* mprotect flag: extend change to end of growsup vma */
26
+
27
+/*
28
+ * Flags for mmap
29
+ */
30
+#define MAP_SHARED	0x001		/* Share changes */
31
+#define MAP_PRIVATE	0x002		/* Changes are private */
32
+#define MAP_SHARED_VALIDATE 0x003	/* share + validate extension flags */
33
+#define MAP_TYPE	0x00f		/* Mask for type of mapping */
34
+#define MAP_FIXED	0x010		/* Interpret addr exactly */
35
+
36
+/* not used by linux, but here to make sure we don't clash with ABI defines */
37
+#define MAP_RENAME	0x020		/* Assign page to file */
38
+#define MAP_AUTOGROW	0x040		/* File may grow by writing */
39
+#define MAP_LOCAL	0x080		/* Copy on fork/sproc */
40
+#define MAP_AUTORSRV	0x100		/* Logical swap reserved on demand */
41
+
42
+/* These are linux-specific */
43
+#define MAP_NORESERVE	0x0400		/* don't check for reservations */
44
+#define MAP_ANONYMOUS	0x0800		/* don't use a file */
45
+#define MAP_GROWSDOWN	0x1000		/* stack-like segment */
46
+#define MAP_DENYWRITE	0x2000		/* ETXTBSY */
47
+#define MAP_EXECUTABLE	0x4000		/* mark it as an executable */
48
+#define MAP_LOCKED	0x8000		/* pages are locked */
49
+#define MAP_POPULATE	0x10000		/* populate (prefault) pagetables */
50
+#define MAP_NONBLOCK	0x20000		/* do not block on IO */
51
+#define MAP_STACK	0x40000		/* give out an address that is best suited for process/thread stacks */
52
+#define MAP_HUGETLB	0x80000		/* create a huge page mapping */
53
+#define MAP_FIXED_NOREPLACE 0x100000	/* MAP_FIXED which doesn't unmap underlying mapping */
54
+
55
+/*
56
+ * Flags for msync
57
+ */
58
+#define MS_ASYNC	0x0001		/* sync memory asynchronously */
59
+#define MS_INVALIDATE	0x0002		/* invalidate mappings & caches */
60
+#define MS_SYNC		0x0004		/* synchronous memory sync */
61
+
62
+/*
63
+ * Flags for mlockall
64
+ */
65
+#define MCL_CURRENT	1		/* lock all current mappings */
66
+#define MCL_FUTURE	2		/* lock all future mappings */
67
+#define MCL_ONFAULT	4		/* lock all pages that are faulted in */
68
+
69
+/*
70
+ * Flags for mlock
71
+ */
72
+#define MLOCK_ONFAULT	0x01		/* Lock pages in range after they are faulted in, do not prefault */
73
+
74
+#define MADV_NORMAL	0		/* no further special treatment */
75
+#define MADV_RANDOM	1		/* expect random page references */
76
+#define MADV_SEQUENTIAL 2		/* expect sequential page references */
77
+#define MADV_WILLNEED	3		/* will need these pages */
78
+#define MADV_DONTNEED	4		/* don't need these pages */
79
+
80
+/* common parameters: try to keep these consistent across architectures */
81
+#define MADV_FREE	8		/* free pages only if memory pressure */
82
+#define MADV_REMOVE	9		/* remove these pages & resources */
83
+#define MADV_DONTFORK	10		/* don't inherit across fork */
84
+#define MADV_DOFORK	11		/* do inherit across fork */
85
+
86
+#define MADV_MERGEABLE	 12		/* KSM may merge identical pages */
87
+#define MADV_UNMERGEABLE 13		/* KSM may not merge identical pages */
88
+#define MADV_HWPOISON	 100		/* poison a page for testing */
89
+
90
+#define MADV_HUGEPAGE	14		/* Worth backing with hugepages */
91
+#define MADV_NOHUGEPAGE 15		/* Not worth backing with hugepages */
92
+
93
+#define MADV_DONTDUMP	16		/* Explicity exclude from the core dump,
94
+					   overrides the coredump filter bits */
95
+#define MADV_DODUMP	17		/* Clear the MADV_NODUMP flag */
96
+
97
+#define MADV_WIPEONFORK 18		/* Zero memory on fork, child only */
98
+#define MADV_KEEPONFORK 19		/* Undo MADV_WIPEONFORK */
99
+
100
+/* compatibility flags */
101
+#define MAP_FILE	0
102
+
103
+#define PKEY_DISABLE_ACCESS	0x1
104
+#define PKEY_DISABLE_WRITE	0x2
105
+#define PKEY_ACCESS_MASK	(PKEY_DISABLE_ACCESS |\
106
+				 PKEY_DISABLE_WRITE)
107
+
108
+#endif /* _ASM_MMAN_H */

+ 39
- 0
linux-headers/asm-powerpc/mman.h View File

@@ -0,0 +1,39 @@
1
+/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
2
+/*
3
+ * This program is free software; you can redistribute it and/or
4
+ * modify it under the terms of the GNU General Public License
5
+ * as published by the Free Software Foundation; either version
6
+ * 2 of the License, or (at your option) any later version.
7
+ */
8
+#ifndef _ASM_POWERPC_MMAN_H
9
+#define _ASM_POWERPC_MMAN_H
10
+
11
+#include <asm-generic/mman-common.h>
12
+
13
+
14
+#define PROT_SAO	0x10		/* Strong Access Ordering */
15
+
16
+#define MAP_RENAME      MAP_ANONYMOUS   /* In SunOS terminology */
17
+#define MAP_NORESERVE   0x40            /* don't reserve swap pages */
18
+#define MAP_LOCKED	0x80
19
+
20
+#define MAP_GROWSDOWN	0x0100		/* stack-like segment */
21
+#define MAP_DENYWRITE	0x0800		/* ETXTBSY */
22
+#define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
23
+
24
+#define MCL_CURRENT     0x2000          /* lock all currently mapped pages */
25
+#define MCL_FUTURE      0x4000          /* lock all additions to address space */
26
+#define MCL_ONFAULT	0x8000		/* lock all pages that are faulted in */
27
+
28
+#define MAP_POPULATE	0x8000		/* populate (prefault) pagetables */
29
+#define MAP_NONBLOCK	0x10000		/* do not block on IO */
30
+#define MAP_STACK	0x20000		/* give out an address that is best suited for process/thread stacks */
31
+#define MAP_HUGETLB	0x40000		/* create a huge page mapping */
32
+
33
+/* Override any generic PKEY permission defines */
34
+#define PKEY_DISABLE_EXECUTE   0x4
35
+#undef PKEY_ACCESS_MASK
36
+#define PKEY_ACCESS_MASK       (PKEY_DISABLE_ACCESS |\
37
+				PKEY_DISABLE_WRITE  |\
38
+				PKEY_DISABLE_EXECUTE)
39
+#endif /* _ASM_POWERPC_MMAN_H */

+ 1
- 0
linux-headers/asm-s390/mman.h View File

@@ -0,0 +1 @@
1
+#include <asm-generic/mman.h>

+ 31
- 0
linux-headers/asm-x86/mman.h View File

@@ -0,0 +1,31 @@
1
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2
+#ifndef _ASM_X86_MMAN_H
3
+#define _ASM_X86_MMAN_H
4
+
5
+#define MAP_32BIT	0x40		/* only give out 32bit addresses */
6
+
7
+#ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS
8
+/*
9
+ * Take the 4 protection key bits out of the vma->vm_flags
10
+ * value and turn them in to the bits that we can put in
11
+ * to a pte.
12
+ *
13
+ * Only override these if Protection Keys are available
14
+ * (which is only on 64-bit).
15
+ */
16
+#define arch_vm_get_page_prot(vm_flags)	__pgprot(	\
17
+		((vm_flags) & VM_PKEY_BIT0 ? _PAGE_PKEY_BIT0 : 0) |	\
18
+		((vm_flags) & VM_PKEY_BIT1 ? _PAGE_PKEY_BIT1 : 0) |	\
19
+		((vm_flags) & VM_PKEY_BIT2 ? _PAGE_PKEY_BIT2 : 0) |	\
20
+		((vm_flags) & VM_PKEY_BIT3 ? _PAGE_PKEY_BIT3 : 0))
21
+
22
+#define arch_calc_vm_prot_bits(prot, key) (		\
23
+		((key) & 0x1 ? VM_PKEY_BIT0 : 0) |      \
24
+		((key) & 0x2 ? VM_PKEY_BIT1 : 0) |      \
25
+		((key) & 0x4 ? VM_PKEY_BIT2 : 0) |      \
26
+		((key) & 0x8 ? VM_PKEY_BIT3 : 0))
27
+#endif
28
+
29
+#include <asm-generic/mman.h>
30
+
31
+#endif /* _ASM_X86_MMAN_H */

+ 38
- 0
linux-headers/linux/mman.h View File

@@ -0,0 +1,38 @@
1
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2
+#ifndef _LINUX_MMAN_H
3
+#define _LINUX_MMAN_H
4
+
5
+#include <asm/mman.h>
6
+#include <asm-generic/hugetlb_encode.h>
7
+
8
+#define MREMAP_MAYMOVE	1
9
+#define MREMAP_FIXED	2
10
+
11
+#define OVERCOMMIT_GUESS		0
12
+#define OVERCOMMIT_ALWAYS		1
13
+#define OVERCOMMIT_NEVER		2
14
+
15
+/*
16
+ * Huge page size encoding when MAP_HUGETLB is specified, and a huge page
17
+ * size other than the default is desired.  See hugetlb_encode.h.
18
+ * All known huge page size encodings are provided here.  It is the
19
+ * responsibility of the application to know which sizes are supported on
20
+ * the running system.  See mmap(2) man page for details.
21
+ */
22
+#define MAP_HUGE_SHIFT	HUGETLB_FLAG_ENCODE_SHIFT
23
+#define MAP_HUGE_MASK	HUGETLB_FLAG_ENCODE_MASK
24
+
25
+#define MAP_HUGE_64KB	HUGETLB_FLAG_ENCODE_64KB
26
+#define MAP_HUGE_512KB	HUGETLB_FLAG_ENCODE_512KB
27
+#define MAP_HUGE_1MB	HUGETLB_FLAG_ENCODE_1MB
28
+#define MAP_HUGE_2MB	HUGETLB_FLAG_ENCODE_2MB
29
+#define MAP_HUGE_8MB	HUGETLB_FLAG_ENCODE_8MB
30
+#define MAP_HUGE_16MB	HUGETLB_FLAG_ENCODE_16MB
31
+#define MAP_HUGE_32MB	HUGETLB_FLAG_ENCODE_32MB
32
+#define MAP_HUGE_256MB	HUGETLB_FLAG_ENCODE_256MB
33
+#define MAP_HUGE_512MB	HUGETLB_FLAG_ENCODE_512MB
34
+#define MAP_HUGE_1GB	HUGETLB_FLAG_ENCODE_1GB
35
+#define MAP_HUGE_2GB	HUGETLB_FLAG_ENCODE_2GB
36
+#define MAP_HUGE_16GB	HUGETLB_FLAG_ENCODE_16GB
37
+
38
+#endif /* _LINUX_MMAN_H */

+ 1
- 1
linux-user/main.c View File

@@ -662,7 +662,7 @@ int main(int argc, char **argv, char **envp)
662 662
     if (cpu_model == NULL) {
663 663
         cpu_model = cpu_get_model(get_elf_eflags(execfd));
664 664
     }
665
-    cpu_type = parse_cpu_model(cpu_model);
665
+    cpu_type = parse_cpu_option(cpu_model);
666 666
 
667 667
     /* init tcg before creating CPUs and to get qemu_host_page_size */
668 668
     tcg_exec_init(0);

+ 5
- 0
qemu-options.hx View File

@@ -4233,6 +4233,11 @@ using the SNIA NVM programming model (e.g. Intel NVDIMM).
4233 4233
 If @option{pmem} is set to 'on', QEMU will take necessary operations to
4234 4234
 guarantee the persistence of its own writes to @option{mem-path}
4235 4235
 (e.g. in vNVDIMM label emulation and live migration).
4236
+Also, we will map the backend-file with MAP_SYNC flag, which ensures the
4237
+file metadata is in sync for @option{mem-path} in case of host crash
4238
+or a power failure. MAP_SYNC requires support from both the host kernel
4239
+(since Linux kernel 4.15) and the filesystem of @option{mem-path} mounted
4240
+with DAX option.
4236 4241
 
4237 4242
 @item -object memory-backend-ram,id=@var{id},merge=@var{on|off},dump=@var{on|off},share=@var{on|off},prealloc=@var{on|off},size=@var{size},host-nodes=@var{host-nodes},policy=@var{default|preferred|bind|interleave}
4238 4243
 

+ 3
- 3
scripts/update-linux-headers.sh View File

@@ -95,7 +95,7 @@ for arch in $ARCHLIST; do
95 95
 
96 96
     rm -rf "$output/linux-headers/asm-$arch"
97 97
     mkdir -p "$output/linux-headers/asm-$arch"
98
-    for header in kvm.h unistd.h bitsperlong.h; do
98
+    for header in kvm.h unistd.h bitsperlong.h mman.h; do
99 99
         cp "$tmpdir/include/asm/$header" "$output/linux-headers/asm-$arch"
100 100
     done
101 101
 
@@ -139,13 +139,13 @@ done
139 139
 rm -rf "$output/linux-headers/linux"
140 140
 mkdir -p "$output/linux-headers/linux"
141 141
 for header in kvm.h vfio.h vfio_ccw.h vhost.h \
142
-              psci.h psp-sev.h userfaultfd.h; do
142
+              psci.h psp-sev.h userfaultfd.h mman.h; do
143 143
     cp "$tmpdir/include/linux/$header" "$output/linux-headers/linux"
144 144
 done
145 145
 
146 146
 rm -rf "$output/linux-headers/asm-generic"
147 147
 mkdir -p "$output/linux-headers/asm-generic"
148
-for header in unistd.h bitsperlong.h; do
148
+for header in unistd.h bitsperlong.h mman-common.h mman.h hugetlb_encode.h; do
149 149
     cp "$tmpdir/include/asm-generic/$header" "$output/linux-headers/asm-generic"
150 150
 done
151 151
 

+ 19
- 0
tests/acceptance/empty_cpu_model.py View File

@@ -0,0 +1,19 @@
1
+# Check for crash when using empty -cpu option
2
+#
3
+# Copyright (c) 2019 Red Hat, Inc.
4
+#
5
+# Author:
6
+#  Eduardo Habkost <ehabkost@redhat.com>
7
+#
8
+# This work is licensed under the terms of the GNU GPL, version 2 or
9
+# later.  See the COPYING file in the top-level directory.
10
+import subprocess
11
+from avocado_qemu import Test
12
+
13
+class EmptyCPUModel(Test):
14
+    def test(self):
15
+        cmd = [self.qemu_bin, '-S', '-display', 'none', '-machine', 'none', '-cpu', '']
16
+        r = subprocess.run(cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
17
+        self.assertEquals(r.returncode, 1, "QEMU exit code should be 1")
18
+        self.assertEquals(r.stdout, b'', "QEMU stdout should be empty")
19
+        self.assertNotEquals(r.stderr, b'', "QEMU stderr shouldn't be empty")

+ 45
- 2
util/mmap-alloc.c View File

@@ -10,6 +10,13 @@
10 10
  * later.  See the COPYING file in the top-level directory.
11 11
  */
12 12
 
13
+#ifdef CONFIG_LINUX
14
+#include <linux/mman.h>
15
+#else  /* !CONFIG_LINUX */
16
+#define MAP_SYNC              0x0
17
+#define MAP_SHARED_VALIDATE   0x0
18
+#endif /* CONFIG_LINUX */
19
+
13 20
 #include "qemu/osdep.h"
14 21
 #include "qemu/mmap-alloc.h"
15 22
 #include "qemu/host-utils.h"
@@ -75,9 +82,14 @@ size_t qemu_mempath_getpagesize(const char *mem_path)
75 82
     return getpagesize();
76 83
 }
77 84
 
78
-void *qemu_ram_mmap(int fd, size_t size, size_t align, bool shared)
85
+void *qemu_ram_mmap(int fd,
86
+                    size_t size,
87
+                    size_t align,
88
+                    bool shared,
89
+                    bool is_pmem)
79 90
 {
80 91
     int flags;
92
+    int map_sync_flags = 0;
81 93
     int guardfd;
82 94
     size_t offset;
83 95
     size_t pagesize;
@@ -128,9 +140,40 @@ void *qemu_ram_mmap(int fd, size_t size, size_t align, bool shared)
128 140
     flags = MAP_FIXED;
129 141
     flags |= fd == -1 ? MAP_ANONYMOUS : 0;
130 142
     flags |= shared ? MAP_SHARED : MAP_PRIVATE;
143
+    if (shared && is_pmem) {
144
+        map_sync_flags = MAP_SYNC | MAP_SHARED_VALIDATE;
145
+    }
146
+
131 147
     offset = QEMU_ALIGN_UP((uintptr_t)guardptr, align) - (uintptr_t)guardptr;
132 148
 
133
-    ptr = mmap(guardptr + offset, size, PROT_READ | PROT_WRITE, flags, fd, 0);
149
+    ptr = mmap(guardptr + offset, size, PROT_READ | PROT_WRITE,
150
+               flags | map_sync_flags, fd, 0);
151
+
152
+    if (ptr == MAP_FAILED && map_sync_flags) {
153
+        if (errno == ENOTSUP) {
154
+            char *proc_link, *file_name;
155
+            int len;
156
+            proc_link = g_strdup_printf("/proc/self/fd/%d", fd);
157
+            file_name = g_malloc0(PATH_MAX);
158
+            len = readlink(proc_link, file_name, PATH_MAX - 1);
159
+            if (len < 0) {
160
+                len = 0;
161
+            }
162
+            file_name[len] = '\0';
163
+            fprintf(stderr, "Warning: requesting persistence across crashes "
164
+                    "for backend file %s failed. Proceeding without "
165
+                    "persistence, data might become corrupted in case of host "
166
+                    "crash.\n", file_name);
167
+            g_free(proc_link);
168
+            g_free(file_name);
169
+        }
170
+        /*
171
+         * if map failed with MAP_SHARED_VALIDATE | MAP_SYNC,
172
+         * we will remove these flags to handle compatibility.
173
+         */
174
+        ptr = mmap(guardptr + offset, size, PROT_READ | PROT_WRITE,
175
+                   flags, fd, 0);
176
+    }
134 177
 
135 178
     if (ptr == MAP_FAILED) {
136 179
         munmap(guardptr, total);

+ 1
- 1
util/oslib-posix.c View File

@@ -203,7 +203,7 @@ void *qemu_memalign(size_t alignment, size_t size)
203 203
 void *qemu_anon_ram_alloc(size_t size, uint64_t *alignment, bool shared)
204 204
 {
205 205
     size_t align = QEMU_VMALLOC_ALIGN;
206
-    void *ptr = qemu_ram_mmap(-1, size, align, shared);
206
+    void *ptr = qemu_ram_mmap(-1, size, align, shared, false);
207 207
 
208 208
     if (ptr == MAP_FAILED) {
209 209
         return NULL;

+ 37
- 50
vl.c View File

@@ -1465,45 +1465,34 @@ static int usb_parse(const char *cmdline)
1465 1465
 
1466 1466
 MachineState *current_machine;
1467 1467
 
1468
-static MachineClass *find_machine(const char *name)
1468
+static MachineClass *find_machine(const char *name, GSList *machines)
1469 1469
 {
1470
-    GSList *el, *machines = object_class_get_list(TYPE_MACHINE, false);
1471
-    MachineClass *mc = NULL;
1470
+    GSList *el;
1472 1471
 
1473 1472
     for (el = machines; el; el = el->next) {
1474
-        MachineClass *temp = el->data;
1473
+        MachineClass *mc = el->data;
1475 1474
 
1476
-        if (!strcmp(temp->name, name)) {
1477
-            mc = temp;
1478
-            break;
1479
-        }
1480
-        if (temp->alias &&
1481
-            !strcmp(temp->alias, name)) {
1482
-            mc = temp;
1483
-            break;
1475
+        if (!strcmp(mc->name, name) || !g_strcmp0(mc->alias, name)) {
1476
+            return mc;
1484 1477
         }
1485 1478
     }
1486 1479
 
1487
-    g_slist_free(machines);
1488
-    return mc;
1480
+    return NULL;
1489 1481
 }
1490 1482
 
1491
-MachineClass *find_default_machine(void)
1483
+static MachineClass *find_default_machine(GSList *machines)
1492 1484
 {
1493
-    GSList *el, *machines = object_class_get_list(TYPE_MACHINE, false);
1494
-    MachineClass *mc = NULL;
1485
+    GSList *el;
1495 1486
 
1496 1487
     for (el = machines; el; el = el->next) {
1497
-        MachineClass *temp = el->data;
1488
+        MachineClass *mc = el->data;
1498 1489
 
1499
-        if (temp->is_default) {
1500
-            mc = temp;
1501
-            break;
1490
+        if (mc->is_default) {
1491
+            return mc;
1502 1492
         }
1503 1493
     }
1504 1494
 
1505
-    g_slist_free(machines);
1506
-    return mc;
1495
+    return NULL;
1507 1496
 }
1508 1497
 
1509 1498
 MachineInfoList *qmp_query_machines(Error **errp)
@@ -2585,22 +2574,12 @@ static gint machine_class_cmp(gconstpointer a, gconstpointer b)
2585 2574
                   object_class_get_name(OBJECT_CLASS(mc1)));
2586 2575
 }
2587 2576
 
2588
- static MachineClass *machine_parse(const char *name)
2577
+static MachineClass *machine_parse(const char *name, GSList *machines)
2589 2578
 {
2590
-    MachineClass *mc = NULL;
2591
-    GSList *el, *machines = object_class_get_list(TYPE_MACHINE, false);
2579
+    MachineClass *mc;
2580
+    GSList *el;
2592 2581
 
2593
-    if (name) {
2594
-        mc = find_machine(name);
2595
-    }
2596
-    if (mc) {
2597
-        g_slist_free(machines);
2598
-        return mc;
2599
-    }
2600
-    if (name && !is_help_option(name)) {
2601
-        error_report("unsupported machine type");
2602
-        error_printf("Use -machine help to list supported machines\n");
2603
-    } else {
2582
+    if (is_help_option(name)) {
2604 2583
         printf("Supported machines are:\n");
2605 2584
         machines = g_slist_sort(machines, machine_class_cmp);
2606 2585
         for (el = machines; el; el = el->next) {
@@ -2612,10 +2591,16 @@ static gint machine_class_cmp(gconstpointer a, gconstpointer b)
2612 2591
                    mc->is_default ? " (default)" : "",
2613 2592
                    mc->deprecation_reason ? " (deprecated)" : "");
2614 2593
         }
2594
+        exit(0);
2615 2595
     }
2616 2596
 
2617
-    g_slist_free(machines);
2618
-    exit(!name || !is_help_option(name));
2597
+    mc = find_machine(name, machines);
2598
+    if (!mc) {
2599
+        error_report("unsupported machine type");
2600
+        error_printf("Use -machine help to list supported machines\n");
2601
+        exit(1);
2602
+    }
2603
+    return mc;
2619 2604
 }
2620 2605
 
2621 2606
 void qemu_add_exit_notifier(Notifier *notify)
@@ -2706,7 +2691,8 @@ static const QEMUOption *lookup_opt(int argc, char **argv,
2706 2691
 
2707 2692
 static MachineClass *select_machine(void)
2708 2693
 {
2709
-    MachineClass *machine_class = find_default_machine();
2694
+    GSList *machines = object_class_get_list(TYPE_MACHINE, false);
2695
+    MachineClass *machine_class = find_default_machine(machines);
2710 2696
     const char *optarg;
2711 2697
     QemuOpts *opts;
2712 2698
     Location loc;
@@ -2718,7 +2704,7 @@ static MachineClass *select_machine(void)
2718 2704
 
2719 2705
     optarg = qemu_opt_get(opts, "type");
2720 2706
     if (optarg) {
2721
-        machine_class = machine_parse(optarg);
2707
+        machine_class = machine_parse(optarg, machines);
2722 2708
     }
2723 2709
 
2724 2710
     if (!machine_class) {
@@ -2728,6 +2714,7 @@ static MachineClass *select_machine(void)
2728 2714
     }
2729 2715
 
2730 2716
     loc_pop(&loc);
2717
+    g_slist_free(machines);
2731 2718
     return machine_class;
2732 2719
 }
2733 2720
 
@@ -3002,7 +2989,7 @@ int main(int argc, char **argv, char **envp)
3002 2989
     const char *optarg;
3003 2990
     const char *loadvm = NULL;
3004 2991
     MachineClass *machine_class;
3005
-    const char *cpu_model;
2992
+    const char *cpu_option;
3006 2993
     const char *vga_model = NULL;
3007 2994
     const char *qtest_chrdev = NULL;
3008 2995
     const char *qtest_log = NULL;
@@ -3081,7 +3068,7 @@ int main(int argc, char **argv, char **envp)
3081 3068
     QLIST_INIT (&vm_change_state_head);
3082 3069
     os_setup_early_signal_handling();
3083 3070
 
3084
-    cpu_model = NULL;
3071
+    cpu_option = NULL;
3085 3072
     snapshot = 0;
3086 3073
 
3087 3074
     nb_nics = 0;
@@ -3133,7 +3120,7 @@ int main(int argc, char **argv, char **envp)
3133 3120
             switch(popt->index) {
3134 3121
             case QEMU_OPTION_cpu:
3135 3122
                 /* hw initialization will check this */
3136
-                cpu_model = optarg;
3123
+                cpu_option = optarg;
3137 3124
                 break;
3138 3125
             case QEMU_OPTION_hda:
3139 3126
             case QEMU_OPTION_hdb:
@@ -4050,8 +4037,8 @@ int main(int argc, char **argv, char **envp)
4050 4037
         qemu_set_hw_version(machine_class->hw_version);
4051 4038
     }
4052 4039
 
4053
-    if (cpu_model && is_help_option(cpu_model)) {
4054
-        list_cpus(cpu_model);
4040
+    if (cpu_option && is_help_option(cpu_option)) {
4041
+        list_cpus(cpu_option);
4055 4042
         exit(0);
4056 4043
     }
4057 4044
 
@@ -4299,9 +4286,9 @@ int main(int argc, char **argv, char **envp)
4299 4286
      * Global properties get set up by qdev_prop_register_global(),
4300 4287
      * called from user_register_global_props(), and certain option
4301 4288
      * desugaring.  Also in CPU feature desugaring (buried in
4302
-     * parse_cpu_model()), which happens below this point, but may
4289
+     * parse_cpu_option()), which happens below this point, but may
4303 4290
      * only target the CPU type, which can only be created after
4304
-     * parse_cpu_model() returned the type.
4291
+     * parse_cpu_option() returned the type.
4305 4292
      *
4306 4293
      * Machine compat properties: object_set_machine_compat_props().
4307 4294
      * Accelerator compat props: object_set_accelerator_compat_props(),
@@ -4465,8 +4452,8 @@ int main(int argc, char **argv, char **envp)
4465 4452
 
4466 4453
     /* parse features once if machine provides default cpu_type */
4467 4454
     current_machine->cpu_type = machine_class->default_cpu_type;
4468
-    if (cpu_model) {
4469
-        current_machine->cpu_type = parse_cpu_model(cpu_model);
4455
+    if (cpu_option) {
4456
+        current_machine->cpu_type = parse_cpu_option(cpu_option);
4470 4457
     }
4471 4458
     parse_numa_opts(current_machine);
4472 4459
 

Loading…
Cancel
Save