From patchwork Mon Feb 8 18:55:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Willem de Bruijn X-Patchwork-Id: 12076291 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D3F1BC433DB for ; Mon, 8 Feb 2021 18:58:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 81F9464E84 for ; Mon, 8 Feb 2021 18:58:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235938AbhBHS6m (ORCPT ); Mon, 8 Feb 2021 13:58:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235853AbhBHS5T (ORCPT ); Mon, 8 Feb 2021 13:57:19 -0500 Received: from mail-qk1-x72f.google.com (mail-qk1-x72f.google.com [IPv6:2607:f8b0:4864:20::72f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 208CBC061793 for ; Mon, 8 Feb 2021 10:56:03 -0800 (PST) Received: by mail-qk1-x72f.google.com with SMTP id r77so15475271qka.12 for ; Mon, 08 Feb 2021 10:56:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3J632UJbPXnW5jI7wLWLk7WvFrwdIcMwbkqpeY3vEL0=; b=Hoeu2zQdI95fmHYt1Fbz/whuJT9ICgJQ4y2smIelFESDm8DEs611ZSYNwf07OvRVEX q4iGtBQ6lEoS177Lu/di72pvOwyjmg62sTw9yC08S9HI5XIUmNPTLlnvo1P6SF2oI5To HfDmNI9Twgyv+v+vi8HrWiGqf4mV8sp6LP1ekPArBPefX//UduLN9wZCd8HBKJqrkH74 8MONE6165vfthDl/SpTP9D8FOuh24U5HtlrcUbFItepW9EOPnVbPBU5/tEMvWLRmmNvk zVtBjKDMg1ocZ7Mv98jOqMHMS6lUGOeSf04a4N8S3aYPwuGlMqxrqFr+Hq8nJfVKbJGL 6+Pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3J632UJbPXnW5jI7wLWLk7WvFrwdIcMwbkqpeY3vEL0=; b=IuWlJIaofsn+y13yx/2/ANs90O7GJmmRvvlvPQPx3xKp5DyRcMxrWHvfwWKUmOi8Dd IjSmheXE3UZAwGxZOrPHyqnWG/Y2VnydgGIGsD5yoA7rqs54Sx4ga2L2Z2JjnGcWXFEr tL/6VdJhl+EpTH+rDcLF6MCUu8kCGzjTCI6P8/SceTVqdQ4x/vyxAoBMANiRQucOyglJ X4fQv1K3m4NcukHMvhaDxC9M0/fmaNrK9Zf5Xi49++dB5EG1hifiDdEZZdEsEUBp/mFK q9ovst1P+h8TDe76CdyP8l8B5zr33+b/BEPnHob1owKWiHRP9wNe077gr+WTSZ8W9chM oqBA== X-Gm-Message-State: AOAM5313e+0gLcKemM9uBhqh7rMh0Ua0kgouQLIfkwURE+oqa8BnTuwK hMi2+X6d9Jmn0WItpuxiU6A= X-Google-Smtp-Source: ABdhPJxtmh1c+353FOHWeHvBtBodf+fk30pSohJV/0pPlUJ59vA/v8TDJKFt/PU9z5CWg8UXQ9WDIQ== X-Received: by 2002:a37:434c:: with SMTP id q73mr18683570qka.170.1612810562384; Mon, 08 Feb 2021 10:56:02 -0800 (PST) Received: from willemb.nyc.corp.google.com ([2620:0:1003:312:f109:45d3:805f:3b83]) by smtp.gmail.com with ESMTPSA id q25sm17370744qkq.32.2021.02.08.10.56.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Feb 2021 10:56:01 -0800 (PST) From: Willem de Bruijn To: virtualization@lists.linux-foundation.org Cc: netdev@vger.kernel.org, mst@redhat.com, jasowang@redhat.com, richardcochran@gmail.com, Willem de Bruijn Subject: [PATCH RFC v2 1/4] virtio-net: support transmit hash report Date: Mon, 8 Feb 2021 13:55:55 -0500 Message-Id: <20210208185558.995292-2-willemdebruijn.kernel@gmail.com> X-Mailer: git-send-email 2.30.0.478.g8a0d178c01-goog In-Reply-To: <20210208185558.995292-1-willemdebruijn.kernel@gmail.com> References: <20210208185558.995292-1-willemdebruijn.kernel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC From: Willem de Bruijn Virtio-net supports sharing the flow hash from device to driver on rx. Do the same in the other direction for robust routing and telemetry. Linux derives ipv6 flowlabel and ECMP multipath from sk->sk_txhash, and updates this field on error with sk_rethink_txhash. Allow the host stack to do the same. Concrete examples of error conditions that are resolved are mentioned in the commits that add sk_rethink_txhash calls. Such as commit 7788174e8726 ("tcp: change IPv6 flow-label upon receiving spurious retransmission"). Experimental results mirror what the theory suggests: where IPv6 FlowLabel is included in path selection (e.g., LAG/ECMP), flowlabel rotation on TCP timeout avoids the vast majority of TCP disconnects that would otherwise have occurred during link failures in long-haul backbones, when an alternative path is available. Rotation can be applied to various bad connection signals, such as timeouts and spurious retransmissions. In aggregate, such flow level signals can help locate network issues. Reserve field hash_state to share this info. For now, always set VIRTIO_NET_HASH_STATE_DEFAULT. Passing information between TCP stack and driver is future work. Changes RFC->RFCv2 - drop unused VIRTIO_NET_HASH_STATE_TIMEOUT_BIT - convert from cpu_to_virtioXX to cpu_to_leXX Signed-off-by: Willem de Bruijn --- drivers/net/virtio_net.c | 26 +++++++++++++++++++++++--- include/uapi/linux/virtio_net.h | 9 ++++++++- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index ba8e63792549..7f822b2a5205 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -201,6 +201,9 @@ struct virtnet_info { /* Host will merge rx buffers for big packets (shake it! shake it!) */ bool mergeable_rx_bufs; + /* Driver will pass tx path info to the device */ + bool has_tx_hash; + /* Has control virtqueue */ bool has_cvq; @@ -394,9 +397,9 @@ static struct sk_buff *page_to_skb(struct virtnet_info *vi, hdr_len = vi->hdr_len; if (vi->mergeable_rx_bufs) - hdr_padded_len = sizeof(*hdr); + hdr_padded_len = max_t(unsigned int, hdr_len, sizeof(*hdr)); else - hdr_padded_len = sizeof(struct padded_vnet_hdr); + hdr_padded_len = ALIGN(hdr_len, 16); /* hdr_valid means no XDP, so we can copy the vnet header */ if (hdr_valid) @@ -1528,6 +1531,7 @@ static int xmit_skb(struct send_queue *sq, struct sk_buff *skb) struct virtio_net_hdr_mrg_rxbuf *hdr; const unsigned char *dest = ((struct ethhdr *)skb->data)->h_dest; struct virtnet_info *vi = sq->vq->vdev->priv; + struct virtio_net_hdr_v1_hash *ht; int num_sg; unsigned hdr_len = vi->hdr_len; bool can_push; @@ -1552,6 +1556,16 @@ static int xmit_skb(struct send_queue *sq, struct sk_buff *skb) if (vi->mergeable_rx_bufs) hdr->num_buffers = 0; + ht = (void *)hdr; + if (vi->has_tx_hash) { + u16 report = skb->l4_hash ? VIRTIO_NET_HASH_REPORT_L4 : + VIRTIO_NET_HASH_REPORT_OTHER; + + ht->hash_value = cpu_to_le32(skb->hash); + ht->hash_report = cpu_to_le16(report); + ht->hash_state = cpu_to_le16(VIRTIO_NET_HASH_STATE_DEFAULT); + } + sg_init_table(sq->sg, skb_shinfo(skb)->nr_frags + (can_push ? 1 : 2)); if (can_push) { __skb_push(skb, hdr_len); @@ -3050,6 +3064,11 @@ static int virtnet_probe(struct virtio_device *vdev) else vi->hdr_len = sizeof(struct virtio_net_hdr); + if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_TX_HASH)) { + vi->has_tx_hash = true; + vi->hdr_len = sizeof(struct virtio_net_hdr_v1_hash); + } + if (virtio_has_feature(vdev, VIRTIO_F_ANY_LAYOUT) || virtio_has_feature(vdev, VIRTIO_F_VERSION_1)) vi->any_header_sg = true; @@ -3240,7 +3259,8 @@ static struct virtio_device_id id_table[] = { VIRTIO_NET_F_GUEST_ANNOUNCE, VIRTIO_NET_F_MQ, \ VIRTIO_NET_F_CTRL_MAC_ADDR, \ VIRTIO_NET_F_MTU, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS, \ - VIRTIO_NET_F_SPEED_DUPLEX, VIRTIO_NET_F_STANDBY + VIRTIO_NET_F_SPEED_DUPLEX, VIRTIO_NET_F_STANDBY, \ + VIRTIO_NET_F_TX_HASH static unsigned int features[] = { VIRTNET_FEATURES, diff --git a/include/uapi/linux/virtio_net.h b/include/uapi/linux/virtio_net.h index 3f55a4215f11..273d43c35f59 100644 --- a/include/uapi/linux/virtio_net.h +++ b/include/uapi/linux/virtio_net.h @@ -57,6 +57,7 @@ * Steering */ #define VIRTIO_NET_F_CTRL_MAC_ADDR 23 /* Set MAC address */ +#define VIRTIO_NET_F_TX_HASH 56 /* Driver sends hash report */ #define VIRTIO_NET_F_HASH_REPORT 57 /* Supports hash report */ #define VIRTIO_NET_F_RSS 60 /* Supports RSS RX steering */ #define VIRTIO_NET_F_RSC_EXT 61 /* extended coalescing info */ @@ -170,8 +171,14 @@ struct virtio_net_hdr_v1_hash { #define VIRTIO_NET_HASH_REPORT_IPv6_EX 7 #define VIRTIO_NET_HASH_REPORT_TCPv6_EX 8 #define VIRTIO_NET_HASH_REPORT_UDPv6_EX 9 +#define VIRTIO_NET_HASH_REPORT_L4 10 +#define VIRTIO_NET_HASH_REPORT_OTHER 11 __le16 hash_report; - __le16 padding; + union { + __le16 padding; +#define VIRTIO_NET_HASH_STATE_DEFAULT 0 + __le16 hash_state; + }; }; #ifndef VIRTIO_NET_NO_LEGACY From patchwork Mon Feb 8 18:55:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Willem de Bruijn X-Patchwork-Id: 12076293 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CF247C433E6 for ; Mon, 8 Feb 2021 18:59:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 949C564E59 for ; Mon, 8 Feb 2021 18:59:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235907AbhBHS7N (ORCPT ); Mon, 8 Feb 2021 13:59:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235855AbhBHS5T (ORCPT ); Mon, 8 Feb 2021 13:57:19 -0500 Received: from mail-qk1-x732.google.com (mail-qk1-x732.google.com [IPv6:2607:f8b0:4864:20::732]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85DD6C061794 for ; Mon, 8 Feb 2021 10:56:04 -0800 (PST) Received: by mail-qk1-x732.google.com with SMTP id a19so15562733qka.2 for ; Mon, 08 Feb 2021 10:56:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6yp0IdRYkYzaakKnjWKVwWGjwkouMnyOp2X0i4UzkZ0=; b=YZ7pq/JELCAMrvVF/yN1Bn3gZ66+44ob9zGxCVxpgwsu/pfqezXRPJaYyUY5iqnO1j 33+XJ/5u2iBfg09D+VXHbcI7moHy59uyDmlmJKkGZmJwRmNQ4NWjuUpIk7WrQDjF2ztz qemTAaaJ1MOks2gLOtxcrHHMOPSXB8/GvVIa1+gjkV0+Tru+Hm6io7nE0e06lKlfEFse TVm9U9C7580imrSt9o3+eLYkHVf9aJKk7Bku9O05QwuAwu2574yO5WlXiwOy1xJqfhP9 NIvlV9kuQS4zSlJlXHFkvoikvFB9Z6AYFMxBdcvLazVl1srR5Ea3xcSjdtQRwiJR9uLQ Qe/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6yp0IdRYkYzaakKnjWKVwWGjwkouMnyOp2X0i4UzkZ0=; b=BixfLrnTE6+j3G4r5TL4WCKrOG5qvmDfNZZJy0qf4ALgnqHMu5cUjwpeUaZHvu2z+j Lgqbkml98ol7KH2EcgEdoRUM1i+qBRCj/GhKE0hPOAHBzc9C0gJ2pJhzbJV1n7bKYD5+ OKhgWs6I+8aXU6nhcUx3U9CnGUVPtgvVPKa/BmT4CSQRbUT0BT91/EyAadaeDtLHWq1l 1D2PpPKchcZPbhn9ds0X+/rc3fJwiWlE0VUAYrdAPqyQT5dZjDZAhatNi5bcPo/U0Skl Lt24LPcjqrvR8Ihxb+VJ9i/IFZYjxaNV79KQQcMjikPgxRsXRhnr8njJlfDmGIsaTRak 3UDQ== X-Gm-Message-State: AOAM5333f7cW51KOZpf2UnC7IplpzzExJksE6R7i3WVOJ2HZWY+zWdwi w/NsJPlyxa4cT+BEShLtei4= X-Google-Smtp-Source: ABdhPJzV/bknCKSI+lU+s+mQaoJmC0IkuL4JRBp8F4sjN9v2OAZi6u7eW43q1hmKSGDPcc/OwtwpwQ== X-Received: by 2002:a37:aa09:: with SMTP id t9mr17716911qke.214.1612810563753; Mon, 08 Feb 2021 10:56:03 -0800 (PST) Received: from willemb.nyc.corp.google.com ([2620:0:1003:312:f109:45d3:805f:3b83]) by smtp.gmail.com with ESMTPSA id q25sm17370744qkq.32.2021.02.08.10.56.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Feb 2021 10:56:02 -0800 (PST) From: Willem de Bruijn To: virtualization@lists.linux-foundation.org Cc: netdev@vger.kernel.org, mst@redhat.com, jasowang@redhat.com, richardcochran@gmail.com, Willem de Bruijn Subject: [PATCH RFC v2 2/4] virtio-net: support receive timestamp Date: Mon, 8 Feb 2021 13:55:56 -0500 Message-Id: <20210208185558.995292-3-willemdebruijn.kernel@gmail.com> X-Mailer: git-send-email 2.30.0.478.g8a0d178c01-goog In-Reply-To: <20210208185558.995292-1-willemdebruijn.kernel@gmail.com> References: <20210208185558.995292-1-willemdebruijn.kernel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC From: Willem de Bruijn Add optional PTP hardware rx timestamp offload for virtio-net. Accurate RTT measurement requires timestamps close to the wire. Introduce virtio feature VIRTIO_NET_F_RX_TSTAMP. If negotiated, the virtio-net header is expanded with room for a timestamp. A device may pass receive timestamps for all or some packets. Flag VIRTIO_NET_HDR_F_TSTAMP signals whether a timestamp is recorded. A driver that supports hardware timestamping must also support ioctl SIOCSHWTSTAMP. Implement that, as well as information getters ioctl SIOCGHWTSTAMP and ethtool get_ts_info (`ethtool -T $DEV`). The timestamp straddles (virtual) hardware domains. Like PTP, use international atomic time (CLOCK_TAI) as global clock base. The driver must sync with the device, e.g., through kvm-clock. Tested: guest: ./timestamping eth0 \ SOF_TIMESTAMPING_RAW_HARDWARE \ SOF_TIMESTAMPING_RX_HARDWARE host: nc -4 -u 192.168.1.1 319 Changes RFC -> RFCv2 - rename virtio_net_hdr_v12 to virtio_net_hdr_hash_ts - add ethtool .get_ts_info to query capabilities - add ioctl SIOC[GS]HWTSTAMP to configure feature - add vi->enable_rx_tstamp to store configuration - convert virtioXX_to_cpu to leXX_to_cpu - convert reserved to __u32 Signed-off-by: Willem de Bruijn --- drivers/net/virtio_net.c | 113 +++++++++++++++++++++++++++++++- include/uapi/linux/virtio_net.h | 13 ++++ 2 files changed, 124 insertions(+), 2 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 7f822b2a5205..ac44c5efa0bc 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -204,6 +204,12 @@ struct virtnet_info { /* Driver will pass tx path info to the device */ bool has_tx_hash; + /* Device can pass CLOCK_TAI receive time to the driver */ + bool has_rx_tstamp; + + /* Device will pass rx timestamp. Requires has_rx_tstamp */ + bool enable_rx_tstamp; + /* Has control virtqueue */ bool has_cvq; @@ -292,6 +298,13 @@ static inline struct virtio_net_hdr_mrg_rxbuf *skb_vnet_hdr(struct sk_buff *skb) return (struct virtio_net_hdr_mrg_rxbuf *)skb->cb; } +static inline struct virtio_net_hdr_hash_ts *skb_vnet_hdr_ht(struct sk_buff *skb) +{ + BUILD_BUG_ON(sizeof(struct virtio_net_hdr_hash_ts) > sizeof(skb->cb)); + + return (void *)skb->cb; +} + /* * private is used to chain pages for big packets, put the whole * most recent used list in the beginning for reuse @@ -1030,6 +1043,19 @@ static struct sk_buff *receive_mergeable(struct net_device *dev, return NULL; } +static inline void virtnet_record_rx_tstamp(const struct virtnet_info *vi, + struct sk_buff *skb) +{ + const struct virtio_net_hdr_hash_ts *h = skb_vnet_hdr_ht(skb); + + if (h->hdr.flags & VIRTIO_NET_HDR_F_TSTAMP && + vi->enable_rx_tstamp) { + u64 ts = le64_to_cpu(h->tstamp); + + skb_hwtstamps(skb)->hwtstamp = ns_to_ktime(ts); + } +} + static void receive_buf(struct virtnet_info *vi, struct receive_queue *rq, void *buf, unsigned int len, void **ctx, unsigned int *xdp_xmit, @@ -1076,6 +1102,7 @@ static void receive_buf(struct virtnet_info *vi, struct receive_queue *rq, goto frame_err; } + virtnet_record_rx_tstamp(vi, skb); skb_record_rx_queue(skb, vq2rxq(rq->vq)); skb->protocol = eth_type_trans(skb, dev); pr_debug("Receiving skb proto 0x%04x len %i type %i\n", @@ -2263,6 +2290,28 @@ static int virtnet_get_coalesce(struct net_device *dev, return 0; } +static int virtnet_get_ts_info(struct net_device *dev, + struct ethtool_ts_info *info) +{ + struct virtnet_info *vi = netdev_priv(dev); + + /* setup default software timestamp */ + ethtool_op_get_ts_info(dev, info); + + /* return rx capabilities (which may differ from current enable) */ + if (vi->has_rx_tstamp) { + info->so_timestamping |= SOF_TIMESTAMPING_RX_HARDWARE | + SOF_TIMESTAMPING_RAW_HARDWARE; + info->rx_filters = HWTSTAMP_FILTER_ALL; + } else { + info->rx_filters = HWTSTAMP_FILTER_NONE; + } + + info->tx_types = HWTSTAMP_TX_OFF; + + return 0; +} + static void virtnet_init_settings(struct net_device *dev) { struct virtnet_info *vi = netdev_priv(dev); @@ -2300,7 +2349,7 @@ static const struct ethtool_ops virtnet_ethtool_ops = { .get_ethtool_stats = virtnet_get_ethtool_stats, .set_channels = virtnet_set_channels, .get_channels = virtnet_get_channels, - .get_ts_info = ethtool_op_get_ts_info, + .get_ts_info = virtnet_get_ts_info, .get_link_ksettings = virtnet_get_link_ksettings, .set_link_ksettings = virtnet_set_link_ksettings, .set_coalesce = virtnet_set_coalesce, @@ -2558,6 +2607,60 @@ static int virtnet_set_features(struct net_device *dev, return 0; } +static int virtnet_ioctl_set_hwtstamp(struct net_device *dev, struct ifreq *ifr) +{ + struct virtnet_info *vi = netdev_priv(dev); + struct hwtstamp_config tsconf; + + if (copy_from_user(&tsconf, ifr->ifr_data, sizeof(tsconf))) + return -EFAULT; + if (tsconf.flags) + return -EINVAL; + if (tsconf.tx_type != HWTSTAMP_TX_OFF) + return -ERANGE; + if (tsconf.rx_filter != HWTSTAMP_FILTER_NONE && + tsconf.rx_filter != HWTSTAMP_FILTER_ALL) + tsconf.rx_filter = HWTSTAMP_FILTER_ALL; + + if (!vi->has_rx_tstamp) + tsconf.rx_filter = HWTSTAMP_FILTER_NONE; + else + vi->enable_rx_tstamp = tsconf.rx_filter == HWTSTAMP_FILTER_ALL; + + if (copy_to_user(ifr->ifr_data, &tsconf, sizeof(tsconf))) + return -EFAULT; + + return 0; +} + +static int virtnet_ioctl_get_hwtstamp(struct net_device *dev, struct ifreq *ifr) +{ + struct virtnet_info *vi = netdev_priv(dev); + struct hwtstamp_config tsconf; + + tsconf.flags = 0; + tsconf.rx_filter = vi->enable_rx_tstamp ? HWTSTAMP_FILTER_ALL : + HWTSTAMP_FILTER_NONE; + tsconf.tx_type = HWTSTAMP_TX_OFF; + + if (copy_to_user(ifr->ifr_data, &tsconf, sizeof(tsconf))) + return -EFAULT; + + return 0; +} + +static int virtnet_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) +{ + switch (cmd) { + case SIOCSHWTSTAMP: + return virtnet_ioctl_set_hwtstamp(dev, ifr); + + case SIOCGHWTSTAMP: + return virtnet_ioctl_get_hwtstamp(dev, ifr); + } + return -EOPNOTSUPP; +} + static const struct net_device_ops virtnet_netdev = { .ndo_open = virtnet_open, .ndo_stop = virtnet_close, @@ -2573,6 +2676,7 @@ static const struct net_device_ops virtnet_netdev = { .ndo_features_check = passthru_features_check, .ndo_get_phys_port_name = virtnet_get_phys_port_name, .ndo_set_features = virtnet_set_features, + .ndo_do_ioctl = virtnet_ioctl, }; static void virtnet_config_changed_work(struct work_struct *work) @@ -3069,6 +3173,11 @@ static int virtnet_probe(struct virtio_device *vdev) vi->hdr_len = sizeof(struct virtio_net_hdr_v1_hash); } + if (virtio_has_feature(vdev, VIRTIO_NET_F_RX_TSTAMP)) { + vi->has_rx_tstamp = true; + vi->hdr_len = sizeof(struct virtio_net_hdr_hash_ts); + } + if (virtio_has_feature(vdev, VIRTIO_F_ANY_LAYOUT) || virtio_has_feature(vdev, VIRTIO_F_VERSION_1)) vi->any_header_sg = true; @@ -3260,7 +3369,7 @@ static struct virtio_device_id id_table[] = { VIRTIO_NET_F_CTRL_MAC_ADDR, \ VIRTIO_NET_F_MTU, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS, \ VIRTIO_NET_F_SPEED_DUPLEX, VIRTIO_NET_F_STANDBY, \ - VIRTIO_NET_F_TX_HASH + VIRTIO_NET_F_TX_HASH, VIRTIO_NET_F_RX_TSTAMP static unsigned int features[] = { VIRTNET_FEATURES, diff --git a/include/uapi/linux/virtio_net.h b/include/uapi/linux/virtio_net.h index 273d43c35f59..a5c84410cf92 100644 --- a/include/uapi/linux/virtio_net.h +++ b/include/uapi/linux/virtio_net.h @@ -57,6 +57,7 @@ * Steering */ #define VIRTIO_NET_F_CTRL_MAC_ADDR 23 /* Set MAC address */ +#define VIRTIO_NET_F_RX_TSTAMP 55 /* Device sends TAI receive time */ #define VIRTIO_NET_F_TX_HASH 56 /* Driver sends hash report */ #define VIRTIO_NET_F_HASH_REPORT 57 /* Supports hash report */ #define VIRTIO_NET_F_RSS 60 /* Supports RSS RX steering */ @@ -126,6 +127,7 @@ struct virtio_net_hdr_v1 { #define VIRTIO_NET_HDR_F_NEEDS_CSUM 1 /* Use csum_start, csum_offset */ #define VIRTIO_NET_HDR_F_DATA_VALID 2 /* Csum is valid */ #define VIRTIO_NET_HDR_F_RSC_INFO 4 /* rsc info in csum_ fields */ +#define VIRTIO_NET_HDR_F_TSTAMP 8 /* timestamp is recorded */ __u8 flags; #define VIRTIO_NET_HDR_GSO_NONE 0 /* Not a GSO frame */ #define VIRTIO_NET_HDR_GSO_TCPV4 1 /* GSO frame, IPv4 TCP (TSO) */ @@ -181,6 +183,17 @@ struct virtio_net_hdr_v1_hash { }; }; +struct virtio_net_hdr_hash_ts { + struct virtio_net_hdr_v1 hdr; + struct { + __le32 value; + __le16 report; + __le16 flow_state; + } hash; + __u32 reserved; + __le64 tstamp; +}; + #ifndef VIRTIO_NET_NO_LEGACY /* This header comes first in the scatter-gather list. * For legacy virtio, if VIRTIO_F_ANY_LAYOUT is not negotiated, it must From patchwork Mon Feb 8 18:55:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Willem de Bruijn X-Patchwork-Id: 12076297 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 84B0CC433E0 for ; Mon, 8 Feb 2021 19:00:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 20D2364E73 for ; Mon, 8 Feb 2021 19:00:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234553AbhBHS74 (ORCPT ); Mon, 8 Feb 2021 13:59:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235863AbhBHS5V (ORCPT ); Mon, 8 Feb 2021 13:57:21 -0500 Received: from mail-qv1-xf2e.google.com (mail-qv1-xf2e.google.com [IPv6:2607:f8b0:4864:20::f2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5EC7C061797 for ; Mon, 8 Feb 2021 10:56:05 -0800 (PST) Received: by mail-qv1-xf2e.google.com with SMTP id v19so2690951qvl.7 for ; Mon, 08 Feb 2021 10:56:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SlFTIukFGMkw2OKGh13o3RxnKgGPrgHC1zxY8/NglTM=; b=SmManNau/yVkSieMx4AJ2MuyWqQ9HhPoPAh6toxhVSZddXA20Rkt+6GqluzJFpaRt/ qN43Ekq0uJpn40vzcaqAqWUW/xE0WYr96BupaTOGHdeLo1xbJFsZARcQS5+lWga80oww zJig+1oJKw7O705kvDlb1HMBu0Fad9q1wlvFzUSExZEi6c22me71rRjwC2K7jmAaQi4I ZIIaE154GVHCR3WQrZfdhr1YZTY7NfKDWgk2C9gUVY2+wiebzcv1TV3jHMx6lLE5CuLp rLHt+2LrJnbzhxDu6of2n4Edl0iNMMne3TUIH9hpciMYtbtpX5bqSSHwXNjh+jrnexGu bEgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SlFTIukFGMkw2OKGh13o3RxnKgGPrgHC1zxY8/NglTM=; b=YOo7tEekCgmX/nByeBa2vmNXR11ySyzpx4H1OBpc8XCLQJLwbnhTdP3NxWtqpjkHFm XdK/ku5VIFTAUcaNWrWvZ8S/kuuITxRmG9iszmO0pnzjKiBSLXDyZ1WCW2m2Oc0fVmtq UrgTJlm+6U+Wp8hib63907N1fwHRRRZdnhfCXfa7BYMyocz1ga42fUhE076j/9hJknMv oAycg6nTe5Ssjq8s0mIm80qRG4z10o9gv8bu2qZYl3F8vRfrWeJVWrrgJDWVhBEc/ivv 0NrDB2iokEJVEEWzKBdbXlsPMhWTKjszBIbOgVsZ0/ePtvBw6HpCsJEhNwfUHr50Uyhz 2dxQ== X-Gm-Message-State: AOAM532/EKFxpUWYdNzAXPcKNl9nf2KiXPCh6IgX21OeTQovJinWLM5d +H4kiVNKZeazHHXc7iJKs8RvGGCduuk= X-Google-Smtp-Source: ABdhPJzPoHHvBqxCa8V0IRqT8YWCiCMF2H/S/6nVea2y4QUfXDo2I3x7BHG2o/EHP+OeOaB1RbXzzw== X-Received: by 2002:a0c:dd8b:: with SMTP id v11mr17411146qvk.31.1612810565070; Mon, 08 Feb 2021 10:56:05 -0800 (PST) Received: from willemb.nyc.corp.google.com ([2620:0:1003:312:f109:45d3:805f:3b83]) by smtp.gmail.com with ESMTPSA id q25sm17370744qkq.32.2021.02.08.10.56.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Feb 2021 10:56:04 -0800 (PST) From: Willem de Bruijn To: virtualization@lists.linux-foundation.org Cc: netdev@vger.kernel.org, mst@redhat.com, jasowang@redhat.com, richardcochran@gmail.com, Willem de Bruijn Subject: [PATCH RFC v2 3/4] virtio-net: support transmit timestamp Date: Mon, 8 Feb 2021 13:55:57 -0500 Message-Id: <20210208185558.995292-4-willemdebruijn.kernel@gmail.com> X-Mailer: git-send-email 2.30.0.478.g8a0d178c01-goog In-Reply-To: <20210208185558.995292-1-willemdebruijn.kernel@gmail.com> References: <20210208185558.995292-1-willemdebruijn.kernel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC From: Willem de Bruijn Add optional PTP hardware tx timestamp offload for virtio-net. Accurate RTT measurement requires timestamps close to the wire. Introduce virtio feature VIRTIO_NET_F_TX_TSTAMP, the transmit equivalent to VIRTIO_NET_F_RX_TSTAMP. The driver sets VIRTIO_NET_HDR_F_TSTAMP to request a timestamp returned on completion. If the feature is negotiated, the device either places the timestamp or clears the feature bit. The timestamp straddles (virtual) hardware domains. Like PTP, use international atomic time (CLOCK_TAI) as global clock base. The driver must sync with the device, e.g., through kvm-clock. Modify can_push to ensure that on tx completion the header, and thus timestamp, is in a predicatable location at skb_vnet_hdr. RFC: this implementation relies on the device writing to the buffer. That breaks DMA_TO_DEVICE semantics. For now, disable when DMA is on. The virtio changes should be a separate patch at the least. Tested: modified txtimestamp.c to with h/w timestamping: - sock_opt = SOF_TIMESTAMPING_SOFTWARE | + sock_opt = SOF_TIMESTAMPING_RAW_HARDWARE | + do_test(family, SOF_TIMESTAMPING_TX_HARDWARE); Signed-off-by: Willem de Bruijn --- drivers/net/virtio_net.c | 61 ++++++++++++++++++++++++++++----- drivers/virtio/virtio_ring.c | 3 +- include/linux/virtio.h | 1 + include/uapi/linux/virtio_net.h | 1 + 4 files changed, 56 insertions(+), 10 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index ac44c5efa0bc..fc8ecd3a333a 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -210,6 +210,12 @@ struct virtnet_info { /* Device will pass rx timestamp. Requires has_rx_tstamp */ bool enable_rx_tstamp; + /* Device can pass CLOCK_TAI transmit time to the driver */ + bool has_tx_tstamp; + + /* Device will pass tx timestamp. Requires has_tx_tstamp */ + bool enable_tx_tstamp; + /* Has control virtqueue */ bool has_cvq; @@ -1401,6 +1407,20 @@ static int virtnet_receive(struct receive_queue *rq, int budget, return stats.packets; } +static void virtnet_record_tx_tstamp(const struct send_queue *sq, + struct sk_buff *skb) +{ + const struct virtio_net_hdr_hash_ts *h = skb_vnet_hdr_ht(skb); + const struct virtnet_info *vi = sq->vq->vdev->priv; + struct skb_shared_hwtstamps ts; + + if (h->hdr.flags & VIRTIO_NET_HDR_F_TSTAMP && + vi->enable_tx_tstamp) { + ts.hwtstamp = ns_to_ktime(le64_to_cpu(h->tstamp)); + skb_tstamp_tx(skb, &ts); + } +} + static void free_old_xmit_skbs(struct send_queue *sq, bool in_napi) { unsigned int len; @@ -1412,6 +1432,7 @@ static void free_old_xmit_skbs(struct send_queue *sq, bool in_napi) if (likely(!is_xdp_frame(ptr))) { struct sk_buff *skb = ptr; + virtnet_record_tx_tstamp(sq, skb); pr_debug("Sent skb %p\n", skb); bytes += skb->len; @@ -1558,7 +1579,7 @@ static int xmit_skb(struct send_queue *sq, struct sk_buff *skb) struct virtio_net_hdr_mrg_rxbuf *hdr; const unsigned char *dest = ((struct ethhdr *)skb->data)->h_dest; struct virtnet_info *vi = sq->vq->vdev->priv; - struct virtio_net_hdr_v1_hash *ht; + struct virtio_net_hdr_hash_ts *ht; int num_sg; unsigned hdr_len = vi->hdr_len; bool can_push; @@ -1567,7 +1588,8 @@ static int xmit_skb(struct send_queue *sq, struct sk_buff *skb) can_push = vi->any_header_sg && !((unsigned long)skb->data & (__alignof__(*hdr) - 1)) && - !skb_header_cloned(skb) && skb_headroom(skb) >= hdr_len; + !skb_header_cloned(skb) && skb_headroom(skb) >= hdr_len && + !vi->enable_tx_tstamp; /* Even if we can, don't push here yet as this would skew * csum_start offset below. */ if (can_push) @@ -1588,10 +1610,12 @@ static int xmit_skb(struct send_queue *sq, struct sk_buff *skb) u16 report = skb->l4_hash ? VIRTIO_NET_HASH_REPORT_L4 : VIRTIO_NET_HASH_REPORT_OTHER; - ht->hash_value = cpu_to_le32(skb->hash); - ht->hash_report = cpu_to_le16(report); - ht->hash_state = cpu_to_le16(VIRTIO_NET_HASH_STATE_DEFAULT); + ht->hash.value = cpu_to_le32(skb->hash); + ht->hash.report = cpu_to_le16(report); + ht->hash.flow_state = cpu_to_le16(VIRTIO_NET_HASH_STATE_DEFAULT); } + if (vi->enable_tx_tstamp && skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) + ht->hdr.flags |= VIRTIO_NET_HDR_F_TSTAMP; sg_init_table(sq->sg, skb_shinfo(skb)->nr_frags + (can_push ? 1 : 2)); if (can_push) { @@ -2307,7 +2331,13 @@ static int virtnet_get_ts_info(struct net_device *dev, info->rx_filters = HWTSTAMP_FILTER_NONE; } - info->tx_types = HWTSTAMP_TX_OFF; + if (vi->has_tx_tstamp) { + info->so_timestamping |= SOF_TIMESTAMPING_TX_HARDWARE | + SOF_TIMESTAMPING_RAW_HARDWARE; + info->tx_types = HWTSTAMP_TX_ON; + } else { + info->tx_types = HWTSTAMP_TX_OFF; + } return 0; } @@ -2616,7 +2646,8 @@ static int virtnet_ioctl_set_hwtstamp(struct net_device *dev, struct ifreq *ifr) return -EFAULT; if (tsconf.flags) return -EINVAL; - if (tsconf.tx_type != HWTSTAMP_TX_OFF) + if (tsconf.tx_type != HWTSTAMP_TX_OFF && + tsconf.tx_type != HWTSTAMP_TX_ON) return -ERANGE; if (tsconf.rx_filter != HWTSTAMP_FILTER_NONE && tsconf.rx_filter != HWTSTAMP_FILTER_ALL) @@ -2627,6 +2658,11 @@ static int virtnet_ioctl_set_hwtstamp(struct net_device *dev, struct ifreq *ifr) else vi->enable_rx_tstamp = tsconf.rx_filter == HWTSTAMP_FILTER_ALL; + if (!vi->has_tx_tstamp) + tsconf.tx_type = HWTSTAMP_TX_OFF; + else + vi->enable_tx_tstamp = tsconf.tx_type == HWTSTAMP_TX_ON; + if (copy_to_user(ifr->ifr_data, &tsconf, sizeof(tsconf))) return -EFAULT; @@ -2641,7 +2677,8 @@ static int virtnet_ioctl_get_hwtstamp(struct net_device *dev, struct ifreq *ifr) tsconf.flags = 0; tsconf.rx_filter = vi->enable_rx_tstamp ? HWTSTAMP_FILTER_ALL : HWTSTAMP_FILTER_NONE; - tsconf.tx_type = HWTSTAMP_TX_OFF; + tsconf.tx_type = vi->enable_tx_tstamp ? HWTSTAMP_TX_ON : + HWTSTAMP_TX_OFF; if (copy_to_user(ifr->ifr_data, &tsconf, sizeof(tsconf))) return -EFAULT; @@ -3178,6 +3215,12 @@ static int virtnet_probe(struct virtio_device *vdev) vi->hdr_len = sizeof(struct virtio_net_hdr_hash_ts); } + if (virtio_has_feature(vdev, VIRTIO_NET_F_TX_TSTAMP) && + !vring_use_dma_api(vdev)) { + vi->has_tx_tstamp = true; + vi->hdr_len = sizeof(struct virtio_net_hdr_hash_ts); + } + if (virtio_has_feature(vdev, VIRTIO_F_ANY_LAYOUT) || virtio_has_feature(vdev, VIRTIO_F_VERSION_1)) vi->any_header_sg = true; @@ -3369,7 +3412,7 @@ static struct virtio_device_id id_table[] = { VIRTIO_NET_F_CTRL_MAC_ADDR, \ VIRTIO_NET_F_MTU, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS, \ VIRTIO_NET_F_SPEED_DUPLEX, VIRTIO_NET_F_STANDBY, \ - VIRTIO_NET_F_TX_HASH, VIRTIO_NET_F_RX_TSTAMP + VIRTIO_NET_F_TX_HASH, VIRTIO_NET_F_RX_TSTAMP, VIRTIO_NET_F_TX_TSTAMP static unsigned int features[] = { VIRTNET_FEATURES, diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index 71e16b53e9c1..cf5d5d1f9b14 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -238,7 +238,7 @@ static inline bool virtqueue_use_indirect(struct virtqueue *_vq, * unconditionally on data path. */ -static bool vring_use_dma_api(struct virtio_device *vdev) +bool vring_use_dma_api(struct virtio_device *vdev) { if (!virtio_has_dma_quirk(vdev)) return true; @@ -257,6 +257,7 @@ static bool vring_use_dma_api(struct virtio_device *vdev) return false; } +EXPORT_SYMBOL_GPL(vring_use_dma_api); size_t virtio_max_dma_size(struct virtio_device *vdev) { diff --git a/include/linux/virtio.h b/include/linux/virtio.h index 55ea329fe72a..5289e2812e95 100644 --- a/include/linux/virtio.h +++ b/include/linux/virtio.h @@ -140,6 +140,7 @@ int virtio_device_freeze(struct virtio_device *dev); int virtio_device_restore(struct virtio_device *dev); #endif +bool vring_use_dma_api(struct virtio_device *vdev); size_t virtio_max_dma_size(struct virtio_device *vdev); #define virtio_device_for_each_vq(vdev, vq) \ diff --git a/include/uapi/linux/virtio_net.h b/include/uapi/linux/virtio_net.h index a5c84410cf92..b5d6f0c6cead 100644 --- a/include/uapi/linux/virtio_net.h +++ b/include/uapi/linux/virtio_net.h @@ -57,6 +57,7 @@ * Steering */ #define VIRTIO_NET_F_CTRL_MAC_ADDR 23 /* Set MAC address */ +#define VIRTIO_NET_F_TX_TSTAMP 54 /* Device sends TAI transmit time */ #define VIRTIO_NET_F_RX_TSTAMP 55 /* Device sends TAI receive time */ #define VIRTIO_NET_F_TX_HASH 56 /* Driver sends hash report */ #define VIRTIO_NET_F_HASH_REPORT 57 /* Supports hash report */ From patchwork Mon Feb 8 18:55:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Willem de Bruijn X-Patchwork-Id: 12076295 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3F6B3C433E6 for ; Mon, 8 Feb 2021 18:59:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0235564E84 for ; Mon, 8 Feb 2021 18:59:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236008AbhBHS7d (ORCPT ); Mon, 8 Feb 2021 13:59:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235875AbhBHS5V (ORCPT ); Mon, 8 Feb 2021 13:57:21 -0500 Received: from mail-qk1-x735.google.com (mail-qk1-x735.google.com [IPv6:2607:f8b0:4864:20::735]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E06DC0617A7 for ; Mon, 8 Feb 2021 10:56:07 -0800 (PST) Received: by mail-qk1-x735.google.com with SMTP id l27so15474420qki.9 for ; Mon, 08 Feb 2021 10:56:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=V5SXxqRn9iChNkelA4Lz5t2Lq5FsheIFJl6lMmqNafs=; b=k1RlK0+rIiwKwfG+r9ciIyMYKAWET+IcMxexNzwQ+6z4uvYmVm0UL9tmzMKzLCn0r5 MENfN1EXiEQTscopjRumoVdOW1lKWWj4fEVTwe2Hqrf9FD08Cp6diJio+rxvIxngxUCC m6pes9Awe+fNvUqENRRffwYQHGecfMZ4Qmn46xJvm+oFVCGJrZlnfHj9RLogA5D0ZQEz onLIh5gMZg5ENRcaSB5EcFMY0OIoMLlmgFhBl8NWczXYnHyCNPfiARsRf1wlTIXDs1rt CYuyUQgOa2xHtTfCgnCzjNDo1hiiLpBXscWeJQV5KOrUgPLho2xqhVhXRizC9D+VJMma cJYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=V5SXxqRn9iChNkelA4Lz5t2Lq5FsheIFJl6lMmqNafs=; b=Vo4Sph7PmKvsqJdN8O3HT37XEDm/B9giDTUrHMqc0ZAiK65Jee3dzhkkedCCBi2Pwb sXJL2XuZP/kIlZF0wfv7rW/v0AM/xFYjcfI3kJgBCrHn1wqlMG+dtCQuSahV9Ll/IX+X Puy1iY48P4YmOs5wC72fOGy8v8IaUFUZTp6dd60RkIKLyP2lUMbfmaey7552y9Pb2u7A 12RQ9zLruwI+iYXvD96ftxap4S/px2z0YPnBRkdx3TkxlgFmssL8iIgGFECGlK2fxeOg HL27YM+BbOchebqJoKVtkt+88TzBJFoI6iS+WA3P0nRX7eWrqc5ysouFfkAXjgTTlFmd cgDg== X-Gm-Message-State: AOAM533SJZ9UrRrEWG+8cHxzafu2FFpub6KyxZMN2Rx0Pn9UXbSgldkH bqp6yL7CeQVoxrb9GuTvh0+VN6dFVBQ= X-Google-Smtp-Source: ABdhPJx2Vzz3BN3fufrvFs0gfLszLO304XiNcsw2UEPhzqYAxQtPHMyuALjvbbug6pZAp9GoEaItqw== X-Received: by 2002:a05:620a:8dc:: with SMTP id z28mr1023748qkz.404.1612810566558; Mon, 08 Feb 2021 10:56:06 -0800 (PST) Received: from willemb.nyc.corp.google.com ([2620:0:1003:312:f109:45d3:805f:3b83]) by smtp.gmail.com with ESMTPSA id q25sm17370744qkq.32.2021.02.08.10.56.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Feb 2021 10:56:05 -0800 (PST) From: Willem de Bruijn To: virtualization@lists.linux-foundation.org Cc: netdev@vger.kernel.org, mst@redhat.com, jasowang@redhat.com, richardcochran@gmail.com, Willem de Bruijn Subject: [PATCH RFC v2 4/4] virtio-net: support future packet transmit time Date: Mon, 8 Feb 2021 13:55:58 -0500 Message-Id: <20210208185558.995292-5-willemdebruijn.kernel@gmail.com> X-Mailer: git-send-email 2.30.0.478.g8a0d178c01-goog In-Reply-To: <20210208185558.995292-1-willemdebruijn.kernel@gmail.com> References: <20210208185558.995292-1-willemdebruijn.kernel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC From: Willem de Bruijn Add optional transmit time (SO_TXTIME) offload for virtio-net. The Linux TCP/IP stack tries to avoid bursty transmission and network congestion through pacing: computing an skb delivery time based on congestion information. Userspace protocol implementations can achieve the same with SO_TXTIME. This may also reduce scheduling jitter and improve RTT estimation. Pacing can be implemented in ETF or FQ qdiscs or offloaded to NIC hardware. Allow virtio-net driver to offload for the same reasons. The timestamp straddles (virtual) hardware domains. Like PTP, use international atomic time (CLOCK_TAI) as global clock base. The driver must sync with the device, e.g., through kvm-clock. Changes RFC - RFCv2 - rename from transmit timestamp to future packet transmit time - convert cpu_to_virtioXX to cpu_to_leXX Signed-off-by: Willem de Bruijn --- drivers/net/virtio_net.c | 13 ++++++++++++- include/uapi/linux/virtio_net.h | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index fc8ecd3a333a..c09d19b97f42 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -216,6 +216,9 @@ struct virtnet_info { /* Device will pass tx timestamp. Requires has_tx_tstamp */ bool enable_tx_tstamp; + /* Driver will pass CLOCK_TAI delivery time to the device */ + bool has_tx_time; + /* Has control virtqueue */ bool has_cvq; @@ -1616,6 +1619,8 @@ static int xmit_skb(struct send_queue *sq, struct sk_buff *skb) } if (vi->enable_tx_tstamp && skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) ht->hdr.flags |= VIRTIO_NET_HDR_F_TSTAMP; + if (vi->has_tx_time && skb->tstamp) + ht->tstamp = cpu_to_le64(skb->tstamp); sg_init_table(sq->sg, skb_shinfo(skb)->nr_frags + (can_push ? 1 : 2)); if (can_push) { @@ -3221,6 +3226,11 @@ static int virtnet_probe(struct virtio_device *vdev) vi->hdr_len = sizeof(struct virtio_net_hdr_hash_ts); } + if (virtio_has_feature(vdev, VIRTIO_NET_F_TX_TIME)) { + vi->has_tx_time = true; + vi->hdr_len = sizeof(struct virtio_net_hdr_hash_ts); + } + if (virtio_has_feature(vdev, VIRTIO_F_ANY_LAYOUT) || virtio_has_feature(vdev, VIRTIO_F_VERSION_1)) vi->any_header_sg = true; @@ -3412,7 +3422,8 @@ static struct virtio_device_id id_table[] = { VIRTIO_NET_F_CTRL_MAC_ADDR, \ VIRTIO_NET_F_MTU, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS, \ VIRTIO_NET_F_SPEED_DUPLEX, VIRTIO_NET_F_STANDBY, \ - VIRTIO_NET_F_TX_HASH, VIRTIO_NET_F_RX_TSTAMP, VIRTIO_NET_F_TX_TSTAMP + VIRTIO_NET_F_TX_HASH, VIRTIO_NET_F_RX_TSTAMP, VIRTIO_NET_F_TX_TSTAMP, \ + VIRTIO_NET_F_TX_TIME static unsigned int features[] = { VIRTNET_FEATURES, diff --git a/include/uapi/linux/virtio_net.h b/include/uapi/linux/virtio_net.h index b5d6f0c6cead..7ca99a2ee1a3 100644 --- a/include/uapi/linux/virtio_net.h +++ b/include/uapi/linux/virtio_net.h @@ -57,6 +57,7 @@ * Steering */ #define VIRTIO_NET_F_CTRL_MAC_ADDR 23 /* Set MAC address */ +#define VIRTIO_NET_F_TX_TIME 53 /* Driver sets TAI delivery time */ #define VIRTIO_NET_F_TX_TSTAMP 54 /* Device sends TAI transmit time */ #define VIRTIO_NET_F_RX_TSTAMP 55 /* Device sends TAI receive time */ #define VIRTIO_NET_F_TX_HASH 56 /* Driver sends hash report */