Skip to content

Commit

Permalink
mm/mmap: use vms accounted pages in mmap_region()
Browse files Browse the repository at this point in the history
Change from nr_pages variable to vms.nr_accounted for the charged pages
calculation.  This is necessary for a future patch.

This also avoids checking security_vm_enough_memory_mm() if the amount of
memory won't change.

Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Liam R. Howlett <[email protected]>
Reviewed-by: Kees Cook <[email protected]>
Reviewed-by: Lorenzo Stoakes <[email protected]>
Reviewed-by: Suren Baghdasaryan <[email protected]>
Acked-by: Paul Moore <[email protected]>	[LSM]
Cc: Kees Cook <[email protected]>
Cc: Bert Karwatzki <[email protected]>
Cc: Jeff Xu <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Lorenzo Stoakes <[email protected]>
Cc: Mark Brown <[email protected]>
Cc: Matthew Wilcox <[email protected]>
Cc: "Paul E. McKenney" <[email protected]>
Cc: Sidhartha Kumar <[email protected]>
Cc: Vlastimil Babka <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
  • Loading branch information
howlett authored and akpm00 committed Sep 4, 2024
1 parent 5972d97 commit 13d77e0
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions mm/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1414,9 +1414,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
*/
if (accountable_mapping(file, vm_flags)) {
charged = pglen;
charged -= nr_accounted;
if (security_vm_enough_memory_mm(mm, charged))
charged -= vms.nr_accounted;
if (charged && security_vm_enough_memory_mm(mm, charged))
goto abort_munmap;

vms.nr_accounted = 0;
vm_flags |= VM_ACCOUNT;
}
Expand Down

0 comments on commit 13d77e0

Please sign in to comment.