Skip to contentSkip to conversation

x86/mm: Disable INVLPGB when PTI is enabled

PATCH In review Dave Hansen 3 participants 3 messages Jun 10, 2025 – Jun 11, 2025

Subsystems (3)
lore
Share & tools
lore

Dave Hansen

author maintainer
#0 lore raw

PATCH 1/1 x86/mm: Disable INVLPGB when PTI is enabled

From: Dave Hansen <[email protected]>

PTI uses separate ASIDs (aka. PCIDs) for kernel and user address spaces. When the kernel needs to flush the user address space, it just sets a bit in a bitmap and then flushes the entire PCID on the next switch to userspace.

But, this bitmap is a single 'unsigned long' which is plenty for all 6 dynamic ASIDs. But, unfortunately, the INVLPGB support brings along a bunch more user ASIDs, as many as ~2k more. The bitmap can't address that many.

Fortunately, the bitmap is only needed for PTI and all the CPUs with INVLPGB are AMD CPUs that aren't vulnerable to Meltdown and don't need PTI. The only way someone can run into an issue in practice is by booting with pti=on on a newer AMD CPU.

Disable INVLPGB if PTI is enabled. Avoid overrunning the small bitmap.

Note: this will be fixed up properly by making the bitmap bigger. For now, just avoid the mostly theoretical bug.

Fixes 4afeb0ed1753 ("x86/mm: Enable broadcast TLB invalidation for multi-threaded processes")
Cc Rik van Riel <[email protected]>
Cc Borislav Petkov (AMD) <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Nadav Amit <[email protected]>
Cc Andy Lutomirski <[email protected]>
Cc Peter Zijlstra <[email protected]>

---

 b/arch/x86/mm/pti.c |    5 +++++
 1 file changed, 5 insertions(+)
arch/x86/mm/pti.c renamed from arch/x86/mm/pti.c~no-INVLPGB-plus-KPTI +5 -0
diff -puN arch/x86/mm/pti.c~no-INVLPGB-plus-KPTI arch/x86/mm/pti.c
@@ -98,6 +98,11 @@ void __init pti_check_boottime_disable(v
 		return;
 
 	setup_force_cpu_cap(X86_FEATURE_PTI);
+
+	if (cpu_feature_enabled(X86_FEATURE_INVLPGB)) {
+		pr_debug("PTI enabled, disabling INVLPGB\n");
+		setup_clear_cpu_cap(X86_FEATURE_INVLPGB);
+	}
 }
 
 static int __init pti_parse_cmdline(char *arg)

_

Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · Dave Hansen

Disable INVLPGB if PTI is enabled. Avoid overrunning the small bitmap.

Note: this will be fixed up properly by making the bitmap bigger. For now, just avoid the mostly theoretical bug.

Does that mean the patch to make the bitmap bigger is a dependency that needs to be in place before the RAR code (hoping to send out v4 later this week) can be merged?

Quoted 3 lines
Fixes 4afeb0ed1753 ("x86/mm: Enable broadcast TLB invalidation for

multi-threaded processes")

Signature · 1 line
All Rights Reversed.
#2 lore raw
Quoted 11 lines · Rik van Riel
Quoted 6 lines · Dave Hansen

Disable INVLPGB if PTI is enabled. Avoid overrunning the small bitmap.

Note: this will be fixed up properly by making the bitmap bigger. For now, just avoid the mostly theoretical bug.

Does that mean the patch to make the bitmap bigger is a dependency that needs to be in place before the RAR code (hoping to send out v4 later this week) can be merged?

That's what I was thinking. Your series to fix this all up properly from last week looks like the right way. It just seems like a wee bit more work than I want to see getting backported. It's not a huge lift, though.