[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [RFC PATCH 72/84] acpi: don't assume an always-mapped direct map in acpi allocations.
From: Hongyan Xia <hongyax@xxxxxxxxxx> Signed-off-by: Hongyan Xia <hongyax@xxxxxxxxxx> --- xen/drivers/acpi/osl.c | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) 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); + } } -- 2.17.1 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |