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
This commit is contained in:
Kelvin Zhang 2023-08-18 13:13:54 -07:00
parent 4b503b968c
commit d479afa037

View file

@ -35,6 +35,7 @@
#include <android-base/chrono_utils.h>
#include <android-base/file.h>
#include <android-base/logging.h>
#include <android-base/stringprintf.h>
#include <modprobe/modprobe.h>
#include <private/android_filesystem_config.h>
@ -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<std::string> 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;