系统与基础设施randomascii.wordpress.com编辑精选
在 Xbox 360 中发现一个 CPU 设计缺陷
Finding a CPU Design Bug in the Xbox 360
2018 — 2021,它一次次回到首页
黑点是上首页(≥ 50 分)的那次投稿,空心点是没冲上去的投稿,点越大分数越高。
导读
这篇文章记录作者在 Xbox 360 上追查一个诡异且难以复现的错误,最终定位到处理器设计缺陷的过程。问题与分支预测和推测执行路径上的 xdcbt 指令有关:一条本不该真正执行的指令仍可能产生副作用,使程序行为不再完全确定。
为什么经久不衰:它是底层调试和 CPU 验证的经典案例,清楚展示了推测执行的隐蔽副作用,对理解现代处理器安全与调试仍有启发。
HN 评论精选
推测执行会让本不该执行的指令产生真实副作用,打破程序确定性假设。
文章摘录:“所以一个推测执行的 xdcbt 和一个真实的 xdcbt 完全相同!” 在看到这句话之前我从未想过这一点,想法大致是:“汇编指令即使运行时条件可能永远不会满足,也可能被推测执行,而根据指令性质,这可能产生巨大影响,包括程序不正确甚至失败。” 换句话说,你的 100% 确定性图灵机,或你认为 100% 确定性的程序,在这些机制面前可能并不那么确定。这为编写汇编代码时需要考虑的东西增加了全新维度。总之,很棒的文章!
peter_d_sherman查看英文原文
Article Excerpt: "So a speculatively-executed xdcbt was identical to a real xdcbt!" I've never thought about it until I saw the above line in the article, and that thought went something like this: "Assembler instructions which might never have the conditions met for their execution during a program's runtime might be speculatively executed nonetheless, and this, depending on the nature of the instruction executed, might have huge ramifications up to and including program incorrectness and even program failure." In other words, your absolutely 100% deterministic Turing machine (or programs that you write on it that you deem to be 100% deterministic) -- may not be quite so deterministic when viewed against these understandings... It adds a whole new dimension to what must be thought about when writing assembler code... Anyway, it's a really great article!
陈旧的预测表项可能让数据字节被当作指令执行,因此任意数据都可能构成风险。
是否可以公平地说,内存中任何看起来像 xdcbt 指令的字节序列,即使这些字节只是数据,都是不安全的?因为分支预测表中的陈旧条目可能最终指向这些字节。
rwmj查看英文原文
Would it be fair to say that having any sequence of bytes in memory which looks like the xdcbt instruction (even if those bytes are just data) is unsafe? Given that a stale entry in the branch prediction table might end up pointing at those bytes.
错误预测的 xdcbt 若已产生缓存副作用,撤销它需要缓存一致性处理或流水线刷新,并可能留下性能异常。
听起来,一个被错误预测的 xdcbt 实际上需要让它错误地弄成不一致的缓存行失效或恢复一致,这也会影响那些读取了错误数据的指令,所以实际上相当于一次完整的流水线刷新。即便他们正确处理了这一点,我怀疑每当一个被错误预测的 xdcbt 被推测执行后又“取消”时,仍会造成一些有趣的性能异常。值得注意的是,2005 年时拥有惊人 31 级流水线的 P4/Netburst 已接近尾声,CPU 设计正转向提高 IPC 而不是时钟频率。
userbinator查看英文原文
It sounds like a mispredicted xcdbt would actually need to invalidate or otherwise make coherent the cache lines that it mistakenly made incoherent, which also affects the instructions that read the incorrect data, so effectively a full pipeline flush. Even if they got that right, I suspect it would still result in some interesting performance anomalies whenever a mispredicted xcdbt was speculatively executed and then "cancelled". It's notable that in 2005, it was already near the end for the P4/Netburst with its insanely 31-stage pipeline, and CPU designs were moving towards increasing IPC rather than clock frequency.
现代 CPU 验证会把这类缓存一致性缺陷视为不可接受的致命问题。
我最近几年一直在验证现代乱序 CPU 的内存一致性单元。如今这种 bug 若流到硅片上将是大问题,产品会一上市就报废。
seanmclo查看英文原文
I've been working on verifying memory coherency units of modern out-of-order CPUs for a few years now. Nowadays, this would be a huge miss if it were to escape to silicon. You'd have a dead on arrival product.
历次讨论
同类还值得读
TTY 揭秘(2008)
The TTY demystified (2008)
经典文章深入剖析了 Unix/Linux 中 TTY 子系统的工作原理,包括线路规程、终端驱动、信号与控制字符等机制。
系统与基础设施上首页 11 次 · 2009–2025linusakesson.net编辑精选为什么 GNU grep 这么快
Why GNU grep is Fast
FreeBSD 邮件列表上一篇广为流传的帖子,解释 GNU grep 为什么快:核心在于 Boyer-Moore 字符串搜索算法配合精心优化的内部循环和 I/O,让程序在搜索时“…
系统与基础设施上首页 9 次 · 2010–2022lists.freebsd.orgXplain:为普通人讲解 X11
Xplain – Explaining X11 for the rest of us
《Xplain》是作者(HN 用户 Jasper_)写的一系列 X11 长文,用他在浏览器中重建的 X11 绘图模型做交互演示,讲解 X11 的绘图模型与窗口系统设计。
系统与基础设施上首页 6 次 · 2013–2020magcius.github.io编辑精选旋风教程:为 Linux 创建极小 ELF 可执行文件(1999)
A Whirlwind Tutorial on Creating Really Teensy ELF Executables for Linux (1999)
breadbox 写于 1999 年的经典教程,主题是如何为 Linux 手工构造并裁剪出体积极小的 ELF 可执行文件。
系统与基础设施上首页 6 次 · 2007–2025muppetlabs.comPostgreSQL 内部原理
The internals of PostgreSQL
《The Internals of PostgreSQL》是一本免费在线书籍,系统讲解 PostgreSQL 的内部实现,包括查询处理、并发控制、WAL、缓冲区管理等核心机制。
系统与基础设施上首页 5 次 · 2017–2025interdb.jp编辑精选