Re: [PATCH] virtio_pci: Limit DMA mask to 44 bits for legacy virtio devices

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Sep 12, 2016 at 8:57 AM, Will Deacon <will.deacon@xxxxxxx> wrote:
>
> On Mon, Sep 12, 2016 at 06:33:43PM +0300, Michael S. Tsirkin wrote:
> > On Mon, Sep 12, 2016 at 01:10:41PM +0100, Will Deacon wrote:
> > > Legacy virtio defines the virtqueue base using a 32-bit PFN field, with
> > > a read-only register indicating a fixed page size of 4k.
> > >
> > > This can cause problems for DMA allocators that allocate top down from
> > > the DMA mask, which is set to 64 bits. In this case, the addresses are
> > > silently truncated to 44-bit, leading to IOMMU faults, failure to read
> > > from the queue or data corruption.
> > >
> > > This patch restricts the DMA mask for legacy PCI virtio devices to
> > > 44 bits, which matches the specification.
> > >
> > > Cc: Andy Lutomirski <luto@xxxxxxxxxx>
> > > Cc: Michael S. Tsirkin <mst@xxxxxxxxxx>
> > > Signed-off-by: Will Deacon <will.deacon@xxxxxxx>
> >
> > Hmm - IIUC it's actually only the case for the virtio rings
> > themselves. The buffer addresses put in the rings are full 64 bit ones.
>
> I think that's right, yes.


Yes.

>
>
> > It so happens that virtio doesn't use coherent allocs except
> > for the rings.
> > So I'm inclined to say the coherent mask should be set to 44,
> > with a comment explaning that this is for the rings.
>
> I can certainly add that in v2, along with your suggestion to use
> 32 + VIRTIO_PCI_QUEUE_ADDR_SHIFT instead of the 44.
>
> > In case we start using coherent allocations in virtio,
> > it might be cleaner to relax the mask after allocating
> > the rings, but I'm not sure that's allowed by the DMA API.
> > thoughts?
>
> Hmm, that *might* work, but I could certainly imagine some DMA
> implementations going wrong if they assume the mask is fixed.


There's probably a hack to make the buffer addresses be 64-bit capable
while letting the queue addresses be 44-bit, but is it worth the trouble?
Maybe assume that guests with more than 16 TB of RAM are rare today,
and catch the Virtio 1.x spec to fix the 32-bit PFN limit?

Alternately, you could keep the DMA mask at 64 bits but try to allocate
the rings early, and abort if they can't get a < 16 TB address.  I think
I prefer the 44 bit mask approach, though.


>
>
> Will
> _______________________________________________
> Virtualization mailing list
> Virtualization@xxxxxxxxxxxxxxxxxxxxxxxxxx
> https://lists.linuxfoundation.org/mailman/listinfo/virtualization
_______________________________________________
Virtualization mailing list
Virtualization@xxxxxxxxxxxxxxxxxxxxxxxxxx
https://lists.linuxfoundation.org/mailman/listinfo/virtualization



[Index of Archives]     [KVM Development]     [Libvirt Development]     [Libvirt Users]     [CentOS Virtualization]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux