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 <kaleshsingh@google.com>
This commit is contained in:
Kalesh Singh
2025-07-17 16:55:48 -07:00
parent 881ba9d97f
commit 1ee9b67d67

View File

@@ -257,23 +257,11 @@ 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;
}
*pad = *vma;
memcpy(pad, vma, sizeof(struct vm_area_struct));
/* Remove file */
pad->vm_file = NULL;
@@ -289,48 +277,34 @@ static struct vm_area_struct *get_pad_vma(struct vm_area_struct *vma)
/* Remove padding bits */
pad->vm_flags &= ~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)
struct vm_area_struct 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));
/*
* 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);
}
/*