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 E637445DA7; Tue, 26 Nov 2024 04:16:58 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B851F4025F; Tue, 26 Nov 2024 04:16:58 +0100 (CET) Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by mails.dpdk.org (Postfix) with ESMTP id 97EE1400EF for ; Tue, 26 Nov 2024 04:16:56 +0100 (CET) Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-2124a86f4cbso46101225ad.3 for ; Mon, 25 Nov 2024 19:16:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1732591015; x=1733195815; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=9LE/cQVGUuVffPdn21Oiu9zv2liiOQev7u/j+JZ30vA=; b=o3JePuGprUufmuMck+NtItmohBX8uEuY+ZOH/qP8/cviOy0uXJxG1XZBdT1L3xSs4m YZSvBE721XVgjxnvYDa7Gwu+Nsg7gDLQKzPQziaBGI70qURgrlMqlUKxmjdbFE7GW4/Y nNT9Ufs9684oRwaB0/H5RaGoJ7nvZo7hO5U9s1FKczSGU0pbiq5eicb58NZrKbKdpyOx 7m8805SLO5H+ddg8Oj4S+aESZVQ+GTAq5MZCfyWVN9LpDBlvrBXS7T5ZISO+kUh9Kkxk znV8uePpwdGiH/hvMgww78pWH1gN2wEorOhQ92HTrjOszYT03XtZxMo29M2EICTE1aqc VlzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732591015; x=1733195815; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9LE/cQVGUuVffPdn21Oiu9zv2liiOQev7u/j+JZ30vA=; b=qAxjBW6RrOQyki6n2p72lDR0VetWPUoIWpgBS+e0ABdrizZIrHEkQ9QmsKWo1U3HDd 6ujQxFXrc19wPydN0DXNtA/ip8gANRVQIxaN+IAvmGQlou5QB+q85wCI3QC230vtNEfV 4yJFmqn4lcrNQtoJ6n2ggkTnC7NQeVRQ/HR0GoxsESLpvVGdn050vEjJMEQyL8FPR2Rw RQ6jKOCSYy5e4z6md536wVyF/yaPcV16rgmaaSMbxxQY8/0PEftK7HLGQpRXMrBQM6Zf 8JSiCsN0L98y8HDEHg88A8iTAiHz2gohGa8XV9DKS/y4f/SB2Gyb8Q1Z8qB++/+vGmm7 RZ2w== X-Forwarded-Encrypted: i=1; AJvYcCUcqy1+K5DVJx1KDKuBfnX26LmR2FvLq9SpqwUvPqjm8tMxPofahXMPyfVM0HaAofKxkA0=@dpdk.org X-Gm-Message-State: AOJu0YxG7MkE/5QuV7+sMQpS2BcIwQkK8hhzwVwPbEEnovPPQWyhJVJI RqYYOl6Gy/tO3EIaLxQq3lr8FmboW2HG0n2qwk5rer46wUpe05w18iqVVCHx8Rs= X-Gm-Gg: ASbGncucAr1anOA+VEvI85RZJe4OM7fUMIX5Qv2lHmd7LNNy/+5S0XVFD99gCElLlZP atZbO/Zy10rbqdVu+toRy6Oh5mjAAGIpEdbmUop9Cq5VAT/G1MB7K6DszMQ+36KuVMB5OkBXuHR aPIb98e/jqYw6dhESHbBFjNUwkmCGsA6KnDUQROkV1YOx3r51Ymg7F+Rk5pW0wz9cC/6aly9Y5Q 9x7GyDQDBir/WrHQkbot8zNslKHrNTBIekO2zOjFBe9gD43+Lo2J8nivjOCLbY67kTF1iDGhpxh 9aR0HJJb/t8V2lx0ffjm1i/ffy4= X-Google-Smtp-Source: AGHT+IHz0JQqzHktTI3PEqaa/o52rUKTdeMluiCEXt0f/qXIuQOMLRc6QW8i+XlUXJE3eQC3NwvZ3g== X-Received: by 2002:a17:902:e84f:b0:212:514:b30a with SMTP id d9443c01a7336-2129f72fa48mr234724775ad.12.1732591015333; Mon, 25 Nov 2024 19:16:55 -0800 (PST) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2129db87dbesm73312795ad.19.2024.11.25.19.16.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Nov 2024 19:16:55 -0800 (PST) Date: Mon, 25 Nov 2024 19:16:52 -0800 From: Stephen Hemminger To: huangdengdui Cc: Jie Hai , , , , , Yisen Zhuang , "Wei Hu (Xavier)" , "Min Hu (Connor)" , , Subject: Re: [PATCH v3 3/3] net/hns3: fix Rx packet without CRC data Message-ID: <20241125191652.50e06a7f@hermes.local> In-Reply-To: <91eea669-6b30-47a4-bff2-c39cc7e2a20f@huawei.com> References: <20240206011030.2007689-1-haijie1@huawei.com> <20240719090415.1513301-1-haijie1@huawei.com> <20240719090415.1513301-4-haijie1@huawei.com> <20241125094503.2890b603@hermes.local> <91eea669-6b30-47a4-bff2-c39cc7e2a20f@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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 Tue, 26 Nov 2024 10:40:27 +0800 huangdengdui wrote: > 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 Ok, but maybe add an RTE_ASSERT() to be safe.