summaryrefslogtreecommitdiffstats
path: root/meta-xilinx-virtualization
diff options
context:
space:
mode:
authorSandeep Gundlupet Raju <sandeep.gundlupet-raju@amd.com>2024-01-19 13:41:59 -0700
committerMark Hatle <mark.hatle@amd.com>2024-01-22 16:31:41 -0700
commitc192fca9f62b732b5abde4c3633b13e839d654dc (patch)
tree695ca142836556ee1ce40e70c18edd4d3352925f /meta-xilinx-virtualization
parentd1d32d3b7b052823dda679e11749678bf6eb9fab (diff)
downloadmeta-xilinx-c192fca9f62b732b5abde4c3633b13e839d654dc.tar.gz
qemu: Add Xen 4.18 patches
Add Xen 4.18 patches and limit patches to target recipes only. Signed-off-by: Sandeep Gundlupet Raju <sandeep.gundlupet-raju@amd.com> Signed-off-by: Mark Hatle <mark.hatle@amd.com>
Diffstat (limited to 'meta-xilinx-virtualization')
-rw-r--r--meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xen_8.1.inc19
-rw-r--r--meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0001-xen_arm-Create-virtio-mmio-devices-during-initializa.patch116
-rw-r--r--meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0002-xen_arm-Initialize-RAM-and-add-hi-low-memory-regions.patch124
-rw-r--r--meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0003-Xen-Fix-xen_set_irq-and-xendevicemodel_set_irq_level.patch55
-rw-r--r--meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0004-xen-when-unplugging-emulated-devices-skip-virtio-dev.patch70
-rw-r--r--meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0005-softmmu-physmem-Split-ram_block_add.patch117
-rw-r--r--meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0006-xen-add-pseudo-RAM-region-for-grant-mappings.patch153
-rw-r--r--meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0007-softmmu-let-qemu_map_ram_ptr-use-qemu_ram_ptr_length.patch117
-rw-r--r--meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0008-xen-let-xen_ram_addr_from_mapcache-return-1-in-case-.patch49
-rw-r--r--meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0009-memory-add-MemoryRegion-map-and-unmap-callbacks.patch155
-rw-r--r--meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0010-xen-add-map-and-unmap-callbacks-for-grant-region.patch262
-rw-r--r--meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0011-hw-arm-Add-grant-mapping.patch30
-rw-r--r--meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx_2024%.bbappend2
-rw-r--r--meta-xilinx-virtualization/recipes-devtools/qemu/qemu_8.1%.bbappend4
14 files changed, 1270 insertions, 3 deletions
diff --git a/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xen_8.1.inc b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xen_8.1.inc
new file mode 100644
index 00000000..3cf6dae7
--- /dev/null
+++ b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xen_8.1.inc
@@ -0,0 +1,19 @@
1# Xen-4.18 specific changes are only applicable on the target
2SRC_URI_XEN = ""
3SRC_URI_XEN:class-target = " \
4 file://0001-xen_arm-Create-virtio-mmio-devices-during-initializa.patch \
5 file://0002-xen_arm-Initialize-RAM-and-add-hi-low-memory-regions.patch \
6 file://0003-Xen-Fix-xen_set_irq-and-xendevicemodel_set_irq_level.patch \
7 file://0004-xen-when-unplugging-emulated-devices-skip-virtio-dev.patch \
8 file://0005-softmmu-physmem-Split-ram_block_add.patch \
9 file://0006-xen-add-pseudo-RAM-region-for-grant-mappings.patch \
10 file://0007-softmmu-let-qemu_map_ram_ptr-use-qemu_ram_ptr_length.patch \
11 file://0008-xen-let-xen_ram_addr_from_mapcache-return-1-in-case-.patch \
12 file://0009-memory-add-MemoryRegion-map-and-unmap-callbacks.patch \
13 file://0010-xen-add-map-and-unmap-callbacks-for-grant-region.patch \
14 file://0011-hw-arm-Add-grant-mapping.patch \
15 "
16
17FILESEXTRAPATHS:prepend:class-target := "${THISDIR}/qemu-xilinx-8.1:"
18
19SRC_URI .= "${@bb.utils.contains('DISTRO_FEATURES', 'xen', '${SRC_URI_XEN}', '', d)}"
diff --git a/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0001-xen_arm-Create-virtio-mmio-devices-during-initializa.patch b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0001-xen_arm-Create-virtio-mmio-devices-during-initializa.patch
new file mode 100644
index 00000000..1757e9e2
--- /dev/null
+++ b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0001-xen_arm-Create-virtio-mmio-devices-during-initializa.patch
@@ -0,0 +1,116 @@
1From b9291457ca2eb4340c71d2eed08fde83916c9fa4 Mon Sep 17 00:00:00 2001
2From: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
3Date: Tue, 29 Aug 2023 21:35:17 -0700
4Subject: [PATCH 01/11] xen_arm: Create virtio-mmio devices during
5 initialization
6
7In order to use virtio backends we need to allocate virtio-mmio
8parameters (irq and base) and register corresponding buses.
9
10Use the constants defined in public header arch-arm.h to be
11aligned with the toolstack. So the number of current supported
12virtio-mmio devices is 10.
13
14For the interrupts triggering use already existing on Arm
15device-model hypercall.
16
17The toolstack should then insert the same amount of device nodes
18into guest device-tree.
19
20Signed-off-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
21Signed-off-by: Vikram Garhwal <vikram.garhwal@amd.com>
22Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
23Signed-off-by: Stefano Stabellini <stefano.stabellini@amd.com>
24---
25 hw/arm/xen_arm.c | 35 +++++++++++++++++++++++++++++++++++
26 include/hw/xen/xen_native.h | 16 ++++++++++++++++
27 2 files changed, 51 insertions(+)
28
29diff --git a/hw/arm/xen_arm.c b/hw/arm/xen_arm.c
30index 1d3e6d481a..7393b37355 100644
31--- a/hw/arm/xen_arm.c
32+++ b/hw/arm/xen_arm.c
33@@ -26,6 +26,7 @@
34 #include "qapi/qapi-commands-migration.h"
35 #include "qapi/visitor.h"
36 #include "hw/boards.h"
37+#include "hw/irq.h"
38 #include "hw/sysbus.h"
39 #include "sysemu/block-backend.h"
40 #include "sysemu/tpm_backend.h"
41@@ -59,6 +60,38 @@ struct XenArmState {
42 } cfg;
43 };
44
45+/*
46+ * VIRTIO_MMIO_DEV_SIZE is imported from tools/libs/light/libxl_arm.c under Xen
47+ * repository.
48+ *
49+ * Origin: git://xenbits.xen.org/xen.git 2128143c114c
50+ */
51+#define VIRTIO_MMIO_DEV_SIZE 0x200
52+
53+#define NR_VIRTIO_MMIO_DEVICES \
54+ (GUEST_VIRTIO_MMIO_SPI_LAST - GUEST_VIRTIO_MMIO_SPI_FIRST)
55+
56+static void xen_set_irq(void *opaque, int irq, int level)
57+{
58+ xendevicemodel_set_irq_level(xen_dmod, xen_domid, irq, level);
59+}
60+
61+static void xen_create_virtio_mmio_devices(XenArmState *xam)
62+{
63+ int i;
64+
65+ for (i = 0; i < NR_VIRTIO_MMIO_DEVICES; i++) {
66+ hwaddr base = GUEST_VIRTIO_MMIO_BASE + i * VIRTIO_MMIO_DEV_SIZE;
67+ qemu_irq irq = qemu_allocate_irq(xen_set_irq, NULL,
68+ GUEST_VIRTIO_MMIO_SPI_FIRST + i);
69+
70+ sysbus_create_simple("virtio-mmio", base, irq);
71+
72+ DPRINTF("Created virtio-mmio device %d: irq %d base 0x%lx\n",
73+ i, GUEST_VIRTIO_MMIO_SPI_FIRST + i, base);
74+ }
75+}
76+
77 void arch_handle_ioreq(XenIOState *state, ioreq_t *req)
78 {
79 hw_error("Invalid ioreq type 0x%x\n", req->type);
80@@ -110,6 +143,8 @@ static void xen_arm_init(MachineState *machine)
81
82 xen_register_ioreq(xam->state, machine->smp.cpus, &xen_memory_listener);
83
84+ xen_create_virtio_mmio_devices(xam);
85+
86 #ifdef CONFIG_TPM
87 if (xam->cfg.tpm_base_addr) {
88 xen_enable_tpm(xam);
89diff --git a/include/hw/xen/xen_native.h b/include/hw/xen/xen_native.h
90index 4dce905fde..a4b1aa9e5d 100644
91--- a/include/hw/xen/xen_native.h
92+++ b/include/hw/xen/xen_native.h
93@@ -523,4 +523,20 @@ static inline int xen_set_ioreq_server_state(domid_t dom,
94 enable);
95 }
96
97+#if CONFIG_XEN_CTRL_INTERFACE_VERSION <= 41500
98+static inline int xendevicemodel_set_irq_level(xendevicemodel_handle *dmod,
99+ domid_t domid, uint32_t irq,
100+ unsigned int level)
101+{
102+ return 0;
103+}
104+#endif
105+
106+#if CONFIG_XEN_CTRL_INTERFACE_VERSION <= 41700
107+#define GUEST_VIRTIO_MMIO_BASE xen_mk_ullong(0x02000000)
108+#define GUEST_VIRTIO_MMIO_SIZE xen_mk_ullong(0x00100000)
109+#define GUEST_VIRTIO_MMIO_SPI_FIRST 33
110+#define GUEST_VIRTIO_MMIO_SPI_LAST 43
111+#endif
112+
113 #endif /* QEMU_HW_XEN_NATIVE_H */
114--
1152.39.2
116
diff --git a/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0002-xen_arm-Initialize-RAM-and-add-hi-low-memory-regions.patch b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0002-xen_arm-Initialize-RAM-and-add-hi-low-memory-regions.patch
new file mode 100644
index 00000000..f88db620
--- /dev/null
+++ b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0002-xen_arm-Initialize-RAM-and-add-hi-low-memory-regions.patch
@@ -0,0 +1,124 @@
1From 70a74795c5071bf591e6e557b7c8c492ead0e675 Mon Sep 17 00:00:00 2001
2From: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
3Date: Tue, 29 Aug 2023 21:35:18 -0700
4Subject: [PATCH 02/11] xen_arm: Initialize RAM and add hi/low memory regions
5
6In order to use virtio backends we need to initialize RAM for the
7xen-mapcache (which is responsible for mapping guest memory using foreign
8mapping) to work. Calculate and add hi/low memory regions based on
9machine->ram_size.
10
11Use the constants defined in public header arch-arm.h to be aligned with the xen
12toolstack.
13
14While using this machine, the toolstack should then pass real ram_size using
15"-m" arg. If "-m" is not given, create a QEMU machine without IOREQ and other
16emulated devices like TPM and VIRTIO. This is done to keep this QEMU machine
17usable for /etc/init.d/xencommons.
18
19Signed-off-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
20Signed-off-by: Vikram Garhwal <vikram.garhwal@amd.com>
21Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
22Signed-off-by: Stefano Stabellini <stefano.stabellini@amd.com>
23---
24 hw/arm/xen_arm.c | 45 +++++++++++++++++++++++++++++++++++++
25 include/hw/xen/xen_native.h | 8 +++++++
26 2 files changed, 53 insertions(+)
27
28diff --git a/hw/arm/xen_arm.c b/hw/arm/xen_arm.c
29index 7393b37355..f83b983ec5 100644
30--- a/hw/arm/xen_arm.c
31+++ b/hw/arm/xen_arm.c
32@@ -60,6 +60,8 @@ struct XenArmState {
33 } cfg;
34 };
35
36+static MemoryRegion ram_lo, ram_hi;
37+
38 /*
39 * VIRTIO_MMIO_DEV_SIZE is imported from tools/libs/light/libxl_arm.c under Xen
40 * repository.
41@@ -92,6 +94,39 @@ static void xen_create_virtio_mmio_devices(XenArmState *xam)
42 }
43 }
44
45+static void xen_init_ram(MachineState *machine)
46+{
47+ MemoryRegion *sysmem = get_system_memory();
48+ ram_addr_t block_len, ram_size[GUEST_RAM_BANKS];
49+
50+ if (machine->ram_size <= GUEST_RAM0_SIZE) {
51+ ram_size[0] = machine->ram_size;
52+ ram_size[1] = 0;
53+ block_len = GUEST_RAM0_BASE + ram_size[0];
54+ } else {
55+ ram_size[0] = GUEST_RAM0_SIZE;
56+ ram_size[1] = machine->ram_size - GUEST_RAM0_SIZE;
57+ block_len = GUEST_RAM1_BASE + ram_size[1];
58+ }
59+
60+ memory_region_init_ram(&ram_memory, NULL, "xen.ram", block_len,
61+ &error_fatal);
62+
63+ memory_region_init_alias(&ram_lo, NULL, "xen.ram.lo", &ram_memory,
64+ GUEST_RAM0_BASE, ram_size[0]);
65+ memory_region_add_subregion(sysmem, GUEST_RAM0_BASE, &ram_lo);
66+ DPRINTF("Initialized region xen.ram.lo: base 0x%llx size 0x%lx\n",
67+ GUEST_RAM0_BASE, ram_size[0]);
68+
69+ if (ram_size[1] > 0) {
70+ memory_region_init_alias(&ram_hi, NULL, "xen.ram.hi", &ram_memory,
71+ GUEST_RAM1_BASE, ram_size[1]);
72+ memory_region_add_subregion(sysmem, GUEST_RAM1_BASE, &ram_hi);
73+ DPRINTF("Initialized region xen.ram.hi: base 0x%llx size 0x%lx\n",
74+ GUEST_RAM1_BASE, ram_size[1]);
75+ }
76+}
77+
78 void arch_handle_ioreq(XenIOState *state, ioreq_t *req)
79 {
80 hw_error("Invalid ioreq type 0x%x\n", req->type);
81@@ -141,6 +176,14 @@ static void xen_arm_init(MachineState *machine)
82
83 xam->state = g_new0(XenIOState, 1);
84
85+ if (machine->ram_size == 0) {
86+ DPRINTF("ram_size not specified. QEMU machine started without IOREQ"
87+ "(no emulated devices including Virtio)\n");
88+ return;
89+ }
90+
91+ xen_init_ram(machine);
92+
93 xen_register_ioreq(xam->state, machine->smp.cpus, &xen_memory_listener);
94
95 xen_create_virtio_mmio_devices(xam);
96@@ -188,6 +231,8 @@ static void xen_arm_machine_class_init(ObjectClass *oc, void *data)
97 mc->init = xen_arm_init;
98 mc->max_cpus = 1;
99 mc->default_machine_opts = "accel=xen";
100+ /* Set explicitly here to make sure that real ram_size is passed */
101+ mc->default_ram_size = 0;
102
103 #ifdef CONFIG_TPM
104 object_class_property_add(oc, "tpm-base-addr", "uint64_t",
105diff --git a/include/hw/xen/xen_native.h b/include/hw/xen/xen_native.h
106index a4b1aa9e5d..5d2718261f 100644
107--- a/include/hw/xen/xen_native.h
108+++ b/include/hw/xen/xen_native.h
109@@ -539,4 +539,12 @@ static inline int xendevicemodel_set_irq_level(xendevicemodel_handle *dmod,
110 #define GUEST_VIRTIO_MMIO_SPI_LAST 43
111 #endif
112
113+#if defined(__i386__) || defined(__x86_64__)
114+#define GUEST_RAM_BANKS 2
115+#define GUEST_RAM0_BASE 0x40000000ULL /* 3GB of low RAM @ 1GB */
116+#define GUEST_RAM0_SIZE 0xc0000000ULL
117+#define GUEST_RAM1_BASE 0x0200000000ULL /* 1016GB of RAM @ 8GB */
118+#define GUEST_RAM1_SIZE 0xfe00000000ULL
119+#endif
120+
121 #endif /* QEMU_HW_XEN_NATIVE_H */
122--
1232.39.2
124
diff --git a/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0003-Xen-Fix-xen_set_irq-and-xendevicemodel_set_irq_level.patch b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0003-Xen-Fix-xen_set_irq-and-xendevicemodel_set_irq_level.patch
new file mode 100644
index 00000000..c6945d54
--- /dev/null
+++ b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0003-Xen-Fix-xen_set_irq-and-xendevicemodel_set_irq_level.patch
@@ -0,0 +1,55 @@
1From 14b9dbd7f0261ae7a36bef251924ba211beef17a Mon Sep 17 00:00:00 2001
2From: Vikram Garhwal <vikram.garhwal@amd.com>
3Date: Wed, 1 Nov 2023 14:07:23 -0700
4Subject: [PATCH 03/11] Xen: Fix xen_set_irq() and
5 xendevicemodel_set_irq_level()
6
7Remove '=' from 'if CONFIG_XEN_CTRL_INTERFACE_VERSION <= 41500'.
8Because xendevicemodel_set_irq_level() was introduced in 4.15 version.
9
10Also, update xendevicemodel_set_irq_level() to return -1 for older versions.
11
12Signed-off-by: Vikram Garhwal <vikram.garhwal@amd.com>
13Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
14---
15 hw/arm/xen_arm.c | 4 +++-
16 include/hw/xen/xen_native.h | 4 ++--
17 2 files changed, 5 insertions(+), 3 deletions(-)
18
19diff --git a/hw/arm/xen_arm.c b/hw/arm/xen_arm.c
20index f83b983ec5..a5631529d0 100644
21--- a/hw/arm/xen_arm.c
22+++ b/hw/arm/xen_arm.c
23@@ -75,7 +75,9 @@ static MemoryRegion ram_lo, ram_hi;
24
25 static void xen_set_irq(void *opaque, int irq, int level)
26 {
27- xendevicemodel_set_irq_level(xen_dmod, xen_domid, irq, level);
28+ if (xendevicemodel_set_irq_level(xen_dmod, xen_domid, irq, level)) {
29+ error_report("xendevicemodel_set_irq_level failed");
30+ }
31 }
32
33 static void xen_create_virtio_mmio_devices(XenArmState *xam)
34diff --git a/include/hw/xen/xen_native.h b/include/hw/xen/xen_native.h
35index 5d2718261f..6f09c48823 100644
36--- a/include/hw/xen/xen_native.h
37+++ b/include/hw/xen/xen_native.h
38@@ -523,12 +523,12 @@ static inline int xen_set_ioreq_server_state(domid_t dom,
39 enable);
40 }
41
42-#if CONFIG_XEN_CTRL_INTERFACE_VERSION <= 41500
43+#if CONFIG_XEN_CTRL_INTERFACE_VERSION < 41500
44 static inline int xendevicemodel_set_irq_level(xendevicemodel_handle *dmod,
45 domid_t domid, uint32_t irq,
46 unsigned int level)
47 {
48- return 0;
49+ return -1;
50 }
51 #endif
52
53--
542.39.2
55
diff --git a/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0004-xen-when-unplugging-emulated-devices-skip-virtio-dev.patch b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0004-xen-when-unplugging-emulated-devices-skip-virtio-dev.patch
new file mode 100644
index 00000000..da2f042b
--- /dev/null
+++ b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0004-xen-when-unplugging-emulated-devices-skip-virtio-dev.patch
@@ -0,0 +1,70 @@
1From 02507086b3ad9beb9c669aae54fcb4857cd61ef8 Mon Sep 17 00:00:00 2001
2From: Juergen Gross <jgross@suse.com>
3Date: Tue, 16 Mar 2021 14:00:33 +0100
4Subject: [PATCH 04/11] xen: when unplugging emulated devices skip virtio
5 devices
6
7Virtio devices should never be unplugged at boot time, as they are
8similar to pci passthrough devices.
9
10Signed-off-by: Juergen Gross <jgross@suse.com>
11Signed-off-by: Vikram Garhwal <vikram.garhwal@amd.com>
12---
13 docs/system/i386/xen.rst | 3 ---
14 hw/i386/xen/xen_platform.c | 10 ++++++++--
15 2 files changed, 8 insertions(+), 5 deletions(-)
16
17diff --git a/docs/system/i386/xen.rst b/docs/system/i386/xen.rst
18index f06765e88c..b86d57af6e 100644
19--- a/docs/system/i386/xen.rst
20+++ b/docs/system/i386/xen.rst
21@@ -52,9 +52,6 @@ It is necessary to use the pc machine type, as the q35 machine uses AHCI instead
22 of legacy IDE, and AHCI disks are not unplugged through the Xen PV unplug
23 mechanism.
24
25-VirtIO devices can also be used; Linux guests may need to be dissuaded from
26-umplugging them by adding 'xen_emul_unplug=never' on their command line.
27-
28 Properties
29 ----------
30
31diff --git a/hw/i386/xen/xen_platform.c b/hw/i386/xen/xen_platform.c
32index 17457ff3de..0187b73eeb 100644
33--- a/hw/i386/xen/xen_platform.c
34+++ b/hw/i386/xen/xen_platform.c
35@@ -28,6 +28,7 @@
36 #include "hw/ide/pci.h"
37 #include "hw/pci/pci.h"
38 #include "migration/vmstate.h"
39+#include "hw/virtio/virtio-bus.h"
40 #include "net/net.h"
41 #include "trace.h"
42 #include "sysemu/xen.h"
43@@ -129,10 +130,11 @@ static bool pci_device_is_passthrough(PCIDevice *d)
44
45 static void unplug_nic(PCIBus *b, PCIDevice *d, void *o)
46 {
47- /* We have to ignore passthrough devices */
48+ /* We have to ignore passthrough devices and virtio devices. */
49 if (pci_get_word(d->config + PCI_CLASS_DEVICE) ==
50 PCI_CLASS_NETWORK_ETHERNET
51- && !pci_device_is_passthrough(d)) {
52+ && !pci_device_is_passthrough(d)
53+ && !qdev_get_child_bus(&d->qdev, TYPE_VIRTIO_BUS)) {
54 object_unparent(OBJECT(d));
55 }
56 }
57@@ -208,6 +210,10 @@ static void unplug_disks(PCIBus *b, PCIDevice *d, void *opaque)
58 /* We have to ignore passthrough devices */
59 if (pci_device_is_passthrough(d))
60 return;
61+ /* Ignore virtio devices */
62+ if (qdev_get_child_bus(&d->qdev, TYPE_VIRTIO_BUS)) {
63+ return;
64+ }
65
66 switch (pci_get_word(d->config + PCI_CLASS_DEVICE)) {
67 case PCI_CLASS_STORAGE_IDE:
68--
692.39.2
70
diff --git a/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0005-softmmu-physmem-Split-ram_block_add.patch b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0005-softmmu-physmem-Split-ram_block_add.patch
new file mode 100644
index 00000000..3c39dd19
--- /dev/null
+++ b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0005-softmmu-physmem-Split-ram_block_add.patch
@@ -0,0 +1,117 @@
1From d4774a0e5e1ebed605c5d49e81433fd371d0b680 Mon Sep 17 00:00:00 2001
2From: Vikram Garhwal <vikram.garhwal@amd.com>
3Date: Tue, 17 Oct 2023 20:22:26 +0000
4Subject: [PATCH 05/11] softmmu: physmem: Split ram_block_add()
5
6Extract ram block list update to a new function ram_block_add_list(). This is
7done to support grant mappings which adds a memory region for granted memory and
8updates the ram_block list.
9
10Signed-off-by: Juergen Gross <jgross@suse.com>
11Signed-off-by: Vikram Garhwal <vikram.garhwal@amd.com>
12Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
13---
14 include/exec/ram_addr.h | 1 +
15 softmmu/physmem.c | 62 ++++++++++++++++++++++++++---------------
16 2 files changed, 40 insertions(+), 23 deletions(-)
17
18diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
19index 9f2e3893f5..76fa360463 100644
20--- a/include/exec/ram_addr.h
21+++ b/include/exec/ram_addr.h
22@@ -139,6 +139,7 @@ void qemu_ram_free(RAMBlock *block);
23 int qemu_ram_resize(RAMBlock *block, ram_addr_t newsize, Error **errp);
24
25 void qemu_ram_msync(RAMBlock *block, ram_addr_t start, ram_addr_t length);
26+void ram_block_add_list(RAMBlock *new_block);
27
28 /* Clear whole block of mem */
29 static inline void qemu_ram_block_writeback(RAMBlock *block)
30diff --git a/softmmu/physmem.c b/softmmu/physmem.c
31index 3df73542e1..f73629733e 100644
32--- a/softmmu/physmem.c
33+++ b/softmmu/physmem.c
34@@ -1786,12 +1786,47 @@ static void dirty_memory_extend(ram_addr_t old_ram_size,
35 }
36 }
37
38+static void ram_block_add_list_locked(RAMBlock *new_block)
39+ {
40+ RAMBlock *block;
41+ RAMBlock *last_block = NULL;
42+
43+ /*
44+ * Keep the list sorted from biggest to smallest block. Unlike QTAILQ,
45+ * QLIST (which has an RCU-friendly variant) does not have insertion at
46+ * tail, so save the last element in last_block.
47+ */
48+ RAMBLOCK_FOREACH(block) {
49+ last_block = block;
50+ if (block->max_length < new_block->max_length) {
51+ break;
52+ }
53+ }
54+ if (block) {
55+ QLIST_INSERT_BEFORE_RCU(block, new_block, next);
56+ } else if (last_block) {
57+ QLIST_INSERT_AFTER_RCU(last_block, new_block, next);
58+ } else { /* list is empty */
59+ QLIST_INSERT_HEAD_RCU(&ram_list.blocks, new_block, next);
60+ }
61+ ram_list.mru_block = NULL;
62+
63+ /* Write list before version */
64+ smp_wmb();
65+ ram_list.version++;
66+}
67+
68+void ram_block_add_list(RAMBlock *new_block)
69+{
70+ qemu_mutex_lock_ramlist();
71+ ram_block_add_list_locked(new_block);
72+ qemu_mutex_unlock_ramlist();
73+}
74+
75 static void ram_block_add(RAMBlock *new_block, Error **errp)
76 {
77 const bool noreserve = qemu_ram_is_noreserve(new_block);
78 const bool shared = qemu_ram_is_shared(new_block);
79- RAMBlock *block;
80- RAMBlock *last_block = NULL;
81 ram_addr_t old_ram_size, new_ram_size;
82 Error *err = NULL;
83
84@@ -1829,28 +1864,9 @@ static void ram_block_add(RAMBlock *new_block, Error **errp)
85 if (new_ram_size > old_ram_size) {
86 dirty_memory_extend(old_ram_size, new_ram_size);
87 }
88- /* Keep the list sorted from biggest to smallest block. Unlike QTAILQ,
89- * QLIST (which has an RCU-friendly variant) does not have insertion at
90- * tail, so save the last element in last_block.
91- */
92- RAMBLOCK_FOREACH(block) {
93- last_block = block;
94- if (block->max_length < new_block->max_length) {
95- break;
96- }
97- }
98- if (block) {
99- QLIST_INSERT_BEFORE_RCU(block, new_block, next);
100- } else if (last_block) {
101- QLIST_INSERT_AFTER_RCU(last_block, new_block, next);
102- } else { /* list is empty */
103- QLIST_INSERT_HEAD_RCU(&ram_list.blocks, new_block, next);
104- }
105- ram_list.mru_block = NULL;
106+
107+ ram_block_add_list_locked(new_block);
108
109- /* Write list before version */
110- smp_wmb();
111- ram_list.version++;
112 qemu_mutex_unlock_ramlist();
113
114 cpu_physical_memory_set_dirty_range(new_block->offset,
115--
1162.39.2
117
diff --git a/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0006-xen-add-pseudo-RAM-region-for-grant-mappings.patch b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0006-xen-add-pseudo-RAM-region-for-grant-mappings.patch
new file mode 100644
index 00000000..a43748fe
--- /dev/null
+++ b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0006-xen-add-pseudo-RAM-region-for-grant-mappings.patch
@@ -0,0 +1,153 @@
1From 637d10471fef76a7ab0e8f5631ea3c85ff5ce9db Mon Sep 17 00:00:00 2001
2From: Juergen Gross <jgross@suse.com>
3Date: Thu, 20 May 2021 11:19:58 +0200
4Subject: [PATCH 06/11] xen: add pseudo RAM region for grant mappings
5
6Add a memory region which can be used to automatically map granted
7memory. It is starting at 0x8000000000000000ULL in order to be able to
8distinguish it from normal RAM.
9
10For this reason the xen.ram memory region is expanded, which has no
11further impact as it is used just as a container of the real RAM
12regions and now the grant region.
13
14Signed-off-by: Juergen Gross <jgross@suse.com>
15Signed-off-by: Vikram Garhwal <vikram.garhwal@amd.com>
16Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
17---
18 hw/i386/xen/xen-hvm.c | 3 +++
19 hw/xen/xen-hvm-common.c | 4 ++--
20 hw/xen/xen-mapcache.c | 27 +++++++++++++++++++++++++++
21 include/hw/xen/xen-hvm-common.h | 2 ++
22 include/hw/xen/xen_pvdev.h | 3 +++
23 include/sysemu/xen-mapcache.h | 3 +++
24 6 files changed, 40 insertions(+), 2 deletions(-)
25
26diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c
27index f42621e674..67a55558a6 100644
28--- a/hw/i386/xen/xen-hvm.c
29+++ b/hw/i386/xen/xen-hvm.c
30@@ -172,6 +172,9 @@ static void xen_ram_init(PCMachineState *pcms,
31 x86ms->above_4g_mem_size);
32 memory_region_add_subregion(sysmem, 0x100000000ULL, &ram_hi);
33 }
34+
35+ /* Add grant mappings as a pseudo RAM region. */
36+ ram_grants = *xen_init_grant_ram();
37 }
38
39 static XenPhysmap *get_physmapping(hwaddr start_addr, ram_addr_t size)
40diff --git a/hw/xen/xen-hvm-common.c b/hw/xen/xen-hvm-common.c
41index 565dc39c8f..b7255977a5 100644
42--- a/hw/xen/xen-hvm-common.c
43+++ b/hw/xen/xen-hvm-common.c
44@@ -9,7 +9,7 @@
45 #include "hw/boards.h"
46 #include "hw/xen/arch_hvm.h"
47
48-MemoryRegion ram_memory;
49+MemoryRegion ram_memory, ram_grants;
50
51 void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, MemoryRegion *mr,
52 Error **errp)
53@@ -26,7 +26,7 @@ void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, MemoryRegion *mr,
54 return;
55 }
56
57- if (mr == &ram_memory) {
58+ if (mr == &ram_memory || mr == &ram_grants) {
59 return;
60 }
61
62diff --git a/hw/xen/xen-mapcache.c b/hw/xen/xen-mapcache.c
63index f7d974677d..8115c44c00 100644
64--- a/hw/xen/xen-mapcache.c
65+++ b/hw/xen/xen-mapcache.c
66@@ -14,7 +14,9 @@
67
68 #include <sys/resource.h>
69
70+#include "hw/xen/xen-hvm-common.h"
71 #include "hw/xen/xen_native.h"
72+#include "hw/xen/xen_pvdev.h"
73 #include "qemu/bitmap.h"
74
75 #include "sysemu/runstate.h"
76@@ -597,3 +599,28 @@ uint8_t *xen_replace_cache_entry(hwaddr old_phys_addr,
77 mapcache_unlock();
78 return p;
79 }
80+
81+MemoryRegion *xen_init_grant_ram(void)
82+{
83+ RAMBlock *block;
84+
85+ memory_region_init(&ram_grants, NULL, "xen.grants",
86+ XEN_MAX_VIRTIO_GRANTS * XC_PAGE_SIZE);
87+ block = g_malloc0(sizeof(*block));
88+ block->mr = &ram_grants;
89+ block->used_length = XEN_MAX_VIRTIO_GRANTS * XC_PAGE_SIZE;
90+ block->max_length = XEN_MAX_VIRTIO_GRANTS * XC_PAGE_SIZE;
91+ block->fd = -1;
92+ block->page_size = XC_PAGE_SIZE;
93+ block->host = (void *)XEN_GRANT_ADDR_OFF;
94+ block->offset = XEN_GRANT_ADDR_OFF;
95+ block->flags = RAM_PREALLOC;
96+ ram_grants.ram_block = block;
97+ ram_grants.ram = true;
98+ ram_grants.terminates = true;
99+ ram_block_add_list(block);
100+ memory_region_add_subregion(get_system_memory(), XEN_GRANT_ADDR_OFF,
101+ &ram_grants);
102+
103+ return &ram_grants;
104+}
105diff --git a/include/hw/xen/xen-hvm-common.h b/include/hw/xen/xen-hvm-common.h
106index 4e9904f1a6..0d300ba898 100644
107--- a/include/hw/xen/xen-hvm-common.h
108+++ b/include/hw/xen/xen-hvm-common.h
109@@ -17,6 +17,8 @@
110 #include <xen/hvm/ioreq.h>
111
112 extern MemoryRegion ram_memory;
113+
114+extern MemoryRegion ram_grants;
115 extern MemoryListener xen_io_listener;
116 extern DeviceListener xen_device_listener;
117
118diff --git a/include/hw/xen/xen_pvdev.h b/include/hw/xen/xen_pvdev.h
119index ddad4b9f36..0f1b5edfa9 100644
120--- a/include/hw/xen/xen_pvdev.h
121+++ b/include/hw/xen/xen_pvdev.h
122@@ -80,4 +80,7 @@ int xen_pv_send_notify(struct XenLegacyDevice *xendev);
123 void xen_pv_printf(struct XenLegacyDevice *xendev, int msg_level,
124 const char *fmt, ...) G_GNUC_PRINTF(3, 4);
125
126+#define XEN_GRANT_ADDR_OFF 0x8000000000000000ULL
127+#define XEN_MAX_VIRTIO_GRANTS 65536
128+
129 #endif /* QEMU_HW_XEN_PVDEV_H */
130diff --git a/include/sysemu/xen-mapcache.h b/include/sysemu/xen-mapcache.h
131index c8e7c2f6cf..f4bedb1c11 100644
132--- a/include/sysemu/xen-mapcache.h
133+++ b/include/sysemu/xen-mapcache.h
134@@ -10,6 +10,7 @@
135 #define XEN_MAPCACHE_H
136
137 #include "exec/cpu-common.h"
138+#include "exec/ram_addr.h"
139
140 typedef hwaddr (*phys_offset_to_gaddr_t)(hwaddr phys_offset,
141 ram_addr_t size);
142@@ -25,6 +26,8 @@ void xen_invalidate_map_cache(void);
143 uint8_t *xen_replace_cache_entry(hwaddr old_phys_addr,
144 hwaddr new_phys_addr,
145 hwaddr size);
146+MemoryRegion *xen_init_grant_ram(void);
147+
148 #else
149
150 static inline void xen_map_cache_init(phys_offset_to_gaddr_t f,
151--
1522.39.2
153
diff --git a/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0007-softmmu-let-qemu_map_ram_ptr-use-qemu_ram_ptr_length.patch b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0007-softmmu-let-qemu_map_ram_ptr-use-qemu_ram_ptr_length.patch
new file mode 100644
index 00000000..ee400e2c
--- /dev/null
+++ b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0007-softmmu-let-qemu_map_ram_ptr-use-qemu_ram_ptr_length.patch
@@ -0,0 +1,117 @@
1From 82139e7e4bdcf5ca51b2ac90c63e4af699e3eb6f Mon Sep 17 00:00:00 2001
2From: Juergen Gross <jgross@suse.com>
3Date: Thu, 20 May 2021 11:54:48 +0200
4Subject: [PATCH 07/11] softmmu: let qemu_map_ram_ptr() use
5 qemu_ram_ptr_length()
6
7qemu_map_ram_ptr() and qemu_ram_ptr_length() share quite some code, so
8modify qemu_ram_ptr_length() a little bit and use it for
9qemu_map_ram_ptr(), too.
10
11Signed-off-by: Juergen Gross <jgross@suse.com>
12Signed-off-by: Vikram Garhwal <vikram.garhwal@amd.com>
13Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
14---
15 softmmu/physmem.c | 58 +++++++++++++++++++----------------------------
16 1 file changed, 23 insertions(+), 35 deletions(-)
17
18diff --git a/softmmu/physmem.c b/softmmu/physmem.c
19index f73629733e..a934e44fe7 100644
20--- a/softmmu/physmem.c
21+++ b/softmmu/physmem.c
22@@ -2123,38 +2123,8 @@ void qemu_ram_remap(ram_addr_t addr, ram_addr_t length)
23 }
24 #endif /* !_WIN32 */
25
26-/* Return a host pointer to ram allocated with qemu_ram_alloc.
27- * This should not be used for general purpose DMA. Use address_space_map
28- * or address_space_rw instead. For local memory (e.g. video ram) that the
29- * device owns, use memory_region_get_ram_ptr.
30- *
31- * Called within RCU critical section.
32- */
33-void *qemu_map_ram_ptr(RAMBlock *ram_block, ram_addr_t addr)
34-{
35- RAMBlock *block = ram_block;
36-
37- if (block == NULL) {
38- block = qemu_get_ram_block(addr);
39- addr -= block->offset;
40- }
41-
42- if (xen_enabled() && block->host == NULL) {
43- /* We need to check if the requested address is in the RAM
44- * because we don't want to map the entire memory in QEMU.
45- * In that case just map until the end of the page.
46- */
47- if (block->offset == 0) {
48- return xen_map_cache(addr, 0, 0, false);
49- }
50-
51- block->host = xen_map_cache(block->offset, block->max_length, 1, false);
52- }
53- return ramblock_ptr(block, addr);
54-}
55-
56-/* Return a host pointer to guest's ram. Similar to qemu_map_ram_ptr
57- * but takes a size argument.
58+/*
59+ * Return a host pointer to guest's ram.
60 *
61 * Called within RCU critical section.
62 */
63@@ -2162,7 +2132,9 @@ static void *qemu_ram_ptr_length(RAMBlock *ram_block, ram_addr_t addr,
64 hwaddr *size, bool lock)
65 {
66 RAMBlock *block = ram_block;
67- if (*size == 0) {
68+ hwaddr len = 0;
69+
70+ if (size && *size == 0) {
71 return NULL;
72 }
73
74@@ -2170,7 +2142,10 @@ static void *qemu_ram_ptr_length(RAMBlock *ram_block, ram_addr_t addr,
75 block = qemu_get_ram_block(addr);
76 addr -= block->offset;
77 }
78- *size = MIN(*size, block->max_length - addr);
79+ if (size) {
80+ *size = MIN(*size, block->max_length - addr);
81+ len = *size;
82+ }
83
84 if (xen_enabled() && block->host == NULL) {
85 /* We need to check if the requested address is in the RAM
86@@ -2178,7 +2153,7 @@ static void *qemu_ram_ptr_length(RAMBlock *ram_block, ram_addr_t addr,
87 * In that case just map the requested area.
88 */
89 if (block->offset == 0) {
90- return xen_map_cache(addr, *size, lock, lock);
91+ return xen_map_cache(addr, len, lock, lock);
92 }
93
94 block->host = xen_map_cache(block->offset, block->max_length, 1, lock);
95@@ -2187,6 +2162,19 @@ static void *qemu_ram_ptr_length(RAMBlock *ram_block, ram_addr_t addr,
96 return ramblock_ptr(block, addr);
97 }
98
99+/*
100+ * Return a host pointer to ram allocated with qemu_ram_alloc.
101+ * This should not be used for general purpose DMA. Use address_space_map
102+ * or address_space_rw instead. For local memory (e.g. video ram) that the
103+ * device owns, use memory_region_get_ram_ptr.
104+ *
105+ * Called within RCU critical section.
106+ */
107+void *qemu_map_ram_ptr(RAMBlock *ram_block, ram_addr_t addr)
108+{
109+ return qemu_ram_ptr_length(ram_block, addr, NULL, false);
110+}
111+
112 /* Return the offset of a hostpointer within a ramblock */
113 ram_addr_t qemu_ram_block_host_offset(RAMBlock *rb, void *host)
114 {
115--
1162.39.2
117
diff --git a/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0008-xen-let-xen_ram_addr_from_mapcache-return-1-in-case-.patch b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0008-xen-let-xen_ram_addr_from_mapcache-return-1-in-case-.patch
new file mode 100644
index 00000000..c1e9abd9
--- /dev/null
+++ b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0008-xen-let-xen_ram_addr_from_mapcache-return-1-in-case-.patch
@@ -0,0 +1,49 @@
1From 857bcafe8beb5a0cd78c070f432108049661a56d Mon Sep 17 00:00:00 2001
2From: Juergen Gross <jgross@suse.com>
3Date: Thu, 20 May 2021 13:31:32 +0200
4Subject: [PATCH 08/11] xen: let xen_ram_addr_from_mapcache() return -1 in case
5 of not found entry
6
7Today xen_ram_addr_from_mapcache() will either abort() or return 0 in
8case it can't find a matching entry for a pointer value. Both cases
9are bad, so change that to return an invalid address instead.
10
11Signed-off-by: Juergen Gross <jgross@suse.com>
12Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
13---
14 hw/xen/xen-mapcache.c | 12 +++---------
15 1 file changed, 3 insertions(+), 9 deletions(-)
16
17diff --git a/hw/xen/xen-mapcache.c b/hw/xen/xen-mapcache.c
18index 8115c44c00..8a61c7dde6 100644
19--- a/hw/xen/xen-mapcache.c
20+++ b/hw/xen/xen-mapcache.c
21@@ -404,13 +404,8 @@ ram_addr_t xen_ram_addr_from_mapcache(void *ptr)
22 }
23 }
24 if (!found) {
25- fprintf(stderr, "%s, could not find %p\n", __func__, ptr);
26- QTAILQ_FOREACH(reventry, &mapcache->locked_entries, next) {
27- DPRINTF(" "HWADDR_FMT_plx" -> %p is present\n", reventry->paddr_index,
28- reventry->vaddr_req);
29- }
30- abort();
31- return 0;
32+ mapcache_unlock();
33+ return RAM_ADDR_INVALID;
34 }
35
36 entry = &mapcache->entry[paddr_index % mapcache->nr_buckets];
37@@ -418,8 +413,7 @@ ram_addr_t xen_ram_addr_from_mapcache(void *ptr)
38 entry = entry->next;
39 }
40 if (!entry) {
41- DPRINTF("Trying to find address %p that is not in the mapcache!\n", ptr);
42- raddr = 0;
43+ raddr = RAM_ADDR_INVALID;
44 } else {
45 raddr = (reventry->paddr_index << MCACHE_BUCKET_SHIFT) +
46 ((unsigned long) ptr - (unsigned long) entry->vaddr_base);
47--
482.39.2
49
diff --git a/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0009-memory-add-MemoryRegion-map-and-unmap-callbacks.patch b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0009-memory-add-MemoryRegion-map-and-unmap-callbacks.patch
new file mode 100644
index 00000000..fa18ef16
--- /dev/null
+++ b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0009-memory-add-MemoryRegion-map-and-unmap-callbacks.patch
@@ -0,0 +1,155 @@
1From 364a11be6274336ec9b0f06f3272f964d27c9349 Mon Sep 17 00:00:00 2001
2From: Juergen Gross <jgross@suse.com>
3Date: Thu, 27 May 2021 15:27:55 +0200
4Subject: [PATCH 09/11] memory: add MemoryRegion map and unmap callbacks
5
6In order to support mapping and unmapping guest memory dynamically to
7and from qemu during address_space_[un]map() operations add the map()
8and unmap() callbacks to MemoryRegionOps.
9
10Those will be used e.g. for Xen grant mappings when performing guest
11I/Os.
12
13Signed-off-by: Juergen Gross <jgross@suse.com>
14Signed-off-by: Vikram Garhwal <vikram.garhwal@amd.com>
15---
16 include/exec/memory.h | 21 ++++++++++++++++++
17 softmmu/physmem.c | 50 +++++++++++++++++++++++++++++++++----------
18 2 files changed, 60 insertions(+), 11 deletions(-)
19
20diff --git a/include/exec/memory.h b/include/exec/memory.h
21index 68284428f8..55414417ab 100644
22--- a/include/exec/memory.h
23+++ b/include/exec/memory.h
24@@ -274,6 +274,27 @@ struct MemoryRegionOps {
25 unsigned size,
26 MemTxAttrs attrs);
27
28+ /*
29+ * Dynamically create mapping. @addr is the guest address to map; @plen
30+ * is the pointer to the usable length of the buffer.
31+ * @mr contents can be changed in case a new memory region is created for
32+ * the mapping.
33+ * Returns the buffer address for accessing the data.
34+ */
35+ void *(*map)(MemoryRegion **mr,
36+ hwaddr addr,
37+ hwaddr *plen,
38+ bool is_write,
39+ MemTxAttrs attrs);
40+
41+ /* Unmap an area obtained via map() before. */
42+ void (*unmap)(MemoryRegion *mr,
43+ void *buffer,
44+ ram_addr_t addr,
45+ hwaddr len,
46+ bool is_write,
47+ hwaddr access_len);
48+
49 enum device_endian endianness;
50 /* Guest-visible constraints: */
51 struct {
52diff --git a/softmmu/physmem.c b/softmmu/physmem.c
53index a934e44fe7..a1e2030424 100644
54--- a/softmmu/physmem.c
55+++ b/softmmu/physmem.c
56@@ -3070,6 +3070,7 @@ void *address_space_map(AddressSpace *as,
57 hwaddr len = *plen;
58 hwaddr l, xlat;
59 MemoryRegion *mr;
60+ void *ptr = NULL;
61 FlatView *fv;
62
63 if (len == 0) {
64@@ -3103,12 +3104,20 @@ void *address_space_map(AddressSpace *as,
65 return bounce.buffer;
66 }
67
68-
69 memory_region_ref(mr);
70+
71+ if (mr->ops && mr->ops->map) {
72+ ptr = mr->ops->map(&mr, addr, plen, is_write, attrs);
73+ }
74+
75 *plen = flatview_extend_translation(fv, addr, len, mr, xlat,
76 l, is_write, attrs);
77 fuzz_dma_read_cb(addr, *plen, mr);
78- return qemu_ram_ptr_length(mr->ram_block, xlat, plen, true);
79+ if (ptr == NULL) {
80+ ptr = qemu_ram_ptr_length(mr->ram_block, xlat, plen, true);
81+ }
82+
83+ return ptr;
84 }
85
86 /* Unmaps a memory region previously mapped by address_space_map().
87@@ -3124,11 +3133,16 @@ void address_space_unmap(AddressSpace *as, void *buffer, hwaddr len,
88
89 mr = memory_region_from_host(buffer, &addr1);
90 assert(mr != NULL);
91- if (is_write) {
92- invalidate_and_set_dirty(mr, addr1, access_len);
93- }
94- if (xen_enabled()) {
95- xen_invalidate_map_cache_entry(buffer);
96+
97+ if (mr->ops && mr->ops->unmap) {
98+ mr->ops->unmap(mr, buffer, addr1, len, is_write, access_len);
99+ } else {
100+ if (is_write) {
101+ invalidate_and_set_dirty(mr, addr1, access_len);
102+ }
103+ if (xen_enabled()) {
104+ xen_invalidate_map_cache_entry(buffer);
105+ }
106 }
107 memory_region_unref(mr);
108 return;
109@@ -3201,10 +3215,18 @@ int64_t address_space_cache_init(MemoryRegionCache *cache,
110 * doing this if we found actual RAM, which behaves the same
111 * regardless of attributes; so UNSPECIFIED is fine.
112 */
113+ if (mr->ops && mr->ops->map) {
114+ cache->ptr = mr->ops->map(&mr, addr, &l, is_write,
115+ MEMTXATTRS_UNSPECIFIED);
116+ }
117+
118 l = flatview_extend_translation(cache->fv, addr, len, mr,
119 cache->xlat, l, is_write,
120 MEMTXATTRS_UNSPECIFIED);
121- cache->ptr = qemu_ram_ptr_length(mr->ram_block, cache->xlat, &l, true);
122+ if (!cache->ptr) {
123+ cache->ptr = qemu_ram_ptr_length(mr->ram_block, cache->xlat, &l,
124+ true);
125+ }
126 } else {
127 cache->ptr = NULL;
128 }
129@@ -3226,14 +3248,20 @@ void address_space_cache_invalidate(MemoryRegionCache *cache,
130
131 void address_space_cache_destroy(MemoryRegionCache *cache)
132 {
133- if (!cache->mrs.mr) {
134+ MemoryRegion *mr = cache->mrs.mr;
135+
136+ if (!mr) {
137 return;
138 }
139
140- if (xen_enabled()) {
141+ if (mr->ops && mr->ops->unmap) {
142+ mr->ops->unmap(mr, cache->ptr, cache->xlat, cache->len,
143+ cache->is_write, cache->len);
144+ } else if (xen_enabled()) {
145 xen_invalidate_map_cache_entry(cache->ptr);
146 }
147- memory_region_unref(cache->mrs.mr);
148+
149+ memory_region_unref(mr);
150 flatview_unref(cache->fv);
151 cache->mrs.mr = NULL;
152 cache->fv = NULL;
153--
1542.39.2
155
diff --git a/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0010-xen-add-map-and-unmap-callbacks-for-grant-region.patch b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0010-xen-add-map-and-unmap-callbacks-for-grant-region.patch
new file mode 100644
index 00000000..48dcf7d7
--- /dev/null
+++ b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0010-xen-add-map-and-unmap-callbacks-for-grant-region.patch
@@ -0,0 +1,262 @@
1From 90496d4c71e3b9334aebca118661bf72631ed0f0 Mon Sep 17 00:00:00 2001
2From: Juergen Gross <jgross@suse.com>
3Date: Fri, 26 Aug 2022 13:57:06 +0200
4Subject: [PATCH 10/11] xen: add map and unmap callbacks for grant region
5
6Add the callbacks for mapping/unmapping guest memory via grants to the
7special grant memory region.
8
9Signed-off-by: Juergen Gross <jgross@suse.com>
10Signed-off-by: Vikram Garhwal <vikram.garhwal@amd.com>
11---
12 hw/xen/xen-mapcache.c | 176 +++++++++++++++++++++++++++++++++++++++++-
13 softmmu/physmem.c | 11 ++-
14 2 files changed, 182 insertions(+), 5 deletions(-)
15
16diff --git a/hw/xen/xen-mapcache.c b/hw/xen/xen-mapcache.c
17index 8a61c7dde6..e071328fc5 100644
18--- a/hw/xen/xen-mapcache.c
19+++ b/hw/xen/xen-mapcache.c
20@@ -9,6 +9,8 @@
21 */
22
23 #include "qemu/osdep.h"
24+#include "qemu/queue.h"
25+#include "qemu/thread.h"
26 #include "qemu/units.h"
27 #include "qemu/error-report.h"
28
29@@ -23,6 +25,8 @@
30 #include "sysemu/xen-mapcache.h"
31 #include "trace.h"
32
33+#include <xenevtchn.h>
34+#include <xengnttab.h>
35
36 //#define MAPCACHE_DEBUG
37
38@@ -385,7 +389,7 @@ uint8_t *xen_map_cache(hwaddr phys_addr, hwaddr size,
39 return p;
40 }
41
42-ram_addr_t xen_ram_addr_from_mapcache(void *ptr)
43+static ram_addr_t xen_ram_addr_from_mapcache_try(void *ptr)
44 {
45 MapCacheEntry *entry = NULL;
46 MapCacheRev *reventry;
47@@ -594,10 +598,179 @@ uint8_t *xen_replace_cache_entry(hwaddr old_phys_addr,
48 return p;
49 }
50
51+struct XENMappedGrantRegion {
52+ void *addr;
53+ unsigned int pages;
54+ unsigned int refs;
55+ unsigned int prot;
56+ uint32_t idx;
57+ QLIST_ENTRY(XENMappedGrantRegion) list;
58+};
59+
60+static xengnttab_handle *xen_region_gnttabdev;
61+static QLIST_HEAD(GrantRegionList, XENMappedGrantRegion) xen_grant_mappings =
62+ QLIST_HEAD_INITIALIZER(xen_grant_mappings);
63+static QemuMutex xen_map_mutex;
64+
65+static void *xen_map_grant_dyn(MemoryRegion **mr, hwaddr addr, hwaddr *plen,
66+ bool is_write, MemTxAttrs attrs)
67+{
68+ unsigned int page_off = addr & (XC_PAGE_SIZE - 1);
69+ unsigned int i;
70+ unsigned int total_grants = 0;
71+ unsigned int nrefs = (page_off + *plen + XC_PAGE_SIZE - 1) >> XC_PAGE_SHIFT;
72+ uint32_t ref = (addr - XEN_GRANT_ADDR_OFF) >> XC_PAGE_SHIFT;
73+ uint32_t *refs = NULL;
74+ unsigned int prot = PROT_READ;
75+ struct XENMappedGrantRegion *mgr = NULL;
76+
77+ if (is_write) {
78+ prot |= PROT_WRITE;
79+ }
80+
81+ qemu_mutex_lock(&xen_map_mutex);
82+
83+ QLIST_FOREACH(mgr, &xen_grant_mappings, list) {
84+ if (mgr->idx == ref &&
85+ mgr->pages == nrefs &&
86+ (mgr->prot & prot) == prot) {
87+ break;
88+ }
89+
90+ total_grants += mgr->pages;
91+ }
92+
93+ if (!mgr) {
94+ if (nrefs + total_grants >= XEN_MAX_VIRTIO_GRANTS) {
95+ qemu_mutex_unlock(&xen_map_mutex);
96+ return NULL;
97+ }
98+
99+ mgr = g_new(struct XENMappedGrantRegion, 1);
100+
101+ if (nrefs == 1) {
102+ refs = &ref;
103+ } else {
104+ refs = g_new(uint32_t, nrefs);
105+ for (i = 0; i < nrefs; i++) {
106+ refs[i] = ref + i;
107+ }
108+ }
109+ mgr->addr = xengnttab_map_domain_grant_refs(xen_region_gnttabdev, nrefs,
110+ xen_domid, refs, prot);
111+ if (mgr->addr) {
112+ mgr->pages = nrefs;
113+ mgr->refs = 1;
114+ mgr->prot = prot;
115+ mgr->idx = ref;
116+
117+ QLIST_INSERT_HEAD(&xen_grant_mappings, mgr, list);
118+ } else {
119+ g_free(mgr);
120+ mgr = NULL;
121+ }
122+ } else {
123+ mgr->refs++;
124+ }
125+
126+ qemu_mutex_unlock(&xen_map_mutex);
127+
128+ if (nrefs > 1) {
129+ g_free(refs);
130+ }
131+
132+ return mgr ? mgr->addr + page_off : NULL;
133+}
134+
135+static void xen_unmap_grant_dyn(MemoryRegion *mr, void *buffer, ram_addr_t addr,
136+ hwaddr len, bool is_write, hwaddr access_len)
137+{
138+ unsigned int page_off = (unsigned long)buffer & (XC_PAGE_SIZE - 1);
139+ unsigned int nrefs = (page_off + len + XC_PAGE_SIZE - 1) >> XC_PAGE_SHIFT;
140+ unsigned int prot = PROT_READ;
141+ struct XENMappedGrantRegion *mgr = NULL;
142+
143+ if (is_write) {
144+ prot |= PROT_WRITE;
145+ }
146+
147+ qemu_mutex_lock(&xen_map_mutex);
148+
149+ QLIST_FOREACH(mgr, &xen_grant_mappings, list) {
150+ if (mgr->addr == buffer - page_off &&
151+ mgr->pages == nrefs &&
152+ (mgr->prot & prot) == prot) {
153+ break;
154+ }
155+ }
156+ if (mgr) {
157+ mgr->refs--;
158+ if (!mgr->refs) {
159+ xengnttab_unmap(xen_region_gnttabdev, mgr->addr, nrefs);
160+
161+ QLIST_REMOVE(mgr, list);
162+ g_free(mgr);
163+ }
164+ } else {
165+ error_report("xen_unmap_grant_dyn() trying to unmap unknown buffer");
166+ }
167+
168+ qemu_mutex_unlock(&xen_map_mutex);
169+}
170+
171+static ram_addr_t xen_ram_addr_from_grant_cache(void *ptr)
172+{
173+ unsigned int page_off = (unsigned long)ptr & (XC_PAGE_SIZE - 1);
174+ struct XENMappedGrantRegion *mgr = NULL;
175+ ram_addr_t raddr = RAM_ADDR_INVALID;
176+
177+ qemu_mutex_lock(&xen_map_mutex);
178+
179+ QLIST_FOREACH(mgr, &xen_grant_mappings, list) {
180+ if (mgr->addr == ptr - page_off) {
181+ break;
182+ }
183+ }
184+
185+ if (mgr) {
186+ raddr = (mgr->idx << XC_PAGE_SHIFT) + page_off + XEN_GRANT_ADDR_OFF;
187+ }
188+
189+ qemu_mutex_unlock(&xen_map_mutex);
190+
191+ return raddr;
192+}
193+
194+ram_addr_t xen_ram_addr_from_mapcache(void *ptr)
195+{
196+ ram_addr_t raddr;
197+
198+ raddr = xen_ram_addr_from_mapcache_try(ptr);
199+ if (raddr == RAM_ADDR_INVALID) {
200+ raddr = xen_ram_addr_from_grant_cache(ptr);
201+ }
202+
203+ return raddr;
204+}
205+
206+static const struct MemoryRegionOps xen_grant_mr_ops = {
207+ .map = xen_map_grant_dyn,
208+ .unmap = xen_unmap_grant_dyn,
209+ .endianness = DEVICE_LITTLE_ENDIAN,
210+};
211+
212 MemoryRegion *xen_init_grant_ram(void)
213 {
214 RAMBlock *block;
215
216+ qemu_mutex_init(&xen_map_mutex);
217+
218+ xen_region_gnttabdev = xengnttab_open(NULL, 0);
219+ if (xen_region_gnttabdev == NULL) {
220+ fprintf(stderr, "can't open gnttab device\n");
221+ return NULL;
222+ }
223+
224 memory_region_init(&ram_grants, NULL, "xen.grants",
225 XEN_MAX_VIRTIO_GRANTS * XC_PAGE_SIZE);
226 block = g_malloc0(sizeof(*block));
227@@ -612,6 +785,7 @@ MemoryRegion *xen_init_grant_ram(void)
228 ram_grants.ram_block = block;
229 ram_grants.ram = true;
230 ram_grants.terminates = true;
231+ ram_grants.ops = &xen_grant_mr_ops;
232 ram_block_add_list(block);
233 memory_region_add_subregion(get_system_memory(), XEN_GRANT_ADDR_OFF,
234 &ram_grants);
235diff --git a/softmmu/physmem.c b/softmmu/physmem.c
236index a1e2030424..e1057304f1 100644
237--- a/softmmu/physmem.c
238+++ b/softmmu/physmem.c
239@@ -2210,13 +2210,16 @@ RAMBlock *qemu_ram_block_from_host(void *ptr, bool round_offset,
240
241 if (xen_enabled()) {
242 ram_addr_t ram_addr;
243+
244 RCU_READ_LOCK_GUARD();
245 ram_addr = xen_ram_addr_from_mapcache(ptr);
246- block = qemu_get_ram_block(ram_addr);
247- if (block) {
248- *offset = ram_addr - block->offset;
249+ if (ram_addr != RAM_ADDR_INVALID) {
250+ block = qemu_get_ram_block(ram_addr);
251+ if (block) {
252+ *offset = ram_addr - block->offset;
253+ }
254+ return block;
255 }
256- return block;
257 }
258
259 RCU_READ_LOCK_GUARD();
260--
2612.39.2
262
diff --git a/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0011-hw-arm-Add-grant-mapping.patch b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0011-hw-arm-Add-grant-mapping.patch
new file mode 100644
index 00000000..fb5450e6
--- /dev/null
+++ b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0011-hw-arm-Add-grant-mapping.patch
@@ -0,0 +1,30 @@
1From b1eaba758a9000061fc53a934c348d6ef8dcdf64 Mon Sep 17 00:00:00 2001
2From: Vikram Garhwal <vikram.garhwal@amd.com>
3Date: Tue, 31 Jan 2023 21:46:43 +0000
4Subject: [PATCH 11/11] hw: arm: Add grant mapping.
5
6Enable grant ram mapping support for Xenpvh machine on ARM.
7
8Signed-off-by: Vikram Garhwal <vikram.garhwal@amd.com>
9Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
10---
11 hw/arm/xen_arm.c | 3 +++
12 1 file changed, 3 insertions(+)
13
14diff --git a/hw/arm/xen_arm.c b/hw/arm/xen_arm.c
15index a5631529d0..1587e2a43b 100644
16--- a/hw/arm/xen_arm.c
17+++ b/hw/arm/xen_arm.c
18@@ -127,6 +127,9 @@ static void xen_init_ram(MachineState *machine)
19 DPRINTF("Initialized region xen.ram.hi: base 0x%llx size 0x%lx\n",
20 GUEST_RAM1_BASE, ram_size[1]);
21 }
22+
23+ DPRINTF("init grant ram mapping for XEN\n");
24+ ram_grants = *xen_init_grant_ram();
25 }
26
27 void arch_handle_ioreq(XenIOState *state, ioreq_t *req)
28--
292.39.2
30
diff --git a/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx_2024%.bbappend b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx_2024%.bbappend
index b1e94b5a..2f8e55aa 100644
--- a/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx_2024%.bbappend
+++ b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx_2024%.bbappend
@@ -1,5 +1,5 @@
1require qemu-tpm.inc 1require qemu-tpm.inc
2#require qemu-xen.inc 2require qemu-xen_8.1.inc
3 3
4# We do not want QEMU, on the target to be configured with OpenGL 4# We do not want QEMU, on the target to be configured with OpenGL
5PACKAGECONFIG:remove:class-target:petalinux = "virglrenderer epoxy gtk+" 5PACKAGECONFIG:remove:class-target:petalinux = "virglrenderer epoxy gtk+"
diff --git a/meta-xilinx-virtualization/recipes-devtools/qemu/qemu_8.1%.bbappend b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu_8.1%.bbappend
index b1e94b5a..95b1902b 100644
--- a/meta-xilinx-virtualization/recipes-devtools/qemu/qemu_8.1%.bbappend
+++ b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu_8.1%.bbappend
@@ -1,5 +1,5 @@
1require qemu-tpm.inc 1require qemu-tpm.inc
2#require qemu-xen.inc 2require qemu-xen_8.1.inc
3 3
4# We do not want QEMU, on the target to be configured with OpenGL 4# We do not want QEMU, on the target to be configured with OpenGL
5PACKAGECONFIG:remove:class-target:petalinux = "virglrenderer epoxy gtk+" 5PACKAGECONFIG:remove:class-target = "virglrenderer epoxy gtk+"