Linux 内核:通过替换进行功能拦截的指令缓存和 mp-IRQ 子系统是什么?
我正在尝试实现内核函数拦截(使用 这个老方法 (c) Silvio);根据 此论坛帖子,一些可能的缺陷可能与指令缓存和 mp 有关-IRQ 源,在拦截后不会刷新/更新。
这些子系统是什么以及在这种情况下如何处理它们?
I'm trying to implement a kernel function intercept (replacing a System.map's pointer to function, using this old method (c) Silvio); according to this forum post, some possible flaws may be related to instruction cache and mp-IRQ sources, which aren't flushed/updated after the interception.
What are these subsystems and how to deal with them in this case?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
指令缓存不是 Linux 内核子系统 - 它是 CPU 的一部分。
从主存中获取代码需要花费大量时间,因此 CPU 使用高速缓存来缓存代码段。这是指令缓存,保存 CPU 有理由相信很快就会需要的指令(代码)副本。
如果您更改内存中的指令(代码)(如所提到的示例所示),但不刷新指令缓存,则更改后的代码可能会神秘地无法运行,直到某个随机时间点,指令缓存条目保存您替换的指令被清除。
mp-IRQ 是多处理器中断的缩写。与此相关的问题是,在 SMP(多 CPU 或多核)系统上,植入跟踪点的代码可能在一个 CPU 上运行,而另一个 CPU 正在执行它。为了安全地处理这个问题,您需要执行非常复杂的同步所有 CPU 的任务,以确保您尝试修补的代码不会被中断在其他 CPU 上使用。
The instruction cache isn't a Linux kernel subsystem - it's part of the CPU.
Fetching code from main memory takes a lot of time, so CPUs use cache memory to cache code sections. This is the instruction cache that holds copies of instructions (code) that the CPU has a reason to believe will be needed soon.
If you change the instructions (code) in memory, as the example referred to does, but do not flush the instruction cache, your changed code might mysteriously fail to run until some random point in time where the instruction cache entry holding the instruction you replaced gets cleared.
mp-IRQ is short for Multiple Processor Interrupts. The problem related to in this context is that on a SMP (multiple CPU or multi core) system, the code that plants your trace point might be running on one CPU, while another is executing it. To handle that safely you need to do the very complex task of syncing al the CPU to make sure the code you are trying to patch is not being use on some other CPU by an interrupt.