From: "Kalev, Leonid" <Leonid.Kalev@ca.com>
To: "Taylor, Neal E" <Neal.Taylor@ca.com>
Cc: Konrad Rzeszutek Wilk <konrad@darnok.org>,
xen-devel <xen-devel@lists.xensource.com>,
Tushar N Dave <tushar.n.dave@intel.com>,
Jan Beulich <JBeulich@suse.com>
Subject: Re: Buffers not reachable by PCI
Date: Wed, 14 Dec 2011 18:42:07 +0000 [thread overview]
Message-ID: <4EE8EDF5.5070800@ca.com> (raw)
In-Reply-To: <3E243B26F475504B9BB0BCC9728B0DA629E18A6B@USILMS110A.ca.com>
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???
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).
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))
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).
>
> The test that fails is (from drivers/xen/swiotlb-xen.c):
> xen_swiotlb_dma_supported(struct device *hwdev, u64 mask)
> {
> return xen_virt_to_bus(xen_io_tlb_end - 1)<= mask;
> }
>
>
> "xen_virt_to_bus" in turn:
> static dma_addr_t xen_virt_to_bus(void *address)
> {
> return xen_phys_to_bus(virt_to_phys(address));
> }
>
>
> Now, "virt_to_phys" (out of arch/x86/include/asm/io.h) is defined as follows but carries a comment bothersome to this usage of it as we're, basically, dealing with a dma "transfer" and calling from a device driver:
> /**
> * virt_to_phys - map virtual addresses to physical
> * @address: address to remap
> *
> * The returned physical address is the physical (CPU) mapping for
> * the memory address given. It is only valid to use this function on
> * addresses directly mapped or allocated via kmalloc.
> *
> * This function does not give bus mappings for DMA transfers. In
> * almost all conceivable cases a device driver should not be using
> * this function
> */
> static inline phys_addr_t virt_to_phys(volatile void *address)
> {
> return __pa(address);
> }
>
>
> Going a couple of steps further, "__pa" is defined (in arch/x86/include/asm/page.h) as:
> #define __pa(x) __phys_addr((unsigned long)(x))
>
>
> and "__phys_addr" (in arch/x86/mm/physaddr.c) as:
> unsigned long __phys_addr(unsigned long x)
> {
> if (x>= __START_KERNEL_map) {
> x -= __START_KERNEL_map;
> VIRTUAL_BUG_ON(x>= KERNEL_IMAGE_SIZE);
> x += phys_base;
> } else {
> VIRTUAL_BUG_ON(x< PAGE_OFFSET);
> x -= PAGE_OFFSET;
> VIRTUAL_BUG_ON(!phys_addr_valid(x));
> }
> return x;
> }
> EXPORT_SYMBOL(__phys_addr);
>
>
> So, if "virt_to_phys" isn't yielding a valid test of whether addresses will be reachable from a PCI device, what's the correct way to test it and should xen_swiotlb_dma_supported be updated to the correct way (I think so) or a new function be created?
>
> Neal
>
>
> -----Original Message-----
> From: Jan Beulich [mailto:JBeulich@suse.com]
> Sent: Wednesday, December 14, 2011 1:20 AM
> To: Taylor, Neal E
> Cc: Kalev, Leonid; Konrad Rzeszutek Wilk; Tushar N Dave; xen-devel
> Subject: Re: [Xen-devel] Buffers not reachable by PCI
>
>>>> On 14.12.11 at 01:38, "Taylor, Neal E"<Neal.Taylor@ca.com> wrote:
>> [ 0.000000] MFN 0x7f7f->0x7f00
>
> This is clearly indicating the last chunk ends well below the 4G boundary.
>
>> [ 0.000000] Placing 64MB software IO TLB between d832cf00 - dc32cf00
>> [ 0.000000] software IO TLB at phys 0x1832cf00 - 0x1c32cf00
>> [ 0.000000] software IO TLB at bus 0x1c0f00 - 0x120fdff00
>
> Consequently, the question is how you got to this value, or what
> changed between the first and last quoted printouts.
>
> Jan
>
--
Leonid Kalev
CA Technologies
Principal Software Engineer
Tel: +972 4 825 3952
Mobile: +972 54 4631508
Leonid.Kalev@ca.com
next prev parent reply other threads:[~2011-12-14 18:42 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 [this message]
2011-12-15 1:59 ` Konrad Rzeszutek Wilk
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=4EE8EDF5.5070800@ca.com \
--to=leonid.kalev@ca.com \
--cc=JBeulich@suse.com \
--cc=Neal.Taylor@ca.com \
--cc=konrad@darnok.org \
--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.