Skip to content

[Deepin-Kernel-SIG] [linux 6.6.y] [Upstream] KVM: x86/mmu: Check write tracking in all address spaces - #2136

Merged
opsiff merged 1 commit into
deepin-community:linux-6.6.yfrom
opsiff:linux-6.6.y-2026-09-10-stable
Sep 11, 2026
Merged

[Deepin-Kernel-SIG] [linux 6.6.y] [Upstream] KVM: x86/mmu: Check write tracking in all address spaces#2136
opsiff merged 1 commit into
deepin-community:linux-6.6.yfrom
opsiff:linux-6.6.y-2026-09-10-stable

Conversation

@opsiff

@opsiff opsiff commented Sep 10, 2026

Copy link
Copy Markdown
Member

stable 6.6.156 #2120

use mainline version.

kvm_gfn_is_write_tracked() checks only the supplied memslot, but page tracking is per-address-space and shadow pages are shared across all address spaces. With SMM, a GFN can therefore be write-tracked in one address space and appear untracked through the other.

Check the supplied slot first, then the slot for the other address space. This ensures all callers honor write tracking regardless of the active address space. In particular, it prevents mmu_try_to_unsync_pages() from marking an upper-level shadow page unsync and eventually triggering the BUG in pte_list_remove().

Fixes: 699023e ("KVM: x86: add SMM to the MMU role, support SMRAM address space")
Assisted-by: Codex:GPT-5

Message-ID: 20260721103512.2136240-2-kimjw04271234@gmail.com
[invert direction of the conditional. - Paolo]

(cherry picked from commit 0f38453)

Summary by Sourcery

Fix KVM x86 write-tracking checks so shared shadow pages honor tracking state across address spaces.

Bug Fixes:

  • Ensure KVM x86 write tracking is recognized across all address spaces, preventing incorrect shadow-page synchronization and potential MMU crashes when using SMM.

Enhancements:

  • Refactor write-tracking checks to evaluate both the supplied memory slot and its corresponding slot in the alternate address space.

kvm_gfn_is_write_tracked() checks only the supplied memslot, but page
tracking is per-address-space and shadow pages are shared across all
address spaces.  With SMM, a GFN can therefore be write-tracked in one
address space and appear untracked through the other.

Check the supplied slot first, then the slot for the other address space.
This ensures all callers honor write tracking regardless of the active
address space.  In particular, it prevents mmu_try_to_unsync_pages() from
marking an upper-level shadow page unsync and eventually triggering the
BUG in pte_list_remove().

Fixes: 699023e ("KVM: x86: add SMM to the MMU role, support SMRAM address space")
Assisted-by: Codex:GPT-5
Signed-off-by: Jinu Kim <kimjw04271234@gmail.com>
Message-ID: <20260721103512.2136240-2-kimjw04271234@gmail.com>
[invert direction of the conditional. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

(cherry picked from commit 0f38453)
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
@sourcery-ai

sourcery-ai Bot commented Sep 10, 2026

Copy link
Copy Markdown

Reviewer's Guide

Updates KVM x86 write-tracking detection to search both address spaces, preventing SMM-related mismatches where shared shadow pages could be treated as untracked and later trigger pte_list_remove() failures.

Flow diagram for KVM write-tracking lookup across address spaces

flowchart TD
    A[kvm_gfn_is_write_tracked] --> B{Write tracking enabled?}
    B -- No --> C[Return false]
    B -- Yes --> D[Check supplied memslot]
    D -- Tracked --> E[Return true]
    D -- Untracked --> F{Second address space exists?}
    F -- No --> G[Return false]
    F -- Yes --> H[Find other address-space memslot]
    H --> I[Check other memslot]
    I -- Tracked --> E
    I -- Untracked --> G
Loading

File-Level Changes

Change Details Files
Make write-tracking checks account for both KVM address spaces while preserving the existing fast path for the supplied slot.
  • Extract per-slot write-tracking lookup into a null-safe helper.
  • Check the supplied memory slot first, then resolve and check the corresponding slot in the alternate address space.
  • Add a build-time constraint for the two-address-space XOR lookup and retain early exits when tracking is disabled or no slot is supplied.
arch/x86/kvm/mmu/page_track.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 reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@opsiff
opsiff merged commit 6302163 into deepin-community:linux-6.6.y Sep 11, 2026
13 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