Skip to content

HAOC: IEE_SIP: Fix kdump failure in native_idt_invalidate()#1523

Open
amjac27 wants to merge 1 commit intodeepin-community:linux-6.6.yfrom
amjac27:fix-kdump
Open

HAOC: IEE_SIP: Fix kdump failure in native_idt_invalidate()#1523
amjac27 wants to merge 1 commit intodeepin-community:linux-6.6.yfrom
amjac27:fix-kdump

Conversation

@amjac27
Copy link
Contributor

@amjac27 amjac27 commented Mar 3, 2026

kdump 生成 vmcore 的路径中会通过 machine_kexec() 调用 native_idt_invalidate() 。当启用 IEE_SIP 时,native_idt_invalidate() 最终会调用 iee_rwx_gate,其试图切换函数栈时发生错误。

因此,我们修改了 native_idt_invalidate() 函数,它只被 machine_kexec() 调用,使其始终直接调用 lidt,避免访问 iee_rwx_gate。

Summary by Sourcery

Bug Fixes:

  • Prevent kdump failures in native_idt_invalidate() under IEE_SIP by loading an invalid IDT via the early IDT loader instead of the IEE-enabled path.

The native_idt_invalidate() function is called via machine_kexec()
during the kdump vmcore generation path. When IEE_SIP is enabled,
the invalidation eventually triggers iee_rwx_gate, which fails
while attempting to switch the function stack.

This patch modifies native_idt_invalidate(), which is exclusively
called by machine_kexec(), to always invoke the 'lidt' instruction
directly. This avoids calling into the complex iee_rwx_gate.
@sourcery-ai
Copy link

sourcery-ai bot commented Mar 3, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts native_idt_invalidate() so that, when CONFIG_IEE_SIP is enabled, the kdump path uses iee_load_idt_early() instead of going through the IEE_SIP indirection, preventing a stack-switch error during kexec/kdump while still loading an invalid IDT descriptor.

Sequence diagram for kdump machine_kexec IDT invalidation with CONFIG_IEE_SIP

sequenceDiagram
    actor KdumpPath
    participant machine_kexec
    participant native_idt_invalidate
    participant iee_load_idt_early
    participant native_load_idt

    KdumpPath ->> machine_kexec: initiate kdump
    machine_kexec ->> native_idt_invalidate: native_idt_invalidate()

    alt CONFIG_IEE_SIP enabled
        native_idt_invalidate ->> iee_load_idt_early: iee_load_idt_early(&invalid_idt)
        iee_load_idt_early --> native_idt_invalidate: invalid IDT loaded
    else CONFIG_IEE_SIP disabled
        native_idt_invalidate ->> native_load_idt: native_load_idt(&invalid_idt)
        native_load_idt --> native_idt_invalidate: invalid IDT loaded
    end

    native_idt_invalidate --> machine_kexec: return
    machine_kexec --> KdumpPath: continue kdump without IEE_SIP stack switch
Loading

File-Level Changes

Change Details Files
Special-case native_idt_invalidate() under CONFIG_IEE_SIP to bypass IEE_SIP runtime machinery during kdump and directly load an invalid IDT via iee_load_idt_early().
  • Wrap the IDT invalidation logic in native_idt_invalidate() with a CONFIG_IEE_SIP conditional
  • For CONFIG_IEE_SIP=y, replace native_load_idt() with iee_load_idt_early() to load the invalid IDT descriptor
  • For non-IEE_SIP builds, preserve existing behavior by continuing to call native_load_idt()
  • Document in comments that native_idt_invalidate() is only called by machine_kexec() and that IEE_SIP should not be used in the kdump path
arch/x86/include/asm/desc.h

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • The new comments in native_idt_invalidate() use // style, which is non-idiomatic for kernel code; please convert them to /* ... */ block comments to match existing style.
  • Instead of adding a CONFIG_IEE_SIP-specific call to iee_load_idt_early() in native_idt_invalidate(), consider moving this conditional logic into native_load_idt() (or a helper it uses) so callers don't need to know about IEE_SIP-specific variants and you avoid sprinkling CONFIG_IEE_SIP ifdefs at call sites.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new comments in native_idt_invalidate() use `//` style, which is non-idiomatic for kernel code; please convert them to `/* ... */` block comments to match existing style.
