mm: fix process_vm_rw page counts
authorYork Jasper Niebuhr <yjnworkstation@gmail.com>
Sat, 11 Nov 2023 18:48:59 +0000 (19:48 +0100)
committerAndrew Morton <akpm@linux-foundation.org>
Mon, 11 Dec 2023 00:51:39 +0000 (16:51 -0800)
commit932b59e3beaefefb1a0bd65f1bb3f9e2000d7315
tree945384e2b149af740329e30b1be43cb8413acaf6
parent69e583eaca579d50ffc699b1f4358258e75fa008
mm: fix process_vm_rw page counts

1. There is a "-1" missing in the page number calculation in
   process_vm_rw_core.  While this can't break anything, it can cause
   unnecessary allocations in certain cases:

   Consider handling an iovec ranging over PVM_MAX_PP_ARRAY_COUNT pages
   that is also aligned to a page boundary.  While pp_stack could hold
   references to such an amount of pinned pages, nr_pages yields
   (PVM_MAX_PP_ARRAY + 1) in process_vm_rw_core.  Consequently, a larger
   buffer is allocated with kmalloc for no reason.

   For any page boundary aligned iovec that is a multiple of PAGE_SIZE
   and larger than PVM_MAX_PP_ARRAY_COUNT pages, nr_pages will be too big
   by 1 and thus kmalloc allocates excess space for one more pointer.

2. max_pages_per_loop is constant and there is no reason to have it as
   a variable.  A macro does the job just fine and saves memory.

3. Replaced "sizeof(struct pages *)" with "sizeof(struct page *)" to
   have matching types for allocation and prevent confusion.

Link: https://lkml.kernel.org/r/20231111184859.44264-1-yjnworkstation@gmail.com
Signed-off-by: York Jasper Niebuhr <yjnworkstation@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/process_vm_access.c