From: Alexander Duyck <alexander.duyck@gmail.com>
To: Russell King - ARM Linux <linux@armlinux.org.uk>
Cc: Alexander Duyck <alexander.h.duyck@intel.com>,
Netdev <netdev@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
linux-mm <linux-mm@kvack.org>,
Jesper Dangaard Brouer <brouer@redhat.com>,
David Miller <davem@davemloft.net>
Subject: Re: [net-next PATCH RFC 04/26] arch/arm: Add option to skip sync on DMA map and unmap
Date: Mon, 31 Oct 2016 08:26:30 -0700 [thread overview]
Message-ID: <CAKgT0Uf8vg-78T15EMtnZ7Muz5aRZ_0o2e0GZn8Pc+TjD3xn7w@mail.gmail.com> (raw)
In-Reply-To: <20161031102057.GZ1041@n2100.armlinux.org.uk>
On Mon, Oct 31, 2016 at 3:20 AM, Russell King - ARM Linux
<linux@armlinux.org.uk> wrote:
> On Mon, Oct 24, 2016 at 08:04:47AM -0400, Alexander Duyck wrote:
>> The use of DMA_ATTR_SKIP_CPU_SYNC was not consistent across all of the DMA
>> APIs in the arch/arm folder. This change is meant to correct that so that
>> we get consistent behavior.
>
> I'm really not convinced that this is anywhere close to correct behaviour.
>
> If we're DMA-ing to a buffer, and we unmap it or sync_for_cpu, then we
> will want to access the DMA'd data - especially in the sync_for_cpu case,
> it's pointless to call sync_for_cpu if we're not going to access the
> data.
First, let me clarify. The sync_for_cpu call will still work the
same. This only effects the map/unmap calls.
> So the idea of skipping the CPU copy when DMA_ATTR_SKIP_CPU_SYNC is set
> seems to be completely wrong - it means we end up reading the stale data
> that was in the buffer, completely ignoring whatever was DMA'd to it.
I agree. However this is meant to be used in the dma_unmap call only
if sync_for_cpu has already been called for the regions that could
have been updated by the device.
> What's the use case for DMA_ATTR_SKIP_CPU_SYNC ?
The main use case I have in mind is to allow for pseudo-static DMA
mappings where we can share them between the network stack and the
device driver. I use igb as an example.
1 allocate page, reset page_offset to 0
2 map page while passing DMA_ATTR_SKIP_CPU_SYNC
3 dma_sync_single_range_for_device starting at page_offset, length
2K (largest possible write by device)
4 device performs Rx DMA and updates Rx descriptor
5 read length from Rx descriptor
6 dma_sync_single_range_for_cpu starting at page_offset, length
reported by descriptor
7 if page_count == 1
7.1 update page_offset with xor 2K
7.2 hand page up to network stack
7.3 goto 3
8 unmap page with DMA_ATTR_SKIP_CPU_SYNC
9 hand page up to network stack
10 goto 1
The idea is we want to be able to have a page be accessible to the
device, but be able to share it with the network stack which might try
to write to the page. By letting the driver handle the
synchronization we get two main advantages. First we end up looping
over fewer cache lines as we only have to invalidate the region
updated by the device in steps 3 and 6 instead of the entire page.
The other advantage is that the pages are writable by the network
stack since step 8 will not invalidate the entire mapping.
I am just as concerned about the possibility of stale data. That is
why I have gone through and made sure that any path in the igb driver
called sync for the region held by the device before we might call
unmap. It isn't that I don't want the data to be kept fresh, it is a
matter of wanting control over what we are invalidating. Here is a
link to the igb patch I have that was a part of this set.
https://patchwork.ozlabs.org/patch/686747/
Thanks.
- Alex
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2016-10-31 15:26 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-24 12:04 [net-next PATCH RFC 00/26] Add support for DMA writable pages being writable by the network stack Alexander Duyck
2016-10-24 12:04 ` [net-next PATCH RFC 01/26] swiotlb: Drop unused function swiotlb_map_sg Alexander Duyck
2016-10-24 18:10 ` Konrad Rzeszutek Wilk
2016-10-24 12:04 ` [net-next PATCH RFC 02/26] swiotlb: Add support for DMA_ATTR_SKIP_CPU_SYNC Alexander Duyck
2016-10-24 18:09 ` Konrad Rzeszutek Wilk
2016-10-24 19:16 ` Alexander Duyck
2016-10-25 1:22 ` Konrad Rzeszutek Wilk
2016-10-24 12:04 ` [net-next PATCH RFC 03/26] arch/arc: Add option to skip sync on DMA mapping Alexander Duyck
2016-10-24 12:04 ` [net-next PATCH RFC 04/26] arch/arm: Add option to skip sync on DMA map and unmap Alexander Duyck
2016-10-31 10:20 ` Russell King - ARM Linux
2016-10-31 15:26 ` Alexander Duyck [this message]
2016-10-24 12:04 ` [net-next PATCH RFC 05/26] arch/avr32: Add option to skip sync on DMA map Alexander Duyck
2016-10-24 18:27 ` Hans-Christian Noren Egtvedt
2016-10-24 12:04 ` [net-next PATCH RFC 06/26] arch/blackfin: " Alexander Duyck
2016-10-24 12:05 ` [net-next PATCH RFC 07/26] arch/c6x: Add option to skip sync on DMA map and unmap Alexander Duyck
2016-10-28 14:59 ` Mark Salter
2016-10-24 12:05 ` [net-next PATCH RFC 08/26] arch/frv: Add option to skip sync on DMA map Alexander Duyck
2016-10-24 12:05 ` [net-next PATCH RFC 09/26] arch/hexagon: Add option to skip DMA sync as a part of mapping Alexander Duyck
2016-10-24 12:05 ` [net-next PATCH RFC 10/26] arch/m68k: " Alexander Duyck
2016-10-24 12:05 ` [net-next PATCH RFC 11/26] arch/metag: Add option to skip DMA sync as a part of map and unmap Alexander Duyck
2016-10-24 12:05 ` [net-next PATCH RFC 12/26] arch/microblaze: " Alexander Duyck
2016-10-24 12:05 ` [net-next PATCH RFC 13/26] arch/mips: " Alexander Duyck
2016-10-24 12:05 ` [net-next PATCH RFC 14/26] arch/nios2: " Alexander Duyck
2016-10-24 12:05 ` [net-next PATCH RFC 15/26] arch/openrisc: Add option to skip DMA sync as a part of mapping Alexander Duyck
2016-10-24 12:05 ` [net-next PATCH RFC 16/26] arch/parisc: Add option to skip DMA sync as a part of map and unmap Alexander Duyck
2016-10-24 12:05 ` [net-next PATCH RFC 17/26] arch/powerpc: Add option to skip DMA sync as a part of mapping Alexander Duyck
2016-10-24 12:06 ` [net-next PATCH RFC 18/26] arch/sh: " Alexander Duyck
2016-10-24 12:06 ` [net-next PATCH RFC 19/26] arch/sparc: Add option to skip DMA sync as a part of map and unmap Alexander Duyck
2016-10-24 18:27 ` David Miller
2016-10-24 19:24 ` Alexander Duyck
2016-10-24 12:06 ` [net-next PATCH RFC 20/26] arch/tile: " Alexander Duyck
2016-10-24 12:06 ` [net-next PATCH RFC 21/26] arch/xtensa: Add option to skip DMA sync as a part of mapping Alexander Duyck
2016-10-24 12:06 ` [net-next PATCH RFC 22/26] dma: Add calls for dma_map_page_attrs and dma_unmap_page_attrs Alexander Duyck
2016-10-24 12:06 ` [net-next PATCH RFC 23/26] mm: Add support for releasing multiple instances of a page Alexander Duyck
2016-10-24 12:06 ` [net-next PATCH RFC 24/26] igb: Update driver to make use of DMA_ATTR_SKIP_CPU_SYNC Alexander Duyck
2016-10-24 12:06 ` [net-next PATCH RFC 25/26] igb: Update code to better handle incrementing page count Alexander Duyck
2016-10-24 12:06 ` [net-next PATCH RFC 26/26] igb: Revert "igb: Revert support for build_skb in igb" 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=CAKgT0Uf8vg-78T15EMtnZ7Muz5aRZ_0o2e0GZn8Pc+TjD3xn7w@mail.gmail.com \
--to=alexander.duyck@gmail.com \
--cc=alexander.h.duyck@intel.com \
--cc=brouer@redhat.com \
--cc=davem@davemloft.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux@armlinux.org.uk \
--cc=netdev@vger.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