Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp447433ybl; Tue, 28 Jan 2020 06:08:53 -0800 (PST) X-Google-Smtp-Source: APXvYqwZ/k1qGET4AQM28tMoUp2gJJH5nrmYKtXR97WGDDJUgtJUhmoAOISdMIOjB9E6xZcM4yYo X-Received: by 2002:aca:2109:: with SMTP id 9mr2768530oiz.119.1580220533403; Tue, 28 Jan 2020 06:08:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580220533; cv=none; d=google.com; s=arc-20160816; b=Azu7OPZiFxAU+0aAvS1PL6TITJEh8DWEt3eDSI1sCHjfadUfCpHCW2R/T7DLIGGWgo U5NZ/8RxDQrg+WddV51oe8gCECA00GyCEw028LKQ/PynKKK3i3gckYI5CWMqlaYU7SV0 YQTeNX5bOKqWWZvgwr5ZvnefVXGhfG3NMIoQg6BE9f1xcYvSXHdibK+oKT+hta7fWq9K 8gGEEVn+J1uVQYCsKsmx+rrtR+v0EfBzvFfwOMwENnknEaUTJhS6nSkgur/791Pb3w5S u7ILgY1U/9EYy2S1aKVMwBv+ZC1Iy88dWx2VzfhrA892hqQOQqFnMp4jq3EsUOMcQ5lN 8ekg== 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=9lbgxyvNRjbYYGHlA2y0HCBgVSPlixwVK1ls26eV5jw=; b=xccS//Ad3j3P3xwBdn3gCCRimKh6iH30e3ZkK1UD28G27DiBgVWQRUNxx1gyebVWlZ MIq+x00O1F44p2QBwdNWA9sUF2FkR1yR8qh3mKpRbv1QDkpzOT+6muuXH9Xs6dIFX5vh naubGiIbJQLH0O4haOjuXSqhWI+77QqeireIJ2g7u+mXCYegYuPSmZeNft4Jvxl6S3rb aLeM1lD+9dv+jbSHN+hzUq7tq/4+eMHx1UHztCLsHjKuOw7X6fE5Lz2f8Fju80ExSCF7 nZSz57HaM9qj4SGdIpTpWqE7ZutE+ur+mqTCnb7bN/Dl1C9saM9X2sPHck+WL4nnF14z 9Ncw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="V/FWUTGu"; 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 a28si8607513otd.257.2020.01.28.06.08.33; Tue, 28 Jan 2020 06:08:53 -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="V/FWUTGu"; 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 S1727912AbgA1ODl (ORCPT + 99 others); Tue, 28 Jan 2020 09:03:41 -0500 Received: from mail.kernel.org ([198.145.29.99]:50374 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727877AbgA1ODf (ORCPT ); Tue, 28 Jan 2020 09:03:35 -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 2345D2468D; Tue, 28 Jan 2020 14:03:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580220214; bh=Y8GCpmQnOmVHFtUiBvlcZHyG45MewdZ47K+7M+lP/AM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V/FWUTGuFHDJuJXrP+Y72ggRKoYpdbeGsv/5ogpSq9t8KAcA11v3JxOclbTJdfthr 2r0sAbsTo+OcM+IEgmmRJLZbfFh5IUC50rzVv5UcMmFsRDD/cF+RrHeiNvEs1a5uA9 EhsxFLmOXc7OhU+rJsMvFzrmnIJMDOJcV+B8NfFg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ido Schimmel , Shalom Toledo , Jiri Pirko , "David S. Miller" Subject: [PATCH 5.4 062/104] mlxsw: switchx2: Do not modify cloned SKBs during xmit Date: Tue, 28 Jan 2020 15:00:23 +0100 Message-Id: <20200128135826.124448690@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200128135817.238524998@linuxfoundation.org> References: <20200128135817.238524998@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: Ido Schimmel commit 63963d0f9d17be83d0e419e03282847ecc2c3715 upstream. The driver needs to prepend a Tx header to each packet it is transmitting. The header includes information such as the egress port and traffic class. The addition of the header requires the driver to modify the SKB's header and therefore it must not be shared. Otherwise, we risk hitting various race conditions. For example, when a packet is flooded (cloned) by the bridge driver to two switch ports swp1 and swp2: t0 - mlxsw_sp_port_xmit() is called for swp1. Tx header is prepended with swp1's port number t1 - mlxsw_sp_port_xmit() is called for swp2. Tx header is prepended with swp2's port number, overwriting swp1's port number t2 - The device processes data buffer from t0. Packet is transmitted via swp2 t3 - The device processes data buffer from t1. Packet is transmitted via swp2 Usually, the device is fast enough and transmits the packet before its Tx header is overwritten, but this is not the case in emulated environments. Fix this by making sure the SKB's header is writable by calling skb_cow_head(). Since the function ensures we have headroom to push the Tx header, the check further in the function can be removed. v2: * Use skb_cow_head() instead of skb_unshare() as suggested by Jakub * Remove unnecessary check regarding headroom Fixes: 31557f0f9755 ("mlxsw: Introduce Mellanox SwitchX-2 ASIC support") Signed-off-by: Ido Schimmel Reported-by: Shalom Toledo Acked-by: Jiri Pirko Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/mellanox/mlxsw/switchx2.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) --- a/drivers/net/ethernet/mellanox/mlxsw/switchx2.c +++ b/drivers/net/ethernet/mellanox/mlxsw/switchx2.c @@ -299,22 +299,17 @@ static netdev_tx_t mlxsw_sx_port_xmit(st u64 len; int err; + if (skb_cow_head(skb, MLXSW_TXHDR_LEN)) { + this_cpu_inc(mlxsw_sx_port->pcpu_stats->tx_dropped); + dev_kfree_skb_any(skb); + return NETDEV_TX_OK; + } + memset(skb->cb, 0, sizeof(struct mlxsw_skb_cb)); if (mlxsw_core_skb_transmit_busy(mlxsw_sx->core, &tx_info)) return NETDEV_TX_BUSY; - if (unlikely(skb_headroom(skb) < MLXSW_TXHDR_LEN)) { - struct sk_buff *skb_orig = skb; - - skb = skb_realloc_headroom(skb, MLXSW_TXHDR_LEN); - if (!skb) { - this_cpu_inc(mlxsw_sx_port->pcpu_stats->tx_dropped); - dev_kfree_skb_any(skb_orig); - return NETDEV_TX_OK; - } - dev_consume_skb_any(skb_orig); - } mlxsw_sx_txhdr_construct(skb, &tx_info); /* TX header is consumed by HW on the way so we shouldn't count its * bytes as being sent.