Skip to content

fix(kernelmod): page-align ring buffer allocation for non-4K page kernels - #255

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/eagle-1070from
wangrong1069:pr0901
Sep 2, 2026
Merged

deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/eagle-1070from
wangrong1069:pr0901

Conversation

@wangrong1069

@wangrong1069 wangrong1069 commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

vzalloc rounds up to whole pages, but mem_size recorded the raw header+data total. On 16 KiB/64 KiB page kernels the consumer's page-aligned mmap was larger than mem_size and got rejected.

将 ring buffer 分配大小在 vzalloc 前显式按页对齐,使分配请求、
记录的 mem_size 与用户态 mmap 映射大小保持一致,修复非 4K 页
内核上 mmap 报 "size > mem_size" 导致模块不可用的问题。

Log: 修复非4K页内核上mmap大小检查失败
PMS: BUG-374927
Influence: 修复在 Loongson 等非4K页内核上 vfs_monitor 模块 mmap 失败导致服务不可用的问题。

Summary by Sourcery

Bug Fixes:

  • Fix ring-buffer mmap failures on kernels with non-4 KiB page sizes by keeping the allocated and reported memory size page-aligned.

@sourcery-ai

sourcery-ai Bot commented Sep 1, 2026

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

Reviewer's Guide

Fix ring-buffer mmap failures on kernels with non-4K pages by aligning the allocated and recorded buffer size to PAGE_SIZE, keeping it consistent with the page-aligned userspace mapping.

Sequence diagram for page-aligned ring buffer mmap

sequenceDiagram
    participant Init as vfs_ring_init
    participant Kernel as Kernel memory allocator
    participant User as Userspace consumer

    Init->>Init: PAGE_ALIGN(header_size + data_size)
    Init->>Kernel: vzalloc(alloc_size)
    Kernel-->>Init: ring->mem
    Init->>Init: ring->mem_size = alloc_size
    User->>Init: mmap(page-aligned size)
    Init-->>User: mapping accepted when size <= mem_size
Loading

File-Level Changes

Change Details Files
Page-align the ring buffer allocation and recorded size before virtual allocation so kernel and userspace mapping sizes remain consistent.
  • Compute PAGE_ALIGN(header_size + data_size) as the allocation size.
  • Pass the aligned size to vzalloc and store it in mem_size.
  • Update allocation-failure logging to report the aligned size.
src/kernelmod/vfs_chrdev.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

…nels

vzalloc rounds up to whole pages, but mem_size recorded the raw
header+data total. On 16 KiB/64 KiB page kernels the consumer's
page-aligned mmap was larger than mem_size and got rejected.

将 ring buffer 分配大小在 vzalloc 前显式按页对齐,使分配请求、
记录的 mem_size 与用户态 mmap 映射大小保持一致,修复非 4K 页
内核上 mmap 报 "size > mem_size" 导致模块不可用的问题。

Log: 修复非4K页内核上mmap大小检查失败
PMS: BUG-374927
Influence: 修复在 Loongson 等非4K页内核上 vfs_monitor 模块 mmap 失败导致服务不可用的问题。

@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.

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: max-lvs, wangrong1069

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

@wangrong1069

Copy link
Copy Markdown
Contributor Author

/merge

@deepin-bot
deepin-bot Bot merged commit 0ef5e11 into linuxdeepin:develop/eagle-1070 Sep 2, 2026
17 checks passed
@wangrong1069
wangrong1069 deleted the pr0901 branch September 2, 2026 01:28
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