Skip to content

Conversation

@myslqyr
Copy link

@myslqyr myslqyr commented Aug 19, 2025

The Struct_op operation allocates a single memory page to store target platform binary code.On x86, where instruction lengths are shorter, one page is sufficient. However, on ARM architectures, longer instructions require more memory space, causing the single page allocation to overflow.

To resolve this, the memory allocation has been
increased to two pages, ensuring stable operation
of the fuse_daemon.

Summary by Sourcery

Increase the executable image buffer for BPF struct operations from one page to two pages to prevent overflows on architectures with longer instructions (e.g., ARM).

Bug Fixes:

  • Prevent segmentation faults when running fuse-bpf on ARM by expanding the code buffer size for struct_ops.

Enhancements:

  • Introduce ST_IMAGE_SIZE constant (PAGE_SIZE * 2) for consistent two-page allocations.
  • Allocate two pages for the JIT-compiled image and adjust image_end accordingly.
  • Update all set_memory_* calls to operate on two pages instead of one.

The Struct_op operation allocates a single memory page
to store target platform binary code.On x86, where
instruction lengths are shorter, one page is sufficient.
However, on ARM architectures, longer instructions
require more memory space, causing the single page
allocation to overflow.

To resolve this, the memory allocation has been
increased to two pages, ensuring stable operation
of the fuse_daemon.

Signed-off-by: myslqyr <[email protected]>
@sourcery-ai
Copy link

sourcery-ai bot commented Aug 19, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This patch defines a new ST_IMAGE_SIZE macro (2× PAGE_SIZE) and replaces hard-coded PAGE_SIZE values in buffer allocation, boundary checks, and memory protection calls to double the executable buffer for BPF struct operations, preventing overflows on architectures with larger instruction encodings.

Class diagram for updated bpf_struct_ops_map structure and related functions

classDiagram
    class bpf_struct_ops_map {
        +void *image
        +void *uvalue
        +struct bpf_links **links
    }
    class bpf_struct_ops_map_alloc {
        +bpf_struct_ops_map_alloc(union bpf_attr *attr)
    }
    class bpf_struct_ops_map_update_elem {
        +bpf_struct_ops_map_update_elem(struct bpf_map *map, void *key, void *value, u64 flags)
    }
    bpf_struct_ops_map_alloc --> bpf_struct_ops_map : allocates
    bpf_struct_ops_map_update_elem --> bpf_struct_ops_map : updates
    bpf_struct_ops_map : image field now allocated with ST_IMAGE_SIZE (2 * PAGE_SIZE)
Loading

File-Level Changes

Change Details Files
Introduce ST_IMAGE_SIZE and replace PAGE_SIZE usage to double buffer size
  • Add #define ST_IMAGE_SIZE (PAGE_SIZE * 2)
  • Use ST_IMAGE_SIZE instead of PAGE_SIZE in bpf_jit_alloc_exec()
  • Update image_end calculation to ST_IMAGE_SIZE
  • Adjust all set_memory_{rox,nx,rw} calls to use ST_IMAGE_SIZE / PAGE_SIZE
kernel/bpf/bpf_struct_ops.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

Hi @myslqyr. Thanks for your PR. 😃

@deepin-ci-robot
Copy link

Hi @myslqyr. Thanks for your PR.

I'm waiting for a deepin-community member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@deepin-ci-robot
Copy link

[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 assign avenger-285714 for approval. For more information see the Code Review Process.

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants