From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757058AbdKGKjj (ORCPT ); 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 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: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@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(-) 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); } } -- 2.9.0