Skip to content

Fix compatibility with Linux kernel 6.15–6.16 ABI/API changes#302

Open
sheviks wants to merge 5 commits intoXilinx-CNS:masterfrom
sheviks:fix-for-kernel-6.15-and-6.16
Open

Fix compatibility with Linux kernel 6.15–6.16 ABI/API changes#302
sheviks wants to merge 5 commits intoXilinx-CNS:masterfrom
sheviks:fix-for-kernel-6.15-and-6.16

Conversation

@sheviks
Copy link
Copy Markdown

@sheviks sheviks commented Aug 10, 2025

This patch is an extension of issue #293, addressing additional ABI/API changes required to successfully build against kernel 6.15+.

In addition to the kbuild ccflags-y issue reported in #293, this update resolves several compatibility problems introduced in recent upstream kernel changes:

  • Renamed page->index to page->__folio_index
    Upstream commit: acc53a0

  • UNIXCB() usage has been restricted to internal use
    Upstream commit: 84960bf

  • Replaced d_hash_and_lookup() with try_lookup_noperm()
    Upstream commit: 06c5674

  • Corrected EFRM_HAVE_OLD_FAULT usage: vm_operations_struct::fault() has consistently been a single-parameter function; EFRM_HAVE_NEW_FAULT remains valid
    Upstream commit: 1c8f422

  • Resolved Clang build error
    When building via env LLVM=1 scripts/onload_build --kernelver <clang-compiled kernel>, compilation would fail due to unsupported Clang extension:
    error: fields must have a constant size: variable length array in structure
    The affected #if conditions have now been updated to use valid macros.

This patch introduces some new kernel_compact tests and can be merged independently. However, to fully build on Linux 6.15+, the kbuild adjustments from issue #293 are still required.

… structure

Building with 'scripts/onload_build --kernelver <clang-compiled kernel>'
would fail due to unsupported Clang extension:
'error: fields must have a constant size: variable length array in structure'.
This commit updates the affected #if conditions to use valid macros.
- Rename `page->index` to `page->__folio_index`
  [acc53a0](torvalds/linux@acc53a0)

- `UNIXCB()` usage is now restricted to internal only as per upstream change
  [84960bf](torvalds/linux@84960bf)

- Replace `d_hash_and_lookup()` with `try_lookup_noperm()`
  [06c5674](torvalds/linux@06c5674)

- Fix `EFRM_HAVE_OLD_FAULT`; `vm_operations_struct::fault()` has always been single-parameter, and `EFRM_HAVE_NEW_FAULT` remains valid
  [1c8f422](torvalds/linux@1c8f422)
@sheviks sheviks requested a review from a team as a code owner August 10, 2025 04:41
@sheviks
Copy link
Copy Markdown
Author

sheviks commented Aug 10, 2025

I've applied @lukester1975's kbuild ccflags-y patch locally (with a small tweak for Clang compatibility).
I tested the build successfully on four kernel versions:

  • 6.16.0 compiled with GCC
  • 6.16.0 compiled with Clang
  • 6.12.40 compiled with GCC
  • 6.12.36 compiled with Clang

If needed, I can commit and push the changes so they can be included and await merge.

Thanks!

@sheviks
Copy link
Copy Markdown
Author

sheviks commented Aug 14, 2025

I just realized that when I initially addressed the UNIXCB() issue, I missed an important detail.

When copying struct unix_skb_parms, I didn’t notice that its definition ends with __randomize_layout.
This means the structure layout may vary across different kernels (although most distributions disable this feature for compatibility).

The function using UNIXCB() also contains this comment:
Sadly kernel_recvmsg doesn't offer any way to extract files from a unix socket, so we'll need to dig into the socket buffer to find them.

This indicates that using UNIXCB() is essentially a forced workaround.
I searched through the latest kernel source and couldn’t find any alternative API equivalent to retrieving UNIXCB(skb).fp.

If __randomize_layout is enabled, I can think of two methods to accurately get the layout of struct unix_skb_parms:

  1. Using bpftool
    bpftool btf dump file /lib/modules/<kernelver>/build/vmlinux format c > vmlinux.h
    Then extract struct unix_skb_parms from vmlinux.h

  2. Using pahole
    pahole -C unix_skb_parms /lib/modules/<kernelver>/build/vmlinux

Both methods require the kernel to be built with the appropriate debug configuration options enabled (e.g., CONFIG_DEBUG_INFO).
In either case, the extracted struct unix_skb_parms should be placed into a new header file.

