All of lore.kernel.org
 help / color / mirror / Atom feed
From: Konrad Rzeszutek Wilk <konrad@darnok.org>
To: "Kalev, Leonid" <Leonid.Kalev@ca.com>, konrad.wilk@oracle.com
Cc: xen-devel <xen-devel@lists.xensource.com>,
	Jan Beulich <JBeulich@suse.com>,
	Tushar N Dave <tushar.n.dave@intel.com>
Subject: Re: Buffers not reachable by PCI
Date: Wed, 14 Dec 2011 20:59:45 -0500	[thread overview]
Message-ID: <20111215015944.GD10268@konrad-lan> (raw)
In-Reply-To: <4EE8EDF5.5070800@ca.com>

On Wed, Dec 14, 2011 at 06:42:07PM +0000, Kalev, Leonid wrote:
> On 12/14/2011 06:42 PM, Taylor, Neal E wrote:
> > The last quoted printout is calculated the same way as the test that fails which leads me to question the computation's validity.
> 
> The computation validity seems OK to me (the 'phys' address is, as correctly stated 
> in the comments, not suitable for DMA, but it is first translated via 
> xen_phys_to_bus, which gives the machine address - and on x86 that is also the bus 
> address)
> 
> I have a STUPID question, though: why are the start and end addresses of the swiotlb 
> memory area not page-aligned???

That is not a stupid question.
> 
> The io_tlb_end address is one byte PAST the valid area, which is why the 
> xen_swiotlb_dma_supported function uses (xen_io_tlb_end-1). However, this will work 
> properly only if the value is page-aligned. If it isn't, then decrementing it by one 
> will keep the value in the same page (which is one page past the last valid one).
> 
> The function that allocates the memory uses alloc_bootmem(), which provides just 
> cache-aligned memory (not page-aligned).

Yup.

It is actually funny (sad?), b/c I am the committer for the
e79f86b2ef9c0a8c47225217c1018b7d3d90101c which adds something like this:

 alloc_bootmem_pages(PAGE_ALIGN(io_tlb_nslabs * sizeof(int)

in the swiotlb code but I completly missed doing it for the Xen SWIOTLB.

<sigh>

I think this patch:

>From 47409eecc08effe20fc4aa0da899dd6ac475cb0b Mon Sep 17 00:00:00 2001
From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Date: Wed, 14 Dec 2011 20:48:01 -0500
Subject: [PATCH] xen/swiotlb: Use page alignment for early buffer allocation.

This piggybacks on git commit e79f86b2ef9c0a8c47225217c1018b7d3d90101c
"swiotlb: Use page alignment for early buffer allocation" which:

"We could call free_bootmem_late() if swiotlb is not used, and
it will shrink to page alignment.

So alloc them with page alignment at first, to avoid lose two pages"

Reported-by: "Kalev, Leonid" <Leonid.Kalev@ca.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
---
 drivers/xen/swiotlb-xen.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
index 8e964b9..5c8e445 100644
--- a/drivers/xen/swiotlb-xen.c
+++ b/drivers/xen/swiotlb-xen.c
@@ -166,7 +166,8 @@ retry:
 	/*
 	 * Get IO TLB memory from any location.
 	 */
-	xen_io_tlb_start = alloc_bootmem(bytes);
+	xen_io_tlb_start = alloc_bootmem_pages(PAGE_ALIGN(bytes));
+
 	if (!xen_io_tlb_start) {
 		m = "Cannot allocate Xen-SWIOTLB buffer!\n";
 		goto error;
@@ -179,7 +180,7 @@ retry:
 			       bytes,
 			       xen_io_tlb_nslabs);
 	if (rc) {
-		free_bootmem(__pa(xen_io_tlb_start), bytes);
+		free_bootmem(__pa(xen_io_tlb_start), PAGE_ALIGN(bytes));
 		m = "Failed to get contiguous memory for DMA from Xen!\n"\
 		    "You either: don't have the permissions, do not have"\
 		    " enough free memory under 4GB, or the hypervisor memory"\
-- 
1.7.1

is in order.
> 
> If it is OK for the swiotlb area not to be page-aligned, then the 
> xen_swiotlb_dma_supported should use (xen_io_tlb_end - (PAGE_SIZE-1))

Lets make it page aligned.

> 
> If the memory should be in fact aligned, then the allocation must be changed to 
> alloc_bootmem_pages() (which is the same as alloc_bootmem, but page-aligned).

  reply	other threads:[~2011-12-15  1:59 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-09 20:19 Buffers not reachable by PCI Taylor, Neal E
2011-12-09 20:30 ` Konrad Rzeszutek Wilk
2011-12-12 22:11   ` Taylor, Neal E
2011-12-13  0:19     ` Konrad Rzeszutek Wilk
2011-12-13 19:34       ` Taylor, Neal E
2011-12-13 22:17       ` Taylor, Neal E
2011-12-13 23:28         ` Konrad Rzeszutek Wilk
2011-12-14  0:38           ` Taylor, Neal E
2011-12-14  9:20             ` Jan Beulich
2011-12-14 16:42               ` Taylor, Neal E
2011-12-14 18:42                 ` Kalev, Leonid
2011-12-15  1:59                   ` Konrad Rzeszutek Wilk [this message]
2011-12-15  2:19                     ` Taylor, Neal E
2011-12-15  2:29                       ` Konrad Rzeszutek Wilk
2011-12-15  2:40                         ` Taylor, Neal E
2011-12-15 16:12                           ` Konrad Rzeszutek Wilk
2011-12-15 16:14                             ` Taylor, Neal E
2011-12-15  2:16                   ` Taylor, Neal E
2011-12-14 19:11               ` 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=20111215015944.GD10268@konrad-lan \
    --to=konrad@darnok.org \
    --cc=JBeulich@suse.com \
    --cc=Leonid.Kalev@ca.com \
    --cc=konrad.wilk@oracle.com \
    --cc=tushar.n.dave@intel.com \
    --cc=xen-devel@lists.xensource.com \
    /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.