Skip to content

Conversation

@pfliu
Copy link
Collaborator

@pfliu pfliu commented Nov 19, 2025

Resolves: https://issues.redhat.com/browse/RHEL-75537

Configure "makedumpfile -E -d 31" in kdump.conf, and panic the system, kdump will fail with the error as:

[ 41.891856] kdump.sh[724]: --num-threads cannot used with ELF format.
[ 41.897104] kdump.sh[724]: Commandline parameter is invalid.
[ 41.897290] kdump.sh[724]: Try `makedumpfile --help' for more information.
[ 41.897435] kdump.sh[724]: makedumpfile Failed.
[ 41.898804] kdump[726]:
saving vmcore failed, exitcode:1

Skip --num-threads when -E option is given

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @pfliu, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical bug in the kdump process where makedumpfile would terminate with an error when attempting to generate a crash dump in ELF format while also leveraging multiple CPU threads. The change introduces a safeguard in the kdump.sh script to ensure that the --num-threads option is not passed to makedumpfile if the ELF format option (-E) is already in use, thereby preventing the command-line parameter conflict and allowing successful crash dump generation.

Highlights

  • Bug Fix: Resolves an issue where makedumpfile would fail when both the -E (ELF format) option and --num-threads were specified, leading to kdump failures.
  • Conditional Threading: The kdump.sh script is updated to conditionally add the --num-threads option to makedumpfile. It now explicitly checks if the -E option is present in the CORE_COLLECTOR variable and skips adding --num-threads if -E is found, preventing the conflict.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses a failure in kdump.sh where --num-threads was incorrectly added to makedumpfile when the ELF format (-E) was specified. The change prevents this by checking for the -E option before adding --num-threads.

My review includes a suggestion to make the implementation POSIX-compliant, as required by the script's own documentation. The current change uses a bash-specific construct which could cause issues on some systems.

Additionally, I've noticed that the same potential issue exists in the dump_raw function (lines 389-391 in kdump.sh). It would be beneficial to apply a similar fix there to ensure raw dumps with -E specified also work correctly.

CORE_COLLECTOR=$(echo "$CORE_COLLECTOR" | sed -e "s/-F//g")
THREADS=$(nproc)
if [ "$THREADS" -gt 1 ]; then
if [ "$THREADS" -gt 1 ] && [[ "$CORE_COLLECTOR" != *"-E"* ]]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The use of [[...]] is not POSIX-compliant, but this script is expected to be POSIX-compliant as stated in the file's header comment. Using [[...]] can lead to issues on systems where /bin/sh is not bash.

A more portable approach that is consistent with other parts of this file is to use grep to check for the presence of the -E option.

Suggested change
if [ "$THREADS" -gt 1 ] && [[ "$CORE_COLLECTOR" != *"-E"* ]]; then
if [ "$THREADS" -gt 1 ] && ! echo "$CORE_COLLECTOR" | grep -q -- '-E'; then

@coiby
Copy link
Member

coiby commented Nov 21, 2025

Hi @pfliu

Gemini also notices that "the same potential issue exists in the dump_raw function (lines 389-391 in kdump.sh)". I think this is a valid concern, right?

@pfliu
Copy link
Collaborator Author

pfliu commented Nov 21, 2025

Hi @pfliu

Gemini also notices that "the same potential issue exists in the dump_raw function (lines 389-391 in kdump.sh)". I think this is a valid concern, right?

@coiby, yes, it is a valid concern. I will update it.

Thanks

@pfliu pfliu force-pushed the elf_fix branch 3 times, most recently from 8b918fb to 190bf7f Compare November 21, 2025 08:00
@prudo1
Copy link
Collaborator

prudo1 commented Nov 24, 2025

Hi @pfliu,
Hi @coiby,

as mentioned in #117, I find the current handling of --num-threads= sub optimal. In particular the fact that it is added so late in the dump_* functions. My fear is that this will repeatedly cause issues in the future where we forget to update one of the code paths. Personally I think it makes much more sense to move the code to get_kdump_conf() and handle all the different cases there. Especially as the dump_raw case is already broken today, as for raw dumps -F is required that cannot be used with --num-threads= as well...

@pfliu could you do this cleanup as well while fixing the issue? I'd appreciate it.

Thanks
Philipp

@coiby
Copy link
Member

coiby commented Nov 25, 2025

Hi @prudo1

Thanks for sharing your feedback! I also agree addressing num-thread early in get_kdump_conf is a better choice.

@pfliu
Copy link
Collaborator Author

pfliu commented Nov 27, 2025

get_kdump_conf

@prudo1, I have pushed an update version, which make the code clean. Please help to review.

Thanks

Comment on lines 58 to 65
case $CORE_COLLECTOR in
*makedumpfile*)
THREADS=$(nproc)
if [ "$THREADS" -gt 1 ]; then
CORE_COLLECTOR="$CORE_COLLECTOR --num-threads=$THREADS"
fi
;;
esac
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @pfliu,

thanks for the update! A few nits I found with your code

  1. The hunk should be moved to the end of the function. The way it is implemented right now the option is only added when core_collector is set in kdump.conf but not when the default value is used.
  2. The flattened dump format also doesn't support --num-threads=. So you have to prevent setting the option when -F is set as well.
  3. Ideally the CORE_COLLECTOR is no longer changed after get_kdump_confs(). So...

@@ -149,10 +157,6 @@ dump_fs() {
case $CORE_COLLECTOR in
*makedumpfile*)
CORE_COLLECTOR=$(echo "$CORE_COLLECTOR" | sed -e "s/-F//g")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... this line should be moved to get_kdump_confs() as well.

All in all, I would implement it so the code looks something like this in the end.
Note: The diff is meant as an example. I haven't done any testing on it.

diff --git a/dracut/99kdumpbase/kdump.sh b/dracut/99kdumpbase/kdump.sh
index 0ec1c3c..1c8ec85 100755
--- a/dracut/99kdumpbase/kdump.sh
+++ b/dracut/99kdumpbase/kdump.sh
@@ -22,8 +22,7 @@ KDUMP_LOG_DEST=""
 KDUMP_LOG_OP=""
 KDUMP_TEST_ID=""
 KDUMP_TEST_STATUS=""
-CORE_COLLECTOR=""
-DEFAULT_CORE_COLLECTOR="makedumpfile -l --message-level 7 -d 31"
+CORE_COLLECTOR="makedumpfile -l --message-level 7 -d 31"
 DMESG_COLLECTOR="/sbin/vmcore-dmesg"
 FAILURE_ACTION="systemctl reboot -f"
 DATEDIR=$(date +%Y-%m-%d-%T)
@@ -55,20 +54,6 @@ get_kdump_confs() {
                 ;;
             core_collector)
                 [ -n "$config_val" ] && CORE_COLLECTOR="$config_val"
-                case $CORE_COLLECTOR in
-                    *makedumpfile*)
-                        THREADS=$(nproc)
-                        if [ "$THREADS" -gt 1 ]; then
-                            case "$CORE_COLLECTOR" in
-                                *-E*) ;;
-
-                                *)
-                                    CORE_COLLECTOR="$CORE_COLLECTOR --num-threads=$THREADS"
-                                    ;;
-                            esac
-                        fi
-                        ;;
-                esac
                 ;;
             sshkey)
                 if [ -f "$config_val" ]; then
@@ -122,12 +107,37 @@ get_kdump_confs() {
         esac
     done < "$KDUMP_CONF_PARSED"
 
-    if [ -z "$CORE_COLLECTOR" ]; then
-        CORE_COLLECTOR="$DEFAULT_CORE_COLLECTOR"
-        if is_ssh_dump_target || is_raw_dump_target; then
-            CORE_COLLECTOR="$CORE_COLLECTOR -F"
-        fi
-    fi
+    case $CORE_COLLECTOR in
+        *makedumpfile*)
+            # make sure the flattened dump format is used for ssh and raw
+            # targets but not for fs targets.
+            if is_ssh_dump_target || is_raw_dump_target; then
+                case "$CORE_COLLECTOR" in
+                    *-F*) ;;
+                    *)
+                        dwarn "When dumping to ssh/raw targets the flattened dump format must be used. Adding option -F to makedumpfile."
+                        CORE_COLLECTOR="$CORE_COLLECTOR -F"
+                        ;;
+                esac
+            else
+                CORE_COLLECTOR=$(echo "$CORE_COLLECTOR" | sed -e "s/-F//g")
+            fi
+
+            case "$CORE_COLLECTOR" in
+                *-F*|*-E*)
+                    # --num-threads= is only supported by the kdump format
+                    ;;
+                *)
+                    THREADS=$(nproc)
+                    if [ "$THREADS" -gt 1 ]; then
+                        CORE_COLLECTOR="$CORE_COLLECTOR --num-threads=$THREADS"
+                    fi
+                    ;;
+            esac
+            ;;
+
+        *) ;;
+    esac
 }
 
 # store the kexec kernel log to a file.
@@ -159,13 +169,6 @@ dump_fs() {
         fi
     fi
 
-    # Remove -F in makedumpfile case. We don't want a flat format dump here.
-    case $CORE_COLLECTOR in
-        *makedumpfile*)
-            CORE_COLLECTOR=$(echo "$CORE_COLLECTOR" | sed -e "s/-F//g")
-            ;;
-    esac
-
     if [ -z "$KDUMP_TEST_ID" ]; then
         _dump_fs_path=$(echo "$1/$KDUMP_PATH/$HOST_IP-$DATEDIR/" | tr -s /)
     else
diff --git a/mkdumprd b/mkdumprd
index caca83b..a8a5c8d 100644
--- a/mkdumprd
+++ b/mkdumprd
@@ -288,10 +288,13 @@ verify_core_collector()
 	fi
 
 	if is_ssh_dump_target || is_raw_dump_target; then
-		if ! strstr "$_params" "-F"; then
-			perror_exit 'The specified dump target needs makedumpfile "-F" option.'
+		# temporarily add -F option, if needed. It will be added for
+		# automatically in kdump.sh.
+		if [[ " $_params " != *" -F "* ]]; then
+			_params="$_params -F vmcore"
+		else
+			_params="$_params vmcore"
 		fi
-		_params="$_params vmcore"
 	else
 		_params="$_params vmcore dumpfile"
 	fi

That should also allow to remove the error in mkdumprd when the -F option is missing for ssh/raw dump targets, which IMHO is a big improvement (I always forget to add -F when I try to dump via ssh...).

Thanks
Philipp

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your suggestion. I have re-organize the patch into three

Pingfan Liu added 3 commits November 28, 2025 09:49
Signed-off-by: Pingfan Liu <piliu@redhat.com>
The handling of num-threads is duplicated in dump_fs() and dump_raw().
Centralize them into get_kdump_confs()

Signed-off-by: Pingfan Liu <piliu@redhat.com>
Resolves: https://issues.redhat.com/browse/RHEL-75537

Configure "makedumpfile -E -d 31" in kdump.conf, and panic the system, kdump will fail with the error as:

[ 41.891856] kdump.sh[724]: --num-threads cannot used with ELF format.
[ 41.897104] kdump.sh[724]: Commandline parameter is invalid.
[ 41.897290] kdump.sh[724]: Try `makedumpfile --help' for more information.
[ 41.897435] kdump.sh[724]: makedumpfile Failed.
[ 41.898804] kdump[726]:
saving vmcore failed, exitcode:1

Skip --num-threads when -E option is given.

As for the -F option, it is meaningless to sequentially access linear
addresses with multiple threads Skip --num-threads too in that case.

Signed-off-by: Pingfan Liu <piliu@redhat.com>
Copy link
Collaborator

@prudo1 prudo1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @pfliu,

personally, I'd really love the check for -F in mkdumprd to be gone. But that is only because I always forget to set it when I test a ssh target and it buggers me that I've forgot it, again...

Anyway, while getting rid of the check would be nice I'm afraid that's something that can wait. In general I think it would be good to reconsider how the config is handled so we don't have to parse it over and over again and make changes to it at different places. But that is a bigger task and way out of scope for this PR. Plus the PR is a big step in the right direction.

Having that said, looks good to me!

Thanks
Philipp

@pfliu
Copy link
Collaborator Author

pfliu commented Dec 3, 2025

places. But that is a bigger task and way out of scope for this

Thank you very much. Your suggestion makes the code cleaner and easy to maintain

@coiby coiby merged commit 9a51c4b into rhkdump:main Dec 4, 2025
5 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants