Hi Baoquan, Thanks for your review. Please see the comment below.
On Thu, Nov 6, 2025 at 10:04 AM Baoquan He <[email protected]> wrote: > > Hi Pingfan, > > On 11/05/25 at 09:09pm, Pingfan Liu wrote: > > When I tested kexec with the latest kernel, I ran into the following > > warning: > > > > [ 40.712410] ------------[ cut here ]------------ > > [ 40.712576] WARNING: CPU: 2 PID: 1562 at kernel/kexec_core.c:1001 > > kimage_map_segment+0x144/0x198 > > [...] > > [ 40.816047] Call trace: > > [ 40.818498] kimage_map_segment+0x144/0x198 (P) > > [ 40.823221] ima_kexec_post_load+0x58/0xc0 > > [ 40.827246] __do_sys_kexec_file_load+0x29c/0x368 > > [...] > > [ 40.855423] ---[ end trace 0000000000000000 ]--- > > > > This is caused by the fact that kexec allocates the destination directly > > in the CMA area. In that case, the CMA kernel address should be exported > > directly to the IMA component, instead of using the vmalloc'd address. > > > > Signed-off-by: Pingfan Liu <[email protected]> > > Cc: Andrew Morton <[email protected]> > > Cc: Baoquan He <[email protected]> > > Cc: Alexander Graf <[email protected]> > > Cc: Steven Chen <[email protected]> > > Cc: [email protected] > > To: [email protected] > > --- > > kernel/kexec_core.c | 7 ++++++- > > 1 file changed, 6 insertions(+), 1 deletion(-) > > > > diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c > > index 9a1966207041..abe40286a02c 100644 > > --- a/kernel/kexec_core.c > > +++ b/kernel/kexec_core.c > > @@ -967,6 +967,7 @@ void *kimage_map_segment(struct kimage *image, int idx) > > kimage_entry_t *ptr, entry; > > struct page **src_pages; > > unsigned int npages; > > + struct page *cma; > > void *vaddr = NULL; > > int i; > > > > @@ -974,6 +975,9 @@ void *kimage_map_segment(struct kimage *image, int idx) > > size = image->segment[idx].memsz; > > eaddr = addr + size; > > > > + cma = image->segment_cma[idx]; > > Thanks for your fix. But I totally can't get what you are doing. The idx > passed into kimage_map_segment() could index image->segment[], and can > index image->segment_cma[], could you reconsider and make the code more > reasonable? > Since idx can index both image->segment[] and segment_cma[], the behavior differs based on whether segment_cma[idx] is NULL: - If segment_cma[idx] is not NULL, it points directly to the final target location, eliminating the need for data copying that traditional kexec relocation requires. - If segment_cma[idx] is NULL, the segment relies on the traditional kexec relocation code to copy its data. Thanks, Pingfan > > + if (cma) > > + return cma; > > /* > > * Collect the source pages and map them in a contiguous VA range. > > */ > > @@ -1014,7 +1018,8 @@ void *kimage_map_segment(struct kimage *image, int > > idx) > > > > void kimage_unmap_segment(void *segment_buffer) > > { > > - vunmap(segment_buffer); > > + if (is_vmalloc_addr(segment_buffer)) > > + vunmap(segment_buffer); > > } > > > > struct kexec_load_limit { > > -- > > 2.49.0 > > >
