Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp1136579ybf; Thu, 27 Feb 2020 05:43:36 -0800 (PST) X-Google-Smtp-Source: APXvYqwjknp9QWI25GoZbLSS7uMjec3JrmgwKlBt8O9Ai0R0QYzAbKSugJohQ8iAZvP1834pDjRv X-Received: by 2002:aca:4106:: with SMTP id o6mr3305587oia.173.1582811016874; Thu, 27 Feb 2020 05:43:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582811016; cv=none; d=google.com; s=arc-20160816; b=TAoXJjAImEv63hZTpXW+VTqdYDYGm8/D9qMeHSTLw/I7hNGhLcnDLjbWNgYvBTY4gu V3amYDb8vSdZ0s1nOabwN61oYe9RtlEFcOdFMYJSroyv4ZTWik7vGP6CDZag8Dlam7Z0 o2NwiI3Vn+FrZ1yD0vxjG5zODl8wJO4NKfbWikXVliUIjyi8IsE8DmCnvAGLqGCmR5RK h1X5T7GgTKv65PvtFDwYyWIrjqpajlUjq+UCrkH6/WXtGk/XU9weewHRcx4I+wZ9KNwh KDlDkRsz0vaD0t0uM2/nRwpdtXiWSO17kQLKAv+U6jz6onZywc2K1pHaaM0ONAnHqYGe xMTA== 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=FFVeVWIi1VoOVw6tVIwp5ibqsmq0TE6zV8Uwg7XUX6U=; b=Sh3ttm6RLFifNJES8BAscJ6ZOaRSXh1ZTBWGSNVP8rwV2c/vnty4O/WPL3ncrIQJKd zJYzsecetaqzt+w68iulcptWMeVr/H69FEFOtTOe8udJqBGz/iqQHp7ibJjsA+wA4twX Dvu7Sg6MiMzZ8fxyor1P46MK+aSV62kw34+5oeU1KdeXPKZg25Fy1+XtiwNYlgliUhOH aPTgzNrE5n+CgfA7+QFBJVpTRAGXwnP8GqkTcOtzx2VmVPsojtjBX3nEONTBVdl4tPZJ N9IFyZWJLOCdWV2YOhIAb/OF37HcoZtjhlAnYfJPiJXgwohg1VRZjUE9WZG8ANtHM7IS ERDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FBUGHRd6; 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 j143si1324656oib.16.2020.02.27.05.43.24; Thu, 27 Feb 2020 05:43:36 -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=FBUGHRd6; 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 S1729809AbgB0Nme (ORCPT + 99 others); Thu, 27 Feb 2020 08:42:34 -0500 Received: from mail.kernel.org ([198.145.29.99]:37522 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729784AbgB0Nma (ORCPT ); Thu, 27 Feb 2020 08:42:30 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.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 9D5F720726; Thu, 27 Feb 2020 13:42:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582810950; bh=ceEKIn991IqRty82jZ7YFd0bpyp4Qtq2iCa6roB5hYk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FBUGHRd6vlp8whaKyaWpjAlKCSfGaiAY2oH+l6WsdxDaG+pdHY8IuFJIwYxvKnR95 Gkfwswu872wdDj2uEP71kEuc4XzQybUcHS/OIFlQo3bOnBYGNJRRRONlDO4BYeiz1N lVUQ+WUX+3EnHPDTtCAFNokSNgv3eBtNeaCl0lkQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vladimir Oltean , Richard Cochran , "David S. Miller" , Sasha Levin Subject: [PATCH 4.4 021/113] gianfar: Fix TX timestamping with a stacked DSA driver Date: Thu, 27 Feb 2020 14:35:37 +0100 Message-Id: <20200227132215.055211164@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200227132211.791484803@linuxfoundation.org> References: <20200227132211.791484803@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Vladimir Oltean [ Upstream commit c26a2c2ddc0115eb088873f5c309cf46b982f522 ] The driver wrongly assumes that it is the only entity that can set the SKBTX_IN_PROGRESS bit of the current skb. Therefore, in the gfar_clean_tx_ring function, where the TX timestamp is collected if necessary, the aforementioned bit is used to discriminate whether or not the TX timestamp should be delivered to the socket's error queue. But a stacked driver such as a DSA switch can also set the SKBTX_IN_PROGRESS bit, which is actually exactly what it should do in order to denote that the hardware timestamping process is undergoing. Therefore, gianfar would misinterpret the "in progress" bit as being its own, and deliver a second skb clone in the socket's error queue, completely throwing off a PTP process which is not expecting to receive it, _even though_ TX timestamping is not enabled for gianfar. There have been discussions [0] as to whether non-MAC drivers need or not to set SKBTX_IN_PROGRESS at all (whose purpose is to avoid sending 2 timestamps, a sw and a hw one, to applications which only expect one). But as of this patch, there are at least 2 PTP drivers that would break in conjunction with gianfar: the sja1105 DSA switch and the felix switch, by way of its ocelot core driver. So regardless of that conclusion, fix the gianfar driver to not do stuff based on flags set by others and not intended for it. [0]: https://www.spinics.net/lists/netdev/msg619699.html Fixes: f0ee7acfcdd4 ("gianfar: Add hardware TX timestamping support") Signed-off-by: Vladimir Oltean Acked-by: Richard Cochran Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/ethernet/freescale/gianfar.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/freescale/gianfar.c b/drivers/net/ethernet/freescale/gianfar.c index 2d61369f586f7..37cc1f838dd8b 100644 --- a/drivers/net/ethernet/freescale/gianfar.c +++ b/drivers/net/ethernet/freescale/gianfar.c @@ -2679,13 +2679,17 @@ static void gfar_clean_tx_ring(struct gfar_priv_tx_q *tx_queue) skb_dirtytx = tx_queue->skb_dirtytx; while ((skb = tx_queue->tx_skbuff[skb_dirtytx])) { + bool do_tstamp; + + do_tstamp = (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) && + priv->hwts_tx_en; frags = skb_shinfo(skb)->nr_frags; /* When time stamping, one additional TxBD must be freed. * Also, we need to dma_unmap_single() the TxPAL. */ - if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS)) + if (unlikely(do_tstamp)) nr_txbds = frags + 2; else nr_txbds = frags + 1; @@ -2699,7 +2703,7 @@ static void gfar_clean_tx_ring(struct gfar_priv_tx_q *tx_queue) (lstatus & BD_LENGTH_MASK)) break; - if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS)) { + if (unlikely(do_tstamp)) { next = next_txbd(bdp, base, tx_ring_size); buflen = be16_to_cpu(next->length) + GMAC_FCB_LEN + GMAC_TXPAL_LEN; @@ -2709,7 +2713,7 @@ static void gfar_clean_tx_ring(struct gfar_priv_tx_q *tx_queue) dma_unmap_single(priv->dev, be32_to_cpu(bdp->bufPtr), buflen, DMA_TO_DEVICE); - if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS)) { + if (unlikely(do_tstamp)) { struct skb_shared_hwtstamps shhwtstamps; u64 *ns = (u64 *)(((uintptr_t)skb->data + 0x10) & ~0x7UL); -- 2.20.1