Skip to content

Fix build error on Linux 6.11: update virtio_find_vqs() to use virtqueue_info #74

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

Merged
merged 1 commit into from
Jun 3, 2025

Conversation

horseface1110
Copy link
Contributor

This patch updates the call to virtio_find_vqs() to follow the new signature introduced in Linux 6.11, which replaces the separate callbacks and names arrays with a struct virtqueue_info[].

Tested on:

  • Kernel: 6.11.0
  • Distro: Ubuntu 24.04
  • Confirmed vwifi.ko builds and loads successfully

This resolves #73.

@horseface1110
Copy link
Contributor Author

result:

oloomb@oloomb:~/vwifi$ ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: ens18: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
    link/ether bc:24:11:36:19:75 brd ff:ff:ff:ff:ff:ff
    altname enp0s18
3: vw0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ether 00:76:77:30:00:00 brd ff:ff:ff:ff:ff:ff
4: vw1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ether 00:76:77:31:00:00 brd ff:ff:ff:ff:ff:ff
5: vw2: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ether 00:76:77:32:00:00 brd ff:ff:ff:ff:ff:ff
6: vw3: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ether 00:76:77:33:00:00 brd ff:ff:ff:ff:ff:ff
7: vw4: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ether 00:76:77:34:00:00 brd ff:ff:ff:ff:ff:ff

Copy link
Contributor

@jserv jserv left a comment

Choose a reason for hiding this comment

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

Indent with clang-format version 18.

@jserv
Copy link
Contributor

jserv commented May 25, 2025

The proposed change breaks the build on Linux v6.8:

/tmp/vwifi/vwifi.c: In function ‘vwifi_virtio_init_vqs’:
/tmp/vwifi/vwifi.c:3170:27: error: array type has incomplete element type ‘struct virtqueue_info’
 3170 |     struct virtqueue_info vqs_info[VWIFI_NUM_VQS];
      |                           ^~~~~~~~
/tmp/vwifi/vwifi.c:3177:12: error: too few arguments to function ‘virtio_find_vqs’
 3177 |     return virtio_find_vqs(vdev, VWIFI_NUM_VQS, vwifi_vqs, vqs_info, NULL);
      |            ^~~~~~~~~~~~~~~
In file included from /tmp/vwifi/vwifi.c:11:
./include/linux/virtio_config.h:228:5: note: declared here
  228 | int virtio_find_vqs(struct virtio_device *vdev, unsigned nvqs,
      |     ^~~~~~~~~~~~~~~
/tmp/vwifi/vwifi.c:3170:27: warning: unused variable ‘vqs_info’ [-Wunused-variable]
 3170 |     struct virtqueue_info vqs_info[VWIFI_NUM_VQS];
      |                           ^~~~~~~~
/tmp/vwifi/vwifi.c:3178:1: error: control reaches end of non-void function [-Werror=return-type]
 3178 | }
      | ^
cc1: some warnings being treated as errors

You must ensure the changes are compatible with older Linux versions.

Copy link
Contributor

@jserv jserv left a comment

Choose a reason for hiding this comment

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

You should check the git history of the Linux kernel to locate the exact commit hash that indicates the interface changes to virtio_find_vqs(), so that the commit messages can be more informative.

Example: sysprog21/simplefs@357a813

Copy link
Collaborator

@jychen0611 jychen0611 left a comment

Choose a reason for hiding this comment

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

Refine the assignment of ctx. It is a bool, so avoid using NULL. Use true or false depending on whether extra context is required.

