diff mbox series

[RESEND,v6,14/36] multi-process: setup a machine object for remote device process

Message ID 6b44b86adfae6324f4dd62a24c1d84961627fca1.1587614626.git.elena.ufimtseva@oracle.com (mailing list archive)
State New, archived
Headers show
Series [RESEND,v6,01/36] memory: alloc RAM from file at offset | expand

Commit Message

Elena Ufimtseva April 23, 2020, 4:13 a.m. UTC
From: Jagannathan Raman <jag.raman@oracle.com>

remote-machine object sets up various subsystems of the remote device
process. Instantiate PCI host bridge object and initialize RAM, IO &
PCI memory regions.

Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
---
 MAINTAINERS                   |  2 +
 Makefile.objs                 |  1 +
 exec.c                        |  3 +-
 include/exec/address-spaces.h |  2 +
 include/remote/machine.h      | 30 +++++++++++++
 remote/Makefile.objs          |  2 +
 remote/machine.c              | 84 +++++++++++++++++++++++++++++++++++
 remote/remote-main.c          |  7 +++
 util/Makefile.objs            |  2 +
 9 files changed, 131 insertions(+), 2 deletions(-)
 create mode 100644 include/remote/machine.h
 create mode 100644 remote/machine.c

Comments

Stefan Hajnoczi May 12, 2020, 10:43 a.m. UTC | #1
On Wed, Apr 22, 2020 at 09:13:49PM -0700, elena.ufimtseva@oracle.com wrote:
> From: Jagannathan Raman <jag.raman@oracle.com>
> 
> remote-machine object sets up various subsystems of the remote device
> process. Instantiate PCI host bridge object and initialize RAM, IO &
> PCI memory regions.
> 
> Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
> Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
> Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> ---
>  MAINTAINERS                   |  2 +
>  Makefile.objs                 |  1 +
>  exec.c                        |  3 +-
>  include/exec/address-spaces.h |  2 +
>  include/remote/machine.h      | 30 +++++++++++++
>  remote/Makefile.objs          |  2 +
>  remote/machine.c              | 84 +++++++++++++++++++++++++++++++++++
>  remote/remote-main.c          |  7 +++

Now that the separate remote emulation program is going away I think it
makes sense to move the PCIe host and machine type into hw/:

  hw/pci-host/remote.c <-- PCIe host
  hw/i386/remote.c     <-- machine type (could be moved again later if
                           other architectures are supported)

