Re: [PATCH 2/3] mm/mprotect: Use long for page accountings and retval

From: James Houghton
Date: Wed Jan 04 2023 - 20:52:09 EST


On Wed, Jan 4, 2023 at 10:52 PM Peter Xu <peterx@xxxxxxxxxx> wrote:
>
> Switch to use type "long" for page accountings and retval across the whole
> procedure of change_protection().
>
> The change should have shrinked the possible maximum page number to be half
> comparing to previous (ULONG_MAX / 2), but it shouldn't overflow on any
> system either because the maximum possible pages touched by change
> protection should be ULONG_MAX / PAGE_SIZE.
>
> Two reasons to switch from "unsigned long" to "long":
>
> 1. It suites better on count_vm_numa_events(), whose 2nd parameter takes
> a long type.
>
> 2. It paves way for returning negative (error) values in the future.
>
> Currently the only caller that consumes this retval is change_prot_numa(),
> where the unsigned long was converted to an int. Since at it, touching up
> the numa code to also take a long, so it'll avoid any possible overflow too
> during the int-size convertion.
>
> Signed-off-by: Peter Xu <peterx@xxxxxxxxxx>
> ---
> include/linux/hugetlb.h | 4 ++--
> include/linux/mm.h | 2 +-
> mm/hugetlb.c | 4 ++--
> mm/mempolicy.c | 2 +-
> mm/mprotect.c | 26 +++++++++++++-------------
> 5 files changed, 19 insertions(+), 19 deletions(-)

Acked-by: James Houghton <jthoughton@xxxxxxxxxx>