tree: https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master head: 5e4f84f18c4ee9b0ccdc19e39b7de41df21699dd commit: 849599b702ef8977fcd5b2f27c61ef773c42bb88 [7646/8170] powerpc/crash: add crash memory hotplug support config: powerpc-randconfig-r061-20240426 (https://download.01.org/0day-ci/archive/20240426/202404261048.skfV5DDB-lkp@xxxxxxxxx/config) compiler: powerpc-linux-gcc (GCC) 13.2.0 If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@xxxxxxxxx> | Closes: https://lore.kernel.org/oe-kbuild-all/202404261048.skfV5DDB-lkp@xxxxxxxxx/ cocci warnings: (new ones prefixed by >>) >> arch/powerpc/kexec/crash.c:488:2-8: WARNING: NULL check before some freeing functions is not needed. vim +488 arch/powerpc/kexec/crash.c 418 419 /** 420 * update_crash_elfcorehdr() - Recreate the elfcorehdr and replace it with old 421 * elfcorehdr in the kexec segment array. 422 * @image: the active struct kimage 423 * @mn: struct memory_notify data handler 424 */ 425 static void update_crash_elfcorehdr(struct kimage *image, struct memory_notify *mn) 426 { 427 int ret; 428 struct crash_mem *cmem = NULL; 429 struct kexec_segment *ksegment; 430 void *ptr, *mem, *elfbuf = NULL; 431 unsigned long elfsz, memsz, base_addr, size; 432 433 ksegment = &image->segment[image->elfcorehdr_index]; 434 mem = (void *) ksegment->mem; 435 memsz = ksegment->memsz; 436 437 ret = get_crash_memory_ranges(&cmem); 438 if (ret) { 439 pr_err("Failed to get crash mem range\n"); 440 return; 441 } 442 443 /* 444 * The hot unplugged memory is part of crash memory ranges, 445 * remove it here. 446 */ 447 if (image->hp_action == KEXEC_CRASH_HP_REMOVE_MEMORY) { 448 base_addr = PFN_PHYS(mn->start_pfn); 449 size = mn->nr_pages * PAGE_SIZE; 450 ret = remove_mem_range(&cmem, base_addr, size); 451 if (ret) { 452 pr_err("Failed to remove hot-unplugged memory from crash memory ranges\n"); 453 goto out; 454 } 455 } 456 457 ret = crash_prepare_elf64_headers(cmem, false, &elfbuf, &elfsz); 458 if (ret) { 459 pr_err("Failed to prepare elf header\n"); 460 goto out; 461 } 462 463 /* 464 * It is unlikely that kernel hit this because elfcorehdr kexec 465 * segment (memsz) is built with addition space to accommodate growing 466 * number of crash memory ranges while loading the kdump kernel. It is 467 * Just to avoid any unforeseen case. 468 */ 469 if (elfsz > memsz) { 470 pr_err("Updated crash elfcorehdr elfsz %lu > memsz %lu", elfsz, memsz); 471 goto out; 472 } 473 474 ptr = __va(mem); 475 if (ptr) { 476 /* Temporarily invalidate the crash image while it is replaced */ 477 xchg(&kexec_crash_image, NULL); 478 479 /* Replace the old elfcorehdr with newly prepared elfcorehdr */ 480 memcpy((void *)ptr, elfbuf, elfsz); 481 482 /* The crash image is now valid once again */ 483 xchg(&kexec_crash_image, image); 484 } 485 out: 486 kvfree(cmem); 487 if (elfbuf) > 488 kvfree(elfbuf); 489 } 490 -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki