linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
	Andrew Morton <akpm@linux-foundation.org>
Cc: Vlastimil Babka <vbabka@suse.cz>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	Daniel Axtens <dja@axtens.net>
Subject: Re: [PATCH] mm: fix apply_to_existing_page_range()
Date: Wed, 9 Apr 2025 11:52:43 +0200	[thread overview]
Message-ID: <00a37819-b2ae-4399-b21d-86339059c46a@redhat.com> (raw)
In-Reply-To: <20250409094043.1629234-1-kirill.shutemov@linux.intel.com>

On 09.04.25 11:40, Kirill A. Shutemov wrote:
> In the case of apply_to_existing_page_range(), apply_to_pte_range() is
> reached with 'create' set to false. When !create, the loop over the PTE
> page table is broken.
> 
> apply_to_pte_range() will only move to the next PTE entry if 'create' is
> true or if the current entry is not pte_none().
> 
> This means that the user of apply_to_existing_page_range() will not have
> 'fn' called for any entries after the first pte_none() in the PTE page
> table.
> 
> Fix the loop logic in apply_to_pte_range().
> 
> Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> Fixes: be1db4753ee6 ("mm/memory.c: add apply_to_existing_page_range() helper")
> Cc: Daniel Axtens <dja@axtens.net>
> ---
>   mm/memory.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/memory.c b/mm/memory.c
> index fb7b8dc75167..2094564f4dfb 100644
> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -2907,11 +2907,11 @@ static int apply_to_pte_range(struct mm_struct *mm, pmd_t *pmd,
>   	if (fn) {
>   		do {
>   			if (create || !pte_none(ptep_get(pte))) {
> -				err = fn(pte++, addr, data);
> +				err = fn(pte, addr, data);
>   				if (err)
>   					break;
>   			}
> -		} while (addr += PAGE_SIZE, addr != end);
> +		} while (pte++, addr += PAGE_SIZE, addr != end);
>   	}
>   	*mask |= PGTBL_PTE_MODIFIED;
>   

LGTM. just curious, did you run into any actual issues that are worth 
describing?

It should affect apply_to_existing_page_range() users where 
create==false. There are not many, and likely most PTEs in the range 
they are passing are all non-none.

Acked-by: David Hildenbrand <david@redhat.com>

-- 
Cheers,

David / dhildenb



       reply	other threads:[~2025-04-09  9:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20250409094043.1629234-1-kirill.shutemov@linux.intel.com>
2025-04-09  9:52 ` David Hildenbrand [this message]
2025-04-09 10:23   ` Kirill A. Shutemov
2025-04-09 10:26     ` David Hildenbrand
2025-04-09 10:41       ` Kirill A. Shutemov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=00a37819-b2ae-4399-b21d-86339059c46a@redhat.com \
    --to=david@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=dja@axtens.net \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=vbabka@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox