Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3209199pxb; Mon, 9 Nov 2020 05:39:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJzuPV2g//mxXK+skC/V+IZJ1fA0Ke8+WPnjgGJzFFpV9EYYJ9j5Di+uBFeOl4PQRzrGgWZh X-Received: by 2002:a17:906:d7a3:: with SMTP id pk3mr14633156ejb.208.1604929155818; Mon, 09 Nov 2020 05:39:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604929155; cv=none; d=google.com; s=arc-20160816; b=p+hDxFMsV5R8I4ZWvo08n/qa7YyOxayyMLaoZfXs0gDQv7YYuffex7StTaRe14d9/D PTunp83W1W0S8GYyTkrJ0YQzWRWgqxRW7L1RvZEv29+pqcbNoM0dYYz5ZLT+gfCRCajx YKzv1ZzpFVU5fE1ZrlB8v7wMwO3E3TNH+0gfkx300vHR95ooEFz592dj44mnJmG77Pej ARrtCB6Hper2JvbwiHlbaw4aWvp7SwkAUAr17KtquejgE7ykX3g2gXYPubFIq9mDkYW4 kuMiSEEPJcQVeBoFVtoN+M7Zz80A8QRcslXBZjU2wDS6jSGaRB4RBzvXplFb0tNGGeoE YBOQ== 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=MmuwUQDP6+QbrrKzJ088WWyCdCWzkBT1+cbHXh0j0rI=; b=uTvZzDXe5cA9jIC4t8LWojkU9qCRQuAPYA01DqKyHM7Dkv6AeVMowLQAD5/m/+yR4O VV0A++87ayq/DVboFSLJ/nAyYddIxHwU9ZIM+qBeXa6s7FGGPGTo2LUJXShJISl/8GCL hKSsfBL002VTPUxh+NJqIkh35d+TcmhROMukK06mltfQ6nw7S/rd3zn3aytW5/o2fQQz LdF5jLcD7Dd6NPeGSZp/hLk79c4NmjDpP5kSDK/241VnLn8VLeHH4Q6zr/hkmBg4RNF3 Qa4yW0mV4Kngfhq8MhDKXA/rHzA/KZEkmlUYslkDTsoLi0ABx5aNGX5N1MHJeg+SFZew QSZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CS3J+rLT; 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 t1si7091732ejy.446.2020.11.09.05.38.52; Mon, 09 Nov 2020 05:39:15 -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=CS3J+rLT; 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 S1731075AbgKINhi (ORCPT + 99 others); Mon, 9 Nov 2020 08:37:38 -0500 Received: from mail.kernel.org ([198.145.29.99]:57292 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729913AbgKINEM (ORCPT ); Mon, 9 Nov 2020 08:04:12 -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 2922320663; Mon, 9 Nov 2020 13:04:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604927049; bh=kmMfjDW4t3+wdiEPhf8tYLDHxq/71ArM7bQTrfZPWbs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CS3J+rLT32sipt8DL3slSG5BBlbM/6NbHc7RuS09v1bR4cM1k9YRB3A75gMaNjIXH t7qaOC7r7gYlkCle589EUlqW4o8Bvy/vc6nj53uQJmJIrBum8smXrR2T1fl0PUHfUp eAZOI9wMRqBUpC9zG2r6ioy0+3sw5pKvGpVUe6i4= 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 4.9 094/117] gianfar: Replace skb_realloc_headroom with skb_cow_head for PTP Date: Mon, 9 Nov 2020 13:55:20 +0100 Message-Id: <20201109125030.160234760@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201109125025.630721781@linuxfoundation.org> References: <20201109125025.630721781@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 @@ -2367,20 +2367,12 @@ static int gfar_start_xmit(struct sk_buf 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 */