From: Nanyong Sun <sunnanyong@huawei.com>
To: Robin Murphy <robin.murphy@arm.com>, Ard Biesheuvel <ardb@kernel.org>
Cc: <will@kernel.org>, <catalin.marinas@arm.com>,
<sstabellini@kernel.org>, <jgross@suse.com>,
<oleksandr_tyshchenko@epam.com>,
<linux-arm-kernel@lists.infradead.org>,
<linux-kernel@vger.kernel.org>, <wangkefeng.wang@huawei.com>,
<linux@armlinux.org.uk>
Subject: Re: [RFC PATCH] arm64: mm: Add invalidate back in arch_sync_dma_for_device when FROM_DEVICE
Date: Sun, 20 Nov 2022 10:58:40 +0800 [thread overview]
Message-ID: <e6bd415a-201a-b3e3-48f0-beeff91f3b7a@huawei.com> (raw)
In-Reply-To: <f41f4fb9-9459-1fa1-494f-c20033c315da@arm.com>
On 2022/11/17 18:23, Robin Murphy wrote:
> On 2022-11-17 08:24, Ard Biesheuvel wrote:
>> On Thu, 17 Nov 2022 at 07:33, Nanyong Sun <sunnanyong@huawei.com> wrote:
>>>
>>> The commit c50f11c6196f ("arm64: mm: Don't invalidate FROM_DEVICE
>>> buffers at start of DMA transfer") replaces invalidate with clean
>>> when DMA_FROM_DEVICE, this changes the behavior of functions like
>>> dma_map_single() and dma_sync_single_for_device(*, *, *,
>>> DMA_FROM_DEVICE),
>>> then it may make some drivers works unwell because the implementation
>>> of these DMA APIs lose the original cache invalidation.
>>>
>>> Situation 1:
>> ...
>>> Situation 2:
>>> After backporting the above commit, we find a network card driver go
>>> wrong with cache inconsistency when doing DMA transfer: CPU got the
>>> stale data in cache when reading DMA data received from device.
>>
>> I suppose this means those drivers may lack dma_sync_single_for_cpu()
>> calls after the inbound transfers complete, and are instead relying on
>> the cache invalidation performed before the transfer to make the DMA'd
>> data visible to the CPU.
>
> It also commonly goes wrong the other way round when the drivers are
> correct but DT/ACPI failed to indicate a coherent device as such. If
> writes from the device actually snoop, they hit the still-present
> cache line, which then gets invalidated by unmap/sync_for_cpu and the
> new data is lost.
>
> Robin.
>
> .
Is it acceptable? Does the coherent device MUST run with coherent
identifier? At least they can run with no wrong before.
next prev parent reply other threads:[~2022-11-20 3:03 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-17 7:21 Nanyong Sun
2022-11-17 8:24 ` Ard Biesheuvel
2022-11-17 10:23 ` Robin Murphy
2022-11-20 2:58 ` Nanyong Sun [this message]
2022-11-20 2:59 ` Nanyong Sun
2022-11-24 20:04 ` Robin Murphy
2022-12-06 17:07 ` Nanyong Sun
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=e6bd415a-201a-b3e3-48f0-beeff91f3b7a@huawei.com \
--to=sunnanyong@huawei.com \
--cc=ardb@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=jgross@suse.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=oleksandr_tyshchenko@epam.com \
--cc=robin.murphy@arm.com \
--cc=sstabellini@kernel.org \
--cc=wangkefeng.wang@huawei.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®