Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934034AbcJLSUc (ORCPT ); Wed, 12 Oct 2016 14:20:32 -0400 Received: from mail-lf0-f52.google.com ([209.85.215.52]:33714 "EHLO mail-lf0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932868AbcJLSU0 (ORCPT ); Wed, 12 Oct 2016 14:20:26 -0400 Subject: Re: igb driver can cause cache invalidation of non-owned memory? To: Alexander Duyck References: <0b57cbe2-84f7-6c0a-904a-d166571234b5@cogentembedded.com> <20161010.050125.1981283393312167625.davem@davemloft.net> <10474d19-df1a-3b09-917e-70659be3a56c@cogentembedded.com> <20161010.075731.2449861168238706.davem@davemloft.net> <19aebfc3-5f1a-9206-4493-2255af7269f9@cogentembedded.com> <063D6719AE5E284EB5DD2968C1650D6DB01E6F0F@AcuExch.aculab.com> Cc: David Laight , Eric Dumazet , David Miller , Jeff Kirsher , intel-wired-lan , Netdev , "linux-kernel@vger.kernel.org" , Chris Healy From: Nikita Yushchenko X-Enigmail-Draft-Status: N1110 Message-ID: Date: Wed, 12 Oct 2016 21:12:39 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1633 Lines: 39 > It would make more sense to update the DMA API for > __dma_page_cpu_to_dev on ARM so that you don't invalidate the cache if > the direction is DMA_FROM_DEVICE. No, in generic case it's unsafe. If CPU issued a write to a location, and sometime later that location is used as DMA buffer, there is danger that write is still in cache only, and writeback is pending. Later this writeback can overwrite data written to memory via DMA, causing corruption. > The point I was trying to make is that you are invalidating the cache > in both the sync_for_device and sync_for_cpu. Do you really need that > for ARM or do you need to perform the invalidation on sync_for_device > if that may be pushed out anyway? If you aren't running with with > speculative look-ups do you even need the invalidation in > sync_for_cpu? I'm not lowlevel arm guru and I don't know for sure. Probably another CPU core can be accessing locations neighbor page, causing specilative load of locations in DMA page. > Changing the driver code for this won't necessarily work on all > architectures, and on top of it we have some changes planned which > will end up making the pages writable in the future to support the > ongoing XDP effort. That is one of the reasons why I would not be > okay with changing the driver to make this work. Well I was not really serious about removing that sync_for_device() in mainline :) Although >20% throughput win that this provides is impressive... But what about doing something safer, e.g. adding a bit of tracking and only sync_for_device() what was previously sync_for_cpu()ed? Will you accept that? Nikita