All of lore.kernel.org
 help / color / mirror / Atom feed
From: Russell King <rmk+alsa@arm.linux.org.uk>
To: Alsa Devel list <alsa-devel@lists.sourceforge.net>
Subject: 2.6.4-rc1: ALSA makes invalid assumptions about memory types
Date: Sun, 29 Feb 2004 12:22:34 +0000	[thread overview]
Message-ID: <20040229122234.B28963@flint.arm.linux.org.uk> (raw)

1) Memory types.

   In snd_dma_alloc_pages(), ALSA does this:

        case SNDRV_DMA_TYPE_PCI:
                dmab->area = snd_malloc_pci_pages(dev->dev.pci, size, &dmab->addr);

   which eventually comes down to this:

        res = pci_alloc_consistent(pci, PAGE_SIZE * (1 << pg), dma_addr);

   IOW:

	dmab->area = pci_alloc_consistent(dev->dev.pci, size, &dmab->addr);

   and in snd_pcm_lib_malloc_pages() we copy these into the runtime, thusly:

        runtime->dma_area = dmab.area;
        runtime->dma_addr = dmab.addr;
        runtime->dma_private = dmab.private_data;
        runtime->dma_bytes = size;

   However, in snd_pcm_mmap_data_nopage(), ALSA does this:

                vaddr = runtime->dma_area + offset;
                page = virt_to_page(vaddr);

   virt_to_page may _only_ be used on memory returned by get_free_page()
   and kmalloc(), and certainly not on memory returned by
   pci_alloc_consistent(). The only reason it works on x86 is because
   x86 is a fully cache coherent architecture, so pci_alloc_consistent()
   _just happens_ to be equivalent to get_free_pages() on that platform.
   Note that the same applies to dma_alloc_coherent().

   In other words, the above code will not work on non-cache coherent
   architectures without modification.

   I believe this needs discussing with the DMA API authors on LKML since
   AFAIK the kernel currently doesn't have a clear API to translate memory
   returned by either pci_alloc_consistent() or dma_alloc_coherent() back
   to it's consituent struct page pointers.

   Secondly the user space mapping will be marked as cacheable on some
   architectures, which would be Real Bad(tm) on architectures which
   are not DMA coherent.

   The way architectures mark their mappings uncacheable and/or only
   writecombining is architecture specific... see drivers/video/fbmem.c
   as an example.

2) PCM mmap control/status mappings

   These suffer from a similar cache coherency problem - you can not
   assume that two different mappings of the same page will not alias
   in the CPUs caches.

   In my case on ARM, not only must the user space mappings of these
   structures be marked uncacheable, but also the kernel space mappings
   of the same to ensure that accesses via both mappings always return
   up to date information.

   I have hacks in my tree which work around this using ARM specific
   functionality, but this is very much architecture specific at the
   moment, and I suspect requires a new kernel API for creating memory
   (it's similar to the DMA case above.)

-- 
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 PCMCIA      - http://pcmcia.arm.linux.org.uk/
                 2.6 Serial core


-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click

             reply	other threads:[~2004-02-29 12:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-02-29 12:22 Russell King [this message]
2004-02-29 12:48 ` 2.6.4-rc1: ALSA makes invalid assumptions about memory types Jaroslav Kysela
2004-02-29 12:48   ` [Alsa-devel] " Jaroslav Kysela
2004-02-29 15:26   ` Russell King

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=20040229122234.B28963@flint.arm.linux.org.uk \
    --to=rmk+alsa@arm.linux.org.uk \
    --cc=alsa-devel@lists.sourceforge.net \
    /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.