Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3200614pxb; Mon, 9 Nov 2020 05:27:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJzYhiyVHzqKM863a5mavA7I770j8pzHBZv9dc4DqxIvkAU9RnfOqtFP/TsmVOIvgBwcObjG X-Received: by 2002:a17:906:3a97:: with SMTP id y23mr14677599ejd.250.1604928446985; Mon, 09 Nov 2020 05:27:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604928446; cv=none; d=google.com; s=arc-20160816; b=FlZLpc2yEp57oqfRM6GtUp3Ngf2P3iW6k47ixwBLV+LUJhDa43hjD925F05CFK7el/ x2KuNfl502TFOY5OHxZbDOLarMUnOiNdo2/7P26I7pK27iIHZkvum8NJMPlhbhqcfTlp VFbWUWDAQ2eNWryG4LdJkcWUKspdq4soGhm/fDMSMSqrqUZ66SmqxUIFmOrlQfoSWJcq XjNBEfkPLuEV30Jn3jqTFvUEAstLingbcFR9+wE/KsKgjub7N8hWeam9XQGSwm6H9Mey X9ERydzizS08lEL/5pRMVBCaRDvVInz7ZJALg7nCDzVwNSpFSvjjTgH0DEEmRWDgTXDi ehdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=z+gIyAu0GZZbMVpVPLPi/cjUR02jAV/r4jK4B1LqRcM=; b=R5oii7lb/d/Ol3MVIbXMJFYI6r5dhzELXXZwBiTMKsCvEgB5jy2ZmO7DInnOUfN3Pt Y+2arVI6Jk4VqzvtLXj3woAj3Gvp5PH+S7TCrTzZA/m0T0oCyP7CBZS+mnMGO/AnZHjP Z2PoaXOm/IbwRxdtGJxcKvg3MG23Ecb5nMQ+k1y2/vmtk1JPhdUzKDjwMroITtFFU2rF 5o1NmkjD2Y9ksCwe7PIdJ31dJ6g12bEFY9GnRi+AkKhBft3Rnn3o7prGlLSVf7LOhnSh LIU/MffBnmDa4FvnTitE+QhPh+6Kjoi6XNoMV35xlqKQo5Q/8UniK65R+G60sd1Jt1Le 7WmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bOTDGFFh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f19si6544615ejh.370.2020.11.09.05.27.03; Mon, 09 Nov 2020 05:27:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bOTDGFFh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387830AbgKINYg (ORCPT + 99 others); Mon, 9 Nov 2020 08:24:36 -0500 Received: from mail.kernel.org ([198.145.29.99]:46116 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387757AbgKINSr (ORCPT ); Mon, 9 Nov 2020 08:18:47 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 961F120731; Mon, 9 Nov 2020 13:18:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604927926; bh=E28vdnPt6e8xzeM4ATXGAUZwGqi6W3a7h1Nf1PRKSys=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bOTDGFFhXC7vcN31wsEQFwYYJiHHjaf/e7i6HEsH5R4r0YJjHX1Mubvp2feU6xMEL 2ysC16eN1YsQSARpEqDTSdUgA2cpR9oKOvzBzzXa3Mwj5mrFTm2BI/579bepQjeb5l 97m4xaQqSXLlzqx7AEZqE6VXbjD35peuocfy+C+c= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, James Jurack , Jakub Kicinski , Claudiu Manoil Subject: [PATCH 5.9 028/133] gianfar: Replace skb_realloc_headroom with skb_cow_head for PTP Date: Mon, 9 Nov 2020 13:54:50 +0100 Message-Id: <20201109125032.074358576@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201109125030.706496283@linuxfoundation.org> References: <20201109125030.706496283@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Claudiu Manoil [ Upstream commit d145c9031325fed963a887851d9fa42516efd52b ] When PTP timestamping is enabled on Tx, the controller inserts the Tx timestamp at the beginning of the frame buffer, between SFD and the L2 frame header. This means that the skb provided by the stack is required to have enough headroom otherwise a new skb needs to be created by the driver to accommodate the timestamp inserted by h/w. Up until now the driver was relying on skb_realloc_headroom() to create new skbs to accommodate PTP frames. Turns out that this method is not reliable in this context at least, as skb_realloc_headroom() for PTP frames can cause random crashes, mostly in subsequent skb_*() calls, when multiple concurrent TCP streams are run at the same time with the PTP flow on the same device (as seen in James' report). I also noticed that when the system is loaded by sending multiple TCP streams, the driver receives cloned skbs in large numbers. skb_cow_head() instead proves to be stable in this scenario, and not only handles cloned skbs too but it's also more efficient and widely used in other drivers. The commit introducing skb_realloc_headroom in the driver goes back to 2009, commit 93c1285c5d92 ("gianfar: reallocate skb when headroom is not enough for fcb"). For practical purposes I'm referencing a newer commit (from 2012) that brings the code to its current structure (and fixes the PTP case). Fixes: 9c4886e5e63b ("gianfar: Fix invalid TX frames returned on error queue when time stamping") Reported-by: James Jurack Suggested-by: Jakub Kicinski Signed-off-by: Claudiu Manoil Link: https://lore.kernel.org/r/20201029081057.8506-1-claudiu.manoil@nxp.com Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/freescale/gianfar.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) --- a/drivers/net/ethernet/freescale/gianfar.c +++ b/drivers/net/ethernet/freescale/gianfar.c @@ -1829,20 +1829,12 @@ static netdev_tx_t gfar_start_xmit(struc fcb_len = GMAC_FCB_LEN + GMAC_TXPAL_LEN; /* make space for additional header when fcb is needed */ - if (fcb_len && unlikely(skb_headroom(skb) < fcb_len)) { - struct sk_buff *skb_new; - - skb_new = skb_realloc_headroom(skb, fcb_len); - if (!skb_new) { + if (fcb_len) { + if (unlikely(skb_cow_head(skb, fcb_len))) { dev->stats.tx_errors++; dev_kfree_skb_any(skb); return NETDEV_TX_OK; } - - if (skb->sk) - skb_set_owner_w(skb_new, skb->sk); - dev_consume_skb_any(skb); - skb = skb_new; } /* total number of fragments in the SKB */