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

Add AF_XDP transmit checksum offload #375

Merged
merged 33 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
3b68335
provide minimum UDP checksum and segmentation offload to support MsQu…
mtfriesen Aug 11, 2023
40d64ef
clear USO OOB when GSO isn't specified
mtfriesen Aug 12, 2023
cfc4e4d
perform GSO check after populating GSO fields...
mtfriesen Aug 12, 2023
7fff278
provide minimum UDP checksum and segmentation offload to support MsQu…
mtfriesen Aug 11, 2023
11a7a4c
clear USO OOB when GSO isn't specified
mtfriesen Aug 12, 2023
ec69c2e
perform GSO check after populating GSO fields...
mtfriesen Aug 12, 2023
f9c8054
WIP - doesn't even compile.
mtfriesen Apr 30, 2024
4ae02d3
Merge branch 'mtfriesen/udp_checksum_uso_poc' of https://github.com/m…
mtfriesen Oct 1, 2024
0f0fd14
Merge remote-tracking branch 'origin/main' into mtfriesen/udp_checksu…
mtfriesen Oct 1, 2024
87ab315
Merge remote-tracking branch 'origin/main' into mtfriesen/udp_checksu…
mtfriesen Oct 3, 2024
380f1ca
fix build
mtfriesen Oct 3, 2024
862463f
Merge branch 'main' into mtfriesen/udp_checksum_uso_poc
mtfriesen Dec 10, 2024
1778da4
fix submodules
mtfriesen Dec 10, 2024
0230122
WIP
mtfriesen Dec 10, 2024
6a570eb
wip/sync
mtfriesen Dec 11, 2024
8a724e8
wip/sync
mtfriesen Dec 11, 2024
5b7a1ff
builds and smoke tests pass locally
mtfriesen Dec 11, 2024
e017012
plumb to XDP TX queue and XDP LWF TX queue
mtfriesen Dec 11, 2024
f7adcfb
sync fixes and add XSK frame extension set
mtfriesen Dec 11, 2024
34c40d1
remove stale #include of offload.h
mtfriesen Dec 11, 2024
4649459
fix several bugs
mtfriesen Dec 12, 2024
02524ca
send validation in LWF
mtfriesen Dec 13, 2024
e4a455f
plumb af_xdp ring extensions and sockopts
mtfriesen Dec 13, 2024
b0bbd49
add spin coverage, some initial fixes
mtfriesen Dec 13, 2024
0fd7207
fix more spin bugs
mtfriesen Dec 13, 2024
7e900e2
another fix
mtfriesen Dec 13, 2024
d87f2f6
more bugfixes
mtfriesen Dec 13, 2024
ac14a37
Merge branch 'main' into mtfriesen/udp_checksum_uso_poc
mtfriesen Dec 16, 2024
17601e8
clean up todo
mtfriesen Dec 16, 2024
98d8ec5
rename sockopts for consistency, add control path functional test
mtfriesen Dec 16, 2024
8f8cbf0
add IP checksum offload test
mtfriesen Dec 16, 2024
f85a4c9
add TCP and UDP tests and fix more bugs
mtfriesen Dec 16, 2024
78e7865
PR feedback
mtfriesen Dec 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/api/driver-txqueueconfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,13 @@ BOOLEAN
XdpTxQueueIsOutOfOrderCompletionEnabled(
_In_ XDP_TX_QUEUE_CONFIG_ACTIVATE TxQueueConfig
);

//
// Returns whether checksum offload is enabled.
//
BOOLEAN
XdpTxQueueIsChecksumOffloadEnabled(
_In_ XDP_TX_QUEUE_CONFIG_ACTIVATE TxQueueConfig
);

