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 76290A0C45; Mon, 13 Sep 2021 16:09:22 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 60ABD40151; Mon, 13 Sep 2021 16:09:22 +0200 (CEST) Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) by mails.dpdk.org (Postfix) with ESMTP id 2C1974014F for ; Mon, 13 Sep 2021 16:09:21 +0200 (CEST) Received: by mail-wm1-f48.google.com with SMTP id l7-20020a1c2507000000b002e6be5d86b3so62026wml.3 for ; Mon, 13 Sep 2021 07:09:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id; bh=oeZ9empgrbszcne2NyAsHX2CYYfYbrUf20CiVEewAio=; b=LwHSXbOy4nuk5LYeupij7TbSi8zDn5YmWzwqYOu7FAr/ItALO61/OO5ArlsDmsHu9+ Bqfxv6yu4iV0O+XmoIZfCyH+X5I2LFtMPzSQSh5otjfT3Yo9srAN6H35iN7jmiObRMOX FEdXfw6NLilIO3NmKBK5fzqdUWSAP+E+QkVw9GNV15KybZ/Kn0m78R8czajz4mVj3xng KC2mAy+p7Ld72ns1wB0PfxNDQB9D5gLSihzKpGXZ8xLGXRUIejWrcYmkIyZ4o+vfwmtp JgR4cUlzMpWbHAE+MuKT0S6dQhsPNgHUpdubxOejUpBAVGYMgrU+CivME810V+1B74RR uMMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=oeZ9empgrbszcne2NyAsHX2CYYfYbrUf20CiVEewAio=; b=Y51OK6Wjb43kY//g0mjRFKrgwYdiZbKpjTRtXwmhaIuEXpjpT26kbTxNayFncVzP2R lmKxa1vQrW1Q2aMfuqRlSzQwUQNnud7E9JPK5G83w/9tOt4xpTAQTMaOmGb+TwoFUNnF C9vzKF87/wNQ7bgIe9Y9IPSPY1UBw5IN9vckWvq81iUwUq3RQNGjursuGRpQbjIQnH1l pQWGmRSAmmF2jbDVnhs/7Vqhn8gnoYafhBlBDUxpqxitxw+q4/lZjFDW/Da9Rcs+yN2O 4+jRKOs0jAOgsXP1IIH6hGg7PkZ1kM8bqxrNuw5LL72k/bBOYW28CUhH6om/MY4q0LCl zllQ== X-Gm-Message-State: AOAM532cEkxXbVyRWtXSuUfwD7oM1qg022GiiFlS5wh/uKJyRk6Vfm+E VFmUfyrpUxHVhQmn9/Iokl8= X-Google-Smtp-Source: ABdhPJw3edww/sho44A9Kbci0aGfl93qaK/ae4rwxJ8XHyY+Iwry/YTPcsTJEG5xwCZkVWvJiWLvUw== X-Received: by 2002:a1c:2057:: with SMTP id g84mr11485259wmg.140.1631542160931; Mon, 13 Sep 2021 07:09:20 -0700 (PDT) Received: from tucornea-dev-machine.localdomain ([193.226.172.44]) by smtp.gmail.com with ESMTPSA id u6sm9149058wrp.0.2021.09.13.07.09.20 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Sep 2021 07:09:20 -0700 (PDT) From: Tudor Cornea To: ferruh.yigit@intel.com Cc: linville@tuxdriver.com, thomas@monjalon.net, pogonarumihai@gmail.com, dev@dpdk.org, Tudor Cornea Date: Mon, 13 Sep 2021 17:09:11 +0300 Message-Id: <1631542151-62895-1-git-send-email-tudor.cornea@gmail.com> X-Mailer: git-send-email 2.7.4 Subject: [dpdk-dev] [PATCH] net/af_packet: remove timestamp from packet status 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" We should eliminate the timestamp status from the packet status. This should only matter if timestamping is enabled on the socket, but we might hit a kernel bug, which is fixed in newer releases. For interfaces of type 'veth', the sent skb is forwarded to the peer and back into the network stack which timestamps it on the RX path if timestamping is enabled globally (which happens if any socket enables timestamping). When the skb is destructed, tpacket_destruct_skb() is called and it calls __packet_set_timestamp() which doesn't check the flags on the socket and returns the timestamp if it is set in the skb (and for veth it is, as mentioned above). See the following kernel commit for reference [1]: net: packetmmap: fix only tx timestamp on request The packetmmap tx ring should only return timestamps if requested via setsockopt PACKET_TIMESTAMP, as documented. This allows compatibility with non-timestamp aware user-space code which checks tp_status == TP_STATUS_AVAILABLE; not expecting additional timestamp flags to be set in tp_status. [1] https://www.spinics.net/lists/kernel/msg3959391.html Signed-off-by: Mihai Pogonaru Signed-off-by: Tudor Cornea --- drivers/net/af_packet/rte_eth_af_packet.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c index b73b211..a6638a2 100644 --- a/drivers/net/af_packet/rte_eth_af_packet.c +++ b/drivers/net/af_packet/rte_eth_af_packet.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -167,6 +168,23 @@ eth_af_packet_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) return num_rx; } +static inline bool tx_ring_status_unavailable(uint32_t tp_status) +{ +#if KERNEL_VERSION(5, 10, 0) > LINUX_VERSION_CODE + /* + * We eliminate the timestamp status from the packet status. + * This should only matter if timestamping is enabled on the socket, + * but there is a bug in the kernel which is fixed in newer releases. + * + * See the following kernel commit for reference: + * commit 171c3b151118a2fe0fc1e2a9d1b5a1570cfe82d2 + * net: packetmmap: fix only tx timestamp on request + */ + tp_status &= ~(TP_STATUS_TS_SOFTWARE | TP_STATUS_TS_RAW_HARDWARE); +#endif + return tp_status != TP_STATUS_AVAILABLE; +} + /* * Callback to handle sending packets through a real NIC. */ @@ -212,8 +230,8 @@ eth_af_packet_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) } /* point at the next incoming frame */ - if ((ppd->tp_status != TP_STATUS_AVAILABLE) && - (poll(&pfd, 1, -1) < 0)) + if (tx_ring_status_unavailable(ppd->tp_status) && + poll(&pfd, 1, -1) < 0) break; /* copy the tx frame data */ -- 2.7.4