Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport upstream patch to fix downstream patch collision in RPi 6.6 kernel #3856

Merged
merged 1 commit into from
Feb 4, 2025

Conversation

sairon
Copy link
Member

@sairon sairon commented Feb 4, 2025

Because of refactoring/code quality improvements in upstream, IPv6 reachability patch no longer applied on 6.12 kernel. We added two versions of the patch to address this initially, however, this requires updating of the patch directory name on every kernel bump. Backport the patch causing collision instead to RPi kernel, so we can carry only one version of the patch.

This also requires swapping of the patching order - now we first apply board-specific patches, then the global ones. Unless there are collisions, these operations should be idempontent, so at this point it shouldn't have any side-effects.

Summary by CodeRabbit

  • New Features
    • Introduced an option for IPv6 reachability probing, allowing more flexible routing configurations.
  • Bug Fixes
    • Improved IPv6 forwarding stability by enhancing concurrency handling to prevent data access conflicts.
  • Chores
    • Standardized Raspberry Pi board configurations by reordering patch application priorities for a more consistent build process.

…kernel

Because of refactoring/code quality improvements in upstream, IPv6 reachability
patch no longer applied on 6.12 kernel. We added two versions of the patch to
address this initially, however, this requires updating of the patch directory
name on every kernel bump. Backport the patch causing collision instead to RPi
kernel, so we can carry only one version of the patch.

This also requires swapping of the patching order - now we first apply
board-specific patches, then the global ones. Unless there are collisions,
these operations should be idempontent, so at this point it shouldn't have any
side-effects.
@sairon sairon added board/raspberrypi Raspberry Pi Boards linux Linux kernel related issue labels Feb 4, 2025
@sairon sairon requested a review from agners February 4, 2025 11:30
Copy link

coderabbitai bot commented Feb 4, 2025

📝 Walkthrough

Walkthrough

The changes introduce a new compile‐time IPv6 reachability probing option by adding the configuration variable IPV6_REACHABILITY_PROBE and updating the routing logic in route.c to apply the RT6_LOOKUP_F_REACHABLE flag when either IPv6 forwarding is disabled or the probe is enabled. In parallel, annotations using READ_ONCE() and WRITE_ONCE() have been added to accesses of the cnf.forwarding field across several networking files, with an updated function signature in ipv6.h. Additionally, Buildroot defconfig files for various Raspberry Pi boards have been modified to reorder BR2_GLOBAL_PATCH_DIR entries so that board-specific patches are prioritized.

Changes

File(s) Change Summary
buildroot-external/board/raspberrypi/patches/linux/0004-ipv6-add-option-to-explicitly-enable-reachability-te.patch, .../net/ipv6/Kconfig, .../route.c Added the IPV6_REACHABILITY_PROBE configuration option and modified routing logic to apply the RT6_LOOKUP_F_REACHABLE flag when either IPv6 forwarding is off or reachability probing is enabled.
buildroot-external/board/raspberrypi/patches/linux/0004-ipv6-annotate-data-races-around-cnf.forwarding.patch, .../cdc_mbim.c, .../ipv6.h, .../filter.c, .../addrconf.c, .../ip6_output.c, .../ndisc.c, .../route.c Annotated accesses to cnf.forwarding with READ_ONCE()/WRITE_ONCE() to prevent data races; updated ipv6_accept_ra() in ipv6.h to accept a const pointer.
buildroot-external/configs/rpi*_defconfig Reordered BR2_GLOBAL_PATCH_DIR entries to prioritize board-specific patches (board/raspberrypi/patches) over general patches in Buildroot configuration files.

Sequence Diagram(s)

sequenceDiagram
    participant NP as Network Packet
    participant RL as Route Lookup
    participant CF as Config Checker
    NP->>RL: Receive IPv6 packet
    RL->>CF: Check IPv6 forwarding & IPV6_REACHABILITY_PROBE
    alt Forwarding disabled or probe enabled
        CF-->>RL: Condition met
        RL->>RL: Set RT6_LOOKUP_F_REACHABLE flag
    else
        CF-->>RL: Condition not met
    end
    RL->>NP: Continue with routing decision
Loading

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
buildroot-external/board/raspberrypi/patches/linux/0004-ipv6-annotate-data-races-around-cnf.forwarding.patch (1)

194-195: Mixed usage of READ_ONCE and direct field access.

While READ_ONCE(in6_dev->cnf.forwarding) is correct, consider whether in6_dev->cnf.accept_redirects needs a similar concurrency annotation if it can be updated in other threads. If so, switching to READ_ONCE(in6_dev->cnf.accept_redirects) could further reduce data race risks.

buildroot-external/configs/rpi3_defconfig (1)

9-9: LGTM! Patch directory order change is consistent.

The change follows the same pattern as other board configurations, ensuring board-specific patches take precedence.

This consistent reordering across all board configurations suggests a deliberate architectural decision to:

  1. Prioritize board-specific patches
  2. Allow global patches as fallback
  3. Maintain a clear hierarchy in patch application

This approach should make it easier to:

  • Override global patches with board-specific ones when needed
  • Maintain board-specific customizations without affecting other boards
  • Reduce patch collisions by having a clear precedence order
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b5b2f5d and 40d8944.

📒 Files selected for processing (8)
  • buildroot-external/board/raspberrypi/patches/linux/0004-ipv6-add-option-to-explicitly-enable-reachability-te.patch (0 hunks)
  • buildroot-external/board/raspberrypi/patches/linux/0004-ipv6-annotate-data-races-around-cnf.forwarding.patch (1 hunks)
  • buildroot-external/configs/rpi2_defconfig (1 hunks)
  • buildroot-external/configs/rpi3_64_defconfig (1 hunks)
  • buildroot-external/configs/rpi3_defconfig (1 hunks)
  • buildroot-external/configs/rpi4_64_defconfig (1 hunks)
  • buildroot-external/configs/rpi4_defconfig (1 hunks)
  • buildroot-external/configs/rpi5_64_defconfig (1 hunks)
💤 Files with no reviewable changes (1)
  • buildroot-external/board/raspberrypi/patches/linux/0004-ipv6-add-option-to-explicitly-enable-reachability-te.patch
✅ Files skipped from review due to trivial changes (1)
  • buildroot-external/configs/rpi4_defconfig
🔇 Additional comments (22)
buildroot-external/configs/rpi5_64_defconfig (1)

8-8: LGTM! The patch directory order change aligns with the PR objectives.

The modification to prioritize board-specific patches (board/raspberrypi/patches) before global patches is consistent across all RPi defconfigs. This change supports the PR's goal of fixing the patch collision by ensuring board-specific patches take precedence, while maintaining idempotency as mentioned in the PR objectives.

Run the following script to verify the patch application order:

Also applies to: 9-9, 9-9, 9-9

✅ Verification successful

Patch ordering and collision check verified

The board-specific patch directory is correctly prioritized, and our checks didn’t detect any patch collisions. This aligns with the PR objectives.

  • Verified the configuration in multiple defconfigs (rpi2, rpi3, rpi4, and rpi5).
  • Confirmed that the ordering keeps board-specific patches (board/raspberrypi/patches) ahead of global patches.
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that patches are applied in the correct order with board-specific patches taking precedence.

