From patchwork Tue Jul 21 07:49:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Li RongQing X-Patchwork-Id: 1332833 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=osuosl.org (client-ip=140.211.166.138; helo=whitealder.osuosl.org; envelope-from=intel-wired-lan-bounces@osuosl.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=baidu.com Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4B9rMj1Wtmz9sRk for ; Tue, 21 Jul 2020 17:49:20 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 58ABF85404; Tue, 21 Jul 2020 07:49:19 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id e-DhdxogSy7d; Tue, 21 Jul 2020 07:49:17 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by whitealder.osuosl.org (Postfix) with ESMTP id B429281EB7; Tue, 21 Jul 2020 07:49:17 +0000 (UTC) X-Original-To: intel-wired-lan@lists.osuosl.org Delivered-To: intel-wired-lan@lists.osuosl.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by ash.osuosl.org (Postfix) with ESMTP id F33281BF303 for ; Tue, 21 Jul 2020 07:49:16 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id EED2489219 for ; Tue, 21 Jul 2020 07:49:16 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id bVdmiMXI-csM for ; Tue, 21 Jul 2020 07:49:14 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from baidu.com (mx24.baidu.com [111.206.215.185]) by hemlock.osuosl.org (Postfix) with ESMTP id 6D5ED89200 for ; Tue, 21 Jul 2020 07:49:14 +0000 (UTC) Received: from BJHW-Mail-Ex13.internal.baidu.com (unknown [10.127.64.36]) by Forcepoint Email with ESMTPS id 67670E92BED48DA19C78; Tue, 21 Jul 2020 15:49:06 +0800 (CST) Received: from BJHW-Mail-Ex13.internal.baidu.com (10.127.64.36) by BJHW-Mail-Ex13.internal.baidu.com (10.127.64.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3; Tue, 21 Jul 2020 15:49:06 +0800 Received: from BJHW-Mail-Ex13.internal.baidu.com ([100.100.100.36]) by BJHW-Mail-Ex13.internal.baidu.com ([100.100.100.36]) with mapi id 15.01.1979.003; Tue, 21 Jul 2020 15:49:00 +0800 From: "Li,Rongqing" To: Magnus Karlsson Thread-Topic: [Intel-wired-lan] [PATCH 1/2] xdp: i40e: ixgbe: ixgbevf: not flip rx buffer for copy mode xdp Thread-Index: AQHWXmZtsIr9AHsudEOLFGU9se5TiKkRPZUQgABrUQA= Date: Tue, 21 Jul 2020 07:49:00 +0000 Message-ID: References: <1594967062-20674-1-git-send-email-lirongqing@baidu.com> <1594967062-20674-2-git-send-email-lirongqing@baidu.com> Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [172.22.197.254] x-baidu-bdmsfe-datecheck: 1_BJHW-Mail-Ex13_2020-07-21 15:49:06:416 MIME-Version: 1.0 Subject: [Intel-wired-lan] =?utf-8?q?=E7=AD=94=E5=A4=8D=3A__=5BPATCH_1/2=5D_?= =?utf-8?q?xdp=3A_i40e=3A_ixgbe=3A_ixgbevf=3A_not_flip_rx_buffer_for_copy_mo?= =?utf-8?q?de_xdp?= X-BeenThere: intel-wired-lan@osuosl.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Wired Ethernet Linux Kernel Driver Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Network Development , =?utf-8?b?QmrDtnJuIFTDtnBl?= =?utf-8?b?bA==?= , intel-wired-lan , "Karlsson, Magnus" Errors-To: intel-wired-lan-bounces@osuosl.org Sender: "Intel-wired-lan" > -----邮件原件----- > 发件人: Li,Rongqing > 发送时间: 2020年7月21日 9:43 > 收件人: 'Magnus Karlsson' > 抄送: Network Development ; intel-wired-lan > ; Karlsson, Magnus > ; Björn Töpel > 主题: 答复: [Intel-wired-lan] [PATCH 1/2] xdp: i40e: ixgbe: ixgbevf: not flip rx > buffer for copy mode xdp > > > > > -----邮件原件----- > > 发件人: Magnus Karlsson [mailto:magnus.karlsson@gmail.com] > > 发送时间: 2020年7月20日 15:21 > > 收件人: Li,Rongqing > > 抄送: Network Development ; intel-wired-lan > > ; Karlsson, Magnus > > ; Björn Töpel > > 主题: Re: [Intel-wired-lan] [PATCH 1/2] xdp: i40e: ixgbe: ixgbevf: not > > flip rx buffer for copy mode xdp > > > > On Fri, Jul 17, 2020 at 8:24 AM Li RongQing wrote: > > > > > > i40e/ixgbe/ixgbevf_rx_buffer_flip in copy mode xdp can lead to data > > > corruption, like the following flow: > > > > > > 1. first skb is not for xsk, and forwarded to another device > > > or socket queue > > > 2. seconds skb is for xsk, copy data to xsk memory, and page > > > of skb->data is released > > > 3. rx_buff is reusable since only first skb is in it, but > > > *_rx_buffer_flip will make that page_offset is set to > > > first skb data > > > 4. then reuse rx buffer, first skb which still is living > > > will be corrupted. > e, but known size type */ > > > u32 id; > > > @@ -73,6 +75,7 @@ struct xdp_buff { > > > struct xdp_rxq_info *rxq; > > > struct xdp_txq_info *txq; > > > u32 frame_sz; /* frame size to deduce data_hard_end/reserved > > > tailroom*/ > > > + u32 flags; > > > > RongQing, > > > > Sorry that I was not clear enough. Could you please submit the simple > > patch you had, the one that only tests for the memory type. > > > > if (xdp->rxq->mem.type != MEM_TYPE_XSK_BUFF_POOL) > > i40e_rx_buffer_flip(rx_ring, rx_buffer, size); > > > > I do not think that adding a flags field in the xdp_mem_info to fix an > > Intel driver problem will be hugely popular. The struct is also meant > > to contain long lived information, not things that will frequently change. > > > > > Thank you Magnus > > My original suggestion is wrong , it should be following > > if (xdp->rxq->mem.type == MEM_TYPE_XSK_BUFF_POOL) > i40e_rx_buffer_flip(rx_ring, rx_buffer, size); > > > but I feel it is not enough to only check mem.type, it must ensure that > map_type is BPF_MAP_TYPE_XSKMAP ? but it is not expose. > > other maptype, like BPF_MAP_TYPE_DEVMAP, and if mem.type is > MEM_TYPE_PAGE_SHARED, not flip the rx buffer, will cause data corruption. > > > -Li > > How about this? --- a/drivers/net/ethernet/intel/i40e/i40e_txrx.c +++ b/drivers/net/ethernet/intel/i40e/i40e_txrx.c @@ -2394,7 +2394,10 @@ static int i40e_clean_rx_irq(struct i40e_ring *rx_ring, int budget) if (xdp_res & (I40E_XDP_TX | I40E_XDP_REDIR)) { xdp_xmit |= xdp_res; - i40e_rx_buffer_flip(rx_ring, rx_buffer, size); + + if (xdp.rxq->mem.type == MEM_TYPE_XSK_BUFF_POOL || + xdp_get_map_type() != BPF_MAP_TYPE_XSKMAP) + i40e_rx_buffer_flip(rx_ring, rx_buffer, size); } else { rx_buffer->pagecnt_bias++; } diff --git a/include/linux/filter.h b/include/linux/filter.h index 259377723603..94f4435a77f3 100644 --- a/include/linux/filter.h +++ b/include/linux/filter.h @@ -919,6 +919,17 @@ static inline void xdp_clear_return_frame_no_direct(void) ri->kern_flags &= ~BPF_RI_F_RF_NO_DIRECT; } +static enum bpf_map_type xdp_get_map_type(void) +{ + struct bpf_redirect_info *ri = this_cpu_ptr(&bpf_redirect_info); + struct bpf_map *map = READ_ONCE(ri->map); + + if (map) + return map->map_type; + else + return BPF_MAP_TYPE_UNSPEC; +} + static inline int xdp_ok_fwd_dev(const struct net_device *fwd, unsigned int pktlen)