From: Robin Murphy <robin.murphy@arm.com>
To: Yunsheng Lin <linyunsheng@huawei.com>,
Somnath Kotur <somnath.kotur@broadcom.com>,
Jesper Dangaard Brouer <hawk@kernel.org>
Cc: Yonglong Liu <liuyonglong@huawei.com>,
"David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
pabeni@redhat.com, ilias.apalodimas@linaro.org,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
Alexander Duyck <alexander.duyck@gmail.com>,
Alexei Starovoitov <ast@kernel.org>,
"shenjian (K)" <shenjian15@huawei.com>,
Salil Mehta <salil.mehta@huawei.com>,
joro@8bytes.org, will@kernel.org, iommu@lists.linux.dev
Subject: Re: [BUG REPORT]net: page_pool: kernel crash at iommu_get_dma_domain+0xc/0x20
Date: Tue, 6 Aug 2024 13:50:08 +0100 [thread overview]
Message-ID: <ae995d55-daa9-4060-85fa-31b4f725a17d@arm.com> (raw)
In-Reply-To: <5b0415ff-9bbe-4553-89d6-17d12fd44b47@huawei.com>
On 06/08/2024 12:54 pm, Yunsheng Lin wrote:
> On 2024/8/5 20:53, Robin Murphy wrote:
>>>>>
>>>>> The page_pool bumps refcnt via get_device() + put_device() on the DMA
>>>>> 'struct device', to avoid it going away, but I guess there is also some
>>>>> IOMMU code that we need to make sure doesn't go away (until all inflight
>>>>> pages are returned) ???
>>>
>>> I guess the above is why thing went wrong here, the question is which
>>> IOMMU code need to be called here to stop them from going away.
>>
>> This looks like the wrong device is being passed to dma_unmap_page() - if a device had an IOMMU DMA domain at the point when the DMA mapping was create, then neither that domain nor its group can legitimately have disappeared while that device still had a driver bound. Or if it *was* the right device, but it's already had device_del() called on it, then you have a fundamental lifecycle problem - a device with no driver bound should not be passed to the DMA API, much less a dead device that's already been removed from its parent bus.
>
> Yes, the device *was* the right device, And it's already had device_del()
> called on it.
> page_pool tries to call get_device() on the DMA 'struct device' to avoid the
> above lifecycle problem, it seems get_device() does not stop device_del()
> from being called, and that is where we have the problem here:
> https://elixir.bootlin.com/linux/v6.11-rc2/source/net/core/page_pool.c#L269
>
> The above happens because 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.
OK, that sounds like a more insidious problem - it's not just IOMMU
stuff, in general the page pool should not be holding and using the
device pointer after the device has already been destroyed. Even without
an IOMMU, 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.
Thanks,
Robin.
next prev parent reply other threads:[~2024-08-06 12:50 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <0e54954b-0880-4ebc-8ef0-13b3ac0a6838@huawei.com>
2024-07-30 13:08 ` Yonglong Liu
2024-07-30 17:21 ` Jesper Dangaard Brouer
2024-07-31 8:42 ` Somnath Kotur
2024-07-31 11:32 ` Yonglong Liu
2024-08-02 2:06 ` Yonglong Liu
2024-08-06 9:51 ` Jesper Dangaard Brouer
2024-08-06 14:23 ` Robin Murphy
2024-08-05 12:19 ` Yunsheng Lin
2024-08-05 12:53 ` Robin Murphy
2024-08-06 11:54 ` Yunsheng Lin
2024-08-06 12:50 ` Robin Murphy [this message]
2024-08-06 13:50 ` Jason Gunthorpe
2024-08-20 13:22 ` Mina Almasry
2024-08-20 14:43 ` Jakub Kicinski
2024-08-20 7:18 ` Yonglong Liu
2024-08-20 10:05 ` Robin Murphy
2024-08-06 13:35 ` Niklas Schnelle
2024-08-13 18:49 ` Matthew Rosato
2024-08-02 16:38 ` Alexander Duyck
2024-08-05 12:50 ` Yunsheng Lin
2024-08-06 0:39 ` Alexander Duyck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ae995d55-daa9-4060-85fa-31b4f725a17d@arm.com \
--to=robin.murphy@arm.com \
--cc=alexander.duyck@gmail.com \
--cc=ast@kernel.org \
--cc=davem@davemloft.net \
--cc=hawk@kernel.org \
--cc=ilias.apalodimas@linaro.org \
--cc=iommu@lists.linux.dev \
--cc=joro@8bytes.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linyunsheng@huawei.com \
--cc=liuyonglong@huawei.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=salil.mehta@huawei.com \
--cc=shenjian15@huawei.com \
--cc=somnath.kotur@broadcom.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®