Skip to content

[PWCI] "dpdk: Update dpdk-lcore-mask handling."#11

Open
ovsrobot wants to merge 3 commits intomainfrom
series_472733
Open

[PWCI] "dpdk: Update dpdk-lcore-mask handling."#11
ovsrobot wants to merge 3 commits intomainfrom
series_472733

Conversation

@ovsrobot
Copy link
Owner

@ovsrobot ovsrobot commented Sep 8, 2025

Auto-submission for "http://patchwork.ozlabs.org/project/openvswitch/list/?series=472733"

Summary by Sourcery

Introduce a core-mask conversion utility and integrate it into DPDK startup options, replacing the old dpdk-lcore-mask handling and improving parameter conversion and validation.

Enhancements:

  • Add cmask_to_lcore_list helper to generate sorted DPDK lcore list strings from hexadecimal core masks
  • Refactor construct_dpdk_options to support generic param_conversion callbacks and apply it to dpdk-lcore-mask
  • Add warning and skip logic for invalid dpdk-lcore-mask values

Documentation:

  • Update vswitchd/vswitch.xml documentation to explain dpdk-lcore-mask thread assignment and default behavior

Add some more details about dpdk-lcore-mask and remove
the recommendation to use it.

Signed-off-by: Kevin Traynor <ktraynor@redhat.com>
Signed-off-by: 0-day Robot <robot@bytheb.org>
Default values are not used here, so remove the option for them.

Suggested-by: David Marchand <david.marchand@redhat.com>
Signed-off-by: Kevin Traynor <ktraynor@redhat.com>
Signed-off-by: 0-day Robot <robot@bytheb.org>
OVS currently uses other_config:dpdk-lcore-mask <coremask> directly
in DPDK rte_eal_init() with '-c <coremask>' argument.

'-c' argument is now deprecated from DPDK and will be removed in
DPDK 25.11, so OVS will no longer be able to use the '-c <coremask>'
argument.

Convert dpdk-lcore-mask core mask to a core list that can be used with
'--lcores' and add some tests.

The core list is validated to prevent invalid cores being passed to
DPDK rte_eal_init().

Using the '--lcores' argument also adds compability for using a core
in the core mask that is greater than the max lcore, similar to commit
fe53b47 ("dpdk: Fix main lcore on systems with many cores.")

Signed-off-by: Kevin Traynor <ktraynor@redhat.com>
Signed-off-by: 0-day Robot <robot@bytheb.org>
@coderabbitai
Copy link

coderabbitai bot commented Sep 8, 2025

Caution

Review failed

An error occurred during the review process. Please try again later.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch series_472733

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sourcery-ai
Copy link

sourcery-ai bot commented Sep 8, 2025

Reviewer's Guide

This PR enhances dpdk-lcore-mask support by introducing a conversion helper that translates a hex core mask into a sorted DPDK lcore list, refactors the options mapping to use a generic conversion callback for parameters, and updates documentation and tests to reflect the new behavior.

Class diagram for updated DPDK options mapping and core mask conversion

classDiagram
    class dpdk_options_map {
        +const char *ovs_configuration
        +const char *dpdk_option
        +char *(*param_conversion)(const char *)
    }
    class cmask_to_lcore_list {
        +char *cmask_to_lcore_list(const char *cmask)
    }
    dpdk_options_map --> cmask_to_lcore_list : uses param_conversion
    class construct_dpdk_options {
        +void construct_dpdk_options(const struct smap *, struct svec *)
    }
    construct_dpdk_options --> dpdk_options_map : iterates opts[]
    construct_dpdk_options --> cmask_to_lcore_list : calls for conversion
    class compare_core_ids {
        +int compare_core_ids(const void *, const void *)
    }
    cmask_to_lcore_list --> compare_core_ids : uses for sorting
    class ovs_numa_dump_cores_with_cmask {
        +struct ovs_numa_dump *ovs_numa_dump_cores_with_cmask(const char *)
    }
    cmask_to_lcore_list --> ovs_numa_dump_cores_with_cmask : gets core dump
    class ovs_numa_dump_count {
        +unsigned int ovs_numa_dump_count(struct ovs_numa_dump *)
    }
    cmask_to_lcore_list --> ovs_numa_dump_count : gets core count
    class ovs_numa_dump_destroy {
        +void ovs_numa_dump_destroy(struct ovs_numa_dump *)
    }
    cmask_to_lcore_list --> ovs_numa_dump_destroy : cleans up
    class svec {
        +void svec_add(struct svec *, const char *)
    }
    construct_dpdk_options --> svec : adds options
