简体   繁体   English

在Linux / aarch64上记录和调试未对齐的访问

[英]Logging and debugging unaligned accesses on Linux / aarch64

How can I log unaligned memory accesses on Linux / aarch64 (Cortex-a57)? 如何在Linux / aarch64(Cortex-a57)上记录未对齐的内存访问?

I understand there are two different things involved here: 我知道这里涉及两件不同的事情:

  1. Choosing to raise an interrupt from the cpu on an unaligned access (ie. interrupts for unaligned memory accesses that would otherwise be supported by the cpu at a performance cost) 选择在未对齐访问时从cpu引发中断(即,对于未对齐的内存访问的中断,否则将以性能成本支持cpu)
  2. Choosing how to handle these interrupts in Linux (log them / fire a SIGBUS / soft emulate unaligned access) 选择如何在Linux中处理这些中断(记录/触发SIGBUS / soft模拟未对齐访问)

My problem is that first, I do not know how to manage the cpu's control registers from my program (nor if I should actually do it in my userspace application), and second, the /proc/cpu/alignment interface for managing the unaligned accesses in Linux seems to be gone (I am using a 4.4.0 kernel), see link below. 我的问题是,首先,我不知道如何从我的程序中管理cpu的控制寄存器(我也不应该在我的用户空间应用程序中实现它),其次,用于管理未对齐访问的/proc/cpu/alignment接口在Linux中似乎已经消失了(我使用的是4.4.0内核),请参阅下面的链接。

Managing unaligned accesses from the kernel: https://www.kernel.org/doc/Documentation/arm/mem_alignment (likely out-of-date) 管理来自内核的未对齐访问: https//www.kernel.org/doc/Documentation/arm/mem_alignment (可能已过期)

Related: Does AArch64 support unaligned access? 相关: AArch64是否支持未对齐访问?

You can't do this. 你不能这样做。 Not with Linux, anyway. 无论如何,不​​是用Linux。

Alignment faults for EL0 are governed by the SCTLR_EL1.A bit, but that also affects EL1. EL0的对齐故障由SCTLR_EL1.A位控制,但这也会影响EL1。 Thus even if you wrote a hacky kernel module to enable it (you obviously can't touch privileged system control registers directly from userspace), you're pretty much guaranteed that the kernel's going to panic as soon as the next network packet arrives. 因此,即使你编写了一个hacky内核模块来启用它(你显然无法直接从用户空间触摸特权系统控制寄存器),你几乎可以保证一旦下一个网络数据包到达,内核就会出现恐慌。 The arm64 kernel port relies on having the unaligned access capability provided by AArch64. arm64内核端口依赖于AArch64提供的未对齐访问功能。 It doesn't have the ARM port's /proc/cpu/alignment handler, because it doesn't have the legacy of pre-ARMv6 CPUs that didn't support unaligned access at all (well, in any usable fashion at least). 它没有ARM端口的/proc/cpu/alignment处理程序,因为它没有完全不支持未对齐访问的前ARMv6 CPU的遗留(至少以任何可用的方式)。

What you can do, though, is use perf tools to monitor any or all of Cortex-A57's microarchitectural PMU events 0x68, 0x69 or 0x6a, to count the unaligned-access-related events which your program triggers. 但是,您可以使用perf工具监视Cortex-A57的任何或所有微体系结构PMU事件 0x68,0x69或0x6a,以计算程序触发的未对齐访问相关事件。 There's no means to trap or debug individual accesses as there might be with the blunt instrument of alignment faults, but otherwise it's arguably more useful since it'll only count events attributable to your program. 没有办法捕获或调试单个访问,因为可能存在对齐错误的钝器,但是否则它可能更有用,因为它只会计算可归因于程序的事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM