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 3D4A9CF58D2 for ; Fri, 20 Sep 2024 06:14:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8B7BD6B0082; Fri, 20 Sep 2024 02:14:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 867B26B0083; Fri, 20 Sep 2024 02:14:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 730036B0085; Fri, 20 Sep 2024 02:14:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 53B7E6B0082 for ; Fri, 20 Sep 2024 02:14:11 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id BB5C1140E96 for ; Fri, 20 Sep 2024 06:14:10 +0000 (UTC) X-FDA: 82584101460.11.BB10F8A Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by imf10.hostedemail.com (Postfix) with ESMTP id 4F26CC0009 for ; Fri, 20 Sep 2024 06:14:06 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf10.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.190 as permitted sender) smtp.mailfrom=linyunsheng@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1726812816; a=rsa-sha256; cv=none; b=Qv+XvBM3JoLoAvo9HBpb5Z6/hLIIhCEJQa2pGE97Gci/AZZThOJDzmk4wLi8SGOrYiETkv wgJAgOeNwc27kpRvsMeVtE7CD4d4G6nGWrAWuVTpm+HuZMIfeW6R0z6kBF5mNS/4qYuCJ7 WHvAnJpaJ6daM2teE6CUisIDRCpynSA= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf10.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=1726812816; 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; bh=ijTL2zKnUof+4XF+ZG6s13+2/2KOA0aKlwgKuQEWNso=; b=CUkuxJB9Yflt6NcdfX0FAOo1pkV+jpu6eZi31ZTodlG7KBe03Wv0U7myBCPYadERcIqAj9 yNDqgvE0aHMOpHj2urjJ5uQRAe43YzcJBl8Mtx0IJQj+hWFtAevvFBJngitZy7NScQhFD1 5/yx4jNcvbvGPveqAnAZGkoLt34Xijs= Received: from mail.maildlp.com (unknown [172.19.162.112]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4X92BV2t0Fz2DcJj; Fri, 20 Sep 2024 14:13:22 +0800 (CST) Received: from dggpemf200006.china.huawei.com (unknown [7.185.36.61]) by mail.maildlp.com (Postfix) with ESMTPS id 140801401DC; Fri, 20 Sep 2024 14:14:03 +0800 (CST) Received: from [10.67.120.129] (10.67.120.129) 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, 20 Sep 2024 14:14:02 +0800 Message-ID: <2c5ccfff-6ab4-4aea-bff6-3679ff72cc9a@huawei.com> Date: Fri, 20 Sep 2024 14:14:02 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH net 2/2] page_pool: fix IOMMU crash when driver has already unbound To: Ilias Apalodimas , Jesper Dangaard Brouer CC: , , , , , , Robin Murphy , Alexander Duyck , IOMMU , Wei Fang , Shenwei Wang , Clark Wang , Eric Dumazet , Tony Nguyen , Przemek Kitszel , Alexander Lobakin , Alexei Starovoitov , Daniel Borkmann , John Fastabend , Saeed Mahameed , Leon Romanovsky , Tariq Toukan , Felix Fietkau , Lorenzo Bianconi , Ryder Lee , Shayne Chen , Sean Wang , Kalle Valo , Matthias Brugger , AngeloGioacchino Del Regno , Andrew Morton , , , , , , , , , , References: <20240918111826.863596-1-linyunsheng@huawei.com> <20240918111826.863596-3-linyunsheng@huawei.com> <894a3c2c-22f9-45b9-a82b-de7320066b42@kernel.org> <0e8c7a7a-0e2a-42ec-adbc-b29f6a514517@kernel.org> Content-Language: en-US From: Yunsheng Lin In-Reply-To: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.67.120.129] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemf200006.china.huawei.com (7.185.36.61) X-Rspam-User: X-Rspamd-Queue-Id: 4F26CC0009 X-Rspamd-Server: rspam01 X-Stat-Signature: edk3zzdfmsi9r1ydjpz451nsdxh8ssgh X-HE-Tag: 1726812846-165390 X-HE-Meta: U2FsdGVkX1+bZntI+gY7tFaEzvFMRGBsuTiMfSSBGbPDSz45Cj1B3XyMOZchGtX5bLLJF7GH/xYT0btObyPDQLxj11RCp5n5QaOqEb9mNF0gzbjZaxRi3puXq2lYQZ98/bN4asrKeKd50FH6S5v6feBuEuKUwDmZm2qs2i7WzulYzK51PmXEFet6UqRZGUAo9NCu2A2r3MXv/cdygYgCYW3H3ZnP5Licw+aqiqqUJI616jnCMHGMaAlH7lTAlt06sk3F9+MHnWa5z3x2DbmGBx//JYL6mxAuTzYensdWUnIBulsDyELnxTY9S4IMJz1peK75YzloBYiDs0oI27oIfqBk/J+o3NTUaMhUHAsdPyB53B8GBJ65Jb/1XN0W5bkkEMhipJIoM8O+46NGoOozb3RVpxQsNBJ8gjRo8ZXiqjHSe+z6A5C5Yws58PpHF5kfJQe9MkBhRnpLF+lsmbISXNdUhbzdrO+4i4yt7QUV0TMCgyl0mzIBC5Eg5ELUiy44lRMyW/zKgbaIAF7s7EnDguH2MTM/JIIUWB49w/ObLoPl4qT5F6QmhwQwq5MVDRwE2Fr7NhpEj0XZFZHOVF92UqKI5HMLQrKV7DDDrWbdl5Me2ify+z2W0p6ug5i4iBD73wyY20/spxn7CjjVgJZxo/oX8YQmV2iY4mEu1mBqSjvY4J2gwguGcpXOUT4K1vhs0KbqYHUbKzEcFRf4pAMPQSjxI9I8BLmnjshkSNPSpVGTSEYF1hC/169B5PkhI6br8rPqpOCGXb05gFJQUibHsilfMZetsKGzJSboeMIIK7bzmiHyU6/jydOMpm5xAui3kqkYO+vKonsZyWnYPvaF4uA48c+/0egvMGcQmv/QAh/hdutknRSUwMEcsEX0jrKUZdzaWJUnChfv7yIH0NR48cd/+kiLC8y1PGMbMLu40eOQqz21WbhfBhrqP/jK8GNB5pvojunAcL5aaBS1+3o QJWLyeHn S23DljgsljVUgjWu+d+AWER/bGG+GqcZ+BFmBLPyMcT/ammZ34Hlrs0WYePxxIVdAgx9t4C+gOUfMCcAXtnXTtrc1BTbz+SSKMTZkqtVdFvNu184ceVd3iANc669Q195UZW1MS4Nmgt7MEl2Y2NJ925tu1L7G90RZPnaM8ZLqUE/WfpOFlszdromZB3AtM1fqtFn2J6t+WWnos3EqHNnX3s6w1DtwOcsqBptpPrTvbGcpqIzHzYPAdUM5Tmo0JmgMYFOyCRWg8w0Ov0fM1ggCB0oNvq8HdGnQzExy 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 2024/9/20 13:29, Ilias Apalodimas wrote: > Hi Jesper, > > On Fri, 20 Sept 2024 at 00:04, Jesper Dangaard Brouer wrote: >> >> >> >> On 19/09/2024 13.15, Yunsheng Lin wrote: >>> On 2024/9/19 17:42, Jesper Dangaard Brouer wrote: >>>> >>>> On 18/09/2024 19.06, Ilias Apalodimas wrote: >>>>>> In order not to do the dma unmmapping after driver has already >>>>>> unbound and stall the unloading of the networking driver, add >>>>>> the pool->items array to record all the 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. >>>>> >>>>> So, I was thinking of a very similar idea. But what do you mean by >>>>> "all"? The pages that are still in caches (slow or fast) of the pool >>>>> will be unmapped during page_pool_destroy(). >>>> >>>> I really dislike this idea of having to keep track of all outstanding pages. >>>> >>>> I liked Jakub's idea of keeping the netdev around for longer. >>>> >>>> This is all related to destroying the struct device that have points to >>>> the DMA engine, right? >>> >>> Yes, the problem seems to be that when device_del() is called, there is >>> no guarantee hw behind the 'struct device ' will be usable even if we >>> call get_device() on it. >>> >>>> >>>> Why don't we add an API that allow netdev to "give" struct device to >>>> page_pool. And then the page_poll will take over when we can safely >>>> free the stuct device? >>> >>> By 'allow netdev to "give" struct device to page_pool', does it mean >>> page_pool become the driver for the device? >>> If yes, it seems that is similar to jakub's idea, as both seems to stall >>> the calling of device_del() by not returning when the driver unloading. >> >> Yes, this is what I mean. (That is why I mentioned Jakub's idea). I am not sure what dose the API that allows netdev to "give" struct device to page_pool look like or how to implement the API yet, but the obvious way to stall the calling of device_del() is to wait for the inflight page to come back in page_pool_destroy(), which seems the same as the jakub's way from the viewpoint of user, and jakub's way seems more elegant than waiting in page_pool_destroy(). > > Keeping track of inflight packets that need to be unmapped is > certainly more complex. Delaying the netdevice destruction certainly > solves the problem but there's a huge cost IMHO. Those devices might > stay there forever and we have zero guarantees that the network stack > will eventually release (and unmap) those packets. What happens in > that case? The user basically has to reboot the entire machine, just > because he tries to bring an interface down and up again. Yes. The problem seems to be how long page_pool is allowed to stall the driver unloading? Does the driver unload stalling affect some feature like device hotplug? As the problem in [1], the stall might be forever due to caching in the network stack as discussed in [2], and there might be some other caching we don't know yet. The stalling log in [1] is caused by the caching in skb_attempt_defer_free(), we may argue that a timeout is needed for those kind of caching, but Eric seemed to think otherwise in commit log of [3]: "As Eric pointed out/predicted there's no guarantee that applications will read / close their sockets so a page pool page may be stuck in a socket (but not leaked) forever." 1. https://lore.kernel.org/netdev/20240814075603.05f8b0f5@kernel.org/T/#me2f2c89fbeb7f92a27d54a85aab5527efedfe260 2. https://lore.kernel.org/netdev/20240814075603.05f8b0f5@kernel.org/T/#m2687f25537395401cd6a810ac14e0e0d9addf97e 3. https://lore.kernel.org/netdev/ZWfuyc13oEkp583C@makrotopia.org/T/ > > Thanks > /Ilias >> >> >>> If no, it seems that the problem is still existed when the driver for >>> the device has unbound after device_del() is called.