vwifi.c Outdated
struct virtqueue_info vqs_info[VWIFI_NUM_VQS];
for (int i = 0; i < VWIFI_NUM_VQS; i++) {
vqs_info[i].callback = callbacks[i];
vqs_info[i].name = names[i];
vqs_info[i].ctx = NULL; // optional
vqs_info[i].ctx = NULL;
Copy link
Collaborator

Choose a reason for hiding this comment

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

ctx is a bool, so setting it to NULL is inappropriate. Please set it explicitly to true or false depending on whether this virtqueue requires maintaining an extra context.

If unsure, check whether the vwifi logic relies on extra context per virtqueue. If context is not needed, use false.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing this out. I checked the definition of virtio_find_vqs() in Linux v6.8.12, which passes NULL as the ctx parameter internally.

Our project originally used virtio_find_vqs() instead of the _ctx variant, so I’ve conservatively set ctx = false for all virtqueues to match the original behavior. Since the non-_ctx version does not support passing context flags, switching to virtio_find_vqs_ctx() would be required if any virtqueue truly needs extra context. Given that the original code used the non-_ctx version, I assume that additional context is not needed.

Copy link
Contributor

@jserv jserv left a comment

Choose a reason for hiding this comment

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

Use git rebase -i to squash and rework commits. Then, append Close #73 at the end of git commit messages.

@jserv jserv requested a review from jychen0611 May 27, 2025 03:00
@horseface1110 horseface1110 force-pushed the fix-virtio-api-linux-6.11 branch 2 times, most recently from 652f115 to 7c4fd63 Compare May 27, 2025 05:18
Copy link
Contributor

@jserv jserv left a comment

Choose a reason for hiding this comment

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

Avoid using backticks in commit subjects. Backticks can be easily confused with single quotes on some terminals, reducing readability. Plain text or single quotes provide sufficient clarity and emphasis.

for (int i = 0; i < VWIFI_NUM_VQS; i++) {
vqs_info[i].callback = callbacks[i];
vqs_info[i].name = names[i];
vqs_info[i].ctx = false;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add a brief comment for .ctx = false, following the project's comment style, to clarify its intended usage for future maintainers.

Copy link
Collaborator

@jychen0611 jychen0611 left a comment

Choose a reason for hiding this comment

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

Have you tested the virtio-related feature after your modification?

@horseface1110
Copy link
Contributor Author

horseface1110 commented May 27, 2025

Have you tested the virtio-related feature after your modification?

Thanks for the reminder. I initially thought it worked, but after rechecking, I found the virtio feature still has issues. I’ll follow up with a fix soon.

@horseface1110 horseface1110 force-pushed the fix-virtio-api-linux-6.11 branch 2 times, most recently from fab7de1 to 8a2d9c4 Compare May 28, 2025 06:08
@horseface1110
Copy link
Contributor Author

This PR addresses API changes introduced in Linux kernel v6.11.

During the process, I also noticed additional modifications required for compatibility with v6.15.
I will open a new PR specifically for handling the v6.15-related updates to keep the changes clean and focused.

Please let me know if anything else needs to be adjusted here. Thank you!

Copy link
Collaborator

@jychen0611 jychen0611 left a comment

Choose a reason for hiding this comment

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

Avoid using backticks ( ` ) in commit subjects. Backticks can be easily confused with single quotes on some terminals, reducing readability. Plain text or single quotes provide sufficient clarity and emphasis.

@jserv
Copy link
Contributor

jserv commented May 28, 2025

During the process, I also noticed additional modifications required for compatibility with v6.15. I will open a new PR specifically for handling the v6.15-related updates to keep the changes clean and focused.

Create a new issue to address v6.15 compatibility. Let's concentrate on Linux v6.11 here.

Copy link
Contributor

@jserv jserv left a comment

Choose a reason for hiding this comment

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

Consider the following git commit messages:

Support Linux v6.11

Update virtqueue setup to use the new virtio_find_vqs() interface
introduced in Linux commit c502eb8 ("virtio: Introduce struct
virtqueue_info and find_vqs_info() config op"), which now takes an array
of struct virtqueue_info instead of separate parameter arrays.

The legacy virtio_find_vqs() interface was replaced in Linux commit
6c85d6b ("virtio: Rename virtio_find_vqs_info() to virtio_find_vqs")
with a new implementation using struct virtqueue_info.

Since the original code relied on virtio_find_vqs() with implicit NULL
context, the ctx field is set to false to maintain equivalent behavior. 

Copy link
Contributor

@jserv jserv left a comment

Choose a reason for hiding this comment

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

Refine git commit messages per requested.

Update virtqueue setup to use the new virtio_find_vqs() interface
introduced in Linux commit c502eb8 ("virtio: Introduce struct
virtqueue_info and find_vqs_info() config op"), which now takes an array
of struct virtqueue_info instead of separate parameter arrays.

The legacy virtio_find_vqs() interface was replaced in Linux commit
6c85d6b ("virtio: Rename virtio_find_vqs_info() to virtio_find_vqs")
with a new implementation using struct virtqueue_info.

Since the original code relied on virtio_find_vqs() with implicit NULL
context, the ctx field is set to false to maintain equivalent behavior.
@horseface1110 horseface1110 force-pushed the fix-virtio-api-linux-6.11 branch from 8a2d9c4 to 800ad32 Compare June 2, 2025 12:52
@jserv jserv merged commit d3114d3 into sysprog21:main Jun 3, 2025
4 checks passed
@jserv
Copy link
Contributor

jserv commented Jun 3, 2025

Thank @horseface1110 for contributing!

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.

Failed to build with Linux v6.11
3 participants