From patchwork Tue Nov 7 10:38:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 118144 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp3810063qgn; Tue, 7 Nov 2017 02:40:04 -0800 (PST) X-Google-Smtp-Source: ABhQp+SIkYoN+KpQ/89sm+AKMqmfmJRHkf2U6BFMzoTPgzMwp8QpEaLP2tlQ5JB/JW8QNk1qWlJ1 X-Received: by 10.84.150.131 with SMTP id h3mr17966895plh.126.1510051204546; Tue, 07 Nov 2017 02:40:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510051204; cv=none; d=google.com; s=arc-20160816; b=RGHmUPN20TD+1BuREGGUXksBQVEdRiecwS5XWoqOStB6dP9lVqNPWKHbPB8EACwk8n c7q+bm75snmXl1mzvmsp2zaguJGlKPlrqp8tbUEfdHG/NQkTDoTdf2Fm5rwqLk21qUa2 Zt49rBYg4BhxOaGUXmUyeanEeoeQd0ELeZslukGgNimjgibBqlxJkTgeaqfLb+NFSdTy zytkIZi4Qs58dPGgbRqvKshLAHUDKRZIIjCwo6oe93nnduNNYsMDJBRTIu7ZnFdoeQf6 /zPlgR7cqy3cf3OpeY8pzSwCvAjqliCi6ZWlnK7fCpC4xY20huCHTDf5sqWw1yXLldFx Wm4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=gQw36K8heVo9A+KJpsFZnerB81BZEYtJUt98OzaZyfE=; b=sKt0RksbcNFRWuClBfPUT5M/g7MevdHJVsUAqi//1Dx6PplrOCQuN9lPXHd+YjGUXz HF9eIdmeIcBoAwsjvatACVfoOnrOJzaRPRDDQ9BZxLxU6ddnlL+mgerzbfFyXPCmwGSM bmvuuLzI9ypcl2hslP8uqaeghs2zbQ+d4bf5rRCuql5CBZOKTBtTBSKOKLOtVCLCTLUI 4KH5dBV3e3XGwDbnf4jljYSepJnWaVm4eoJDM0kaiGI4LcOWL0jfx1k0x/J1WD1N6wd2 lDc8wDEPeCySR703ClJiL6n+HakB/wOsJCUc87onGDxMhmiD+ROA8+/b4GnpnR6TExfL v+yA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a61si873149plc.406.2017.11.07.02.40.04; Tue, 07 Nov 2017 02:40:04 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757062AbdKGKjj (ORCPT + 7 others); Tue, 7 Nov 2017 05:39:39 -0500 Received: from mout.kundenserver.de ([212.227.126.130]:55373 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756870AbdKGKjd (ORCPT ); Tue, 7 Nov 2017 05:39:33 -0500 Received: from wuerfel.lan ([109.193.157.232]) by mrelayeu.kundenserver.de (mreue007 [212.227.15.129]) with ESMTPA (Nemesis) id 0MT2av-1edLB30nht-00RpBa; Tue, 07 Nov 2017 11:39:08 +0100 From: Arnd Bergmann To: "David S. Miller" Cc: stephen@networkplumber.org, fan.du@windriver.com, edumazet@google.com, john.fastabend@gmail.com, oleg@redhat.com, ast@plumgrid.com, minipli@googlemail.com, tgraf@suug.ch, Arnd Bergmann , Johannes Berg , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] pktgen: document 32-bit timestamp overflow Date: Tue, 7 Nov 2017 11:38:32 +0100 Message-Id: <20171107103856.2830339-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:/O+fVrpwMraRalEZLzEdNoKsW+lM7QwZ4zDxF5WwokYYjPDb3+2 JMKG9Cd3rhatORakpFOmiIaFd5UYgFukSduiN6850JDdDsjiCZdgFAUouXtIXi59X0huIhF 1tYmKJ+rSGYS+rGRYPYg3kxIc5nP0w91ixXWW/FE2EN/caViB1FCr9Ot7bbhGE5Tk+3Hqzi ZWizykEHnhWd0GMUxs6pw== X-UI-Out-Filterresults: notjunk:1; V01:K0:Y1p5E+yHypk=:smtj4o6f/vijMJYYhLIWWu ZR/RvKsRRG5JgBimXINh9wg5pjJzF0rPOr+furn1+kLUoTIzhJkzEUL6F6rxVhPbOJh/5GQQr D3IK35Y5eMgOn0L6M+/kdd0khf4XAucjX6EhQhB0EFQuHLKTrlV8HyTUGUMB3YQvDQWgs/M9u W0gJQgGHQCoc5EFUS978BDam/aK0XoSz3rKXmCKOlza6ROgLV+++0mzEsyiaPW9aL0EVLAu53 T3RruRAPkAffNjqX9BvTbMWxsHFXw5Ip7Zvow12fqUI6ybimacqYTRGqEx1yXti9XiiXpEyQu yN9RXr38ZhUpPZxRcQU8nVMoUSn04+8doeC1nDxU0fGMuRCvrt3/+bpCG3WOuoY+XpsoPcouO Uz1Jc/nDblmmlsCjzO++fkL8Z9g3GyN8wCbA9nEmkz2KICXF+axyCv2DNENBR8OrkjzHfcBIi S37otzVRbvVOrRTsoSQuUy8F68krpDgZxwKT+A7z5x2NsyRFi89wxaz7NKnstdq0TcVYfpiu7 UnE3Qm2GbsiBvIeG9oWFHcfpSf2XqyivYfjTbJ4/ClxLIo1Ucx3MRzwLgEQSQSaJ9XkvGPSCy cwh67DFFIfscLuV3tRyFpSA2Q/qOkoMC0qa4Z2oBf9azNVBrkmCr8+po2I+sjmjKj0Dhmr0kk TtCgrnICymVCEKliaGayRQUhHYecd5R1vh2/u/Exncm9zhhYHth7r/XiCGAhaKEuYAm6QAx81 mShnPxJ5JNMOG1dcfJeNWI6UAB6uaTBxt+kwMA== Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Timestamps in pktgen are currently retrieved using the deprecated do_gettimeofday() function that wraps its signed 32-bit seconds in 2038 (on 32-bit architectures) and requires a division operation to calculate microseconds. The pktgen header is also defined with the same limitations, hardcoding to a 32-bit seconds field that can be interpreted as unsigned to produce times that only wrap in 2106. Whatever code reads the timestamps should be aware of that problem in general, but probably doesn't care too much as we are mostly interested in the time passing between packets, and that is correctly represented. Using 64-bit nanoseconds would be cheaper and good for 584 years. Using monotonic times would also make this unambiguous by avoiding the overflow, but would make it harder to correlate to the times with those on remote machines. Either approach would require adding a new runtime flag and implementing the same thing on the remote side, which we probably don't want to do unless someone sees it as a real problem. Also, this should be coordinated with other pktgen implementations and might need a new magic number. For the moment, I'm documenting the overflow in the source code, and changing the implementation over to an open-coded ktime_get_real_ts64() plus division, so we don't have to look at it again while scanning for deprecated time interfaces. Signed-off-by: Arnd Bergmann --- net/core/pktgen.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) -- 2.9.0 diff --git a/net/core/pktgen.c b/net/core/pktgen.c index 6c5763b4411c..f95a15086225 100644 --- a/net/core/pktgen.c +++ b/net/core/pktgen.c @@ -2711,7 +2711,7 @@ static inline __be16 build_tci(unsigned int id, unsigned int cfi, static void pktgen_finalize_skb(struct pktgen_dev *pkt_dev, struct sk_buff *skb, int datalen) { - struct timeval timestamp; + struct timespec64 timestamp; struct pktgen_hdr *pgh; pgh = skb_put(skb, sizeof(*pgh)); @@ -2773,9 +2773,17 @@ static void pktgen_finalize_skb(struct pktgen_dev *pkt_dev, struct sk_buff *skb, pgh->tv_sec = 0; pgh->tv_usec = 0; } else { - do_gettimeofday(×tamp); + /* + * pgh->tv_sec wraps in y2106 when interpreted as unsigned + * as done by wireshark, or y2038 when interpreted as signed. + * This is probably harmless, but if anyone wants to improve + * it, we could introduce a variant that puts 64-bit nanoseconds + * into the respective header bytes. + * This would also be slightly faster to read. + */ + ktime_get_real_ts64(×tamp); pgh->tv_sec = htonl(timestamp.tv_sec); - pgh->tv_usec = htonl(timestamp.tv_usec); + pgh->tv_usec = htonl(timestamp.tv_nsec / NSEC_PER_USEC); } }