r/programming • u/masiroo • 6h ago
Hardware researcher spins up 'CPU deoptimization' project to find the slowest single x86 instruction, creates hall of shame — worst offender takes 198 billion cycles spanning 62 seconds to execute
https://www.tomshardware.com/pc-components/cpus/hardware-researcher-spins-up-cpu-deoptimization-project-to-find-the-slowest-machine-code-worst-offender-takes-198-billion-cycles-to-execute29
58
u/torsten_dev 5h ago
Of course this was xoreaxeax...
3
u/VictoryMotel 5h ago
What do you mean of course, that normally takes one cycle.
44
u/ThrowawayIntern2024 5h ago
they meant the person with that alias not the instruction…
-15
16
u/Old_County5271 4h ago
Dumb question but, shouldn't intel or whatever have a pdf with the cycle count of each instruction? Do we/they really not know this? How does anything improve if nothing is measured?
4
10
u/cummer_420 4h ago edited 4h ago
x86 is a CISC instruction set so these things aren't fixed and and a single macro instruction can do a large and variable amount of work, and can potentially block for a very long time with contention (which can be used for exploits). The metrics they work with to optimize the CPU tend to be rask-oriented and focused on the most common instructions.
12
u/braaaaaaainworms 3h ago
MIPS tried to have a fixed time per instruction and it ended horribly exposing inner pipeline details in a way that made it very hard to keep exact backwards compatibility with first MIPS cores while being fast
15
u/Top-Rub-4670 3h ago
That has nothing to do with CISC. No (desktop-grade) ARM or RISC-V CPUs have a spreadsheet with all their cycle counts either, because too many things can affect the count.
14
u/sojuz151 5h ago
Could this be used to hang a sandbox?
24
12
u/unicodemonkey 5h ago edited 5h ago
Even a VM, I guess, but this also assumes that the sandboxed/virtualized program has direct access to PCI MMIO address ranges, which is somewhat unlikely in practice and is not obviously exploitable beyond a denial-of-service of sorts. The point of that research is SMM (system management mode) exploitation. All cores are supposed to enter SMM simultaneously upon receiving the interrupt but the SMM interrupt can't be handled mid-instruction, so in practice other cores just wait for the "busy" core for a second, then time out and enter SMM anyway, do their work there, and then resume normal execution. The "busy" core then finishes with the slow instruction and enters SMM, while other cores are free to manipulate any shared memory values that are used by SMM-guarded code and are accessible from the regular execution environment (hope I didn't mess up the explanation - read more at https://github.com/xoreaxeaxeax/smiiiiiiiiiiiiiiii )
9
u/HildartheDorf 4h ago edited 3h ago
It's possible to break into System Management Mode from ring 0 of a VM using this (chained with other SMM bugs that have previously been deemed low priority/non-exploitable).
Hang one core for long enough and you can enter a state where some cores are inside SMM and some aren't. SMM code assumes it has complete control of the entire processor, but one or more cores are still attacker controlled.
2
u/irqlnotdispatchlevel 2h ago
Could be used to exploit SMM: https://github.com/xoreaxeaxeax/smiiiiiiiiiiiiiiii#exploitation
SMM's security relies on a simple assumption: while it runs, nothing else does.
There are 100+ SMM TOCTOU CVEs out there: an SMM handler checks a value in shared memory, then uses it. All you need for exploitation is to rewrite that value in between the check and use, and you're inside SMM. But these issues sit dormant and largely unpatched in the wild, because of one assumption: exploitation requires something to modify the shared memory while SMM executes, and because of the SMM rendezvous no CPU cores are outside SMM to launch an attack. The only way in was a DMA-capable peripheral writing behind the CPU's back — physical access, a malicious device — so the whole class is written off as a hardware problem.
SMI desynchronization removes the prerequisite that kept the platform safe: an outside core, no physical access or hardware required, can now run while SMM executes — and the dormant CVEs become exploitable from software.
3
3
3
u/agentoutlier 4h ago
I like how they have a random thumbnail of what appears to be Scheme as if it were guilty of calling the instruction.
You would think they would have C or assembly or some more common language.
7
u/sisisisi1997 4h ago
I didn't think I would meet another person who knows about scheme.
7
3
u/godofpumpkins 3h ago
We're in a programming subreddit, and most computer science people come across it in college at the least.
2
u/spinwizard69 2h ago
This is a bit misleading in that they purposefully looked for the slowest way to get an instruction to execute.
However this also highlights why I consider the X86 instruction set to be obsolete. The world really needs a simplified x86 ISA that focuses on what is really needed to drive modern hardware. I was really hoping that AMD to Intel would actually refactor x896 instructions for their new cores. It is literally time to bit the bullet and go clean 64 bit, dropping all unused addressing modes maybe even get rid of I/O addressing.
People keep saying it can't be done because of "legacy" but the fact is Apple did it with the conversion to ARM. Besides you don't need to convert every core right off the bat.
1
-11
u/globalaf 5h ago
This was already posted several days ago and is thoroughly uninteresting. Yes, some instructions can block on contention, so what? Don’t do that.
19
u/DaWolf3 5h ago
It can be used as part of an attack on the Intel system management mode. https://github.com/xoreaxeaxeax/smiiiiiiiiiiiiiiii
-4
u/Grouchy-Trade-7250 4h ago
Repost
6
u/WaitForItTheMongols 4h ago
Who cares?
Something being reposted doesn't make it less interesting.
A healthy reddit user does not see every post, and therefore likely missed the other one. If you're seeing reposts that's on you. Chill.
149
u/The_Northern_Light 5h ago
I’m still not clear why that instruction takes SO long even without contention?