[PATCH v5 02/79] machine: introduce memory-backend property

Igor Mammedov posted 79 patches 5 years, 11 months ago
Maintainers: "Michael S. Tsirkin" <mst@redhat.com>, KONRAD Frederic <frederic.konrad@adacore.com>, Jan Kiszka <jan.kiszka@web.de>, Paolo Bonzini <pbonzini@redhat.com>, Aurelien Jarno <aurelien@aurel32.net>, Cornelia Huck <cohuck@redhat.com>, Laurent Vivier <lvivier@redhat.com>, Paul Burton <pburton@wavecomp.com>, David Hildenbrand <david@redhat.com>, Radoslaw Biernacki <radoslaw.biernacki@linaro.org>, Fabien Chouteau <chouteau@adacore.com>, Andrew Baumann <Andrew.Baumann@microsoft.com>, Michael Walle <michael@walle.cc>, Peter Chubb <peter.chubb@nicta.com.au>, Richard Henderson <rth@twiddle.net>, Laurent Vivier <laurent@vivier.eu>, Aleksandar Rikalo <aleksandar.rikalo@rt-rk.com>, Sergio Lopez <slp@redhat.com>, Thomas Huth <huth@tuxfamily.org>, Beniamino Galvani <b.galvani@gmail.com>, Eduardo Habkost <ehabkost@redhat.com>, Jean-Christophe Dubois <jcd@tribudubois.net>, Helge Deller <deller@gmx.de>, Igor Mammedov <imammedo@redhat.com>, David Gibson <david@gibson.dropbear.id.au>, Andrew Jeffery <andrew@aj.id.au>, Joel Stanley <joel@jms.id.au>, Alistair Francis <alistair@alistair23.me>, Christian Borntraeger <borntraeger@de.ibm.com>, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, Thomas Huth <thuth@redhat.com>, "Hervé Poussineau" <hpoussin@reactos.org>, Andrey Smirnov <andrew.smirnov@gmail.com>, Halil Pasic <pasic@linux.ibm.com>, BALATON Zoltan <balaton@eik.bme.hu>, Antony Pavlov <antonynpavlov@gmail.com>, Aleksandar Markovic <amarkovic@wavecomp.com>, Rob Herring <robh@kernel.org>, Peter Maydell <peter.maydell@linaro.org>, "Cédric Le Goater" <clg@kaod.org>, "Philippe Mathieu-Daudé" <philmd@redhat.com>, Andrzej Zaborowski <balrogg@gmail.com>, Leif Lindholm <leif@nuviainc.com>, "Edgar E. Iglesias" <edgar.iglesias@gmail.com>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Artyom Tarasenko <atar4qemu@gmail.com>
There is a newer version of this series
[PATCH v5 02/79] machine: introduce memory-backend property
Posted by Igor Mammedov 5 years, 11 months ago
Property will contain link to memory backend that will be
used for backing initial RAM.
Follow up commit will alias -mem-path and -mem-prealloc
CLI options into memory backend options to make memory
handling consistent (using only hostmem backend family
for guest RAM allocation).

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
v4:
 * make property a string, instead of a link.
   Fixes -M memory-backend=foo: foo not found error
   since foo creation is delayed well beyond point
   where machine's properties are set
v3:
 * rename property name from ram-memdev to memory-backend
   (Paolo Bonzini <pbonzini@redhat.com>)

CC: ehabkost@redhat.com
CC: pbonzini@redhat.com
CC: pasic@linux.ibm.com
---
 include/hw/boards.h |  2 ++
 hw/core/machine.c   | 24 ++++++++++++++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/include/hw/boards.h b/include/hw/boards.h
index fb1b43d5b9..7b4b6b79d7 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -4,6 +4,7 @@
 #define HW_BOARDS_H
 
 #include "exec/memory.h"
+#include "sysemu/hostmem.h"
 #include "sysemu/blockdev.h"
 #include "sysemu/accel.h"
 #include "qapi/qapi-types-machine.h"
@@ -285,6 +286,7 @@ struct MachineState {
     bool enforce_config_section;
     bool enable_graphics;
     char *memory_encryption;
+    char *ram_memdev_id;
     DeviceMemoryState *device_memory;
 
     ram_addr_t ram_size;
diff --git a/hw/core/machine.c b/hw/core/machine.c
index 84812a1d1c..1a6e485c87 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -508,6 +508,22 @@ static void validate_sysbus_device(SysBusDevice *sbdev, void *opaque)
     }
 }
 
+static char *machine_get_memdev(Object *obj, Error **errp)
+{
+    MachineState *ms = MACHINE(obj);
+
+    return g_strdup(ms->ram_memdev_id);
+}
+
+static void machine_set_memdev(Object *obj, const char *value, Error **errp)
+{
+    MachineState *ms = MACHINE(obj);
+
+    g_free(ms->ram_memdev_id);
+    ms->ram_memdev_id = g_strdup(value);
+}
+
+
 static void machine_init_notify(Notifier *notifier, void *data)
 {
     MachineState *machine = MACHINE(qdev_get_machine());
@@ -889,6 +905,14 @@ static void machine_initfn(Object *obj)
                                         "Table (HMAT)", NULL);
     }
 
