On 7/10/26 22:16, Lorenzo Stoakes wrote:
> Adjust the stack expansion functions expand_upwards() and
> expand_downwards() such that they are expressed in terms of named constant
> values, and make use of vma_start_pgoff().
> 
> This clearly documents that we are referencing the page offset of the start
> of the VMA.
> 
> Additionally this cleans up the overflow check in expand_upwards().
> 
> No functional change intended.
> 
> Reviewed-by: Pedro Falcato <[email protected]>
> Reviewed-by: Gregory Price <[email protected]>
> Signed-off-by: Lorenzo Stoakes <[email protected]>

Reviewed-by: Vlastimil Babka (SUSE) <[email protected]>

> ---
>  mm/vma.c | 17 +++++++----------
>  1 file changed, 7 insertions(+), 10 deletions(-)
> 
> diff --git a/mm/vma.c b/mm/vma.c
> index 7265a054cfa3..5d5e60ea8a25 100644
> --- a/mm/vma.c
> +++ b/mm/vma.c
> @@ -3216,13 +3216,12 @@ int expand_upwards(struct vm_area_struct *vma, 
> unsigned long address)
>  
>       /* Somebody else might have raced and expanded it already */
>       if (address > vma->vm_end) {
> -             unsigned long size, grow;
> -
> -             size = address - vma->vm_start;
> -             grow = (address - vma->vm_end) >> PAGE_SHIFT;
> +             const unsigned long size = address - vma->vm_start;
> +             const unsigned long grow = (address - vma->vm_end) >> 
> PAGE_SHIFT;
> +             const pgoff_t pgoff = vma_start_pgoff(vma);
>  
>               error = -ENOMEM;
> -             if (vma->vm_pgoff + (size >> PAGE_SHIFT) >= vma->vm_pgoff) {
> +             if (pgoff + (size >> PAGE_SHIFT) >= pgoff) {
>                       error = acct_stack_growth(vma, size, grow);
>                       if (!error) {
>                               if (vma_test(vma, VMA_LOCKED_BIT))
> @@ -3295,13 +3294,11 @@ int expand_downwards(struct vm_area_struct *vma, 
> unsigned long address)
>  
>       /* Somebody else might have raced and expanded it already */
>       if (address < vma->vm_start) {
> -             unsigned long size, grow;
> -
> -             size = vma->vm_end - address;
> -             grow = (vma->vm_start - address) >> PAGE_SHIFT;
> +             const unsigned long size = vma->vm_end - address;
> +             const unsigned long grow = (vma->vm_start - address) >> 
> PAGE_SHIFT;
>  
>               error = -ENOMEM;
> -             if (grow <= vma->vm_pgoff) {
> +             if (grow <= vma_start_pgoff(vma)) {
>                       error = acct_stack_growth(vma, size, grow);
>                       if (!error) {
>                               if (vma_test(vma, VMA_LOCKED_BIT))
> 

Reply via email to