From a45fb061b3c6318deca20bbde2d29c2897a73043 Mon Sep 17 00:00:00 2001 From: Kalesh Singh Date: Thu, 17 Jul 2025 16:55:48 -0700 Subject: [PATCH] ANDROID: 16K: Allocate pad vma on the stack Now that the padding VMA is only used in show_map_pad_vma(), initialize the padding VMA struct on the stack. This is a nice clean up and avoid having to deal with dynamic allocation failure. Bug: 440210631 Bug: 432564748 Change-Id: I168cda6cdb98423a40bb691b687c0f99bd160db6 Signed-off-by: Kalesh Singh --- mm/pgsize_migration.c | 48 ++++++++++--------------------------------- 1 file changed, 11 insertions(+), 37 deletions(-) diff --git a/mm/pgsize_migration.c b/mm/pgsize_migration.c index 3b020924a7a9..5443ae2429c5 100644 --- a/mm/pgsize_migration.c +++ b/mm/pgsize_migration.c @@ -271,22 +271,10 @@ static const struct vm_operations_struct pad_vma_ops = { }; /* - * Returns a new VMA representing the padding in @vma; - * returns NULL if no padding in @vma or allocation failed. + * Initialize @pad VMA fields with information from the original @vma. */ -static struct vm_area_struct *get_pad_vma(struct vm_area_struct *vma) +static void init_pad_vma(struct vm_area_struct *vma, struct vm_area_struct *pad) { - struct vm_area_struct *pad; - - if (!is_pgsize_migration_enabled() || !(vma->vm_flags & VM_PAD_MASK)) - return NULL; - - pad = kzalloc(sizeof(struct vm_area_struct), GFP_KERNEL); - if (!pad) { - pr_warn("Page size migration: Failed to allocate padding VMA"); - return NULL; - } - memcpy(pad, vma, sizeof(struct vm_area_struct)); /* Remove file */ @@ -306,48 +294,34 @@ static struct vm_area_struct *get_pad_vma(struct vm_area_struct *vma) __vm_flags_mod(pad, 0, VM_READ|VM_WRITE|VM_EXEC); /* Remove padding bits */ __vm_flags_mod(pad, 0, VM_PAD_MASK); - - return pad; } /* - * Calls the show_pad_vma_fn on the @pad VMA, and frees the copies of @vma - * and @pad. + * Calls the show_pad_vma_fn on the @pad VMA. */ void show_map_pad_vma(struct vm_area_struct *vma, struct seq_file *m, void *func, bool smaps) { - struct vm_area_struct *pad = get_pad_vma(vma); - if (!pad) + if (!is_pgsize_migration_enabled() || !(vma->vm_flags & VM_PAD_MASK)) return; - /* - * This cannot happen. If @pad vma was allocated the corresponding - * @vma should have the VM_PAD_MASK bit(s) set. - */ - BUG_ON(!(vma->vm_flags & VM_PAD_MASK)); + struct vm_area_struct pad; - /* - * This cannot happen. @pad is a section of the original VMA. - * Therefore @vma cannot be null if @pad is not null. - */ - BUG_ON(!vma); + init_pad_vma(vma, &pad); /* The pad VMA should be anonymous. */ - BUG_ON(pad->vm_file); + BUG_ON(pad.vm_file); /* The pad VMA should be PROT_NONE. */ - BUG_ON(pad->vm_flags & (VM_READ|VM_WRITE|VM_EXEC)); + BUG_ON(pad.vm_flags & (VM_READ|VM_WRITE|VM_EXEC)); /* The pad VMA itself cannot have padding; infinite recursion */ - BUG_ON(pad->vm_flags & VM_PAD_MASK); + BUG_ON(pad.vm_flags & VM_PAD_MASK); if (smaps) - ((show_pad_smaps_fn)func)(m, pad); + ((show_pad_smaps_fn)func)(m, &pad); else - ((show_pad_maps_fn)func)(m, pad); - - kfree(pad); + ((show_pad_maps_fn)func)(m, &pad); } /*