From: Stephen Hemminger <stephen@networkplumber.org>
To: huangdengdui <huangdengdui@huawei.com>
Cc: Jie Hai <haijie1@huawei.com>, <dev@dpdk.org>,
<ferruh.yigit@amd.com>, <mb@smartsharesystems.com>,
<andrew.rybchenko@oktetlabs.ru>,
Yisen Zhuang <yisen.zhuang@huawei.com>,
"Wei Hu (Xavier)" <xavier.huwei@huawei.com>,
"Min Hu (Connor)" <humin29@huawei.com>, <fengchengwen@huawei.com>,
<lihuisong@huawei.com>
Subject: Re: [PATCH v3 3/3] net/hns3: fix Rx packet without CRC data
Date: Mon, 25 Nov 2024 19:16:52 -0800 [thread overview]
Message-ID: <20241125191652.50e06a7f@hermes.local> (raw)
In-Reply-To: <91eea669-6b30-47a4-bff2-c39cc7e2a20f@huawei.com>
On Tue, 26 Nov 2024 10:40:27 +0800
huangdengdui <huangdengdui@huawei.com> wrote:
> On 2024/11/26 1:45, Stephen Hemminger wrote:
> > On Fri, 19 Jul 2024 17:04:15 +0800
> > Jie Hai <haijie1@huawei.com> 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
Ok, but maybe add an RTE_ASSERT() to be safe.
next prev parent reply other threads:[~2024-11-26 3:16 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-06 1:10 [PATCH] net/hns3: fix Rx packet truncation when KEEP CRC enabled Jie Hai
2024-02-07 14:15 ` Ferruh Yigit
2024-02-20 3:58 ` Jie Hai
2024-02-23 13:53 ` Ferruh Yigit
2024-02-26 3:16 ` Jie Hai
2024-02-26 16:43 ` Ferruh Yigit
2024-02-28 2:27 ` huangdengdui
2024-02-28 13:07 ` Ferruh Yigit
2024-02-29 3:58 ` huangdengdui
2024-02-29 9:25 ` Ferruh Yigit
2024-03-01 6:55 ` huangdengdui
2024-03-01 11:10 ` Ferruh Yigit
2024-03-08 11:36 ` Jie Hai
2024-03-22 6:28 ` Jie Hai
2024-06-03 1:38 ` Jie Hai
2024-06-03 2:33 ` Stephen Hemminger
2024-06-03 5:24 ` Morten Brørup
2024-06-03 7:07 ` Andrew Rybchenko
2024-07-18 11:48 ` [PATCH v2 0/3] bugfix about KEEP CRC offload Jie Hai
2024-07-18 11:48 ` [PATCH v2 1/3] ethdev: add description for " Jie Hai
2024-07-18 11:57 ` Morten Brørup
2024-07-18 11:48 ` [PATCH v2 2/3] net/hns3: fix packet length do not contain CRC data length Jie Hai
2024-07-18 11:48 ` [PATCH v2 3/3] net/hns3: fix Rx packet without CRC data Jie Hai
2024-11-26 23:17 ` [RFC] net/hns3: clarify handling of crc reinsert Stephen Hemminger
2024-07-18 12:35 ` [PATCH v2 0/3] bugfix about KEEP CRC offload lihuisong (C)
2024-11-26 23:12 ` Stephen Hemminger
2024-07-19 9:04 ` [PATCH v3 " Jie Hai
2024-07-19 9:04 ` [PATCH v3 1/3] ethdev: add description for " Jie Hai
2024-09-05 6:33 ` Andrew Rybchenko
2024-11-22 17:10 ` Stephen Hemminger
2024-11-26 7:47 ` Jie Hai
2024-11-26 23:51 ` Stephen Hemminger
2024-11-22 17:35 ` Stephen Hemminger
2024-07-19 9:04 ` [PATCH v3 2/3] net/hns3: fix packet length do not contain CRC data length Jie Hai
2024-07-19 9:04 ` [PATCH v3 3/3] net/hns3: fix Rx packet without CRC data Jie Hai
2024-11-24 19:42 ` Stephen Hemminger
2024-11-25 17:45 ` Stephen Hemminger
2024-11-26 2:40 ` huangdengdui
2024-11-26 3:16 ` Stephen Hemminger [this message]
2024-11-27 0:16 ` Stephen Hemminger
2024-11-27 2:32 ` Jie Hai
2024-11-27 3:21 ` Stephen Hemminger
2024-07-19 9:49 ` [PATCH v3 0/3] bugfix about KEEP CRC offload fengchengwen
2024-08-09 9:21 ` Jie Hai
2024-09-05 2:53 ` Jie Hai
2024-10-18 1:39 ` Jie Hai
2024-11-06 2:19 ` Jie Hai
2024-11-13 3:14 ` Jie Hai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241125191652.50e06a7f@hermes.local \
--to=stephen@networkplumber.org \
--cc=andrew.rybchenko@oktetlabs.ru \
--cc=dev@dpdk.org \
--cc=fengchengwen@huawei.com \
--cc=ferruh.yigit@amd.com \
--cc=haijie1@huawei.com \
--cc=huangdengdui@huawei.com \
--cc=humin29@huawei.com \
--cc=lihuisong@huawei.com \
--cc=mb@smartsharesystems.com \
--cc=xavier.huwei@huawei.com \
--cc=yisen.zhuang@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).