From d479afa0372598d1417fbd4ba7cd2459df1aed4a Mon Sep 17 00:00:00 2001 From: Kelvin Zhang Date: Fri, 18 Aug 2023 13:13:54 -0700 Subject: [PATCH] Load kernel modules from /lib/modules/`uname -r`_$(page_size) if present To support booting from both 4k/16k kernels, init need to tell which kernel we are currently booting and load the right modules. To resolve this issue, we store 16K modules into /lib/modules/`uname -r`_16k directory. Test: th Bug: 293313353 Change-Id: I4a8296384537a71e16cd20e76e6c5dfb9074f574 --- init/first_stage_init.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/init/first_stage_init.cpp b/init/first_stage_init.cpp index 88300cb29..3239eb7ca 100644 --- a/init/first_stage_init.cpp +++ b/init/first_stage_init.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -153,6 +154,15 @@ void PrepareSwitchRoot() { Copy(snapuserd, dst); } } + +std::string GetPageSizeSuffix() { + static const size_t page_size = sysconf(_SC_PAGE_SIZE); + if (page_size <= 4096) { + return ""; + } + return android::base::StringPrintf("_%zuk", page_size / 1024); +} + } // namespace std::string GetModuleLoadList(BootMode boot_mode, const std::string& dir_path) { @@ -201,10 +211,18 @@ bool LoadKernelModules(BootMode boot_mode, bool want_console, bool want_parallel } dirent* entry = nullptr; std::vector module_dirs; + const std::string release_specific_module_dir = uts.release + GetPageSizeSuffix(); while ((entry = readdir(base_dir.get()))) { if (entry->d_type != DT_DIR) { continue; } + if (entry->d_name == release_specific_module_dir) { + LOG(INFO) << "Release specific kernel module dir " << release_specific_module_dir + << " found, loading modules from here with no fallbacks."; + module_dirs.clear(); + module_dirs.emplace_back(entry->d_name); + break; + } int dir_major = 0, dir_minor = 0; if (sscanf(entry->d_name, "%d.%d", &dir_major, &dir_minor) != 2 || dir_major != major || dir_minor != minor) { @@ -228,6 +246,7 @@ bool LoadKernelModules(BootMode boot_mode, bool want_console, bool want_parallel bool retval = m.LoadListedModules(!want_console); modules_loaded = m.GetModuleCount(); if (modules_loaded > 0) { + LOG(INFO) << "Loaded " << modules_loaded << " modules from " << dir_path; return retval; } } @@ -237,6 +256,7 @@ bool LoadKernelModules(BootMode boot_mode, bool want_console, bool want_parallel : m.LoadListedModules(!want_console); modules_loaded = m.GetModuleCount(); if (modules_loaded > 0) { + LOG(INFO) << "Loaded " << modules_loaded << " modules from " << MODULE_BASE_DIR; return retval; } return true;