From patchwork Fri Jan 10 13:06:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunsheng Lin X-Patchwork-Id: 13934590 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2BAB5E77188 for ; Fri, 10 Jan 2025 13:14:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B00166B00A8; Fri, 10 Jan 2025 08:14:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AB0236B00AB; Fri, 10 Jan 2025 08:14:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 977466B00AC; Fri, 10 Jan 2025 08:14:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 78D3B6B00A8 for ; Fri, 10 Jan 2025 08:14:12 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 2BB5A1C5FCF for ; Fri, 10 Jan 2025 13:14:12 +0000 (UTC) X-FDA: 82991585544.27.177F6F9 Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by imf25.hostedemail.com (Postfix) with ESMTP id B1F21A0005 for ; Fri, 10 Jan 2025 13:14:09 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf25.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.190 as permitted sender) smtp.mailfrom=linyunsheng@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736514850; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references; bh=4I5Yfq9yY/wnrZyGHd+LMVKzseruORJiCs9modwakpA=; b=FUQVlamVASOzazxMuoXPQoJ1z3uRkwS3u8MCIclSvkJIrVhmOWhJYdH0EdhRj8WvUOuZLF /cZ+LKE/5as4CqZuUzGSY4J4cENKOZxpdkgASUNa5A5BSu2ZaBYSQ0o2SOkl0imS3NTlAT I+Q3XFrsJq+tNHNntFIKQLvfZS0IwP8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736514850; a=rsa-sha256; cv=none; b=WqpoiLR7mTc1s20MU0kcgGI9pgk2O9MuWMY+0h1UYFzK8svSdP4grXWVUzKCQgijCcNUOi Qa3NNb+d2XzXyVhZ0UK1k3C+KFJQ5jUxGLxrJwHR4E0fHZ+4NGU7vVxGSNl0WZMkLzxGXo IMPsT9AQnDlxcJ6wQd9jwD0R8RcpX+M= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf25.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.190 as permitted sender) smtp.mailfrom=linyunsheng@huawei.com Received: from mail.maildlp.com (unknown [172.19.163.44]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4YV28h5lGjz2DkMS; Fri, 10 Jan 2025 21:11:00 +0800 (CST) Received: from dggpemf200006.china.huawei.com (unknown [7.185.36.61]) by mail.maildlp.com (Postfix) with ESMTPS id DF7EE1402DE; Fri, 10 Jan 2025 21:14:04 +0800 (CST) Received: from localhost.localdomain (10.90.30.45) by dggpemf200006.china.huawei.com (7.185.36.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 10 Jan 2025 21:14:04 +0800 From: Yunsheng Lin To: , , CC: , , , Yunsheng Lin , Alexander Lobakin , Robin Murphy , Alexander Duyck , Andrew Morton , IOMMU , MM , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Matthias Brugger , AngeloGioacchino Del Regno , , , , , , Subject: [PATCH net-next v7 0/8] fix two bugs related to page_pool Date: Fri, 10 Jan 2025 21:06:54 +0800 Message-ID: <20250110130703.3814407-1-linyunsheng@huawei.com> X-Mailer: git-send-email 2.30.0 MIME-Version: 1.0 X-Originating-IP: [10.90.30.45] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemf200006.china.huawei.com (7.185.36.61) X-Rspamd-Queue-Id: B1F21A0005 X-Rspam-User: X-Rspamd-Server: rspam07 X-Stat-Signature: 9p49dps4cdrxxq5iwsip9wkj6czr9k87 X-HE-Tag: 1736514849-711047 X-HE-Meta: U2FsdGVkX19S85DzVPIudPWR50jajNzI8QWRvwJd/oMrheQ6W1bXT5GGwIbCQSOc5gxIvpDa1jA/y8n/roA9xLPIIWFQBymyTqH1oGdocPg8X3smO9kpY2Iyf8+kNjNUJwCZulPmuoK9EFxMFTeGP+kUoRvgv6EgkcaNdDyQbWAp6AlUKVTEDVjJanPvUuM269/4EdiN5LkkAirC+wfScKXaRjExj/DCCn+NAdLsg+PyM9yPYHD9V23rwscf/9Ou3nZTvQDMxVMc9TOkmuc+GqTnb6DwnDkPc0WQ3Rkpfg/hpZTrqJ5mVO6RWd7oGm1DQap4rj8pkYbUZzmlYQwjcXPFAqO6LxdSTTDTpqLxSOne5RJW/4yi45T9YEHKH4b5M2UqttzI9ccqHMMaTXAuLZgasBEJXb4mkkuKb4VfKlw8T7q5G8Rc/UFRAgWs101vpYZtkWart5P/ktB+GOYCQntzyWKV9oHOLbb9CV6aY5eCE94RghcdHdKMoVewAxY/HysmOeXcAfpi2P9vM8QEd4KltYEb+tBv9CVUK3weGkW9zjGkBfZeJqAxL0A3UxcY+YOERZHQd+xTpMDgN8pFb3jQrd7X3LxEfE47Hi5+1ztGlIarJEku507K+AWZ8bHZ/qc1uw8dK0RRz444BLo8wWstZqj0peJ9dvrrZIH6mf3WDzw6u6af5NSOQJ2zvNUlaKR8Jit8/OGIBL2t57EjKnYfsVMn5RPccK2mfdZvGCQRXoJ4sU+sTySJVZZ2alZSw9xMiClrLulaTxTunlOPjHe7PIxUoKV/NZGIgbmz2AGCR15YVu9E5/qmON6uNjed0xlhbUhkIvxq6o2LUOEVTyd96+EfDVuz9HbM9KL8+BtD0/yVOdvCsqGsyBxR+GySnufcvXFWRH+xXZHAcKJ79CKPw0v5mhZvcKJDrXK9wLVI1Slq+qcRZUs+erjCAgt/gY+W0f0tH6boGWpZjLv C1xFFTA/ oZd8dKKF68O8FTsJfDjwgzq4Ob3gnVfAIYDAo45zsCB+lJAZRigzUWdRynwljPy5L75WJL3Jnho/3RHA5jDia+4GltfEb+VNpwDILZ5NndDIdZbTGGyLjkCSZNr16TBoO/Kuzd/yyYODt2A1K0s8IFQ++fXqId29QC/dg7Jplat+5kfOlUpbSQR7sm1FRasuDV9o8wl7ut0RdAWyBlmCWMG/snu4TAYing+1U1QZgpT8OGijUOmZB7jrwCEewkVz3CjbwXCMxX6/iytWDoo4GuRL4J6L5+jCZ04eSuuOt64m74kUc/d1VmgiEcuhoduNymUrdcVME6KoN/V/bmUwOV4HXCYQs8JhroC5iIhiogWi0de22GrGVUOQBglFExzpg0HEN72FxFqa7QF+9z04bS2vdh7/1EPgAfQzLmYRQ01yGIw0hX7ZT9bkDRM/u7PGEx5hS2kzmRGvF8t5hiCuyTCGqG3c/HDIOxdq9E7qQLkUzFMI= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: This patchset fix a possible time window problem for page_pool and the dma API misuse problem as mentioned in [1], and try to avoid the overhead of the fixing using some optimization. From the below performance data, the overhead is not so obvious due to performance variations for time_bench_page_pool01_fast_path() and time_bench_page_pool02_ptr_ring, and there is about 20ns overhead for time_bench_page_pool03_slow() for fixing the bug. Before this patchset: root@(none)$ insmod bench_page_pool_simple.ko [ 323.367627] bench_page_pool_simple: Loaded [ 323.448747] time_bench: Type:for_loop Per elem: 0 cycles(tsc) 0.769 ns (step:0) - (measurement period time:0.076997150 sec time_interval:76997150) - (invoke count:100000000 tsc_interval:7699707) [ 324.812884] time_bench: Type:atomic_inc Per elem: 1 cycles(tsc) 13.468 ns (step:0) - (measurement period time:1.346855130 sec time_interval:1346855130) - (invoke count:100000000 tsc_interval:134685507) [ 324.980875] time_bench: Type:lock Per elem: 1 cycles(tsc) 15.010 ns (step:0) - (measurement period time:0.150101270 sec time_interval:150101270) - (invoke count:10000000 tsc_interval:15010120) [ 325.652195] time_bench: Type:rcu Per elem: 0 cycles(tsc) 6.542 ns (step:0) - (measurement period time:0.654213000 sec time_interval:654213000) - (invoke count:100000000 tsc_interval:65421294) [ 325.669215] bench_page_pool_simple: time_bench_page_pool01_fast_path(): Cannot use page_pool fast-path [ 325.974848] time_bench: Type:no-softirq-page_pool01 Per elem: 2 cycles(tsc) 29.633 ns (step:0) - (measurement period time:0.296338200 sec time_interval:296338200) - (invoke count:10000000 tsc_interval:29633814) [ 325.993517] bench_page_pool_simple: time_bench_page_pool02_ptr_ring(): Cannot use page_pool fast-path [ 326.576636] time_bench: Type:no-softirq-page_pool02 Per elem: 5 cycles(tsc) 57.391 ns (step:0) - (measurement period time:0.573911820 sec time_interval:573911820) - (invoke count:10000000 tsc_interval:57391174) [ 326.595307] bench_page_pool_simple: time_bench_page_pool03_slow(): Cannot use page_pool fast-path [ 328.422661] time_bench: Type:no-softirq-page_pool03 Per elem: 18 cycles(tsc) 181.849 ns (step:0) - (measurement period time:1.818495880 sec time_interval:1818495880) - (invoke count:10000000 tsc_interval:181849581) [ 328.441681] bench_page_pool_simple: pp_tasklet_handler(): in_serving_softirq fast-path [ 328.449584] bench_page_pool_simple: time_bench_page_pool01_fast_path(): in_serving_softirq fast-path [ 328.755031] time_bench: Type:tasklet_page_pool01_fast_path Per elem: 2 cycles(tsc) 29.632 ns (step:0) - (measurement period time:0.296327910 sec time_interval:296327910) - (invoke count:10000000 tsc_interval:29632785) [ 328.774308] bench_page_pool_simple: time_bench_page_pool02_ptr_ring(): in_serving_softirq fast-path [ 329.578579] time_bench: Type:tasklet_page_pool02_ptr_ring Per elem: 7 cycles(tsc) 79.523 ns (step:0) - (measurement period time:0.795236560 sec time_interval:795236560) - (invoke count:10000000 tsc_interval:79523650) [ 329.597769] bench_page_pool_simple: time_bench_page_pool03_slow(): in_serving_softirq fast-path [ 331.507501] time_bench: Type:tasklet_page_pool03_slow Per elem: 19 cycles(tsc) 190.104 ns (step:0) - (measurement period time:1.901047510 sec time_interval:1901047510) - (invoke count:10000000 tsc_interval:190104743) After this patchset: root@(none)$ insmod bench_page_pool_simple.ko [ 138.634758] bench_page_pool_simple: Loaded [ 138.715879] time_bench: Type:for_loop Per elem: 0 cycles(tsc) 0.769 ns (step:0) - (measurement period time:0.076972720 sec time_interval:76972720) - (invoke count:100000000 tsc_interval:7697265) [ 140.079897] time_bench: Type:atomic_inc Per elem: 1 cycles(tsc) 13.467 ns (step:0) - (measurement period time:1.346735370 sec time_interval:1346735370) - (invoke count:100000000 tsc_interval:134673531) [ 140.247841] time_bench: Type:lock Per elem: 1 cycles(tsc) 15.005 ns (step:0) - (measurement period time:0.150055080 sec time_interval:150055080) - (invoke count:10000000 tsc_interval:15005497) [ 140.919072] time_bench: Type:rcu Per elem: 0 cycles(tsc) 6.541 ns (step:0) - (measurement period time:0.654125000 sec time_interval:654125000) - (invoke count:100000000 tsc_interval:65412493) [ 140.936091] bench_page_pool_simple: time_bench_page_pool01_fast_path(): Cannot use page_pool fast-path [ 141.246985] time_bench: Type:no-softirq-page_pool01 Per elem: 3 cycles(tsc) 30.159 ns (step:0) - (measurement period time:0.301598160 sec time_interval:301598160) - (invoke count:10000000 tsc_interval:30159812) [ 141.265654] bench_page_pool_simple: time_bench_page_pool02_ptr_ring(): Cannot use page_pool fast-path [ 141.976265] time_bench: Type:no-softirq-page_pool02 Per elem: 7 cycles(tsc) 70.140 ns (step:0) - (measurement period time:0.701405780 sec time_interval:701405780) - (invoke count:10000000 tsc_interval:70140573) [ 141.994933] bench_page_pool_simple: time_bench_page_pool03_slow(): Cannot use page_pool fast-path [ 144.018945] time_bench: Type:no-softirq-page_pool03 Per elem: 20 cycles(tsc) 201.514 ns (step:0) - (measurement period time:2.015141210 sec time_interval:2015141210) - (invoke count:10000000 tsc_interval:201514113) [ 144.037966] bench_page_pool_simple: pp_tasklet_handler(): in_serving_softirq fast-path [ 144.045870] bench_page_pool_simple: time_bench_page_pool01_fast_path(): in_serving_softirq fast-path [ 144.205045] time_bench: Type:tasklet_page_pool01_fast_path Per elem: 1 cycles(tsc) 15.005 ns (step:0) - (measurement period time:0.150056510 sec time_interval:150056510) - (invoke count:10000000 tsc_interval:15005645) [ 144.224320] bench_page_pool_simple: time_bench_page_pool02_ptr_ring(): in_serving_softirq fast-path [ 144.916044] time_bench: Type:tasklet_page_pool02_ptr_ring Per elem: 6 cycles(tsc) 68.269 ns (step:0) - (measurement period time:0.682693070 sec time_interval:682693070) - (invoke count:10000000 tsc_interval:68269300) [ 144.935234] bench_page_pool_simple: time_bench_page_pool03_slow(): in_serving_softirq fast-path [ 146.997684] time_bench: Type:tasklet_page_pool03_slow Per elem: 20 cycles(tsc) 205.376 ns (step:0) - (measurement period time:2.053766310 sec time_interval:2053766310) - (invoke count:10000000 tsc_interval:205376624) 1. https://lore.kernel.org/lkml/8067f204-1380-4d37-8ffd-007fc6f26738@kernel.org/T/ CC: Alexander Lobakin CC: Robin Murphy CC: Alexander Duyck CC: Andrew Morton CC: IOMMU CC: MM Change log: V7: 1. Fix a used-after-free bug reported by KASAN as mentioned by Jakub. 2. Fix the 'netmem' variable not setting up correctly bug as mentioned by Simon. V6: 1. Repost based on latest net-next. 2. Rename page_pool_to_pp() to page_pool_get_pp(). V5: 1. Support unlimit inflight pages. 2. Add some optimization to avoid the overhead of fixing bug. V4: 1. use scanning to do the unmapping 2. spilt dma sync skipping into separate patch V3: 1. Target net-next tree instead of net tree. 2. Narrow the rcu lock as the discussion in v2. 3. Check the ummapping cnt against the inflight cnt. V2: 1. Add a item_full stat. 2. Use container_of() for page_pool_to_pp(). Yunsheng Lin (8): page_pool: introduce page_pool_get_pp() API page_pool: fix timing for checking and disabling napi_local page_pool: fix IOMMU crash when driver has already unbound page_pool: support unlimited number of inflight pages page_pool: skip dma sync operation for inflight pages page_pool: use list instead of ptr_ring for ring cache page_pool: batch refilling pages to reduce atomic operation page_pool: use list instead of array for alloc cache drivers/net/ethernet/freescale/fec_main.c | 8 +- .../ethernet/google/gve/gve_buffer_mgmt_dqo.c | 2 +- drivers/net/ethernet/intel/iavf/iavf_txrx.c | 6 +- drivers/net/ethernet/intel/idpf/idpf_txrx.c | 14 +- drivers/net/ethernet/intel/libeth/rx.c | 2 +- .../net/ethernet/mellanox/mlx5/core/en/xdp.c | 3 +- drivers/net/netdevsim/netdev.c | 6 +- drivers/net/wireless/mediatek/mt76/mt76.h | 2 +- include/linux/mm_types.h | 2 +- include/linux/skbuff.h | 1 + include/net/libeth/rx.h | 3 +- include/net/netmem.h | 24 +- include/net/page_pool/helpers.h | 11 + include/net/page_pool/types.h | 64 +- net/core/devmem.c | 4 +- net/core/netmem_priv.h | 5 +- net/core/page_pool.c | 664 ++++++++++++++---- net/core/page_pool_priv.h | 12 +- 18 files changed, 675 insertions(+), 158 deletions(-)