仅在调用 mtrr_type_lookup() 后检查统一

仅在调用 mtrr_type_lookup() 后检查统一

为什么检查机制会改变?是因为 MTRR 代码升级吗?还是之前检查时出了问题?

https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/arch/x86/mm/pgtable.c?h=v6.5.7&id=12f0dd8df14285a5604f35ed3af8b8c33e8fd97f

x86/mm: Only check uniform after calling mtrr_type_lookup()
Today pud_set_huge() and pmd_set_huge() test for the MTRR type to be
WB or INVALID after calling mtrr_type_lookup().

Those tests can be dropped as the only reason not to use a large mapping
would be uniform being 0.

Any MTRR type can be accepted as long as it applies to the whole memory
range covered by the mapping, as the alternative would only be to map
the same region with smaller pages instead, using the same PAT type as
for the large mapping.

答案1

代码已更改,因为 的语义uniform不正确。这是在补丁集的早期迭代中发现的;尤尔根·格罗斯问道

如果大型映射跨越多个 MTRR,即使它们定义相同的缓存类型(在这种情况下统一设置为 0),也会出现问题。

所以对我来说基本的问题是:不应该调整uniform的语义吗?今天,它的意思是“该范围仅由一项 MTRR 覆盖或没有覆盖”。看看用例,我想知道它是否不应该是“整个范围具有相同的缓存类型”。

到哪个莱纳斯·托瓦尔兹回复了

哦,我想你应该将uniform固定为1。

IOW,我们不应该认为“多个MTRR”意味着“不统一”。只有“不同的实际内存类型”才意味着不一致性。

如果我没记错的话,MTRR 重叠是有充分理由的。事实上,如果您有奇怪的内存设置,您可以生成一个描述内存 ttype 的 MTRR,该内存 ttype 甚至不连续。

英特尔明确定义了 MTRR 的工作重叠方式,并且“相同类型重叠”被记录为真实的事情。

这导致了您所询问的补丁,该补丁被标记为 Linus 建议的。

(在这种情况下,要找到算作建议的电子邮件,查找建议者发给补丁作者的电子邮件.)

相关内容