From: "Huang, Ying" <ying.huang@linux.alibaba.com>
To: Jianpeng Chang <jianpeng.chang.cn@windriver.com>
Cc: <catalin.marinas@arm.com>, <will@kernel.org>, <ardb@kernel.org>,
<anshuman.khandual@arm.com>,
<linux-arm-kernel@lists.infradead.org>,
<linux-kernel@vger.kernel.org>,
"Shenhar, Talel" <talel@amazon.com>
Subject: Re: [PATCH] arm64: mm: Fix kexec failure after pte_mkwrite_novma() change
Date: Fri, 28 Nov 2025 17:32:17 +0800 [thread overview]
Message-ID: <87qztiec4e.fsf@DESKTOP-5N7EMDA> (raw)
In-Reply-To: <20251127034350.3600454-1-jianpeng.chang.cn@windriver.com> (Jianpeng Chang's message of "Thu, 27 Nov 2025 11:43:50 +0800")
Hi, Jianpeng,
Jianpeng Chang <jianpeng.chang.cn@windriver.com> writes:
> Commit 143937ca51cc ("arm64, mm: avoid always making PTE dirty in
> pte_mkwrite()") modified pte_mkwrite_novma() to only clear PTE_RDONLY
> when the page is already dirty (PTE_DIRTY is set). While this optimization
> prevents unnecessary dirty page marking in normal memory management paths,
> it breaks kexec on some platforms like NXP LS1043.
>
> The issue occurs in the kexec code path:
> 1. machine_kexec_post_load() calls trans_pgd_create_copy() to create a
> writable copy of the linear mapping
> 2. _copy_pte() calls pte_mkwrite_novma() to ensure all pages in the copy
> are writable for the new kernel image copying
> 3. With the new logic, clean pages (without PTE_DIRTY) remain read-only
> 4. When kexec tries to copy the new kernel image through the linear
> mapping, it fails on read-only pages, causing the system to hang
> after "Bye!"
>
> The same issue affects hibernation which uses the same trans_pgd code path.
>
> Fix this by explicitly clearing PTE_RDONLY in _copy_pte() for both
> kexec and hibernation, ensuring all pages in the temporary mapping are
> writable regardless of their dirty state. This preserves the original
> commit's optimization for normal memory management while fixing the
> kexec/hibernation regression.
>
> Fixes: 143937ca51cc ("arm64, mm: avoid always making PTE dirty in pte_mkwrite()")
IMHO, this isn't the right "Fixes" tag. The original _copy_pte() code
should be the fixing target.
> Signed-off-by: Jianpeng Chang <jianpeng.chang.cn@windriver.com>
> ---
> arch/arm64/mm/trans_pgd.c | 12 ++++++++++--
> 1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/arch/arm64/mm/trans_pgd.c b/arch/arm64/mm/trans_pgd.c
> index 18543b603c77..ad4e5e4fcc91 100644
> --- a/arch/arm64/mm/trans_pgd.c
> +++ b/arch/arm64/mm/trans_pgd.c
> @@ -40,8 +40,13 @@ static void _copy_pte(pte_t *dst_ptep, pte_t *src_ptep, unsigned long addr)
> * Resume will overwrite areas that may be marked
> * read only (code, rodata). Clear the RDONLY bit from
> * the temporary mappings we use during restore.
> + *
> + * For kexec/hibernation, we need writable access regardless
> + * of the page's dirty state, so force clear PTE_RDONLY.
> */
> - __set_pte(dst_ptep, pte_mkwrite_novma(pte));
> + pte = set_pte_bit(pte, __pgprot(PTE_WRITE));
> + pte = clear_pte_bit(pte, __pgprot(PTE_RDONLY));
> + __set_pte(dst_ptep, pte);
Why not
__set_pte(dst_ptep, pte_mkwrite_novma(pte_mkdirty(pte));
?
> } else if (!pte_none(pte)) {
> /*
> * debug_pagealloc will removed the PTE_VALID bit if
> @@ -57,7 +62,10 @@ static void _copy_pte(pte_t *dst_ptep, pte_t *src_ptep, unsigned long addr)
> */
> BUG_ON(!pfn_valid(pte_pfn(pte)));
>
> - __set_pte(dst_ptep, pte_mkvalid(pte_mkwrite_novma(pte)));
> + pte = pte_mkvalid(pte);
> + pte = set_pte_bit(pte, __pgprot(PTE_WRITE));
> + pte = clear_pte_bit(pte, __pgprot(PTE_RDONLY));
> + __set_pte(dst_ptep, pte);
> }
> }
---
Best Regards,
Huang, Ying
next prev parent reply other threads:[~2025-11-28 9:32 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-27 3:43 [PATCH] arm64: mm: Fix kexec failure after pte_mkwrite_novma() change Jianpeng Chang
2025-11-27 5:41 ` Anshuman Khandual
2025-11-27 10:24 ` Chang, Jianpeng (CN)
2025-11-28 4:33 ` Anshuman Khandual
2025-11-28 9:32 ` Huang, Ying [this message]
2025-12-01 7:54 ` Jianpeng Chang
2025-12-01 8:42 ` Huang, Ying
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=87qztiec4e.fsf@DESKTOP-5N7EMDA \
--to=ying.huang@linux.alibaba.com \
--cc=anshuman.khandual@arm.com \
--cc=ardb@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=jianpeng.chang.cn@windriver.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=talel@amazon.com \
--cc=will@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;
as well as URLs for NNTP newsgroup(s).