[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH V7 10/29] machine: memfd-alloc option
From: |
Steven Sistare |
Subject: |
Re: [PATCH V7 10/29] machine: memfd-alloc option |
Date: |
Thu, 3 Mar 2022 10:55:16 -0500 |
User-agent: |
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 |
On 2/18/2022 3:05 AM, Guoyi Tu wrote:
> On Wed, 2021-12-22 at 11:05 -0800, Steve Sistare wrote:
>> Allocate anonymous memory using memfd_create if the memfd-alloc
>> machine
>> option is set.
>>
>> Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
>> ---
>> hw/core/machine.c | 19 +++++++++++++++++++
>> include/hw/boards.h | 1 +
>> qemu-options.hx | 6 ++++++
>> softmmu/physmem.c | 47 ++++++++++++++++++++++++++++++++++++++-----
>> ----
>> softmmu/vl.c | 1 +
>> trace-events | 1 +
>> util/qemu-config.c | 4 ++++
>> 7 files changed, 70 insertions(+), 9 deletions(-)
>>
>> diff --git a/hw/core/machine.c b/hw/core/machine.c
>> index 53a99ab..7739d88 100644
>> --- a/hw/core/machine.c
>> +++ b/hw/core/machine.c
>> @@ -392,6 +392,20 @@ static void machine_set_mem_merge(Object *obj,
>> bool value, Error **errp)
>> ms->mem_merge = value;
>> }
>>
>> +static bool machine_get_memfd_alloc(Object *obj, Error **errp)
>> +{
>> + MachineState *ms = MACHINE(obj);
>> +
>> + return ms->memfd_alloc;
>> +}
>> +
>> +static void machine_set_memfd_alloc(Object *obj, bool value, Error
>> **errp)
>> +{
>> + MachineState *ms = MACHINE(obj);
>> +
>> + ms->memfd_alloc = value;
>> +}
>> +
>> static bool machine_get_usb(Object *obj, Error **errp)
>> {
>> MachineState *ms = MACHINE(obj);
>> @@ -829,6 +843,11 @@ static void machine_class_init(ObjectClass *oc,
>> void *data)
>> object_class_property_set_description(oc, "mem-merge",
>> "Enable/disable memory merge support");
>>
>> + object_class_property_add_bool(oc, "memfd-alloc",
>> + machine_get_memfd_alloc, machine_set_memfd_alloc);
>> + object_class_property_set_description(oc, "memfd-alloc",
>> + "Enable/disable allocating anonymous memory using
>> memfd_create");
>> +
>> object_class_property_add_bool(oc, "usb",
>> machine_get_usb, machine_set_usb);
>> object_class_property_set_description(oc, "usb",
>> diff --git a/include/hw/boards.h b/include/hw/boards.h
>> index 9c1c190..a57d7a0 100644
>> --- a/include/hw/boards.h
>> +++ b/include/hw/boards.h
>> @@ -327,6 +327,7 @@ struct MachineState {
>> char *dt_compatible;
>> bool dump_guest_core;
>> bool mem_merge;
>> + bool memfd_alloc;
>> bool usb;
>> bool usb_disabled;
>> char *firmware;
>> diff --git a/qemu-options.hx b/qemu-options.hx
>> index 7d47510..33c8173 100644
>> --- a/qemu-options.hx
>> +++ b/qemu-options.hx
>> @@ -30,6 +30,7 @@ DEF("machine", HAS_ARG, QEMU_OPTION_machine, \
>> " vmport=on|off|auto controls emulation of vmport
>> (default: auto)\n"
>> " dump-guest-core=on|off include guest memory in
>> a core dump (default=on)\n"
>> " mem-merge=on|off controls memory merge support
>> (default: on)\n"
>> + " memfd-alloc=on|off controls allocating
>> anonymous guest RAM using memfd_create (default: off)\n"
>> " aes-key-wrap=on|off controls support for AES
>> key wrapping (default=on)\n"
>> " dea-key-wrap=on|off controls support for DEA
>> key wrapping (default=on)\n"
>> " suppress-vmdesc=on|off disables self-describing
>> migration (default=off)\n"
>> @@ -76,6 +77,11 @@ SRST
>> supported by the host, de-duplicates identical memory pages
>> among VMs instances (enabled by default).
>>
>> + ``memfd-alloc=on|off``
>> + Enables or disables allocation of anonymous guest RAM using
>> + memfd_create. Any associated memory-backend objects are
>> created with
>> + share=on. The memfd-alloc default is off.
>> +
>> ``aes-key-wrap=on|off``
>> Enables or disables AES key wrapping support on s390-ccw
>> hosts.
>> This feature controls whether AES wrapping keys will be
>> created
>> diff --git a/softmmu/physmem.c b/softmmu/physmem.c
>> index 3524c04..95e2b49 100644
>> --- a/softmmu/physmem.c
>> +++ b/softmmu/physmem.c
>> @@ -41,6 +41,7 @@
>> #include "qemu/config-file.h"
>> #include "qemu/error-report.h"
>> #include "qemu/qemu-print.h"
>> +#include "qemu/memfd.h"
>> #include "exec/memory.h"
>> #include "exec/ioport.h"
>> #include "sysemu/dma.h"
>> @@ -1964,35 +1965,63 @@ static void ram_block_add(RAMBlock
>> *new_block, Error **errp)
>> const bool shared = qemu_ram_is_shared(new_block);
>> RAMBlock *block;
>> RAMBlock *last_block = NULL;
>> + struct MemoryRegion *mr = new_block->mr;
>> ram_addr_t old_ram_size, new_ram_size;
>> Error *err = NULL;
>> + const char *name;
>> + void *addr = 0;
>> + size_t maxlen;
>> + MachineState *ms = MACHINE(qdev_get_machine());
>>
>> old_ram_size = last_ram_page();
>>
>> qemu_mutex_lock_ramlist();
>> - new_block->offset = find_ram_offset(new_block->max_length);
>> + maxlen = new_block->max_length;
>> + new_block->offset = find_ram_offset(maxlen);
>>
>> if (!new_block->host) {
>> if (xen_enabled()) {
>> - xen_ram_alloc(new_block->offset, new_block->max_length,
>> - new_block->mr, &err);
>> + xen_ram_alloc(new_block->offset, maxlen, new_block->mr,
>> &err);
>> if (err) {
>> error_propagate(errp, err);
>> qemu_mutex_unlock_ramlist();
>> return;
>> }
>> } else {
>> - new_block->host = qemu_anon_ram_alloc(new_block-
>>> max_length,
>> - &new_block->mr-
>>> align,
>> - shared,
>> noreserve);
>> - if (!new_block->host) {
>> + name = memory_region_name(mr);
>> + if (ms->memfd_alloc) {
>> + Object *parent = &mr->parent_obj;
>> + int mfd = -1; /* placeholder until next
>> patch */
>> + mr->align = QEMU_VMALLOC_ALIGN;
>> + if (mfd < 0) {
>> + mfd = qemu_memfd_create(name, maxlen + mr-
>>> align,
>> + 0, 0, 0, &err);
>> + if (mfd < 0) {
>
> the error message should be propagated
>
> Guoyi Tu
>
>> + return;
>> + }
Will do, thanks, by setting errp directly:
mfd = qemu_memfd_create(name, maxlen + mr->align, 0, 0, 0, errp);
- Steve
- Re: [PATCH V7 10/29] machine: memfd-alloc option,
Steven Sistare <=
- Re: [PATCH V7 10/29] machine: memfd-alloc option, Steven Sistare, 2022/03/03
- Re: [PATCH V7 10/29] machine: memfd-alloc option, Michael S. Tsirkin, 2022/03/03
- Re: [PATCH V7 10/29] machine: memfd-alloc option, Igor Mammedov, 2022/03/04
- Re: [PATCH V7 10/29] machine: memfd-alloc option, Steven Sistare, 2022/03/07
- Re: [PATCH V7 10/29] machine: memfd-alloc option, Michael S. Tsirkin, 2022/03/08
- Re: [PATCH V7 10/29] machine: memfd-alloc option, Igor Mammedov, 2022/03/08
- Re: [PATCH V7 10/29] machine: memfd-alloc option, Steven Sistare, 2022/03/10
- Re: [PATCH V7 10/29] machine: memfd-alloc option, Igor Mammedov, 2022/03/10
- Re: [PATCH V7 10/29] machine: memfd-alloc option, Steven Sistare, 2022/03/10
- Re: [PATCH V7 10/29] machine: memfd-alloc option, Steven Sistare, 2022/03/10