mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Qi Zheng <zhengqi.arch@bytedance.com>
To: Ryan Roberts <ryan.roberts@arm.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1] mm: use ptep_get() instead of directly dereferencing pte_t*
Date: Mon, 10 Mar 2025 23:51:01 +0800	[thread overview]
Message-ID: <f0d9986d-b3f0-42db-8fb6-d6087dd77f7d@bytedance.com> (raw)
In-Reply-To: <20250310140418.1737409-1-ryan.roberts@arm.com>

Hi Ryan,

On 3/10/25 10:04 PM, Ryan Roberts wrote:
> It is best practice for all pte accesses to go via the arch helpers, to
> ensure non-torn values and to allow the arch to intervene where needed
> (contpte for arm64 for example). While in this case it was probably safe
> to directly dereference, let's tidy it up for consistency.
> 
> Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
> ---
>   mm/migrate.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)

This looks good to me. So

Reviewed-by: Qi Zheng <zhengqi.arch@bytedance.com>

BTW, there are many other places in the kernel that directly
dereference pmd_t* and pud_t*, etc.

For example:

root@debian:~# grep "*vmf->pmd" . -rwn
./mm/memory.c:5113:	if (pmd_none(*vmf->pmd) && !vmf->prealloc_pte) {
./mm/memory.c:5207:	if (unlikely(!pmd_none(*vmf->pmd)))
./mm/memory.c:5339:	if (pmd_none(*vmf->pmd)) {
./mm/memory.c:5490:	if (pmd_none(*vmf->pmd)) {
./mm/memory.c:5996:	if (unlikely(pmd_none(*vmf->pmd))) {
./mm/filemap.c:3612:	if (pmd_trans_huge(*vmf->pmd)) {
./mm/filemap.c:3618:	if (pmd_none(*vmf->pmd) && 
folio_test_pmd_mappable(folio)) {
./mm/filemap.c:3628:	if (pmd_none(*vmf->pmd) && vmf->prealloc_pte)
./mm/huge_memory.c:1237:	if (unlikely(!pmd_none(*vmf->pmd))) {
./mm/huge_memory.c:1352:		if (pmd_none(*vmf->pmd)) {
./mm/huge_memory.c:1496:	if (pmd_none(*vmf->pmd)) {
./mm/huge_memory.c:1882:	if (unlikely(!pmd_same(*vmf->pmd, vmf->orig_pmd)))
./mm/huge_memory.c:1947:	if (unlikely(!pmd_same(*vmf->pmd, orig_pmd))) {
./mm/huge_memory.c:1965:		if (unlikely(!pmd_same(*vmf->pmd, orig_pmd))) {
./fs/dax.c:1935:	if (pmd_trans_huge(*vmf->pmd) || pmd_devmap(*vmf->pmd)) {
./fs/dax.c:2058:	if (!pmd_none(*vmf->pmd) && !pmd_trans_huge(*vmf->pmd) &&
./fs/dax.c:2059:			!pmd_devmap(*vmf->pmd)) {

Would it be best to clean them up as well?

Thanks,
Qi

> 
> diff --git a/mm/migrate.c b/mm/migrate.c
> index 22e270f727ed..33a22c2d6b20 100644
> --- a/mm/migrate.c
> +++ b/mm/migrate.c
> @@ -202,7 +202,7 @@ static bool try_to_map_unused_to_zeropage(struct page_vma_mapped_walk *pvmw,
>   		return false;
>   	VM_BUG_ON_PAGE(!PageAnon(page), page);
>   	VM_BUG_ON_PAGE(!PageLocked(page), page);
> -	VM_BUG_ON_PAGE(pte_present(*pvmw->pte), page);
> +	VM_BUG_ON_PAGE(pte_present(ptep_get(pvmw->pte)), page);
> 
>   	if (folio_test_mlocked(folio) || (pvmw->vma->vm_flags & VM_LOCKED) ||
>   	    mm_forbids_zeropage(pvmw->vma->vm_mm))
> --
> 2.43.0
> 


  parent reply	other threads:[~2025-03-10 15:51 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-10 14:04 Ryan Roberts
2025-03-10 14:10 ` Lorenzo Stoakes
2025-03-10 15:51 ` Qi Zheng [this message]
2025-03-10 16:31   ` Ryan Roberts
2025-03-11  3:14     ` Qi Zheng
2025-03-11  5:28 ` Anshuman Khandual
2025-03-11  6:03 ` Dev Jain

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=f0d9986d-b3f0-42db-8fb6-d6087dd77f7d@bytedance.com \
    --to=zhengqi.arch@bytedance.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=ryan.roberts@arm.com \
    /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

all inboxes | Powered by JetHome®