• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revision0001a964b840a62c66da42a89a10a2656831aa4b (tree)
Time2022-07-26 03:57:27
AuthorDmytro Firsov <Dmytro_Firsov@epam...>
CommiterTom Rini

Log Message

drivers: xen: unmap Enlighten page before jumping to Linux

This commit fixes issue with usage of Xen hypervisor shared info page.
Previously U-boot did not unmap it at the end of OS boot process. Xen
did not prevent guest from this. So, it worked, but caused wierd
issues - one memory page, that was returned by memalign in U-boot
for Enlighten mapping was not unmaped by Xen (shared_info values was
not removed from there) and returned to allocator. During the Linux
boot, it uses shared_info page as regular RAM page, which leads to
hypervisor shared info corruption.

So, to fix this issue, as discussed on the xen-devel mailing list, the
code should:

1) Unmap the page
2) Populate the area with memory using XENMEM_populate_physmap

This patch adds page unmapping via XENMEM_remove_from_physmap, fills
hole in address space where page was mapped via XENMEM_populate_physmap
and return this address to memory allocator for freeing.

Signed-off-by: Dmytro Firsov <dmytro_firsov@epam.com>
Reviewed-by: Anastasiia Lukianenko <vicooodin@gmail.com>

Change Summary

Incremental Difference

--- a/drivers/xen/hypervisor.c
+++ b/drivers/xen/hypervisor.c
@@ -144,6 +144,36 @@ struct shared_info *map_shared_info(void *p)
144144 return HYPERVISOR_shared_info;
145145 }
146146
147+void unmap_shared_info(void)
148+{
149+ xen_pfn_t shared_info_pfn = virt_to_pfn(HYPERVISOR_shared_info);
150+ struct xen_remove_from_physmap xrfp = {0};
151+ struct xen_memory_reservation reservation = {0};
152+ xen_ulong_t nr_exts = 1;
153+
154+ xrfp.domid = DOMID_SELF;
155+ xrfp.gpfn = shared_info_pfn;
156+ if (HYPERVISOR_memory_op(XENMEM_remove_from_physmap, &xrfp) != 0)
157+ panic("Failed to unmap HYPERVISOR_shared_info\n");
158+
159+ /*
160+ * After removing from physmap there will be a hole in address space on
161+ * HYPERVISOR_shared_info address, so to free memory allocated with
162+ * memalign and prevent exceptions during access to this page we need to
163+ * fill this 4KB hole with XENMEM_populate_physmap before jumping to Linux.
164+ */
165+ reservation.domid = DOMID_SELF;
166+ reservation.extent_order = 0;
167+ reservation.address_bits = 0;
168+ set_xen_guest_handle(reservation.extent_start, &shared_info_pfn);
169+ reservation.nr_extents = nr_exts;
170+ if (HYPERVISOR_memory_op(XENMEM_populate_physmap, &reservation) != nr_exts)
171+ panic("Failed to populate memory on HYPERVISOR_shared_info addr\n");
172+
173+ /* Now we can return this to memory allocator */
174+ free(HYPERVISOR_shared_info);
175+}
176+
147177 void do_hypervisor_callback(struct pt_regs *regs)
148178 {
149179 unsigned long l1, l2, l1i, l2i;
@@ -251,4 +281,5 @@ void xen_fini(void)
251281 fini_gnttab();
252282 fini_xenbus();
253283 fini_events();
284+ unmap_shared_info();
254285 }