From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (xvm-189-124.dc0.ghst.net [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 91530A0524; Thu, 7 Jan 2021 21:42:48 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0F3A6140DBC; Thu, 7 Jan 2021 21:42:48 +0100 (CET) Received: from smtp-fw-6002.amazon.com (smtp-fw-6002.amazon.com [52.95.49.90]) by mails.dpdk.org (Postfix) with ESMTP id 60401140DB9 for ; Thu, 7 Jan 2021 21:42:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1610052167; x=1641588167; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=bjFqY9bibIV51ZV8e2me5/dlstsQqXO+GXfdkCiq0TU=; b=E+FHrw0wSlVInC8eFEQgOT77IIJFh5NriTkMU9g4tUHu8yFg3HLTaoxZ 6Nw7PkE+od86eGKT3wEL4qlAONosjuUKyG7UOjhobM8dl+dpS0N3B0zdJ rLw/AMQmsyv+zD/R9zTR0v1Q2HV/g30LpO+iZXB0aBnD4cJ5iGew1/ceQ Q=; X-IronPort-AV: E=Sophos;i="5.79,330,1602547200"; d="scan'208";a="76076492" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-2c-456ef9c9.us-west-2.amazon.com) ([10.43.8.2]) by smtp-border-fw-out-6002.iad6.amazon.com with ESMTP; 07 Jan 2021 20:42:45 +0000 Received: from EX13MTAUWC002.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan3.pdx.amazon.com [10.236.137.198]) by email-inbound-relay-2c-456ef9c9.us-west-2.amazon.com (Postfix) with ESMTPS id C3181ABBE6; Thu, 7 Jan 2021 20:42:42 +0000 (UTC) Received: from EX13D12UWC002.ant.amazon.com (10.43.162.253) by EX13MTAUWC002.ant.amazon.com (10.43.162.240) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 7 Jan 2021 20:42:42 +0000 Received: from AUS-1800118119.amazon.com (10.43.160.48) by EX13D12UWC002.ant.amazon.com (10.43.162.253) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 7 Jan 2021 20:42:40 +0000 From: George Prekas To: Wenzhuo Lu , Beilei Xing , Bernard Iremonger , Stephen Hemminger , Ferruh Yigit , "Harry van Haaren" CC: , George Prekas Date: Thu, 7 Jan 2021 14:42:28 -0600 Message-ID: <20210107204228.20934-1-prekageo@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201205054238.12469-1-prekageo@amazon.com> References: <20201205054238.12469-1-prekageo@amazon.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.43.160.48] X-ClientProxiedBy: EX13D50UWC004.ant.amazon.com (10.43.162.109) To EX13D12UWC002.ant.amazon.com (10.43.162.253) Subject: [dpdk-dev] [PATCH v3] app/testpmd: fix IP checksum calculation 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 Sender: "dev" Strict-aliasing rules are violated by cast to uint16_t* in flowgen.c and the calculated IP checksum is wrong. Use attribute __may_alias__ to fix the problem. Signed-off-by: George Prekas --- v3: * Instead of a compiler flag, use a compiler attribute. v2: * Instead of a compiler barrier, use a compiler flag. --- app/test-pmd/flowgen.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/test-pmd/flowgen.c b/app/test-pmd/flowgen.c index acf3e2460..cabfc688f 100644 --- a/app/test-pmd/flowgen.c +++ b/app/test-pmd/flowgen.c @@ -53,8 +53,11 @@ static struct rte_ether_addr cfg_ether_dst = #define IP_DEFTTL 64 /* from RFC 1340. */ +/* Use this type to inform GCC that ip_sum violates aliasing rules. */ +typedef unaligned_uint16_t alias_int16_t __attribute__((__may_alias__)); + static inline uint16_t -ip_sum(const unaligned_uint16_t *hdr, int hdr_len) +ip_sum(const alias_int16_t *hdr, int hdr_len) { uint32_t sum = 0; @@ -150,7 +153,7 @@ pkt_burst_flow_gen(struct fwd_stream *fs) next_flow); ip_hdr->total_length = RTE_CPU_TO_BE_16(pkt_size - sizeof(*eth_hdr)); - ip_hdr->hdr_checksum = ip_sum((unaligned_uint16_t *)ip_hdr, + ip_hdr->hdr_checksum = ip_sum((const alias_int16_t *)ip_hdr, sizeof(*ip_hdr)); /* Initialize UDP header. */ -- 2.17.1