]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.4.172/e1000e-allow-non-monotonic-systim-readings.patch
4.14-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.4.172 / e1000e-allow-non-monotonic-systim-readings.patch
1 From fee85f4dae2ac4ea158a9716a7fc7dd3b577de4f Mon Sep 17 00:00:00 2001
2 From: Miroslav Lichvar <mlichvar@redhat.com>
3 Date: Tue, 23 Oct 2018 14:37:39 +0200
4 Subject: e1000e: allow non-monotonic SYSTIM readings
5
6 [ Upstream commit e1f65b0d70e9e5c80e15105cd96fa00174d7c436 ]
7
8 It seems with some NICs supported by the e1000e driver a SYSTIM reading
9 may occasionally be few microseconds before the previous reading and if
10 enabled also pass e1000e_sanitize_systim() without reaching the maximum
11 number of rereads, even if the function is modified to check three
12 consecutive readings (i.e. it doesn't look like a double read error).
13 This causes an underflow in the timecounter and the PHC time jumps hours
14 ahead.
15
16 This was observed on 82574, I217 and I219. The fastest way to reproduce
17 it is to run a program that continuously calls the PTP_SYS_OFFSET ioctl
18 on the PHC.
19
20 Modify e1000e_phc_gettime() to use timecounter_cyc2time() instead of
21 timecounter_read() in order to allow non-monotonic SYSTIM readings and
22 prevent the PHC from jumping.
23
24 Cc: Richard Cochran <richardcochran@gmail.com>
25 Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
26 Acked-by: Jacob Keller <jacob.e.keller@intel.com>
27 Tested-by: Aaron Brown <aaron.f.brown@intel.com>
28 Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
29 Signed-off-by: Sasha Levin <sashal@kernel.org>
30 ---
31 drivers/net/ethernet/intel/e1000e/ptp.c | 13 ++++++++++---
32 1 file changed, 10 insertions(+), 3 deletions(-)
33
34 diff --git a/drivers/net/ethernet/intel/e1000e/ptp.c b/drivers/net/ethernet/intel/e1000e/ptp.c
35 index 25a0ad5102d6..855cf8c15c8a 100644
36 --- a/drivers/net/ethernet/intel/e1000e/ptp.c
37 +++ b/drivers/net/ethernet/intel/e1000e/ptp.c
38 @@ -111,10 +111,14 @@ static int e1000e_phc_gettime(struct ptp_clock_info *ptp, struct timespec64 *ts)
39 struct e1000_adapter *adapter = container_of(ptp, struct e1000_adapter,
40 ptp_clock_info);
41 unsigned long flags;
42 - u64 ns;
43 + u64 cycles, ns;
44
45 spin_lock_irqsave(&adapter->systim_lock, flags);
46 - ns = timecounter_read(&adapter->tc);
47 +
48 + /* Use timecounter_cyc2time() to allow non-monotonic SYSTIM readings */
49 + cycles = adapter->cc.read(&adapter->cc);
50 + ns = timecounter_cyc2time(&adapter->tc, cycles);
51 +
52 spin_unlock_irqrestore(&adapter->systim_lock, flags);
53
54 *ts = ns_to_timespec64(ns);
55 @@ -170,9 +174,12 @@ static void e1000e_systim_overflow_work(struct work_struct *work)
56 systim_overflow_work.work);
57 struct e1000_hw *hw = &adapter->hw;
58 struct timespec64 ts;
59 + u64 ns;
60
61 - adapter->ptp_clock_info.gettime64(&adapter->ptp_clock_info, &ts);
62 + /* Update the timecounter */
63 + ns = timecounter_read(&adapter->tc);
64
65 + ts = ns_to_timespec64(ns);
66 e_dbg("SYSTIM overflow check at %lld.%09lu\n",
67 (long long) ts.tv_sec, ts.tv_nsec);
68
69 --
70 2.19.1
71