> diff --git a/exec.c b/exec.c
> index d0ac9545f4..5b1e414099 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -161,7 +161,6 @@ typedef struct subpage_t {
>  #define PHYS_SECTION_UNASSIGNED 0
>  
>  static void io_mem_init(void);
> -static void memory_map_init(void);

The memory_map_init() change is unnecessary once a softmmu target is
used since it will be called from cpu_exec_init_all().

> +static void remote_machine_init(Object *obj)
> +{
> +    RemMachineState *s = REMOTE_MACHINE(obj);
> +    RemPCIHost *rem_host;
> +    MemoryRegion *system_memory, *system_io, *pci_memory;
> +
> +    Error *error_abort = NULL;
> +
> +    object_property_add_child(object_get_root(), "machine", obj, &error_abort);
> +    if (error_abort) {

error_abort aborts the program so handling it is not necessary.

> +        error_report_err(error_abort);
> +    }
> +
> +    memory_map_init();
> +
> +    system_memory = get_system_memory();
> +    system_io = get_system_io();
> +
> +    pci_memory = g_new(MemoryRegion, 1);
> +    memory_region_init(pci_memory, NULL, "pci", UINT64_MAX);
> +
> +    rem_host = REMOTE_HOST_DEVICE(qdev_create(NULL, TYPE_REMOTE_HOST_DEVICE));
> +
> +    rem_host->mr_pci_mem = pci_memory;
> +    rem_host->mr_sys_mem = system_memory;
> +    rem_host->mr_sys_io = system_io;
> +
> +    s->host = rem_host;
> +
> +    object_property_add_child(OBJECT(s), "remote-device", OBJECT(rem_host),
> +                              &error_abort);
> +    if (error_abort) {

error_abort aborts the program so handling it is not necessary.

> +        error_report_err(error_abort);
> +        return;
> +    }
> +
> +    qemu_mutex_lock_iothread();

This will be executed with the iothread lock held. There is no need to
acquire it.

> +    memory_region_add_subregion_overlap(system_memory, 0x0, pci_memory, -1);
> +    qemu_mutex_unlock_iothread();
> +
> +    qdev_init_nofail(DEVICE(rem_host));
> +}
Jag Raman May 12, 2020, 12:12 p.m. UTC | #2
> On May 12, 2020, at 6:43 AM, Stefan Hajnoczi <stefanha@redhat.com> wrote:
> 
> On Wed, Apr 22, 2020 at 09:13:49PM -0700, elena.ufimtseva@oracle.com wrote:
>> From: Jagannathan Raman <jag.raman@oracle.com>
>> 
>> remote-machine object sets up various subsystems of the remote device
>> process. Instantiate PCI host bridge object and initialize RAM, IO &
>> PCI memory regions.
>> 
>> Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
>> Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
>> Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
>> ---
>> MAINTAINERS                   |  2 +
>> Makefile.objs                 |  1 +
>> exec.c                        |  3 +-
>> include/exec/address-spaces.h |  2 +
>> include/remote/machine.h      | 30 +++++++++++++
>> remote/Makefile.objs          |  2 +
>> remote/machine.c              | 84 +++++++++++++++++++++++++++++++++++
>> remote/remote-main.c          |  7 +++
> 
> Now that the separate remote emulation program is going away I think it
> makes sense to move the PCIe host and machine type into hw/:
> 
>  hw/pci-host/remote.c <-- PCIe host
>  hw/i386/remote.c     <-- machine type (could be moved again later if
>                           other architectures are supported)

OK, got it.

> 
>> diff --git a/exec.c b/exec.c
>> index d0ac9545f4..5b1e414099 100644
>> --- a/exec.c
>> +++ b/exec.c
>> @@ -161,7 +161,6 @@ typedef struct subpage_t {
>> #define PHYS_SECTION_UNASSIGNED 0
>> 
>> static void io_mem_init(void);
>> -static void memory_map_init(void);
> 
> The memory_map_init() change is unnecessary once a softmmu target is
> used since it will be called from cpu_exec_init_all().

OK.

> 
>> +static void remote_machine_init(Object *obj)
>> +{
>> +    RemMachineState *s = REMOTE_MACHINE(obj);
>> +    RemPCIHost *rem_host;
>> +    MemoryRegion *system_memory, *system_io, *pci_memory;
>> +
>> +    Error *error_abort = NULL;
>> +
>> +    object_property_add_child(object_get_root(), "machine", obj, &error_abort);
>> +    if (error_abort) {
> 
> error_abort aborts the program so handling it is not necessary.

OK, thanks!

> 
>> +        error_report_err(error_abort);
>> +    }
>> +
>> +    memory_map_init();
>> +
>> +    system_memory = get_system_memory();
>> +    system_io = get_system_io();
>> +
>> +    pci_memory = g_new(MemoryRegion, 1);
>> +    memory_region_init(pci_memory, NULL, "pci", UINT64_MAX);
>> +
>> +    rem_host = REMOTE_HOST_DEVICE(qdev_create(NULL, TYPE_REMOTE_HOST_DEVICE));
>> +
>> +    rem_host->mr_pci_mem = pci_memory;
>> +    rem_host->mr_sys_mem = system_memory;
>> +    rem_host->mr_sys_io = system_io;
>> +
>> +    s->host = rem_host;
>> +
>> +    object_property_add_child(OBJECT(s), "remote-device", OBJECT(rem_host),
>> +                              &error_abort);
>> +    if (error_abort) {
> 
> error_abort aborts the program so handling it is not necessary.
> 
>> +        error_report_err(error_abort);
>> +        return;
>> +    }
>> +
>> +    qemu_mutex_lock_iothread();
> 
> This will be executed with the iothread lock held. There is no need to
> acquire it.

Yes, this wouldn’t be necessary from QEMU’s main loop.

Thanks!
--
Jag

> 
>> +    memory_region_add_subregion_overlap(system_memory, 0x0, pci_memory, -1);
>> +    qemu_mutex_unlock_iothread();
>> +
>> +    qdev_init_nofail(DEVICE(rem_host));
>> +}
diff mbox series

Patch

diff --git a/MAINTAINERS b/MAINTAINERS
index 0cda5ee06a..09764e461c 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2861,6 +2861,8 @@  F: include/io/mpqemu-link.h
 F: io/mpqemu-link.c
 F: include/remote/pcihost.h
 F: remote/pcihost.c
+F: include/remote/machine.h
+F: remote/machine.c
 
 Build and test automation
 -------------------------
diff --git a/Makefile.objs b/Makefile.objs
index f6654633b4..ff3f06b146 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -31,6 +31,7 @@  remote-pci-obj-$(CONFIG_MPQEMU) += block/
 remote-pci-obj-$(CONFIG_MPQEMU) += migration/
 remote-pci-obj-$(CONFIG_MPQEMU) += remote/
 remote-pci-obj-$(CONFIG_MPQEMU) += accel/
+remote-pci-obj-$(CONFIG_MPQEMU) += util/
 
 remote-pci-obj-$(CONFIG_MPQEMU) += cpus-common.o
 remote-pci-obj-$(CONFIG_MPQEMU) += dma-helpers.o
diff --git a/exec.c b/exec.c
index d0ac9545f4..5b1e414099 100644
--- a/exec.c
+++ b/exec.c
@@ -161,7 +161,6 @@  typedef struct subpage_t {
 #define PHYS_SECTION_UNASSIGNED 0
 
 static void io_mem_init(void);
-static void memory_map_init(void);
 static void tcg_log_global_after_sync(MemoryListener *listener);
 static void tcg_commit(MemoryListener *listener);
 
@@ -2963,7 +2962,7 @@  static void tcg_commit(MemoryListener *listener)
     tlb_flush(cpuas->cpu);
 }
 
-static void memory_map_init(void)
+void memory_map_init(void)
 {
     system_memory = g_malloc(sizeof(*system_memory));
 
diff --git a/include/exec/address-spaces.h b/include/exec/address-spaces.h
index db8bfa9a92..56a877b7ba 100644
--- a/include/exec/address-spaces.h
+++ b/include/exec/address-spaces.h
@@ -33,6 +33,8 @@  MemoryRegion *get_system_memory(void);
  */
 MemoryRegion *get_system_io(void);
 
+void memory_map_init(void);
+
 extern AddressSpace address_space_memory;
 extern AddressSpace address_space_io;
 
diff --git a/include/remote/machine.h b/include/remote/machine.h
new file mode 100644
index 0000000000..7e9bdbe28e
--- /dev/null
+++ b/include/remote/machine.h
@@ -0,0 +1,30 @@ 
+/*
+ * Remote machine configuration
+ *
+ * Copyright © 2018, 2020 Oracle and/or its affiliates.
+ *
+ * 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 REMOTE_MACHINE_H
+#define REMOTE_MACHINE_H
+
+#include "qemu/osdep.h"
+#include "qom/object.h"
+#include "hw/boards.h"
+#include "remote/pcihost.h"
+#include "qemu/notify.h"
+
+typedef struct RemMachineState {
+    MachineState parent_obj;
+
+    RemPCIHost *host;
+} RemMachineState;
+
+#define TYPE_REMOTE_MACHINE "remote-machine"
+#define REMOTE_MACHINE(obj) \
+    OBJECT_CHECK(RemMachineState, (obj), TYPE_REMOTE_MACHINE)
+
+#endif
diff --git a/remote/Makefile.objs b/remote/Makefile.objs
index 2757f5a265..55f405d048 100644
--- a/remote/Makefile.objs
+++ b/remote/Makefile.objs
@@ -1,2 +1,4 @@ 
 remote-pci-obj-$(CONFIG_MPQEMU) += remote-main.o
 remote-pci-obj-$(CONFIG_MPQEMU) += pcihost.o
+remote-pci-obj-$(CONFIG_MPQEMU) += machine.o
+remote-pci-obj-$(CONFIG_MPQEMU) += ../util/machine-notify.o
diff --git a/remote/machine.c b/remote/machine.c
new file mode 100644
index 0000000000..97e4f194ea
--- /dev/null
+++ b/remote/machine.c
@@ -0,0 +1,84 @@ 
+/*
+ * Machine for remote device
+ *
+ * Copyright © 2018, 2020 Oracle and/or its affiliates.
+ *
+ * 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 <stdint.h>
+#include <sys/types.h>
+
+#include "qemu/osdep.h"
+#include "remote/pcihost.h"
+#include "remote/machine.h"
+#include "exec/address-spaces.h"
+#include "exec/memory.h"
+#include "exec/ioport.h"
+#include "qemu/thread.h"
+#include "qom/object.h"
+#include "qemu/module.h"
+#include "qapi/error.h"
+#include "qemu/main-loop.h"
+#include "qemu-common.h"
+#include "sysemu/sysemu.h"
+#include "qemu/notify.h"
+
+static void remote_machine_init(Object *obj)
+{
+    RemMachineState *s = REMOTE_MACHINE(obj);
+    RemPCIHost *rem_host;
+    MemoryRegion *system_memory, *system_io, *pci_memory;
+
+    Error *error_abort = NULL;
+
+    object_property_add_child(object_get_root(), "machine", obj, &error_abort);
+    if (error_abort) {
+        error_report_err(error_abort);
+    }
+
+    memory_map_init();
+
+    system_memory = get_system_memory();
+    system_io = get_system_io();
+
+    pci_memory = g_new(MemoryRegion, 1);
+    memory_region_init(pci_memory, NULL, "pci", UINT64_MAX);
+
+    rem_host = REMOTE_HOST_DEVICE(qdev_create(NULL, TYPE_REMOTE_HOST_DEVICE));
+
+    rem_host->mr_pci_mem = pci_memory;
+    rem_host->mr_sys_mem = system_memory;
+    rem_host->mr_sys_io = system_io;
+
+    s->host = rem_host;
+
+    object_property_add_child(OBJECT(s), "remote-device", OBJECT(rem_host),
+                              &error_abort);
+    if (error_abort) {
+        error_report_err(error_abort);
+        return;
+    }
+
+    qemu_mutex_lock_iothread();
+    memory_region_add_subregion_overlap(system_memory, 0x0, pci_memory, -1);
+    qemu_mutex_unlock_iothread();
+
+    qdev_init_nofail(DEVICE(rem_host));
+}
+
+static const TypeInfo remote_machine = {
+    .name = TYPE_REMOTE_MACHINE,
+    .parent = TYPE_MACHINE,
+    .instance_size = sizeof(RemMachineState),
+    .instance_init = remote_machine_init,
+};
+
+static void remote_machine_register_types(void)
+{
+    type_register_static(&remote_machine);
+}
+
+type_init(remote_machine_register_types);
diff --git a/remote/remote-main.c b/remote/remote-main.c
index 7c0764ad01..ecf30e0cba 100644
--- a/remote/remote-main.c
+++ b/remote/remote-main.c
@@ -14,10 +14,17 @@ 
 #include <stdio.h>
 
 #include "qemu/module.h"
+#include "remote/pcihost.h"
+#include "remote/machine.h"
+#include "hw/boards.h"
+#include "hw/qdev-core.h"
+#include "qemu/main-loop.h"
 
 int main(int argc, char *argv[])
 {
     module_call_init(MODULE_INIT_QOM);
 
+    current_machine = MACHINE(REMOTE_MACHINE(object_new(TYPE_REMOTE_MACHINE)));
+
     return 0;
 }
diff --git a/util/Makefile.objs b/util/Makefile.objs
index fe339c2636..d8f0061157 100644
--- a/util/Makefile.objs
+++ b/util/Makefile.objs
@@ -64,3 +64,5 @@  util-obj-$(CONFIG_GIO) += dbus.o
 dbus.o-cflags = $(GIO_CFLAGS)
 dbus.o-libs = $(GIO_LIBS)
 util-obj-$(CONFIG_USER_ONLY) += selfmap.o
+
+remote-pci-obj-$(CONFIG_MPQEMU) += notify.o