Re: [PATCH v3] accel: Move Xen accelerator code under accel/xen/

2020-05-21 Thread Paolo Bonzini
On 08/05/20 12:02, Philippe Mathieu-Daudé wrote:
> This code is not related to hardware emulation.
> Move it under accel/ with the other hypervisors.
> 
> Reviewed-by: Paul Durrant 
> Signed-off-by: Philippe Mathieu-Daudé 
> ---
> We could also move the memory management functions from
> hw/i386/xen/xen-hvm.c but it is not trivial.
> 
> v2: Use g_assert_not_reached() instead of abort()
> v3: (quintela)
>  - Do not expose xen_allowed
>  - Do not abort in xen_hvm_modified_memory
> ---
>  include/exec/ram_addr.h|  2 +-
>  include/hw/xen/xen.h   | 11 ---
>  include/sysemu/xen.h   | 38 ++
>  hw/xen/xen-common.c => accel/xen/xen-all.c |  8 +
>  hw/acpi/piix4.c|  2 +-
>  hw/i386/pc.c   |  1 +
>  hw/i386/pc_piix.c  |  1 +
>  hw/i386/pc_q35.c   |  1 +
>  hw/i386/xen/xen-hvm.c  |  1 +
>  hw/i386/xen/xen_platform.c |  1 +
>  hw/isa/piix3.c |  1 +
>  hw/pci/msix.c  |  1 +
>  migration/savevm.c |  2 +-
>  softmmu/vl.c   |  2 +-
>  stubs/xen-hvm.c|  9 -
>  target/i386/cpu.c  |  2 +-
>  MAINTAINERS|  2 ++
>  accel/Makefile.objs|  1 +
>  accel/xen/Makefile.objs|  1 +
>  hw/xen/Makefile.objs   |  2 +-
>  20 files changed, 63 insertions(+), 26 deletions(-)
>  create mode 100644 include/sysemu/xen.h
>  rename hw/xen/xen-common.c => accel/xen/xen-all.c (98%)
>  create mode 100644 accel/xen/Makefile.objs
> 
> diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
> index 5e59a3d8d7..4e05292f91 100644
> --- a/include/exec/ram_addr.h
> +++ b/include/exec/ram_addr.h
> @@ -21,7 +21,7 @@
>  
>  #ifndef CONFIG_USER_ONLY
>  #include "cpu.h"
> -#include "hw/xen/xen.h"
> +#include "sysemu/xen.h"
>  #include "sysemu/tcg.h"
>  #include "exec/ramlist.h"
>  #include "exec/ramblock.h"
> diff --git a/include/hw/xen/xen.h b/include/hw/xen/xen.h
> index 5ac1c6dc55..771dd447f2 100644
> --- a/include/hw/xen/xen.h
> +++ b/include/hw/xen/xen.h
> @@ -20,13 +20,6 @@ extern uint32_t xen_domid;
>  extern enum xen_mode xen_mode;
>  extern bool xen_domid_restrict;
>  
> -extern bool xen_allowed;
> -
> -static inline bool xen_enabled(void)
> -{
> -return xen_allowed;
> -}
> -
>  int xen_pci_slot_get_pirq(PCIDevice *pci_dev, int irq_num);
>  void xen_piix3_set_irq(void *opaque, int irq_num, int level);
>  void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int 
> len);
> @@ -39,10 +32,6 @@ void xenstore_store_pv_console_info(int i, struct Chardev 
> *chr);
>  
>  void xen_hvm_init(PCMachineState *pcms, MemoryRegion **ram_memory);
>  
> -void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size,
> -   struct MemoryRegion *mr, Error **errp);
> -void xen_hvm_modified_memory(ram_addr_t start, ram_addr_t length);
> -
>  void xen_register_framebuffer(struct MemoryRegion *mr);
>  
>  #endif /* QEMU_HW_XEN_H */
> diff --git a/include/sysemu/xen.h b/include/sysemu/xen.h
> new file mode 100644
> index 00..1ca292715e
> --- /dev/null
> +++ b/include/sysemu/xen.h
> @@ -0,0 +1,38 @@
> +/*
> + * QEMU Xen support
> + *
> + * 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 SYSEMU_XEN_H
> +#define SYSEMU_XEN_H
> +
> +#ifdef CONFIG_XEN
> +
> +bool xen_enabled(void);
> +
> +#ifndef CONFIG_USER_ONLY
> +void xen_hvm_modified_memory(ram_addr_t start, ram_addr_t length);
> +void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size,
> +   struct MemoryRegion *mr, Error **errp);
> +#endif
> +
> +#else /* !CONFIG_XEN */
> +
> +#define xen_enabled() 0
> +#ifndef CONFIG_USER_ONLY
> +static inline void xen_hvm_modified_memory(ram_addr_t start, ram_addr_t 
> length)
> +{
> +/* nothing */
> +}
> +static inline void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size,
> + MemoryRegion *mr, Error **errp)
> +{
> +g_assert_not_reached();
> +}
> +#endif
> +
> +#endif /* CONFIG_XEN */
> +
> +#endif
> diff --git a/hw/xen/xen-common.c b/accel/xen/xen-all.c
> similarity index 98%
> rename from hw/xen/xen-common.c
> rename to accel/xen/xen-all.c
> index a15070f7f6..4f22c53731 100644
> --- a/hw/xen/xen-common.c
> +++ b/accel/xen/xen-all.c
> @@ -16,6 +16,7 @@
>  #include "hw/xen/xen_pt.h"
>  #include "chardev/char.h"
>  #include "sysemu/accel.h"
> +#include "sysemu/xen.h"
>  #include "sysemu/runstate.h"
>  #include "migration/misc.h"
>  #include "migration/global_state.h"
> @@ -31,6 +32,13 @@
>  do { } while (0)
>  #endif
>  
> +static bool xen_allowed;
> +
> +bool xen_enabled(void)
> +{
> +return 

Re: [PATCH v3] accel: Move Xen accelerator code under accel/xen/

2020-05-08 Thread Juan Quintela
Philippe Mathieu-Daudé  wrote:
> This code is not related to hardware emulation.
> Move it under accel/ with the other hypervisors.
>
> Reviewed-by: Paul Durrant 
> Signed-off-by: Philippe Mathieu-Daudé 

Reviewed-by: Juan Quintela 




[PATCH v3] accel: Move Xen accelerator code under accel/xen/

2020-05-08 Thread Philippe Mathieu-Daudé
This code is not related to hardware emulation.
Move it under accel/ with the other hypervisors.

Reviewed-by: Paul Durrant 
Signed-off-by: Philippe Mathieu-Daudé 
---
We could also move the memory management functions from
hw/i386/xen/xen-hvm.c but it is not trivial.

v2: Use g_assert_not_reached() instead of abort()
v3: (quintela)
 - Do not expose xen_allowed
 - Do not abort in xen_hvm_modified_memory
---
 include/exec/ram_addr.h|  2 +-
 include/hw/xen/xen.h   | 11 ---
 include/sysemu/xen.h   | 38 ++
 hw/xen/xen-common.c => accel/xen/xen-all.c |  8 +
 hw/acpi/piix4.c|  2 +-
 hw/i386/pc.c   |  1 +
 hw/i386/pc_piix.c  |  1 +
 hw/i386/pc_q35.c   |  1 +
 hw/i386/xen/xen-hvm.c  |  1 +
 hw/i386/xen/xen_platform.c |  1 +
 hw/isa/piix3.c |  1 +
 hw/pci/msix.c  |  1 +
 migration/savevm.c |  2 +-
 softmmu/vl.c   |  2 +-
 stubs/xen-hvm.c|  9 -
 target/i386/cpu.c  |  2 +-
 MAINTAINERS|  2 ++
 accel/Makefile.objs|  1 +
 accel/xen/Makefile.objs|  1 +
 hw/xen/Makefile.objs   |  2 +-
 20 files changed, 63 insertions(+), 26 deletions(-)
 create mode 100644 include/sysemu/xen.h
 rename hw/xen/xen-common.c => accel/xen/xen-all.c (98%)
 create mode 100644 accel/xen/Makefile.objs

diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
index 5e59a3d8d7..4e05292f91 100644
--- a/include/exec/ram_addr.h
+++ b/include/exec/ram_addr.h
@@ -21,7 +21,7 @@
 
 #ifndef CONFIG_USER_ONLY
 #include "cpu.h"
-#include "hw/xen/xen.h"
+#include "sysemu/xen.h"
 #include "sysemu/tcg.h"
 #include "exec/ramlist.h"
 #include "exec/ramblock.h"
diff --git a/include/hw/xen/xen.h b/include/hw/xen/xen.h
index 5ac1c6dc55..771dd447f2 100644
--- a/include/hw/xen/xen.h
+++ b/include/hw/xen/xen.h
@@ -20,13 +20,6 @@ extern uint32_t xen_domid;
 extern enum xen_mode xen_mode;
 extern bool xen_domid_restrict;
 
-extern bool xen_allowed;
-
-static inline bool xen_enabled(void)
-{
-return xen_allowed;
-}
-
 int xen_pci_slot_get_pirq(PCIDevice *pci_dev, int irq_num);
 void xen_piix3_set_irq(void *opaque, int irq_num, int level);
 void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len);
