Skip to content
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

Hardware checksum offloading with partially computed TCP and UDP checksums #12

Open
wants to merge 9 commits into
base: staging
Choose a base branch
from

Conversation

skuenzer
Copy link
Member

This PR enables transmitting and receiving of packets with a partially computed checksum for lib/uknetdev devices that support packets with partial checksums. Additionally, this commit activates the ability to skip checking of the checksum for already validated packets, e.g., by physical NIC on the host.
This PR bridges the gap between the lwIP implementation with PR #1 and the Unikraft uknetdev implementation with PR #308. Additonally, this PR depends on PR #10. All three PRs need to be merged before this PR can be applied.

@razvand razvand requested a review from craciunoiuc November 17, 2021 06:27
Copy link
Member

@craciunoiuc craciunoiuc left a comment

Choose a reason for hiding this comment

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

Hey @skuenzer,

I left you some initial comments. I will come back to this once some of the PR dependencies are resolved.

Cezar

Comment on lines +267 to +269
IF__NETIF_CHECKSUM_ENABLED(nf, NETIF_CHECKSUM_CHECK_IP) {
uk_pr_info(" IP");
}
Copy link
Member

@craciunoiuc craciunoiuc Nov 17, 2021

Choose a reason for hiding this comment

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

This macro looks okay, but, wouldn't it be better if there was another macro that included the print too?

PRINT_IF__NETIF_CHECKSUM_ENABLED(nf, NETIF_CHECKSUM_CHECK_IP,  " IP");
PRINT_IF__NETIF_CHECKSUM_ENABLED(nf, NETIF_CHECKSUM_CHECK_UDP, " UDP");
...

It would save a lot of lines as this is repeated a lot below 🙂

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a lwip provided macro that I am using here. I find it counter-intuitive to add another macro on top for the printing.

@@ -317,6 +317,19 @@ void sys_free(void *ptr);
#define CHECKSUM_CHECK_ICMP6 1
#define CHECKSUM_CHECK_TCP 1

/*
* As long as partial checksummin gis not upstream available,
Copy link
Member

Choose a reason for hiding this comment

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

checksummin gis -> checksumming is

Comment on lines +273 to +275
IF__NETIF_CHECKSUM_ENABLED(nf, NETIF_CHECKSUM_PARTIAL_UDP) {
uk_pr_info("[+partial]");
}
Copy link
Member

Choose a reason for hiding this comment

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

Same suggestion as before/above. This is repeated a lot and I think would sit better inside a macro.

Also, this can be a different define and it can be empty if partial checksumming is disabled:

#if LWIP_CHECKSUM_PARTIAL

#define PRINT_PART_IF__NETIF_CHECKSUM_ENABLED(INTF, NETIF_CHECKSUM_FLAG, MSG)	\
		IF__NETIF_CHECKSUM_ENABLED(INTF, NETIF_CHECKSUM_FLAG)		\
				uk_pr_info(MSG)

#else

#define PRINT_PART_IF__NETIF_CHECKSUM_ENABLED(INTF, NETIF_CHECKSUM_FLAG, MSG)	\
		do { } while (0)

#endif /* LWIP_CHECKSUM_PARTIAL */

Something like this, to have fewer #if checks. (you are free to change the suggestion in any way, of course 😉)

@skuenzer skuenzer force-pushed the skuenzer/partial-checksum branch 2 times, most recently from 2e60853 to 4480eed Compare November 30, 2021 16:00
Latest lib/uknetdev updates make it necessary that new network
interfaces need to be probed for feature negotiation before the
interface can be used.

Signed-off-by: Simon Kuenzer <[email protected]>
During network device initialization, print the hardware
address of the network device to the info kernel console.
This should simplify first-level of diagnosis.

Signed-off-by: Simon Kuenzer <[email protected]>
During network device initialization, print the checksum
handling configuration that get set by the underlying
uknetdev driver. This should simplify first-level of
diagnosis.

Signed-off-by: Simon Kuenzer <[email protected]>
The netdev device features were refactored in `lib/uknetdev`.
This commit adopts the usage for initializing interrupt
and polling mode for a device:
`UK_FEATURE_RXQ_INTR_AVAILABLE` is now called
`UK_NETDEV_F_RXQ_INTR`.

Signed-off-by: Simon Kuenzer <[email protected]>
Like Linux, we enable checking the checksum of the IP header
on packet reception and let lwIP drop the packet if it was
invalid.

Signed-off-by: Simon Kuenzer <[email protected]>
Add more details why we need to copy a packet for
transmission. We support asynchronous transmit but not with
zero-copy. Problem is that lwIP may modify a packet header
for preparing retransmissions while the NIC is still
accessing the packet buffer for transmission.

Signed-off-by: Simon Kuenzer <[email protected]>
@skuenzer skuenzer force-pushed the skuenzer/partial-checksum branch from 4480eed to 4058185 Compare November 30, 2021 16:14
This commit implements and enables checksum offloading with
the Unikraft fork of lwIP and if the underlying uknetdev
device announced support for it. For non-supported devices,
all checksums are checked and computed. When an lwIP stack
version is used that currently does not support checksum
offloading, the original behavior is kept.

Signed-off-by: Simon Kuenzer <[email protected]>
During netif initialization, the handling of checksums is
printed per device with the info level. This commits adds
the following properties next to the protocols:
- For received traffic
 - `[+partial]`   Driver and device additionally support
                  receiving of partial checksummed packets.
 - `[+offloaded]` Driver and device additionally skip checksum
                  validation of already validated packets,
		  e.g., by a physical NIC on the host.
- For transmitted traffic
 - `[partial]`    Generated packets will only have a partial
                  checksum computed in software. The rest of
		  the checksum is intended to be computed by
		  a physical NIC on the host.

Signed-off-by: Simon Kuenzer <[email protected]>
Whenever we need to wait for the device/driver to be
ready for sending out another packet, we enter a
busy-wait loop. With this commit, we call
`uk_sched_yield()` while we wait so that other threads
in the system can be executed.

Signed-off-by: Simon Kuenzer <[email protected]>
@skuenzer skuenzer force-pushed the skuenzer/partial-checksum branch from 4058185 to 7d33417 Compare December 2, 2021 00:01
@razvand razvand requested a review from craciunoiuc February 5, 2022 05:39
@razvand razvand added the enhancement New feature or request label Mar 26, 2022
@razvand razvand added this to the v0.9.0 (Hyperion) milestone Mar 28, 2022
@nderjung
Copy link
Member

Hi!

Can we cherry pick f9e7d14 out of this PR and place it into a new PR? The current stable (v0.8) of Unikraft relies on this change and results in breaking builds with the current version of LwIP.

@craciunoiuc
Copy link
Member

Actually, the first 3 are in now, so this PR can be rebased

@marcrittinghaus
Copy link
Member

Hmm. I was sure that it built for me, when I tested just putting in the PRs that are now accepted ☹️

Lets cherry pick the change because I have problems with this patch. curl in PHP no longer works with it. I already told @skuenzer, but I have not yet had the time to prepare a network trace for him to debug the issue.

@marcrittinghaus marcrittinghaus removed this from the v0.10.0 (Phoebe) milestone Aug 11, 2022
@razvand
Copy link
Contributor

razvand commented Aug 14, 2022

@marcrittinghaus , is there still an issue with curl and this PR? I moved it to 0.11. Is that reasonable? Or should we move it to 0.12?

@razvand razvand requested a review from mogasergiu August 19, 2024 10:54
@razvand razvand assigned razvand and unassigned marcrittinghaus Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: In Progress
Status: review:changes_requested
Development

Successfully merging this pull request may close these issues.

5 participants