Loading

Flow diagram for hex core mask to DPDK lcore list conversion

flowchart TD
    A["Input: Hexadecimal core mask"] --> B["ovs_numa_dump_cores_with_cmask(cmask)"]
    B --> C["ovs_numa_dump_count(lcore_dump)"]
    C --> D["Extract core IDs from dump"]
    D --> E["Sort core IDs (compare_core_ids)"]
    E --> F["Limit to RTE_MAX_LCORE if needed"]
    F --> G["Format as DPDK lcore list string"]
    G --> H["Output: lcore list string"]
Loading

File-Level Changes

Change Details Files
Introduce core‐mask to lcore‐list conversion
  • Add compare_core_ids for sorting core IDs
  • Implement cmask_to_lcore_list using ovs_numa_dump and qsort
  • Build comma-separated lcores string and handle RTE_MAX_LCORE limit
lib/dpdk.c
Refactor DPDK options mapping to support parameter conversion
  • Remove default_enabled/default_value fields
  • Add param_conversion callback to options map
  • Invoke conversion, warn on invalid value, add/ free converted string
lib/dpdk.c
Update dpdk-lcore-mask documentation
  • Clarify assignment of main and worker threads
  • Describe auto-determination and threading behavior
  • Adjust text on default behavior and threading model
vswitchd/vswitch.xml
Adjust test suite for updated lcore-mask handling
  • Update or add tests to verify cmask_to_lcore_list output
  • Refactor macros and system tests to exercise new parameter conversion
tests/pmd.at
tests/system-dpdk-macros.at
tests/system-dpdk.at
tests/testsuite.at

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

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `lib/dpdk.c:90` </location>
<code_context>
+    lcore_dump = ovs_numa_dump_cores_with_cmask(cmask);
+
+    num_cores = ovs_numa_dump_count(lcore_dump);
+    core_ids = xmalloc(num_cores * sizeof *core_ids);
+
+    FOR_EACH_CORE_ON_DUMP(core, lcore_dump) {
</code_context>

<issue_to_address>
Potential allocation of zero bytes if num_cores is zero.

Check if num_cores is zero before allocating memory, and return NULL early to prevent unsafe zero-byte allocation.
</issue_to_address>

### Comment 2
<location> `lib/dpdk.c:113` </location>
<code_context>
+        free(lcores);
+        lcores = new_lcores;
+    }
+    if (lcores) {
+        lcores[strlen(lcores) - 1] = '\0';
+    }
+
</code_context>

<issue_to_address>
Manual removal of trailing comma may be error-prone.

Setting the last character to '\0' without verifying the string length can cause undefined behavior if lcores is empty. Please add a length check before modifying the string.
</issue_to_address>

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.

lcore_dump = ovs_numa_dump_cores_with_cmask(cmask);

num_cores = ovs_numa_dump_count(lcore_dump);
core_ids = xmalloc(num_cores * sizeof *core_ids);
Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): Potential allocation of zero bytes if num_cores is zero.

Check if num_cores is zero before allocating memory, and return NULL early to prevent unsafe zero-byte allocation.

Comment on lines +113 to +114
if (lcores) {
lcores[strlen(lcores) - 1] = '\0';
Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): Manual removal of trailing comma may be error-prone.

Setting the last character to '\0' without verifying the string length can cause undefined behavior if lcores is empty. Please add a length check before modifying the string.

ovsrobot pushed a commit that referenced this pull request Sep 19, 2025
When vport_add_channel() is called duplicate, the resources for previously
specified sock was not freed. This patch fixes this issue.

Reported by Address Sanitizer.

