ANDROID: vendor_hooks: add hooks to modify pageflags

These hooks are designed to set or clear OEM reserved pageflags when the
memory state may change.

Bug: 336964184

Change-Id: I9cb288ef6eef7a719d4f4748d6b71010645b7d50
Signed-off-by: Xiaofeng Yuan <yuanxiaofeng@vivo.com>
This commit is contained in:
Xiaofeng Yuan 2024-06-25 19:56:31 +08:00
parent a5d073d697
commit 284a6a930d
5 changed files with 32 additions and 0 deletions

View File

@ -543,6 +543,11 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_blk_mq_all_tag_iter);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_blk_mq_queue_tag_busy_iter);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_blk_mq_free_tags);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_blk_mq_sched_insert_request);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_shmem_swapin_page);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_do_wp_page);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_do_swap_page);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_do_anonymous_page);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_uprobes_replace_page);
/*
* For type visibility
*/

View File

@ -370,6 +370,22 @@ DECLARE_HOOK(android_vh_do_swap_page_spf,
DECLARE_HOOK(android_vh_tune_fault_around_bytes,
TP_PROTO(unsigned long *fault_around_bytes),
TP_ARGS(fault_around_bytes));
DECLARE_HOOK(android_vh_do_anonymous_page,
TP_PROTO(struct vm_area_struct *vma, struct page *page),
TP_ARGS(vma, page));
DECLARE_HOOK(android_vh_do_swap_page,
TP_PROTO(struct page *page, pte_t *pte, struct vm_fault *vmf,
swp_entry_t entry),
TP_ARGS(page, pte, vmf, entry));
DECLARE_HOOK(android_vh_do_wp_page,
TP_PROTO(struct page *page),
TP_ARGS(page));
DECLARE_HOOK(android_vh_uprobes_replace_page,
TP_PROTO(struct page *new_page, struct page *old_page),
TP_ARGS(new_page, old_page));
DECLARE_HOOK(android_vh_shmem_swapin_page,
TP_PROTO(struct page *page),
TP_ARGS(page));
#endif /* _TRACE_HOOK_MM_H */
/* This part must be outside protection */

View File

@ -30,6 +30,9 @@
#include <linux/uprobes.h>
#undef CREATE_TRACE_POINTS
#include <trace/hooks/mm.h>
#define UINSNS_PER_PAGE (PAGE_SIZE/UPROBE_XOL_SLOT_BYTES)
#define MAX_UPROBE_XOL_SLOTS UINSNS_PER_PAGE
@ -185,6 +188,7 @@ static int __replace_page(struct vm_area_struct *vma, unsigned long addr,
get_page(new_page);
page_add_new_anon_rmap(new_page, vma, addr, false);
lru_cache_add_inactive_or_unevictable(new_page, vma);
trace_android_vh_uprobes_replace_page(new_page, old_page);
} else
/* no new page, just dec_mm_counter for old_page */
dec_mm_counter(mm, MM_ANONPAGES);

View File

@ -78,6 +78,9 @@
#include <trace/events/kmem.h>
#undef CREATE_TRACE_POINTS
#include <trace/hooks/mm.h>
#include <asm/io.h>
#include <asm/mmu_context.h>
#include <asm/pgalloc.h>
@ -3444,6 +3447,7 @@ static vm_fault_t do_wp_page(struct vm_fault *vmf)
* Take out anonymous pages first, anonymous shared vmas are
* not dirty accountable.
*/
trace_android_vh_do_wp_page(vmf->page);
if (PageAnon(vmf->page)) {
struct page *page = vmf->page;
@ -3815,6 +3819,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)
inc_mm_counter_fast(vma->vm_mm, MM_ANONPAGES);
dec_mm_counter_fast(vma->vm_mm, MM_SWAPENTS);
pte = mk_pte(page, vmf->vma_page_prot);
trace_android_vh_do_swap_page(page, &pte, vmf, entry);
if ((vmf->flags & FAULT_FLAG_WRITE) && reuse_swap_page(page, NULL)) {
pte = maybe_mkwrite(pte_mkdirty(pte), vmf->vma_flags);
vmf->flags &= ~FAULT_FLAG_WRITE;
@ -3971,6 +3976,7 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf)
*/
__SetPageUptodate(page);
trace_android_vh_do_anonymous_page(vma, page);
entry = mk_pte(page, vmf->vma_page_prot);
entry = pte_sw_mkyoung(entry);
if (vmf->vma_flags & VM_WRITE)

View File

@ -1742,6 +1742,7 @@ static int shmem_swapin_page(struct inode *inode, pgoff_t index,
/* We have to do this with page locked to prevent races */
lock_page(page);
trace_android_vh_shmem_swapin_page(page);
if (!PageSwapCache(page) || page_private(page) != swap.val ||
!shmem_confirm_swap(mapping, index, swap)) {
error = -EEXIST;