From: Will Deacon <will.deacon@arm.com>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Andy Lutomirski <luto@kernel.org>,
kvm@vger.kernel.org, virtualization@lists.linux-foundation.org
Subject: Re: [PATCH v2] virtio_pci: Limit DMA mask to 44 bits for legacy virtio devices
Date: Wed, 14 Sep 2016 17:03:04 +0100 [thread overview]
Message-ID: <20160914160304.GH19622@arm.com> (raw)
In-Reply-To: <20160914154034-mutt-send-email-mst@kernel.org>
Hi Michael,
On Wed, Sep 14, 2016 at 03:42:25PM +0300, Michael S. Tsirkin wrote:
> On Wed, Sep 14, 2016 at 12:16:28PM +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@kernel.org>
> > Cc: Michael S. Tsirkin <mst@redhat.com>
> > Cc: Benjamin Serebrin <serebrin@google.com>
> > Signed-off-by: Will Deacon <will.deacon@arm.com>
> > ---
> > drivers/virtio/virtio_pci_legacy.c | 9 +++++++--
> > 1 file changed, 7 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/virtio/virtio_pci_legacy.c b/drivers/virtio/virtio_pci_legacy.c
> > index 8c4e61783441..efb3f5dff4b7 100644
> > --- a/drivers/virtio/virtio_pci_legacy.c
> > +++ b/drivers/virtio/virtio_pci_legacy.c
> > @@ -212,12 +212,17 @@ int virtio_pci_legacy_probe(struct virtio_pci_device *vp_dev)
> > return -ENODEV;
> > }
> >
> > - rc = dma_set_mask_and_coherent(&pci_dev->dev, DMA_BIT_MASK(64));
> > + /*
> > + * The virtio ring base address is expressed as a 32-bit PFN, with a
> > + * page size of 1 << VIRTIO_PCI_QUEUE_ADDR_SHIFT.
> > + */
> > + rc = dma_set_mask_and_coherent(&pci_dev->dev,
> > + DMA_BIT_MASK(32 + VIRTIO_PCI_QUEUE_ADDR_SHIFT));
>
> So why not limit just the coherent mask, as I suggested in a comment on v1?
Sorry, I completely missed that suggestion. I'll roll a v3 with that
included, although I'll rejig things a bit to make the error handling
a bit more bearable.
> > if (rc)
> > rc = dma_set_mask_and_coherent(&pci_dev->dev,
> > DMA_BIT_MASK(32));
> > if (rc)
> > - dev_warn(&pci_dev->dev, "Failed to enable 64-bit or 32-bit DMA. Trying to continue, but this might not work.\n");
> > + dev_warn(&pci_dev->dev, "Failed to enable %d-bit or 32-bit DMA. Trying to continue, but this might not work.\n", 32 + VIRTIO_PCI_QUEUE_ADDR_SHIFT);
>
>
> I'd rather we split this.
I'll actually just leave like it was in the first place if we're trying a
64-bit streaming mask.
Stay tuned,
Will
prev parent reply other threads:[~2016-09-14 16:03 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-14 11:16 [PATCH v2] virtio_pci: Limit DMA mask to 44 bits for legacy virtio devices Will Deacon
2016-09-14 12:42 ` Michael S. Tsirkin
2016-09-14 16:03 ` Will Deacon [this message]
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=20160914160304.GH19622@arm.com \
--to=will.deacon@arm.com \
--cc=kvm@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mst@redhat.com \
--cc=virtualization@lists.linux-foundation.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 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.