Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2402506imu; Thu, 24 Jan 2019 12:08:56 -0800 (PST) X-Google-Smtp-Source: ALg8bN5w92RM/kbV6Fr0og/STYpyS8p0h/SlgJoaiIHjMpc597OmQ3tA7cb75ReV8i4nNC64aK+M X-Received: by 2002:a63:990a:: with SMTP id d10mr7246381pge.279.1548360536066; Thu, 24 Jan 2019 12:08:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548360536; cv=none; d=google.com; s=arc-20160816; b=HlLjWrubZ9uAmLlZAV87caKlVSoxnQ6nGkCq5qrm2jYnwrCEjSj2VCVvjzJeLGqByE z0T4IGi5ovx/WKs6FO/gcq6QsBxvwha43jCmNtp9c9oNe53zzMAhbvc1gTHhLXlmD+Az XpQJkvDkBEBb/bL+etSxRRPkQA7t3nDsEbUe2v0qrgP92wuiIy1W7hVk2z4fGzGvT4j3 3DAngRSre6ek2QLoKNXVLP30B4Nu1J4T3UvJRVO74cVMQmBJcm1HCgj1f3cVnO6oXyn2 p3KDrUeI1Cc8Zz5uHVZO8TKnbmCN1zpuiRItDkkHAuhGk96u6wBgs1fvOuByen8DyopW gS5Q== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=oTjmtYZvPjg3/PP1iabshhVzIOnhqRkqlkMF9SbmCLk=; b=rso+9EPsLWl1wm7sE8sioWbR9aDh7n7vogor0AVMh3Pm0LRC5DpxYGTQKZmS+TeAyM ncTo96AAn4i8OelQkxrliaOzXcEAhjgUrHzI2KPhpShf3q5UGb8ZUnvcg2xSt86KaqMD xCeFrnahWt61tv2o1PS5aEt1HmE/kVlWveeHNBuYLTqkSPUDBYhWmyxFw5sS2C2Gb4HI pN8DI3aG1Q28O6xYxRcpLIYUARyz4A+3htsih3xGKAI/0YvJwMxu33J4nP814O6jdzsZ iBpNQgZvG1eF6TFHqJwysmcmkEZisck73IlIV0ZUtGDILKJ9wPqgkoxQP8zMhKbcceZF fQWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=nfAn4vkG; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 1si6305814plr.189.2019.01.24.12.08.40; Thu, 24 Jan 2019 12:08:56 -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=nfAn4vkG; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731304AbfAXT36 (ORCPT + 99 others); Thu, 24 Jan 2019 14:29:58 -0500 Received: from mail.kernel.org ([198.145.29.99]:57310 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730032AbfAXT34 (ORCPT ); Thu, 24 Jan 2019 14:29:56 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BD71E218D4; Thu, 24 Jan 2019 19:29:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548358195; bh=tzzuLFGQia/MKs9Eu8HX0xfOIgcf1IYXYc4js7tdoVw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nfAn4vkGghcWAKPMjLEfz+4DXjimPK1XGOYz+Xhhw3Tq7PI9Pz6m6ttdp2UgW6dpO agiPYz0sdDtE19N5BHpDtKTedvIGStFv+AJN45C+3zU5d/flsP6ZQWA1vsYR93rhD0 QwQoqfsjExNnWkfa9UamMUDQrGMMbm5vAtKLpBGM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Richard Cochran , Miroslav Lichvar , Jacob Keller , Aaron Brown , Jeff Kirsher , Sasha Levin Subject: [PATCH 4.9 05/39] e1000e: allow non-monotonic SYSTIM readings Date: Thu, 24 Jan 2019 20:20:08 +0100 Message-Id: <20190124190448.420952725@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190124190448.232316246@linuxfoundation.org> References: <20190124190448.232316246@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ [ 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 ad03763e009a..a9f8edc17827 100644 --- a/drivers/net/ethernet/intel/e1000e/ptp.c +++ b/drivers/net/ethernet/intel/e1000e/ptp.c @@ -191,10 +191,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); @@ -250,9 +254,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