public inbox for linux-arch@vger.kernel.org
 help / color / mirror / Atom feed
From: William Lee Irwin III <wli@holomorphy.com>
To: linux-arch@vger.kernel.org, Jeff Garzik <jgarzik@pobox.com>
Cc: rmk@arm.linux.org.uk, Linus Torvalds <torvalds@osdl.org>,
	David Woodhouse <dwmw2@infradead.org>,
	Christoph Hellwig <hch@infradead.org>,
	Andrew Morton <akpm@osdl.org>, Andrea Arcangeli <andrea@suse.de>
Subject: Re: can device drivers return non-ram via vm_ops->nopage?
Date: Sun, 21 Mar 2004 19:45:09 -0800	[thread overview]
Message-ID: <20040322034509.GB2045@holomorphy.com> (raw)
In-Reply-To: <405E3387.1050505@pobox.com>

Sorry about the top posting and long quote; I wanted to fully quote the
API under discussion while getting the central issues aired in the first
few lines. The suggested dma_scatterlist structure, for the API
proposed below, was:

struct dma_scatterlist {
        dma_addr_t dma_addr;            /* DMA address */
        void *cpu_addr;                 /* cpu address */
        unsigned long length;           /* in units of pages */
};

What we're trying to resolve here is drivers supporting ->mmap() doing
virt_to_page() on the results of dma_alloc_coherent() and other things
they shouldn't, and so passing back bogus page pointers as the return
value from ->nopage(), and having no method of resolving it due to the
fact mem_map[] may not cover the area referred to and there is no
portable method for reliably determining pfn's or other information
necessary even to establish mappings by hand. I think it's worth noting
that (according to rmk) ->cpu_addr may not be in any way relevant to
RAM, pfn's, or virtual mappings (I'm not actually sure what it is)
and has to be treated as arch-private otherwise-opaque data.

The way this is expected to solve the problem is by providing a method
for the arch to establish mappings of these areas not reliant on struct
page or fault handling. That is, these functions prefault the areas
into the process address space, thus insulating the core from the
details of fault handling on these areas and eliminating fault handling
on these areas altogether.

I tried to translate a function prototype for prefaulting these areas
into userspace that rmk gave as an example into a full set of operations
based on his proposed piece of the API. So what I'm looking for here
is to find out whether this is good enough for all of the various
arches, and if not, how we can get something together that will fix the
bugs in these drivers that will work portably.

jgarzik's comments on suitability for sound drivers follow the API
itself.


William Lee Irwin III wrote:
>>int dma_mmap_coherent_sg(struct dma_scatterlist *sglist,
>>                        int nr_sglist_elements,     /* length of sglist */
>>                        struct vm_area_struct *vma, /* for address space */
>>                        unsigned long address,      /* user virtual 
>>                        address */
>>                        unsigned long offset,       /* offset (in pages) */
>>                        unsigned long nr_pages);    /* length (in pages) */
>>
>>int dma_munmap_coherent_sg(struct dma_scatterlist *sglist,
>>                        int nr_sglist_elements,     /* length of sglist */
>>                        struct vm_area_struct *vma, /* for address space */
>>                        unsigned long address,      /* user virtual 
>>                        address */
>>                        unsigned long offset,       /* offset (in pages) */
>>                        unsigned long nr_pages);    /* length (in pages) */
>>
>>int dma_alloc_coherent_sg(struct dma_scatterlist **sglist,
>>                        unsigned long length);      /* length in pages */
>>
>>int dma_free_coherent_sg(struct dma_scatterlist **sglist,
>>                        unsigned long length);      /* length in pages */

Where it was proposed that these would be helper functions that sit
atop primitive functions like:

int dma_mmap_coherent(struct vm_area_struct *vma,
                        unsigned long address,      
                        dma_addr_t dma_addr,            /* DMA address */
                        void *cpu_addr,                 /* cpu address */
                        unsigned long nr_pages);        /* length (in pages) */

int dma_munmap_coherent(struct vm_area_struct *vma,
                        unsigned long address,
                        dma_addr_t dma_addr,            /* DMA address */
                        void *cpu_addr,                 /* cpu address */
                        unsigned long nr_pages);        /* length (in pages) */


jgarzik's assessment was:


On Sun, Mar 21, 2004 at 07:29:59PM -0500, Jeff Garzik wrote:
> No comment on struct dma_scatterlist, but the above is the most natural 
> API for audio drivers at least.
> Audio drivers allocate buffers at ->probe() or open(2), and the only 
> entity that actually cares about the contents of the buffers are (a) the 
> hardware and (b) userland.  via82cxxx_audio only uses 
> pci_alloc_consistent because there's not a more appropriate DMA 
> allocator for the use to which that memory is put.
> Audio drivers only need to read/write the buffers inside the kernel when 
> implementing read(2) and write(2) via copy_{to,from}_user().

One thing that concerns me about this is that jgarzik seems to be
saying that via82cxxx_audio's needs aren't covered, so some alteration
to accommodate it may be necessary.


-- wli

       reply	other threads:[~2004-03-22  3:45 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20040321204931.A11519@infradead.org>
     [not found] ` <1079902670.17681.324.camel@imladris.demon.co.uk>
     [not found]   ` <Pine.LNX.4.58.0403211349340.1106@ppc970.osdl.org>
     [not found]     ` <20040321222327.D26708@flint.arm.linux.org.uk>
     [not found]       ` <405E1859.5030906@pobox.com>
     [not found]         ` <20040321225117.F26708@flint.arm.linux.org.uk>
     [not found]           ` <Pine.LNX.4.58.0403211504550.1106@ppc970.osdl.org>
     [not found]             ` <20040321234515.G26708@flint.arm.linux.org.uk>
     [not found]               ` <20040322002349.GZ2045@holomorphy.com>
     [not found]                 ` <405E3387.1050505@pobox.com>
2004-03-22  3:45                   ` William Lee Irwin III [this message]
2004-03-22  4:41                     ` can device drivers return non-ram via vm_ops->nopage? James Bottomley
2004-03-22  4:46                       ` William Lee Irwin III
2004-03-22  4:56                         ` James Bottomley
2004-03-22  5:26                           ` Benjamin Herrenschmidt
2004-03-22 11:58                             ` Andrea Arcangeli
2004-03-22 12:05                               ` Russell King
2004-03-22 12:34                                 ` Andrea Arcangeli
2004-03-22  9:30                       ` Russell King
2004-03-22 15:04                         ` James Bottomley
2004-03-22 15:15                           ` Russell King
2004-03-22 15:27                             ` James Bottomley
2004-03-22 21:50                               ` Benjamin Herrenschmidt
2004-03-22 22:18                                 ` Jeff Garzik
2004-03-22 22:35                                   ` William Lee Irwin III
2004-03-22 23:57                                     ` Benjamin Herrenschmidt
2004-03-23  0:22                                       ` David Woodhouse
2004-03-23  2:07                                       ` William Lee Irwin III
2004-03-23  9:28                                         ` Russell King
2004-03-23  9:34                                           ` David Woodhouse
2004-03-23 10:04                                             ` Russell King
2004-03-23 10:05                                               ` William Lee Irwin III
2004-03-23 11:29                                               ` Benjamin Herrenschmidt
2004-03-23 11:35                                         ` Andrea Arcangeli
2004-03-23 11:44                                           ` William Lee Irwin III
2004-03-23 12:34                                             ` Andrea Arcangeli
2004-03-23 12:40                                               ` Russell King
2004-03-23 15:25                                                 ` Linus Torvalds
2004-03-23 15:36                                                   ` Andrea Arcangeli
2004-03-23 15:46                                                     ` Linus Torvalds
2004-03-23 15:50                                                     ` Russell King
2004-03-23 22:10                                                     ` Benjamin Herrenschmidt
2004-03-25 20:25                                                 ` Russell King
2004-03-28 10:17                                                   ` Russell King
2004-03-23 12:49                                               ` William Lee Irwin III
2004-03-22 23:19                                   ` Russell King
2004-03-22 23:35                                     ` Jeff Garzik
2004-03-23  2:26                                       ` James Bottomley

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=20040322034509.GB2045@holomorphy.com \
    --to=wli@holomorphy.com \
    --cc=akpm@osdl.org \
    --cc=andrea@suse.de \
    --cc=dwmw2@infradead.org \
    --cc=hch@infradead.org \
    --cc=jgarzik@pobox.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=rmk@arm.linux.org.uk \
    --cc=torvalds@osdl.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