diff mbox series

[RESEND,v6,17/36] multi-process: introduce proxy object

Message ID 53e7ef183df66e34aa20c026b6bf299b1726ad75.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: Elena Ufimtseva <elena.ufimtseva@oracle.com>

Defines a PCI Device proxy object as a parent of TYPE_PCI_DEVICE.

PCI Proxy Object registers as a PCI device with QEMU and forwards all
PCI accesses to the remote process using the communication channel.

Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
---
 MAINTAINERS                   |  3 ++
 hw/Makefile.objs              |  2 ++
 hw/proxy/Makefile.objs        |  1 +
 hw/proxy/qemu-proxy.c         | 56 +++++++++++++++++++++++++++++++++++
 include/hw/proxy/qemu-proxy.h | 46 ++++++++++++++++++++++++++++
 include/io/mpqemu-link.h      |  1 +
 6 files changed, 109 insertions(+)
 create mode 100644 hw/proxy/Makefile.objs
 create mode 100644 hw/proxy/qemu-proxy.c
 create mode 100644 include/hw/proxy/qemu-proxy.h

Comments

Stefan Hajnoczi May 12, 2020, 12:23 p.m. UTC | #1
On Wed, Apr 22, 2020 at 09:13:52PM -0700, elena.ufimtseva@oracle.com wrote:
> From: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> 
> Defines a PCI Device proxy object as a parent of TYPE_PCI_DEVICE.

s/parent/child/

> 
> PCI Proxy Object registers as a PCI device with QEMU and forwards all
> PCI accesses to the remote process using the communication channel.

Please include that functionality in this patch. The code below just
sets up a skeleton PCI device. There is no code that forwards accesses
to the remote process.

> Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
> Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
> ---
>  MAINTAINERS                   |  3 ++
>  hw/Makefile.objs              |  2 ++
>  hw/proxy/Makefile.objs        |  1 +
>  hw/proxy/qemu-proxy.c         | 56 +++++++++++++++++++++++++++++++++++
>  include/hw/proxy/qemu-proxy.h | 46 ++++++++++++++++++++++++++++
>  include/io/mpqemu-link.h      |  1 +
>  6 files changed, 109 insertions(+)
>  create mode 100644 hw/proxy/Makefile.objs
>  create mode 100644 hw/proxy/qemu-proxy.c
>  create mode 100644 include/hw/proxy/qemu-proxy.h
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 96f8d7ff19..3da3dcd311 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -2866,6 +2866,9 @@ F: include/remote/machine.h
>  F: remote/machine.c
>  F: include/remote/memory.h
>  F: remote/memory.c
> +F: hw/proxy/Makefile.objs
> +F: hw/proxy/qemu-proxy.c
> +F: include/hw/proxy/qemu-proxy.h

It's a generic PCI device. hw/pci/proxy.c would be a good location for
it.

By the way an alternative to the "proxy"/"remote" terminology is
RemotePCIClient/RemotePCIServer. That makes it more obvious that "proxy"
is related the "remote" feature. Feel free to keep the existing
terminology, I just wanted to suggest another possibility.

