From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com [115.124.30.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4DECE2951A7 for ; Tue, 2 Dec 2025 05:42:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.130 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764654151; cv=none; b=H/111BsN2le9n8IVzPEJc+FvpihQDTMqtf0AGfx0EGVwQYuPiKfKOnXRDjVckHOJlmOa6x9+d6h6peGiVHD8FVyjNhbmw8dUDEX7UQ6cOCFLGwyOxtpqw0dKlhJubt4mXc7PwPT1QLhMZbr8kJXBMVaM4mnzWKSi/Pqas1aIYbQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764654151; c=relaxed/simple; bh=tak1z4AJ7oV1Rd0PJ07qT3OV7lD7zrLyjwuLjq9LCNA=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=uKPX8mM7i2eDCO9WZR5HbX4fzktFjX8zqs2CoGTBgTEA/+/hDONy72BV59SC+KIaGBC1USZBKQdaciLyWWbKJY6F1kxGrKeF69Um3Unr+n69/nbO46s1mDCPluVu9WOhkgEBqpj4WfYUnYIH3evQfM++yrjcWksBqGj9L2w81Us= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=ZkqPO9zw; arc=none smtp.client-ip=115.124.30.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="ZkqPO9zw" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1764654139; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; bh=LrK+wMnVK5P5qucWSjcyyUEDnxwMcENlpJzk4sPkR90=; b=ZkqPO9zw2HdslRGfonYWy/9JSIdrIKn5n8YdqVrHPdeaNQxWhLOgZPhCiD43qdMyrZ9uefv/I9KKvLQdxLwODtpe9JL3JzWjNgKlEUcZdYYBoYx124xjF9tVWvpZLFVSZuL9nNZ4X4jeiwIHxS0QdiK1rYNjh4wRgB8NWvZ+G78= Received: from DESKTOP-5N7EMDA(mailfrom:ying.huang@linux.alibaba.com fp:SMTPD_---0Wtv977t_1764654138 cluster:ay36) by smtp.aliyun-inc.com; Tue, 02 Dec 2025 13:42:18 +0800 From: "Huang, Ying" To: Jianpeng Chang Cc: , , , , , Subject: Re: [v2 PATCH] arm64: mm: Fix kexec failure after pte_mkwrite_novma() change In-Reply-To: <20251202022707.2720933-1-jianpeng.chang.cn@windriver.com> (Jianpeng Chang's message of "Tue, 2 Dec 2025 10:27:07 +0800") References: <20251202022707.2720933-1-jianpeng.chang.cn@windriver.com> Date: Tue, 02 Dec 2025 13:42:17 +0800 Message-ID: <87qztdh22u.fsf@DESKTOP-5N7EMDA> User-Agent: Gnus/5.13 (Gnus v5.13) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=ascii Jianpeng Chang 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()") > Signed-off-by: Jianpeng Chang LGTM, Thanks! Feel free to add my Reviewed-by: Huang Ying in the future versions. > --- > v2: > - Use pte_mkwrite_novma(pte_mkdirty(pte)) instead of manual bit manipulation > - Updated comments to clarify pte_mkwrite_novma() alone cannot be used > v1: https://lore.kernel.org/all/20251127034350.3600454-1-jianpeng.chang.cn@windriver.com/ > > arch/arm64/mm/trans_pgd.c | 9 +++++++-- > 1 file changed, 7 insertions(+), 2 deletions(-) > > diff --git a/arch/arm64/mm/trans_pgd.c b/arch/arm64/mm/trans_pgd.c > index 18543b603c77..08f5ee6643e1 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 to all > + * pages in the linear mapping to copy the new kernel image. > + * Mark pages dirty first to ensure pte_mkwrite_novma() > + * clears PTE_RDONLY. > */ > - __set_pte(dst_ptep, pte_mkwrite_novma(pte)); > + __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,7 @@ 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))); > + __set_pte(dst_ptep, pte_mkvalid(pte_mkwrite_novma(pte_mkdirty(pte)))); > } > } --- Best Regards, Huang, Ying