Skip to content

[Deepin-Kernel-SIG] [linux 6.6.y] [Upstream] Sync LoongArch KVM bugfixes from upstream - #2112

Merged
opsiff merged 4 commits into
deepin-community:linux-6.6.yfrom
opsiff:linux-6.6.y-2026-08-29
Aug 28, 2026
Merged

[Deepin-Kernel-SIG] [linux 6.6.y] [Upstream] Sync LoongArch KVM bugfixes from upstream#2112
opsiff merged 4 commits into
deepin-community:linux-6.6.yfrom
opsiff:linux-6.6.y-2026-08-29

Conversation

@opsiff

@opsiff opsiff commented Aug 28, 2026

Copy link
Copy Markdown
Member

Summary by Sourcery

Bug Fixes:

  • Fix LoongArch KVM CSR exchange results, userspace write error handling, FPU register copying, and interrupt vector validation.

bibo-mao and others added 4 commits August 29, 2026 00:01
Function kvm_vcpu_ioctl_interrupt() can be called from userspace, here
add irq validility cheking in kvm_vcpu_ioctl_interrupt().

Cc: [email protected]
Fixes: f45ad5b ("LoongArch: KVM: Implement vcpu interrupt operations")
Signed-off-by: Bibo Mao <[email protected]>
Signed-off-by: Huacai Chen <[email protected]>
(cherry picked from commit 09b318a)
Signed-off-by: Wentao Guan <[email protected]>
At the beginning, only 64 bit FPU is supported. With FPU register get
interface, 64 bit FPU data is copied to user space, the same with FPU
register set API. However with LSX and LASX supported in later, there
should be FPU data copied with bigger width. So here fixes this issue,
copy the whole 256 bit FPU data from/to user space.

Cc: [email protected]
Fixes: db1ecca ("LoongArch: KVM: Add LSX (128bit SIMD) support")
Signed-off-by: Bibo Mao <[email protected]>
Signed-off-by: Huacai Chen <[email protected]>
(cherry picked from commit f4caaac)
Signed-off-by: Wentao Guan <[email protected]>
The LoongArch CSRXCHG instruction returns the full old CSR value in rd
after applying the masked update. kvm_emu_xchg_csr() currently masks
the saved value before returning it to the guest, so rd receives only
the bits selected by the write mask.

That breaks the architectural behavior and makes a zero mask return 0
instead of the previous CSR value. So, keep the masked CSR update, but
return the unmodified old CSR value.

Cc: [email protected]
Fixes: da50f5a ("LoongArch: KVM: Implement handle csr exception")
Reviewed-by: Bibo Mao <[email protected]>
Signed-off-by: Qiang Ma <[email protected]>
Signed-off-by: Huacai Chen <[email protected]>
(cherry picked from commit ebd50de)
Signed-off-by: Wentao Guan <[email protected]>
put_user() may return -EFAULT, so, when the user space address is
invalid, the caller should return -EFAULT.

Cc: [email protected]
Reviewed-by: Bibo Mao <[email protected]>
Signed-off-by: Qiang Ma <[email protected]>
Signed-off-by: Huacai Chen <[email protected]>
(cherry picked from commit fb89e0f)
Signed-off-by: Wentao Guan <[email protected]>
@sourcery-ai

sourcery-ai Bot commented Aug 28, 2026

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

Reviewer's Guide

Syncs LoongArch KVM upstream fixes by correcting software CSR exchange results, handling userspace and FPU data transfers safely, and validating interrupt vectors before injection.

Sequence diagram for validated LoongArch KVM interrupt injection

sequenceDiagram
    participant Userspace
    participant KVM
    participant VCPU

    Userspace->>KVM: kvm_vcpu_ioctl_interrupt
    KVM->>KVM: abs
    alt vector >= EXCCODE_INT_NUM
        KVM-->>Userspace: -EINVAL
    else valid vector
        KVM->>VCPU: kvm_queue_irq
        KVM-->>Userspace: success
    end
Loading

Sequence diagram for safe LoongArch KVM userspace data transfer

sequenceDiagram
    participant Userspace
    participant KVM

    Userspace->>KVM: kvm_loongarch_cpucfg_get_attr
    KVM->>Userspace: put_user
    alt put_user fails
        KVM-->>Userspace: -EFAULT
    else put_user succeeds
        KVM-->>Userspace: result
    end

    Userspace->>KVM: kvm_arch_vcpu_ioctl_get_fpu
    KVM->>KVM: memcpy sizeof(union fpureg)
    KVM-->>Userspace: FPU state

    Userspace->>KVM: kvm_arch_vcpu_ioctl_set_fpu
    KVM->>KVM: memcpy sizeof(union fpureg)
    KVM-->>Userspace: success
Loading

File-Level Changes

Change Details Files
Correct CSR exchange return semantics for software-backed CSRs.
  • Preserve the complete pre-update CSR value instead of masking the returned old value.
arch/loongarch/kvm/exit.c
Improve error handling and data-width correctness in VCPU ioctls.
  • Propagate userspace write failures as -EFAULT.
  • Copy FPU registers using the full union fpureg size.
arch/loongarch/kvm/vcpu.c
Validate injected interrupt vectors before queuing them.
  • Reject interrupt values whose absolute vector is outside the supported exception-code range with -EINVAL.
arch/loongarch/kvm/vcpu.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 ✨
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

Backports four upstream LoongArch KVM correctness fixes.

Changes:

  • Correct CSR exchange return values.
  • Propagate userspace write failures and copy full 256-bit FPU registers.
  • Reject invalid interrupt vectors.

Reviewed changes

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

File Description
arch/loongarch/kvm/exit.c Returns the complete previous CSR value.
arch/loongarch/kvm/vcpu.c Fixes CPUCFG, FPU, and interrupt handling.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@opsiff
opsiff merged commit 0a93a0b into deepin-community:linux-6.6.y Aug 28, 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.

5 participants