mm/mmap: use vms accounted pages in mmap_region()

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/20240830040101.822209-18-Liam.Howlett@oracle.com
Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
Reviewed-by: Kees Cook <kees@kernel.org>
Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Reviewed-by: Suren Baghdasaryan <surenb@google.com>
Acked-by: Paul Moore <paul@paul-moore.com>	[LSM]
Cc: Kees Cook <kees@kernel.org>
Cc: Bert Karwatzki <spasswolf@web.de>
Cc: Jeff Xu <jeffxu@chromium.org>
Cc: Jiri Olsa <olsajiri@gmail.com>
Cc: Lorenzo Stoakes <lstoakes@gmail.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: "Paul E. McKenney" <paulmck@kernel.org>
Cc: Sidhartha Kumar <sidhartha.kumar@oracle.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
Liam R. Howlett 2024-08-30 00:00:57 -04:00 committed by Andrew Morton
parent 5972d97c44
commit 13d77e0133

View File

@ -1414,9 +1414,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
*/ */
if (accountable_mapping(file, vm_flags)) { if (accountable_mapping(file, vm_flags)) {
charged = pglen; charged = pglen;
charged -= nr_accounted; charged -= vms.nr_accounted;
if (security_vm_enough_memory_mm(mm, charged)) if (charged && security_vm_enough_memory_mm(mm, charged))
goto abort_munmap; goto abort_munmap;
vms.nr_accounted = 0; vms.nr_accounted = 0;
vm_flags |= VM_ACCOUNT; vm_flags |= VM_ACCOUNT;
} }