[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
Conversation
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>
Reviewer's guide (collapsed on small PRs)Reviewer's GuideFixes 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 checkflowchart 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]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
There was a problem hiding this comment.
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 themiscfield for ZDI errors, making future maintenance less error-prone. - In
init_microcode_pages, the error path labelfail_pudis 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.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
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.
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: