当Skylake具有FSGSBASE时,为什么我使用__builtin_ia32_wrfsbase64获得非法指令?

发布于 2025-02-10 20:21:45 字数 622 浏览 1 评论 0 原文

我正在使用“ Intel Xeon处理器(Skylake,ibrs)”的服务器上运行代码。我在底部列出了CPU标志。我得到了一个核心转储,在GDB中运行它,并看到非法指令是__builtin_ia32_wrfsbase64(我称为intinsic _WRITEFSBASE_U64)。 __builtin_ia32_rdfsbase64也会导致非法指令。它支持FSGSBase标志,所以我不知道为什么我会遇到问题

标志:fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pat pat pat ps ps ps ps clflush mmx fxsr sse2 syscall ssesscall nx pdpe1gb 16 PCID SSE4_1 SSE4_2 X2APIC MOVBE POPCNT TSC_DEADLINE_TIMER AES XSAVE AVX F16C RDRAND HYPERVISOR LAHF_LM ABM CPUID_FAULT INVPCID_SINGLE PTI SSBD SSBD IBRS IBPB FSGSBASE BMI1 HLE BMI1 HLE AVX2 HLE AVX2 SMEP saveopt arat pku ospke

I'm running my code on a server with "Intel Xeon Processor (Skylake, IBRS)". I listed the cpu flags at the bottom. I got a core dump, ran it in gdb and saw the illegal instruction was __builtin_ia32_wrfsbase64 (I call the intrinsic _writefsbase_u64). __builtin_ia32_rdfsbase64 also causes the illegal instruction. It supports the fsgsbase flag so I don't know why I'm getting a problem

flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology cpuid tsc_known_freq pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm cpuid_fault invpcid_single pti ssbd ibrs ibpb fsgsbase bmi1 hle avx2 smep bmi2 erms invpcid rtm avx512f avx512dq clwb avx512cd avx512bw avx512vl xsaveopt arat pku ospke

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鹿港巷口少年归 2025-02-17 20:21:45

FSGSBASE指令需要操作系统以及硬件的支持。操作系统必须意识到,可以通过用户代码更改基本寄存器,而无需通知操作系统。 OSS可能已经假设只有在用户进行明确的系统调用时才能更改寄存器。 CR4中有一些确定是否允许非特权代码执行这些说明,默认情况下,它是不设置的。这个想法是,只有包含适当支持的操作系统才能实现这一点。参见 Intel的指南有关更多详细信息。

在Linux中,在内核版本5.9中添加了此支持( Arch_prctl 系统调用以请求对FS或GS基本寄存器的更新。否则升级您的内核 / OS。

ELF AUX VECTOR中有一些程序可以在运行时测试,以确定FSGSBASE指令是否可用。参见在“ FSGSBASE指令启用”下。

The FSGSBASE instructions require support from the operating system as well as the hardware. The OS has to be aware that the base registers could be changed by user code without informing the OS; older OSes might have assumed that the registers could only be changed when the user made an explicit system call. There is a bit in CR4 that determines whether unprivileged code is allowed to execute these instructions, and by default, it is unset. The idea is that only an OS that contains the appropriate support will enable this bit. See Intel's guidelines for more details.

In Linux, this support was added in kernel version 5.9 (changelog). Per your comment, you are using an older kernel, so you cannot use these instructions, and must fall back to using the arch_prctl system call to request an update to the FS or GS base registers. Or else upgrade your kernel / OS.

There is a bit in the ELF AUX vector that your program can test at runtime to determine whether the FSGSBASE instructions are usable. See https://www.kernel.org/doc/html/latest/x86/x86_64/fsgs.html under "FSGSBASE instructions enablement".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文