* [PATCH v2] kvm tools: fix boot of guests with more than 4gb of ram
@ 2013-07-07 16:00 Sasha Levin
2013-07-08 8:12 ` Pekka Enberg
0 siblings, 1 reply; 4+ messages in thread
From: Sasha Levin @ 2013-07-07 16:00 UTC (permalink / raw)
To: penberg; +Cc: will.deacon, kvm, Sasha Levin
Commit "kvm tools: virtio: remove hardcoded assumptions
about guest page size" has introduced a bug that prevented
guests with more than 4gb of ram from booting.
The issue is that 'pfn' is a 32bit integer, so when multiplying
it by page size to get the actual page will cause an overflow if
the pfn referred to a memory area above 4gb.
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
---
tools/kvm/include/kvm/virtio.h | 6 ++++++
tools/kvm/virtio/9p.c | 2 +-
tools/kvm/virtio/balloon.c | 2 +-
tools/kvm/virtio/blk.c | 2 +-
tools/kvm/virtio/console.c | 2 +-
tools/kvm/virtio/net.c | 2 +-
tools/kvm/virtio/rng.c | 2 +-
tools/kvm/virtio/scsi.c | 2 +-
8 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/tools/kvm/include/kvm/virtio.h b/tools/kvm/include/kvm/virtio.h
index 269ea4a..820b94a 100644
--- a/tools/kvm/include/kvm/virtio.h
+++ b/tools/kvm/include/kvm/virtio.h
@@ -90,4 +90,10 @@ int virtio_init(struct kvm *kvm, void *dev, struct virtio_device *vdev,
struct virtio_ops *ops, enum virtio_trans trans,
int device_id, int subsys_id, int class);
int virtio_compat_add_message(const char *device, const char *config);
+
+static inline void *virtio_get_vq(struct kvm *kvm, u32 pfn, u32 page_size)
+{
+ return guest_flat_to_host(kvm, (u64)pfn * page_size);
+}
+
#endif /* KVM__VIRTIO_H */
diff --git a/tools/kvm/virtio/9p.c b/tools/kvm/virtio/9p.c
index b7a5723..127b13a 100644
--- a/tools/kvm/virtio/9p.c
+++ b/tools/kvm/virtio/9p.c
@@ -1267,7 +1267,7 @@ static int init_vq(struct kvm *kvm, void *dev, u32 vq, u32 page_size, u32 align,
queue = &p9dev->vqs[vq];
queue->pfn = pfn;
- p = guest_flat_to_host(kvm, queue->pfn * page_size);
+ p = virtio_get_vq(kvm, queue->pfn, page_size);
job = &p9dev->jobs[vq];
vring_init(&queue->vring, VIRTQUEUE_NUM, p, align);
diff --git a/tools/kvm/virtio/balloon.c b/tools/kvm/virtio/balloon.c
index d1b64fa..4863535 100644
--- a/tools/kvm/virtio/balloon.c
+++ b/tools/kvm/virtio/balloon.c
@@ -204,7 +204,7 @@ static int init_vq(struct kvm *kvm, void *dev, u32 vq, u32 page_size, u32 align,
queue = &bdev->vqs[vq];
queue->pfn = pfn;
- p = guest_flat_to_host(kvm, queue->pfn * page_size);
+ p = virtio_get_vq(kvm, queue->pfn, page_size);
thread_pool__init_job(&bdev->jobs[vq], kvm, virtio_bln_do_io, queue);
vring_init(&queue->vring, VIRTIO_BLN_QUEUE_SIZE, p, align);
diff --git a/tools/kvm/virtio/blk.c b/tools/kvm/virtio/blk.c
index 44ac44b..ab18716 100644
--- a/tools/kvm/virtio/blk.c
+++ b/tools/kvm/virtio/blk.c
@@ -167,7 +167,7 @@ static int init_vq(struct kvm *kvm, void *dev, u32 vq, u32 page_size, u32 align,
queue = &bdev->vqs[vq];
queue->pfn = pfn;
- p = guest_flat_to_host(kvm, queue->pfn * page_size);
+ p = virtio_get_vq(kvm, queue->pfn, page_size);
vring_init(&queue->vring, VIRTIO_BLK_QUEUE_SIZE, p, align);
diff --git a/tools/kvm/virtio/console.c b/tools/kvm/virtio/console.c
index 1f88a4b..83c58bf 100644
--- a/tools/kvm/virtio/console.c
+++ b/tools/kvm/virtio/console.c
@@ -137,7 +137,7 @@ static int init_vq(struct kvm *kvm, void *dev, u32 vq, u32 page_size, u32 align,
queue = &cdev.vqs[vq];
queue->pfn = pfn;
- p = guest_flat_to_host(kvm, queue->pfn * page_size);
+ p = virtio_get_vq(kvm, queue->pfn, page_size);
vring_init(&queue->vring, VIRTIO_CONSOLE_QUEUE_SIZE, p, align);
diff --git a/tools/kvm/virtio/net.c b/tools/kvm/virtio/net.c
index 7855cfc..298903c 100644
--- a/tools/kvm/virtio/net.c
+++ b/tools/kvm/virtio/net.c
@@ -410,7 +410,7 @@ static int init_vq(struct kvm *kvm, void *dev, u32 vq, u32 page_size, u32 align,
queue = &ndev->vqs[vq];
queue->pfn = pfn;
- p = guest_flat_to_host(kvm, queue->pfn * page_size);
+ p = virtio_get_vq(kvm, queue->pfn, page_size);
vring_init(&queue->vring, VIRTIO_NET_QUEUE_SIZE, p, align);
diff --git a/tools/kvm/virtio/rng.c b/tools/kvm/virtio/rng.c
index 2ce8afd..394de71 100644
--- a/tools/kvm/virtio/rng.c
+++ b/tools/kvm/virtio/rng.c
@@ -98,7 +98,7 @@ static int init_vq(struct kvm *kvm, void *dev, u32 vq, u32 page_size, u32 align,
queue = &rdev->vqs[vq];
queue->pfn = pfn;
- p = guest_flat_to_host(kvm, queue->pfn * page_size);
+ p = virtio_get_vq(kvm, queue->pfn, page_size);
job = &rdev->jobs[vq];
diff --git a/tools/kvm/virtio/scsi.c b/tools/kvm/virtio/scsi.c
index 05b2dc6..8da2420 100644
--- a/tools/kvm/virtio/scsi.c
+++ b/tools/kvm/virtio/scsi.c
@@ -63,7 +63,7 @@ static int init_vq(struct kvm *kvm, void *dev, u32 vq, u32 page_size, u32 align,
queue = &sdev->vqs[vq];
queue->pfn = pfn;
- p = guest_flat_to_host(kvm, queue->pfn * page_size);
+ p = virtio_get_vq(kvm, queue->pfn, page_size);
vring_init(&queue->vring, VIRTIO_SCSI_QUEUE_SIZE, p, align);
--
1.8.1.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] kvm tools: fix boot of guests with more than 4gb of ram
2013-07-07 16:00 [PATCH v2] kvm tools: fix boot of guests with more than 4gb of ram Sasha Levin
@ 2013-07-08 8:12 ` Pekka Enberg
2013-07-08 10:58 ` Will Deacon
0 siblings, 1 reply; 4+ messages in thread
From: Pekka Enberg @ 2013-07-08 8:12 UTC (permalink / raw)
To: Sasha Levin
Cc: Will Deacon, KVM General, Michael Tokarev, Michael Ellerman, Asias He
On Sun, Jul 7, 2013 at 7:00 PM, Sasha Levin <sasha.levin@oracle.com> wrote:
> Commit "kvm tools: virtio: remove hardcoded assumptions
> about guest page size" has introduced a bug that prevented
> guests with more than 4gb of ram from booting.
>
> The issue is that 'pfn' is a 32bit integer, so when multiplying
> it by page size to get the actual page will cause an overflow if
> the pfn referred to a memory area above 4gb.
>
> Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Will, Michael, Asias, good to merge?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] kvm tools: fix boot of guests with more than 4gb of ram
2013-07-08 8:12 ` Pekka Enberg
@ 2013-07-08 10:58 ` Will Deacon
2013-07-09 6:29 ` Pekka Enberg
0 siblings, 1 reply; 4+ messages in thread
From: Will Deacon @ 2013-07-08 10:58 UTC (permalink / raw)
To: Pekka Enberg
Cc: Sasha Levin, KVM General, Michael Tokarev, Michael Ellerman,
Asias He, jonathan.austin
Hi guys,
On Mon, Jul 08, 2013 at 09:12:26AM +0100, Pekka Enberg wrote:
> On Sun, Jul 7, 2013 at 7:00 PM, Sasha Levin <sasha.levin@oracle.com> wrote:
> > Commit "kvm tools: virtio: remove hardcoded assumptions
> > about guest page size" has introduced a bug that prevented
> > guests with more than 4gb of ram from booting.
> >
> > The issue is that 'pfn' is a 32bit integer, so when multiplying
> > it by page size to get the actual page will cause an overflow if
> > the pfn referred to a memory area above 4gb.
> >
> > Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
>
> Will, Michael, Asias, good to merge?
I'm at a conference at the moment, so unable to test this patch, but it
looks simple and correct enough to me:
Acked-by: Will Deacon <will.deacon@arm.com>
Cheers,
Will
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] kvm tools: fix boot of guests with more than 4gb of ram
2013-07-08 10:58 ` Will Deacon
@ 2013-07-09 6:29 ` Pekka Enberg
0 siblings, 0 replies; 4+ messages in thread
From: Pekka Enberg @ 2013-07-09 6:29 UTC (permalink / raw)
To: Will Deacon
Cc: Sasha Levin, KVM General, Michael Tokarev, Michael Ellerman,
Asias He, jonathan.austin
On 07/08/2013 01:58 PM, Will Deacon wrote:
> Hi guys,
>
> On Mon, Jul 08, 2013 at 09:12:26AM +0100, Pekka Enberg wrote:
>> On Sun, Jul 7, 2013 at 7:00 PM, Sasha Levin <sasha.levin@oracle.com> wrote:
>>> Commit "kvm tools: virtio: remove hardcoded assumptions
>>> about guest page size" has introduced a bug that prevented
>>> guests with more than 4gb of ram from booting.
>>>
>>> The issue is that 'pfn' is a 32bit integer, so when multiplying
>>> it by page size to get the actual page will cause an overflow if
>>> the pfn referred to a memory area above 4gb.
>>>
>>> Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
>>
>> Will, Michael, Asias, good to merge?
>
> I'm at a conference at the moment, so unable to test this patch, but it
> looks simple and correct enough to me:
>
> Acked-by: Will Deacon <will.deacon@arm.com>
Applied, thanks a lot!
Pekka
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-07-09 6:29 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-07 16:00 [PATCH v2] kvm tools: fix boot of guests with more than 4gb of ram Sasha Levin
2013-07-08 8:12 ` Pekka Enberg
2013-07-08 10:58 ` Will Deacon
2013-07-09 6:29 ` Pekka Enberg
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.