If we completely avoid using UNIXCB(), one possible approach is similar to
src/lib/ciul/shrub_socket.c’s ef_shrub_socket_recv_metrics()
modify it to use kernel_recvmsg() and then parse cmsghdr to retrieve the data.
However, I’m not sure whether the cmsghdr would contain this information in an Onload kernel bypass environment.

Does anyone have other ideas or suggestions?

@boyracer2014
Copy link
Copy Markdown

clone the repo. swtiched and tried the branch but on a rocky linux 6.15 i am getting:

  AR      src/lib/cplane/lib.a
  CC [M]  src/driver/linux_char/vi_resource.o
In file included from src/driver/linux_net/drivers/net/ethernet/sfc/net_driver.h:77,
                 from src/driver/linux_net/drivers/net/ethernet/sfc/efx.c:33:
src/driver/linux_net/drivers/net/ethernet/sfc/efx_client.h:21:10: fatal error: linux/sfc/efx_auxbus.h: No such file or directory
   21 | #include <linux/sfc/efx_auxbus.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[6]: *** [/usr/src/kernels/6.15.7-1.el9.elrepo.x86_64/scripts/Makefile.build:203: src/driver/linux_net/drivers/net/ethernet/sfc/efx.o] Error 1
make[6]: *** Waiting for unfinished jobs....

what am i missing ?

@sheviks
Copy link
Copy Markdown
Author

sheviks commented Aug 19, 2025

This issue is due to the absence of @lukester1975's kbuild ccflags-y patch mentioned above.
Since I’m not the author of that patch, I wasn’t sure if it was appropriate to include it in this PR.

If you'd like to test the compilation, you can try:
git clone -b test-6.17 https://github.com/sheviks/onload.git

This branch additionally includes:

  1. The kbuild ccflags-y patch
    (sheviks@fdcf56e)
  2. A minor tweak to improve compatibility with Clang
    (sheviks@9525ca6)
  3. A temporary workaround for __randomize_layout mentioned above
    (sheviks@5c53f7b)
  4. Adjustments for kernel 6.17-rc
    (sheviks@b29408a)
    (sheviks@a3171bf)

Thanks!

clone the repo. swtiched and tried the branch but on a rocky linux 6.15 i am getting:

  AR      src/lib/cplane/lib.a
  CC [M]  src/driver/linux_char/vi_resource.o
In file included from src/driver/linux_net/drivers/net/ethernet/sfc/net_driver.h:77,
                 from src/driver/linux_net/drivers/net/ethernet/sfc/efx.c:33:
src/driver/linux_net/drivers/net/ethernet/sfc/efx_client.h:21:10: fatal error: linux/sfc/efx_auxbus.h: No such file or directory
   21 | #include <linux/sfc/efx_auxbus.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[6]: *** [/usr/src/kernels/6.15.7-1.el9.elrepo.x86_64/scripts/Makefile.build:203: src/driver/linux_net/drivers/net/ethernet/sfc/efx.o] Error 1
make[6]: *** Waiting for unfinished jobs....

what am i missing ?

@boyracer2014
Copy link
Copy Markdown

nice. compiled and tested. works well !

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This file is part of the sfc Linux net driver which is managed in a separate project so we would make changes there. Linux 6.15 build compatibility changes have already been made in the net driver so this particular change is no longer needed since 2b28cf9, thanks!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This file is part of the sfc Linux net driver which is managed in a separate project so we would make changes there. Linux 6.15 build compatibility changes have already been made in the net driver so this particular change is no longer needed since 2b28cf9, thanks!

Copy link
Copy Markdown
Contributor

@kieranm-xilinx kieranm-xilinx left a comment

Choose a reason for hiding this comment

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

Thanks for the pull request. This is helpful in identifying the areas of change needed. I've left comments for the individual parts, as I think the Onload team needs to make some changes before merging. Likely we'll split this into small changes so we can immediately merge some parts.

/* verifies compile time expression is 0 or positive -
* no-op for runtime expressions */
#if __GNUC__ * 100 + __GNUC_MINOR__ >= 409
#if defined(__clang__) || __GNUC__ * 100 + __GNUC_MINOR__ >= 409
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Although we don't officially support clang I'm inclined to recommend taking this fix as it will make life easier for any clang users and seems harmless for everyone else.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

If the Clang-related changes above are accepted, I’d really appreciate it if you could also include this commit: sheviks@9525ca6.

Clang emits more errors than GCC; adding that commit ensures Clang generates the same autocompat.h as GCC.
This is also harmless for users not using Clang.

Thanks!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hi @sheviks, I don't think that commit 9525ca6 features in a pull request. Would you mind putting it in one if you'd like our team to review it, please? Thanks!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I’ve committed the change. Please see this commit for details: sheviks@dc0b741
Thank you.

Copy link
Copy Markdown
Author

@sheviks sheviks Sep 19, 2025

Choose a reason for hiding this comment

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

After I committed the patch, GitHub reported conflicts. When I resolved them, GitHub automatically added a merge commit.
Because of that, I found that the commit mentioned in issue #293 (2b28cf9) does not include all ccflags-y changes.
For example:

A grep for EXTRA_CFLAGS on current master still shows quite a few remaining occurrences.
Could you please take another look and make sure the ccflags-y changes are applied consistently?

Alternatively, if you'd prefer, I can review them and submit the fixes here.

Thank you.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I reconsidered the approach. Since this PR will be split into smaller merges, I went ahead and committed the ccflags-y changes so they’re ready for review.
Please review and decide on the final merge strategy.

Thanks!

EFRM_NET_HAS_USER_NS member struct_net user_ns include/net/net_namespace.h

EFRM_HAVE_OLD_FAULT memtype struct_vm_operations_struct fault include/linux/mm.h int (*)(struct vm_area_struct *vma, struct vm_fault *vmf)
EFRM_HAVE_OLD_FAULT memtype struct_vm_operations_struct fault include/linux/mm.h int (*)(struct vm_fault *vmf)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd like us to understand why this was wrong before changing it. It has been this way for a long time. I appreciate that as this repository doesn't have the history pre-2020, it makes it difficult for external contributors to do that kind of archaeology, so I think this is a task for the AMD team. I'm wondering if when this was written, what was "new" then has become "old" now. I.e. there are potentially three signatures we need to interoperate with, although I'm hoping that the original "old" is now so old that we don't need it.

In summary, I think this change is probably correct, but I want to check history to be sure.

#include "ef100_vdpa.h"
#include "mcdi_filters.h"
#endif
#ifdef EFX_HAVE_TRY_LOOKUP_NOPERM
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The changes to src/driver/linux_net/* need to go via the AMD net driver team, as we consume the driver unmodified from them. We'll work internally to get this kernel supported with them, and then import a new version of the net driver to the Onload repository.

EFRM_HAVE_FOLLOW_PTE symbol follow_pte include/linux/mm.h
EFRM_HAVE_FOLLOW_PTE_VMA symtype follow_pte include/linux/mm.h int(struct vm_area_struct*, unsigned long, pte_t**, spinlock_t**)

EFRM_PAGE_HAS_FOLIO_INDEX member struct_page __folio_index include/linux/mm_types.h
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks good to me.

EFRM_HAVE_FOLLOW_PTE_VMA symtype follow_pte include/linux/mm.h int(struct vm_area_struct*, unsigned long, pte_t**, spinlock_t**)

EFRM_PAGE_HAS_FOLIO_INDEX member struct_page __folio_index include/linux/mm_types.h
EFRM_NEED_UNIXCB nsymbol UNIXCB include/net/af_unix.h
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This, and the code that uses it in shrub_socket_kernel.c needs closer inspection. While it might succeed in getting it to compile on recent kernels, we need to be careful about introducing new kernel definitions as they can be fragile to maintain. If there's a way we can avoid that, we'd have a strong preference for that. AMD Onload team to have a look at this.

Comment on lines +318 to +326
#ifdef EFRM_PAGE_HAS_FOLIO_INDEX
pgoff_t index = page->__folio_index;
#else
pgoff_t index = page->index;
#endif
#if defined(EFRM_HAS_FILEMAP_LOCK_HUGETLB_FOLIO) && ! defined(EFRM_HAS_HUGETLB_BASEPAGE_INDEX)
return page->index * PAGE_SIZE;
return index * PAGE_SIZE;
#else
return page->index * OO_HUGEPAGE_SIZE;
return index * OO_HUGEPAGE_SIZE;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me.

Comment on lines +24 to +38
#ifdef EFRM_NEED_UNIXCB
struct unix_skb_parms {
struct pid *pid; /* skb credentials */
kuid_t uid;
kgid_t gid;
struct scm_fp_list *fp; /* Passed files */
#ifdef CONFIG_SECURITY_NETWORK
u32 secid; /* Security ID */
#endif
u32 consumed;
} __randomize_layout;

#define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
#endif

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

See above comment for UNIXCB - Onload team to have a look

@sheviks sheviks requested a review from abower-amd September 19, 2025 12:00
@sheviks
Copy link
Copy Markdown
Author

sheviks commented Sep 19, 2025

I have replied above regarding the Clang-related part.
Aside from that, everything looks fine to me — please proceed according to your usual process.

Thank you!

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.

4 participants