Direct leak of 60 byte(s) in 3 object(s) allocated from:
    #0 0xffffb3658080 in malloc (/usr/lib64/libasan.so.6+0xa9080)
    #1 0x922630 in xmalloc__ lib/util.c:141
    #2 0x922718 in xmalloc lib/util.c:176
    #3 0x9c67e4 in nl_sock_create lib/netlink-socket.c:147
    #4 0x94cb6c in create_nl_sock lib/dpif-netlink.c:283
    #5 0x950bec in dpif_netlink_port_add__ lib/dpif-netlink.c:978
    #6 0x951a20 in dpif_netlink_port_add_compat lib/dpif-netlink.c:1101
    #7 0x951cd0 in dpif_netlink_port_add lib/dpif-netlink.c:1147
    #8 0x616354 in dpif_port_add lib/dpif.c:602
    #9 0x49f424 in port_add ofproto/ofproto-dpif.c:4144
    #10 0x44d51c in ofproto_port_add ofproto/ofproto.c:2204
    #11 0x416914 in iface_do_create vswitchd/bridge.c:2203
    #12 0x416dbc in iface_create vswitchd/bridge.c:2246
    #13 0x40e1d0 in bridge_add_ports__ vswitchd/bridge.c:1225
    #14 0x40e290 in bridge_add_ports vswitchd/bridge.c:1241
    #15 0x40cc6c in bridge_reconfigure vswitchd/bridge.c:952
    #16 0x420884 in bridge_run vswitchd/bridge.c:3440
    #17 0x42f3d0 in main vswitchd/ovs-vswitchd.c:137

Fixes: 69c5158 ("dpif-netlink: don't allocate per thread netlink sockets")
Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
Signed-off-by: 0-day Robot <robot@bytheb.org>
ovsrobot pushed a commit that referenced this pull request Oct 9, 2025
When vport_add_channel() is called duplicate, the resources for previously
specified sock was not freed. This patch fixes this issue.

Reported by Address Sanitizer.

Direct leak of 60 byte(s) in 3 object(s) allocated from:
    #0 0xffffb3658080 in malloc (/usr/lib64/libasan.so.6+0xa9080)
    #1 0x922630 in xmalloc__ lib/util.c:141
    #2 0x922718 in xmalloc lib/util.c:176
    #3 0x9c67e4 in nl_sock_create lib/netlink-socket.c:147
    #4 0x94cb6c in create_nl_sock lib/dpif-netlink.c:283
    #5 0x950bec in dpif_netlink_port_add__ lib/dpif-netlink.c:978
    #6 0x951a20 in dpif_netlink_port_add_compat lib/dpif-netlink.c:1101
    #7 0x951cd0 in dpif_netlink_port_add lib/dpif-netlink.c:1147
    #8 0x616354 in dpif_port_add lib/dpif.c:602
    #9 0x49f424 in port_add ofproto/ofproto-dpif.c:4144
    #10 0x44d51c in ofproto_port_add ofproto/ofproto.c:2204
    #11 0x416914 in iface_do_create vswitchd/bridge.c:2203
    #12 0x416dbc in iface_create vswitchd/bridge.c:2246
    #13 0x40e1d0 in bridge_add_ports__ vswitchd/bridge.c:1225
    #14 0x40e290 in bridge_add_ports vswitchd/bridge.c:1241
    #15 0x40cc6c in bridge_reconfigure vswitchd/bridge.c:952
    #16 0x420884 in bridge_run vswitchd/bridge.c:3440
    #17 0x42f3d0 in main vswitchd/ovs-vswitchd.c:137

Reproduce steps:
    ovs-vsctl add-br br-ovs
    ovs-vsctl add-port br-ovs test -- set interface test type=internal
    ip netns add ns_test
    ip link set test netns ns_test
    ip netns del ns_test
    ifconfig br-ovs up
    sleep 1
    ifconfig br-ovs down
    sleep 1
    ovs-vsctl del-br br-ovs

Fixes: 69c5158 ("dpif-netlink: don't allocate per thread netlink sockets")
Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
Signed-off-by: 0-day Robot <robot@bytheb.org>
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.

2 participants