>  
>  Build and test automation
>  -------------------------
> diff --git a/hw/Makefile.objs b/hw/Makefile.objs
> index af9235b6f2..7b489b12a5 100644
> --- a/hw/Makefile.objs
> +++ b/hw/Makefile.objs
> @@ -45,6 +45,8 @@ endif
>  common-obj-y += $(devices-dirs-y)
>  obj-y += $(devices-dirs-y)
>  
> +common-obj-$(CONFIG_MPQEMU) += proxy/
> +
>  remote-pci-obj-$(CONFIG_MPQEMU) += core/
>  remote-pci-obj-$(CONFIG_MPQEMU) += block/
>  remote-pci-obj-$(CONFIG_MPQEMU) += pci/
> diff --git a/hw/proxy/Makefile.objs b/hw/proxy/Makefile.objs
> new file mode 100644
> index 0000000000..eb81624cf8
> --- /dev/null
> +++ b/hw/proxy/Makefile.objs
> @@ -0,0 +1 @@
> +common-obj-$(CONFIG_MPQEMU) += qemu-proxy.o
> diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c
> new file mode 100644
> index 0000000000..bf6c4117ef
> --- /dev/null
> +++ b/hw/proxy/qemu-proxy.c
> @@ -0,0 +1,56 @@
> +/*
> + * 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 "qemu/osdep.h"
> +#include "qemu-common.h"
> +
> +#include "qapi/error.h"
> +#include "io/mpqemu-link.h"
> +#include "hw/proxy/qemu-proxy.h"
> +#include "hw/pci/pci.h"
> +
> +static void pci_proxy_dev_realize(PCIDevice *device, Error **errp)
> +{
> +    PCIProxyDev *dev = PCI_PROXY_DEV(device);
> +    PCIProxyDevClass *k = PCI_PROXY_DEV_GET_CLASS(dev);
> +    Error *local_err = NULL;
> +
> +    if (k->realize) {

Will anything inherit from this class? I thought this is the remote PCI
client that can acts as a stand-in for all remote PCI devices, so it's
not clear why it's acting as a base class here.

> diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h
> index d46cb81058..73cc59b874 100644
> --- a/include/io/mpqemu-link.h
> +++ b/include/io/mpqemu-link.h
> @@ -14,6 +14,7 @@
>  #include "qemu/osdep.h"
>  #include "qemu-common.h"
>  
> +#include "sys/eventfd.h"

Why? Nothing in this patch uses this header.
Jag Raman May 12, 2020, 12:35 p.m. UTC | #2
> On May 12, 2020, at 8:23 AM, Stefan Hajnoczi <stefanha@redhat.com> wrote:
> 
> On Wed, Apr 22, 2020 at 09:13:52PM -0700, elena.ufimtseva@oracle.com wrote:
>> From: Elena Ufimtseva <elena.ufimtseva@oracle.com>
>> 
>> Defines a PCI Device proxy object as a parent of TYPE_PCI_DEVICE.
> 
> s/parent/child/
> 
>> 
>> PCI Proxy Object registers as a PCI device with QEMU and forwards all
>> PCI accesses to the remote process using the communication channel.
> 
> Please include that functionality in this patch. The code below just
> sets up a skeleton PCI device. There is no code that forwards accesses
> to the remote process.
> 
>> Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
>> Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
>> Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
>> ---
>> MAINTAINERS                   |  3 ++
>> hw/Makefile.objs              |  2 ++
>> hw/proxy/Makefile.objs        |  1 +
>> hw/proxy/qemu-proxy.c         | 56 +++++++++++++++++++++++++++++++++++
>> include/hw/proxy/qemu-proxy.h | 46 ++++++++++++++++++++++++++++
>> include/io/mpqemu-link.h      |  1 +
>> 6 files changed, 109 insertions(+)
>> create mode 100644 hw/proxy/Makefile.objs
>> create mode 100644 hw/proxy/qemu-proxy.c
>> create mode 100644 include/hw/proxy/qemu-proxy.h
>> 
>> diff --git a/MAINTAINERS b/MAINTAINERS
>> index 96f8d7ff19..3da3dcd311 100644
>> --- a/MAINTAINERS
>> +++ b/MAINTAINERS
>> @@ -2866,6 +2866,9 @@ F: include/remote/machine.h
>> F: remote/machine.c
>> F: include/remote/memory.h
>> F: remote/memory.c
>> +F: hw/proxy/Makefile.objs
>> +F: hw/proxy/qemu-proxy.c
>> +F: include/hw/proxy/qemu-proxy.h
> 
> It's a generic PCI device. hw/pci/proxy.c would be a good location for
> it.
> 
> By the way an alternative to the "proxy"/"remote" terminology is
> RemotePCIClient/RemotePCIServer. That makes it more obvious that "proxy"
> is related the "remote" feature. Feel free to keep the existing
> terminology, I just wanted to suggest another possibility.

OK, got it.

> 
>> 
>> Build and test automation
>> -------------------------
>> diff --git a/hw/Makefile.objs b/hw/Makefile.objs
>> index af9235b6f2..7b489b12a5 100644
>> --- a/hw/Makefile.objs
>> +++ b/hw/Makefile.objs
>> @@ -45,6 +45,8 @@ endif
>> common-obj-y += $(devices-dirs-y)
>> obj-y += $(devices-dirs-y)
>> 
>> +common-obj-$(CONFIG_MPQEMU) += proxy/
>> +
>> remote-pci-obj-$(CONFIG_MPQEMU) += core/
>> remote-pci-obj-$(CONFIG_MPQEMU) += block/
>> remote-pci-obj-$(CONFIG_MPQEMU) += pci/
>> diff --git a/hw/proxy/Makefile.objs b/hw/proxy/Makefile.objs
>> new file mode 100644
>> index 0000000000..eb81624cf8
>> --- /dev/null
>> +++ b/hw/proxy/Makefile.objs
>> @@ -0,0 +1 @@
>> +common-obj-$(CONFIG_MPQEMU) += qemu-proxy.o
>> diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c
>> new file mode 100644
>> index 0000000000..bf6c4117ef
>> --- /dev/null
>> +++ b/hw/proxy/qemu-proxy.c
>> @@ -0,0 +1,56 @@
>> +/*
>> + * 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 "qemu/osdep.h"
>> +#include "qemu-common.h"
>> +
>> +#include "qapi/error.h"
>> +#include "io/mpqemu-link.h"
>> +#include "hw/proxy/qemu-proxy.h"
>> +#include "hw/pci/pci.h"
>> +
>> +static void pci_proxy_dev_realize(PCIDevice *device, Error **errp)
>> +{
>> +    PCIProxyDev *dev = PCI_PROXY_DEV(device);
>> +    PCIProxyDevClass *k = PCI_PROXY_DEV_GET_CLASS(dev);
>> +    Error *local_err = NULL;
>> +
>> +    if (k->realize) {
> 
> Will anything inherit from this class? I thought this is the remote PCI
> client that can acts as a stand-in for all remote PCI devices, so it's
> not clear why it's acting as a base class here.

No one is inheriting from this class anymore. This is code from before
when that was the case. We could remove this.

> 
>> diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h
>> index d46cb81058..73cc59b874 100644
>> --- a/include/io/mpqemu-link.h
>> +++ b/include/io/mpqemu-link.h
>> @@ -14,6 +14,7 @@
>> #include "qemu/osdep.h"
>> #include "qemu-common.h"
>> 
>> +#include "sys/eventfd.h"
> 
> Why? Nothing in this patch uses this header.

OK, got it.

Thanks!
—
Jag
diff mbox series

Patch

diff --git a/MAINTAINERS b/MAINTAINERS
index 96f8d7ff19..3da3dcd311 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2866,6 +2866,9 @@  F: include/remote/machine.h
 F: remote/machine.c
 F: include/remote/memory.h
 F: remote/memory.c
+F: hw/proxy/Makefile.objs
+F: hw/proxy/qemu-proxy.c
+F: include/hw/proxy/qemu-proxy.h
 
 Build and test automation
 -------------------------
diff --git a/hw/Makefile.objs b/hw/Makefile.objs
index af9235b6f2..7b489b12a5 100644
--- a/hw/Makefile.objs
+++ b/hw/Makefile.objs
@@ -45,6 +45,8 @@  endif
 common-obj-y += $(devices-dirs-y)
 obj-y += $(devices-dirs-y)
 
+common-obj-$(CONFIG_MPQEMU) += proxy/
+
 remote-pci-obj-$(CONFIG_MPQEMU) += core/
 remote-pci-obj-$(CONFIG_MPQEMU) += block/
 remote-pci-obj-$(CONFIG_MPQEMU) += pci/
diff --git a/hw/proxy/Makefile.objs b/hw/proxy/Makefile.objs
new file mode 100644
index 0000000000..eb81624cf8
--- /dev/null
+++ b/hw/proxy/Makefile.objs
@@ -0,0 +1 @@ 
+common-obj-$(CONFIG_MPQEMU) += qemu-proxy.o
diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c
new file mode 100644
index 0000000000..bf6c4117ef
--- /dev/null
+++ b/hw/proxy/qemu-proxy.c
@@ -0,0 +1,56 @@ 
+/*
+ * 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 "qemu/osdep.h"
+#include "qemu-common.h"
+
+#include "qapi/error.h"
+#include "io/mpqemu-link.h"
+#include "hw/proxy/qemu-proxy.h"
+#include "hw/pci/pci.h"
+
+static void pci_proxy_dev_realize(PCIDevice *device, Error **errp)
+{
+    PCIProxyDev *dev = PCI_PROXY_DEV(device);
+    PCIProxyDevClass *k = PCI_PROXY_DEV_GET_CLASS(dev);
+    Error *local_err = NULL;
+
+    if (k->realize) {
+        k->realize(dev, &local_err);
+        if (local_err) {
+            error_propagate(errp, local_err);
+        }
+    }
+}
+
+static void pci_proxy_dev_class_init(ObjectClass *klass, void *data)
+{
+    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+    k->realize = pci_proxy_dev_realize;
+}
+
+static const TypeInfo pci_proxy_dev_type_info = {
+    .name          = TYPE_PCI_PROXY_DEV,
+    .parent        = TYPE_PCI_DEVICE,
+    .instance_size = sizeof(PCIProxyDev),
+    .class_size    = sizeof(PCIProxyDevClass),
+    .class_init    = pci_proxy_dev_class_init,
+    .interfaces = (InterfaceInfo[]) {
+        { INTERFACE_CONVENTIONAL_PCI_DEVICE },
+        { },
+    },
+};
+
+static void pci_proxy_dev_register_types(void)
+{
+    type_register_static(&pci_proxy_dev_type_info);
+}
+
+type_init(pci_proxy_dev_register_types)
+
diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h
new file mode 100644
index 0000000000..d7eaf26f29
--- /dev/null
+++ b/include/hw/proxy/qemu-proxy.h
@@ -0,0 +1,46 @@ 
+/*
+ * 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 QEMU_PROXY_H
+#define QEMU_PROXY_H
+
+#include "qemu/osdep.h"
+#include "qemu-common.h"
+
+#include "io/mpqemu-link.h"
+#include "hw/pci/pci.h"
+
+#define TYPE_PCI_PROXY_DEV "pci-proxy-dev"
+
+#define PCI_PROXY_DEV(obj) \
+            OBJECT_CHECK(PCIProxyDev, (obj), TYPE_PCI_PROXY_DEV)
+
+#define PCI_PROXY_DEV_CLASS(klass) \
+            OBJECT_CLASS_CHECK(PCIProxyDevClass, (klass), TYPE_PCI_PROXY_DEV)
+
+#define PCI_PROXY_DEV_GET_CLASS(obj) \
+            OBJECT_GET_CLASS(PCIProxyDevClass, (obj), TYPE_PCI_PROXY_DEV)
+
+typedef struct PCIProxyDev {
+    PCIDevice parent_dev;
+
+    MPQemuLinkState *mpqemu_link;
+
+    int socket;
+
+} PCIProxyDev;
+
+typedef struct PCIProxyDevClass {
+    PCIDeviceClass parent_class;
+
+    void (*realize)(PCIProxyDev *dev, Error **errp);
+
+    char *command;
+} PCIProxyDevClass;
+
+#endif /* QEMU_PROXY_H */
diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h
index d46cb81058..73cc59b874 100644
--- a/include/io/mpqemu-link.h
+++ b/include/io/mpqemu-link.h
@@ -14,6 +14,7 @@ 
 #include "qemu/osdep.h"
 #include "qemu-common.h"
 
+#include "sys/eventfd.h"
 #include "qom/object.h"
 #include "qemu/thread.h"
 #include "exec/cpu-common.h"