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

try sending with tx checksum offload #4587

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion scripts/xdp.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"installer": "https://github.com/microsoft/xdp-for-windows/releases/download/v1.0.1/xdp-for-windows.1.0.1.msi"
"installer": "https://github.com/microsoft/xdp-for-windows/releases/download/v1.1.0%2B5421c3c5/xdp-for-windows.1.1.0-prerelease+cfc4e4dd.msi"
Copy link
Member

Choose a reason for hiding this comment

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

A thought I had: How will MsQuic require the XDP version that supports the new offloads in the future? Should we rely on API version, or is there a way to require a specific XDP driver version?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you should try loading the highest api versions, falling back gracefully, if a new API version is introduced. for some features, socket options will be added and shouldn't require an API version change

}
2 changes: 1 addition & 1 deletion src/platform/datapath_raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ RawSocketSend(
const CXPLAT_INTERFACE* Interface = CxPlatDpRawGetInterfaceFromQueue(Route->Queue);

CxPlatFramingWriteHeaders(
Socket, Route, &SendData->Buffer, SendData->ECN,
Socket, Route, SendData, &SendData->Buffer, SendData->ECN,
Interface->OffloadStatus.Transmit.NetworkLayerXsum,
Interface->OffloadStatus.Transmit.TransportLayerXsum,
Route->TcpState.SequenceNumber,
Expand Down
4 changes: 4 additions & 0 deletions src/platform/datapath_raw.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ typedef struct CXPLAT_SEND_DATA {

QUIC_BUFFER Buffer;

uint16_t L2HeaderSize;
uint16_t L3HeaderSize;
uint8_t IsIpv4 : 1;
} CXPLAT_SEND_DATA;

_IRQL_requires_max_(PASSIVE_LEVEL)
Expand Down Expand Up @@ -375,6 +378,7 @@ void
CxPlatFramingWriteHeaders(
_In_ CXPLAT_SOCKET_RAW* Socket,
_In_ const CXPLAT_ROUTE* Route,
_Inout_ CXPLAT_SEND_DATA* SendData,
_Inout_ QUIC_BUFFER* Buffer,
_In_ CXPLAT_ECN_TYPE ECN,
_In_ BOOLEAN SkipNetworkLayerXsum,
Expand Down
16 changes: 11 additions & 5 deletions src/platform/datapath_raw_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ CxPlatDpRawSocketAckFin(
TCP_HEADER* ReceivedTcpHeader = (TCP_HEADER*)(Packet->Buffer - Packet->ReservedEx);

CxPlatFramingWriteHeaders(
Socket, Route, &SendData->Buffer, SendData->ECN,
Socket, Route, SendData, &SendData->Buffer, SendData->ECN,
Interface->OffloadStatus.Transmit.NetworkLayerXsum,
Interface->OffloadStatus.Transmit.TransportLayerXsum,
ReceivedTcpHeader->AckNumber,
Expand Down Expand Up @@ -597,7 +597,7 @@ CxPlatDpRawSocketAckSyn(
CASTED_CLOG_BYTEARRAY(sizeof(Route->LocalAddress), &Route->LocalAddress));

CxPlatFramingWriteHeaders(
Socket, Route, &SendData->Buffer, SendData->ECN,
Socket, Route, SendData, &SendData->Buffer, SendData->ECN,
Interface->OffloadStatus.Transmit.NetworkLayerXsum,
Interface->OffloadStatus.Transmit.TransportLayerXsum,
ReceivedTcpHeader->AckNumber,
Expand All @@ -617,7 +617,7 @@ CxPlatDpRawSocketAckSyn(
CASTED_CLOG_BYTEARRAY(sizeof(Route->RemoteAddress), &Route->RemoteAddress),
CASTED_CLOG_BYTEARRAY(sizeof(Route->LocalAddress), &Route->LocalAddress));
CxPlatFramingWriteHeaders(
Socket, Route, &SendData->Buffer, SendData->ECN,
Socket, Route, SendData, &SendData->Buffer, SendData->ECN,
Interface->OffloadStatus.Transmit.NetworkLayerXsum,
Interface->OffloadStatus.Transmit.TransportLayerXsum,
CxPlatByteSwapUint32(CxPlatByteSwapUint32(ReceivedTcpHeader->AckNumber) + 1),
Expand All @@ -640,7 +640,7 @@ CxPlatDpRawSocketAckSyn(
CASTED_CLOG_BYTEARRAY(sizeof(Route->RemoteAddress), &Route->RemoteAddress),
CASTED_CLOG_BYTEARRAY(sizeof(Route->LocalAddress), &Route->LocalAddress));
CxPlatFramingWriteHeaders(
Socket, Route, &SendData->Buffer, SendData->ECN,
Socket, Route, SendData, &SendData->Buffer, SendData->ECN,
Interface->OffloadStatus.Transmit.NetworkLayerXsum,
Interface->OffloadStatus.Transmit.TransportLayerXsum,
ReceivedTcpHeader->AckNumber,
Expand Down Expand Up @@ -676,7 +676,7 @@ CxPlatDpRawSocketSyn(
CXPLAT_DBG_ASSERT(Route->Queue != NULL);
const CXPLAT_INTERFACE* Interface = CxPlatDpRawGetInterfaceFromQueue(Route->Queue);
CxPlatFramingWriteHeaders(
Socket, Route, &SendData->Buffer, SendData->ECN,
Socket, Route, SendData, &SendData->Buffer, SendData->ECN,
Interface->OffloadStatus.Transmit.NetworkLayerXsum,
Interface->OffloadStatus.Transmit.TransportLayerXsum,
Route->TcpState.SequenceNumber, 0, TH_SYN);
Expand All @@ -688,6 +688,7 @@ void
CxPlatFramingWriteHeaders(
_In_ CXPLAT_SOCKET_RAW* Socket,
_In_ const CXPLAT_ROUTE* Route,
_Inout_ CXPLAT_SEND_DATA* SendData,
_Inout_ QUIC_BUFFER* Buffer,
_In_ CXPLAT_ECN_TYPE ECN,
_In_ BOOLEAN SkipNetworkLayerXsum,
Expand Down Expand Up @@ -757,6 +758,7 @@ CxPlatFramingWriteHeaders(
IPv4->TimeToLive = IP_DEFAULT_HOP_LIMIT;
IPv4->Protocol = TransportProtocol;
IPv4->HeaderChecksum = 0;
SendData->IsIpv4 = TRUE;
CxPlatCopyMemory(IPv4->Source, &Route->LocalAddress.Ipv4.sin_addr, sizeof(Route->LocalAddress.Ipv4.sin_addr));
CxPlatCopyMemory(IPv4->Destination, &Route->RemoteAddress.Ipv4.sin_addr, sizeof(Route->RemoteAddress.Ipv4.sin_addr));
IPv4->HeaderChecksum = SkipNetworkLayerXsum ? 0 : ~CxPlatFramingChecksum((uint8_t*)IPv4, sizeof(IPV4_HEADER), 0);
Expand Down Expand Up @@ -805,6 +807,7 @@ CxPlatFramingWriteHeaders(
IPv6->PayloadLength = htons(TransportLength + (uint16_t)Buffer->Length);
IPv6->HopLimit = IP_DEFAULT_HOP_LIMIT;
IPv6->NextHeader = TransportProtocol;
SendData->IsIpv4 = FALSE;
CxPlatCopyMemory(IPv6->Source, &Route->LocalAddress.Ipv6.sin6_addr, sizeof(Route->LocalAddress.Ipv6.sin6_addr));
CxPlatCopyMemory(IPv6->Destination, &Route->RemoteAddress.Ipv6.sin6_addr, sizeof(Route->RemoteAddress.Ipv6.sin6_addr));
EthType = ETHERNET_TYPE_IPV6;
Expand Down Expand Up @@ -839,6 +842,9 @@ CxPlatFramingWriteHeaders(

Buffer->Length += TransportLength + IpHeaderLen + sizeof(ETHERNET_HEADER);
Buffer->Buffer -= TransportLength + IpHeaderLen + sizeof(ETHERNET_HEADER);

SendData->L2HeaderSize = sizeof(ETHERNET_HEADER);
SendData->L3HeaderSize = IpHeaderLen;
}

QUIC_STATUS
Expand Down
17 changes: 16 additions & 1 deletion src/platform/datapath_raw_xdp_win.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ CxPlatXdpReadConfig(
Xdp->TxBufferCount = 8192;
Xdp->TxRingSize = 256;
Xdp->TxAlwaysPoke = FALSE;
Xdp->SkipXsum = TRUE;

//
// Read config from config file.
Expand Down Expand Up @@ -1687,13 +1688,27 @@ CxPlatXdpTx(
uint32_t TxIndex;
uint32_t TxAvailable = XskRingProducerReserve(&Queue->TxRing, MAXUINT32, &TxIndex);
while (TxAvailable-- > 0 && !CxPlatListIsEmpty(&Queue->PartitionTxQueue)) {
XSK_BUFFER_DESCRIPTOR* Buffer = XskRingGetElement(&Queue->TxRing, TxIndex++);
XSK_FRAME_DESCRIPTOR* Frame = XskRingGetElement(&Queue->TxRing, TxIndex++);
XSK_BUFFER_DESCRIPTOR* Buffer = &Frame->Buffer;
CXPLAT_LIST_ENTRY* Entry = CxPlatListRemoveHead(&Queue->PartitionTxQueue);
XDP_TX_PACKET* Packet = CONTAINING_RECORD(Entry, XDP_TX_PACKET, Link);

Buffer->Address.BaseAddress = (uint8_t*)Packet - Queue->TxBuffers;
Buffer->Address.Offset = FIELD_OFFSET(XDP_TX_PACKET, FrameBuffer);
Buffer->Length = Packet->Buffer.Length;

Frame->Layout.Layer2Type = XdpFrameLayer2TypeEthernet;
Frame->Layout.Layer2HeaderLength = Packet->L2HeaderSize;
Frame->Layout.Layer3Type =
Packet->IsIpv4 ?
XdpFrameLayer3TypeIPv4UnspecifiedOptions :
XdpFrameLayer3TypeIPv6UnspecifiedExtensions;
Frame->Layout.Layer3HeaderLength = Packet->L3HeaderSize;
Frame->Layout.Layer4Type = XdpFrameLayer4TypeUdp;
Frame->Checksum.Layer3 =
Packet->IsIpv4 ? XdpFrameTxChecksumActionRequired : XdpFrameTxChecksumActionPassthrough;
Frame->Checksum.Layer4 = XdpFrameTxChecksumActionRequired;

ProdCount++;
}

Expand Down
2 changes: 1 addition & 1 deletion submodules/xdp-for-windows
Submodule xdp-for-windows updated 133 files
Loading