* [QEMU][PATCH v3 0/2] Add Virtio support to Xenpvh machine for arm @ 2023-08-25 22:53 Vikram Garhwal 2023-08-25 22:53 ` [QEMU][PATCH v3 1/2] xen_arm: Create virtio-mmio devices during initialization Vikram Garhwal 2023-08-25 22:53 ` [QEMU][PATCH v3 2/2] xen_arm: Initialize RAM and add hi/low memory regions Vikram Garhwal 0 siblings, 2 replies; 5+ messages in thread From: Vikram Garhwal @ 2023-08-25 22:53 UTC (permalink / raw) To: qemu-devel; +Cc: sstabellini, vikram.garhwal Hi, We added virtio-mmio support in xenpvh machine. Now, it can support upto 10 virtio mmio. Changelog: v2->v3: Define GUEST_VIRTIO_*, GUEST_RAM* and xendevicemodel_set_irq() manually for old xen version. This was done to avoid build failures in gitlab-ci v1->v2: Add reference for VIRTIO_MMIO_DEV_SIZE. Update ram_size=0 print statement. Oleksandr Tyshchenko (2): xen_arm: Create virtio-mmio devices during initialization xen_arm: Initialize RAM and add hi/low memory regions hw/arm/xen_arm.c | 104 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) -- 2.17.1 ^ permalink raw reply [flat|nested] 5+ messages in thread
* [QEMU][PATCH v3 1/2] xen_arm: Create virtio-mmio devices during initialization 2023-08-25 22:53 [QEMU][PATCH v3 0/2] Add Virtio support to Xenpvh machine for arm Vikram Garhwal @ 2023-08-25 22:53 ` Vikram Garhwal 2023-08-29 0:24 ` Stefano Stabellini 2023-08-25 22:53 ` [QEMU][PATCH v3 2/2] xen_arm: Initialize RAM and add hi/low memory regions Vikram Garhwal 1 sibling, 1 reply; 5+ messages in thread From: Vikram Garhwal @ 2023-08-25 22:53 UTC (permalink / raw) To: qemu-devel; +Cc: sstabellini, vikram.garhwal, Oleksandr Tyshchenko From: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com> In order to use virtio backends we need to allocate virtio-mmio parameters (irq and base) and register corresponding buses. Use the constants defined in public header arch-arm.h to be aligned with the toolstack. So the number of current supported virtio-mmio devices is 10. For the interrupts triggering use already existing on Arm device-model hypercall. The toolstack should then insert the same amount of device nodes into guest device-tree. Signed-off-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com> Signed-off-by: Vikram Garhwal <vikram.garhwal@amd.com> --- hw/arm/xen_arm.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/hw/arm/xen_arm.c b/hw/arm/xen_arm.c index 1d3e6d481a..d1e9f7b488 100644 --- a/hw/arm/xen_arm.c +++ b/hw/arm/xen_arm.c @@ -26,6 +26,7 @@ #include "qapi/qapi-commands-migration.h" #include "qapi/visitor.h" #include "hw/boards.h" +#include "hw/irq.h" #include "hw/sysbus.h" #include "sysemu/block-backend.h" #include "sysemu/tpm_backend.h" @@ -59,6 +60,54 @@ struct XenArmState { } cfg; }; +/* + * VIRTIO_MMIO_DEV_SIZE is imported from tools/libs/light/libxl_arm.c under Xen + * repository. + * + * Origin: git://xenbits.xen.org/xen.git 2128143c114c + */ +#define VIRTIO_MMIO_DEV_SIZE 0x200 + +#define NR_VIRTIO_MMIO_DEVICES \ + (GUEST_VIRTIO_MMIO_SPI_LAST - GUEST_VIRTIO_MMIO_SPI_FIRST) + +#if CONFIG_XEN_CTRL_INTERFACE_VERSION <= 41500 +static int xendevicemodel_set_irq_level( + xendevicemodel_handle *dmod, domid_t domid, uint32_t irq, + unsigned int level) +{ + return 0; +} +#endif + +#if CONFIG_XEN_CTRL_INTERFACE_VERSION <= 41700 +#define GUEST_VIRTIO_MMIO_BASE xen_mk_ullong(0x02000000) +#define GUEST_VIRTIO_MMIO_SIZE xen_mk_ullong(0x00100000) +#define GUEST_VIRTIO_MMIO_SPI_FIRST 33 +#define GUEST_VIRTIO_MMIO_SPI_LAST 43 +#endif + +static void xen_set_irq(void *opaque, int irq, int level) +{ + xendevicemodel_set_irq_level(xen_dmod, xen_domid, irq, level); +} + +static void xen_create_virtio_mmio_devices(XenArmState *xam) +{ + int i; + + for (i = 0; i < NR_VIRTIO_MMIO_DEVICES; i++) { + hwaddr base = GUEST_VIRTIO_MMIO_BASE + i * VIRTIO_MMIO_DEV_SIZE; + qemu_irq irq = qemu_allocate_irq(xen_set_irq, NULL, + GUEST_VIRTIO_MMIO_SPI_FIRST + i); + + sysbus_create_simple("virtio-mmio", base, irq); + + DPRINTF("Created virtio-mmio device %d: irq %d base 0x%lx\n", + i, GUEST_VIRTIO_MMIO_SPI_FIRST + i, base); + } +} + void arch_handle_ioreq(XenIOState *state, ioreq_t *req) { hw_error("Invalid ioreq type 0x%x\n", req->type); @@ -110,6 +159,8 @@ static void xen_arm_init(MachineState *machine) xen_register_ioreq(xam->state, machine->smp.cpus, &xen_memory_listener); + xen_create_virtio_mmio_devices(xam); + #ifdef CONFIG_TPM if (xam->cfg.tpm_base_addr) { xen_enable_tpm(xam); -- 2.17.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [QEMU][PATCH v3 1/2] xen_arm: Create virtio-mmio devices during initialization 2023-08-25 22:53 ` [QEMU][PATCH v3 1/2] xen_arm: Create virtio-mmio devices during initialization Vikram Garhwal @ 2023-08-29 0:24 ` Stefano Stabellini 0 siblings, 0 replies; 5+ messages in thread From: Stefano Stabellini @ 2023-08-29 0:24 UTC (permalink / raw) To: Vikram Garhwal; +Cc: qemu-devel, sstabellini, Oleksandr Tyshchenko On Fri, 25 Aug 2023, Vikram Garhwal wrote: > From: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com> > > In order to use virtio backends we need to allocate virtio-mmio > parameters (irq and base) and register corresponding buses. > > Use the constants defined in public header arch-arm.h to be > aligned with the toolstack. So the number of current supported > virtio-mmio devices is 10. > > For the interrupts triggering use already existing on Arm > device-model hypercall. > > The toolstack should then insert the same amount of device nodes > into guest device-tree. > > Signed-off-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com> > Signed-off-by: Vikram Garhwal <vikram.garhwal@amd.com> > --- > hw/arm/xen_arm.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 51 insertions(+) > > diff --git a/hw/arm/xen_arm.c b/hw/arm/xen_arm.c > index 1d3e6d481a..d1e9f7b488 100644 > --- a/hw/arm/xen_arm.c > +++ b/hw/arm/xen_arm.c > @@ -26,6 +26,7 @@ > #include "qapi/qapi-commands-migration.h" > #include "qapi/visitor.h" > #include "hw/boards.h" > +#include "hw/irq.h" > #include "hw/sysbus.h" > #include "sysemu/block-backend.h" > #include "sysemu/tpm_backend.h" > @@ -59,6 +60,54 @@ struct XenArmState { > } cfg; > }; > > +/* > + * VIRTIO_MMIO_DEV_SIZE is imported from tools/libs/light/libxl_arm.c under Xen > + * repository. > + * > + * Origin: git://xenbits.xen.org/xen.git 2128143c114c > + */ > +#define VIRTIO_MMIO_DEV_SIZE 0x200 > + > +#define NR_VIRTIO_MMIO_DEVICES \ > + (GUEST_VIRTIO_MMIO_SPI_LAST - GUEST_VIRTIO_MMIO_SPI_FIRST) > + > +#if CONFIG_XEN_CTRL_INTERFACE_VERSION <= 41500 > +static int xendevicemodel_set_irq_level( > + xendevicemodel_handle *dmod, domid_t domid, uint32_t irq, > + unsigned int level) > +{ > + return 0; > +} > +#endif > + > +#if CONFIG_XEN_CTRL_INTERFACE_VERSION <= 41700 > +#define GUEST_VIRTIO_MMIO_BASE xen_mk_ullong(0x02000000) > +#define GUEST_VIRTIO_MMIO_SIZE xen_mk_ullong(0x00100000) > +#define GUEST_VIRTIO_MMIO_SPI_FIRST 33 > +#define GUEST_VIRTIO_MMIO_SPI_LAST 43 > +#endif Thanks Vikram. Please move this compat definitions to include/hw/xen/xen_native.h > +static void xen_set_irq(void *opaque, int irq, int level) > +{ > + xendevicemodel_set_irq_level(xen_dmod, xen_domid, irq, level); > +} > + > +static void xen_create_virtio_mmio_devices(XenArmState *xam) > +{ > + int i; > + > + for (i = 0; i < NR_VIRTIO_MMIO_DEVICES; i++) { > + hwaddr base = GUEST_VIRTIO_MMIO_BASE + i * VIRTIO_MMIO_DEV_SIZE; > + qemu_irq irq = qemu_allocate_irq(xen_set_irq, NULL, > + GUEST_VIRTIO_MMIO_SPI_FIRST + i); > + > + sysbus_create_simple("virtio-mmio", base, irq); > + > + DPRINTF("Created virtio-mmio device %d: irq %d base 0x%lx\n", > + i, GUEST_VIRTIO_MMIO_SPI_FIRST + i, base); > + } > +} > + > void arch_handle_ioreq(XenIOState *state, ioreq_t *req) > { > hw_error("Invalid ioreq type 0x%x\n", req->type); > @@ -110,6 +159,8 @@ static void xen_arm_init(MachineState *machine) > > xen_register_ioreq(xam->state, machine->smp.cpus, &xen_memory_listener); > > + xen_create_virtio_mmio_devices(xam); > + > #ifdef CONFIG_TPM > if (xam->cfg.tpm_base_addr) { > xen_enable_tpm(xam); > -- > 2.17.1 > ^ permalink raw reply [flat|nested] 5+ messages in thread
* [QEMU][PATCH v3 2/2] xen_arm: Initialize RAM and add hi/low memory regions 2023-08-25 22:53 [QEMU][PATCH v3 0/2] Add Virtio support to Xenpvh machine for arm Vikram Garhwal 2023-08-25 22:53 ` [QEMU][PATCH v3 1/2] xen_arm: Create virtio-mmio devices during initialization Vikram Garhwal @ 2023-08-25 22:53 ` Vikram Garhwal 2023-08-29 0:24 ` Stefano Stabellini 1 sibling, 1 reply; 5+ messages in thread From: Vikram Garhwal @ 2023-08-25 22:53 UTC (permalink / raw) To: qemu-devel; +Cc: sstabellini, vikram.garhwal, Oleksandr Tyshchenko From: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com> In order to use virtio backends we need to initialize RAM for the xen-mapcache (which is responsible for mapping guest memory using foreign mapping) to work. Calculate and add hi/low memory regions based on machine->ram_size. Use the constants defined in public header arch-arm.h to be aligned with the xen toolstack. While using this machine, the toolstack should then pass real ram_size using "-m" arg. If "-m" is not given, create a QEMU machine without IOREQ and other emulated devices like TPM and VIRTIO. This is done to keep this QEMU machine usable for /etc/init.d/xencommons. Signed-off-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com> Signed-off-by: Vikram Garhwal <vikram.garhwal@amd.com> --- hw/arm/xen_arm.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/hw/arm/xen_arm.c b/hw/arm/xen_arm.c index d1e9f7b488..aa8b6171ad 100644 --- a/hw/arm/xen_arm.c +++ b/hw/arm/xen_arm.c @@ -60,6 +60,8 @@ struct XenArmState { } cfg; }; +static MemoryRegion ram_lo, ram_hi; + /* * VIRTIO_MMIO_DEV_SIZE is imported from tools/libs/light/libxl_arm.c under Xen * repository. @@ -80,6 +82,14 @@ static int xendevicemodel_set_irq_level( } #endif +#if defined(__i386__) || defined(__x86_64__) +#define GUEST_RAM_BANKS 2 +#define GUEST_RAM0_BASE 0x40000000ULL /* 3GB of low RAM @ 1GB */ +#define GUEST_RAM0_SIZE 0xc0000000ULL +#define GUEST_RAM1_BASE 0x0200000000ULL /* 1016GB of RAM @ 8GB */ +#define GUEST_RAM1_SIZE 0xfe00000000ULL +#endif + #if CONFIG_XEN_CTRL_INTERFACE_VERSION <= 41700 #define GUEST_VIRTIO_MMIO_BASE xen_mk_ullong(0x02000000) #define GUEST_VIRTIO_MMIO_SIZE xen_mk_ullong(0x00100000) @@ -108,6 +118,39 @@ static void xen_create_virtio_mmio_devices(XenArmState *xam) } } +static void xen_init_ram(MachineState *machine) +{ + MemoryRegion *sysmem = get_system_memory(); + ram_addr_t block_len, ram_size[GUEST_RAM_BANKS]; + + if (machine->ram_size <= GUEST_RAM0_SIZE) { + ram_size[0] = machine->ram_size; + ram_size[1] = 0; + block_len = GUEST_RAM0_BASE + ram_size[0]; + } else { + ram_size[0] = GUEST_RAM0_SIZE; + ram_size[1] = machine->ram_size - GUEST_RAM0_SIZE; + block_len = GUEST_RAM1_BASE + ram_size[1]; + } + + memory_region_init_ram(&ram_memory, NULL, "xen.ram", block_len, + &error_fatal); + + memory_region_init_alias(&ram_lo, NULL, "xen.ram.lo", &ram_memory, + GUEST_RAM0_BASE, ram_size[0]); + memory_region_add_subregion(sysmem, GUEST_RAM0_BASE, &ram_lo); + DPRINTF("Initialized region xen.ram.lo: base 0x%llx size 0x%lx\n", + GUEST_RAM0_BASE, ram_size[0]); + + if (ram_size[1] > 0) { + memory_region_init_alias(&ram_hi, NULL, "xen.ram.hi", &ram_memory, + GUEST_RAM1_BASE, ram_size[1]); + memory_region_add_subregion(sysmem, GUEST_RAM1_BASE, &ram_hi); + DPRINTF("Initialized region xen.ram.hi: base 0x%llx size 0x%lx\n", + GUEST_RAM1_BASE, ram_size[1]); + } +} + void arch_handle_ioreq(XenIOState *state, ioreq_t *req) { hw_error("Invalid ioreq type 0x%x\n", req->type); @@ -157,6 +200,14 @@ static void xen_arm_init(MachineState *machine) xam->state = g_new0(XenIOState, 1); + if (machine->ram_size == 0) { + DPRINTF("ram_size not specified. QEMU machine started without IOREQ" + "(no emulated devices including Virtio)\n"); + return; + } + + xen_init_ram(machine); + xen_register_ioreq(xam->state, machine->smp.cpus, &xen_memory_listener); xen_create_virtio_mmio_devices(xam); @@ -204,6 +255,8 @@ static void xen_arm_machine_class_init(ObjectClass *oc, void *data) mc->init = xen_arm_init; mc->max_cpus = 1; mc->default_machine_opts = "accel=xen"; + /* Set explicitly here to make sure that real ram_size is passed */ + mc->default_ram_size = 0; #ifdef CONFIG_TPM object_class_property_add(oc, "tpm-base-addr", "uint64_t", -- 2.17.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [QEMU][PATCH v3 2/2] xen_arm: Initialize RAM and add hi/low memory regions 2023-08-25 22:53 ` [QEMU][PATCH v3 2/2] xen_arm: Initialize RAM and add hi/low memory regions Vikram Garhwal @ 2023-08-29 0:24 ` Stefano Stabellini 0 siblings, 0 replies; 5+ messages in thread From: Stefano Stabellini @ 2023-08-29 0:24 UTC (permalink / raw) To: Vikram Garhwal; +Cc: qemu-devel, sstabellini, Oleksandr Tyshchenko On Fri, 25 Aug 2023, Vikram Garhwal wrote: > From: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com> > > In order to use virtio backends we need to initialize RAM for the > xen-mapcache (which is responsible for mapping guest memory using foreign > mapping) to work. Calculate and add hi/low memory regions based on > machine->ram_size. > > Use the constants defined in public header arch-arm.h to be aligned with the xen > toolstack. > > While using this machine, the toolstack should then pass real ram_size using > "-m" arg. If "-m" is not given, create a QEMU machine without IOREQ and other > emulated devices like TPM and VIRTIO. This is done to keep this QEMU machine > usable for /etc/init.d/xencommons. > > Signed-off-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com> > Signed-off-by: Vikram Garhwal <vikram.garhwal@amd.com> > --- > hw/arm/xen_arm.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 53 insertions(+) > > diff --git a/hw/arm/xen_arm.c b/hw/arm/xen_arm.c > index d1e9f7b488..aa8b6171ad 100644 > --- a/hw/arm/xen_arm.c > +++ b/hw/arm/xen_arm.c > @@ -60,6 +60,8 @@ struct XenArmState { > } cfg; > }; > > +static MemoryRegion ram_lo, ram_hi; > + > /* > * VIRTIO_MMIO_DEV_SIZE is imported from tools/libs/light/libxl_arm.c under Xen > * repository. > @@ -80,6 +82,14 @@ static int xendevicemodel_set_irq_level( > } > #endif > > +#if defined(__i386__) || defined(__x86_64__) > +#define GUEST_RAM_BANKS 2 > +#define GUEST_RAM0_BASE 0x40000000ULL /* 3GB of low RAM @ 1GB */ > +#define GUEST_RAM0_SIZE 0xc0000000ULL > +#define GUEST_RAM1_BASE 0x0200000000ULL /* 1016GB of RAM @ 8GB */ > +#define GUEST_RAM1_SIZE 0xfe00000000ULL > +#endif Also here please move to include/hw/xen/xen_native.h > #if CONFIG_XEN_CTRL_INTERFACE_VERSION <= 41700 > #define GUEST_VIRTIO_MMIO_BASE xen_mk_ullong(0x02000000) > #define GUEST_VIRTIO_MMIO_SIZE xen_mk_ullong(0x00100000) > @@ -108,6 +118,39 @@ static void xen_create_virtio_mmio_devices(XenArmState *xam) > } > } > > +static void xen_init_ram(MachineState *machine) > +{ > + MemoryRegion *sysmem = get_system_memory(); > + ram_addr_t block_len, ram_size[GUEST_RAM_BANKS]; > + > + if (machine->ram_size <= GUEST_RAM0_SIZE) { > + ram_size[0] = machine->ram_size; > + ram_size[1] = 0; > + block_len = GUEST_RAM0_BASE + ram_size[0]; > + } else { > + ram_size[0] = GUEST_RAM0_SIZE; > + ram_size[1] = machine->ram_size - GUEST_RAM0_SIZE; > + block_len = GUEST_RAM1_BASE + ram_size[1]; > + } > + > + memory_region_init_ram(&ram_memory, NULL, "xen.ram", block_len, > + &error_fatal); > + > + memory_region_init_alias(&ram_lo, NULL, "xen.ram.lo", &ram_memory, > + GUEST_RAM0_BASE, ram_size[0]); > + memory_region_add_subregion(sysmem, GUEST_RAM0_BASE, &ram_lo); > + DPRINTF("Initialized region xen.ram.lo: base 0x%llx size 0x%lx\n", > + GUEST_RAM0_BASE, ram_size[0]); > + > + if (ram_size[1] > 0) { > + memory_region_init_alias(&ram_hi, NULL, "xen.ram.hi", &ram_memory, > + GUEST_RAM1_BASE, ram_size[1]); > + memory_region_add_subregion(sysmem, GUEST_RAM1_BASE, &ram_hi); > + DPRINTF("Initialized region xen.ram.hi: base 0x%llx size 0x%lx\n", > + GUEST_RAM1_BASE, ram_size[1]); > + } > +} > + > void arch_handle_ioreq(XenIOState *state, ioreq_t *req) > { > hw_error("Invalid ioreq type 0x%x\n", req->type); > @@ -157,6 +200,14 @@ static void xen_arm_init(MachineState *machine) > > xam->state = g_new0(XenIOState, 1); > > + if (machine->ram_size == 0) { > + DPRINTF("ram_size not specified. QEMU machine started without IOREQ" > + "(no emulated devices including Virtio)\n"); > + return; > + } > + > + xen_init_ram(machine); > + > xen_register_ioreq(xam->state, machine->smp.cpus, &xen_memory_listener); > > xen_create_virtio_mmio_devices(xam); > @@ -204,6 +255,8 @@ static void xen_arm_machine_class_init(ObjectClass *oc, void *data) > mc->init = xen_arm_init; > mc->max_cpus = 1; > mc->default_machine_opts = "accel=xen"; > + /* Set explicitly here to make sure that real ram_size is passed */ > + mc->default_ram_size = 0; > > #ifdef CONFIG_TPM > object_class_property_add(oc, "tpm-base-addr", "uint64_t", > -- > 2.17.1 > ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-08-29 0:25 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-08-25 22:53 [QEMU][PATCH v3 0/2] Add Virtio support to Xenpvh machine for arm Vikram Garhwal 2023-08-25 22:53 ` [QEMU][PATCH v3 1/2] xen_arm: Create virtio-mmio devices during initialization Vikram Garhwal 2023-08-29 0:24 ` Stefano Stabellini 2023-08-25 22:53 ` [QEMU][PATCH v3 2/2] xen_arm: Initialize RAM and add hi/low memory regions Vikram Garhwal 2023-08-29 0:24 ` Stefano Stabellini
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).