Skip to content

Comments

Support vhost_vdpa devices#427

Open
bgartzi wants to merge 5 commits intok8snetworkplumbingwg:mainfrom
bgartzi:vhost_vdpa
Open

Support vhost_vdpa devices#427
bgartzi wants to merge 5 commits intok8snetworkplumbingwg:mainfrom
bgartzi:vhost_vdpa

Conversation

@bgartzi
Copy link

@bgartzi bgartzi commented Feb 2, 2026

This PR adds support for vhost_vdpa devices to ovs-cni.

Most of the steps needed to set up a vhost_vdpa device are similar to the ones of sriov devices. However, instead of setting the mac address to the VF that is moved into the pod namespace, it is the vdpa device that needs to be updated.

Setting a mac address to vdpa devices is supported from kernel 6.12 on.

If I understand correctly, there's no proper way to make IPAM work directly as the vdpa interface would be under the VM, not the host or the pod.

Support vhost-vdpa devices for clusters running on kernels newer than 6.12

@kubevirt-bot kubevirt-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. labels Feb 2, 2026
@kubevirt-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: bgartzi
Once this PR has been reviewed and has the lgtm label, please assign alonakaplan for approval. 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

@kubevirt-bot kubevirt-bot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Feb 2, 2026
@kubevirt-bot
Copy link
Collaborator

Hi @bgartzi. Thanks for your PR.

I'm waiting for a k8snetworkplumbingwg 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.

Details

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-sigs/prow repository.

We will need govdpa later to find pciaddr-vdpa relationships and setting
mac addresses to vdpa devices.

Signed-off-by: Beñat Gartzia Arruabarrena <bgartzia@redhat.com>
This is some logic that we might need to reuse in other use-cases such
as vdpa-vhost devices. Move the logic into a function so we're not
rewriting it.

Signed-off-by: Beñat Gartzia Arruabarrena <bgartzia@redhat.com>
Other device types such as vdpa-vhost need to move the VF into the
pod's network namespace. Make the function publicly available for those
cases to use.

Signed-off-by: Beñat Gartzia Arruabarrena <bgartzia@redhat.com>
As in previous commits, others might need to run similar steps, so make
it public to be reused.

Signed-off-by: Beñat Gartzia Arruabarrena <bgartzia@redhat.com>
This commit implements ovs-cni's support for vhost-vdpa attachments.
These devices are provisioned by the sriov-network-operator in switchdev
mode [0]. That means that the process to attach these devices to pods is
similar to the one followed for sriov devices that work on switchdev
mode: attach the representor to the target ovs bridge and move the VF
into the target pod's network namespace.

There is one little difference though: the mac address received through
the environment variables (if any) needs to be set onto the vdpa device,
not the VF. This is possible since vdpa dev set mac supported in kernels
6.12 and above.

This commit adds a skeleton for a vdpa subpackage, and wires everything
up to the CmdAdd command. Note that this only adds support for
kernel vhost-vdpa devices (those whose mgmtdev is a sriov VF), but that
in the future this could be extended to virtio-vdpa and vduse vdpa.

[0] https://github.com/k8snetworkplumbingwg/sriov-network-operator/blob/4d96f5c4d18ac4fbbdbbd0bde4b78383955ba285/doc/vdpa.md?plain=1#L13C1-L13C35

Signed-off-by: Beñat Gartzia Arruabarrena <bgartzia@redhat.com>
@kubevirt-bot kubevirt-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 2, 2026
@bgartzi
Copy link
Author

bgartzi commented Feb 2, 2026

Hi @SchSeba, could you have a look into this patch?
Thanks a lot!

@gemini-code-assist
Copy link

Summary of Changes

Hello @bgartzi, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request extends ovs-cni's capabilities by integrating support for vhost-vdpa devices. The changes enable the CNI plugin to properly configure and manage these virtualized network interfaces, adapting existing SR-IOV patterns where applicable while accounting for the unique characteristics of vdpa devices, particularly concerning MAC address assignment and network namespace interactions. This enhancement broadens the range of high-performance networking options available to Kubernetes pods.

Highlights

  • vhost-vdpa Device Support: Introduced comprehensive support for vhost-vdpa devices within ovs-cni, enabling their configuration and management similar to SR-IOV devices.
  • MAC Address Handling for vdpa: Implemented specific logic to update MAC addresses directly on vdpa devices, a feature supported on Linux kernels version 6.12 and newer.
  • IPAM Considerations: Acknowledged and addressed limitations regarding IPAM functionality for vdpa interfaces, as the interface resides within the VM rather than the host or pod namespace.
  • Dependency Updates: Updated project dependencies, including the addition of the govdpa library for vdpa device interaction, and a significant update to the netlink library.
  • SR-IOV Function Refactoring: Refactored existing SR-IOV related utility functions (GetNetVF, MoveVFToNetns, RenameLink) into exported functions to allow reuse by the new vdpa device handling logic.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds support for vhost_vdpa devices to ovs-cni, which is a valuable enhancement. The changes are well-structured, introducing a new vdpa package for device-specific logic and refactoring the sriov package for better code reuse. The main logic in CmdAdd correctly prioritizes vdpa device handling. My feedback includes a couple of suggestions to improve error messages for better debuggability.

Comment on lines +33 to +35
if err != nil {
return nil, fmt.Errorf("failed to run vdpa netlink command")
}

Choose a reason for hiding this comment

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

medium

The error message here is a bit generic. Wrapping the original error with more context, such as the device ID, would be more helpful for debugging.

Suggested change
if err != nil {
return nil, fmt.Errorf("failed to run vdpa netlink command")
}
if err != nil {
return nil, fmt.Errorf("failed to get vdpa devices for PCI address %q: %w", deviceID, err)
}

Comment on lines +51 to +56
switch (*vdpaDev).Driver() {
case kvdpa.VhostVdpaDriver:
return VdpaDeviceTypeKernelVhost, nil
default:
return VdpaDeviceTypeNone, fmt.Errorf("unknown vdpa device type")
}

Choose a reason for hiding this comment

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

medium

The error message "unknown vdpa device type" could be more informative. Including the actual driver name that was not recognized would aid in debugging.

Suggested change
switch (*vdpaDev).Driver() {
case kvdpa.VhostVdpaDriver:
return VdpaDeviceTypeKernelVhost, nil
default:
return VdpaDeviceTypeNone, fmt.Errorf("unknown vdpa device type")
}
switch driver := (*vdpaDev).Driver(); driver {
case kvdpa.VhostVdpaDriver:
return VdpaDeviceTypeKernelVhost, nil
default:
return VdpaDeviceTypeNone, fmt.Errorf("unknown vdpa device type: %q", driver)
}

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

Labels

dco-signoff: yes Indicates the PR's author has DCO signed all their commits. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants