Questions about AF_XDP checksum offloading

cass wang <[email protected]> Mon, 22 Jul 2024 17:45:29 +0800
Newsgroups org.kernel.vger.xdp-newbies
Message-ID <CAEXf7PBMa1z7DyLkbwQ5BwsLhZOVkHzKNEV_gZBnA9Zvyw9FxA@mail.gmail.com>
Hi,

I have a few questions about the AF_XDP TX checksum offloading.
Please let me throw my questions first, and I'll provide more info:

1. Is it possible that `xsk_tx_metadata` is not aligned to 8?
2. If it is possible, then: is it ok when running on a non x86 platform?
3. Does checksum offload always work when using SKB mode (except for virtio)?

Here's what I think I've found:

I read the kernel doc `xsk-tx-metadata.html`, it says that the kernel will
> use `xdp_desc->addr - tx_metadata_len` to locate the `xsk_tx_metadata`.
And the v6.8 kernel code can confirm that.

However, since `desc->addr` is provided by a user program, a user may set the
addr to a non-8-bytes-aligned address, and this is likely to happen, when user
removes the vlan tag from the packet, or encaps the packet into vxlan, etc...

As a result, the `xsk_tx_metadata` may not be properly aligned.
                        ==> Question 1

However, some platforms don't support unaligned access, so I'm wondering
whether this could cause a problem or even a panic.
                             ==> Question 2

I can see that the bfp helper function `bpf_xdp_adjust_meta` checks alignment
after setting the meta pointer, but it seems to be missing on AF_XDP datapath?
(or maybe I didn't find the checking code)

When trying to read the code, I see that in `xsk.c` `xsk_build_skb()`, it sets
`CHECKSUM_PARTIAL` on the skb, so I'm wondering does the checksum gets
offloaded just like other "normal" `CHECKSUM_PARTIAL` packets generated by
the net stack?
                                                     ==> Question 3