From mboxrd@z Thu Jan 1 00:00:00 1970 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 E9D57C021A0 for ; Sat, 15 Feb 2025 12:13:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 508AD6B00A0; Sat, 15 Feb 2025 07:13:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 44FDD6B00A1; Sat, 15 Feb 2025 07:13:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 30A95280005; Sat, 15 Feb 2025 07:13:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 101486B00A0 for ; Sat, 15 Feb 2025 07:13:56 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 82228C1A74 for ; Sat, 15 Feb 2025 12:13:55 +0000 (UTC) X-FDA: 83122070430.04.779AC95 Received: from mail-pl1-f194.google.com (mail-pl1-f194.google.com [209.85.214.194]) by imf17.hostedemail.com (Postfix) with ESMTP id 7728140009 for ; Sat, 15 Feb 2025 12:13:53 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Vbeb0aIR; spf=pass (imf17.hostedemail.com: domain of yunshenglin0825@gmail.com designates 209.85.214.194 as permitted sender) smtp.mailfrom=yunshenglin0825@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1739621633; a=rsa-sha256; cv=none; b=o+O3APBRjUKKo0VrQN/Y3HzVwuTyak+2QKfc4NGSLgokJMHkES8sA/9f/WHwM16mnJ1s6P baEgAiNMYwQ78kAhVp93gRFNGqvn3lnVBlC7j15tyFAJPXzdbyvF1gvgaCBjvCvq5OA77g V5OTNsvJJXIXSjlNswI40kYPyu/YqOc= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Vbeb0aIR; spf=pass (imf17.hostedemail.com: domain of yunshenglin0825@gmail.com designates 209.85.214.194 as permitted sender) smtp.mailfrom=yunshenglin0825@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1739621633; 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:in-reply-to:references:references:dkim-signature; bh=+u+CA/lSm+9nBXmX/PuduGARGI9A6dkgRJTZchCRgBM=; b=L4ObMf95CA/I75h0pY0OTJxMnB/aF2+PNcgmLtINsK47zg87EPJ/049h4IigHLti6Icv+p 1rGpvNaKo9V3rUBjTSScjLfzU6UdZQtkhSdvqXqrfmac/NAMvMl3JmNC7CHzWr7F7ampD5 boMhNyDabbe3/m1ihxKKXFIAp5mXcu4= Received: by mail-pl1-f194.google.com with SMTP id d9443c01a7336-220ca204d04so39301935ad.0 for ; Sat, 15 Feb 2025 04:13:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739621632; x=1740226432; darn=kvack.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=+u+CA/lSm+9nBXmX/PuduGARGI9A6dkgRJTZchCRgBM=; b=Vbeb0aIRTfk550SdfgBEa35jcz35F6RjMFPaYb4UfrTpbtIYjh2TtmwnNDIhnvTf+d RPX+BsNgtVPzOmOnMerm89H6Z4Vi9s7f9vbuk6Od6h6q9MiCdAurPWIzs0bGGqsJt5sP pMeX4TT7VRSXY5dH0iHtfJbqQ2Qg5ddXYonPT060gdZeCr86hZmt4xvq/Me9+Zi0T+f+ SlR1g2Ucp7sl/BlNg20GkLdCb55bjm48AO6LyWTLVcuYM4hlr56dO48FpTwruS1benvg 3Y0SHR7I/hUjnpZ3c3/QGBGfaj92YzYyt2wjFNeBKVTYUCmO4r7qASdARrPETnOjIBem Y+KA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739621632; x=1740226432; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=+u+CA/lSm+9nBXmX/PuduGARGI9A6dkgRJTZchCRgBM=; b=DSZEbknmnJ1IgbBeOOc2zOk6A9tktEde7PwSztXAyytmc2pKQs98d3OR1kNAOzDmMg 0m7jui9gvroPPgd/UxolaYQynfM09nFv2ynOJFW1eNKg/6QVtG8nxdurU2d2hM1LoxxR udN+cuz+vnJ3HK+asaJLpIQoYNBlWfA1+ldrriml2H05sn9rEZCtD15b1NV/ji3BhIu3 i0NKEZ9SY0exPaIhI5keQUQRsK4rPAZSZcnOHBC6TRKjnx5rM59yXsmQf+Od0GySeHnk WvjRZ0BywbBleFUVHmWkzGozi1AvAscp1YCR+rMS0RtZZIckse38ET/X8NCfrerWyg5e Mo2g== X-Forwarded-Encrypted: i=1; AJvYcCXVcepN0hl0qClSSGSxjptQRikNW0V84kEB4ZPcbaMvzJtVtaLuFZCJTkx+VFE/YkmUSZ9cVVltag==@kvack.org X-Gm-Message-State: AOJu0YyR+sQWeh7MH3QkNxxIWZhilolr2jQQW52vLi5PDqLOZsmpPIZa UI2ivbK8tgwaIwttet94dvjzj3NxdSU/M2JrYIeNJp4x7XfsElQb X-Gm-Gg: ASbGnctuBquxSga4No8I6H1IuDPmAc1YWUsaz0KAcWW8B+U2QXQaZYhqT6dghSNnIVQ JVGymQUeDET1TCFKP6QKtcm+9OQNyPJd2fURbmYq3d1AOJObDHTAttVHTbuFdcFx1Ma35lGa6+2 qz1WOqzDZWWmUCp1hDz95CBlP8Or6fzD2xrchcOkVPqUEDHozxgLoYQfqjDdvmywl7f9stZEFRl 1S4UHkugSFx9/kqgwKIHLNLcFC6hLxyvdGtXLa6oBvS2X4zeiP5SAuCb+74UHq265GP6EPOUIrz lGeddmUoAK0Jg2v6iQwX7fxwgEC+8d0gSYiYo25C0MyJnEJSM8/m5QHzjf44vDQHqzRqnRVZTxM jdAI= X-Google-Smtp-Source: AGHT+IFJykoOYu33+zfWUVUg0sZz5RNHHYceinZgxb0Gxr+xnoVpFCsY/aZ5CYDKvVkNHhuFwTfTHQ== X-Received: by 2002:a05:6a00:c87:b0:732:24ad:8e08 with SMTP id d2e1a72fcca58-73261776247mr3835535b3a.1.1739621632155; Sat, 15 Feb 2025 04:13:52 -0800 (PST) Received: from ?IPV6:2409:8a55:301b:e120:4c58:8d4e:99f3:3687? ([2409:8a55:301b:e120:4c58:8d4e:99f3:3687]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7324273e30dsm4845569b3a.99.2025.02.15.04.13.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 15 Feb 2025 04:13:51 -0800 (PST) Message-ID: Date: Sat, 15 Feb 2025 20:13:42 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH net-next v9 2/4] page_pool: fix IOMMU crash when driver has already unbound To: Mina Almasry , Yunsheng Lin Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, zhangkun09@huawei.com, liuyonglong@huawei.com, fanghaiqing@huawei.com, Robin Murphy , Alexander Duyck , IOMMU , Andrew Morton , Eric Dumazet , Simon Horman , Jesper Dangaard Brouer , Ilias Apalodimas , linux-mm@kvack.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org References: <20250212092552.1779679-1-linyunsheng@huawei.com> <20250212092552.1779679-3-linyunsheng@huawei.com> Content-Language: en-US From: Yunsheng Lin In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 7728140009 X-Stat-Signature: b8mfnia4n4z6k6wcmrei46354hjajwk7 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1739621633-522555 X-HE-Meta: U2FsdGVkX186mtumt5b+CkwNqpMxA6nkUgr1WbwgcypqwKur4XoTjPXuNZzzf5O3DdccZ2RZ27C8IFZQAAjrp9jHcYtTAHUvv2YRYb5jgkWOVWb//Antb/2QTw9/q5qfdVhFLt2IQQkrtNxQqmWooIyfPx23GRd5Ef9ByxiC0OXnKQiLx+CYQCn2nmccf58Hz3neVxRH7LFTPoRzJBZD65Gv2b6tT7/NzsdQ0ORKBhy6WsAJPqrKWMe5TwZ/F6ErWiPbSIilNWeGIBVHP0TYizNUs/QFJCfqejN+XWmHt6Sqs31E8ABCJnJMge5TbxWNaamnHLoVxUtVBcL8Z+aBRulxgvDGKOrpSthlUdMkW/PorXvjaL8G5bAoTNsmyLoVB7kMx0ill+IKMAXF148pP2hmKtf84ItEVr0ffaN7h8dFMmm4W5haAJNaqEcmRx5Xo0+5H3lwswlK9Uh3FzaqRY442X91Kq4aJSVFLPV7XVBUd3uTieZ8v7lvuF5RUknBJovDloQKLXENx+ZrjB+DwIQ6CfhYRMq8Vr3MCmwBRh9yrn1kzTOkd3YPpL+1bwkfpDeN37Kyesf2hhyn+0uME3uXL7TSDBsC5m71VdO+gXH/R4IYLK6VhTCHa85vVKOrVHosJ4WSdJfcgwvRArKV2ml3jostheIQoR43H20KIpIsb/N+kUyvowTQo0Ms4Kq4Wjk0WfKLw9w8Aa05GMSBHmjnoCkwxM7KfN3SXiDcIm7BrHo5KpCO+rPQwjpUGT1hpghXU7VTMJr7yz41WRuAcuINbfcJ76WgzGWfhIfxREsguFpedI3aYIRwlZPQBPSCE65epdOX908EzJXVLx+Yr0UE9FXCs2+cGOyOtd8ttwnutsbRJ+D5mrdC0N9iRCK0oVPJPxRWAneioYjZ2B23txl3JaQd091MWvn6SwjBYorJs8Is+del8bjJRLk/pH/fTFuKLm75W8+375Wf9no 171ChK1/ zDMLQ10YJxts+xkXn/n3FMQwf4MIjm26VP23CaPGSgJaucIbZyMqpTTnp1NlN8EZc4d6tXOv+eOT8poIP4ivQ706+I0DMiPW3i6GGz+7kq2AsWnq1/FSY6ZGT+XglliCzBucrJW95LvHcLgmQMR3kRs6pFjMiG7+lk4NljExPloyyGNiC7lgUp+4UrE+K92caqER2hUyKkFzbiaOr/UCuIUnn5t6bnHruFBkNmNOvYAhb6QBXbnjgDXxcgO9Fc/hGlWwG41hMCF511uhytMJ6CQZyM0OyQ/cgDNsH7aUIjJkHO5QpzXLHjjTsUY/iGuaeAVqpCprhG8GRn4Lv40yfqetVphUeySiJxg1yuLjuVZKHe25HsG1MZFuEnVhP4rLQmgDJOxh2xqnhR64voq/ntbu+gnqTXNcCiYq+EqUOn4Zt7kjFhk+l6neiAyi45fUScwgGngkXG5yXZLQ0NZazRT+VLqul2KI9vCtkQEWJ8QR+MIdQcy5bGKWq3JCnEqvlzzc1yxACfSMOWDiCwdrUSUUL3tfXkMx2Wd604sbzNxFTtlXIiC9Cgecog7AtEDirmmJg0+EwOXOCxrgI3bTJfN/ZsZjc4rodo4mZnzBbctbJDquGTqCXTbqK0bUMr6c6I7ZEh7wlMABiY8qtP9qObZPDGrXL4n4+aSqnCJkHmCXqPcHVEjhzsRbO6NvpyxAhKmFFc2EHWrfUckxtkLwPxuoWnsmUI4hZ7o2TyrHGPvqWBppPU//E/KWNwIfugdLjhqcCmxBIKFdGjVI/KifAYI/+dWW+gZHOMGSUB69BXJbjDoN6HKSQjkf0ZOXZLMWBPWmS 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: On 2/15/2025 4:58 AM, Mina Almasry wrote: > On Wed, Feb 12, 2025 at 1:34 AM Yunsheng Lin wrote: >> >> Networking driver with page_pool support may hand over page >> still with dma mapping to network stack and try to reuse that >> page after network stack is done with it and passes it back >> to page_pool to avoid the penalty of dma mapping/unmapping. >> With all the caching in the network stack, some pages may be >> held in the network stack without returning to the page_pool >> soon enough, and with VF disable causing the driver unbound, >> the page_pool does not stop the driver from doing it's >> unbounding work, instead page_pool uses workqueue to check >> if there is some pages coming back from the network stack >> periodically, if there is any, it will do the dma unmmapping >> related cleanup work. >> >> As mentioned in [1], attempting DMA unmaps after the driver >> has already unbound may leak resources or at worst corrupt >> memory. Fundamentally, the page pool code cannot allow DMA >> mappings to outlive the driver they belong to. >> >> Currently it seems there are at least two cases that the page >> is not released fast enough causing dma unmmapping done after >> driver has already unbound: >> 1. ipv4 packet defragmentation timeout: this seems to cause >> delay up to 30 secs. >> 2. skb_defer_free_flush(): this may cause infinite delay if >> there is no triggering for net_rx_action(). >> >> In order not to call DMA APIs to do DMA unmmapping after driver >> has already unbound and stall the unloading of the networking >> driver, use some pre-allocated item blocks to record inflight >> pages including the ones which are handed over to network stack, >> so the page_pool can do the DMA unmmapping for those pages when >> page_pool_destroy() is called. As the pre-allocated item blocks >> need to be large enough to avoid performance degradation, add a >> 'item_fast_empty' stat to indicate the unavailability of the >> pre-allocated item blocks. >> >> By using the 'struct page_pool_item' referenced by page->pp_item, >> page_pool is not only able to keep track of the inflight page to >> do dma unmmaping if some pages are still handled in networking >> stack when page_pool_destroy() is called, and networking stack is >> also able to find the page_pool owning the page when returning >> pages back into page_pool: >> 1. When a page is added to the page_pool, an item is deleted from >> pool->hold_items and set the 'pp_netmem' pointing to that page >> and set item->state and item->pp_netmem accordingly in order to >> keep track of that page, refill from pool->release_items when >> pool->hold_items is empty or use the item from pool->slow_items >> when fast items run out. >> 2. When a page is released from the page_pool, it is able to tell >> which page_pool this page belongs to by masking off the lower >> bits of the pointer to page_pool_item *item, as the 'struct >> page_pool_item_block' is stored in the top of a struct page. And >> after clearing the pp_item->state', the item for the released page >> is added back to pool->release_items so that it can be reused for >> new pages or just free it when it is from the pool->slow_items. >> 3. When page_pool_destroy() is called, item->state is used to tell if >> a specific item is being used/dma mapped or not by scanning all the >> item blocks in pool->item_blocks, then item->netmem can be used to >> do the dma unmmaping if the corresponding inflight page is dma >> mapped. >> >> The overhead of tracking of inflight pages is about 10ns~20ns, >> which causes about 10% performance degradation for the test case >> of time_bench_page_pool03_slow() in [2]. >> >> Note, the devmem patchset seems to make the bug harder to fix, >> and may make backporting harder too. As there is no actual user >> for the devmem and the fixing for devmem is unclear for now, >> this patch does not consider fixing the case for devmem yet. >> >> 1. https://lore.kernel.org/lkml/8067f204-1380-4d37-8ffd-007fc6f26738@kernel.org/T/ >> 2. https://github.com/netoptimizer/prototype-kernel >> CC: Robin Murphy >> CC: Alexander Duyck >> CC: IOMMU >> Fixes: f71fec47c2df ("page_pool: make sure struct device is stable") >> Signed-off-by: Yunsheng Lin >> Tested-by: Yonglong Liu > [...] >> + >> +/* The size of item_block is always PAGE_SIZE, so that the address of item_block >> + * for a specific item can be calculated using 'item & PAGE_MASK' >> + */ >> +struct page_pool_item_block { >> + struct page_pool *pp; >> + struct list_head list; >> + struct page_pool_item items[]; >> +}; >> + > > I think this feedback was mentioned in earlier iterations of the series: > Can we not hold a struct list_head in the page_pool that keeps track > of inflight netmems that we need to dma-unmap on page_pool_destroy? > Why do we have to modify the pp entry in the struct page and struct > net_iov? Jesper asked a similar question in [1], see below: 1. https://lore.kernel.org/all/95f258b2-52f5-4a80-a670-b9a182caec7c@kernel.org/ > > The decision to modify pp entry in struct page and struct net_iov is > making this patchset bigger and harder to review IMO. I am open to any better suggestion of simple and easy way to fix this with little performance impact as much as possible, but I really doubtful that using some advanced struct like 'list_head" as suggested above will not cause significant performance degradation.