From patchwork Thu Sep 23 18:13:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tudor Cornea X-Patchwork-Id: 99499 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 9380FA0C43; Thu, 23 Sep 2021 20:13:39 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1D52741260; Thu, 23 Sep 2021 20:13:39 +0200 (CEST) Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) by mails.dpdk.org (Postfix) with ESMTP id 7A15F41257 for ; Thu, 23 Sep 2021 20:13:37 +0200 (CEST) Received: by mail-wr1-f46.google.com with SMTP id t8so19831071wri.1 for ; Thu, 23 Sep 2021 11:13:37 -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=J4gtSjEMx1I5p3JO7KwkXsIpDqsMPkz0U3EHqTjpbRQ=; b=OOdn9KYfgdSR6N1BYXT1y6n6NEUEqvXwop8juk3B9RLGlnzStN/em0x3rxnMvvlmfx foDN2KwdbvkDPqeIyImRShaHVG0n33TZ6bPfVhhlLuMI0FFrUG0LscAJT64a8MgE5ST3 tgP1oMgzNs+/nQ/yCDTmWMq8PZ8kkH3mumFyqBllNwwop2tdHCnyScGnnx+8ZiLF7zz8 cyCdl/BspZKmiaQc1JRDMx9STmttoiUTT0NePMBgFrdsJxpVFv65QELsrsA1wKqO2027 9tGgG0hFGGsptr5ntWPjwdDSB7unV+ZwTYTc5UHyQgQ+Nwbt36nLnxV2xINJVd41rsIU fPJg== 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=J4gtSjEMx1I5p3JO7KwkXsIpDqsMPkz0U3EHqTjpbRQ=; b=c+QLViAGBzvbRvLHO/nlUc8zYVQYmVYPdFQjNQkzkD/6B6COnksmXnrXRVMdsWxJID X1HV1cQoTr+cjyWttNk6sYDxXC3EadKV5gmpwcbm/Jw/7ky0vVWy1G9o9xHtJ+IPLx7K iZ43R1udNTJ3ls/x7kJjwCu/U2UJc44BG+ehSY96Ww7EqyPfxE8GhkzmB4mgFP9Vfc6w NCb4WomvqPB7SOnoXni6x7fuiiQcJb4SEIUjCeiQra7lXf7ZoqlhU+JWDKHkN5inlQN5 zV0vtOmPE2JKBebIA/JUBZYeSPoOnn/HwABKGewshbloGPqQeqWg9KdAq8nnTzKYCGT/ bzKQ== X-Gm-Message-State: AOAM531KeNE0t1sKtvTX+/NYhXHDsuHQGZoskSvOFVvRS94x3LJTRqz6 xNHQ66EeklBNtY2I/PpHOpY= X-Google-Smtp-Source: ABdhPJxc0NG/9E11Xv9eVOMrmIxvJk5leggXQR5EHYjiJgNuow9phkjKW//m3vAgKn9d60t3ItDuMQ== X-Received: by 2002:a5d:64cd:: with SMTP id f13mr6735793wri.419.1632420817186; Thu, 23 Sep 2021 11:13:37 -0700 (PDT) Received: from tucornea-dev-machine.localdomain ([193.226.172.43]) by smtp.gmail.com with ESMTPSA id o26sm9916237wmc.17.2021.09.23.11.13.36 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Sep 2021 11:13:36 -0700 (PDT) From: Tudor Cornea To: ferruh.yigit@intel.com Cc: stephen@networkplumber.org, linville@tuxdriver.com, thomas@monjalon.net, pogonarumihai@gmail.com, dev@dpdk.org, Tudor Cornea Date: Thu, 23 Sep 2021 21:13:24 +0300 Message-Id: <1632420804-398-1-git-send-email-tudor.cornea@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1631553801-75072-1-git-send-email-tudor.cornea@gmail.com> References: <1631553801-75072-1-git-send-email-tudor.cornea@gmail.com> Subject: [dpdk-dev] [PATCH v3] 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 Reviewed-by: Ferruh Yigit --- v3: * Place function name and parameters on a separate line. v2: * Remove compile-time check for kernel version --- drivers/net/af_packet/rte_eth_af_packet.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 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..fcd8090 100644 --- a/drivers/net/af_packet/rte_eth_af_packet.c +++ b/drivers/net/af_packet/rte_eth_af_packet.c @@ -168,6 +168,26 @@ eth_af_packet_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) } /* + * Check if there is an available frame in the ring + */ +static inline bool +tx_ring_status_available(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. */ static uint16_t @@ -212,8 +232,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_available(ppd->tp_status) && + poll(&pfd, 1, -1) < 0) break; /* copy the tx frame data */