- Instead of adding a CONFIG_IEE_SIP-specific call to iee_load_idt_early() in native_idt_invalidate(), consider moving this conditional logic into native_load_idt() (or a helper it uses) so callers don't need to know about IEE_SIP-specific variants and you avoid sprinkling CONFIG_IEE_SIP ifdefs at call sites.

## Individual Comments

### Comment 1
<location path="arch/x86/include/asm/desc.h" line_range="266-269" />
<code_context>

+#ifdef CONFIG_IEE_SIP
+	// The native_idt_invalidate() is only called by machine_kexec(). 
+	// In the kdump path, IEE_SIP should not be used, so we directly
+	// call iee_load_idt_early(), which is the original version of
+	// native_load_idt() to load an invalid IDT.
+	iee_load_idt_early(&invalid_idt);
+#else
 	native_load_idt(&invalid_idt);
</code_context>
<issue_to_address>
**question:** Comment about kdump usage may be misleading given `native_idt_invalidate()` is used for all `machine_kexec()` paths.

Since `native_idt_invalidate()` is used for all `machine_kexec()` paths (not just kdump), this wording could suggest a behavior that only applies to kdump. If you intend to describe a kdump-specific constraint, please adjust the condition or comment to clearly distinguish kdump from other kexec paths so the documentation matches the actual semantics.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +266 to +269
// In the kdump path, IEE_SIP should not be used, so we directly
// call iee_load_idt_early(), which is the original version of
// native_load_idt() to load an invalid IDT.
iee_load_idt_early(&invalid_idt);
Copy link

Choose a reason for hiding this comment

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

question: Comment about kdump usage may be misleading given native_idt_invalidate() is used for all machine_kexec() paths.

Since native_idt_invalidate() is used for all machine_kexec() paths (not just kdump), this wording could suggest a behavior that only applies to kdump. If you intend to describe a kdump-specific constraint, please adjust the condition or comment to clearly distinguish kdump from other kexec paths so the documentation matches the actual semantics.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a kdump vmcore generation failure when machine_kexec() triggers native_idt_invalidate() on kernels built with CONFIG_IEE_SIP, by ensuring the invalid IDT load bypasses the IEE-enabled IDT loading path.

Changes:

  • Update native_idt_invalidate() to load an invalid IDT via iee_load_idt_early() when CONFIG_IEE_SIP is enabled.
  • Avoid the IEE gate/stack-switching path (iee_rwx_gate / iee_load_idt) during kexec/kdump IDT invalidation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +265 to +268
// The native_idt_invalidate() is only called by machine_kexec().
// In the kdump path, IEE_SIP should not be used, so we directly
// call iee_load_idt_early(), which is the original version of
// native_load_idt() to load an invalid IDT.
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

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

The new inline comment uses '//' style and includes trailing whitespace after machine_kexec(). (checkpatch will flag this). Please switch to kernel-standard /* ... */ comments and remove the trailing space to keep the header consistent with the surrounding comment style in this file.

Suggested change
// The native_idt_invalidate() is only called by machine_kexec().
// In the kdump path, IEE_SIP should not be used, so we directly
// call iee_load_idt_early(), which is the original version of
// native_load_idt() to load an invalid IDT.
/*
* The native_idt_invalidate() is only called by machine_kexec().
* In the kdump path, IEE_SIP should not be used, so we directly
* call iee_load_idt_early(), which is the original version of
* native_load_idt() to load an invalid IDT.
*/

Copilot uses AI. Check for mistakes.
Comment on lines +265 to +268
// The native_idt_invalidate() is only called by machine_kexec().
// In the kdump path, IEE_SIP should not be used, so we directly
// call iee_load_idt_early(), which is the original version of
// native_load_idt() to load an invalid IDT.
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

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

The comment says "In the kdump path" but native_idt_invalidate() is invoked from machine_kexec() for both regular kexec and kdump flows. Consider rewording to describe the broader "machine_kexec"/kexec context (and the reason for bypassing the IEE-enabled path) to avoid misleading future readers.

Suggested change
// The native_idt_invalidate() is only called by machine_kexec().
// In the kdump path, IEE_SIP should not be used, so we directly
// call iee_load_idt_early(), which is the original version of
// native_load_idt() to load an invalid IDT.
// native_idt_invalidate() is only called from machine_kexec(), which
// covers both regular kexec and kdump flows. In this context IEE_SIP
// must be bypassed, so we directly call iee_load_idt_early(), the
// non-IEE variant of native_load_idt(), to load an invalid IDT.

Copilot uses AI. Check for mistakes.
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.

2 participants