[PATCH v11 07/12] x86/mm: use INVLPGB in flush_tlb_all

Rik van Riel posted 12 patches 10 months, 1 week ago
There is a newer version of this series
[PATCH v11 07/12] x86/mm: use INVLPGB in flush_tlb_all
Posted by Rik van Riel 10 months, 1 week ago
The flush_tlb_all() function is not used a whole lot, but we might
as well use broadcast TLB flushing there, too.

Signed-off-by: Rik van Riel <riel@surriel.com>
Tested-by: Manali Shukla <Manali.Shukla@amd.com>
Tested-by: Brendan Jackman <jackmanb@google.com>
Tested-by: Michael Kelley <mhklinux@outlook.com>
---
 arch/x86/mm/tlb.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
index ce9df82754ce..3c29ef25dce4 100644
--- a/arch/x86/mm/tlb.c
+++ b/arch/x86/mm/tlb.c
@@ -1065,6 +1065,16 @@ void flush_tlb_mm_range(struct mm_struct *mm, unsigned long start,
 }
 
 
+static bool broadcast_flush_tlb_all(void)
+{
+	if (!cpu_feature_enabled(X86_FEATURE_INVLPGB))
+		return false;
+
+	guard(preempt)();
+	invlpgb_flush_all();
+	return true;
+}
+
 static void do_flush_tlb_all(void *info)
 {
 	count_vm_tlb_event(NR_TLB_REMOTE_FLUSH_RECEIVED);
@@ -1073,6 +1083,8 @@ static void do_flush_tlb_all(void *info)
 
 void flush_tlb_all(void)
 {
+	if (broadcast_flush_tlb_all())
+		return;
 	count_vm_tlb_event(NR_TLB_REMOTE_FLUSH);
 	on_each_cpu(do_flush_tlb_all, NULL, 1);
 }
-- 
2.47.1
Re: [PATCH v11 07/12] x86/mm: use INVLPGB in flush_tlb_all
Posted by Dave Hansen 10 months, 1 week ago
On 2/13/25 08:13, Rik van Riel wrote:
>  void flush_tlb_all(void)
>  {
> +	if (broadcast_flush_tlb_all())
> +		return;
>  	count_vm_tlb_event(NR_TLB_REMOTE_FLUSH);
>  	on_each_cpu(do_flush_tlb_all, NULL, 1);
>  }

This could use a couple of one-line comments.

Also, let's just keep the NR_TLB_REMOTE_FLUSH manipulation even when
using the INVLPGB. It's still logically a remote flush even if it
doesn't use an IPI.