Re: [PATCH v3 2/4] x86/alternative: Support relocations in alternatives

From: Borislav Petkov
Date: Fri Feb 17 2023 - 15:28:20 EST


On Wed, Feb 08, 2023 at 06:10:52PM +0100, Peter Zijlstra wrote:
> /*
> + * What we start with is:

Some more clarification and de-personalization of this comment. Diff
ontop:

---
diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
index 625f05c2b255..e14bc15bf646 100644
--- a/arch/x86/kernel/alternative.c
+++ b/arch/x86/kernel/alternative.c
@@ -201,15 +201,21 @@ static void __init_or_module noinline optimize_nops(u8 *instr, size_t len)
}

/*
- * What we start with is:
+ * In this context, "source" is where the instructions are placed in the
+ * section .altinstr_replacement, for example during kernel build by the
+ * toolchain.
+ * "Destination" is where the instructions are being patched in by this
+ * machinery.
+ *
+ * The source offset is:
*
* src_imm = target - src_next_ip (1)
*
- * what we want is:
+ * and the target offset is:
*
* dst_imm = target - dst_next_ip (2)
*
- * so what we do is rework (1) as an expression for target like:
+ * so rework (1) as an expression for target like:
*
* target = src_imm + src_next_ip (1a)
*
@@ -217,8 +223,8 @@ static void __init_or_module noinline optimize_nops(u8 *instr, size_t len)
*
* dst_imm = (src_imm + src_next_ip) - dst_next_ip (3)
*
- * Now, since the instruction stream is 'identical' at src and dst (we copy
- * after all) we can state that:
+ * Now, since the instruction stream is 'identical' at src and dst (it
+ * is being copied after all) it can be stated that:
*
* src_next_ip = src + ip_offset
* dst_next_ip = dst + ip_offset (4)


--
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette