lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20151109120017.GY8644@n2100.arm.linux.org.uk>
Date:	Mon, 9 Nov 2015 12:00:17 +0000
From:	Russell King - ARM Linux <linux@....linux.org.uk>
To:	"Sharma, Sanjeev" <Sanjeev_Sharma@...tor.com>
Cc:	Will Deacon <will.deacon@....com>,
	sanjeev sharma <sanjeevsharmaengg@...il.com>,
	"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
	"linux-arm-kernel@...ts.infradead.org" 
	<linux-arm-kernel@...ts.infradead.org>,
	"m.szyprowski@...sung.com" <m.szyprowski@...sung.com>
Subject: Re: [PATCH] ARM:dma-mapping: Handle DMA_BIDIRECTIONAL in
 _dma_page_cpu_to_dev()

On Mon, Nov 09, 2015 at 10:15:34AM +0000, Sharma, Sanjeev wrote:
> It may cause the following issue.
> 1.we create the buffer with cache, and in some cases, the cache may be dirty.
> 2.then we call the sync_for_device function with flag DMA_BIDIRECTIONAL to
> avoid some cache problems.

This is wrong.  Please read the DMA-API document on proper use of these
functions.  Enable CONFIG_DMA_API_DEBUG as well.

> 3. however __dma_page_cpu_to_dev() just see DMA_BIDIRECTIONAL the same as 
> DMA_TO_DEVICE, which means the kernel will not invalid the cache if we use
> the flag DMA_BIDIRECTIONAL.
> 4.since the dirty cache is not invalid, the dirty content may be showed on
> the buffer in the future rendering.

This is again wrong.  __dma_page_cpu_to_dev() with DMA_BIDIRECTIONAL will
_clean_ the cache, which means it will push out all the dirty content
in the cache.  However, it leaves the data in the cache in case we want
to read it later (for the FROM_DEVICE.)

It is _invalid_ to read from the mapping while the device owns it, and
as Cortex CPUs speculatively prefetch, you can end up with new cach
lines allocated in this memory region.  So, before reading the memory,
you _must_ either unmap the DMA buffer, or call dma_sync_for_cpu().
Either of those two functions will then invalidate the cache for a
DMA_BIDIRECTIONAL mapping, allowing you to safely read the data.

-- 
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