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 F1C07CE8E80 for ; Thu, 24 Oct 2024 14:40:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6924F8D000A; Thu, 24 Oct 2024 10:40:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 641DD8D0003; Thu, 24 Oct 2024 10:40:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4E2CC8D000A; Thu, 24 Oct 2024 10:40:48 -0400 (EDT) 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 2E69E8D0003 for ; Thu, 24 Oct 2024 10:40:48 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id AFC3C40FBC for ; Thu, 24 Oct 2024 14:40:37 +0000 (UTC) X-FDA: 82708756998.04.F3E7C7F Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf27.hostedemail.com (Postfix) with ESMTP id B9FDE40003 for ; Thu, 24 Oct 2024 14:40:26 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=DaZuzUEI; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf27.hostedemail.com: domain of toke@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=toke@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729780676; 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=RHSCv9bt2jpShj23dRckGzXNJ1xifqFFBkLD9MkzBQQ=; b=xc7ZVW+3zyFkuHKJSCuNl7tv1XVF5o0wkj3kmTcH9murSthGlG5BRKHQfkl6Baj05inf/M 3o8mud1h+M+//j+lODtM3NgM2K+o+swVsQs6AE4MEVSEZ86oydxb/9ZBftf/W6drMafBva QBb0WJyx5plSLhrtYaCd7W7NEZtdZ5M= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729780676; a=rsa-sha256; cv=none; b=6Cdl50YdFS4sRWkIYiKBz6Ox3f3aB9GNckoUN/XPQKpEXE7JawIfHRyHqm3ehfSz6ZibEf nvFM5HSrN2VjJYKeEwx+O1AzPirRcNqgpZmtiiSrVbVxGo7ekFJiJl5qUlwuaDYj+Rmj+N yI3HYyNZt5IBUm9Ti5NQTsymjTamRzI= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=DaZuzUEI; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf27.hostedemail.com: domain of toke@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=toke@redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729780844; h=from:from: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=RHSCv9bt2jpShj23dRckGzXNJ1xifqFFBkLD9MkzBQQ=; b=DaZuzUEIpd/4ulJrcF1r8hTNbx3nhDN+Mp3l2KWtJ5by9UXXRKCPndsSzcbPKs24XcQmXR OYAJ4PYv4KuxgqPGgli7quZ8vvRNi+rcM0uktCUBtd0VCkiqp0q2EAcx+d2WM9r1AdovAl TYE+BwkMhXngywRKORMtA4VdhTqHdJQ= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-505-YS7fQKtsPjeGbfKWZnvn2g-1; Thu, 24 Oct 2024 10:40:43 -0400 X-MC-Unique: YS7fQKtsPjeGbfKWZnvn2g-1 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-42ac185e26cso8142725e9.3 for ; Thu, 24 Oct 2024 07:40:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729780842; x=1730385642; h=content-transfer-encoding:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+CjMdzWLILQKd2T9F7nyB4WETCRS6M6pCeZeEmGLW54=; b=Mq5tmlGt1IYzsv7JhXwWHdtxfiYg48UOXSLDtOP/ZPZhYdf1JYRHH/2JPWShcFGZCU gNfZU2x9WMrrv+vgCzqqw1eU560pKjslQ4wczgKpYH6AWyuemSvuoL16UTwuV5Z6mrxl Z1jpjPqRaxECB25aa4wD5xv0hMCd2KBuTfa6u5O8ieA6Tr12AM3k2BdnSvZ2JbzzJ9BC RCjARDF7Vu0UMMDhZ2yEWoiL831UVSJoZKiPmQKS75ADnd4FSMQc2r3UxO9oB3xG+mBp 1lcrBggr6Pw+Tfkedy2wLw6YKbfUCZ2dobCVWMgR9gZVeIaoVbdafG024/S4OXUpY1Q+ oN5Q== X-Forwarded-Encrypted: i=1; AJvYcCVmJialS5iLjQPRdV0HX486GBYKzHVTVyQLi67Hm82IXgF17L5gCjxTW2n4FI3NS91BVXp0LjAC/Q==@kvack.org X-Gm-Message-State: AOJu0YzUYiU5hk+qJ5EYF3dE4dogoaKl/nn9GXUnoQ7Bvw6mtpUGrHq4 hOD/tgOhnjR3y61ZVfSrB86/0bh9rYFqKtO1tje5+5OVINcweGNzTOqagoLAqVlqHgAiy9xNCnw XY9QVy+bdj3fx+qHfYE4cJ1y/liCEhN6yzcv4P2zFGX6yluz+ X-Received: by 2002:adf:f850:0:b0:37d:50f8:a801 with SMTP id ffacd0b85a97d-380458ec65bmr1564902f8f.47.1729780842078; Thu, 24 Oct 2024 07:40:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEHlCZfIV1vlnJ8aUV+taDRYgNoiomN86d8HqIw3XbXDwesM0GycuE5hSHY+Pb/gN5r8/Xadw== X-Received: by 2002:adf:f850:0:b0:37d:50f8:a801 with SMTP id ffacd0b85a97d-380458ec65bmr1564881f8f.47.1729780841620; Thu, 24 Oct 2024 07:40:41 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([45.145.92.2]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37ee0b94356sm11505321f8f.67.2024.10.24.07.40.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 07:40:41 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 41B6B160B4E3; Thu, 24 Oct 2024 16:40:40 +0200 (CEST) From: Toke =?utf-8?Q?H=C3=B8iland-J=C3=B8rgensen?= To: Yunsheng Lin , Jesper Dangaard Brouer , davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com Cc: zhangkun09@huawei.com, fanghaiqing@huawei.com, liuyonglong@huawei.com, Robin Murphy , Alexander Duyck , IOMMU , Andrew Morton , Eric Dumazet , Ilias Apalodimas , linux-mm@kvack.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, kernel-team Subject: Re: [PATCH net-next v3 3/3] page_pool: fix IOMMU crash when driver has already unbound In-Reply-To: <113c9835-f170-46cf-92ba-df4ca5dfab3d@huawei.com> References: <20241022032214.3915232-1-linyunsheng@huawei.com> <20241022032214.3915232-4-linyunsheng@huawei.com> <113c9835-f170-46cf-92ba-df4ca5dfab3d@huawei.com> X-Clacks-Overhead: GNU Terry Pratchett Date: Thu, 24 Oct 2024 16:40:40 +0200 Message-ID: <878qudftsn.fsf@toke.dk> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: B9FDE40003 X-Stat-Signature: ci7pistoowk9s6hgmhk8hrrukcktgtuu X-Rspam-User: X-HE-Tag: 1729780826-103264 X-HE-Meta: U2FsdGVkX1996eY+9LxsGw0yCJVN4o5ksu1jA5UCA1DlyAhcdcqXyu3SZlMfghI/b5Sol1IwEbcER/MoR5EjIHiWzac/Dp8WxyujOYIbtouNUTc65z7F7W9HLK005GQbyg/B4XDZVpJC8Vk4MW0vP39mKryAVMuzG8IWWqQh7Prg9F1FmQYJjRQeTm11LsZXPV7ZaKEnjEwKmooc/+AkM12PM+RaFtYoYjPlNJiu52o0cwHRGo8sK2WibKYc/vwwFIP3DHU0RQDnvcMJohR20E6wCT0//U5FL7I9d+4hG1fY5GNdjIFYEEx3kqHt105nr/sSlLkN8XMPAzigboRsIZHUxi5hkfJ7C5GvbFVyba4kBpTuVnH7D8sdGmnCOBkuZRZD0BTIxdSPhmqVI6nYpeMVsMu42h4hntSbQKYVGEYOJ4EfnWDs7BeeZrkEotnDZWTRDTllykp63cUEBMAjaXvBTChSxkMbKD6ytjijYKjRo+VfQl/R1dWishDXyPfSA+r1AkBp83VfENSIZ7ehSWskpcqkn6NztebFOSmIsTPLUbutaIQolSCuhT3Xa5M/+SnxFEaiZcjD/oWXyOlPtK7aOlYDCNqbhQZ+5OTlqJIhFXODa2A82vZl3ldWrsfFJ8eMHXIoD20lTv4+T7PgXKAHkf6GZY+dtTPSUfX/KWPwwL0+yahXOjGnAkRZqhmQB3ETG2Feqcat5hEPjXiZL2GiQpoufbMQhZIj6CdHX62mo7kGhPPvQOwhJf14hvqsua6tOXyAZP250a2tOy2XfY/0jIVdlhIE5oGqECxUREJ6F/RUe0DGUvUXdKf/jk58H8s0lGhN6ef74gTWDlhf/lsMGKK5sD6SE2iH+9GgkxKnUWyCmlrcMpioWtdy53G46ElaPPrgV2rtLEn17k3rOu42Sa69q1et3artImx2DHaGuQJGg/vAUE+I0qvrR9EjEhjrl658wxADPCua2Kl aDrg4D+l +9EDXxPMYacwS/I2lK21WEybLbkAJ4i9andSKB5rQwAqpUAjAMahy0V7XuxfggQfeTUWuo8kA+T3BI5ZdFgbbguvY3K3puXFCwXsx56FigHcsIUDn9OKbu+UcMQeNJHnpdy/v4y1sZP4hmRyNt3zz0aB3O8uE03X7DT/yJ03VsFIxnugi+VuDrBanMPAEHcrxE0RMQpgd93+dTBlQU/EwYC8Wv7KolyUE1MXe52sgIzMvTk/H2uPKFwddD2g+MR0Xp18H2wbeQJkWuloCh6Eon1QZezeilnc3oN7uTtbeldECDRXdJ7pQ4Ht3Vkh2j3toIpvdLZHu/N0mrS31N6DSHWEyYqC/Vpvgga+fwC9aYODn7zxlABLvo0T7LVZIUl2bmSpPkPjtjbf0N5SF21jv0l9a8pL4co53ouY6+aXNjkgRg7jMWdT71YTffvVS8cuDQBoNTUxp4V0Tp+UZPUHAKrkpvoJGcPHpZIgghkJUUSq2YBNGGqcEmlO9OwrukfhzrphH/Mas+hLkgDNJL8IBT5UIE1liJh7F6A2k/2fgXZWzxW2KKQxEnJOeXt3Pm6Iaf30BzKZLSB1RIMgJ6RPkYUcUNOT+K96/YOFlMobRp4AN3NErasdDJYtuvv0dNzRmtWUa 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: Yunsheng Lin writes: > On 2024/10/23 2:14, Jesper Dangaard Brouer wrote: >>=20 >>=20 >> On 22/10/2024 05.22, 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 >>> =C2=A0=C2=A0=C2=A0 delay up to 30 secs. >>> 2. skb_defer_free_flush(): this may cause infinite delay if >>> =C2=A0=C2=A0=C2=A0 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 >>=20 >> I really really dislike this approach! >>=20 >> Nacked-by: Jesper Dangaard Brouer >>=20 >> Having to keep an array to record all the pages including the ones >> which are handed over to network stack, goes against the very principle >> behind page_pool. We added members to struct page, such that pages could >> be "outstanding". > > Before and after this patch both support "outstanding", the difference is > how many "outstanding" pages do they support. > > The question seems to be do we really need unlimited inflight page for > page_pool to work as mentioned in [1]? > > 1. https://lore.kernel.org/all/5d9ea7bd-67bb-4a9d-a120-c8f290c31a47@huawe= i.com/ Well, yes? Imposing an arbitrary limit on the number of in-flight packets (especially such a low one as in this series) is a complete non-starter. Servers have hundreds of gigs of memory these days, and if someone wants to use that for storing in-flight packets, the kernel definitely shouldn't impose some (hard-coded!) limit on that. >>=20 >> The page_pool already have a system for waiting for these outstanding / >> inflight packets to get returned.=C2=A0 As I suggested before, the page_= pool >> should simply take over the responsability (from net_device) to free the >> struct device (after inflight reach zero), where AFAIK the DMA device is >> connected via. > > It seems you mentioned some similar suggestion in previous version, > it would be good to show some code about the idea in your mind, I am sure > that Yonglong Liu Cc'ed will be happy to test it if there some code like > POC/RFC is provided. I believe Jesper is basically referring to Jakub's RFC that you mentioned below. > I should mention that it seems that DMA device is not longer vaild when > remove() function of the device driver returns, as mentioned in [2], whic= h > means dma API is not allowed to called after remove() function of the dev= ice > driver returns. > > 2. https://www.spinics.net/lists/netdev/msg1030641.html > >>=20 >> The alternative is what Kuba suggested (and proposed an RFC for),=C2=A0 = that >> the net_device teardown waits for the page_pool inflight packets. > > As above, the question is how long does the waiting take here? > Yonglong tested Kuba's RFC, see [3], the waiting took forever due to > reason as mentioned in commit log: > "skb_defer_free_flush(): this may cause infinite delay if there is no > triggering for net_rx_action()." Honestly, this just seems like a bug (the "no triggering of net_rx_action()") that should be root caused and fixed; not a reason that waiting can't work. -Toke