Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5098850imu; Tue, 8 Jan 2019 11:28:18 -0800 (PST) X-Google-Smtp-Source: ALg8bN6dv3Ahd8QQyrA9lTgptu5vYJBt1uit/+xSbftDJ4pT2YwiP14BEQyThyORs0YovjaJOkhJ X-Received: by 2002:a63:981:: with SMTP id 123mr2662329pgj.444.1546975698500; Tue, 08 Jan 2019 11:28:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546975698; cv=none; d=google.com; s=arc-20160816; b=RMVwLx/1XxniJigwdhZ8LWXf7iR4OwZho8U8F92AMBb32Z0x0hvii2W112dBcKAgx+ k2k7g5Psd3PbhNWXvbyDt87DRZdLjfM+ObP6TumhFENgoPjlAYXc8QJf5Q0X2ySmHPEo ApYno60Us+WPaO2KFY26XhcWlEQ1kB0CuZwFmiR3+xXg0hQmqjKe3Fue7gP3IwH0q+EA wYPREK4iaq1nBgmJABy/1mNOm59kpc24lL8lMnvwnxOKndYU7yiePhFOXSNN/89YPiT7 zgHd8Hn3NGe3LQW4vs0Op9rquRofdaHT94etWv8u8ONMeBaCFIlQ50aCFkODfso8P9ew hSWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=jdJbeAYfp0DzMXZFEam5xM+ucYimstdbHEejYu3ZwkE=; b=Ief9q3kGko5rY9jkRLgD818wZE2vexBWaIMQ6R0/zbvrwqTMCsPpQ1BeJosOU0m4qC 8W630MhaoUIezZGMG+L/C3xVYTEKSzXFABsy9pc7Zn64DN9bph1cNd5J8EF+KVB+mcFA tSUkaBFdcvkEnOVFwqpY/PZWFdiaYEtDBIWyZRJ5/ujroe62Dzhj/QaR/YkmAbhU++zi fRu0gEHikTJxFbxRHmf8+IyWAneAGCjSrfaOFXJ8byAELNyCxxU5dpmOxhHa1gUS37pU 2HbrVTeuDo8v4gPGHcYy/K1TDPJgH9Jmi+iNIko8d6N3v/DReNckm3kE6SQtdsk78QJo TKFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=DxvcMKyf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w24si66165758pgj.582.2019.01.08.11.28.03; Tue, 08 Jan 2019 11:28:18 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=DxvcMKyf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729204AbfAHT0t (ORCPT + 99 others); Tue, 8 Jan 2019 14:26:49 -0500 Received: from mail.kernel.org ([198.145.29.99]:60828 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729148AbfAHT0r (ORCPT ); Tue, 8 Jan 2019 14:26:47 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9F5D82183F; Tue, 8 Jan 2019 19:26:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546975606; bh=EMECKitYHCNs6mdQpAsguMDrlsALDn0K5BIylxtCV0g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DxvcMKyfhDhCQjyVtITro/7gxkX3C/bQuCL20VhFpInMyN2Wy4I578QCOgTbtrkQd P1B7ZJPrsZxs42GAuLL1Op8CXPcecu5sy8WyWSv9tWED7/qP2ni+3KWGAR6+yiQIUI eGiFNBcIqZpx+tovP3M8O/GGROIU75dYmpCaA7hw= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Miroslav Lichvar , Richard Cochran , Jeff Kirsher , Sasha Levin , netdev@vger.kernel.org Subject: [PATCH AUTOSEL 4.20 009/117] e1000e: allow non-monotonic SYSTIM readings Date: Tue, 8 Jan 2019 14:24:37 -0500 Message-Id: <20190108192628.121270-9-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190108192628.121270-1-sashal@kernel.org> References: <20190108192628.121270-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Miroslav Lichvar [ Upstream commit e1f65b0d70e9e5c80e15105cd96fa00174d7c436 ] It seems with some NICs supported by the e1000e driver a SYSTIM reading may occasionally be few microseconds before the previous reading and if enabled also pass e1000e_sanitize_systim() without reaching the maximum number of rereads, even if the function is modified to check three consecutive readings (i.e. it doesn't look like a double read error). This causes an underflow in the timecounter and the PHC time jumps hours ahead. This was observed on 82574, I217 and I219. The fastest way to reproduce it is to run a program that continuously calls the PTP_SYS_OFFSET ioctl on the PHC. Modify e1000e_phc_gettime() to use timecounter_cyc2time() instead of timecounter_read() in order to allow non-monotonic SYSTIM readings and prevent the PHC from jumping. Cc: Richard Cochran Signed-off-by: Miroslav Lichvar Acked-by: Jacob Keller Tested-by: Aaron Brown Signed-off-by: Jeff Kirsher Signed-off-by: Sasha Levin --- drivers/net/ethernet/intel/e1000e/ptp.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/intel/e1000e/ptp.c b/drivers/net/ethernet/intel/e1000e/ptp.c index 37c76945ad9b..e1f821edbc21 100644 --- a/drivers/net/ethernet/intel/e1000e/ptp.c +++ b/drivers/net/ethernet/intel/e1000e/ptp.c @@ -173,10 +173,14 @@ static int e1000e_phc_gettime(struct ptp_clock_info *ptp, struct timespec64 *ts) struct e1000_adapter *adapter = container_of(ptp, struct e1000_adapter, ptp_clock_info); unsigned long flags; - u64 ns; + u64 cycles, ns; spin_lock_irqsave(&adapter->systim_lock, flags); - ns = timecounter_read(&adapter->tc); + + /* Use timecounter_cyc2time() to allow non-monotonic SYSTIM readings */ + cycles = adapter->cc.read(&adapter->cc); + ns = timecounter_cyc2time(&adapter->tc, cycles); + spin_unlock_irqrestore(&adapter->systim_lock, flags); *ts = ns_to_timespec64(ns); @@ -232,9 +236,12 @@ static void e1000e_systim_overflow_work(struct work_struct *work) systim_overflow_work.work); struct e1000_hw *hw = &adapter->hw; struct timespec64 ts; + u64 ns; - adapter->ptp_clock_info.gettime64(&adapter->ptp_clock_info, &ts); + /* Update the timecounter */ + ns = timecounter_read(&adapter->tc); + ts = ns_to_timespec64(ns); e_dbg("SYSTIM overflow check at %lld.%09lu\n", (long long) ts.tv_sec, ts.tv_nsec); -- 2.19.1