Machine queue, 2019-03-11
[Qemu-devel] [PULL 7/7] memfd: improve error messages
In reply to Eduardo HabkostFrom: Ilya Maximets <[email protected]>
This gives more information about the failure. Additionally 'ENOSYS' returned for a non-Linux platforms instead of 'errno', which is not initilaized in this case.
Message-Id: <[email protected]>
--- util/memfd.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
util/memfd.c +6 -1
@@ -71,14 +71,18 @@ int qemu_memfd_create(const char *name, size_t size, bool hugetlb, } mfd =memfd_create (name, flags);if (mfd <0 ) { +error_setg_errno (errp, errno, +"failed to create memfd with flags 0x%x" , flags); goto err; }if (ftruncate (mfd, size) ==-1 ) { +error_setg_errno (errp, errno,"failed to resize memfd to %zu" , size); goto err; }if (seals &&fcntl (mfd,F_ADD_SEALS , seals) ==-1 ) { +error_setg_errno (errp, errno,"failed to add seals 0x%x" , seals); goto err; }
@@ -88,8 +92,9 @@ err:if (mfd >=0 ) {close (mfd); } +#else +error_setg_errno (errp,ENOSYS ,"failed to create memfd" );#endif -error_setg_errno (errp, errno,"failed to create memfd" );return -1 ; }
Signature · 1 line
2.18.0.rc1.1.g3f1ff2140
[Qemu-devel] [PULL 5/7] memfd: always check for MFD_CLOEXEC
In reply to Eduardo HabkostFrom: Ilya Maximets <[email protected]>
QEMU always sets this flag unconditionally. We need to check if it's supported.
Message-Id: <[email protected]>
--- util/memfd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
util/memfd.c +1 -1
@@ -188,7 +188,7 @@ bool qemu_memfd_alloc_check(void)bool qemu_memfd_check (unsigned int flags) {#ifdef CONFIG_LINUX -int mfd =memfd_create ("test" , flags); +int mfd =memfd_create ("test" , flags |MFD_CLOEXEC );if (mfd >=0 ) {close (mfd);
Signature · 1 line
2.18.0.rc1.1.g3f1ff2140
[Qemu-devel] [PULL 6/7] memfd: set up correct errno if not supported
In reply to Eduardo HabkostFrom: Ilya Maximets <[email protected]>
qemu_memfd_create() prints the value of 'errno' which is not set in this case.
Message-Id: <[email protected]>
--- util/memfd.c | 1 + 1 file changed, 1 insertion(+)
util/memfd.c +1 -0
@@ -40,6 +40,7 @@ static int memfd_create(const char *name, unsigned int flags)#ifdef __NR_memfd_createreturn syscall (__NR_memfd_create, name, flags);#else + errno =ENOSYS ;return -1 ;#endif }
Signature · 1 line
2.18.0.rc1.1.g3f1ff2140
[Qemu-devel] [PULL 4/7] hostmem-memfd: disable for systems without sealing support
In reply to Eduardo HabkostFrom: Ilya Maximets <[email protected]>
If seals are not supported, memfd_create() will fail. Furthermore, there is no way to disable it in this case because '.seal' property is not registered.
This issue leads to vhost-user-test failures on RHEL 7.2:
qemu-system-x86_64: -object memory-backend-memfd,id=mem,size=2M,: \
failed to create memfd: Invalid argument
and actually breaks the feature on such systems.
Let's restrict memfd backend to systems with sealing support.
Message-Id: <[email protected]>
--- backends/hostmem-memfd.c | 18 ++++++++---------- tests/vhost-user-test.c | 5 +++-- 2 files changed, 11 insertions(+), 12 deletions(-)
backends/hostmem-memfd.c +8 -10
@@ -154,15 +154,13 @@ memfd_backend_class_init(ObjectClass *oc, void *data)"Huge pages size (ex: 2M, 1G)" , &error_abort); } -if (qemu_memfd_check (MFD_ALLOW_SEALING )) { -object_class_property_add_bool (oc,"seal" , - memfd_backend_get_seal, - memfd_backend_set_seal, - &error_abort); -object_class_property_set_description (oc,"seal" , -"Seal growing & shrinking" , - &error_abort); - } +object_class_property_add_bool (oc,"seal" , + memfd_backend_get_seal, + memfd_backend_set_seal, + &error_abort); +object_class_property_set_description (oc,"seal" , +"Seal growing & shrinking" , + &error_abort); }static const TypeInfo memfd_backend_info = {
@@ -175,7 +173,7 @@ static const TypeInfo memfd_backend_info = {static void register_types (void ) { -if (qemu_memfd_check (0 )) { +if (qemu_memfd_check (MFD_ALLOW_SEALING )) {type_register_static (&memfd_backend_info); } }
tests/vhost-user-test.c +3 -2
@@ -178,7 +178,8 @@ static void append_mem_opts(TestServer *server, GString *cmd_line, int size, enum test_memfd memfd) {if (memfd ==TEST_MEMFD_AUTO ) { - memfd =qemu_memfd_check (0 ) ?TEST_MEMFD_YES :TEST_MEMFD_NO ; + memfd =qemu_memfd_check (MFD_ALLOW_SEALING ) ?TEST_MEMFD_YES + :TEST_MEMFD_NO ; }if (memfd ==TEST_MEMFD_YES ) {
@@ -930,7 +931,7 @@ static void register_vhost_user_test(void)"virtio-net" , test_read_guest_mem, &opts); -if (qemu_memfd_check (0 )) { +if (qemu_memfd_check (MFD_ALLOW_SEALING )) { opts.before = vhost_user_test_setup_memfd; qos_add_test("vhost-user/read-guest-mem/memfd", "virtio-net",
Signature · 1 line
2.18.0.rc1.1.g3f1ff2140
The following changes since commit 336cfef495f0cd5b1606251c52628d0372e9a809:
Makefile: Don't install non-sphinx files in sphinx docs install (2019-03-11 11:10:44 +0000)
are available in the Git repository at:
git://github.com/ehabkost/qemu.git tags/machine-next-pull-request
for you to fetch changes up to edaed6c711f07267785a05a633d97dc9268a7385:
memfd: improve error messages (2019-03-11 17:17:01 -0300)
----------------------------------------------------------------
Machine queue, 2019-03-11
* memfd fixes (Ilya Maximets)
* Move nvdimms state into struct MachineState (Eric Auger)
* hostmem-file: reject invalid pmem file sizes (Stefan Hajnoczi)
----------------------------------------------------------------
Queue for Machine Core patches
Eric Auger (2):
nvdimm: Rename AcpiNVDIMMState into NVDIMMState
machine: Move nvdimms state into struct MachineState
Ilya Maximets (4):
hostmem-memfd: disable for systems without sealing support
memfd: always check for MFD_CLOEXEC
memfd: set up correct errno if not supported
memfd: improve error messages
Stefan Hajnoczi (1):
hostmem-file: reject invalid pmem file sizes
include/hw/boards.h | 2 ++ include/hw/i386/pc.h | 4 --- include/hw/mem/nvdimm.h | 10 +++---- include/qemu/osdep.h | 13 ++++++++ backends/hostmem-file.c | 23 ++++++++++++++ backends/hostmem-memfd.c | 18 +++++------ hw/acpi/nvdimm.c | 18 +++++------ hw/core/machine.c | 65 ++++++++++++++++++++++++++++++++++++++++ hw/i386/acpi-build.c | 6 ++-- hw/i386/pc.c | 57 ++++------------------------------- hw/i386/pc_piix.c | 4 +-- hw/i386/pc_q35.c | 4 +-- tests/vhost-user-test.c | 5 ++-- util/memfd.c | 10 +++++-- util/oslib-posix.c | 53 ++++++++++++++++++++++++++++++++ util/oslib-win32.c | 5 ++++ 16 files changed, 206 insertions(+), 91 deletions(-)
Signature · 1 line
2.18.0.rc1.1.g3f1ff2140
[Qemu-devel] [PULL 1/7] hostmem-file: reject invalid pmem file sizes
From: Stefan Hajnoczi <[email protected]>
Guests started with NVDIMMs larger than the underlying host file produce confusing errors inside the guest. This happens because the guest accesses pages beyond the end of the file.
Check the pmem file size on startup and print a clear error message if the size is invalid.
Message-Id: <[email protected]>
--- include/qemu/osdep.h | 13 ++++++++++ backends/hostmem-file.c | 23 ++++++++++++++++++ util/oslib-posix.c | 53 +++++++++++++++++++++++++++++++++++++++++ util/oslib-win32.c | 5 ++++ 4 files changed, 94 insertions(+)
include/qemu/osdep.h +13 -0
@@ -570,6 +570,19 @@ void qemu_set_tty_echo(int fd, bool echo);void os_mem_prealloc (int fd,char *area,size_t sz,int smp_cpus,Error **errp); +/** +* qemu_get_pmem_size: +* @filename: path to a pmem file +* @errp: pointer to a NULL-initialized error object +* +* Determine the size of a persistent memory file. Besides supporting files on +* DAX file systems, this function also supports Linux devdax character +* devices. +* +* Returns: the size or 0 on failure +*/ +uint64_t qemu_get_pmem_size (const char *filename,Error **errp); +/** * qemu_get_pid_name: * @pid: pid of a process
backends/hostmem-file.c +23 -0
@@ -56,6 +56,29 @@ file_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)error_setg (errp,"mem-path property not set" );return ; } + +/* +* Verify pmem file size since starting a guest with an incorrect size +* leads to confusing failures inside the guest. +*/ +if (fb->is_pmem) { +Error *local_err =NULL ; +uint64_t size; + + size =qemu_get_pmem_size (fb->mem_path, &local_err); +if (!size) { +error_propagate (errp, local_err); +return ; + } + +if (backend->size > size) { +error_setg (errp,"size property %" PRIu64" is larger than " +"pmem file \"%s\" size %" PRIu64, backend->size, + fb->mem_path, size); +return ; + } + } + backend->force_prealloc = mem_prealloc; name =host_memory_backend_get_name (backend); memory_region_init_ram_from_file(&backend->mr, OBJECT(backend),
util/oslib-posix.c +53 -0
59 lines not on this page · raw message
util/oslib-win32.c +5 -0
@@ -560,6 +560,11 @@ void os_mem_prealloc(int fd, char *area, size_t memory, int smp_cpus, } } +uint64_t qemu_get_pmem_size (const char *filename,Error **errp) +{ +error_setg (errp,"pmem support not available" ); +return 0 ; +}char *qemu_get_pid_name (pid_t pid) {
Signature · 1 line
2.18.0.rc1.1.g3f1ff2140
[Qemu-devel] [PULL 2/7] nvdimm: Rename AcpiNVDIMMState into NVDIMMState
In reply to Eduardo HabkostFrom: Eric Auger <[email protected]>
As we intend to migrate the acpi_nvdimm_state into the base machine with a new dimms_state name, let's also rename the datatype.
Message-Id: <[email protected]>
--- include/hw/i386/pc.h | 2 +- include/hw/mem/nvdimm.h | 10 +++++----- hw/acpi/nvdimm.c | 18 +++++++++--------- hw/i386/pc.c | 2 +- 4 files changed, 16 insertions(+), 16 deletions(-)
include/hw/i386/pc.h +1 -1
@@ -45,7 +45,7 @@ struct PCMachineState {OnOffAuto vmport;OnOffAuto smm; -AcpiNVDIMMState acpi_nvdimm_state; +NVDIMMState acpi_nvdimm_state;bool acpi_build_enabled;bool smbus_enabled;
include/hw/mem/nvdimm.h +5 -5
@@ -123,7 +123,7 @@ struct NvdimmFitBuffer { };typedef struct NvdimmFitBuffer NvdimmFitBuffer ; -struct AcpiNVDIMMState { +struct NVDIMMState {/* detect if NVDIMM support is enabled. */ bool is_enabled;
@@ -141,13 +141,13 @@ struct AcpiNVDIMMState {int32_t persistence; char *persistence_string; }; -typedef struct AcpiNVDIMMState AcpiNVDIMMState ; +typedef struct NVDIMMState NVDIMMState ; -void nvdimm_init_acpi_state (AcpiNVDIMMState *state,MemoryRegion *io, +void nvdimm_init_acpi_state (NVDIMMState *state,MemoryRegion *io,FWCfgState *fw_cfg,Object *owner);void nvdimm_build_acpi (GArray *table_offsets,GArray *table_data, -BIOSLinker *linker,AcpiNVDIMMState *state, +BIOSLinker *linker,NVDIMMState *state,uint32_t ram_slots); -void nvdimm_plug (AcpiNVDIMMState *state); +void nvdimm_plug (NVDIMMState *state);void nvdimm_acpi_plug_cb (HotplugHandler *hotplug_dev,DeviceState *dev);#endif
hw/acpi/nvdimm.c +9 -9
@@ -382,7 +382,7 @@ nvdimm_build_structure_caps(GArray *structures, uint32_t capabilities) nfit_caps->capabilities =cpu_to_le32 (capabilities); } -static GArray *nvdimm_build_device_structure (AcpiNVDIMMState *state) +static GArray *nvdimm_build_device_structure (NVDIMMState *state) {GSList *device_list =nvdimm_get_device_list ();GArray *structures =g_array_new (false, true/* clear */ ,1 );
@@ -416,7 +416,7 @@ static void nvdimm_init_fit_buffer(NvdimmFitBuffer *fit_buf) fit_buf->fit =g_array_new (false, true/* clear */ ,1 ); } -static void nvdimm_build_fit_buffer (AcpiNVDIMMState *state) +static void nvdimm_build_fit_buffer (NVDIMMState *state) {NvdimmFitBuffer *fit_buf = &state->fit_buf;
@@ -425,12 +425,12 @@ static void nvdimm_build_fit_buffer(AcpiNVDIMMState *state) fit_buf->dirty = true; } -void nvdimm_plug (AcpiNVDIMMState *state) +void nvdimm_plug (NVDIMMState *state) {nvdimm_build_fit_buffer (state); } -static void nvdimm_build_nfit (AcpiNVDIMMState *state,GArray *table_offsets, +static void nvdimm_build_nfit (NVDIMMState *state,GArray *table_offsets,GArray *table_data,BIOSLinker *linker) {NvdimmFitBuffer *fit_buf = &state->fit_buf;
@@ -570,7 +570,7 @@ nvdimm_dsm_no_payload(uint32_t func_ret_status, hwaddr dsm_mem_addr)#define NVDIMM_QEMU_RSVD_HANDLE_ROOT 0x10000/* Read FIT data, defined in docs/specs/acpi_nvdimm.txt. */ -static void nvdimm_dsm_func_read_fit (AcpiNVDIMMState *state,NvdimmDsmIn *in, +static void nvdimm_dsm_func_read_fit (NVDIMMState *state,NvdimmDsmIn *in,hwaddr dsm_mem_addr) {NvdimmFitBuffer *fit_buf = &state->fit_buf;
@@ -619,7 +619,7 @@ exit: }static void -nvdimm_dsm_handle_reserved_root_method (AcpiNVDIMMState *state, +nvdimm_dsm_handle_reserved_root_method (NVDIMMState *state,NvdimmDsmIn *in,hwaddr dsm_mem_addr) {switch (in->function) {
@@ -863,7 +863,7 @@ nvdimm_dsm_read(void *opaque, hwaddr addr, unsigned size)static void nvdimm_dsm_write (void *opaque,hwaddr addr,uint64_t val,unsigned size) { -AcpiNVDIMMState *state = opaque; +NVDIMMState *state = opaque;NvdimmDsmIn *in;hwaddr dsm_mem_addr = val;
@@ -925,7 +925,7 @@ void nvdimm_acpi_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev) } } -void nvdimm_init_acpi_state (AcpiNVDIMMState *state,MemoryRegion *io, +void nvdimm_init_acpi_state (NVDIMMState *state,MemoryRegion *io,FWCfgState *fw_cfg,Object *owner) { memory_region_init_io(&state->io_mr, owner, &nvdimm_dsm_ops, state,
@@ -1319,7 +1319,7 @@ static void nvdimm_build_ssdt(GArray *table_offsets, GArray *table_data, }void nvdimm_build_acpi (GArray *table_offsets,GArray *table_data, -BIOSLinker *linker,AcpiNVDIMMState *state, +BIOSLinker *linker,NVDIMMState *state,uint32_t ram_slots) {GSList *device_list;
hw/i386/pc.c +1 -1
@@ -2571,7 +2571,7 @@ static void pc_machine_set_nvdimm_persistence(Object *obj, const char *value, Error **errp) {PCMachineState *pcms =PC_MACHINE (obj); -AcpiNVDIMMState *nvdimm_state = &pcms->acpi_nvdimm_state; +NVDIMMState *nvdimm_state = &pcms->acpi_nvdimm_state;if (strcmp (value,"cpu" ) ==0 ) nvdimm_state->persistence =3 ;
Signature · 1 line
2.18.0.rc1.1.g3f1ff2140
[Qemu-devel] [PULL 3/7] machine: Move nvdimms state into struct MachineState
In reply to Eduardo HabkostFrom: Eric Auger <[email protected]>
As NVDIMM support is looming for ARM and SPAPR, let's move the acpi_nvdimm_state to the generic machine struct instead of duplicating the same code in several machines. It is also renamed into nvdimms_state and becomes a pointer.
nvdimm and nvdimm-persistence become generic machine options. They become guarded by a nvdimm_supported machine class member. We also add a description for those options.
Message-Id: <[email protected]>
--- include/hw/boards.h | 2 ++ include/hw/i386/pc.h | 4 --- hw/core/machine.c | 65 ++++++++++++++++++++++++++++++++++++++++++++ hw/i386/acpi-build.c | 6 ++-- hw/i386/pc.c | 57 ++++---------------------------------- hw/i386/pc_piix.c | 4 +-- hw/i386/pc_q35.c | 4 +-- 7 files changed, 79 insertions(+), 63 deletions(-)
include/hw/boards.h +2 -0
@@ -210,6 +210,7 @@ struct MachineClass { int nb_nodes, ram_addr_t size);bool ignore_boot_device_suffixes;bool smbus_no_migration_support; +bool nvdimm_supported; HotplugHandler *(*get_hotplug_handler)(MachineState *machine, DeviceState *dev);
@@ -272,6 +273,7 @@ struct MachineState {const char *cpu_type;AccelState *accelerator;CPUArchIdList *possible_cpus; +struct NVDIMMState *nvdimms_state; };#define DEFINE_MACHINE (namestr, machine_initfn) \
include/hw/i386/pc.h +0 -4
@@ -45,8 +45,6 @@ struct PCMachineState {OnOffAuto vmport;OnOffAuto smm; -NVDIMMState acpi_nvdimm_state; -bool acpi_build_enabled;bool smbus_enabled;bool sata_enabled;
@@ -74,8 +72,6 @@ struct PCMachineState {#define PC_MACHINE_MAX_RAM_BELOW_4G "max-ram-below-4g"#define PC_MACHINE_VMPORT "vmport"#define PC_MACHINE_SMM "smm" -#define PC_MACHINE_NVDIMM "nvdimm" -#define PC_MACHINE_NVDIMM_PERSIST "nvdimm-persistence"#define PC_MACHINE_SMBUS "smbus"#define PC_MACHINE_SATA "sata"#define PC_MACHINE_PIT "pit"
hw/core/machine.c +65 -0
89 lines not on this page · raw message
hw/i386/acpi-build.c +3 -3
@@ -1867,7 +1867,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,aml_append (scope, method); } -if (pcms->acpi_nvdimm_state.is_enabled) { +if (machine->nvdimms_state->is_enabled) { method =aml_method ("_E04" ,0 ,AML_NOTSERIALIZED );aml_append (method,aml_notify (aml_name ("\\_SB.NVDR" ),aml_int (0x80 )));
@@ -2704,9 +2704,9 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)build_dmar_q35 (tables_blob, tables->linker); } } -if (pcms->acpi_nvdimm_state.is_enabled) { +if (machine->nvdimms_state->is_enabled) {nvdimm_build_acpi (table_offsets, tables_blob, tables->linker, - &pcms->acpi_nvdimm_state, machine->ram_slots); + machine->nvdimms_state, machine->ram_slots); }/* Add tables supplied by user (if any) */
hw/i386/pc.c +5 -52
105 lines not on this page · raw message
hw/i386/pc_piix.c +2 -2
@@ -297,8 +297,8 @@ static void pc_init1(MachineState *machine, PC_MACHINE_ACPI_DEVICE_PROP, &error_abort); } -if (pcms->acpi_nvdimm_state.is_enabled) { -nvdimm_init_acpi_state (&pcms->acpi_nvdimm_state, system_io, +if (machine->nvdimms_state->is_enabled) { +nvdimm_init_acpi_state (machine->nvdimms_state, system_io, pcms->fw_cfg,OBJECT (pcms)); } }
hw/i386/pc_q35.c +2 -2
@@ -329,8 +329,8 @@ static void pc_q35_init(MachineState *machine)pc_vga_init (isa_bus, host_bus);pc_nic_init (pcmc, isa_bus, host_bus); -if (pcms->acpi_nvdimm_state.is_enabled) { -nvdimm_init_acpi_state (&pcms->acpi_nvdimm_state, system_io, +if (machine->nvdimms_state->is_enabled) { +nvdimm_init_acpi_state (machine->nvdimms_state, system_io, pcms->fw_cfg,OBJECT (pcms)); } }
Signature · 1 line
2.18.0.rc1.1.g3f1ff2140