diff options
Diffstat (limited to 'meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-7.1/0002-xen-add-pseudo-RAM-region-for-grant-mappings.patch')
-rw-r--r-- | meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-7.1/0002-xen-add-pseudo-RAM-region-for-grant-mappings.patch | 252 |
1 files changed, 0 insertions, 252 deletions
diff --git a/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-7.1/0002-xen-add-pseudo-RAM-region-for-grant-mappings.patch b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-7.1/0002-xen-add-pseudo-RAM-region-for-grant-mappings.patch deleted file mode 100644 index 8facb189..00000000 --- a/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-7.1/0002-xen-add-pseudo-RAM-region-for-grant-mappings.patch +++ /dev/null | |||
@@ -1,252 +0,0 @@ | |||
1 | From e18daac2f6d3f60c8217f44189a91cf8240a591f Mon Sep 17 00:00:00 2001 | ||
2 | From: Juergen Gross <jgross@suse.com> | ||
3 | Date: Thu, 20 May 2021 11:19:58 +0200 | ||
4 | Subject: [PATCH 2/8] xen: add pseudo RAM region for grant mappings | ||
5 | |||
6 | Add a memory region which can be used to automatically map granted | ||
7 | memory. It is starting at 0x8000000000000000ULL in order to be able to | ||
8 | distinguish it from normal RAM. | ||
9 | |||
10 | For this reason the xen.ram memory region is expanded, which has no | ||
11 | further impact as it is used just as a container of the real RAM | ||
12 | regions and now the grant region. | ||
13 | |||
14 | Signed-off-by: Juergen Gross <jgross@suse.com> | ||
15 | Signed-off-by: Vikram Garhwal <vikram.garhwal@amd.com> | ||
16 | Acked-by: Stefano Stabellini <stefano.stabellini@amd.com> | ||
17 | --- | ||
18 | hw/i386/xen/xen-hvm.c | 3 ++ | ||
19 | hw/xen/xen-hvm-common.c | 4 +-- | ||
20 | hw/xen/xen-mapcache.c | 28 +++++++++++++++ | ||
21 | include/exec/ram_addr.h | 1 + | ||
22 | include/hw/xen/xen-hvm-common.h | 2 ++ | ||
23 | include/hw/xen/xen_pvdev.h | 3 ++ | ||
24 | include/sysemu/xen-mapcache.h | 3 ++ | ||
25 | softmmu/physmem.c | 61 ++++++++++++++++++++------------- | ||
26 | 8 files changed, 80 insertions(+), 25 deletions(-) | ||
27 | |||
28 | diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c | ||
29 | index 36d87555a9..2dcc2e1179 100644 | ||
30 | --- a/hw/i386/xen/xen-hvm.c | ||
31 | +++ b/hw/i386/xen/xen-hvm.c | ||
32 | @@ -171,6 +171,9 @@ static void xen_ram_init(PCMachineState *pcms, | ||
33 | x86ms->above_4g_mem_size); | ||
34 | memory_region_add_subregion(sysmem, 0x100000000ULL, &ram_hi); | ||
35 | } | ||
36 | + | ||
37 | + /* Add grant mappings as a pseudo RAM region. */ | ||
38 | + ram_grants = *xen_init_grant_ram(); | ||
39 | } | ||
40 | |||
41 | static XenPhysmap *get_physmapping(hwaddr start_addr, ram_addr_t size) | ||
42 | diff --git a/hw/xen/xen-hvm-common.c b/hw/xen/xen-hvm-common.c | ||
43 | index 7e7d23397f..abd6e379d3 100644 | ||
44 | --- a/hw/xen/xen-hvm-common.c | ||
45 | +++ b/hw/xen/xen-hvm-common.c | ||
46 | @@ -10,7 +10,7 @@ | ||
47 | #include "hw/boards.h" | ||
48 | #include "hw/xen/arch_hvm.h" | ||
49 | |||
50 | -MemoryRegion ram_memory; | ||
51 | +MemoryRegion ram_memory, ram_grants; | ||
52 | |||
53 | MemoryListener xen_io_listener = { | ||
54 | .name = "xen-io", | ||
55 | @@ -742,7 +742,7 @@ void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, MemoryRegion *mr, | ||
56 | return; | ||
57 | } | ||
58 | |||
59 | - if (mr == &ram_memory) { | ||
60 | + if (mr == &ram_memory || mr == &ram_grants) { | ||
61 | return; | ||
62 | } | ||
63 | |||
64 | diff --git a/hw/xen/xen-mapcache.c b/hw/xen/xen-mapcache.c | ||
65 | index a2f93096e7..0b75f1633a 100644 | ||
66 | --- a/hw/xen/xen-mapcache.c | ||
67 | +++ b/hw/xen/xen-mapcache.c | ||
68 | @@ -14,7 +14,10 @@ | ||
69 | |||
70 | #include <sys/resource.h> | ||
71 | |||
72 | +#include "hw/xen/xen-hvm-common.h" | ||
73 | #include "hw/xen/xen-legacy-backend.h" | ||
74 | +#include "hw/xen/xen_pvdev.h" | ||
75 | + | ||
76 | #include "qemu/bitmap.h" | ||
77 | |||
78 | #include "sysemu/runstate.h" | ||
79 | @@ -597,3 +600,28 @@ uint8_t *xen_replace_cache_entry(hwaddr old_phys_addr, | ||
80 | mapcache_unlock(); | ||
81 | return p; | ||
82 | } | ||
83 | + | ||
84 | +MemoryRegion *xen_init_grant_ram(void) | ||
85 | +{ | ||
86 | + RAMBlock *block; | ||
87 | + | ||
88 | + memory_region_init(&ram_grants, NULL, "xen.grants", | ||
89 | + XEN_MAX_VIRTIO_GRANTS * XC_PAGE_SIZE); | ||
90 | + block = g_malloc0(sizeof(*block)); | ||
91 | + block->mr = &ram_grants; | ||
92 | + block->used_length = XEN_MAX_VIRTIO_GRANTS * XC_PAGE_SIZE; | ||
93 | + block->max_length = XEN_MAX_VIRTIO_GRANTS * XC_PAGE_SIZE; | ||
94 | + block->fd = -1; | ||
95 | + block->page_size = XC_PAGE_SIZE; | ||
96 | + block->host = (void *)XEN_GRANT_ADDR_OFF; | ||
97 | + block->offset = XEN_GRANT_ADDR_OFF; | ||
98 | + block->flags = RAM_PREALLOC; | ||
99 | + ram_grants.ram_block = block; | ||
100 | + ram_grants.ram = true; | ||
101 | + ram_grants.terminates = true; | ||
102 | + ram_block_add_list(block); | ||
103 | + memory_region_add_subregion(get_system_memory(), XEN_GRANT_ADDR_OFF, | ||
104 | + &ram_grants); | ||
105 | + | ||
106 | + return &ram_grants; | ||
107 | +} | ||
108 | diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h | ||
109 | index f3e0c78161..e60b055867 100644 | ||
110 | --- a/include/exec/ram_addr.h | ||
111 | +++ b/include/exec/ram_addr.h | ||
112 | @@ -137,6 +137,7 @@ void qemu_ram_free(RAMBlock *block); | ||
113 | int qemu_ram_resize(RAMBlock *block, ram_addr_t newsize, Error **errp); | ||
114 | |||
115 | void qemu_ram_msync(RAMBlock *block, ram_addr_t start, ram_addr_t length); | ||
116 | +void ram_block_add_list(RAMBlock *new_block); | ||
117 | |||
118 | /* Clear whole block of mem */ | ||
119 | static inline void qemu_ram_block_writeback(RAMBlock *block) | ||
120 | diff --git a/include/hw/xen/xen-hvm-common.h b/include/hw/xen/xen-hvm-common.h | ||
121 | index 2979f84ee2..6f7cc05d38 100644 | ||
122 | --- a/include/hw/xen/xen-hvm-common.h | ||
123 | +++ b/include/hw/xen/xen-hvm-common.h | ||
124 | @@ -16,6 +16,8 @@ | ||
125 | #include <xen/hvm/ioreq.h> | ||
126 | |||
127 | extern MemoryRegion ram_memory; | ||
128 | + | ||
129 | +extern MemoryRegion ram_grants; | ||
130 | extern MemoryListener xen_io_listener; | ||
131 | extern DeviceListener xen_device_listener; | ||
132 | |||
133 | diff --git a/include/hw/xen/xen_pvdev.h b/include/hw/xen/xen_pvdev.h | ||
134 | index 7cd4bc2b82..36cd3ec1d4 100644 | ||
135 | --- a/include/hw/xen/xen_pvdev.h | ||
136 | +++ b/include/hw/xen/xen_pvdev.h | ||
137 | @@ -78,4 +78,7 @@ int xen_pv_send_notify(struct XenLegacyDevice *xendev); | ||
138 | void xen_pv_printf(struct XenLegacyDevice *xendev, int msg_level, | ||
139 | const char *fmt, ...) G_GNUC_PRINTF(3, 4); | ||
140 | |||
141 | +#define XEN_GRANT_ADDR_OFF 0x8000000000000000ULL | ||
142 | +#define XEN_MAX_VIRTIO_GRANTS 65536 | ||
143 | + | ||
144 | #endif /* QEMU_HW_XEN_PVDEV_H */ | ||
145 | diff --git a/include/sysemu/xen-mapcache.h b/include/sysemu/xen-mapcache.h | ||
146 | index c8e7c2f6cf..f4bedb1c11 100644 | ||
147 | --- a/include/sysemu/xen-mapcache.h | ||
148 | +++ b/include/sysemu/xen-mapcache.h | ||
149 | @@ -10,6 +10,7 @@ | ||
150 | #define XEN_MAPCACHE_H | ||
151 | |||
152 | #include "exec/cpu-common.h" | ||
153 | +#include "exec/ram_addr.h" | ||
154 | |||
155 | typedef hwaddr (*phys_offset_to_gaddr_t)(hwaddr phys_offset, | ||
156 | ram_addr_t size); | ||
157 | @@ -25,6 +26,8 @@ void xen_invalidate_map_cache(void); | ||
158 | uint8_t *xen_replace_cache_entry(hwaddr old_phys_addr, | ||
159 | hwaddr new_phys_addr, | ||
160 | hwaddr size); | ||
161 | +MemoryRegion *xen_init_grant_ram(void); | ||
162 | + | ||
163 | #else | ||
164 | |||
165 | static inline void xen_map_cache_init(phys_offset_to_gaddr_t f, | ||
166 | diff --git a/softmmu/physmem.c b/softmmu/physmem.c | ||
167 | index dc3c3e5f2e..63ba5f7495 100644 | ||
168 | --- a/softmmu/physmem.c | ||
169 | +++ b/softmmu/physmem.c | ||
170 | @@ -1971,12 +1971,46 @@ static void dirty_memory_extend(ram_addr_t old_ram_size, | ||
171 | } | ||
172 | } | ||
173 | |||
174 | +static void ram_block_add_list_locked(RAMBlock *new_block) | ||
175 | + { | ||
176 | + RAMBlock *block; | ||
177 | + RAMBlock *last_block = NULL; | ||
178 | + | ||
179 | + /* Keep the list sorted from biggest to smallest block. Unlike QTAILQ, | ||
180 | + * QLIST (which has an RCU-friendly variant) does not have insertion at | ||
181 | + * tail, so save the last element in last_block. | ||
182 | + */ | ||
183 | + RAMBLOCK_FOREACH(block) { | ||
184 | + last_block = block; | ||
185 | + if (block->max_length < new_block->max_length) { | ||
186 | + break; | ||
187 | + } | ||
188 | + } | ||
189 | + if (block) { | ||
190 | + QLIST_INSERT_BEFORE_RCU(block, new_block, next); | ||
191 | + } else if (last_block) { | ||
192 | + QLIST_INSERT_AFTER_RCU(last_block, new_block, next); | ||
193 | + } else { /* list is empty */ | ||
194 | + QLIST_INSERT_HEAD_RCU(&ram_list.blocks, new_block, next); | ||
195 | + } | ||
196 | + ram_list.mru_block = NULL; | ||
197 | + | ||
198 | + /* Write list before version */ | ||
199 | + smp_wmb(); | ||
200 | + ram_list.version++; | ||
201 | +} | ||
202 | + | ||
203 | +void ram_block_add_list(RAMBlock *new_block) | ||
204 | +{ | ||
205 | + qemu_mutex_lock_ramlist(); | ||
206 | + ram_block_add_list_locked(new_block); | ||
207 | + qemu_mutex_unlock_ramlist(); | ||
208 | +} | ||
209 | + | ||
210 | static void ram_block_add(RAMBlock *new_block, Error **errp) | ||
211 | { | ||
212 | const bool noreserve = qemu_ram_is_noreserve(new_block); | ||
213 | const bool shared = qemu_ram_is_shared(new_block); | ||
214 | - RAMBlock *block; | ||
215 | - RAMBlock *last_block = NULL; | ||
216 | ram_addr_t old_ram_size, new_ram_size; | ||
217 | Error *err = NULL; | ||
218 | |||
219 | @@ -2014,28 +2048,9 @@ static void ram_block_add(RAMBlock *new_block, Error **errp) | ||
220 | if (new_ram_size > old_ram_size) { | ||
221 | dirty_memory_extend(old_ram_size, new_ram_size); | ||
222 | } | ||
223 | - /* Keep the list sorted from biggest to smallest block. Unlike QTAILQ, | ||
224 | - * QLIST (which has an RCU-friendly variant) does not have insertion at | ||
225 | - * tail, so save the last element in last_block. | ||
226 | - */ | ||
227 | - RAMBLOCK_FOREACH(block) { | ||
228 | - last_block = block; | ||
229 | - if (block->max_length < new_block->max_length) { | ||
230 | - break; | ||
231 | - } | ||
232 | - } | ||
233 | - if (block) { | ||
234 | - QLIST_INSERT_BEFORE_RCU(block, new_block, next); | ||
235 | - } else if (last_block) { | ||
236 | - QLIST_INSERT_AFTER_RCU(last_block, new_block, next); | ||
237 | - } else { /* list is empty */ | ||
238 | - QLIST_INSERT_HEAD_RCU(&ram_list.blocks, new_block, next); | ||
239 | - } | ||
240 | - ram_list.mru_block = NULL; | ||
241 | |||
242 | - /* Write list before version */ | ||
243 | - smp_wmb(); | ||
244 | - ram_list.version++; | ||
245 | + ram_block_add_list_locked(new_block); | ||
246 | + | ||
247 | qemu_mutex_unlock_ramlist(); | ||
248 | |||
249 | cpu_physical_memory_set_dirty_range(new_block->offset, | ||
250 | -- | ||
251 | 2.25.1 | ||
252 | |||