Path: csiph.com!news.mixmin.net!news.unit0.net!news.panservice.it!bofh.it!news.nic.it!robomod From: "Levin, Alexander (Sasha Levin)" Newsgroups: linux.kernel Subject: [PATCH review for 4.9 10/50] net/mlx4_en: fix overflow in mlx4_en_init_timestamp() Date: Mon, 25 Sep 2017 03:40:02 +0200 Message-ID: References: X-Original-To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=verizon.com; i=@verizon.com; q=dns/txt; s=corp; t=1506302050; x=1537838050; h=from:cc:to:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=sBS+SGdChURZ6eRC76Fi9iJo770m9t/APIPJ26tOv9E=; b=YYHZJezVd/uSyy87JpmnBGuFsQICcjfMXz2UDTd1XP/jLRZhLIKJVjY0 8OdsuW54wLoXyPfmAOEeewSK+4YqQiQIwgPw2lIJgUpXfTXf0y1N0ffM6 ubT/cfKf//5WEc4C+xbuq2bavQSRNdKJLkh1shi/Bs6SEeLw50h9D+J6/ Y=; Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=verizon.com; i=@verizon.com; q=dns/txt; s=corp; t=1506301968; x=1537837968; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=sBS+SGdChURZ6eRC76Fi9iJo770m9t/APIPJ26tOv9E=; b=WCNoznF+Fon6eaKzns05CEveIdz7jak0Z5OSgMuIFVdCfMLFrokTf+JH jrS4gmKCl7dpbkYFyb+O6gpnOjkaunUQ5cxYgl7pLlXcab8qnNTnBIEcq UiJ4cypcID1hI+Re/KrGKGEMQLgoSQe62bn/k4FMCvZXRNLClUA0lzfXB 4=; Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=verizon.com; i=@verizon.com; q=dns/txt; s=corp; t=1506301967; x=1537837967; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=sBS+SGdChURZ6eRC76Fi9iJo770m9t/APIPJ26tOv9E=; b=QuXGCSN/ZRnXjhGZYACZiJCVQRxGDTrzuuCAc/ieobbErk26tbYbo1aI tUUsUkso0dZ7egZTC4JlfWpgTfjEVV2rm5JL3uqMELwkV6I01NERZJA7l wTgEyzAJPx4dPFsJGavMzgnHmYkwAlHUQAZ+5UsP29B7cqBECPkB4R3WN 0=; X-Host: viking.odc.vzwcorp.com Thread-Topic: [PATCH review for 4.9 10/50] net/mlx4_en: fix overflow in mlx4_en_init_timestamp() Thread-Index: AQHTNZtjjybBPXFZCEi+lqtgzboRyg== Accept-Language: en-US Content-Language: en-US X-Ms-Exchange-Messagesentrepresentingtype: 1 X-Ms-Exchange-Transport-Fromentityheader: Hosted X-Originating-IP: [10.144.60.250] Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: robomod@news.nic.it List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Approved: robomod@news.nic.it Lines: 102 Organization: linux.* mail to news gateway X-Original-Cc: Eric Dumazet , Tariq Toukan , Eugenia Emantayev , "David S . Miller" , "Levin, Alexander (Sasha Levin)" X-Original-Date: Mon, 25 Sep 2017 01:12:43 +0000 X-Original-Message-ID: <20170925011225.10029-10-alexander.levin@verizon.com> X-Original-References: <20170925011225.10029-1-alexander.levin@verizon.com> X-Original-Sender: linux-kernel-owner@vger.kernel.org Xref: csiph.com linux.kernel:1738693 From: Eric Dumazet [ Upstream commit 47d3a07528ecbbccf53bc4390d70b4e3d1c04fcf ] The cited commit makes a great job of finding optimal shift/multiplier values assuming a 10 seconds wrap around, but forgot to change the overflow_period computation. It overflows in cyclecounter_cyc2ns(), and the final result is 804 ms, which is silly. Lets simply use 5 seconds, no need to recompute this, given how it is supposed to work. Later, we will use a timer instead of a work queue, since the new RX allocation schem will no longer need mlx4_en_recover_from_oom() and the service_task firing every 250 ms. Fixes: 31c128b66e5b ("net/mlx4_en: Choose time-stamping shift value accordi= ng to HW frequency") Signed-off-by: Eric Dumazet Cc: Tariq Toukan Cc: Eugenia Emantayev Reviewed-by: Tariq Toukan Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/ethernet/mellanox/mlx4/en_clock.c | 18 ++++++++---------- drivers/net/ethernet/mellanox/mlx4/mlx4_en.h | 1 - 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx4/en_clock.c b/drivers/net/et= hernet/mellanox/mlx4/en_clock.c index a5fc46bbcbe2..d4d97ca12e83 100644 --- a/drivers/net/ethernet/mellanox/mlx4/en_clock.c +++ b/drivers/net/ethernet/mellanox/mlx4/en_clock.c @@ -88,10 +88,17 @@ void mlx4_en_remove_timestamp(struct mlx4_en_dev *mdev) } } =20 +#define MLX4_EN_WRAP_AROUND_SEC 10UL +/* By scheduling the overflow check every 5 seconds, we have a reasonably + * good chance we wont miss a wrap around. + * TOTO: Use a timer instead of a work queue to increase the guarantee. + */ +#define MLX4_EN_OVERFLOW_PERIOD (MLX4_EN_WRAP_AROUND_SEC * HZ / 2) + void mlx4_en_ptp_overflow_check(struct mlx4_en_dev *mdev) { bool timeout =3D time_is_before_jiffies(mdev->last_overflow_check + - mdev->overflow_period); + MLX4_EN_OVERFLOW_PERIOD); unsigned long flags; =20 if (timeout) { @@ -236,7 +243,6 @@ static const struct ptp_clock_info mlx4_en_ptp_clock_in= fo =3D { .enable =3D mlx4_en_phc_enable, }; =20 -#define MLX4_EN_WRAP_AROUND_SEC 10ULL =20 /* This function calculates the max shift that enables the user range * of MLX4_EN_WRAP_AROUND_SEC values in the cycles register. @@ -261,7 +267,6 @@ void mlx4_en_init_timestamp(struct mlx4_en_dev *mdev) { struct mlx4_dev *dev =3D mdev->dev; unsigned long flags; - u64 ns, zero =3D 0; =20 /* mlx4_en_init_timestamp is called for each netdev. * mdev->ptp_clock is common for all ports, skip initialization if @@ -285,13 +290,6 @@ void mlx4_en_init_timestamp(struct mlx4_en_dev *mdev) ktime_to_ns(ktime_get_real())); write_unlock_irqrestore(&mdev->clock_lock, flags); =20 - /* Calculate period in seconds to call the overflow watchdog - to make - * sure counter is checked at least once every wrap around. - */ - ns =3D cyclecounter_cyc2ns(&mdev->cycles, mdev->cycles.mask, zero, &zero)= ; - do_div(ns, NSEC_PER_SEC / 2 / HZ); - mdev->overflow_period =3D ns; - /* Configure the PHC */ mdev->ptp_clock_info =3D mlx4_en_ptp_clock_info; snprintf(mdev->ptp_clock_info.name, 16, "mlx4 ptp"); diff --git a/drivers/net/ethernet/mellanox/mlx4/mlx4_en.h b/drivers/net/eth= ernet/mellanox/mlx4/mlx4_en.h index a3528dd1e72e..df0f39611c5e 100644 --- a/drivers/net/ethernet/mellanox/mlx4/mlx4_en.h +++ b/drivers/net/ethernet/mellanox/mlx4/mlx4_en.h @@ -419,7 +419,6 @@ struct mlx4_en_dev { struct cyclecounter cycles; struct timecounter clock; unsigned long last_overflow_check; - unsigned long overflow_period; struct ptp_clock *ptp_clock; struct ptp_clock_info ptp_clock_info; struct notifier_block nb; --=20 2.11.0