ANDROID: vendor_hooks: Add vendor hook for GenieZone demand paging

Add Android kernel vendor hooks before and after VM demand paging to
enable calls to vendor modules for memory protection. This enhancement
ensures that memory protection mechanisms are properly invoked during
the demand paging process, improving the overall security and
stability of the system.

This feature is particularly important for systems that rely on
multiple IOMMU components to manage memory protection, ensuring that
all necessary preparation are properly applied during the demand
paging process.

Bug: 430175928
Signed-off-by: Willix Yeh <chi-shen.yeh@mediatek.com>
Signed-off-by: Liju Chen <liju-clr.chen@mediatek.com>
Change-Id: Iff019cc82d4bda852a7b72405ebe6026c893b26d
This commit is contained in:
Liju-clr Chen
2025-07-02 09:32:26 +08:00
committed by Treehugger Robot
parent 5c1cddc983
commit c302079179
4 changed files with 28 additions and 0 deletions

View File

@@ -577,3 +577,6 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_cpuset_fork);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_alloc_uid);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_free_user);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_gzvm_vcpu_exit_reason);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_gzvm_handle_demand_page_pre);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_gzvm_handle_demand_page_post);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_gzvm_destroy_vm_post_process);

View File

@@ -4,6 +4,7 @@
*/
#include <linux/soc/mediatek/gzvm_drv.h>
#include <trace/hooks/gzvm.h>
static int cmp_ppages(struct rb_node *node, const struct rb_node *parent)
{
@@ -160,10 +161,14 @@ static int handle_single_demand_page(struct gzvm *vm, int memslot_id, u64 gfn)
if (unlikely(ret))
return -EFAULT;
trace_android_vh_gzvm_handle_demand_page_pre(vm, memslot_id, pfn, gfn, 1);
ret = gzvm_arch_map_guest(vm->vm_id, memslot_id, pfn, gfn, 1);
if (unlikely(ret))
return -EFAULT;
trace_android_vh_gzvm_handle_demand_page_post(vm, memslot_id, pfn, gfn, 1);
return ret;
}
@@ -207,12 +212,16 @@ static int handle_block_demand_page(struct gzvm *vm, int memslot_id, u64 gfn)
vm->demand_page_buffer[i] = pfn;
}
trace_android_vh_gzvm_handle_demand_page_pre(vm, memslot_id, 0, gfn, nr_entries);
ret = gzvm_arch_map_guest_block(vm->vm_id, memslot_id,
start_gfn, nr_entries);
if (unlikely(ret)) {
ret = -EFAULT;
goto err_unlock;
}
trace_android_vh_gzvm_handle_demand_page_post(vm, memslot_id, 0, gfn, nr_entries);
}
err_unlock:
mutex_unlock(&vm->demand_paging_lock);

View File

@@ -12,6 +12,7 @@
#include <linux/platform_device.h>
#include <linux/slab.h>
#include <linux/soc/mediatek/gzvm_drv.h>
#include <trace/hooks/gzvm.h>
#include "gzvm_common.h"
static DEFINE_MUTEX(gzvm_list_lock);
@@ -374,6 +375,8 @@ static void gzvm_destroy_vm(struct gzvm *gzvm)
mutex_unlock(&gzvm->lock);
trace_android_vh_gzvm_destroy_vm_post_process(gzvm);
/* No need to lock here becauese it's single-threaded execution */
gzvm_destroy_all_ppage(gzvm);

View File

@@ -6,11 +6,24 @@
#define _TRACE_HOOK_GZVM_H
#include <trace/hooks/vendor_hooks.h>
struct gzvm_vcpu;
struct gzvm;
DECLARE_HOOK(android_vh_gzvm_vcpu_exit_reason,
TP_PROTO(struct gzvm_vcpu *vcpu, bool *userspace),
TP_ARGS(vcpu, userspace));
DECLARE_HOOK(android_vh_gzvm_handle_demand_page_pre,
TP_PROTO(struct gzvm *vm, int memslot_id, u64 pfn, u64 gfn, u32 nr_entries),
TP_ARGS(vm, memslot_id, pfn, gfn, nr_entries));
DECLARE_HOOK(android_vh_gzvm_handle_demand_page_post,
TP_PROTO(struct gzvm *vm, int memslot_id, u64 pfn, u64 gfn, u32 nr_entries),
TP_ARGS(vm, memslot_id, pfn, gfn, nr_entries));
DECLARE_HOOK(android_vh_gzvm_destroy_vm_post_process,
TP_PROTO(struct gzvm *vm),
TP_ARGS(vm));
#endif /* _TRACE_HOOK_GZVM_H */
/* This part must be outside protection */
#include <trace/define_trace.h>