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 8B91ACF3198 for ; Wed, 2 Oct 2024 06:52:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D8FA66B0350; Wed, 2 Oct 2024 02:52:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D3E786B0351; Wed, 2 Oct 2024 02:52:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B90B26B0352; Wed, 2 Oct 2024 02:52:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 8ABC46B0350 for ; Wed, 2 Oct 2024 02:52:29 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 17CB01A1950 for ; Wed, 2 Oct 2024 06:52:29 +0000 (UTC) X-FDA: 82627743618.08.AE716C2 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) by imf25.hostedemail.com (Postfix) with ESMTP id 20AAFA0008 for ; Wed, 2 Oct 2024 06:52:26 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=linaro.org header.s=google header.b=pdZaKLBZ; spf=pass (imf25.hostedemail.com: domain of ilias.apalodimas@linaro.org designates 209.85.210.180 as permitted sender) smtp.mailfrom=ilias.apalodimas@linaro.org; dmarc=pass (policy=none) header.from=linaro.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727851881; a=rsa-sha256; cv=none; b=v6lVQFVutJDc+aQoPX9JS1Cwx9qYkul3JtDhpdvGNtExeimHhqC/96t8BwIG0y/lDMrmgr e/p9OyRqZ2x/vcBA32FNvpTmIJVntNXvVAq1L9SusLtlDr+w4CO+zyl7BmbyjTYkebBTlQ WnlLyfSlNjNe8OJyZ4E/aADhOJbTNhk= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=linaro.org header.s=google header.b=pdZaKLBZ; spf=pass (imf25.hostedemail.com: domain of ilias.apalodimas@linaro.org designates 209.85.210.180 as permitted sender) smtp.mailfrom=ilias.apalodimas@linaro.org; dmarc=pass (policy=none) header.from=linaro.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727851881; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Wi2knaZL4xgHJFaFdtzBXqIWLSuRG81LD3CTPdMJ4G8=; b=5FZrr4SRRFYjd4eOXHEQG+3aPhN42mKGdE+sXaI6RB1pWGjPQkS6S8wKmjyqsSboTc6ca2 0ec4/H4RxYQIhJ403BcZiNZCchJF1rPDy/TQB6FfrKOEiq5Vcfwccap/wF8vopvlqMl7ez mq0+zVg/e9lX/u54jbkkGYmCiRr1O7o= Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-7193010d386so5465884b3a.1 for ; Tue, 01 Oct 2024 23:52:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1727851945; x=1728456745; darn=kvack.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=Wi2knaZL4xgHJFaFdtzBXqIWLSuRG81LD3CTPdMJ4G8=; b=pdZaKLBZ2iw5u3Z0MDnwSncYFMY4MHXtC/zp7ZTC5QN9hw4tKYrqzFykpqpj1OnoZF 143SPx5WQgO75JhNEjOj8qlNsdg7b8xlE7eZXATYpUyPuBYZnCiVv3biE0f15FkqSfAN g40IibjFburtuM0LG2Qqmsomybt7lXHAtSuN1WZYiBaUz5+RYEHYSria4DFeMb3Fieg4 G3MzyAiq/rMR3VinkCSIwg5a0MaZuZuObQ4nsqTprL9uGgpMpWjZ6jb9iwRak4P6ZOkq V6dw79sjm0iEt6jlyNjyNFUYSmH5UCciKm58IKjeMq+JNZzdbo0joXBji2FXgfU3l8zB ZXLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727851945; x=1728456745; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Wi2knaZL4xgHJFaFdtzBXqIWLSuRG81LD3CTPdMJ4G8=; b=h3Zgc9YN5d4S3AJDj6zUWfcJ/BlyT4qjFyeyXMhUQRfEpf55vdYxGMxVSyDfRMWpVx mvkD1qRcvTrOhI1FYv4KNXHrIbZ6hhqNh3PGxMsXMPY1R/31iQI6VELhan+2UwAt9duo s9nCzdKey8a6cYluvTOYKdTJwTjAitldhgydwtEKDoyrY94s4O8VTm78pYjIoo6ptmZw bHfoNo76n1Lkb2kGWPl/eAO61aypk6T437cV0n8rT19upY3OV/8dyK8ZjJmM5L8KtL07 IGjAAenPGFUndJt+JFlYWROafZXGeXQWW/ieCGibl7wvXxfvme2ikaRbhnUMFzF1x3Ro yKWQ== X-Forwarded-Encrypted: i=1; AJvYcCUyoORHxuYvyX1hkJMGC8FToMHWqVwst9TFelEbT5bhcgkGZ6upjBExUlttxILRz5xjYapKyWkiGg==@kvack.org X-Gm-Message-State: AOJu0YwndmE53iDtfa+BpwYJnN5GalK9dVcAcRAs6JEUGB9Kpdc98IWq SJqEnVRByzJAHFzyWoCEOVlwfgHoqhJQG6lvBoVHGGixcRURB++lff+B+hulscMvdTIZXKCtiSB PKjy0Bzr042V+wucVWQvg0cDaTLLM0eARKnGMIQ== X-Google-Smtp-Source: AGHT+IHsypqnvHxqefjiDxYFDz2akYzDsFoGU6PLh+7312onUDhEMOGndUNDmbbTnJmbGIeOeR17h1E7o2px85taLvw= X-Received: by 2002:a05:6a21:2d8b:b0:1d5:10c3:af5a with SMTP id adf61e73a8af0-1d5e2d3df25mr3361839637.47.1727851945585; Tue, 01 Oct 2024 23:52:25 -0700 (PDT) MIME-Version: 1.0 References: <20240925075707.3970187-1-linyunsheng@huawei.com> <20240925075707.3970187-3-linyunsheng@huawei.com> <4968c2ec-5584-4a98-9782-143605117315@redhat.com> In-Reply-To: From: Ilias Apalodimas Date: Wed, 2 Oct 2024 09:51:49 +0300 Message-ID: Subject: Re: [PATCH net v2 2/2] page_pool: fix IOMMU crash when driver has already unbound To: Paolo Abeni Cc: Yunsheng Lin , davem@davemloft.net, kuba@kernel.org, liuyonglong@huawei.com, fanghaiqing@huawei.com, zhangkun09@huawei.com, Robin Murphy , Alexander Duyck , IOMMU , Wei Fang , Shenwei Wang , Clark Wang , Eric Dumazet , Tony Nguyen , Przemek Kitszel , Alexander Lobakin , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , 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 , imx@lists.linux.dev, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, intel-wired-lan@lists.osuosl.org, bpf@vger.kernel.org, linux-rdma@vger.kernel.org, linux-wireless@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-mm@kvack.org Content-Type: text/plain; charset="UTF-8" X-Stat-Signature: 53zq37ezn9ia157ux8guwbfm7hwfpd7r X-Rspamd-Queue-Id: 20AAFA0008 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1727851946-823479 X-HE-Meta: U2FsdGVkX1+sEuB7nU/Q9JtloKERxhIWSmA42su+J4Nfdm2wnXJSjkZK/cnizAd9xMwi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Qe0CMyNpIbCnUV1FkK89F01708Hh6S99lIpvNXa21BhnF57k1075fNioYeDeJVt18FOIYChGgnWeuiNsMxTj8jz09CIr21vKPAM8eUypE0Cxeq5IbF+ya2UebeL2f2VsMQo32zvv2rpfZ3heLZ+xXDoQEWB7mapE2o4affcsslLk+Xw92QZbQLvmqk+sq+R8Xn/Gu0fkrdcKCkbQbx7UcbrhFJWY7+Sp3slmFnOsMnUEbihM= 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 Wed, 2 Oct 2024 at 09:46, Ilias Apalodimas wrote: > > Hi Paolo, > > Thanks for taking the time. > > On Tue, 1 Oct 2024 at 16:32, Paolo Abeni wrote: > > > > On 9/25/24 09:57, 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 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. As the pool->items need to be large enough to avoid > > > performance degradation, add a 'item_full' stat to indicate the > > > allocation failure due to unavailability of pool->items. > > > > This looks really invasive, with room for potentially large performance > > regressions or worse. At very least it does not look suitable for net. > > Perhaps, and you are right we need to measure performance before > pulling it but... > > > > > Is the problem only tied to VFs drivers? It's a pity all the page_pool > > users will have to pay a bill for it... > > It's not. The problem happens when an SKB has been scheduled for > recycling and has already been mapped via page_pool. If the driver > disappears in the meantime, Apologies, this wasn't correct. It's the device that has to disappear not the driver > page_pool will free all the packets it > holds in its private rings (both slow and fast), but is not in control > of the SKB anymore. So any packets coming back for recycling *after* > that point cannot unmap memory properly. > > As discussed this can either lead to memory corruption and resource > leaking, or worse as seen in the bug report panics. I am fine with > this going into -next, but it really is a bugfix, although I am not > 100% sure that the Fixes: tag in the current patch is correct. > > Thanks > /Ilias > > > > /P > >