As Google Summer of Code is almost over I will create a summary of my contribution to The Linux Foundation during this period.
Firstly, I will describe again my project in order for the further work description to be more comprehensible.
This project aims to add support for Linux Kernel backports in already existing configuration option, localmodconfig. The goal is to automatically determine the available functionalities not only from the drivers provided by the current kernel version but also from all the backported ones. This project is not limited to backports but aims to build a better kernel configuration generator. Current solutions are based on heuristics so this project’s ultimate goal is to provide a deterministic algorithm of generating the most suitable kernel configuration for a target machine.
I have documented my entire work in blog posts so, for additional information about the project’s purpose you can consult this post.
This project consists of research so it had multiple phases / approaches:
1. The first approach was to use hardware interrogation tools to determine what actual devices are available on a particular system and create a configuration which includes the drivers for these devices. During my research I have created this document gathering all information encountered. This approach is not fiable: firstly, the list is not exhaustive for the existing hardware interfaces and, secondly, some tools do not provide driver information about the connected devices so they are not relevant. Finally, I have found a generic hardware interrogation tool ‘udevadm’ which determines all connected devices and driver information for those which have an available driver in the current kernel.
Other documents created during phase 1: Short summary based on the ‘Attack Surface Metrics and Automated Compile-Time OS Kernel Tailoring’ paper which targets same goal as this project.
2. I modified the already existing scripts/kconfig/streamline_config.pl which creates a configuration starting from the output of ‘lsmod’ (comand which returns the current loaded drivers) to apply same algorithm for drivers found with ‘udevadm’
Phases 1 & 2 are documented in this post including conclusions and results.
3. Since not all devices expose the driver name my next task was to extend entries from virtual file system /sys to display by default the CONFIG_* symbol that needs to be set at configuration time in order to add the corresponding driver to the kernel. I extended the kernel ‘struct kobject’ to contain and display this information.
Here you can find the patch for this implementation.
Documentation, conclusions and results: this blog post – section Approach 1.
4. Modifying the kobject structure did not provide the required results so next step was to extend the kernel ‘struct module’ to display the desired information.
Documentation, conclusions and results: this blog post – section Approach 2
The series of patches:
5. Starting from the previous series of patches I have implemented dynamic pegging of CONFIG_* symbol, namely, CONFIG_* symbol is determined at compilation time by the Makefile and passed to the kernel modules as compilation parameter. This implementation also solves few matching problems between module names – CONFIG_* symbol and optimizes it.
Documentation, conclusions and results: this blog post – section Approach 3
The series of patches:
What is done by now ?
The result of the project currently is that for each module instance from /sys there is a kconfig_symbol atribute which displays the CONFIG_* option for that module.
The project’s flow:
- Generate associations (module name – CONFIG_* symbol) into file scripts/Module.ksymb
- Update Makefile to load file scripts/Module.ksymb and access the matchings.
- Update the Makfile to dynamically add the corresponding CONFIG_FOO symbol to the compilation command of kernel module ‘foo’ as macro passed as parameter
- Add extra attribute to kernel ‘struct module’ for kconfig_symbol
- Update modpost to add that macro as content of kconfig_symbol attribute
The project provides the infrastructure of loading the associations from a file scripts/Module.ksymb, adding them to the kernel module and update the kernel module’s code to have an extra attribute in order to display this information. Therefore, if the generator will be upgraded / replaced with another one which outputs data in the same format, the other components of the project are perfectly reusable.
The solution offers a good matching (module-name <-> CONFIG_* symbol) correctness percentage but still has some issues. For the tested system (x86_64, configuration generated with ‘make localmodconfig’), from a total of 58 loaded modules, 54 has a correct kconfig_symbol attribute while the other 4 had an empty kconfig_symbol attribute.
Note: This post contains brief descriptions of each phase. More details can be found in each corresponding blog post.
What will be done ?
- Implement a better algorithm for generating the associations (module-name <–> CONFIG_* symbol).
- Extend kernel structures to display the CONFIG_* symbol for all devices not only the ones for which drivers are loaded
- Extend udevadm to extract CONFIG_* symbols from /sys along with other collected information