```
42 changes: 19 additions & 23 deletions published/external/afxdp_experimental.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
extern "C" {
#endif

#include <xdp/framechecksum.h>
#include <xdp/framelayout.h>

//
// XSK_SOCKOPT_POLL_MODE
//
Expand Down Expand Up @@ -52,51 +55,44 @@ typedef enum _XSK_POLL_MODE {
// XSK_SOCKOPT_TX_FRAME_LAYOUT_EXTENSION
//
// Supports: get
// Optval type: XDP_EXTENSION
// Optval type: UINT16
// Description: Gets the XDP_FRAME_LAYOUT descriptor extension for the TX frame
// ring. This requires the socket is bound, the TX ring size is
// set, and at least one socket option has enabled the frame layout
// extension.
// extension. The returned value is the offset of the
// XDP_FRAME_LAYOUT structure from the start of each TX descriptor.
//
#define XSK_SOCKOPT_TX_FRAME_LAYOUT_EXTENSION 1001

//
// XSK_SOCKOPT_TX_FRAME_CHECKSUM_EXTENSION
//
// Supports: get
// Optval type: XDP_EXTENSION
// Optval type: UINT16
// Description: Gets the XDP_FRAME_CHECKSUM descriptor extension for the TX
// frame ring. This requires the socket is bound, the TX ring size
// is set, and at least one socket option has enabled the frame
// layout extension.
// is set, and at least one socket option has enabled the checksum
// extension. The returned value is the offset of the
// XDP_FRAME_CHECKSUM structure from the start of each TX descriptor.
//
#define XSK_SOCKOPT_TX_FRAME_CHECKSUM_EXTENSION 1002

//
// XSK_SOCKOPT_OFFLOAD_UDP_CHECKSUM_TX
// XSK_SOCKOPT_TX_OFFLOAD_CHECKSUM
//
// Supports: set
// Optval type: BOOLEAN
// Description: Sets whether UDP checksum transmit offload is enabled. This
// Optval type: UINT32
// Description: Sets whether checksum transmit offload is enabled. This
// option requires the socket is bound and the TX frame ring size
// is not set. This option enables the XDP_FRAME_LAYOUT and
// XDP_FRAME_CHECKSUM extensions on the TX frame ring.
// If the socket is bound to a queue that has already been
// activated by another socket without enabling checksum offload,
// then enabling the offload on another socket is currently not
// supported. Disabling the offload after is has been enabled is
// also currently not supported.
//
#define XSK_SOCKOPT_OFFLOAD_UDP_CHECKSUM_TX 1003

//
// XSK_SOCKOPT_OFFLOAD_UDP_CHECKSUM_TX_CAPABILITIES
//
// Supports: get
// Optval type: XSK_OFFLOAD_UDP_CHECKSUM_TX_CAPABILITIES
// Description: Returns the UDP checksum transmit offload capabilities. This
// option requires the socket is bound.
//
#define XSK_SOCKOPT_OFFLOAD_UDP_CHECKSUM_TX_CAPABILITIES 1004

typedef struct _XSK_OFFLOAD_UDP_CHECKSUM_TX_CAPABILITIES {
BOOLEAN Supported;
} XSK_OFFLOAD_UDP_CHECKSUM_TX_CAPABILITIES;
#define XSK_SOCKOPT_TX_OFFLOAD_CHECKSUM 1003

#ifdef __cplusplus
} // extern "C"
Expand Down
16 changes: 16 additions & 0 deletions published/external/xdp/details/txqueueconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ typedef struct _XDP_TX_QUEUE_CONFIG_ACTIVATE_DISPATCH {
XDP_TX_QUEUE_ACTIVATE_IS_ENABLED *IsTxCompletionContextEnabled;
XDP_TX_QUEUE_ACTIVATE_IS_ENABLED *IsFragmentationEnabled;
XDP_TX_QUEUE_ACTIVATE_IS_ENABLED *IsOutOfOrderCompletionEnabled;
XDP_TX_QUEUE_ACTIVATE_IS_ENABLED *IsChecksumOffloadEnabled;
} XDP_TX_QUEUE_CONFIG_ACTIVATE_DISPATCH;

#define XDP_TX_QUEUE_CONFIG_ACTIVATE_DISPATCH_REVISION_1 1
Expand Down Expand Up @@ -236,4 +237,19 @@ XDPEXPORT(XdpTxQueueIsOutOfOrderCompletionEnabled)(
return Details->Dispatch->IsOutOfOrderCompletionEnabled(TxQueueConfig);
}

inline
BOOLEAN
XDPEXPORT(XdpTxQueueIsChecksumOffloadEnabled)(
_In_ XDP_TX_QUEUE_CONFIG_ACTIVATE TxQueueConfig
)
{
XDP_TX_QUEUE_CONFIG_ACTIVATE_DETAILS *Details = (XDP_TX_QUEUE_CONFIG_ACTIVATE_DETAILS *)TxQueueConfig;
if (Details->Dispatch->Header.Revision == XDP_TX_QUEUE_CONFIG_ACTIVATE_DISPATCH_REVISION_1 &&
Details->Dispatch->Header.Size >= RTL_SIZEOF_THROUGH_FIELD(XDP_TX_QUEUE_CONFIG_ACTIVATE_DISPATCH, IsChecksumOffloadEnabled)) {
return Details->Dispatch->IsChecksumOffloadEnabled(TxQueueConfig);
} else {
return FALSE;
}
}

EXTERN_C_END
41 changes: 41 additions & 0 deletions published/external/xdp/framechecksum.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
//

#pragma once

EXTERN_C_START

#pragma warning(push)
#pragma warning(default:4820) // warn if the compiler inserted padding
#pragma warning(disable:4201) // nonstandard extension used: nameless struct/union
#pragma warning(disable:4214) // nonstandard extension used: bit field types other than int

typedef enum _XDP_FRAME_TX_CHECKSUM_ACTION {
XdpFrameTxChecksumActionPassthrough = 0,
XdpFrameTxChecksumActionRequired = 1,
} XDP_FRAME_TX_CHECKSUM_ACTION;

typedef enum _XDP_FRAME_RX_CHECKSUM_EVALUATION {
XdpFrameRxChecksumEvaluationNotChecked = 0,
XdpFrameRxChecksumEvaluationSucceeded = 1,
XdpFrameRxChecksumEvaluationFailed = 2,
XdpFrameRxChecksumEvaluationInvalid = 3,
} XDP_FRAME_RX_CHECKSUM_EVALUATION;

typedef struct _XDP_FRAME_CHECKSUM {
// One of XDP_FRAME_TX_CHECKSUM_ACTION or XDP_FRAME_RX_CHECKSUM_EVALUATION
UINT8 Layer3 : 2;

// One of XDP_FRAME_TX_CHECKSUM_ACTION or XDP_FRAME_RX_CHECKSUM_EVALUATION
UINT8 Layer4 : 2;

UINT8 Reserved : 4;
} XDP_FRAME_CHECKSUM;

C_ASSERT(sizeof(XDP_FRAME_CHECKSUM) == 1);

#pragma warning(pop)

EXTERN_C_END
27 changes: 27 additions & 0 deletions published/external/xdp/framechecksumextension.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
//

#pragma once

EXTERN_C_START

#include <xdp/framechecksum.h>

#define XDP_FRAME_EXTENSION_CHECKSUM_NAME L"ms_frame_checksum"
#define XDP_FRAME_EXTENSION_CHECKSUM_VERSION_1 1U

#include <xdp/extension.h>

inline
XDP_FRAME_CHECKSUM *
XdpGetChecksumExtension(
_In_ XDP_FRAME *Frame,
_In_ XDP_EXTENSION *Extension
)
{
return (XDP_FRAME_CHECKSUM *)XdpGetExtensionData(Frame, Extension);
}

EXTERN_C_END
62 changes: 62 additions & 0 deletions published/external/xdp/framelayout.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
//

#pragma once

EXTERN_C_START

#pragma warning(push)
#pragma warning(default:4820) // warn if the compiler inserted padding
#pragma warning(disable:4201) // nonstandard extension used: nameless struct/union
#pragma warning(disable:4214) // nonstandard extension used: bit field types other than int

typedef enum _XDP_FRAME_LAYER2_TYPE {
XdpFrameLayer2TypeUnspecified,
XdpFrameLayer2TypeNull,
XdpFrameLayer2TypeEthernet,
} XDP_FRAME_LAYER2_TYPE;

typedef enum _XDP_FRAME_LAYER3_TYPE {
XdpFrameLayer3TypeUnspecified,
XdpFrameLayer3TypeIPv4UnspecifiedOptions,
XdpFrameLayer3TypeIPv4WithOptions,
XdpFrameLayer3TypeIPv4NoOptions,
XdpFrameLayer3TypeIPv6UnspecifiedExtensions,
XdpFrameLayer3TypeIPv6WithExtensions,
XdpFrameLayer3TypeIPv6NoExtensions,
} XDP_FRAME_LAYER3_TYPE;

typedef enum _XDP_FRAME_LAYER4_TYPE {
XdpFrameLayer4TypeUnspecified,
XdpFrameLayer4TypeTcp,
XdpFrameLayer4TypeUdp,
XdpFrameLayer4TypeIPFragment,
XdpFrameLayer4TypeIPNotFragment,
} XDP_FRAME_LAYER4_TYPE;

#include <pshpack1.h>
nibanks marked this conversation as resolved.
Show resolved Hide resolved
typedef struct _XDP_FRAME_LAYOUT {
UINT16 Layer2HeaderLength : 7;
UINT16 Layer3HeaderLength : 9;
UINT8 Layer4HeaderLength : 8;

// One of the XDP_FRAME_LAYER2_TYPE values
UINT8 Layer2Type : 4;

// One of the XDP_FRAME_LAYER3_TYPE values
UINT8 Layer3Type : 4;

// One of the XDP_FRAME_LAYER4_TYPE values
UINT8 Layer4Type : 4;

UINT8 Reserved0 : 4;
} XDP_FRAME_LAYOUT;
#include <poppack.h>

C_ASSERT(sizeof(XDP_FRAME_LAYOUT) == 5);
mtfriesen marked this conversation as resolved.
Show resolved Hide resolved

#pragma warning(pop)

EXTERN_C_END
27 changes: 27 additions & 0 deletions published/external/xdp/framelayoutextension.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
//

#pragma once

EXTERN_C_START

#include <xdp/framelayout.h>

#define XDP_FRAME_EXTENSION_LAYOUT_NAME L"ms_frame_layout"
#define XDP_FRAME_EXTENSION_LAYOUT_VERSION_1 1U

#include <xdp/extension.h>

inline
XDP_FRAME_LAYOUT *
XdpGetLayoutExtension(
_In_ XDP_FRAME *Frame,
_In_ XDP_EXTENSION *Extension
)
{
return (XDP_FRAME_LAYOUT *)XdpGetExtensionData(Frame, Extension);
}

EXTERN_C_END
82 changes: 0 additions & 82 deletions published/external/xdp/offload.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,86 +13,6 @@ EXTERN_C_START
// significant changes.
//

#pragma warning(push)
#pragma warning(default:4820) // warn if the compiler inserted padding
#pragma warning(disable:4201) // nonstandard extension used: nameless struct/union
#pragma warning(disable:4214) // nonstandard extension used: bit field types other than int

typedef enum _XDP_FRAME_LAYER2_TYPE {
XdpFrameLayer2TypeUnspecified,
XdpFrameLayer2TypeNull,
XdpFrameLayer2TypeEthernet,
} XDP_FRAME_LAYER2_TYPE;

typedef enum _XDP_FRAME_LAYER3_TYPE {
XdpFrameLayer3TypeUnspecified,
XdpFrameLayer3TypeIPv4UnspecifiedOptions,
XdpFrameLayer3TypeIPv4WithOptions,
XdpFrameLayer3TypeIPv4NoOptions,
XdpFrameLayer3TypeIPv6UnspecifiedExtensions,
XdpFrameLayer3TypeIPv6WithExtensions,
XdpFrameLayer3TypeIPv6NoExtensions,
} XDP_FRAME_LAYER3_TYPE;

typedef enum _XDP_FRAME_LAYER4_TYPE {
XdpFrameLayer4TypeUnspecified,
XdpFrameLayer4TypeTcp,
XdpFrameLayer4TypeUdp,
XdpFrameLayer4TypeIPFragment,
XdpFrameLayer4TypeIPNotFragment,
} XDP_FRAME_LAYER4_TYPE;

#include <pshpack1.h>
typedef struct _XDP_FRAME_LAYOUT {
UINT16 Layer2HeaderLength : 7;
UINT16 Layer3HeaderLength : 9;
UINT8 Layer4HeaderLength : 8;

// One of the XDP_FRAME_LAYER2_TYPE values
UINT8 Layer2Type : 4;

// One of the XDP_FRAME_LAYER3_TYPE values
UINT8 Layer3Type : 4;

// One of the XDP_FRAME_LAYER4_TYPE values
UINT8 Layer4Type : 4;

UINT8 Reserved0 : 4;
} XDP_FRAME_LAYOUT;
#include <poppack.h>

C_ASSERT(sizeof(XDP_FRAME_LAYOUT) == 5);

#pragma warning(pop)

typedef enum _XDP_FRAME_TX_CHECKSUM_ACTION {
XdpFrameTxChecksumActionPassthrough = 0,
XdpFrameTxChecksumActionRequired = 1,
} XDP_FRAME_TX_CHECKSUM_ACTION;

typedef enum _XDP_FRAME_RX_CHECKSUM_EVALUATION {
XdpFrameRxChecksumEvaluationNotChecked = 0,
XdpFrameRxChecksumEvaluationSucceeded = 1,
XdpFrameRxChecksumEvaluationFailed = 2,
XdpFrameRxChecksumEvaluationInvalid = 3,
} XDP_FRAME_RX_CHECKSUM_EVALUATION;

#pragma warning(push)
#pragma warning(default:4820) // warn if the compiler inserted padding

typedef struct _XDP_FRAME_CHECKSUM {
// One of XDP_FRAME_TX_CHECKSUM_ACTION or XDP_FRAME_RX_CHECKSUM_EVALUATION
UINT8 Layer3 : 2;

// One of XDP_FRAME_TX_CHECKSUM_ACTION or XDP_FRAME_RX_CHECKSUM_EVALUATION
UINT8 Layer4 : 2;

UINT8 Reserved : 4;
} XDP_FRAME_CHECKSUM;

C_ASSERT(sizeof(XDP_FRAME_CHECKSUM) == 1);

#pragma warning(pop)

#pragma warning(push)
#pragma warning(default:4820) // warn if the compiler inserted padding
Expand Down Expand Up @@ -143,8 +63,6 @@ typedef struct _XDP_FRAME_GRO_TIMESTAMP {

C_ASSERT(sizeof(XDP_FRAME_GRO_TIMESTAMP) == 4);

#pragma warning(pop)
mtfriesen marked this conversation as resolved.
Show resolved Hide resolved

typedef struct _XDP_FRAME_TIMESTAMP {
UINT64 Timestamp;
} XDP_FRAME_TIMESTAMP;
Expand Down
6 changes: 6 additions & 0 deletions published/external/xdp/txqueueconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ typedef struct _XDP_TX_CAPABILITIES {
UINT32 MaximumFrameSize;
UINT8 MaximumFragments;
BOOLEAN OutOfOrderCompletionEnabled;
BOOLEAN ChecksumOffload;
} XDP_TX_CAPABILITIES;
mtfriesen marked this conversation as resolved.
Show resolved Hide resolved


Expand Down Expand Up @@ -172,6 +173,11 @@ XdpTxQueueIsOutOfOrderCompletionEnabled(
_In_ XDP_TX_QUEUE_CONFIG_ACTIVATE TxQueueConfig
);

BOOLEAN
XdpTxQueueIsChecksumOffloadEnabled(
_In_ XDP_TX_QUEUE_CONFIG_ACTIVATE TxQueueConfig
);

#include <xdp/details/txqueueconfig.h>

EXTERN_C_END
Loading
Loading