linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Shivank Garg <shivankg@amd.com>
To: Luiz Capitulino <luizcap@redhat.com>,
	david@redhat.com, willy@infradead.org, akpm@linux-foundation.org
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, sj@kernel.org
Subject: Re: [PATCH v2 1/4] mm/memory: introduce is_huge_zero_pfn() and use it in vm_normal_page_pmd()
Date: Tue, 8 Jul 2025 01:07:58 +0530	[thread overview]
Message-ID: <6d11acba-76ce-4c02-baac-4828adbb9525@amd.com> (raw)
In-Reply-To: <0e343f6f088fc79f625161b5d74567d696f2228e.1751914235.git.luizcap@redhat.com>



On 7/8/2025 12:20 AM, Luiz Capitulino wrote:
> From: David Hildenbrand <david@redhat.com>
> 
> Let's avoid working with the PMD when not required. If
> vm_normal_page_pmd() would be called on something that is not a present
> pmd, it would already be a bug (pfn possibly garbage).
> 
> While at it, let's support passing in any pfn covered by the huge zero
> folio by masking off PFN bits -- which should be rather cheap.
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>
> Reviewed-by: Oscar Salvador <osalvador@suse.de>
> Signed-off-by: Luiz Capitulino <luizcap@redhat.com>
> ---
>  include/linux/huge_mm.h | 12 +++++++++++-
>  mm/memory.c             |  2 +-
>  2 files changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h
> index 2f190c90192d..59e93fba15f4 100644
> --- a/include/linux/huge_mm.h
> +++ b/include/linux/huge_mm.h
> @@ -486,9 +486,14 @@ static inline bool is_huge_zero_folio(const struct folio *folio)
>  	return READ_ONCE(huge_zero_folio) == folio;
>  }
>  
> +static inline bool is_huge_zero_pfn(unsigned long pfn)
> +{
> +	return READ_ONCE(huge_zero_pfn) == (pfn & ~(HPAGE_PMD_NR - 1));
> +}
> +
>  static inline bool is_huge_zero_pmd(pmd_t pmd)
>  {
> -	return pmd_present(pmd) && READ_ONCE(huge_zero_pfn) == pmd_pfn(pmd);
> +	return pmd_present(pmd) && is_huge_zero_pfn(pmd_pfn(pmd));
>  }
>  
>  struct folio *mm_get_huge_zero_folio(struct mm_struct *mm);
> @@ -636,6 +641,11 @@ static inline bool is_huge_zero_folio(const struct folio *folio)
>  	return false;
>  }
>  
> +static inline bool is_huge_zero_pfn(unsigned long pfn)
> +{
> +	return false;
> +}
> +
>  static inline bool is_huge_zero_pmd(pmd_t pmd)
>  {
>  	return false;
> diff --git a/mm/memory.c b/mm/memory.c
> index b0cda5aab398..3a765553bacb 100644
> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -687,7 +687,7 @@ struct page *vm_normal_page_pmd(struct vm_area_struct *vma, unsigned long addr,
>  
>  	if (pmd_devmap(pmd))
>  		return NULL;
> -	if (is_huge_zero_pmd(pmd))
> +	if (is_huge_zero_pfn(pfn))
>  		return NULL;
>  	if (unlikely(pfn > highest_memmap_pfn))
>  		return NULL;

Reviewed-by: Shivank Garg <shivankg@amd.com>




  reply	other threads:[~2025-07-07 19:38 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-07 18:50 [PATCH v2 0/4] mm: introduce snapshot_page() Luiz Capitulino
2025-07-07 18:50 ` [PATCH v2 1/4] mm/memory: introduce is_huge_zero_pfn() and use it in vm_normal_page_pmd() Luiz Capitulino
2025-07-07 19:37   ` Shivank Garg [this message]
2025-07-07 18:50 ` [PATCH v2 2/4] mm/util: introduce snapshot_page() Luiz Capitulino
2025-07-08  5:49   ` Shivank Garg
2025-07-08 16:59     ` Luiz Capitulino
2025-07-14 13:16       ` Luiz Capitulino
2025-07-14 13:43         ` Shivank Garg
2025-07-11 11:56   ` David Hildenbrand
2025-07-11 12:59     ` Luiz Capitulino
2025-07-07 18:50 ` [PATCH v2 3/4] proc: kpagecount: use snapshot_page() Luiz Capitulino
2025-07-08  5:51   ` Shivank Garg
2025-07-07 18:50 ` [PATCH v2 4/4] fs: stable_page_flags(): " Luiz Capitulino
2025-07-08  5:55   ` Shivank Garg
2025-07-09  8:14 ` BUG: KASAN: stack-out-of-bounds in snapshot_page during gup_test test case Harry Yoo
2025-07-09 12:51   ` Luiz Capitulino
2025-07-10  3:32     ` Luiz Capitulino

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=6d11acba-76ce-4c02-baac-4828adbb9525@amd.com \
    --to=shivankg@amd.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=luizcap@redhat.com \
    --cc=sj@kernel.org \
    --cc=willy@infradead.org \
    /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