Skip to content

Commit

Permalink
x86: map all RAM if ACPI
Browse files Browse the repository at this point in the history
ACPI tables can lurk anywhere. Map all memory so they can be
read.

Signed-off-by: Andrew Boie <[email protected]>
  • Loading branch information
Andrew Boie committed Jan 23, 2021
1 parent 481bed3 commit 9cc440e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
1 change: 0 additions & 1 deletion arch/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ config X86
select ARCH_HAS_TIMING_FUNCTIONS
select ARCH_HAS_THREAD_LOCAL_STORAGE
select ARCH_HAS_DEMAND_PAGING
select ARCH_MAPS_ALL_RAM
help
x86 architecture

Expand Down
1 change: 1 addition & 0 deletions arch/x86/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ endchoice

config ACPI
bool "ACPI (Advanced Configuration and Power Interface) support"
select ARCH_MAPS_ALL_RAM
help
Allow retrieval of platform configuration at runtime.

Expand Down
14 changes: 11 additions & 3 deletions arch/x86/gen_mmu.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,15 @@ def main():
debug("building %s" % pclass.__name__)

vm_base = syms["CONFIG_KERNEL_VM_BASE"]
vm_size = syms["CONFIG_KERNEL_VM_SIZE"]
# Work around #31562
vm_size = syms["CONFIG_KERNEL_VM_SIZE"] & 0xFFFFFFFF

image_base = syms["z_mapped_start"]
image_size = syms["z_mapped_size"]
if isdef("CONFIG_ARCH_MAPS_ALL_RAM"):
image_base = syms["CONFIG_SRAM_BASE_ADDRESS"]
image_size = syms["CONFIG_SRAM_SIZE"] * 1024
else:
image_base = syms["z_mapped_start"]
image_size = syms["z_mapped_size"]
ptables_phys = syms["z_x86_pagetables_start"]

debug("Address space: 0x%x - 0x%x size %x" %
Expand All @@ -471,6 +476,9 @@ def main():

is_perm_regions = isdef("CONFIG_SRAM_REGION_PERMISSIONS")

if image_size >= vm_size:
error("VM size is too small (have 0x%x need more than 0x%x)" % (vm_size, image_size))

if is_perm_regions:
# Don't allow execution by default for any pages. We'll adjust this
# in later calls to pt.set_region_perms()
Expand Down
16 changes: 16 additions & 0 deletions tests/arch/x86/pagetables/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,22 @@ void test_ram_perms(void)
PRI_ENTRY, flags, pos, expected);
}
#endif /* CONFIG_X86_64 */

#ifdef CONFIG_ARCH_MAPS_ALL_RAM
/* All RAM page frame entries aside from 0x0 must have a mapping.
* We currently identity-map on x86, no conversion necessary other than a cast
*/
for (pos = (uint8_t *)Z_PHYS_RAM_START; pos < (uint8_t *)Z_PHYS_RAM_END;
pos += CONFIG_MMU_PAGE_SIZE) {
if (pos == NULL) {
continue;
}

entry = get_entry(&flags, pos);
zassert_true((flags & MMU_P) != 0,
"address %p isn't mapped", pos);
}
#endif
}

/**
Expand Down

0 comments on commit 9cc440e

Please sign in to comment.