All of lore.kernel.org
 help / color / mirror / Atom feed
From: konrad.wilk@oracle.com (Konrad Rzeszutek Wilk)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v8 18/19] swiotlb-xen: no need to do execute two bus_to_phys translations in a row
Date: Wed, 23 Oct 2013 10:01:50 -0400	[thread overview]
Message-ID: <20131023140150.GB27771@phenom.dumpdata.com> (raw)
In-Reply-To: <1382031814-8782-18-git-send-email-stefano.stabellini@eu.citrix.com>

On Thu, Oct 17, 2013 at 06:43:33PM +0100, Stefano Stabellini wrote:
> xen_unmap_single calls xen_bus_to_phys, then passes dev_addr to
> is_xen_swiotlb_buffer that calls xen_bus_to_phys again.

It does?

I see it call mfn_to_local_pfn which calls pfn_to_mfn and
get_phys_to_machine (which I presume is going to be a slow
operation on ARM).

> xen_bus_to_phys is potentially a slow operation that might involve
> walking a tree.
> We can avoid calling xen_bus_to_phys twice by removing the
> is_xen_swiotlb_buffer call and doing the check directly in
> xen_unmap_single using the physical address.
> 
> Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>

Have you tested this with a PFN that is in a foreign domain?

I am bit uncomfortable with this - I recall when developing this
that I had hit some odd cases of doing DMA of a page to a guest
and it not always working. It was the case of not detecting whether
the pfn was foreign or not. Sadly I can't recall the details.

I would think that this problem would also be present with ARM?
But perhaps all the new changes in the pfn_to_mfn that had lately
been done have fixed this?

> ---
>  drivers/xen/swiotlb-xen.c |    4 ++--
>  1 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
> index 4d50058..6d9ca61 100644
> --- a/drivers/xen/swiotlb-xen.c
> +++ b/drivers/xen/swiotlb-xen.c
> @@ -426,8 +426,8 @@ static void xen_unmap_single(struct device *hwdev, dma_addr_t dev_addr,
>  
>  	xen_dma_unmap_page(hwdev, paddr, size, dir, attrs);
>  
> -	/* NOTE: We use dev_addr here, not paddr! */
> -	if (is_xen_swiotlb_buffer(dev_addr)) {
> +	if (paddr >= virt_to_phys(xen_io_tlb_start) &&
> +		paddr < virt_to_phys(xen_io_tlb_end)) {
>  		swiotlb_tbl_unmap_single(hwdev, paddr, size, dir);
>  		return;
>  	}
> -- 
> 1.7.2.5
> 

WARNING: multiple messages have this Message-ID (diff)
From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: xen-devel@lists.xensource.com, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, Ian.Campbell@citrix.com
Subject: Re: [PATCH v8 18/19] swiotlb-xen: no need to do execute two bus_to_phys translations in a row
Date: Wed, 23 Oct 2013 10:01:50 -0400	[thread overview]
Message-ID: <20131023140150.GB27771@phenom.dumpdata.com> (raw)
In-Reply-To: <1382031814-8782-18-git-send-email-stefano.stabellini@eu.citrix.com>

On Thu, Oct 17, 2013 at 06:43:33PM +0100, Stefano Stabellini wrote:
> xen_unmap_single calls xen_bus_to_phys, then passes dev_addr to
> is_xen_swiotlb_buffer that calls xen_bus_to_phys again.

It does?

I see it call mfn_to_local_pfn which calls pfn_to_mfn and
get_phys_to_machine (which I presume is going to be a slow
operation on ARM).

> xen_bus_to_phys is potentially a slow operation that might involve
> walking a tree.
> We can avoid calling xen_bus_to_phys twice by removing the
> is_xen_swiotlb_buffer call and doing the check directly in
> xen_unmap_single using the physical address.
> 
> Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>

Have you tested this with a PFN that is in a foreign domain?

I am bit uncomfortable with this - I recall when developing this
that I had hit some odd cases of doing DMA of a page to a guest
and it not always working. It was the case of not detecting whether
the pfn was foreign or not. Sadly I can't recall the details.

I would think that this problem would also be present with ARM?
But perhaps all the new changes in the pfn_to_mfn that had lately
been done have fixed this?

> ---
>  drivers/xen/swiotlb-xen.c |    4 ++--
>  1 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
> index 4d50058..6d9ca61 100644
> --- a/drivers/xen/swiotlb-xen.c
> +++ b/drivers/xen/swiotlb-xen.c
> @@ -426,8 +426,8 @@ static void xen_unmap_single(struct device *hwdev, dma_addr_t dev_addr,
>  
>  	xen_dma_unmap_page(hwdev, paddr, size, dir, attrs);
>  
> -	/* NOTE: We use dev_addr here, not paddr! */
> -	if (is_xen_swiotlb_buffer(dev_addr)) {
> +	if (paddr >= virt_to_phys(xen_io_tlb_start) &&
> +		paddr < virt_to_phys(xen_io_tlb_end)) {
>  		swiotlb_tbl_unmap_single(hwdev, paddr, size, dir);
>  		return;
>  	}
> -- 
> 1.7.2.5
> 

  reply	other threads:[~2013-10-23 14:01 UTC|newest]

Thread overview: 118+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-17 17:42 [PATCH v8 0/19] enable swiotlb-xen on arm and arm64 Stefano Stabellini
2013-10-17 17:42 ` Stefano Stabellini
2013-10-17 17:42 ` Stefano Stabellini
2013-10-17 17:43 ` [PATCH v8 01/19] arm: make SWIOTLB available Stefano Stabellini
2013-10-17 17:43   ` Stefano Stabellini
2013-10-17 17:43   ` Stefano Stabellini
2013-10-18 15:56   ` Stefano Stabellini
2013-10-18 15:56     ` Stefano Stabellini
2013-10-18 15:56     ` Stefano Stabellini
2013-10-17 17:43 ` [PATCH v8 02/19] arm64: define DMA_ERROR_CODE Stefano Stabellini
2013-10-17 17:43   ` Stefano Stabellini
2013-10-17 17:43   ` Stefano Stabellini
2013-10-17 17:43 ` [PATCH v8 03/19] arm/xen,arm64/xen: introduce p2m Stefano Stabellini
2013-10-17 17:43   ` Stefano Stabellini
2013-10-17 17:43   ` Stefano Stabellini
2013-10-17 17:43 ` [PATCH v8 04/19] xen/x86: allow __set_phys_to_machine for autotranslate guests Stefano Stabellini
2013-10-17 17:43   ` Stefano Stabellini
2013-10-17 17:43   ` Stefano Stabellini
2013-10-17 17:43 ` [PATCH v8 05/19] xen: make xen_create_contiguous_region return the dma address Stefano Stabellini
2013-10-17 17:43   ` Stefano Stabellini
2013-10-17 17:43   ` Stefano Stabellini
2013-10-17 17:43 ` [PATCH v8 06/19] xen/arm,arm64: enable SWIOTLB_XEN Stefano Stabellini
2013-10-17 17:43   ` Stefano Stabellini
2013-10-17 17:43   ` Stefano Stabellini
2013-10-17 17:43 ` [PATCH v8 07/19] swiotlb-xen: introduce xen_swiotlb_set_dma_mask Stefano Stabellini
2013-10-17 17:43   ` Stefano Stabellini
2013-10-17 17:43   ` Stefano Stabellini
2013-10-17 17:43 ` [PATCH v8 08/19] arm/xen: get_dma_ops: return xen_dma_ops if we are running as xen_initial_domain Stefano Stabellini
2013-10-17 17:43   ` Stefano Stabellini
2013-10-17 17:43   ` Stefano Stabellini
2013-10-18 12:22   ` Stefano Stabellini
2013-10-18 12:22     ` Stefano Stabellini
2013-10-18 12:22     ` Stefano Stabellini
2013-10-18 15:42     ` Russell King - ARM Linux
2013-10-18 15:42       ` Russell King - ARM Linux
2013-10-18 15:46       ` Stefano Stabellini
2013-10-18 15:46         ` Stefano Stabellini
2013-10-18 15:46         ` Stefano Stabellini
2013-10-18 15:48         ` Russell King - ARM Linux
2013-10-18 15:48           ` Russell King - ARM Linux
2013-10-18 15:59           ` Stefano Stabellini
2013-10-18 15:59             ` Stefano Stabellini
2013-10-18 15:59             ` Stefano Stabellini
2013-10-17 17:43 ` [PATCH v8 09/19] arm64/xen: " Stefano Stabellini
2013-10-17 17:43   ` Stefano Stabellini
2013-10-17 17:43   ` Stefano Stabellini
2013-10-17 17:43 ` [PATCH v8 10/19] xen: introduce xen_alloc/free_coherent_pages Stefano Stabellini
2013-10-17 17:43   ` Stefano Stabellini
2013-10-17 17:43   ` Stefano Stabellini
2013-10-17 17:43 ` [PATCH v8 11/19] swiotlb-xen: use xen_alloc/free_coherent_pages Stefano Stabellini
2013-10-17 17:43   ` Stefano Stabellini
2013-10-17 17:43   ` Stefano Stabellini
2013-10-17 17:43 ` [PATCH v8 12/19] xen: introduce xen_dma_map/unmap_page and xen_dma_sync_single_for_cpu/device Stefano Stabellini
2013-10-17 17:43   ` Stefano Stabellini
2013-10-17 17:43   ` Stefano Stabellini
2013-10-17 17:43 ` [PATCH v8 13/19] swiotlb-xen: use xen_dma_map/unmap_page, xen_dma_sync_single_for_cpu/device Stefano Stabellini
2013-10-17 17:43   ` Stefano Stabellini
2013-10-17 17:43   ` Stefano Stabellini
2013-10-23 14:09   ` Konrad Rzeszutek Wilk
2013-10-23 14:09     ` Konrad Rzeszutek Wilk
2013-10-23 17:20     ` Stefano Stabellini
2013-10-23 17:20       ` Stefano Stabellini
2013-10-23 17:20       ` Stefano Stabellini
2013-10-23 19:51       ` Konrad Rzeszutek Wilk
2013-10-23 19:51         ` Konrad Rzeszutek Wilk
2013-10-24 10:44         ` Stefano Stabellini
2013-10-24 10:44           ` Stefano Stabellini
2013-10-24 10:44           ` Stefano Stabellini
2013-10-24 13:11           ` Stefano Stabellini
2013-10-24 13:11             ` Stefano Stabellini
2013-10-24 13:11             ` Stefano Stabellini
2013-10-25 20:46             ` Konrad Rzeszutek Wilk
2013-10-25 20:46               ` Konrad Rzeszutek Wilk
2013-10-25 20:44           ` Konrad Rzeszutek Wilk
2013-10-25 20:44             ` Konrad Rzeszutek Wilk
2013-10-17 17:43 ` [PATCH v8 14/19] ASoC: Samsung: Rename dma_ops by samsung_dma_ops Stefano Stabellini
2013-10-17 17:43   ` Stefano Stabellini
2013-10-17 17:43   ` Stefano Stabellini
2013-10-23 14:39   ` Julien Grall
2013-10-23 14:39     ` Julien Grall
2013-10-17 17:43 ` [PATCH v8 15/19] swiotlb: print a warning when the swiotlb is full Stefano Stabellini
2013-10-17 17:43   ` Stefano Stabellini
2013-10-17 17:43   ` Stefano Stabellini
2013-10-17 17:43 ` [PATCH v8 16/19] arm, arm64: do not always merge biovec if we are running on Xen Stefano Stabellini
2013-10-17 17:43   ` [PATCH v8 16/19] arm,arm64: " Stefano Stabellini
2013-10-17 17:43   ` Stefano Stabellini
2013-10-18 12:23   ` Stefano Stabellini
2013-10-18 12:23     ` Stefano Stabellini
2013-10-18 12:23     ` Stefano Stabellini
2013-10-18 14:07     ` Catalin Marinas
2013-10-18 14:07       ` Catalin Marinas
2013-10-18 14:07       ` Catalin Marinas
2013-10-17 17:43 ` [PATCH v8 17/19] grant-table: call set_phys_to_machine after mapping grant refs Stefano Stabellini
2013-10-17 17:43   ` Stefano Stabellini
2013-10-17 17:43   ` Stefano Stabellini
2013-10-23 14:04   ` Konrad Rzeszutek Wilk
2013-10-23 14:04     ` Konrad Rzeszutek Wilk
2013-10-23 17:15     ` Stefano Stabellini
2013-10-23 17:15       ` Stefano Stabellini
2013-10-23 17:15       ` Stefano Stabellini
2013-10-17 17:43 ` [PATCH v8 18/19] swiotlb-xen: no need to do execute two bus_to_phys translations in a row Stefano Stabellini
2013-10-17 17:43   ` Stefano Stabellini
2013-10-17 17:43   ` Stefano Stabellini
2013-10-23 14:01   ` Konrad Rzeszutek Wilk [this message]
2013-10-23 14:01     ` Konrad Rzeszutek Wilk
2013-10-23 17:34     ` Stefano Stabellini
2013-10-23 17:34       ` Stefano Stabellini
2013-10-23 17:34       ` Stefano Stabellini
2013-10-23 19:53       ` Konrad Rzeszutek Wilk
2013-10-23 19:53         ` Konrad Rzeszutek Wilk
2013-10-24 10:32         ` Stefano Stabellini
2013-10-24 10:32           ` Stefano Stabellini
2013-10-24 10:32           ` Stefano Stabellini
2013-10-17 17:43 ` [PATCH v8 19/19] swiotlb-xen: static inline xen_phys_to_bus, xen_bus_to_phys, xen_virt_to_bus and range_straddles_page_boundary Stefano Stabellini
2013-10-17 17:43   ` Stefano Stabellini
2013-10-17 17:43   ` Stefano Stabellini
2013-10-23 14:15 ` [PATCH v8 0/19] enable swiotlb-xen on arm and arm64 Konrad Rzeszutek Wilk
2013-10-23 14:15   ` Konrad Rzeszutek Wilk

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=20131023140150.GB27771@phenom.dumpdata.com \
    --to=konrad.wilk@oracle.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 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.