aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--arch/x86_64/arch/memory/mmu.hpp2
-rw-r--r--arch/x86_64/arch/memory/page_table.hpp34
-rw-r--r--kapi/kapi/memory.hpp7
-rw-r--r--kapi/kapi/memory/page_mapper.hpp17
-rw-r--r--kernel/kapi/memory.cpp7
5 files changed, 50 insertions, 17 deletions
diff --git a/arch/x86_64/arch/memory/mmu.hpp b/arch/x86_64/arch/memory/mmu.hpp
index 934aa63f..f824ba53 100644
--- a/arch/x86_64/arch/memory/mmu.hpp
+++ b/arch/x86_64/arch/memory/mmu.hpp
@@ -11,6 +11,8 @@ namespace arch::memory
auto tlb_flush(kapi::memory::linear_address address) -> void;
//! Invalidate all translation lookaside buffer (TLB) entries
+ //!
+ //! @note Once CR4.PGE is set, this function will no longer flush TLB entries for global pages.
auto tlb_flush_all() -> void;
} // namespace arch::memory
diff --git a/arch/x86_64/arch/memory/page_table.hpp b/arch/x86_64/arch/memory/page_table.hpp
index 0c0f1a77..c34f72e0 100644
--- a/arch/x86_64/arch/memory/page_table.hpp
+++ b/arch/x86_64/arch/memory/page_table.hpp
@@ -40,16 +40,30 @@ namespace arch::memory
enum struct flags : std::uint64_t
{
empty = 0,
- present = 1uz << 0, //!< The page is mapped.
- writable = 1uz << 1, //!< The page is writable.
- user_accessible = 1uz << 2, //!< The page is accessible in user mode.
- write_through = 1uz << 3, //!< Any writes to the page must immediately hit memory.
- disable_cache = 1uz << 4, //!< Any writes to the page must never be cached.
- accessed = 1uz << 5, //!< The page was accessed.
- dirty = 1uz << 6, //!< The page was written to.
- huge_page = 1uz << 7, //!< The page is huge.
- global = 1uz << 8, //!< The TLB entry for this page must not be flushed on context switches.
- no_execute = 1uz << 63, //!< The data in this page must not be executed.
+ //! The page is mapped.
+ present = 1uz << 0,
+ //! The page is writable.
+ writable = 1uz << 1,
+ //! The page is accessible in user mode.
+ user_accessible = 1uz << 2,
+ //! Any writes to the page must immediately hit memory.
+ write_through = 1uz << 3,
+ //! Any writes to the page must never be cached.
+ disable_cache = 1uz << 4,
+ //! The page was accessed.
+ accessed = 1uz << 5,
+ //! The page was written to.
+ dirty = 1uz << 6,
+ //! The page is huge.
+ huge_page = 1uz << 7,
+ //! The TLB entry for this page must not be flushed on context switches.
+ //!
+ //! @note This flag is currently not honored by this implementation, since the CR4.PGE bit is not set. As a
+ //! consequence, any CR3 reload or a call to arch::memory::tlb_flush_all will still flush this entry on context
+ //! switches.
+ global = 1uz << 8,
+ //! The data in this page must not be executed.
+ no_execute = 1uz << 63,
};
//! Construct an empty entry.
diff --git a/kapi/kapi/memory.hpp b/kapi/kapi/memory.hpp
index 4cdd6ac1..7979c7e1 100644
--- a/kapi/kapi/memory.hpp
+++ b/kapi/kapi/memory.hpp
@@ -103,9 +103,12 @@ namespace kapi::memory
//! Map a region of Memory-mapped I/O address space to a given hardware address using the given flags.
//!
//! @warning This function will panic if no page mapper has been registered, or the page has already been mapped.
- //! This function will not ensure that the frame is not already in use.
//!
- //! This function will always set the @p uncached flag.
+ //! @warning This function will not ensure that the frame is not already in use.
+ //!
+ //! @warning This function will panic if an attempt is made to map an MMIO region as executable.
+ //!
+ //! This function will always set the @p uncached, @p global, and @p supervisor_only flags.
//!
//! @param region The region to map.
//! @param hw_base The base of the hardware region.
diff --git a/kapi/kapi/memory/page_mapper.hpp b/kapi/kapi/memory/page_mapper.hpp
index 4a4827b6..889ef052 100644
--- a/kapi/kapi/memory/page_mapper.hpp
+++ b/kapi/kapi/memory/page_mapper.hpp
@@ -32,11 +32,18 @@ namespace kapi::memory
enum struct flags : std::uint64_t
{
empty,
- writable = 1 << 0, //! The page is writable.
- executable = 1 << 1, //! The page contains executable instructions.
- uncached = 1 << 2, //! The page contents must not be cached.
- supervisor_only = 1 << 3, //! The page is only accessible in supervisor mode.
- global = 1 << 4, //! The page translation persists across context switches.
+ //! The page is writable.
+ writable = 1 << 0,
+ //! The page contains executable instructions.
+ executable = 1 << 1,
+ //! The page contents must not be cached.
+ uncached = 1 << 2,
+ //! The page is only accessible in supervisor mode.
+ supervisor_only = 1 << 3,
+ //! The page translation persists across context switches.
+ //!
+ //! @note A given platform may not honor this flag.
+ global = 1 << 4,
};
virtual ~page_mapper() = default;
diff --git a/kernel/kapi/memory.cpp b/kernel/kapi/memory.cpp
index 65f9f319..83b32f0d 100644
--- a/kernel/kapi/memory.cpp
+++ b/kernel/kapi/memory.cpp
@@ -183,6 +183,13 @@ namespace kapi::memory
auto map_mmio_region(mmio_region region, physical_address hw_base, page_mapper::flags flags)
-> kstd::result<kstd::observer_ptr<std::byte>>
{
+ // Ensure that the MMIO region is not mapped as executable. Asking for an executable mapping of an MMIO region is a
+ // logical error, not a runtime issue.
+ if ((flags & page_mapper::flags::executable) != page_mapper::flags::empty)
+ {
+ system::panic("[OS:MEM] Attempt to map MMIO region at {:#018x} as executable!", region.first);
+ }
+
auto [start, count] = region;
auto start_page = page::containing(start);