From: Christian Borntraeger <borntraeger@de.ibm.com>
To: Cornelia Huck <cornelia.huck@de.ibm.com>,
Andy Lutomirski <luto@kernel.org>
Cc: linux-s390 <linux-s390@vger.kernel.org>,
Joerg Roedel <jroedel@suse.de>, KVM <kvm@vger.kernel.org>,
"Michael S. Tsirkin" <mst@redhat.com>,
benh@kernel.crashing.org,
Sebastian Ott <sebott@linux.vnet.ibm.com>,
linux-kernel@vger.kernel.org, Christoph Hellwig <hch@lst.de>,
Martin Schwidefsky <schwidefsky@de.ibm.com>,
sparclinux@vger.kernel.org, Paolo Bonzini <pbonzini@redhat.com>,
virtualization@lists.linux-foundation.org, dwmw2@infradead.org,
"David S. Miller" <davem@davemloft.net>
Subject: Re: [PATCH v4 2/6] virtio_ring: Support DMA APIs
Date: Fri, 30 Oct 2015 13:05:11 +0100 [thread overview]
Message-ID: <56335CF7.2050101@de.ibm.com> (raw)
In-Reply-To: <20151030130116.52a87922.cornelia.huck@de.ibm.com>
Am 30.10.2015 um 13:01 schrieb Cornelia Huck:
> On Thu, 29 Oct 2015 18:09:47 -0700
> Andy Lutomirski <luto@kernel.org> wrote:
>
>> virtio_ring currently sends the device (usually a hypervisor)
>> physical addresses of its I/O buffers. This is okay when DMA
>> addresses and physical addresses are the same thing, but this isn't
>> always the case. For example, this never works on Xen guests, and
>> it is likely to fail if a physical "virtio" device ever ends up
>> behind an IOMMU or swiotlb.
>>
>> The immediate use case for me is to enable virtio on Xen guests.
>> For that to work, we need vring to support DMA address translation
>> as well as a corresponding change to virtio_pci or to another
>> driver.
>>
>> With this patch, if enabled, virtfs survives kmemleak and
>> CONFIG_DMA_API_DEBUG.
>>
>> Signed-off-by: Andy Lutomirski <luto@kernel.org>
>> ---
>> drivers/virtio/Kconfig | 2 +-
>> drivers/virtio/virtio_ring.c | 190 +++++++++++++++++++++++++++++++--------
>> tools/virtio/linux/dma-mapping.h | 17 ++++
>> 3 files changed, 172 insertions(+), 37 deletions(-)
>> create mode 100644 tools/virtio/linux/dma-mapping.h
>
>> static void detach_buf(struct vring_virtqueue *vq, unsigned int head)
>> {
>> - unsigned int i;
>> + unsigned int i, j;
>> + u16 nextflag = cpu_to_virtio16(vq->vq.vdev, VRING_DESC_F_NEXT);
>>
>> /* Clear data ptr. */
>> - vq->data[head] = NULL;
>> + vq->desc_state[head].data = NULL;
>>
>> - /* Put back on free list: find end */
>> + /* Put back on free list: unmap first-level descriptors and find end */
>> i = head;
>>
>> - /* Free the indirect table */
>> - if (vq->vring.desc[i].flags & cpu_to_virtio16(vq->vq.vdev, VRING_DESC_F_INDIRECT))
>> - kfree(phys_to_virt(virtio64_to_cpu(vq->vq.vdev, vq->vring.desc[i].addr)));
>> -
>> - while (vq->vring.desc[i].flags & cpu_to_virtio16(vq->vq.vdev, VRING_DESC_F_NEXT)) {
>> + while (vq->vring.desc[i].flags & nextflag) {
>> + vring_unmap_one(vq, &vq->vring.desc[i]);
>> i = virtio16_to_cpu(vq->vq.vdev, vq->vring.desc[i].next);
>> vq->vq.num_free++;
>> }
>>
>> + vring_unmap_one(vq, &vq->vring.desc[i]);
>> vq->vring.desc[i].next = cpu_to_virtio16(vq->vq.vdev, vq->free_head);
>> vq->free_head = head;
>> +
>> /* Plus final descriptor */
>> vq->vq.num_free++;
>> +
>> + /* Free the indirect table, if any, now that it's unmapped. */
>> + if (vq->desc_state[head].indir_desc) {
>> + struct vring_desc *indir_desc = vq->desc_state[head].indir_desc;
>> + u32 len = vq->vring.desc[head].len;
>
> This one needs to be virtio32_to_cpu(...) as well.
Yes, just did the exact same change
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index f269e1c..f2249df 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -556,7 +556,7 @@ static void detach_buf(struct vring_virtqueue *vq, unsigned int head)
/* Free the indirect table, if any, now that it's unmapped. */
if (vq->desc_state[head].indir_desc) {
struct vring_desc *indir_desc = vq->desc_state[head].indir_desc;
- u32 len = vq->vring.desc[head].len;
+ u32 len = virtio32_to_cpu(vq->vq.vdev, vq->vring.desc[head].len);
BUG_ON(!(vq->vring.desc[head].flags &
cpu_to_virtio16(vq->vq.vdev, VRING_DESC_F_INDIRECT)));
now it boots.
>
>> +
>> + BUG_ON(!(vq->vring.desc[head].flags &
>> + cpu_to_virtio16(vq->vq.vdev, VRING_DESC_F_INDIRECT)));
>> + BUG_ON(len == 0 || len % sizeof(struct vring_desc));
>> +
>> + for (j = 0; j < len / sizeof(struct vring_desc); j++)
>> + vring_unmap_one(vq, &indir_desc[j]);
>> +
>> + kfree(vq->desc_state[head].indir_desc);
>> + vq->desc_state[head].indir_desc = NULL;
>> + }
>> }
>
> With that change on top of your current branch, I can boot (root on
> virtio-blk, either virtio-1 or legacy virtio) on current qemu master
> with kvm enabled on s390. Haven't tried anything further.
>
next prev parent reply other threads:[~2015-10-30 12:05 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <cover.1446162273.git.luto@kernel.org>
2015-10-30 1:09 ` [PATCH v4 1/6] virtio-net: Stop doing DMA from the stack Andy Lutomirski
2015-10-30 1:09 ` [PATCH v4 2/6] virtio_ring: Support DMA APIs Andy Lutomirski
2015-10-30 1:09 ` [PATCH v4 3/6] virtio_pci: Use the DMA API Andy Lutomirski
2015-10-30 1:09 ` [PATCH v4 4/6] virtio: Add improved queue allocation API Andy Lutomirski
2015-10-30 1:09 ` [PATCH v4 5/6] virtio_mmio: Use the DMA API Andy Lutomirski
2015-10-30 1:09 ` [PATCH v4 6/6] virtio_pci: " Andy Lutomirski
2015-10-30 1:17 ` [PATCH v4 0/6] virtio core DMA API conversion Andy Lutomirski
2015-10-30 9:57 ` Christian Borntraeger
[not found] ` <7c590bf685f5cbc3f01e42bdbc1dbe3ffd83420f.1446162273.git.luto@kernel.org>
2015-10-30 12:01 ` [PATCH v4 2/6] virtio_ring: Support DMA APIs Cornelia Huck
2015-10-30 12:05 ` Christian Borntraeger [this message]
2015-10-30 18:51 ` Andy Lutomirski
[not found] ` <8d6b1fc3b5d3b6f5e8b212ef690691a52fbefaff.1446162273.git.luto@kernel.org>
2015-10-30 13:55 ` [PATCH v4 1/6] virtio-net: Stop doing DMA from the stack Christian Borntraeger
[not found] ` <563376D2.20502@de.ibm.com>
2015-10-31 5:02 ` Andy Lutomirski
2015-11-09 12:15 ` [PATCH v4 0/6] virtio core DMA API conversion Michael S. Tsirkin
2015-11-09 12:27 ` Paolo Bonzini
2015-11-09 22:58 ` Benjamin Herrenschmidt
2015-11-10 0:46 ` Andy Lutomirski
2015-11-10 2:04 ` Benjamin Herrenschmidt
2015-11-10 2:18 ` Andy Lutomirski
[not found] ` <CALCETrW5_bKCX5gKYaH5y4rvD9jrjY5O5d=oX8hHtAM9EE2Bew@mail.gmail.com>
2015-11-10 5:26 ` Benjamin Herrenschmidt
2015-11-10 5:33 ` Andy Lutomirski
2015-11-10 5:28 ` Benjamin Herrenschmidt
2015-11-10 5:35 ` Andy Lutomirski
[not found] ` <CALCETrVPQc04Ah7FXcRMb4RhpUJ1WPCoC_4dbacB8a+u5XpmwA@mail.gmail.com>
2015-11-10 10:37 ` Benjamin Herrenschmidt
2015-11-10 12:43 ` Michael S. Tsirkin
2015-11-10 18:54 ` Andy Lutomirski
2015-11-10 22:27 ` Benjamin Herrenschmidt
2015-11-10 23:44 ` Andy Lutomirski
[not found] ` <CALCETrWb9poeyxXhcbAbQkpcP-XYjWtz2w9iSPkKJH8rdzAj-A@mail.gmail.com>
2015-11-11 0:44 ` Benjamin Herrenschmidt
2015-11-11 4:46 ` Andy Lutomirski
2015-11-11 5:08 ` Benjamin Herrenschmidt
[not found] ` <20151110142633-mutt-send-email-mst@redhat.com>
2015-11-10 19:37 ` Benjamin Herrenschmidt
2015-11-10 7:28 ` Jan Kiszka
2015-11-10 9:45 ` Knut Omang
[not found] ` <1447148714.3005.133.camel@oracle.com>
2015-11-10 10:26 ` Benjamin Herrenschmidt
2015-11-10 10:27 ` Joerg Roedel
2015-11-10 19:36 ` Benjamin Herrenschmidt
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=56335CF7.2050101@de.ibm.com \
--to=borntraeger@de.ibm.com \
--cc=benh@kernel.crashing.org \
--cc=cornelia.huck@de.ibm.com \
--cc=davem@davemloft.net \
--cc=dwmw2@infradead.org \
--cc=hch@lst.de \
--cc=jroedel@suse.de \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=schwidefsky@de.ibm.com \
--cc=sebott@linux.vnet.ibm.com \
--cc=sparclinux@vger.kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).