@@ -216,14 +216,25 @@ acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width)
void *__init acpi_os_alloc_memory(size_t sz)
{
- void *ptr;
-
- if (system_state == SYS_STATE_early_boot)
- return mfn_to_virt(mfn_x(alloc_boot_pages(PFN_UP(sz), 1)));
-
- ptr = xmalloc_bytes(sz);
- ASSERT(!ptr || is_xmalloc_memory(ptr));
- return ptr;
+ void *ptr;
+ unsigned long nr_pfns = PFN_UP(sz);
+ mfn_t mfn;
+
+ if (system_state == SYS_STATE_early_boot)
+ {
+ mfn = alloc_boot_pages(nr_pfns, 1);
+ ptr = mfn_to_virt(mfn_x(mfn));
+ /*
+ * Direct map is garbage now, fill the actual mapping. Safe to do so
+ * now because map_pages got rid of the direct map even in early boot.
+ */
+ map_pages_to_xen((unsigned long)ptr, mfn, nr_pfns, PAGE_HYPERVISOR);
+ return ptr;
+ }
+
+ ptr = xmalloc_bytes(sz);
+ ASSERT(!ptr || is_xmalloc_memory(ptr));
+ return ptr;
}
void *__init acpi_os_zalloc_memory(size_t sz)
@@ -241,8 +252,14 @@ void *__init acpi_os_zalloc_memory(size_t sz)
void __init acpi_os_free_memory(void *ptr)
{
- if (is_xmalloc_memory(ptr))
- xfree(ptr);
- else if (ptr && system_state == SYS_STATE_early_boot)
- init_boot_pages(__pa(ptr), __pa(ptr) + PAGE_SIZE);
+ mfn_t mfn;
+ if (is_xmalloc_memory(ptr))
+ xfree(ptr);
+ else if (ptr && system_state == SYS_STATE_early_boot)
+ {
+ init_boot_pages(__pa(ptr), __pa(ptr) + PAGE_SIZE);
+ /* Also unmap in the 1:1 region for security. */
+ mfn = _mfn(virt_to_mfn(ptr));
+ map_pages_to_xen((unsigned long)ptr, mfn, 1, _PAGE_NONE);
+ }
}