dvd dma problems

Matthew Dillon dillon at apollo.backplane.com
Tue Jul 15 00:17:39 UTC 2008

:> quite fine from 5.3 to somewhere in the 6.x branch. Nowadays I have to send
:> them to PIO4 to play DVDs, because they'll just throw DMA not aligned errors
:> around in UDMA33 or WDMA2 mode.
:> Should someone be interested in this I'm willing to supply all necessary
:> information, such as the exact drives, firmware versions, kernel traces...
:> whatever comes to your mind. I'm also willing to test patches.
:Is the problem you're seeing identical to this?
:| Jeremy Chadwick                                jdc at parodius.com |

    One of our guys (in DragonFly-land) tracked this down two two issues,
    fixing either one will fix the problem.  I'd include a patch but he
    has not finished it yet.  Still, anyone with moderate kernel
    programming skills can probably fix it in an hour or less.

    physio() - uses vmapbuf().  vmapbuf() does NOT realign the user address,
    it simply maps it into the buffer and adjusts b_data.  So if the
    user supplies a badly aligned buffer, physio() will happily pass that
    bad alignment to the driver.

    physio() could be modified to allocate kernel memory to back the pbuf
    and copy instead of calling vmapbuf(), for those cases where the user
    supplied buffer is not well aligned (e.g. not at least 512-byte aligned).
    The pbuf already reserve KVA so all one would need to do is allocate
    pages to back the KVA space.  I think a couple of other subsystems in
    the kernel do this with pbufs so there is plenty of example material.


    The ATA driver has an explicit alignment check and also uses
    BUS_DMA_NOWAIT in its call to bus_dmamap_load() in ata_dmaload().

    The ATA driver could be adjusted to remove the alignment check,
    remove the BUS_DMA_NOWAIT flag, and also not free the bounce buffer
    when DMA ends (so you don't get allocator deadlocks).  You might have
    other issues related to lock ordering, and this solution would eat
    a considerable amount of memory (upwards of a megabyte, more if you have
    more ATA channels), but that's the jist of it.

    It should be noted that only physio() can supply unaligned BIOs to the
    driver layer.  All other BIO sources (that I know of) will always be
    at least 512-byte aligned.


    My recommendation is to fix physio().  User programs that do not supply
    aligned buffers clearly don't care about performance, so the kernel
    can just back the pbuf with memory and copyin/out the user data.

					Matthew Dillon 
					<dillon at backplane.com>

More information about the freebsd-stable mailing list