ANDROID: GKI: add a vendor hook in ptep_clear_flush_young()

Add a vendor hook to be able to skip ptep tlb flush.

Bug: 312692863
Test: boot
Change-Id: Ifbc7a52111616d0542b866532a9bf82368e6c8f1
Signed-off-by: Martin Liu <[email protected]>
(cherry picked from commit 46f8b2ca58846be1052412fd90b4da12222c37fe)
diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
index 4495113..826c77c 100644
--- a/arch/arm64/include/asm/pgtable.h
+++ b/arch/arm64/include/asm/pgtable.h
@@ -837,12 +837,14 @@ static inline int ptep_test_and_clear_young(struct vm_area_struct *vma,
 }
 
 #define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
+extern bool should_flush_tlb_when_young(void);
+
 static inline int ptep_clear_flush_young(struct vm_area_struct *vma,
 					 unsigned long address, pte_t *ptep)
 {
 	int young = ptep_test_and_clear_young(vma, address, ptep);
 
-	if (young) {
+	if (young && should_flush_tlb_when_young()) {
 		/*
 		 * We can elide the trailing DSB here since the worst that can
 		 * happen is that a CPU continues to use the young entry in its
diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
index 07f7315..cbbf9c6 100644
--- a/arch/arm64/mm/mmu.c
+++ b/arch/arm64/mm/mmu.c
@@ -37,6 +37,8 @@
 #include <asm/tlbflush.h>
 #include <asm/pgalloc.h>
 
+#include <trace/hooks/mm.h>
+
 #define NO_BLOCK_MAPPINGS	BIT(0)
 #define NO_CONT_MAPPINGS	BIT(1)
 
@@ -1493,6 +1495,14 @@ int p4d_free_pud_page(p4d_t *p4d, unsigned long addr)
 	return 0;	/* Don't attempt a block mapping */
 }
 
+bool should_flush_tlb_when_young(void)
+{
+	bool skip = false;
+
+	trace_android_vh_ptep_clear_flush_young(&skip);
+	return !skip;
+}
+
 #ifdef CONFIG_MEMORY_HOTPLUG
 static void __remove_pgd_mapping(pgd_t *pgdir, unsigned long start, u64 size)
 {
diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c
index 021f7e6..93661ff 100644
--- a/drivers/android/vendor_hooks.c
+++ b/drivers/android/vendor_hooks.c
@@ -431,3 +431,4 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_early_resume_begin);
 EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_alloc_pages_reclaim_bypass);
 EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_alloc_pages_failure_bypass);
 EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_rebuild_root_domains_bypass);
+EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_ptep_clear_flush_young);
diff --git a/include/trace/hooks/mm.h b/include/trace/hooks/mm.h
index d9be2be..3a405b4 100644
--- a/include/trace/hooks/mm.h
+++ b/include/trace/hooks/mm.h
@@ -172,6 +172,9 @@ DECLARE_HOOK(android_vh_alloc_pages_failure_bypass,
 	TP_PROTO(gfp_t gfp_mask, int order, int alloc_flags,
 	int migratetype, struct page **page),
 	TP_ARGS(gfp_mask, order, alloc_flags, migratetype, page));
+DECLARE_HOOK(android_vh_ptep_clear_flush_young,
+	TP_PROTO(bool *skip),
+	TP_ARGS(skip));
 /* macro versions of hooks are no longer required */
 
 #endif /* _TRACE_HOOK_MM_H */