From: Mike Rapoport <rppt@kernel.org>
To: gaohan@iscas.ac.cn
Cc: Paul Walmsley <pjw@kernel.org>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Alexandre Ghiti <alex@ghiti.fr>,
Nathan Chancellor <nathan@kernel.org>,
Nick Desaulniers <ndesaulniers@google.com>,
Bill Wendling <morbo@google.com>,
Justin Stitt <justinstitt@google.com>,
Andrew Morton <akpm@linux-foundation.org>,
Baoquan He <baoquan.he@linux.dev>,
Pasha Tatashin <pasha.tatashin@soleen.com>,
Pratyush Yadav <pratyush@kernel.org>, Yao Zi <me@ziyao.cc>,
Han Gao <rabenda.cn@gmail.com>,
linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
llvm@lists.linux.dev, kexec@lists.infradead.org
Subject: Re: [PATCH 3/5] kexec_file: Honor the segment alignment for CMA allocations
Date: Tue, 3 Nov 2026 12:14:50 +0200 [thread overview]
Message-ID: <aum0GlBKTfZ6rvgL@kernel.org> (raw)
In-Reply-To: <20261023-riscv-kexec-cma-fixes-v1-3-825b90ea23c4@iscas.ac.cn>
On Fri, Oct 23, 2026 at 03:33:16PM +0800, Han Gao via B4 Relay wrote:
> From: Han Gao <gaohan@iscas.ac.cn>
>
> dma_alloc_from_contiguous() limits the requested alignment to
> CONFIG_CMA_ALIGNMENT without reporting it. kexec_alloc_contig() can
> therefore place a segment at a less aligned address than buf_align. On
> RISC-V with 4 KiB pages, the default 1 MiB limit is below the 2 MiB
> kernel alignment, and the new kernel stops at the setup_vm() BUG_ON for
> a misaligned physical address.
>
> Release such a block and fall back to the regular memory hole search,
> which honors the alignment.
>
> Fixes: 07d24902977e ("kexec: enable CMA based contiguous allocation")
> Signed-off-by: Han Gao <gaohan@iscas.ac.cn>
Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---
> kernel/kexec_file.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c
> index 59fb9d71e9d8..6ce10e01414e 100644
> --- a/kernel/kexec_file.c
> +++ b/kernel/kexec_file.c
> @@ -690,6 +690,13 @@ static int kexec_alloc_contig(struct kexec_buf *kbuf)
>
> mem = page_to_boot_pfn(p) << PAGE_SHIFT;
>
> + /* dma_alloc_from_contiguous() caps the alignment at CONFIG_CMA_ALIGNMENT. */
> + if (!IS_ALIGNED(mem, kbuf->buf_align)) {
> + pr_debug("CMA block 0x%lx is not aligned to 0x%lx\n", mem, kbuf->buf_align);
> + dma_release_from_contiguous(NULL, p, nr_pages);
> + return -EINVAL;
> + }
> +
> if (kimage_is_destination_range(kbuf->image, mem, mem + kbuf->memsz)) {
> /* Our region is already in use by a statically defined one. Bail out. */
> pr_debug("CMA overlaps existing mem: 0x%lx+0x%lx\n", mem, kbuf->memsz);
>
> --
> 2.55.0
>
>
--
Sincerely yours,
Mike.
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
WARNING: multiple messages have this Message-ID (diff)
From: Mike Rapoport <rppt@kernel.org>
To: gaohan@iscas.ac.cn
Cc: Paul Walmsley <pjw@kernel.org>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Alexandre Ghiti <alex@ghiti.fr>,
Nathan Chancellor <nathan@kernel.org>,
Nick Desaulniers <ndesaulniers@google.com>,
Bill Wendling <morbo@google.com>,
Justin Stitt <justinstitt@google.com>,
Andrew Morton <akpm@linux-foundation.org>,
Baoquan He <baoquan.he@linux.dev>,
Pasha Tatashin <pasha.tatashin@soleen.com>,
Pratyush Yadav <pratyush@kernel.org>, Yao Zi <me@ziyao.cc>,
Han Gao <rabenda.cn@gmail.com>,
linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
llvm@lists.linux.dev, kexec@lists.infradead.org
Subject: Re: [PATCH 3/5] kexec_file: Honor the segment alignment for CMA allocations
Date: Tue, 3 Nov 2026 12:14:50 +0200 [thread overview]
Message-ID: <aum0GlBKTfZ6rvgL@kernel.org> (raw)
In-Reply-To: <20261023-riscv-kexec-cma-fixes-v1-3-825b90ea23c4@iscas.ac.cn>
On Fri, Oct 23, 2026 at 03:33:16PM +0800, Han Gao via B4 Relay wrote:
> From: Han Gao <gaohan@iscas.ac.cn>
>
> dma_alloc_from_contiguous() limits the requested alignment to
> CONFIG_CMA_ALIGNMENT without reporting it. kexec_alloc_contig() can
> therefore place a segment at a less aligned address than buf_align. On
> RISC-V with 4 KiB pages, the default 1 MiB limit is below the 2 MiB
> kernel alignment, and the new kernel stops at the setup_vm() BUG_ON for
> a misaligned physical address.
>
> Release such a block and fall back to the regular memory hole search,
> which honors the alignment.
>
> Fixes: 07d24902977e ("kexec: enable CMA based contiguous allocation")
> Signed-off-by: Han Gao <gaohan@iscas.ac.cn>
Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---
> kernel/kexec_file.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c
> index 59fb9d71e9d8..6ce10e01414e 100644
> --- a/kernel/kexec_file.c
> +++ b/kernel/kexec_file.c
> @@ -690,6 +690,13 @@ static int kexec_alloc_contig(struct kexec_buf *kbuf)
>
> mem = page_to_boot_pfn(p) << PAGE_SHIFT;
>
> + /* dma_alloc_from_contiguous() caps the alignment at CONFIG_CMA_ALIGNMENT. */
> + if (!IS_ALIGNED(mem, kbuf->buf_align)) {
> + pr_debug("CMA block 0x%lx is not aligned to 0x%lx\n", mem, kbuf->buf_align);
> + dma_release_from_contiguous(NULL, p, nr_pages);
> + return -EINVAL;
> + }
> +
> if (kimage_is_destination_range(kbuf->image, mem, mem + kbuf->memsz)) {
> /* Our region is already in use by a statically defined one. Bail out. */
> pr_debug("CMA overlaps existing mem: 0x%lx+0x%lx\n", mem, kbuf->memsz);
>
> --
> 2.55.0
>
>
--
Sincerely yours,
Mike.
next prev parent reply other threads:[~2026-11-03 10:15 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-23 7:33 [PATCH 0/5] riscv: kexec: fix kexec_file with CMA-backed segments Han Gao via B4 Relay
2026-10-23 7:33 ` Han Gao via B4 Relay
2026-10-23 7:33 ` Han Gao
2026-10-23 7:33 ` [PATCH 1/5] riscv: kexec: Disable the MMU before walking the entry list Han Gao via B4 Relay
2026-10-23 7:33 ` Han Gao via B4 Relay
2026-10-23 7:33 ` Han Gao
2026-10-23 7:39 ` sashiko-bot
2026-10-23 7:33 ` [PATCH 2/5] riscv: kexec_file: Pair PC-relative low parts with their high parts Han Gao via B4 Relay
2026-10-23 7:33 ` Han Gao via B4 Relay
2026-10-23 7:33 ` Han Gao
2026-10-23 7:45 ` sashiko-bot
2026-10-23 7:33 ` [PATCH 3/5] kexec_file: Honor the segment alignment for CMA allocations Han Gao via B4 Relay
2026-10-23 7:33 ` Han Gao via B4 Relay
2026-10-23 7:33 ` Han Gao
2026-10-23 8:18 ` sashiko-bot
2026-11-03 10:14 ` Mike Rapoport [this message]
2026-11-03 10:14 ` Mike Rapoport
2026-10-23 7:33 ` [PATCH 4/5] kexec_core: Clear the unused part of CMA segments Han Gao via B4 Relay
2026-10-23 7:33 ` Han Gao via B4 Relay
2026-10-23 7:33 ` Han Gao
2026-10-23 8:04 ` sashiko-bot
2026-11-03 10:15 ` Mike Rapoport
2026-11-03 10:15 ` Mike Rapoport
2026-10-23 7:33 ` [PATCH 5/5] riscv: mm: Reserve the DTB before scanning reserved memory Han Gao via B4 Relay
2026-10-23 7:33 ` Han Gao via B4 Relay
2026-10-23 7:33 ` Han Gao
2026-10-23 8:06 ` sashiko-bot
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=aum0GlBKTfZ6rvgL@kernel.org \
--to=rppt@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=alex@ghiti.fr \
--cc=aou@eecs.berkeley.edu \
--cc=baoquan.he@linux.dev \
--cc=gaohan@iscas.ac.cn \
--cc=justinstitt@google.com \
--cc=kexec@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=llvm@lists.linux.dev \
--cc=me@ziyao.cc \
--cc=morbo@google.com \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=palmer@dabbelt.com \
--cc=pasha.tatashin@soleen.com \
--cc=pjw@kernel.org \
--cc=pratyush@kernel.org \
--cc=rabenda.cn@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.