# Test: Check if there are any patches with the same name in both directories
echo "Checking for potential patch collisions..."
for config in $(fd -t f "rpi.*_defconfig" buildroot-external/configs/); do
  board_patches_dir=$(grep "BR2_GLOBAL_PATCH_DIR" "$config" | grep -o 'board/raspberrypi/patches')
  global_patches_dir=$(grep "BR2_GLOBAL_PATCH_DIR" "$config" | grep -o '/patches"' | tr -d '"')
  
  if [ -d "$board_patches_dir" ] && [ -d "$global_patches_dir" ]; then
    echo "Checking patches in $config..."
    for patch in "$global_patches_dir"/*; do
      if [ -f "$board_patches_dir/$(basename "$patch")" ]; then
        echo "Found potential collision: $(basename "$patch")"
        echo "- Board-specific: $board_patches_dir/$(basename "$patch")"
        echo "- Global: $patch"
      fi
    done
  fi
done

Length of output: 2587

buildroot-external/configs/rpi4_64_defconfig (1)

8-8: LGTM! The patch directory reordering aligns with the PR objectives.

The change prioritizes board-specific patches by placing them before global patches in BR2_GLOBAL_PATCH_DIR. This reordering helps resolve the patch collision issue mentioned in the PR objectives while maintaining an idempotent patch application process.

To ensure consistency across all RPi board configurations, run:

✅ Verification successful

Final Verification: Patch Directory Reordering Confirmed

All checked RPi board configuration files correctly list the board-specific patches before the global patches. No defconfig was found with the old (reversed) order. This verifies that the changes align with the PR objectives.

  • Verified in files: rpi2_defconfig, rpi3_defconfig, rpi3_64_defconfig, rpi4_defconfig, rpi4_64_defconfig, and rpi5_64_defconfig.
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that all RPi board configs have the same patch directory order

# Test: Check BR2_GLOBAL_PATCH_DIR in all RPi defconfigs
# Expect: All configs should have board patches before global patches
rg -l 'BR2_GLOBAL_PATCH_DIR.*board/raspberrypi/patches.*patches' buildroot-external/configs/rpi*_defconfig

# Test: Check for any RPi defconfigs with different order
# Expect: No matches (old order should be completely replaced)
rg -l 'BR2_GLOBAL_PATCH_DIR.*patches.*board/raspberrypi/patches' buildroot-external/configs/rpi*_defconfig

Length of output: 916

buildroot-external/board/raspberrypi/patches/linux/0004-ipv6-annotate-data-races-around-cnf.forwarding.patch (18)

1-5: Commit metadata looks good.

The commit message and metadata are consistent and clear, detailing the rationale for annotating data races around cnf.forwarding.


6-9: Good clarification of the concurrency rationale.

The note that idev->cnf.forwarding and net->ipv6.devconf_all->forwarding may be accessed locklessly is a helpful pointer for developers.


10-13: Sign-offs are proper.

No issues in the signing sequence; standard kernel practice.


14-21: File change summary is accurate.

The list of impacted files and net lines changed is correct, providing easy navigation for reviewers.


31-32: Correct use of READ_ONCE in cdc_mbim.c.

Switching to READ_ONCE(in6_dev->cnf.forwarding) is appropriate to protect against concurrent writes.


44-56: Const correctness and atomic reads in ipv6_accept_ra.

  1. Updating the function signature to const struct inet6_dev *idev is correct since the function body does not modify idev.
  2. Using READ_ONCE for both idev->cnf.accept_ra and idev->cnf.forwarding ensures data-race avoidance.

67-68: Consistent use of READ_ONCE in bpf_ipv6_fib_lookup.

Replacing the direct read with READ_ONCE(idev->cnf.forwarding) maintains concurrency safety.


79-83: Safe read for reporting devconf->forwarding.

Using READ_ONCE(devconf->forwarding) before calling nla_put_s32 prevents race conditions if forwarding changes mid-read.


89-93: WRITE_ONCE used correctly for idev->cnf.forwarding assignment.

Ensuring atomicity when changing the forwarding field is essential for concurrency correctness.


100-101: Pointer assignment wrapped with WRITE_ONCE.

Applying WRITE_ONCE(*p, newf) avoids potential data races on the pointer-based assignment.


109-110: Default forwarding assignment properly updated with WRITE_ONCE.

This enforces atomic writes on the devconf_dflt->forwarding field, matching the rest of the patch’s conventions.


122-123: Forwarding check now protected by READ_ONCE.

Ensuring consistent forward-check logic in ip6_output.c is aligned with the concurrency safeguards introduced here.


135-136: NDP code uses READ_ONCE correctly.

Preventing data races when determining if the device is forwarding packets addresses concurrency concerns in neighbor discovery logic.


145-145: Synchronous read when setting is_router.

Properly uses READ_ONCE(idev->cnf.forwarding) to keep the read coherent under parallel updates.


154-154: Router condition guarded by READ_ONCE.

Again, ensuring safe concurrent usage of forwarding in NA message processing.


163-164: Transition to READ_ONCE for checking devconf_all->forwarding.

Matches the rest of the patch’s approach to concurrency on forwarding.


173-174: Consistent concurrency check for RS acceptance.

READ_ONCE(idev->cnf.forwarding) ensures correctness for router solicitation handling.


185-186: Conditional forwarding check uses READ_ONCE.

Maintains concurrency guarantees for net->ipv6.devconf_all->forwarding.

buildroot-external/configs/rpi2_defconfig (1)

9-9: LGTM! Patch directory order change aligns with PR objectives.

The change prioritizes board-specific patches over global patches, which helps resolve the patch collision issue mentioned in the PR objectives.

Let's verify the patch directories exist and understand their contents:

✅ Verification successful

Below is an updated verification script that explicitly sets the environment variable (assuming that the repository’s base directory for external patches is "buildroot-external") before checking for the patch directories and listing their contents. This should help us verify that the board‐specific and global patch directories exist as expected.


Patch directory order verified:

  • The board-specific patch directory exists at buildroot-external/board/raspberrypi/patches.
  • The global patch directory exists at buildroot-external/patches.

Both directories were detected in the repository, and the board-specific directory is prioritized in the configuration as expected. This aligns with the PR objectives to resolve patch collisions.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify patch directories and their contents

# Check if both patch directories exist
echo "Checking patch directories..."
fd -t d -g "*patches" "$(BR2_EXTERNAL_HASSOS_PATH)"

# List patches in both directories
echo -e "\nListing patches in board-specific directory..."
fd -t f -e patch "$(BR2_EXTERNAL_HASSOS_PATH)/board/raspberrypi/patches"

echo -e "\nListing patches in global directory..."
fd -t f -e patch "$(BR2_EXTERNAL_HASSOS_PATH)/patches"

Length of output: 908


Script:

#!/bin/bash
# Set the BR2_EXTERNAL_HASSOS_PATH to simulate the external configuration environment.
export BR2_EXTERNAL_HASSOS_PATH="buildroot-external"
echo "Using BR2_EXTERNAL_HASSOS_PATH = ${BR2_EXTERNAL_HASSOS_PATH}"

echo "Checking for patch directories..."
fd -t d -g "*patches" "${BR2_EXTERNAL_HASSOS_PATH}" --color=never

echo -e "\nListing patches in board-specific directory..."
if [ -d "${BR2_EXTERNAL_HASSOS_PATH}/board/raspberrypi/patches" ]; then
    fd -t f -e patch "${BR2_EXTERNAL_HASSOS_PATH}/board/raspberrypi/patches" --color=never
else
    echo "Directory ${BR2_EXTERNAL_HASSOS_PATH}/board/raspberrypi/patches does not exist."
fi

echo -e "\nListing patches in global directory..."
if [ -d "${BR2_EXTERNAL_HASSOS_PATH}/patches" ]; then
    fd -t f -e patch "${BR2_EXTERNAL_HASSOS_PATH}/patches" --color=never
else
    echo "Directory ${BR2_EXTERNAL_HASSOS_PATH}/patches does not exist."
fi

Length of output: 2109

buildroot-external/configs/rpi3_64_defconfig (1)

8-8: LGTM! Consistent patch directory ordering.

The change maintains consistency with other board configurations by prioritizing board-specific patches.

@sairon sairon merged commit 47309b4 into dev Feb 4, 2025
3 checks passed
@sairon sairon deleted the ipv6-reorganize-patches branch February 4, 2025 12:13
sairon added a commit that referenced this pull request Feb 5, 2025
After #3856, we need to change the patch order also for Yellow.
sairon added a commit that referenced this pull request Feb 5, 2025
After #3856, we need to change the patch order also for Yellow.
@sairon sairon mentioned this pull request Mar 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
board/raspberrypi Raspberry Pi Boards cla-signed linux Linux kernel related issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants