From patchwork Thu Jun 14 00:53:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saeed Mahameed X-Patchwork-Id: 929150 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=mellanox.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 415lVY4KVGz9s01 for ; Thu, 14 Jun 2018 10:53:41 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935850AbeFNAxW (ORCPT ); Wed, 13 Jun 2018 20:53:22 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:34583 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S935720AbeFNAxW (ORCPT ); Wed, 13 Jun 2018 20:53:22 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from saeedm@mellanox.com) with ESMTPS (AES256-SHA encrypted); 14 Jun 2018 03:55:41 +0300 Received: from stpd.hsd1.ca.comcast.net ([172.16.5.53]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id w5E0rE24007924; Thu, 14 Jun 2018 03:53:15 +0300 From: Saeed Mahameed To: Tariq Toukan , Martin KaFai Lau Cc: netdev@vger.kernel.org, Saeed Mahameed , Eric Dumazet Subject: [net RFC] net/mlx4_en: Use frag stride in crossing page boundary condition Date: Wed, 13 Jun 2018 17:53:09 -0700 Message-Id: <20180614005309.17357-1-saeedm@mellanox.com> X-Mailer: git-send-email 2.17.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org When a new rx packet arrives, the rx path will decide whether to reuse the same page or not according to the current rx frag page offset and frag size, i.e: release = frags->page_offset + frag_info->frag_size > PAGE_SIZE; Martin debugged this and he showed that this can cause mlx4 XDP to reuse buffers when it shouldn't. Using frag_info->frag_size is wrong since frag size is always the port mtu and the frag stride might be larger, especially in XDP case where frag_stride == PAGE_SIZE. In XDP there is an assumption to have a page per packet and reuse can break such assumption and might cause packet data corruptions, since in XDP frag_offset will always reset to the beginning of the page when refilling the rx buffer. Fix this by using the stride size rather than frag size in "release" condition evaluation. For non XDP setup this will yield the same behavior since frag_stride already equals to ALIGN(frag_size, SMP_CACHE_BYTES) and on XDP setup the "release" condition will always be true as it is supposed to be since frag_stride == PAGE_SIZE. Fixes: 34db548bfb95 ("mlx4: add page recycling in receive path") Signed-off-by: Saeed Mahameed Reported-by: Martin KaFai Lau CC: Eric Dumazet --- drivers/net/ethernet/mellanox/mlx4/en_rx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/mellanox/mlx4/en_rx.c b/drivers/net/ethernet/mellanox/mlx4/en_rx.c index 5c613c6663da..f63dde0288b7 100644 --- a/drivers/net/ethernet/mellanox/mlx4/en_rx.c +++ b/drivers/net/ethernet/mellanox/mlx4/en_rx.c @@ -504,7 +504,7 @@ static int mlx4_en_complete_rx_desc(struct mlx4_en_priv *priv, u32 sz_align = ALIGN(frag_size, SMP_CACHE_BYTES); frags->page_offset += sz_align; - release = frags->page_offset + frag_info->frag_size > PAGE_SIZE; + release = frags->page_offset + frag_info->frag_stride > PAGE_SIZE; } if (release) { dma_unmap_page(priv->ddev, dma, PAGE_SIZE, priv->dma_dir);