From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id E78E643866; Mon, 8 Jan 2024 16:50:19 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8688C402E5; Mon, 8 Jan 2024 16:50:19 +0100 (CET) Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by mails.dpdk.org (Postfix) with ESMTP id 8EDCE4027E for ; Mon, 8 Jan 2024 16:50:18 +0100 (CET) Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-6d9b37f4804so1872733b3a.1 for ; Mon, 08 Jan 2024 07:50:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704729017; x=1705333817; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4xCfUigz/rfGOWxkFew9irYuSKnKZ+ze/YRCcHEPkeU=; b=bDsUSEUQR0OXX65qJC9KCzQFbRxkMZVLAqDH7GOrmOcpZ/LliSuyd0dXcCx0+u0Gyj /RwtZaQlD/PRa8r6QdvPuprepNmHZpJaGmQLyULOrew/HXH8WGPr2+W8iNaF54iIymvl B8QXhWhQxae5bf0wzmEkzYGtoiQinhQZ54SAWhBLMSIwdaVAZSoF0RJd6NuP7tyGj22I +AWfE/I9qEbgGA4PoKIU3jZdDVj2Y/qr5S9PvRQ5DH/5EHa/iNXw6FVVhx7Oh2Gn7w5e jcKwCFyzcf0GMSMtdhzGTyl9TSTh8J6xxBgeqRy251PLoRFpt3pUzWbWIk6gjxj9ynhZ DUFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704729017; x=1705333817; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4xCfUigz/rfGOWxkFew9irYuSKnKZ+ze/YRCcHEPkeU=; b=GjUxL8rbpp9NHz+C1/t8SM/U45lnUtvGrkrd6q+1TR5oS8YgJWoLEFH22p8n9nW3B1 px8dTdT7BF0UhJh8ibSCzgLw6pMlGqHDuZUnIxoMZotRm+ZZwS87uldjAoHucGNRyUzt 0miDg0GRxVjlaGf1792GJpZ3JbuLzD5Rtsc4fLQh00bV+5L2E5WyzNqGrSg4tNXreoxZ oSnam77fOIoumv/8zbZEaOYNLknETQ4RQBduRYEDgiI389kzqC0v9zjfqfG3Di+G3iJE Oaop7PuAr/dG0vdD4sya7O1Dk15ym5NsqVmUfyM97vLRq7QZUTMD2Qpb+2GC9pjDGDoR gG6A== X-Gm-Message-State: AOJu0YyKq9PxygQ7zP4aFcqS1rbXDHlf5wSVVIowhMPx5RwIER8XHJsC AiSBAz1CeAVLvx1kF4U61c+fVIQOTR8= X-Google-Smtp-Source: AGHT+IE+18LP26KKkasZaONV+k02UqMHKgcozURuuC/uU4uwUXjeWhObZOYWUfCn3FWnTjQRud19bg== X-Received: by 2002:aa7:84c5:0:b0:6da:ca28:c3d2 with SMTP id x5-20020aa784c5000000b006daca28c3d2mr6310053pfn.4.1704729017352; Mon, 08 Jan 2024 07:50:17 -0800 (PST) Received: from IDCREDBOX918.fareast.corp.microsoft.com ([167.220.238.25]) by smtp.gmail.com with ESMTPSA id n21-20020a056a000d5500b006da1942d9f3sm21184pfv.104.2024.01.08.07.50.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jan 2024 07:50:17 -0800 (PST) From: Kumara Parameshwaran To: hujiayu.hu@foxmail.com Cc: dev@dpdk.org, Kumara Parameshwaran Subject: [PATCH v12] gro: fix reordering of packets in GRO layer Date: Mon, 8 Jan 2024 21:20:06 +0530 Message-Id: <20240108155006.722195-1-kumaraparamesh92@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231208181738.23931-1-kumaraparamesh92@gmail.com> References: <20231208181738.23931-1-kumaraparamesh92@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org In the current implementation when a packet is received with special TCP flag(s) set, only that packet is delivered out of order. There could be already coalesced packets in the GRO table belonging to the same flow but not delivered. This fix makes sure that the entire segment is delivered with the special flag(s) set which is how the Linux GRO is also implemented Signed-off-by: Kumara Parameshwaran --- If the received packet is not a pure ACK packet, we check if there are any previous packets in the flow, if present we indulge the received packet also in the coalescing logic and update the flags of the last recived packet to the entire segment which would avoid re-ordering. Lets say a case where P1(PSH), P2(ACK), P3(ACK) are received in burst mode, P1 contains PSH flag and since it does not contain any prior packets in the flow we copy it to unprocess_packets and P2(ACK) and P3(ACK) are merged together. In the existing case the P2,P3 would be delivered as single segment first and the unprocess_packets will be copied later which will cause reordering. With the patch copy the unprocess packets first and then the packets from the GRO table. Testing done The csum test-pmd was modified to support the following GET request of 10MB from client to server via test-pmd (static arp entries added in client and server). Enable GRO and TSO in test-pmd where the packets recived from the client mac would be sent to server mac and vice versa. In above testing, without the patch the client observerd re-ordering of 25 packets and with the patch there were no packet re-ordering observerd. v2: Fix warnings in commit and comment. Do not consider packet as candidate to merge if it contains SYN/RST flag. v3: Fix warnings. v4: Rebase with master. v5: Adding co-author email v6: Address review comments from the maintainer to restructure the code and handle only special flags PSH,FIN v7: Fix warnings and errors v8: Fix warnings and errors v9: Fix commit message v10: Update tcp header flags and address review comments v11: Fix warnings v12: Fix nit review comments lib/gro/gro_tcp.h | 9 +++++++ lib/gro/gro_tcp4.c | 48 ++++++++++++++++++++++++-------------- lib/gro/gro_tcp_internal.h | 2 +- lib/gro/gro_vxlan_tcp4.c | 5 ++-- 4 files changed, 44 insertions(+), 20 deletions(-) diff --git a/lib/gro/gro_tcp.h b/lib/gro/gro_tcp.h index d926c4b8cc..2c68b5f23e 100644 --- a/lib/gro/gro_tcp.h +++ b/lib/gro/gro_tcp.h @@ -19,6 +19,8 @@ #define INVALID_TCP_HDRLEN(len) \ (((len) < sizeof(struct rte_tcp_hdr)) || ((len) > MAX_TCP_HLEN)) +#define VALID_GRO_TCP_FLAGS (RTE_TCP_ACK_FLAG | RTE_TCP_PSH_FLAG | RTE_TCP_FIN_FLAG) + struct cmn_tcp_key { struct rte_ether_addr eth_saddr; struct rte_ether_addr eth_daddr; @@ -81,11 +83,13 @@ merge_two_tcp_packets(struct gro_tcp_item *item, struct rte_mbuf *pkt, int cmp, uint32_t sent_seq, + uint8_t tcp_flags, uint16_t ip_id, uint16_t l2_offset) { struct rte_mbuf *pkt_head, *pkt_tail, *lastseg; uint16_t hdr_len, l2_len; + struct rte_tcp_hdr *tcp_hdr; if (cmp > 0) { pkt_head = item->firstseg; @@ -128,6 +132,11 @@ merge_two_tcp_packets(struct gro_tcp_item *item, /* update MBUF metadata for the merged packet */ pkt_head->nb_segs += pkt_tail->nb_segs; pkt_head->pkt_len += pkt_tail->pkt_len; + if (tcp_flags != RTE_TCP_ACK_FLAG) { + tcp_hdr = rte_pktmbuf_mtod_offset(pkt, struct rte_tcp_hdr *, + l2_offset + pkt_head->l2_len + pkt_head->l3_len); + tcp_hdr->tcp_flags |= tcp_flags; + } return 1; } diff --git a/lib/gro/gro_tcp4.c b/lib/gro/gro_tcp4.c index 6645de592b..ad9cf04dbe 100644 --- a/lib/gro/gro_tcp4.c +++ b/lib/gro/gro_tcp4.c @@ -126,6 +126,7 @@ gro_tcp4_reassemble(struct rte_mbuf *pkt, uint32_t item_idx; uint32_t i, max_flow_num, remaining_flow_num; uint8_t find; + uint32_t item_start_idx; /* * Don't process the packet whose TCP header length is greater @@ -139,11 +140,8 @@ gro_tcp4_reassemble(struct rte_mbuf *pkt, tcp_hdr = (struct rte_tcp_hdr *)((char *)ipv4_hdr + pkt->l3_len); hdr_len = pkt->l2_len + pkt->l3_len + pkt->l4_len; - /* - * Don't process the packet which has FIN, SYN, RST, PSH, URG, ECE - * or CWR set. - */ - if (tcp_hdr->tcp_flags != RTE_TCP_ACK_FLAG) + /* Return early if the TCP flags are not handled in GRO layer */ + if (tcp_hdr->tcp_flags & ~VALID_GRO_TCP_FLAGS) return -1; /* trim the tail padding bytes */ @@ -183,25 +181,43 @@ gro_tcp4_reassemble(struct rte_mbuf *pkt, if (tbl->flows[i].start_index != INVALID_ARRAY_INDEX) { if (is_same_tcp4_flow(tbl->flows[i].key, key)) { find = 1; + item_start_idx = tbl->flows[i].start_index; break; } remaining_flow_num--; } } - if (find == 0) { + if (find == 1) { + /* + * Any packet with additional flags like PSH,FIN should be processed + * and flushed immediately. + * Hence marking the start time to 0, so that the packets will be flushed + * immediately in timer mode. + */ + if (tcp_hdr->tcp_flags & (RTE_TCP_ACK_FLAG | RTE_TCP_PSH_FLAG | RTE_TCP_FIN_FLAG)) { + if (tcp_hdr->tcp_flags != RTE_TCP_ACK_FLAG) + tbl->items[item_start_idx].start_time = 0; + return process_tcp_item(pkt, tcp_hdr, tcp_dl, tbl->items, tbl->flows[i].start_index, + &tbl->item_num, tbl->max_item_num, ip_id, is_atomic, start_time); + } else { + return -1; + } + } + /* + * Add new flow to the table only if contains ACK flag with data. + * Do not add any packets with additional tcp flags to the GRO table + */ + if (tcp_hdr->tcp_flags == RTE_TCP_ACK_FLAG) { sent_seq = rte_be_to_cpu_32(tcp_hdr->sent_seq); - item_idx = insert_new_tcp_item(pkt, tbl->items, &tbl->item_num, - tbl->max_item_num, start_time, - INVALID_ARRAY_INDEX, sent_seq, ip_id, - is_atomic); + item_idx = insert_new_tcp_item(pkt, tbl->items, &tbl->item_num, tbl->max_item_num, + start_time, INVALID_ARRAY_INDEX, sent_seq, ip_id, is_atomic); if (item_idx == INVALID_ARRAY_INDEX) return -1; - if (insert_new_flow(tbl, &key, item_idx) == - INVALID_ARRAY_INDEX) { + if (insert_new_flow(tbl, &key, item_idx) == INVALID_ARRAY_INDEX) { /* - * Fail to insert a new flow, so delete the - * stored packet. + * Fail to insert a new flow, so delete the + * stored packet. */ delete_tcp_item(tbl->items, item_idx, &tbl->item_num, INVALID_ARRAY_INDEX); return -1; @@ -209,9 +225,7 @@ gro_tcp4_reassemble(struct rte_mbuf *pkt, return 0; } - return process_tcp_item(pkt, tcp_hdr, tcp_dl, tbl->items, tbl->flows[i].start_index, - &tbl->item_num, tbl->max_item_num, - ip_id, is_atomic, start_time); + return -1; } /* diff --git a/lib/gro/gro_tcp_internal.h b/lib/gro/gro_tcp_internal.h index cc84abeaeb..e4855da1ad 100644 --- a/lib/gro/gro_tcp_internal.h +++ b/lib/gro/gro_tcp_internal.h @@ -101,7 +101,7 @@ process_tcp_item(struct rte_mbuf *pkt, is_atomic); if (cmp) { if (merge_two_tcp_packets(&items[cur_idx], - pkt, cmp, sent_seq, ip_id, 0)) + pkt, cmp, sent_seq, tcp_hdr->tcp_flags, ip_id, 0)) return 1; /* * Fail to merge the two packets, as the packet diff --git a/lib/gro/gro_vxlan_tcp4.c b/lib/gro/gro_vxlan_tcp4.c index 6ab7001922..8dd62a949c 100644 --- a/lib/gro/gro_vxlan_tcp4.c +++ b/lib/gro/gro_vxlan_tcp4.c @@ -239,10 +239,11 @@ merge_two_vxlan_tcp4_packets(struct gro_vxlan_tcp4_item *item, struct rte_mbuf *pkt, int cmp, uint32_t sent_seq, + uint8_t tcp_flags, uint16_t outer_ip_id, uint16_t ip_id) { - if (merge_two_tcp_packets(&item->inner_item, pkt, cmp, sent_seq, + if (merge_two_tcp_packets(&item->inner_item, pkt, cmp, sent_seq, tcp_flags, ip_id, pkt->outer_l2_len + pkt->outer_l3_len)) { /* Update the outer IPv4 ID to the large value. */ @@ -413,7 +414,7 @@ gro_vxlan_tcp4_reassemble(struct rte_mbuf *pkt, tcp_dl, outer_is_atomic, is_atomic); if (cmp) { if (merge_two_vxlan_tcp4_packets(&(tbl->items[cur_idx]), - pkt, cmp, sent_seq, + pkt, cmp, sent_seq, tcp_hdr->tcp_flags, outer_ip_id, ip_id)) return 1; /* -- 2.25.1