by Falcon [email protected] of tinylab.org
2014/01/22
Section mismatch Introduction
Section mismatch is a very serious bug that can cause unpredictable memory access problems, and it is recommended to be cautious, and if you add drivers with similar warning, you may need to pay close attention and resolve them.
The following is an analysis of the problem's detection, causes, solutions, and the latest frontier.
Detection of section mismatch
CONFIG_DEBUG_SECTION_MISMATCH=y
With the above option turned on, the kernel will call to modpost
detect a similar problem.
Reasons for section mismatch
In order to reduce unnecessary memory consumption, Linux is placed in the init sections for some resources (including functions and variables) that are used only during kernel initialization, and these init sections are lost by the kernel after the kernel initialization is complete. In addition, considering the differences between different modules or subsystems, their code and data will be placed in their respective sections, and cross-references may have potential problems.
If a section refers to a variable in the other of the sections, there will be a sections mismatch warning. If a run-time function refers to a function in an init section, then the problem arises.
When the Linux kernel is started, the memory used by the Init section is free, and if this memory is written into unpredictable content by other devices, then there is an unpredictable risk that the system may be in some cases lucky, and this memory has never been referenced by other devices. , so, even if the compiler saw the warning, the system did not crash, but the bombs on the pillow, very dangerous, moved early as well.
Section Mismatch's solution
There are several situations:
- If a run-time function references a function or variable in the init section
If the run-time function is required to be used at run time and cannot be placed in the Init section, remove the markup for the function in the init section __init*
, otherwise add the corresponding Init declaration to the former.
For the associated init tag, please refer to: include/linux/init.h
- If there is a cross-reference between the different sections, the cross-reference is secure, then the section
__ref
mismatch Detector (modpost) is ignored by the tag to ignore the relevant check
For example, in the CPU hotplug, not in the __cpuinit
init section, Access is safe at run time, if there is an external function (unmarked __cpuinit
) access to the __cpuinit
marked function, there is a cross-reference. Because this access is secure, you can let the kernel ignore its detection and __ref
mark the function.
Recent developments in section mismatch
In the latest arm kernel, an intelligent detection is introduced, which is a situation where free memory is accessed by the runtime function, and the previous analysis mentions that similar situations can lead to unpredictable risks, and that intelligent detection clearly reports specific problems.
The principle of this detection is to initialize all memory areas of the Init section into 0XE7FDDEF0 (an undefined instruction (ARM) or a branch to an undefined instru when the kernel is initialized Ction (Thumb)), if the run-time function illegally accesses these zones, it triggers a undef instruction exception and prints the appropriate callback, which assists the developer in resolving the problem more quickly.
Of course, this does not mean that we do not need to solve the compile-time warning, the delay to the runtime to solve the problem is more energy-intensive, should be in the coding or compilation, such as the early development process to solve, this will improve the development efficiency, this idea for other problems also apply.
This part of the Code please refer to: Arch/arm/mm/init.c:poison_init_mem ()
Linux kernel section mismatch detailed