@@ -39,10 +32,6 @@ void xenstore_store_pv_console_info(int i, struct Chardev 
*chr);
 
 void xen_hvm_init(PCMachineState *pcms, MemoryRegion **ram_memory);
 
-void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size,
-   struct MemoryRegion *mr, Error **errp);
-void xen_hvm_modified_memory(ram_addr_t start, ram_addr_t length);
-
 void xen_register_framebuffer(struct MemoryRegion *mr);
 
 #endif /* QEMU_HW_XEN_H */
diff --git a/include/sysemu/xen.h b/include/sysemu/xen.h
new file mode 100644
index 00..1ca292715e
--- /dev/null
+++ b/include/sysemu/xen.h
@@ -0,0 +1,38 @@
+/*
+ * QEMU Xen support
+ *
+ * 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 SYSEMU_XEN_H
+#define SYSEMU_XEN_H
+
+#ifdef CONFIG_XEN
+
+bool xen_enabled(void);
+
+#ifndef CONFIG_USER_ONLY
+void xen_hvm_modified_memory(ram_addr_t start, ram_addr_t length);
+void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size,
+   struct MemoryRegion *mr, Error **errp);
+#endif
+
+#else /* !CONFIG_XEN */
+
+#define xen_enabled() 0
+#ifndef CONFIG_USER_ONLY
+static inline void xen_hvm_modified_memory(ram_addr_t start, ram_addr_t length)
+{
+/* nothing */
+}
+static inline void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size,
+ MemoryRegion *mr, Error **errp)
+{
+g_assert_not_reached();
+}
+#endif
+
+#endif /* CONFIG_XEN */
+
+#endif
diff --git a/hw/xen/xen-common.c b/accel/xen/xen-all.c
similarity index 98%
rename from hw/xen/xen-common.c
rename to accel/xen/xen-all.c
index a15070f7f6..4f22c53731 100644
--- a/hw/xen/xen-common.c
+++ b/accel/xen/xen-all.c
@@ -16,6 +16,7 @@
 #include "hw/xen/xen_pt.h"
 #include "chardev/char.h"
 #include "sysemu/accel.h"
+#include "sysemu/xen.h"
 #include "sysemu/runstate.h"
 #include "migration/misc.h"
 #include "migration/global_state.h"
@@ -31,6 +32,13 @@
 do { } while (0)
 #endif
 
+static bool xen_allowed;
+
+bool xen_enabled(void)
+{
+return xen_allowed;
+}
+
 xc_interface *xen_xc;
 xenforeignmemory_handle *xen_fmem;
 xendevicemodel_handle *xen_dmod;
diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index 964d6f5990..daed273687 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -30,6 +30,7 @@
 #include "hw/acpi/acpi.h"
 #include "sysemu/runstate.h"
 #include "sysemu/sysemu.h"
+#include