diff mbox series

[RFC,72/84] acpi: don't assume an always-mapped direct map in acpi allocations.

Message ID e5719944c6005ee7eebcdbee503baf26c106d14f.1569489002.git.hongyax@amazon.com (mailing list archive)
State New, archived
Headers show
Series Remove direct map from Xen | expand

Commit Message

Xia, Hongyan Sept. 26, 2019, 9:46 a.m. UTC
From: Hongyan Xia <hongyax@amazon.com>

Signed-off-by: Hongyan Xia <hongyax@amazon.com>
---
 xen/drivers/acpi/osl.c | 41 +++++++++++++++++++++++++++++------------
 1 file changed, 29 insertions(+), 12 deletions(-)
diff mbox series

Patch

diff --git a/xen/drivers/acpi/osl.c b/xen/drivers/acpi/osl.c
index 4c8bb7839e..dbf62325f3 100644
--- a/xen/drivers/acpi/osl.c
+++ b/xen/drivers/acpi/osl.c
@@ -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);
+    }
 }