+    object_property_add_str(obj, "memory-backend",
+                            machine_get_memdev, machine_set_memdev,
+                            &error_abort);
+    object_property_set_description(obj, "memory-backend",
+                                    "Set RAM backend"
+                                    "Valid value is ID of hostmem based backend",
+                                     &error_abort);
+
     /* Register notifier when init is done for sysbus sanity checks */
     ms->sysbus_notifier.notify = machine_init_notify;
     qemu_add_machine_init_done_notifier(&ms->sysbus_notifier);
-- 
2.18.1


Re: [PATCH v5 02/79] machine: introduce memory-backend property
Posted by Richard Henderson 5 years, 11 months ago
On 2/17/20 9:33 AM, Igor Mammedov wrote:
> Property will contain link to memory backend that will be
> used for backing initial RAM.
> Follow up commit will alias -mem-path and -mem-prealloc
> CLI options into memory backend options to make memory
> handling consistent (using only hostmem backend family
> for guest RAM allocation).
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
> v4:
>  * make property a string, instead of a link.
>    Fixes -M memory-backend=foo: foo not found error
>    since foo creation is delayed well beyond point
>    where machine's properties are set
> v3:
>  * rename property name from ram-memdev to memory-backend
>    (Paolo Bonzini <pbonzini@redhat.com>)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~

Re: [PATCH v5 02/79] machine: introduce memory-backend property
Posted by Philippe Mathieu-Daudé 5 years, 11 months ago
On 2/17/20 6:33 PM, Igor Mammedov wrote:
> Property will contain link to memory backend that will be
> used for backing initial RAM.
> Follow up commit will alias -mem-path and -mem-prealloc
> CLI options into memory backend options to make memory
> handling consistent (using only hostmem backend family
> for guest RAM allocation).
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
> v4:
>   * make property a string, instead of a link.
>     Fixes -M memory-backend=foo: foo not found error
>     since foo creation is delayed well beyond point
>     where machine's properties are set
> v3:
>   * rename property name from ram-memdev to memory-backend
>     (Paolo Bonzini <pbonzini@redhat.com>)
> 
> CC: ehabkost@redhat.com
> CC: pbonzini@redhat.com
> CC: pasic@linux.ibm.com
> ---
>   include/hw/boards.h |  2 ++
>   hw/core/machine.c   | 24 ++++++++++++++++++++++++
>   2 files changed, 26 insertions(+)
> 
> diff --git a/include/hw/boards.h b/include/hw/boards.h
> index fb1b43d5b9..7b4b6b79d7 100644
> --- a/include/hw/boards.h
> +++ b/include/hw/boards.h
> @@ -4,6 +4,7 @@
>   #define HW_BOARDS_H
>   
>   #include "exec/memory.h"
> +#include "sysemu/hostmem.h"
>   #include "sysemu/blockdev.h"
>   #include "sysemu/accel.h"
>   #include "qapi/qapi-types-machine.h"
> @@ -285,6 +286,7 @@ struct MachineState {
>       bool enforce_config_section;
>       bool enable_graphics;
>       char *memory_encryption;
> +    char *ram_memdev_id;
>       DeviceMemoryState *device_memory;
>   
>       ram_addr_t ram_size;
> diff --git a/hw/core/machine.c b/hw/core/machine.c
> index 84812a1d1c..1a6e485c87 100644
> --- a/hw/core/machine.c
> +++ b/hw/core/machine.c
> @@ -508,6 +508,22 @@ static void validate_sysbus_device(SysBusDevice *sbdev, void *opaque)
>       }
>   }
>   
> +static char *machine_get_memdev(Object *obj, Error **errp)
> +{
> +    MachineState *ms = MACHINE(obj);
> +
> +    return g_strdup(ms->ram_memdev_id);
> +}
> +
> +static void machine_set_memdev(Object *obj, const char *value, Error **errp)
> +{
> +    MachineState *ms = MACHINE(obj);
> +
> +    g_free(ms->ram_memdev_id);
> +    ms->ram_memdev_id = g_strdup(value);
> +}
> +
> +
>   static void machine_init_notify(Notifier *notifier, void *data)
>   {
>       MachineState *machine = MACHINE(qdev_get_machine());
> @@ -889,6 +905,14 @@ static void machine_initfn(Object *obj)
>                                           "Table (HMAT)", NULL);
>       }
>   
> +    object_property_add_str(obj, "memory-backend",
> +                            machine_get_memdev, machine_set_memdev,
> +                            &error_abort);
> +    object_property_set_description(obj, "memory-backend",
> +                                    "Set RAM backend"
> +                                    "Valid value is ID of hostmem based backend",
> +                                     &error_abort);
> +
>       /* Register notifier when init is done for sysbus sanity checks */
>       ms->sysbus_notifier.notify = machine_init_notify;
>       qemu_add_machine_init_done_notifier(&ms->sysbus_notifier);
> 

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>