All of lore.kernel.org
 help / color / mirror / Atom feed
From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: Ian Campbell <ian.campbell@citrix.com>, stefano.panella@citrix.com
Cc: stefano.stabellini@eu.citrix.com, xen-devel@lists.xen.org
Subject: Re: [PATCH] xen: swiotlb: handle sizeof(dma_addr_t) != sizeof(phys_addr_t)
Date: Tue, 21 Jan 2014 17:03:55 -0500	[thread overview]
Message-ID: <20140121220355.GA6557@phenom.dumpdata.com> (raw)
In-Reply-To: <1389979493-22670-1-git-send-email-ian.campbell@citrix.com>

On Fri, Jan 17, 2014 at 05:24:53PM +0000, Ian Campbell wrote:
> The use of phys_to_machine and machine_to_phys in the phys<=>bus conversions
> causes us to lose the top bits of the DMA address if the size of a DMA address is not the same as the size of the phyiscal address.
> 
> This can happen in practice on ARM where foreign pages can be above 4GB even
> though the local kernel does not have LPAE page tables enabled (which is
> totally reasonable if the guest does not itself have >4GB of RAM). In this
> case the kernel still maps the foreign pages at a phys addr below 4G (as it
> must) but the resulting DMA address (returned by the grant map operation) is
> much higher.
> 
> This is analogous to a hardware device which has its view of RAM mapped up
> high for some reason.
> 
> This patch makes I/O to foreign pages (specifically blkif) work on 32-bit ARM
> systems with more than 4GB of RAM.

There was another patch posted by somebody from Citrix for a fix on 
32-bit x86 dom0 with more than 4GB of RAM (for x86 platforms).

Their fix was in the generic parts of code. Changing most of the 'unsigned'
to 'phys_addr_t' or such. Is his patch better or will this patch replace his?

It was " dma-mapping: dma_alloc_coherent_mask return dma_addr_t"
https://lkml.org/lkml/2013/12/10/593

> 
> Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
> ---
>  arch/arm/Kconfig          |    1 +
>  drivers/xen/swiotlb-xen.c |   14 ++++++++++++--
>  2 files changed, 13 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
> index c1f1a7e..24307dc 100644
> --- a/arch/arm/Kconfig
> +++ b/arch/arm/Kconfig
> @@ -1885,6 +1885,7 @@ config XEN
>  	depends on !GENERIC_ATOMIC64
>  	select ARM_PSCI
>  	select SWIOTLB_XEN
> +	select ARCH_DMA_ADDR_T_64BIT
>  	help
>  	  Say Y if you want to run Linux in a Virtual Machine on Xen on ARM.
>  
> diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
> index 1eac073..b626c79 100644
> --- a/drivers/xen/swiotlb-xen.c
> +++ b/drivers/xen/swiotlb-xen.c
> @@ -77,12 +77,22 @@ static u64 start_dma_addr;
>  
>  static inline dma_addr_t xen_phys_to_bus(phys_addr_t paddr)
>  {
> -	return phys_to_machine(XPADDR(paddr)).maddr;
> +	unsigned long mfn = pfn_to_mfn(PFN_DOWN(paddr));
> +	dma_addr_t dma = (dma_addr_t)mfn << PAGE_SHIFT;
> +	dma |= paddr & ~PAGE_MASK;
> +	return dma;
>  }
>  
>  static inline phys_addr_t xen_bus_to_phys(dma_addr_t baddr)
>  {
> -	return machine_to_phys(XMADDR(baddr)).paddr;
> +	dma_addr_t dma = PFN_PHYS(mfn_to_pfn(PFN_DOWN(baddr)));
> +	phys_addr_t paddr = dma;
> +
> +	BUG_ON(paddr != dma); /* truncation has occurred, should never happen */
> +
> +	paddr |= baddr & ~PAGE_MASK;
> +
> +	return paddr;
>  }
>  
>  static inline dma_addr_t xen_virt_to_bus(void *address)
> -- 
> 1.7.10.4
> 

  parent reply	other threads:[~2014-01-21 22:03 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-17 17:24 [PATCH] xen: swiotlb: handle sizeof(dma_addr_t) != sizeof(phys_addr_t) Ian Campbell
2014-01-17 18:09 ` Stefano Stabellini
2014-01-20  9:46   ` Ian Campbell
2014-01-21 22:03 ` Konrad Rzeszutek Wilk [this message]
2014-01-22  9:50   ` Ian Campbell
2014-01-22 12:11     ` Stefano Stabellini
2014-01-22 14:47       ` Stefano Panella
2014-01-22 14:54         ` Stefano Stabellini
2014-01-22 21:01 ` Konrad Rzeszutek Wilk
2014-01-23 11:19   ` Ian Campbell
2014-01-23 17:42     ` Konrad Rzeszutek Wilk
2014-01-23 17:51       ` Ian Campbell

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=20140121220355.GA6557@phenom.dumpdata.com \
    --to=konrad.wilk@oracle.com \
    --cc=ian.campbell@citrix.com \
    --cc=stefano.panella@citrix.com \
    --cc=stefano.stabellini@eu.citrix.com \
    --cc=xen-devel@lists.xen.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.