qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Don Slutz <dslutz@verizon.com>
To: Igor Mammedov <imammedo@redhat.com>, qemu-devel@nongnu.org
Cc: pbonzini@redhat.com, dslutz@verizon.com, mst@redhat.com
Subject: Re: [Qemu-devel] [PATCH v4.1 5/33 FIXED] add memdev backend infrastructure
Date: Fri, 06 Jun 2014 13:25:12 -0400	[thread overview]
Message-ID: <5391F978.8080102@terremark.com> (raw)
In-Reply-To: <1402070069-19222-1-git-send-email-imammedo@redhat.com>

Tested that "make check" no longer fails with this version.

    -Don Slutz

On 06/06/14 11:54, Igor Mammedov wrote:
> Provides framework for splitting host RAM allocation/
> policies into a separate backend that could be used
> by devices.
>
> Initially only legacy RAM backend is provided, which
> uses memory_region_init_ram() allocator and compatible
> with every CLI option that affects memory_region_init_ram().
>
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> v6:
>   - change memory backend type from "memory" to "memory-backend"
>     to avoid conflict with sparc arch where they also have "memory"
>     type
>   - the same as above for "memory-ram" -> "memory-backend-ram"
>     to keep ram backend in memory-backend namespace
> v5:
>   - drop default 'complete' method, allowing child not to implement it
>   - codestyle cleanups
> v4:
>   - don't use nonexisting anymore error_is_set()
> v3:
>   - fix path leak & use object_get_canonical_path_component()
>     for getting object name
> v2:
>   - reuse UserCreatable interface instead of custom callbacks
> ---
>   backends/Makefile.objs   |    2 +
>   backends/hostmem-ram.c   |   54 +++++++++++++++++++++++++
>   backends/hostmem.c       |   97 ++++++++++++++++++++++++++++++++++++++++++++++
>   include/sysemu/hostmem.h |   60 ++++++++++++++++++++++++++++
>   4 files changed, 213 insertions(+), 0 deletions(-)
>   create mode 100644 backends/hostmem-ram.c
>   create mode 100644 backends/hostmem.c
>   create mode 100644 include/sysemu/hostmem.h
>
> diff --git a/backends/Makefile.objs b/backends/Makefile.objs
> index 591ddcf..7fb7acd 100644
> --- a/backends/Makefile.objs
> +++ b/backends/Makefile.objs
> @@ -6,3 +6,5 @@ common-obj-$(CONFIG_BRLAPI) += baum.o
>   baum.o-cflags := $(SDL_CFLAGS)
>   
>   common-obj-$(CONFIG_TPM) += tpm.o
> +
> +common-obj-y += hostmem.o hostmem-ram.o
> diff --git a/backends/hostmem-ram.c b/backends/hostmem-ram.c
> new file mode 100644
> index 0000000..bba2ebc
> --- /dev/null
> +++ b/backends/hostmem-ram.c
> @@ -0,0 +1,54 @@
> +/*
> + * QEMU Host Memory Backend
> + *
> + * Copyright (C) 2013-2014 Red Hat Inc
> + *
> + * Authors:
> + *   Igor Mammedov <imammedo@redhat.com>
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2 or later.
> + * See the COPYING file in the top-level directory.
> + */
> +#include "sysemu/hostmem.h"
> +#include "qom/object_interfaces.h"
> +
> +#define TYPE_MEMORY_BACKEND_RAM "memory-backend-ram"
> +
> +
> +static void
> +ram_backend_memory_init(UserCreatable *uc, Error **errp)
> +{
> +    HostMemoryBackend *backend = MEMORY_BACKEND(uc);
> +    char *path;
> +
> +    if (!backend->size) {
> +        error_setg(errp, "can't create backend with size 0");
> +        return;
> +    }
> +
> +    path = object_get_canonical_path_component(OBJECT(backend));
> +    memory_region_init_ram(&backend->mr, OBJECT(backend), path,
> +                           backend->size);
> +    g_free(path);
> +}
> +
> +static void
> +ram_backend_class_init(ObjectClass *oc, void *data)
> +{
> +    UserCreatableClass *ucc = USER_CREATABLE_CLASS(oc);
> +
> +    ucc->complete = ram_backend_memory_init;
> +}
> +
> +static const TypeInfo ram_backend_info = {
> +    .name = TYPE_MEMORY_BACKEND_RAM,
> +    .parent = TYPE_MEMORY_BACKEND,
> +    .class_init = ram_backend_class_init,
> +};
> +
> +static void register_types(void)
> +{
> +    type_register_static(&ram_backend_info);
> +}
> +
> +type_init(register_types);
> diff --git a/backends/hostmem.c b/backends/hostmem.c
> new file mode 100644
> index 0000000..2f578ac
> --- /dev/null
> +++ b/backends/hostmem.c
> @@ -0,0 +1,97 @@
> +/*
> + * QEMU Host Memory Backend
> + *
> + * Copyright (C) 2013-2014 Red Hat Inc
> + *
> + * Authors:
> + *   Igor Mammedov <imammedo@redhat.com>
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2 or later.
> + * See the COPYING file in the top-level directory.
> + */
> +#include "sysemu/hostmem.h"
> +#include "sysemu/sysemu.h"
> +#include "qapi/visitor.h"
> +#include "qapi/qmp/qerror.h"
> +#include "qemu/config-file.h"
> +#include "qom/object_interfaces.h"
> +
> +static void
> +hostmemory_backend_get_size(Object *obj, Visitor *v, void *opaque,
> +                            const char *name, Error **errp)
> +{
> +    HostMemoryBackend *backend = MEMORY_BACKEND(obj);
> +    uint64_t value = backend->size;
> +
> +    visit_type_size(v, &value, name, errp);
> +}
> +
> +static void
> +hostmemory_backend_set_size(Object *obj, Visitor *v, void *opaque,
> +                            const char *name, Error **errp)
> +{
> +    HostMemoryBackend *backend = MEMORY_BACKEND(obj);
> +    Error *local_err = NULL;
> +    uint64_t value;
> +
> +    if (memory_region_size(&backend->mr)) {
> +        error_setg(&local_err, "cannot change property value");
> +        goto out;
> +    }
> +
> +    visit_type_size(v, &value, name, &local_err);
> +    if (local_err) {
> +        goto out;
> +    }
> +    if (!value) {
> +        error_setg(&local_err, "Property '%s.%s' doesn't take value '%"
> +                   PRIu64 "'", object_get_typename(obj), name, value);
> +        goto out;
> +    }
> +    backend->size = value;
> +out:
> +    error_propagate(errp, local_err);
> +}
> +
> +static void hostmemory_backend_init(Object *obj)
> +{
> +    object_property_add(obj, "size", "int",
> +                        hostmemory_backend_get_size,
> +                        hostmemory_backend_set_size, NULL, NULL, NULL);
> +}
> +
> +static void hostmemory_backend_finalize(Object *obj)
> +{
> +    HostMemoryBackend *backend = MEMORY_BACKEND(obj);
> +
> +    if (memory_region_size(&backend->mr)) {
> +        memory_region_destroy(&backend->mr);
> +    }
> +}
> +
> +MemoryRegion *
> +host_memory_backend_get_memory(HostMemoryBackend *backend, Error **errp)
> +{
> +    return memory_region_size(&backend->mr) ? &backend->mr : NULL;
> +}
> +
> +static const TypeInfo hostmemory_backend_info = {
> +    .name = TYPE_MEMORY_BACKEND,
> +    .parent = TYPE_OBJECT,
> +    .abstract = true,
> +    .class_size = sizeof(HostMemoryBackendClass),
> +    .instance_size = sizeof(HostMemoryBackend),
> +    .instance_init = hostmemory_backend_init,
> +    .instance_finalize = hostmemory_backend_finalize,
> +    .interfaces = (InterfaceInfo[]) {
> +        { TYPE_USER_CREATABLE },
> +        { }
> +    }
> +};
> +
> +static void register_types(void)
> +{
> +    type_register_static(&hostmemory_backend_info);
> +}
> +
> +type_init(register_types);
> diff --git a/include/sysemu/hostmem.h b/include/sysemu/hostmem.h
> new file mode 100644
> index 0000000..4fc081e
> --- /dev/null
> +++ b/include/sysemu/hostmem.h
> @@ -0,0 +1,60 @@
> +/*
> + * QEMU Host Memory Backend
> + *
> + * Copyright (C) 2013-2014 Red Hat Inc
> + *
> + * Authors:
> + *   Igor Mammedov <imammedo@redhat.com>
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2 or later.
> + * See the COPYING file in the top-level directory.
> + */
> +#ifndef QEMU_RAM_H
> +#define QEMU_RAM_H
> +
> +#include "qom/object.h"
> +#include "qapi/error.h"
> +#include "exec/memory.h"
> +#include "qemu/option.h"
> +
> +#define TYPE_MEMORY_BACKEND "memory-backend"
> +#define MEMORY_BACKEND(obj) \
> +    OBJECT_CHECK(HostMemoryBackend, (obj), TYPE_MEMORY_BACKEND)
> +#define MEMORY_BACKEND_GET_CLASS(obj) \
> +    OBJECT_GET_CLASS(HostMemoryBackendClass, (obj), TYPE_MEMORY_BACKEND)
> +#define MEMORY_BACKEND_CLASS(klass) \
> +    OBJECT_CLASS_CHECK(HostMemoryBackendClass, (klass), TYPE_MEMORY_BACKEND)
> +
> +typedef struct HostMemoryBackend HostMemoryBackend;
> +typedef struct HostMemoryBackendClass HostMemoryBackendClass;
> +
> +/**
> + * HostMemoryBackendClass:
> + * @parent_class: opaque parent class container
> + */
> +struct HostMemoryBackendClass {
> +    ObjectClass parent_class;
> +};
> +
> +/**
> + * @HostMemoryBackend
> + *
> + * @parent: opaque parent object container
> + * @size: amount of memory backend provides
> + * @id: unique identification string in memdev namespace
> + * @mr: MemoryRegion representing host memory belonging to backend
> + */
> +struct HostMemoryBackend {
> +    /* private */
> +    Object parent;
> +
> +    /* protected */
> +    uint64_t size;
> +
> +    MemoryRegion mr;
> +};
> +
> +MemoryRegion *host_memory_backend_get_memory(HostMemoryBackend *backend,
> +                                             Error **errp);
> +
> +#endif

  reply	other threads:[~2014-06-06 17:25 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-02 13:24 [Qemu-devel] [PATCH v4 00/33] pc: ACPI memory hotplug Igor Mammedov
2014-06-02 13:24 ` [Qemu-devel] [PATCH v4 01/33] pc: create custom generic PC machine type Igor Mammedov
2014-06-02 13:24 ` [Qemu-devel] [PATCH v4 02/33] pc: ACPI BIOS: use enum for defining memory affinity flags Igor Mammedov
2014-06-02 13:24 ` [Qemu-devel] [PATCH v4 03/33] object_add: allow completion handler to get canonical path Igor Mammedov
2014-06-02 13:25 ` [Qemu-devel] [PATCH v4 04/33] vl.c: daemonize before guest memory allocation Igor Mammedov
2014-06-02 13:25 ` [Qemu-devel] [PATCH v4 05/33] add memdev backend infrastructure Igor Mammedov
2014-06-05 21:36   ` Don Slutz
2014-06-06 15:54     ` [Qemu-devel] [PATCH v4.1 5/33 FIXED] " Igor Mammedov
2014-06-06 17:25       ` Don Slutz [this message]
2014-06-02 13:25 ` [Qemu-devel] [PATCH v4 06/33] vl.c: extend -m option to support options for memory hotplug Igor Mammedov
2014-06-02 13:25 ` [Qemu-devel] [PATCH v4 07/33] qdev: hotplug for buss-less devices Igor Mammedov
2014-06-02 13:25 ` [Qemu-devel] [PATCH v4 08/33] qdev: expose DeviceState.hotplugged field as a property Igor Mammedov
2014-06-02 13:25 ` [Qemu-devel] [PATCH v4 09/33] pc: implement pc-dimm device abstraction Igor Mammedov
2014-06-02 13:25 ` [Qemu-devel] [PATCH v4 10/33] memory: add memory_region_is_mapped() API Igor Mammedov
2014-06-02 13:25 ` [Qemu-devel] [PATCH v4 11/33] pc-dimm: do not allow to set already used memdev Igor Mammedov
2014-06-02 13:25 ` [Qemu-devel] [PATCH v4 12/33] pc: initialize memory hotplug address space Igor Mammedov
2014-06-02 13:25 ` [Qemu-devel] [PATCH v4 13/33] pc: exit QEMU if number of slots more than supported 256 Igor Mammedov
2014-06-02 13:25 ` [Qemu-devel] [PATCH v4 14/33] pc: add 'etc/reserved-memory-end' fw_cfg interface for SeaBIOS Igor Mammedov
2014-06-02 13:25 ` [Qemu-devel] [PATCH v4 15/33] pc: exit QEMU if compat machine doesn't support memory hotlpug Igor Mammedov
2014-06-02 13:25 ` [Qemu-devel] [PATCH v4 16/33] pc: add memory hotplug handler to PC_MACHINE Igor Mammedov
2014-06-02 13:25 ` [Qemu-devel] [PATCH v4 17/33] pc-dimm: add busy address check and address auto-allocation Igor Mammedov
2014-06-02 13:25 ` [Qemu-devel] [PATCH v4 18/33] pc-dimm: add busy slot check and slot auto-allocation Igor Mammedov
2014-06-02 13:25 ` [Qemu-devel] [PATCH v4 19/33] acpi: rename cpu_hotplug_defs.h to pc-hotplug.h Igor Mammedov
2014-06-02 13:25 ` [Qemu-devel] [PATCH v4 20/33] acpi: memory hotplug ACPI hardware implementation Igor Mammedov
2014-06-02 13:25 ` [Qemu-devel] [PATCH v4 21/33] trace: add acpi memory hotplug IO region events Igor Mammedov
2014-06-02 13:25 ` [Qemu-devel] [PATCH v4 22/33] trace: pc: add PC_DIMM slot & address allocation Igor Mammedov
2014-06-02 13:25 ` [Qemu-devel] [PATCH v4 23/33] acpi:piix4: allow plug/unlug callbacks handle not only PCI devices Igor Mammedov
2014-06-02 13:25 ` [Qemu-devel] [PATCH v4 24/33] acpi:piix4: add memory hotplug handling Igor Mammedov
2014-06-02 13:25 ` [Qemu-devel] [PATCH v4 25/33] pc: ich9 lpc: make it work with global/compat properties Igor Mammedov
2014-06-02 13:25 ` [Qemu-devel] [PATCH v4 26/33] acpi:ich9: add memory hotplug handling Igor Mammedov
2014-06-08 11:57   ` Michael S. Tsirkin
2014-06-02 13:25 ` [Qemu-devel] [PATCH v4 27/33] pc: migrate piix4 & ich9 MemHotplugState Igor Mammedov
2014-06-02 13:25 ` [Qemu-devel] [PATCH v4 28/33] pc: add acpi-device link to PCMachineState Igor Mammedov
2014-06-02 13:25 ` [Qemu-devel] [PATCH v4 29/33] pc: propagate memory hotplug event to ACPI device Igor Mammedov
2014-06-02 13:25 ` [Qemu-devel] [PATCH v4 30/33] pc: ACPI BIOS: implement memory hotplug interface Igor Mammedov
2014-06-02 13:25 ` [Qemu-devel] [PATCH v4 31/33] pc: add "hotplug-memory-region-size" property to PC_MACHINE Igor Mammedov
2014-06-02 13:25 ` [Qemu-devel] [PATCH v4 32/33] pc: ACPI BIOS: reserve SRAT entry for hotplug mem hole Igor Mammedov
2014-06-02 13:25 ` [Qemu-devel] [PATCH v4 33/33] pc: ACPI BIOS: make GPE.3 handle memory hotplug event on PIIX and Q35 machines Igor Mammedov
2014-06-06 12:44   ` Don Slutz
2014-06-06 15:23     ` Igor Mammedov
2014-06-08  7:43       ` Michael S. Tsirkin
2014-06-02 14:32 ` [Qemu-devel] [PATCH v4 00/33] pc: ACPI memory hotplug Eric Blake
2014-06-02 14:50   ` Igor Mammedov
2014-06-08 13:01 ` Michael S. Tsirkin
2014-06-11  7:13   ` Santosh Shukla
2014-06-11  8:08     ` Michael S. Tsirkin
2014-06-11  9:35       ` Santosh Shukla
2014-06-11  9:54         ` Michael S. Tsirkin
2014-06-11 10:22           ` Santosh Shukla

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5391F978.8080102@terremark.com \
    --to=dslutz@verizon.com \
    --cc=imammedo@redhat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).