Skip to content

[Deepin-Kernel-SIG] [linux 6.6.y] [zhaoxin] x86/microcode/zhaoxin: Fix NULL check for the P4D page allocation x86/mce/zhaoxin: Fix bus number shift in ZDI error reporting - #2031

Merged
opsiff merged 2 commits into
deepin-community:linux-6.6.yfrom
opsiff:linux-6.6.y-2026-07-30-fixes
Jul 30, 2026

Conversation

@opsiff

@opsiff opsiff commented Jul 30, 2026

Copy link
Copy Markdown
Member

x86/mce/zhaoxin: Fix bus number shift in ZDI error reporting
x86/microcode/zhaoxin: Fix NULL check for the P4D page allocation

Summary by Sourcery

Fix Zhaoxin-specific x86 error handling and microcode page allocation issues.

Bug Fixes:

  • Correct the bit shift used when encoding the bus number in ZDI machine check error reporting.
  • Fix the NULL pointer check after allocating the P4D microcode page when 5-level paging is enabled.

opsiff added 2 commits July 30, 2026 23:13
init_microcode_pages() allocates the P4D page into microcode_p4d_page
but then checks microcode_pud_page for allocation failure. When the P4D
page allocation fails, the NULL dereference is not caught and the
subsequent error path is never taken.

Check microcode_p4d_page instead.

Fixes: 75c8905 ("x86/microcode: Add Zhaoxin cpu microcode update driver")
Reported-by: WangYuli <wangyl5933@chinaunicom.cn>
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
zx_apei_mce_report_zdi_error() encodes the bus number (bits 8-15 of
requestor_id) into bits 24-31 of mce.misc, but shifts it right by 24
instead of left. As a result the bus number is always reported as 0.

Fix the shift direction so the bus number lands in the correct position.

Fixes: 743ad5c ("x86/mce/zhaoxin: Enable mcelog to decode PCIE, ZDI/ZPI, and DRAM errors")
Reported-by: WangYuli <wangyl5933@chinaunicom.cn>
Acked-by: leoliu-oc <leoliu-oc@zhaoxin.com>
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
@sourcery-ai

sourcery-ai Bot commented Jul 30, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Fixes two Zhaoxin x86 issues: corrects the bit shift used for encoding the bus number in ZDI error reporting, and fixes a NULL pointer check after allocating the P4D page for microcode page tables.

Flow diagram for init_microcode_pages P4D allocation and NULL check

flowchart TD
  A[init_microcode_pages] --> B[pgtable_l5_enabled]
  B -->|false| G[continue without P4D]
  B -->|true| C[microcode_p4d_page = __get_free_page]
  C --> D{microcode_p4d_page is NULL}
  D -->|true| E[pr_err Failed to allocate P4D page]
  E --> F[goto fail_pud]
  D -->|false| H[proceed with microcode P4D setup]
Loading

File-Level Changes

Change Details Files
Correct bus number bit placement in ZDI machine-check error reporting for Zhaoxin CPUs.
  • Adjust the bit shift direction when encoding the high byte of requestor_id into the m.misc field.
  • Ensure the upper bus bits are left-shifted into the correct high-order bits rather than being right-shifted out of range.
arch/x86/kernel/cpu/mce/apei.c
Fix incorrect NULL check after P4D page allocation in Zhaoxin microcode initialization.
  • Update the post-allocation NULL check to validate microcode_p4d_page instead of microcode_pud_page.
  • Keep failure handling and logging paths the same, only correcting which pointer is checked.
arch/x86/kernel/cpu/microcode/zhaoxin.c

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

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from opsiff. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • In zx_apei_mce_report_zdi_error, consider replacing the hard-coded bit positions (19 and 24) with named constants or macros that document the layout of the misc field for ZDI errors, making future maintenance less error-prone.
  • In init_microcode_pages, the error path label fail_pud is now used for a P4D allocation failure as well; renaming or restructuring the labels to more clearly reflect the failing allocation step would improve readability of the error handling.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `zx_apei_mce_report_zdi_error`, consider replacing the hard-coded bit positions (19 and 24) with named constants or macros that document the layout of the `misc` field for ZDI errors, making future maintenance less error-prone.
- In `init_microcode_pages`, the error path label `fail_pud` is now used for a P4D allocation failure as well; renaming or restructuring the labels to more clearly reflect the failing allocation step would improve readability of the error handling.

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Fixes two Zhaoxin-specific x86 issues: one in early microcode page-table setup when 5-level paging is enabled, and one in ZDI machine-check error encoding for APEI reporting.

Changes:

  • Correct the NULL check to validate the newly allocated P4D page (instead of mistakenly checking the PUD page).
  • Fix bus number encoding by shifting the extracted requestor bus byte into the correct bit position in m.misc.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
arch/x86/kernel/cpu/microcode/zhaoxin.c Fixes incorrect NULL check after allocating the P4D page during microcode identity-mapping setup under 5-level paging.
arch/x86/kernel/cpu/mce/apei.c Corrects the bit shift used to pack the requestor bus number into the MCE misc field for ZDI error reporting.

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

@opsiff
opsiff merged commit aea8885 into deepin-community:linux-6.6.y Jul 30, 2026
14 of 16 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