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 742D445DA6; Tue, 26 Nov 2024 03:40:33 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0305F4025F; Tue, 26 Nov 2024 03:40:32 +0100 (CET) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id 21438400EF for ; Tue, 26 Nov 2024 03:40:29 +0100 (CET) Received: from mail.maildlp.com (unknown [172.19.162.254]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Xy6Fn4RK1zqSnl; Tue, 26 Nov 2024 10:38:37 +0800 (CST) Received: from dggpeml500011.china.huawei.com (unknown [7.185.36.84]) by mail.maildlp.com (Postfix) with ESMTPS id D63E8180216; Tue, 26 Nov 2024 10:40:27 +0800 (CST) Received: from [10.67.121.193] (10.67.121.193) by dggpeml500011.china.huawei.com (7.185.36.84) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Tue, 26 Nov 2024 10:40:27 +0800 Message-ID: <91eea669-6b30-47a4-bff2-c39cc7e2a20f@huawei.com> Date: Tue, 26 Nov 2024 10:40:27 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 3/3] net/hns3: fix Rx packet without CRC data Content-Language: en-US To: Stephen Hemminger , Jie Hai CC: , , , , Yisen Zhuang , "Wei Hu (Xavier)" , "Min Hu (Connor)" , , References: <20240206011030.2007689-1-haijie1@huawei.com> <20240719090415.1513301-1-haijie1@huawei.com> <20240719090415.1513301-4-haijie1@huawei.com> <20241125094503.2890b603@hermes.local> From: huangdengdui In-Reply-To: <20241125094503.2890b603@hermes.local> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.67.121.193] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpeml500011.china.huawei.com (7.185.36.84) 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 On 2024/11/26 1:45, Stephen Hemminger wrote: > On Fri, 19 Jul 2024 17:04:15 +0800 > Jie Hai wrote: > >> +static inline void >> +hns3_recalculate_crc(struct rte_mbuf *m) >> +{ >> + char *append_data; >> + uint32_t crc; >> + >> + crc = rte_net_crc_calc(rte_pktmbuf_mtod(m, void *), >> + m->data_len, RTE_NET_CRC32_ETH); >> + >> + /* >> + * The hns3 driver requires that mbuf size must be at least 512B. >> + * When CRC is stripped by hardware, the pkt_len must be less than >> + * or equal to 60B. Therefore, the space of the mbuf is enough >> + * to insert the CRC. >> + * >> + * In addition, after CRC is stripped by hardware, pkt_len and data_len >> + * do not contain the CRC length. Therefore, after CRC data is appended >> + * by PMD again, both pkt_len and data_len add the CRC length. >> + */ >> + append_data = rte_pktmbuf_append(m, RTE_NET_CRC32_ETH); >> + /* The CRC data is binary data and does not care about the byte order. */ >> + rte_memcpy(append_data, (void *)&crc, RTE_NET_CRC32_ETH); >> +} >> + > > There is a bug here. If there is no space at end of mbuf (tailroom) then > rte_pktmbuf_append will return NULL. This would only happen if mbuf pool > was sized such that there was space of a full size packet without CRC > and then the code to add kept CRC was executed. > > You need to check for NULL return and figure out some kind of unwind > path such as making it a receive error and dropping the packet. This situation has been described in the comments. The hns3 driver requires that mbuf size must be at least 512B.[1] When CRC needs to be recalculated, the packet length must be less than 60. So the space of the mbuf must be enough to insert the CRC. [1]:https://elixir.bootlin.com/dpdk/v23.11/source/drivers/net/hns3/hns3_rxtx.c#L1723