This patch adds a low-cost, conditional execution mechanism based on hot-patching.
Its main goal is to provide a way of optimize infrequently used if-statements in performance-sensitive code.
Instead of repeatedly evaluating an if statement, a single branch
direction is "baked in" at compile time. This is achieved by an unconditional
jump or nop using the using 'asm goto' feature. When the branch direction needs
to be changed, the appropriate instruction is patched at runtime.
Previous code blocks of form:
```
bool flag = false;
if(flag) {
action1();
}
if(!flag) {
action2();
}
```
would be migrated to the new interface as:
```
DEFINE_ZCOND_FALSE(flag);
if(zcond_true(flag)) {
action1();
}
if(zcond_false(flag)) {
action2();
}
```
Since this kernel code patching is central to this mechanism, special care was taken to mitigate any potential security risks.
Rather than explicitly turning certain hardware protections off (e.g. disable_wp()), this patch uses a separate
kernel page table to perform kernel code patching. This separate page table is initalized by copying parts of the kernel pmap during boot.
Instruction patching will use the `smp_rendevous` routines to ensure that only one CPU
is performing the patching while the rest are stopped. The code will then map the underlying phsyical page
containing the target instruction into the separate kernel page table and temporarily switch to it in order to patch the instruction.
This revision also modifies SDT to use this mechanism, both as a proof of concept and example of use.
This revision introduces support for the amd64 architecture only.
Support for all other architectures will be added if the overall approach is deemed acceptable.
This work was sponsored by the GSoC '24 program.