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, TPM and
VIRTIO to keep it 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 | 45 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
diff --git a/hw/arm/xen_arm.c b/hw/arm/xen_arm.c
index c0a93f2c9d..cc4dffee70 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;
+
#define VIRTIO_MMIO_DEV_SIZE 0x200
#define NR_VIRTIO_MMIO_DEVICES \
@@ -86,6 +88,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);
@@ -135,6 +170,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 will be started without"
+ " TPM, IOREQ and Virtio-MMIO backends\n");
+ return;
+ }
+
+ xen_init_ram(machine);
+
xen_register_ioreq(xam->state, machine->smp.cpus, xen_memory_listener);
xen_create_virtio_mmio_devices(xam);
@@ -182,6 +225,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;
printf("CHECK for NEW BUILD\n");
#ifdef CONFIG_TPM
--
2.25.1
On Thu, 29 Jun 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, TPM and
> VIRTIO to keep it 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 | 45 +++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 45 insertions(+)
>
> diff --git a/hw/arm/xen_arm.c b/hw/arm/xen_arm.c
> index c0a93f2c9d..cc4dffee70 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;
> +
> #define VIRTIO_MMIO_DEV_SIZE 0x200
>
> #define NR_VIRTIO_MMIO_DEVICES \
> @@ -86,6 +88,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);
> @@ -135,6 +170,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 will be started without"
> + " TPM, IOREQ and Virtio-MMIO backends\n");
> + return;
> + }
I would say "ram_size not specified. QEMU machine started without IOREQ
(no emulated devices including Virtio)."
We might add more devices in the future beyond Virtio and TPM. I don't
think we want to call out the whole list here.
> + xen_init_ram(machine);
> +
> xen_register_ioreq(xam->state, machine->smp.cpus, xen_memory_listener);
>
> xen_create_virtio_mmio_devices(xam);
> @@ -182,6 +225,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;
>
> printf("CHECK for NEW BUILD\n");
> #ifdef CONFIG_TPM
> --
> 2.25.1
>
Hi Vikram,
On Thu, Jun 29, 2023 at 10:43:10AM -0700, Oleksandr Tyshchenko wrote:
[...]
> void arch_handle_ioreq(XenIOState *state, ioreq_t *req)
> {
> hw_error("Invalid ioreq type 0x%x\n", req->type);
> @@ -135,6 +170,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 will be started without"
> + " TPM, IOREQ and Virtio-MMIO backends\n");
> + return;
> + }
> +
> + xen_init_ram(machine);
> +
> xen_register_ioreq(xam->state, machine->smp.cpus, xen_memory_listener);
>
> xen_create_virtio_mmio_devices(xam);
> @@ -182,6 +225,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;
This patch fails to apply on my side on QEMU 8.0.0.
> printf("CHECK for NEW BUILD\n");
The printf sentence is introduced unexpectly, right?
Thanks,
Leo
> #ifdef CONFIG_TPM
> --
> 2.25.1
HI Leo,
On 7/2/23 11:14 PM, Leo Yan wrote:
> Hi Vikram,
>
> On Thu, Jun 29, 2023 at 10:43:10AM -0700, Oleksandr Tyshchenko wrote:
>
> [...]
>
>> void arch_handle_ioreq(XenIOState *state, ioreq_t *req)
>> {
>> hw_error("Invalid ioreq type 0x%x\n", req->type);
>> @@ -135,6 +170,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 will be started without"
>> + " TPM, IOREQ and Virtio-MMIO backends\n");
>> + return;
>> + }
>> +
>> + xen_init_ram(machine);
>> +
>> xen_register_ioreq(xam->state, machine->smp.cpus, xen_memory_listener);
>>
>> xen_create_virtio_mmio_devices(xam);
>> @@ -182,6 +225,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;
> This patch fails to apply on my side on QEMU 8.0.0.
>
>> printf("CHECK for NEW BUILD\n");
> The printf sentence is introduced unexpectly, right?
I will rebase it with latest and resend v2.
Thank you!
>
> Thanks,
> Leo
>
>> #ifdef CONFIG_TPM
>> --
>> 2.25.1
© 2016 - 2026 Red Hat, Inc.