From 40ba4015e313863facc721f7f06210b03057197c Mon Sep 17 00:00:00 2001 From: Daniel Leung Date: Tue, 21 Nov 2023 15:04:02 -0800 Subject: [PATCH] kernel: mm: only include demand_paging.h if needed This moves including of demand_paging.h out of kernel/mm.h, so that users of demand paging APIs must include the header explicitly. Since the main user is kernel itself, we can be more discipline about header inclusion. Signed-off-by: Daniel Leung --- arch/x86/core/userspace.c | 4 ++++ include/zephyr/kernel/mm.h | 1 - include/zephyr/kernel/thread.h | 2 +- kernel/mmu.c | 4 ++++ kernel/paging/statistics.c | 2 +- .../demand_paging/backing_store/backing_store_qemu_x86_tiny.c | 1 + subsys/demand_paging/backing_store/ram.c | 1 + subsys/demand_paging/eviction/nru.c | 2 ++ tests/kernel/fatal/exception/src/main.c | 4 ++++ tests/kernel/mem_protect/demand_paging/src/main.c | 1 + 10 files changed, 19 insertions(+), 3 deletions(-) diff --git a/arch/x86/core/userspace.c b/arch/x86/core/userspace.c index 2b058206232..9380c14d005 100644 --- a/arch/x86/core/userspace.c +++ b/arch/x86/core/userspace.c @@ -11,6 +11,10 @@ #include #include +#ifdef CONFIG_DEMAND_PAGING +#include +#endif + #ifndef CONFIG_X86_KPTI /* Update the to the incoming thread's page table, and update the location of * the privilege elevation stack. diff --git a/include/zephyr/kernel/mm.h b/include/zephyr/kernel/mm.h index 392dc4b7cde..0f6c76e7cdc 100644 --- a/include/zephyr/kernel/mm.h +++ b/include/zephyr/kernel/mm.h @@ -14,7 +14,6 @@ #endif #include -#include /** * @brief Kernel Memory Management diff --git a/include/zephyr/kernel/thread.h b/include/zephyr/kernel/thread.h index b152dfb909a..91cf710e870 100644 --- a/include/zephyr/kernel/thread.h +++ b/include/zephyr/kernel/thread.h @@ -8,7 +8,7 @@ #define ZEPHYR_INCLUDE_KERNEL_THREAD_H_ #ifdef CONFIG_DEMAND_PAGING_THREAD_STATS -#include +#include #endif #include diff --git a/kernel/mmu.c b/kernel/mmu.c index 6abd9349dd6..a58bc77189b 100644 --- a/kernel/mmu.c +++ b/kernel/mmu.c @@ -20,6 +20,10 @@ #include LOG_MODULE_DECLARE(os, CONFIG_KERNEL_LOG_LEVEL); +#ifdef CONFIG_DEMAND_PAGING +#include +#endif + /* * General terminology: * - A page frame is a page-sized physical memory region in RAM. It is a diff --git a/kernel/paging/statistics.c b/kernel/paging/statistics.c index e8972738135..06e867cd218 100644 --- a/kernel/paging/statistics.c +++ b/kernel/paging/statistics.c @@ -8,7 +8,7 @@ #include #include #include -#include +#include extern struct k_mem_paging_stats_t paging_stats; diff --git a/subsys/demand_paging/backing_store/backing_store_qemu_x86_tiny.c b/subsys/demand_paging/backing_store/backing_store_qemu_x86_tiny.c index 023adc06fad..9f100649d49 100644 --- a/subsys/demand_paging/backing_store/backing_store_qemu_x86_tiny.c +++ b/subsys/demand_paging/backing_store/backing_store_qemu_x86_tiny.c @@ -20,6 +20,7 @@ #include #include #include +#include void *location_to_flash(uintptr_t location) { diff --git a/subsys/demand_paging/backing_store/ram.c b/subsys/demand_paging/backing_store/ram.c index c8ba9378a0b..a18995e1b7f 100644 --- a/subsys/demand_paging/backing_store/ram.c +++ b/subsys/demand_paging/backing_store/ram.c @@ -8,6 +8,7 @@ #include #include #include +#include /* * TODO: diff --git a/subsys/demand_paging/eviction/nru.c b/subsys/demand_paging/eviction/nru.c index 108bc504c02..83c4a3b53d7 100644 --- a/subsys/demand_paging/eviction/nru.c +++ b/subsys/demand_paging/eviction/nru.c @@ -10,6 +10,8 @@ #include #include +#include + /* The accessed and dirty states of each page frame are used to create * a hierarchy with a numerical value. When evicting a page, try to evict * page with the highest value (we prefer clean, not accessed pages). diff --git a/tests/kernel/fatal/exception/src/main.c b/tests/kernel/fatal/exception/src/main.c index ea4ffaa7c34..07ac26ffc55 100644 --- a/tests/kernel/fatal/exception/src/main.c +++ b/tests/kernel/fatal/exception/src/main.c @@ -18,6 +18,10 @@ #include "test_syscalls.h" #endif +#if defined(CONFIG_DEMAND_PAGING) +#include +#endif + #if defined(CONFIG_X86) && defined(CONFIG_X86_MMU) #define STACKSIZE (8192) #else diff --git a/tests/kernel/mem_protect/demand_paging/src/main.c b/tests/kernel/mem_protect/demand_paging/src/main.c index a453c06a573..7b733bfc340 100644 --- a/tests/kernel/mem_protect/demand_paging/src/main.c +++ b/tests/kernel/mem_protect/demand_paging/src/main.c @@ -6,6 +6,7 @@ #include #include +#include #include #include #include