From patchwork Mon Sep 13 17:23:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tudor Cornea X-Patchwork-Id: 98797 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id CBD13A0C45; Mon, 13 Sep 2021 19:23:34 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 25EFA40151; Mon, 13 Sep 2021 19:23:34 +0200 (CEST) Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) by mails.dpdk.org (Postfix) with ESMTP id CD1824014F for ; Mon, 13 Sep 2021 19:23:32 +0200 (CEST) Received: by mail-wm1-f51.google.com with SMTP id i3so7211274wmq.3 for ; Mon, 13 Sep 2021 10:23:32 -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:in-reply-to:references; bh=qI5wPd2K6HWrqbDq0q/iFqKq0u71o00094IjMUmlz8o=; b=WA8gYZBz+ERPDZpWgwQT6RZcn+ipfIoJAr/P1ZqrP3ONHKLdkzkN3G48/XeRN4NKJ5 EhsCIAwea16F+zKpaDDB8g3Jtf+ZWIhzqDeLwbE4Yz696QCOGEVr6Z6KOyFGyyIMRDoH iUfLKdARUXCUJoPYswBMJZ360IVz/cAjUuvl3M4e4kjcL/rd5BTFcb1+7Oliz9fpDIvu zqmZdufPALpeALB2ndeZTfpr8qyhuSt76lahynuqA09lY7tcqq5f+wIcnjq5V64ozM9a CfewQlC5k9uzTJlgw59UhtUvBfi6CeO9LgxZQE0LZrie7IFeSqrwfFq1LzG0FYvo08Qt nPqw== 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:in-reply-to :references; bh=qI5wPd2K6HWrqbDq0q/iFqKq0u71o00094IjMUmlz8o=; b=fd01jauiHog6vDh4OYHnbwfAwE8ReoCZ1hx9ZsJcSNPZ2UvSek5Y21/FNAiba9JhmZ P0fB7Di+0or+faCbjzNMbmEMUk3muwzLsv7DxDXDRcGQe5p11xggAD1F2f6N1ksIubEj QDMclcp9LD7TsPfCSpWNLui3x3RKh6LjAXHjHiB15JYtRgcNrNACHtX10VGEdVOuW0Me xFDHlUHk04ViEALw+xjAC1qeS0HKFPwSlarNSzhYE1dNioOAWCor9mGu0H8Tn6KVQp+l 4Lb8PWF4+8EXDY8/D130Eu1I+5fQEqIQ1/PLBiJvOztKLx7T4puem0/eHreVI+XMCaJu ZqIw== X-Gm-Message-State: AOAM530L4lDSZppO0G0a+17NwYBoo1/FXOwwQ8igXG3/mS8etm6WNrs0 WSNK42TCWnJqqBHxvGjuV6w= X-Google-Smtp-Source: ABdhPJyef3o/EOz4OyUAual+D4RYSi9VRjDrG/ztO2DnHB32zzb1Zflmd6IQgPAt7m/8yn1CGsrvBg== X-Received: by 2002:a1c:21c3:: with SMTP id h186mr12592017wmh.89.1631553812277; Mon, 13 Sep 2021 10:23:32 -0700 (PDT) Received: from tucornea-dev-machine.localdomain ([193.226.172.44]) by smtp.gmail.com with ESMTPSA id j23sm7422159wmo.14.2021.09.13.10.23.31 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Sep 2021 10:23:31 -0700 (PDT) From: Tudor Cornea To: stephen@networkplumber.org Cc: ferruh.yigit@intel.com, linville@tuxdriver.com, thomas@monjalon.net, pogonarumihai@gmail.com, dev@dpdk.org, Tudor Cornea Date: Mon, 13 Sep 2021 20:23:21 +0300 Message-Id: <1631553801-75072-1-git-send-email-tudor.cornea@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1631542151-62895-1-git-send-email-tudor.cornea@gmail.com> References: <1631542151-62895-1-git-send-email-tudor.cornea@gmail.com> Subject: [dpdk-dev] [PATCH v2] 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 --- v2: * Remove compile-time check for kernel version --- drivers/net/af_packet/rte_eth_af_packet.c | 20 ++++++++++++++++++-- 1 file changed, 18 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..7ecea4e 100644 --- a/drivers/net/af_packet/rte_eth_af_packet.c +++ b/drivers/net/af_packet/rte_eth_af_packet.c @@ -167,6 +167,22 @@ 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) +{ + /* + * 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); + + return tp_status != TP_STATUS_AVAILABLE; +} + /* * Callback to handle sending packets through a real NIC. */ @@ -212,8 +228,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 */