From: Nikita Yushchenko <nikita.yoush@cogentembedded.com>
To: David Miller <davem@davemloft.net>
Cc: jeffrey.t.kirsher@intel.com, intel-wired-lan@lists.osuosl.org,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
cphealy@gmail.com
Subject: Re: igb driver can cause cache invalidation of non-owned memory?
Date: Mon, 10 Oct 2016 15:27:47 +0300 [thread overview]
Message-ID: <f75cf1e1-d7e8-e044-188a-987f05f321a5@cogentembedded.com> (raw)
In-Reply-To: <20161010.075731.2449861168238706.davem@davemloft.net>
>> Hmm... I'm not about device writing to memory.
>
> This absolutely is about whether the device wrote into the
> area or not.
Not only.
>> Sequence in igb driver is:
>>
>> dma_map(full_page)
>> <device writes here>
>> sync_to_cpu(half_page);
>> skb_add_rx_frag(skb, half_page);
>> napi_gro_receive(skb);
>> ...
>> dma_unmap(full_page)
>>
>> What I'm concerned about is - same area is first passed up to network
>> stack, and _later_ dma_unmap()ed. Is this indeed safe?
>
> dma_unmap() should never write anything unless the device has
> meanwhile written to that chunk of memory.
dma_unmap() for DMA_FROM_DEVICE never writes whatever to memory,
regardless of what device did.
dma_unmap() for DMA_FROM_DEVICE ensures that data written to memory
by device (if any) is visible to CPU. Cache may contain stale data
for that memory region. To drop that from cache, dma_unmap() for
DMA_FROM_DEVICE does cache invalidation.
static void arm_dma_unmap_page(struct device *dev, dma_addr_t handle,
size_t size, enum dma_data_direction dir, unsigned long attrs)
{
if ((attrs & DMA_ATTR_SKIP_CPU_SYNC) == 0)
__dma_page_dev_to_cpu(pfn_to_page(dma_to_pfn(dev, handle)),
handle & ~PAGE_MASK, size, dir);
}
static void __dma_page_dev_to_cpu(struct page *page, unsigned long off,
size_t size, enum dma_data_direction dir)
{
...
if (dir != DMA_TO_DEVICE) {
outer_inv_range(paddr, paddr + size);
dma_cache_maint_page(page, off, size, dir, dmac_unmap_area);
}
...
}
> If the device made no intervening writes into the area, dma_unmap()
> should not cause any data to be written to that area, period.
I'm not about writing.
I'm about just the opposite - dropping not-written data from cache.
- napi_gro_receive(skb) passes area to upper layers of the network stack,
- something in those layers - perhaps packet mangling or such - writes
to the area,
- this write enters cache but does not end into memory immediately,
- at this moment, igb does dma_unmap(),
- write that was in cache but not yet in memory gets lost.
> In your example above, consider the case where the device never
> writes into the memory area after sync_to_cpu(). In that case
> there is nothing that dma_unmap() can possibly write.
> All the data has been synced
Non-synced data is write done by CPU executing upper layers of network stack,
Nikita
next prev parent reply other threads:[~2016-10-10 12:27 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-10 8:52 igb driver can cause cache invalidation of non-owned memory? Nikita Yushchenko
2016-10-10 9:01 ` David Miller
2016-10-10 9:51 ` Nikita Yushchenko
2016-10-10 11:57 ` David Miller
2016-10-10 12:27 ` Nikita Yushchenko [this message]
2016-10-10 12:31 ` Nikita Yushchenko
2016-10-10 15:11 ` Alexander Duyck
2016-10-10 17:00 ` Nikita Yushchenko
2016-10-10 17:38 ` Alexander Duyck
2016-10-12 6:55 ` Nikita Yushchenko
2016-10-12 15:32 ` Alexander Duyck
2016-10-12 16:03 ` David Laight
2016-10-12 16:11 ` Nikita Yushchenko
2016-10-12 17:56 ` Alexander Duyck
2016-10-12 18:12 ` Nikita Yushchenko
2016-10-12 18:30 ` Alexander Duyck
2016-10-13 10:39 ` David Laight
2016-10-13 11:00 ` Nikita Yushchenko
2016-10-13 20:32 ` 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=f75cf1e1-d7e8-e044-188a-987f05f321a5@cogentembedded.com \
--to=nikita.yoush@cogentembedded.com \
--cc=cphealy@gmail.com \
--cc=davem@davemloft.net \
--cc=intel-wired-lan@lists.osuosl.org \
--cc=jeffrey.t.kirsher@intel.com \
--cc=linux-kernel@vger.kernel.org \
--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