Linux-RISC-V Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Jisheng Zhang <jszhang@kernel.org>
To: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
Cc: Albert Ou <aou@eecs.berkeley.edu>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Paul Walmsley <pjw@kernel.org>, Alexandre Ghiti <alex@ghiti.fr>,
	linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org
Subject: Re: [PATCH 2/2] riscv: mm: check the valid bit in kernel_page_present()
Date: Sun, 15 Nov 2026 21:15:54 +0800	[thread overview]
Message-ID: <avmwinvQyS_X0G7o@xhacker> (raw)
In-Reply-To: <20261112-fixes-riscv-v1-2-1caac19897b5@kernel.org>

On Thu, Nov 12, 2026 at 03:42:19PM +0200, Mike Rapoport (Microsoft) wrote:
> set_direct_map_invalid_noflush() clears _PAGE_PRESENT, but the kernel
> mappings keep _PAGE_PROT_NONE set: it used to be _PAGE_READ and now it is
> the same bit as _PAGE_GLOBAL. pte_present() and pmd_present() still
> return true for the invalidated entry. kernel_page_present() then reports
> that an unmapped page is mapped, and hibernation copies it without
> remapping it first.
> 
> Test _PAGE_PRESENT directly for PMD and PTE leaves.
> 
> Fixes: 32a0de886eb3 ("arch, mm: make kernel_page_present() always available")
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---
>  arch/riscv/mm/pageattr.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/riscv/mm/pageattr.c b/arch/riscv/mm/pageattr.c
> index b138113755359..62fbcf7cf36b6 100644
> --- a/arch/riscv/mm/pageattr.c
> +++ b/arch/riscv/mm/pageattr.c
> @@ -453,8 +453,9 @@ bool kernel_page_present(struct page *page)
>  	if (!pmd_present(pmdp_get(pmd)))
>  		return false;
>  	if (pmd_leaf(pmdp_get(pmd)))
> -		return true;
> +		return pmd_val(pmdp_get(pmd)) & _PAGE_PRESENT;

so we call pmdp_get() up to 3 times, could we save its result
and reuse it?

>  
> +	/* pte_present() is true for PAGE_KERNEL with _PAGE_PRESENT cleared */
>  	pte = pte_offset_kernel(pmd, addr);
> -	return pte_present(ptep_get(pte));
> +	return pte_val(ptep_get(pte)) & _PAGE_PRESENT;
>  }
> 
> -- 
> 2.53.0
> 
> 
> _______________________________________________
> linux-riscv mailing list
> linux-riscv@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-riscv

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

      reply	other threads:[~2026-11-15 13:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12 13:42 [PATCH 0/2] riscv: mm: fix set_memory_x() and kernel_page_present() Mike Rapoport (Microsoft)
2026-11-12 13:42 ` [PATCH 1/2] riscv: do not make the linear map alias executable in set_memory_*() Mike Rapoport (Microsoft)
2026-11-12 13:42 ` [PATCH 2/2] riscv: mm: check the valid bit in kernel_page_present() Mike Rapoport (Microsoft)
2026-11-15 13:15   ` Jisheng Zhang [this message]

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=avmwinvQyS_X0G7o@xhacker \
    --to=jszhang@kernel.org \
    --cc=alex@ghiti.fr \
    --cc=aou@eecs.berkeley.edu \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=palmer@dabbelt.com \
    --cc=pjw@kernel.org \
    --cc=rppt@kernel.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