Re: [Qemu-devel] Re: [PATCH 2 of 5] add can_dma/post_dma for direct IO

Anthony Liguori
2008-12-14T19:10:50Z

Avi Kivity wrote:
> Anthony Liguori wrote:
>>>
>>> There are N users of this code, all of which would need to cope with
>>> the
>>> failure. Or there could be one user (dma.c) which handles the failure
>>> and the bouncing.
>>>
>>
>> N should be small long term. It should only be for places that would
>> interact directly with CPU memory. This would be the PCI BUS, the
>> ISA BUS, some speciality devices, and possibly virtio (although you
>> could argue it should go through the PCI BUS).
>
> Fine, then let's rename it pci-dma.c.

Better, but then it should be part of pci.c. I've thought quite a bit
about it, and I'm becoming less convinced that this sort of API is going
to be helpful.

I was thinking that we need to make one minor change to the map API I
proposed. It should return a mapped size as an output parameter and
take a flag as to whether partial mappings can be handled. The effect
would be that you never bounce to RAM which means that you can also
quite accurately determine the maximum amount of bouncing (it should be
proportional to the amount of MMIO memory that's registered).

For virtio, I think the only change that we would make it to replace the
existing bouncing code with calls to map()/unmap() for each
scatter/gather array. You may need to cope with a scatter/gather list
that is larger than the inputted vector but that's easy.

This means you always map complete requests which is where I think it
fundamentally differs from what you propose. However, this is safe
because you should be able to guarantee that you can always bounce the
MMIO memory at least once. The only place where you could run into
trouble is if the same MMIO page is mapped multiple times in a single
scatter/gather. You could, in theory, attempt to cache MMIO bouncing
but that's probably unnecessary.

So virtio would not need this dma API.

I think the same is true about IDE/SCSI. I think we can built code that
relies on being able to completely map a scatter/gather list as long as
we make the map function sufficiently smart. As long as our bounce pool
is as large as the registered MMIO memory, we can always be safe is
we're sufficiently clever.

Xen is a more difficult case but I'm perfectly willing to punt that to
them to figure out.

Regards,

Anthony Liguori