Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1952525ybv; Fri, 14 Feb 2020 08:47:21 -0800 (PST) X-Google-Smtp-Source: APXvYqxk8NC18woCUpnSPyp7fBYwjGKIT+z2nA/FwnDC1yloa09QwBJV/lMz0kW1YFWLqOJ9bziZ X-Received: by 2002:aca:c70b:: with SMTP id x11mr2527759oif.29.1581698841655; Fri, 14 Feb 2020 08:47:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581698841; cv=none; d=google.com; s=arc-20160816; b=s1EmVT8xpcj8sSNP1FS94MjFest1CGppMybcUMvINcNbzO642M7WFY4KuE93yj1oLv sD7Qz2UYIQhsljwVNFJDkX1R6VpxarF0hiDMNdZvaeXNyK7fohxetcL4MurL/HUHwcpK Tj2ODuIpliNi4g4BFm1KbweRXaxQUOoPACs3Een6SeESsxUwt+RULNM2MxId5+7QC4YM CT/3nJkBMByy3/4kV5F3WqOm1DVNvnnOhnmAG5Mf0HN3UnETXjPiqi+hRBFV1DDde5JO tMVTxKrD3MO4eDyaFVISVtJT+TX4slYy+F8CYqEfNDzJMarrrVujC5YR5x3lvqwkZDOP 7huA== 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=nydCedaa4PXoBz/Y2pWHeUuqYiD7oPfJ9fXQVqhbn2s=; b=1LSO5ovUx4K7GdEYYybhCigpyhUhIWJx+neesvBlx72iL48eUZU0UZ25lsXzQD0Phz QlknPi+NNuKKG13mSE/zthcLUdvYzAsks6mH2m5j/1zmXgQE9G8J8DEiEX9nPPcSq7go GkOoY/GJUTTku/qTZzXoHS5+cpTRRsxo05KAFyc6xQueOXc4aUq8+gomuXwBxRu9/pQZ BH9vp+pm3b5lOT59zIHuvdwHFfP/PPe9dPliTfF8Mb8/3JyP7SR3vaODx8mKyDnlArup fWRBFxdtx3/doGSS1khrPranih60ZSYqixfXzluzED+/OeZEneAPmEIAzFk9rzWQ8Ots GpsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Ne+AsbrE; 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 z62si3078543oiz.271.2020.02.14.08.47.09; Fri, 14 Feb 2020 08:47:21 -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=Ne+AsbrE; 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 S2405909AbgBNQpe (ORCPT + 99 others); Fri, 14 Feb 2020 11:45:34 -0500 Received: from mail.kernel.org ([198.145.29.99]:56220 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392979AbgBNQVd (ORCPT ); Fri, 14 Feb 2020 11:21:33 -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 E3461246B9; Fri, 14 Feb 2020 16:21:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581697292; bh=N4OFUR8Rjq/tz9yIJS8wJbqHyEE3LrRcBxWuos5/4N0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ne+AsbrE7sLVd3PRzdSxD8jePeFK80DlR+fWOZoYOerMa7QX4ZA5YKOXE+nIaj2cB z1hybGV91PWaNdSrGmffr2V63pw/UQkfXpc1C3V/ypADGTogu0g+NdPxFMgWiNgKye Ew106xzkA61Drxn/K4rKLDCwNxeYx/RWcAR0N24Q= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Vladimir Oltean , Richard Cochran , "David S . Miller" , Sasha Levin , netdev@vger.kernel.org Subject: [PATCH AUTOSEL 4.9 007/141] gianfar: Fix TX timestamping with a stacked DSA driver Date: Fri, 14 Feb 2020 11:19:07 -0500 Message-Id: <20200214162122.19794-7-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200214162122.19794-1-sashal@kernel.org> References: <20200214162122.19794-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review 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: 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 60bd1b36df606..b665d27f8e299 100644 --- a/drivers/net/ethernet/freescale/gianfar.c +++ b/drivers/net/ethernet/freescale/gianfar.c @@ -2688,13 +2688,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; @@ -2708,7 +2712,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; @@ -2718,7 +2722,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