linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: robin.murphy@arm.com (Robin Murphy)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2] iommu/io-pgtable-arm: Don't use dma_to_phys()
Date: Fri, 18 Sep 2015 12:04:26 +0100	[thread overview]
Message-ID: <55FBEFBA.6000606@arm.com> (raw)
In-Reply-To: <1442566550.8145.156.camel@mhfsdcap03>

On 18/09/15 09:55, Yong Wu wrote:
> On Thu, 2015-09-17 at 17:42 +0100, Robin Murphy wrote:
[...]
>> the appropriate course of action. Further care (and ugliness) is also
>> necessary in the comparison to avoid truncation if phys_addr_t and
>> dma_addr_t differ in size.
[...]
>>   		/*
>>   		 * We depend on the IOMMU being able to work with any physical
>> -		 * address directly, so if the DMA layer suggests it can't by
>> -		 * giving us back some translation, that bodes very badly...
>> +		 * address directly, so if the DMA layer suggests otherwise by
>> +		 * translating or truncating them, that bodes very badly...
>>   		 */
>> -		if (dma != __arm_lpae_dma_addr(dev, pages))
>> +		if (dma != virt_to_phys(pages))
>
> Could I ask why not use __arm_lpae_dma_addr(pages) here?
> dma is dma_addr_t.

Specifically, the problem case for that is when phys_addr_t is 64-bit 
but dma_addr_t is 32-bit. The cast in __arm_lpae_dma_addr is necessary 
to avoid a truncation warning when we make the DMA API calls, but we 
actually need the opposite in the comparison here - comparing the 
different types directly allows integer promotion to kick in 
appropriately so we don't lose the top half of the larger address. 
Otherwise, you'd never spot the difference between, say, your original 
page at 0x88c0000000 and a bounce-buffered copy that happened to end up 
mapped to 0xc0000000.

Robin.

  reply	other threads:[~2015-09-18 11:04 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-17 14:22 [PATCH] iommu/io-pgtable-arm: Don't use dma_to_phys() Robin Murphy
2015-09-17 14:52 ` Will Deacon
2015-09-17 15:53   ` Robin Murphy
2015-09-17 16:42 ` [PATCH v2] " Robin Murphy
2015-09-18  8:55   ` Yong Wu
2015-09-18 11:04     ` Robin Murphy [this message]
2015-09-18 12:29       ` Russell King - ARM Linux
2015-09-22 13:25       ` Yong Wu
2015-09-22 16:23         ` Robin Murphy
2015-09-22 16:26           ` Will Deacon

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=55FBEFBA.6000606@arm.com \
    --to=robin.murphy@arm.com \
    --cc=linux-arm-kernel@lists.infradead.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;
as well as URLs for NNTP newsgroup(s).